API Reference Overview
The Zyfai SDK provides a comprehensive TypeScript API for integrating DeFi yield optimization into your applications. All methods are fully typed and include built-in error handling.
Quick Links
API Organization
The SDK is organized into logical categories:
Account Management
Manage wallet connections and authentication.
- connectAccount - Connect wallet and authenticate with SIWE
- disconnectAccount - Disconnect and clear authentication state
Smart Wallet
Deploy and manage Safe smart wallets with ERC-4337 account abstraction.
- getSmartWalletAddress - Get deterministic Safe address
- deploySafe - Deploy Safe wallet with gasless transactions
Session Keys
Create and manage session keys for delegated transactions.
- createSessionKey - Create session key with limited permissions
Fund Management
Deposit and withdraw funds from your Smart Wallet.
- depositFunds - Transfer tokens to Smart Wallet
- withdrawFunds - Withdraw from active positions
Protocol Data
Access DeFi protocol information and user positions.
- getAvailableProtocols - Get available protocols and pools
- getPositions - Get user's active DeFi positions
User Data
Retrieve authenticated user information.
- getUserDetails - Get current user profile and settings
Analytics & Metrics
Platform-wide and wallet-specific analytics.
- getTVL - Get total value locked across platform
- getVolume - Get total trading volume
- getActiveWallets - Get active wallets by chain
- getSmartWalletByEOA - Map EOA to smart wallet
- getFirstTopup - Get first deposit information
- getHistory - Get transaction history
Earnings & Performance
Track and calculate earnings and APY.
- getOnchainEarnings - Get current earnings
- calculateOnchainEarnings - Refresh earnings calculation
- getDailyEarnings - Get daily earnings breakdown
- getDailyApyHistory - Get APY history with weighted averages
Opportunities
Discover yield opportunities by risk profile.
- getSafeOpportunities - Get low-risk yield opportunities
- getDegenStrategies - Get high-risk, high-reward strategies
Rebalancing
Monitor and analyze rebalancing strategies.
- getRebalanceInfo - Get rebalance events
- getRebalanceFrequency - Get rebalance tier and frequency
Portfolio
Multi-chain portfolio tracking (premium feature).
- getDebankPortfolio - Get multi-chain portfolio data
Common Patterns
Authentication Required
Most methods require authentication via SIWE (Sign-In with Ethereum), which is handled automatically when you call connectAccount():
// Authentication is automatic
await sdk.connectAccount(privateKey, chainId);
// Now all protected methods work
const user = await sdk.getUserDetails();
Chain IDs
The SDK supports three chains:
- 8453 - Base
- 42161 - Arbitrum
- 9745 - Plasma
import { getSupportedChainIds, isSupportedChain } from "@zyfai/sdk";
const chains = getSupportedChainIds(); // [8453, 42161, 9745]
const isValid = isSupportedChain(8453); // true
Error Handling
All methods throw typed errors that can be caught and handled:
try {
await sdk.deploySafe(userAddress, chainId);
} catch (error) {
if (error.message.includes("already deployed")) {
console.log("Safe already exists");
} else {
console.error("Deployment failed:", error.message);
}
}
Amount Formatting
Token amounts are always in the least decimal units (wei):
// For USDC (6 decimals), 100 USDC = 100 * 10^6
const amount = "100000000"; // 100 USDC
await sdk.depositFunds(userAddress, chainId, usdcAddress, amount);
Async Processing
Some operations like withdrawals are processed asynchronously:
// Withdrawal is queued
const result = await sdk.withdrawFunds(userAddress, chainId);
console.log(result.message); // "Withdrawal request sent"
// Check history later to see completion
const history = await sdk.getHistory(walletAddress, chainId);
Type Safety
The SDK is fully typed with TypeScript. Import types as needed:
import type {
SDKConfig,
DeploySafeResponse,
SessionKeyResponse,
PositionsResponse,
SupportedChainId,
} from "@zyfai/sdk";
All TypeScript types are exported from the SDK package. Each API method page includes its complete return type interface.
Response Format
All SDK methods return consistent response objects:
{
success: boolean; // Operation success status
// ... method-specific data
}
Rate Limiting
API calls are rate-limited. The SDK includes automatic retry logic with exponential backoff.