diff --git a/solidity/src/FeesManager.sol b/solidity/src/FeesManager.sol index c2c469a3..d9f71a52 100644 --- a/solidity/src/FeesManager.sol +++ b/solidity/src/FeesManager.sol @@ -40,10 +40,11 @@ contract FeesManager is IFeesManager, Ownable { error NothingToClaim(); error TooEarly(); error AlreadyClaimed(); + error AlreadyInitialized(); error UnsupportedToken(address xerc20); modifier onlyOnce() { - require(initialized == false, "Already initialized"); + if (initialized) revert AlreadyInitialized(); _; initialized = true; } @@ -62,6 +63,13 @@ contract FeesManager is IFeesManager, Ownable { } } + function setFeesManagerForXERC20( + address xerc20, + address newFeesManager + ) external onlyOwner { + IXERC20(xerc20).setFeesManager(newFeesManager); + } + /// @inheritdoc IFeesManager function claimFeeByEpoch(address token, uint16 epoch) external { address payable sender = payable(_msgSender()); diff --git a/solidity/src/interfaces/IXERC20.sol b/solidity/src/interfaces/IXERC20.sol index 49ba126a..3f004a9a 100644 --- a/solidity/src/interfaces/IXERC20.sol +++ b/solidity/src/interfaces/IXERC20.sol @@ -165,4 +165,10 @@ interface IXERC20 { * @notice Returns the fees manager address */ function getFeesManager() external view returns (address); + + /** + * @notice Set the fees manager address + * @param newAddress new fees manager address + */ + function setFeesManager(address newAddress) external; } diff --git a/solidity/src/test/XERC20.sol b/solidity/src/test/XERC20.sol index bd9d34cc..8f2124f1 100644 --- a/solidity/src/test/XERC20.sol +++ b/solidity/src/test/XERC20.sol @@ -36,7 +36,6 @@ contract XERC20 is ERC20, Ownable, IXERC20, ERC20Permit { /** * @notice Maps each bridge's adapter to a PAM - * is handled */ mapping(address => address) adapterToPAM; @@ -46,11 +45,6 @@ contract XERC20 is ERC20, Ownable, IXERC20, ERC20Permit { event FeesManagerChanged(address newAddress); - modifier onlyFeesManager() { - if (msg.sender != feesManager) revert OnlyFeesManager(); - _; - } - /** * @notice Constructs the initial config of the XERC20 * @@ -62,22 +56,14 @@ contract XERC20 is ERC20, Ownable, IXERC20, ERC20Permit { string memory _name, string memory _symbol, address /*_factory*/ - ) ERC20(_name, _symbol) ERC20Permit(_name) Ownable(msg.sender) { - // _transferOwnership(_factory); - // FACTORY = _factory; - - // Set to msg.sender in order to be changed - // later - feesManager = msg.sender; - } + ) ERC20(_name, _symbol) ERC20Permit(_name) Ownable(msg.sender) {} - /** - * @notice Set the new fees manager address - * - * @param newAddress new address of the fees manager - */ + /// @inheritdoc IXERC20 + function setFeesManager(address newAddress) public { + if (feesManager == address(0)) { + feesManager = newAddress; + } else if (msg.sender != feesManager) revert OnlyFeesManager(); - function setFeesManager(address newAddress) public onlyFeesManager { if (newAddress.code.length == 0) revert NotAContract(feesManager); feesManager = newAddress;