Skip to content

Instantly share code, notes, and snippets.

@thexeromin
Created January 20, 2023 08:49
Show Gist options
  • Save thexeromin/fd68b91054c915b20ab4d905e9d2192a to your computer and use it in GitHub Desktop.
Save thexeromin/fd68b91054c915b20ab4d905e9d2192a to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract BridgeBSC is Ownable {
using SafeMath for uint256;
IERC20 briseToken = IERC20(0xB66651FE14178A10017053A2417565A88162eC17);
address public tokenReceiver = 0x7604cC735Baaf33283dc4f3372A7B4A14B93Ce10;
address public feeReceiver = 0x7604cC735Baaf33283dc4f3372A7B4A14B93Ce10;
uint256 public fee = 5;
uint256 public feeDenominator = 10000;
// Check token allowance
modifier checkAllowance(uint amount) {
require(briseToken.allowance(msg.sender, address(this)) >= amount, "Error");
_;
}
function initiate(uint256 _amount) public payable checkAllowance(_amount) {
uint256 feeAmount = _amount.mul(fee).div(feeDenominator);
briseToken.transferFrom(msg.sender, feeReceiver, feeAmount);
briseToken.transferFrom(msg.sender, address(this), _amount - feeAmount);
emit Received(msg.sender, _amount - feeAmount);
}
function withdrawETH(uint256 _amount) public onlyOwner {
bool sent = payable(tokenReceiver).send(_amount);
require(sent, "Failed to send BRISE");
emit Withdraw(tokenReceiver, _amount);
}
function withdrawBRISE(uint256 _amount) public onlyOwner {
briseToken.transfer(feeReceiver, _amount);
}
function transfer(address _to, uint256 _amount) public onlyOwner {
transfer_from_contract(_to, _amount);
}
function transfer_from_contract(address _to, uint256 _amount) public onlyOwner {
briseToken.transfer(_to, _amount);
}
function updateTokenReceiver(address _receiver) public onlyOwner {
tokenReceiver = _receiver;
}
function updateFee(uint256 _fee, uint256 _feeDenominator) public onlyOwner {
fee = _fee;
feeDenominator = _feeDenominator;
}
function ethBalance() public view onlyOwner returns (uint256) {
return address(this).balance;
}
receive() external payable {}
event Received(address, uint);
event Withdraw(address, uint);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment