From 03cba2c7f96d7c346a914b4b54397378a5dadfe5 Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:10:46 +0530 Subject: [PATCH] logs for failing test accounting --- contracts/token/BiconomyTokenPaymaster.sol | 21 +++++++++++++++++++-- test/base/TestBase.sol | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/contracts/token/BiconomyTokenPaymaster.sol b/contracts/token/BiconomyTokenPaymaster.sol index c171217..26e7cbb 100644 --- a/contracts/token/BiconomyTokenPaymaster.sol +++ b/contracts/token/BiconomyTokenPaymaster.sol @@ -16,6 +16,7 @@ import { SignatureCheckerLib } from "solady/utils/SignatureCheckerLib.sol"; import { ECDSA as ECDSA_solady } from "solady/utils/ECDSA.sol"; import "account-abstraction/core/Helpers.sol"; import "./swaps/Uniswapper.sol"; +// Todo: marked for removal import "forge-std/console2.sol"; /** @@ -435,6 +436,14 @@ contract BiconomyTokenPaymaster is revert InvalidPaymasterMode(); } + // callGasLimit + paymasterPostOpGas + uint256 maxPenalty = ( + ( + uint128(uint256(userOp.accountGasLimits)) + + uint128(bytes16(userOp.paymasterAndData[_PAYMASTER_POSTOP_GAS_OFFSET:_PAYMASTER_DATA_OFFSET])) + ) * 10 * userOp.unpackMaxFeePerGas() + ) / 100; + if (mode == PaymasterMode.EXTERNAL) { // Use the price and other params specified in modeSpecificData by the verifyingSigner // Useful for supporting tokens which don't have oracle support @@ -469,10 +478,12 @@ contract BiconomyTokenPaymaster is revert InvalidPriceMarkup(); } + uint256 tokenAmount; + // Review { uint256 maxFeePerGas = UserOperationLib.unpackMaxFeePerGas(userOp); - tokenAmount = ((maxCost + (unaccountedGas) * maxFeePerGas) * externalPriceMarkup * tokenPrice) + tokenAmount = ((maxCost + maxPenalty + (unaccountedGas * maxFeePerGas)) * externalPriceMarkup * tokenPrice) / (1e18 * _PRICE_DENOMINATOR); } @@ -496,7 +507,7 @@ contract BiconomyTokenPaymaster is { // Calculate token amount to precharge uint256 maxFeePerGas = UserOperationLib.unpackMaxFeePerGas(userOp); - tokenAmount = ((maxCost + (unaccountedGas) * maxFeePerGas) * independentPriceMarkup * tokenPrice) + tokenAmount = ((maxCost + maxPenalty + (unaccountedGas * maxFeePerGas)) * independentPriceMarkup * tokenPrice) / (1e18 * _PRICE_DENOMINATOR); } @@ -539,6 +550,12 @@ contract BiconomyTokenPaymaster is uint256 actualTokenAmount = ( (actualGasCost + (unaccountedGas * actualUserOpFeePerGas)) * appliedPriceMarkup * tokenPrice ) / (1e18 * _PRICE_DENOMINATOR); + console2.log("tokenPrice", tokenPrice); + console2.log("appliedPriceMarkup", appliedPriceMarkup); + console2.log("actualGasCost", actualGasCost); + console2.log("actualUserOpFeePerGas", actualUserOpFeePerGas); + console2.log("actualTokenAmount", actualTokenAmount); + console2.log("prechargedAmount", prechargedAmount); if (prechargedAmount > actualTokenAmount) { // If the user was overcharged, refund the excess tokens diff --git a/test/base/TestBase.sol b/test/base/TestBase.sol index 8670052..ba15ec1 100644 --- a/test/base/TestBase.sol +++ b/test/base/TestBase.sol @@ -474,7 +474,7 @@ abstract contract TestBase is CheatCodes, TestHelper, BaseEventsAndErrors { // Note: yet to figure out why we're charging too low in tokens vs bundler is paying high gas fees! // Review we will also need to update premium numbers in below if there is premium: multiply by 1e6 / premium - // assertGt(gasPaidBySAInERC20 * 1e18 / tokenPrice, BUNDLER.addr.balance - initialBundlerBalance); + assertGt(gasPaidBySAInERC20 * 1e18 / tokenPrice, BUNDLER.addr.balance - initialBundlerBalance); // Ensure that max 2% difference between total gas paid + the adjustment premium and gas paid by smart account (ERC20 charge * token gas price) (from // Todo