// Contract: EquivalenceTokenWrapper
// Target function: function wrapEQT(uint256 amount) external
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

interface IERC20 {
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
    }
interface EquivalenceProtocol {
    function externalMint(address _addr, uint256 amount) external;
    function burnFrom(address account, uint256 amount) external;
    }





//********************************************************************************************
//***********************      HERE STARTS THE CODE OF CONTRACT     **************************
//********************************************************************************************

contract EquivalenceTokenWrapper {

// simplified version of ownable (to save gas)
    address private _owner;
    constructor() {_owner = msg.sender;}
    modifier onlyOwner() {require(_owner == msg.sender, "Ownable: caller is not the owner"); _;}

// variables
    EquivalenceProtocol public EQT;
    IERC20 public WEQT;
    bool public EQTaddressLocked = false;
    bool public WEQTaddressLocked = false;
    uint256 public RequiredUnlockTime = 7776000; // 90 days in seconds
    uint256 internal timestamp = 0;
    error Locked();
    error Amount_Too_High();

// onlyOwner functions
    function setEQT(EquivalenceProtocol _addr) external onlyOwner {if (EQTaddressLocked) {revert Locked();} else {EQT = _addr;}}
    function lockEQTaddress(bool confirm) external onlyOwner {if (confirm) {EQTaddressLocked = true;}}
    function setWEQT(IERC20 _addr) external onlyOwner {if (WEQTaddressLocked) {revert Locked();} else {WEQT = _addr;}}
    function lockWEQTaddress(bool confirm) external onlyOwner {if (confirm) {WEQTaddressLocked = true;}}
    function lock() external onlyOwner {timestamp = 0;}
    function unlock() external onlyOwner {timestamp = block.timestamp;}
    function Withdraw_WEQT(uint256 amount) external onlyOwner {
        if ((timestamp == 0) || (timestamp + RequiredUnlockTime >= block.timestamp)) {revert Locked();}
        WEQT.transfer(_owner, amount);
    }

// view functions
    function checkRemainingLockTime() external view returns (string memory status, uint256 time) {
        if (timestamp == 0) {return ("locked", 99999999999);}
        else if ((block.timestamp - timestamp) >= RequiredUnlockTime) {return ("unlocked", 0);}
        else {return ("unlocking", (RequiredUnlockTime - (block.timestamp - timestamp)));}
    }