Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm: Add back rate limiter view #240

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions evm/src/libraries/RateLimiter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
_setLimit(limit, _getOutboundLimitParamsStorage());
}

function _getOutboundLimitParams() internal pure returns (RateLimitParams memory) {
function getOutboundLimitParams() public pure returns (RateLimitParams memory) {
return _getOutboundLimitParamsStorage();
}

function getCurrentOutboundCapacity() public view returns (uint256) {
TrimmedAmount memory trimmedCapacity = _getCurrentCapacity(_getOutboundLimitParams());
TrimmedAmount memory trimmedCapacity = _getCurrentCapacity(getOutboundLimitParams());
uint8 decimals = tokenDecimals();
return trimmedCapacity.untrim(decimals);
}
Expand All @@ -123,16 +123,12 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
_setLimit(limit, _getInboundLimitParamsStorage()[chainId_]);
}

function _getInboundLimitParams(uint16 chainId_)
internal
view
returns (RateLimitParams memory)
{
function getInboundLimitParams(uint16 chainId_) public view returns (RateLimitParams memory) {
return _getInboundLimitParamsStorage()[chainId_];
}

function getCurrentInboundCapacity(uint16 chainId_) public view returns (uint256) {
TrimmedAmount memory trimmedCapacity = _getCurrentCapacity(_getInboundLimitParams(chainId_));
TrimmedAmount memory trimmedCapacity = _getCurrentCapacity(getInboundLimitParams(chainId_));
uint8 decimals = tokenDecimals();
return trimmedCapacity.untrim(decimals);
}
Expand Down Expand Up @@ -213,22 +209,22 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
function _consumeOutboundAmount(TrimmedAmount memory amount) internal {
if (rateLimitDuration == 0) return;
_consumeRateLimitAmount(
amount, _getCurrentCapacity(_getOutboundLimitParams()), _getOutboundLimitParamsStorage()
amount, _getCurrentCapacity(getOutboundLimitParams()), _getOutboundLimitParamsStorage()
);
}

function _backfillOutboundAmount(TrimmedAmount memory amount) internal {
if (rateLimitDuration == 0) return;
_backfillRateLimitAmount(
amount, _getCurrentCapacity(_getOutboundLimitParams()), _getOutboundLimitParamsStorage()
amount, _getCurrentCapacity(getOutboundLimitParams()), _getOutboundLimitParamsStorage()
);
}

function _consumeInboundAmount(TrimmedAmount memory amount, uint16 chainId_) internal {
if (rateLimitDuration == 0) return;
_consumeRateLimitAmount(
amount,
_getCurrentCapacity(_getInboundLimitParams(chainId_)),
_getCurrentCapacity(getInboundLimitParams(chainId_)),
_getInboundLimitParamsStorage()[chainId_]
);
}
Expand All @@ -237,7 +233,7 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
if (rateLimitDuration == 0) return;
_backfillRateLimitAmount(
amount,
_getCurrentCapacity(_getInboundLimitParams(chainId_)),
_getCurrentCapacity(getInboundLimitParams(chainId_)),
_getInboundLimitParamsStorage()[chainId_]
);
}
Expand Down Expand Up @@ -268,7 +264,7 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
returns (bool)
{
return rateLimitDuration != 0
? _isAmountRateLimited(_getCurrentCapacity(_getOutboundLimitParams()), amount)
? _isAmountRateLimited(_getCurrentCapacity(getOutboundLimitParams()), amount)
: false;
}

Expand All @@ -277,7 +273,7 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
uint16 chainId_
) internal view returns (bool) {
return rateLimitDuration != 0
? _isAmountRateLimited(_getCurrentCapacity(_getInboundLimitParams(chainId_)), amount)
? _isAmountRateLimited(_getCurrentCapacity(getInboundLimitParams(chainId_)), amount)
: false;
}

Expand Down
8 changes: 0 additions & 8 deletions evm/test/mocks/MockNttManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ contract MockNttManagerContract is NttManager {
result := my_slot.slot
}
}

function getOutboundLimitParams() public pure returns (RateLimitParams memory) {
return _getOutboundLimitParams();
}

function getInboundLimitParams(uint16 chainId_) public view returns (RateLimitParams memory) {
return _getInboundLimitParams(chainId_);
}
}

contract MockNttManagerMigrateBasic is NttManager {
Expand Down
Loading