Skip to content

Commit 9a79f79

Browse files
authored
Merge pull request #103 from bgd-labs/feat/mantle
feat: Add Mantle bridge adapter
2 parents 263a7cf + 4d9bd05 commit 9a79f79

File tree

5 files changed

+401
-0
lines changed

5 files changed

+401
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.0;
3+
4+
import {MantleAdapter, IMantleAdapter} from '../../src/contracts/adapters/mantle/MantleAdapter.sol';
5+
import './BaseAdapterScript.sol';
6+
import {MantleAdapterTestnet} from '../contract_extensions/MantleAdapter.sol';
7+
8+
library MantleAdapterDeploymentHelper {
9+
struct MantleAdapterArgs {
10+
BaseAdapterArgs baseArgs;
11+
address ovm;
12+
}
13+
14+
function getAdapterCode(MantleAdapterArgs memory mantleArgs) internal pure returns (bytes memory) {
15+
bytes memory creationCode = mantleArgs.baseArgs.isTestnet
16+
? type(MantleAdapterTestnet).creationCode
17+
: type(MantleAdapter).creationCode;
18+
19+
return
20+
abi.encodePacked(
21+
creationCode,
22+
abi.encode(
23+
IMantleAdapter.MantleParams({
24+
crossChainController: mantleArgs.baseArgs.crossChainController,
25+
ovmCrossDomainMessenger: mantleArgs.ovm,
26+
providerGasLimit: mantleArgs.baseArgs.providerGasLimit,
27+
trustedRemotes: mantleArgs.baseArgs.trustedRemotes
28+
})
29+
)
30+
);
31+
}
32+
}
33+
34+
abstract contract BaseMantleAdapter is BaseAdapterScript {
35+
function OVM() internal view virtual returns (address);
36+
37+
function _getAdapterByteCode(
38+
BaseAdapterArgs memory baseArgs
39+
) internal view override returns (bytes memory) {
40+
require(OVM() != address(0), 'Invalid OVM address');
41+
42+
return
43+
MantleAdapterDeploymentHelper.getAdapterCode(
44+
MantleAdapterDeploymentHelper.MantleAdapterArgs({baseArgs: baseArgs, ovm: OVM()})
45+
);
46+
}
47+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.8;
3+
4+
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
5+
import {MantleAdapter, IOpAdapter, IMantleAdapter} from '../../src/contracts/adapters/mantle/MantleAdapter.sol';
6+
7+
/**
8+
* @title MantleAdapterTestnet
9+
* @author BGD Labs
10+
*/
11+
contract MantleAdapterTestnet is MantleAdapter {
12+
/**
13+
* @param params object containing the necessary parameters to initialize the contract
14+
*/
15+
constructor(IMantleAdapter.MantleParams memory params) MantleAdapter(params) {}
16+
17+
/// @inheritdoc IOpAdapter
18+
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
19+
return chainId == TestNetChainIds.MANTLE_SEPOLIA;
20+
}
21+
22+
/// @inheritdoc IOpAdapter
23+
function getOriginChainId() public pure override returns (uint256) {
24+
return TestNetChainIds.ETHEREUM_SEPOLIA;
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.0;
3+
4+
import {IBaseAdapter} from '../IBaseAdapter.sol';
5+
6+
/**
7+
* @title IMantleAdapter
8+
* @author BGD Labs
9+
* @notice interface containing the events, objects and method definitions used in the Mantle bridge adapter
10+
*/
11+
interface IMantleAdapter is IBaseAdapter {
12+
/**
13+
* @notice struct used to pass parameters to the Mantle constructor
14+
* @param crossChainController address of the cross chain controller that will use this bridge adapter
15+
* @param ovmCrossDomainMessenger Mantle entry point address
16+
* @param providerGasLimit base gas limit used by the bridge adapter
17+
* @param trustedRemotes list of remote configurations to set as trusted
18+
*/
19+
struct MantleParams {
20+
address crossChainController;
21+
address ovmCrossDomainMessenger;
22+
uint256 providerGasLimit;
23+
TrustedRemotesConfig[] trustedRemotes;
24+
}
25+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.0;
3+
4+
import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
5+
import {OpAdapter, IOpAdapter} from '../optimism/OpAdapter.sol';
6+
import {IMantleAdapter} from './IMantleAdapter.sol';
7+
/**
8+
* @title MantleAdapter
9+
* @author BGD Labs
10+
* @notice Mantle bridge adapter. Used to send and receive messages cross chain between Ethereum and Mantle
11+
* @dev it uses the eth balance of CrossChainController contract to pay for message bridging as the method to bridge
12+
is called via delegate call
13+
* @dev note that this adapter can only be used for the communication path ETHEREUM -> MANTLE
14+
* @dev note that this adapter inherits from Optimism adapter and overrides only supported chain
15+
* @dev note that max total gas limit is 1M
16+
*/
17+
contract MantleAdapter is OpAdapter, IMantleAdapter {
18+
/**
19+
* @param params object containing the necessary parameters to initialize the contract
20+
*/
21+
constructor(
22+
MantleParams memory params
23+
)
24+
OpAdapter(
25+
params.crossChainController,
26+
params.ovmCrossDomainMessenger,
27+
params.providerGasLimit,
28+
'Mantle native adapter',
29+
params.trustedRemotes
30+
)
31+
{}
32+
33+
/// @inheritdoc IOpAdapter
34+
function isDestinationChainIdSupported(
35+
uint256 chainId
36+
) public view virtual override returns (bool) {
37+
return chainId == ChainIds.MANTLE;
38+
}
39+
40+
/// @inheritdoc IOpAdapter
41+
function getOriginChainId() public pure virtual override returns (uint256) {
42+
return ChainIds.ETHEREUM;
43+
}
44+
}

0 commit comments

Comments
 (0)