Skip to main content
Welcome to the Zyfai SDK documentation! This TypeScript SDK provides a comprehensive solution for interacting with the Zyfai Yield Optimization Engine, enabling you to deposit into Safe smart wallets, manage DeFi positions, and optimize yield across multiple protocols.

What is Zyfai SDK?

The Zyfai SDK is a powerful TypeScript library that simplifies interaction with Zyfai’s yield optimization infrastructure.

Two Ways to Earn Yield

The SDK offers two distinct approaches for earning yield:
  • Smart Wallet: On first deposit, a personal pre-deployed Safe (with session key) is assigned for automated yield optimization across Base, Arbitrum, and Mainnet
  • Vault: Deposit into a shared vault on Base and receive shares representing your stake

Features

The SDK provides:
  • Pre-deployed Smart Wallets: First depositFunds assigns an ERC-4337 / ERC-7579 Safe with a signed session key
  • Flexible Authentication: Support for private keys and modern wallet providers with automatic SIWE authentication
  • Multi-Chain Support: Base (8453), Arbitrum (42161), and Ethereum Mainnet (1)
  • Multi-Asset Support: USDC, WETH, and EURC (EURC on Mainnet and Base)
  • Yield Optimization: Access multiple DeFi protocols and strategies
  • Position Tracking: Monitor and manage your DeFi positions across chains
  • Analytics & Earnings: Track earnings, APY history, and portfolio performance
  • SDK Key Analytics: Access wallet lists and TVL data without requiring wallet connection
Want to see the SDK in action before diving into the code? Check out our Official Demo Application.🔗 Repo: github.com/ondefy/zyfai-sdk-demo
🔗 Website: demo.zyf.ai
This Vite + React demo integrated with Reown AppKit showcases:
  • Wallet Connection (EOA via AppKit)
  • Fund Management (Deposit / Withdrawal — first deposit onboards the Safe)
  • Real-time Data Retrieval (Positions & Earnings)

Prerequisites

Before you begin, ensure your environment meets these requirements:
  1. Node.js: Version 18.0.0 or higher
  2. API Key: Obtain your SDK API Key from the Zyfai Dashboard
  3. CORS Whitelist: Your application domain must be whitelisted on the Zyfai backend to allow API calls from the browser. Contact the Zyfai team with your domain (e.g. https://app.yourproject.com) to get it added. Without this, browser-side SDK calls will be blocked by CORS policy.

Installation

Install the SDK along with viem as a peer dependency. Latest version: 0.2.50

Architecture

The SDK bridges your application with two core backend systems:

Quick Start

Follow these steps to integrate Zyfai into your application.

1. Initialize the SDK

Create a new instance of the Zyfai SDK with your configuration:

2. Connect an Account

The SDK handles SIWE (Sign-In with Ethereum) authentication automatically.

Option A: Backend/Node.js (Private Key)

Option B: Browser/Frontend (Wallet Provider)

connectAccount() performs the full SIWE handshake. No additional authentication logic is required in your application.

3. Fund Management (onboarding via deposit)

Zyfai uses Safe smart accounts to manage user funds. There is no separate deploy or session-key step.
The first depositFunds call associates the EOA with a pre-deployed Smart Account that already has a signed session key. The Safe is available immediately on Base, Arbitrum, and Ethereum Mainnet. This does not change how the user’s EOA works — they remain the owner of a linked Smart Wallet with session permissions for automated rebalancing.

Deposit

Transfer tokens from the EOA to the Safe smart wallet:
Strategy Options (applied on first deposit):
  • "conservative" (default): Optimized for low-risk, stable yield.
  • "aggressive": Optimized for higher yield with higher risk profile.
Supported assets: "USDC", "WETH", "EURC" (EURC on Mainnet and Base only).
Minimums apply to total Safe balance after deposit. Smaller top-ups are allowed if the Safe already meets the threshold.

Withdrawal

Initiate a withdrawal from the Safe back to an EOA:
Withdrawals are processed asynchronously and will always complete — but not instantly. Follow these guidelines to handle them correctly:
  • Do not poll the withdrawal endpoint repeatedly. Once a withdrawal is initiated, it will be processed. Polling adds unnecessary load and can lead to duplicate requests.
  • Track withdrawal state locally. Save a flag in your local state (e.g. isPendingWithdrawal: true) as soon as withdrawFunds() is called. Use this flag to reflect a “pending” status in your UI.
  • Use sdk.getHistory() to confirm when the transaction has landed on-chain. Poll this endpoint at a reasonable interval (e.g. every 15–30 seconds) and clear your local flag once the transaction appears.

4. Monitor Performance


Full Workflow Example

Here is a complete integration script:

Advanced Configuration

Environment Variables

Store sensitive credentials securely:

Custom RPC Setup

Key Features Deep Dive

Pre-deployed Wallets

On first deposit, the backend assigns a pre-deployed Safe (with signed session key) to the EOA. The same Safe is available immediately on Base, Arbitrum, and Ethereum Mainnet.

Session Key Security

Session keys ship with the pre-deployed Safe. They cannot withdraw funds to arbitrary addresses; they are strictly limited to rebalancing assets within the Zyfai ecosystem.

Comprehensive Analytics

  • Platform-wide: TVL, volume, and active user metrics.
  • User-specific: Historical APY (7D/14D/30D), detailed earnings breakdown, and transaction logs.

Target Audience

  • dApp Developers: Build DeFi apps with abstraction and yield optimization.
  • DeFi Services: Manage Safe wallets and positions at scale.
  • Wallet Providers: Embed yield optimization directly into your wallet UI.

Troubleshooting

  • “No account connected”: Ensure sdk.connectAccount() is called and resolved before executing transactions.
  • “Unsupported chain”: Verify the chain ID is supported (1, 8453, 42161).
  • CORS Errors: In browsers, ensure your domain is whitelisted in the Zyfai Dashboard.

Next Steps

Check out the API Reference for a detailed list of all available methods.

Support