From 5f9a67410c269adae1836897bcf814f09b6623a7 Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Fri, 22 Nov 2024 05:43:34 +0700 Subject: [PATCH] move price update to validate fn --- .../prebuilts/account/token-paymaster/TokenPaymaster.sol | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contracts/prebuilts/account/token-paymaster/TokenPaymaster.sol b/contracts/prebuilts/account/token-paymaster/TokenPaymaster.sol index 21763889f..c7104c763 100644 --- a/contracts/prebuilts/account/token-paymaster/TokenPaymaster.sol +++ b/contracts/prebuilts/account/token-paymaster/TokenPaymaster.sol @@ -127,6 +127,10 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper { uint256 refundPostopCost = tokenPaymasterConfig.refundPostopCost; require(refundPostopCost < userOp.unpackPostOpGasLimit(), "TPM: postOpGasLimit too low"); uint256 preChargeNative = requiredPreFund + (refundPostopCost * maxFeePerGas); + + bool forceUpdate = (block.timestamp - cachedPriceTimestamp) > tokenPaymasterConfig.priceMaxAge; + updateCachedPrice(forceUpdate); + // note: as price is in native-asset-per-token and we want more tokens increasing it means dividing it by markup uint256 cachedPriceWithMarkup = (cachedPrice * PRICE_DENOMINATOR) / priceMarkup; if (dataLength == 32) { @@ -165,8 +169,7 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper { unchecked { uint256 priceMarkup = tokenPaymasterConfig.priceMarkup; (uint256 preCharge, address userOpSender) = abi.decode(context, (uint256, address)); - bool forceUpdate = (block.timestamp - cachedPriceTimestamp) > tokenPaymasterConfig.priceMaxAge; - uint256 _cachedPrice = updateCachedPrice(forceUpdate); + uint256 _cachedPrice = cachedPrice; // note: as price is in native-asset-per-token and we want more tokens increasing it means dividing it by markup uint256 cachedPriceWithMarkup = (_cachedPrice * PRICE_DENOMINATOR) / priceMarkup; // Refund tokens based on actual gas cost