From 6b4ea16e8ff4f18aa4e0f78cdecb3d2eaaf8dfec Mon Sep 17 00:00:00 2001 From: Sriram Nurani Viswanathan <50625504+nvsriram@users.noreply.github.com> Date: Wed, 6 Nov 2024 20:52:41 -0500 Subject: [PATCH] evm: Emit events when updating inbound and outbound limits (#546) * Add `OutboundTransferLimitUpdated` and `InboundTransferLimitUpdated` events * Emit these events when `_setOutboundLimit` and `_setInboundLimit` are called respectively --- evm/src/interfaces/IRateLimiterEvents.sol | 15 +++++++++++++++ evm/src/libraries/RateLimiter.sol | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/evm/src/interfaces/IRateLimiterEvents.sol b/evm/src/interfaces/IRateLimiterEvents.sol index 71a92a539..3beb70f1f 100644 --- a/evm/src/interfaces/IRateLimiterEvents.sol +++ b/evm/src/interfaces/IRateLimiterEvents.sol @@ -25,4 +25,19 @@ interface IRateLimiterEvents { event OutboundTransferRateLimited( address indexed sender, uint64 sequence, uint256 amount, uint256 currentCapacity ); + + /// @notice Emitted when the outbound transfer limit is updated. + /// @dev Topic0 + /// 0x7e3b0fc388be9d36273f66210aed83be975df3a9adfffa4c734033f498f362cd. + /// @param oldLimit The old outbound limit. + /// @param newLimit The new outbound limit. + event OutboundTransferLimitUpdated(uint256 oldLimit, uint256 newLimit); + + /// @notice Emitted when the inbound transfer limit is updated. + /// @dev Topic0 + /// 0x739ed886fd81a3ddc9f4b327ab69152e513cd45b26fda0c73660eaca8e119301. + /// @param chainId The chain ID the limit is set for. + /// @param oldLimit The old inbound limit. + /// @param newLimit The new inbound limit. + event InboundTransferLimitUpdated(uint16 indexed chainId, uint256 oldLimit, uint256 newLimit); } diff --git a/evm/src/libraries/RateLimiter.sol b/evm/src/libraries/RateLimiter.sol index 2543c542f..877c86ee1 100644 --- a/evm/src/libraries/RateLimiter.sol +++ b/evm/src/libraries/RateLimiter.sol @@ -96,7 +96,11 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents { function _setOutboundLimit( TrimmedAmount limit ) internal virtual { - _setLimit(limit, _getOutboundLimitParamsStorage()); + RateLimitParams storage rateLimitParams = _getOutboundLimitParamsStorage(); + TrimmedAmount oldLimit = rateLimitParams.limit; + uint8 decimals = tokenDecimals(); + _setLimit(limit, rateLimitParams); + emit OutboundTransferLimitUpdated(oldLimit.untrim(decimals), limit.untrim(decimals)); } function getOutboundLimitParams() public pure virtual returns (RateLimitParams memory) { @@ -116,7 +120,13 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents { } function _setInboundLimit(TrimmedAmount limit, uint16 chainId_) internal virtual { - _setLimit(limit, _getInboundLimitParamsStorage()[chainId_]); + RateLimitParams storage rateLimitParams = _getInboundLimitParamsStorage()[chainId_]; + TrimmedAmount oldLimit = rateLimitParams.limit; + uint8 decimals = tokenDecimals(); + _setLimit(limit, rateLimitParams); + emit InboundTransferLimitUpdated( + chainId_, oldLimit.untrim(decimals), limit.untrim(decimals) + ); } function getInboundLimitParams(