Skip to main content

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.

API Organization

The SDK is organized into logical categories:

Account Management

Manage wallet connections and authentication.

Smart Wallet

Deploy and manage Safe smart wallets with ERC-4337 account abstraction.

Session Keys

Create and manage session keys for delegated transactions.

Fund Management

Deposit and withdraw funds from your Smart Wallet.

Protocol Data

Access DeFi protocol information and user positions.

User Data

Retrieve authenticated user information.

Analytics & Metrics

Platform-wide and wallet-specific analytics.

Earnings & Performance

Track and calculate earnings and APY.

Opportunities

Discover yield opportunities by risk profile.

Rebalancing

Monitor and analyze rebalancing strategies.

Portfolio

Multi-chain portfolio tracking (premium feature).

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.

Support