Skip to main content

getBestOpportunity

Get the best yield opportunity for a registered smart wallet on a given chain. Returns the highest-APY opportunity available based on the wallet's strategy and enabled protocols, along with comparison to the current position.

Signature

getBestOpportunity(walletAddress: Address, chainId: SupportedChainId): Promise<BestOpportunityResponse>

Parameters

ParameterTypeRequiredDescription
walletAddressAddressSmart wallet address (must be registered)
chainIdSupportedChainIdChain ID to check opportunities on (8453, 42161, or 9745)

Returns

Best opportunity details including the current position, the recommended opportunity, whether a rebalance is warranted, and the full list of available opportunities.

Return Type

interface BestOpportunityResponse {
success: boolean;
error?: string;
wallet?: Address;
chainId?: number;
strategy?: string;
token?: {
symbol: string;
address: string;
decimals: number;
};
currentPosition?: OpportunityPosition | null;
bestOpportunity?: BestOpportunityDetails | null;
shouldRebalance?: boolean;
apyImprovement?: number | null;
allOpportunities?: Array<{
protocol: string;
pool: string;
apy: number;
tvl: number;
zyfiTvl?: number;
}>;
userConfig?: {
autoSelectProtocols: boolean;
enabledProtocols: string[];
};
enabledChains?: number[];
}

interface OpportunityPosition {
protocol: string;
pool: string;
apy: number;
tvl?: number;
}

interface BestOpportunityDetails {
protocol: string;
pool: string;
apy: number;
tvl: number;
zyfiTvl?: number;
poolApy?: number;
rewardsApy?: number;
protocolApy?: number;
}

Examples

const result = await sdk.getBestOpportunity(walletAddress, 8453);

if (result.shouldRebalance) {
console.log("Rebalance recommended!");
console.log("Current APY:", result.currentPosition?.apy);
console.log("Best APY:", result.bestOpportunity?.apy);
console.log("APY improvement:", result.apyImprovement);
}

List all available opportunities

const result = await sdk.getBestOpportunity(walletAddress, 42161);

console.log("Strategy:", result.strategy);
console.log("Best:", result.bestOpportunity?.protocol, "-", result.bestOpportunity?.pool);

result.allOpportunities?.forEach(opp => {
console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}% APY (TVL: $${opp.tvl})`);
});