S Price: $0.613404 (+18.50%)

Contract Diff Checker

Contract Name:
StarterDummies

Contract Source Code:

// File: contracts\openzeppelin\contracts\utils\ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.19;
/**
 * @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * 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;
    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();
    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
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }
        // 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: contracts\openzeppelin\contracts\utils\Context.sol
pragma solidity ^0.8.19;
/**
 * @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: contracts\openzeppelin\contracts\utils\Pausable.sol
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.19;
/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);
    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);
    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();
    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();
    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }
    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }
    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }
    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }
    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }
    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }
    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }
    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
// File: contracts\openzeppelin\contracts\token\ERC20\IERC20.sol
pragma solidity ^0.8.19;
interface IERC20 {
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
// File: contracts\openzeppelin\contracts\access\Ownable.sol
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.19;
/**
 * @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: contracts/Bubble/holding.sol
pragma solidity ^0.8.19;
interface IPairFactory {
    function getPair(address tokenA, address token, bool stable) external view returns (address);
}
struct Route {
    address from;
    address to;
    bool stable;
}
interface IRouter {
    function addLiquidityETH (address token, bool stable, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
    function removeLiquidityETH(address token, bool stable, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline) external returns (uint amountToken, uint amountETH);
    function getAmountsOut(uint amountIn, Route[] memory routes) external view returns (uint[] memory amounts);
    function weth() external view returns (address);
    function factory() external view returns (address);
}
interface IClaimable {
    function claimFees() external returns (uint claimed0, uint claimed1);
    function claimable0 (address holder) external view returns (uint256);
    function claimable1 (address holder) external view returns (uint256);
    function token0() external view returns (address);
    function token1() external view returns (address);
}
contract StarterDummies is ReentrancyGuard, Ownable, Pausable {
    IERC20 public dToken;
    IRouter public equalRouter;
    constructor() Ownable(0x061117bBCeb190f32D52487A391c956F4E9Da459) ReentrancyGuard() Pausable() {
        dToken = IERC20(0x7c7AA1B786477d4b157E6372dFADC78D73eE97F8);
        equalRouter = IRouter(0x7635cD591CFE965bE8beC60Da6eA69b6dcD27e4b);
    }
    struct Stake {
        uint256 liquidity; // LP tokens staked
        uint256 startTime; // When staking started
    }
    mapping(address => Stake) public stakes;
    address[] public stakers;
    
    function removeAddr(address addr) internal {
        uint l = stakers.length;
        if (l>0) {
            for(uint256 i=0; i<l; i++) {
                if (stakers[i] == addr) {
                    stakers[i] = stakers[l - 1];
                    stakers.pop();
                    return;
                }
            }
        }
    }
    event Staked(address indexed user, uint256 tokenAmount, uint256 ethAmount, uint256 liquidity);
    event Unstaked(address indexed user, uint256 ethAmount, uint256 tokenAmount);
    event RedistributeFee(address indexed owner, uint256 amount);
    function start(uint256 prize) public payable onlyOwner {
        dToken.approve(address(equalRouter), type(uint256).max);
        address pool = IPairFactory(equalRouter.factory()).getPair(equalRouter.weth(), address(dToken), false);
        if (pool == address(0))
        {
            uint256 bubbleAmount = msg.value * prize;  //to 2 decimals prize.
            uint256 balEcu = dToken.balanceOf(address(this));
            require(bubbleAmount <= balEcu, "no sufficient ecu");
            // Add liquidity with the remaining ETH and swapped ECU tokens
            (uint256 amountToken, uint256 amountETH, uint256 liquidity) = equalRouter.addLiquidityETH{value: msg.value}(
                address(dToken), false,
                bubbleAmount,
                0, // Accept any amount of tokens
                0, // Accept any amount of ETH
                address(this), // Lock LP tokens in the contract
                block.timestamp + 60
            );
            // Record the stake
            Stake storage userStake = stakes[msg.sender];
            if (userStake.liquidity == 0) {
                stakers.push(msg.sender);
            }
            userStake.liquidity += liquidity;
            userStake.startTime = block.timestamp;
            emit Staked(msg.sender, amountToken, amountETH, liquidity);
        }
    }
    function setPause(bool p) external onlyOwner {
        if (p)
            _pause();
        else
            _unpause();
    }
    function simulateStake(uint256 value) public view returns (uint256) {
        // Path for swapping ETH -> ECU
        Route[] memory path = new Route[](1);
        path[0] = Route(address(equalRouter.weth()), address(dToken), false); // WETH
        uint256[] memory amounts = equalRouter.getAmountsOut(value, path);
        return amounts[1];
    }
    // Stake S and go direct to 100% to add liquidity
    function stake() public payable nonReentrant() whenNotPaused() {
        address pairAddress = IPairFactory(equalRouter.factory()).getPair(equalRouter.weth(), address(dToken), false);
        require(pairAddress != address(0), "Pair not found");
        require(msg.value > 0, "Cannot stake 0 ETH");
        // Path for swapping ETH -> ECU
        Route[] memory path = new Route[](1);
        path[0] = Route(equalRouter.weth(), address(dToken), false); // WETH
        uint256[] memory amounts = equalRouter.getAmountsOut(msg.value, path);
        uint256 bubbleAmount = amounts[1];
        uint256 bal = dToken.balanceOf(address(this));
        require(bubbleAmount <= bal, "no sufficient ecu");
        // Ensure that the contract has approved the router for ECU tokens
        uint256 allowance = dToken.allowance(address(this), address(equalRouter));
        if (allowance < bubbleAmount) {
            dToken.approve(address(equalRouter), bubbleAmount);
        }
        
        // Add liquidity with the remaining ETH and swapped ECU tokens
        (uint256 amountToken, uint256 amountETH, uint256 liquidity) = equalRouter.addLiquidityETH{value: msg.value}(
            address(dToken), false,
            bubbleAmount,
            0, // Accept any amount of tokens
            0, // Accept any amount of ETH
            address(this), // Lock LP tokens in the contract
            block.timestamp + 60
        );
        // Record the stake
        Stake storage userStake = stakes[msg.sender];
        if (userStake.liquidity == 0) {
            stakers.push(msg.sender);
        }
        userStake.liquidity += liquidity;
        userStake.startTime = block.timestamp;
        emit Staked(msg.sender, amountToken, amountETH, liquidity);
    }
    // Unstake and retrieve S
    function unstake() public nonReentrant() whenNotPaused() {
        Stake storage userStake = stakes[msg.sender];
        require(userStake.liquidity > 0, "No staked liquidity");
        uint256 liquidity = userStake.liquidity;
        userStake.liquidity = 0; // Reset stake
        removeAddr(msg.sender);
        address pairAddress = IPairFactory(equalRouter.factory()).getPair(equalRouter.weth(), address(dToken), false);
        require(pairAddress != address(0), "Pair not found");
        uint256 lpBalance = IERC20(pairAddress).balanceOf(address(this));
        require(lpBalance >= liquidity, "Insufficient LP token balance in the contract");
        uint256 allowance = IERC20(pairAddress).allowance(address(this), address(equalRouter));
        if (allowance < lpBalance) {
            IERC20(pairAddress).approve(address(equalRouter), type(uint256).max);
        }
        // Remove liquidity and transfer assets to user
        (uint256 amountToken, uint256 amountETH) = equalRouter.removeLiquidityETH(
            address(dToken), false,
            liquidity,
            0, // Accept any amount of tokens
            0, // Accept any amount of ETH
            address(this), // Send assets to contract
            block.timestamp + 60
        );
        // send eth to sender.
        (bool success,) = payable(msg.sender).call{value: amountETH}("");
        require(success);
        emit Unstaked(msg.sender, amountETH, amountToken);
    }
    function claimable() external view returns (uint256 amount0, uint256 amount1) {
        address pairAddress = IPairFactory(equalRouter.factory()).getPair(equalRouter.weth(), address(dToken), false);
        require(pairAddress != address(0), "Pair not found");
        IClaimable icl = IClaimable(pairAddress);
        amount0 = icl.claimable0(address(this));
        amount1 = icl.claimable1(address(this));
    }
    function redistributeFee() external onlyOwner nonReentrant returns (bool) {
        address pairAddress = IPairFactory(equalRouter.factory()).getPair(equalRouter.weth(), address(dToken), false);
        require(pairAddress != address(0), "Pair not found");
        (uint claimed0, uint claimed1) = IClaimable(pairAddress).claimFees();
        uint claimableVal = (IClaimable(pairAddress).token0() == equalRouter.weth()) ? claimed0 : claimed1;
        require(claimableVal > 0, "claim");
        uint l = stakers.length;
        require (l>0);
        uint256 sumLiqui = 0;
        for(uint256 i=0; i<l; i++) {
            address stker = stakers[i];
            Stake storage userStake = stakes[stker];
            if ((userStake.startTime + 1 days) >= block.timestamp || stker == owner()) {
                sumLiqui += userStake.liquidity;
            }
        }
        if (sumLiqui > 0) {
            for(uint256 i=0; i<l; i++) {
                address stker = stakers[i];
                Stake storage userStake = stakes[stker];
                if ((userStake.startTime + 1 days) >= block.timestamp || stker == owner()) {
                    uint256 sum = claimableVal * userStake.liquidity / sumLiqui;
                    if (sum > 0) {
                        uint256 bal = address(this).balance;
                        require(sum <= bal, "amount to high");
                        (bool success, ) = payable(stker).call{value: sum}("");
                        require(success, "");
                        emit RedistributeFee(stker, sum);
                    }
                }
            }
        }  
        return true;
    }
    
    // Owner withdraws excess Buuble tokens from the contract.
    function withdrawBubble(uint256 amount) external onlyOwner {
        uint256 contractBalance = dToken.balanceOf(address(this));
        require(amount <= contractBalance, "Insufficient ECU balance");
        dToken.transfer(owner(), amount);
    }
    // Normally the bal of this contract must bed "0". but to maintenance.
    function withdraw(uint256 amount) external onlyOwner { 
        uint256 bal = address(this).balance;
        require(amount <= bal, "amount to high");
        (bool success, ) = payable(owner()).call{value: amount}("");
        require(success, "");
    }
    // Receive ETH fallback.
    receive() external payable {}
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):