TokenPaymaster: token charge workflow

Hello everyone,

In the token paymaster, I can see that the max theoretical token amount is charged in the preRelayedCall and then the excess is refunded in the postRelayedCall.

Couldn’t we just charge the token amount in the postRelayedCall once we know the exact amount we of gas that have been spent ?

Both the functions are called in the in the same transaction no security risk, and that would save some gas.

Am I missing something ?

Yes, you could charge the user in the post call - but then you trust the user not to perform an operation that withdraw the amount, because if the user does withdraw, then the paymaster pays for the gas, but can’t get compensated…

1 Like