Skip to content

Commit

Permalink
merge FeePaid event into CCIPMessageSent
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanRHall committed Sep 19, 2024
1 parent 97f6f55 commit e041123
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
12 changes: 7 additions & 5 deletions contracts/src/v0.8/ccip/onRamp/OnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ contract OnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCreator {
event DestChainConfigSet(
uint64 indexed destChainSelector, uint64 sequenceNumber, IRouter router, bool allowListEnabled
);
event FeePaid(address indexed feeToken, uint256 feeValueJuels);
event FeeTokenWithdrawn(address indexed feeAggregator, address indexed feeToken, uint256 amount);
/// RMN depends on this event, if changing, please notify the RMN maintainers.
event CCIPMessageSent(uint64 indexed destChainSelector, Internal.EVM2AnyRampMessage message);
event CCIPMessageSent(
uint64 indexed destChainSelector,
address indexed feeToken,
uint256 feeValueJuels,
Internal.EVM2AnyRampMessage message
);
event AllowListAdminSet(address indexed allowListAdmin);
event AllowListSendersAdded(uint64 indexed destChainSelector, address[] senders);
event AllowListSendersRemoved(uint64 indexed destChainSelector, address[] senders);
Expand Down Expand Up @@ -233,8 +237,6 @@ contract OnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCreator {
destChainSelector, message.feeToken, feeTokenAmount, message.extraArgs, newMessage.tokenAmounts, tokenAmounts
);

emit FeePaid(message.feeToken, msgFeeJuels);

newMessage.header.nonce = isOutOfOrderExecution
? 0
: INonceManager(i_nonceManager).getIncrementedOutboundNonce(destChainSelector, originalSender);
Expand All @@ -255,7 +257,7 @@ contract OnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCreator {
// Emit message request
// This must happen after any pool events as some tokens (e.g. USDC) emit events that we expect to precede this
// event in the offchain code.
emit CCIPMessageSent(destChainSelector, newMessage);
emit CCIPMessageSent(destChainSelector, message.feeToken, msgFeeJuels, newMessage);

s_dynamicConfig.reentrancyGuardEntered = false;

Expand Down
16 changes: 12 additions & 4 deletions contracts/src/v0.8/ccip/test/NonceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ contract NonceManager_OnRampUpgrade is OnRampSetup {
Client.EVM2AnyMessage memory message = _generateEmptyMessage();

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, FEE_AMOUNT, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, FEE_AMOUNT, _messageToEvent(message, 1, 1, FEE_AMOUNT, OWNER)
);
s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, FEE_AMOUNT, OWNER);
}

Expand All @@ -292,14 +294,18 @@ contract NonceManager_OnRampUpgrade is OnRampSetup {

// new onramp nonce should start from 2, while sequence number start from 1
vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, startNonce + 2, FEE_AMOUNT, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, FEE_AMOUNT, _messageToEvent(message, 1, startNonce + 2, FEE_AMOUNT, OWNER)
);
s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, FEE_AMOUNT, OWNER);

assertEq(startNonce + 2, s_outboundNonceManager.getOutboundNonce(DEST_CHAIN_SELECTOR, OWNER));

// after another send, nonce should be 3, and sequence number be 2
vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 2, startNonce + 3, FEE_AMOUNT, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, FEE_AMOUNT, _messageToEvent(message, 2, startNonce + 3, FEE_AMOUNT, OWNER)
);
s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, FEE_AMOUNT, OWNER);

assertEq(startNonce + 3, s_outboundNonceManager.getOutboundNonce(DEST_CHAIN_SELECTOR, OWNER));
Expand All @@ -314,7 +320,9 @@ contract NonceManager_OnRampUpgrade is OnRampSetup {
address newSender = address(1234567);
// new onramp nonce should start from 1 for new sender
vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, FEE_AMOUNT, newSender));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, FEE_AMOUNT, _messageToEvent(message, 1, 1, FEE_AMOUNT, newSender)
);
s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, FEE_AMOUNT, newSender);
}
}
Expand Down
6 changes: 4 additions & 2 deletions contracts/src/v0.8/ccip/test/e2e/MultiRampsEnd2End.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,23 @@ contract MultiRampsE2E is OnRampSetup, OffRampSetup {
IERC20(s_sourceTokens[0]).approve(address(router), i_tokenAmount0 + router.getFee(DEST_CHAIN_SELECTOR, message));
IERC20(s_sourceTokens[1]).approve(address(router), i_tokenAmount1);

uint256 feeAmount = router.getFee(DEST_CHAIN_SELECTOR, message);

message.receiver = abi.encode(address(s_receiver));
Internal.EVM2AnyRampMessage memory msgEvent = _messageToEvent(
message,
sourceChainSelector,
DEST_CHAIN_SELECTOR,
expectedSeqNum,
nonce,
router.getFee(DEST_CHAIN_SELECTOR, message),
feeAmount,
OWNER,
metadataHash,
tokenAdminRegistry
);

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, msgEvent);
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, msgEvent);

vm.resumeGasMetering();
router.ccipSend(DEST_CHAIN_SELECTOR, message);
Expand Down
50 changes: 35 additions & 15 deletions contracts/src/v0.8/ccip/test/onRamp/OnRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, feeAmount, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
Expand Down Expand Up @@ -181,7 +183,9 @@ contract OnRamp_forwardFromRouter is OnRampSetup {

vm.expectEmit();
// We expect the message to be emitted with strict = false.
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, feeAmount, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
Expand All @@ -194,7 +198,9 @@ contract OnRamp_forwardFromRouter is OnRampSetup {

vm.expectEmit();
// We expect the message to be emitted with strict = false.
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, feeAmount, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
Expand All @@ -206,7 +212,9 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, feeAmount, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
Expand All @@ -220,7 +228,9 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, feeAmount, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
Expand All @@ -234,7 +244,9 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, feeAmount, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
Expand All @@ -247,7 +259,7 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
uint64 sequenceNumberBefore = s_onRamp.getExpectedNextSequenceNumber(DEST_CHAIN_SELECTOR) - 1;

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, i, i, 0, OWNER));
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, s_sourceFeeToken, 0, _messageToEvent(message, i, i, 0, OWNER));

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, 0, OWNER);

Expand All @@ -269,7 +281,7 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
uint64 sequenceNumberBefore = s_onRamp.getExpectedNextSequenceNumber(DEST_CHAIN_SELECTOR) - 1;

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, i, i, 0, OWNER));
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, s_sourceFeeToken, 0, _messageToEvent(message, i, i, 0, OWNER));

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, 0, OWNER);

Expand All @@ -287,7 +299,10 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
IERC20(s_sourceFeeToken).transferFrom(OWNER, address(s_onRamp), feeAmount);

vm.expectEmit();
emit OnRamp.FeePaid(s_sourceFeeToken, feeAmount);
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);

assertEq(IERC20(s_sourceFeeToken).balanceOf(address(s_onRamp)), feeAmount);
Expand All @@ -307,7 +322,10 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
uint256 expectedJuels = (feeAmount * conversionRate) / 1e18;

vm.expectEmit();
emit OnRamp.FeePaid(s_sourceTokens[1], expectedJuels);
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceTokens[1], expectedJuels, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);

assertEq(IERC20(s_sourceTokens[1]).balanceOf(address(s_onRamp)), feeAmount);
Expand Down Expand Up @@ -351,10 +369,10 @@ contract OnRamp_forwardFromRouter is OnRampSetup {

Internal.EVM2AnyRampMessage memory expectedEvent = _messageToEvent(message, 1, 1, feeTokenAmount, originalSender);

vm.expectEmit();
emit OnRamp.FeePaid(s_sourceFeeToken, feeTokenAmount);
vm.expectEmit(false, false, false, true);
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, expectedEvent);
// vm.expectEmit();
// emit OnRamp.FeePaid(s_sourceFeeToken, feeTokenAmount);
// vm.expectEmit(false, false, false, true);
// emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, expectedEvent);

// Assert the message Id is correct
assertEq(
Expand All @@ -376,7 +394,9 @@ contract OnRamp_forwardFromRouter is OnRampSetup {
s_outboundmessageInterceptor.setMessageIdValidationState(keccak256(abi.encode(message)), false);

vm.expectEmit();
emit OnRamp.CCIPMessageSent(DEST_CHAIN_SELECTOR, _messageToEvent(message, 1, 1, feeAmount, OWNER));
emit OnRamp.CCIPMessageSent(
DEST_CHAIN_SELECTOR, s_sourceFeeToken, feeAmount, _messageToEvent(message, 1, 1, feeAmount, OWNER)
);

s_onRamp.forwardFromRouter(DEST_CHAIN_SELECTOR, message, feeAmount, OWNER);
}
Expand Down

0 comments on commit e041123

Please sign in to comment.