From 02f3f55bd63008371d66cef9f5714b465e80af55 Mon Sep 17 00:00:00 2001 From: Ivan Zhelyazkov Date: Thu, 17 Oct 2024 14:27:48 +0300 Subject: [PATCH] whitelist - minor fixes --- contracts/network/BancorNetwork.sol | 48 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/contracts/network/BancorNetwork.sol b/contracts/network/BancorNetwork.sol index 497b17329..06f72c200 100644 --- a/contracts/network/BancorNetwork.sol +++ b/contracts/network/BancorNetwork.sol @@ -349,6 +349,18 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl } } + modifier onlyWhitelisted(address addr) { + _onlyWhitelisted(addr); + + _; + } + + function _onlyWhitelisted(address addr) internal view { + if (!_feeExemptionWhitelist.contains(addr)) { + revert AccessDenied(); + } + } + receive() external payable {} /** @@ -702,10 +714,7 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl uint256 minReturnAmount, uint256 deadline, address beneficiary - ) external payable whenNotPaused returns (uint256) { - if (!_feeExemptionWhitelist.contains(msg.sender)) { - revert AccessDenied(); - } + ) external payable whenNotPaused onlyWhitelisted(msg.sender) returns (uint256) { return _tradeBySourceAmount( sourceToken, @@ -729,10 +738,7 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl uint256 maxSourceAmount, uint256 deadline, address beneficiary - ) external payable whenNotPaused returns (uint256) { - if (!_feeExemptionWhitelist.contains(msg.sender)) { - revert AccessDenied(); - } + ) external payable whenNotPaused onlyWhitelisted(msg.sender) returns (uint256) { return _tradeByTargetAmount( sourceToken, @@ -902,7 +908,7 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl function feeExemptionWhitelist() external view returns (address[] memory) { uint256 length = _feeExemptionWhitelist.length(); address[] memory list = new address[](length); - for (uint256 i = 0; i < length; i++) { + for (uint256 i = 0; i < length; ++i) { list[i] = _feeExemptionWhitelist.at(i); } return list; @@ -929,22 +935,11 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl function addAddressesToWhitelist(address[] calldata addrs) external onlyAdmin { uint256 length = addrs.length; - for (uint256 i = 0; i < length; i++) { + for (uint256 i = 0; i < length; ++i) { _addToWhitelist(addrs[i]); } } - /** - * @dev adds an address to the fee exemption whitelist - */ - function _addToWhitelist(address addr) private validExternalAddress(addr) { - if (!_feeExemptionWhitelist.add(addr)) { - revert AlreadyExists(); - } - - emit AddressAddedToWhitelist(addr); - } - /** * @dev removes an address from the fee exemption whitelist * @@ -1023,6 +1018,17 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl emit MinNetworkFeeBurnUpdated(oldMinNetworkFeeBurn, newMinNetworkFeeBurn); } + /** + * @dev adds an address to the fee exemption whitelist + */ + function _addToWhitelist(address addr) private validExternalAddress(addr) { + if (!_feeExemptionWhitelist.add(addr)) { + revert AlreadyExists(); + } + + emit AddressAddedToWhitelist(addr); + } + /** * @dev generates context ID for a deposit request */