#5 Collateralized Vault

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.

  • For example, user can deposit WETH as collateral, and borrow DAI against it.

Sequence

  1. Users deposit WETH into Vault

  2. Users borrow DAI against their WETH collateral

  3. Loan is considered healthy as long as the Vault does not lose money.

    1. This happens when:

      1. the weth collateral held by the Vault is worth less than DAI lent

      2. Vault cannot sell weth at market price to collect back DAI lent

    2. This occurs when price appreciates:

      1. Initial DAI/WETH price: 0.00038637284

        • price appreciation

        • 1 DAI : 0.38637284 WETH

      2. 1 DAI gets your more WETH

      3. But that means to get the same amount of DAI, Vaul needs more WETH.

  4. Liquidation occurs when the WETH collateral, calculated in weth terms.

    1. if value of collateral drops in underlying terms, the user will be liquidated.

Tokens

  • Collateral: WETH

  • Underlying: DAI

Contracts

  1. Pull the contract code for both from Etherscan

  2. Ensure there is a mint() function that allows you to obtain as much as you need for testing.

Workflow

  1. Users deposit WETH into Vault,

    • (Vault records WETH deposited by each user)

  2. 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.

  3. Exchange rate: Chainlink Oracle [https://docs.chain.link/docs/ethereum-addresses]

  4. Users repay debt in DAI

  5. Withdrawal

    • To withdraw WETH, the users must repay the DAI they borrowed.

  6. 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