Skip to content

Commit 9441a7e

Browse files
feat: Update ForeignController to use modifiers (SC-1281) (#201)
* save * add: modifiers
1 parent 9ef81e8 commit 9441a7e

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/ForeignController.sol

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
161161
}
162162

163163
function setMaxExchangeRate(address token, uint256 shares, uint256 maxExpectedAssets)
164-
external nonReentrant
164+
external nonReentrant onlyRole(DEFAULT_ADMIN_ROLE)
165165
{
166-
_checkRole(DEFAULT_ADMIN_ROLE);
167-
168166
require(token != address(0), "FC/token-zero-address");
169167

170168
emit MaxExchangeRateSet(
@@ -187,13 +185,14 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
187185
/**********************************************************************************************/
188186

189187
function transferAsset(address asset, address destination, uint256 amount)
190-
external nonReentrant onlyRole(RELAYER)
191-
{
192-
_rateLimited(
188+
external
189+
nonReentrant
190+
onlyRole(RELAYER)
191+
rateLimited(
193192
RateLimitHelpers.makeAddressAddressKey(LIMIT_ASSET_TRANSFER, asset, destination),
194193
amount
195-
);
196-
194+
)
195+
{
197196
bytes memory returnData = proxy.doCall(
198197
asset,
199198
abi.encodeCall(IERC20(asset).transfer, (destination, amount))
@@ -298,19 +297,19 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
298297
uint256 amount,
299298
uint32 destinationEndpointId
300299
)
301-
external payable nonReentrant
300+
external
301+
payable
302+
nonReentrant
303+
onlyRole(RELAYER)
304+
rateLimited(
305+
keccak256(abi.encode(LIMIT_LAYERZERO_TRANSFER, oftAddress, destinationEndpointId)),
306+
amount
307+
)
302308
{
303-
_checkRole(RELAYER);
304-
305309
bytes32 recipient = layerZeroRecipients[destinationEndpointId];
306310

307311
require(recipient != bytes32(0), "FC/recipient-not-set");
308312

309-
_rateLimited(
310-
keccak256(abi.encode(LIMIT_LAYERZERO_TRANSFER, oftAddress, destinationEndpointId)),
311-
amount
312-
);
313-
314313
// NOTE: Full integration testing of this logic is not possible without OFTs with
315314
// approvalRequired == true. Add integration testing for this case before
316315
// using in production.
@@ -602,10 +601,6 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
602601
emit CCTPTransferInitiated(nonce, destinationDomain, mintRecipient, usdcAmount);
603602
}
604603

605-
function _rateLimited(bytes32 key, uint256 amount) internal {
606-
rateLimits.triggerRateLimitDecrease(key, amount);
607-
}
608-
609604
/**********************************************************************************************/
610605
/*** Exchange rate helper functions ***/
611606
/**********************************************************************************************/

0 commit comments

Comments
 (0)