getPositionsAndPortfolio
Retrieve the current active DeFi positions and idle balances for the user across all configured chains. This method provides a complete view of the user's portfolio, including deployed capital and latent funds.
Signature
getPositions(): Promise<PortfolioResponse>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userAddress | string | ✅ | User's EOA address |
chainId | SupportedChainId | ❌ | Optional: Filter by specific chain ID |
Returns
A comprehensive breakdown of the user's assets, separated into active positions and idle (stale) balances.
Return Type
interface PortfolioResponse {
success: boolean;
userAddress: string;
portfolio: Portfolio;
}
interface Portfolio {
user?: string;
eoa?: Address;
chains?: number[];
strategy?: string;
smartWallet?: Address;
positions?: PositionSlot[];
hasActiveSessionKey?: boolean;
hasBalance?: boolean;
newSessionKeyAvailable?: boolean;
contracts?: Address[];
omniAccount?: boolean;
crosschainStrategy?: boolean;
staleBalances?: staleBalances[];
splitting?: boolean;
minSplits?: number;
executorProxy?: boolean;
assetTypeSettings?: AssetTypeSettings;
}
interface AssetTypeSettings {
[assetType: string]: {
rebalanceStrategy?: string;
autocompounding?: boolean;
crosschainStrategy?: boolean;
splitting?: boolean;
minSplits?: number;
chains?: number[];
autoSelectProtocols?: boolean;
protocols?: string[];
};
}
interface PositionSlot {
chain?: string;
protocol_id?: string;
protocol_name?: string;
protocol_icon?: string;
pool?: string;
token_id?: string;
token_symbol?: string;
token_icon?: string;
amount?: string;
underlyingAmount?: string;
pool_apy?: number;
pool_tvl?: number;
}
interface staleBalances {
chainId: number;
tokenSymbol: string;
balance: string;
isPending: boolean;
}
Portfolio Calculation
To calculate the total Portfolio Value, you must consider both active and idle funds:
Portfolio Formula
Total Portfolio Value = Active Positions + Stale Balances
positions: Represents capital that has been successfully deployed by the Zyfai agent into liquidity pools or vaults. These assets are actively earning yield.staleBalances: Represents "latent" funds that are sitting in the user's Safe Smart Wallet but have not yet been allocated to a strategy (e.g., recently deposited funds or funds awaiting the next rebalance cycle).
Example
const response = await sdk.getPositions();
const portfolio = response.portfolio;
console.log(`Smart Wallet: ${portfolio.smartWallet}`);
// List active yield-earning positions
portfolio.positions?.forEach(p => {
console.log(`${p.protocol_name} (${p.chain}): ${p.underlyingAmount} ${p.token_symbol} @ ${p.pool_apy}% APY`);
});
// List idle funds awaiting deployment
portfolio.staleBalances?.forEach(b => {
console.log(`Idle on Chain ${b.chainId}: ${b.balance} ${b.tokenSymbol}`);
});
Notes
- The
underlyingAmountis provided in the token's least decimal units. staleBalancesare automatically picked up by the agent during the next optimization/rebalance window.