-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fee manager for Native-to-ERC that collects fees on home network #155
Add fee manager for Native-to-ERC that collects fees on home network #155
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify things a bit.
If we look at the Home Bridge functionality from the Fee Management point of view it could be as following:
- the
fallback
function
- change the value to transfer (if the Home fee is not zero. The Fee Manager is responsible for both directions)
- keep the value to transfer (if the Home fee is zero. There is no fee manager or it is responsible for one direction)
onSignaturesCollected
- recover fee from the message and distribute it among the validators (if the Home fee is not zero. The Fee Manager is responsible for both directions)
- nothing special (if the Home fee is zero. There is no fee manager or it is responsible for one direction)
The same is applicable for the Foreign Bridge functionality: onExecuteMessage
- change the value received from the message, send the corresponding value of assets, distribute fee among the validators (if the Home fee is not zero. The Fee Manager is responsible for one directions)
- keep the value received from the message unchanged and send the corresponding value of assets (if the Home fee is zero. There is no fee manager)
So, we don't need to introduce onRequestForSignature
or onSignaturesCollected
in the Fee Manager contract. We can implement similar we already done for the erc-to-native
mode:
fallback, the HomeBridge contract
uint256 valueToTransfer = msg.value;
address feeManager = feeManagerContract();
if (feeManager != address(0)) {
uint256 fee = calculateFee(valueToTransfer, false, feeManager, HOME_FEE);
valueToTransfer = valueToTransfer.sub(fee);
}
emit UserRequestForSignature(msg.sender, valueToTransfer);
It will work for both types of Fee Managers since the Home Fee is zero when there is no fee manager or it is responsible for one direction (called for onExecuteAffirmation
only)
onSignaturesCollected, the HomeBridge contract
address feeManager = feeManagerContract();
if (feeManager != address(0)) {
address recipient;
uint256 amount;
bytes32 txHash;
address contractAddress;
(recipient, amount, txHash, contractAddress) = Message.parseMessage(_message);
uint256 fee = calculateFee(amount, true, feeManager, HOME_FEE);
if (fee != 0) {
distributeFeeFromSignatures(fee, feeManager);
}
}
By adding if (fee != 0)
it will work for both types of Fee Managers since the Home Fee is zero when there is no fee manager or it is responsible for one direction
onExecuteMessage, the ForeignBridge contract
uint256 valueToMint = _amount;
address feeManager = feeManagerContract();
if (feeManager != address(0)) {
uint256 fee = calculateFee(valueToMint, false, feeManager, HOME_FEE);
if (fee != 0) {
distributeFeeFromSignatures(fee, feeManager);
valueToMint = valueToMint.sub(fee);
}
}
By adding if (fee != 0)
it will work in both scenarios as well. In the scenario when there is no Fee Manager the fee will be calculated as zero.
contracts/upgradeable_contracts/native_to_erc20/FeeManagerNativeToErc.sol
Outdated
Show resolved
Hide resolved
Thanks for the suggestions, I applied the changes. If no more changes are needed, I'll update gas consumption document |
…anager-POA-bridge # Conflicts: # contracts/upgradeable_contracts/native_to_erc20/ForeignBridgeNativeToErc.sol # contracts/upgradeable_contracts/native_to_erc20/HomeBridgeNativeToErc.sol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing this PR up to date! Let's merge it
Closes #138
I had to make some changes on
HomeBridgeNativeToErc.sol
to make it work with the two fee manager approaches on this bridge mode.Also I refactored how the .env variables
HOME_REWARDABLE
andFOREIGN_REWARDABLE
works to be able to deploy the correct contracts on the deploy script.After we agree on the changes, I'll update the gas consumption document as part of this PR.