Skip to content

Commit

Permalink
evm: Refactor transfer limit updated events to IRateLimiterEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
nvsriram committed Nov 6, 2024
1 parent c12f209 commit 738c37b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
9 changes: 0 additions & 9 deletions evm/src/NttManager/NttManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {

uint8 toDecimals = tokenDecimals();
_setInboundLimit(inboundLimit.trim(toDecimals, toDecimals), peerChainId);
emit InboundLimitUpdated(peerChainId, 0, inboundLimit);

emit PeerUpdated(
peerChainId, oldPeer.peerAddress, oldPeer.tokenDecimals, peerContract, decimals
Expand All @@ -138,22 +137,14 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {
function setOutboundLimit(
uint256 limit
) external onlyOwner {
TrimmedAmount oldLimit = getOutboundLimitParams().limit;

uint8 toDecimals = tokenDecimals();
_setOutboundLimit(limit.trim(toDecimals, toDecimals));

emit OutboundLimitUpdated(oldLimit.untrim(toDecimals), limit);
}

/// @inheritdoc INttManager
function setInboundLimit(uint256 limit, uint16 chainId_) external onlyOwner {
TrimmedAmount oldLimit = getInboundLimitParams(chainId_).limit;

uint8 toDecimals = tokenDecimals();
_setInboundLimit(limit.trim(toDecimals, toDecimals), chainId_);

emit InboundLimitUpdated(chainId_, oldLimit.untrim(toDecimals), limit);
}

/// ============== Invariants =============================================
Expand Down
22 changes: 0 additions & 22 deletions evm/src/interfaces/INttManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,6 @@ interface INttManager is IManagerBase {
uint8 peerDecimals
);

/// @notice Emitted when the outbound transfer limit is updated.
/// @dev Topic0
/// 0x47b89bcc74f69b843254b547e92022bb07e57681833d4a1858300790b3e0a901.
/// @param oldLimit The old outbound limit.
/// @param newLimit The new outbound limit.
event OutboundLimitUpdated(
uint256 oldLimit,
uint256 newLimit
);

/// @notice Emitted when the inbound transfer limit is updated.
/// @dev Topic0
/// 0x35d8618fbee970d48f845ecb4474f125fd1f91e3213b126871989fdb37e77f3f.
/// @param chainId The chain ID the limit is set for.
/// @param oldLimit The old inbound limit.
/// @param newLimit The new inbound limit.
event InboundLimitUpdated(
uint16 indexed chainId,
uint256 oldLimit,
uint256 newLimit
);

/// @notice Emitted when a transfer has been redeemed
/// (either minted or unlocked on the recipient chain).
/// @dev Topic0
Expand Down
22 changes: 22 additions & 0 deletions evm/src/interfaces/IRateLimiterEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,26 @@ 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
);
}
12 changes: 10 additions & 2 deletions evm/src/libraries/RateLimiter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -116,7 +120,11 @@ 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(
Expand Down

0 comments on commit 738c37b

Please sign in to comment.