You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ee79c98
Browse filesBrowse the repository at this point in the historyBrowse files
authored
PaymasterERC20: pass the selected token to _minTokensPerNative (#6831)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Luiz Vasconcelos Júnior <64055364+luiz-lvj@users.noreply.github.com>
[BREAKING]`PaymasterERC20`: Pass the selected `token` to the `_minTokensPerNative` hook so multi-token paymasters can set a per-token minimum. The hook signature changes from `_minTokensPerNative()` to `_minTokensPerNative(IERC20 token)`; overrides must adopt the new signature.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/paymasters.adoc
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -208,7 +208,7 @@ contract PaymasterUSDCChainlink is PaymasterERC20, Ownable {
208
208
209
209
/// @dev Floor: refuse to sponsor when 1 ETH is worth less than 100 USDC.
210
210
/// 1e8 = 100 (USDC per ETH) * 10**6 (USDC decimals); the 1e18 denom cancels 1e18 wei/ETH.
211
-
function _minTokensPerNative() internal view virtual override returns (uint256) {
211
+
function _minTokensPerNative(IERC20) internal view virtual override returns (uint256) {
212
212
return 1e8;
213
213
}
214
214
@@ -239,7 +239,7 @@ contract PaymasterUSDCChainlink is PaymasterERC20, Ownable {
239
239
240
240
NOTE: The `PaymasterUSDCChainlink` contract uses specific Chainlink price feeds (ETH/USD and USDC/USD) on Sepolia. For production use or other networks, you'll need to modify the contract to use the appropriate price feed addresses.
241
241
242
-
NOTE: xref:api:account.adoc#PaymasterERC20-_minTokensPerNative--[`_minTokensPerNative`] defaults to `0` in `PaymasterERC20` and should be overridden. It is a lower bound on `tokenPerNative` (same units: token-units per native coin, scaled by xref:api:account.adoc#PaymasterERC20-_tokenPerNativeDenominator--[`_tokenPerNativeDenominator`]); any operation whose `_fetchDetails` returns a `tokenPerNative` strictly below this floor is rejected with `SIG_VALIDATION_FAILED` before pre-charging the user. The example above returns `1e8`, which refuses to sponsor when 1 ETH is worth less than 100 USDC — a conservative sanity check against misconfigured oracles or extreme market conditions. Returning `0` disables the check and re-opens the "free sponsorship" footgun if `_fetchDetails` ever returns a near-zero price.
242
+
NOTE: xref:api:account.adoc#PaymasterERC20-_minTokensPerNative-contract-IERC20-[`_minTokensPerNative`] defaults to `0` in `PaymasterERC20` and should be overridden. It receives the `token` selected by `_fetchDetails`, so a multi-token paymaster can return a different floor per token. It is a lower bound on `tokenPerNative` (same units: token-units per native coin, scaled by xref:api:account.adoc#PaymasterERC20-_tokenPerNativeDenominator--[`_tokenPerNativeDenominator`]); any operation whose `_fetchDetails` returns a `tokenPerNative` strictly below this floor is rejected with `SIG_VALIDATION_FAILED` before pre-charging the user. The example above returns `1e8`, which refuses to sponsor when 1 ETH is worth less than 100 USDC — a conservative sanity check against misconfigured oracles or extreme market conditions. Returning `0` disables the check and re-opens the "free sponsorship" footgun if `_fetchDetails` ever returns a near-zero price.
243
243
244
244
As you can see, a `_fetchOracleDetails` function is specified to fetch the token price that will be used as a reference for calculating the final ERC-20 payment. One can fetch and process price data from Chainlink oracles to determine the exchange rate between ETH and a concrete ERC-20. An example with USDC would be:
0 commit comments