Skip to content

Commit

Permalink
attempted bug fix of CCIPClient fee-token allowance when pre-funding
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweintraub committed Jul 15, 2024
1 parent 9d6199b commit a54d2de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
20 changes: 10 additions & 10 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 243568)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 24260)
CCIPClientTest:test_HappyPath_Success() (gas: 192504)
CCIPClientTest:test_ccipSend_withNonNativeFeetoken_andDestTokens_Success() (gas: 325792)
CCIPClientTest:test_ccipSend_withNonNativeFeetoken_andNoDestTokens_Success() (gas: 218834)
CCIPClientTest:test_ccipSend_with_NativeFeeToken_andDestTokens_Success() (gas: 376797)
CCIPClientTest:test_ccipSend_withNonNativeFeetoken_andDestTokens_Success() (gas: 326914)
CCIPClientTest:test_ccipSend_withNonNativeFeetoken_andNoDestTokens_Success() (gas: 219955)
CCIPClientTest:test_ccipSend_with_NativeFeeToken_andDestTokens_Success() (gas: 376823)
CCIPClientTest:test_modifyFeeToken_Success() (gas: 74452)
CCIPClientWithACKTest:test_ccipReceiveAndSendAck_Success() (gas: 331795)
CCIPClientWithACKTest:test_ccipReceiver_ack_with_invalidAckMessageHeaderBytes_Revert() (gas: 438714)
Expand Down Expand Up @@ -703,10 +703,10 @@ OCR2Base_transmit:test_UnAuthorizedTransmitter_Revert() (gas: 23484)
OCR2Base_transmit:test_UnauthorizedSigner_Revert() (gas: 39665)
OCR2Base_transmit:test_WrongNumberOfSignatures_Revert() (gas: 20557)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 380711)
PingPong_example_ccipReceive:test_CcipReceive_Success() (gas: 307328)
PingPong_example_plumbing:test_Pausing_Success() (gas: 17943)
PingPong_example_plumbing:test_typeAndVersion() (gas: 9745)
PingPong_example_startPingPong:test_StartPingPong_Success() (gas: 234270)
PingPong_example_ccipReceive:test_CcipReceive_Success() (gas: 179553)
PingPong_example_plumbing:test_Pausing_Success() (gas: 17917)
PingPong_example_plumbing:test_typeAndVersion() (gas: 9786)
PingPong_example_startPingPong:test_StartPingPong_Success() (gas: 203446)
PriceRegistry_applyFeeTokensUpdates:test_ApplyFeeTokensUpdates_Success() (gas: 79823)
PriceRegistry_applyFeeTokensUpdates:test_OnlyCallableByOwner_Revert() (gas: 12580)
PriceRegistry_constructor:test_InvalidStalenessThreshold_Revert() (gas: 67418)
Expand Down Expand Up @@ -853,9 +853,9 @@ Router_routeMessage:test_ManualExec_Success() (gas: 35381)
Router_routeMessage:test_OnlyOffRamp_Revert() (gas: 25116)
Router_routeMessage:test_WhenNotHealthy_Revert() (gas: 44724)
Router_setWrappedNative:test_OnlyOwner_Revert() (gas: 10985)
SelfFundedPingPong_ccipReceive:test_FundingIfNotANop_Revert() (gas: 289627)
SelfFundedPingPong_ccipReceive:test_Funding_Success() (gas: 448499)
SelfFundedPingPong_setCountIncrBeforeFunding:test_setCountIncrBeforeFunding() (gas: 20203)
SelfFundedPingPong_ccipReceive:test_FundingIfNotANop_Revert() (gas: 291579)
SelfFundedPingPong_ccipReceive:test_Funding_Success() (gas: 448569)
SelfFundedPingPong_setCountIncrBeforeFunding:test_setCountIncrBeforeFunding() (gas: 20273)
TokenAdminRegistry_acceptAdminRole:test_acceptAdminRole_OnlyPendingAdministrator_Revert() (gas: 51085)
TokenAdminRegistry_acceptAdminRole:test_acceptAdminRole_Success() (gas: 43947)
TokenAdminRegistry_addRegistryModule:test_addRegistryModule_OnlyOwner_Revert() (gas: 12629)
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/v0.8/ccip/applications/external/CCIPClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract CCIPClient is CCIPReceiver {
uint256 fee = IRouterClient(s_ccipRouter).getFee(destChainSelector, message);

// Additional tokens for fees do not need to be approved to the router since it is already handled by setting s_feeToken
if (address(s_feeToken) != address(0)) {
if ((address(s_feeToken) != address(0)) && (s_feeToken.balanceOf(address(this)) < fee)) {
IERC20(s_feeToken).safeTransferFrom(msg.sender, address(this), fee);
}

Expand All @@ -77,6 +77,7 @@ contract CCIPClient is CCIPReceiver {
/// @dev It has to be external because of the try/catch of ccipReceive() which invokes it
function processMessage(Client.Any2EVMMessage calldata message)
external
virtual
override
onlySelf
isValidSender(message.sourceChainSelector, message.sender)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity ^0.8.0;

import {Client} from "../../libraries/Client.sol";
import {CCIPClientWithACK} from "../external/CCIPClientWithACK.sol";
import {CCIPClient} from "../external/CCIPClient.sol";

import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";

/// @title PingPongDemo - A simple ping-pong contract for demonstrating cross-chain communication
contract PingPongDemo is CCIPClientWithACK {
contract PingPongDemo is CCIPClient {
using SafeERC20 for IERC20;

event Ping(uint256 pingPongCount);
Expand All @@ -24,7 +24,7 @@ contract PingPongDemo is CCIPClientWithACK {
bool private s_isPaused;

// CCIPClient will handle the token approval so there's no need to do it here
constructor(address router, IERC20 feeToken) CCIPClientWithACK(router, feeToken) {}
constructor(address router, IERC20 feeToken) CCIPClient(router, feeToken) {}

function typeAndVersion() external pure virtual returns (string memory) {
return "PingPongDemo 1.3.0";
Expand All @@ -47,7 +47,7 @@ contract PingPongDemo is CCIPClientWithACK {
bytes memory data = abi.encode(pingPongCount);

ccipSend({
destChainSelector: s_counterpartChainSelector, // destChaio
destChainSelector: s_counterpartChainSelector, // destChain
tokenAmounts: new Client.EVMTokenAmount[](0),
data: data
});
Expand Down

0 comments on commit a54d2de

Please sign in to comment.