-
Notifications
You must be signed in to change notification settings - Fork 95
[WIP] Cross-chain Strategy #2715
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
Draft
shahthepro
wants to merge
25
commits into
master
Choose a base branch
from
shah/cross-chain-strategy-cctpv2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
637fb40
some scaffolding
sparrowDom 7630f6d
add basic necessities for unit tests
sparrowDom 6a97767
checkpoint
shahthepro 9517fca
Fix compiling issues
shahthepro 41f1fd9
Add fork test scaffolding
shahthepro 7a109cc
Fix stuffs
shahthepro 48d317e
Prettify and change salt
shahthepro c6a254a
Add auto-verification
shahthepro 8f4e39e
Fix checkBalance
shahthepro f7a9b97
Make CCTPHookWrapper more resilient
shahthepro b3c1eb4
refactor message version and type checks
sparrowDom d3c4a39
add some comments
sparrowDom 792c890
add comment
sparrowDom 70166bc
fix compile errors
sparrowDom 1e700b1
Change addresses
shahthepro 7d60614
Cross chain changes (#2718)
sparrowDom ada1546
Merge branch 'master' into shah/cross-chain-strategy-cctpv2
shahthepro 987dc0a
Fix compilation issues
shahthepro b63bd5f
Fix deployment files a bit
shahthepro bf1fbe2
Fix Message relayer
shahthepro a0dd07b
Clean up master strategy
shahthepro 4071943
Fix deployment file name
shahthepro 9e36485
move around stuff
shahthepro e401fa1
Fix CCTP Integrator
shahthepro 73abf6c
clean up fork
shahthepro File filter
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| interface ICCTPTokenMessenger { | ||
| function depositForBurn( | ||
| uint256 amount, | ||
| uint32 destinationDomain, | ||
| bytes32 mintRecipient, | ||
| address burnToken, | ||
| bytes32 destinationCaller, | ||
| uint256 maxFee, | ||
| uint32 minFinalityThreshold | ||
| ) external; | ||
|
|
||
| function depositForBurnWithHook( | ||
| uint256 amount, | ||
| uint32 destinationDomain, | ||
| bytes32 mintRecipient, | ||
| address burnToken, | ||
| bytes32 destinationCaller, | ||
| uint256 maxFee, | ||
| uint32 minFinalityThreshold, | ||
| bytes memory hookData | ||
| ) external; | ||
|
|
||
| function getMinFeeAmount(uint256 amount) external view returns (uint256); | ||
| } | ||
|
|
||
| interface ICCTPMessageTransmitter { | ||
| function sendMessage( | ||
| uint32 destinationDomain, | ||
| bytes32 recipient, | ||
| bytes32 destinationCaller, | ||
| uint32 minFinalityThreshold, | ||
| bytes memory messageBody | ||
| ) external; | ||
|
|
||
| function receiveMessage(bytes calldata message, bytes calldata attestation) | ||
| external | ||
| returns (bool); | ||
| } | ||
|
|
||
| interface IMessageHandlerV2 { | ||
| /** | ||
| * @notice Handles an incoming finalized message from an IReceiverV2 | ||
| * @dev Finalized messages have finality threshold values greater than or equal to 2000 | ||
| * @param sourceDomain The source domain of the message | ||
| * @param sender The sender of the message | ||
| * @param finalityThresholdExecuted the finality threshold at which the message was attested to | ||
| * @param messageBody The raw bytes of the message body | ||
| * @return success True, if successful; false, if not. | ||
| */ | ||
| function handleReceiveFinalizedMessage( | ||
| uint32 sourceDomain, | ||
| bytes32 sender, | ||
| uint32 finalityThresholdExecuted, | ||
| bytes calldata messageBody | ||
| ) external returns (bool); | ||
|
|
||
| /** | ||
| * @notice Handles an incoming unfinalized message from an IReceiverV2 | ||
| * @dev Unfinalized messages have finality threshold values less than 2000 | ||
| * @param sourceDomain The source domain of the message | ||
| * @param sender The sender of the message | ||
| * @param finalityThresholdExecuted The finality threshold at which the message was attested to | ||
| * @param messageBody The raw bytes of the message body | ||
| * @return success True, if successful; false, if not. | ||
| */ | ||
| function handleReceiveUnfinalizedMessage( | ||
| uint32 sourceDomain, | ||
| bytes32 sender, | ||
| uint32 finalityThresholdExecuted, | ||
| bytes calldata messageBody | ||
| ) external returns (bool); | ||
| } |
21 changes: 21 additions & 0 deletions
21
contracts/contracts/mocks/crosschain/CrossChainMasterStrategyMock.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,21 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| /** | ||
| * @title OUSD Yearn V3 Master Strategy Mock - the Mainnet part | ||
| * @author Origin Protocol Inc | ||
| */ | ||
|
|
||
| contract CrossChainMasterStrategyMock { | ||
| address public _remoteAddress; | ||
|
|
||
| constructor() {} | ||
|
|
||
| function remoteAddress() public view returns (address) { | ||
| return _remoteAddress; | ||
| } | ||
|
|
||
| function setRemoteAddress(address __remoteAddress) public { | ||
| _remoteAddress = __remoteAddress; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
contracts/contracts/mocks/crosschain/CrossChainRemoteStrategyMock.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,21 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| /** | ||
| * @title OUSD Yearn V3 Remote Strategy Mock - the Mainnet part | ||
| * @author Origin Protocol Inc | ||
| */ | ||
|
|
||
| contract CrossChainRemoteStrategyMock { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove is a better name than Slave :) |
||
| address public _masterAddress; | ||
|
|
||
| constructor() {} | ||
|
|
||
| function masterAddress() public view returns (address) { | ||
| return _masterAddress; | ||
| } | ||
|
|
||
| function setMasterAddress(address __masterAddress) public { | ||
| _masterAddress = __masterAddress; | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
contracts/contracts/proxies/InitializeGovernedUpgradeabilityProxy2.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,22 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import { InitializeGovernedUpgradeabilityProxy } from "./InitializeGovernedUpgradeabilityProxy.sol"; | ||
|
|
||
| /** | ||
| * @title BaseGovernedUpgradeabilityProxy2 | ||
| * @dev This is the same as InitializeGovernedUpgradeabilityProxy except that the | ||
| * governor is defined in the constructor. | ||
| * @author Origin Protocol Inc | ||
| */ | ||
| contract InitializeGovernedUpgradeabilityProxy2 is | ||
| InitializeGovernedUpgradeabilityProxy | ||
| { | ||
| /** | ||
| * This is used when the msg.sender can not be the governor. E.g. when the proxy is | ||
| * deployed via CreateX | ||
| */ | ||
| constructor(address governor) InitializeGovernedUpgradeabilityProxy() { | ||
| _setGovernor(governor); | ||
| } | ||
| } |
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
23 changes: 23 additions & 0 deletions
23
contracts/contracts/proxies/create2/CrossChainStrategyProxy.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,23 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import { InitializeGovernedUpgradeabilityProxy2 } from "../InitializeGovernedUpgradeabilityProxy2.sol"; | ||
|
|
||
| // ******************************************************** | ||
| // ******************************************************** | ||
| // IMPORTANT: DO NOT CHANGE ANYTHING IN THIS FILE. | ||
| // Any changes to this file (even whitespaces) will | ||
| // affect the create2 address of the proxy | ||
| // ******************************************************** | ||
| // ******************************************************** | ||
|
|
||
| /** | ||
| * @notice CrossChainStrategyProxy delegates calls to a | ||
| * CrossChainMasterStrategy or CrossChainRemoteStrategy | ||
| * implementation contract. | ||
| */ | ||
| contract CrossChainStrategyProxy is InitializeGovernedUpgradeabilityProxy2 { | ||
| constructor(address governor) | ||
| InitializeGovernedUpgradeabilityProxy2(governor) | ||
| {} | ||
| } |
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
112 changes: 112 additions & 0 deletions
112
contracts/contracts/strategies/crosschain/AbstractCCTP4626Strategy.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,112 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| /** | ||
| * @title AbstractCCTP4626Strategy - Abstract contract for CCTP morpho strategy | ||
| * @author Origin Protocol Inc | ||
| */ | ||
|
|
||
| import { AbstractCCTPIntegrator } from "./AbstractCCTPIntegrator.sol"; | ||
|
|
||
| abstract contract AbstractCCTP4626Strategy is AbstractCCTPIntegrator { | ||
| uint32 public constant DEPOSIT_MESSAGE = 1; | ||
| uint32 public constant WITHDRAW_MESSAGE = 2; | ||
| uint32 public constant BALANCE_CHECK_MESSAGE = 3; | ||
|
|
||
| constructor(CCTPIntegrationConfig memory _config) | ||
| AbstractCCTPIntegrator(_config) | ||
| {} | ||
|
|
||
| function _encodeDepositMessage(uint64 nonce, uint256 depositAmount) | ||
| internal | ||
| virtual | ||
| returns (bytes memory) | ||
| { | ||
| return | ||
| abi.encodePacked( | ||
| ORIGIN_MESSAGE_VERSION, | ||
| DEPOSIT_MESSAGE, | ||
| abi.encode(nonce, depositAmount) | ||
| ); | ||
| } | ||
|
|
||
| function _decodeDepositMessage(bytes memory message) | ||
| internal | ||
| virtual | ||
| returns (uint64, uint256) | ||
| { | ||
| _verifyMessageVersionAndType( | ||
| message, | ||
| ORIGIN_MESSAGE_VERSION, | ||
| DEPOSIT_MESSAGE | ||
| ); | ||
|
|
||
| (uint64 nonce, uint256 depositAmount) = abi.decode( | ||
| _getMessagePayload(message), | ||
| (uint64, uint256) | ||
| ); | ||
| return (nonce, depositAmount); | ||
| } | ||
|
|
||
| function _encodeWithdrawMessage(uint64 nonce, uint256 withdrawAmount) | ||
| internal | ||
| virtual | ||
| returns (bytes memory) | ||
| { | ||
| return | ||
| abi.encodePacked( | ||
| ORIGIN_MESSAGE_VERSION, | ||
| WITHDRAW_MESSAGE, | ||
| abi.encode(nonce, withdrawAmount) | ||
| ); | ||
| } | ||
|
|
||
| function _decodeWithdrawMessage(bytes memory message) | ||
| internal | ||
| virtual | ||
| returns (uint64, uint256) | ||
| { | ||
| _verifyMessageVersionAndType( | ||
| message, | ||
| ORIGIN_MESSAGE_VERSION, | ||
| WITHDRAW_MESSAGE | ||
| ); | ||
|
|
||
| (uint64 nonce, uint256 withdrawAmount) = abi.decode( | ||
| _getMessagePayload(message), | ||
| (uint64, uint256) | ||
| ); | ||
| return (nonce, withdrawAmount); | ||
| } | ||
|
|
||
| function _encodeBalanceCheckMessage(uint64 nonce, uint256 balance) | ||
| internal | ||
| virtual | ||
| returns (bytes memory) | ||
| { | ||
| return | ||
| abi.encodePacked( | ||
| ORIGIN_MESSAGE_VERSION, | ||
| BALANCE_CHECK_MESSAGE, | ||
| abi.encode(nonce, balance) | ||
| ); | ||
| } | ||
|
|
||
| function _decodeBalanceCheckMessage(bytes memory message) | ||
| internal | ||
| virtual | ||
| returns (uint64, uint256) | ||
| { | ||
| _verifyMessageVersionAndType( | ||
| message, | ||
| ORIGIN_MESSAGE_VERSION, | ||
| BALANCE_CHECK_MESSAGE | ||
| ); | ||
|
|
||
| (uint64 nonce, uint256 balance) = abi.decode( | ||
| _getMessagePayload(message), | ||
| (uint64, uint256) | ||
| ); | ||
| return (nonce, balance); | ||
| } | ||
| } |
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.
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.
"- the Mainnet part" should probably be "- the L2 chain part"