// File: @openzeppelin/contracts/access/Ownable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../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.
 *
 * By default, the owner account will be the one that deploys the contract. 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;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @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 {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing 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 {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _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



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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;
    }
}

// File: @openzeppelin/contracts/token/ERC20/IERC20.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount
    ) external returns (bool);
}

// File: @openzeppelin/contracts/utils/Context.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @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;
    }
}

// File: contracts/streetmachine/interfaces/IERC20BackwardsCompatible.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.5.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20BackwardsCompatible {
    /**
     * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` 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 amount) external;

    /**
     * @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 `amount` 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 amount) external;

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount
    ) external;
}
// File: contracts/streetmachine/SMVesting.sol





// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./interfaces/IERC20BackwardsCompatible.sol";

contract SMVesting is Ownable, ReentrancyGuard {
    address public immutable SMC;
    IERC20 public immutable smc;
    address public immutable SLP;
    IERC20 public immutable slp;

    mapping (address => uint256) public ethAmount;
    mapping (address => mapping (uint256 => bool)) public claims;
    mapping (address => uint256) public claimedTokens;
    mapping (address => uint256) public claimedLpTokens;
    uint256 public ethTotal = 84_000_000 ether;
    uint256 public start;
    uint256 public slpTotal;

    constructor (address _SMC, address _SLP) {
        SMC = _SMC;
        smc = IERC20(_SMC);
        SLP = _SLP;
        slp = IERC20(_SLP);

        //PRESALERS
        ethAmount[0xD18B0c6eFef33DaD909eC86D6e18eBf292836c72] = 139485.43616457 ether;
        ethAmount[0x96d5F564D347496f3217c2649599Bef3a1AD59Bc] = 1046140.77123428 ether;
        ethAmount[0x708F2D42c28659eEB32A6b091300079DE5Da762A] = 348713.590411425 ether;
        ethAmount[0x949710D6fF4D3D8030694b5582126Bad57250066] = 697427.18082285 ether;
        ethAmount[0xE4e11BfD7CE95036582CD7a86F6DabF54AB900f9] = 383584.949452568 ether;
        ethAmount[0xb7f64cd4A7cf08325b411A36Ee7ADd648E0B4752] = 348713.590411425 ether;
        ethAmount[0xCbA5dFee5A80aE669B97cD35E92641bE7B684D87] = 697427.18082285 ether;
        ethAmount[0x502452a508546016d35bd0381972B0833b8243ff] = 697427.18082285 ether;
        ethAmount[0x8B0ed17D29693b515ae216dc04583Ae936dC261c] = 209228.154246855 ether;
        ethAmount[0x610188A80d2659EDE5d68bD32b9cA8cDe47539FA] = 174356.795205713 ether;
        ethAmount[0x877b3E08682d1E131dBeAB76B2CDDc2cD4c03224] = 87178.3976028563 ether;
        ethAmount[0x8f3652E9E6fbb9CF49D21d203a11A1F33BbD447d] = 453327.667534853 ether;
        ethAmount[0xB26c2511f02025c3002962c0E0eaC7c5bC50D2bB] = 1046140.77123428 ether;
        ethAmount[0xC1bb5cBe54071f43cC7f96c5D0c7C82b6852Af35] = 217520.666497793 ether;
        ethAmount[0xDeABE8d70c4fb1D13ac46c5a5ab117EcBfC08186] = 348713.590411425 ether;
        ethAmount[0xBA94E79B45b04Da4feD98B3587B75DaCb2eF28bD] = 104614.077123428 ether;


        //WALLETS
        ethAmount[0x356815f53d5DFa738E5a38ffB261afa8731e45Be] = 7_000_000 ether; //fostering partnership synergies
        ethAmount[0x60e18f804FF8aB716b83ee65D2893B292481911F] = 30_000_000 ether; //cross-chain bridging
        ethAmount[0x25d2FCd5759C3B822672B4d78faf1e7DC350b2B5] = 10_000_000 ether; //philanthropy
        ethAmount[0x8Bf164d2aDf1167f9611B8067D1a845f89cdeA61] = 15_000_000 ether; //House Wallet 1
        ethAmount[0x7B85429fa9E1c7F83B2Cb3Ca4Be367Decb708886] = 15_000_000 ether; //House Wallet 2

        start = block.timestamp;
    }

    function setSLPTotal(uint256 _slpTotal) external nonReentrant onlyOwner {
        slpTotal = _slpTotal;
    }

    function getTokensPerAccount(address _account) public view returns (uint256) {
        if (ethAmount[_account] == 0) {
            return 0;
        }
        return ethAmount[_account];
    }

    function getLpTokensPerAccount(address _account) public view returns (uint256) {
        if (ethAmount[_account] == 0) {
            return 0;
        }
        return slpTotal * ethAmount[_account] / ethTotal;
    }

    function getClaimsByAccount(address _account) external view returns (uint256, uint256) {
        return (claimedTokens[_account], claimedLpTokens[_account]);
    }

    function claim() external nonReentrant {
        uint256 _tokens;
        uint256 _lpTokens;
        if ((block.timestamp) >= start && (!claims[msg.sender][0])) {
            _tokens += getTokensPerAccount(msg.sender) * 10000 / 60000;
            claimedTokens[msg.sender] += _tokens;
            claims[msg.sender][0] = true;
        }
        if ((block.timestamp >= start + (86400 * 7)) && (!claims[msg.sender][1])) {
            _tokens += getTokensPerAccount(msg.sender) * 10000 / 60000;
            _lpTokens += getLpTokensPerAccount(msg.sender) * 10000 / 50000;
            claimedTokens[msg.sender] += _tokens;
            claimedLpTokens[msg.sender] += _lpTokens;
            claims[msg.sender][1] = true;
        }
        if ((block.timestamp >= start + (86400 * 14)) && (!claims[msg.sender][2])) {
            _tokens += getTokensPerAccount(msg.sender) * 10000 / 60000;
            _lpTokens += getLpTokensPerAccount(msg.sender) * 10000 / 50000;
            claimedTokens[msg.sender] += _tokens;
            claimedLpTokens[msg.sender] += _lpTokens;
            claims[msg.sender][2] = true;
        }
        if ((block.timestamp >= start + (86400 * 21)) && (!claims[msg.sender][3])) {
            _tokens += getTokensPerAccount(msg.sender) * 10000 / 60000;
            _lpTokens += getLpTokensPerAccount(msg.sender) * 10000 / 50000;
            claimedTokens[msg.sender] += _tokens;
            claimedLpTokens[msg.sender] += _lpTokens;
            claims[msg.sender][3] = true;
        }
        if ((block.timestamp >= start + (86400 * 28)) && (!claims[msg.sender][4])) {
            _tokens += getTokensPerAccount(msg.sender) * 10000 / 60000;
            _lpTokens += getLpTokensPerAccount(msg.sender) * 10000 / 50000;
            claimedTokens[msg.sender] += _tokens;
            claimedLpTokens[msg.sender] += _lpTokens;
            claims[msg.sender][4] = true;
        }
        if ((block.timestamp >= start + (86400 * 35)) && (!claims[msg.sender][5])) {
            _tokens += getTokensPerAccount(msg.sender) * 10000 / 60000;
            _lpTokens += getLpTokensPerAccount(msg.sender) * 10000 / 50000;
            claimedTokens[msg.sender] += _tokens;
            claimedLpTokens[msg.sender] += _lpTokens;
            claims[msg.sender][5] = true;
        }
        if (_tokens > 0) {
            smc.transfer(msg.sender, _tokens);
        }
        if (_lpTokens > 0) {
            slp.transfer(msg.sender, _lpTokens);
        }
    }

    function emergencyWithdrawToken(address _token, uint256 _amount) external nonReentrant onlyOwner {
        IERC20BackwardsCompatible(_token).transfer(msg.sender, _amount);
    }

    function emergencyWithdrawETH(uint256 _amount) external nonReentrant onlyOwner {
        (bool success,) = payable(msg.sender).call{value : _amount}("");
    }

    receive() external payable {}
}