Skip to main content

getPortfolioV2Data

Description

getPortfolioV2Data is a function that returns the ERC20 portfolio data for a given Senpi user using the Zapper V2 API.

Pre-requisites

To use this function for local development, make sure that you have the following environment variables set:

ZAPPER_API_KEY=xxx
ZAPPER_API_URL=https://public.zapper.xyz/graphql

Usage

import { getPortfolioV2Data } from "@moxie-protocol/moxie-agent-lib";

const portfolioData = await getPortfolioV2Data(
["0x0000000000000000000000000000000000000000"], // user's wallet addresses
["BASE_MAINNET"],
"M1", // Senpi User ID
runtime // IAgentRuntime
);

Response

{
tokenBalances: {
totalBalanceUSD: 1000000000000000000,
byToken: {
edges: [
{
cursor: "1",
node: {
id: "1",
tokenAddress:
"0x0000000000000000000000000000000000000000",
name: "ETH",
symbol: "ETH",
price: 1000000000000000000,
balance: 1000000000000000000,
balanceUSD: 1000000000000000000,
holdingPercentage: 100,
},
},
],
},
},
metadata: {
addresses: ["0x0000000000000000000000000000000000000000"],
networks: ["BASE_MAINNET"],
},
}

Type Signature

export async function getPortfolioV2Data(
addresses: string[],
networks: string[],
userId: string,
runtime: IAgentRuntime
): Promise<PortfolioV2Data>;

Parameters

ParameterTypeDescription
addressesstring[]The addresses of the wallets to get the portfolio data for
networksstring[]The networks to get the portfolio data for
userIdstringThe Senpi User ID to get the portfolio data for
runtimeIAgentRuntimeThe runtime to get the portfolio data for

Fields

FieldTypeDescription
tokenBalancesTokenBalance[]The token balances for the given user
metadataMetadataThe metadata for the given user