Skip to content

Commit

Permalink
logs for failing test accounting
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Oct 30, 2024
1 parent 026d758 commit 03cba2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check failure on line 20 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected import of console file

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -539,6 +550,12 @@ contract BiconomyTokenPaymaster is
uint256 actualTokenAmount = (
(actualGasCost + (unaccountedGas * actualUserOpFeePerGas)) * appliedPriceMarkup * tokenPrice
) / (1e18 * _PRICE_DENOMINATOR);
console2.log("tokenPrice", tokenPrice);

Check failure on line 553 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected console statement
console2.log("appliedPriceMarkup", appliedPriceMarkup);

Check failure on line 554 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected console statement
console2.log("actualGasCost", actualGasCost);

Check failure on line 555 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected console statement
console2.log("actualUserOpFeePerGas", actualUserOpFeePerGas);

Check failure on line 556 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected console statement
console2.log("actualTokenAmount", actualTokenAmount);

Check failure on line 557 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected console statement
console2.log("prechargedAmount", prechargedAmount);

Check failure on line 558 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected console statement

if (prechargedAmount > actualTokenAmount) {
// If the user was overcharged, refund the excess tokens
Expand Down
2 changes: 1 addition & 1 deletion test/base/TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03cba2c

Please sign in to comment.