Skip to content

Commit

Permalink
feat: merge limit change events (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShaito authored Jul 5, 2023
1 parent ccfdb4e commit 52d1e5c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 37 deletions.
23 changes: 3 additions & 20 deletions solidity/contracts/XERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ contract XERC20 is ERC20, Ownable, IXERC20, ERC20Permit {
* @param _bridge The address of the bridge we are setting the limits too
*/
function setLimits(address _bridge, uint256 _mintingLimit, uint256 _burningLimit) external onlyOwner {
_changeLimit(_mintingLimit, _bridge, true);
_changeLimit(_burningLimit, _bridge, false);
_changeMinterLimit(_mintingLimit, _bridge);
_changeBurnerLimit(_burningLimit, _bridge);
emit BridgeLimitsSet(_mintingLimit, _burningLimit, _bridge);
}

/**
Expand Down Expand Up @@ -185,7 +186,6 @@ contract XERC20 is ERC20, Ownable, IXERC20, ERC20Permit {

bridges[_bridge].minterParams.ratePerSecond = _limit / _DURATION;
bridges[_bridge].minterParams.timestamp = block.timestamp;
emit MinterLimitsSet(_limit, _bridge);
}

/**
Expand All @@ -204,23 +204,6 @@ contract XERC20 is ERC20, Ownable, IXERC20, ERC20Permit {

bridges[_bridge].burnerParams.ratePerSecond = _limit / _DURATION;
bridges[_bridge].burnerParams.timestamp = block.timestamp;
emit BurnerLimitsSet(_limit, _bridge);
}

/**
* @notice Updates the limit of any bridge
*
* @param _newLimit The updated limit we are setting to the bridge
* @param _bridge The address of the bridge we are setting the limit too
* @param _mintingLimit Whether or not we are updating the minting limit
*/

function _changeLimit(uint256 _newLimit, address _bridge, bool _mintingLimit) internal {
if (_mintingLimit) {
_changeMinterLimit(_newLimit, _bridge);
} else {
_changeBurnerLimit(_newLimit, _bridge);
}
}

/**
Expand Down
17 changes: 4 additions & 13 deletions solidity/interfaces/IXERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,11 @@ interface IXERC20 {
/**
* @notice Emits when a limit is set
*
* @param _newLimit The updated limit we are setting to the minter
* @param _minter The address of the minter we are setting the limit too
*/

event MinterLimitsSet(uint256 _newLimit, address indexed _minter);

/**
* @notice Emits when a limit is set
*
* @param _newLimit The updated limit we are setting to the minter
* @param _burner The address of the minter we are setting the limit too
* @param _mintingLimit The updated minting limit we are setting to the bridge
* @param _burningLimit The updated burning limit we are setting to the bridge
* @param _bridge The address of the bridge we are setting the limit too
*/

event BurnerLimitsSet(uint256 _newLimit, address indexed _burner);
event BridgeLimitsSet(uint256 _mintingLimit, uint256 _burningLimit, address indexed _bridge);

/**
* @notice Reverts when a user with too low of a limit tries to call mint/burn
Expand Down
7 changes: 3 additions & 4 deletions solidity/test/unit/XERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ abstract contract Base is Test {

XERC20 internal _xerc20;

event MinterLimitsSet(uint256 _newLimit, address indexed _minter);
event BurnerLimitsSet(uint256 _newLimit, address indexed _burner);
event BridgeLimitsSet(uint256 _mintingLimit, uint256 _burningLimit, address indexed _bridge);
event LockboxSet(address _lockbox);

function setUp() public virtual {
Expand Down Expand Up @@ -140,14 +139,14 @@ contract UnitCreateParams is Base {
function testchangeBridgeMintingLimitEmitsEvent(uint256 _limit, address _minter) public {
vm.prank(_owner);
vm.expectEmit(true, true, true, true);
emit MinterLimitsSet(_limit, _minter);
emit BridgeLimitsSet(_limit, 0, _minter);
_xerc20.setLimits(_minter, _limit, 0);
}

function testchangeBridgeBurningLimitEmitsEvent(uint256 _limit, address _minter) public {
vm.prank(_owner);
vm.expectEmit(true, true, true, true);
emit BurnerLimitsSet(_limit, _minter);
emit BridgeLimitsSet(0, _limit, _minter);
_xerc20.setLimits(_minter, 0, _limit);
}

Expand Down

0 comments on commit 52d1e5c

Please sign in to comment.