Escrow

In layman terms, an escrow is a third party that holds funds, bonds, deeds or other documents that take effect only when certain conditions are fulfilled. An example would be:

  • An escrow account between a buyer and seller holding funds required to buy a home

  • The escrow will only transfer to the seller the funds if certain conditions are met by both the buyer and the seller

In the Teller Protocol, our Escrow holds funds between a user of the Teller App and the multiple DeFi applications Teller can call upon, which include:

  • Compound

  • Uniswap

  • Yearn

This allows users to deposit loaned funds into a Loan Escrow and, depending if conditions are fulfilled, can interact with multiple DeFi applications. Quite exciting stuff!

dapps

The dapps directory contains all the meta data we need to connect to our multiple DeFi applications. In here, we will find:

  • interfaces contains all the different functions available for a respective DeFi application. Some applications, like Aave, contain 4 different interfaces.

  • libraries contains all the defined functions needed to be implemented in our Facet files. If you don't know what a Diamond Contract is, kindly refer to **EIP-2535.**

  • DappMods.sol is a contract that contains modifiers required to transact certain functions in the Facet files

  • <dapp-name>Facet.sol are the multiple Facet contracts that call their respective dapp interface functions and store the updated storage inside the Escrow libraries

escrow

This directory contains the Interface ILoansEscrow along with it's implemented contracts.

It contains functions like

  • callDapp()

  • setTokenAllowance()

  • claimToken()

These functions calls a dapp, sets the token allowance of your escrow tokens and claim your escrow tokens. How your escrow tokens get updated (adding or removing) is explained in the libraries section.

libraries

The LibEscrow.sol library contains functions that help us interact with our respective escrow. It does the following:

  • Gets our list of escrow tokens

  • Checks out the balance of a respective token in our escrow

  • Finds the total value of our escrow loan

  • And, perhaps most importantly, updates our tokens in the escrow

This function tokenUpdated() either adds or removes escrow tokens from a loan escrow depending whether the tokenAddress is contained in the list of tokens or not.

EscrowClaimTokensFacet.sol

Finally, our Facet here has one function, claimTokens() that allows the user, as long as they are the borrower and the loan status is closed, to safely transfer all the escrow tokens from the loan escrow to the user's wallet.

Last updated