Iammrjude

presale.sol

Jun 18th, 2021
746
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // SPDX-License-Identifier: MIT
  2.  
  3. pragma solidity >=0.4.22 <0.8.0;
  4.  
  5. contract Context {
  6.     constructor () internal { }
  7.     // solhint-disable-previous-line no-empty-blocks
  8.  
  9.     function _msgSender() internal view returns (address payable) {
  10.         return msg.sender;
  11.     }
  12.  
  13.     function _msgData() internal view returns (bytes memory) {
  14.         this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
  15.         return msg.data;
  16.     }
  17. }
  18.  
  19. interface IERC20 {
  20.     function totalSupply() external view returns (uint);
  21.     function balanceOf(address account) external view returns (uint);
  22.     function transfer(address recipient, uint amount) external returns (bool);
  23.     function allowance(address owner, address spender) external view returns (uint);
  24.     function approve(address spender, uint amount) external returns (bool);
  25.     function transferFrom(address sender, address recipient, uint amount) external returns (bool);
  26.     event Transfer(address indexed from, address indexed to, uint value);
  27.     event Approval(address indexed owner, address indexed spender, uint value);
  28.     function TokensPurchased(address buyer, uint256 amount) external  returns (bool success);
  29.     function burn(uint256 _value) external returns (bool success);
  30. }
  31.  
  32. library SafeMath {
  33.     function add(uint a, uint b) internal pure returns (uint) {
  34.         uint c = a + b;
  35.         require(c >= a, "SafeMath: addition overflow");
  36.  
  37.         return c;
  38.     }
  39.     function sub(uint a, uint b) internal pure returns (uint) {
  40.         return sub(a, b, "SafeMath: subtraction overflow");
  41.     }
  42.     function sub(uint a, uint b, string memory errorMessage) internal pure returns (uint) {
  43.         require(b <= a, errorMessage);
  44.         uint c = a - b;
  45.  
  46.         return c;
  47.     }
  48.     function mul(uint a, uint b) internal pure returns (uint) {
  49.         if (a == 0) {
  50.             return 0;
  51.         }
  52.  
  53.         uint c = a * b;
  54.         require(c / a == b, "SafeMath: multiplication overflow");
  55.  
  56.         return c;
  57.     }
  58.     function div(uint a, uint b) internal pure returns (uint) {
  59.         return div(a, b, "SafeMath: division by zero");
  60.     }
  61.     function div(uint a, uint b, string memory errorMessage) internal pure returns (uint) {
  62.         // Solidity only automatically asserts when dividing by 0
  63.         require(b > 0, errorMessage);
  64.         uint c = a / b;
  65.  
  66.         return c;
  67.     }
  68.     function mod(uint256 a, uint256 b) internal pure returns (uint256) {
  69.         return mod(a, b, "SafeMath: modulo by zero");
  70.     }
  71.  
  72.    
  73.     function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
  74.         require(b != 0, errorMessage);
  75.         return a % b;
  76.     }
  77. }
  78.  
  79. library Address {
  80.     function isContract(address account) internal view returns (bool) {
  81.         bytes32 codehash;
  82.         bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
  83.         // solhint-disable-next-line no-inline-assembly
  84.         assembly { codehash := extcodehash(account) }
  85.         return (codehash != 0x0 && codehash != accountHash);
  86.     }
  87. }
  88.  
  89. library SafeERC20 {
  90.     using SafeMath for uint;
  91.     using Address for address;
  92.  
  93.     function safeTransfer(IERC20 token, address to, uint value) internal {
  94.         callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
  95.     }
  96.  
  97.     function safeTransferFrom(IERC20 token, address from, address to, uint value) internal {
  98.         callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
  99.     }
  100.  
  101.     function safeApprove(IERC20 token, address spender, uint value) internal {
  102.         require((value == 0) || (token.allowance(address(this), spender) == 0),
  103.             "SafeERC20: approve from non-zero to non-zero allowance"
  104.         );
  105.         callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
  106.     }
  107.     function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
  108.         uint256 newAllowance = token.allowance(address(this), spender).add(value);
  109.         callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
  110.     }
  111.  
  112.     function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
  113.         uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
  114.         callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
  115.     }
  116.     function callOptionalReturn(IERC20 token, bytes memory data) private {
  117.         require(address(token).isContract(), "SafeERC20: call to non-contract");
  118.  
  119.         // solhint-disable-next-line avoid-low-level-calls
  120.         (bool success, bytes memory returndata) = address(token).call(data);
  121.         require(success, "SafeERC20: low-level call failed");
  122.  
  123.         if (returndata.length > 0) { // Return data is optional
  124.             // solhint-disable-next-line max-line-length
  125.             require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
  126.         }
  127.     }
  128. }
  129.  
  130. contract ReentrancyGuard {
  131.     bool private _notEntered;
  132.  
  133.     constructor () internal {
  134.        
  135.         _notEntered = true;
  136.     }
  137.  
  138.    
  139.     modifier nonReentrant() {
  140.         // On the first call to nonReentrant, _notEntered will be true
  141.         require(_notEntered, "ReentrancyGuard: reentrant call");
  142.  
  143.         // Any calls to nonReentrant after this point will fail
  144.         _notEntered = false;
  145.  
  146.         _;
  147.  
  148.        
  149.         _notEntered = true;
  150.     }
  151. }
  152.  
  153. contract presale is Context, ReentrancyGuard{
  154.    
  155.     using SafeMath for uint256;
  156.     using SafeERC20 for IERC20;
  157.     address public governance;
  158.    
  159.     uint256 public rate;
  160.     uint256 private _weiRaised;
  161.     uint256 public totalSold;
  162.     IERC20 public tokenAddress;
  163.     //uint256 public startTime = 1607407761; //
  164.     //uint256 public endTime = 1608407761; //
  165.    
  166.     uint256 public minimumBuyAmount = 10 ** 17;
  167.     uint256 public maximumBuyAmount = 2*10**18;
  168.     address payable public walletAddress;
  169.     event TokensPurchased(address indexed to, uint256 amount);
  170.    
  171.     constructor () public {
  172.         governance = tx.origin;
  173.         rate = uint256(50);
  174.         walletAddress = 0xB3fA96b68A4e0C4AC358FE6BeE3620C787651256; //MultiSender 0x383f7CC1124c255b9DD71F8f8A41c08C10480C1a //TEAM Ropsten 0x30D095D6f0043C9030a545A3B7cFAAE738F44de5
  175.         tokenAddress = IERC20(0x0); // AmpleForth 0x0c14d945Df4a2A5606490b363ccA33e3b7043706 //0xf62A0f785C28d18774Df1d07A555A68336a5c16E
  176.     }
  177.    
  178.     function () external payable {
  179.         buy();
  180.     }
  181.    
  182.     function changeWallet (address payable _walletAddress) public {
  183.         require(msg.sender == governance, "!governance");
  184.         walletAddress = _walletAddress;
  185.     }
  186.    
  187.     function setToken(IERC20 _tokenAddress) public {
  188.         require(msg.sender == governance, "!governance");
  189.         tokenAddress = _tokenAddress;
  190.     }
  191.    
  192.     function buy() public payable {
  193.         //require((block.timestamp > startTime ) && (block.timestamp < endTime)  , "D01 Token Crowdsate is not active");
  194.         uint256 weiValue = msg.value;
  195.         IERC20 token = IERC20(tokenAddress);
  196.         require((weiValue >= minimumBuyAmount) &&(weiValue<= maximumBuyAmount), "Minimum amount is 0.1 eth and Maximum amount is 30 Eth");
  197.         uint256 senderBal = token.balanceOf(msg.sender);
  198.         require((senderBal < maximumBuyAmount.mul(rate)), "You can only buy maximum of 30 Eth worth of tokens");
  199.         uint256 amount = weiValue.mul(rate);
  200.         _weiRaised = _weiRaised.add(weiValue);  
  201.         token.safeTransfer(msg.sender, amount);
  202.         walletAddress.transfer(weiValue);
  203.         //require(walletAddress.send(weiValue)); //_fundRaisingWallet.transfer(msg.value);
  204.         //require(token.TokensPurchased(msg.sender, amount));
  205.         totalSold += amount;
  206.         emit TokensPurchased(msg.sender, amount);
  207.     }
  208.    
  209.     function burnUnsold() public {
  210.         require(msg.sender == governance, "!governance");
  211.         //require((block.timestamp > endTime), "D01 Token Crowdsate is still active");
  212.         IERC20 token = IERC20(tokenAddress);
  213.         uint256 amount = token.balanceOf(address(this));
  214.         token.burn(amount);
  215.     }
  216.    
  217. }
  218.  
RAW Paste Data