Summary
The test suite and some comments in this repository assume that Solady’s ERC20 implementation grants infinite allowance to the canonical Permit2 contract (0x000000000022D473030F116dDEE9F6B43aC78BA3) by default. However, this is not the case unless the ERC20 implementation explicitly overrides the _givePermit2InfiniteAllowance() function to return true.
Details
-
Solady’s base ERC20 contract includes logic for infinite Permit2 allowance, but the default implementation of:
function _givePermit2InfiniteAllowance() internal view virtual returns (bool) {
return false;
}
means that Permit2 does not have infinite allowance unless this function is overridden.
-
Current test setup and comments (e.g., in Setup.sol) assume infinite approval is granted by default, which is misleading.
-
Observed behavior:
- Tests involving Permit2 revert with
InsufficientAllowance() unless an explicit approve(permit2, amount) is called.
- Adding this approval in the test setup resolves the issue.
Steps to Reproduce
- Use Solady’s
MockERC20 in a test.
- Attempt a Permit2 transfer without calling
approve(permit2, amount).
- Observe a revert due to insufficient allowance.
Expected Behavior
- Either:
- The test setup should always explicitly approve Permit2, or
- The custom ERC20 used in tests should override
_givePermit2InfiniteAllowance() to return true.
Suggested Fix
- Update test setup to always call
token.approve(permit2, amount) for any token used with Permit2.
- Update comments to clarify that infinite Permit2 approval is not enabled by default in Solady ERC20.
- Optionally, provide a custom mock that enables infinite Permit2 allowance for tests that require it.
References
Summary
The test suite and some comments in this repository assume that Solady’s ERC20 implementation grants infinite allowance to the canonical Permit2 contract (
0x000000000022D473030F116dDEE9F6B43aC78BA3) by default. However, this is not the case unless the ERC20 implementation explicitly overrides the_givePermit2InfiniteAllowance()function to returntrue.Details
Solady’s base ERC20 contract includes logic for infinite Permit2 allowance, but the default implementation of:
means that Permit2 does not have infinite allowance unless this function is overridden.
Current test setup and comments (e.g., in
Setup.sol) assume infinite approval is granted by default, which is misleading.Observed behavior:
InsufficientAllowance()unless an explicitapprove(permit2, amount)is called.Steps to Reproduce
MockERC20in a test.approve(permit2, amount).Expected Behavior
_givePermit2InfiniteAllowance()to returntrue.Suggested Fix
token.approve(permit2, amount)for any token used with Permit2.References