Skip to content

Commit

Permalink
Merge pull request #19 from bgd-labs/fix/refactor-adapter-gas-naming
Browse files Browse the repository at this point in the history
Fix/refactor adapter gas naming
  • Loading branch information
sendra authored Dec 19, 2023
2 parents 825b3f1 + e567f63 commit 629aa8a
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 87 deletions.
4 changes: 2 additions & 2 deletions scripts/contract_extensions/ArbitrumAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ contract ArbitrumAdapterTestnet is ArbAdapter {
address crossChainController,
address inbox,
address destinationCCC,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) ArbAdapter(crossChainController, inbox, destinationCCC, baseGasLimit, trustedRemotes) {}
) ArbAdapter(crossChainController, inbox, destinationCCC, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IArbAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/contract_extensions/CBAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ contract CBaseAdapterTestnet is CBaseAdapter {
constructor(
address crossChainController,
address ovmCrossDomainMessenger,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) CBaseAdapter(crossChainController, ovmCrossDomainMessenger, baseGasLimit, trustedRemotes) {}
) CBaseAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/contract_extensions/CCIPAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ contract CCIPAdapterTestnet is CCIPAdapter {
constructor(
address crossChainController,
address ccipRouter,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes,
address linkToken
) CCIPAdapter(crossChainController, ccipRouter, baseGasLimit, trustedRemotes, linkToken) {}
) CCIPAdapter(crossChainController, ccipRouter, providerGasLimit, trustedRemotes, linkToken) {}

/// @inheritdoc IBaseAdapter
function nativeToInfraChainId(uint256 nativeChainId) public pure override returns (uint256) {
Expand Down
9 changes: 7 additions & 2 deletions scripts/contract_extensions/GnosisChainAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ contract GnosisChainAdapterTestnet is GnosisChainAdapter {
constructor(
address crossChainController,
address arbitraryMessageBridge,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
)
GnosisChainAdapter(crossChainController, arbitraryMessageBridge, baseGasLimit, trustedRemotes)
GnosisChainAdapter(
crossChainController,
arbitraryMessageBridge,
providerGasLimit,
trustedRemotes
)
{}

function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/contract_extensions/LayerZeroAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ contract LayerZeroAdapterTestnet is LayerZeroAdapter {
constructor(
address lzEndpoint,
address crossChainController,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory originConfigs
) LayerZeroAdapter(lzEndpoint, crossChainController, baseGasLimit, originConfigs) {}
) LayerZeroAdapter(lzEndpoint, crossChainController, providerGasLimit, originConfigs) {}

/// @inheritdoc IBaseAdapter
function nativeToInfraChainId(uint256 nativeChainId) public pure override returns (uint256) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/contract_extensions/MetisAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ contract MetisAdapterTestnet is MetisAdapter {
constructor(
address crossChainController,
address ovmCrossDomainMessenger,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) MetisAdapter(crossChainController, ovmCrossDomainMessenger, baseGasLimit, trustedRemotes) {}
) MetisAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/contract_extensions/OptimismAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ contract OptimismAdapterTestnet is OpAdapter {
constructor(
address crossChainController,
address ovmCrossDomainMessenger,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) OpAdapter(crossChainController, ovmCrossDomainMessenger, baseGasLimit, trustedRemotes) {}
) OpAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/contract_extensions/PolygonAdapterTestnets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ contract PolygonAdapterMumbai is PolygonAdapterBase {
constructor(
address crossChainController,
address fxTunnel,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) PolygonAdapterBase(crossChainController, fxTunnel, baseGasLimit, trustedRemotes) {}
) PolygonAdapterBase(crossChainController, fxTunnel, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IPolygonAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand All @@ -38,9 +38,9 @@ contract PolygonAdapterGoerli is PolygonAdapterBase {
constructor(
address crossChainController,
address fxTunnel,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) PolygonAdapterBase(crossChainController, fxTunnel, baseGasLimit, trustedRemotes) {}
) PolygonAdapterBase(crossChainController, fxTunnel, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IPolygonAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/contract_extensions/ZkEVMAdapterTestnets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ contract ZkEVMAdapterGoerli is ZkEVMAdapter {
constructor(
address crossChainController,
address zkEVMBridge,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) ZkEVMAdapter(crossChainController, zkEVMBridge, baseGasLimit, trustedRemotes) {}
) ZkEVMAdapter(crossChainController, zkEVMBridge, providerGasLimit, trustedRemotes) {}

function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
return chainId == TestNetChainIds.POLYGON_ZK_EVM_GOERLI;
Expand Down Expand Up @@ -39,9 +39,9 @@ contract ZkEVMAdapterZkEVMGoerli is ZkEVMAdapter {
constructor(
address crossChainController,
address zkEVMBridge,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) ZkEVMAdapter(crossChainController, zkEVMBridge, baseGasLimit, trustedRemotes) {}
) ZkEVMAdapter(crossChainController, zkEVMBridge, providerGasLimit, trustedRemotes) {}

function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
return chainId == TestNetChainIds.ETHEREUM_GOERLI;
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/adapters/BaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ abstract contract BaseAdapter is IBaseAdapter {

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

BASE_GAS_LIMIT = baseGasLimit;
BASE_GAS_LIMIT = providerGasLimit;

_selfAddress = address(this);

Expand Down
4 changes: 2 additions & 2 deletions src/contracts/adapters/IBaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ interface IBaseAdapter {
/**
* @notice method that will bridge the payload to the chain specified
* @param receiver address of the receiver contract on destination chain
* @param messageDeliveryGasLimit amount of the gas limit in wei to use for delivering the message on destination network.
* @param executionGasLimit amount of the gas limit in wei to use for delivering the message on destination network.
Each adapter will manage this as needed.
* @param destinationChainId id of the destination chain in the bridge notation
* @param message to send to the specified chain
* @return the third-party bridge entrypoint, the third-party bridge message id
*/
function forwardMessage(
address receiver,
uint256 messageDeliveryGasLimit,
uint256 executionGasLimit,
uint256 destinationChainId,
bytes calldata message
) external returns (address, uint256);
Expand Down
14 changes: 7 additions & 7 deletions src/contracts/adapters/arbitrum/ArbAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ contract ArbAdapter is IArbAdapter, BaseAdapter {
/**
* @param crossChainController address of the cross chain controller that will use this bridge adapter
* @param inbox arbitrum entry point address
* @param baseGasLimit base gas limit used by the bridge adapter
* @param providerGasLimit base gas limit used by the bridge adapter
* @param trustedRemotes list of remote configurations to set as trusted
*/
constructor(
address crossChainController,
address inbox,
address destinationCCC,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, baseGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
INBOX = inbox;
DESTINATION_CCC = destinationCCC;
}
Expand All @@ -60,7 +60,7 @@ contract ArbAdapter is IArbAdapter, BaseAdapter {
/// @inheritdoc IBaseAdapter
function forwardMessage(
address receiver,
uint256 messageDeliveryGasLimit,
uint256 executionGasLimit,
uint256 destinationChainId,
bytes calldata message
) external returns (address, uint256) {
Expand All @@ -72,13 +72,13 @@ contract ArbAdapter is IArbAdapter, BaseAdapter {

bytes memory data = abi.encodeWithSelector(IArbAdapter.arbReceive.selector, message);

uint256 totalGasLimit = messageDeliveryGasLimit + BASE_GAS_LIMIT;
uint256 totalGasLimit = executionGasLimit + BASE_GAS_LIMIT;

(uint256 maxSubmission, uint256 maxRedemption) = getRequiredGas(data.length, totalGasLimit);
uint256 ticketID = _forwardMessage(
MessageInformation({
receiver: receiver,
messageDeliveryGasLimit: totalGasLimit,
executionGasLimit: totalGasLimit,
encodedMessage: data,
maxSubmission: maxSubmission,
maxRedemption: maxRedemption
Expand Down Expand Up @@ -136,7 +136,7 @@ contract ArbAdapter is IArbAdapter, BaseAdapter {
message.maxSubmission,
DESTINATION_CCC,
DESTINATION_CCC,
message.messageDeliveryGasLimit,
message.executionGasLimit,
L2_MAX_FEE_PER_GAS,
message.encodedMessage
);
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/adapters/arbitrum/IArbAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ interface IArbAdapter {
/**
* @notice object used to store the message information
* @param receiver address that will receive the message
* @param messageDeliveryGasLimit max gas limit to be used on destination chain
* @param executionGasLimit max gas limit to be used on destination chain
* @param maxSubmission gas required for ticket submission
* @param maxRedemption gas required for ticket redemption
* @param encodedMessage calldata used on destination chain
*/
struct MessageInformation {
address receiver;
uint256 messageDeliveryGasLimit;
uint256 executionGasLimit;
uint256 maxSubmission;
uint256 maxRedemption;
bytes encodedMessage;
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/adapters/cBase/CBaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ contract CBaseAdapter is OpAdapter {
/**
* @param crossChainController address of the cross chain controller that will use this bridge adapter
* @param ovmCrossDomainMessenger optimism entry point address
* @param baseGasLimit base gas limit used by the bridge adapter
* @param providerGasLimit base gas limit used by the bridge adapter
* @param trustedRemotes list of remote configurations to set as trusted
*/
constructor(
address crossChainController,
address ovmCrossDomainMessenger,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) OpAdapter(crossChainController, ovmCrossDomainMessenger, baseGasLimit, trustedRemotes) {}
) OpAdapter(crossChainController, ovmCrossDomainMessenger, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IOpAdapter
function isDestinationChainIdSupported(
Expand Down
10 changes: 5 additions & 5 deletions src/contracts/adapters/ccip/CCIPAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ contract CCIPAdapter is ICCIPAdapter, BaseAdapter, IAny2EVMMessageReceiver, IERC
/**
* @param crossChainController address of the cross chain controller that will use this bridge adapter
* @param ccipRouter ccip entry point address
* @param baseGasLimit base gas limit used by the bridge adapter
* @param providerGasLimit base gas limit used by the bridge adapter
* @param trustedRemotes list of remote configurations to set as trusted
* @param linkToken address of the erc20 LINK token
*/
constructor(
address crossChainController,
address ccipRouter,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes,
address linkToken
) BaseAdapter(crossChainController, baseGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, 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 All @@ -66,15 +66,15 @@ contract CCIPAdapter is ICCIPAdapter, BaseAdapter, IAny2EVMMessageReceiver, IERC
/// @inheritdoc IBaseAdapter
function forwardMessage(
address receiver,
uint256 messageDeliveryGasLimit,
uint256 executionGasLimit,
uint256 destinationChainId,
bytes calldata message
) external returns (address, uint256) {
uint64 nativeChainId = SafeCast.toUint64(infraToNativeChainId(destinationChainId));
require(CCIP_ROUTER.isChainSupported(nativeChainId), Errors.DESTINATION_CHAIN_ID_NOT_SUPPORTED);
require(receiver != address(0), Errors.RECEIVER_NOT_SET);

uint256 totalGasLimit = messageDeliveryGasLimit + BASE_GAS_LIMIT;
uint256 totalGasLimit = executionGasLimit + BASE_GAS_LIMIT;

Client.EVMExtraArgsV1 memory evmExtraArgs = Client.EVMExtraArgsV1({
gasLimit: totalGasLimit,
Expand Down
10 changes: 5 additions & 5 deletions src/contracts/adapters/gnosisChain/GnosisChainAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ contract GnosisChainAdapter is BaseAdapter, IGnosisChainAdapter {
/**
* @param crossChainController address of the cross chain controller that will use this bridge adapter
* @param arbitraryMessageBridge The Gnosis AMB contract
* @param baseGasLimit base gas limit used by the bridge adapter
* @param providerGasLimit base gas limit used by the bridge adapter
* @param trustedRemotes list of remote configurations to set as trusted
*/
constructor(
address crossChainController,
address arbitraryMessageBridge,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, baseGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
require(arbitraryMessageBridge != address(0), Errors.ZERO_GNOSIS_ARBITRARY_MESSAGE_BRIDGE);
BRIDGE = arbitraryMessageBridge;
}

/// @inheritdoc IBaseAdapter
function forwardMessage(
address receiver,
uint256 messageDeliveryGasLimit,
uint256 executionGasLimit,
uint256 destinationChainId,
bytes calldata message
) external override returns (address, uint256) {
Expand All @@ -50,7 +50,7 @@ contract GnosisChainAdapter is BaseAdapter, IGnosisChainAdapter {

bytes memory data = abi.encodeWithSelector(this.receiveMessage.selector, message);

uint256 totalGasLimit = messageDeliveryGasLimit + BASE_GAS_LIMIT;
uint256 totalGasLimit = executionGasLimit + BASE_GAS_LIMIT;

IArbitraryMessageBridge(BRIDGE).requireToPassMessage(receiver, data, totalGasLimit);
return (address(BRIDGE), 0);
Expand Down
10 changes: 5 additions & 5 deletions src/contracts/adapters/hyperLane/HyperLaneAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ contract HyperLaneAdapter is BaseAdapter, IHyperLaneAdapter, IMessageRecipient {
* @param crossChainController address of the cross chain controller that will use this bridge adapter
* @param mailBox HyperLane router contract address to send / receive cross chain messages
* @param igp HyperLane contract to get the gas estimation to pay for sending messages
* @param baseGasLimit base gas limit used by the bridge adapter
* @param providerGasLimit base gas limit used by the bridge adapter
* @param trustedRemotes list of remote configurations to set as trusted
*/
constructor(
address crossChainController,
address mailBox,
address igp,
uint256 baseGasLimit,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) BaseAdapter(crossChainController, baseGasLimit, trustedRemotes) {
) BaseAdapter(crossChainController, providerGasLimit, trustedRemotes) {
HL_MAIL_BOX = IMailbox(mailBox);
IGP = IInterchainGasPaymaster(igp);
}

/// @inheritdoc IBaseAdapter
function forwardMessage(
address receiver,
uint256 messageDeliveryGasLimit,
uint256 executionGasLimit,
uint256 destinationChainId,
bytes calldata message
) external returns (address, uint256) {
Expand All @@ -64,7 +64,7 @@ contract HyperLaneAdapter is BaseAdapter, IHyperLaneAdapter, IMessageRecipient {
message
);

uint256 totalGasLimit = messageDeliveryGasLimit + BASE_GAS_LIMIT;
uint256 totalGasLimit = executionGasLimit + BASE_GAS_LIMIT;

// Get the required payment from the IGP.
uint256 quotedPayment = IGP.quoteGasPayment(nativeChainId, totalGasLimit);
Expand Down
Loading

0 comments on commit 629aa8a

Please sign in to comment.