Inspiration

The inspiration for our project was an essay written by Manny Rincon-Cruz called Mechanical Finance: Vaults, Runs, Aggregation, and Automation. The essay argues that the need for high TPS on blockchains can be worked around by the implementation of "Vaults", which have 3 sets of rules. 1) Depositing/Redeeming collateral. 2) Minting/Burning Notes and 3) Deploying and Recovering Investments.

In TradFi, a lot of attention is paid to the rules for deploying and recovering investments. Typically this is the job of a portfolio manager or a risk manager. A common risk metric in TradFI is VaR (Value at Risk). VaR is a statistical technique used to measure and quantify the level of financial risk within a firm or investment portfolio over a specific time frame. This metric is most commonly used by investment and commercial banks to determine the extent and occurrence ratio of potential losses in their institutional portfolios. VaR modelling can accurately measure only the potential loss amount, not the maximum loss and the exact loss.

What it does

The VarVault maintains a portfolio of deposits and collateral and manages it according to the Value at Risk. Users can deposit their stablecoins and then redeem collateral in the future. If the risk model is a good one, the vault value should appreciate over time.

Using Chainlink Functions, we are able to post a VaR calculation to each vault. By embedding this in a Chainlink Automation compatible contract, the vault is updated regularly with a new VaR calculation.

How we built it

The smart-contracts were built and tested using Foundry and the Chainlink Functions Starter-kit. We made use of Our front-end was built using TypeScript and Material UI.

We also built our own API for the actual VaR calculation. The API built is a Python, FastAPI application deployed to Heroku. The FastAPI allows asynchronous code, which is necessary when making multiple calls to external data APIs. The API first accepts a POST query which provides it with the collateral asset to be used, the amount of collateral that will be posted, the date that the collateral will be posted and the risk parameter for the VaR calculation.

The API will then make a call to the Binance API and retrieve historical prices for the desired asset. It will also make a call to the Deribit API to retrieve the implied 3-month volatility data for the desired asset.

It will then use the price data to calculate the log returns and fit a t-student distribution to those returns. Finally the VaR metric is calculated by multiplying the collateral amount, the t statistic obtained from the t distribution of returns and the implied volatility obtained from Deribit. The VaR metric is returned to the user.

Challenges we ran into

One of the challenges we ran into was data-limitation with Chainlink Functions. To work-around this, we built our own API to run the VaR calculation instead of passing data between multiple APIs.

Accomplishments that we're proud of

  • Learning how to use new technologies such as Functions, as well as building our own APIs and tools to help us work around problems

What we learned

  • How to use Chainlink Functions
  • How to use Chainlink Automation

What's next for VarVault

Built With

Share this project:

Updates