// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
abstract contract IERC20 {
function decimals() external view virtual returns (uint8);
function name() external view virtual returns (string memory);
function symbol() external view virtual returns (string memory);
}
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x095ea7b3, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: APPROVE_FAILED"
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0xa9059cbb, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: TRANSFER_FAILED"
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x23b872dd, from, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: TRANSFER_FROM_FAILED"
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, "TransferHelper: ETH_TRANSFER_FAILED");
}
}
contract BridgeCrogecoinERC is Context, Ownable {
using SafeMath for uint256;
mapping(uint256 => uint256) private _nonces;
mapping(uint256 => mapping(uint256 => bool)) private nonceProcessed;
mapping(uint256 => uint256) private _processedFees;
mapping(address => bool) public _isExcludedFromFees;
uint256 private _bridgeFee = 3;
bool public _isBridgingPaused = false;
address public croge;
address public system = address(0x24EEc2380e2EcfA160B7Fe14738B66d7873c9523);
address public governor = address(0xd070544810510865114Ad5A0b6a821A5BD2E7C49);
address public bridgeFeesAddress = address(0xf18275845EB7A5d804d7a032679764C3562488c5);
event SwapRequest(
address indexed to,
uint256 amount,
uint256 nonce,
uint256 toChainID
);
modifier onlySystem() {
require(system == _msgSender(), "Ownable: caller is not the system");
_;
}
modifier onlyGovernance() {
require(governor == _msgSender(), "Ownable: caller is not the system");
_;
}
modifier bridgingPaused() {
require(!_isBridgingPaused, "the bridging is paused");
_;
}
constructor() {
// initializing processed fees
_processedFees[25] = 0.0001 ether;
_processedFees[56] = 0.0001 ether;
}
function updateCrogeContract(address _croge) external onlyOwner {
croge = _croge;
}
function excludeFromFees(address account, bool exclude) external onlyGovernance {
_isExcludedFromFees[account] = exclude;
}
function setBridgeFee(uint256 bridgeFee) external onlyGovernance returns (bool) {
_bridgeFee = bridgeFee;
return true;
}
function changeGovernor(address _governor) external onlyGovernance {
governor = _governor;
}
function getBridgeFee() external view returns (uint256) {
return _bridgeFee;
}
function setBridgeFeesAddress(address _bridgeFeesAddress) external onlyGovernance {
bridgeFeesAddress = _bridgeFeesAddress;
}
function setSystem(address _system) external onlyOwner returns (bool) {
system = _system;
return true;
}
function setProcessedFess(uint256 chainID, uint256 processedFees)
external
onlyOwner
{
_processedFees[chainID] = processedFees;
}
function getProcessedFees(uint256 chainID) external view returns(uint256){
return _processedFees[chainID];
}
function getBridgeStatus(uint256 nonce, uint256 fromChainID)
external
view
returns (bool)
{
return nonceProcessed[fromChainID][nonce];
}
function updateBridgingStaus(bool paused) external onlyOwner {
_isBridgingPaused = paused;
}
function swap(uint256 amount, uint256 toChainID)
external
payable
bridgingPaused
{
require(
msg.value >= _processedFees[toChainID],
"Insufficient processed fees"
);
uint256 _nonce = _nonces[toChainID];
_nonce = _nonce.add(1);
_nonces[toChainID] = _nonce;
TransferHelper.safeTransferFrom(
croge,
_msgSender(),
address(this),
amount
);
payable(system).transfer(msg.value);
emit SwapRequest(_msgSender(), amount, _nonce, toChainID);
}
function feeCalculation(uint256 amount) public view returns (uint256) {
uint256 _amountAfterFee = (amount - (amount.mul(_bridgeFee) / 1000));
return _amountAfterFee;
}
function swapBack(
address to,
uint256 amount,
uint256 nonce,
uint256 fromChainID
) external onlySystem {
require(
!nonceProcessed[fromChainID][nonce],
"Swap is already proceeds"
);
nonceProcessed[fromChainID][nonce] = true;
uint256 temp;
if(_isExcludedFromFees[to]){
temp = amount;
} else {
temp = feeCalculation(amount);
}
uint256 fees = amount.sub(temp);
if(fees > 0) {
TransferHelper.safeTransfer(croge, bridgeFeesAddress, fees);
}
TransferHelper.safeTransfer(croge, to, temp);
}
}
{
"compilationTarget": {
"BridgeCrogecoinERC.sol": "BridgeCrogecoinERC"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"toChainID","type":"uint256"}],"name":"SwapRequest","type":"event"},{"inputs":[],"name":"_isBridgingPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_isExcludedFromFees","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bridgeFeesAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_governor","type":"address"}],"name":"changeGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"croge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"exclude","type":"bool"}],"name":"excludeFromFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"feeCalculation","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBridgeFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"fromChainID","type":"uint256"}],"name":"getBridgeStatus","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"chainID","type":"uint256"}],"name":"getProcessedFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"bridgeFee","type":"uint256"}],"name":"setBridgeFee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_bridgeFeesAddress","type":"address"}],"name":"setBridgeFeesAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"chainID","type":"uint256"},{"internalType":"uint256","name":"processedFees","type":"uint256"}],"name":"setProcessedFess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_system","type":"address"}],"name":"setSystem","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"toChainID","type":"uint256"}],"name":"swap","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"fromChainID","type":"uint256"}],"name":"swapBack","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"system","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"paused","type":"bool"}],"name":"updateBridgingStaus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_croge","type":"address"}],"name":"updateCrogeContract","outputs":[],"stateMutability":"nonpayable","type":"function"}]