-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFeeVault.sol
More file actions
109 lines (86 loc) · 3.89 KB
/
Copy pathFeeVault.sol
File metadata and controls
109 lines (86 loc) · 3.89 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IHypNativeMinter {
function transferRemote(uint32 _destination, bytes32 _recipient, uint256 _amount)
external
payable
returns (bytes32 messageId);
}
contract FeeVault {
IHypNativeMinter public immutable hypNativeMinter;
address public owner;
uint32 public destinationDomain;
bytes32 public recipientAddress;
uint256 public minimumAmount;
uint256 public callFee;
// Split accounting
address public otherRecipient;
uint256 public bridgeShareBps; // Basis points (0-10000) for bridge share
event SentToCelestia(uint256 amount, bytes32 recipient, bytes32 messageId);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event RecipientUpdated(uint32 destinationDomain, bytes32 recipientAddress);
event MinimumAmountUpdated(uint256 minimumAmount);
event CallFeeUpdated(uint256 callFee);
event BridgeShareUpdated(uint256 bridgeShareBps);
event OtherRecipientUpdated(address otherRecipient);
event FundsSplit(uint256 totalNew, uint256 bridgeAmount, uint256 otherAmount);
modifier onlyOwner() {
require(msg.sender == owner, "FeeVault: caller is not the owner");
_;
}
constructor(address _hypNativeMinter, address _owner) {
hypNativeMinter = IHypNativeMinter(_hypNativeMinter);
owner = _owner;
bridgeShareBps = 10000; // Default to 100% bridge
emit OwnershipTransferred(address(0), _owner);
}
receive() external payable {}
function sendToCelestia() external payable {
require(msg.value >= callFee, "FeeVault: insufficient fee");
uint256 currentBalance = address(this).balance;
// Calculate split
uint256 bridgeAmount = (currentBalance * bridgeShareBps) / 10000;
uint256 otherAmount = currentBalance - bridgeAmount;
require(bridgeAmount >= minimumAmount, "FeeVault: minimum amount not met");
emit FundsSplit(currentBalance, bridgeAmount, otherAmount);
// Send other amount if any
if (otherAmount > 0) {
require(otherRecipient != address(0), "FeeVault: other recipient not set");
(bool success,) = otherRecipient.call{value: otherAmount}("");
require(success, "FeeVault: transfer failed");
}
// Bridge the bridge amount
bytes32 messageId =
hypNativeMinter.transferRemote{value: bridgeAmount}(destinationDomain, recipientAddress, bridgeAmount);
emit SentToCelestia(bridgeAmount, recipientAddress, messageId);
}
// Admin functions
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "FeeVault: new owner is the zero address");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function setRecipient(uint32 _destinationDomain, bytes32 _recipientAddress) external onlyOwner {
destinationDomain = _destinationDomain;
recipientAddress = _recipientAddress;
emit RecipientUpdated(_destinationDomain, _recipientAddress);
}
function setMinimumAmount(uint256 _minimumAmount) external onlyOwner {
minimumAmount = _minimumAmount;
emit MinimumAmountUpdated(_minimumAmount);
}
function setCallFee(uint256 _callFee) external onlyOwner {
callFee = _callFee;
emit CallFeeUpdated(_callFee);
}
function setBridgeShare(uint256 _bridgeShareBps) external onlyOwner {
require(_bridgeShareBps <= 10000, "FeeVault: invalid bps");
bridgeShareBps = _bridgeShareBps;
emit BridgeShareUpdated(_bridgeShareBps);
}
function setOtherRecipient(address _otherRecipient) external onlyOwner {
require(_otherRecipient != address(0), "FeeVault: zero address");
otherRecipient = _otherRecipient;
emit OtherRecipientUpdated(_otherRecipient);
}
}