-
Notifications
You must be signed in to change notification settings - Fork 69
chore: Update & deploy new WorldChain implementation #1014
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
Open
pxrl
wants to merge
2
commits into
master
Choose a base branch
from
pxrl/worldUSDC
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,98 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./interfaces/AdapterInterface.sol"; | ||
import "../external/interfaces/WETH9Interface.sol"; | ||
|
||
// @dev Use local modified CrossDomainEnabled contract instead of one exported by eth-optimism because we need | ||
// this contract's state variables to be `immutable` because of the delegateCall call. | ||
import "./CrossDomainEnabled.sol"; | ||
import "@eth-optimism/contracts/L1/messaging/IL1StandardBridge.sol"; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
import "../libraries/CircleCCTPAdapter.sol"; | ||
import "../external/interfaces/CCTPInterfaces.sol"; | ||
|
||
/** | ||
* @notice Contract containing logic to send messages from L1 to Doctor Who. This is a modified version of the Optimism adapter | ||
* that excludes the custom bridging logic. | ||
* @custom:security-contact [email protected] | ||
* @dev Public functions calling external contracts do not guard against reentrancy because they are expected to be | ||
* called via delegatecall, which will execute this contract's logic within the context of the originating contract. | ||
* For example, the HubPool will delegatecall these functions, therefore its only necessary that the HubPool's methods | ||
* that call this contract's logic guard against reentrancy. | ||
*/ | ||
|
||
// solhint-disable-next-line contract-name-camelcase | ||
contract WorldChain_Adapter is CrossDomainEnabled, AdapterInterface, CircleCCTPAdapter { | ||
using SafeERC20 for IERC20; | ||
uint32 public constant L2_GAS_LIMIT = 200_000; | ||
|
||
WETH9Interface public immutable L1_WETH; | ||
|
||
IL1StandardBridge public immutable L1_STANDARD_BRIDGE; | ||
|
||
/** | ||
* @notice Constructs new Adapter. | ||
* @param _l1Weth WETH address on L1. | ||
* @param _crossDomainMessenger XDomainMessenger Doctor Who system contract. | ||
* @param _l1StandardBridge Standard bridge contract. | ||
* @param _l1Usdc USDC address on L1. | ||
* @param _cctpTokenMessenger TokenMessenger contract to bridge via CCTP. | ||
*/ | ||
constructor( | ||
WETH9Interface _l1Weth, | ||
address _crossDomainMessenger, | ||
IL1StandardBridge _l1StandardBridge, | ||
IERC20 _l1Usdc, | ||
ITokenMessenger _cctpTokenMessenger | ||
) | ||
CrossDomainEnabled(_crossDomainMessenger) | ||
CircleCCTPAdapter(_l1Usdc, _cctpTokenMessenger, CircleDomainIds.WorldChain) | ||
{ | ||
L1_WETH = _l1Weth; | ||
L1_STANDARD_BRIDGE = _l1StandardBridge; | ||
} | ||
|
||
/** | ||
* @notice Send cross-chain message to target on Doctor Who. | ||
* @param target Contract on Doctor Who that will receive message. | ||
* @param message Data to send to target. | ||
*/ | ||
function relayMessage(address target, bytes calldata message) external payable override { | ||
sendCrossDomainMessage(target, L2_GAS_LIMIT, message); | ||
emit MessageRelayed(target, message); | ||
} | ||
|
||
/** | ||
* @notice Bridge tokens to Doctor Who. | ||
* @param l1Token L1 token to deposit. | ||
* @param l2Token L2 token to receive. | ||
* @param amount Amount of L1 tokens to deposit and L2 tokens to receive. | ||
* @param to Bridge recipient. | ||
*/ | ||
function relayTokens( | ||
address l1Token, | ||
address l2Token, | ||
uint256 amount, | ||
address to | ||
) external payable override { | ||
// If the l1Token is weth then unwrap it to ETH then send the ETH to the standard bridge. | ||
if (l1Token == address(L1_WETH)) { | ||
L1_WETH.withdraw(amount); | ||
L1_STANDARD_BRIDGE.depositETHTo{ value: amount }(to, L2_GAS_LIMIT, ""); | ||
} | ||
// Check if this token is USDC, which requires a custom bridge via CCTP. | ||
else if (_isCCTPEnabled() && l1Token == address(usdcToken)) { | ||
_transferUsdc(to, amount); | ||
} else { | ||
IL1StandardBridge _l1StandardBridge = L1_STANDARD_BRIDGE; | ||
|
||
IERC20(l1Token).safeIncreaseAllowance(address(_l1StandardBridge), amount); | ||
_l1StandardBridge.depositERC20To(l1Token, l2Token, to, amount, L2_GAS_LIMIT, ""); | ||
} | ||
emit TokensRelayed(l1Token, l2Token, amount, to); | ||
} | ||
} |
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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.
nb. I wasn't successful in verifying via this adapter due to the Etherscan v2 migration. I ended up having to deploy & verify with foundry instead, so this deployment script is mostly for documentation.