Skip to content

Feature/add grants swap#1006

Merged
alexcos20 merged 5 commits intomainfrom
feature/add_grants_swap
Feb 12, 2026
Merged

Feature/add grants swap#1006
alexcos20 merged 5 commits intomainfrom
feature/add_grants_swap

Conversation

@alexcos20
Copy link
Member

@alexcos20 alexcos20 commented Feb 11, 2026

Fixes #1002

This PR introduces a new GrantsSwap contract 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

  • Users can swap input tokens for COMPY tokens at a 1:1 ratio
  • Automatically handles decimal conversion between tokens with different decimal places
  • Uses SafeERC20 for secure token transfers
  • Protected by ReentrancyGuard to prevent reentrancy attacks

2. ERC20Permit Support

  • swapToCOMPYwithPermit() function allows gasless token approvals
  • Users can swap without a separate approval transaction by providing a permit signature
  • Reduces gas costs and improves user experience

3. Owner Functionality

  • Contract inherits from OpenZeppelin's Ownable for access control
  • Owner can withdraw any ERC20 tokens from the contract via withdrawTokens()
  • Enables contract management and emergency token recovery

@alexcos20
Copy link
Member Author

/run-security-scan

Copy link
Member Author

@alexcos20 alexcos20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@alexcos20
Copy link
Member Author

WIP:

  • deploy scripts
  • actual deployments

@alexcos20 alexcos20 self-assigned this Feb 11, 2026
@alexcos20 alexcos20 added the Status: InProgress Work in progress, don't merge label Feb 11, 2026
@openzeppelin-code
Copy link

openzeppelin-code bot commented Feb 11, 2026

Feature/add grants swap

Generated at commit: dce752b150efe508cf618741a9519932ecdd61f2

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
2
1
0
9
40
52
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@alexcos20 alexcos20 marked this pull request as ready for review February 12, 2026 07:57
@alexcos20 alexcos20 requested a review from trentmc as a code owner February 12, 2026 07:57
@alexcos20 alexcos20 removed the Status: InProgress Work in progress, don't merge label Feb 12, 2026
@alexcos20 alexcos20 merged commit cfb6abb into main Feb 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swap contract COMPY<->USDC

1 participant