// File: Context.sol



/**
 *Submitted for verification at Etherscan.io on 2022-06-20
*/

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

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: MactivasICO.sol



/**
 *Submitted for verification at Etherscan.io on 2022-06-20
*/

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;


interface IERC20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function allowance(address owner, address spender)
        external
        view
        returns (uint256);

    function transfer(address recipient, uint256 amount)
        external
        returns (bool);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
}

contract MactivasICO is IERC20 {
    string public constant name = "MactivasICO";
    string public constant symbol = "MACT ICO";
    uint8 public constant decimals = 18;
    uint256 totalSupply_ = 200000000000000000000000000;

    mapping(address => uint256) balances;
    mapping(address => mapping(address => uint256)) allowed;

    constructor() {
        balances[msg.sender] = totalSupply_;
    }

    function totalSupply() public view returns (uint256) {
        return totalSupply_;
    }

    function balanceOf(address MactP_Owner)
        public
        view
        
        returns (uint256)
    {
        return balances[MactP_Owner];
    }

    function transfer(address _to, uint256 amount)
        public
        
        returns (bool)
    {
        require(amount <= balances[msg.sender]);
        balances[msg.sender] = balances[msg.sender] - amount;
        balances[_to] = balances[_to] + amount;
        emit Transfer(msg.sender, _to, amount);
        return true;
    }

    function approve(address spender, uint256 amount)
        public
        
        returns (bool)
    {
        allowed[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }

    function allowance(address owner, address spender)
        public
        view
        
        returns (uint256)
    {
        return allowed[owner][spender];
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public  returns (bool) {
        require(amount <= balances[from]);
        require(amount <= allowed[from][msg.sender]);

        balances[from] = balances[from] - amount;
        allowed[from][msg.sender] = allowed[from][msg.sender] + amount;
        balances[to] = balances[to] + amount;
        emit Transfer(from, to, amount);
        return true;
    }
}

// File: Ownable.sol



/**
 *Submitted for verification at Etherscan.io on 2022-06-20
*/

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "./Context.sol";

abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
    constructor() {
        _transferOwnership(_msgSender());
    }

    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    function owner() public view virtual returns (address) {
        return _owner;
    }

    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
// File: Pausable.sol



/**
 *Submitted for verification at Etherscan.io on 2022-06-20
*/

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "./Context.sol";

abstract contract Pausable is Context {
    
    event Paused(address account);
    event Unpaused(address account);

    bool private _paused;
    
    constructor() {
        _paused = false;
    }

    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    modifier whenPaused() {
        _requirePaused();
        _;
    }

    function paused() public view virtual returns (bool) {
        return _paused;
    }

    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }
 
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

     function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }
  
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
// File: Presale.sol



/**
 *Submitted for verification at Etherscan.io on 2022-06-20
*/

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import "./MactivasICO.sol";
import "./Ownable.sol";
import "./Pausable.sol";

contract Presale is Pausable, Ownable {
    string public name = "Presale";
    MactivasICO public mact;
    uint256 public rate = 25000;
    address private _owner;
    bool private _paused;

    event Buy(
        address account,
        address mact,
        uint256 amount,
        uint256 rate
    );

    constructor(MactivasICO _mact) {
        mact = _mact;
        _owner = msg.sender;
        _paused = false;
    }

    function buy() public payable {
        uint256 mactAmount = msg.value * rate;
        require(mact.balanceOf(address(this)) >= mactAmount);
        mact.transfer(msg.sender, mactAmount);  
        emit Buy(msg.sender, address(mact), mactAmount, rate);    
    }

    function withdraw(address payable _to) public onlyOwner {
        require(_owner == msg.sender, "You cannot call this function.");
        _to.transfer(address(this).balance);
        payable(msg.sender).transfer(address(this).balance);
    }

    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }
}