-
Notifications
You must be signed in to change notification settings - Fork 49
RUSDT -> USDT0 converter #565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a RUSDT to USDT0 token swap contract for the Rootstock network. The contract acts as an ERC777 recipient that automatically converts incoming RUSDT tokens to USDT0 tokens at a 1:1 ratio (accounting for decimal differences).
Key changes:
- Added
RootstockUsdtSwap.solcontract that implements ERC777 recipient interface to handle automatic token swaps - Created comprehensive test suite covering success cases, error conditions, and rescue functionality
- Added deployment script with placeholder addresses for the three required roles
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| contracts/utils/RootstockUsdtSwap.sol | Core swap contract implementing ERC777 recipient hook, decimal conversion logic, and emergency rescue function |
| tests-foundry/RootstockUsdtSwap.t.sol | Complete test coverage including mock contracts, success scenarios, validation checks, and edge cases |
| script/DeployRootstockUsdtSwap.s.sol | Deployment script with hardcoded test addresses for the three contract roles |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| require(allowance >= usdt0Amount, "USDT0 allowance too low"); | ||
| uint256 providerBalance = USDT0.balanceOf(usdt0Provider); | ||
| require(providerBalance >= usdt0Amount, "USDT0 provider balance too low"); | ||
| bool success = USDT0.transferFrom(usdt0Provider, from, usdt0Amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use SafeERC20 library here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SafeERC20 is used to cover cases with not fully compatible ERC20, like USDT on Ethereum transfer function doesn't return bool which would at most lead to revert of the whole swap.
but based on the technical documentation for USDT0 on Rootstock, it is explicitly designed to be fully ERC-20 compliant, which means it is safe to call transferFrom and check its boolean return value, meaning this is a gas saving approach in this particular case.
| uint256 allowance = USDT0.allowance(usdt0Provider, address(this)); | ||
| require(allowance >= usdt0Amount, "USDT0 allowance too low"); | ||
| uint256 providerBalance = USDT0.balanceOf(usdt0Provider); | ||
| require(providerBalance >= usdt0Amount, "USDT0 provider balance too low"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required, since we will check the below transfer whether it's failed or not.
But in case you want to keep this for the better revert message, then i am fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just to revert early in case there is not enough balance or allowance and for clear revert msg.
No description provided.