-
Notifications
You must be signed in to change notification settings - Fork 75
feat(Linea): Add CCTP V2 support to Linea #910
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
Changes from all commits
3bd74f4
be61552
b5cdf31
833fa10
f5cb584
fb10db9
b6f0929
ba40d92
1b5960f
33955f3
d439eaf
0d436fd
f683c90
9f7e40c
17b6ccf
51dde94
b6ff742
90650df
13b4953
e12ea2c
c518515
46824c4
71b6b2a
f8729d3
9f1064b
f908e38
039870d
08ee557
7e40e02
b2e634c
30e2754
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ library CircleDomainIds { | |
| uint32 public constant Base = 6; | ||
| uint32 public constant Polygon = 7; | ||
| uint32 public constant DoctorWho = 10; | ||
| uint32 public constant Linea = 11; // TODO replace with actual domain once Circle publishes it. | ||
| // Use this value for placeholder purposes only for adapters that extend this adapter but haven't yet been | ||
| // assigned a domain ID by Circle. | ||
| uint32 public constant UNINITIALIZED = type(uint32).max; | ||
|
|
@@ -50,6 +51,13 @@ abstract contract CircleCCTPAdapter { | |
| /// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
| ITokenMessenger public immutable cctpTokenMessenger; | ||
nicholaspai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @notice Indicates if the CCTP V2 TokenMessenger is being used. | ||
| * @dev This is determined by checking if the feeRecipient() function exists and returns a non-zero address. | ||
| */ | ||
| /// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
| bool public immutable cctpV2; | ||
|
|
||
| /** | ||
| * @notice intiailizes the CircleCCTPAdapter contract. | ||
| * @param _usdcToken USDC address on the current chain. | ||
|
|
@@ -59,12 +67,23 @@ abstract contract CircleCCTPAdapter { | |
| /// @custom:oz-upgrades-unsafe-allow constructor | ||
| constructor( | ||
| IERC20 _usdcToken, | ||
| /// @dev This should ideally be an address but its kept as an ITokenMessenger to avoid rippling changes to the | ||
| /// constructors for every SpokePool/Adapter. | ||
| ITokenMessenger _cctpTokenMessenger, | ||
| uint32 _recipientCircleDomainId | ||
| ) { | ||
| usdcToken = _usdcToken; | ||
| cctpTokenMessenger = _cctpTokenMessenger; | ||
| recipientCircleDomainId = _recipientCircleDomainId; | ||
|
|
||
| // Only the CCTP V2 TokenMessenger has a feeRecipient() function, so we use it to | ||
| // figure out if we are using CCTP V2 or V1. `success` can be true even if the contract doesn't | ||
| // implement feeRecipient but it has a fallback function so to be extra safe, we check the return value | ||
| // of feeRecipient() as well. | ||
| (bool success, bytes memory feeRecipient) = address(cctpTokenMessenger).staticcall( | ||
| abi.encodeWithSignature("feeRecipient()") | ||
|
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. This is something I want to highlight to OZ. We are doing this to avoid adding an extra constructor argument and, thus, create a larger diff for all the contracts that inherit from this CCTP contract. However, the downside is that this could be broken in the future if circle removes this function. |
||
| ); | ||
| cctpV2 = (success && address(bytes20(feeRecipient)) != address(0)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -101,7 +120,25 @@ abstract contract CircleCCTPAdapter { | |
| uint256 remainingAmount = amount; | ||
| while (remainingAmount > 0) { | ||
| uint256 partAmount = remainingAmount > burnLimit ? burnLimit : remainingAmount; | ||
| cctpTokenMessenger.depositForBurn(partAmount, recipientCircleDomainId, to, address(usdcToken)); | ||
| if (cctpV2) { | ||
|
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. This if branch adds some bytecode |
||
| // Uses the CCTP V2 "standard transfer" speed and | ||
| // therefore pays no additional fee for the transfer to be sped up. | ||
| ITokenMessengerV2(address(cctpTokenMessenger)).depositForBurn( | ||
| partAmount, | ||
| recipientCircleDomainId, | ||
| to, | ||
| address(usdcToken), | ||
| // The following parameters are new in this function from V2 to V1, can read more here: | ||
| // https://developers.circle.com/stablecoins/evm-smart-contracts | ||
| bytes32(0), // destinationCaller is set to bytes32(0) to indicate that anyone can call | ||
| // receiveMessage on the destination to finalize the transfer | ||
| 0, // maxFee can be set to 0 for a "standard transfer" | ||
| 2000 // minFinalityThreshold can be set to 20000 for a "standard transfer", | ||
| // https://github.com/circlefin/evm-cctp-contracts/blob/63ab1f0ac06ce0793c0bbfbb8d09816bc211386d/src/v2/FinalityThresholds.sol#L21 | ||
| ); | ||
| } else { | ||
| cctpTokenMessenger.depositForBurn(partAmount, recipientCircleDomainId, to, address(usdcToken)); | ||
| } | ||
| remainingAmount -= partAmount; | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.