forked from icon-project/devportal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIBSHCore.sol
251 lines (228 loc) · 9.46 KB
/
IBSHCore.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;
import "../Libraries/TypesLib.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155ReceiverUpgradeable.sol";
/**
@title Interface of BSHCore contract
@dev This contract is used to handle coin transferring service
Note: The coin of following interface can be:
Native Coin : The native coin of this chain
Wrapped Native Coin : A tokenized ERC1155 version of another native coin like ICX
*/
interface IBSHCore is IERC1155Upgradeable, IERC1155ReceiverUpgradeable {
/**
@notice Adding another Onwer.
@dev Caller must be an Onwer of BTP network
@param _owner Address of a new Onwer.
*/
function addOwner(address _owner) external;
/**
@notice Removing an existing Owner.
@dev Caller must be an Owner of BTP network
@dev If only one Owner left, unable to remove the last Owner
@param _owner Address of an Owner to be removed.
*/
function removeOwner(address _owner) external;
/**
@notice Checking whether one specific address has Owner role.
@dev Caller can be ANY
@param _owner Address needs to verify.
*/
function isOwner(address _owner) external view returns (bool);
/**
@notice Get a list of current Owners
@dev Caller can be ANY
@return An array of addresses of current Owners
*/
function getOwners() external view returns (address[] memory);
/**
@notice update BSH Periphery address.
@dev Caller must be an Owner of this contract
_bshPeriphery Must be different with the existing one.
@param _bshPeriphery BSHPeriphery contract address.
*/
function updateBSHPeriphery(address _bshPeriphery) external;
/**
@notice update base uri.
@dev Caller must be an Owner of this contract
the uri must be initilized in construction.
@param _newURI new uri
*/
function updateUri(string calldata _newURI) external;
/**
@notice set fee ratio.
@dev Caller must be an Owner of this contract
The transfer fee is calculated by feeNumerator/FEE_DEMONINATOR.
The feeNumetator should be less than FEE_DEMONINATOR
_feeNumerator is set to `10` in construction by default, which means the default fee ratio is 0.1%.
@param _feeNumerator the fee numerator
*/
function setFeeRatio(uint256 _feeNumerator) external;
/**
@notice Registers a wrapped coin and id number of a supporting coin.
@dev Caller must be an Owner of this contract
_name Must be different with the native coin name.
@dev '_id' of a wrapped coin is generated by using keccak256
'_id' = 0 is fixed to assign to native coin
@param _name Coin name.
*/
function register(string calldata _name) external;
/**
@notice Return all supported coins names
@dev
@return _names An array of strings.
*/
function coinNames() external view returns (string[] memory _names);
/**
@notice Return an _id number of Coin whose name is the same with given _coinName.
@dev Return nullempty if not found.
@return _coinId An ID number of _coinName.
*/
function coinId(string calldata _coinName)
external
view
returns (uint256 _coinId);
/**
@notice Check Validity of a _coinName
@dev Call by BSHPeriphery contract to validate a requested _coinName
@return _valid true of false
*/
function isValidCoin(string calldata _coinName)
external
view
returns (bool _valid);
/**
@notice Return a usable/locked/refundable balance of an account based on coinName.
@return _usableBalance the balance that users are holding.
@return _lockedBalance when users transfer the coin,
it will be locked until getting the Service Message Response.
@return _refundableBalance refundable balance is the balance that will be refunded to users.
*/
function getBalanceOf(address _owner, string memory _coinName)
external
view
returns (
uint256 _usableBalance,
uint256 _lockedBalance,
uint256 _refundableBalance
);
/**
@notice Return a list Balance of an account.
@dev The order of request's coinNames must be the same with the order of return balance
Return 0 if not found.
@return _usableBalances An array of Usable Balances
@return _lockedBalances An array of Locked Balances
@return _refundableBalances An array of Refundable Balances
*/
function getBalanceOfBatch(address _owner, string[] calldata _coinNames)
external
view
returns (
uint256[] memory _usableBalances,
uint256[] memory _lockedBalances,
uint256[] memory _refundableBalances
);
/**
@notice Return a list accumulated Fees.
@dev only return the asset that has Asset's value greater than 0
@return _accumulatedFees An array of Asset
*/
function getAccumulatedFees()
external
view
returns (Types.Asset[] memory _accumulatedFees);
/**
@notice Allow users to deposit `msg.value` native coin into a BSHCore contract.
@dev MUST specify msg.value
@param _to An address that a user expects to receive an amount of tokens.
*/
function transfer(string calldata _to) external payable;
/**
@notice Allow users to deposit an amount of wrapped native coin `_coinName` from the `msg.sender` address into the BSHCore contract.
@dev Caller must set to approve that the wrapped tokens can be transferred out of the `msg.sender` account by BSHCore contract.
It MUST revert if the balance of the holder for token `_coinName` is lower than the `_value` sent.
@param _coinName A given name of a wrapped coin
@param _value An amount request to transfer.
@param _to Target BTP address.
*/
function transfer(
string calldata _coinName,
uint256 _value,
string calldata _to
) external;
/**
@notice Allow users to transfer multiple coins/wrapped coins to another chain
@dev Caller must set to approve that the wrapped tokens can be transferred out of the `msg.sender` account by BSHCore contract.
It MUST revert if the balance of the holder for token `_coinName` is lower than the `_value` sent.
In case of transferring a native coin, it also checks `msg.value` with `_values[i]`
It MUST revert if `msg.value` is not equal to `_values[i]`
The number of requested coins MUST be as the same as the number of requested values
The requested coins and values MUST be matched respectively
@param _coinNames A list of requested transferring coins/wrapped coins
@param _values A list of requested transferring values respectively with its coin name
@param _to Target BTP address.
*/
function transferBatch(
string[] memory _coinNames,
uint256[] memory _values,
string calldata _to
) external payable;
/**
@notice Reclaim the token's refundable balance by an owner.
@dev Caller must be an owner of coin
The amount to claim must be smaller or equal than refundable balance
@param _coinName A given name of coin
@param _value An amount of re-claiming tokens
*/
function reclaim(string calldata _coinName, uint256 _value) external;
/**
@notice return coin for the failed transfer.
@dev Caller must be itself
@param _to account
@param _coinName coin name
@param _value the minted amount
*/
function refund(
address _to,
string calldata _coinName,
uint256 _value
) external;
/**
@notice mint the wrapped coin.
@dev Caller must be an BSHPeriphery contract
Invalid _coinName will have an _id = 0. However, _id = 0 is also dedicated to Native Coin
Thus, BSHPeriphery will check a validity of a requested _coinName before calling
for the _coinName indicates with id = 0, it should send the Native Coin (Example: PRA) to user account
@param _to the account receive the minted coin
@param _coinName coin name
@param _value the minted amount
*/
function mint(
address _to,
string calldata _coinName,
uint256 _value
) external;
/**
@notice Handle a request of Fee Gathering
@dev Caller must be an BSHPeriphery contract
@param _fa BTP Address of Fee Aggregator
*/
function transferFees(string calldata _fa) external;
/**
@notice Handle a response of a requested service
@dev Caller must be an BSHPeriphery contract
@param _requester An address of originator of a requested service
@param _coinName A name of requested coin
@param _value An amount to receive on a destination chain
@param _fee An amount of charged fee
*/
function handleResponseService(
address _requester,
string calldata _coinName,
uint256 _value,
uint256 _fee,
uint256 rspCode
) external;
}