Проверенный контрактТочноеMIT
ICO
Адрес0x7bd401b87529db9a34d93ff94cd8b048f9303e89
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.28
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.28+commit.7893614a
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- paris
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 23 769 147
- Транзакция создания
- 0x0beb70c1a2…09e346f1e5
11 файлов
- contracts/ICO.solглавный21,64 КБ
- @openzeppelin/contracts/access/Ownable.sol3,1 КБ
- @openzeppelin/contracts/proxy/utils/Initializable.sol8,91 КБ
- @openzeppelin/contracts/token/ERC20/IERC20.sol2,78 КБ
- @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol683 Б
- @openzeppelin/contracts/utils/Context.sol963 Б
- contracts/interfaces/IICO.sol950 Б
- contracts/interfaces/IVesting.sol438 Б
- contracts/interfaces/OracleWrapper.sol147 Б
- contracts/libraries/TransferHelper.sol1,89 КБ
- contracts/utils/ReentrancyGuard.sol2,6 КБ
contracts/ICO.sol
//SPDX-License-Identifier: MIT
pragma solidity =0.8.28;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "./interfaces/IICO.sol";
import "./interfaces/IVesting.sol";
import "./utils/ReentrancyGuard.sol";
import "./libraries/TransferHelper.sol";
import "./interfaces/OracleWrapper.sol";
contract ICO is Ownable, Initializable, ReentrancyGuard, IICO {
uint256 public tokensToBeSold;
uint256 public totalTokenSold;
uint256 public totalUSDRaised;
uint256 public tokenDecimal;
uint256 private counter;
uint32 public referralPercentage;
uint8 public defaultPhase;
uint8 public totalPhases;
address public receiverAddress;
/* ================ STRUCT SECTION ================ */
/* Stores phases */
struct Phases {
uint256 tokenSold;
uint256 tokenLimit;
uint32 startTime;
uint32 expirationTimestamp;
uint32 price /* 10 ** 8 */;
uint32 percentage;
bool isComplete;
}
struct ReferralEarned {
uint256 amountInHaven;
uint256 amountInUSD;
}
mapping(uint256 => Phases) public phaseInfo;
mapping(bytes => address) public referralCodeToUserMapping;
mapping(address => address) public userToParentMapping;
mapping(address => bytes) public UserToReferralCodeMapping;
mapping(address => ReferralEarned) public userReferralEarnedMapping;
IERC20Metadata public tokenInstance; /* Lumen token instance */
IERC20Metadata public usdtInstance; /* USDT token instance */
IERC20Metadata public usdcInstance; /* USDC token instance */
IVesting public vestingInstance;
OracleWrapper public USDTOracle;
OracleWrapper public USDCOracle;
OracleWrapper public ETHOracle;
/* ================ CONSTRUCTOR SECTION ================ */
constructor() Ownable(msg.sender) {}
function initialize(
address _tokenAddress,
address _vestingAddress,
address _usdtToken,
address _usdcToken,
address _owner
) external initializer {
receiverAddress = 0x30E66Ab36BadfaE5c12373A634B8054129eaE4dA;
USDTOracle = OracleWrapper(0x3E7d1eAB13ad0104d2750B8863b489D65364e32D);
USDCOracle = OracleWrapper(0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6);
ETHOracle = OracleWrapper(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
tokenInstance = IERC20Metadata(_tokenAddress);
usdtInstance = IERC20Metadata(_usdtToken);
usdcInstance = IERC20Metadata(_usdcToken);
vestingInstance = IVesting(_vestingAddress);
totalPhases = 9;
defaultPhase = 1;
tokenDecimal = uint256(10 ** tokenInstance.decimals());
tokensToBeSold = 400_000_000 * tokenDecimal;
referralPercentage = 2; // 0.02%
uint32 currentTime = uint32(block.timestamp);
phaseInfo[1] = Phases({
tokenLimit: 200_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 30 minutes, // 1/8/2025
expirationTimestamp: currentTime + 90 minutes, // 31/10/2025
price: 5000000 /* 0.05 */,
percentage: 0,
isComplete: false
});
phaseInfo[2] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 90 minutes, // 1/11/2025
expirationTimestamp: currentTime + 120 minutes, // 28/2/2026
price: 6000000 /* 0.06 */,
percentage: 1000,
isComplete: false
});
phaseInfo[3] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 120 minutes, // 1/3/2026
expirationTimestamp: currentTime + 180 minutes, // 30/6/2026
price: 6500000 /* 0.065 */,
percentage: 1000,
isComplete: false
});
phaseInfo[4] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 180 minutes, // 1/3/2026
expirationTimestamp: currentTime + 240 minutes, // 30/6/2026
price: 7000000 /* 0.07 */,
percentage: 1000,
isComplete: false
});
phaseInfo[5] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 240 minutes, // 1/3/2026
expirationTimestamp: currentTime + 300 minutes, // 30/6/2026
price: 7500000 /* 0.075 */,
percentage: 1000,
isComplete: false
});
phaseInfo[6] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 300 minutes, // 1/3/2026
expirationTimestamp: currentTime + 360 minutes, // 30/6/2026
price: 8000000 /* 0.08 */,
percentage: 1000,
isComplete: false
});
phaseInfo[7] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 360 minutes, // 1/3/2026
expirationTimestamp: currentTime + 420 minutes, // 30/6/2026
price: 8500000 /* 0.085 */,
percentage: 1000,
isComplete: false
});
phaseInfo[8] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 420 minutes, // 1/3/2026
expirationTimestamp: currentTime + 480 minutes, // 30/6/2026
price: 9000000 /* 0.09 */,
percentage: 1000,
isComplete: false
});
phaseInfo[9] = Phases({
tokenLimit: 25_000_000 * tokenDecimal,
tokenSold: 0,
startTime: currentTime + 480 minutes, // 1/3/2026
expirationTimestamp: currentTime + 540 minutes, // 30/6/2026
price: 9500000 /* 0.095 */,
percentage: 1000,
isComplete: false
});
_transferOwnership(_owner);
}
/* ================ BUYING TOKENS SECTION ================ */
/* Receive Function */
receive() external payable {
/* Sending deposited currency to the receiver address */
TransferHelper.safeTransferETH(receiverAddress, msg.value);
}
/** Function lets user buy ALTR tokens || Type 1 = BNB or ETH,
* Type = 2 for USDT,
* Type = 3 for USDC
*/
function buyTokens(
uint256 _usdtAmount,
uint8 _type,
bytes calldata _referralCode
) external payable override nonReentrant {
uint8 _phase = getCurrentPhase();
require(
block.timestamp >= phaseInfo[_phase].startTime,
"Phase has not started yet."
);
require(
block.timestamp < phaseInfo[(totalPhases)].expirationTimestamp,
"Buying phases are over."
);
uint256 _buyAmount;
IERC20Metadata _instance;
/* If type == 1 */
if (_type == 1) {
_buyAmount = msg.value;
}
/* If type == 2 */
else {
_buyAmount = _usdtAmount;
_instance = _type == 2 ? usdtInstance : usdcInstance;
/* Balance Check */
require(
_instance.balanceOf(_msgSender()) >= _buyAmount,
"User doesn't have enough balance."
);
/* Allowance Check */
require(
_instance.allowance(_msgSender(), address(this)) >= _buyAmount,
"Allowance provided is low."
);
}
require(_buyAmount > 0, "Please enter value more than 0.");
/* Token calculation */
(
uint256 _tokenAmount,
uint256 _amountToUSD,
uint8 _phaseNo
) = calculateTokens(_buyAmount, 0, defaultPhase, _type);
/* Setup for vesting in vesting contract */
require(_tokenAmount > 0, "Token amount should be more then zero.");
/* Phase info setting */
setPhaseInfo(_tokenAmount, defaultPhase);
/* Update Phase number and add token amount */
defaultPhase = _phaseNo;
totalTokenSold += _tokenAmount;
totalUSDRaised += _amountToUSD;
uint256 _amountToTransfer = ((_tokenAmount *
phaseInfo[_phaseNo].percentage) / 10000);
ReferralDetails memory _referralDetails = setUpReferrals(
_tokenAmount,
_amountToTransfer,
_phaseNo,
_msgSender(),
_referralCode
);
if (_type == 1) {
/* Sending deposited currency to the receiver address */
TransferHelper.safeTransferETH(receiverAddress, _buyAmount);
} else {
/* Sending deposited currency to the receiver address */
TransferHelper.safeTransferFrom(
address(_instance),
_msgSender(),
receiverAddress,
_buyAmount
);
}
if (_amountToTransfer > 0) {
TransferHelper.safeTransfer(
address(tokenInstance),
_msgSender(),
_amountToTransfer
);
}
{
/* Emits event */
BuyTokenDetails memory _details = BuyTokenDetails({
buyAmount: _buyAmount,
tokenAmount: _tokenAmount,
amountToTransfer: _amountToTransfer,
amountToVesting: _tokenAmount - _amountToTransfer,
amountToUSD: _amountToUSD,
timestamp: uint32(block.timestamp),
buyType: _type,
phaseNo: _phaseNo,
userAddress: _msgSender()
});
emit TokenBought(_details, _referralDetails);
}
}
function setUpReferrals(
uint256 _tokenAmount,
uint256 _amountToTransfer,
uint8 _phaseNo,
address _userAddress,
bytes calldata _referralCode
) internal returns (ReferralDetails memory _referralDetails) {
uint256 _referralAmountInHaven;
uint256 _referralAmountInUSD;
address _referralUser;
bytes memory _perentReferralCode;
if (_phaseNo > 1) {
if (
_referralCode.length > 0 &&
UserToReferralCodeMapping[_userAddress].length == 0
) {
require(
referralCodeToUserMapping[_referralCode] != address(0),
"Please use a valid referal code."
);
_referralUser = referralCodeToUserMapping[_referralCode];
userToParentMapping[_userAddress] = _referralUser;
}
if (userToParentMapping[_userAddress] != address(0)) {
_referralUser = userToParentMapping[_userAddress];
uint256 _referralAmount = ((_tokenAmount * referralPercentage) /
10000);
_referralAmountInHaven = _referralAmount / 2;
Phases memory pInfo = phaseInfo[_phaseNo];
_referralAmountInUSD = getUsdAmount(
(_referralAmount - _referralAmountInHaven),
pInfo.price
);
userReferralEarnedMapping[_referralUser]
.amountInHaven += _referralAmountInHaven;
userReferralEarnedMapping[_referralUser]
.amountInUSD += _referralAmountInUSD;
_perentReferralCode = UserToReferralCodeMapping[_referralUser];
}
if (UserToReferralCodeMapping[_userAddress].length == 0) {
bytes memory _userReferralCode = randomBytes();
UserToReferralCodeMapping[_userAddress] = _userReferralCode;
referralCodeToUserMapping[_userReferralCode] = _userAddress;
emit ReferralCodeGenerated(_msgSender(), _userReferralCode);
}
_referralDetails = ReferralDetails({
referralAmountInHaven: _referralAmountInHaven,
referralAmountInUSD: _referralAmountInUSD,
referredBy: _referralUser,
parentReferralCode: _perentReferralCode
});
}
vestingInstance.registerUser(
_tokenAmount - _amountToTransfer,
_phaseNo == 1 ? 1 : 2,
_msgSender()
);
TransferHelper.safeTransfer(
address(tokenInstance),
address(vestingInstance),
_tokenAmount - _amountToTransfer
);
}
function generateReferralCode() external {
bytes memory _referralCode = UserToReferralCodeMapping[_msgSender()];
require(_referralCode.length == 0, "User already has a referral code.");
bytes memory randomWord = randomBytes();
UserToReferralCodeMapping[_msgSender()] = randomWord;
referralCodeToUserMapping[randomWord] = _msgSender();
emit ReferralCodeGenerated(_msgSender(), randomWord);
}
function randomBytes() internal returns (bytes memory referralCode) {
bytes memory randomWord = new bytes(6);
// since we have 36 letters
bytes memory chars = new bytes(36);
chars = "abcdefghijklmnopqrstuvwxyz0123456789";
for (uint i = 0; i < 6; i++) {
uint randomNumber = random();
// Index access for string is not possible
randomWord[i] = chars[randomNumber];
}
// randomWord = "a3f5h6";
if (referralCodeToUserMapping[bytes(randomWord)] == address(0)) {
return bytes(randomWord);
} else {
randomBytes();
}
}
function random() internal returns (uint) {
counter++;
return
uint(
keccak256(
abi.encodePacked(
block.timestamp,
block.prevrandao,
msg.sender,
counter
)
)
) % 36;
}
function getCurrentPhase() public view returns (uint8) {
uint8 phase;
for (uint8 i = defaultPhase; i <= totalPhases; i++) {
if (
block.timestamp >= phaseInfo[i].startTime &&
block.timestamp < phaseInfo[i].expirationTimestamp
) {
phase = i;
break;
} else if (block.timestamp < phaseInfo[i].startTime) {
phase = i;
break;
}
}
return phase;
}
/* Internal function to calculate tokens */
// _types 1 == ETH, 2 == USDT, 3 == USDC
function calculateTokens(
uint256 _amount,
uint256 _previousTokens,
uint8 _phaseNo,
uint8 _buyType
) public view returns (uint256, uint256, uint8) {
(uint256 _usdAmount, uint256 _typeDecimal) = cryptoValues(_buyType);
_amount =
(_amount * _usdAmount * (10 ** 8)) /
(_typeDecimal * (10 ** 8));
(uint256 _tokenAmount, uint8 _newPhaseNo) = _calculateTokens(
_amount,
_previousTokens,
0,
_phaseNo
);
return (_tokenAmount, _amount, _newPhaseNo);
}
function _calculateTokens(
uint256 _amount,
uint256 _previousTokens,
uint256 _previousPhaseTokens,
uint8 _phaseNo
) internal view returns (uint256, uint8) {
/* Phases cannot exceed totalPhases */
require(_phaseNo <= totalPhases, "Not enough tokens in the ICO.");
Phases memory pInfo = phaseInfo[_phaseNo];
if (_phaseNo == totalPhases) {
require(
pInfo.expirationTimestamp >= uint32(block.timestamp),
"ICO is Ended."
);
}
if (pInfo.expirationTimestamp > uint32(block.timestamp)) {
uint256 _tokensAmount = tokensUserWillGet(_amount, pInfo.price);
uint256 _tokensLeftToSell = (pInfo.tokenLimit +
_previousPhaseTokens) - pInfo.tokenSold;
if (_tokensLeftToSell >= _tokensAmount) {
return (_tokensAmount + _previousTokens, _phaseNo);
}
/* In case the phase is expired. New will begin after sending the left tokens to the next phase */
else {
if (_phaseNo == 1) {
revert("Not enough tokens in private sale.");
} else {
uint256 _remainingTokens = _tokensAmount -
_tokensLeftToSell;
_previousTokens += _tokensLeftToSell;
uint256 _remainingUsdAmount = getUsdAmount(
_remainingTokens,
pInfo.price
);
return
_calculateTokens(
_remainingUsdAmount,
_previousTokens,
0,
_phaseNo + 1
);
}
}
} else {
_previousPhaseTokens += (pInfo.tokenLimit - pInfo.tokenSold);
return
_calculateTokens(
_amount,
_previousTokens,
_previousPhaseTokens,
_phaseNo + 1
);
}
}
function getUsdAmount(
uint256 _remainingTokens,
uint32 _phasePrice
) internal view returns (uint256 _remainingUsdAmount) {
return ((_remainingTokens * _phasePrice * (10 ** 18) * (10 ** 8)) /
(tokenDecimal * (10 ** 18) * (10 ** 8)));
}
/* Tokens user will get according to the price */
function tokensUserWillGet(
uint256 _amount,
uint32 _price
) internal view returns (uint256) {
return ((_amount * tokenDecimal * (10 ** 8)) /
((10 ** 8) * uint256(_price)));
}
/* Returns the crypto values used */
function cryptoValues(
uint8 _type
) internal view returns (uint256, uint256) {
uint256 _amountToUSD;
uint256 _typeDecimal;
if (_type == 1) {
_amountToUSD = ETHOracle.latestAnswer();
_typeDecimal = 10 ** 18;
} else if (_type == 2) {
_amountToUSD = USDTOracle.latestAnswer();
_typeDecimal = uint256(10 ** usdtInstance.decimals());
} else {
_amountToUSD = USDCOracle.latestAnswer();
_typeDecimal = uint256(10 ** usdcInstance.decimals());
}
return (_amountToUSD, _typeDecimal);
}
/* Sets phase info according to the tokens bought */
function setPhaseInfo(uint256 _tokensUserWillGet, uint8 _phaseNo) internal {
require(_phaseNo <= totalPhases, "All tokens have been exhausted.");
Phases storage pInfo = phaseInfo[_phaseNo];
if (block.timestamp < pInfo.expirationTimestamp) {
/* when phase has more tokens than reuired */
if ((pInfo.tokenLimit - pInfo.tokenSold) > _tokensUserWillGet) {
pInfo.tokenSold += _tokensUserWillGet;
}
/* when phase has equal tokens as reuired */
else if (
(pInfo.tokenLimit - pInfo.tokenSold) == _tokensUserWillGet
) {
pInfo.tokenSold = pInfo.tokenLimit;
pInfo.expirationTimestamp = uint32(block.timestamp);
pInfo.isComplete = true;
phaseInfo[_phaseNo + 1].startTime = uint32(block.timestamp);
}
/* when tokens required are more than left tokens in phase */
else {
_tokensUserWillGet -= (pInfo.tokenLimit - pInfo.tokenSold);
pInfo.tokenSold = pInfo.tokenLimit;
pInfo.expirationTimestamp = uint32(block.timestamp);
pInfo.isComplete = true;
phaseInfo[_phaseNo + 1].startTime = uint32(block.timestamp);
setPhaseInfo(_tokensUserWillGet, _phaseNo + 1);
}
}
/* if tokens left in phase afterb completion of expiration time */
else {
uint256 remainingTokens = pInfo.tokenLimit - pInfo.tokenSold;
pInfo.tokenLimit = pInfo.tokenSold;
pInfo.isComplete = true;
phaseInfo[_phaseNo + 1].tokenLimit += remainingTokens;
setPhaseInfo(_tokensUserWillGet, _phaseNo + 1);
}
}
function sendLeftoverTokens() external onlyOwner {
require(
phaseInfo[totalPhases].expirationTimestamp < block.timestamp,
"ICO is not over yet."
);
uint256 _balance = (tokensToBeSold - totalTokenSold);
require(_balance > 0, "No tokens left to send.");
TransferHelper.safeTransfer(
address(tokenInstance),
receiverAddress,
_balance
);
}
/* ================ OTHER FUNCTIONS SECTION ================ */
/* Updates Receiver Address */
function updateReceiverAddress(
address _receiverAddress
) external onlyOwner {
require(_receiverAddress != address(0), "Zero address passed.");
address _oldReceiverAddress = receiverAddress;
receiverAddress = _receiverAddress;
emit UpdateReceiverAddress(_oldReceiverAddress, receiverAddress);
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
contracts/interfaces/IICO.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IICO {
struct BuyTokenDetails {
uint256 buyAmount;
uint256 tokenAmount;
uint256 amountToTransfer;
uint256 amountToVesting;
uint256 amountToUSD;
uint32 timestamp;
uint8 buyType;
uint8 phaseNo;
address userAddress;
}
struct ReferralDetails {
uint256 referralAmountInHaven;
uint256 referralAmountInUSD;
address referredBy;
bytes parentReferralCode;
}
event TokenBought(
BuyTokenDetails buyTokenDetail,
ReferralDetails referralDetails
);
event ReferralCodeGenerated(address userAddress, bytes referralCode);
event UpdateReceiverAddress(address oldReceiverAddress, address newReceiverAddress);
function buyTokens(
uint256 _usdtAmount,
uint8 _type,
bytes calldata _referralCode
) external payable;
}
contracts/interfaces/IVesting.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IVesting {
event RegisterUser(uint256 totalTokens, address userAddress, uint8 choice);
event ClaimedToken(
address userAddress,
uint256 claimedAmount,
uint32 timestamp,
uint8 claimCount,
uint8 choice
);
function registerUser(
uint256 _amount,
uint8 _choice,
address _to
) external;
}
contracts/interfaces/OracleWrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.8.28;
interface OracleWrapper {
function latestAnswer() external view returns (uint256);
}
contracts/libraries/TransferHelper.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.8.28;
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x095ea7b3, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper::safeApprove: approve failed"
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0xa9059cbb, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper::safeTransfer: transfer failed"
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x23b872dd, from, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper::transferFrom: transferFrom failed"
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(
success,
"TransferHelper::safeTransferETH: ETH transfer failed"
);
}
}contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.8.28;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
Настройки компилятораПоказать
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.