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 methods to register first bridge adapters #28

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 18 additions & 0 deletions src/contracts/CrossChainForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,24 @@ contract CrossChainForwarder is OwnableWithGuardian, ICrossChainForwarder {
_disableBridgeAdapters(bridgeAdapters);
}

/// @inheritdoc ICrossChainForwarder
function enableInitialBridgeAdapter(
ForwarderBridgeAdapterConfigInput memory bridgeAdapter
) external onlyOwnerOrGuardian {
ChainIdBridgeConfig[] memory destinationChainConfig = _bridgeAdaptersByChain[
bridgeAdapter.destinationChainId
];
require(
destinationChainConfig.length == 0,
Errors.ADAPTERS_ALREADY_ENABLED_FOR_DESTINATION_CHAIN
);
ForwarderBridgeAdapterConfigInput[]
memory bridgeAdapters = new ForwarderBridgeAdapterConfigInput[](1);
bridgeAdapters[0] = bridgeAdapter;

_enableBridgeAdapters(bridgeAdapters);
}

/**
* @notice internal method that has the logic to forward a transaction to the specified chain
* @param envelopeId the id of the envelope
Expand Down
25 changes: 25 additions & 0 deletions src/contracts/CrossChainReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ contract CrossChainReceiver is OwnableWithGuardian, ICrossChainReceiver {
_updateReceiverBridgeAdapters(bridgeAdaptersInput, true);
}

// TODO: not entirely sure if this method makes sense.
// Also could make sense to allow the full ReceiverBridgeAdapterConfigInput object in case we want to set an adapter
// for multiple new chains???
/// @inheritdoc ICrossChainReceiver
function allowInitialReceiverBridgeAdapter(
address bridgeAdapter,
uint256 chainId
) external onlyOwnerOrGuardian {
require(
_configurationsByChain[chainId].allowedBridgeAdapters.values().length == 0,
Errors.CHAIN_MUST_NOT_HAVE_ANY_RECEIVER_ADAPTER_SET
);

uint256[] memory chainIds = new uint256[](1);
chainIds[0] = chainId;
ReceiverBridgeAdapterConfigInput[]
memory bridgeAdaptersInput = new ReceiverBridgeAdapterConfigInput[](1);
bridgeAdaptersInput[0] = ReceiverBridgeAdapterConfigInput({
bridgeAdapter: bridgeAdapter,
chainIds: chainIds
});

_updateReceiverBridgeAdapters(bridgeAdaptersInput, true);
}

/// @inheritdoc ICrossChainReceiver
function disallowReceiverBridgeAdapters(
ReceiverBridgeAdapterConfigInput[] memory bridgeAdapters
Expand Down
9 changes: 9 additions & 0 deletions src/contracts/interfaces/ICrossChainForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ interface ICrossChainForwarder {
*/
function disableBridgeAdapters(BridgeAdapterToDisable[] memory bridgeAdapters) external;

/**
* @notice method to enable a bridge adapter for a network where no adapter is set yet
* @param bridgeAdapter object with the new bridge adapter configuration
* @dev only callable by guardian and owner
*/
function enableInitialBridgeAdapter(
ForwarderBridgeAdapterConfigInput memory bridgeAdapter
) external;

/**
* @notice method to remove sender addresses
* @param senders list of addresses to remove
Expand Down
8 changes: 8 additions & 0 deletions src/contracts/interfaces/ICrossChainReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,12 @@ interface ICrossChainReceiver {
function disallowReceiverBridgeAdapters(
ReceiverBridgeAdapterConfigInput[] memory bridgeAdaptersInput
) external;

/**
* @notice method to add a bridge adapter to the allowed list, for a chain with no current adapter set
* @param bridgeAdapter address of the bridge adapter to set
* @param chainId id of the chain that the bridge adapter will receive messages from
* @dev callable by guardian and owner
*/
function allowInitialReceiverBridgeAdapter(address bridgeAdapter, uint256 chainId) external;
}
2 changes: 2 additions & 0 deletions src/contracts/libs/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ library Errors {
string public constant CALLER_NOT_GNOSIS_ARBITRARY_MESSAGE_BRIDGE = '37'; // the caller must be the Gnosis AMB contract
string public constant ZERO_GNOSIS_ARBITRARY_MESSAGE_BRIDGE = '38'; // The passed Gnosis AMB contract is zero
string public constant CALLER_NOT_ZK_EVM_BRIDGE = '39'; // the caller must be the zk evm bridge
string public constant ADAPTERS_ALREADY_ENABLED_FOR_DESTINATION_CHAIN = '40'; // destination chain already has at least one adapter set, for communication
string public constant CHAIN_MUST_NOT_HAVE_ANY_RECEIVER_ADAPTER_SET = '41'; // there is already one adapter set, that can receive messages from origin chain
}
Loading