Skip to content

Commit

Permalink
Exposed fee getters.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Dec 6, 2024
1 parent 1913a49 commit c94ebf4
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 14 deletions.

Large diffs are not rendered by default.

66 changes: 64 additions & 2 deletions contracts/generated/EthereumBridge/EthereumBridge.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

66 changes: 64 additions & 2 deletions contracts/generated/MerkleTreeMessageBus/MerkleTreeMessageBus.go

Large diffs are not rendered by default.

66 changes: 64 additions & 2 deletions contracts/generated/MessageBus/MessageBus.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/ObsERC20/ObsERC20.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/ObscuroBridge/ObscuroBridge.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/SystemDeployer/SystemDeployer.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/WrappedERC20/WrappedERC20.go

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions contracts/src/bridge/L2/EthereumBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,19 @@ contract EthereumBridge is
return address(wrappedTokens[wrappedToken]) != address(0x0);
}

function erc20Fee() public view returns (uint256) {
// receiveAssets selector (4 bytes) + address (20 bytes) + uint256 (32 bytes) + address (20 bytes) = 76 bytes
uint256 dataLength = 76;
return _messageBus().getMessageFee(dataLength);
}

function valueTransferFee() public view returns (uint256) {
return _messageBus().getValueTransferFee();
}

function sendNative(address receiver) external payable {
require(msg.value > 0, "Nothing sent.");
require(msg.value >= _messageBus().getValueTransferFee(), "Insufficient funds to publish value transfer");
_messageBus().sendValueToL2{value: msg.value}(receiver, msg.value);
}

Expand All @@ -77,6 +88,8 @@ contract EthereumBridge is
amount,
receiver
);

require(msg.value >= _messageBus().getMessageFee(data.length), "Insufficient funds to publish message");
queueMessage(remoteBridgeAddress, data, uint32(Topics.TRANSFER), 0, 0, msg.value);
}

Expand Down
6 changes: 6 additions & 0 deletions contracts/src/messaging/IMessageBus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ interface IMessageBus {

// This is a testnet function which allows the bridge owner to retrieve all funds from the message bus.
function retrieveAllFunds(address receiver) external;

// the fee needed to be paid in msg.value to publish the value transfer
function getValueTransferFee() external view returns (uint256);

// the fee needed to be paid in msg.value to publish a message
function getMessageFee(uint256 payloadLength) external view returns (uint256);
}
4 changes: 2 additions & 2 deletions contracts/src/messaging/MessageBus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ contract MessageBus is IMessageBus, Initializable, OwnableUpgradeable {
8; // sequence (uint64)
}

function getValueTransferFee() internal view returns (uint256) {
function getValueTransferFee() public view returns (uint256) {
return fees.messageFee(32); //just a hash
}

function getMessageFee(uint256 payloadLength) internal view returns (uint256) {
function getMessageFee(uint256 payloadLength) public view returns (uint256) {
return fees.messageFee(payloadLength + getFixedDataLength());
}

Expand Down

0 comments on commit c94ebf4

Please sign in to comment.