A smart contract standard for a fund that executes the index portfolio management strategy. Has mock implementation of externally-dependent functionality, and a Uniswap implementation of it
This project is about smart contracts that manage people's money using the index strategy. The index strategy is defined by this rule: at each point in time, your target allocation in an asset is proportional to the market cap of that asset.
The key point about the organization of this system is: there are two parts, (1) internal business logic and (2) externally-dependent logic. This split was chosen to make the system as extensible as possible. (1) is the top-level where we call functions for updating the allocation of the fund and manage accounting about who's contributed to the fund and what holdings the fund has. This should be the same for every index fund. (2) is about (2.1) retrieving quote-type information about assets and (2.2) executing trades. I have an abstract contract that implements (1), and I have two implementations of contracts for (2): one is a mock implementation that I use to test the logic in (1) and show an example user story. The other is a Uniswap-based implementation!
There is much to say about other products and standards that are out there. Notably, in my opinion, EIP-4626: Tokenized Vaults is a standard for a similar idea. In short, I opted to go this custom route because I wanted to see what an on-chain index fund from first principles might look like, in case I catch something other people missed.
In this (public) Google doc I have the full details: https://docs.google.com/document/d/1P7B8YbMYtgKWLpTUFDoFH_Krtiwo9xgKgCTuOfMV0Do/edit#heading=h.u9wkg182qwbd.
For most of this project, I was coding in Tenderly's Sandbox. It was great for getting started-- I didn't have to worry about environment setup. Eventually my code got long and it was not as convenient to use the UI. So I setup hardhat environment and worked in VSCode.
The core stages of this work were: (1) implement the core business logic in a way that seems to make sense and compiles in Tenderly, (2) setup a hardhat Solidity development environment on my machine, and write a test file that demos the core business logic using a mocked version of the externally-dependent logic, (3) setup a local hardhat Uniswap integration and implement the externally-dependent logic using Uniswap functionality.