Skip to content

Commit

Permalink
Refactor and cleanup of adapter events
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Sep 21, 2023
1 parent bef8f4c commit 8ec831b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
8 changes: 7 additions & 1 deletion src/adapters/BaseSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ 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;
}
}
}

/// @inheritdoc IMessageSenderAdapter
function getReceiverAdapter(uint256 _dstChainId) external view override returns (address) {
return receiverAdapters[_dstChainId];
}

/*/////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
////////////////////////////////////////////////////////////////*/
Expand Down
2 changes: 0 additions & 2 deletions src/adapters/axelar/AxelarReceiverAdapter.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 0 additions & 2 deletions src/adapters/axelar/AxelarSenderAdapter.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
20 changes: 10 additions & 10 deletions src/interfaces/IMultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/interfaces/adapters/IMessageSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
1 change: 0 additions & 1 deletion test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 7 additions & 6 deletions test/unit-tests/adapters/BaseSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 8ec831b

Please sign in to comment.