An DeFi protocol which is a decentralized, over-collateralized stablecoin system that allows users to deposit crypto assets as collateral(ETH/BTC) and mint a decentralized stablecoin (DSC) while ensuring system stability through robust liquidation and health factor mechanisms. The protocol leverages Chainlink price feeds for accurate asset valuation and maintains collateral security by preventing under-collateralization. This approach ensures the stablecoin remains secure, decentralized, and resistant to volatility, making it a reliable component of the DeFi ecosystem.
- Test Coverage: Unit and fuzz testing achieved Forge coverage of 76.15%, 78.35%, and 60.00%.
- Stablecoin Peg: The protocol effectively maintains the stablecoin's value around $1, backed by equivalent assets.
- System Stability: The protocol ensures system stability by liquidating users whose health factor (HF) falls below the minimum threshold.
- Over-Collateralization: The protocol consistently remains over-collateralized, ensuring robust financial security.
- Invarient Fuzz testing: Successfully implemented the invarient fuzz testing covering over 1000 input data for functions parameters for better protocol security.
- Deposit collateral function
- mintDSC function
- Redeem collateral function
- burnDSC function
- Get user health factor function
- Liquidate user when user has less health factor!!!
- Chainlink price feeds
Stablecoins is a cryptocurrencies whose buying power remains stable!!!
Stablecoinsare usually tied to the value of something stable, like a national currency (US Dollar) or commodity(gold).- For ex, Bitcoin or Ethereum, which are not Stablecoins, whose prices can change drastically.
EX: (1 USDC == 1 USD)
-
Relatively Stabled(Pegged/Floating Stablecoin):- Coins which depends on other assets(cryptocurrencies).
Pegged StableCoinhave their value tied to another assetsFloating stablecoinuse maths and mechanism to maintain a constant buying power.
-
Stability method(Governced/Algorithmic Stablecoin):- This is a mechanism that makes coin stable.
Governced Stablecointhis mint and burn token via human intervationAlgorithmic Stablecoinit uses a transparent math equation or set of codes to mint and burn tokens.
-
Collateral Types:-
This include
endogenouslly and exogenouslly Collateralized Stablecoins -
Exogenous: Backed by external assets (USD, ETH). Generally more stable. (
USDT/DAI/RAI/USDC/FRAX) -
Endogenous: Backed by internal assets (project's own token). More risky due to dependency on the token's value.(
UST-Lunna/Terra)
-
-
Fiat-Collateralized Stablecoins:- These are backed by real-world money, like dollars, stored in a bank.
- Example: USDT (Tether), USDC
-
Crypto-Collateralized Stablecoins:- These are backed by other cryptocurrencies as collateral.
- This are often
over-collateralized - Example: DAI,RAI,FRAX
-
Algorithmic Stablecoins:- This uses algorithms and smart contracts to manage the coin's supply and keep its value stable.
- Example: UST(Terra/Luna)
-
Reduce Volatility:
- Unlike Bitcoin or Ethereum, their value doesn't swing wildly, making them safer for
financial transactions.
- Unlike Bitcoin or Ethereum, their value doesn't swing wildly, making them safer for
-
Ease of Use:
- They provide a familiar, dollar-like currency for DeFi users.
-
Seamless Trading:
- Stablecoins are used as a base currency in trading pairs, allowing people to trade crypto assets without dealing with volatility.
-
Lending and Borrowing:
- Users can lend and borrow stablecoins on DeFi platforms, avoiding the risks of crypto price changes.
-
Savings:
- Stablecoins allow users to earn interest without worrying about their savings losing value.
-
Tether(USDT): Backed by fiat currency reserves.
-
USD Coin(USDC): Similar to Tether but focuses on transparency.
-
DAI/RAI/FRAX: Decentralized and backed by other crypto assets.
Note: In protocols we will keep some x% of Liquidation_Threshold that determines the maximum amount of depositColllateral value that is safe
- If userDeposit -> 2 ETH($4000)
- And, LIQUIDATION_THRESHOLD = 50%
- So, Considered_Valid_Collateral => ($4000 * 0.5 == $2000)
- This value can be considered for minting and burning or redeeming.
-
depositCollateral:
- User deposits 2 ETH.
- Protocol stores users collateral deposit
- Users_Deposit -> 2 ETH ($4000)
-
mintDSC:
- User mints/borrows 1000 DSC ($1000).
- Protocol checks (HF) of user after minting.
- If (HF) of user is less than MIN_HF after minting, transaction failed!!!
- User Debt -> 1000 DSC($1000)
- HF -> $4000/$1000 = 400%
- User deposit -> 2ETH ($4000)
- We can consider LIQUIDATION_THRESHOLD here!!!
-
redeem collateral:
- Protocol ensures that users HF remains stable after redeeming!!!
- Users redeem 0.5 ETH($1000)
- System will check users HF and reverts if its break.
- Remaining Collateral -> 1.5 ETH($3000)
- users HF -> $3000/$1000 = 300%
- We can consider LIQUIDATION_THRESHOLD here!!!
-
burnDSC:
- Users burns 500DSC ($500)
- Protocol checks user have enough debt balance to burn DSC
- System reverts if HF of user breaks after redeeming.
- Users debt -> 500DSC ($500)
- users HF -> $3000/$500 = 600%
-
Liquidating User:
-
UserA: deposits -> $150 of ETH
anddebt -> $100 of DSCandHF->1.5 -
If ETH falls to 40%
-
UserA's deposit->$90 debt->$100 HF->0.9
-
If UserA's HF falls below 1!!! They are eligible for liquidation.
-
Let, liquidator pays partial-debt of UserA($50)
-
If protocol decides to give 5% or 10% discount price to liquidator from Users collteral amount.
-
Liquidator will receive $52.5/$55 of ETH from users collateral amount
-
Final position of UserA after liquidation:
- Debt reduced to $50
- Collateral reduced -> $90-$52.5 == $37.5
- Liquidator recieves -> $52.5 of ETH
- Improves UserA health factor.
-
- LIQUIDATION_THRESHOLD = 50%
Valid_Collateral = (collateralAmount * LIQUIDATION_THRESHOLD) Health_Factor = ((Valid_Collateral * 1e10)/totalDSCMinted)
-
Safe Health factor:
- Deposit->1 ETH($2000) Debt->1000 DSC($1000)
- Valid collateral -> $2000*0.5 == $1000
- Health factor -> (($1000 * 1e10)/$1000) == 1 * 1e10
-
Poorer Health factor:
- Deposit->0.5 ETH($1000) Debt->800 DSC($800)
- Valid collateral -> $1000*0.5 == $500
- Health factor -> (($500 * 1e10)/$800) == 0.625 * 1e10
ChatGPT link:(IMP.) https://chatgpt.com/c/6789544e-f88c-800d-9a31-bc3f063804aa