From 8ec831b10320ad9c9044e1d502acbe4c1731d0f5 Mon Sep 17 00:00:00 2001 From: Ermyas Abebe Date: Thu, 21 Sep 2023 17:15:19 +1000 Subject: [PATCH] Refactor and cleanup of adapter events --- src/adapters/BaseSenderAdapter.sol | 8 +++++++- src/adapters/axelar/AxelarReceiverAdapter.sol | 2 -- src/adapters/axelar/AxelarSenderAdapter.sol | 2 -- .../IMultiBridgeMessageReceiver.sol | 20 +++++++++---------- .../adapters/IMessageSenderAdapter.sol | 14 ++++++++++--- test/Setup.t.sol | 1 - .../adapters/BaseSenderAdapter.t.sol | 13 ++++++------ 7 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/adapters/BaseSenderAdapter.sol b/src/adapters/BaseSenderAdapter.sol index 101b995..1a76a4a 100644 --- a/src/adapters/BaseSenderAdapter.sol +++ b/src/adapters/BaseSenderAdapter.sol @@ -62,8 +62,9 @@ abstract contract BaseSenderAdapter is IMessageSenderAdapter { } for (uint256 i; i < arrLength;) { + address oldReceiver = receiverAdapters[_dstChainIds[i]]; receiverAdapters[_dstChainIds[i]] = _receiverAdapters[i]; - emit ReceiverAdapterUpdated(_dstChainIds[i], _receiverAdapters[i]); + emit ReceiverAdapterUpdated(_dstChainIds[i], oldReceiver, _receiverAdapters[i]); unchecked { ++i; @@ -71,6 +72,11 @@ abstract contract BaseSenderAdapter is IMessageSenderAdapter { } } + /// @inheritdoc IMessageSenderAdapter + function getReceiverAdapter(uint256 _dstChainId) external view override returns (address) { + return receiverAdapters[_dstChainId]; + } + /*///////////////////////////////////////////////////////////////// HELPER FUNCTIONS ////////////////////////////////////////////////////////////////*/ diff --git a/src/adapters/axelar/AxelarReceiverAdapter.sol b/src/adapters/axelar/AxelarReceiverAdapter.sol index 80b06a7..c9e4ded 100644 --- a/src/adapters/axelar/AxelarReceiverAdapter.sol +++ b/src/adapters/axelar/AxelarReceiverAdapter.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.8.9; -import "forge-std/console.sol"; - /// local imports import "../../interfaces/adapters/IMessageReceiverAdapter.sol"; import "../../interfaces/IMultiBridgeMessageReceiver.sol"; diff --git a/src/adapters/axelar/AxelarSenderAdapter.sol b/src/adapters/axelar/AxelarSenderAdapter.sol index c32c1f9..dbe8001 100644 --- a/src/adapters/axelar/AxelarSenderAdapter.sol +++ b/src/adapters/axelar/AxelarSenderAdapter.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.8.9; -import "forge-std/console.sol"; - /// local imports import "../BaseSenderAdapter.sol"; import "../../interfaces/controllers/IGAC.sol"; diff --git a/src/interfaces/IMultiBridgeMessageReceiver.sol b/src/interfaces/IMultiBridgeMessageReceiver.sol index 11a94ce..bbff20e 100644 --- a/src/interfaces/IMultiBridgeMessageReceiver.sol +++ b/src/interfaces/IMultiBridgeMessageReceiver.sol @@ -19,16 +19,6 @@ interface IMultiBridgeMessageReceiver { uint256 expiration; } - /// @notice emitted when receiver adapter of a specific bridge is updated - /// @param receiverAdapter is the new receiver adapter address - /// @param add is true if the receiver adapter was added, false if removed - event BridgeReceiverAdapterUpdated(address indexed receiverAdapter, bool add); - - /// @notice emitted when the quorum for message validity is updated - /// @param oldQuorum is the old quorum value - /// @param newQuorum is the new quorum value - event QuorumUpdated(uint64 oldQuorum, uint64 newQuorum); - /// @notice emitted when a message has been received from a single bridge /// @param msgId is the unique identifier of the message /// @param bridgeName is the name of the bridge from which the message was received @@ -48,6 +38,16 @@ interface IMultiBridgeMessageReceiver { bytes32 indexed msgId, address indexed target, uint256 nativeValue, uint256 nonce, bytes callData ); + /// @notice emitted when receiver adapter of a specific bridge is updated + /// @param receiverAdapter is the new receiver adapter address + /// @param add is true if the receiver adapter was added, false if removed + event BridgeReceiverAdapterUpdated(address indexed receiverAdapter, bool add); + + /// @notice emitted when the quorum for message validity is updated + /// @param oldQuorum is the old quorum value + /// @param newQuorum is the new quorum value + event QuorumUpdated(uint64 oldQuorum, uint64 newQuorum); + /// @notice Receive messages from allowed bridge receiver adapters. /// @dev Every receiver adapter should call this function with decoded MessageLibrary.Message /// @param _message is the message to be received diff --git a/src/interfaces/adapters/IMessageSenderAdapter.sol b/src/interfaces/adapters/IMessageSenderAdapter.sol index 9aae195..23d8e27 100644 --- a/src/interfaces/adapters/IMessageSenderAdapter.sol +++ b/src/interfaces/adapters/IMessageSenderAdapter.sol @@ -8,8 +8,9 @@ import "../EIP5164/SingleMessageDispatcher.sol"; interface IMessageSenderAdapter is SingleMessageDispatcher { /// @notice emitted when a the sender's corresponding receiver adapter on a remote chain is changed /// @param dstChainId is the destination chain for which the receiver adapter is updated - /// @param receiverAdapter is the new receiver adapter address - event ReceiverAdapterUpdated(uint256 indexed dstChainId, address indexed receiverAdapter); + /// @param oldReceiver is the old receiver adapter address + /// @param newReceiver is the new receiver adapter address + event ReceiverAdapterUpdated(uint256 indexed dstChainId, address indexed oldReceiver, address indexed newReceiver); /// @notice allows owner to update the receiver adapters on different destination chains /// @param _dstChainIds are the destination chain IDs for which the receiver adapters are to be updated @@ -19,6 +20,13 @@ interface IMessageSenderAdapter is SingleMessageDispatcher { /// @notice returns name of the message bridge wrapped by the adapter function name() external view returns (string memory); - /// @notice return native token amount in wei required by this message bridge for sending a message + /// @notice return the fee (in native token wei) that would be charged by the bridge for the provided remote call + /// @param _toChainId is the destination chain id + /// @param _to is the destination address on the destination chain + /// @param _data is the data to be sent to the destination chain function getMessageFee(uint256 _toChainId, address _to, bytes calldata _data) external view returns (uint256); + + /// @notice returns the bridge receiver adapter address for a given destination chain id + /// @param _chainId is the destination chain whose receiver adapter address is to be returned + function getReceiverAdapter(uint256 _chainId) external view returns (address); } diff --git a/test/Setup.t.sol b/test/Setup.t.sol index 7a26e95..8e60dc3 100644 --- a/test/Setup.t.sol +++ b/test/Setup.t.sol @@ -3,7 +3,6 @@ pragma solidity >=0.8.9; /// library imports import {Test, Vm} from "forge-std/Test.sol"; -import "forge-std/console.sol"; /// @dev imports from Pigeon Helper (Facilitate State Transfer Mocks) import {WormholeHelper} from "pigeon/wormhole/WormholeHelper.sol"; diff --git a/test/unit-tests/adapters/BaseSenderAdapter.t.sol b/test/unit-tests/adapters/BaseSenderAdapter.t.sol index f157c7e..c977a86 100644 --- a/test/unit-tests/adapters/BaseSenderAdapter.t.sol +++ b/test/unit-tests/adapters/BaseSenderAdapter.t.sol @@ -8,12 +8,13 @@ import {Vm} from "forge-std/Test.sol"; import "../../Setup.t.sol"; import "src/libraries/Error.sol"; import {AxelarSenderAdapter} from "src/adapters/axelar/AxelarSenderAdapter.sol"; +import {BaseSenderAdapter} from "src/adapters/BaseSenderAdapter.sol"; contract AxelarSenderAdapterTest is Setup { - event ReceiverAdapterUpdated(uint256 indexed dstChainId, address indexed receiverAdapter); + event ReceiverAdapterUpdated(uint256 indexed dstChainId, address indexed oldReceiver, address indexed newReceiver); // Test base contract with Axelar adapter - AxelarSenderAdapter adapter; + BaseSenderAdapter adapter; /// @dev initializes the setup function setUp() public override { @@ -32,14 +33,14 @@ contract AxelarSenderAdapterTest is Setup { receiverAdapters[1] = address(43); vm.expectEmit(true, true, true, true, address(adapter)); - emit ReceiverAdapterUpdated(BSC_CHAIN_ID, address(42)); + emit ReceiverAdapterUpdated(BSC_CHAIN_ID, adapter.getReceiverAdapter(BSC_CHAIN_ID), address(42)); vm.expectEmit(true, true, true, true, address(adapter)); - emit ReceiverAdapterUpdated(POLYGON_CHAIN_ID, address(43)); + emit ReceiverAdapterUpdated(POLYGON_CHAIN_ID, adapter.getReceiverAdapter(POLYGON_CHAIN_ID), address(43)); adapter.updateReceiverAdapter(DST_CHAINS, receiverAdapters); - assertEq(adapter.receiverAdapters(BSC_CHAIN_ID), address(42)); - assertEq(adapter.receiverAdapters(POLYGON_CHAIN_ID), address(43)); + assertEq(adapter.getReceiverAdapter(BSC_CHAIN_ID), address(42)); + assertEq(adapter.getReceiverAdapter(POLYGON_CHAIN_ID), address(43)); } /// @dev only global owner can update receiver adapter