# How to fork Liquity V2 for Saga (safely)
## Steps
1. Get the license from the Liquity team.
2. Decide on collaterals and deploy high quality oracles with tellor or.
3. Write new oracle relayers, price feeds, and collateral branch contracts.
4. Make other security updates specific to that collateral, chain, and other features you want.
5. Write a new deployment script.
6. Fix up the front end to match all the branding from designs consistently with strong attention to detail
7. Deploy subgraphs, liquidation bots, peg maintence bots, zappers if possible, liquidity pools, and other side infrastructure to keep things running smoothly.
8. Test
9. Audit
10. Test again
11. Verify
12. Ship
Read the full readme on the Bold repo, and also write your own guide to how it works like [this one](https://hackmd.io/XsKiM79ESk-SxUsnDjkDPA) for your own reference. You should know immediately which contracts are deployed once and which are deployed for each collateral branch, and what all of the core contracts do in the system.
## Security tips and tricks:
1. If you are adding any new collateral types that increase the risk beyound accepting just ETH, wstETH, and rETH, then you need to add debt limits. Use the collateral branches to add a debt limits for each collateral type conservatively. Set high ones for ETH and much much lower for riskier assets.
2. Because of how the list of troves works for redemptions and gas constraints, you can only have up to 10 total collateral types without making massive changes. Do NOT add more than 10 collaterals unless you are prepared.
3. If the average deviation threshold of between oracle price and market price of an asset is expected to go above 50 BPs then you should raise the Base Redemption Fee above 50 BPs to prevent leaking value. This will effect the price that it is profitable to redeem at, so take that into account. If you raise this, the lower bound on peg will be lowered by that much. For example, if base redemption fee is 55BPs, peg floor will be $0.9945 instead of Liquity's $0.995. It may be optimal to have a different redemption fee per branch, but this is not supported in Liquity as is – check out the Ebisu fork.
4. If you are changing collateral types from the ones Liquity uses, double check your collateral tokens do NOT revert when a transfer of 0 tokens is made. Otherwise, this could break liquidations for when remaining col in a trove is 0. If you do have any tokens which revert on 0 transfer, the fix is easy. Add this to troveManager:
WETH must also never revert on 0 amount transfer because of the gas compensation transfer when making new positions.
5. You NEED to read all of the "known issues" disclosed in the Liquity docs. Understand how they will effect your particular fork.
6. The repo comes with many test for your contracts, and uses the `deal()` cheatcode from forge. If you change the storage layout for BoldToken or make it a proxy, you may break these. Easily fix by replace `deal` with mints by pretending to be borrowerO 
7. If you are deploying on an L2 you should significantly lower the gas compensation fee for when users open a trove. If sending a transaction to liquidate a trove costs $0.10 then asking for a fee of $115 to cover this is not good. But be careful!! If you lower it too much to the cost of normal transactions that might not be enough to cover gas during highest demand periods, for example when ETH price is crashing and everyone is freaking out.
8. Study throttled launch redemptions: https://x.com/LiquityProtocol/status/1879852191495946475
9. Be careful with oracles. Be Careful With Oracles. **BE CAREFUL WITH ORACLES.** The stEthPerToken function which the liquity relayer uses is not available in L2 bridged versions of wsteth, so you will need to use an oracle to get this. Double check all oracle params and functions and uptime and price deviations. Composite oracles use a "Canonical rate", for example wstETH gives you a canonical amount of ETH per wstETH. Bridged token contracts on L2s probably dont have a function to get a Canonical rate, so double check how to get that.
10. `COLL_GAS_COMPENSATION_CAP` must be updated if the gas token is not ETH. For example, if the gas token was some other token worth $0.05 then the default max a bot can earn by liquidating things would be $0.10. That might not be enough, so update this based on value of the gas token and expected gas costs.
11. When updating tests, there are many which test interactions with zombies troves. They will all fail if you lower the minimum borrow amount because the amount needed to redeem to bring it under the minimum debt limit is not enough. Increase the amount being redeemed to fix this, and spend time cleaning up your tests.
12. Understand that the most likely way your protocol gets nuked is you accept a bad collateral or a token you accept does something crazy. Double check the implementations of all your collateral tokens.
## Growth
1. Stability pools - 75% of yield from the protocol goes to the stability pools, so growth here is the main focus. Yearn and K3 (Nexo) build aggrigators for stability pool yield. Those agrigation tokens (sBold and yBold on Liquity mainnet) can then be used for looping yield in money markets, creating YT-tokens and PT-tokens in bonding protocols like Pendle, etc..
2. Gauges fly wheel - 25% of revenue is directed by gauges to various LP pools. This drives liquidity for AMM pools, creates direct incentives for continued growth there, and gives utility to future governance tokens.