Deployment
This page documents the steps for actually deploying the multicollateral upgrade to production.
⚠️ Warning
Make sure you really understand the deployment process before applying it to production, especially for the contracts part.
💡 Tips
The patch for Linear-finance/linear-dev-cli demonstrates how each of the additional collateral token is handled. It could be a useful source of reference.
💡 Tips
It might be helpful to practice/test by deploying a development environment with a version or Linear-finance/linear-dev prior to the upgrade, and then upgrading it.
Assumed collateral configuration
| Name | Symbol | Decimals |
|---|---|---|
| Linear Token | LINA | 18 |
| Wrapped BNB | WBNB | 18 |
| BTCB Token | BTCB | 18 |
| Ethereum Token | ETH | 18 |
ℹ️ Note
Code changes to services and web apps are required if you plan to deploy different collateral tokens.
Deploying contract changes
ℹ️ Note
This section only documents the deployment steps. See the contract changes page for details.
Deploying new SafeDecimalMath instance
Due to changes in SafeDecimalMath, a new instance of the library needs to be deployed. Once deployed, the address of this new instance should be used in any subsequent step where any contract using the libarary is upgraded/deployed.
Deploying the DebtDistribution contracts
Apart from turning some contracts from singleton deployments into being collateral-specific, the upgrade also adds a new contract DebtDistribution. This contract needs to be deployed first, as the collatera-specific contracts rely on it to function.
Once deployed, take note of its address as it will be needed for the subsequent steps.
Deciding on Collateral ID
For each collateral token (including LINA), you must decide on a Collateral ID to use. This Collateral ID could be different from the token symbol itself, but it's recommended to simply use the symbol. The Collateral ID will be needed when activating the tokens.
An example of deriving the Collateral ID from the string value "LINA" using ethers.js's formatBytes32String function:
const collateralId = formatBytes32String("LINA");
Upgrading LINA contracts
This step involves upgrading existing collateral-specific contracts for LINA to make them multi-collateral-aware.
Specifically, the following contracts need to be upgraded:
LnBuildBurnSystemLnCollateralSystemLnDebtSystemLnLiquidation
Once upgraded, activate LINA as collateral by sending these two transactions:
- Calling
addCollateral()onDebtDistributionwithLINA'sLnDebtSystemaddress and its Collateral ID to register the token. - Calling
setDebtDistribution()onLINA'sLnDebtSystemcontract withDebtDistribution's address to link the two contracts.
ℹ️ Note
With the multi-collateral system, each token must be activated to become usable as collateral. This includes
LINA. So it's important for the activation step to be performed in a timely manner to limit downtime.
ℹ️ Note
Once this step is done, the system would have techinically already enabled multi-collateral support. It's just that
LINAis the only activated collateral token.It's therefore a good opportunity to pause here and test that everything still works as expected before proceeding.
Deploying new collateral contracts
ℹ️ Note
Some contract constructor fields require addresses of contracts that are not yet deployed. While it's technically possible to pre-compute those addresses before deployment, it might be easier to simply feed the constructor with mock addresses first (e.g.
0x0000000000000000000000000000000000000001) and configure them later via setters once all other contracts are deployed.
For each collateral token:
- Deploy
LnDebtSystem. - Deploy
LnBuildBurnSystem, leaving the_collaterSysand_liquidationarguments as mocked addresses. - Deploy
LnCollateralSystem, leaving the_mRewardLockerand_liquidationarguments as mocked addresses. - Deploy
LnLiquidation, leaving the_lnRewardLockerargument as mocked address.
⚠️ Warning
The address for
LnRewardLockeris deliberately left out (and not filled back in later) forLnCollateralSystemandLnLiquidation, as only the native collateral token (i.e.LINA) can be locked as rewards. Incorrectly feedingLINA'sLnRewardLockeraddress to these contracts will result in system misbehaviors.
-
Deploy
LnRewardSystem, usingLINA'sLnRewardLocker's address for the_rewardLockerAddressargument. -
Configure the collateral token by setting the following values on
LnConfig:COLLATERALID_BuildRatioCOLLATERALID_LiqRatioCOLLATERALID_LiqMarkerRewardCOLLATERALID_LiqLiquidatorRewardCOLLATERALID_LiqDelay
where
COLLATERALIDmust be replaced with the actual Collateral ID chosen. For example, if the chosen Collateral ID isBTCB, then the first key would beBTCB_BuildRatio. -
Assign the following roles on
LnAccessControl:ISSUE_ASSETforLnBuildBurnSystemBURN_ASSETforLnBuildBurnSystemLnDebtSystemforLnBuildBurnSystemLOCK_REWARDforLnRewardSystem
-
Fill some of the addresses left out during deployment:
- Call
setCollateralSystemAddress()onLnBuildBurnSystem - Call
setLiquidationAddress()onLnBuildBurnSystem - Call
setLiquidationAddress()onLnCollateralSystem
- Call
-
Call
updateTokenInfo()onLnCollateralSystemwith the token's Collateral ID and address. -
Set up
LnOracleRouterto handle price queries for the Collateral ID, if the Collateral ID doesn't already map to a valid oracle setting.
Activating new collateral tokens
⚠️ Warning
Once this step is done, users can already start using the new collateral tokens (even if the web apps haven't been updated). Old subgraphs are not aware of the upgrade and would serve inaccurate data if anyone actually uses the new tokens.
To avoid this, consider deploying and synchronizing the new subgraphs first before proceeding with this step. This is especially true considering that some subgraphs take a long time to synchronize.
For each collateral token, follow the same steps taken to activate LINA:
- Calling
addCollateral()onDebtDistributionwith the collateral token'sLnDebtSystemaddress and its Collateral ID to register the token. - Calling
setDebtDistribution()on the collateral token'sLnDebtSystemcontract withDebtDistribution's address to link the two contracts.
Upgrading subgraphs
See this subgraphs section for the list of changed subgraphs.
To deploy new subgraphs, first make changes to Linear-finance/graph-registry to bump subgraph versions and update environment variables.
Then, deploy the updated subgraphs and wait for the synchronization to finish. After that, update Linear-finance/graph-proxy-config to start routing traffic to the new subgraphs.
💡 Tips
See the patch in Linear-finance/linear-dev for subgraph deployment changes.
Upgrading services
See the workers section and Docker services section for the list of changed services.
💡 Tips
See the patch in Linear-finance/linear-dev for service deployment changes.
Upgrading web apps
The final step is upgrading the web apps to enable end users to interact with the new collateral tokens. See this page for a list of changed web apps.