ERC20SafeApproveLib
Author: Golem Foundation
Library for safe ERC20 approve operations handling non-standard tokens
*Handles tokens that don't return bool or revert silently PROBLEM SOLVED:
- Some tokens (USDT, BNB) don't return bool from approve()
- Some tokens revert silently on approval failure
- Standard Solidity expects bool return value SOLUTION:
- Uses low-level call to handle any return data format
- Validates success flag
- Validates return data if present
- Reverts with ApprovalFailed() on any failure*
Notes:
-
security-contact: [email protected]
-
security: Critical for compatibility with non-standard ERC20 tokens
Functions
safeApprove
Safely approves ERC20 tokens handling non-standard implementations
*Uses low-level call to handle tokens that:
- Don't return bool (e.g., USDT)
- Return false instead of reverting
- Have non-standard approval behavior*
Note: security: Reverts with ApprovalFailed() on any failure
function safeApprove(address token, address spender, uint256 amount) external;
Parameters
| Name | Type | Description |
|---|---|---|
token | address | ERC20 token address |
spender | address | Address being approved to spend tokens |
amount | uint256 | Amount to approve |