Inspiration

Prior to delving into the blockchain rabbit hole, I completed masters in investments & wealth management and had some industry experience. With that said, I've seen substantial evidence that index investing outperforms other forms of investment on the risk-adjusted basis and only a few talented investors are able to outperform the SP500 long-term. However, to this day, index investing in crypto is not accessible in a decentralised manner, and I decided to fill this gap.

What it does

Prior to CCIP, other protocols are primarily focused on cross-chain messaging, therefore liquidity pools have to be built on top, rather than used in parallel. Combining assets transfers (via Stargate or orbiter) with management actions (performing swaps on DEXs) would be a complex task given random finality of two parallel messages sent. CCIP opens up opportunities to send tokens along with data, which can used in various DeFi use cases. In this project, I'm focusing on building a fully decentralised index fund. There is a single controlling contract, which communicates with remote protocol contracts to add / remove tokens during portfolio composition.

How we built it

  1. Using Chainlink Data feed the contract is able to fetch the latest token prices that would form a portfolio.
  2. Unfortunately, I haven't found a way to get token market caps via oracles, however it can be resolved with custom oracles in production.
  3. Using Chainlink CCIP the protocol contract requesting latest token prices from other chains through protocol contracts, which receive CCIP messages, fetch prices from Chainlink Price Oracles and send back a message to calling contract with the latest price. For testing, I used Sepolia and OP Goerli. The parent chain is Sepolia and the price for OP / USD is request via CCIP. Receive hook stores the latest price in the parent protocol contract
  4. Management actions are performed on the parent contract to derive fractions of tokens that should form a portfolio.
  5. Portfolio creation: using Chainlink CCIP, the trade order is sent along with BnM tokens to purchase tokens of interest in specific amounts on destination chains. The amount of CCIP-BnM tokens sent is 20% larger than required to purchase the target token amount to deal with price fluctuations. In my testnet scenario, tokens are exchanged using mock DEXs, however they are swapped with the latest price available from the Data Feed. The excess of BnM tokens is sent back to the parent protocol contract, which is then refunded to the portfolio owner during CCIP receive hook.
  6. The protocol also performs rebalancing with new weights and redemption of portfolio in a similar manner. For redemption, a sell order is sent, tokens are sold at current prices, and all stablecoins are refunded to the portfolio owner. For rebalancing, if the position has to be increased, tokens are sent along with buy order message (similar to portfolio creation). If position has to be reduced in a specific token, the required amount is simply sold on the remote chain and refunded to portfolio owner.
  7. Token positions on the local chain are entered and exited with mock DEX.

Challenges we ran into

The most challenging part was to create and test returning CCIP messages in a single transaction.

Accomplishments that we're proud of

Through extensive testing, the complex communication between contracts on multiple network, the user is able to create an index portfolio with a single transaction.

What we learned

I learned how Index Funds are formed in classic finance and took the inspiration of architecture from there. My contract is performing the task that would have been done by Authorized Providers. I also learned CCIP integration with both data & token and data transfers.

What's next for DYOR & HODL Crypto Index Fund

  1. Scale the project to include more test networks
  2. Wrap the portfolio in ERC1155 to create tradable shares of portfolios with possibility of secondary market creation
  3. Migrate from manual to automated testing
  4. Optimise the code & audit
  5. Integrate & test mainnet DEXs
  6. Invest in design, UX/UI and front-end
  7. Get feedback and deploy to market :)

Built With

Share this project:

Updates