Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Mantle bridge adapter #103

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions scripts/Adapters/DeployMantleAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {MantleAdapter, IMantleAdapter} from '../../src/contracts/adapters/mantle/MantleAdapter.sol';
import './BaseAdapterScript.sol';
import {MantleAdapterTestnet} from '../contract_extensions/MantleAdapter.sol';

library MantleAdapterDeploymentHelper {
struct MantleAdapterArgs {
BaseAdapterArgs baseArgs;
address ovm;
}

function getAdapterCode(MantleAdapterArgs memory mantleArgs) internal pure returns (bytes memory) {
bytes memory creationCode = mantleArgs.baseArgs.isTestnet
? type(MantleAdapterTestnet).creationCode
: type(MantleAdapter).creationCode;

return
abi.encodePacked(
creationCode,
abi.encode(
IMantleAdapter.MantleParams({
crossChainController: mantleArgs.baseArgs.crossChainController,
ovmCrossDomainMessenger: mantleArgs.ovm,
providerGasLimit: mantleArgs.baseArgs.providerGasLimit,
trustedRemotes: mantleArgs.baseArgs.trustedRemotes
})
)
);
}
}

abstract contract BaseMantleAdapter is BaseAdapterScript {
function OVM() internal view virtual returns (address);

function _getAdapterByteCode(
BaseAdapterArgs memory baseArgs
) internal view override returns (bytes memory) {
require(OVM() != address(0), 'Invalid OVM address');

return
MantleAdapterDeploymentHelper.getAdapterCode(
MantleAdapterDeploymentHelper.MantleAdapterArgs({baseArgs: baseArgs, ovm: OVM()})
);
}
}
26 changes: 26 additions & 0 deletions scripts/contract_extensions/MantleAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {MantleAdapter, IOpAdapter, IMantleAdapter} from '../../src/contracts/adapters/mantle/MantleAdapter.sol';

/**
* @title MantleAdapterTestnet
* @author BGD Labs
*/
contract MantleAdapterTestnet is MantleAdapter {
/**
* @param params object containing the necessary parameters to initialize the contract
*/
constructor(IMantleAdapter.MantleParams memory params) MantleAdapter(params) {}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
return chainId == TestNetChainIds.MANTLE_SEPOLIA;
}

/// @inheritdoc IOpAdapter
function getOriginChainId() public pure override returns (uint256) {
return TestNetChainIds.ETHEREUM_SEPOLIA;
}
}
25 changes: 25 additions & 0 deletions src/contracts/adapters/mantle/IMantleAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {IBaseAdapter} from '../IBaseAdapter.sol';

/**
* @title IMantleAdapter
* @author BGD Labs
* @notice interface containing the events, objects and method definitions used in the Mantle bridge adapter
*/
interface IMantleAdapter is IBaseAdapter {
/**
* @notice struct used to pass parameters to the Mantle constructor
* @param crossChainController address of the cross chain controller that will use this bridge adapter
* @param ovmCrossDomainMessenger Mantle entry point address
* @param providerGasLimit base gas limit used by the bridge adapter
* @param trustedRemotes list of remote configurations to set as trusted
*/
struct MantleParams {
address crossChainController;
address ovmCrossDomainMessenger;
uint256 providerGasLimit;
TrustedRemotesConfig[] trustedRemotes;
}
}
44 changes: 44 additions & 0 deletions src/contracts/adapters/mantle/MantleAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {OpAdapter, IOpAdapter} from '../optimism/OpAdapter.sol';
import {IMantleAdapter} from './IMantleAdapter.sol';
/**
* @title MantleAdapter
* @author BGD Labs
* @notice Mantle bridge adapter. Used to send and receive messages cross chain between Ethereum and Mantle
* @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 can only be used for the communication path ETHEREUM -> MANTLE
* @dev note that this adapter inherits from Optimism adapter and overrides only supported chain
* @dev note that max total gas limit is 1M
*/
contract MantleAdapter is OpAdapter, IMantleAdapter {
/**
* @param params object containing the necessary parameters to initialize the contract
*/
constructor(
MantleParams memory params
)
OpAdapter(
params.crossChainController,
params.ovmCrossDomainMessenger,
params.providerGasLimit,
'Mantle native adapter',
params.trustedRemotes
)
{}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(
uint256 chainId
) public view virtual override returns (bool) {
return chainId == ChainIds.MANTLE;
}

/// @inheritdoc IOpAdapter
function getOriginChainId() public pure virtual override returns (uint256) {
return ChainIds.ETHEREUM;
}
}
Loading
Loading