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

WIP: add name to adapter contracts #27

Merged
merged 6 commits into from
Jan 16, 2024
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
8 changes: 7 additions & 1 deletion scripts/Adapters/DeployOpAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ abstract contract BaseOpAdapter is BaseAdapterScript {
);
} else {
addresses.opAdapter = address(
new OpAdapter(addresses.crossChainController, OVM(), GET_BASE_GAS_LIMIT(), trustedRemotes)
new OpAdapter(
addresses.crossChainController,
OVM(),
GET_BASE_GAS_LIMIT(),
'Optimism native adapter',
trustedRemotes
)
);
}
}
Expand Down
10 changes: 9 additions & 1 deletion scripts/contract_extensions/OptimismAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ contract OptimismAdapterTestnet is OpAdapter {
address ovmCrossDomainMessenger,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) OpAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {}
)
OpAdapter(
crossChainController,
ovmCrossDomainMessenger,
providerGasLimit,
'Optimism native adapter',
trustedRemotes
)
{}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand Down
6 changes: 6 additions & 0 deletions src/contracts/adapters/BaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,26 @@ abstract contract BaseAdapter is IBaseAdapter {
// (standard chain id -> origin forwarder address) saves for every chain the address that can forward messages to this adapter
mapping(uint256 => address) internal _trustedRemotes;

/// @inheritdoc IBaseAdapter
string public adapterName;

/**
* @param crossChainController address of the CrossChainController the bridged messages will be routed to
* @param providerGasLimit base gas limit used by the bridge adapter
* @param name name of the bridge adapter contract
* @param originConfigs pair of origin address and chain id that adapter is allowed to get messages from
*/
constructor(
address crossChainController,
uint256 providerGasLimit,
string memory name,
TrustedRemotesConfig[] memory originConfigs
) {
require(crossChainController != address(0), Errors.INVALID_BASE_ADAPTER_CROSS_CHAIN_CONTROLLER);
CROSS_CHAIN_CONTROLLER = IBaseCrossChainController(crossChainController);

BASE_GAS_LIMIT = providerGasLimit;
adapterName = name;

_selfAddress = address(this);

Expand Down
7 changes: 7 additions & 0 deletions src/contracts/adapters/IBaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ interface IBaseAdapter {

/**
* @notice method to get the address of the linked cross chain controller
* @return address of CrossChainController
*/
function CROSS_CHAIN_CONTROLLER() external returns (IBaseCrossChainController);

/**
* @notice method to get the name of the adapter contract
* @return name of the adapter contract
*/
function adapterName() external view returns (string memory);

/**
* @notice method to get the base gas limit used by the bridge adapter
*/
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/adapters/arbitrum/ArbAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract ArbAdapter is IArbAdapter, BaseAdapter {
address destinationCCC,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, 'Arbitrum native adapter', trustedRemotes) {
INBOX = inbox;
DESTINATION_CCC = destinationCCC;
}
Expand Down
10 changes: 9 additions & 1 deletion src/contracts/adapters/cBase/CBaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ contract CBaseAdapter is OpAdapter {
address ovmCrossDomainMessenger,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) OpAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {}
)
OpAdapter(
crossChainController,
ovmCrossDomainMessenger,
providerGasLimit,
'Base native adapter',
trustedRemotes
)
{}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/adapters/ccip/CCIPAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract CCIPAdapter is ICCIPAdapter, BaseAdapter, IAny2EVMMessageReceiver, IERC
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes,
address linkToken
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, 'CCIP adapter', trustedRemotes) {
require(ccipRouter != address(0), Errors.CCIP_ROUTER_CANT_BE_ADDRESS_0);
require(linkToken != address(0), Errors.LINK_TOKEN_CANT_BE_ADDRESS_0);
CCIP_ROUTER = IRouterClient(ccipRouter);
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/adapters/gnosisChain/GnosisChainAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract GnosisChainAdapter is BaseAdapter, IGnosisChainAdapter {
address arbitraryMessageBridge,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, 'Gnosis native adapter', trustedRemotes) {
require(arbitraryMessageBridge != address(0), Errors.ZERO_GNOSIS_ARBITRARY_MESSAGE_BRIDGE);
BRIDGE = arbitraryMessageBridge;
}
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/adapters/hyperLane/HyperLaneAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract HyperLaneAdapter is BaseAdapter, IHyperLaneAdapter, IMessageRecipient {
address igp,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, 'Hyperlane adapter', trustedRemotes) {
HL_MAIL_BOX = IMailbox(mailBox);
IGP = IInterchainGasPaymaster(igp);
}
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/adapters/layerZero/LayerZeroAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ contract LayerZeroAdapter is BaseAdapter, ILayerZeroAdapter, ILayerZeroReceiver
* @param lzEndpoint address of the layer zero endpoint on the current chain where adapter is deployed
* @param crossChainController address of the contract that manages cross chain infrastructure
* @param providerGasLimit base gas limit used by the bridge adapter
* @param originConfigs array of objects with chain id and origin addresses which will be allowed to send messages to this adapter
* @param trustedRemotes array of objects with chain id and origin addresses which will be allowed to send messages to this adapter
*/
constructor(
address lzEndpoint,
address crossChainController,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory originConfigs // TODO: check if we can change to trustedRemotes to align with other adapters
) BaseAdapter(crossChainController, providerGasLimit, originConfigs) {
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, 'LayerZero adapter', trustedRemotes) {
require(lzEndpoint != address(0), Errors.INVALID_LZ_ENDPOINT);
LZ_ENDPOINT = ILayerZeroEndpoint(lzEndpoint);
}
Expand Down
10 changes: 9 additions & 1 deletion src/contracts/adapters/metis/MetisAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ contract MetisAdapter is OpAdapter {
address ovmCrossDomainMessenger,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) OpAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {}
)
OpAdapter(
crossChainController,
ovmCrossDomainMessenger,
providerGasLimit,
'Metis native adapter',
trustedRemotes
)
{}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(
Expand Down
4 changes: 3 additions & 1 deletion src/contracts/adapters/optimism/OpAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ contract OpAdapter is IOpAdapter, BaseAdapter {
* @param crossChainController address of the cross chain controller that will use this bridge adapter
* @param ovmCrossDomainMessenger optimism entry point address
* @param providerGasLimit base gas limit used by the bridge adapter
* @param adapterName string indicating the adapter name
* @param trustedRemotes list of remote configurations to set as trusted
*/
constructor(
address crossChainController,
address ovmCrossDomainMessenger,
uint256 providerGasLimit,
string memory adapterName,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, adapterName, trustedRemotes) {
OVM_CROSS_DOMAIN_MESSENGER = ovmCrossDomainMessenger;
}

Expand Down
2 changes: 1 addition & 1 deletion src/contracts/adapters/polygon/PolygonAdapterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract contract PolygonAdapterBase is IPolygonAdapter, IFxMessageProcessor, Ba
address fxTunnel,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, 'Polygon native adapter', trustedRemotes) {
FX_TUNNEL = fxTunnel;
}

Expand Down
5 changes: 5 additions & 0 deletions src/contracts/adapters/sameChain/SameChainAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ contract SameChainAdapter is IBaseAdapter {
return (envelope.destination, 0);
}

/// @inheritdoc IBaseAdapter
function adapterName() external view virtual returns (string memory) {
return 'SameChain adapter';
}

/// @inheritdoc IBaseAdapter
function setupPayments() external {}

Expand Down
10 changes: 9 additions & 1 deletion src/contracts/adapters/scroll/ScrollAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ contract ScrollAdapter is OpAdapter {
address ovmCrossDomainMessenger,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) OpAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {
)
OpAdapter(
crossChainController,
ovmCrossDomainMessenger,
providerGasLimit,
'Scroll native adapter',
trustedRemotes
)
{
SCROLL_MESSAGE_QUEUE = IL1MessageQueue(
IScrollMessenger(OVM_CROSS_DOMAIN_MESSENGER).messageQueue()
);
Expand Down
9 changes: 8 additions & 1 deletion src/contracts/adapters/zkEVM/ZkEVMAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ abstract contract ZkEVMAdapter is BaseAdapter, IBridgeMessageReceiver {
address zkEVMBridge,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
)
BaseAdapter(
crossChainController,
providerGasLimit,
'Polygon ZkEvm native adapter',
trustedRemotes
)
{
ZK_EVM_BRIDGE = zkEVMBridge;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/adapters/ArbAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ contract ArbAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(arbAdapter.adapterName())),
keccak256(abi.encode('Arbitrum native adapter'))
);
assertEq(arbAdapter.getTrustedRemoteByChainId(ORIGIN_CHAIN_ID), CROSS_CHAIN_CONTROLLER);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/BaseAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract MockAdapter is BaseAdapter {
address crossChainController,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {}
) BaseAdapter(crossChainController, providerGasLimit, 'Base adapter', trustedRemotes) {}

function forwardMessage(
address,
Expand Down
4 changes: 4 additions & 0 deletions tests/adapters/CCIPAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ contract CCIPAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(ccipAdapter.adapterName())),
keccak256(abi.encode('CCIP adapter'))
);
assertEq(ccipAdapter.getTrustedRemoteByChainId(ORIGIN_CCIP_CHAIN_ID), ORIGIN_FORWARDER);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/adapters/GnosisChainAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ contract GnosisChainAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(gnosisChainAdapter.adapterName())),
keccak256(abi.encode('Gnosis native adapter'))
);
assertEq(gnosisChainAdapter.getTrustedRemoteByChainId(ORIGIN_CHAIN_ID), ORIGIN_FORWARDER);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/adapters/HyperLaneAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ contract HyperLaneAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(hlAdapter.adapterName())),
keccak256(abi.encode('Hyperlane adapter'))
);
assertEq(hlAdapter.getTrustedRemoteByChainId(ORIGIN_HL_CHAIN_ID), ORIGIN_FORWARDER);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/adapters/LayerZeroAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ contract LayerZeroAdapterTest is Test {

function testInit() public {
address originForwarder = layerZeroAdapter.getTrustedRemoteByChainId(1);

assertEq(
keccak256(abi.encode(layerZeroAdapter.adapterName())),
keccak256(abi.encode('LayerZero adapter'))
);
assertEq(originForwarder, ORIGIN_FORWARDER);
assertEq(address(layerZeroAdapter.LZ_ENDPOINT()), LZ_ENDPOINT);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/adapters/MetisAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ contract MetisAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(metisAdapter.adapterName())),
keccak256(abi.encode('Metis native adapter'))
);
assertEq(metisAdapter.getTrustedRemoteByChainId(ORIGIN_CHAIN_ID), ORIGIN_FORWARDER);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/adapters/OpAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ contract OpAdapterTest is Test {
CROSS_CHAIN_CONTROLLER,
OVM_CROSS_DOMAIN_MESSENGER,
BASE_GAS_LIMIT,
'Optimism native adapter',
originConfigs
);
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(opAdapter.adapterName())),
keccak256(abi.encode('Optimism native adapter'))
);
assertEq(opAdapter.getTrustedRemoteByChainId(ORIGIN_CHAIN_ID), ORIGIN_FORWARDER);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/adapters/PolygonAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ contract PolygonAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(polygonAdapterEthereum.adapterName())),
keccak256(abi.encode('Polygon native adapter'))
);
assertEq(
keccak256(abi.encode(polygonAdapterPolygon.adapterName())),
keccak256(abi.encode('Polygon native adapter'))
);
assertEq(
polygonAdapterEthereum.getTrustedRemoteByChainId(DESTINATION_CHAIN_ID),
CROSS_CHAIN_CONTROLLER
Expand Down
5 changes: 5 additions & 0 deletions tests/adapters/SameChainAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ contract SameChainAdapterTest is Test {

function setUp() public {
sameChainAdapter = new SameChainAdapter();

assertEq(
keccak256(abi.encode(sameChainAdapter.adapterName())),
keccak256(abi.encode('SameChain adapter'))
);
}

function testForwardPayload() public {
Expand Down
4 changes: 4 additions & 0 deletions tests/adapters/ScrollAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ contract ScrollAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(scrollAdapter.adapterName())),
keccak256(abi.encode('Scroll native adapter'))
);
assertEq(scrollAdapter.getTrustedRemoteByChainId(ORIGIN_CHAIN_ID), ORIGIN_FORWARDER);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/adapters/ZkEvmAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ contract ZkEvmAdapterTest is Test {
}

function testInitialize() public {
assertEq(
keccak256(abi.encode(zkEvmAdapterPolygonZkEvm.adapterName())),
keccak256(abi.encode('Polygon ZkEvm native adapter'))
);
assertEq(
keccak256(abi.encode(zkEvmAdapterEthereum.adapterName())),
keccak256(abi.encode('Polygon ZkEvm native adapter'))
);
assertEq(
zkEvmAdapterPolygonZkEvm.getTrustedRemoteByChainId(ORIGIN_CHAIN_ID),
CROSS_CHAIN_CONTROLLER
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/FailingAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {BaseAdapter, IBaseAdapter} from '../../src/contracts/adapters/BaseAdapte
contract FailingAdapter is BaseAdapter {
constructor(
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(address(1), 0, trustedRemotes) {}
) BaseAdapter(address(1), 0, 'failing adapter', trustedRemotes) {}

/// @inheritdoc IBaseAdapter
function forwardMessage(
Expand Down
Loading