Quickstart

The OpenPool Reporting SDK is a Typescript SDK for retrieving detailed onchain reporting data.

Processing and navigating blockchain transaction data is time-consuming while creating accurate on-chain reporting demands precision and financial know-how. OpenPool's SDK allows you to build bespoke financial dashboards and internal reporting to support business operations and customer demands. The OpenPool SDK is powered by theΒ OpenPool APIΒ and requires an API Key you can get at theΒ OpenPool Developer Portal.

The OpenPool SDK currently supports the following chains:

  • Arbitrum
  • Avalanche
  • Base
  • BNB
  • Ethereum
  • Gnosis
  • Optimism
  • Polygon

🌟 Features

  • πŸ“ˆΒ Detailed Wallet Balances & Performance: Retrieve the real-time and historical enriched balances and performance (with unrealized + realized P&L) data of a given wallet or contract’s tokens (ERC-20’s), NFTs, and DeFi staked positions.
  • πŸ“’Β Flexible Wallet Accounting History:Β Query an enriched human-readable transaction history with accounting data for a given wallet or contract. For these requests, a custom cost-method and base-currency can be provided.
  • 🏷️ Customizable Address Labels: Create, update and manage custom smart contract names for counterparty addresses your wallet interacts with.
  • πŸ“‡Β Detailed Metadata: Retrieve metadata for Smart Contracts, Assets, Blockchains, Protocols and Tokens.
  • πŸ”’Β Typescript: Written in Typescript with full type-safety

Installation

NPM:npm install @openpool/openpool-sdk

Yarn: yarn add @openpool/openpool-sdk

PNPM: pnpm add @openpool/openpool-sdk

πŸ› οΈ Usage

Initialization

Once you install the SDK, you can initialize it like so:

import { OpenPool } from "@openpool/openpool-sdk";

const config = {  
  apiKey: 'whatILearnedInBoatingSchoolIs', // Replace with your OpenPool API key.  
};

const openpool = new OpenPool(config);

Making requests

Every address that you will want to retrieve data for will need to be registered first. Once registered, an address will have anΒ is_loadedΒ field that will update upon the completion of its transactions being processed.

πŸ’‘ How to register an address

import { OpenPool } from "@openpool/openpool-sdk";

const config = {  
  apiKey: 'whatILearnedInBoatingSchoolIs', // Replace with your OpenPool API key.  
};

const openpool = new OpenPool(config);

const registerAddress = async (address: string) => {  
  try {  
    const requestBody = {address}  
    const response = await openpool.registerWallet(requestBody);  
    return response  
  }  
  catch(e){  
    // Handle Error  
  }  
  finally {  
    // Do something...  
  }  
}

const registerWalletResponse = await registerAddress('0x123abc')

πŸ’‘ How to look up the registration status of an address

import { OpenPool } from "@openpool/openpool-sdk";

const config = {  
  apiKey: 'whatILearnedInBoatingSchoolIs', // Replace with your OpenPool API key.  
};

const openpool = new OpenPool(config);

const lookupTheRegistrationStatusOfAnAddress = async (address: string) => {  
  try {  
    const requestBody = {address}  
    const response = await openpool.getWalletRegistrations(requestBody);  
    const registrationStatusResults = response.results  
    const registrationStatus = response.results[0].is_loaded  
    return registrationStatus  
  }  
  catch(e){  
    // Handle Error  
  }  
  finally {  
    // Do something...  
  }  
}

const walletRegistrationStatus = await lookupTheRegistrationStatusOfAnAddress('0x123abc')

Examples

Fetching the token balance and performance in USD of a given address

import { OpenPool } from "@openpool/openpool-sdk";

const config = {
  apiKey: 'whatILearnedInBoatingSchoolIs', // Replace with your OpenPool API key.
};

const openpool = new OpenPool(config);

const getTokenBalancesForAnAddress = async (address: string) => {
  try {
    const params = { wallet: address }
    const tokenBalanceResponse = await openpool.getTokenBalances(params);
    return tokenBalanceResponse.result;
  }
  catch(e){
    // Handle Error
  }
  finally {
    // Do something...
  }
}

Fetching the enriched transactions data for a set of addresses

import { OpenPool } from '@openpool/openpool-sdk';

const config = {
  apiKey: 'whatILearnedInBoatingSchoolIs', // Replace with your OpenPool API key.
};

const openpool = new OpenPool(config);

const getTransactionsForAddress = async (address: string) => {
  try {
    const params = { wallet: address }
    const transactionsResponse = await openpool.getTransactions(params);
    return transactionsResponse.result;
  }
  catch(e) {
    // Handle Error
  }
  finally {
    // Do something...
  }
}

const transactions = await getTransactionsForAddress("0x123abc, 0x456cdef, 0x789ghi")

Getting the total unrealized P&L of a given address

import { OpenPool } from "@openpool/openpool-sdk";

const config = {
  apiKey: 'whatILearnedInBoatingSchoolIs', // Replace with your OpenPool API key.
};

const openpool = new OpenPool(config);
    const params = { wallet: address }

const getTotalUnrealizedPnL = async (address: string) => {
  try {
    const params = { wallet: address }
    const transactionsResponse = await openpool.getTotalUnrealizedPnL(params);
    return transactionsResponse.value;
  }
  catch(e) {
    // Handle Error
  }
  finally {
    // Do something...
  }
}

const unrealizedPnl = await getTotalUnrealizedPnL('0x123abc')