-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat(contracts-rfq): Synapse Intent Router #3433
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces several new files and functionalities related to the Synapse Intent Router. It adds an interface, Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (12)
packages/contracts-rfq/contracts/interfaces/ISynapseIntentRouter.sol (2)
2-2
: Consider updating the Solidity pragma for consistencyThe current Solidity pragma is
^0.8.4
, while other files likeSynapseIntentRouter.sol
usepragma solidity 0.8.24
. Aligning the Solidity version across all related contracts can prevent potential compilation issues and ensure compatibility.
18-18
: Define the "SIR" acronym upon first useThe abbreviation "SIR" is used without prior definition. For clarity, consider defining "SIR" (Synapse Intent Router) when it is first mentioned in the documentation.
packages/contracts-rfq/contracts/router/SynapseIntentRouter.sol (2)
19-19
: Add documentation for theNATIVE_GAS_TOKEN
special addressIncluding a comment explaining that
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
is used as a placeholder for the native gas token (e.g., ETH) can improve code readability and help other developers understand its purpose.
68-70
: Optimize input validation usingrequire
statementsFor consistency and readability, consider using
require
statements instead ofif...revert
for input validations:- if (block.timestamp > deadline) revert SIR__DeadlineExceeded(); - if (length == 0) revert SIR__StepsNotProvided(); + require(block.timestamp <= deadline, "SIR__DeadlineExceeded"); + require(length != 0, "SIR__StepsNotProvided");packages/contracts-rfq/contracts/interfaces/ISynapseIntentRouterErrors.sol (1)
2-2
: Synchronize Solidity version pragma for consistencyThe Solidity pragma is set to
^0.8.4
, whereas other contracts likeSynapseIntentRouter.sol
usepragma solidity 0.8.24
. Aligning the Solidity versions across all contracts can prevent compilation issues and maintain consistency.packages/contracts-rfq/test/mocks/WETHMock.sol (2)
21-25
: Clarify the use ofvm.deal
in themint
functionThe
mint
function utilizesvm.deal
to adjust the contract's balance for testing purposes. Sincevm
is a testing utility provided by Foundry, consider adding a comment to emphasize that this function should not be used in production code.
22-23
: Prevent potential overflow in balance calculationWhen calculating
newBalance
, addingamount
toaddress(this).balance
could potentially overflow. Although unlikely in tests, consider adding a check to prevent overflow:uint256 newBalance = address(this).balance + amount; require(newBalance >= address(this).balance, "Overflow in newBalance calculation");packages/contracts-rfq/test/mocks/PoolMock.sol (3)
23-24
: Enhance documentation clarityThe comment could be more explicit about why an empty test function prevents coverage reporting.
- /// @notice We include an empty "test" function so that this contract does not appear in the coverage report. + /// @notice Empty function with "test" prefix to exclude this mock contract from coverage reports, + /// as test files starting with "test" are typically excluded from coverage analysis.
26-28
: Consider adding access controlWhile this is a mock contract, consider adding access control to prevent unauthorized ratio changes during tests.
+ address private owner; + + constructor(address token0_, address token1_) { + token0 = token0_; + token1 = token1_; + owner = msg.sender; + } + + modifier onlyOwner() { + require(msg.sender == owner, "PoolMock: caller is not the owner"); + _; + } - function setRatioWei(uint256 ratioWei_) external { + function setRatioWei(uint256 ratioWei_) external onlyOwner { ratioWei = ratioWei_; }
30-43
: Add explicit overflow checks for ratio calculationsWhile Solidity 0.8+ includes overflow checks, consider adding explicit checks for better testing control.
function swap(uint256 amountIn, address tokenIn) external returns (uint256 amountOut) { address tokenOut; + unchecked { + // Prevent overflow in intermediate calculations + require(amountIn <= type(uint256).max / ratioWei, "PoolMock: amount too large"); + } if (tokenIn == token0) { tokenOut = token1; amountOut = amountIn * ratioWei / 1e18; } else if (tokenIn == token1) { tokenOut = token0; amountOut = amountIn * 1e18 / ratioWei; } else { revert PoolMock__TokenNotSupported(); } + require(amountOut > 0, "PoolMock: zero amount out"); IERC20(tokenIn).safeTransferFrom(msg.sender, address(this), amountIn); IERC20(tokenOut).safeTransfer(msg.sender, amountOut); }packages/contracts-rfq/test/router/SynapseIntentRouter.BalanceChecks.t.sol (2)
31-62
: Consider adding edge case testsWhile the current tests cover basic scenarios, consider adding tests for:
- Zero amount deposits
- Maximum uint256 amounts
- Amounts that could cause overflow in intermediate calculations
66-206
: Document magic numbers and constantsConsider adding documentation for constants like
TOKEN_PRICE
,FULL_BALANCE
, andAMOUNT
to explain their significance in the test scenarios.+ /// @notice Standard test amount, chosen to be large enough to test meaningful operations + /// but small enough to avoid overflow concerns uint256 constant AMOUNT = /* current value */; + + /// @notice Mock token price used for swap calculations uint256 constant TOKEN_PRICE = /* current value */; + + /// @notice Represents the full balance available for testing uint256 constant FULL_BALANCE = /* current value */;
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (7)
packages/contracts-rfq/contracts/interfaces/ISynapseIntentRouter.sol
(1 hunks)packages/contracts-rfq/contracts/interfaces/ISynapseIntentRouterErrors.sol
(1 hunks)packages/contracts-rfq/contracts/router/SynapseIntentRouter.sol
(1 hunks)packages/contracts-rfq/test/mocks/PoolMock.sol
(1 hunks)packages/contracts-rfq/test/mocks/WETHMock.sol
(2 hunks)packages/contracts-rfq/test/router/SynapseIntentRouter.BalanceChecks.t.sol
(1 hunks)packages/contracts-rfq/test/router/SynapseIntentRouter.t.sol
(1 hunks)
🔇 Additional comments (3)
packages/contracts-rfq/test/router/SynapseIntentRouter.t.sol (1)
20-1035
: Well-structured and comprehensive test suite
The test suite is extensive and covers multiple scenarios, ensuring that the SynapseIntentRouter
functions correctly under various conditions. The use of helper functions and thorough checks contributes to the maintainability and reliability of the tests.
packages/contracts-rfq/test/mocks/PoolMock.sol (1)
1-15
: LGTM! Well-structured contract declarations
Good use of SafeERC20 for secure token operations and appropriate use of immutable variables for token addresses.
packages/contracts-rfq/test/router/SynapseIntentRouter.BalanceChecks.t.sol (1)
1-28
: LGTM! Well-implemented test helper function
The completeUserIntent
override correctly implements balance checks using completeIntentWithBalanceChecks
and properly simulates user context with vm.prank
.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3433 +/- ##
============================================
Coverage ? 98.52008%
============================================
Files ? 10
Lines ? 473
Branches ? 0
============================================
Hits ? 466
Misses ? 7
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Description
Synapse Intent Router (or just SIR) is a contract that completes the user intents using a series of generic Zap steps (see #3352 for more details about Zaps). Actions like swapping, depositing, bridging, sending tokens and many others are supported as long as they could be represented as a Zap.
Contract exposes two entry points with minor differences:
completeIntent
andcompleteIntentWithBalanceChecks
:completeIntentWithBalanceChecks
also verifies that no leftover tokens are left in the auxilaryZapRecipient
contract used for performing the Zap steps.Summary by CodeRabbit
New Features
ISynapseIntentRouter
interface for executing complex token transfers with balance checks.ISynapseIntentRouterErrors
interface.SynapseIntentRouter
contract to manage and execute "zap" operations.WETHMock
contract to support token minting.Bug Fixes
SynapseIntentRouter
for better user experience.Tests
SynapseIntentRouter
, validating functionality and error conditions.