diff --git a/scripts/contract_extensions/LineaAdapter.sol b/scripts/contract_extensions/LineaAdapter.sol index a4a23b32..7eb4bbf6 100644 --- a/scripts/contract_extensions/LineaAdapter.sol +++ b/scripts/contract_extensions/LineaAdapter.sol @@ -19,7 +19,16 @@ contract LineaAdapterTestnet is LineaAdapter { address lineaMessageService, uint256 providerGasLimit, TrustedRemotesConfig[] memory trustedRemotes - ) LineaAdapter(crossChainController, lineaMessageService, providerGasLimit, trustedRemotes) {} + ) + LineaAdapter( + ILineaAdapter.LineaParams({ + crossChainController: crossChainController, + lineaMessageService: lineaMessageService, + providerGasLimit: providerGasLimit, + trustedRemotes: trustedRemotes + }) + ) + {} /// @inheritdoc ILineaAdapter function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) { diff --git a/src/contracts/adapters/linea/ILineaAdapter.sol b/src/contracts/adapters/linea/ILineaAdapter.sol index bb19d1cd..c72eba89 100644 --- a/src/contracts/adapters/linea/ILineaAdapter.sol +++ b/src/contracts/adapters/linea/ILineaAdapter.sol @@ -1,12 +1,28 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; +import {IBaseAdapter} from '../IBaseAdapter.sol'; + /** * @title ILineaAdapter * @author BGD Labs * @notice interface containing the events, objects and method definitions used in the Linea bridge adapter */ -interface ILineaAdapter { +interface ILineaAdapter is IBaseAdapter { + /** + * @notice struct used to pass parameters to the Linea constructor + * @param crossChainController address of the cross chain controller that will use this bridge adapter + * @param lineaMessageService Linea entry point address + * @param providerGasLimit base gas limit used by the bridge adapter + * @param trustedRemotes list of remote configurations to set as trusted + */ + struct LineaParams { + address crossChainController; + address lineaMessageService; + uint256 providerGasLimit; + TrustedRemotesConfig[] trustedRemotes; + } + /** * @notice method to get the Linea message service address * @return address of the Linea message service diff --git a/src/contracts/adapters/linea/LineaAdapter.sol b/src/contracts/adapters/linea/LineaAdapter.sol index b3ef9c1d..7a89a76b 100644 --- a/src/contracts/adapters/linea/LineaAdapter.sol +++ b/src/contracts/adapters/linea/LineaAdapter.sol @@ -2,26 +2,27 @@ pragma solidity ^0.8.0; import {IMessageService} from './interfaces/IMessageService.sol'; -import {BaseAdapter, IBaseAdapter} from '../BaseAdapter.sol'; +import {BaseAdapter} from '../BaseAdapter.sol'; import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol'; import {Errors} from '../../libs/Errors.sol'; -import {ILineaAdapter} from './ILineaAdapter.sol'; +import {ILineaAdapter, IBaseAdapter} from './ILineaAdapter.sol'; import {SafeCast} from 'solidity-utils/contracts/oz-common/SafeCast.sol'; /** * @title LineaAdapter * @author BGD Labs - * @notice Optimism bridge adapter. Used to send and receive messages cross chain between Ethereum and Optimism + * @notice Linea bridge adapter. Used to send and receive messages cross chain between Ethereum and Linea * @dev it uses the eth balance of CrossChainController contract to pay for message bridging as the method to bridge is called via delegate call - * @dev note that this adapter is can only be used for the communication path ETHEREUM -> LINEA + * @dev note that this adapter can only be used for the communication path ETHEREUM -> LINEA + * @dev documentation regarding the Linea bridge can be found here: https://docs.linea.build/get-started/concepts/message-service#technical-reference */ contract LineaAdapter is ILineaAdapter, BaseAdapter { /// @inheritdoc ILineaAdapter address public immutable LINEA_MESSAGE_SERVICE; /** - * @notice only calls from the set ovm are accepted. + * @notice only calls from the set message service are accepted. */ modifier onlyLineaMessageService() { require(msg.sender == address(LINEA_MESSAGE_SERVICE), Errors.CALLER_NOT_LINEA_MESSAGE_SERVICE); @@ -29,19 +30,23 @@ contract LineaAdapter is ILineaAdapter, BaseAdapter { } /** - * @param crossChainController address of the cross chain controller that will use this bridge adapter - * @param lineaMessageService Linea entry point address - * @param providerGasLimit base gas limit used by the bridge adapter - * @param trustedRemotes list of remote configurations to set as trusted + * @param params object containing the necessary parameters to initialize the contract */ constructor( - address crossChainController, - address lineaMessageService, - uint256 providerGasLimit, - TrustedRemotesConfig[] memory trustedRemotes - ) BaseAdapter(crossChainController, providerGasLimit, 'Linea native adapter', trustedRemotes) { - require(lineaMessageService != address(0), Errors.LINEA_MESSAGE_SERVICE_CANT_BE_ADDRESS_0); - LINEA_MESSAGE_SERVICE = lineaMessageService; + LineaParams memory params + ) + BaseAdapter( + params.crossChainController, + params.providerGasLimit, + 'Linea native adapter', + params.trustedRemotes + ) + { + require( + params.lineaMessageService != address(0), + Errors.LINEA_MESSAGE_SERVICE_CANT_BE_ADDRESS_0 + ); + LINEA_MESSAGE_SERVICE = params.lineaMessageService; } /// @inheritdoc IBaseAdapter @@ -90,12 +95,16 @@ contract LineaAdapter is ILineaAdapter, BaseAdapter { } /// @inheritdoc IBaseAdapter - function nativeToInfraChainId(uint256 nativeChainId) public pure override returns (uint256) { + function nativeToInfraChainId( + uint256 nativeChainId + ) public pure override(BaseAdapter, IBaseAdapter) returns (uint256) { return nativeChainId; } /// @inheritdoc IBaseAdapter - function infraToNativeChainId(uint256 infraChainId) public pure override returns (uint256) { + function infraToNativeChainId( + uint256 infraChainId + ) public pure override(BaseAdapter, IBaseAdapter) returns (uint256) { return infraChainId; } } diff --git a/tests/adapters/LineaAdapter.t.sol b/tests/adapters/LineaAdapter.t.sol index d03bc513..f093d7c9 100644 --- a/tests/adapters/LineaAdapter.t.sol +++ b/tests/adapters/LineaAdapter.t.sol @@ -34,10 +34,12 @@ contract LineaAdapterTest is BaseAdapterTest { originConfigs[0] = originConfig; lineaAdapter = new LineaAdapter( - crossChainController, - lineaMessageService, - baseGasLimit, - originConfigs + ILineaAdapter.LineaParams({ + crossChainController: crossChainController, + lineaMessageService: lineaMessageService, + providerGasLimit: baseGasLimit, + trustedRemotes: originConfigs + }) ); _; } @@ -69,7 +71,14 @@ contract LineaAdapterTest is BaseAdapterTest { memory originConfigs = new IBaseAdapter.TrustedRemotesConfig[](1); originConfigs[0] = originConfig; vm.expectRevert(bytes(Errors.LINEA_MESSAGE_SERVICE_CANT_BE_ADDRESS_0)); - new LineaAdapter(crossChainController, address(0), baseGasLimit, originConfigs); + new LineaAdapter( + ILineaAdapter.LineaParams({ + crossChainController: crossChainController, + lineaMessageService: address(0), + providerGasLimit: baseGasLimit, + trustedRemotes: originConfigs + }) + ); } function testInitialize(