Useful links:
This repository powers SonarWatch website by fetching all DeFi assets for a wallet on multiple chains, it covers:
Anyone can contribute to this repository to help us cover more protocols and create a better coverage for the user.
This repository is divided in plugins, each plugin can have :
A Job will store data into our Cache, those data are usually common data for all users (information about the amounts of a tokens on a lending protocol, liquidity pools prices, etc..)
To add data to the Cache, you will mainly use the following methods on the cache
object :
cache.setTokenPriceSource()
cache.setItem()
Warning If your Job is adding prices for tokens, make sure to verify those prices by :
wallet-tokens-<networkId>
, this will fetch all tokens within the wallet and get the prices from the Cache (local + distant). (see below for commands)You can create as many Jobs as needed by plugins.
A Fetcher is were the logic stand, it usually (not necessarily) recover some data from the Cache, then use it to compute the value of the assets deposited by a user on a protocol.
Some examples of Fetchers :
You can create as many Fetchers as needed by plugins, each Fetcher being entitled to a Networkd (Solana, Sui, Aptos etc..).
You always need to provide a user address to run a fetcher.
npm install
.env
file by running :cp .env.example .env
npx nx generate @sonarwatch/portfolio-plugins:plugin my-super-protocol
Job
or a Fetcher
(see commands below)Once you're down writing the logic on your Job
or Fetcher
:
Job
(s) and Fetcher
(s) to your index.ts
file in your plugin
folderFetchers
and Jobs
to the packages\plugins\src\index.ts
fileBefore anything, you need to run the Cache on your local network, simply run :
npx nx run plugins:serve-cache
If you are adding a liquidity protocol
You're now ready to try your Fetcher
or Job
by running the following commands :
npx nx run plugins:run-job jobId
Example :
# Run the job mango-banks
npx nx run plugins:run-job mango-banks
npx nx run plugins:run-fetcher fetcherId userAddress
Example :
# Run the fetcher mango-collateral on the address Demo...tKG
npx nx run plugins:run-fetcher mango-collateral DemoSX9F2zXfQLtBr56Yr5he15P7viZWsYJpSDAX3tKG
If you need the price of a token but don't find it in the Cache, please submit a PR to our token list repository
Here is a list of useful command that can help you during your integration.
# Getting started
npm install
cp .env.example .env
# Set your RPCs
# Generate a plugin
npx nx generate @sonarwatch/portfolio-plugins:plugin my-super-protocol
# Generator a job
npx nx generate @sonarwatch/portfolio-plugins:job --jobName=myJob --pluginId=my-super-protocol
# Generator a fetcher
npx nx generate @sonarwatch/portfolio-plugins:fetcher --fetcherName=myFetcher --pluginId=my-super-protocol
# Serve cache in background
npx nx run plugins:serve-cache
# Run a job
npx nx run plugins:run-job mango-banks
npx nx run plugins:run-job wallet-tokens-aptos
# Run a fetcher
npx nx run plugins:run-fetcher mango-collateral DemoSX9F2zXfQLtBr56Yr5he15P7viZWsYJpSDAX3tKG
npx nx run plugins:run-fetcher marinade-tickets DemoSX9F2zXfQLtBr56Yr5he15P7viZWsYJpSDAX3tKG
npx nx run plugins:run-fetcher wallet-tokens-aptos \"0xaa3fca2b46efb0c9b63e9c92ee31a28b9f22ca52a36967151416706f2ca138c6\"
npx nx run plugins:run-fetcher wallet-tokens-aptos aa3fca2b46efb0c9b63e9c92ee31a28b9f22ca52a36967151416706f2ca138c6
npx nx run plugins:run-fetcher wallet-tokens-ethereum-top \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\"
npx nx run plugins:run-fetcher wallet-tokens-ethereum-top d8dA6BF26964aF9D7eEd9e03E53415D37aA96045
# Run a airdrop fetcher
npx nx run plugins:run-airdrop-fetcher drift-airdrop-1 DemoSX9F2zXfQLtBr56Yr5he15P7viZWsYJpSDAX3tKG
npx nx run core:build
npx nx run plugins:build
npx nx run core:version --releaseAs=patch
npx nx run plugins:version --releaseAs=patch
npx nx run core:version --releaseAs=minor
npx nx run plugins:version --releaseAs=minor
npm run nx:version