--- title: 'DeFi Vault (DFV) Whitepaper' --- DeFi Vault (DFV) Whitepaper === ## Table of Contents [TOC] ## System Overview ## Main Components ### DFVConnector contract DeFi users interact with DFVConnector smart contract to work with underlying DeFi product, such as to make deposit and withdraw their tokens etc. Each DeFi product has a specific DFVConnector implementation deployed to work with. Those implementations have the specific logics to work with various underlying DeFi products, and give users different tokens based on the assets they use. For example, Alice lends her DAI thru DAI_MMM_DFVConnector contract to MetaMoneyMarket, then she gets bMaxDAI tokens back. While she gets bMaxUSDC tokens if she deposits USDC thru USDC_MMM_DFVConnector to MetaMoneyMarket product. ### BackedToken (BToken) contract All DFVConnector implementations are inherited from BToken smart contract, which is an ERC20 token, and has all the logics about tracking and updating users' principles and fees accrued. User's principle is stored as the balance and exchange rate got from the underlying product; Fees are calculated based on the fee rate set by each connector, user's principle, and the duration of user's fund. ### DeFiVault (DFV) contract DeFiVault smart contract manages the insurance pool. Anyone can create and deploy his own implementation of DFVConnectors, but the DFVConnectors which can interact with DFV smart contract need to be voted and accepted by DFV token holders. From the DFVConnectors, all user fees are sent to DFV smart contract, then DFV contract buys DFV tokens based on the amount of fees received, and burns those DFV tokens to make the whole system deflationary. DFV contract also creates new DFV tokens when there are user claims sent from DFVConnectors. ## Main User Interactions ### Deposit - User makes a deposit of token in amount X, e.g. X DAI - Connector calculates the fee for previous balance if exists and send to DFV contract - Calculate the amount of BToken needed to create based on the total supply of existing BTokens and the current exchange rate - Make deposit of user's token to the underlying product, and get the underlying tokens - Send user the minted BTokens, and update user's principle and exchange rate ```sequence Lender->Connector: Deposit token Connector->DFV: Send fees Note right of DFV: Buy and burn\nDFV Tokens Connector->Underlying: Send lender's tokens Underlying-->Connector: Store underlying tokens Note right of Connector: Mint BTokens Note right of Connector: Update lender principle Connector-->Lender: Return BTokens ``` ### Withdraw - User sends BTokens to connector contract - Connector calculates the fee for previous balance if exists and send to DFV contract - Get the latest exchange rate from the underlying DeFi product, calculates how many underlying tokens need to send to it to get user's tokens back - Send user's token to the underlying to exchange user's token - Send user his tokens and update user's principle and exchange rate - Anything goes wrong here, the user needs to call the claim process separately ```sequence Lender->Connector: Send BToken Connector->DFV: Send fees Note right of DFV: Buy and burn\nDFV Tokens Note right of Connector: Calc redeemable amount Connector->Underlying: Send underlying tokens Underlying-->Connector: Return user's token Note right of Connector: Burn user's BToken Note right of Connector: Update user principle Connector-->Lender: Return BTokens ``` ### Claim - User call the claim function with his BTokens - Connector calculates the fee for previous balance if exists and send to DFV contract - Calculate how many tokens need to send back to the user with the principle and exchange rate stored for the user - Connector sends the amount to DFV contract to get DFV tokens - DFV contract creates DFV tokens based on the current exchange rate of user token vs DFV token, then send back DFV tokens - Connector gets DFV tokens and send back to the user ```sequence Lender->Connector: Send BToken Connector->DFV: Send fees Note right of DFV: Buy and burn\nDFV Tokens Note right of Connector: Calc claimable amount Connector->DFV: Send claim amount DFV->Oracle: Get DFV price Oracle->DFV: Return exchange rate Note left of DFV: Create DFV tokens DFV-->Connector: Return DFV tokens Note right of Connector: Update principle Connector-->Lender: Return DFV tokens ``` ### Transfer When transfer, both parties need to calculate and pay their fees first, then update each other's balance and exchange rate accordingly. ###### tags: `DeFi` `Ethereum` `Insurance`