Verified contractPartialMIT
DEGEN
Address0xec945d8c595600a17a2c986eb6e7ae182b16070f
- Balance
0 ETH
- Transactions
29
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 22,781,069
- Creation transaction
- 0xb9ca2cec7f…db4defa269
DEGEN.sol
// SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/utils/Context.sol
// 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;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
/**
* @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);
}
}
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
// File: ico.sol
pragma solidity 0.8.26;
interface AggregatorV3Interface {
function decimals() external view returns (uint);
function description() external view returns (string memory);
function version() external view returns (uint);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (
uint roundId,
uint answer,
uint startedAt,
uint updatedAt,
uint answeredInRound
);
function latestRoundData()
external
view
returns (
uint roundId,
uint answer,
uint startedAt,
uint updatedAt,
uint answeredInRound
);
}
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
constructor() {
priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); // eth/usdt mainnet
}
function getThePrice() public view returns (uint) {
(
uint roundID,
uint price,
uint startedAt,
uint timeStamp,
uint answeredInRound
) = priceFeed.latestRoundData();
return price;
}
}
contract Ownable1 {
address owner1;
address public owner2;
address public owner3;
constructor() {
owner1 = msg.sender;
owner2 = 0xA947fb060F56370dD49B223f57f08F8dD6E95055;
owner3 = 0xA947fb060F56370dD49B223f57f08F8dD6E95055;
}
modifier onlyOwner1() {
require(msg.sender == owner1 || msg.sender == owner2 || msg.sender == owner3 );
_;
}
}
interface BEP20 {
function totalSupply() external view returns (uint theTotalSupply);
function balanceOf(address _owner) external view returns (uint balance);
function transfer(address _to, uint _value) external ;
function transferFrom(address _from, address _to, uint _value) external ;
function approve(address _spender, uint _value) external returns (bool success);
function allowance(address _owner, address _spender) external view returns (uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
interface ERC20 {
function totalSupply() external view returns (uint theTotalSupply);
function balanceOf(address _owner) external view returns (uint balance);
function transfer(address _to, uint _value) external returns (bool success);
function transferFrom(address _from, address _to, uint _value) external returns (bool success);
function approve(address _spender, uint _value) external returns (bool success);
function allowance(address _owner, address _spender) external view returns (uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
contract DEGEN is Ownable , Ownable1, ReentrancyGuard {
PriceConsumerV3 priceConsumerV3 = new PriceConsumerV3();
uint public priceOfETH = priceConsumerV3.getThePrice();
struct Deposit {
uint tariff;
uint amount;
uint tokenAmount;
uint at;
}
struct Investor {
Deposit[] deposits;
uint invested;
}
struct TokenPurchase {
address buyer;
uint amount;
uint timestamp;
uint amountType ; // 0 = ETH , 1 =token
}
TokenPurchase[] public allTokenPurchases;
// MainNet
address public usdt = 0xdAC17F958D2ee523a2206206994597C13D831ec7; //USDT MainNet
address public usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; // USDC MainNet
uint public tokenPrice;
uint public tokenPriceDecimal;
uint public totalInvested;
address payable public FundAddr ;
mapping (address => Investor) public investors;
mapping(address => TokenPurchase[]) public tokenPurchases;
event DepositAt(address user, uint tariff, uint amount);
event Withdraw(address user, uint amount);
constructor(address payable _Fund) Ownable(msg.sender) {
FundAddr = _Fund;
tokenPrice = 69;
tokenPriceDecimal = 4;
}
function buyTokenWithETH(address payable _to) external payable nonReentrant {
uint tariff = 0;
require(msg.value >= 0);
priceOfETH = priceConsumerV3.getThePrice();
uint tokenVal = (msg.value * priceOfETH * 10**tokenPriceDecimal) / (tokenPrice * 100000000);
if (isContract(_to)) {
(bool success, ) = _to.call{value: msg.value}("");
require(success, "Transfer to contract failed");
} else {
_to.transfer(msg.value);
}
investors[msg.sender].invested += tokenVal;
investors[msg.sender].deposits.push(Deposit(tariff, msg.value, tokenVal, block.timestamp));
allTokenPurchases.push(TokenPurchase(msg.sender, msg.value, block.timestamp, 0));
emit DepositAt(msg.sender, tariff, tokenVal);
}
function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
function buyWithToken(uint amount,uint investToken) external nonReentrant {
require(investToken==1 || investToken==2 , "invalid Token");
address duductToken = usdt;
address duductTokens = usdc;
if(investToken==1){
duductToken = usdt;
BEP20 receiveToken = BEP20(duductToken);
require(receiveToken.balanceOf(msg.sender) >= amount, "Insufficient user balance");
receiveToken.transferFrom(msg.sender, FundAddr, amount);
}
else {
duductTokens = usdc;
ERC20 receiveTokens = ERC20(duductTokens);
require(receiveTokens.balanceOf(msg.sender) >= amount, "Insufficient user balance");
require(receiveTokens.transferFrom(msg.sender, FundAddr, amount), "Transfer failed");
}
uint tokenVal = (amount* 10**tokenPriceDecimal) / tokenPrice ;
investors[msg.sender].invested += tokenVal;
investors[msg.sender].deposits.push(Deposit(investToken,amount,tokenVal,block.timestamp));
allTokenPurchases.push(TokenPurchase(msg.sender, amount, block.timestamp, investToken));
emit DepositAt(msg.sender, investToken, tokenVal);
}
function setBuyPrice(uint8 _price, uint8 _decimal) public nonReentrant {
require(msg.sender == owner1 || msg.sender == owner2 || msg.sender == owner3 , "Only Owner1 or Owner2 or Owner3" );
require(_price > 0, "Price must be greater than 0");
require(_decimal >= 0, "Decimal must be 0 or greater");
tokenPrice = _price;
tokenPriceDecimal = _decimal;
}
function updateFundAddress(address payable _newaddr) public onlyOwner nonReentrant {
FundAddr = _newaddr;
}
// Owner ETH Withdraw
// Only owner can withdraw ETH
function withdrawETH(address payable to, uint amount) public onlyOwner nonReentrant returns(bool) {
require(to != address(0), "Cannot send to zero address");
to.transfer(amount);
return true;
}
function usd_price() public view returns (uint) {
return priceOfETH;
}
function tokenInETH(uint amount) public view returns (uint) {
uint tokenVal = (amount * priceOfETH* 10**tokenPriceDecimal) /(tokenPrice*100000000*1000000000000000000) ;
return (tokenVal);
}
// Only owner can withdraw token
function withdrawToken(address tokenAddress, address to, uint amount) public onlyOwner nonReentrant returns(bool) {
require(to != address(0), "Cannot send to zero address");
BEP20 _token = BEP20(tokenAddress);
_token.transfer(to, amount);
return true;
}
// View details
function userDeposits(address indexAddress) public view returns (uint[] memory tariffs,uint[] memory amounts,uint[] memory getTokens, uint[] memory times) {
uint len = investors[indexAddress].deposits.length;
tariffs = new uint[](len);
amounts = new uint[](len);
getTokens = new uint[](len);
times = new uint[](len);
for(uint i = 0; i <len; i++){
tariffs[i] = investors[indexAddress].deposits[i].tariff;
amounts[i] = investors[indexAddress].deposits[i].amount;
getTokens[i] = investors[indexAddress].deposits[i].tokenAmount;
times[i] = investors[indexAddress].deposits[i].at;
}
return (tariffs, amounts, getTokens, times);
}
function allPrice() public view returns (uint ,uint ,uint,uint,uint,uint,uint) {
return (priceOfETH, tokenPrice, tokenPriceDecimal,0,8 ,0,0);
}
function getAllTokenPurchases() public view returns (TokenPurchase[] memory) {
return allTokenPurchases;
}
function updateowner2(address _newaddress) public onlyOwner nonReentrant {
require(_newaddress != address(0), "New owner cannot be zero address");
require(_newaddress != owner2, "This address is already set as owner2");
owner2 = _newaddress;
}
function updateowner3(address _newaddress) public onlyOwner nonReentrant {
require(_newaddress != address(0), "New owner cannot be zero address");
require(_newaddress != owner2, "This address is already set as owner2");
owner3 = _newaddress;
}
receive() external payable {
FundAddr.transfer(msg.value);
}
}Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.