From 2c38141bec322dd9ee343dec203e4b8334781fa3 Mon Sep 17 00:00:00 2001 From: Ryan Hall Date: Tue, 8 Oct 2024 12:03:19 -0400 Subject: [PATCH] refactor _getTokenAndGasPrices --- contracts/src/v0.8/ccip/FeeQuoter.sol | 19 +++++++++---------- .../v0.8/ccip/test/feeQuoter/FeeQuoter.t.sol | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/contracts/src/v0.8/ccip/FeeQuoter.sol b/contracts/src/v0.8/ccip/FeeQuoter.sol index e13f14102c..75b43e2568 100644 --- a/contracts/src/v0.8/ccip/FeeQuoter.sol +++ b/contracts/src/v0.8/ccip/FeeQuoter.sol @@ -35,7 +35,6 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver, error DataFeedValueOutOfUint224Range(); error InvalidDestBytesOverhead(address token, uint32 destBytesOverhead); error MessageGasLimitTooHigh(); - error DestinationChainNotEnabled(uint64 destChainSelector); error ExtraArgOutOfOrderExecutionMustBeTrue(); error InvalidExtraArgsTag(); error SourceTokenDataTooLarge(address token); @@ -308,7 +307,9 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver, address token, uint64 destChainSelector ) external view returns (uint224 tokenPrice, uint224 gasPriceValue) { - return _getTokenAndGasPrices(token, destChainSelector, s_destChainConfigs[destChainSelector]); + if (!s_destChainConfigs[destChainSelector].isEnabled) revert ChainNotSupported(destChainSelector); + return + _getTokenAndGasPrices(token, destChainSelector, s_destChainConfigs[destChainSelector].gasPriceStalenessThreshold); } /// @notice Convert a given token amount to target token amount. @@ -373,22 +374,20 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver, /// @dev Gets the fee token price and the gas price, both denominated in dollars. /// @param token The source token to get the price for. /// @param destChainSelector The destination chain to get the gas price for. - /// @param destChainConfig The config struct for the dest chain selector. /// @return tokenPrice The price of the feeToken in 1e18 dollars per base unit. /// @return gasPriceValue The price of gas in 1e18 dollars per base unit. function _getTokenAndGasPrices( address token, uint64 destChainSelector, - DestChainConfig memory destChainConfig + uint32 gasPriceStalenessThreshold ) private view returns (uint224 tokenPrice, uint224 gasPriceValue) { - if (!destChainConfig.isEnabled) revert ChainNotSupported(destChainSelector); Internal.TimestampedPackedUint224 memory gasPrice = s_usdPerUnitGasByDestChainSelector[destChainSelector]; // If the staleness threshold is 0, we consider the gas price to be always valid - if (destChainConfig.gasPriceStalenessThreshold != 0) { + if (gasPriceStalenessThreshold != 0) { // We do allow a gas price of 0, but no stale or unset gas prices uint256 timePassed = block.timestamp - gasPrice.timestamp; - if (timePassed > destChainConfig.gasPriceStalenessThreshold) { - revert StaleGasPrice(destChainSelector, destChainConfig.gasPriceStalenessThreshold, timePassed); + if (timePassed > gasPriceStalenessThreshold) { + revert StaleGasPrice(destChainSelector, gasPriceStalenessThreshold, timePassed); } } @@ -521,7 +520,7 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver, Client.EVM2AnyMessage calldata message ) external view returns (uint256 feeTokenAmount) { DestChainConfig memory destChainConfig = s_destChainConfigs[destChainSelector]; - if (!destChainConfig.isEnabled) revert DestinationChainNotEnabled(destChainSelector); + if (!destChainConfig.isEnabled) revert ChainNotSupported(destChainSelector); if (!s_feeTokens.contains(message.feeToken)) revert FeeTokenNotSupported(message.feeToken); uint256 numberOfTokens = message.tokenAmounts.length; @@ -529,7 +528,7 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver, // The below call asserts that feeToken is a supported token (uint224 feeTokenPrice, uint224 packedGasPrice) = - _getTokenAndGasPrices(message.feeToken, destChainSelector, destChainConfig); + _getTokenAndGasPrices(message.feeToken, destChainSelector, destChainConfig.gasPriceStalenessThreshold); // Calculate premiumFee in USD with 18 decimals precision first. // If message-only and no token transfers, a flat network fee is charged. diff --git a/contracts/src/v0.8/ccip/test/feeQuoter/FeeQuoter.t.sol b/contracts/src/v0.8/ccip/test/feeQuoter/FeeQuoter.t.sol index 09750ca6cd..8a5a21798a 100644 --- a/contracts/src/v0.8/ccip/test/feeQuoter/FeeQuoter.t.sol +++ b/contracts/src/v0.8/ccip/test/feeQuoter/FeeQuoter.t.sol @@ -1658,8 +1658,8 @@ contract FeeQuoter_getValidatedFee is FeeQuoterFeeSetup { // Reverts - function test_DestinationChainNotEnabled_Revert() public { - vm.expectRevert(abi.encodeWithSelector(FeeQuoter.DestinationChainNotEnabled.selector, DEST_CHAIN_SELECTOR + 1)); + function test_ChainNotSupported_Revert() public { + vm.expectRevert(abi.encodeWithSelector(FeeQuoter.ChainNotSupported.selector, DEST_CHAIN_SELECTOR + 1)); s_feeQuoter.getValidatedFee(DEST_CHAIN_SELECTOR + 1, _generateEmptyMessage()); }