Skip to content

Commit

Permalink
fix: use struct as contructor params, fix natspec
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Dec 10, 2024
1 parent a8acb23 commit e8bd84e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 25 deletions.
11 changes: 10 additions & 1 deletion scripts/contract_extensions/LineaAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion src/contracts/adapters/linea/ILineaAdapter.sol
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 27 additions & 18 deletions src/contracts/adapters/linea/LineaAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,51 @@
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);
_;
}

/**
* @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
Expand Down Expand Up @@ -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;
}
}
19 changes: 14 additions & 5 deletions tests/adapters/LineaAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
);
_;
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e8bd84e

Please sign in to comment.