Disable per-token fees (#581)

This commit is contained in:
Kirill Fedoseev 2021-03-11 08:09:53 +03:00 committed by GitHub
parent eba5180291
commit 16d178924a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View File

@ -66,6 +66,7 @@ contract HomeFeeManagerMultiAMBErc20ToErc677 is BaseRewardAddressList, Ownable,
* @param _fee new fee value, in percentage (1 ether == 10**18 == 100%).
*/
function setFee(bytes32 _feeType, address _token, uint256 _fee) external onlyOwner {
require(isTokenRegistered(_token));
_setFee(_feeType, _token, _fee);
}
@ -76,6 +77,19 @@ contract HomeFeeManagerMultiAMBErc20ToErc677 is BaseRewardAddressList, Ownable,
* @return fee value associated with the requested fee type.
*/
function getFee(bytes32 _feeType, address _token) public view validFeeType(_feeType) returns (uint256) {
if (_getFee(_feeType, _token) > 0) {
return _getFee(_feeType, address(0));
}
return 0;
}
/**
* @dev Internal function for reading fee values mapping.
* @param _feeType type of the fee, can be one of [HOME_TO_FOREIGN_FEE, FOREIGN_TO_HOME_FEE].
* @param _token address of the token contract for which fee should apply.
* @return fee value associated with the requested fee type.
*/
function _getFee(bytes32 _feeType, address _token) internal returns (uint256) {
return uintStorage[keccak256(abi.encodePacked(_feeType, _token))];
}
@ -98,7 +112,6 @@ contract HomeFeeManagerMultiAMBErc20ToErc677 is BaseRewardAddressList, Ownable,
* @param _fee new fee value, in percentage (1 ether == 10**18 == 100%).
*/
function _setFee(bytes32 _feeType, address _token, uint256 _fee) internal validFeeType(_feeType) validFee(_fee) {
require(isTokenRegistered(_token));
uintStorage[keccak256(abi.encodePacked(_feeType, _token))] = _fee;
emit FeeUpdated(_feeType, _token, _fee);
}

View File

@ -37,6 +37,23 @@ contract HomeMultiAMBErc20ToErc677 is
require(msg.sender == owner());
}
/**
* @dev Throws if caller on the other side is not an associated mediator.
*/
modifier onlyMediator() {
_onlyMediator();
/* solcov ignore next */
_;
}
/**
* @dev Internal function for reducing onlyMediator modifier bytecode size overhead.
*/
function _onlyMediator() internal {
require(msg.sender == address(bridgeContract()));
require(messageSender() == mediatorContractOnOtherSide());
}
/**
* @dev Stores the initial parameters of the mediator.
* @param _bridgeContract the address of the AMB bridge contract.

View File

@ -1195,7 +1195,8 @@ contract('HomeMultiAMBErc20ToErc677', async accounts => {
.fulfilled
expectEventInLogs(logs, 'FeeUpdated')
expect(await contract.getFee(feeType, token.address)).to.be.bignumber.equal(ether('0.1'))
// expect(await contract.getFee(feeType, token.address)).to.be.bignumber.equal(ether('0.1'))
expect(await contract.getFee(feeType, token.address)).to.be.bignumber.equal(ether('0.02'))
expect(await contract.getFee(await contract.FOREIGN_TO_HOME_FEE(), token.address)).to.be.bignumber.equal(
ether('0.01')
)
@ -1215,7 +1216,8 @@ contract('HomeMultiAMBErc20ToErc677', async accounts => {
.fulfilled
expectEventInLogs(logs, 'FeeUpdated')
expect(await contract.getFee(feeType, token.address)).to.be.bignumber.equal(ether('0.1'))
// expect(await contract.getFee(feeType, token.address)).to.be.bignumber.equal(ether('0.1'))
expect(await contract.getFee(feeType, token.address)).to.be.bignumber.equal(ether('0.01'))
expect(await contract.getFee(await contract.HOME_TO_FOREIGN_FEE(), token.address)).to.be.bignumber.equal(
ether('0.02')
)