Skip to content

Commit

Permalink
SIP-311 Teleporters (#1694)
Browse files Browse the repository at this point in the history
* start on cross chain pools with cl functions

* initial efforts

edge cases identified and will be irioned out tomorrow. but this is most
of the structure!

* closer pre single chain tests

* write out planned tests, rework a bit of the cross chain details

starting to look just a bit ugly, hopefully getting pretty close to the
end of the edge cases. we see!

* add missing file

* tests back to normal

* add important debt check test

* add some tests before I leave for vacation

* minor fixes

* more minor fixes

* Run yarn lint:sol:fix

* Run yarn lint:js:fix

* Use CrossChain storage lib for cross chain usd transfers

* fixes for utils module, allow xchain pools to have its own versioning

* v3.2.0-xchain.0

* fix error

* Implement burn from sender (#1622)

* add burn from sender

* call burn with target as caller

* Add access check

* add tests

* fix lint

* fix lint

* fixes

* first successful ccip send of createCrossChainPool

next step: pool sync

final step: pool config

* fixes to load contract from misc source

* Add transfer cross chain USD tests (#1634)

* add transferCrossChain tests

* refund leftover gas and test cleanup

* create CrossChainUSDModule

* fix lint

* update transferCrossChain (#1650)

* fix sol lint and revert deps change

* fixes

* run yarn

* Use EVMTokenAmount amount

* decouple from xchain-pools branch

* revert unnecessary changes

* remove more unnecessary files

* Update storage dump

* fix lint

* fix deps

* fix lint: use safe cast in utils module

* implement feedback

* update comment

* revert version changes

---------

Co-authored-by: Daniel Beal <[email protected]>
Co-authored-by: Daniel Beal <[email protected]>
  • Loading branch information
3 people authored Jul 7, 2023
1 parent 00fbcda commit 202cf92
Show file tree
Hide file tree
Showing 305 changed files with 1,780 additions and 932 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/glob-npm-8.1.0-65f64af8b1-92fbea3221.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/nopt-npm-7.1.0-8189bf0f5a-77185170d4.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/qs-npm-6.11.1-1dedced93e-82ee78ef12.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/uuid-npm-7.0.3-2b088bd924-f5b7b5cc28.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"version": {
"allowBranch": [
"main",
"lerna"
"lerna",
"teleporters"
]
}
}
Expand Down
7 changes: 7 additions & 0 deletions markets/perps-market/cannonfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ defaultValue = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
[setting.synthetixPackage]
defaultValue = "synthetix:<%= package.version %>"

[setting.synthetixPreset]
defaultValue = "main"

[setting.spotMarketPackage]
defaultValue = "synthetix-spot-market:<%= package.version %>"

[setting.salt]
defaultValue = 'snax'

[import.synthetix]
source = "<%= settings.synthetixPackage %>"
preset = "<%= settings.synthetixPreset %>"

[import.spotMarket]
source = "<%= settings.spotMarketPackage %>"
Expand Down
7 changes: 7 additions & 0 deletions markets/spot-market/cannonfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ defaultValue = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
[setting.synthetixPackage]
defaultValue = "synthetix:<%= package.version %>"

[setting.synthetixPreset]
defaultValue = "main"

[setting.salt]
defaultValue = 'snax'

[import.synthetix]
source = "<%= settings.synthetixPackage %>"
preset = "<%= settings.synthetixPreset %>"

[contract.SpotMarketFactoryModule]
artifact = "SpotMarketFactoryModule"
Expand Down
9 changes: 9 additions & 0 deletions protocol/synthetix/cannonfile.test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ 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 @@ -66,8 +69,10 @@ contracts = [
"AccountModule",
"AssociateDebtModule",
"AssociatedSystemsModule",
"CcipReceiverModule",
"CollateralModule",
"CollateralConfigurationModule",
"CrossChainUSDModule",
"IssueUSDModule",
"LiquidationModule",
"MarketCollateralModule",
Expand All @@ -83,6 +88,7 @@ contracts = [
"TestableCollateralStorage",
"TestableCollateralConfigurationStorage",
"TestableCollateralLockStorage",
"TestableCrossChainStorage",
"TestableDistributionStorage",
"TestableDistributionActorStorage",
"TestableMarketStorage",
Expand All @@ -102,8 +108,10 @@ depends = [
"contract.AccountModule",
"contract.AssociateDebtModule",
"contract.AssociatedSystemsModule",
"contract.CcipReceiverModule",
"contract.CollateralModule",
"contract.CollateralConfigurationModule",
"contract.CrossChainUSDModule",
"contract.IssueUSDModule",
"contract.LiquidationModule",
"contract.MarketCollateralModule",
Expand All @@ -119,6 +127,7 @@ depends = [
"contract.TestableCollateralStorage",
"contract.TestableCollateralConfigurationStorage",
"contract.TestableCollateralLockStorage",
"contract.TestableCrossChainStorage",
"contract.TestableDistributionStorage",
"contract.TestableDistributionActorStorage",
"contract.TestableMarketStorage",
Expand Down
42 changes: 41 additions & 1 deletion protocol/synthetix/cannonfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ artifact = "contracts/modules/core/AssociateDebtModule.sol:AssociateDebtModule"
[contract.AssociatedSystemsModule]
artifact = "contracts/modules/associated-systems/AssociatedSystemsModule.sol:AssociatedSystemsModule"

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

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

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

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

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

Expand Down Expand Up @@ -90,8 +96,10 @@ contracts = [
"AccountModule",
"AssociateDebtModule",
"AssociatedSystemsModule",
"CcipReceiverModule",
"CollateralModule",
"CollateralConfigurationModule",
"CrossChainUSDModule",
"IssueUSDModule",
"LiquidationModule",
"MarketCollateralModule",
Expand All @@ -110,8 +118,10 @@ depends = [
"contract.AccountModule",
"contract.AssociateDebtModule",
"contract.AssociatedSystemsModule",
"contract.CcipReceiverModule",
"contract.CollateralModule",
"contract.CollateralConfigurationModule",
"contract.CrossChainUSDModule",
"contract.IssueUSDModule",
"contract.LiquidationModule",
"contract.MarketCollateralModule",
Expand Down Expand Up @@ -164,7 +174,7 @@ depends = [
contracts = [
"InitialModuleBundle",
"AssociatedSystemsModule",
"USDTokenModule",
"USDTokenModule"
]
depends = [
"contract.InitialModuleBundle",
Expand Down Expand Up @@ -243,3 +253,33 @@ args = [[
]]

depends = ["invoke.upgrade_core_proxy"]


[invoke.register_const_one_oracle]
target = ["oracle_manager.Proxy"]
func = "registerNode"
args = [
# 8 = "constant" oracle
8,
"<%= defaultAbiCoder.encode(['uint256'], [parseEther('1')]) %>",
[]
]

extra.const_one_oracle_id.event = "NodeRegistered"
extra.const_one_oracle_id.arg = 0

depends = [
"provision.oracle_manager"
]

# we register USD as a collateral type because it is useful to treat it the same way as any other collateral
[invoke.configure_usd_collateral]
target = ["CoreProxy"]
fromCall.func = "owner"
func = "configureCollateral"

args = [
{ tokenAddress = "<%= contracts.USDProxy.address %>", oracleNodeId = "<%= extras.const_one_oracle_id %>", issuanceRatioD18 = "<%= parseEther('10') %>", liquidationRatioD18 = "<%= parseEther('10') %>", liquidationRewardD18 = "0", minDelegationD18 = "<%= MaxUint256 %>", depositingEnabled = true }
]

depends = ["invoke.register_const_one_oracle", "invoke.init_usd"]
24 changes: 24 additions & 0 deletions protocol/synthetix/contracts/interfaces/ICrossChainUSDModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.11 <0.9.0;

/**
* @title Module for the cross-chain transfers of stablecoins.
*/
interface ICrossChainUSDModule {
event TransferCrossChainInitiated(
uint64 indexed destChainId,
uint256 indexed amount,
address sender
);

/**
* @notice Allows users to transfer tokens cross-chain using CCIP.
* @param destChainId The id of the chain where tokens are to be transferred to.
* @param amount The amount of tokens to be transferred, denominated with 18 decimals of precision.
* @return gasTokenUsed The amount of fees paid in the cross-chain transfer, denominated with 18 decimals of precision.
*/
function transferCrossChain(
uint64 destChainId,
uint256 amount
) external payable returns (uint256 gasTokenUsed);
}
13 changes: 3 additions & 10 deletions protocol/synthetix/contracts/interfaces/IUSDTokenModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@ interface IUSDTokenModule is ITokenModule {
function burnWithAllowance(address from, address spender, uint256 amount) external;

/**
* @notice Allows users to transfer tokens cross-chain using CCIP. This is disabled until _CCIP_CHAINLINK_SEND is set in UtilsModule. This is currently included for testing purposes. Functionality will change, including fee collection, as CCIP continues development.
* @param destChainId The id of the chain where tokens are to be transferred to.
* @param to The destination address in the target chain.
* @param amount The amount of tokens to be transferred, denominated with 18 decimals of precision.
* @return feesPaidD18 The amount of fees paid in the cross-chain transfer, denominated with 18 decimals of precision.
* @notice Destroys `amount` of snxUSD tokens from the caller. This is derived from ERC20Burnable.sol and is currently included for testing purposes with CCIP token pools.
* @param amount The amount of snxUSD to be burned, denominated with 18 decimals of precision.
*/
function transferCrossChain(
uint256 destChainId,
address to,
uint256 amount
) external returns (uint256 feesPaidD18);
function burn(uint256 amount) external;
}
27 changes: 23 additions & 4 deletions protocol/synthetix/contracts/interfaces/IUtilsModule.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.11 <0.9.0;

import {IERC165} from "@synthetixio/core-contracts/contracts/interfaces/IERC165.sol";

/**
* @title Module with assorted utility functions.
*/
interface IUtilsModule {
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 ccipSend The address on this chain to which CCIP messages will be sent.
* @param ccipReceive The address on this chain from which CCIP messages will be received.
* @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 registerCcip(address ccipSend, address ccipReceive, address ccipTokenPool) external;
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "../../utils/CcipClient.sol";

/// @notice Application contracts that intend to receive messages from
/// the router should implement this interface.
interface IAny2EVMMessageReceiver {
/// @notice Router calls this to deliver a message.
/// If this reverts, any token transfers also revert. The message
/// will move to a FAILED state and become available for manual execution
/// as a retry. Fees already paid are NOT currently refunded (may change).
/// @param message CCIP Message
/// @dev Note ensure you check the msg.sender is the router
function ccipReceive(CcipClient.Any2EVMMessage calldata message) external;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "../../utils/CcipClient.sol";

interface ICcipRouterClient {
error UnsupportedDestinationChain(uint64 destinationChainId);
/// @dev Sender is not whitelisted
error SenderNotAllowed(address sender);
error InsufficientFeeTokenAmount();
/// @dev Sent msg.value with a non-empty feeToken
error InvalidMsgValue();

/// @notice Checks if the given chain ID is supported for sending/receiving.
/// @param chainId The chain to check
/// @return supported is true if it is supported, false if not
function isChainSupported(uint64 chainId) external view returns (bool supported);

/// @notice Gets a list of all supported tokens which can be sent or received
/// to/from a given chain id.
/// @param chainId The chainId.
/// @return tokens The addresses of all tokens that are supported.
function getSupportedTokens(uint64 chainId) external view returns (address[] memory tokens);

/// @param destinationChainId The destination chain ID
/// @param message The cross-chain CCIP message including data and/or tokens
/// @return fee returns execution fee for the specified message
/// delivery to destination chain
/// @dev returns 0 fee on invalid message.
function getFee(
uint64 destinationChainId,
CcipClient.EVM2AnyMessage memory message
) external view returns (uint256 fee);

/// @notice Request a message to be sent to the destination chain
/// @param destinationChainId The destination chain ID
/// @param message The cross-chain CCIP message including data and/or tokens
/// @return messageId The message ID
/// @dev Note if msg.value is larger than the required fee (from getFee) we accept
/// the overpayment with no refund.
function ccipSend(
uint64 destinationChainId,
CcipClient.EVM2AnyMessage calldata message
) external payable returns (bytes32 messageId);
}

This file was deleted.

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

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

contract CcipRouterMock {
function ccipSend(
uint64 destinationChainId,
CcipClient.EVM2AnyMessage calldata message
) external payable virtual returns (bytes32 messageId) {}

function getFee(
uint64 destinationChainId,
CcipClient.EVM2AnyMessage memory message
) external view virtual returns (uint256 fee) {}
}
Loading

0 comments on commit 202cf92

Please sign in to comment.