-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWithdrawal.sol
91 lines (80 loc) · 2.72 KB
/
Withdrawal.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
//SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;
import {BytesArrayLibrary} from "./libraries/BytesArrayLibrary.sol";
import {INexusBridge} from "./interfaces/INexusBridge.sol";
/**
*
*
* @dev
*/
contract Withdraw {
using BytesArrayLibrary for bytes[];
address public constant NEXUS_FEE_CONTRACT =
0x4142676ec5706706D3a0792997c4ea343405376b;
address public immutable NEXUS_CONTRACT;
address public immutable DAO_ADDRESS;
uint16 public nexusShare;
uint16 public constant BASIS_POINT = 10000;
uint256 public minimumSlashedAmount = 16 ether;
bytes[] public exitingPubkeys;
uint256 public amountSlashed;
// Events
event SlashingAmountUpdated(uint256 amount);
event NexusShareUpdated(uint32 newShare);
event ExitingValidatorAdded(bytes publicKey);
event NexusRewardSent(uint256 amount);
event RollupRewardSent(uint256 amount);
// Errors
error InvalidAccess();
modifier onlyNexus() {
if (msg.sender != NEXUS_CONTRACT) {
revert InvalidAccess();
}
_;
}
constructor(address _daoAddress, uint16 _nexusFeePercentage) {
DAO_ADDRESS = _daoAddress;
nexusShare = _nexusFeePercentage;
NEXUS_CONTRACT = msg.sender;
}
function exitInitiated(bytes[] memory pubkeys) external onlyNexus {
for (uint256 i; i < pubkeys.length; ) {
exitingPubkeys.addElement(pubkeys[i]);
emit ExitingValidatorAdded(pubkeys[i]);
unchecked {
++i;
}
}
}
function withdrawRewards(bytes[] memory pubkeys) external onlyNexus {
if (pubkeys.length == 0) {
_sendRewards(address(this).balance);
} else {}
}
function _sendRewards(uint256 amount) internal {
uint256 amountNexus = (nexusShare * amount) / BASIS_POINT;
uint256 amountDAO = amount - amountNexus;
(bool rollupSuccess, bytes memory rollupData) = DAO_ADDRESS.call{
value: amountDAO,
gas: 5000
}("");
if (rollupSuccess) emit RollupRewardSent(amountDAO);
(bool nexusSuccess, bytes memory nexusData) = NEXUS_FEE_CONTRACT.call{
value: amountNexus,
gas: 5000
}("");
if (nexusSuccess) emit NexusRewardSent(amountNexus);
}
function _sendBridge(uint256 amount) internal {
}
function slashing(uint256 slashingAmount) external onlyNexus {
if (amountSlashed != slashingAmount) {
amountSlashed = slashingAmount;
emit SlashingAmountUpdated(slashingAmount);
}
}
function updateNexusRewards(uint16 _newFee) external onlyNexus {
nexusShare = _newFee;
emit NexusShareUpdated(_newFee);
}
}