Conversation
|
/run-security-scan |
alexcos20
left a comment
There was a problem hiding this comment.
AI automated code review (Gemini 3).
Overall risk: medium
Summary:
The GrantsSwap contract introduces a one-way swap functionality from an inputToken to a compyToken at a 1:1 token unit ratio, accounting for decimal differences. It includes support for both standard ERC20 approve/transferFrom swaps and ERC20 permit based swaps. The contract utilizes OpenZeppelin's ReentrancyGuard, Ownable, and SafeERC20 for security. Extensive unit tests cover deployment, swap functionality (including permit), and owner-only withdrawal mechanisms. Overall, the contract is well-structured and tested.
Comments:
• [WARNING][other] The constructor directly calls decimals() on the IERC20 interfaces for compyToken and inputToken. While common, the ERC20 standard technically makes decimals() optional, and some tokens might not implement it or might revert when called. For well-known or custom-controlled tokens like GrantsToken, this is usually safe. However, if an arbitrary inputToken could be used, this could lead to deployment failure or incorrect decimal configuration if the token doesn't conform perfectly. Consider explicitly passing decimals as constructor arguments if this becomes a concern for untrusted inputToken deployments.
• [INFO][other] The swapToCOMPYwithPermit function assumes that the inputToken supports the IERC20Permit interface. If a standard ERC20 token that does not implement permit is set as the inputToken, calls to this function will revert. This is a design choice and likely acceptable given specific GrantsToken context, but it's important to be aware of this implicit dependency when configuring the inputToken address for deployment. Adding a NatSpec comment explicitly stating this requirement for the inputToken would improve clarity.
• [INFO][style] The core logic for calculating compyAmount and performing the safeTransferFrom and safeTransfer operations is duplicated between swapToCOMPY and swapToCOMPYwithPermit. While not a bug, extracting this common logic into a private internal helper function could improve code reusability and maintainability.
|
WIP:
|
Feature/add grants swap
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
Fixes #1002
This PR introduces a new
GrantsSwapcontract that enables users to swap input tokens for COMPY tokens at a 1:1 ratio. The contract includes support for ERC20Permit for gasless approvals and owner-controlled token withdrawal functionality.Motivation
The GrantsSwap contract provides a simple, secure mechanism for users to exchange their input tokens for COMPY tokens. This enables a one-way swap mechanism where users can convert their tokens to COMPY while maintaining a fixed 1:1 exchange rate that properly accounts for different token decimal places.
Key Features
1. One-Way Token Swap
2. ERC20Permit Support
swapToCOMPYwithPermit()function allows gasless token approvals3. Owner Functionality
Ownablefor access controlwithdrawTokens()