ETH Price: $1,972.37 (-0.60%)

Contract Diff Checker

Contract Name:
WithdrawManager

Contract Source Code:

File 1 of 1 : WithdrawManager

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.7.4;

interface IExistingContract {
    function StakedPabloTokens(address staker) external view returns(uint256);
}

interface IERC20 {
    function transfer(address recipient, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}

contract Owned {
    address payable public owner;

    event OwnershipTransferred(address indexed _from, address indexed _to);

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    function transferOwnership(address payable _newOwner) public onlyOwner {
        require(_newOwner != address(0), "ERC20: sending to the zero address");
        owner = _newOwner;
        emit OwnershipTransferred(msg.sender, _newOwner);
    }
}

contract WithdrawManager is Owned {
    IExistingContract public existingContract;
    IERC20 public tokenContract;
    mapping(address => bool) public hasWithdrawn;
    mapping(address => uint256) public withdrawnAmounts; // Tracks how much each user has withdrawn.
    bool public breaker = false; //  unlocked

    event WithdrawCompleted(address indexed user, uint256 amount);

    constructor(address _existingContractAddress, address _tokenContractAddress) {
        require(_existingContractAddress != address(0), "Invalid existing contract address");
        require(_tokenContractAddress != address(0), "Invalid token contract address");
        existingContract = IExistingContract(_existingContractAddress);
        tokenContract = IERC20(_tokenContractAddress);
    }

    function withdraw() external {
        require(breaker == false, "Admin Restricted WITHDRAW");
        require(!hasWithdrawn[msg.sender], "Withdrawal already made");

        uint256 stakedAmount = existingContract.StakedPabloTokens(msg.sender);
        require(stakedAmount > 0, "No staked tokens found");
        require(tokenContract.balanceOf(address(this)) >= stakedAmount, "Insufficient tokens in contract for withdrawal");

        hasWithdrawn[msg.sender] = true;
        withdrawnAmounts[msg.sender] += stakedAmount; // Update the withdrawn amount.

        require(tokenContract.transfer(msg.sender, stakedAmount), "Failed to transfer tokens");

        emit WithdrawCompleted(msg.sender, stakedAmount);
    }

    // Function to deposit ERC20 tokens into this contract for withdrawals.
    function depositTokens(uint256 amount, address from) external {
        require(tokenContract.transferFrom(from, address(this), amount), "Failed to deposit tokens");
    }

    function addAlreadyWithdrawn(address _staker) external onlyOwner{
        require(_staker != address(0), "Zero Address");
        hasWithdrawn[_staker] = true;
    }

    function setBreaker(bool _breaker) external onlyOwner {
        breaker = _breaker;
    }

    function saveEmergencyTokens(address tokenAddress) external onlyOwner {
        IERC20 token = IERC20(tokenAddress);
        uint256 tokenBalance = token.balanceOf(address(this));
        token.transfer(owner, tokenBalance);
    }

    // Function to withdraw ETH sent to the contract by mistake
    function saveETH() external onlyOwner {
        payable(owner).transfer(address(this).balance);
    }
}

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

Context size (optional):