The following content will guide you through deploying and configuring all smart contracts to a new network (or to deploy a new staging environment).
If you only want to deploy a new diamond contract and use existing deployed facets, please skip to this section
If you want to deploy an immutable diamond, please skip to this section
- Prepare your .env file to have the following values set:
CREATE3_FACTORY_ADDRESS= 0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1 This needs to be deployed ahead of time on every chain you plan to deploy to. LI.FI has gone ahead and deployed a version of the CREATE3 factory on a handful of chains already. (can be verified here: https://github.com/lifinance/create3-factory/tree/main/deployments)
ETH_NODE_URI_<NETWORK>= (NETWORK being the network you deploy to e.g. MAINNET, POLYGON or BSC) (e.g. https://1rpc.io/eth)
<NETWORK>_ETHERSCAN_API_KEY=
if you deploy to another network, make sure you have both variables set for that specific network. E.g.: ETH_NODE_URI_GOERLI and GOERLI_ETHERSCAN_API_KEY for deployments to Goerli etc.
PRODUCTION=false (set to true if you want to deploy to production obviously, but confirm with @Edmund Zynda beforehand)
- Install required packages
https://github.com/foundry-rs/foundry
https://github.com/charmbracelet/gum
https://github.com/stedolan/jq
- Merge your branch with latest master to make sure you have all the latest addresses stored in your deployments folder
Scripts:
- /scripts/deploy.sh (for deploying any of our contracts)
- execute with command
./scripts/deploy.sh
in your console
- execute with command
- /scripts/diamond-update.sh (update / add to diamond)
- execute with command
./scripts/diamond-update.sh
in your console
- execute with command
- /scripts/update-periphery.sh (add new contract to periphery registry)
- execute with command
./scripts/update-periphery.sh
in your console
- execute with command
Deploy (in this order) using ./scripts/deploy.sh
:
- DiamondCutFacet
- DiamondLoupeFacet
- OwnershipFacet
- DexManagerFacet
- AccessManagerFacet
- WithdrawFacet
- PeripheryRegistryFacet
- LiFiDiamond
- Update the diamond contract using
./scripts/diamond-update.sh
:- select “UpdateCoreFacets”
- Run:
-
./scripts/sync-dexs.sh
-
./scripts/sync-sigs.sh
-
- For each facet that you want to deploy and add to the diamond, run first the deploy script (i.e.
./scripts/deploy.sh
) and, upon success, the update script (i.e../scripts/diamond-update.sh
) (you will be prompted to select a network and facet to deploy/update) - Available facets (* = ETH Mainnet only)
- Across
- Amarok
- ❗️needs to be initialized with chainId ↔ domainId mappings after deployment
- Arbitrum*
- CBridge
- GenericSwap
- Gnosis*
- Gravity
- Hop
- HopFacetOptimized
- ❗️maxApproval calls
- Hyphen
- Multichain
- Omni*
- Optimism*
- Polygon*
- Stargate
- For each periphery contract that you want to deploy and add to the diamond run the deploy script (i.e.
./scripts/deploy.sh
) (you will be prompted to select a network and facet to deploy/update) 1. ERC20 2. Executor 3. Receiver 4. FeeCollector 5. RelayerCBridge - After you deployed all periphery contracts, execute the update script (i.e.
./scripts/update-periphery.sh
) for each contract to be registered (you will be prompted to select a network and contract to register)
(find detailed instructions for each step above)
- deploy new diamond contract
- Update core facets as described here
- run
./scripts/sync-dexs.sh
- run
./scripts/sync-sigs.sh
- add bridge facets as needed (as described here)
- ❗️dont forget any required configuration calls
- Run this script
./scripts/deploy.sh
, select desired network and optionDeployLiFiDiamondImmutable
- Update core facets as described here
- Sync DEXs and Sigs as described here
- Deploy bridge facets (if needed) - in most cases we can use the existing deployments
- add bridge facets as needed (as described here)
- Run facet-specific configuration calls
- Amarok: add domainIds
- HopFacetOptimized: run maxApproval calls for tokens
- Deploy periphery contracts (if needed) - in most cases we can use the existing deployments
- Add periphery contracts to registry as described here
- Run script
./scripts/make-diamond-immutable.sh
- will transfer Ownership of diamond to address(0)
- will remove the diamondCut facet so that no further contract changes are possible
- Update docs
- Create an .md file for the immutable contract
- Deployed-to-addresses in docs (Gitbook)
When releasing a new version of the immutable diamond, some scripts and files need to be updated, namely:
- deploy.sh
- DeployLiFiDiamondImmutable.s.sol
- UpdateScriptBase.sol