Creating a DeFi Index Fund

Victor Yeo
2 min readAug 13, 2021

--

In this article, i describe a simple way to create de-centralised Index Fund using solidity smart contracts on Ethereum blockchain.

The core ideas are we use smart contracts to manage a pool of assets, as well as to function as price oracles. There is a UI which communicates to the smart contracts. The users manage the index fund from the UI.

defi index fund design

Firstly, users add assets to the pool. In smart contract, the assets are represented as tokens. The tokens can be anything, so long as the price oracles are able to set a price that closely follows the real world asset price. The tokens can be erc20 token, stock token, token that tracks S&P 500, or token that tracks Nasdaq.

Once the pool is established, user can add liquidity to the pool. Joining the pool is adding liquidity to the pool. Additionally, user can swap tokens and change the weights of assets to the pool. The smart contracts for creating the pool, and for adding liquidity are heavily borrowed from balancer-core https://github.com/balancer-labs/balancer-core.

Secondly, to manage the price of the assets in smart contract, we create a de-centralised price oracles.

The essence of de-centralised price oracles are:

- For any asset in the set of index fund, F = asset1 + asset2 + asset3…

miners submit a vote for what they believe to be the current price of the target asset.

- Every n blocks the vote is tallied by taking the weighted medians as the true price.

- Some amount of token is rewarded to those who voted within 1 standard deviation of the elected median. Those who voted outside may be punished via slashing of their stakes. The ratio of those that are punished and rewarded may be calibrated by the system in every vote to ensure that a sufficiently large portion of the miners vote.

In the smart contract, a pool token is created that functions as governance token. The pool token is also a reward for users who provide liquidity to the index fund pool.

Thirdly, to demonstrate the concepts, there is one UI frontend that talks to the solidity smart contracts. Users are able to create de-centralised index fund on the UI, and view the information of the created index fund.

Fourthly, there could be another optional UI that let the users talks to the price oracles to set the price of the assets.

The DeFi index fund codes are available on my github at https://github.com/victoryeo/defi_indexfund. It is a work in progress.

There are improvements that can be made to the DeFi index fund. Number one, it should allow investor to buy into the index fund without providing liquidity, by using fiat money. Number two, instead of arbitrary weightage, the index fund can support market capitalization weightage.

--

--

No responses yet