Skip to content
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

Add CCIP from core-modules to protocol/synthetix #1985

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions protocol/synthetix/cannonfile.test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ artifact = "contracts/generated/test/TestableCollateralConfigurationStorage.sol:
[contract.TestableCollateralLockStorage]
artifact = "contracts/generated/test/TestableCollateralLockStorage.sol:TestableCollateralLockStorage"

[contract.TestableCrossChainStorage]
artifact = "contracts/generated/test/TestableCrossChainStorage.sol:TestableCrossChainStorage"

[contract.TestableDistributionStorage]
artifact = "contracts/generated/test/TestableDistributionStorage.sol:TestableDistributionStorage"

Expand Down Expand Up @@ -72,6 +69,7 @@ contracts = [
"CcipReceiverModule",
"CollateralModule",
"CollateralConfigurationModule",
"CrossChainModule",
"CrossChainUSDModule",
"IssueUSDModule",
"LiquidationModule",
Expand All @@ -87,7 +85,6 @@ contracts = [
"TestableCollateralStorage",
"TestableCollateralConfigurationStorage",
"TestableCollateralLockStorage",
"TestableCrossChainStorage",
"TestableDistributionStorage",
"TestableDistributionActorStorage",
"TestableMarketStorage",
Expand Down
4 changes: 4 additions & 0 deletions protocol/synthetix/cannonfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ artifact = "contracts/modules/core/CollateralModule.sol:CollateralModule"
[contract.CollateralConfigurationModule]
artifact = "contracts/modules/core/CollateralConfigurationModule.sol:CollateralConfigurationModule"

[contract.CrossChainModule]
artifact = "contracts/modules/core/CrossChainModule.sol:CrossChainModule"

[contract.CrossChainUSDModule]
artifact = "contracts/modules/core/CrossChainUSDModule.sol:CrossChainUSDModule"

Expand Down Expand Up @@ -96,6 +99,7 @@ contracts = [
"CcipReceiverModule",
"CollateralModule",
"CollateralConfigurationModule",
"CrossChainModule",
"CrossChainUSDModule",
"IssueUSDModule",
"LiquidationModule",
Expand Down
32 changes: 7 additions & 25 deletions protocol/synthetix/contracts/interfaces/IUtilsModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@ import {IERC165} from "@synthetixio/core-contracts/contracts/interfaces/IERC165.
* @title Module with assorted utility functions.
*/
interface IUtilsModule is IERC165 {
/**
* @notice Emitted when a new cross chain network becomes supported by the protocol
*/
event NewSupportedCrossChainNetwork(uint64 newChainId);

/**
* @notice Configure CCIP addresses on the stablecoin.
* @param ccipRouter The address on this chain to which CCIP messages will be sent or received.
* @param ccipTokenPool The address where CCIP fees will be sent to when sending and receiving cross chain messages.
*/
function configureChainlinkCrossChain(address ccipRouter, address ccipTokenPool) external;

/**
* @notice Used to add new cross chain networks to the protocol
* Ignores a network if it matches the current chain id
* Ignores a network if it has already been added
* @param supportedNetworks array of all networks that are supported by the protocol
* @param ccipSelectors the ccip "selector" which maps to the chain id on the same index. must be same length as `supportedNetworks`
* @return numRegistered the number of networks that were actually registered
*/
function setSupportedCrossChainNetworks(
uint64[] memory supportedNetworks,
uint64[] memory ccipSelectors
) external returns (uint256 numRegistered);

/**
* @notice Configure the system's single oracle manager address.
* @param oracleManagerAddress The address of the oracle manager.
Expand Down Expand Up @@ -66,6 +41,13 @@ interface IUtilsModule is IERC165 {
*/
function getConfigAddress(bytes32 k) external view returns (address v);

/**
* @notice Configure CCIP addresses on the stablecoin.
* @param ccipRouter The address on this chain to which CCIP messages will be sent or received.
* @param ccipTokenPool The address where CCIP fees will be sent to when sending and receiving cross chain messages.
*/
function configureUsdTokenChainlink(address ccipRouter, address ccipTokenPool) external;

/**
* @notice Checks if the address is the trusted forwarder
* @param forwarder The address to check
Expand Down

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions protocol/synthetix/contracts/mocks/CcipRouterMock.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

import "../interfaces/external/ICcipRouterClient.sol";
import "@synthetixio/core-modules/contracts/interfaces/external/ICcipRouterClient.sol";

contract CcipRouterMock {
// solhint-disable no-empty-blocks
Expand Down
20 changes: 5 additions & 15 deletions protocol/synthetix/contracts/modules/core/CcipReceiverModule.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.11 <0.9.0;

import "@synthetixio/core-modules/contracts/interfaces/IAssociatedSystemsModule.sol";
import "@synthetixio/core-modules/contracts/storage/AssociatedSystem.sol";
import "@synthetixio/core-contracts/contracts/ownership/OwnableStorage.sol";

import "../../interfaces/external/IAny2EVMMessageReceiver.sol";

import "../../storage/OracleManager.sol";
import "../../storage/Config.sol";
import "../../storage/CrossChain.sol";
import {CcipReceiverModule as BaseCcipReceiverModule} from "@synthetixio/core-modules/contracts/modules/CcipReceiverModule.sol";

/**
* @title Module with assorted utility functions.
* @dev See IUtilsModule.
* @title Module that handles receiving ccip messages.
*/
contract CcipReceiverModule is IAny2EVMMessageReceiver {
function ccipReceive(CcipClient.Any2EVMMessage memory message) external {
CrossChain.processCcipReceive(CrossChain.load(), message);
}
// solhint-disable-next-line no-empty-blocks
contract CcipReceiverModule is BaseCcipReceiverModule {

}
12 changes: 12 additions & 0 deletions protocol/synthetix/contracts/modules/core/CrossChainModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.11 <0.9.0;

import {CrossChainModule as BaseCrossChainModule} from "@synthetixio/core-modules/contracts/modules/CrossChainModule.sol";

/**
* @title Module that handles anything related to cross-chain.
*/
// solhint-disable-next-line no-empty-blocks
contract CrossChainModule is BaseCrossChainModule {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import "../../interfaces/ICrossChainUSDModule.sol";
import "@synthetixio/core-modules/contracts/interfaces/ITokenModule.sol";
import "@synthetixio/core-contracts/contracts/utils/ERC2771Context.sol";

import "../../storage/CrossChain.sol";

import "@synthetixio/core-modules/contracts/storage/AssociatedSystem.sol";
import "@synthetixio/core-modules/contracts/storage/FeatureFlag.sol";
import "@synthetixio/core-modules/contracts/storage/CrossChain.sol";

/**
* @title Module for the cross-chain transfers of stablecoins.
Expand Down
80 changes: 16 additions & 64 deletions protocol/synthetix/contracts/modules/core/UtilsModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,25 @@ pragma solidity >=0.8.11 <0.9.0;
import "@synthetixio/core-modules/contracts/interfaces/IAssociatedSystemsModule.sol";
import "@synthetixio/core-modules/contracts/storage/AssociatedSystem.sol";
import "@synthetixio/core-contracts/contracts/ownership/OwnableStorage.sol";
import "@synthetixio/core-contracts/contracts/errors/ParameterError.sol";
import "@synthetixio/core-contracts/contracts/utils/SafeCast.sol";
import "@synthetixio/core-contracts/contracts/utils/ERC2771Context.sol";

import "../../interfaces/IUtilsModule.sol";

import "../../storage/CrossChain.sol";
import "../../storage/OracleManager.sol";
import "../../storage/Config.sol";

import "../../interfaces/external/IAny2EVMMessageReceiver.sol";

/**
* @title Module with assorted utility functions.
* @dev See IUtilsModule.
*/
contract UtilsModule is IUtilsModule {
using AssociatedSystem for AssociatedSystem.Data;
using SetUtil for SetUtil.UintSet;
using SafeCastU256 for uint256;

bytes32 private constant _USD_TOKEN = "USDToken";
bytes32 private constant _CCIP_CHAINLINK_SEND = "ccipChainlinkSend";
bytes32 private constant _CCIP_CHAINLINK_RECV = "ccipChainlinkRecv";
bytes32 private constant _CCIP_CHAINLINK_TOKEN_POOL = "ccipChainlinkTokenPool";

/**
* @inheritdoc IUtilsModule
*/
function configureChainlinkCrossChain(
address ccipRouter,
address ccipTokenPool
) external override {
OwnableStorage.onlyOwner();

CrossChain.Data storage cc = CrossChain.load();

cc.ccipRouter = ICcipRouterClient(ccipRouter);

IAssociatedSystemsModule usdToken = IAssociatedSystemsModule(
AssociatedSystem.load(_USD_TOKEN).proxy
);

usdToken.registerUnmanagedSystem(_CCIP_CHAINLINK_SEND, ccipRouter);
usdToken.registerUnmanagedSystem(_CCIP_CHAINLINK_RECV, ccipRouter);
usdToken.registerUnmanagedSystem(_CCIP_CHAINLINK_TOKEN_POOL, ccipTokenPool);
}

/**
* @inheritdoc IUtilsModule
*/
function setSupportedCrossChainNetworks(
uint64[] memory supportedNetworks,
uint64[] memory ccipSelectors
) external returns (uint256 numRegistered) {
OwnableStorage.onlyOwner();

uint64 myChainId = block.chainid.to64();

if (ccipSelectors.length != supportedNetworks.length) {
revert ParameterError.InvalidParameter("ccipSelectors", "must match length");
}

CrossChain.Data storage cc = CrossChain.load();
for (uint i = 0; i < supportedNetworks.length; i++) {
if (supportedNetworks[i] == myChainId) continue;
if (
supportedNetworks[i] != myChainId &&
!cc.supportedNetworks.contains(supportedNetworks[i])
) {
numRegistered++;
cc.supportedNetworks.add(supportedNetworks[i]);
emit NewSupportedCrossChainNetwork(supportedNetworks[i]);
}

cc.ccipChainIdToSelector[supportedNetworks[i]] = ccipSelectors[i];
cc.ccipSelectorToChainId[ccipSelectors[i]] = supportedNetworks[i];
}
}

/**
* @inheritdoc IUtilsModule
*/
Expand Down Expand Up @@ -128,8 +67,21 @@ contract UtilsModule is IUtilsModule {
function supportsInterface(
bytes4 interfaceId
) public view virtual override(IERC165) returns (bool) {
return
interfaceId == type(IAny2EVMMessageReceiver).interfaceId ||
interfaceId == this.supportsInterface.selector;
return interfaceId == this.supportsInterface.selector;
}

function configureUsdTokenChainlink(
address ccipRouter,
address ccipTokenPool
) external override {
OwnableStorage.onlyOwner();

IAssociatedSystemsModule usdToken = IAssociatedSystemsModule(
AssociatedSystem.load(_USD_TOKEN).getAddress()
);

usdToken.registerUnmanagedSystem(_CCIP_CHAINLINK_SEND, ccipRouter);
usdToken.registerUnmanagedSystem(_CCIP_CHAINLINK_RECV, ccipRouter);
usdToken.registerUnmanagedSystem(_CCIP_CHAINLINK_TOKEN_POOL, ccipTokenPool);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity ^0.8.7;

import "../../interfaces/IUSDTokenModule.sol";
import "../../storage/CrossChain.sol";

import "@synthetixio/core-contracts/contracts/utils/ERC2771Context.sol";
import "@synthetixio/core-modules/contracts/storage/AssociatedSystem.sol";
import "@synthetixio/core-modules/contracts/storage/CrossChain.sol";
import "@synthetixio/core-contracts/contracts/token/ERC20.sol";
import "@synthetixio/core-modules/contracts/storage/FeatureFlag.sol";
import "@synthetixio/core-contracts/contracts/initializable/InitializableMixin.sol";
Expand Down
Loading