-
Notifications
You must be signed in to change notification settings - Fork 36
feat(contracts-rfq): Synapse Intent Router #3433
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6fd65c4
feat: scaffold IntentRouter
ChiTimesChi 12e6e8b
feat: initial implementation
ChiTimesChi aac2b06
test: single step
ChiTimesChi f3ecf9b
feat: scaffold checked/unchecked `completeIntent`
ChiTimesChi ab32c3a
feat: implement balance checks
ChiTimesChi 1d6d23e
test: add cases where TokenZap has non-zero initial amount
ChiTimesChi 0a3a1ad
test: double step cases (erc20 and/or native combos)
ChiTimesChi abcac42
feat: SIR, TokenZap deployment script
ChiTimesChi 3410d11
deploy: test deploys for SIR
ChiTimesChi a0b9fd3
Merge branch 'master' into feat/syn-intent-router
ChiTimesChi 394f78b
test: update to #3434 changes
ChiTimesChi 4843d57
feat: scaffold SIP
ChiTimesChi 4106cd5
test: coverage for SIP
ChiTimesChi f3404cc
feat: Synapse Intent Previewer
ChiTimesChi 2e6bce6
feat: update deploy script, deploy SIP
ChiTimesChi e28e56e
fix(contracts-rfq): add `forwardTo` to ZapData for Zap Actions that d…
ChiTimesChi File filter 8000
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
packages/contracts-rfq/contracts/interfaces/ISynapseIntentPreviewer.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import {ISynapseIntentRouter} from "./ISynapseIntentRouter.sol"; | ||
|
||
interface ISynapseIntentPreviewer { | ||
/// @notice Preview the completion of a user intent. | ||
/// @dev Will not revert if the intent cannot be completed, returns empty values instead. | ||
/// @dev Returns (amountIn, []) if the intent is a no-op (tokenIn == tokenOut). | ||
/// @param swapQuoter Peripheral contract to use for swap quoting | ||
/// @param forwardTo The address to which the proceeds of the intent should be forwarded to. | ||
/// Note: if no forwarding is required (or done within the intent), use address(0). | ||
/// @param tokenIn Initial token for the intent | ||
/// @param tokenOut Final token for the intent | ||
/// @param amountIn Initial amount of tokens to use for the intent | ||
/// @return amountOut Final amount of tokens to receive. Zero if the intent cannot be completed. | ||
/// @return steps Steps to use in SynapseIntentRouter in order to complete the intent. | ||
/// Empty if the intent cannot be completed, or if intent is a no-op (tokenIn == tokenOut). | ||
function previewIntent( | ||
address swapQuoter, | ||
address forwardTo, | ||
address tokenIn, | ||
address tokenOut, | ||
uint256 amountIn | ||
) | ||
external | ||
view | ||
returns (uint256 amountOut, ISynapseIntentRouter.StepParams[] memory steps); | ||
} |
66 changes: 66 additions & 0 deletions
66
packages/contracts-rfq/contracts/interfaces/ISynapseIntentRouter.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
interface ISynapseIntentRouter { | ||
/// @notice Parameters for a single Zap step. | ||
/// @param token Address of the token to use for the step | ||
/// @param amount Amount of tokens to use for the step (type(uint256).max to use the full ZapRecipient balance) | ||
/// @param msgValue Amount of native token to supply for the step, out of the total `msg.value` used for the | ||
/// `fulfillIntent` call (could differ from `amount` regardless of the token type) | ||
/// @param zapData Instructions for the ZapRecipient contract on how to execute the Zap | ||
struct StepParams { | ||
address token; | ||
uint256 amount; | ||
uint256 msgValue; | ||
bytes zapData; | ||
} | ||
|
||
/// @notice Kindly ask SIR to complete the provided intent by completing a series of Zap steps using the | ||
/// provided ZapRecipient contract. | ||
/// - Each step is verified to be a correct Zap as per `IZapRecipient` specification. | ||
/// - The amounts used for each step can be predetermined or based on the proceeds from the previous steps. | ||
/// - SIR does not perform any checks on the Zap Data; the user is responsible for ensuring correct encoding. | ||
/// - The user is responsible for selecting the correct ZapRecipient for their intent: ZapRecipient must be | ||
/// able to modify the Zap Data to adjust to possible changes in the passed amount value. | ||
/// - SIR checks that the ZapRecipient balance for every token in `steps` has not increased after the last step. | ||
/// @dev Typical workflow involves a series of preparation steps followed by the last step representing the user | ||
/// intent such as bridging, depositing, or a simple transfer to the final recipient. The ZapRecipient must be | ||
/// the funds recipient for the preparation steps, while the final recipient must be used for the last step. | ||
/// @dev This function will revert in any of the following cases: | ||
/// - The deadline has passed. | ||
/// - The array of StepParams is empty. | ||
/// - The 8000 amount of tokens to use for the last step is below the specified minimum. | ||
/// - Any step fails. | ||
/// - `msg.value` does not match `sum(steps[i].msgValue)`. | ||
/// @param zapRecipient Address of the IZapRecipient contract to use for the Zap steps | ||
/// @param amountIn Initial amount of tokens (steps[0].token) to transfer into ZapRecipient | ||
/// @param minLastStepAmountIn Minimum amount of tokens (steps[N-1].token) to use for the last step | ||
/// @param deadline Deadline for the intent to be completed | ||
/// @param steps Parameters for each step. Use amount = type(uint256).max for steps that | ||
/// should use the full ZapRecipient balance. | ||
function completeIntentWithBalanceChecks( | ||
address zapRecipient, | ||
uint256 amountIn, | ||
uint256 minLastStepAmountIn, | ||
uint256 deadline, | ||
StepParams[] memory steps | ||
) | ||
external | ||
payable; | ||
|
||
/// @notice Kindly ask SIR to complete the provided intent by completing a series of Zap steps using the | ||
/// provided ZapRecipient contract. | ||
/// @dev This function is identical to `completeIntentWithBalanceChecks` except that it does not verify that | ||
/// the ZapRecipient balance for every token in `steps` has not increased after the last Zap. | ||
/// Anyone using this function must validate that the funds are fully spent by ZapRecipient | ||
/// using other means like separate on-chain checks or off-chain simulation. | ||
function completeIntent( | ||
address zapRecipient, | ||
uint256 amountIn, | ||
uint256 minLastStepAmountIn, | ||
uint256 deadline, | ||
StepParams[] memory steps | ||
) | ||
external | ||
payable; | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/contracts-rfq/contracts/interfaces/ISynapseIntentRouterErrors.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
interface ISynapseIntentRouterErrors { | ||
error SIR__AmountInsufficient(); | ||
error SIR__DeadlineExceeded(); | ||
error SIR__MsgValueIncorrect(); | ||
error SIR__StepsNotProvided(); | ||
error SIR__TokenNotContract(); | ||
error SIR__UnspentFunds(); | ||
error SIR__ZapIncorrectReturnValue(); | ||
error SIR__ZapNoReturnValue(); | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/contracts-rfq/contracts/legacy/router/interfaces/IDefaultExtendedPool.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/contracts-rfq/contracts/legacy/router/interfaces/IDefaultPool.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/contracts-rfq/contracts/legacy/router/interfaces/IWETH9.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.