Idea: Build an index fund using Rari Capital’s Yield Aggregator Codebase

Pramod Vemulapalli
3 min readMay 20, 2022

The above image is based on Jai’s original tweet shown below.

I wanted to make the case for how a few simple changes to the yield aggregator contract (https://github.com/Rari-Capital/vaults/blob/main/src/Vault.sol) which will allow people to build their own index fund on top of it.

Why do this ?

This enhancement will allow people to deploy funds into rari while getting exposure to a mix of tokens that they think is best for them.

The current Yield aggregator contract by rari capital (https://github.com/Rari-Capital/vaults/blob/main/src/Vault.sol) holds an underlying token and allows for that token to be distributed as a part of multiple strategies. This design is very much akin to Yearn where a vault holds a single token, which is put to use in multiple strategies. The admin controls what proportion of funds are to be allocated to which strategy. When withdrawing from the strategies, the withdrawal happens by emptying one strategy at a time and this is clearly the most gas efficient way to do it.

The idea I want to put forward is that the yield aggregator contract could also be used as an index fund, by having each strategy take the underlying token (let’s say Fei is the underlying token) and purchase a token that makes up the index and gather yield from the token by supplying it to a Fuse pool. The only issue in implementing the index fund in this way is that when a user makes a large withdrawal which cannot be serviced by the float in the protocol, the current approach of first emptying a strategy before moving on to the next strategy will not work as this will break the maintenance of relative weights between the token holdings that is needed for an index fund. Therefore, The main tweak needed for the contract to function as an index fund is for the withdrawal of funds to happen in a proportional manner so that the relative weights of the token holdings are preserved.

Here is a code change that would make this idea happen.
https://github.com/PramodVemulapalli/vaults/commit/a3d7fad6065b2c12a6ac1c44cf280eb272d5c52c

The key change lies in storing the strategyWithdrawalPercent as part of the strategydata struct and to use it to withdraw funds from each strategy in a proportional manner thus keeping the fund weights intact after a withdrawal. The strategyWithdrawalPercent is set by the admin and could be based on the marketcap of the token as is commonly done in many index funds. By setting this parameter and by using the strategyDeposit and strategyWithdrawal functions, the admin can maintain the weights of the individual token in the index fund.

The main code change that allows for proportional withdrawal is shown below.

Of course, if the strategyWithdrawalPercent is set to 1E18, then the contract would function in the same manner as the current code and empty each strategy one after another.

I believe that the above code change may also provide more flexibility to managers of the withdrawal queue to determine how the funds are removed from the queue.

Sorry, if I made any obvious solidity errors / gas optimization errors as my . I was hoping to collect any and all feedback on the above idea and the corresponding code change https://github.com/PramodVemulapalli/vaults/commit/a3d7fad6065b2c12a6ac1c44cf280eb272d5c52c

Many thanks to the whole tribe team and special shoutouts to Jet Jadeja and Transmissions11 , Joey Santoro , and Jai Bhavnani. I have learnt much from you guys and it is a delight to watch you build products and I’m sure you will come out much stronger from the hack

--

--

Pramod Vemulapalli

A product guy by day, tinkerer by night, and a dreamer by nature