-
Notifications
You must be signed in to change notification settings - Fork 2
/
WithDestinationFunctionality.sol
152 lines (128 loc) · 4.07 KB
/
WithDestinationFunctionality.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import '../BridgeBase.sol';
contract WithDestinationFunctionality is BridgeBase {
enum SwapStatus {
Null,
Succeeded,
Failed,
Fallback
}
event CrossChainRequestSent(
bytes32 indexed id,
BaseCrossChainParams parameters
);
event CrossChainProcessed(
bytes32 indexed id,
address outputTokenAddress,
uint256 amount,
SwapStatus status
);
mapping(bytes32 => SwapStatus) public processedTransactions;
mapping(uint256 => uint256) public blockchainToGasFee;
uint256 public availableRubicGasFee;
bytes32 public constant RELAYER_ROLE =
keccak256('RELAYER_ROLE');
modifier onlyRelayer(address _relayer) {
checkIsRelayer(_relayer);
_;
}
function __WithDestinationFunctionalityInit(
uint256 _fixedCryptoFee,
uint256 _RubicPlatformFee,
address[] memory _tokens,
uint256[] memory _minTokenAmounts,
uint256[] memory _maxTokenAmounts,
uint256[] memory _blockchainIDs,
uint256[] memory _blockchainToGasFee,
address _admin
) internal onlyInitializing {
__BridgeBaseInit(
_fixedCryptoFee,
_RubicPlatformFee,
_tokens,
_minTokenAmounts,
_maxTokenAmounts,
_admin
);
uint256 length = _blockchainIDs.length;
if (_blockchainToGasFee.length != length) {
revert LengthMismatch();
}
for (uint256 i; i < length; ) {
blockchainToGasFee[
_blockchainIDs[i]
] = _blockchainToGasFee[i];
unchecked {
++i;
}
}
}
/**
* @dev Calculates and accrues gas fee and fixed crypto fee
* @param _integrator Integrator's address if there is one
* @param _info A struct with integrator fee info
* @param _blockchainID ID of the target blockchain
* @return _amountWithoutCryptoFee The msg.value without gasFee and fixed crypto fee
*/
function accrueFixedAndGasFees(
address _integrator,
IntegratorFeeInfo memory _info,
uint256 _blockchainID
) internal returns (uint256 _amountWithoutCryptoFee) {
uint256 _gasFee = blockchainToGasFee[_blockchainID];
availableRubicGasFee += _gasFee;
_amountWithoutCryptoFee =
accrueFixedCryptoFee(_integrator, _info) -
_gasFee;
}
/// FEE MANAGEMENT ///
/**
* @dev Changes crypto tokens values for blockchains in blockchainCryptoFee variables
* @param _blockchainID ID of the blockchain
* @param _gasFee Fee amount of native token that must be sent in init call
*/
function setGasFeeOfBlockchain(
uint256 _blockchainID,
uint256 _gasFee
) external onlyManagerOrAdmin {
blockchainToGasFee[_blockchainID] = _gasFee;
}
function collectGasFee(
address _to
) external onlyManagerOrAdmin {
uint256 _gasFee = availableRubicGasFee;
availableRubicGasFee = 0;
sendToken(address(0), _gasFee, _to);
}
/// TX STATUSES MANAGEMENT ///
/**
* @dev Function changes values associated with certain originalTxHash
* @param _id ID of the transaction to change
* @param _statusCode Associated status
*/
function changeTxStatus(
bytes32 _id,
SwapStatus _statusCode
) external onlyManagerOrAdmin {
if (_statusCode == SwapStatus.Null) {
revert CantSetToNull();
}
SwapStatus _status = processedTransactions[_id];
if (
_status == SwapStatus.Succeeded ||
_status == SwapStatus.Fallback
) {
revert Unchangeable();
}
processedTransactions[_id] = _statusCode;
}
/**
* @dev Function to check if address is belongs to relayer role
*/
function checkIsRelayer(address _relayer) internal view {
if (!hasRole(RELAYER_ROLE, _relayer)) {
revert NotARelayer();
}
}
}