Project #5 for Arcane x CertiK Developer Workshop: https://calnix.gitbook.io/eth-dev/
Problem Statement: yieldprotocol/mentorship2022#5
- Contract allows users to deposit an asset they own (collateral), to borrow a different asset that the Vault owns (underlying).
- Exchange rate determined by oracle.
- If value of collateral drops in underlying terms, the user will be liquidated.
- User can deposit WETH as collateral, and borrow DAI against it.
- Users deposit WETH into Vault
- Users borrow DAI against their WETH collateral
- Loan is considered healthy as long as the Vault does not lose money.
- This happens when:
- The weth collateral held by the Vault is worth less than DAI lent
- Vault cannot sell weth at market price to collect back DAI lent
- This occurs when price appreciates:
- Initial DAI/WETH price: 0.00038637284
- price appreciation
- 1 DAI : 0.38637284 WETH
- 1 DAI gets your more WETH
- But that means to get the same amount of DAI, Vaul needs more WETH.
- Initial DAI/WETH price: 0.00038637284
- Liquidation occurs when the WETH collateral, calculated in weth terms.
- If value of collateral drops in underlying terms, the user will be liquidated.
Collateral: WETH
Underlying: DAI
- Pull the contract code for both from Etherscan
- Add a mint() function that allows you to obtain as much as you need for testing.
-
Users deposit WETH into Vault,
- (WETH frm User to Vault. Vault recirds WETH deposited.)
-
Users borrow DAI against their WETH
- as long as the value DAI they borrow in WETH terms is less than the value of their WETH collateral
- DAI_value_in_WETH < WETH Collateral
- Vault sends DAI to the users.
- Vault owner finances DAI to the Vault on construction.
-
Exchange rate: Chainlink Oracle [https://docs.chain.link/docs/ethereum-addresses]
-
Users can repay debt in DAI
-
Withdrawal
- To withdraw WETH, the users must repay the DAI they borrowed.
-
Liquidation
- If ETH/DAI price changes such tt debt_value > collateral_value, Vault will erase user records from the contract -> cancelling the user debt, and at the same time stopping that user from withdrawing their collateral.