Skip to content

Commit

Permalink
fix(XERC20): let anyone set the fee manager for the first time
Browse files Browse the repository at this point in the history
and let the fees manager set the new fee manager from the
contract
  • Loading branch information
gitmp01 committed Jun 21, 2024
1 parent c7eb07d commit 261e3d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
10 changes: 9 additions & 1 deletion solidity/src/FeesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions solidity/src/interfaces/IXERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
26 changes: 6 additions & 20 deletions solidity/src/test/XERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*
Expand All @@ -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;
Expand Down

0 comments on commit 261e3d4

Please sign in to comment.