Everything you need to know about plugins.

This repository is divided in plugins, each of them can have :

  • Job(s) : they retrieve common data for all users and store it in the Cache

  • Fetcher(s) : they retrieve information for a single user and send back a list of PortfolioElement (=positions/funds)

Plugins are not necessarily entitled to one unique protocol (=Platform), one good example to illustrate this is the native-stake plugin.

This plugin has multiple fetchers (one per Blockchain), each of them recover Native Stake balances.

One of them (solanaFetcher) send back two types of assets for two different platforms.

We'll get more into how fetchers work in the following sections but it's important to keep in mind that a plugin is only made of Jobs and Fetchers and could be used to retrieve assets for multiple Platforms and Networks.

When do you need a plugin ?

If your protocol is already partially supported in our repository or if your protocol is using another protocol's smart contracts then you don't necessarily need to create one, .

Let' say your protocol is using UniswapV3 smart contracts, which we already support here, you have two solutions :

First solution

  1. Create a new plugin and add in the fetchers array : getUniV3PositionsFetcher with all required parameters.

  2. Add your platform in the constant.ts file of this plugin.

  3. Import all Fetchers, Platforms, Jobs, in the index.ts file

This is useful in case you want to add other things in the plugin that covers your protocol.

Second Solution

  1. Add a platform object in the constant.ts of the Uniswap plugin filled with information about your platform

  2. Add a getUniV3PositionsFetcher and your platform in the index.ts of uniswap's plugin (using your platform in the parameters)

As the fetchers, jobs and platforms from this plugin have already been imported in the main index.ts, you won't need to important anything else.

There is no real best solution here, performance wise it will be exactly the same. So far we've had the habit of creating new plugins per platform, making it easier to understand what is needed to cover the protocol simply by looking at the index.ts file of a plugin.

How to create a plugin ?

Now that you have all the information needed to take the decision, if you want to create a new plugin you simply need to run the following command :

npx nx generate @sonarwatch/portfolio-plugins:plugin <myPluginName>

You will see a new folder being generated under /portfolio/packages/plugins/<myPluginName> with the following files :

  • constant.ts : store here all useful constants but also your Platform object.

  • index.ts : this file regroup all Platforms, Jobs, Fetchers of the plugin.

Import your fetchers, jobs, platforms

You can already import your Platforms, Jobs, Fetchers of this plugin into the index.ts file, this will make sure you can run your test properly on those fetchers and jobs. You can check existing imports and follow the same logic.

Now that you have your plugin ready, let's dive into the the logic of Jobs and Fetchers!

Last updated