Skip to content

Commit

Permalink
change address => IRouter in OnRamp; add getRouter() func
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanRHall committed Aug 2, 2024
1 parent f9c01f9 commit 0fc3c24
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
21 changes: 11 additions & 10 deletions contracts/src/v0.8/ccip/onRamp/EVM2EVMMultiOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {INonceManager} from "../interfaces/INonceManager.sol";
import {IPoolV1} from "../interfaces/IPool.sol";
import {IPriceRegistry} from "../interfaces/IPriceRegistry.sol";
import {IRMN} from "../interfaces/IRMN.sol";
import {IRouter} from "../interfaces/IRouter.sol";
import {ITokenAdminRegistry} from "../interfaces/ITokenAdminRegistry.sol";

import {OwnerIsCreator} from "../../shared/access/OwnerIsCreator.sol";
Expand Down Expand Up @@ -72,15 +73,15 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre
uint64 sequenceNumber;
// This is the local router address that is allowed to send messages to the destination chain.
// This is NOT the receiving router address on the destination chain.
address router;
IRouter router;
}

/// @dev Same as DestChainConfig but with the destChainSelector so that an array of these
/// can be passed in the constructor and the applyDestChainConfigUpdates function
//solhint-disable gas-struct-packing
struct DestChainConfigArgs {
uint64 destChainSelector; // Destination chain selector
address router; // Source router address
IRouter router; // Source router address
}

// STATIC CONFIG
Expand Down Expand Up @@ -155,7 +156,7 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre
// Validate message sender is set and allowed. Not validated in `getFee` since it is not user-driven.
if (originalSender == address(0)) revert RouterMustSetOriginalSender();
// Router address may be zero intentionally to pause.
if (msg.sender != destChainConfig.router) revert MustBeCalledByRouter();
if (msg.sender != address(destChainConfig.router)) revert MustBeCalledByRouter();

{
// scoped to reduce stack usage
Expand Down Expand Up @@ -296,6 +297,13 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre
_setDynamicConfig(dynamicConfig);
}

/// @notice Gets the source router for a destination chain
/// @param destChainSelector The destination chain selector
/// @return router the router for the provided destination chain
function getRouter(uint64 destChainSelector) external view returns (IRouter) {
return s_destChainConfigs[destChainSelector].router;
}

/// @notice Internal version of setDynamicConfig to allow for reuse in the constructor.
function _setDynamicConfig(DynamicConfig memory dynamicConfig) internal {
if (dynamicConfig.priceRegistry == address(0) || dynamicConfig.feeAggregator == address(0)) revert InvalidConfig();
Expand All @@ -313,13 +321,6 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre
);
}

/// @notice Gets the source router for a destination chain
/// @param destChainSelector The destination chain selector
/// @return destChainConfig the config for the provided destination chain
function getDestChainConfig(uint64 destChainSelector) external view returns (DestChainConfig memory) {
return s_destChainConfigs[destChainSelector];
}

/// @notice Updates the destination chain specific config.
/// @param destChainConfigArgs Array of source chain specific configs.
function applyDestChainConfigUpdates(DestChainConfigArgs[] memory destChainConfigArgs) external onlyOwner {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/test/NonceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ contract NonceManager_OnRampUpgrade is EVM2EVMMultiOnRampSetup {
s_outboundNonceManager.applyPreviousRampsUpdates(previousRamps);

(s_onRamp, s_metadataHash) = _deployOnRamp(
SOURCE_CHAIN_SELECTOR, address(s_sourceRouter), address(s_outboundNonceManager), address(s_tokenAdminRegistry)
SOURCE_CHAIN_SELECTOR, s_sourceRouter, address(s_outboundNonceManager), address(s_tokenAdminRegistry)
);

vm.startPrank(address(s_sourceRouter));
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/test/e2e/MultiRampsEnd2End.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract MultiRampsE2E is EVM2EVMMultiOnRampSetup, EVM2EVMMultiOffRampSetup {
s_onRamp2,
s_metadataHash2
) = _deployOnRamp(
SOURCE_CHAIN_SELECTOR + 1, address(s_sourceRouter2), address(s_nonceManager2), address(s_tokenAdminRegistry2)
SOURCE_CHAIN_SELECTOR + 1, s_sourceRouter2, address(s_nonceManager2), address(s_tokenAdminRegistry2)
);

address[] memory authorizedCallers = new address[](1);
Expand Down
38 changes: 19 additions & 19 deletions contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ contract EVM2EVMMultiOnRamp_constructor is EVM2EVMMultiOnRampSetup {
emit EVM2EVMMultiOnRamp.ConfigSet(staticConfig, dynamicConfig);
vm.expectEmit();
emit EVM2EVMMultiOnRamp.DestChainConfigSet(
DEST_CHAIN_SELECTOR, EVM2EVMMultiOnRamp.DestChainConfig(0, address(s_sourceRouter))
DEST_CHAIN_SELECTOR, EVM2EVMMultiOnRamp.DestChainConfig(0, s_sourceRouter)
);

_deployOnRamp(
SOURCE_CHAIN_SELECTOR, address(s_sourceRouter), address(s_outboundNonceManager), address(s_tokenAdminRegistry)
);
_deployOnRamp(SOURCE_CHAIN_SELECTOR, s_sourceRouter, address(s_outboundNonceManager), address(s_tokenAdminRegistry));

EVM2EVMMultiOnRamp.StaticConfig memory gotStaticConfig = s_onRamp.getStaticConfig();
_assertStaticConfigsEqual(staticConfig, gotStaticConfig);
Expand All @@ -48,7 +46,7 @@ contract EVM2EVMMultiOnRamp_constructor is EVM2EVMMultiOnRampSetup {
assertEq("EVM2EVMMultiOnRamp 1.6.0-dev", s_onRamp.typeAndVersion());
assertEq(OWNER, s_onRamp.owner());
assertEq(1, s_onRamp.getExpectedNextSequenceNumber(DEST_CHAIN_SELECTOR));
assertEq(address(s_sourceRouter), s_onRamp.getDestChainConfig(DEST_CHAIN_SELECTOR).router);
assertEq(address(s_sourceRouter), address(s_onRamp.getRouter(DEST_CHAIN_SELECTOR)));
}

function test_Constructor_InvalidConfigChainSelectorEqZero_Revert() public {
Expand All @@ -61,7 +59,7 @@ contract EVM2EVMMultiOnRamp_constructor is EVM2EVMMultiOnRampSetup {
tokenAdminRegistry: address(s_tokenAdminRegistry)
}),
_generateDynamicMultiOnRampConfig(address(s_priceRegistry)),
_generateDestChainConfigArgs(address(0))
_generateDestChainConfigArgs(IRouter(address(0)))
);
}

Expand All @@ -75,7 +73,7 @@ contract EVM2EVMMultiOnRamp_constructor is EVM2EVMMultiOnRampSetup {
tokenAdminRegistry: address(s_tokenAdminRegistry)
}),
_generateDynamicMultiOnRampConfig(address(s_priceRegistry)),
_generateDestChainConfigArgs(address(0))
_generateDestChainConfigArgs(IRouter(address(0)))
);
}

Expand All @@ -89,7 +87,7 @@ contract EVM2EVMMultiOnRamp_constructor is EVM2EVMMultiOnRampSetup {
tokenAdminRegistry: address(s_tokenAdminRegistry)
}),
_generateDynamicMultiOnRampConfig(address(s_priceRegistry)),
_generateDestChainConfigArgs(address(0))
_generateDestChainConfigArgs(IRouter(address(0)))
);
}

Expand All @@ -103,7 +101,7 @@ contract EVM2EVMMultiOnRamp_constructor is EVM2EVMMultiOnRampSetup {
tokenAdminRegistry: address(0)
}),
_generateDynamicMultiOnRampConfig(address(s_priceRegistry)),
_generateDestChainConfigArgs(address(0))
_generateDestChainConfigArgs(IRouter(address(0)))
);
}
}
Expand Down Expand Up @@ -146,7 +144,7 @@ contract EVM2EVMMultiOnRamp_forwardFromRouter is EVM2EVMMultiOnRampSetup {
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);

// Change the source router for this lane
address newRouter = makeAddr("NEW ROUTER");
IRouter newRouter = IRouter(makeAddr("NEW ROUTER"));
vm.stopPrank();
vm.prank(OWNER);
s_onRamp.applyDestChainConfigUpdates(_generateDestChainConfigArgs(newRouter));
Expand All @@ -157,7 +155,7 @@ contract EVM2EVMMultiOnRamp_forwardFromRouter is EVM2EVMMultiOnRampSetup {
s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);

// forward succeeds from correct router
vm.prank(newRouter);
vm.prank(address(newRouter));
s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}

Expand Down Expand Up @@ -752,24 +750,26 @@ contract EVM2EVMMultiOnRamp_applyDestChainConfigUpdates is EVM2EVMMultiOnRampSet

// supports disabling a lane by setting a router to zero
vm.expectEmit();
emit EVM2EVMMultiOnRamp.DestChainConfigSet(DEST_CHAIN_SELECTOR, EVM2EVMMultiOnRamp.DestChainConfig(0, address(0)));
emit EVM2EVMMultiOnRamp.DestChainConfigSet(
DEST_CHAIN_SELECTOR, EVM2EVMMultiOnRamp.DestChainConfig(0, IRouter(address(0)))
);
s_onRamp.applyDestChainConfigUpdates(configArgs);
assertEq(address(0), s_onRamp.getDestChainConfig(DEST_CHAIN_SELECTOR).router);
assertEq(address(0), address(s_onRamp.getRouter(DEST_CHAIN_SELECTOR)));

// supports updating and adding lanes simultaneously
configArgs = new EVM2EVMMultiOnRamp.DestChainConfigArgs[](2);
configArgs[0] =
EVM2EVMMultiOnRamp.DestChainConfigArgs({destChainSelector: DEST_CHAIN_SELECTOR, router: address(s_sourceRouter)});
configArgs[1] = EVM2EVMMultiOnRamp.DestChainConfigArgs({destChainSelector: 9999, router: address(9999)});
EVM2EVMMultiOnRamp.DestChainConfigArgs({destChainSelector: DEST_CHAIN_SELECTOR, router: s_sourceRouter});
configArgs[1] = EVM2EVMMultiOnRamp.DestChainConfigArgs({destChainSelector: 9999, router: IRouter(address(9999))});
vm.expectEmit();
emit EVM2EVMMultiOnRamp.DestChainConfigSet(
DEST_CHAIN_SELECTOR, EVM2EVMMultiOnRamp.DestChainConfig(0, address(s_sourceRouter))
DEST_CHAIN_SELECTOR, EVM2EVMMultiOnRamp.DestChainConfig(0, s_sourceRouter)
);
vm.expectEmit();
emit EVM2EVMMultiOnRamp.DestChainConfigSet(9999, EVM2EVMMultiOnRamp.DestChainConfig(0, address(9999)));
emit EVM2EVMMultiOnRamp.DestChainConfigSet(9999, EVM2EVMMultiOnRamp.DestChainConfig(0, IRouter(address(9999))));
s_onRamp.applyDestChainConfigUpdates(configArgs);
assertEq(address(s_sourceRouter), s_onRamp.getDestChainConfig(DEST_CHAIN_SELECTOR).router);
assertEq(address(9999), s_onRamp.getDestChainConfig(9999).router);
assertEq(address(s_sourceRouter), address(s_onRamp.getRouter(DEST_CHAIN_SELECTOR)));
assertEq(address(9999), address(s_onRamp.getRouter(9999)));

// handles empty list
uint256 numLogs = vm.getRecordedLogs().length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.24;

import {IPoolV1} from "../../interfaces/IPool.sol";
import {IRouter} from "../../interfaces/IRouter.sol";

import {AuthorizedCallers} from "../../../shared/access/AuthorizedCallers.sol";
import {NonceManager} from "../../NonceManager.sol";
Expand Down Expand Up @@ -38,7 +39,7 @@ contract EVM2EVMMultiOnRampSetup is TokenSetup, PriceRegistryFeeSetup {
s_outboundMessageValidator = new MessageInterceptorHelper();
s_outboundNonceManager = new NonceManager(new address[](0));
(s_onRamp, s_metadataHash) = _deployOnRamp(
SOURCE_CHAIN_SELECTOR, address(s_sourceRouter), address(s_outboundNonceManager), address(s_tokenAdminRegistry)
SOURCE_CHAIN_SELECTOR, s_sourceRouter, address(s_outboundNonceManager), address(s_tokenAdminRegistry)
);

s_offRamps = new address[](2);
Expand Down Expand Up @@ -111,7 +112,7 @@ contract EVM2EVMMultiOnRampSetup is TokenSetup, PriceRegistryFeeSetup {
return result;
}

function _generateDestChainConfigArgs(address router)
function _generateDestChainConfigArgs(IRouter router)
internal
pure
returns (EVM2EVMMultiOnRamp.DestChainConfigArgs[] memory)
Expand All @@ -124,7 +125,7 @@ contract EVM2EVMMultiOnRampSetup is TokenSetup, PriceRegistryFeeSetup {

function _deployOnRamp(
uint64 sourceChainSelector,
address router,
IRouter router,
address nonceManager,
address tokenAdminRegistry
) internal returns (EVM2EVMMultiOnRampHelper, bytes32 metadataHash) {
Expand Down

0 comments on commit 0fc3c24

Please sign in to comment.