#5 Collateralized Vault
https://github.com/yieldprotocol/mentorship2022/issues/5
Problem Statement: https://github.com/yieldprotocol/mentorship2022/issues/5
Objective
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.
Sequence
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.
Liquidation occurs when the WETH collateral, calculated in weth terms.
if value of collateral drops in underlying terms, the user will be liquidated.
Tokens
Collateral: WETH
Underlying: DAI
Contracts
Pull the contract code for both from Etherscan
Ensure there is a mint() function that allows you to obtain as much as you need for testing.
Workflow
Users deposit WETH into Vault,
(Vault records WETH deposited by each user)
Users borrow DAI against their WETH collateral
maximum amt of DAI borrowable
DAI_value_in_WETH < WETH Collateral
Vault transfers 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 repay debt in DAI
Withdrawal
To withdraw WETH, the users must repay the DAI they borrowed.
Liquidation
If DAI/ETH price appreciates 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.
Last updated