Untitled
unknown
plain_text
a year ago
4.7 kB
13
Indexable
/**
*Submitted for verification at Etherscan.io on 2024-05-14
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
// File: BlockchainDevelopersale.sol
pragma solidity ^0.8.0;
interface IERC20 {
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
}
contract GuardPreSale {
address public admin;
IERC20 public GuardToken;
uint256 public saleEndTime;
uint256 public totalSold;
AggregatorV3Interface internal ethUsdPriceFeed;
uint256 public tokenPriceForEth = 30;
mapping(address => uint256) public buyAmount;
mapping(address => uint256) public claimableTokens;
event TokensPurchased(
address indexed buyer,
uint256 amount,
uint256 totalPrice
);
event TokensClaimed(address indexed user, uint256 amount);
constructor(
) {
admin = msg.sender;
GuardToken = IERC20(0x9546e108753B5d1F03B0401714747292Bf3dF233);
ethUsdPriceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
saleEndTime = 1726341265;
}
function buyTokensWithEth(uint256 numberOfTokens) external payable {
require(block.timestamp < saleEndTime, " PreSale is end ");
uint256 ethPriceInUSD = getEthPriceInUSD() / 10**8;
uint256 totalPriceInCents = (numberOfTokens * tokenPriceForEth) / 1000;
uint256 totalPriceInWei = (totalPriceInCents * 1 ether) / ethPriceInUSD;
uint256 totalPriceInETH = totalPriceInWei / 10**18;
require(msg.value >= totalPriceInETH, "Insufficient ETH sent");
payable(admin).transfer(msg.value);
buyAmount[msg.sender] = buyAmount[msg.sender] + numberOfTokens;
totalSold = totalSold + numberOfTokens;
claimableTokens[msg.sender] += numberOfTokens;
emit TokensPurchased(msg.sender, numberOfTokens, totalPriceInETH);
}
function gettokensAmountForEth(uint256 ethAmount) view public returns(uint256) {
uint256 ethPriceInUSD = getEthPriceInUSD() / 10**8;
uint256 tokensToSell = (ethAmount * ethPriceInUSD * 1000) / tokenPriceForEth;
return tokensToSell ;
}
modifier onlyAdmin() {
require(msg.sender == admin, "Only admin can call this function");
_;
}
function settokenPriceForETH(uint256 _tokenPriceForEth) external onlyAdmin {
tokenPriceForEth = _tokenPriceForEth;
}
function setEndTime(uint256 _time) external onlyAdmin {
saleEndTime = _time;
}
function getEthPriceInUSD() public view returns (uint256) {
(, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
return uint256(price);
}
function claimTokens() external {
require(block.timestamp > saleEndTime, "ICO has not ended yet");
require(claimableTokens[msg.sender] > 0, "No tokens to claim");
uint256 tokensToClaim = claimableTokens[msg.sender];
claimableTokens[msg.sender] = 0;
require(GuardToken.transfer(msg.sender, tokensToClaim), "Claim token failed");
}
function getClaimableTokens(address user) external view returns (uint256) {
return claimableTokens[user];
}
function withdrawTokens() external onlyAdmin {
uint256 contractBalance = GuardToken.balanceOf(address(this));
require(
GuardToken.transfer(admin, contractBalance),
"Funds withdrawal failed"
);
}
function withdrawETH() external onlyAdmin {
payable(admin).transfer(address(this).balance);
}
function endICO() external onlyAdmin {
require(block.timestamp < saleEndTime, "ICO has already ended");
saleEndTime = block.timestamp; // End ICO immediately
}
}Editor is loading...
Leave a Comment