Skip to content

Commit

Permalink
Fix broken build (#83)
Browse files Browse the repository at this point in the history
* Fix broken build

* Address review comment

* Improve comment relating to bridge fees

* Refactor sender adapter updated event
  • Loading branch information
ermyas authored Sep 22, 2023
1 parent 12f460e commit 39bf2ad
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 63 deletions.
18 changes: 7 additions & 11 deletions src/MultiBridgeMessageSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ contract MultiBridgeMessageSender {
/// @param message is the message that failed to be sent
event MessageSendFailed(address indexed senderAdapter, MessageLibrary.Message message);

/// @notice is emitted when owner updates the sender adapter
/// @param senderAdapter the address of the sender adapter that was updated
/// @param add true if the sender adapter was added, false if it was removed
event SenderAdapterUpdated(address indexed senderAdapter, bool add);
/// @notice is emitted when owner updates the one or more sender adapters
/// @param senderAdapters the address of the sender adapters that were updated
/// @param add true if the sender adapters were added, false if they were removed
event SenderAdaptersUpdated(address[] indexed senderAdapters, bool add);

/*/////////////////////////////////////////////////////////////////
MODIFIERS
Expand Down Expand Up @@ -171,7 +171,8 @@ contract MultiBridgeMessageSender {
/// @param _nativeValue is the value to be sent to _target by low-level call (eg. address(_target).call{value: _nativeValue}(_callData))
/// @param _expiration refers to the number of seconds that a message remains valid before it is considered stale and can no longer be executed.
/// @param _refundAddress refers to the refund address for any extra native tokens paid
/// @param _fees refers to the fees to pay to each adapter
/// @param _fees refers to the fees to pay to each sender adapter that is not in the exclusion list specified by _excludedAdapters.
/// The fees are in the same order as the sender adapters in the senderAdapters list, after the exclusion list is applied.
/// @param _excludedAdapters are the sender adapters to be excluded from relaying the message, in ascending order by address
function remoteCall(
uint256 _dstChainId,
Expand Down Expand Up @@ -451,12 +452,7 @@ contract MultiBridgeMessageSender {
}

function _logSenderAdapterUpdates(address[] memory _updates, bool _add) private {
for (uint256 i = 0; i < _updates.length;) {
emit SenderAdapterUpdated(_updates[i], _add);
unchecked {
++i;
}
}
emit SenderAdaptersUpdated(_updates, _add);
}

/// @dev transfer ETH to an address, revert if it fails.
Expand Down
4 changes: 2 additions & 2 deletions test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ abstract contract Setup is Test {
vm.startPrank(owner);

address[] memory _senderAdapters = new address[](2);
_senderAdapters[0] = contractAddress[SRC_CHAIN_ID][bytes("WORMHOLE_SENDER_ADAPTER")];
_senderAdapters[1] = contractAddress[SRC_CHAIN_ID][bytes("AXELAR_SENDER_ADAPTER")];
_senderAdapters[0] = contractAddress[SRC_CHAIN_ID][bytes("AXELAR_SENDER_ADAPTER")];
_senderAdapters[1] = contractAddress[SRC_CHAIN_ID][bytes("WORMHOLE_SENDER_ADAPTER")];

MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).addSenderAdapters(_senderAdapters);

Expand Down
4 changes: 2 additions & 2 deletions test/integration-tests/GracePeriodExpiry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ contract GracePeriodExpiryTest is Setup {
uint256[] memory fees = new uint256[](2);
(uint256 wormholeFee,) =
IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(_wormholeChainId(DST_CHAIN_ID), 0, 0);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).remoteCall{value: 2 ether}(
DST_CHAIN_ID,
address(target),
Expand Down
4 changes: 2 additions & 2 deletions test/integration-tests/MultiMessageAggregation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ contract MultiBridgeMessageAggregationTest is Setup {
uint256[] memory fees = new uint256[](2);
(uint256 wormholeFee,) =
IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(_wormholeChainId(DST_CHAIN_ID), 0, 0);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).remoteCall{value: 2 ether}(
DST_CHAIN_ID,
address(target),
Expand Down
4 changes: 2 additions & 2 deletions test/integration-tests/RemoteAdapterAdd.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ contract RemoteAdapterAdd is Setup {
uint256[] memory fees = new uint256[](2);
(uint256 wormholeFee,) =
IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(_wormholeChainId(DST_CHAIN_ID), 0, 0);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).remoteCall{value: 2 ether}(
DST_CHAIN_ID,
address(contractAddress[DST_CHAIN_ID][bytes("MMA_RECEIVER")]),
Expand Down
4 changes: 2 additions & 2 deletions test/integration-tests/RemoteAdapterRemove.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ contract RemoteAdapterRemove is Setup {
uint256[] memory fees = new uint256[](2);
(uint256 wormholeFee,) =
IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(_wormholeChainId(DST_CHAIN_ID), 0, 0);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).remoteCall{value: 2 ether}(
DST_CHAIN_ID,
address(contractAddress[DST_CHAIN_ID][bytes("MMA_RECEIVER")]),
Expand Down
4 changes: 2 additions & 2 deletions test/integration-tests/RemoteSetQuorum.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ contract RemoteQuorumUpdate is Setup {
uint256[] memory fees = new uint256[](2);
(uint256 wormholeFee,) =
IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(_wormholeChainId(DST_CHAIN_ID), 0, 0);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[1] = wormholeFee;
fees[0] = 0.01 ether;
MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).remoteCall{value: 2 ether}(
DST_CHAIN_ID,
address(contractAddress[DST_CHAIN_ID][bytes("MMA_RECEIVER")]),
Expand Down
4 changes: 2 additions & 2 deletions test/integration-tests/RemoteTimelockUpdate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ contract RemoteTimelockUpdate is Setup {
uint256[] memory fees = new uint256[](2);
(uint256 wormholeFee,) =
IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(_wormholeChainId(DST_CHAIN_ID), 0, 0);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).remoteCall{value: 2 ether}(
POLYGON_CHAIN_ID,
address(contractAddress[POLYGON_CHAIN_ID][bytes("TIMELOCK")]),
Expand Down
4 changes: 2 additions & 2 deletions test/integration-tests/TimelockCheck.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ contract TimelockCheckTest is Setup {
uint256[] memory fees = new uint256[](2);
(uint256 wormholeFee,) =
IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(_wormholeChainId(DST_CHAIN_ID), 0, 0);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
MultiBridgeMessageSender(contractAddress[SRC_CHAIN_ID][bytes("MMA_SENDER")]).remoteCall{value: 2 ether}(
DST_CHAIN_ID,
address(target),
Expand Down
64 changes: 28 additions & 36 deletions test/unit-tests/MultiBridgeMessageSender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract MultiBridgeMessageSenderTest is Setup {
address[] senderAdapters,
bool[] adapterSuccess
);
event SenderAdapterUpdated(address indexed senderAdapter, bool add);
event SenderAdaptersUpdated(address[] indexed senderAdapters, bool add);
event MessageSendFailed(address indexed senderAdapter, MessageLibrary.Message message);

MultiBridgeMessageSender sender;
Expand Down Expand Up @@ -66,8 +66,8 @@ contract MultiBridgeMessageSenderTest is Setup {
vm.startPrank(caller);

address[] memory senderAdapters = new address[](2);
senderAdapters[0] = wormholeAdapterAddr;
senderAdapters[1] = axelarAdapterAddr;
senderAdapters[0] = axelarAdapterAddr;
senderAdapters[1] = wormholeAdapterAddr;

bool[] memory adapterSuccess = new bool[](2);
adapterSuccess[0] = true;
Expand All @@ -91,8 +91,8 @@ contract MultiBridgeMessageSenderTest is Setup {
(uint256 wormholeFee,) = IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(
_wormholeChainId(DST_CHAIN_ID), 0, senderGAC.getGlobalMsgDeliveryGasLimit()
);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;

vm.expectEmit(true, true, true, true, address(sender));
emit MultiBridgeMessageSent(
Expand Down Expand Up @@ -120,8 +120,8 @@ contract MultiBridgeMessageSenderTest is Setup {
(uint256 wormholeFee,) = IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice(
_wormholeChainId(DST_CHAIN_ID), 0, senderGAC.getGlobalMsgDeliveryGasLimit()
);
fees[0] = wormholeFee;
fees[1] = 0.01 ether;
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
sender.remoteCall{value: nativeValue}(
DST_CHAIN_ID, address(42), bytes("42"), 0, expiration, refundAddress, fees
);
Expand Down Expand Up @@ -342,8 +342,8 @@ contract MultiBridgeMessageSenderTest is Setup {

// Remove both adapters
address[] memory senderAdapters = new address[](2);
senderAdapters[0] = wormholeAdapterAddr;
senderAdapters[1] = axelarAdapterAddr;
senderAdapters[0] = axelarAdapterAddr;
senderAdapters[1] = wormholeAdapterAddr;

sender.removeSenderAdapters(senderAdapters);

Expand All @@ -367,8 +367,8 @@ contract MultiBridgeMessageSenderTest is Setup {

address[] memory senderAdapters = new address[](3);
senderAdapters[0] = failingAdapterAddr;
senderAdapters[1] = wormholeAdapterAddr;
senderAdapters[2] = axelarAdapterAddr;
senderAdapters[1] = axelarAdapterAddr;
senderAdapters[2] = wormholeAdapterAddr;

bool[] memory adapterSuccess = new bool[](3);
adapterSuccess[0] = false;
Expand All @@ -393,8 +393,8 @@ contract MultiBridgeMessageSenderTest is Setup {
_wormholeChainId(DST_CHAIN_ID), 0, senderGAC.getGlobalMsgDeliveryGasLimit()
);
fees[0] = 0.01 ether;
fees[1] = wormholeFee;
fees[2] = 0.01 ether;
fees[1] = 0.01 ether;
fees[2] = wormholeFee;

vm.expectEmit(true, true, true, true, address(sender));
emit MessageSendFailed(failingAdapterAddr, message);
Expand Down Expand Up @@ -439,35 +439,31 @@ contract MultiBridgeMessageSenderTest is Setup {
adapters[1] = address(43);

vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(address(42), true);
vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(address(43), true);
emit SenderAdaptersUpdated(adapters, true);

sender.addSenderAdapters(adapters);

assertEq(sender.senderAdapters(0), address(42));
assertEq(sender.senderAdapters(1), address(43));
assertEq(sender.senderAdapters(2), wormholeAdapterAddr);
assertEq(sender.senderAdapters(3), axelarAdapterAddr);
assertEq(sender.senderAdapters(2), axelarAdapterAddr);
assertEq(sender.senderAdapters(3), wormholeAdapterAddr);
}

/// @dev add to empty sender adapters
function test_add_sender_adapters_to_empty() public {
vm.startPrank(owner);

address[] memory removals = new address[](2);
removals[0] = wormholeAdapterAddr;
removals[1] = axelarAdapterAddr;
removals[0] = axelarAdapterAddr;
removals[1] = wormholeAdapterAddr;
sender.removeSenderAdapters(removals);

address[] memory additions = new address[](2);
additions[0] = address(42);
additions[1] = address(43);

vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(address(42), true);
vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(address(43), true);
emit SenderAdaptersUpdated(additions, true);

sender.addSenderAdapters(additions);

Expand All @@ -480,20 +476,18 @@ contract MultiBridgeMessageSenderTest is Setup {
vm.startPrank(owner);

address[] memory adapters = new address[](2);
address higherAddr0 = address(uint160(axelarAdapterAddr) + 1);
address higherAddr1 = address(uint160(axelarAdapterAddr) + 2);
address higherAddr0 = address(uint160(wormholeAdapterAddr) + 1);
address higherAddr1 = address(uint160(wormholeAdapterAddr) + 2);
adapters[0] = higherAddr0;
adapters[1] = higherAddr1;

vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(higherAddr0, true);
vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(higherAddr1, true);
emit SenderAdaptersUpdated(adapters, true);

sender.addSenderAdapters(adapters);

assertEq(sender.senderAdapters(0), wormholeAdapterAddr);
assertEq(sender.senderAdapters(1), axelarAdapterAddr);
assertEq(sender.senderAdapters(0), axelarAdapterAddr);
assertEq(sender.senderAdapters(1), wormholeAdapterAddr);
assertEq(sender.senderAdapters(2), higherAddr0);
assertEq(sender.senderAdapters(3), higherAddr1);
}
Expand Down Expand Up @@ -556,13 +550,11 @@ contract MultiBridgeMessageSenderTest is Setup {
vm.startPrank(owner);

address[] memory adapters = new address[](2);
adapters[0] = wormholeAdapterAddr;
adapters[1] = axelarAdapterAddr;
adapters[0] = axelarAdapterAddr;
adapters[1] = wormholeAdapterAddr;

vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(wormholeAdapterAddr, false);
vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(axelarAdapterAddr, false);
emit SenderAdaptersUpdated(adapters, false);

sender.removeSenderAdapters(adapters);

Expand All @@ -578,7 +570,7 @@ contract MultiBridgeMessageSenderTest is Setup {
adapters[0] = wormholeAdapterAddr;

vm.expectEmit(true, true, true, true, address(sender));
emit SenderAdapterUpdated(wormholeAdapterAddr, false);
emit SenderAdaptersUpdated(adapters, false);

sender.removeSenderAdapters(adapters);

Expand Down

0 comments on commit 39bf2ad

Please sign in to comment.