Skip to content

Conversation

@tjcloa
Copy link
Contributor

@tjcloa tjcloa commented Nov 26, 2025

No description provided.

@tjcloa tjcloa requested review from Copilot and cwsnt November 26, 2025 10:16
Copy link

Copilot AI left a 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.sol contract 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);
Copy link
Contributor

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

Copy link
Contributor Author

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");
Copy link
Contributor

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

Copy link
Contributor Author

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.

@tjcloa tjcloa requested a review from cwsnt November 27, 2025 14:42
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.

3 participants