#12 - A Complete Guide to Build a Simple Aggregator with Universal Rabbit Hole
[Updated at 2022.9.29]
In this example, we will demonstrate how to implement a simple aggregator by using Universal Rabbit Hole, step by step.
- Instantiate DeFi instances in 1 line of code
- Switch to different DeFi protocol in 1 line of code
- Compose different DeFi protocols in less than 5 lines of code
- You won't touch the details of various SDK
- You won't have to encode / decode the on-chain account data
- You won't have to figure out how to assemble the instruction
We want developers to use DeFi elements as Lego blocks. Universal Rabbit Hole enables developers to utilize various DeFi elements, such as Pool, Farm, Vault, to compose more complex operations without handling enormous amount of client SDK and inconsistent interfaces.
There are two modules in Universal Rabbit Hole: Navigator and Gateway:
Navigator is a Typescript client for instantiating various of kinds of DeFi protocols. You can use it as a standalone dependency in your own project or together with Dappio Gateway.
Gateway is a CaaS (Compasaility-as-a-Service) that standardizes inter-protocol interaction on Solana to unlock the potential of composability. It has an universal interface for various Solana DeFi elements (Pool / Farm / MoneyMarket / Vault / Leveraged Farm / ...) and serves as a common knowledge base that helps Solana community learn and improve.
Let's take a closer look on Gateway module. There are 4 different components in order to make Gateway function:
- Builder: Off-chain component that helps composing different DeFi actions
- Protocol(s): Off-chain component that packages the specific instruction set of each protocol
- Gateway: On-chain program that receives and dispatches all the transactions, manages state, distributes fees
- Adapter(s): On-chain program that connects base program and Gateway program
While Builder and Protocols are packaged into a npm module, Gateway (program) and Adapters are Solana programs deployed by Dappio (sometimes third-party) to be invoked to interact with Base programs
We can separate these series of operations into 2 distinct sections: off-chain part and on-chain part.
- User assembles actions by invoking action setter and providing proper parameters
- Builder composes transactions
- User sends transactions directly to Gateway program
- Gateway dispatches transactions to their corresponding adapters through CPI (cross-program invocation)
- Adapter invokes Base program through another CPI
Following are the current supported protocols:
Pool / Farm
Pool / Farm
Pool / Farm
MoneyMarket / Farm
MoneyMarket / Vault