From 11c275959902783a3c4eaddbfaa5ce5f8707e01f Mon Sep 17 00:00:00 2001 From: Rens Rooimans Date: Mon, 19 Aug 2024 17:53:14 +0200 Subject: [PATCH] set more correct gas overheads (#1319) Cleanup & more realistic values for gas overheads --- contracts/gas-snapshots/ccip.gas-snapshot | 48 +- contracts/package.json | 15 +- contracts/src/v0.8/ccip/test/BaseTest.t.sol | 23 +- .../src/v0.8/ccip/test/NonceManager.t.sol | 3 +- contracts/src/v0.8/ccip/test/TokenSetup.t.sol | 9 +- .../src/v0.8/ccip/test/arm/ARMProxy.t.sol | 3 +- .../MultiOnRampTokenPoolReentrancy.t.sol | 6 +- .../onRamp/OnRampTokenPoolReentrancy.t.sol | 4 +- .../ccip/test/commitStore/CommitStore.t.sol | 42 +- .../src/v0.8/ccip/test/e2e/End2End.t.sol | 2 +- .../v0.8/ccip/test/e2e/MultiRampsEnd2End.sol | 3 +- .../MultiAggregateRateLimiterHelper.sol | 1 - .../ccip/test/legacy/TokenPoolAndProxy.t.sol | 35 +- .../src/v0.8/ccip/test/mocks/MockRMN.sol | 2 - .../ccip/test/mocks/test/MockRouterTest.t.sol | 2 +- .../test/offRamp/EVM2EVMMultiOffRamp.t.sol | 58 +-- .../offRamp/EVM2EVMMultiOffRampSetup.t.sol | 21 +- .../ccip/test/offRamp/EVM2EVMOffRamp.t.sol | 30 +- .../test/offRamp/EVM2EVMOffRampSetup.t.sol | 14 +- .../ccip/test/onRamp/EVM2EVMMultiOnRamp.t.sol | 23 +- .../test/onRamp/EVM2EVMMultiOnRampSetup.t.sol | 17 +- .../v0.8/ccip/test/onRamp/EVM2EVMOnRamp.t.sol | 29 +- .../ccip/test/onRamp/EVM2EVMOnRampSetup.t.sol | 13 +- .../test/pools/BurnFromMintTokenPool.t.sol | 5 +- .../v0.8/ccip/test/pools/BurnMintSetup.t.sol | 4 +- .../ccip/test/pools/BurnMintTokenPool.t.sol | 13 +- .../pools/BurnWithFromMintTokenPool.t.sol | 5 +- .../test/pools/LockReleaseTokenPool.t.sol | 19 +- .../src/v0.8/ccip/test/pools/TokenPool.t.sol | 41 +- .../v0.8/ccip/test/pools/USDCTokenPool.t.sol | 24 +- .../test/priceRegistry/PriceRegistry.t.sol | 486 ++---------------- .../priceRegistry/PriceRegistrySetup.t.sol | 418 +++++++++++++++ .../rateLimiter/AggregateRateLimiter.t.sol | 4 +- .../MultiAggregateRateLimiter.t.sol | 8 +- .../src/v0.8/ccip/test/router/Router.t.sol | 67 +-- .../v0.8/ccip/test/router/RouterSetup.t.sol | 4 +- 36 files changed, 726 insertions(+), 775 deletions(-) create mode 100644 contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistrySetup.t.sol diff --git a/contracts/gas-snapshots/ccip.gas-snapshot b/contracts/gas-snapshots/ccip.gas-snapshot index e1b2d6d5b3..f9c7b93aa7 100644 --- a/contracts/gas-snapshots/ccip.gas-snapshot +++ b/contracts/gas-snapshots/ccip.gas-snapshot @@ -123,22 +123,22 @@ CommitStore_verify:test_Paused_Revert() (gas: 18496) CommitStore_verify:test_TooManyLeaves_Revert() (gas: 36785) DefensiveExampleTest:test_HappyPath_Success() (gas: 200018) DefensiveExampleTest:test_Recovery() (gas: 424256) -E2E:test_E2E_3MessagesSuccess_gas() (gas: 1104304) -EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_NotACompatiblePool_Revert() (gas: 38416) +E2E:test_E2E_3MessagesSuccess_gas() (gas: 1104303) +EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_NotACompatiblePool_Revert() (gas: 38408) EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_Success() (gas: 106250) -EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_TokenHandlingError_transfer_Revert() (gas: 87421) -EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_InvalidDataLength_Revert() (gas: 38958) -EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_ReleaseOrMintBalanceMismatch_Revert() (gas: 96515) -EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_TokenHandlingError_BalanceOf_Revert() (gas: 41964) +EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_TokenHandlingError_transfer_Revert() (gas: 87409) +EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_InvalidDataLength_Revert() (gas: 38954) +EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_ReleaseOrMintBalanceMismatch_Revert() (gas: 96511) +EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_TokenHandlingError_BalanceOf_Revert() (gas: 41956) EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test_releaseOrMintToken_skip_ReleaseOrMintBalanceMismatch_if_pool_Revert() (gas: 88684) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddMultipleChains_Success() (gas: 468131) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddNewChain_Success() (gas: 99235) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ApplyZeroUpdates_Success() (gas: 12399) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChainOnRamp_Revert() (gas: 93193) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChain_Success() (gas: 109906) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_RouterAddress_Revert() (gas: 13267) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroOnRampAddress_Revert() (gas: 17992) -EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroSourceChainSelector_Revert() (gas: 15347) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddMultipleChains_Success() (gas: 468115) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_AddNewChain_Success() (gas: 99227) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ApplyZeroUpdates_Success() (gas: 12395) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChainOnRamp_Revert() (gas: 93181) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ReplaceExistingChain_Success() (gas: 109890) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_RouterAddress_Revert() (gas: 13263) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroOnRampAddress_Revert() (gas: 17988) +EVM2EVMMultiOffRamp_applySourceChainConfigUpdates:test_ZeroSourceChainSelector_Revert() (gas: 15343) EVM2EVMMultiOffRamp_batchExecute:test_MultipleReportsDifferentChains_Success() (gas: 313594) EVM2EVMMultiOffRamp_batchExecute:test_MultipleReportsSameChain_Success() (gas: 254984) EVM2EVMMultiOffRamp_batchExecute:test_MultipleReportsSkipDuplicate_Success() (gas: 166123) @@ -146,7 +146,7 @@ EVM2EVMMultiOffRamp_batchExecute:test_OutOfBoundsGasLimitsAccess_Revert() (gas: EVM2EVMMultiOffRamp_batchExecute:test_SingleReport_Success() (gas: 153140) EVM2EVMMultiOffRamp_batchExecute:test_Unhealthy_Revert() (gas: 518887) EVM2EVMMultiOffRamp_batchExecute:test_ZeroReports_Revert() (gas: 10439) -EVM2EVMMultiOffRamp_ccipReceive:test_Reverts() (gas: 15688) +EVM2EVMMultiOffRamp_ccipReceive:test_Reverts() (gas: 15684) EVM2EVMMultiOffRamp_commit:test_InvalidIntervalMinLargerThanMax_Revert() (gas: 67458) EVM2EVMMultiOffRamp_commit:test_InvalidInterval_Revert() (gas: 59734) EVM2EVMMultiOffRamp_commit:test_InvalidRootRevert() (gas: 58814) @@ -166,7 +166,7 @@ EVM2EVMMultiOffRamp_commit:test_Unhealthy_Revert() (gas: 77608) EVM2EVMMultiOffRamp_commit:test_ValidPriceUpdateThenStaleReportWithRoot_Success() (gas: 205117) EVM2EVMMultiOffRamp_commit:test_WrongConfigWithoutSigners_Revert() (gas: 6532473) EVM2EVMMultiOffRamp_commit:test_ZeroEpochAndRound_Revert() (gas: 47788) -EVM2EVMMultiOffRamp_constructor:test_Constructor_Success() (gas: 6125452) +EVM2EVMMultiOffRamp_constructor:test_Constructor_Success() (gas: 6125436) EVM2EVMMultiOffRamp_constructor:test_SourceChainSelector_Revert() (gas: 137067) EVM2EVMMultiOffRamp_constructor:test_ZeroChainSelector_Revert() (gas: 103784) EVM2EVMMultiOffRamp_constructor:test_ZeroNonceManager_Revert() (gas: 101677) @@ -221,9 +221,9 @@ EVM2EVMMultiOffRamp_executeSingleReport:test_Unhealthy_Revert() (gas: 515089) EVM2EVMMultiOffRamp_executeSingleReport:test_WithCurseOnAnotherSourceChain_Success() (gas: 485207) EVM2EVMMultiOffRamp_executeSingleReport:test__execute_SkippedAlreadyExecutedMessageUnordered_Success() (gas: 133513) EVM2EVMMultiOffRamp_executeSingleReport:test__execute_SkippedAlreadyExecutedMessage_Success() (gas: 162713) -EVM2EVMMultiOffRamp_getExecutionState:test_FillExecutionState_Success() (gas: 3677612) -EVM2EVMMultiOffRamp_getExecutionState:test_GetDifferentChainExecutionState_Success() (gas: 118399) -EVM2EVMMultiOffRamp_getExecutionState:test_GetExecutionState_Success() (gas: 87606) +EVM2EVMMultiOffRamp_getExecutionState:test_FillExecutionState_Success() (gas: 3674540) +EVM2EVMMultiOffRamp_getExecutionState:test_GetDifferentChainExecutionState_Success() (gas: 118375) +EVM2EVMMultiOffRamp_getExecutionState:test_GetExecutionState_Success() (gas: 87586) EVM2EVMMultiOffRamp_manuallyExecute:test_ManualExecGasLimitMismatchSingleReport_Revert() (gas: 75635) EVM2EVMMultiOffRamp_manuallyExecute:test_ManualExecInvalidGasLimit_Revert() (gas: 26471) EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_DoesNotRevertIfUntouched_Success() (gas: 168604) @@ -236,10 +236,10 @@ EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_Success() (gas: 208322) EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_WithGasOverride_Success() (gas: 208944) EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_WithMultiReportGasOverride_Success() (gas: 662979) EVM2EVMMultiOffRamp_manuallyExecute:test_manuallyExecute_WithPartialMessages_Success() (gas: 301931) -EVM2EVMMultiOffRamp_releaseOrMintTokens:test_TokenHandlingError_Reverts() (gas: 164054) -EVM2EVMMultiOffRamp_releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAPool_Reverts() (gas: 23740) -EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidDataLengthReturnData_Revert() (gas: 64488) -EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidEVMAddress_Revert() (gas: 39524) +EVM2EVMMultiOffRamp_releaseOrMintTokens:test_TokenHandlingError_Reverts() (gas: 164042) +EVM2EVMMultiOffRamp_releaseOrMintTokens:test__releaseOrMintTokens_PoolIsNotAPool_Reverts() (gas: 23736) +EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidDataLengthReturnData_Revert() (gas: 64484) +EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_InvalidEVMAddress_Revert() (gas: 39516) EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_PoolDoesNotSupportDest_Reverts() (gas: 81512) EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_Success() (gas: 176140) EVM2EVMMultiOffRamp_releaseOrMintTokens:test_releaseOrMintTokens_destDenominatedDecimals_Success() (gas: 189342) @@ -861,7 +861,7 @@ Router_ccipSend:test_NonLinkFeeToken_Success() (gas: 242732) Router_ccipSend:test_UnsupportedDestinationChain_Revert() (gas: 24749) Router_ccipSend:test_WhenNotHealthy_Revert() (gas: 44724) Router_ccipSend:test_WrappedNativeFeeToken_Success() (gas: 174440) -Router_ccipSend:test_ZeroFeeAndGasPrice_Success() (gas: 245146) +Router_ccipSend:test_ZeroFeeAndGasPrice_Success() (gas: 244856) Router_constructor:test_Constructor_Success() (gas: 13074) Router_getArmProxy:test_getArmProxy() (gas: 10561) Router_getFee:test_GetFeeSupportedChain_Success() (gas: 46464) diff --git a/contracts/package.json b/contracts/package.json index 200548ac66..78f4cf36b8 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -24,28 +24,37 @@ }, "files": [ "src/v0.8/ccip/**/*.sol", - "!src/v0.8/ccip/test/**/*", - "src/v0.8/ccip/test/mocks/**/*", "src/v0.8/shared/access/ConfirmedOwner.sol", "src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol", "src/v0.8/shared/access/OwnerIsCreator.sol", + "src/v0.8/shared/access/AuthorizedCallers.sol", "src/v0.8/shared/call/CallWithExactGas.sol", + "src/v0.8/shared/enumerable/EnumerableMapBytes32.sol", "src/v0.8/shared/enumerable/EnumerableMapAddresses.sol", "src/v0.8/shared/interfaces/IOwnable.sol", "src/v0.8/shared/interfaces/ITypeAndVersion.sol", "src/v0.8/shared/interfaces/IERC677Receiver.sol", + "src/v0.8/shared/interfaces/AggregatorV3Interface.sol", "src/v0.8/shared/token/ERC20/IBurnMintERC20.sol", "src/v0.8/shared/token/ERC677/IERC677.sol", "src/v0.8/shared/token/ERC677/IERC677Receiver.sol", "src/v0.8/shared/token/ERC677/ERC677.sol", "src/v0.8/shared/token/ERC677/BurnMintERC677.sol", + "src/v0.8/shared/util/SortedSetValidationUtil.sol", + "src/v0.8/liquiditymanager/interfaces/ILiquidityContainer.sol", + "src/v0.8/keystone/interfaces/ICapabilityConfiguration.sol", "src/v0.8/vendor/openzeppelin-solidity", "src/v0.8/vendor/Context.sol", "src/v0.8/vendor/Pausable.sol", "abi/v0.8/", "src/v0.8/ccip/LICENSE.md", "src/v0.8/ccip/LICENSE-MIT.md", - "src/v0.8/ccip/v1.5-CCIP-License-grants.md" + "src/v0.8/ccip/v1.5-CCIP-License-grants.md", + "!src/v0.8/ccip/test/**/*", + "src/v0.8/ccip/test/mocks/**/*", + "!src/v0.8/ccip/test/mocks/test/*", + "!src/v0.8/ccip/onRamp/EVM2EVMMultiOnRamp.sol", + "!src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol" ], "pnpm": { "_comment": "See https://github.com/ethers-io/ethers.js/discussions/2849#discussioncomment-2696454", diff --git a/contracts/src/v0.8/ccip/test/BaseTest.t.sol b/contracts/src/v0.8/ccip/test/BaseTest.t.sol index 7570447cee..2eb44ec485 100644 --- a/contracts/src/v0.8/ccip/test/BaseTest.t.sol +++ b/contracts/src/v0.8/ccip/test/BaseTest.t.sol @@ -34,11 +34,11 @@ contract BaseTest is Test { // Onramp uint96 internal constant MAX_NOP_FEES_JUELS = 1e27; uint96 internal constant MAX_MSG_FEES_JUELS = 1e18; - uint32 internal constant DEST_GAS_OVERHEAD = 350_000; + uint32 internal constant DEST_GAS_OVERHEAD = 300_000; uint16 internal constant DEST_GAS_PER_PAYLOAD_BYTE = 16; uint16 internal constant DEFAULT_TOKEN_FEE_USD_CENTS = 50; - uint32 internal constant DEFAULT_TOKEN_DEST_GAS_OVERHEAD = 85_000; + uint32 internal constant DEFAULT_TOKEN_DEST_GAS_OVERHEAD = 90_000; uint32 internal constant DEFAULT_TOKEN_BYTES_OVERHEAD = 32; bool private s_baseTestInitialized; @@ -87,15 +87,15 @@ contract BaseTest is Test { s_mockRMN = new MockRMN(); } - function getOutboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) { + function _getOutboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) { return RateLimiter.Config({isEnabled: true, capacity: 100e28, rate: 1e15}); } - function getInboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) { + function _getInboundRateLimiterConfig() internal pure returns (RateLimiter.Config memory) { return RateLimiter.Config({isEnabled: true, capacity: 222e30, rate: 1e18}); } - function getSingleTokenPriceUpdateStruct( + function _getSingleTokenPriceUpdateStruct( address token, uint224 price ) internal pure returns (Internal.PriceUpdates memory) { @@ -107,17 +107,4 @@ contract BaseTest is Test { return priceUpdates; } - - function getSingleGasPriceUpdateStruct( - uint64 chainSelector, - uint224 usdPerUnitGas - ) internal pure returns (Internal.PriceUpdates memory) { - Internal.GasPriceUpdate[] memory gasPriceUpdates = new Internal.GasPriceUpdate[](1); - gasPriceUpdates[0] = Internal.GasPriceUpdate({destChainSelector: chainSelector, usdPerUnitGas: usdPerUnitGas}); - - Internal.PriceUpdates memory priceUpdates = - Internal.PriceUpdates({tokenPriceUpdates: new Internal.TokenPriceUpdate[](0), gasPriceUpdates: gasPriceUpdates}); - - return priceUpdates; - } } diff --git a/contracts/src/v0.8/ccip/test/NonceManager.t.sol b/contracts/src/v0.8/ccip/test/NonceManager.t.sol index 444329220d..bcf8c9328b 100644 --- a/contracts/src/v0.8/ccip/test/NonceManager.t.sol +++ b/contracts/src/v0.8/ccip/test/NonceManager.t.sol @@ -12,7 +12,6 @@ import {EVM2EVMMultiOnRamp} from "../onRamp/EVM2EVMMultiOnRamp.sol"; import {EVM2EVMOnRamp} from "../onRamp/EVM2EVMOnRamp.sol"; import {BaseTest} from "./BaseTest.t.sol"; -import {EVM2EVMMultiOnRampHelper} from "./helpers/EVM2EVMMultiOnRampHelper.sol"; import {EVM2EVMOffRampHelper} from "./helpers/EVM2EVMOffRampHelper.sol"; import {EVM2EVMOnRampHelper} from "./helpers/EVM2EVMOnRampHelper.sol"; import {MockCommitStore} from "./mocks/MockCommitStore.sol"; @@ -214,7 +213,7 @@ contract NonceManager_OnRampUpgrade is EVM2EVMMultiOnRampSetup { minFeeUSDCents: 1_00, // 1 USD maxFeeUSDCents: 1000_00, // 1,000 USD deciBps: 2_5, // 2.5 bps, or 0.025% - destGasOverhead: 40_000, + destGasOverhead: 140_000, destBytesOverhead: uint32(Pool.CCIP_LOCK_OR_BURN_V1_RET_BYTES), aggregateRateLimitEnabled: true }); diff --git a/contracts/src/v0.8/ccip/test/TokenSetup.t.sol b/contracts/src/v0.8/ccip/test/TokenSetup.t.sol index 182d92c5c9..203145881e 100644 --- a/contracts/src/v0.8/ccip/test/TokenSetup.t.sol +++ b/contracts/src/v0.8/ccip/test/TokenSetup.t.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.24; -import {IPoolV1} from "../interfaces/IPool.sol"; - import {BurnMintERC677} from "../../shared/token/ERC677/BurnMintERC677.sol"; import {Client} from "../libraries/Client.sol"; import {BurnMintTokenPool} from "../pools/BurnMintTokenPool.sol"; @@ -138,7 +136,7 @@ contract TokenSetup is RouterSetup { } } - function getCastedSourceEVMTokenAmountsWithZeroAmounts() + function _getCastedSourceEVMTokenAmountsWithZeroAmounts() internal view returns (Client.EVMTokenAmount[] memory tokenAmounts) @@ -147,6 +145,7 @@ contract TokenSetup is RouterSetup { for (uint256 i = 0; i < tokenAmounts.length; ++i) { tokenAmounts[i].token = s_sourceTokens[i]; } + return tokenAmounts; } function _setPool( @@ -170,8 +169,8 @@ contract TokenSetup is RouterSetup { remotePoolAddress: abi.encode(remotePoolAddress), remoteTokenAddress: abi.encode(remoteToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); TokenPool(pool).applyChainUpdates(chainUpdates); diff --git a/contracts/src/v0.8/ccip/test/arm/ARMProxy.t.sol b/contracts/src/v0.8/ccip/test/arm/ARMProxy.t.sol index 24b617c82a..f1889fae75 100644 --- a/contracts/src/v0.8/ccip/test/arm/ARMProxy.t.sol +++ b/contracts/src/v0.8/ccip/test/arm/ARMProxy.t.sol @@ -4,9 +4,8 @@ pragma solidity 0.8.24; import {IRMN} from "../../interfaces/IRMN.sol"; import {ARMProxy} from "../../ARMProxy.sol"; -import {RMN} from "../../RMN.sol"; import {MockRMN} from "../mocks/MockRMN.sol"; -import {RMNSetup, makeSubjects} from "./RMNSetup.t.sol"; +import {RMNSetup} from "./RMNSetup.t.sol"; contract ARMProxyTest is RMNSetup { MockRMN internal s_mockRMN; diff --git a/contracts/src/v0.8/ccip/test/attacks/onRamp/MultiOnRampTokenPoolReentrancy.t.sol b/contracts/src/v0.8/ccip/test/attacks/onRamp/MultiOnRampTokenPoolReentrancy.t.sol index 5deeda6406..d31cd35016 100644 --- a/contracts/src/v0.8/ccip/test/attacks/onRamp/MultiOnRampTokenPoolReentrancy.t.sol +++ b/contracts/src/v0.8/ccip/test/attacks/onRamp/MultiOnRampTokenPoolReentrancy.t.sol @@ -11,8 +11,6 @@ import {ReentrantMaliciousTokenPool} from "./ReentrantMaliciousTokenPool.sol"; import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; -import {console} from "forge-std/console.sol"; - /// @title MultiOnRampTokenPoolReentrancy /// Attempts to perform a reentrancy exploit on Onramp with a malicious TokenPool contract MultiOnRampTokenPoolReentrancy is EVM2EVMMultiOnRampSetup { @@ -41,8 +39,8 @@ contract MultiOnRampTokenPoolReentrancy is EVM2EVMMultiOnRampSetup { remotePoolAddress: abi.encode(s_destPoolBySourceToken[s_sourceTokens[0]]), remoteTokenAddress: abi.encode(s_destTokens[0]), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_maliciousTokenPool.applyChainUpdates(chainUpdates); s_sourcePoolByToken[address(s_sourceToken)] = address(s_maliciousTokenPool); diff --git a/contracts/src/v0.8/ccip/test/attacks/onRamp/OnRampTokenPoolReentrancy.t.sol b/contracts/src/v0.8/ccip/test/attacks/onRamp/OnRampTokenPoolReentrancy.t.sol index 8fc71be857..03db40a293 100644 --- a/contracts/src/v0.8/ccip/test/attacks/onRamp/OnRampTokenPoolReentrancy.t.sol +++ b/contracts/src/v0.8/ccip/test/attacks/onRamp/OnRampTokenPoolReentrancy.t.sol @@ -39,8 +39,8 @@ contract OnRampTokenPoolReentrancy is EVM2EVMOnRampSetup { remotePoolAddress: abi.encode(s_destPoolBySourceToken[s_sourceTokens[0]]), remoteTokenAddress: abi.encode(s_destTokens[0]), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_maliciousTokenPool.applyChainUpdates(chainUpdates); s_sourcePoolByToken[address(s_sourceToken)] = address(s_maliciousTokenPool); diff --git a/contracts/src/v0.8/ccip/test/commitStore/CommitStore.t.sol b/contracts/src/v0.8/ccip/test/commitStore/CommitStore.t.sol index 8c5e745f43..7ea64c9f89 100644 --- a/contracts/src/v0.8/ccip/test/commitStore/CommitStore.t.sol +++ b/contracts/src/v0.8/ccip/test/commitStore/CommitStore.t.sol @@ -12,7 +12,7 @@ import {MerkleMultiProof} from "../../libraries/MerkleMultiProof.sol"; import {OCR2Abstract} from "../../ocr/OCR2Abstract.sol"; import {CommitStoreHelper} from "../helpers/CommitStoreHelper.sol"; import {OCR2BaseSetup} from "../ocr/OCR2Base.t.sol"; -import {PriceRegistrySetup} from "../priceRegistry/PriceRegistry.t.sol"; +import {PriceRegistrySetup} from "../priceRegistry/PriceRegistrySetup.t.sol"; contract CommitStoreSetup is PriceRegistrySetup, OCR2BaseSetup { CommitStoreHelper internal s_commitStore; @@ -214,7 +214,7 @@ contract CommitStore_resetUnblessedRoots is CommitStoreRealRMNSetup { rootsToReset[2] = "3"; CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(1, 2), merkleRoot: rootsToReset[0] }); @@ -222,7 +222,7 @@ contract CommitStore_resetUnblessedRoots is CommitStoreRealRMNSetup { s_commitStore.report(abi.encode(report), ++s_latestEpochAndRound); report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(3, 4), merkleRoot: rootsToReset[1] }); @@ -230,7 +230,7 @@ contract CommitStore_resetUnblessedRoots is CommitStoreRealRMNSetup { s_commitStore.report(abi.encode(report), ++s_latestEpochAndRound); report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(5, 5), merkleRoot: rootsToReset[2] }); @@ -273,7 +273,7 @@ contract CommitStore_report is CommitStoreSetup { uint64 max1 = 931; bytes32 root = "Only a single root"; CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(1, max1), merkleRoot: root }); @@ -296,7 +296,7 @@ contract CommitStore_report is CommitStoreSetup { uint64 max1 = 12; CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), interval: CommitStore.Interval(1, max1), merkleRoot: "test #2" }); @@ -316,7 +316,7 @@ contract CommitStore_report is CommitStoreSetup { IPriceRegistry(s_commitStore.getDynamicConfig().priceRegistry).getTokenPrice(s_sourceFeeToken).value; CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), interval: CommitStore.Interval(1, maxSeq), merkleRoot: "stale report 1" }); @@ -329,7 +329,7 @@ contract CommitStore_report is CommitStoreSetup { assertEq(s_latestEpochAndRound, s_commitStore.getLatestPriceEpochAndRound()); report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(maxSeq + 1, maxSeq * 2), merkleRoot: "stale report 2" }); @@ -348,7 +348,7 @@ contract CommitStore_report is CommitStoreSetup { function test_OnlyTokenPriceUpdates_Success() public { CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), interval: CommitStore.Interval(0, 0), merkleRoot: "" }); @@ -362,7 +362,7 @@ contract CommitStore_report is CommitStoreSetup { function test_OnlyGasPriceUpdates_Success() public { CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), interval: CommitStore.Interval(0, 0), merkleRoot: "" }); @@ -380,7 +380,7 @@ contract CommitStore_report is CommitStoreSetup { uint224 tokenPrice2 = 5e18; CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice1), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice1), interval: CommitStore.Interval(0, 0), merkleRoot: "" }); @@ -392,7 +392,7 @@ contract CommitStore_report is CommitStoreSetup { assertEq(s_latestEpochAndRound, s_commitStore.getLatestPriceEpochAndRound()); report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice2), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice2), interval: CommitStore.Interval(1, maxSeq), merkleRoot: "stale report" }); @@ -427,7 +427,7 @@ contract CommitStore_report is CommitStoreSetup { function test_InvalidRootRevert() public { CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(1, 4), merkleRoot: bytes32(0) }); @@ -439,7 +439,7 @@ contract CommitStore_report is CommitStoreSetup { function test_InvalidInterval_Revert() public { CommitStore.Interval memory interval = CommitStore.Interval(2, 2); CommitStore.CommitReport memory report = - CommitStore.CommitReport({priceUpdates: getEmptyPriceUpdates(), interval: interval, merkleRoot: bytes32(0)}); + CommitStore.CommitReport({priceUpdates: _getEmptyPriceUpdates(), interval: interval, merkleRoot: bytes32(0)}); vm.expectRevert(abi.encodeWithSelector(CommitStore.InvalidInterval.selector, interval)); @@ -449,7 +449,7 @@ contract CommitStore_report is CommitStoreSetup { function test_InvalidIntervalMinLargerThanMax_Revert() public { CommitStore.Interval memory interval = CommitStore.Interval(1, 0); CommitStore.CommitReport memory report = - CommitStore.CommitReport({priceUpdates: getEmptyPriceUpdates(), interval: interval, merkleRoot: bytes32(0)}); + CommitStore.CommitReport({priceUpdates: _getEmptyPriceUpdates(), interval: interval, merkleRoot: bytes32(0)}); vm.expectRevert(abi.encodeWithSelector(CommitStore.InvalidInterval.selector, interval)); @@ -458,7 +458,7 @@ contract CommitStore_report is CommitStoreSetup { function test_ZeroEpochAndRound_Revert() public { CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), interval: CommitStore.Interval(0, 0), merkleRoot: bytes32(0) }); @@ -470,7 +470,7 @@ contract CommitStore_report is CommitStoreSetup { function test_OnlyPriceUpdateStaleReport_Revert() public { CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), interval: CommitStore.Interval(0, 0), merkleRoot: bytes32(0) }); @@ -485,14 +485,14 @@ contract CommitStore_report is CommitStoreSetup { function test_RootAlreadyCommitted_Revert() public { CommitStore.CommitReport memory report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(1, 2), merkleRoot: "Only a single root" }); s_commitStore.report(abi.encode(report), ++s_latestEpochAndRound); report = CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(3, 3), merkleRoot: "Only a single root" }); @@ -510,7 +510,7 @@ contract CommitStore_verify is CommitStoreRealRMNSetup { s_commitStore.report( abi.encode( CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(1, 2), merkleRoot: leaves[0] }) @@ -529,7 +529,7 @@ contract CommitStore_verify is CommitStoreRealRMNSetup { s_commitStore.report( abi.encode( CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(1, 2), merkleRoot: leaves[0] }) diff --git a/contracts/src/v0.8/ccip/test/e2e/End2End.t.sol b/contracts/src/v0.8/ccip/test/e2e/End2End.t.sol index 90df377313..114265a248 100644 --- a/contracts/src/v0.8/ccip/test/e2e/End2End.t.sol +++ b/contracts/src/v0.8/ccip/test/e2e/End2End.t.sol @@ -52,7 +52,7 @@ contract E2E is EVM2EVMOnRampSetup, CommitStoreSetup, EVM2EVMOffRampSetup { bytes memory commitReport = abi.encode( CommitStore.CommitReport({ - priceUpdates: getEmptyPriceUpdates(), + priceUpdates: _getEmptyPriceUpdates(), interval: CommitStore.Interval(messages[0].sequenceNumber, messages[2].sequenceNumber), merkleRoot: merkleRoots[0] }) diff --git a/contracts/src/v0.8/ccip/test/e2e/MultiRampsEnd2End.sol b/contracts/src/v0.8/ccip/test/e2e/MultiRampsEnd2End.sol index 806b133371..9116c79b9e 100644 --- a/contracts/src/v0.8/ccip/test/e2e/MultiRampsEnd2End.sol +++ b/contracts/src/v0.8/ccip/test/e2e/MultiRampsEnd2End.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.24; import {AuthorizedCallers} from "../../../shared/access/AuthorizedCallers.sol"; import {NonceManager} from "../../NonceManager.sol"; +import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol"; import "../helpers/MerkleHelper.sol"; import "../offRamp/EVM2EVMMultiOffRampSetup.t.sol"; @@ -149,7 +150,7 @@ contract MultiRampsE2E is EVM2EVMMultiOnRampSetup, EVM2EVMMultiOffRampSetup { }); EVM2EVMMultiOffRamp.CommitReport memory report = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.resumeGasMetering(); _commit(report, ++s_latestSequenceNumber); diff --git a/contracts/src/v0.8/ccip/test/helpers/MultiAggregateRateLimiterHelper.sol b/contracts/src/v0.8/ccip/test/helpers/MultiAggregateRateLimiterHelper.sol index d9386ca7db..2bcaabda33 100644 --- a/contracts/src/v0.8/ccip/test/helpers/MultiAggregateRateLimiterHelper.sol +++ b/contracts/src/v0.8/ccip/test/helpers/MultiAggregateRateLimiterHelper.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.24; import {MultiAggregateRateLimiter} from "../../MultiAggregateRateLimiter.sol"; -import {IPriceRegistry} from "../../interfaces/IPriceRegistry.sol"; import {Client} from "../../libraries/Client.sol"; contract MultiAggregateRateLimiterHelper is MultiAggregateRateLimiter { diff --git a/contracts/src/v0.8/ccip/test/legacy/TokenPoolAndProxy.t.sol b/contracts/src/v0.8/ccip/test/legacy/TokenPoolAndProxy.t.sol index a69ca0952c..9645d70b7a 100644 --- a/contracts/src/v0.8/ccip/test/legacy/TokenPoolAndProxy.t.sol +++ b/contracts/src/v0.8/ccip/test/legacy/TokenPoolAndProxy.t.sol @@ -5,7 +5,6 @@ import {IPoolV1} from "../../interfaces/IPool.sol"; import {IPoolPriorTo1_5} from "../../interfaces/IPoolPriorTo1_5.sol"; import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol"; -import {PriceRegistry} from "../../PriceRegistry.sol"; import {Router} from "../../Router.sol"; import {Client} from "../../libraries/Client.sol"; import {Pool} from "../../libraries/Pool.sol"; @@ -14,8 +13,6 @@ import {BurnMintTokenPoolAndProxy} from "../../pools/BurnMintTokenPoolAndProxy.s import {BurnWithFromMintTokenPoolAndProxy} from "../../pools/BurnWithFromMintTokenPoolAndProxy.sol"; import {LockReleaseTokenPoolAndProxy} from "../../pools/LockReleaseTokenPoolAndProxy.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; -import {TokenSetup} from "../TokenSetup.t.sol"; -import {EVM2EVMOnRampHelper} from "../helpers/EVM2EVMOnRampHelper.sol"; import {EVM2EVMOnRampSetup} from "../onRamp/EVM2EVMOnRampSetup.t.sol"; import {RouterSetup} from "../router/RouterSetup.t.sol"; import {BurnMintTokenPool1_2, TokenPool1_2} from "./BurnMintTokenPool1_2.sol"; @@ -260,13 +257,13 @@ contract TokenPoolAndProxyMigration is EVM2EVMOnRampSetup { onRampUpdates[0] = TokenPool1_2.RampUpdate({ ramp: address(s_onRamp), allowed: true, - rateLimiterConfig: getInboundRateLimiterConfig() + rateLimiterConfig: _getInboundRateLimiterConfig() }); TokenPool1_2.RampUpdate[] memory offRampUpdates = new TokenPool1_2.RampUpdate[](1); offRampUpdates[0] = TokenPool1_2.RampUpdate({ ramp: address(s_offRamp), allowed: true, - rateLimiterConfig: getInboundRateLimiterConfig() + rateLimiterConfig: _getInboundRateLimiterConfig() }); BurnMintTokenPool1_2(address(s_legacyPool)).applyRampUpdates(onRampUpdates, offRampUpdates); } @@ -280,14 +277,14 @@ contract TokenPoolAndProxyMigration is EVM2EVMOnRampSetup { legacyChainUpdates[0] = TokenPool1_4.ChainUpdate({ remoteChainSelector: DEST_CHAIN_SELECTOR, allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); legacyChainUpdates[1] = TokenPool1_4.ChainUpdate({ remoteChainSelector: SOURCE_CHAIN_SELECTOR, allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); BurnMintTokenPool1_4(address(s_legacyPool)).applyChainUpdates(legacyChainUpdates); } @@ -306,16 +303,16 @@ contract TokenPoolAndProxyMigration is EVM2EVMOnRampSetup { remotePoolAddress: abi.encode(s_destTokenPool), remoteTokenAddress: abi.encode(s_destToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); chainUpdates[1] = TokenPool.ChainUpdate({ remoteChainSelector: SOURCE_CHAIN_SELECTOR, remotePoolAddress: abi.encode(s_sourcePool), remoteTokenAddress: abi.encode(s_sourceToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_newPool.applyChainUpdates(chainUpdates); @@ -395,10 +392,10 @@ contract TokenPoolAndProxy is EVM2EVMOnRampSetup { TokenPool1_2.RampUpdate[] memory onRampUpdates = new TokenPool1_2.RampUpdate[](1); onRampUpdates[0] = - TokenPool1_2.RampUpdate({ramp: address(s_pool), allowed: true, rateLimiterConfig: getInboundRateLimiterConfig()}); + TokenPool1_2.RampUpdate({ramp: address(s_pool), allowed: true, rateLimiterConfig: _getInboundRateLimiterConfig()}); TokenPool1_2.RampUpdate[] memory offRampUpdates = new TokenPool1_2.RampUpdate[](1); offRampUpdates[0] = - TokenPool1_2.RampUpdate({ramp: address(s_pool), allowed: true, rateLimiterConfig: getInboundRateLimiterConfig()}); + TokenPool1_2.RampUpdate({ramp: address(s_pool), allowed: true, rateLimiterConfig: _getInboundRateLimiterConfig()}); BurnMintTokenPool1_2(address(s_legacyPool)).applyRampUpdates(onRampUpdates, offRampUpdates); } @@ -409,8 +406,8 @@ contract TokenPoolAndProxy is EVM2EVMOnRampSetup { remotePoolAddress: abi.encode(s_destPool), remoteTokenAddress: abi.encode(s_destToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); BurnMintTokenPoolAndProxy(address(s_pool)).applyChainUpdates(chains); @@ -556,8 +553,8 @@ contract LockReleaseTokenPoolAndProxySetup is RouterSetup { remotePoolAddress: abi.encode(s_destPoolAddress), remoteTokenAddress: abi.encode(address(s_token)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_lockReleaseTokenPoolAndProxy.applyChainUpdates(chainUpdate); diff --git a/contracts/src/v0.8/ccip/test/mocks/MockRMN.sol b/contracts/src/v0.8/ccip/test/mocks/MockRMN.sol index 3f7b0200e6..343078cc37 100644 --- a/contracts/src/v0.8/ccip/test/mocks/MockRMN.sol +++ b/contracts/src/v0.8/ccip/test/mocks/MockRMN.sol @@ -1,9 +1,7 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.24; -import {RMN} from "../../RMN.sol"; import {IRMN} from "../../interfaces/IRMN.sol"; -import {OwnerIsCreator} from "./../../../shared/access/OwnerIsCreator.sol"; /// @notice WARNING: This contract is to be only used for testing, all methods are unprotected. contract MockRMN is IRMN { diff --git a/contracts/src/v0.8/ccip/test/mocks/test/MockRouterTest.t.sol b/contracts/src/v0.8/ccip/test/mocks/test/MockRouterTest.t.sol index 91798b494d..6cbe7bf58f 100644 --- a/contracts/src/v0.8/ccip/test/mocks/test/MockRouterTest.t.sol +++ b/contracts/src/v0.8/ccip/test/mocks/test/MockRouterTest.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Client} from "../../../libraries/Client.sol"; import {TokenSetup} from "../../TokenSetup.t.sol"; -import {IRouter, IRouterClient, MockCCIPRouter} from "../MockRouter.sol"; +import {IRouterClient, MockCCIPRouter} from "../MockRouter.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"; diff --git a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol index cfe43a972f..3acc1adae0 100644 --- a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol +++ b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.24; -import {ICommitStore} from "../../interfaces/ICommitStore.sol"; import {IMessageInterceptor} from "../../interfaces/IMessageInterceptor.sol"; import {IPriceRegistry} from "../../interfaces/IPriceRegistry.sol"; import {IRMN} from "../../interfaces/IRMN.sol"; @@ -11,8 +10,6 @@ import {ITokenAdminRegistry} from "../../interfaces/ITokenAdminRegistry.sol"; import {CallWithExactGas} from "../../../shared/call/CallWithExactGas.sol"; import {NonceManager} from "../../NonceManager.sol"; import {PriceRegistry} from "../../PriceRegistry.sol"; -import {RMN} from "../../RMN.sol"; -import {Router} from "../../Router.sol"; import {Client} from "../../libraries/Client.sol"; import {Internal} from "../../libraries/Internal.sol"; import {MerkleMultiProof} from "../../libraries/MerkleMultiProof.sol"; @@ -24,7 +21,6 @@ import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; import {EVM2EVMMultiOffRampHelper} from "../helpers/EVM2EVMMultiOffRampHelper.sol"; import {MaybeRevertingBurnMintTokenPool} from "../helpers/MaybeRevertingBurnMintTokenPool.sol"; -import {MessageInterceptorHelper} from "../helpers/MessageInterceptorHelper.sol"; import {ConformingReceiver} from "../helpers/receivers/ConformingReceiver.sol"; import {MaybeRevertMessageReceiver} from "../helpers/receivers/MaybeRevertMessageReceiver.sol"; import {MaybeRevertMessageReceiverNo165} from "../helpers/receivers/MaybeRevertMessageReceiverNo165.sol"; @@ -958,7 +954,7 @@ contract EVM2EVMMultiOffRamp_executeSingleReport is EVM2EVMMultiOffRampSetup { }); return EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), merkleRoots: roots }); } @@ -2507,7 +2503,7 @@ contract EVM2EVMMultiOffRamp_releaseOrMintTokens is EVM2EVMMultiOffRampSetup { } function test_releaseOrMintTokens_Success() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); IERC20 dstToken1 = IERC20(s_destFeeToken); uint256 startingBalance = dstToken1.balanceOf(OWNER); uint256 amount1 = 100; @@ -2543,7 +2539,7 @@ contract EVM2EVMMultiOffRamp_releaseOrMintTokens is EVM2EVMMultiOffRampSetup { } function test_releaseOrMintTokens_destDenominatedDecimals_Success() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); uint256 amount = 100; uint256 destinationDenominationMultiplier = 1000; srcTokenAmounts[1].amount = amount; @@ -2567,7 +2563,7 @@ contract EVM2EVMMultiOffRamp_releaseOrMintTokens is EVM2EVMMultiOffRampSetup { // Revert function test_TokenHandlingError_Reverts() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); bytes memory unknownError = bytes("unknown error"); s_maybeRevertingPool.setShouldRevert(unknownError); @@ -2585,7 +2581,7 @@ contract EVM2EVMMultiOffRamp_releaseOrMintTokens is EVM2EVMMultiOffRampSetup { function test_releaseOrMintTokens_InvalidDataLengthReturnData_Revert() public { uint256 amount = 100; - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); srcTokenAmounts[0].amount = amount; bytes[] memory offchainTokenData = new bytes[](srcTokenAmounts.length); @@ -2620,7 +2616,7 @@ contract EVM2EVMMultiOffRamp_releaseOrMintTokens is EVM2EVMMultiOffRampSetup { } function test_releaseOrMintTokens_InvalidEVMAddress_Revert() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); bytes[] memory offchainTokenData = new bytes[](srcTokenAmounts.length); Internal.RampTokenAmount[] memory sourceTokenAmounts = _getDefaultSourceTokenData(srcTokenAmounts); @@ -2652,7 +2648,7 @@ contract EVM2EVMMultiOffRamp_releaseOrMintTokens is EVM2EVMMultiOffRampSetup { } function test_releaseOrMintTokens_PoolDoesNotSupportDest_Reverts() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); uint256 amount1 = 100; srcTokenAmounts[0].amount = amount1; @@ -2995,7 +2991,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.expectEmit(); emit EVM2EVMMultiOffRamp.CommitReportAccepted(commitReport); @@ -3022,7 +3018,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { merkleRoot: "stale report 1" }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.expectEmit(); emit EVM2EVMMultiOffRamp.CommitReportAccepted(commitReport); @@ -3056,7 +3052,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { function test_OnlyTokenPriceUpdates_Success() public { EVM2EVMMultiOffRamp.MerkleRoot[] memory roots = new EVM2EVMMultiOffRamp.MerkleRoot[](0); EVM2EVMMultiOffRamp.CommitReport memory commitReport = EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), merkleRoots: roots }); @@ -3074,7 +3070,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { function test_OnlyGasPriceUpdates_Success() public { EVM2EVMMultiOffRamp.MerkleRoot[] memory roots = new EVM2EVMMultiOffRamp.MerkleRoot[](0); EVM2EVMMultiOffRamp.CommitReport memory commitReport = EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), merkleRoots: roots }); @@ -3091,7 +3087,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { function test_PriceSequenceNumberCleared_Success() public { EVM2EVMMultiOffRamp.MerkleRoot[] memory roots = new EVM2EVMMultiOffRamp.MerkleRoot[](0); EVM2EVMMultiOffRamp.CommitReport memory commitReport = EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), merkleRoots: roots }); @@ -3142,7 +3138,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { uint224 tokenPrice2 = 5e18; EVM2EVMMultiOffRamp.MerkleRoot[] memory roots = new EVM2EVMMultiOffRamp.MerkleRoot[](0); EVM2EVMMultiOffRamp.CommitReport memory commitReport = EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice1), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice1), merkleRoots: roots }); @@ -3161,7 +3157,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { interval: EVM2EVMMultiOffRamp.Interval(1, maxSeq), merkleRoot: "stale report" }); - commitReport.priceUpdates = getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice2); + commitReport.priceUpdates = _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, tokenPrice2); commitReport.merkleRoots = roots; vm.expectEmit(); @@ -3263,7 +3259,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.expectRevert(abi.encodeWithSelector(EVM2EVMMultiOffRamp.CursedByRMN.selector, roots[0].sourceChainSelector)); _commit(commitReport, s_latestSequenceNumber); @@ -3277,7 +3273,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { merkleRoot: bytes32(0) }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.expectRevert(EVM2EVMMultiOffRamp.InvalidRoot.selector); _commit(commitReport, s_latestSequenceNumber); @@ -3292,7 +3288,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { merkleRoot: bytes32(0) }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.expectRevert( abi.encodeWithSelector(EVM2EVMMultiOffRamp.InvalidInterval.selector, roots[0].sourceChainSelector, interval) @@ -3310,7 +3306,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { merkleRoot: bytes32(0) }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.expectRevert( abi.encodeWithSelector(EVM2EVMMultiOffRamp.InvalidInterval.selector, roots[0].sourceChainSelector, interval) @@ -3321,7 +3317,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { function test_ZeroEpochAndRound_Revert() public { EVM2EVMMultiOffRamp.MerkleRoot[] memory roots = new EVM2EVMMultiOffRamp.MerkleRoot[](0); EVM2EVMMultiOffRamp.CommitReport memory commitReport = EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), merkleRoots: roots }); @@ -3332,7 +3328,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { function test_OnlyPriceUpdateStaleReport_Revert() public { EVM2EVMMultiOffRamp.MerkleRoot[] memory roots = new EVM2EVMMultiOffRamp.MerkleRoot[](0); EVM2EVMMultiOffRamp.CommitReport memory commitReport = EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), merkleRoots: roots }); @@ -3353,7 +3349,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); vm.expectRevert(abi.encodeWithSelector(EVM2EVMMultiOffRamp.SourceChainNotEnabled.selector, 0)); _commit(commitReport, s_latestSequenceNumber); @@ -3367,7 +3363,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { merkleRoot: "Only a single root" }); EVM2EVMMultiOffRamp.CommitReport memory commitReport = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); _commit(commitReport, s_latestSequenceNumber); commitReport.merkleRoots[0].interval = EVM2EVMMultiOffRamp.Interval(3, 3); @@ -3389,7 +3385,7 @@ contract EVM2EVMMultiOffRamp_commit is EVM2EVMMultiOffRampSetup { }); return EVM2EVMMultiOffRamp.CommitReport({ - priceUpdates: getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), + priceUpdates: _getSingleTokenPriceUpdateStruct(s_sourceFeeToken, 4e18), merkleRoots: roots }); } @@ -3427,7 +3423,7 @@ contract EVM2EVMMultiOffRamp_resetUnblessedRoots is EVM2EVMMultiOffRampSetup { }); EVM2EVMMultiOffRamp.CommitReport memory report = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); _commit(report, ++s_latestSequenceNumber); @@ -3480,7 +3476,7 @@ contract EVM2EVMMultiOffRamp_verify is EVM2EVMMultiOffRampSetup { merkleRoot: leaves[0] }); EVM2EVMMultiOffRamp.CommitReport memory report = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); _commit(report, ++s_latestSequenceNumber); bytes32[] memory proofs = new bytes32[](0); // We have not blessed this root, should return 0. @@ -3498,7 +3494,7 @@ contract EVM2EVMMultiOffRamp_verify is EVM2EVMMultiOffRampSetup { merkleRoot: leaves[0] }); EVM2EVMMultiOffRamp.CommitReport memory report = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); _commit(report, ++s_latestSequenceNumber); // Bless that root. IRMN.TaggedRoot[] memory taggedRoots = new IRMN.TaggedRoot[](1); @@ -3521,7 +3517,7 @@ contract EVM2EVMMultiOffRamp_verify is EVM2EVMMultiOffRampSetup { }); EVM2EVMMultiOffRamp.CommitReport memory report = - EVM2EVMMultiOffRamp.CommitReport({priceUpdates: getEmptyPriceUpdates(), merkleRoots: roots}); + EVM2EVMMultiOffRamp.CommitReport({priceUpdates: _getEmptyPriceUpdates(), merkleRoots: roots}); _commit(report, ++s_latestSequenceNumber); // Bless that root. diff --git a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRampSetup.t.sol b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRampSetup.t.sol index 4813d024af..29864a7071 100644 --- a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRampSetup.t.sol +++ b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRampSetup.t.sol @@ -2,8 +2,6 @@ pragma solidity 0.8.24; import {IAny2EVMMessageReceiver} from "../../interfaces/IAny2EVMMessageReceiver.sol"; - -import {IAny2EVMOffRamp} from "../../interfaces/IAny2EVMOffRamp.sol"; import {ICommitStore} from "../../interfaces/ICommitStore.sol"; import {IRMN} from "../../interfaces/IRMN.sol"; @@ -16,22 +14,18 @@ import {Internal} from "../../libraries/Internal.sol"; import {MultiOCR3Base} from "../../ocr/MultiOCR3Base.sol"; import {EVM2EVMMultiOffRamp} from "../../offRamp/EVM2EVMMultiOffRamp.sol"; import {EVM2EVMOffRamp} from "../../offRamp/EVM2EVMOffRamp.sol"; -import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; -import {TokenSetup} from "../TokenSetup.t.sol"; import {EVM2EVMMultiOffRampHelper} from "../helpers/EVM2EVMMultiOffRampHelper.sol"; import {EVM2EVMOffRampHelper} from "../helpers/EVM2EVMOffRampHelper.sol"; import {MaybeRevertingBurnMintTokenPool} from "../helpers/MaybeRevertingBurnMintTokenPool.sol"; import {MessageInterceptorHelper} from "../helpers/MessageInterceptorHelper.sol"; import {MaybeRevertMessageReceiver} from "../helpers/receivers/MaybeRevertMessageReceiver.sol"; -import {MockCommitStore} from "../mocks/MockCommitStore.sol"; import {MultiOCR3BaseSetup} from "../ocr/MultiOCR3BaseSetup.t.sol"; -import {PriceRegistrySetup} from "../priceRegistry/PriceRegistry.t.sol"; -import {Vm} from "forge-std/Test.sol"; +import {PriceRegistrySetup} from "../priceRegistry/PriceRegistrySetup.t.sol"; -import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; +import {Vm} from "forge-std/Test.sol"; -contract EVM2EVMMultiOffRampSetup is TokenSetup, PriceRegistrySetup, MultiOCR3BaseSetup { +contract EVM2EVMMultiOffRampSetup is PriceRegistrySetup, MultiOCR3BaseSetup { uint64 internal constant SOURCE_CHAIN_SELECTOR_1 = SOURCE_CHAIN_SELECTOR; uint64 internal constant SOURCE_CHAIN_SELECTOR_2 = 6433500567565415381; uint64 internal constant SOURCE_CHAIN_SELECTOR_3 = 4051577828743386545; @@ -63,8 +57,7 @@ contract EVM2EVMMultiOffRampSetup is TokenSetup, PriceRegistrySetup, MultiOCR3Ba uint64 internal s_latestSequenceNumber; - function setUp() public virtual override(TokenSetup, PriceRegistrySetup, MultiOCR3BaseSetup) { - TokenSetup.setUp(); + function setUp() public virtual override(PriceRegistrySetup, MultiOCR3BaseSetup) { PriceRegistrySetup.setUp(); MultiOCR3BaseSetup.setUp(); @@ -149,7 +142,7 @@ contract EVM2EVMMultiOffRampSetup is TokenSetup, PriceRegistrySetup, MultiOCR3Ba rmnProxy: address(s_mockRMN), tokenAdminRegistry: address(s_tokenAdminRegistry) }), - getInboundRateLimiterConfig() + _getInboundRateLimiterConfig() ); offRamp.setOCR2Config( s_validSigners, @@ -289,7 +282,7 @@ contract EVM2EVMMultiOffRampSetup is TokenSetup, PriceRegistrySetup, MultiOCR3Ba uint64 sequenceNumber, uint256[] memory amounts ) internal view returns (Internal.Any2EVMRampMessage memory) { - Client.EVMTokenAmount[] memory tokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory tokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); for (uint256 i = 0; i < tokenAmounts.length; ++i) { tokenAmounts[i].amount = amounts[i]; } @@ -351,7 +344,7 @@ contract EVM2EVMMultiOffRampSetup is TokenSetup, PriceRegistrySetup, MultiOCR3Ba bytes memory onRamp ) internal view returns (Internal.Any2EVMRampMessage[] memory) { Internal.Any2EVMRampMessage[] memory messages = new Internal.Any2EVMRampMessage[](2); - Client.EVMTokenAmount[] memory tokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory tokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); tokenAmounts[0].amount = 1e18; tokenAmounts[1].amount = 5e18; messages[0] = _generateAny2EVMMessage(sourceChainSelector, onRamp, 1, tokenAmounts, false); diff --git a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRamp.t.sol b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRamp.t.sol index 167ac83330..6162419367 100644 --- a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRamp.t.sol +++ b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRamp.t.sol @@ -2,14 +2,12 @@ pragma solidity 0.8.24; import {ICommitStore} from "../../interfaces/ICommitStore.sol"; -import {IPoolV1} from "../../interfaces/IPool.sol"; import {ITokenAdminRegistry} from "../../interfaces/ITokenAdminRegistry.sol"; import {CallWithExactGas} from "../../../shared/call/CallWithExactGas.sol"; import {GenericReceiver} from "../../../shared/test/testhelpers/GenericReceiver.sol"; import {AggregateRateLimiter} from "../../AggregateRateLimiter.sol"; -import {RMN} from "../../RMN.sol"; import {Router} from "../../Router.sol"; import {Client} from "../../libraries/Client.sol"; import {Internal} from "../../libraries/Internal.sol"; @@ -25,8 +23,6 @@ import {ConformingReceiver} from "../helpers/receivers/ConformingReceiver.sol"; import {MaybeRevertMessageReceiver} from "../helpers/receivers/MaybeRevertMessageReceiver.sol"; import {MaybeRevertMessageReceiverNo165} from "../helpers/receivers/MaybeRevertMessageReceiverNo165.sol"; import {ReentrancyAbuser} from "../helpers/receivers/ReentrancyAbuser.sol"; -import {MockCommitStore} from "../mocks/MockCommitStore.sol"; -import {OCR2Base} from "../ocr/OCR2Base.t.sol"; import {OCR2BaseNoChecks} from "../ocr/OCR2BaseNoChecks.t.sol"; import {EVM2EVMOffRampSetup} from "./EVM2EVMOffRampSetup.t.sol"; import {stdError} from "forge-std/Test.sol"; @@ -47,7 +43,7 @@ contract EVM2EVMOffRamp_constructor is EVM2EVMOffRampSetup { EVM2EVMOffRamp.DynamicConfig memory dynamicConfig = generateDynamicOffRampConfig(address(s_destRouter), address(s_priceRegistry)); - s_offRamp = new EVM2EVMOffRampHelper(staticConfig, getInboundRateLimiterConfig()); + s_offRamp = new EVM2EVMOffRampHelper(staticConfig, _getInboundRateLimiterConfig()); s_offRamp.setOCR2Config( s_valid_signers, s_valid_transmitters, s_f, abi.encode(dynamicConfig), s_offchainConfigVersion, abi.encode("") @@ -108,7 +104,7 @@ contract EVM2EVMOffRamp_constructor is EVM2EVMOffRampSetup { rmnProxy: address(s_mockRMN), tokenAdminRegistry: address(s_tokenAdminRegistry) }), - getInboundRateLimiterConfig() + _getInboundRateLimiterConfig() ); } } @@ -1796,7 +1792,7 @@ contract EVM2EVMOffRamp__releaseOrMintToken is EVM2EVMOffRampSetup { contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { function test_releaseOrMintTokens_Success() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); IERC20 dstToken1 = IERC20(s_destFeeToken); uint256 startingBalance = dstToken1.balanceOf(OWNER); uint256 amount1 = 100; @@ -1835,7 +1831,7 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { } function test_releaseOrMintTokens_destDenominatedDecimals_Success() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); uint256 amount = 100; uint256 destinationDenominationMultiplier = 1000; srcTokenAmounts[1].amount = amount; @@ -1859,10 +1855,10 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { function test_OverValueWithARLOff_Success() public { // Set a high price to trip the ARL uint224 tokenPrice = 3 ** 128; - Internal.PriceUpdates memory priceUpdates = getSingleTokenPriceUpdateStruct(s_destFeeToken, tokenPrice); + Internal.PriceUpdates memory priceUpdates = _getSingleTokenPriceUpdateStruct(s_destFeeToken, tokenPrice); s_priceRegistry.updatePrices(priceUpdates); - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); uint256 amount1 = 100; srcTokenAmounts[0].amount = amount1; @@ -1876,7 +1872,7 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { vm.expectRevert( abi.encodeWithSelector( RateLimiter.AggregateValueMaxCapacityExceeded.selector, - getInboundRateLimiterConfig().capacity, + _getInboundRateLimiterConfig().capacity, (amount1 * tokenPrice) / 1e18 ) ); @@ -1900,7 +1896,7 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { // Revert function test_TokenHandlingError_Reverts() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); bytes memory unknownError = bytes("unknown error"); s_maybeRevertingPool.setShouldRevert(unknownError); @@ -1919,7 +1915,7 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { function test_releaseOrMintTokens_InvalidDataLengthReturnData_Revert() public { uint256 amount = 100; - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); srcTokenAmounts[0].amount = amount; bytes memory originalSender = abi.encode(OWNER); @@ -1956,7 +1952,7 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { } function test_releaseOrMintTokens_InvalidEVMAddress_Revert() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); bytes memory originalSender = abi.encode(OWNER); bytes[] memory offchainTokenData = new bytes[](srcTokenAmounts.length); @@ -1980,7 +1976,7 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { } function test_RateLimitErrors_Reverts() public { - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); bytes[] memory rateLimitErrors = new bytes[](5); rateLimitErrors[0] = abi.encodeWithSelector(RateLimiter.BucketOverfilled.selector); @@ -2036,9 +2032,9 @@ contract EVM2EVMOffRamp__releaseOrMintTokens is EVM2EVMOffRampSetup { function test_PriceNotFoundForToken_Reverts() public { // Set token price to 0 - s_priceRegistry.updatePrices(getSingleTokenPriceUpdateStruct(s_destFeeToken, 0)); + s_priceRegistry.updatePrices(_getSingleTokenPriceUpdateStruct(s_destFeeToken, 0)); - Client.EVMTokenAmount[] memory srcTokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory srcTokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); uint256 amount1 = 100; srcTokenAmounts[0].amount = amount1; diff --git a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRampSetup.t.sol b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRampSetup.t.sol index ccb91a7e72..a0fa6a4a8e 100644 --- a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRampSetup.t.sol +++ b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRampSetup.t.sol @@ -3,13 +3,11 @@ pragma solidity 0.8.24; import {IAny2EVMMessageReceiver} from "../../interfaces/IAny2EVMMessageReceiver.sol"; import {ICommitStore} from "../../interfaces/ICommitStore.sol"; -import {IPoolV1} from "../../interfaces/IPool.sol"; import {Router} from "../../Router.sol"; import {Client} from "../../libraries/Client.sol"; import {Internal} from "../../libraries/Internal.sol"; import {EVM2EVMOffRamp} from "../../offRamp/EVM2EVMOffRamp.sol"; -import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; import {TokenSetup} from "../TokenSetup.t.sol"; import {EVM2EVMOffRampHelper} from "../helpers/EVM2EVMOffRampHelper.sol"; @@ -17,9 +15,7 @@ import {MaybeRevertingBurnMintTokenPool} from "../helpers/MaybeRevertingBurnMint import {MaybeRevertMessageReceiver} from "../helpers/receivers/MaybeRevertMessageReceiver.sol"; import {MockCommitStore} from "../mocks/MockCommitStore.sol"; import {OCR2BaseSetup} from "../ocr/OCR2Base.t.sol"; -import {PriceRegistrySetup} from "../priceRegistry/PriceRegistry.t.sol"; - -import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; +import {PriceRegistrySetup} from "../priceRegistry/PriceRegistrySetup.t.sol"; contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup { MockCommitStore internal s_mockCommitStore; @@ -58,7 +54,7 @@ contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup { rmnProxy: address(s_mockRMN), tokenAdminRegistry: address(s_tokenAdminRegistry) }), - getInboundRateLimiterConfig() + _getInboundRateLimiterConfig() ); s_offRamp.setOCR2Config( s_valid_signers, @@ -133,7 +129,7 @@ contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup { uint64 sequenceNumber, uint256[] memory amounts ) internal view returns (Internal.EVM2EVMMessage memory) { - Client.EVMTokenAmount[] memory tokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory tokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); for (uint256 i = 0; i < tokenAmounts.length; ++i) { tokenAmounts[i].amount = amounts[i]; } @@ -192,7 +188,7 @@ contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup { function _generateSingleBasicMessageWithTokens() internal view returns (Internal.EVM2EVMMessage[] memory) { Internal.EVM2EVMMessage[] memory messages = new Internal.EVM2EVMMessage[](1); - Client.EVMTokenAmount[] memory tokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory tokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); tokenAmounts[0].amount = 1e18; messages[0] = _generateAny2EVMMessage(1, tokenAmounts, false); return messages; @@ -200,7 +196,7 @@ contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup { function _generateMessagesWithTokens() internal view returns (Internal.EVM2EVMMessage[] memory) { Internal.EVM2EVMMessage[] memory messages = new Internal.EVM2EVMMessage[](2); - Client.EVMTokenAmount[] memory tokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory tokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); tokenAmounts[0].amount = 1e18; tokenAmounts[1].amount = 5e18; messages[0] = _generateAny2EVMMessage(1, tokenAmounts, false); diff --git a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRamp.t.sol b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRamp.t.sol index f148177094..cb85896b32 100644 --- a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRamp.t.sol +++ b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRamp.t.sol @@ -2,20 +2,21 @@ pragma solidity 0.8.24; import {IMessageInterceptor} from "../../interfaces/IMessageInterceptor.sol"; -import {ITokenAdminRegistry} from "../../interfaces/ITokenAdminRegistry.sol"; +import {IRouter} from "../../interfaces/IRouter.sol"; import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol"; -import {MultiAggregateRateLimiter} from "../../MultiAggregateRateLimiter.sol"; +import {PriceRegistry} from "../../PriceRegistry.sol"; +import {Client} from "../../libraries/Client.sol"; +import {Internal} from "../../libraries/Internal.sol"; import {Pool} from "../../libraries/Pool.sol"; -import {RateLimiter} from "../../libraries/RateLimiter.sol"; import {USDPriceWith18Decimals} from "../../libraries/USDPriceWith18Decimals.sol"; import {EVM2EVMMultiOnRamp} from "../../onRamp/EVM2EVMMultiOnRamp.sol"; -import {EVM2EVMOnRamp} from "../../onRamp/EVM2EVMOnRamp.sol"; -import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol"; -import {EVM2EVMOnRampHelper} from "../helpers/EVM2EVMOnRampHelper.sol"; +import {TokenPool} from "../../pools/TokenPool.sol"; +import {EVM2EVMMultiOnRampHelper} from "../helpers/EVM2EVMMultiOnRampHelper.sol"; import {MaybeRevertingBurnMintTokenPool} from "../helpers/MaybeRevertingBurnMintTokenPool.sol"; -import {MessageInterceptorHelper} from "../helpers/MessageInterceptorHelper.sol"; -import "./EVM2EVMMultiOnRampSetup.t.sol"; +import {EVM2EVMMultiOnRampSetup} from "./EVM2EVMMultiOnRampSetup.t.sol"; + +import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; contract EVM2EVMMultiOnRamp_constructor is EVM2EVMMultiOnRampSetup { function test_Constructor_Success() public { @@ -422,7 +423,7 @@ contract EVM2EVMMultiOnRamp_forwardFromRouter is EVM2EVMMultiOnRampSetup { vm.stopPrank(); vm.startPrank(OWNER); - Internal.PriceUpdates memory priceUpdates = getSingleTokenPriceUpdateStruct(wrongToken, 1); + Internal.PriceUpdates memory priceUpdates = _getSingleTokenPriceUpdateStruct(wrongToken, 1); s_priceRegistry.updatePrices(priceUpdates); // Change back to the router @@ -474,8 +475,8 @@ contract EVM2EVMMultiOnRamp_forwardFromRouter is EVM2EVMMultiOnRampSetup { remotePoolAddress: abi.encode(s_destTokenPool), remoteTokenAddress: abi.encode(s_destToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); newPool.applyChainUpdates(chainUpdates); diff --git a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRampSetup.t.sol b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRampSetup.t.sol index d237a23e8f..66daefedd3 100644 --- a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRampSetup.t.sol +++ b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMMultiOnRampSetup.t.sol @@ -1,27 +1,21 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.24; -import {IPoolV1} from "../../interfaces/IPool.sol"; import {IRouter} from "../../interfaces/IRouter.sol"; import {AuthorizedCallers} from "../../../shared/access/AuthorizedCallers.sol"; import {NonceManager} from "../../NonceManager.sol"; -import {PriceRegistry} from "../../PriceRegistry.sol"; import {Router} from "../../Router.sol"; import {Client} from "../../libraries/Client.sol"; import {Internal} from "../../libraries/Internal.sol"; import {EVM2EVMMultiOnRamp} from "../../onRamp/EVM2EVMMultiOnRamp.sol"; -import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; -import {TokenPool} from "../../pools/TokenPool.sol"; -import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol"; -import {TokenSetup} from "../TokenSetup.t.sol"; import {EVM2EVMMultiOnRampHelper} from "../helpers/EVM2EVMMultiOnRampHelper.sol"; import {MessageInterceptorHelper} from "../helpers/MessageInterceptorHelper.sol"; -import {PriceRegistryFeeSetup} from "../priceRegistry/PriceRegistry.t.sol"; +import {PriceRegistryFeeSetup} from "../priceRegistry/PriceRegistrySetup.t.sol"; import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; -contract EVM2EVMMultiOnRampSetup is TokenSetup, PriceRegistryFeeSetup { +contract EVM2EVMMultiOnRampSetup is PriceRegistryFeeSetup { uint256 internal immutable i_tokenAmount0 = 9; uint256 internal immutable i_tokenAmount1 = 7; @@ -32,9 +26,8 @@ contract EVM2EVMMultiOnRampSetup is TokenSetup, PriceRegistryFeeSetup { address[] internal s_offRamps; NonceManager internal s_outboundNonceManager; - function setUp() public virtual override(TokenSetup, PriceRegistryFeeSetup) { - TokenSetup.setUp(); - PriceRegistryFeeSetup.setUp(); + function setUp() public virtual override { + super.setUp(); s_outboundMessageValidator = new MessageInterceptorHelper(); s_outboundNonceManager = new NonceManager(new address[](0)); @@ -59,7 +52,7 @@ contract EVM2EVMMultiOnRampSetup is TokenSetup, PriceRegistryFeeSetup { } function _generateTokenMessage() public view returns (Client.EVM2AnyMessage memory) { - Client.EVMTokenAmount[] memory tokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory tokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); tokenAmounts[0].amount = i_tokenAmount0; tokenAmounts[1].amount = i_tokenAmount1; return Client.EVM2AnyMessage({ diff --git a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRamp.t.sol b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRamp.t.sol index 8559122be7..54054716e6 100644 --- a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRamp.t.sol +++ b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRamp.t.sol @@ -9,7 +9,8 @@ import {Pool} from "../../libraries/Pool.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; import {USDPriceWith18Decimals} from "../../libraries/USDPriceWith18Decimals.sol"; import {EVM2EVMOnRamp} from "../../onRamp/EVM2EVMOnRamp.sol"; -import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol"; +import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; +import {TokenPool} from "../../pools/TokenPool.sol"; import {MaybeRevertingBurnMintTokenPool} from "../helpers/MaybeRevertingBurnMintTokenPool.sol"; import "./EVM2EVMOnRampSetup.t.sol"; @@ -34,7 +35,7 @@ contract EVM2EVMOnRamp_constructor is EVM2EVMOnRampSetup { s_onRamp = new EVM2EVMOnRampHelper( staticConfig, dynamicConfig, - getOutboundRateLimiterConfig(), + _getOutboundRateLimiterConfig(), s_feeTokenConfigArgs, s_tokenTransferFeeConfigArgs, getNopsAndWeights() @@ -485,14 +486,14 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup { vm.startPrank(OWNER); // Set a high price to trip the ARL uint224 tokenPrice = 3 ** 128; - Internal.PriceUpdates memory priceUpdates = getSingleTokenPriceUpdateStruct(s_sourceTokens[0], tokenPrice); + Internal.PriceUpdates memory priceUpdates = _getSingleTokenPriceUpdateStruct(s_sourceTokens[0], tokenPrice); s_priceRegistry.updatePrices(priceUpdates); vm.startPrank(address(s_sourceRouter)); vm.expectRevert( abi.encodeWithSelector( RateLimiter.AggregateValueMaxCapacityExceeded.selector, - getOutboundRateLimiterConfig().capacity, + _getOutboundRateLimiterConfig().capacity, (message.tokenAmounts[0].amount * tokenPrice) / 1e18 ) ); @@ -660,7 +661,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup { vm.stopPrank(); vm.startPrank(OWNER); - Internal.PriceUpdates memory priceUpdates = getSingleTokenPriceUpdateStruct(wrongToken, 1); + Internal.PriceUpdates memory priceUpdates = _getSingleTokenPriceUpdateStruct(wrongToken, 1); s_priceRegistry.updatePrices(priceUpdates); // Change back to the router @@ -681,7 +682,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup { vm.expectRevert( abi.encodeWithSelector( RateLimiter.AggregateValueMaxCapacityExceeded.selector, - getOutboundRateLimiterConfig().capacity, + _getOutboundRateLimiterConfig().capacity, (message.tokenAmounts[0].amount * s_sourceTokenPrices[0]) / 1e18 ) ); @@ -693,7 +694,7 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup { // Set token price to 0 vm.stopPrank(); vm.startPrank(OWNER); - s_priceRegistry.updatePrices(getSingleTokenPriceUpdateStruct(CUSTOM_TOKEN, 0)); + s_priceRegistry.updatePrices(_getSingleTokenPriceUpdateStruct(CUSTOM_TOKEN, 0)); vm.startPrank(address(s_sourceRouter)); @@ -784,8 +785,8 @@ contract EVM2EVMOnRamp_forwardFromRouter is EVM2EVMOnRampSetup { remotePoolAddress: abi.encode(s_destTokenPool), remoteTokenAddress: abi.encode(s_destToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); newPool.applyChainUpdates(chainUpdates); @@ -905,7 +906,7 @@ contract EVM2EVMOnRamp_forwardFromRouter_upgrade is EVM2EVMOnRampSetup { tokenAdminRegistry: address(s_tokenAdminRegistry) }), generateDynamicOnRampConfig(address(s_sourceRouter), address(s_priceRegistry)), - getOutboundRateLimiterConfig(), + _getOutboundRateLimiterConfig(), s_feeTokenConfigArgs, s_tokenTransferFeeConfigArgs, getNopsAndWeights() @@ -1003,8 +1004,8 @@ contract EVM2EVMOnRamp_getFeeSetup is EVM2EVMOnRampSetup { remotePoolAddress: abi.encode(address(111111)), remoteTokenAddress: abi.encode(s_destToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); wrappedNativePool.applyChainUpdates(wrappedNativeChainUpdate); s_tokenAdminRegistry.setPool(s_sourceRouter.getWrappedNative(), address(wrappedNativePool)); @@ -1018,8 +1019,8 @@ contract EVM2EVMOnRamp_getFeeSetup is EVM2EVMOnRampSetup { remotePoolAddress: abi.encode(makeAddr("random")), remoteTokenAddress: abi.encode(s_destToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); customPool.applyChainUpdates(customChainUpdate); s_tokenAdminRegistry.setPool(CUSTOM_TOKEN, address(customPool)); diff --git a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRampSetup.t.sol b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRampSetup.t.sol index 46a695701f..f827bf983c 100644 --- a/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRampSetup.t.sol +++ b/contracts/src/v0.8/ccip/test/onRamp/EVM2EVMOnRampSetup.t.sol @@ -1,19 +1,14 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.24; -import {IPoolV1} from "../../interfaces/IPool.sol"; - -import {PriceRegistry} from "../../PriceRegistry.sol"; import {Router} from "../../Router.sol"; import {Client} from "../../libraries/Client.sol"; import {Internal} from "../../libraries/Internal.sol"; import {Pool} from "../../libraries/Pool.sol"; import {EVM2EVMOnRamp} from "../../onRamp/EVM2EVMOnRamp.sol"; -import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; -import {TokenPool} from "../../pools/TokenPool.sol"; import {TokenSetup} from "../TokenSetup.t.sol"; import {EVM2EVMOnRampHelper} from "../helpers/EVM2EVMOnRampHelper.sol"; -import {PriceRegistrySetup} from "../priceRegistry/PriceRegistry.t.sol"; +import {PriceRegistrySetup} from "../priceRegistry/PriceRegistrySetup.t.sol"; import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; @@ -36,7 +31,7 @@ contract EVM2EVMOnRampSetup is TokenSetup, PriceRegistrySetup { TokenSetup.setUp(); PriceRegistrySetup.setUp(); - s_priceRegistry.updatePrices(getSingleTokenPriceUpdateStruct(CUSTOM_TOKEN, CUSTOM_TOKEN_PRICE)); + s_priceRegistry.updatePrices(_getSingleTokenPriceUpdateStruct(CUSTOM_TOKEN, CUSTOM_TOKEN_PRICE)); address WETH = s_sourceRouter.getWrappedNative(); @@ -94,7 +89,7 @@ contract EVM2EVMOnRampSetup is TokenSetup, PriceRegistrySetup { tokenAdminRegistry: address(s_tokenAdminRegistry) }), generateDynamicOnRampConfig(address(s_sourceRouter), address(s_priceRegistry)), - getOutboundRateLimiterConfig(), + _getOutboundRateLimiterConfig(), s_feeTokenConfigArgs, s_tokenTransferFeeConfigArgs, getNopsAndWeights() @@ -151,7 +146,7 @@ contract EVM2EVMOnRampSetup is TokenSetup, PriceRegistrySetup { } function _generateTokenMessage() public view returns (Client.EVM2AnyMessage memory) { - Client.EVMTokenAmount[] memory tokenAmounts = getCastedSourceEVMTokenAmountsWithZeroAmounts(); + Client.EVMTokenAmount[] memory tokenAmounts = _getCastedSourceEVMTokenAmountsWithZeroAmounts(); tokenAmounts[0].amount = i_tokenAmount0; tokenAmounts[1].amount = i_tokenAmount1; return Client.EVM2AnyMessage({ diff --git a/contracts/src/v0.8/ccip/test/pools/BurnFromMintTokenPool.t.sol b/contracts/src/v0.8/ccip/test/pools/BurnFromMintTokenPool.t.sol index 307cbf21f4..b5967e74d1 100644 --- a/contracts/src/v0.8/ccip/test/pools/BurnFromMintTokenPool.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/BurnFromMintTokenPool.t.sol @@ -5,7 +5,6 @@ import {Pool} from "../../libraries/Pool.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; import {BurnFromMintTokenPool} from "../../pools/BurnFromMintTokenPool.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; -import {BaseTest} from "../BaseTest.t.sol"; import {BurnMintSetup} from "./BurnMintSetup.t.sol"; import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; @@ -95,8 +94,8 @@ contract BurnFromMintTokenPool_lockOrBurn is BurnFromMintTokenPoolSetup { amount: 1, localToken: address(s_burnMintERC677), remoteChainSelector: wrongChainSelector, - sourcePoolAddress: generateSourceTokenData().sourcePoolAddress, - sourcePoolData: generateSourceTokenData().extraData, + sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress, + sourcePoolData: _generateSourceTokenData().extraData, offchainTokenData: "" }) ); diff --git a/contracts/src/v0.8/ccip/test/pools/BurnMintSetup.t.sol b/contracts/src/v0.8/ccip/test/pools/BurnMintSetup.t.sol index a39fd1bb9f..220f6ca112 100644 --- a/contracts/src/v0.8/ccip/test/pools/BurnMintSetup.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/BurnMintSetup.t.sol @@ -28,8 +28,8 @@ contract BurnMintSetup is RouterSetup { remotePoolAddress: abi.encode(s_remoteBurnMintPool), remoteTokenAddress: abi.encode(s_remoteToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); BurnMintTokenPool(pool).applyChainUpdates(chains); diff --git a/contracts/src/v0.8/ccip/test/pools/BurnMintTokenPool.t.sol b/contracts/src/v0.8/ccip/test/pools/BurnMintTokenPool.t.sol index 5a7644d033..8a6d047380 100644 --- a/contracts/src/v0.8/ccip/test/pools/BurnMintTokenPool.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/BurnMintTokenPool.t.sol @@ -1,15 +1,10 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.24; -import {IPoolV1} from "../../interfaces/IPool.sol"; - -import {Internal} from "../../libraries/Internal.sol"; import {Pool} from "../../libraries/Pool.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; -import {EVM2EVMOffRamp} from "../../offRamp/EVM2EVMOffRamp.sol"; import {BurnMintTokenPool} from "../../pools/BurnMintTokenPool.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; -import {BaseTest} from "../BaseTest.t.sol"; import {BurnMintSetup} from "./BurnMintSetup.t.sol"; import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; @@ -144,8 +139,8 @@ contract BurnMintTokenPool_releaseOrMint is BurnMintTokenPoolSetup { amount: 1e5, localToken: address(s_burnMintERC677), remoteChainSelector: DEST_CHAIN_SELECTOR, - sourcePoolAddress: generateSourceTokenData().sourcePoolAddress, - sourcePoolData: generateSourceTokenData().extraData, + sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress, + sourcePoolData: _generateSourceTokenData().extraData, offchainTokenData: "" }) ); @@ -164,8 +159,8 @@ contract BurnMintTokenPool_releaseOrMint is BurnMintTokenPoolSetup { amount: 1, localToken: address(s_burnMintERC677), remoteChainSelector: wrongChainSelector, - sourcePoolAddress: generateSourceTokenData().sourcePoolAddress, - sourcePoolData: generateSourceTokenData().extraData, + sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress, + sourcePoolData: _generateSourceTokenData().extraData, offchainTokenData: "" }) ); diff --git a/contracts/src/v0.8/ccip/test/pools/BurnWithFromMintTokenPool.t.sol b/contracts/src/v0.8/ccip/test/pools/BurnWithFromMintTokenPool.t.sol index 568aac6ba1..92e871708d 100644 --- a/contracts/src/v0.8/ccip/test/pools/BurnWithFromMintTokenPool.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/BurnWithFromMintTokenPool.t.sol @@ -5,7 +5,6 @@ import {Pool} from "../../libraries/Pool.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; import {BurnWithFromMintTokenPool} from "../../pools/BurnWithFromMintTokenPool.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; -import {BaseTest} from "../BaseTest.t.sol"; import {BurnMintSetup} from "./BurnMintSetup.t.sol"; import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; @@ -96,8 +95,8 @@ contract BurnWithFromMintTokenPool_lockOrBurn is BurnWithFromMintTokenPoolSetup amount: 1, localToken: address(s_burnMintERC677), remoteChainSelector: wrongChainSelector, - sourcePoolAddress: generateSourceTokenData().sourcePoolAddress, - sourcePoolData: generateSourceTokenData().extraData, + sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress, + sourcePoolData: _generateSourceTokenData().extraData, offchainTokenData: "" }) ); diff --git a/contracts/src/v0.8/ccip/test/pools/LockReleaseTokenPool.t.sol b/contracts/src/v0.8/ccip/test/pools/LockReleaseTokenPool.t.sol index fb5d5e0fd1..ed8a1cf31f 100644 --- a/contracts/src/v0.8/ccip/test/pools/LockReleaseTokenPool.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/LockReleaseTokenPool.t.sol @@ -5,13 +5,10 @@ import {IPoolV1} from "../../interfaces/IPool.sol"; import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol"; import {Router} from "../../Router.sol"; -import {Internal} from "../../libraries/Internal.sol"; import {Pool} from "../../libraries/Pool.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; -import {EVM2EVMOffRamp} from "../../offRamp/EVM2EVMOffRamp.sol"; import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; -import {BaseTest} from "../BaseTest.t.sol"; import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; import {IERC165} from "../../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/introspection/IERC165.sol"; @@ -47,8 +44,8 @@ contract LockReleaseTokenPoolSetup is RouterSetup { remotePoolAddress: abi.encode(s_destPoolAddress), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_lockReleaseTokenPool.applyChainUpdates(chainUpdate); @@ -80,7 +77,7 @@ contract LockReleaseTokenPool_setRebalancer is LockReleaseTokenPoolSetup { contract LockReleaseTokenPool_lockOrBurn is LockReleaseTokenPoolSetup { function test_Fuzz_LockOrBurnNoAllowList_Success(uint256 amount) public { - amount = bound(amount, 1, getOutboundRateLimiterConfig().capacity); + amount = bound(amount, 1, _getOutboundRateLimiterConfig().capacity); vm.startPrank(s_allowedOnRamp); vm.expectEmit(); @@ -179,8 +176,8 @@ contract LockReleaseTokenPool_releaseOrMint is LockReleaseTokenPoolSetup { remotePoolAddress: abi.encode(s_sourcePoolAddress), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_lockReleaseTokenPool.applyChainUpdates(chainUpdate); @@ -222,7 +219,7 @@ contract LockReleaseTokenPool_releaseOrMint is LockReleaseTokenPoolSetup { deal(address(s_token), address(s_lockReleaseTokenPool), amount); vm.startPrank(s_allowedOffRamp); - uint256 capacity = getInboundRateLimiterConfig().capacity; + uint256 capacity = _getInboundRateLimiterConfig().capacity; // Determine if we hit the rate limit or the txs should succeed. if (amount > capacity) { vm.expectRevert( @@ -298,8 +295,8 @@ contract LockReleaseTokenPool_releaseOrMint is LockReleaseTokenPoolSetup { amount: 1e5, localToken: address(s_token), remoteChainSelector: SOURCE_CHAIN_SELECTOR, - sourcePoolAddress: generateSourceTokenData().sourcePoolAddress, - sourcePoolData: generateSourceTokenData().extraData, + sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress, + sourcePoolData: _generateSourceTokenData().extraData, offchainTokenData: "" }) ); diff --git a/contracts/src/v0.8/ccip/test/pools/TokenPool.t.sol b/contracts/src/v0.8/ccip/test/pools/TokenPool.t.sol index 2c9eaf6df0..2c1bc0ed57 100644 --- a/contracts/src/v0.8/ccip/test/pools/TokenPool.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/TokenPool.t.sol @@ -5,7 +5,6 @@ import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol"; import {Router} from "../../Router.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; import {TokenPool} from "../../pools/TokenPool.sol"; -import {BaseTest} from "../BaseTest.t.sol"; import {TokenPoolHelper} from "../helpers/TokenPoolHelper.sol"; import {RouterSetup} from "../router/RouterSetup.t.sol"; @@ -55,8 +54,8 @@ contract TokenPool_getRemotePool is TokenPoolSetup { remotePoolAddress: abi.encode(remotePool), remoteTokenAddress: abi.encode(remoteToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdates); @@ -78,8 +77,8 @@ contract TokenPool_setRemotePool is TokenPoolSetup { remotePoolAddress: abi.encode(initialPool), remoteTokenAddress: abi.encode(remoteToken), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdates); @@ -379,8 +378,8 @@ contract TokenPool_setChainRateLimiterConfig is TokenPoolSetup { remotePoolAddress: abi.encode(address(2)), remoteTokenAddress: abi.encode(address(3)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdates); } @@ -434,7 +433,7 @@ contract TokenPool_setChainRateLimiterConfig is TokenPoolSetup { vm.expectRevert(abi.encodeWithSelector(TokenPool.Unauthorized.selector, STRANGER)); s_tokenPool.setChainRateLimiterConfig( - s_remoteChainSelector, getOutboundRateLimiterConfig(), getInboundRateLimiterConfig() + s_remoteChainSelector, _getOutboundRateLimiterConfig(), _getInboundRateLimiterConfig() ); } @@ -443,7 +442,7 @@ contract TokenPool_setChainRateLimiterConfig is TokenPoolSetup { vm.expectRevert(abi.encodeWithSelector(TokenPool.NonExistentChain.selector, wrongChainSelector)); s_tokenPool.setChainRateLimiterConfig( - wrongChainSelector, getOutboundRateLimiterConfig(), getInboundRateLimiterConfig() + wrongChainSelector, _getOutboundRateLimiterConfig(), _getInboundRateLimiterConfig() ); } } @@ -476,8 +475,8 @@ contract TokenPool_onlyOnRamp is TokenPoolSetup { remotePoolAddress: abi.encode(address(1)), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdate); @@ -507,8 +506,8 @@ contract TokenPool_onlyOnRamp is TokenPoolSetup { remotePoolAddress: abi.encode(address(1)), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdate); @@ -548,8 +547,8 @@ contract TokenPool_onlyOnRamp is TokenPoolSetup { remotePoolAddress: abi.encode(address(1)), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdate); @@ -572,8 +571,8 @@ contract TokenPool_onlyOffRamp is TokenPoolSetup { remotePoolAddress: abi.encode(address(1)), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdate); @@ -603,8 +602,8 @@ contract TokenPool_onlyOffRamp is TokenPoolSetup { remotePoolAddress: abi.encode(address(1)), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdate); @@ -644,8 +643,8 @@ contract TokenPool_onlyOffRamp is TokenPoolSetup { remotePoolAddress: abi.encode(address(1)), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_tokenPool.applyChainUpdates(chainUpdate); diff --git a/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol b/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol index 7259e1d17c..e60d5542f4 100644 --- a/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol @@ -57,7 +57,7 @@ contract USDCTokenPoolSetup is BaseTest { BurnMintERC677 usdcToken = new BurnMintERC677("LINK", "LNK", 18, 0); s_token = usdcToken; deal(address(s_token), OWNER, type(uint256).max); - setUpRamps(); + _setUpRamps(); s_mockUSDCTransmitter = new MockE2EUSDCTransmitter(0, DEST_DOMAIN_IDENTIFIER, address(s_token)); s_mockUSDC = new MockUSDCTokenMessenger(0, address(s_mockUSDCTransmitter)); @@ -78,16 +78,16 @@ contract USDCTokenPoolSetup is BaseTest { remotePoolAddress: abi.encode(SOURCE_CHAIN_USDC_POOL), remoteTokenAddress: abi.encode(address(s_token)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); chainUpdates[1] = TokenPool.ChainUpdate({ remoteChainSelector: DEST_CHAIN_SELECTOR, remotePoolAddress: abi.encode(DEST_CHAIN_USDC_POOL), remoteTokenAddress: abi.encode(DEST_CHAIN_USDC_TOKEN), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_usdcTokenPool.applyChainUpdates(chainUpdates); @@ -105,7 +105,7 @@ contract USDCTokenPoolSetup is BaseTest { s_usdcTokenPoolWithAllowList.setDomains(domains); } - function setUpRamps() internal { + function _setUpRamps() internal { s_router = new Router(address(s_token), address(s_mockRMN)); Router.OnRamp[] memory onRampUpdates = new Router.OnRamp[](1); @@ -176,7 +176,7 @@ contract USDCTokenPool_lockOrBurn is USDCTokenPoolSetup { function test_Fuzz_LockOrBurn_Success(bytes32 destinationReceiver, uint256 amount) public { vm.assume(destinationReceiver != bytes32(0)); - amount = bound(amount, 1, getOutboundRateLimiterConfig().capacity); + amount = bound(amount, 1, _getOutboundRateLimiterConfig().capacity); s_token.transfer(address(s_usdcTokenPool), amount); vm.startPrank(s_routerAllowedOnRamp); @@ -217,7 +217,7 @@ contract USDCTokenPool_lockOrBurn is USDCTokenPoolSetup { function test_Fuzz_LockOrBurnWithAllowList_Success(bytes32 destinationReceiver, uint256 amount) public { vm.assume(destinationReceiver != bytes32(0)); - amount = bound(amount, 1, getOutboundRateLimiterConfig().capacity); + amount = bound(amount, 1, _getOutboundRateLimiterConfig().capacity); s_token.transfer(address(s_usdcTokenPoolWithAllowList), amount); vm.startPrank(s_routerAllowedOnRamp); @@ -267,8 +267,8 @@ contract USDCTokenPool_lockOrBurn is USDCTokenPoolSetup { remotePoolAddress: abi.encode(address(1)), remoteTokenAddress: abi.encode(address(2)), allowed: true, - outboundRateLimiterConfig: getOutboundRateLimiterConfig(), - inboundRateLimiterConfig: getInboundRateLimiterConfig() + outboundRateLimiterConfig: _getOutboundRateLimiterConfig(), + inboundRateLimiterConfig: _getInboundRateLimiterConfig() }); s_usdcTokenPool.applyChainUpdates(chainUpdates); @@ -336,7 +336,7 @@ contract USDCTokenPool_releaseOrMint is USDCTokenPoolSetup { function test_Fuzz_ReleaseOrMint_Success(address recipient, uint256 amount) public { vm.assume(recipient != address(0) && recipient != address(s_token)); - amount = bound(amount, 0, getInboundRateLimiterConfig().capacity); + amount = bound(amount, 0, _getInboundRateLimiterConfig().capacity); USDCMessage memory usdcMessage = USDCMessage({ version: 0, @@ -493,7 +493,7 @@ contract USDCTokenPool_releaseOrMint is USDCTokenPoolSetup { } function test_TokenMaxCapacityExceeded_Revert() public { - uint256 capacity = getInboundRateLimiterConfig().capacity; + uint256 capacity = _getInboundRateLimiterConfig().capacity; uint256 amount = 10 * capacity; address recipient = address(1); vm.startPrank(s_routerAllowedOffRamp); diff --git a/contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistry.t.sol b/contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistry.t.sol index b26eb56474..f59d27a2cb 100644 --- a/contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistry.t.sol +++ b/contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistry.t.sol @@ -1,435 +1,17 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.24; -import {IPriceRegistry} from "../../interfaces/IPriceRegistry.sol"; -import {ITokenAdminRegistry} from "../../interfaces/ITokenAdminRegistry.sol"; - import {AuthorizedCallers} from "../../../shared/access/AuthorizedCallers.sol"; -import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol"; import {MockV3Aggregator} from "../../../tests/MockV3Aggregator.sol"; import {PriceRegistry} from "../../PriceRegistry.sol"; - import {Client} from "../../libraries/Client.sol"; import {Internal} from "../../libraries/Internal.sol"; import {Pool} from "../../libraries/Pool.sol"; import {USDPriceWith18Decimals} from "../../libraries/USDPriceWith18Decimals.sol"; -import {LockReleaseTokenPool} from "../../pools/LockReleaseTokenPool.sol"; -import {TokenPool} from "../../pools/TokenPool.sol"; -import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol"; - -import {TokenSetup} from "../TokenSetup.t.sol"; -import {MaybeRevertingBurnMintTokenPool} from "../helpers/MaybeRevertingBurnMintTokenPool.sol"; import {PriceRegistryHelper} from "../helpers/PriceRegistryHelper.sol"; - -import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; +import {PriceRegistryFeeSetup, PriceRegistrySetup} from "./PriceRegistrySetup.t.sol"; import {Vm} from "forge-std/Vm.sol"; -import {console} from "forge-std/console.sol"; - -contract PriceRegistrySetup is TokenSetup { - uint112 internal constant USD_PER_GAS = 1e6; // 0.001 gwei - uint112 internal constant USD_PER_DATA_AVAILABILITY_GAS = 1e9; // 1 gwei - - address internal constant CUSTOM_TOKEN = address(12345); - uint224 internal constant CUSTOM_TOKEN_PRICE = 1e17; // $0.1 CUSTOM - - // Encode L1 gas price and L2 gas price into a packed price. - // L1 gas price is left-shifted to the higher-order bits. - uint224 internal constant PACKED_USD_PER_GAS = - (uint224(USD_PER_DATA_AVAILABILITY_GAS) << Internal.GAS_PRICE_BITS) + USD_PER_GAS; - - PriceRegistryHelper internal s_priceRegistry; - // Cheat to store the price updates in storage since struct arrays aren't supported. - bytes internal s_encodedInitialPriceUpdates; - address internal s_weth; - - address[] internal s_sourceFeeTokens; - uint224[] internal s_sourceTokenPrices; - address[] internal s_destFeeTokens; - uint224[] internal s_destTokenPrices; - - PriceRegistry.PremiumMultiplierWeiPerEthArgs[] internal s_priceRegistryPremiumMultiplierWeiPerEthArgs; - PriceRegistry.TokenTransferFeeConfigArgs[] internal s_priceRegistryTokenTransferFeeConfigArgs; - - mapping(address token => address dataFeedAddress) internal s_dataFeedByToken; - - function setUp() public virtual override { - TokenSetup.setUp(); - - _deployTokenPriceDataFeed(s_sourceFeeToken, 8, 1e8); - - s_weth = s_sourceRouter.getWrappedNative(); - _deployTokenPriceDataFeed(s_weth, 8, 1e11); - - address[] memory sourceFeeTokens = new address[](3); - sourceFeeTokens[0] = s_sourceTokens[0]; - sourceFeeTokens[1] = s_sourceTokens[1]; - sourceFeeTokens[2] = s_sourceRouter.getWrappedNative(); - s_sourceFeeTokens = sourceFeeTokens; - - uint224[] memory sourceTokenPrices = new uint224[](3); - sourceTokenPrices[0] = 5e18; - sourceTokenPrices[1] = 2000e18; - sourceTokenPrices[2] = 2000e18; - s_sourceTokenPrices = sourceTokenPrices; - - address[] memory destFeeTokens = new address[](3); - destFeeTokens[0] = s_destTokens[0]; - destFeeTokens[1] = s_destTokens[1]; - destFeeTokens[2] = s_destRouter.getWrappedNative(); - s_destFeeTokens = destFeeTokens; - - uint224[] memory destTokenPrices = new uint224[](3); - destTokenPrices[0] = 5e18; - destTokenPrices[1] = 2000e18; - destTokenPrices[2] = 2000e18; - s_destTokenPrices = destTokenPrices; - - uint256 sourceTokenCount = sourceFeeTokens.length; - uint256 destTokenCount = destFeeTokens.length; - address[] memory pricedTokens = new address[](sourceTokenCount + destTokenCount); - uint224[] memory tokenPrices = new uint224[](sourceTokenCount + destTokenCount); - for (uint256 i = 0; i < sourceTokenCount; ++i) { - pricedTokens[i] = sourceFeeTokens[i]; - tokenPrices[i] = sourceTokenPrices[i]; - } - for (uint256 i = 0; i < destTokenCount; ++i) { - pricedTokens[i + sourceTokenCount] = destFeeTokens[i]; - tokenPrices[i + sourceTokenCount] = destTokenPrices[i]; - } - - Internal.PriceUpdates memory priceUpdates = getPriceUpdatesStruct(pricedTokens, tokenPrices); - priceUpdates.gasPriceUpdates = - getSingleGasPriceUpdateStruct(DEST_CHAIN_SELECTOR, PACKED_USD_PER_GAS).gasPriceUpdates; - - s_encodedInitialPriceUpdates = abi.encode(priceUpdates); - - address[] memory priceUpdaters = new address[](1); - priceUpdaters[0] = OWNER; - address[] memory feeTokens = new address[](2); - feeTokens[0] = s_sourceTokens[0]; - feeTokens[1] = s_weth; - PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](0); - - s_priceRegistryPremiumMultiplierWeiPerEthArgs.push( - PriceRegistry.PremiumMultiplierWeiPerEthArgs({ - token: s_sourceFeeToken, - premiumMultiplierWeiPerEth: 5e17 // 0.5x - }) - ); - s_priceRegistryPremiumMultiplierWeiPerEthArgs.push( - PriceRegistry.PremiumMultiplierWeiPerEthArgs({ - token: s_sourceRouter.getWrappedNative(), - premiumMultiplierWeiPerEth: 2e18 // 2x - }) - ); - - s_priceRegistryTokenTransferFeeConfigArgs.push(); - s_priceRegistryTokenTransferFeeConfigArgs[0].destChainSelector = DEST_CHAIN_SELECTOR; - s_priceRegistryTokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs.push( - PriceRegistry.TokenTransferFeeConfigSingleTokenArgs({ - token: s_sourceFeeToken, - tokenTransferFeeConfig: PriceRegistry.TokenTransferFeeConfig({ - minFeeUSDCents: 1_00, // 1 USD - maxFeeUSDCents: 1000_00, // 1,000 USD - deciBps: 2_5, // 2.5 bps, or 0.025% - destGasOverhead: 40_000, - destBytesOverhead: 32, - isEnabled: true - }) - }) - ); - s_priceRegistryTokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs.push( - PriceRegistry.TokenTransferFeeConfigSingleTokenArgs({ - token: CUSTOM_TOKEN, - tokenTransferFeeConfig: PriceRegistry.TokenTransferFeeConfig({ - minFeeUSDCents: 2_00, // 1 USD - maxFeeUSDCents: 2000_00, // 1,000 USD - deciBps: 10_0, // 10 bps, or 0.1% - destGasOverhead: 1, - destBytesOverhead: 200, - isEnabled: true - }) - }) - ); - - s_priceRegistry = new PriceRegistryHelper( - PriceRegistry.StaticConfig({ - linkToken: s_sourceTokens[0], - maxFeeJuelsPerMsg: MAX_MSG_FEES_JUELS, - stalenessThreshold: uint32(TWELVE_HOURS) - }), - priceUpdaters, - feeTokens, - tokenPriceFeedUpdates, - s_priceRegistryTokenTransferFeeConfigArgs, - s_priceRegistryPremiumMultiplierWeiPerEthArgs, - _generatePriceRegistryDestChainConfigArgs() - ); - s_priceRegistry.updatePrices(priceUpdates); - } - - function _deployTokenPriceDataFeed(address token, uint8 decimals, int256 initialAnswer) internal returns (address) { - MockV3Aggregator dataFeed = new MockV3Aggregator(decimals, initialAnswer); - s_dataFeedByToken[token] = address(dataFeed); - return address(dataFeed); - } - - function getPriceUpdatesStruct( - address[] memory tokens, - uint224[] memory prices - ) internal pure returns (Internal.PriceUpdates memory) { - uint256 length = tokens.length; - - Internal.TokenPriceUpdate[] memory tokenPriceUpdates = new Internal.TokenPriceUpdate[](length); - for (uint256 i = 0; i < length; ++i) { - tokenPriceUpdates[i] = Internal.TokenPriceUpdate({sourceToken: tokens[i], usdPerToken: prices[i]}); - } - Internal.PriceUpdates memory priceUpdates = - Internal.PriceUpdates({tokenPriceUpdates: tokenPriceUpdates, gasPriceUpdates: new Internal.GasPriceUpdate[](0)}); - - return priceUpdates; - } - - function getEmptyPriceUpdates() internal pure returns (Internal.PriceUpdates memory priceUpdates) { - return Internal.PriceUpdates({ - tokenPriceUpdates: new Internal.TokenPriceUpdate[](0), - gasPriceUpdates: new Internal.GasPriceUpdate[](0) - }); - } - - function getSingleTokenPriceFeedUpdateStruct( - address sourceToken, - address dataFeedAddress, - uint8 tokenDecimals - ) internal pure returns (PriceRegistry.TokenPriceFeedUpdate memory) { - return PriceRegistry.TokenPriceFeedUpdate({ - sourceToken: sourceToken, - feedConfig: IPriceRegistry.TokenPriceFeedConfig({dataFeedAddress: dataFeedAddress, tokenDecimals: tokenDecimals}) - }); - } - - function _initialiseSingleTokenPriceFeed() internal returns (address) { - PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); - s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); - return s_sourceTokens[0]; - } - - function _generateTokenTransferFeeConfigArgs( - uint256 destChainSelectorLength, - uint256 tokenLength - ) internal pure returns (PriceRegistry.TokenTransferFeeConfigArgs[] memory) { - PriceRegistry.TokenTransferFeeConfigArgs[] memory tokenTransferFeeConfigArgs = - new PriceRegistry.TokenTransferFeeConfigArgs[](destChainSelectorLength); - for (uint256 i = 0; i < destChainSelectorLength; ++i) { - tokenTransferFeeConfigArgs[i].tokenTransferFeeConfigs = - new PriceRegistry.TokenTransferFeeConfigSingleTokenArgs[](tokenLength); - } - return tokenTransferFeeConfigArgs; - } - - function _generatePriceRegistryDestChainConfigArgs() - internal - pure - returns (PriceRegistry.DestChainConfigArgs[] memory) - { - PriceRegistry.DestChainConfigArgs[] memory destChainConfigs = new PriceRegistry.DestChainConfigArgs[](1); - destChainConfigs[0] = PriceRegistry.DestChainConfigArgs({ - destChainSelector: DEST_CHAIN_SELECTOR, - destChainConfig: PriceRegistry.DestChainConfig({ - isEnabled: true, - maxNumberOfTokensPerMsg: MAX_TOKENS_LENGTH, - destGasOverhead: DEST_GAS_OVERHEAD, - destGasPerPayloadByte: DEST_GAS_PER_PAYLOAD_BYTE, - destDataAvailabilityOverheadGas: DEST_DATA_AVAILABILITY_OVERHEAD_GAS, - destGasPerDataAvailabilityByte: DEST_GAS_PER_DATA_AVAILABILITY_BYTE, - destDataAvailabilityMultiplierBps: DEST_GAS_DATA_AVAILABILITY_MULTIPLIER_BPS, - maxDataBytes: MAX_DATA_SIZE, - maxPerMsgGasLimit: MAX_GAS_LIMIT, - defaultTokenFeeUSDCents: DEFAULT_TOKEN_FEE_USD_CENTS, - defaultTokenDestGasOverhead: DEFAULT_TOKEN_DEST_GAS_OVERHEAD, - defaultTokenDestBytesOverhead: DEFAULT_TOKEN_BYTES_OVERHEAD, - defaultTxGasLimit: GAS_LIMIT, - gasMultiplierWeiPerEth: 5e17, - networkFeeUSDCents: 1_00, - enforceOutOfOrder: false, - chainFamilySelector: Internal.CHAIN_FAMILY_SELECTOR_EVM - }) - }); - return destChainConfigs; - } - - function _assertTokenPriceFeedConfigEquality( - IPriceRegistry.TokenPriceFeedConfig memory config1, - IPriceRegistry.TokenPriceFeedConfig memory config2 - ) internal pure virtual { - assertEq(config1.dataFeedAddress, config2.dataFeedAddress); - assertEq(config1.tokenDecimals, config2.tokenDecimals); - } - - function _assertTokenPriceFeedConfigUnconfigured(IPriceRegistry.TokenPriceFeedConfig memory config) - internal - pure - virtual - { - _assertTokenPriceFeedConfigEquality( - config, IPriceRegistry.TokenPriceFeedConfig({dataFeedAddress: address(0), tokenDecimals: 0}) - ); - } - - function _assertTokenTransferFeeConfigEqual( - PriceRegistry.TokenTransferFeeConfig memory a, - PriceRegistry.TokenTransferFeeConfig memory b - ) internal pure { - assertEq(a.minFeeUSDCents, b.minFeeUSDCents); - assertEq(a.maxFeeUSDCents, b.maxFeeUSDCents); - assertEq(a.deciBps, b.deciBps); - assertEq(a.destGasOverhead, b.destGasOverhead); - assertEq(a.destBytesOverhead, b.destBytesOverhead); - assertEq(a.isEnabled, b.isEnabled); - } - - function _assertPriceRegistryStaticConfigsEqual( - PriceRegistry.StaticConfig memory a, - PriceRegistry.StaticConfig memory b - ) internal pure { - assertEq(a.linkToken, b.linkToken); - assertEq(a.maxFeeJuelsPerMsg, b.maxFeeJuelsPerMsg); - } - - function _assertPriceRegistryDestChainConfigsEqual( - PriceRegistry.DestChainConfig memory a, - PriceRegistry.DestChainConfig memory b - ) internal pure { - assertEq(a.isEnabled, b.isEnabled); - assertEq(a.maxNumberOfTokensPerMsg, b.maxNumberOfTokensPerMsg); - assertEq(a.maxDataBytes, b.maxDataBytes); - assertEq(a.maxPerMsgGasLimit, b.maxPerMsgGasLimit); - assertEq(a.destGasOverhead, b.destGasOverhead); - assertEq(a.destGasPerPayloadByte, b.destGasPerPayloadByte); - assertEq(a.destDataAvailabilityOverheadGas, b.destDataAvailabilityOverheadGas); - assertEq(a.destGasPerDataAvailabilityByte, b.destGasPerDataAvailabilityByte); - assertEq(a.destDataAvailabilityMultiplierBps, b.destDataAvailabilityMultiplierBps); - assertEq(a.defaultTokenFeeUSDCents, b.defaultTokenFeeUSDCents); - assertEq(a.defaultTokenDestGasOverhead, b.defaultTokenDestGasOverhead); - assertEq(a.defaultTokenDestBytesOverhead, b.defaultTokenDestBytesOverhead); - assertEq(a.defaultTxGasLimit, b.defaultTxGasLimit); - } -} - -contract PriceRegistryFeeSetup is PriceRegistrySetup { - uint224 internal s_feeTokenPrice; - uint224 internal s_wrappedTokenPrice; - uint224 internal s_customTokenPrice; - - address internal s_selfServeTokenDefaultPricing = makeAddr("self-serve-token-default-pricing"); - - address internal s_destTokenPool = makeAddr("destTokenPool"); - address internal s_destToken = makeAddr("destToken"); - - function setUp() public virtual override { - super.setUp(); - - s_feeTokenPrice = s_sourceTokenPrices[0]; - s_wrappedTokenPrice = s_sourceTokenPrices[2]; - s_customTokenPrice = CUSTOM_TOKEN_PRICE; - - s_priceRegistry.updatePrices(getSingleTokenPriceUpdateStruct(CUSTOM_TOKEN, CUSTOM_TOKEN_PRICE)); - } - - function _generateEmptyMessage() public view returns (Client.EVM2AnyMessage memory) { - return Client.EVM2AnyMessage({ - receiver: abi.encode(OWNER), - data: "", - tokenAmounts: new Client.EVMTokenAmount[](0), - feeToken: s_sourceFeeToken, - extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT})) - }); - } - - function _generateSingleTokenMessage( - address token, - uint256 amount - ) public view returns (Client.EVM2AnyMessage memory) { - Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1); - tokenAmounts[0] = Client.EVMTokenAmount({token: token, amount: amount}); - - return Client.EVM2AnyMessage({ - receiver: abi.encode(OWNER), - data: "", - tokenAmounts: tokenAmounts, - feeToken: s_sourceFeeToken, - extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT})) - }); - } - - function _messageToEvent( - Client.EVM2AnyMessage memory message, - uint64 sourceChainSelector, - uint64 destChainSelector, - uint64 seqNum, - uint64 nonce, - uint256 feeTokenAmount, - address originalSender, - bytes32 metadataHash, - TokenAdminRegistry tokenAdminRegistry - ) internal view returns (Internal.EVM2AnyRampMessage memory) { - Client.EVMExtraArgsV2 memory extraArgs = - s_priceRegistry.parseEVMExtraArgsFromBytes(message.extraArgs, destChainSelector); - - Internal.EVM2AnyRampMessage memory messageEvent = Internal.EVM2AnyRampMessage({ - header: Internal.RampMessageHeader({ - messageId: "", - sourceChainSelector: sourceChainSelector, - destChainSelector: destChainSelector, - sequenceNumber: seqNum, - nonce: extraArgs.allowOutOfOrderExecution ? 0 : nonce - }), - sender: originalSender, - data: message.data, - receiver: message.receiver, - extraArgs: Client._argsToBytes(extraArgs), - feeToken: message.feeToken, - feeTokenAmount: feeTokenAmount, - tokenAmounts: new Internal.RampTokenAmount[](message.tokenAmounts.length) - }); - - for (uint256 i = 0; i < message.tokenAmounts.length; ++i) { - messageEvent.tokenAmounts[i] = _getSourceTokenData(message.tokenAmounts[i], tokenAdminRegistry); - } - - messageEvent.header.messageId = Internal._hash(messageEvent, metadataHash); - return messageEvent; - } - - function _getSourceTokenData( - Client.EVMTokenAmount memory tokenAmount, - TokenAdminRegistry tokenAdminRegistry - ) internal view returns (Internal.RampTokenAmount memory) { - address destToken = s_destTokenBySourceToken[tokenAmount.token]; - - return Internal.RampTokenAmount({ - sourcePoolAddress: abi.encode(tokenAdminRegistry.getTokenConfig(tokenAmount.token).tokenPool), - destTokenAddress: abi.encode(destToken), - extraData: "", - amount: tokenAmount.amount - }); - } - - function calcUSDValueFromTokenAmount(uint224 tokenPrice, uint256 tokenAmount) internal pure returns (uint256) { - return (tokenPrice * tokenAmount) / 1e18; - } - - function applyBpsRatio(uint256 tokenAmount, uint16 ratio) internal pure returns (uint256) { - return (tokenAmount * ratio) / 1e5; - } - - function configUSDCentToWei(uint256 usdCent) internal pure returns (uint256) { - return usdCent * 1e16; - } -} contract PriceRegistry_constructor is PriceRegistrySetup { function test_Setup_Success() public virtual { @@ -441,9 +23,9 @@ contract PriceRegistry_constructor is PriceRegistrySetup { feeTokens[1] = s_sourceTokens[1]; PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](2); tokenPriceFeedUpdates[0] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); tokenPriceFeedUpdates[1] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[1], s_dataFeedByToken[s_sourceTokens[1]], 6); + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[1], s_dataFeedByToken[s_sourceTokens[1]], 6); PriceRegistry.DestChainConfigArgs[] memory destChainConfigArgs = _generatePriceRegistryDestChainConfigArgs(); @@ -641,7 +223,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 18, int256(uint256(type(uint224).max))); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); uint224 tokenPriceAnswer = s_priceRegistry.getValidatedTokenPrice(tokenAddress); @@ -655,7 +237,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 8, 1e8); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 6); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 6); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); uint224 tokenPriceAnswer = s_priceRegistry.getValidatedTokenPrice(tokenAddress); @@ -669,7 +251,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 8, 1e8); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 24); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 24); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); uint224 tokenPriceAnswer = s_priceRegistry.getValidatedTokenPrice(tokenAddress); @@ -683,7 +265,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 18, 1e18); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); uint224 tokenPriceAnswer = s_priceRegistry.getValidatedTokenPrice(tokenAddress); @@ -697,7 +279,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 0, 1e31); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 0); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 0); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); uint224 tokenPriceAnswer = s_priceRegistry.getValidatedTokenPrice(tokenAddress); @@ -711,7 +293,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 20, 1e18); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 20); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 20); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); uint224 tokenPriceAnswer = s_priceRegistry.getValidatedTokenPrice(tokenAddress); @@ -738,7 +320,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 18, int256(uint256(type(uint224).max) + 1)); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); vm.expectRevert(PriceRegistry.DataFeedValueOutOfUint224Range.selector); @@ -750,7 +332,7 @@ contract PriceRegistry_getValidatedTokenPrice is PriceRegistrySetup { address feedAddress = _deployTokenPriceDataFeed(tokenAddress, 18, -1); PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); - tokenPriceFeedUpdates[0] = getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); + tokenPriceFeedUpdates[0] = _getSingleTokenPriceFeedUpdateStruct(tokenAddress, feedAddress, 18); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); vm.expectRevert(PriceRegistry.DataFeedValueOutOfUint224Range.selector); @@ -1050,7 +632,7 @@ contract PriceRegistry_updateTokenPriceFeeds is PriceRegistrySetup { function test_SingleFeedUpdate_Success() public { PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); tokenPriceFeedUpdates[0] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); _assertTokenPriceFeedConfigUnconfigured( s_priceRegistry.getTokenPriceFeedConfig(tokenPriceFeedUpdates[0].sourceToken) @@ -1073,7 +655,7 @@ contract PriceRegistry_updateTokenPriceFeeds is PriceRegistrySetup { for (uint256 i = 0; i < 2; ++i) { tokenPriceFeedUpdates[i] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[i], s_dataFeedByToken[s_sourceTokens[i]], 18); + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[i], s_dataFeedByToken[s_sourceTokens[i]], 18); _assertTokenPriceFeedConfigUnconfigured( s_priceRegistry.getTokenPriceFeedConfig(tokenPriceFeedUpdates[i].sourceToken) @@ -1102,7 +684,7 @@ contract PriceRegistry_updateTokenPriceFeeds is PriceRegistrySetup { PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); tokenPriceFeedUpdates[0] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); _assertTokenPriceFeedConfigEquality( @@ -1129,7 +711,7 @@ contract PriceRegistry_updateTokenPriceFeeds is PriceRegistrySetup { function test_FeedNotUpdated() public { PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); tokenPriceFeedUpdates[0] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); @@ -1144,7 +726,7 @@ contract PriceRegistry_updateTokenPriceFeeds is PriceRegistrySetup { function test_FeedUpdatedByNonOwner_Revert() public { PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); tokenPriceFeedUpdates[0] = - getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); vm.startPrank(STRANGER); vm.expectRevert("Only callable by owner"); @@ -1713,7 +1295,7 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { (uint256 feeUSDWei, uint32 destGasOverhead, uint32 destBytesOverhead) = s_priceRegistry.getTokenTransferCost(DEST_CHAIN_SELECTOR, message.feeToken, s_feeTokenPrice, message.tokenAmounts); - assertEq(configUSDCentToWei(transferFeeConfig.minFeeUSDCents), feeUSDWei); + assertEq(_configUSDCentToWei(transferFeeConfig.minFeeUSDCents), feeUSDWei); assertEq(transferFeeConfig.destGasOverhead, destGasOverhead); assertEq(transferFeeConfig.destBytesOverhead, destBytesOverhead); } @@ -1726,7 +1308,7 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { (uint256 feeUSDWei, uint32 destGasOverhead, uint32 destBytesOverhead) = s_priceRegistry.getTokenTransferCost(DEST_CHAIN_SELECTOR, message.feeToken, s_feeTokenPrice, message.tokenAmounts); - assertEq(configUSDCentToWei(transferFeeConfig.minFeeUSDCents), feeUSDWei); + assertEq(_configUSDCentToWei(transferFeeConfig.minFeeUSDCents), feeUSDWei); assertEq(transferFeeConfig.destGasOverhead, destGasOverhead); assertEq(transferFeeConfig.destBytesOverhead, destBytesOverhead); } @@ -1739,7 +1321,7 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { (uint256 feeUSDWei, uint32 destGasOverhead, uint32 destBytesOverhead) = s_priceRegistry.getTokenTransferCost(DEST_CHAIN_SELECTOR, message.feeToken, s_feeTokenPrice, message.tokenAmounts); - assertEq(configUSDCentToWei(transferFeeConfig.maxFeeUSDCents), feeUSDWei); + assertEq(_configUSDCentToWei(transferFeeConfig.maxFeeUSDCents), feeUSDWei); assertEq(transferFeeConfig.destGasOverhead, destGasOverhead); assertEq(transferFeeConfig.destBytesOverhead, destBytesOverhead); } @@ -1754,8 +1336,8 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { (uint256 feeUSDWei, uint32 destGasOverhead, uint32 destBytesOverhead) = s_priceRegistry.getTokenTransferCost(DEST_CHAIN_SELECTOR, message.feeToken, s_feeTokenPrice, message.tokenAmounts); - uint256 usdWei = calcUSDValueFromTokenAmount(s_feeTokenPrice, tokenAmount); - uint256 bpsUSDWei = applyBpsRatio( + uint256 usdWei = _calcUSDValueFromTokenAmount(s_feeTokenPrice, tokenAmount); + uint256 bpsUSDWei = _applyBpsRatio( usdWei, s_priceRegistryTokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs[0].tokenTransferFeeConfig.deciBps ); @@ -1782,8 +1364,8 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { (uint256 feeUSDWei, uint32 destGasOverhead, uint32 destBytesOverhead) = s_priceRegistry.getTokenTransferCost(DEST_CHAIN_SELECTOR, message.feeToken, s_feeTokenPrice, message.tokenAmounts); - uint256 usdWei = calcUSDValueFromTokenAmount(s_customTokenPrice, tokenAmount); - uint256 bpsUSDWei = applyBpsRatio( + uint256 usdWei = _calcUSDValueFromTokenAmount(s_customTokenPrice, tokenAmount); + uint256 bpsUSDWei = _applyBpsRatio( usdWei, s_priceRegistryTokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs[1].tokenTransferFeeConfig.deciBps ); @@ -1816,7 +1398,9 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { // if token charges 0 bps, it should cost minFee to transfer assertEq( - configUSDCentToWei(tokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs[0].tokenTransferFeeConfig.minFeeUSDCents), + _configUSDCentToWei( + tokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs[0].tokenTransferFeeConfig.minFeeUSDCents + ), feeUSDWei ); assertEq(0, destGasOverhead); @@ -1888,7 +1472,7 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { uint256 expectedFeeUSDWei = 0; for (uint256 i = 0; i < testTokens.length; ++i) { - expectedFeeUSDWei += configUSDCentToWei( + expectedFeeUSDWei += _configUSDCentToWei( tokenTransferFeeConfigs[i].minFeeUSDCents == 0 ? DEFAULT_TOKEN_FEE_USD_CENTS : tokenTransferFeeConfigs[i].minFeeUSDCents @@ -1902,15 +1486,15 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { // Set 1st token transfer to a meaningful amount so its bps fee is now between min and max fee message.tokenAmounts[0] = Client.EVMTokenAmount({token: testTokens[0], amount: 10000e18}); - uint256 token0USDWei = applyBpsRatio( - calcUSDValueFromTokenAmount(tokenPrices[0], message.tokenAmounts[0].amount), tokenTransferFeeConfigs[0].deciBps + uint256 token0USDWei = _applyBpsRatio( + _calcUSDValueFromTokenAmount(tokenPrices[0], message.tokenAmounts[0].amount), tokenTransferFeeConfigs[0].deciBps ); - uint256 token1USDWei = configUSDCentToWei(DEFAULT_TOKEN_FEE_USD_CENTS); + uint256 token1USDWei = _configUSDCentToWei(DEFAULT_TOKEN_FEE_USD_CENTS); (feeUSDWei, destGasOverhead, destBytesOverhead) = s_priceRegistry.getTokenTransferCost( DEST_CHAIN_SELECTOR, message.feeToken, s_wrappedTokenPrice, message.tokenAmounts ); - expectedFeeUSDWei = token0USDWei + token1USDWei + configUSDCentToWei(tokenTransferFeeConfigs[2].minFeeUSDCents); + expectedFeeUSDWei = token0USDWei + token1USDWei + _configUSDCentToWei(tokenTransferFeeConfigs[2].minFeeUSDCents); assertEq(expectedFeeUSDWei, feeUSDWei, "wrong feeUSDWei 2"); assertEq(expectedTotalGas, destGasOverhead, "wrong destGasOverhead 2"); @@ -1922,7 +1506,7 @@ contract PriceRegistry_getTokenTransferCost is PriceRegistryFeeSetup { (feeUSDWei, destGasOverhead, destBytesOverhead) = s_priceRegistry.getTokenTransferCost( DEST_CHAIN_SELECTOR, message.feeToken, s_wrappedTokenPrice, message.tokenAmounts ); - expectedFeeUSDWei = token0USDWei + token1USDWei + configUSDCentToWei(tokenTransferFeeConfigs[2].maxFeeUSDCents); + expectedFeeUSDWei = token0USDWei + token1USDWei + _configUSDCentToWei(tokenTransferFeeConfigs[2].maxFeeUSDCents); assertEq(expectedFeeUSDWei, feeUSDWei, "wrong feeUSDWei 3"); assertEq(expectedTotalGas, destGasOverhead, "wrong destGasOverhead 3"); @@ -1947,7 +1531,7 @@ contract PriceRegistry_getValidatedFee is PriceRegistryFeeSetup { uint256 gasUsed = GAS_LIMIT + DEST_GAS_OVERHEAD; uint256 gasFeeUSD = (gasUsed * destChainConfig.gasMultiplierWeiPerEth * USD_PER_GAS); - uint256 messageFeeUSD = (configUSDCentToWei(destChainConfig.networkFeeUSDCents) * premiumMultiplierWeiPerEth); + uint256 messageFeeUSD = (_configUSDCentToWei(destChainConfig.networkFeeUSDCents) * premiumMultiplierWeiPerEth); uint256 dataAvailabilityFeeUSD = s_priceRegistry.getDataAvailabilityCost( DEST_CHAIN_SELECTOR, USD_PER_DATA_AVAILABILITY_GAS, message.data.length, message.tokenAmounts.length, 0 ); @@ -1972,7 +1556,7 @@ contract PriceRegistry_getValidatedFee is PriceRegistryFeeSetup { uint256 gasUsed = GAS_LIMIT + DEST_GAS_OVERHEAD; uint256 gasFeeUSD = (gasUsed * destChainConfig.gasMultiplierWeiPerEth * USD_PER_GAS); - uint256 messageFeeUSD = (configUSDCentToWei(destChainConfig.networkFeeUSDCents) * premiumMultiplierWeiPerEth); + uint256 messageFeeUSD = (_configUSDCentToWei(destChainConfig.networkFeeUSDCents) * premiumMultiplierWeiPerEth); uint256 totalPriceInFeeToken = (gasFeeUSD + messageFeeUSD) / s_feeTokenPrice; assertEq(totalPriceInFeeToken, feeAmount); @@ -1999,7 +1583,7 @@ contract PriceRegistry_getValidatedFee is PriceRegistryFeeSetup { uint256 feeAmount = s_priceRegistry.getValidatedFee(DEST_CHAIN_SELECTOR, message); uint256 gasUsed = customGasLimit + DEST_GAS_OVERHEAD + customDataSize * DEST_GAS_PER_PAYLOAD_BYTE; uint256 gasFeeUSD = (gasUsed * destChainConfig.gasMultiplierWeiPerEth * USD_PER_GAS); - uint256 messageFeeUSD = (configUSDCentToWei(destChainConfig.networkFeeUSDCents) * premiumMultiplierWeiPerEth); + uint256 messageFeeUSD = (_configUSDCentToWei(destChainConfig.networkFeeUSDCents) * premiumMultiplierWeiPerEth); uint256 dataAvailabilityFeeUSD = s_priceRegistry.getDataAvailabilityCost( DEST_CHAIN_SELECTOR, USD_PER_DATA_AVAILABILITY_GAS, message.data.length, message.tokenAmounts.length, 0 ); diff --git a/contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistrySetup.t.sol b/contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistrySetup.t.sol new file mode 100644 index 0000000000..6a4a1e3205 --- /dev/null +++ b/contracts/src/v0.8/ccip/test/priceRegistry/PriceRegistrySetup.t.sol @@ -0,0 +1,418 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.24; + +import {IPriceRegistry} from "../../interfaces/IPriceRegistry.sol"; + +import {MockV3Aggregator} from "../../../tests/MockV3Aggregator.sol"; +import {PriceRegistry} from "../../PriceRegistry.sol"; +import {Client} from "../../libraries/Client.sol"; +import {Internal} from "../../libraries/Internal.sol"; +import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol"; +import {TokenSetup} from "../TokenSetup.t.sol"; +import {PriceRegistryHelper} from "../helpers/PriceRegistryHelper.sol"; + +contract PriceRegistrySetup is TokenSetup { + uint112 internal constant USD_PER_GAS = 1e6; // 0.001 gwei + uint112 internal constant USD_PER_DATA_AVAILABILITY_GAS = 1e9; // 1 gwei + + address internal constant CUSTOM_TOKEN = address(12345); + uint224 internal constant CUSTOM_TOKEN_PRICE = 1e17; // $0.1 CUSTOM + + // Encode L1 gas price and L2 gas price into a packed price. + // L1 gas price is left-shifted to the higher-order bits. + uint224 internal constant PACKED_USD_PER_GAS = + (uint224(USD_PER_DATA_AVAILABILITY_GAS) << Internal.GAS_PRICE_BITS) + USD_PER_GAS; + + PriceRegistryHelper internal s_priceRegistry; + // Cheat to store the price updates in storage since struct arrays aren't supported. + bytes internal s_encodedInitialPriceUpdates; + address internal s_weth; + + address[] internal s_sourceFeeTokens; + uint224[] internal s_sourceTokenPrices; + address[] internal s_destFeeTokens; + uint224[] internal s_destTokenPrices; + + PriceRegistry.PremiumMultiplierWeiPerEthArgs[] internal s_priceRegistryPremiumMultiplierWeiPerEthArgs; + PriceRegistry.TokenTransferFeeConfigArgs[] internal s_priceRegistryTokenTransferFeeConfigArgs; + + mapping(address token => address dataFeedAddress) internal s_dataFeedByToken; + + function setUp() public virtual override { + TokenSetup.setUp(); + + _deployTokenPriceDataFeed(s_sourceFeeToken, 8, 1e8); + + s_weth = s_sourceRouter.getWrappedNative(); + _deployTokenPriceDataFeed(s_weth, 8, 1e11); + + address[] memory sourceFeeTokens = new address[](3); + sourceFeeTokens[0] = s_sourceTokens[0]; + sourceFeeTokens[1] = s_sourceTokens[1]; + sourceFeeTokens[2] = s_sourceRouter.getWrappedNative(); + s_sourceFeeTokens = sourceFeeTokens; + + uint224[] memory sourceTokenPrices = new uint224[](3); + sourceTokenPrices[0] = 5e18; + sourceTokenPrices[1] = 2000e18; + sourceTokenPrices[2] = 2000e18; + s_sourceTokenPrices = sourceTokenPrices; + + address[] memory destFeeTokens = new address[](3); + destFeeTokens[0] = s_destTokens[0]; + destFeeTokens[1] = s_destTokens[1]; + destFeeTokens[2] = s_destRouter.getWrappedNative(); + s_destFeeTokens = destFeeTokens; + + uint224[] memory destTokenPrices = new uint224[](3); + destTokenPrices[0] = 5e18; + destTokenPrices[1] = 2000e18; + destTokenPrices[2] = 2000e18; + s_destTokenPrices = destTokenPrices; + + uint256 sourceTokenCount = sourceFeeTokens.length; + uint256 destTokenCount = destFeeTokens.length; + address[] memory pricedTokens = new address[](sourceTokenCount + destTokenCount); + uint224[] memory tokenPrices = new uint224[](sourceTokenCount + destTokenCount); + for (uint256 i = 0; i < sourceTokenCount; ++i) { + pricedTokens[i] = sourceFeeTokens[i]; + tokenPrices[i] = sourceTokenPrices[i]; + } + for (uint256 i = 0; i < destTokenCount; ++i) { + pricedTokens[i + sourceTokenCount] = destFeeTokens[i]; + tokenPrices[i + sourceTokenCount] = destTokenPrices[i]; + } + + Internal.PriceUpdates memory priceUpdates = _getPriceUpdatesStruct(pricedTokens, tokenPrices); + priceUpdates.gasPriceUpdates = new Internal.GasPriceUpdate[](1); + priceUpdates.gasPriceUpdates[0] = + Internal.GasPriceUpdate({destChainSelector: DEST_CHAIN_SELECTOR, usdPerUnitGas: PACKED_USD_PER_GAS}); + + s_encodedInitialPriceUpdates = abi.encode(priceUpdates); + + address[] memory priceUpdaters = new address[](1); + priceUpdaters[0] = OWNER; + address[] memory feeTokens = new address[](2); + feeTokens[0] = s_sourceTokens[0]; + feeTokens[1] = s_weth; + PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](0); + + s_priceRegistryPremiumMultiplierWeiPerEthArgs.push( + PriceRegistry.PremiumMultiplierWeiPerEthArgs({ + token: s_sourceFeeToken, + premiumMultiplierWeiPerEth: 5e17 // 0.5x + }) + ); + s_priceRegistryPremiumMultiplierWeiPerEthArgs.push( + PriceRegistry.PremiumMultiplierWeiPerEthArgs({ + token: s_sourceRouter.getWrappedNative(), + premiumMultiplierWeiPerEth: 2e18 // 2x + }) + ); + + s_priceRegistryTokenTransferFeeConfigArgs.push(); + s_priceRegistryTokenTransferFeeConfigArgs[0].destChainSelector = DEST_CHAIN_SELECTOR; + s_priceRegistryTokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs.push( + PriceRegistry.TokenTransferFeeConfigSingleTokenArgs({ + token: s_sourceFeeToken, + tokenTransferFeeConfig: PriceRegistry.TokenTransferFeeConfig({ + minFeeUSDCents: 1_00, // 1 USD + maxFeeUSDCents: 1000_00, // 1,000 USD + deciBps: 2_5, // 2.5 bps, or 0.025% + destGasOverhead: 40_000, + destBytesOverhead: 32, + isEnabled: true + }) + }) + ); + s_priceRegistryTokenTransferFeeConfigArgs[0].tokenTransferFeeConfigs.push( + PriceRegistry.TokenTransferFeeConfigSingleTokenArgs({ + token: CUSTOM_TOKEN, + tokenTransferFeeConfig: PriceRegistry.TokenTransferFeeConfig({ + minFeeUSDCents: 2_00, // 1 USD + maxFeeUSDCents: 2000_00, // 1,000 USD + deciBps: 10_0, // 10 bps, or 0.1% + destGasOverhead: 1, + destBytesOverhead: 200, + isEnabled: true + }) + }) + ); + + s_priceRegistry = new PriceRegistryHelper( + PriceRegistry.StaticConfig({ + linkToken: s_sourceTokens[0], + maxFeeJuelsPerMsg: MAX_MSG_FEES_JUELS, + stalenessThreshold: uint32(TWELVE_HOURS) + }), + priceUpdaters, + feeTokens, + tokenPriceFeedUpdates, + s_priceRegistryTokenTransferFeeConfigArgs, + s_priceRegistryPremiumMultiplierWeiPerEthArgs, + _generatePriceRegistryDestChainConfigArgs() + ); + s_priceRegistry.updatePrices(priceUpdates); + } + + function _deployTokenPriceDataFeed(address token, uint8 decimals, int256 initialAnswer) internal returns (address) { + MockV3Aggregator dataFeed = new MockV3Aggregator(decimals, initialAnswer); + s_dataFeedByToken[token] = address(dataFeed); + return address(dataFeed); + } + + function _getPriceUpdatesStruct( + address[] memory tokens, + uint224[] memory prices + ) internal pure returns (Internal.PriceUpdates memory) { + uint256 length = tokens.length; + + Internal.TokenPriceUpdate[] memory tokenPriceUpdates = new Internal.TokenPriceUpdate[](length); + for (uint256 i = 0; i < length; ++i) { + tokenPriceUpdates[i] = Internal.TokenPriceUpdate({sourceToken: tokens[i], usdPerToken: prices[i]}); + } + Internal.PriceUpdates memory priceUpdates = + Internal.PriceUpdates({tokenPriceUpdates: tokenPriceUpdates, gasPriceUpdates: new Internal.GasPriceUpdate[](0)}); + + return priceUpdates; + } + + function _getEmptyPriceUpdates() internal pure returns (Internal.PriceUpdates memory priceUpdates) { + return Internal.PriceUpdates({ + tokenPriceUpdates: new Internal.TokenPriceUpdate[](0), + gasPriceUpdates: new Internal.GasPriceUpdate[](0) + }); + } + + function _getSingleTokenPriceFeedUpdateStruct( + address sourceToken, + address dataFeedAddress, + uint8 tokenDecimals + ) internal pure returns (PriceRegistry.TokenPriceFeedUpdate memory) { + return PriceRegistry.TokenPriceFeedUpdate({ + sourceToken: sourceToken, + feedConfig: IPriceRegistry.TokenPriceFeedConfig({dataFeedAddress: dataFeedAddress, tokenDecimals: tokenDecimals}) + }); + } + + function _initialiseSingleTokenPriceFeed() internal returns (address) { + PriceRegistry.TokenPriceFeedUpdate[] memory tokenPriceFeedUpdates = new PriceRegistry.TokenPriceFeedUpdate[](1); + tokenPriceFeedUpdates[0] = + _getSingleTokenPriceFeedUpdateStruct(s_sourceTokens[0], s_dataFeedByToken[s_sourceTokens[0]], 18); + s_priceRegistry.updateTokenPriceFeeds(tokenPriceFeedUpdates); + return s_sourceTokens[0]; + } + + function _generateTokenTransferFeeConfigArgs( + uint256 destChainSelectorLength, + uint256 tokenLength + ) internal pure returns (PriceRegistry.TokenTransferFeeConfigArgs[] memory) { + PriceRegistry.TokenTransferFeeConfigArgs[] memory tokenTransferFeeConfigArgs = + new PriceRegistry.TokenTransferFeeConfigArgs[](destChainSelectorLength); + for (uint256 i = 0; i < destChainSelectorLength; ++i) { + tokenTransferFeeConfigArgs[i].tokenTransferFeeConfigs = + new PriceRegistry.TokenTransferFeeConfigSingleTokenArgs[](tokenLength); + } + return tokenTransferFeeConfigArgs; + } + + function _generatePriceRegistryDestChainConfigArgs() + internal + pure + returns (PriceRegistry.DestChainConfigArgs[] memory) + { + PriceRegistry.DestChainConfigArgs[] memory destChainConfigs = new PriceRegistry.DestChainConfigArgs[](1); + destChainConfigs[0] = PriceRegistry.DestChainConfigArgs({ + destChainSelector: DEST_CHAIN_SELECTOR, + destChainConfig: PriceRegistry.DestChainConfig({ + isEnabled: true, + maxNumberOfTokensPerMsg: MAX_TOKENS_LENGTH, + destGasOverhead: DEST_GAS_OVERHEAD, + destGasPerPayloadByte: DEST_GAS_PER_PAYLOAD_BYTE, + destDataAvailabilityOverheadGas: DEST_DATA_AVAILABILITY_OVERHEAD_GAS, + destGasPerDataAvailabilityByte: DEST_GAS_PER_DATA_AVAILABILITY_BYTE, + destDataAvailabilityMultiplierBps: DEST_GAS_DATA_AVAILABILITY_MULTIPLIER_BPS, + maxDataBytes: MAX_DATA_SIZE, + maxPerMsgGasLimit: MAX_GAS_LIMIT, + defaultTokenFeeUSDCents: DEFAULT_TOKEN_FEE_USD_CENTS, + defaultTokenDestGasOverhead: DEFAULT_TOKEN_DEST_GAS_OVERHEAD, + defaultTokenDestBytesOverhead: DEFAULT_TOKEN_BYTES_OVERHEAD, + defaultTxGasLimit: GAS_LIMIT, + gasMultiplierWeiPerEth: 5e17, + networkFeeUSDCents: 1_00, + enforceOutOfOrder: false, + chainFamilySelector: Internal.CHAIN_FAMILY_SELECTOR_EVM + }) + }); + return destChainConfigs; + } + + function _assertTokenPriceFeedConfigEquality( + IPriceRegistry.TokenPriceFeedConfig memory config1, + IPriceRegistry.TokenPriceFeedConfig memory config2 + ) internal pure virtual { + assertEq(config1.dataFeedAddress, config2.dataFeedAddress); + assertEq(config1.tokenDecimals, config2.tokenDecimals); + } + + function _assertTokenPriceFeedConfigUnconfigured(IPriceRegistry.TokenPriceFeedConfig memory config) + internal + pure + virtual + { + _assertTokenPriceFeedConfigEquality( + config, IPriceRegistry.TokenPriceFeedConfig({dataFeedAddress: address(0), tokenDecimals: 0}) + ); + } + + function _assertTokenTransferFeeConfigEqual( + PriceRegistry.TokenTransferFeeConfig memory a, + PriceRegistry.TokenTransferFeeConfig memory b + ) internal pure { + assertEq(a.minFeeUSDCents, b.minFeeUSDCents); + assertEq(a.maxFeeUSDCents, b.maxFeeUSDCents); + assertEq(a.deciBps, b.deciBps); + assertEq(a.destGasOverhead, b.destGasOverhead); + assertEq(a.destBytesOverhead, b.destBytesOverhead); + assertEq(a.isEnabled, b.isEnabled); + } + + function _assertPriceRegistryStaticConfigsEqual( + PriceRegistry.StaticConfig memory a, + PriceRegistry.StaticConfig memory b + ) internal pure { + assertEq(a.linkToken, b.linkToken); + assertEq(a.maxFeeJuelsPerMsg, b.maxFeeJuelsPerMsg); + } + + function _assertPriceRegistryDestChainConfigsEqual( + PriceRegistry.DestChainConfig memory a, + PriceRegistry.DestChainConfig memory b + ) internal pure { + assertEq(a.isEnabled, b.isEnabled); + assertEq(a.maxNumberOfTokensPerMsg, b.maxNumberOfTokensPerMsg); + assertEq(a.maxDataBytes, b.maxDataBytes); + assertEq(a.maxPerMsgGasLimit, b.maxPerMsgGasLimit); + assertEq(a.destGasOverhead, b.destGasOverhead); + assertEq(a.destGasPerPayloadByte, b.destGasPerPayloadByte); + assertEq(a.destDataAvailabilityOverheadGas, b.destDataAvailabilityOverheadGas); + assertEq(a.destGasPerDataAvailabilityByte, b.destGasPerDataAvailabilityByte); + assertEq(a.destDataAvailabilityMultiplierBps, b.destDataAvailabilityMultiplierBps); + assertEq(a.defaultTokenFeeUSDCents, b.defaultTokenFeeUSDCents); + assertEq(a.defaultTokenDestGasOverhead, b.defaultTokenDestGasOverhead); + assertEq(a.defaultTokenDestBytesOverhead, b.defaultTokenDestBytesOverhead); + assertEq(a.defaultTxGasLimit, b.defaultTxGasLimit); + } +} + +contract PriceRegistryFeeSetup is PriceRegistrySetup { + uint224 internal s_feeTokenPrice; + uint224 internal s_wrappedTokenPrice; + uint224 internal s_customTokenPrice; + + address internal s_selfServeTokenDefaultPricing = makeAddr("self-serve-token-default-pricing"); + + address internal s_destTokenPool = makeAddr("destTokenPool"); + address internal s_destToken = makeAddr("destToken"); + + function setUp() public virtual override { + super.setUp(); + + s_feeTokenPrice = s_sourceTokenPrices[0]; + s_wrappedTokenPrice = s_sourceTokenPrices[2]; + s_customTokenPrice = CUSTOM_TOKEN_PRICE; + + s_priceRegistry.updatePrices(_getSingleTokenPriceUpdateStruct(CUSTOM_TOKEN, CUSTOM_TOKEN_PRICE)); + } + + function _generateEmptyMessage() public view returns (Client.EVM2AnyMessage memory) { + return Client.EVM2AnyMessage({ + receiver: abi.encode(OWNER), + data: "", + tokenAmounts: new Client.EVMTokenAmount[](0), + feeToken: s_sourceFeeToken, + extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT})) + }); + } + + function _generateSingleTokenMessage( + address token, + uint256 amount + ) public view returns (Client.EVM2AnyMessage memory) { + Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1); + tokenAmounts[0] = Client.EVMTokenAmount({token: token, amount: amount}); + + return Client.EVM2AnyMessage({ + receiver: abi.encode(OWNER), + data: "", + tokenAmounts: tokenAmounts, + feeToken: s_sourceFeeToken, + extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: GAS_LIMIT})) + }); + } + + function _messageToEvent( + Client.EVM2AnyMessage memory message, + uint64 sourceChainSelector, + uint64 destChainSelector, + uint64 seqNum, + uint64 nonce, + uint256 feeTokenAmount, + address originalSender, + bytes32 metadataHash, + TokenAdminRegistry tokenAdminRegistry + ) internal view returns (Internal.EVM2AnyRampMessage memory) { + Client.EVMExtraArgsV2 memory extraArgs = + s_priceRegistry.parseEVMExtraArgsFromBytes(message.extraArgs, destChainSelector); + + Internal.EVM2AnyRampMessage memory messageEvent = Internal.EVM2AnyRampMessage({ + header: Internal.RampMessageHeader({ + messageId: "", + sourceChainSelector: sourceChainSelector, + destChainSelector: destChainSelector, + sequenceNumber: seqNum, + nonce: extraArgs.allowOutOfOrderExecution ? 0 : nonce + }), + sender: originalSender, + data: message.data, + receiver: message.receiver, + extraArgs: Client._argsToBytes(extraArgs), + feeToken: message.feeToken, + feeTokenAmount: feeTokenAmount, + tokenAmounts: new Internal.RampTokenAmount[](message.tokenAmounts.length) + }); + + for (uint256 i = 0; i < message.tokenAmounts.length; ++i) { + messageEvent.tokenAmounts[i] = _getSourceTokenData(message.tokenAmounts[i], tokenAdminRegistry); + } + + messageEvent.header.messageId = Internal._hash(messageEvent, metadataHash); + return messageEvent; + } + + function _getSourceTokenData( + Client.EVMTokenAmount memory tokenAmount, + TokenAdminRegistry tokenAdminRegistry + ) internal view returns (Internal.RampTokenAmount memory) { + address destToken = s_destTokenBySourceToken[tokenAmount.token]; + + return Internal.RampTokenAmount({ + sourcePoolAddress: abi.encode(tokenAdminRegistry.getTokenConfig(tokenAmount.token).tokenPool), + destTokenAddress: abi.encode(destToken), + extraData: "", + amount: tokenAmount.amount + }); + } + + function _calcUSDValueFromTokenAmount(uint224 tokenPrice, uint256 tokenAmount) internal pure returns (uint256) { + return (tokenPrice * tokenAmount) / 1e18; + } + + function _applyBpsRatio(uint256 tokenAmount, uint16 ratio) internal pure returns (uint256) { + return (tokenAmount * ratio) / 1e5; + } + + function _configUSDCentToWei(uint256 usdCent) internal pure returns (uint256) { + return usdCent * 1e16; + } +} diff --git a/contracts/src/v0.8/ccip/test/rateLimiter/AggregateRateLimiter.t.sol b/contracts/src/v0.8/ccip/test/rateLimiter/AggregateRateLimiter.t.sol index d3a07ef11e..af970b0f92 100644 --- a/contracts/src/v0.8/ccip/test/rateLimiter/AggregateRateLimiter.t.sol +++ b/contracts/src/v0.8/ccip/test/rateLimiter/AggregateRateLimiter.t.sol @@ -6,7 +6,7 @@ import {Client} from "../../libraries/Client.sol"; import {Internal} from "../../libraries/Internal.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; import {AggregateRateLimiterHelper} from "../helpers/AggregateRateLimiterHelper.sol"; -import {PriceRegistrySetup} from "../priceRegistry/PriceRegistry.t.sol"; +import {PriceRegistrySetup} from "../priceRegistry/PriceRegistrySetup.t.sol"; import {stdError} from "forge-std/Test.sol"; @@ -20,7 +20,7 @@ contract AggregateTokenLimiterSetup is PriceRegistrySetup { function setUp() public virtual override { PriceRegistrySetup.setUp(); - Internal.PriceUpdates memory priceUpdates = getSingleTokenPriceUpdateStruct(TOKEN, TOKEN_PRICE); + Internal.PriceUpdates memory priceUpdates = _getSingleTokenPriceUpdateStruct(TOKEN, TOKEN_PRICE); s_priceRegistry.updatePrices(priceUpdates); s_config = RateLimiter.Config({isEnabled: true, rate: 5, capacity: 100}); diff --git a/contracts/src/v0.8/ccip/test/rateLimiter/MultiAggregateRateLimiter.t.sol b/contracts/src/v0.8/ccip/test/rateLimiter/MultiAggregateRateLimiter.t.sol index e30ce02212..292c4533e4 100644 --- a/contracts/src/v0.8/ccip/test/rateLimiter/MultiAggregateRateLimiter.t.sol +++ b/contracts/src/v0.8/ccip/test/rateLimiter/MultiAggregateRateLimiter.t.sol @@ -8,7 +8,7 @@ import {Internal} from "../../libraries/Internal.sol"; import {RateLimiter} from "../../libraries/RateLimiter.sol"; import {BaseTest} from "../BaseTest.t.sol"; import {MultiAggregateRateLimiterHelper} from "../helpers/MultiAggregateRateLimiterHelper.sol"; -import {PriceRegistrySetup} from "../priceRegistry/PriceRegistry.t.sol"; +import {PriceRegistrySetup} from "../priceRegistry/PriceRegistrySetup.t.sol"; import {stdError} from "forge-std/Test.sol"; import {Vm} from "forge-std/Vm.sol"; @@ -33,7 +33,7 @@ contract MultiAggregateRateLimiterSetup is BaseTest, PriceRegistrySetup { BaseTest.setUp(); PriceRegistrySetup.setUp(); - Internal.PriceUpdates memory priceUpdates = getSingleTokenPriceUpdateStruct(TOKEN, TOKEN_PRICE); + Internal.PriceUpdates memory priceUpdates = _getSingleTokenPriceUpdateStruct(TOKEN, TOKEN_PRICE); s_priceRegistry.updatePrices(priceUpdates); MultiAggregateRateLimiter.RateLimiterConfigArgs[] memory configUpdates = @@ -683,7 +683,7 @@ contract MultiAggregateRateLimiter_onInboundMessage is MultiAggregateRateLimiter }); Internal.PriceUpdates memory priceUpdates = - getSingleTokenPriceUpdateStruct(s_destTokens[i], TOKEN_PRICE * (i + 1)); + _getSingleTokenPriceUpdateStruct(s_destTokens[i], TOKEN_PRICE * (i + 1)); s_priceRegistry.updatePrices(priceUpdates); } s_rateLimiter.updateRateLimitTokens(new MultiAggregateRateLimiter.LocalRateLimitToken[](0), tokensToAdd); @@ -919,7 +919,7 @@ contract MultiAggregateRateLimiter_onOutboundMessage is MultiAggregateRateLimite }); Internal.PriceUpdates memory priceUpdates = - getSingleTokenPriceUpdateStruct(s_sourceTokens[i], TOKEN_PRICE * (i + 1)); + _getSingleTokenPriceUpdateStruct(s_sourceTokens[i], TOKEN_PRICE * (i + 1)); s_priceRegistry.updatePrices(priceUpdates); } s_rateLimiter.updateRateLimitTokens(new MultiAggregateRateLimiter.LocalRateLimitToken[](0), tokensToAdd); diff --git a/contracts/src/v0.8/ccip/test/router/Router.t.sol b/contracts/src/v0.8/ccip/test/router/Router.t.sol index cfe01e3c41..5f3a3a66ab 100644 --- a/contracts/src/v0.8/ccip/test/router/Router.t.sol +++ b/contracts/src/v0.8/ccip/test/router/Router.t.sol @@ -265,8 +265,11 @@ contract Router_ccipSend is EVM2EVMOnRampSetup { s_priceRegistry.applyFeeTokensUpdates(feeTokens, new address[](0)); // Update the price of the newly set feeToken - Internal.PriceUpdates memory priceUpdates = getSingleTokenPriceUpdateStruct(feeTokenWithZeroFeeAndGas, 2_000 ether); - priceUpdates.gasPriceUpdates = getSingleGasPriceUpdateStruct(DEST_CHAIN_SELECTOR, 0).gasPriceUpdates; + Internal.PriceUpdates memory priceUpdates = _getSingleTokenPriceUpdateStruct(feeTokenWithZeroFeeAndGas, 2_000 ether); + priceUpdates.gasPriceUpdates = new Internal.GasPriceUpdate[](1); + priceUpdates.gasPriceUpdates[0] = + Internal.GasPriceUpdate({destChainSelector: DEST_CHAIN_SELECTOR, usdPerUnitGas: 0}); + s_priceRegistry.updatePrices(priceUpdates); // Set the feeToken args on the onRamp @@ -396,20 +399,20 @@ contract Router_applyRampUpdates is RouterSetup { s_receiver = new MaybeRevertMessageReceiver(false); } - function assertOffRampRouteSucceeds(Router.OffRamp memory offRamp) internal { + function _assertOffRampRouteSucceeds(Router.OffRamp memory offRamp) internal { vm.startPrank(offRamp.offRamp); - Client.Any2EVMMessage memory message = generateReceiverMessage(offRamp.sourceChainSelector); + Client.Any2EVMMessage memory message = _generateReceiverMessage(offRamp.sourceChainSelector); vm.expectCall(address(s_receiver), abi.encodeWithSelector(IAny2EVMMessageReceiver.ccipReceive.selector, message)); s_sourceRouter.routeMessage(message, GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver)); } - function assertOffRampRouteReverts(Router.OffRamp memory offRamp) internal { + function _assertOffRampRouteReverts(Router.OffRamp memory offRamp) internal { vm.startPrank(offRamp.offRamp); vm.expectRevert(IRouter.OnlyOffRamp.selector); s_sourceRouter.routeMessage( - generateReceiverMessage(offRamp.sourceChainSelector), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) + _generateReceiverMessage(offRamp.sourceChainSelector), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) ); } @@ -483,7 +486,7 @@ contract Router_applyRampUpdates is RouterSetup { for (uint256 i = 0; i < offRampUpdates.length; ++i) { assertEq(offRampUpdates[i].offRamp, gotOffRamps[i].offRamp); assertTrue(s_sourceRouter.isOffRamp(offRampUpdates[i].sourceChainSelector, offRampUpdates[i].offRamp)); - assertOffRampRouteSucceeds(offRampUpdates[i]); + _assertOffRampRouteSucceeds(offRampUpdates[i]); } vm.startPrank(OWNER); @@ -520,14 +523,14 @@ contract Router_applyRampUpdates is RouterSetup { assertFalse( s_sourceRouter.isOffRamp(partialOffRampRemoves[i].sourceChainSelector, partialOffRampRemoves[i].offRamp) ); - assertOffRampRouteReverts(partialOffRampRemoves[i]); + _assertOffRampRouteReverts(partialOffRampRemoves[i]); assertTrue(s_sourceRouter.isOffRamp(partialOffRampAdds[i].sourceChainSelector, partialOffRampAdds[i].offRamp)); - assertOffRampRouteSucceeds(partialOffRampAdds[i]); + _assertOffRampRouteSucceeds(partialOffRampAdds[i]); } for (uint256 i = numberOfPartialUpdates; i < offRampUpdates.length; ++i) { assertTrue(s_sourceRouter.isOffRamp(offRampUpdates[i].sourceChainSelector, offRampUpdates[i].offRamp)); - assertOffRampRouteSucceeds(offRampUpdates[i]); + _assertOffRampRouteSucceeds(offRampUpdates[i]); } vm.startPrank(OWNER); @@ -557,11 +560,11 @@ contract Router_applyRampUpdates is RouterSetup { for (uint256 i = 0; i < numberOfPartialUpdates; ++i) { assertFalse(s_sourceRouter.isOffRamp(partialOffRampAdds[i].sourceChainSelector, partialOffRampAdds[i].offRamp)); - assertOffRampRouteReverts(partialOffRampAdds[i]); + _assertOffRampRouteReverts(partialOffRampAdds[i]); } for (uint256 i = 0; i < offRampUpdates.length; ++i) { assertFalse(s_sourceRouter.isOffRamp(offRampUpdates[i].sourceChainSelector, offRampUpdates[i].offRamp)); - assertOffRampRouteReverts(offRampUpdates[i]); + _assertOffRampRouteReverts(offRampUpdates[i]); } vm.startPrank(OWNER); @@ -582,13 +585,13 @@ contract Router_applyRampUpdates is RouterSetup { for (uint256 i = 0; i < offRampUpdates.length; ++i) { assertEq(offRampUpdates[i].offRamp, gotOffRamps[i].offRamp); assertTrue(s_sourceRouter.isOffRamp(offRampUpdates[i].sourceChainSelector, offRampUpdates[i].offRamp)); - assertOffRampRouteSucceeds(offRampUpdates[i]); + _assertOffRampRouteSucceeds(offRampUpdates[i]); } // Check offramps that were not added back remain unset. for (uint256 i = 0; i < numberOfPartialUpdates; ++i) { assertFalse(s_sourceRouter.isOffRamp(partialOffRampAdds[i].sourceChainSelector, partialOffRampAdds[i].offRamp)); - assertOffRampRouteReverts(partialOffRampAdds[i]); + _assertOffRampRouteReverts(partialOffRampAdds[i]); } } @@ -691,18 +694,18 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { vm.startPrank(address(s_offRamp)); } - function generateManualGasLimit(uint256 callDataLength) internal view returns (uint256) { + function _generateManualGasLimit(uint256 callDataLength) internal view returns (uint256) { return ((gasleft() - 2 * (16 * callDataLength + GAS_FOR_CALL_EXACT_CHECK)) * 62) / 64; } function test_ManualExec_Success() public { - Client.Any2EVMMessage memory message = generateReceiverMessage(SOURCE_CHAIN_SELECTOR); + Client.Any2EVMMessage memory message = _generateReceiverMessage(SOURCE_CHAIN_SELECTOR); // Manuel execution cannot run out of gas (bool success, bytes memory retData, uint256 gasUsed) = s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, - generateManualGasLimit(message.data.length), + _generateManualGasLimit(message.data.length), address(s_receiver) ); assertTrue(success); @@ -711,7 +714,7 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { } function test_ExecutionEvent_Success() public { - Client.Any2EVMMessage memory message = generateReceiverMessage(SOURCE_CHAIN_SELECTOR); + Client.Any2EVMMessage memory message = _generateReceiverMessage(SOURCE_CHAIN_SELECTOR); // Should revert with reason bytes memory realError1 = new bytes(2); realError1[0] = 0xbe; @@ -727,9 +730,9 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { ); (bool success, bytes memory retData, uint256 gasUsed) = s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, - generateManualGasLimit(message.data.length), + _generateManualGasLimit(message.data.length), address(s_reverting_receiver) ); @@ -753,9 +756,9 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { ); (success, retData, gasUsed) = s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, - generateManualGasLimit(message.data.length), + _generateManualGasLimit(message.data.length), address(s_reverting_receiver) ); @@ -782,9 +785,9 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { ); (success, retData, gasUsed) = s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, - generateManualGasLimit(message.data.length), + _generateManualGasLimit(message.data.length), address(s_receiver) ); @@ -794,7 +797,7 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { } function test_Fuzz_ExecutionEvent_Success(bytes calldata error) public { - Client.Any2EVMMessage memory message = generateReceiverMessage(SOURCE_CHAIN_SELECTOR); + Client.Any2EVMMessage memory message = _generateReceiverMessage(SOURCE_CHAIN_SELECTOR); s_reverting_receiver.setErr(error); bytes memory expectedRetData; @@ -827,9 +830,9 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { } (bool success, bytes memory retData,) = s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, - generateManualGasLimit(message.data.length), + _generateManualGasLimit(message.data.length), address(s_reverting_receiver) ); @@ -839,13 +842,13 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { function test_AutoExec_Success() public { (bool success,,) = s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) ); assertTrue(success); (success,,) = s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 1, address(s_receiver) + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 1, address(s_receiver) ); // Can run out of gas, should return false @@ -859,7 +862,7 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { vm.expectRevert(IRouter.OnlyOffRamp.selector); s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) ); } @@ -867,7 +870,7 @@ contract Router_routeMessage is EVM2EVMOffRampSetup { s_mockRMN.setGlobalCursed(true); vm.expectRevert(Router.BadARMSignal.selector); s_destRouter.routeMessage( - generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) + _generateReceiverMessage(SOURCE_CHAIN_SELECTOR), GAS_FOR_CALL_EXACT_CHECK, 100_000, address(s_receiver) ); } } diff --git a/contracts/src/v0.8/ccip/test/router/RouterSetup.t.sol b/contracts/src/v0.8/ccip/test/router/RouterSetup.t.sol index 423a47951d..7297721baa 100644 --- a/contracts/src/v0.8/ccip/test/router/RouterSetup.t.sol +++ b/contracts/src/v0.8/ccip/test/router/RouterSetup.t.sol @@ -26,7 +26,7 @@ contract RouterSetup is BaseTest { } } - function generateReceiverMessage(uint64 chainSelector) internal pure returns (Client.Any2EVMMessage memory) { + function _generateReceiverMessage(uint64 chainSelector) internal pure returns (Client.Any2EVMMessage memory) { Client.EVMTokenAmount[] memory ta = new Client.EVMTokenAmount[](0); return Client.Any2EVMMessage({ messageId: bytes32("a"), @@ -37,7 +37,7 @@ contract RouterSetup is BaseTest { }); } - function generateSourceTokenData() internal pure returns (Internal.SourceTokenData memory) { + function _generateSourceTokenData() internal pure returns (Internal.SourceTokenData memory) { return Internal.SourceTokenData({ sourcePoolAddress: abi.encode(address(12312412312)), destTokenAddress: abi.encode(address(9809808909)),