API

buff.getPortfolio()

Read all token balances and USD values for a Buff wallet address.

Signature

types.ts
typescript
1async getPortfolio(address: string): Promise<Portfolio>
2
3interface Portfolio {
4 walletAddress: string
5 balances: TokenBalance[]
6 totalUsd: number // Total invested assets value
7 pendingSol: number // SOL waiting for threshold
8 pendingUsd: number // In USD
9 solPriceUsd: number // Current SOL price
10}
11
12interface TokenBalance {
13 asset: SupportedAsset
14 mint: string
15 balance: string // Human-readable amount
16 usdValue: number
17}

Example

portfolio.ts
typescript
1const portfolio = await buff.getPortfolio(buffWalletPubkey)
2
3console.log("Wallet:", portfolio.walletAddress)
4console.log("Total invested:", "$" + portfolio.totalUsd.toFixed(2))
5console.log("Pending SOL:", portfolio.pendingSol.toFixed(6))
6console.log("Pending USD:", "$" + portfolio.pendingUsd.toFixed(2))
7
8for (const balance of portfolio.balances) {
9 console.log(balance.asset + ":", balance.balance, "($" + balance.usdValue.toFixed(2) + ")")
10}
11// BTC: 0.00068 ($48.20)
12// ETH: 0.015 ($31.50)

Other Methods

methods.ts
typescript
1// Derive the Buff wallet address (server-side)
2const buffWallet = await buff.deriveWallet(signature)
3// "E71R6Ph2sS4eYJVSNLacorUtSDNK1rUixVswgFD5hCY3"
4
5// Get accumulator state
6const state = await buff.getAccumulator(buffWalletPubkey)
7// { balanceSol: 0.034, balanceUsd: 5.10, thresholdReached: true, ... }
8
9// Get available plans
10const plans = await buff.getPlans()
11// [{ tier: "seed", roundToUsd: 0.05, feePercent: 1.00 }, ...]
12
13// Get current asset prices
14const prices = await buff.getPrices()
15// { SOL: 150.00, BTC: 71000, ETH: 2100, ... }
16
17// Preview round-up without wrapping
18const breakdown = await buff.calculateRoundUp(27.63)
19// { roundUpUsd: 0.37, userInvestmentUsd: 0.3672, ... }
Note
getPortfolio() now requires a wallet address parameter. Portfolio values are fetched from the Buff API with live USD prices. All calculations happen server-side.