calculateOnchainEarnings
Calculate/refresh onchain earnings for a wallet. Triggers a recalculation on the backend.
Signature
calculateOnchainEarnings(walletAddress: string): Promise<OnchainEarningsResponse>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
walletAddress | string | ✅ | Smart wallet address |
Returns
Updated onchain earnings data
Return Type
// Token-keyed earnings — amounts as decimal strings: { "USDC": "421.315354", "WETH": "0.000009" }
type TokenEarnings = Record<string, string>;
// Chain + token-keyed earnings: { "8453": { "USDC": "324.31" }, "42161": { "USDC": "97.00" } }
type ChainTokenEarnings = Record<string, TokenEarnings>;
interface OnchainEarningsResponse {
success: boolean;
data: OnchainEarnings;
}
interface OnchainEarnings {
walletAddress: string;
totalEarningsByToken: TokenEarnings;
totalEarningsByChain?: ChainTokenEarnings;
lastCheckTimestamp?: string;
lastLogDate?: Record<string, string | null>;
}
Amounts are strings
All earnings values are decimal strings (e.g. "421.315354"), not numbers. Parse them with parseFloat() or a BigNumber library when doing arithmetic.
Example
const earnings = await sdk.calculateOnchainEarnings("0x...");
const { totalEarningsByToken, totalEarningsByChain } = earnings.data;
// Total across all chains
console.log("Total USDC earned:", totalEarningsByToken["USDC"]);
// "421.315354"
// Per-chain breakdown
console.log("Base USDC earnings:", totalEarningsByChain?.["8453"]?.["USDC"]);
// "324.313028"
console.log("Arbitrum USDC earnings:", totalEarningsByChain?.["42161"]?.["USDC"]);
// "97.002326"
const totalUsdc = parseFloat(totalEarningsByToken["USDC"] ?? "0");
console.log(`$${totalUsdc.toFixed(2)} USDC earned`);
// "$421.32 USDC earned"