// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract SwapForBtc is ReentrancyGuard, Ownable {
    uint256 private poolBalance;

    constructor() {}

    function depositFund(uint256 _amount) external payable onlyOwner {
        require(
            (msg.value > 0 && msg.value == _amount),
            "The deposit amount must not be 0"
        );

        poolBalance += _amount;
    }

    function withdrawFund(uint256 _amount) external nonReentrant onlyOwner {
        require(address(this).balance >= _amount, "Insufficient Pool Balance");

        (bool success, ) = msg.sender.call{value: _amount}("");
        require(success);

        poolBalance -= _amount;
    }

    function getPoolBalance() public view returns (uint256) {
        return poolBalance;
    }

    function releaseFunds(
        uint256 _amount,
        address _receiver
    ) external nonReentrant onlyOwner {
        require(address(this).balance >= _amount, "Insufficient Pool Balance");

        (bool success, ) = _receiver.call{value: _amount}("");
        require(success);

        poolBalance -= _amount;

        emit EtherReleased(_amount, _receiver);
    }

    fallback() external payable {
        revert();
    }

    receive() external payable {
        poolBalance += msg.value;

        emit EtherDepositedForBtc(msg.value, msg.sender);
    }

    event EtherDepositedForBtc(uint256 amount, address indexed trader);
    event EtherReleased(uint256 amount, address indexed receiver);
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"trader","type":"address"}],"name":"EtherDepositedForBtc","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"}],"name":"EtherReleased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"depositFund","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getPoolBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"releaseFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawFund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]