Skip to content

Commit e3f27fc

Browse files
committed
evm: Add back rate limiter view
1 parent 1470fc6 commit e3f27fc

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

evm/src/libraries/RateLimiter.sol

+10-14
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
101101
_setLimit(limit, _getOutboundLimitParamsStorage());
102102
}
103103

104-
function _getOutboundLimitParams() internal pure returns (RateLimitParams memory) {
104+
function getOutboundLimitParams() public pure returns (RateLimitParams memory) {
105105
return _getOutboundLimitParamsStorage();
106106
}
107107

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

126-
function _getInboundLimitParams(uint16 chainId_)
127-
internal
128-
view
129-
returns (RateLimitParams memory)
130-
{
126+
function getInboundLimitParams(uint16 chainId_) public view returns (RateLimitParams memory) {
131127
return _getInboundLimitParamsStorage()[chainId_];
132128
}
133129

134130
function getCurrentInboundCapacity(uint16 chainId_) public view returns (uint256) {
135-
TrimmedAmount memory trimmedCapacity = _getCurrentCapacity(_getInboundLimitParams(chainId_));
131+
TrimmedAmount memory trimmedCapacity = _getCurrentCapacity(getInboundLimitParams(chainId_));
136132
uint8 decimals = tokenDecimals();
137133
return trimmedCapacity.untrim(decimals);
138134
}
@@ -213,22 +209,22 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
213209
function _consumeOutboundAmount(TrimmedAmount memory amount) internal {
214210
if (rateLimitDuration == 0) return;
215211
_consumeRateLimitAmount(
216-
amount, _getCurrentCapacity(_getOutboundLimitParams()), _getOutboundLimitParamsStorage()
212+
amount, _getCurrentCapacity(getOutboundLimitParams()), _getOutboundLimitParamsStorage()
217213
);
218214
}
219215

220216
function _backfillOutboundAmount(TrimmedAmount memory amount) internal {
221217
if (rateLimitDuration == 0) return;
222218
_backfillRateLimitAmount(
223-
amount, _getCurrentCapacity(_getOutboundLimitParams()), _getOutboundLimitParamsStorage()
219+
amount, _getCurrentCapacity(getOutboundLimitParams()), _getOutboundLimitParamsStorage()
224220
);
225221
}
226222

227223
function _consumeInboundAmount(TrimmedAmount memory amount, uint16 chainId_) internal {
228224
if (rateLimitDuration == 0) return;
229225
_consumeRateLimitAmount(
230226
amount,
231-
_getCurrentCapacity(_getInboundLimitParams(chainId_)),
227+
_getCurrentCapacity(getInboundLimitParams(chainId_)),
232228
_getInboundLimitParamsStorage()[chainId_]
233229
);
234230
}
@@ -237,7 +233,7 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
237233
if (rateLimitDuration == 0) return;
238234
_backfillRateLimitAmount(
239235
amount,
240-
_getCurrentCapacity(_getInboundLimitParams(chainId_)),
236+
_getCurrentCapacity(getInboundLimitParams(chainId_)),
241237
_getInboundLimitParamsStorage()[chainId_]
242238
);
243239
}
@@ -268,7 +264,7 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
268264
returns (bool)
269265
{
270266
return rateLimitDuration != 0
271-
? _isAmountRateLimited(_getCurrentCapacity(_getOutboundLimitParams()), amount)
267+
? _isAmountRateLimited(_getCurrentCapacity(getOutboundLimitParams()), amount)
272268
: false;
273269
}
274270

@@ -277,7 +273,7 @@ abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
277273
uint16 chainId_
278274
) internal view returns (bool) {
279275
return rateLimitDuration != 0
280-
? _isAmountRateLimited(_getCurrentCapacity(_getInboundLimitParams(chainId_)), amount)
276+
? _isAmountRateLimited(_getCurrentCapacity(getInboundLimitParams(chainId_)), amount)
281277
: false;
282278
}
283279

evm/test/mocks/MockNttManager.sol

-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ contract MockNttManagerContract is NttManager {
2424
result := my_slot.slot
2525
}
2626
}
27-
28-
function getOutboundLimitParams() public pure returns (RateLimitParams memory) {
29-
return _getOutboundLimitParams();
30-
}
31-
32-
function getInboundLimitParams(uint16 chainId_) public view returns (RateLimitParams memory) {
33-
return _getInboundLimitParams(chainId_);
34-
}
3527
}
3628

3729
contract MockNttManagerMigrateBasic is NttManager {

0 commit comments

Comments
 (0)