-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBridge.sol
136 lines (94 loc) · 4.5 KB
/
Bridge.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
interface ERC20Essential
{
function balanceOf(address user) external view returns(uint256);
function transfer(address _to, uint256 _amount) external returns (bool);
function transferFrom(address _from, address _to, uint256 _amount) external returns (bool);
}
//USDT contract in Ethereum does not follow ERC20 standard so it needs different interface
interface usdtContract
{
function transferFrom(address _from, address _to, uint256 _amount) external;
}
//*******************************************************************//
//------------------ Contract to Manage Ownership -------------------//
//*******************************************************************//
contract owned
{
address public owner;
address internal newOwner;
mapping(address => bool) public signer;
event OwnershipTransferred(address indexed _from, address indexed _to);
event SignerUpdated(address indexed signer, bool indexed status);
constructor() {
owner = msg.sender;
signer[msg.sender] = true;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
modifier onlySigner {
require(signer[msg.sender], 'caller must be signer');
_;
}
function changeSigner(address _signer, bool _status) public onlyOwner {
signer[_signer] = _status;
emit SignerUpdated(_signer, _status);
}
function transferOwnership(address _newOwner) public onlyOwner {
newOwner = _newOwner;
}
//the reason for this flow is to protect owners from sending ownership to unintended address due to human error
function acceptOwnership() public {
require(msg.sender == newOwner);
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
//****************************************************************************//
//--------------------- MAIN CODE STARTS HERE ---------------------//
//****************************************************************************//
contract BitindiBridge is owned {
uint256 public orderID;
// This generates a public event of coin received by contract
event CoinIn(uint256 indexed orderID, address indexed user, uint256 value, address outputCurrency);
event CoinOut(uint256 indexed orderID, address indexed user, uint256 value);
event CoinOutFailed(uint256 indexed orderID, address indexed user, uint256 value);
event TokenIn(uint256 indexed orderID, address indexed tokenAddress, address indexed user, uint256 value, uint256 chainID, address outputCurrency);
event TokenOut(uint256 indexed orderID, address indexed tokenAddress, address indexed user, uint256 value, uint256 chainID);
event TokenOutFailed(uint256 indexed orderID, address indexed tokenAddress, address indexed user, uint256 value, uint256 chainID);
receive () external payable {
//nothing happens for incoming fund
}
function coinIn(address outputCurrency) external payable returns(bool){
orderID++;
payable(owner).transfer(msg.value); //send fund to owner
emit CoinIn(orderID, msg.sender, msg.value, outputCurrency);
return true;
}
function coinOut(address user, uint256 amount, uint256 _orderID) external onlySigner returns(bool){
payable(user).transfer(amount);
emit CoinOut(_orderID, user, amount);
return true;
}
function tokenIn(address tokenAddress, uint256 tokenAmount, uint256 chainID, address outputCurrency) external returns(bool){
orderID++;
//fund will go to the owner
if(tokenAddress == address(0xdAC17F958D2ee523a2206206994597C13D831ec7)){
//There should be different interface for the USDT Ethereum contract
usdtContract(tokenAddress).transferFrom(msg.sender, owner, tokenAmount);
}else{
ERC20Essential(tokenAddress).transferFrom(msg.sender, owner, tokenAmount);
}
emit TokenIn(orderID, tokenAddress, msg.sender, tokenAmount, chainID, outputCurrency);
return true;
}
function tokenOut(address tokenAddress, address user, uint256 tokenAmount, uint256 _orderID, uint256 chainID) external onlySigner returns(bool){
ERC20Essential(tokenAddress).transfer(user, tokenAmount);
emit TokenOut(_orderID, tokenAddress, user, tokenAmount, chainID);
return true;
}
}