contract_name
stringlengths
1
61
file_path
stringlengths
5
50.4k
contract_address
stringlengths
42
42
language
stringclasses
1 value
class_name
stringlengths
1
61
class_code
stringlengths
4
330k
class_documentation
stringlengths
0
29.1k
class_documentation_type
stringclasses
6 values
func_name
stringlengths
0
62
func_code
stringlengths
1
303k
func_documentation
stringlengths
2
14.9k
func_documentation_type
stringclasses
4 values
compiler_version
stringlengths
15
42
license_type
stringclasses
14 values
swarm_source
stringlengths
0
71
meta
dict
__index_level_0__
int64
0
60.4k
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
withdrawAllFunds
function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } }
//Recovery of funds
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 7671, 8036 ] }
12,700
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
withdrawAlltokenFunds
function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); }
//Recovery of Token funds
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 8070, 8416 ] }
12,701
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
kill
function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); }
// Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner.
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 8571, 8688 ] }
12,702
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
placeBet
function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); }
//Bet by ether: Commits are signed with a block limit to ensure that they are used at most once.
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 9766, 11435 ] }
12,703
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
getPossibleWinPrize
function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); }
//Get deductedBalance
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 21172, 21400 ] }
12,704
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
getPossibleWinAmount
function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); }
//Get deductedBalance
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 21434, 22040 ] }
12,705
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
refundBet
function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; }
// Refund transaction
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 23181, 23975 ] }
12,706
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
clearStorage
function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } }
// A helper routine to bulk clean the storage.
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 24907, 25136 ] }
12,707
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
clearProcessedBet
function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; }
// Helper routine to move 'processed' bets into 'clean' state.
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 25207, 25664 ] }
12,708
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
sendFunds
function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } }
// Helper routine to process the payment.
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 25714, 25950 ] }
12,709
Play0x_LottoBall
Play0x_LottoBall.sol
0x892552275e5d68d889a33ad119af86b7ddf7c237
Solidity
Play0x_LottoBall
contract Play0x_LottoBall { using SafeMath for uint256; using SafeMath for uint128; using SafeMath for uint40; using SafeMath for uint8; uint public jackpotSize; uint public MIN_BET; uint public MAX_BET; uint public MAX_AMOUNT; uint constant MAX_MODULO = 15; //Adjustable max bet profit. uint public maxProfit; //Fee percentage uint8 public platformFeePercentage = 15; uint8 public jackpotFeePercentage = 5; uint8 public ERC20rewardMultiple = 5; //0:ether 1:token uint8 public currencyType = 0; //Bets can be refunded via invoking refundBet. uint constant BetExpirationBlocks = 250; //Funds that are locked in potentially winning bets. uint public lockedInBets; //Standard contract ownership transfer. address public owner; address private nextOwner; address public secretSigner; address public refunder; //The address corresponding to a private key used to sign placeBet commits. address public ERC20ContractAddres; address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; //Single bet. struct Bet { //Amount in wei. uint amount; //place tx Block number. uint40 placeBlockNumber; // Address of a gambler. address gambler; // Game mode. uint8 machineMode; // Number of draws uint8 rotateTime; } //Mapping from commits mapping (uint => Bet) public bets; //Mapping from signer mapping(address => bool) public signerList; //Mapping from withdrawal mapping(uint8 => uint32) public withdrawalMode; //Admin Payment event ToManagerPayment(address indexed beneficiary, uint amount); event ToManagerFailedPayment(address indexed beneficiary, uint amount); event ToOwnerPayment(address indexed beneficiary, uint amount); event ToOwnerFailedPayment(address indexed beneficiary, uint amount); //Bet Payment event Payment(address indexed beneficiary, uint amount); event AllFundsPayment(address indexed beneficiary, uint amount); event AllTokenPayment(address indexed beneficiary, uint amount); event FailedPayment(address indexed beneficiary, uint amount); event TokenPayment(address indexed beneficiary, uint amount); //JACKPOT event JackpotBouns(address indexed beneficiary, uint amount); // Events that are issued to make statistic recovery easier. event PlaceBetLog(address indexed player, uint amount,uint8 rotateTime,uint commit); //Play0x_LottoBall_Event event BetRelatedData( address indexed player, uint playerBetAmount, uint playerGetAmount, bytes32 entropy, uint8 rotateTime ); //Refund_Event event RefundLog(address indexed player, uint commit, uint amount); // Constructor. Deliberately does not take any parameters. constructor () public { owner = msg.sender; secretSigner = DUMMY_ADDRESS; ERC20ContractAddres = DUMMY_ADDRESS; refunder = DUMMY_ADDRESS; } // Standard modifier on methods invokable only by contract owner. modifier onlyOwner { require (msg.sender == owner); _; } modifier onlyRefunder { require (msg.sender == refunder); _; } modifier onlySigner { require (signerList[msg.sender] == true); _; } //Init Parameter. function initialParameter( // address _manager, address _secretSigner, address _erc20tokenAddress , address _refunder, uint _MIN_BET, uint _MAX_BET, uint _maxProfit, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint8 _ERC20rewardMultiple, uint8 _currencyType, address[] _signerList, uint32[] _withdrawalMode)public onlyOwner{ secretSigner = _secretSigner; ERC20ContractAddres = _erc20tokenAddress; refunder = _refunder; MIN_BET = _MIN_BET; MAX_BET = _MAX_BET; maxProfit = _maxProfit; MAX_AMOUNT = _MAX_AMOUNT; platformFeePercentage = _platformFeePercentage; jackpotFeePercentage = _jackpotFeePercentage; ERC20rewardMultiple = _ERC20rewardMultiple; currencyType = _currencyType; createSignerList(_signerList); createWithdrawalMode(_withdrawalMode); } // Standard contract ownership transfer implementation, function approveNextOwner(address _nextOwner) public onlyOwner { require (_nextOwner != owner); nextOwner = _nextOwner; } function acceptNextOwner() public { require (msg.sender == nextOwner); owner = nextOwner; } // Fallback function deliberately left empty. function () public payable { } //Creat SignerList. function createSignerList(address[] _signerList)private onlyOwner { for (uint i=0; i<_signerList.length; i++) { address newSigner = _signerList[i]; signerList[newSigner] = true; } } //Creat WithdrawalMode. function createWithdrawalMode(uint32[] _withdrawalMode)private onlyOwner { for (uint8 i=0; i<_withdrawalMode.length; i++) { uint32 newWithdrawalMode = _withdrawalMode[i]; uint8 mode = i + 1; withdrawalMode[mode] = newWithdrawalMode; } } //Set SecretSigner. function setSecretSigner(address _secretSigner) external onlyOwner { secretSigner = _secretSigner; } //Set settle signer. function setSigner(address signer,bool isActive )external onlyOwner{ signerList[signer] = isActive; } //Set Refunder. function setRefunder(address _refunder) external onlyOwner { refunder = _refunder; } //Set tokenAddress. function setTokenAddress(address _tokenAddress) external onlyOwner { ERC20ContractAddres = _tokenAddress; } // Change max bet reward. Setting this to zero effectively disables betting. function setMaxProfit(uint _maxProfit) external onlyOwner { require (_maxProfit < MAX_AMOUNT && _maxProfit > 0); maxProfit = _maxProfit; } // Funds withdrawal. function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= address(this).balance && withdrawAmount > 0); uint safetyAmount = jackpotSize.add(lockedInBets).add(withdrawAmount); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= address(this).balance); sendFunds(beneficiary, withdrawAmount ); } // Token withdrawal. function withdrawToken(address beneficiary, uint withdrawAmount) external onlyOwner { require (withdrawAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); uint safetyAmount = jackpotSize.add(lockedInBets); safetyAmount = safetyAmount.add(withdrawAmount); require (safetyAmount <= ERC20(ERC20ContractAddres).balanceOf(address(this))); ERC20(ERC20ContractAddres).transfer(beneficiary, withdrawAmount); emit TokenPayment(beneficiary, withdrawAmount); } //Recovery of funds function withdrawAllFunds(address beneficiary) external onlyOwner { if (beneficiary.send(address(this).balance)) { lockedInBets = 0; jackpotSize = 0; emit AllFundsPayment(beneficiary, address(this).balance); } else { emit FailedPayment(beneficiary, address(this).balance); } } //Recovery of Token funds function withdrawAlltokenFunds(address beneficiary) external onlyOwner { ERC20(ERC20ContractAddres).transfer(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); lockedInBets = 0; jackpotSize = 0; emit AllTokenPayment(beneficiary, ERC20(ERC20ContractAddres).balanceOf(address(this))); } // Contract may be destroyed only when there are no ongoing bets, // either settled or refunded. All funds are transferred to contract owner. function kill() external onlyOwner { require (lockedInBets == 0); selfdestruct(owner); } function getContractInformation()public view returns( uint _jackpotSize, uint _MIN_BET, uint _MAX_BET, uint _MAX_AMOUNT, uint8 _platformFeePercentage, uint8 _jackpotFeePercentage, uint _maxProfit, uint _lockedInBets){ _jackpotSize = jackpotSize; _MIN_BET = MIN_BET; _MAX_BET = MAX_BET; _MAX_AMOUNT = MAX_AMOUNT; _platformFeePercentage = platformFeePercentage; _jackpotFeePercentage = jackpotFeePercentage; _maxProfit = maxProfit; _lockedInBets = lockedInBets; } function getContractAddress()public view returns( address _owner, address _ERC20ContractAddres, address _secretSigner, address _refunder ){ _owner = owner; _ERC20ContractAddres = ERC20ContractAddres; _secretSigner = secretSigner; _refunder = refunder; } //Bet by ether: Commits are signed with a block limit to ensure that they are used at most once. function placeBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s ) external payable { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); lockedInBets = lockedInBets.add( getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) ); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],msg.value) > 0); require (lockedInBets.add(jackpotSize) <= address(this).balance); //Amount should be within range require (msg.value >= MIN_BET && msg.value <= MAX_BET); emit PlaceBetLog(msg.sender, msg.value,_rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = msg.value; bet.placeBlockNumber = uint40(block.number); bet.gambler = msg.sender; bet.machineMode = uint8(_machineMode); bet.rotateTime = uint8(_rotateTime); } function placeTokenBet(uint8 _rotateTime , uint8 _machineMode , uint _commitLastBlock, uint _commit, bytes32 r, bytes32 s, uint _amount, address _playerAddress) external onlySigner { // Check that the bet is in 'clean' state. Bet storage bet = bets[_commit]; require (bet.gambler == address(0)); //Check SecretSigner. bytes32 signatureHash = keccak256(abi.encodePacked(_commitLastBlock, _commit)); require (secretSigner == ecrecover(signatureHash, 27, r, s)); //Check rotateTime ,machineMode and commitLastBlock. require (_rotateTime > 0 && _rotateTime <= 20); //_machineMode: 1~15 require (_machineMode > 0 && _machineMode <= MAX_MODULO); require (block.number < _commitLastBlock ); //Token lockedInBets lockedInBets = lockedInBets.add(getPossibleWinPrize(withdrawalMode[_machineMode],_amount)); //Check the highest profit require (getPossibleWinPrize(withdrawalMode[_machineMode],_amount) <= maxProfit && getPossibleWinPrize(withdrawalMode[_machineMode],_amount) > 0); require (lockedInBets.add(jackpotSize) <= ERC20(ERC20ContractAddres).balanceOf(address(this))); //Amount should be within range require (_amount >= MIN_BET && _amount <= MAX_BET); emit PlaceBetLog(_playerAddress, _amount, _rotateTime,_commit); // Store bet parameters on blockchain. bet.amount = _amount; bet.placeBlockNumber = uint40(block.number); bet.gambler = _playerAddress; bet.machineMode = _machineMode; bet.rotateTime = _rotateTime; } function settleBet(bytes32 luckySeed,uint reveal, bytes32 blockHash ) external onlySigner{ // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; // Check that bet is in 'active' state and check that bet has not expired yet. require (bet.amount != 0); require (bet.rotateTime > 0 && bet.rotateTime <= 20); require (bet.machineMode > 0 && bet.machineMode <= MAX_MODULO); require (block.number > bet.placeBlockNumber); require (block.number <= bet.placeBlockNumber.add(BetExpirationBlocks)); require (blockhash(bet.placeBlockNumber) == blockHash); //check possibleWinAmount require (getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount) < maxProfit); require (luckySeed > 0); //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. bytes32 _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); //Player profit uint totalAmount = 0; //Player Token profit uint totalTokenAmount = 0; //Jackpot check default value bool isGetJackpot = false; //Settlement record bytes32 tmp_entropy = _entropy; //Billing mode uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } //Player get Jackpot if (isGetJackpot == true ) { emit JackpotBouns(bet.gambler,jackpotSize); totalAmount = totalAmount.add(jackpotSize); jackpotSize = 0; } if (currencyType == 0) { //Ether game if (totalAmount != 0 && totalAmount < maxProfit){ sendFunds(bet.gambler, totalAmount ); } //Send ERC20 Token if (totalTokenAmount != 0){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalTokenAmount); emit TokenPayment(bet.gambler, totalTokenAmount); } } }else if(currencyType == 1){ //ERC20 game //Send ERC20 Token if (totalAmount != 0 && totalAmount < maxProfit){ if(ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ ERC20(ERC20ContractAddres).transfer(bet.gambler, totalAmount); emit TokenPayment(bet.gambler, totalAmount); } } } //Unlock the bet amount, regardless of the outcome. lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount)); //Save jackpotSize jackpotSize = jackpotSize.add(bet.amount.mul(jackpotFeePercentage).div(1000)); emit BetRelatedData( bet.gambler, bet.amount, totalAmount, _entropy, bet.rotateTime ); //Move bet into 'processed' state already. bet.amount = 0; } function runRotateTime (Bet storage bet, bytes32 _entropy )private view returns(uint totalAmount, uint totalTokenAmount, bool isGetJackpot ) { bytes32 tmp_entropy = _entropy; isGetJackpot = false; uint8 machineMode = bet.machineMode; for (uint8 i = 0; i < bet.rotateTime; i++) { //every round result bool isWinThisRound = false; //Random number of must be less than the machineMode assembly { switch gt(machineMode,and(tmp_entropy, 0xf)) case 1 { isWinThisRound := 1 } } if (isWinThisRound == true ){ //bet win, get single round bonus totalAmount = totalAmount.add(getPossibleWinPrize(withdrawalMode[bet.machineMode],bet.amount).div(bet.rotateTime)); //Platform fee determination:Ether Game Winning players must pay platform fees totalAmount = totalAmount.sub( ( ( bet.amount.div(bet.rotateTime) ).mul(platformFeePercentage) ).div(1000) ); }else if ( isWinThisRound == false && currencyType == 0 && ERC20(ERC20ContractAddres).balanceOf(address(this)) > 0){ //Ether game lose, get token reward totalTokenAmount = totalTokenAmount.add(bet.amount.div(bet.rotateTime).mul(ERC20rewardMultiple)); } //Get jackpotWin Result, only one chance to win Jackpot in each game. if (isGetJackpot == false){ //getJackpotWinBonus assembly { let buf := and(tmp_entropy, 0xffff) switch buf case 0xffff { isGetJackpot := 1 } } } //This round is settled, shift settlement record. tmp_entropy = tmp_entropy >> 4; } if (isGetJackpot == true ) { //gambler get jackpot. totalAmount = totalAmount.add(jackpotSize); } } //Get deductedBalance function getPossibleWinPrize(uint bonusPercentage,uint senderValue)public pure returns (uint possibleWinAmount) { //Win Amount possibleWinAmount = ((senderValue.mul(bonusPercentage))).div(10000); } //Get deductedBalance function getPossibleWinAmount(uint bonusPercentage,uint senderValue)public view returns (uint platformFee,uint jackpotFee,uint possibleWinAmount) { //Platform Fee uint prePlatformFee = (senderValue).mul(platformFeePercentage); platformFee = (prePlatformFee).div(1000); //Get jackpotFee uint preJackpotFee = (senderValue).mul(jackpotFeePercentage); jackpotFee = (preJackpotFee).div(1000); //Win Amount uint preUserGetAmount = senderValue.mul(bonusPercentage); possibleWinAmount = preUserGetAmount.div(10000); } function settleBetVerifi(bytes32 luckySeed,uint reveal,bytes32 blockHash )external view onlySigner returns(uint totalAmount,uint totalTokenAmount,bytes32 _entropy,bool isGetJackpot ) { // "commit" for bet settlement can only be obtained by hashing a "reveal". uint commit = uint(keccak256(abi.encodePacked(reveal))); // Fetch bet parameters into local variables (to save gas). Bet storage bet = bets[commit]; //The RNG - combine "reveal" and blockhash of LuckySeed using Keccak256. _entropy = keccak256( abi.encodePacked( uint( keccak256( abi.encodePacked( reveal, luckySeed ) ) ), blockHash ) ); isGetJackpot = false; (totalAmount,totalTokenAmount,isGetJackpot) = runRotateTime( bet, _entropy ); } // Refund transaction function refundBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); //Refund emit RefundLog(bet.gambler,commit, amount); sendFunds(bet.gambler, amount ); // Move bet into 'processed' state, release funds. bet.amount = 0; } function refundTokenBet(uint commit) external onlyRefunder{ // Check that bet is in 'active' state. Bet storage bet = bets[commit]; uint amount = bet.amount; uint8 machineMode = bet.machineMode; require (amount != 0, "Bet should be in an 'active' state"); // Check that bet has already expired. require (block.number > bet.placeBlockNumber.add(BetExpirationBlocks)); //Amount unlock lockedInBets = lockedInBets.sub(getPossibleWinPrize(withdrawalMode[machineMode],bet.amount)); emit RefundLog(bet.gambler,commit, amount); //Refund emit TokenPayment(bet.gambler, amount); ERC20(ERC20ContractAddres).transfer(bet.gambler, amount); // Move bet into 'processed' state, release funds. bet.amount = 0; } // A helper routine to bulk clean the storage. function clearStorage(uint[] cleanCommits) external onlyRefunder { uint length = cleanCommits.length; for (uint i = 0; i < length; i++) { clearProcessedBet(cleanCommits[i]); } } // Helper routine to move 'processed' bets into 'clean' state. function clearProcessedBet(uint commit) private { Bet storage bet = bets[commit]; // Do not overwrite active bets with zeros if (bet.amount != 0 || block.number <= bet.placeBlockNumber + BetExpirationBlocks) { return; } // Zero out the remaining storage bet.placeBlockNumber = 0; bet.gambler = address(0); bet.machineMode = 0; bet.rotateTime = 0; } // Helper routine to process the payment. function sendFunds(address receiver, uint amount ) private { if (receiver.send(amount)) { emit Payment(receiver, amount); } else { emit FailedPayment(receiver, amount); } } function sendFundsToOwner(address beneficiary, uint amount) external onlyOwner { if (beneficiary.send(amount)) { emit ToOwnerPayment(beneficiary, amount); } else { emit ToOwnerFailedPayment(beneficiary, amount); } } //Update function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; } function updateMAX_BET(uint _uintNumber)external onlyOwner { MAX_BET = _uintNumber; } function updateMAX_AMOUNT(uint _uintNumber)external onlyOwner { MAX_AMOUNT = _uintNumber; } function updateWithdrawalMode(uint8 _mode, uint32 _modeValue) external onlyOwner{ withdrawalMode[_mode] = _modeValue; } function updatePlatformFeePercentage(uint8 _platformFeePercentage ) external onlyOwner{ platformFeePercentage = _platformFeePercentage; } function updateJackpotFeePercentage(uint8 _jackpotFeePercentage ) external onlyOwner{ jackpotFeePercentage = _jackpotFeePercentage; } function updateERC20rewardMultiple(uint8 _ERC20rewardMultiple ) external onlyOwner{ ERC20rewardMultiple = _ERC20rewardMultiple; } function updateCurrencyType(uint8 _currencyType ) external onlyOwner{ currencyType = _currencyType; } function updateJackpot(uint newSize) external onlyOwner { require (newSize < address(this).balance && newSize > 0); jackpotSize = newSize; } }
updateMIN_BET
function updateMIN_BET(uint _uintNumber)external onlyOwner { MIN_BET = _uintNumber; }
//Update
LineComment
v0.4.24+commit.e67f0147
bzzr://b654f22f57aa857a1fab23118d87f2f9641b8a0d78456353eeb05e0ca95fb071
{ "func_code_index": [ 26252, 26357 ] }
12,710
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
IERC20
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); }
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 94, 154 ] }
12,711
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
IERC20
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); }
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 237, 310 ] }
12,712
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
IERC20
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); }
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 534, 616 ] }
12,713
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
IERC20
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); }
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @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. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 895, 983 ] }
12,714
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
IERC20
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); }
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @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. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 1647, 1726 ] }
12,715
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
IERC20
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); }
transferFrom
function transferFrom(address sender, address recipient, 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. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 2039, 2141 ] }
12,716
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
WanFarmErrorReporter
contract WanFarmErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED } enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK, SET_PENDING_ADMIN_OWNER_CHECK, SET_PENDING_IMPLEMENTATION_OWNER_CHECK } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint error, uint info, uint detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } }
fail
function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); }
/** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 747, 905 ] }
12,717
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
WanFarmErrorReporter
contract WanFarmErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED } enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK, SET_PENDING_ADMIN_OWNER_CHECK, SET_PENDING_IMPLEMENTATION_OWNER_CHECK } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint error, uint info, uint detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } }
failOpaque
function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); }
/** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 1023, 1215 ] }
12,718
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
UniFarm
contract UniFarm is UniFarmAdminStorage, WanFarmErrorReporter { /** * @notice Emitted when pendingWanFarmImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingWanFarmImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingWanFarmImplementation || pendingWanFarmImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = wanFarmImplementation; address oldPendingImplementation = pendingWanFarmImplementation; wanFarmImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = address(0); emit NewImplementation(oldImplementation, wanFarmImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // delegate all other functions to current implementation (bool success, ) = wanFarmImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
/** * @title ComptrollerCore * @dev Storage for the comptroller is at this address, while execution is delegated to the `wanFarmImplementation`. * CTokens should reference this contract as their comptroller. */
NatSpecMultiLine
_setPendingImplementation
function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); }
/*** Admin Functions ***/
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 935, 1468 ] }
12,719
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
UniFarm
contract UniFarm is UniFarmAdminStorage, WanFarmErrorReporter { /** * @notice Emitted when pendingWanFarmImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingWanFarmImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingWanFarmImplementation || pendingWanFarmImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = wanFarmImplementation; address oldPendingImplementation = pendingWanFarmImplementation; wanFarmImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = address(0); emit NewImplementation(oldImplementation, wanFarmImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // delegate all other functions to current implementation (bool success, ) = wanFarmImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
/** * @title ComptrollerCore * @dev Storage for the comptroller is at this address, while execution is delegated to the `wanFarmImplementation`. * CTokens should reference this contract as their comptroller. */
NatSpecMultiLine
_acceptImplementation
function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingWanFarmImplementation || pendingWanFarmImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = wanFarmImplementation; address oldPendingImplementation = pendingWanFarmImplementation; wanFarmImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = address(0); emit NewImplementation(oldImplementation, wanFarmImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); }
/** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 1762, 2659 ] }
12,720
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
UniFarm
contract UniFarm is UniFarmAdminStorage, WanFarmErrorReporter { /** * @notice Emitted when pendingWanFarmImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingWanFarmImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingWanFarmImplementation || pendingWanFarmImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = wanFarmImplementation; address oldPendingImplementation = pendingWanFarmImplementation; wanFarmImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = address(0); emit NewImplementation(oldImplementation, wanFarmImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // delegate all other functions to current implementation (bool success, ) = wanFarmImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
/** * @title ComptrollerCore * @dev Storage for the comptroller is at this address, while execution is delegated to the `wanFarmImplementation`. * CTokens should reference this contract as their comptroller. */
NatSpecMultiLine
_setPendingAdmin
function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); }
/** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 3070, 3712 ] }
12,721
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
UniFarm
contract UniFarm is UniFarmAdminStorage, WanFarmErrorReporter { /** * @notice Emitted when pendingWanFarmImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingWanFarmImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingWanFarmImplementation || pendingWanFarmImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = wanFarmImplementation; address oldPendingImplementation = pendingWanFarmImplementation; wanFarmImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = address(0); emit NewImplementation(oldImplementation, wanFarmImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // delegate all other functions to current implementation (bool success, ) = wanFarmImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
/** * @title ComptrollerCore * @dev Storage for the comptroller is at this address, while execution is delegated to the `wanFarmImplementation`. * CTokens should reference this contract as their comptroller. */
NatSpecMultiLine
_acceptAdmin
function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); }
/** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 3985, 4728 ] }
12,722
UniFarm
UniFarm.sol
0x3e460895ddeea50dd67f098f1bceffb03f36a04c
Solidity
UniFarm
contract UniFarm is UniFarmAdminStorage, WanFarmErrorReporter { /** * @notice Emitted when pendingWanFarmImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingWanFarmImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingWanFarmImplementation || pendingWanFarmImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = wanFarmImplementation; address oldPendingImplementation = pendingWanFarmImplementation; wanFarmImplementation = pendingWanFarmImplementation; pendingWanFarmImplementation = address(0); emit NewImplementation(oldImplementation, wanFarmImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingWanFarmImplementation); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // delegate all other functions to current implementation (bool success, ) = wanFarmImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
/** * @title ComptrollerCore * @dev Storage for the comptroller is at this address, while execution is delegated to the `wanFarmImplementation`. * CTokens should reference this contract as their comptroller. */
NatSpecMultiLine
function () payable external { // delegate all other functions to current implementation (bool success, ) = wanFarmImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } }
/** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
MIT
bzzr://551eb6e8a67d3a2965fd243e7e2a25a81587914e8795350764745743efbca3ad
{ "func_code_index": [ 4920, 5405 ] }
12,723
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
SpreadswapFinance
function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _totalSupply); }
// ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 464, 816 ] }
12,724
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
totalSupply
function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; }
// ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 1004, 1125 ] }
12,725
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
balanceOf
function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; }
// ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 1345, 1474 ] }
12,726
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transfer
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; }
// ------------------------------------------------------------------------ // 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 // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 1818, 2095 ] }
12,727
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
approve
function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, 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 // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 2603, 2811 ] }
12,728
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transferFrom
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; }
// ------------------------------------------------------------------------ // 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 // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 3342, 3700 ] }
12,729
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
allowance
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; }
// ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 3983, 4139 ] }
12,730
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
approveAndCall
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; }
// ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 4494, 4811 ] }
12,731
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
function () public payable { revert(); }
// ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 5003, 5062 ] }
12,732
SpreadswapFinance
SpreadswapFinance.sol
0x8b30b3e33fa704858fb58e7de70030d8bcfaaef7
Solidity
SpreadswapFinance
contract SpreadswapFinance 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 // ------------------------------------------------------------------------ function SpreadswapFinance() public { symbol = "SSF"; name = "Spreadswap.Finance"; decimals = 18; _totalSupply = 36000000000000000000000; balances[0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a] = _totalSupply; Transfer(address(0), 0x4aaDefF6693FB4dc8FfaFfA6E69b0CB7aB4a458a, _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); 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; 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); 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; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transferAnyERC20Token
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); }
// ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------
LineComment
v0.4.23+commit.124ca40d
None
bzzr://0d3b274bf418717256907574afa6ac9694510a09a52c94b8657a6b7cc96d230b
{ "func_code_index": [ 5295, 5484 ] }
12,733
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
name
function name() public view returns (string memory) { return _name; }
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 909, 997 ] }
12,734
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
symbol
function symbol() public view returns (string memory) { return _symbol; }
/** * @dev Returns the symbol of the token, usually a shorter version of the * name. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 1111, 1203 ] }
12,735
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
decimals
function decimals() public view returns (uint8) { return _decimals; }
/** * @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}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 1836, 1924 ] }
12,736
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
totalSupply
function totalSupply() public view override returns (uint256) { return _totalSupply; }
/** * @dev See {IERC20-totalSupply}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 1984, 2089 ] }
12,737
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
balanceOf
function balanceOf(address account) public view override returns (uint256) { return _balances[account]; }
/** * @dev See {IERC20-balanceOf}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 2147, 2271 ] }
12,738
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
transfer
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; }
/** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 2479, 2659 ] }
12,739
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
allowance
function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; }
/** * @dev See {IERC20-allowance}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 2717, 2873 ] }
12,740
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
approve
function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; }
/** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 3015, 3189 ] }
12,741
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
transferFrom
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 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`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 3666, 3992 ] }
12,742
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
increaseAllowance
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 4396, 4619 ] }
12,743
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
decreaseAllowance
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 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`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 5117, 5391 ] }
12,744
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
_transfer
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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 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`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 5876, 6578 ] }
12,745
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
_mint
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 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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 6855, 7238 ] }
12,746
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
_burn
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 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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 7566, 7989 ] }
12,747
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
_approve
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 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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 8422, 8773 ] }
12,748
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
_setupDecimals
function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; }
/** * @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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 9100, 9195 ] }
12,749
ArbitrumDoge
ArbitrumDoge.sol
0xc5f3b23460ae231ca0f6774c941aac28c748d1eb
Solidity
ArbitrumDoge
contract ArbitrumDoge is Ownable, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply = 0; string private _name = 'ArbitrumDoge '; string private _symbol = 'ADOGE'; uint8 private _decimals = 18; uint256 public maxTxAmount = 1000000000000000e18; /** * @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 () public { _mint(_msgSender(), 1000000000000000e18); } /** * @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"); if(sender != owner() && recipient != owner()) require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); _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 { } function setMaxTxAmount(uint256 _maxTxAmount) external onlyOwner() { require(_maxTxAmount >= 10000e9 , 'maxTxAmount should be greater than 10000e9'); maxTxAmount = _maxTxAmount; } }
_beforeTokenTransfer
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
/** * @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]. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MIT
ipfs://665d9032ae8bc52c8f60910cdab66e0ae587be8ed43e636cdf7540fb333f7645
{ "func_code_index": [ 9797, 9894 ] }
12,750
SingleStaking
@openzeppelin/contracts/utils/Multicall.sol
0x6755630c583f12ffbd10568eb633c0319db34922
Solidity
Multicall
abstract contract Multicall { /** * @dev Receives and executes a batch of function calls on this contract. */ function multicall(bytes[] calldata data) external returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; i++) { results[i] = Address.functionDelegateCall(address(this), data[i]); } return results; } }
/** * @dev Provides a function to batch together multiple calls in a single external call. * * _Available since v4.1._ */
NatSpecMultiLine
multicall
function multicall(bytes[] calldata data) external returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; i++) { results[i] = Address.functionDelegateCall(address(this), data[i]); } return results; }
/** * @dev Receives and executes a batch of function calls on this contract. */
NatSpecMultiLine
v0.8.6+commit.11564f7e
{ "func_code_index": [ 124, 428 ] }
12,751
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
totalSupply
function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; }
// ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 978, 1099 ] }
12,752
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
balanceOf
function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; }
// ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 1319, 1448 ] }
12,753
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transfer
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; }
// ------------------------------------------------------------------------ // 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 // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 1792, 2074 ] }
12,754
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
approve
function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; }
// ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 2360, 2573 ] }
12,755
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transferFrom
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; }
// ------------------------------------------------------------------------ // 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 // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 3104, 3467 ] }
12,756
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
allowance
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; }
// ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 3750, 3906 ] }
12,757
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
approveAndCall
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; }
// ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 4261, 4583 ] }
12,758
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
function () public payable { revert(); }
// ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 4775, 4834 ] }
12,759
AntiDAI
AntiDAI.sol
0xc42817e3fe8203bc5b874b374433dd2545bfd95f
Solidity
AntiDAI
contract AntiDAI 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 = "XDAI"; name = "AntiDAI"; decimals = 18; _totalSupply = 720000000000000000000000000; balances[0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C] = _totalSupply; emit Transfer(address(0), 0xE293ecDe7Bc409f6062634a2aAa652fe4F6C253C, _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 // // ------------------------------------------------------------------------ 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(); } // ------------------------------------------------------------------------ // 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); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transferAnyERC20Token
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); }
// ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
None
bzzr://24863800f759b2cf044985920df2c448b1ba9de4e298655085be1ae3baf9a65f
{ "func_code_index": [ 5067, 5256 ] }
12,760
iColabRegistry
iColabRegistry.sol
0x4e469b6a7b782a8e6e9c4d22e5e52806fd3410d5
Solidity
Ownable
contract Ownable { 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 = msg.sender; 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 msg.sender == _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; } }
owner
function owner() public view returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
MIT
bzzr://be9d2555bf70fc8705d417b818bf45d5e1321129bece5f1a5ee932a7c823ee72
{ "func_code_index": [ 443, 527 ] }
12,761
iColabRegistry
iColabRegistry.sol
0x4e469b6a7b782a8e6e9c4d22e5e52806fd3410d5
Solidity
Ownable
contract Ownable { 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 = msg.sender; 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 msg.sender == _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; } }
isOwner
function isOwner() public view returns (bool) { return msg.sender == _owner; }
/** * @dev Returns true if the caller is the current owner. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
MIT
bzzr://be9d2555bf70fc8705d417b818bf45d5e1321129bece5f1a5ee932a7c823ee72
{ "func_code_index": [ 809, 906 ] }
12,762
iColabRegistry
iColabRegistry.sol
0x4e469b6a7b782a8e6e9c4d22e5e52806fd3410d5
Solidity
Ownable
contract Ownable { 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 = msg.sender; 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 msg.sender == _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; } }
renounceOwnership
function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @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. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
MIT
bzzr://be9d2555bf70fc8705d417b818bf45d5e1321129bece5f1a5ee932a7c823ee72
{ "func_code_index": [ 1254, 1399 ] }
12,763
iColabRegistry
iColabRegistry.sol
0x4e469b6a7b782a8e6e9c4d22e5e52806fd3410d5
Solidity
Ownable
contract Ownable { 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 = msg.sender; 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 msg.sender == _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; } }
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.5.8+commit.23d335f2
MIT
bzzr://be9d2555bf70fc8705d417b818bf45d5e1321129bece5f1a5ee932a7c823ee72
{ "func_code_index": [ 1549, 1663 ] }
12,764
iColabRegistry
iColabRegistry.sol
0x4e469b6a7b782a8e6e9c4d22e5e52806fd3410d5
Solidity
Ownable
contract Ownable { 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 = msg.sender; 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 msg.sender == _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; } }
_transferOwnership
function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). */
NatSpecMultiLine
v0.5.8+commit.23d335f2
MIT
bzzr://be9d2555bf70fc8705d417b818bf45d5e1321129bece5f1a5ee932a7c823ee72
{ "func_code_index": [ 1764, 1998 ] }
12,765
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ 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; } /** * @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 SafeMath * @dev Math operations with safety checks that throw on error */
NatSpecMultiLine
mul
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; }
/** * @dev Multiplies two numbers, throws on overflow. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 89, 266 ] }
12,766
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ 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; } /** * @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 SafeMath * @dev Math operations with safety checks that throw on error */
NatSpecMultiLine
div
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 Integer division of two numbers, truncating the quotient. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 350, 630 ] }
12,767
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ 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; } /** * @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 SafeMath * @dev Math operations with safety checks that throw on error */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; }
/** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 744, 860 ] }
12,768
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ 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; } /** * @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 SafeMath * @dev Math operations with safety checks that throw on error */
NatSpecMultiLine
add
function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; }
/** * @dev Adds two numbers, throws on overflow. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 924, 1054 ] }
12,769
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
BasicToken
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 Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
totalSupply
function totalSupply() public view returns (uint256) { return totalSupply_; }
/** * @dev total number of tokens in existence */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 199, 287 ] }
12,770
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
BasicToken
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 Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
transfer
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 transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 445, 777 ] }
12,771
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
BasicToken
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 Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
balanceOf
function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; }
/** * @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. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 983, 1087 ] }
12,772
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
StandardToken
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 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 */
NatSpecMultiLine
transferFrom
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 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 */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 401, 858 ] }
12,773
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
StandardToken
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 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 */
NatSpecMultiLine
approve
function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _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. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 1490, 1685 ] }
12,774
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
StandardToken
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 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 */
NatSpecMultiLine
allowance
function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; }
/** * @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. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 2009, 2140 ] }
12,775
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
StandardToken
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 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 */
NatSpecMultiLine
increaseApproval
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 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. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 2606, 2875 ] }
12,776
ARTIDToken
ARTIDToken.sol
0xc23867dabd392da14c602a3a65bcca4960fd2545
Solidity
StandardToken
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 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 */
NatSpecMultiLine
decreaseApproval
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; }
/** * @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. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://9a31a38ecb46c139ea7d02323c17b8edca3f681d8fe324049468d6795980e5ed
{ "func_code_index": [ 3346, 3761 ] }
12,777
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
TokenERC20
function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 }
/** * 初始化构造 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 588, 1015 ] }
12,778
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
_transfer
function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); }
/** * 代币交易转移的内部实现 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 1060, 1747 ] }
12,779
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
transfer
function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); }
/** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 1891, 2003 ] }
12,780
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
transferFrom
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; }
/** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 2126, 2427 ] }
12,781
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
approve
function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; }
/** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @param _spender The address authorized to spend * @param _value the max amount they can spend */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 2654, 2830 ] }
12,782
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
approveAndCall
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; } }
/** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 3009, 3382 ] }
12,783
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
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 Burn(msg.sender, _value); return true; }
/** * 销毁我(创建交易者)账户中指定个代币 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 3434, 3808 ] }
12,784
TokenERC20
TokenERC20.sol
0x0687f759b6a8940e6c984187e928875a767728b5
Solidity
TokenERC20
contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // decimals 可以有的小数点个数,最小的代币单位。18 是建议的默认值 uint256 public totalSupply; // 用mapping保存每个地址对应的余额 mapping (address => uint256) public balanceOf; // 存储对账号的控制 mapping (address => mapping (address => uint256)) public allowance; // 事件,用来通知客户端交易发生 event Transfer(address indexed from, address indexed to, uint256 value); // 事件,用来通知客户端代币被消费 event Burn(address indexed from, uint256 value); /** * 初始化构造 */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 symbol = tokenSymbol; // 代币符号 } /** * 代币交易转移的内部实现 */ function _transfer(address _from, address _to, uint _value) internal { // 确保目标地址不为0x0,因为0x0地址代表销毁 require(_to != 0x0); // 检查发送者余额 require(balanceOf[_from] >= _value); // 确保转移为正数个 require(balanceOf[_to] + _value > balanceOf[_to]); // 以下用来检查交易, uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * 代币交易转移 * 从自己(创建交易者)账号发送`_value`个代币到 `_to`账号 * * @param _to 接收者地址 * @param _value 转移数额 */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * 账号之间代币交易转移 * @param _from 发送者地址 * @param _to 接收者地址 * @param _value 转移数额 */ 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; } /** * 设置某个地址(合约)可以创建交易者名义花费的代币数。 * * 允许发送者`_spender` 花费不多于 `_value` 个代币 * * @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; } /** * 设置允许一个地址(合约)以我(创建交易者)的名义可最多花费的代币数。 * * @param _spender 被授权的地址(合约) * @param _value 最大可花费代币数 * @param _extraData 发送给合约的附加数据 */ 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; } } /** * 销毁我(创建交易者)账户中指定个代币 */ 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 Burn(msg.sender, _value); return true; } /** * 销毁用户账户中指定个代币 * * 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 Burn(_from, _value); return true; } }
burnFrom
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 Burn(_from, _value); return true; }
/** * 销毁用户账户中指定个代币 * * 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 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
None
bzzr://b8aaf66fc72be61462fa3721b19b60e95b7e1d18e90ff9bd02a98648c54a1d54
{ "func_code_index": [ 4049, 4660 ] }
12,785
SidusPreSale
SidusPreSale.sol
0x486a339e20c1349c95873c5d1c80416cbb3d10e4
Solidity
SidusPreSale
contract SidusPreSale is Ownable { using SafeERC20 for IERC20; struct LimitItem { uint256 tokenId; uint256 limit; } struct CardsSupply { uint256 maxTotalSupply; uint256 currentSupply; } struct Price { uint256 value; uint256 decimals; } uint256 public CARDS_PER_USER; address public beneficiary; uint256 public activeAfter; // date of start presale uint256 public closedAfter; // date of end presalr // maping from user to limits mapping(address => LimitItem[]) public whiteList; // mapping erc20 to 1155 tokenId to card price in this erc20 mapping(address => mapping(uint256 => Price)) public priceForCard; mapping(uint256 => CardsSupply) public maxTotalSupply; event Purchase( address indexed user, address indexed erc20, uint256 amount ); constructor (address _beneficiary, uint256 _activeAfter, uint256 _closedAfter) { require(_beneficiary != address(0), "No zero addess"); beneficiary = _beneficiary; activeAfter = _activeAfter; closedAfter = _closedAfter; CARDS_PER_USER = 10; } function registerForPreSale(address _erc20, LimitItem[] calldata _wanted) external { uint256 currLimit; uint256 userDebt; require(block.timestamp >= activeAfter, "Cant buy before start"); require(block.timestamp <= closedAfter, "Cant buy after closed"); for (uint256 i = 0; i < _wanted.length; i ++){ currLimit = _getUserLimitTotal(msg.sender); require(priceForCard[_erc20][_wanted[i].tokenId].value > 0, "Cant buy with this token" ); require( (currLimit + _addLimitForCard(msg.sender, _wanted[i].tokenId, _wanted[i].limit)) <= CARDS_PER_USER, "Purchase limit exceeded" ); userDebt += _getERC20AmountPerItem(_erc20, _wanted[i]); require( (_wanted[i].limit + maxTotalSupply[_wanted[i].tokenId].currentSupply) <= maxTotalSupply[_wanted[i].tokenId].maxTotalSupply, "Max Total Supply limit exceeded" ); maxTotalSupply[_wanted[i].tokenId].currentSupply += _wanted[i].limit; } IERC20(_erc20).safeTransferFrom(msg.sender, beneficiary, userDebt); emit Purchase(msg.sender, _erc20, userDebt); } /////////////////////////////////////////////////////////////////// ///// Owners Functions /////////////////////////////////////////// /////////////////////////////////////////////////////////////////// function registerUserForPreSale(address _erc20, LimitItem[] calldata _wanted, address _user) external onlyOwner { uint256 currLimit; for (uint256 i = 0; i < _wanted.length; i ++){ currLimit = _getUserLimitTotal(_user); require(priceForCard[_erc20][_wanted[i].tokenId].value > 0, "Cant buy with this token" ); require( (currLimit + _addLimitForCard(_user, _wanted[i].tokenId, _wanted[i].limit)) <= CARDS_PER_USER, "Purchase limit exceeded" ); require( _wanted[i].limit + maxTotalSupply[_wanted[i].tokenId].currentSupply <= maxTotalSupply[_wanted[i].tokenId].maxTotalSupply, "Max Total Supply limit exceeded" ); maxTotalSupply[_wanted[i].tokenId].currentSupply += _wanted[i].limit; } emit Purchase(_user, _erc20, 0); } function setStartStop(uint256 _activeAfter, uint256 _closedAfter) external onlyOwner { activeAfter = _activeAfter; closedAfter = _closedAfter; } function setBeneficiary(address _beneficiary) external onlyOwner { require(_beneficiary != address(0), "No zero addess"); beneficiary = _beneficiary; } function setCardsPerUser(uint256 _cardsCount) external onlyOwner { CARDS_PER_USER = _cardsCount; } function setERC20Price( address _erc20, uint256 _tokenId, uint256 _newPriceValue, uint256 _newPriceDecimals ) external onlyOwner { priceForCard[_erc20][_tokenId].value = _newPriceValue; priceForCard[_erc20][_tokenId].decimals = _newPriceDecimals; } function setMaxTotalSupply( uint256 _tokenId, uint256 _cardsCount) external onlyOwner { maxTotalSupply[_tokenId].maxTotalSupply = _cardsCount; } /////////////////////////////////////////////////////////////////// function getCardPrice(address _erc20, uint256 _tokenId) external view returns (Price memory) { return priceForCard[_erc20][_tokenId]; } function getUserLimitsInfo(address _user) external view returns (LimitItem[] memory) { return whiteList[_user]; } function getUserLimitTotal(address _user) external view returns (uint256) { return _getUserLimitTotal(_user); } function getUserLimitForCard(address _user, uint256 _tokenId) external view returns (uint256) { return _getUserLimitForCard(_user, _tokenId); } function getERC20Amount(address _erc20, LimitItem[] calldata _wanted) external view returns (uint256 erc20Amount) { for (uint256 i = 0; i < _wanted.length; i ++){ erc20Amount += _getERC20AmountPerItem(_erc20, _wanted[i]); } } /////////////////////////////////////////////////////////////////// ///// Internal Functions ///////////////////////////////////////// /////////////////////////////////////////////////////////////////// function _addLimitForCard(address _user, uint256 _tokenId, uint256 _increment) internal returns (uint256 increment) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ if (whiteList[_user][i].tokenId == _tokenId) { whiteList[_user][i].limit += _increment; increment = _increment; break; } } // if newLimit == 0 means that there is NO record // in array for this tokenId yet. So we need add it if (increment == 0){ whiteList[_user].push(LimitItem({ tokenId: _tokenId, limit: _increment })); increment = _increment; } } function _getUserLimitForCard(address _user, uint256 _tokenId) internal view returns (uint256 limit) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ if (whiteList[_user][i].tokenId == _tokenId) { limit += whiteList[_user][i].limit; } } } function _getUserLimitTotal(address _user) internal view returns (uint256 limit) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ limit += whiteList[_user][i].limit; } } function _getERC20AmountPerItem(address _erc20, LimitItem calldata _wanted) internal view returns(uint256) { return _wanted.limit * priceForCard[_erc20][_wanted.tokenId].value / priceForCard[_erc20][_wanted.tokenId].decimals; } }
registerUserForPreSale
function registerUserForPreSale(address _erc20, LimitItem[] calldata _wanted, address _user) external onlyOwner { uint256 currLimit; for (uint256 i = 0; i < _wanted.length; i ++){ currLimit = _getUserLimitTotal(_user); require(priceForCard[_erc20][_wanted[i].tokenId].value > 0, "Cant buy with this token" ); require( (currLimit + _addLimitForCard(_user, _wanted[i].tokenId, _wanted[i].limit)) <= CARDS_PER_USER, "Purchase limit exceeded" ); require( _wanted[i].limit + maxTotalSupply[_wanted[i].tokenId].currentSupply <= maxTotalSupply[_wanted[i].tokenId].maxTotalSupply, "Max Total Supply limit exceeded" ); maxTotalSupply[_wanted[i].tokenId].currentSupply += _wanted[i].limit; } emit Purchase(_user, _erc20, 0); }
/////////////////////////////////////////////////////////////////// ///// Owners Functions /////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
NatSpecSingleLine
v0.8.11+commit.d7f03943
MIT
{ "func_code_index": [ 2707, 3642 ] }
12,786
SidusPreSale
SidusPreSale.sol
0x486a339e20c1349c95873c5d1c80416cbb3d10e4
Solidity
SidusPreSale
contract SidusPreSale is Ownable { using SafeERC20 for IERC20; struct LimitItem { uint256 tokenId; uint256 limit; } struct CardsSupply { uint256 maxTotalSupply; uint256 currentSupply; } struct Price { uint256 value; uint256 decimals; } uint256 public CARDS_PER_USER; address public beneficiary; uint256 public activeAfter; // date of start presale uint256 public closedAfter; // date of end presalr // maping from user to limits mapping(address => LimitItem[]) public whiteList; // mapping erc20 to 1155 tokenId to card price in this erc20 mapping(address => mapping(uint256 => Price)) public priceForCard; mapping(uint256 => CardsSupply) public maxTotalSupply; event Purchase( address indexed user, address indexed erc20, uint256 amount ); constructor (address _beneficiary, uint256 _activeAfter, uint256 _closedAfter) { require(_beneficiary != address(0), "No zero addess"); beneficiary = _beneficiary; activeAfter = _activeAfter; closedAfter = _closedAfter; CARDS_PER_USER = 10; } function registerForPreSale(address _erc20, LimitItem[] calldata _wanted) external { uint256 currLimit; uint256 userDebt; require(block.timestamp >= activeAfter, "Cant buy before start"); require(block.timestamp <= closedAfter, "Cant buy after closed"); for (uint256 i = 0; i < _wanted.length; i ++){ currLimit = _getUserLimitTotal(msg.sender); require(priceForCard[_erc20][_wanted[i].tokenId].value > 0, "Cant buy with this token" ); require( (currLimit + _addLimitForCard(msg.sender, _wanted[i].tokenId, _wanted[i].limit)) <= CARDS_PER_USER, "Purchase limit exceeded" ); userDebt += _getERC20AmountPerItem(_erc20, _wanted[i]); require( (_wanted[i].limit + maxTotalSupply[_wanted[i].tokenId].currentSupply) <= maxTotalSupply[_wanted[i].tokenId].maxTotalSupply, "Max Total Supply limit exceeded" ); maxTotalSupply[_wanted[i].tokenId].currentSupply += _wanted[i].limit; } IERC20(_erc20).safeTransferFrom(msg.sender, beneficiary, userDebt); emit Purchase(msg.sender, _erc20, userDebt); } /////////////////////////////////////////////////////////////////// ///// Owners Functions /////////////////////////////////////////// /////////////////////////////////////////////////////////////////// function registerUserForPreSale(address _erc20, LimitItem[] calldata _wanted, address _user) external onlyOwner { uint256 currLimit; for (uint256 i = 0; i < _wanted.length; i ++){ currLimit = _getUserLimitTotal(_user); require(priceForCard[_erc20][_wanted[i].tokenId].value > 0, "Cant buy with this token" ); require( (currLimit + _addLimitForCard(_user, _wanted[i].tokenId, _wanted[i].limit)) <= CARDS_PER_USER, "Purchase limit exceeded" ); require( _wanted[i].limit + maxTotalSupply[_wanted[i].tokenId].currentSupply <= maxTotalSupply[_wanted[i].tokenId].maxTotalSupply, "Max Total Supply limit exceeded" ); maxTotalSupply[_wanted[i].tokenId].currentSupply += _wanted[i].limit; } emit Purchase(_user, _erc20, 0); } function setStartStop(uint256 _activeAfter, uint256 _closedAfter) external onlyOwner { activeAfter = _activeAfter; closedAfter = _closedAfter; } function setBeneficiary(address _beneficiary) external onlyOwner { require(_beneficiary != address(0), "No zero addess"); beneficiary = _beneficiary; } function setCardsPerUser(uint256 _cardsCount) external onlyOwner { CARDS_PER_USER = _cardsCount; } function setERC20Price( address _erc20, uint256 _tokenId, uint256 _newPriceValue, uint256 _newPriceDecimals ) external onlyOwner { priceForCard[_erc20][_tokenId].value = _newPriceValue; priceForCard[_erc20][_tokenId].decimals = _newPriceDecimals; } function setMaxTotalSupply( uint256 _tokenId, uint256 _cardsCount) external onlyOwner { maxTotalSupply[_tokenId].maxTotalSupply = _cardsCount; } /////////////////////////////////////////////////////////////////// function getCardPrice(address _erc20, uint256 _tokenId) external view returns (Price memory) { return priceForCard[_erc20][_tokenId]; } function getUserLimitsInfo(address _user) external view returns (LimitItem[] memory) { return whiteList[_user]; } function getUserLimitTotal(address _user) external view returns (uint256) { return _getUserLimitTotal(_user); } function getUserLimitForCard(address _user, uint256 _tokenId) external view returns (uint256) { return _getUserLimitForCard(_user, _tokenId); } function getERC20Amount(address _erc20, LimitItem[] calldata _wanted) external view returns (uint256 erc20Amount) { for (uint256 i = 0; i < _wanted.length; i ++){ erc20Amount += _getERC20AmountPerItem(_erc20, _wanted[i]); } } /////////////////////////////////////////////////////////////////// ///// Internal Functions ///////////////////////////////////////// /////////////////////////////////////////////////////////////////// function _addLimitForCard(address _user, uint256 _tokenId, uint256 _increment) internal returns (uint256 increment) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ if (whiteList[_user][i].tokenId == _tokenId) { whiteList[_user][i].limit += _increment; increment = _increment; break; } } // if newLimit == 0 means that there is NO record // in array for this tokenId yet. So we need add it if (increment == 0){ whiteList[_user].push(LimitItem({ tokenId: _tokenId, limit: _increment })); increment = _increment; } } function _getUserLimitForCard(address _user, uint256 _tokenId) internal view returns (uint256 limit) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ if (whiteList[_user][i].tokenId == _tokenId) { limit += whiteList[_user][i].limit; } } } function _getUserLimitTotal(address _user) internal view returns (uint256 limit) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ limit += whiteList[_user][i].limit; } } function _getERC20AmountPerItem(address _erc20, LimitItem calldata _wanted) internal view returns(uint256) { return _wanted.limit * priceForCard[_erc20][_wanted.tokenId].value / priceForCard[_erc20][_wanted.tokenId].decimals; } }
getCardPrice
function getCardPrice(address _erc20, uint256 _tokenId) external view returns (Price memory) { return priceForCard[_erc20][_tokenId]; }
///////////////////////////////////////////////////////////////////
NatSpecSingleLine
v0.8.11+commit.d7f03943
MIT
{ "func_code_index": [ 4669, 4820 ] }
12,787
SidusPreSale
SidusPreSale.sol
0x486a339e20c1349c95873c5d1c80416cbb3d10e4
Solidity
SidusPreSale
contract SidusPreSale is Ownable { using SafeERC20 for IERC20; struct LimitItem { uint256 tokenId; uint256 limit; } struct CardsSupply { uint256 maxTotalSupply; uint256 currentSupply; } struct Price { uint256 value; uint256 decimals; } uint256 public CARDS_PER_USER; address public beneficiary; uint256 public activeAfter; // date of start presale uint256 public closedAfter; // date of end presalr // maping from user to limits mapping(address => LimitItem[]) public whiteList; // mapping erc20 to 1155 tokenId to card price in this erc20 mapping(address => mapping(uint256 => Price)) public priceForCard; mapping(uint256 => CardsSupply) public maxTotalSupply; event Purchase( address indexed user, address indexed erc20, uint256 amount ); constructor (address _beneficiary, uint256 _activeAfter, uint256 _closedAfter) { require(_beneficiary != address(0), "No zero addess"); beneficiary = _beneficiary; activeAfter = _activeAfter; closedAfter = _closedAfter; CARDS_PER_USER = 10; } function registerForPreSale(address _erc20, LimitItem[] calldata _wanted) external { uint256 currLimit; uint256 userDebt; require(block.timestamp >= activeAfter, "Cant buy before start"); require(block.timestamp <= closedAfter, "Cant buy after closed"); for (uint256 i = 0; i < _wanted.length; i ++){ currLimit = _getUserLimitTotal(msg.sender); require(priceForCard[_erc20][_wanted[i].tokenId].value > 0, "Cant buy with this token" ); require( (currLimit + _addLimitForCard(msg.sender, _wanted[i].tokenId, _wanted[i].limit)) <= CARDS_PER_USER, "Purchase limit exceeded" ); userDebt += _getERC20AmountPerItem(_erc20, _wanted[i]); require( (_wanted[i].limit + maxTotalSupply[_wanted[i].tokenId].currentSupply) <= maxTotalSupply[_wanted[i].tokenId].maxTotalSupply, "Max Total Supply limit exceeded" ); maxTotalSupply[_wanted[i].tokenId].currentSupply += _wanted[i].limit; } IERC20(_erc20).safeTransferFrom(msg.sender, beneficiary, userDebt); emit Purchase(msg.sender, _erc20, userDebt); } /////////////////////////////////////////////////////////////////// ///// Owners Functions /////////////////////////////////////////// /////////////////////////////////////////////////////////////////// function registerUserForPreSale(address _erc20, LimitItem[] calldata _wanted, address _user) external onlyOwner { uint256 currLimit; for (uint256 i = 0; i < _wanted.length; i ++){ currLimit = _getUserLimitTotal(_user); require(priceForCard[_erc20][_wanted[i].tokenId].value > 0, "Cant buy with this token" ); require( (currLimit + _addLimitForCard(_user, _wanted[i].tokenId, _wanted[i].limit)) <= CARDS_PER_USER, "Purchase limit exceeded" ); require( _wanted[i].limit + maxTotalSupply[_wanted[i].tokenId].currentSupply <= maxTotalSupply[_wanted[i].tokenId].maxTotalSupply, "Max Total Supply limit exceeded" ); maxTotalSupply[_wanted[i].tokenId].currentSupply += _wanted[i].limit; } emit Purchase(_user, _erc20, 0); } function setStartStop(uint256 _activeAfter, uint256 _closedAfter) external onlyOwner { activeAfter = _activeAfter; closedAfter = _closedAfter; } function setBeneficiary(address _beneficiary) external onlyOwner { require(_beneficiary != address(0), "No zero addess"); beneficiary = _beneficiary; } function setCardsPerUser(uint256 _cardsCount) external onlyOwner { CARDS_PER_USER = _cardsCount; } function setERC20Price( address _erc20, uint256 _tokenId, uint256 _newPriceValue, uint256 _newPriceDecimals ) external onlyOwner { priceForCard[_erc20][_tokenId].value = _newPriceValue; priceForCard[_erc20][_tokenId].decimals = _newPriceDecimals; } function setMaxTotalSupply( uint256 _tokenId, uint256 _cardsCount) external onlyOwner { maxTotalSupply[_tokenId].maxTotalSupply = _cardsCount; } /////////////////////////////////////////////////////////////////// function getCardPrice(address _erc20, uint256 _tokenId) external view returns (Price memory) { return priceForCard[_erc20][_tokenId]; } function getUserLimitsInfo(address _user) external view returns (LimitItem[] memory) { return whiteList[_user]; } function getUserLimitTotal(address _user) external view returns (uint256) { return _getUserLimitTotal(_user); } function getUserLimitForCard(address _user, uint256 _tokenId) external view returns (uint256) { return _getUserLimitForCard(_user, _tokenId); } function getERC20Amount(address _erc20, LimitItem[] calldata _wanted) external view returns (uint256 erc20Amount) { for (uint256 i = 0; i < _wanted.length; i ++){ erc20Amount += _getERC20AmountPerItem(_erc20, _wanted[i]); } } /////////////////////////////////////////////////////////////////// ///// Internal Functions ///////////////////////////////////////// /////////////////////////////////////////////////////////////////// function _addLimitForCard(address _user, uint256 _tokenId, uint256 _increment) internal returns (uint256 increment) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ if (whiteList[_user][i].tokenId == _tokenId) { whiteList[_user][i].limit += _increment; increment = _increment; break; } } // if newLimit == 0 means that there is NO record // in array for this tokenId yet. So we need add it if (increment == 0){ whiteList[_user].push(LimitItem({ tokenId: _tokenId, limit: _increment })); increment = _increment; } } function _getUserLimitForCard(address _user, uint256 _tokenId) internal view returns (uint256 limit) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ if (whiteList[_user][i].tokenId == _tokenId) { limit += whiteList[_user][i].limit; } } } function _getUserLimitTotal(address _user) internal view returns (uint256 limit) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ limit += whiteList[_user][i].limit; } } function _getERC20AmountPerItem(address _erc20, LimitItem calldata _wanted) internal view returns(uint256) { return _wanted.limit * priceForCard[_erc20][_wanted.tokenId].value / priceForCard[_erc20][_wanted.tokenId].decimals; } }
_addLimitForCard
function _addLimitForCard(address _user, uint256 _tokenId, uint256 _increment) internal returns (uint256 increment) { for (uint256 i = 0; i < whiteList[_user].length; i ++){ if (whiteList[_user][i].tokenId == _tokenId) { whiteList[_user][i].limit += _increment; increment = _increment; break; } } // if newLimit == 0 means that there is NO record // in array for this tokenId yet. So we need add it if (increment == 0){ whiteList[_user].push(LimitItem({ tokenId: _tokenId, limit: _increment })); increment = _increment; } }
/////////////////////////////////////////////////////////////////// ///// Internal Functions ///////////////////////////////////////// ///////////////////////////////////////////////////////////////////
NatSpecSingleLine
v0.8.11+commit.d7f03943
MIT
{ "func_code_index": [ 5729, 6480 ] }
12,788
WeiToken
WeiToken.sol
0x14654cc00fce33b50de832781fd730ec1e9f2b29
Solidity
WeiToken
contract WeiToken is StandardToken, Pausable { string public constant name = "WeiToken"; string public constant symbol = "YOUNG"; uint256 public constant decimals = 18; string public version = "1.0"; uint256 public constant total = 65 * (10**8) * 10**decimals; // 20 *10^8 HNC total function WeiToken() public { balances[msg.sender] = total; Transfer(0x0, msg.sender, total); } function totalSupply() public view returns (uint256) { return total; } function transfer(address _to, uint _value) whenNotPaused public returns (bool success) { return super.transfer(_to,_value); } function approve(address _spender, uint _value) whenNotPaused public returns (bool success) { return super.approve(_spender,_value); } function airdropToAddresses(address[] addrs, uint256 amount) public { for (uint256 i = 0; i < addrs.length; i++) { transfer(addrs[i], amount); } } }
WeiToken
function WeiToken() public { balances[msg.sender] = total; Transfer(0x0, msg.sender, total); }
// 20 *10^8 HNC total
LineComment
v0.4.20+commit.3155dd80
bzzr://400b98547b5c6d7de276c7b5a34eea6c3c68eaccf77a7c5fa7867f5e6bbfd30d
{ "func_code_index": [ 305, 415 ] }
12,789
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
Strings
library Strings { /** * @dev Converts a `uint256` to its ASCII `string` 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); uint256 index = digits - 1; temp = value; while (temp != 0) { buffer[index--] = byte(uint8(48 + temp % 10)); temp /= 10; } return string(buffer); } }
/** * @dev String operations. */
NatSpecMultiLine
toString
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); uint256 index = digits - 1; temp = value; while (temp != 0) { buffer[index--] = byte(uint8(48 + temp % 10)); temp /= 10; } return string(buffer); }
/** * @dev Converts a `uint256` to its ASCII `string` representation. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 109, 858 ] }
12,790
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
_set
function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } }
/** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 1091, 1788 ] }
12,791
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
_remove
function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } }
/** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 1958, 3512 ] }
12,792
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
_contains
function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; }
/** * @dev Returns true if the key is in the map. O(1). */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 3591, 3721 ] }
12,793
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
_length
function _length(Map storage map) private view returns (uint256) { return map._entries.length; }
/** * @dev Returns the number of key-value pairs in the map. O(1). */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 3811, 3926 ] }
12,794
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
_at
function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); }
/** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 4276, 4560 ] }
12,795
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
_get
function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); }
/** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 4716, 4870 ] }
12,796
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
_get
function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based }
/** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 4978, 5302 ] }
12,797
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
set
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); }
/** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 5621, 5802 ] }
12,798
NFTeGG_Burner
NFTeGG_Burner.sol
0x8409a26de50daad783ac7ac1cf91159c1e8fdf21
Solidity
EnumerableMap
library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry 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. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { return _get(map, key, "EnumerableMap: nonexistent key"); } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint256(value))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key)))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint256(_get(map._inner, bytes32(key), errorMessage))); } }
/** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */
NatSpecMultiLine
remove
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); }
/** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */
NatSpecMultiLine
v0.6.12+commit.27d51765
{ "func_code_index": [ 5963, 6110 ] }
12,799