Paul

Zyfai Yield Automation

专业领域v1.0.13
作者:Paul更新于 2026-09-04共 14 个版本 · 最新版本发布于 2026-09-04zyfai-sdk@clawhub_pauldefi/zyfai-sdk
金融分析#Wallet#Sdk

据 AlphaMoat 统计,截至 2026-10,Zyfai Yield Automation 累计下载 5,503 次、获 4 个星标,按累计下载量在本次参与排名的 10,914 个 AI 技能中排名第 5,253 位,在「专业领域」分类(1,228 个)中排名第 583 位。

列表默认按累计下载量排序,也可按星标排序;详情页排名按累计下载量计算。

累计下载
5,503
星标
4
全站下载量排名
#5,253
全站前 49% · 「专业领域」前 48%
平台累计下载星标评论
ClawHub ↗5,5034-
SkillHub ↗4,8464—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

该指南介绍连接 Zyfai SDK、配置支持网络上的策略以及查看账户。操作可能涉及真实资金和链上变更;执行前逐笔确认网络、资产、金额和策略。不要把私钥直接放进提示或脚本,安全保存 API 凭据,并说明智能合约、市场和协议风险。 策略变更、跨链设置和链上注册也须事先明确批准。

资料发布于 2026-10-29

可以用来做什么

  • 查看钱包与收益策略流程
  • 检查拟议的存入或提取操作
  • 核对支持的网络和资产要求

什么时候用

  • 钱包访问和凭据已安全管理时
  • 实现和交易细节已核实后
  • 每项资金操作均获明确批准后

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

只解释 SDK 的存入和提取流程及风险;不要连接钱包、创建密钥、签名或发送链上交易。

月度数据趋势

累计下载5,503
2,2644,0045,7432026-03 · 累计下载 2,5042026-06 · 累计下载 3,4272026-07 · 累计下载 3,8542026-08 · 累计下载 4,0812026-09 · 累计下载 5,1752026-10 · 累计下载 5,50326-0326-0926-10
星标4
3442026-03 · 星标 32026-06 · 星标 42026-07 · 星标 42026-08 · 星标 42026-09 · 星标 42026-10 · 星标 426-0326-0926-10

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-105,503—4
2026-095,175—4
2026-084,081+5.9%4
2026-073,854+12.5%4
2026-063,427—4
2026-032,504—3

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

29 KB · ClawHub v1.0.13
---
name: zyfai
description: Earn yield on any Ethereum wallet on Ethereum Mainnet, Base, and Arbitrum. Use when a user wants passive DeFi yield on their funds. The first deposit assigns a non-custodial pre-deployed subaccount (Safe) with a signed session key to their EOA — no separate deploy or session-key step. Supports USDC, WETH, and EURC, with automated yield optimization and deposit/withdraw anytime.
---

# Zyfai — Yield for Any Wallet

Turn any Ethereum wallet into a yield-generating account.

## What This Does
展开全部(共 777 行)

When a user wants to **earn yield** on their crypto, their first `depositFunds` call associates their EOA with a **pre-deployed Smart Account (Safe)** that already has a signed session key. Funds deposited into this subaccount are automatically optimized across DeFi protocols. The user stays in full control and can withdraw anytime. Their EOA is unchanged.

```
┌─────────────────┐      ┌──────────────────────┐
│   User's EOA    │ ───► │  Zyfai Subaccount    │
│  (their wallet) │      │  (Safe smart wallet) │
│                 │      │                      │
│  Owns & controls│      │  • Auto-rebalancing  │
│                 │      │  • Yield optimization│
│                 │      │  • Non-custodial     │
└─────────────────┘      └──────────────────────┘
```

**Key points:**
- The subaccount is **owned by the user's EOA** — only they can withdraw
- Session keys allow **automated rebalancing** but cannot withdraw to other addresses
- The **first deposit** assigns the Safe live on Ethereum Mainnet, Base, and Arbitrum at once
- **No separate deploy or session-key step** — `depositFunds` is the onboarding call

## The Flow

```
1. CONNECT   →  Authenticate the user's wallet
2. DEPOSIT   →  First deposit assigns pre-deployed Safe + session; starts earning
3. WITHDRAW  →  Pull funds back to wallet (anytime)
```

On the first deposit, Zyfai assigns a pre-deployed Safe with a signed session key to the EOA. The Safe is available immediately on Ethereum Mainnet, Base, and Arbitrum. This does not impact the EOA itself.

## Prerequisites

- **API Key** — Get one programmatically (see below) or manually at [sma.zyf.ai](https://sma.zyf.ai)
- **Wallet Connection** — Either a wallet provider (browser) or secure key management (server)
- **Node.js 18+**

```bash
npm install @zyfai/sdk viem
```

> Latest version: `@zyfai/[email protected]`

### Programmatic API Key Creation (Agent-Native)

Agents can create their own API key without human intervention. You need the wallet address (public key) of the agent.

```bash
POST https://sma.zyf.ai/api/sdk-api-keys/create
Content-Type: application/json

{
  "clientName": "my-agent",
  "walletAddress": "0x...",
  "email": "[email protected]"
}
```

**Response:**
```json
{
  "success": true,
  "message": "SDK API key created successfully. Store the apiKey securely - it cannot be retrieved later!",
  "data": {
    "id": "936...",
    "apiKey": "zyfai_361ad41d083c2fe.....",
    "keyPrefix": "zyfai_361ad4",
    "clientName": "my-agent",
    "ownerWalletAddress": "0x..."
  }
}
```

> **Important:** Store the `apiKey` securely — it cannot be retrieved later. The key is linked to the provided wallet address.

## Supported Chains

| Chain            | ID    | Assets            | Min. deposit                          |
|------------------|-------|-------------------|---------------------------------------|
| Ethereum Mainnet | 1     | USDC, WETH, EURC  | $10,000 (WETH: $10,000 worth of WETH) |
| Base             | 8453  | USDC, WETH, EURC  | $100 (WETH: $100 worth of WETH)       |
| Arbitrum         | 42161 | USDC, WETH        | $100 (WETH: $100 worth of WETH)       |

> **EURC** is available on **Ethereum Mainnet and Base only** (not Arbitrum).
>
> **Minimums** apply to the total Safe balance *after* the deposit — top-ups below the minimum are allowed if the Safe already holds enough. WETH minimums use the live ETH/USD price, so the wei threshold moves with the market.

## Important: Always Use EOA Address

When calling SDK methods, **always pass the EOA address** (the user's wallet address) as `userAddress` — never the subaccount/Safe address. The SDK resolves the assigned Safe address for that EOA automatically.

## Wallet Connection Options

The SDK supports multiple ways to connect a wallet. Choose based on your security requirements and deployment context.

### Option 1: Wallet Provider (Recommended for Browser/dApps)

Use an injected wallet provider like MetaMask. The private key never leaves the user's wallet.

```typescript
import { ZyfaiSDK } from "@zyfai/sdk";

const sdk = new ZyfaiSDK({ apiKey: "your-api-key", referralSource: "openclaw-skill" });

// Connect using injected wallet provider (MetaMask, WalletConnect, etc.)
await sdk.connectAccount(window.ethereum, 8453);
```

**Security:** The private key stays in the user's wallet. The SDK only requests signatures when needed.

### Option 2: Viem WalletClient (Recommended for Server Agents)

Use a pre-configured viem WalletClient. This is the recommended approach for server-side agents as it allows integration with secure key management solutions.

```typescript
import { ZyfaiSDK } from "@zyfai/sdk";
import { createWalletClient, http } from "viem";
import { base } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

// Create wallet client with your preferred key management
// Option A: From environment variable (simple but requires secure env management)
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);

// Option B: From KMS (AWS, GCP, etc.) - recommended for production
// const account = await getAccountFromKMS();

// Option C: From Wallet-as-a-Service (Turnkey, Privy, etc.)
// const account = await turnkeyClient.getAccount();

const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http(),
});

const sdk = new ZyfaiSDK({ apiKey: "your-api-key", referralSource: "openclaw-skill" });

// Connect using the WalletClient
await sdk.connectAccount(walletClient, 8453);
```

**Security:** The WalletClient abstraction allows you to integrate with secure key management solutions like:
- **AWS KMS** / **GCP Cloud KMS** — Hardware-backed key storage
- **Turnkey** / **Privy** / **Dynamic** — Wallet-as-a-Service providers
- **Hardware wallets** — Via WalletConnect or similar

### Option 3: Private Key String (Development Only)

Direct private key usage.

```typescript
import { ZyfaiSDK } from "@zyfai/sdk";

const sdk = new ZyfaiSDK({ apiKey: "your-api-key", referralSource: "openclaw-skill" });

// WARNING: Only use for development. Never hardcode private keys in production.
await sdk.connectAccount(process.env.PRIVATE_KEY, 8453);
```

**Security Warning:** Raw private keys in environment variables are a security risk. For production autonomous agents, use Option 2 with a proper key management solution.

### Security Comparison

| Method | Security Level | Use Case |
|--------|---------------|----------|
| Wallet Provider | High | Browser dApps, user-facing apps |
| WalletClient + KMS | High | Production server agents |
| WalletClient + WaaS | High | Production server agents |
| Private Key String | Low | Development/testing only |

## Step-by-Step

### 1. Connect to Zyfai

`connectAccount` automatically authenticates the user via SIWE (Sign-In with Ethereum). No extra auth step is needed.

```typescript
import { ZyfaiSDK } from "@zyfai/sdk";
import { createWalletClient, http } from "viem";
import { base } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

const sdk = new ZyfaiSDK({ apiKey: "your-api-key", referralSource: "openclaw-skill" });

// For browser: use wallet provider
await sdk.connectAccount(window.ethereum, 8453);

// For server: use WalletClient (see Wallet Connection Options above)
const walletClient = createWalletClient({
  account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
  chain: base,
  transport: http(),
});
await sdk.connectAccount(walletClient, 8453);
```

### 2. Deposit Funds

The first deposit **onboards** the user: it assigns a pre-deployed Safe with a signed session key on Ethereum Mainnet, Base, and Arbitrum — no separate deploy or session-key call. `asset` is **required**.

```typescript
const userAddress = "0x..."; // User's EOA (NOT the subaccount address!)
const chainId = 8453; // Base

// Deposit 10 USDC (6 decimals). Optional strategy applies on first deposit only.
await sdk.depositFunds(userAddress, chainId, "10000000", "USDC", "conservative");

// Deposit 0.5 WETH (18 decimals)
// IMPORTANT: User must have WETH, not ETH. Wrap ETH to WETH first if needed.
await sdk.depositFunds(userAddress, chainId, "500000000000000000", "WETH");

// Deposit 10 EURC (6 decimals) — Ethereum Mainnet / Base only
await sdk.depositFunds(userAddress, chainId, "10000000", "EURC");
```

Funds move from EOA → Subaccount and start earning yield immediately.

**Strategies (first deposit only):**
- `"conservative"` — Stable yield, lower risk (default)
- `"aggressive"` — Higher yield, higher risk

**Minimum portfolio balance** (checked against the total Safe balance *after* the deposit — top-ups below the minimum are allowed if the Safe already holds enough):

| Chain            | USDC     | WETH               | EURC        |
|------------------|----------|--------------------|-------------|
| Base / Arbitrum  | $100     | $100 worth of WETH | €5 (Base only) |
| Ethereum Mainnet | $10,000  | $10,000 worth of WETH | €10,000  |

WETH minimums use the live ETH/USD price from the Data API, so the wei threshold moves with the market.

**Returns:**

```typescript
interface DepositResponse {
  success: boolean;
  txHash: string;
  smartWallet: string;
  amount: string;
}
```

After depositing you can inspect the assigned Safe:

```typescript
const wallet = await sdk.getSmartWalletAddress(userAddress, chainId);
console.log(`Subaccount: ${wallet.address}`);
console.log(`Deployed: ${wallet.isDeployed}`);

const user = await sdk.getUserDetails();
console.log("Session key active:", user.hasActiveSessionKey);
```

#### Log External Deposit (Sponsored / Gasless Transactions)

If you execute the token transfer yourself (e.g. via Privy, Biconomy, or another sponsored/gasless provider), register it with Zyfai's backend using `logDeposit`:

```typescript
// 1. Execute the ERC-20 transfer to the Safe with your own wallet implementation
const txHash = await privyWallet.sendTransaction({ to: safeAddress, data: transferData });

// 2. Log the deposit so Zyfai tracks it and optimizes yield
const result = await sdk.logDeposit(8453, txHash, "100000000"); // 100 USDC
```

### 3. Withdraw Funds

```typescript
// Withdraw all USDC (default)
await sdk.withdrawFunds(userAddress, chainId);

// Partial USDC withdrawal (5 USDC)
await sdk.withdrawFunds(userAddress, chainId, "5000000");

// Withdraw all WETH
await sdk.withdrawFunds(userAddress, chainId, undefined, "WETH");

// Partial WETH withdrawal (0.1 WETH)
await sdk.withdrawFunds(userAddress, chainId, "100000000000000000", "WETH");

// Withdraw all EURC
await sdk.withdrawFunds(userAddress, chainId, undefined, "EURC");
```

Funds always return to the user's EOA (the Safe owner). Withdrawals are processed **asynchronously** by the backend, so `txHash` may not be immediately available — check `result.message` and use `getHistory()` to track it.

### 4. Disconnect

```typescript
await sdk.disconnectAccount();
```

## Complete Example

```typescript
import { ZyfaiSDK } from "@zyfai/sdk";
import { createWalletClient, http } from "viem";
import { base } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

async function startEarningYield(userAddress: string) {
  const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
  const chainId = 8453; // Base

  // Connect using WalletClient (recommended for server agents)
  const walletClient = createWalletClient({
    account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
    chain: base,
    transport: http(),
  });
  await sdk.connectAccount(walletClient, chainId);

  // First deposit assigns the pre-deployed Safe + session (pass EOA as userAddress)
  await sdk.depositFunds(userAddress, chainId, "100000000", "USDC", "conservative");
  console.log("Deposited! Now earning yield.");

  await sdk.disconnectAccount();
}

async function withdrawYield(userAddress: string, amount?: string) {
  const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
  const chainId = 8453; // Base

  // Connect using WalletClient
  const walletClient = createWalletClient({
    account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
    chain: base,
    transport: http(),
  });
  await sdk.connectAccount(walletClient, chainId);

  // Withdraw funds (pass EOA as userAddress)
  if (amount) {
    await sdk.withdrawFunds(userAddress, chainId, amount); // partial
    console.log(`Withdrawn ${amount} (6 decimals) to EOA`);
  } else {
    await sdk.withdrawFunds(userAddress, chainId); // full
    console.log("Withdrawn all funds to EOA");
  }

  await sdk.disconnectAccount();
}
```

## API Reference

| Method | Params | Description |
|--------|--------|-------------|
| `connectAccount` | `(walletClientOrProvider, chainId?)` | Authenticate with Zyfai (SIWE) |
| `getSmartWalletAddress` | `(userAddress, chainId)` | Get subaccount address & status |
| `depositFunds` | `(userAddress, chainId, amount, asset, strategy?)` | Deposit USDC/WETH/EURC (first deposit onboards) |
| `logDeposit` | `(chainId, txHash, amount, tokenAddress?)` | Log an externally-executed deposit |
| `withdrawFunds` | `(userAddress, chainId, amount?, assetType?)` | Withdraw USDC/WETH/EURC |
| `getPositions` | `(userAddress, chainId?)` | Get active DeFi positions |
| `getPortfolio` | `(userAddress)` | Portfolio with net-of-fee balances |
| `getAvailableProtocols` | `(chainId)` | Get available protocols & pools |
| `getAPYPerStrategy` | `(crossChain?, days?, strategy?, chainId?, tokenSymbol?)` | Get APY by strategy and token |
| `getUserDetails` | `(asset?)` | Get user details for USDC, WETH, or EURC |
| `getOnchainEarnings` | `(walletAddress)` | Get earnings data by token |
| `updateUserProfile` | `(params)` | Update strategy, protocols, splitting per asset |
| `pauseAgent` / `resumeAgent` | `()` | Pause / resume automated operations |
| `registerAgentOnIdentityRegistry` | `(smartWallet, chainId)` | Register agent on ERC-8004 Identity Registry |
| `disconnectAccount` | `()` | End session |

**Note:** All methods that take `userAddress` expect the **EOA address**, not the subaccount/Safe address.

> `deploySafe(userAddress, chainId, strategy?)` and `createSessionKey(userAddress, chainId)` remain available for legacy flows but are **deprecated** — prefer `depositFunds()` for onboarding.

## Data Methods

### getPositions

Get all active DeFi positions for a user across protocols. Optionally filter by chain.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| userAddress | string | Yes | User's EOA address |
| chainId | SupportedChainId | No | Optional: filter by specific chain ID |

```typescript
// Get all positions across all chains
const positions = await sdk.getPositions("0xUser...");

// Get positions on Arbitrum only
const arbPositions = await sdk.getPositions("0xUser...", 42161);

positions.positions.forEach((bundle) => {
  console.log(`Chain: ${bundle.chain}, Strategy: ${bundle.strategy}`);
  bundle.positions.forEach((slot) => {
    console.log(`Token: ${slot.token_symbol}, Pool: ${slot.pool}`);
    console.log(`Underlying Amount: ${slot.underlyingAmount}`);
  });
});
```

### getPortfolio

Returns the full wallet portfolio plus **net-of-pending-fee** fields. Pending fee is `current` onchain earnings × 10%; gross balances are unchanged.

```typescript
const { portfolio } = await sdk.getPortfolio(userAddress);

// Gross vs net (after pending Zyfi fee)
console.log(portfolio.portfolioByAssetType?.usdc?.balance);
console.log(portfolio.portfolioByAssetType?.usdc?.balanceWithFee);

portfolio.positions?.forEach((slot) => {
  console.log(slot.pool, slot.underlyingAmount, slot.underlyingAmountWithFee);
  console.log(slot.pool_apy, slot.pool_apy_withFee); // pool_apy_withFee = pool_apy × 0.9
});
```

### getAvailableProtocols

Get available DeFi protocols and pools for a specific chain with APY data.

```typescript
const protocols = await sdk.getAvailableProtocols(42161); // Arbitrum

protocols.protocols.forEach((protocol) => {
  console.log(`${protocol.name} (ID: ${protocol.id})`);
  protocol.pools?.forEach((pool) => {
    console.log(`  Pool: ${pool.name} - APY: ${pool.apy || "N/A"}%`);
  });
});
```

Returns:
```typescript
interface ProtocolsResponse {
  success: boolean;
  chainId: SupportedChainId;
  protocols: Protocol[];
}
```

### getUserDetails

Get the authenticated user's details including smart wallet, chains, protocols, and settings. Requires SIWE authentication (done automatically by `connectAccount`). Accepts an optional `asset` (`"USDC"` default, `"WETH"`, or `"EURC"`) — each asset has its own configuration.

```typescript
await sdk.connectAccount(walletClient, chainId);

const user = await sdk.getUserDetails();          // USDC settings (default)
const wethUser = await sdk.getUserDetails("WETH"); // WETH settings

console.log("Smart Wallet:", user.smartWallet);
console.log("Chains:", user.chains);
console.log("Strategy:", user.strategy);
console.log("Has Active Session:", user.hasActiveSessionKey);
```

Returns `UpdateUserProfileResponse` (same shape as `updateUserProfile`).

### updateUserProfile

Update the authenticated user's profile settings including strategy, protocols, splitting, and cross-chain options. Requires SIWE authentication.

**Parameters:**

```typescript
interface UpdateUserProfileRequest {
  /** Investment strategy: "conservative" or "aggressive" */
  strategy?: string;
  /** Array of protocol IDs to use */
  protocols?: string[];
  /** Enable auto-selection of protocols */
  autoSelectProtocols?: boolean;
  /** Enable omni-account for cross-chain operations */
  omniAccount?: boolean;
  /** Array of chain IDs to operate on */
  chains?: number[];
  /** Enable automatic compounding (default: true) */
  autocompounding?: boolean;
  /** Custom name for your agent */
  agentName?: string;
  /** Enable cross-chain strategy execution */
  crosschainStrategy?: boolean;
  /** Enable position splitting across multiple protocols */
  splitting?: boolean;
  /** Minimum number of splits (1-4) */
  minSplits?: number;
  /** Asset to update settings for: "USDC" (default), "WETH", or "EURC" */
  asset?: "USDC" | "WETH" | "EURC";
}
```

**Note on `asset`:** Each asset has its own configuration. Use `asset: "WETH"` or `asset: "EURC"` to update that asset separately from USDC.

**Returns:**

```typescript
interface UpdateUserProfileResponse {
  success: boolean;
  smartWallet?: string;
  chains?: number[];
  strategy?: string;
  protocols?: string[];
  autoSelectProtocols?: boolean;
  omniAccount?: boolean;
  autocompounding?: boolean;
  agentName?: string;
  crosschainStrategy?: boolean;
  executorProxy?: boolean;
  hasActiveSessionKey?: boolean;
  splitting?: boolean;
  minSplits?: number;
  customization?: Record<string, any>;
  asset?: "USDC" | "WETH" | "EURC";
}
```

**Examples:**

```typescript
// Update strategy from conservative to aggressive
await sdk.updateUserProfile({ strategy: "aggressive" });

// Configure specific protocols
const protocolsResponse = await sdk.getAvailableProtocols(8453);
const selectedProtocols = protocolsResponse.protocols
  .filter(p => ["Aave", "Compound", "Moonwell"].includes(p.name))
  .map(p => p.id);
await sdk.updateUserProfile({ protocols: selectedProtocols });

// Enable position splitting (distribute across multiple protocols)
await sdk.updateUserProfile({ splitting: true, minSplits: 3 });
```

> **Cross-chain strategies:** Only enable cross-chain when the user **explicitly requests** it. For cross-chain to work, **both** `crosschainStrategy` and `omniAccount` must be `true`. Never enable cross-chain settings by default.

```typescript
// Enable cross-chain ONLY when explicitly requested by the user
await sdk.updateUserProfile({ crosschainStrategy: true, omniAccount: true });
```

**Notes:**
- **Strategy:** Can be changed anytime. Subsequent rebalancing uses the new active strategy.
- **Protocols:** Use `getAvailableProtocols(chainId)` to get valid protocol IDs before updating.
- **Smart Splitting (minSplits = 1):** Default mode. Funds are distributed across multiple DeFi pools only when beneficial, based on current market conditions.
- **Forced Splitting (minSplits > 1):** Funds are always distributed across at least that many pools (up to 4) for risk diversification.
- **Cross-chain:** Requires **both** `crosschainStrategy: true` AND `omniAccount: true`.
- **Auto-compounding:** Enabled by default — yields are reinvested automatically.
- Smart wallet address, chains, and `executorProxy` cannot be updated via this method.

### pauseAgent / resumeAgent

Pause the agent by clearing all protocols (stops automated operations) across USDC, WETH, and EURC. Resume to restart.

```typescript
await sdk.pauseAgent();

// Verify
const details = await sdk.getUserDetails();
console.log("Active protocols:", details.protocols?.length); // 0 when paused

await sdk.resumeAgent();
```

### getAPYPerStrategy

Get global APY by strategy type, time period, chain, and token. Use this to compare expected returns before depositing. Prefer `average_apy_withFee` / `average_apy_with_rzfi_withFee` (gross × 0.9) for user-facing display (renamed from `*_with_fee` in `@zyfai/sdk` 0.2.51).

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| crossChain | boolean | No | If `true`, cross-chain strategies; else single-chain (default: `false`) |
| days | number | No | Period: `7`, `15`, `30`, `60` (default: `7`) |
| strategy | string | No | `"conservative"` (default) or `"aggressive"` |
| chainId | number | No | Filter by chain ID (e.g. `8453`) |
| tokenSymbol | string | No | Filter by token: `"USDC"`, `"WETH"`, or `"EURC"` |

```typescript
// 7-day APY for USDC conservative
const usdcApy = await sdk.getAPYPerStrategy(false, 7, "conservative", undefined, "USDC");

// Compare strategies (30d)
const conservative = await sdk.getAPYPerStrategy(false, 30, "conservative");
const aggressive = await sdk.getAPYPerStrategy(false, 30, "aggressive");
console.log(`Conservative 30d APY: ${conservative.data[0]?.average_apy_withFee}%`);
console.log(`Aggressive 30d APY: ${aggressive.data[0]?.average_apy_withFee}%`);
```

Returns:
```typescript
interface APYPerStrategyResponse {
  success: boolean;
  count: number;
  data: APYPerStrategy[];
}

interface APYPerStrategy {
  id: string;
  timestamp: string;
  amount: number;
  fee_threshold: number;
  days: number;
  chain_id: number;
  is_cross_chain: boolean;
  average_apy: number;
  average_apy_with_rzfi: number;
  total_rebalances: number;
  created_at: string;
  strategy: string;
  token_symbol?: string;
  average_apy_withFee: number;
  average_apy_with_rzfi_withFee: number;
  events_average_apy?: Record<string, number>;
  events_average_apy_withFee?: Record<string, number>;
  events_average_apy_with_rzfi_withFee?: Record<string, number>;
}
```

### getOnchainEarnings

Get onchain earnings for a wallet with per-token totals (multi-asset).

```typescript
const earnings = await sdk.getOnchainEarnings(smartWalletAddress);

console.log("Total by token:", earnings.data.totalEarningsByToken);
// { "USDC": 150.50, "WETH": 0.05 }

// Net totals (after fee): lifetime + unrealized + current × 0.9
console.log("Net by token:", earnings.data.totalEarningsByTokenWithFee);
```

Returns:
```typescript
type TokenEarnings = Record<string, number>;                  // { "USDC": 100.5, "WETH": 0.025 }
type ChainTokenEarnings = Record<string, TokenEarnings>;      // { "8453": { "USDC": 100.5 } }

interface OnchainEarnings {
  walletAddress: string;
  totalEarningsByToken: TokenEarnings;
  totalEarningsByChain?: ChainTokenEarnings;
  totalEarningsByTokenWithFee: TokenEarnings; // lifetime + unrealized + current × 0.9
  totalEarningsByChainWithFee?: ChainTokenEarnings;
  lastCheckTimestamp?: string;
  lastLogDate?: Record<string, string | null>;
}

interface OnchainEarningsResponse {
  success: boolean;
  data: OnchainEarnings;
}
```

> **Fee formula:** pending fee = `current × 0.1` (unrealised yield only). Do **not** apply `× 0.9` to lifetime or unrealized earnings.

### registerAgentOnIdentityRegistry (ERC-8004)

Register your Zyfai deployed agent on the Identity Registry following the ERC-8004 standard (used for OpenClaw agent registration). The method fetches a `tokenUri` with the agent's metadata (stored on IPFS), then registers it on-chain.

**Supported Chains:** Base (8453), Arbitrum (42161)

```typescript
const sdk = new ZyfaiSDK({ apiKey: "your-api-key" });
await sdk.connectAccount(walletClient, 8453);

const walletInfo = await sdk.getSmartWalletAddress(userAddress, 8453);
const result = await sdk.registerAgentOnIdentityRegistry(walletInfo.address, 8453);

console.log("Tx Hash:", result.txHash);
console.log("Chain ID:", result.chainId);
console.log("Smart Wallet:", result.smartWallet);
```

Returns:
```typescript
interface RegisterAgentResponse {
  success: boolean;
  txHash: string;
  chainId: number;
  smartWallet: string;
}
```

## Security

- **Non-custodial** — User's EOA owns the subaccount
- **Session keys are limited** — Can rebalance, cannot withdraw elsewhere
- **Deterministic** — Same EOA = same subaccount address across Mainnet, Base, and Arbitrum
- **Flexible key management** — Use wallet providers, WalletClients, or KMS integrations

### Key Management Best Practices

For **production autonomous agents**, we recommend:

1. **Use a WalletClient** with a secure key source (not raw private keys)
2. **Integrate with KMS** (AWS KMS, GCP Cloud KMS) for hardware-backed key storage
3. **Consider Wallet-as-a-Service** providers like Turnkey, Privy, or Dynamic
4. **Never hardcode** private keys in source code
5. **Rotate keys** periodically and implement key revocation procedures

## Troubleshooting

### "No account connected" error

Call `connectAccount()` before methods that require **signing or SIWE authentication** (e.g. `depositFunds`, `withdrawFunds`, `updateUserProfile`). Read-only data methods (e.g. `getPositions`, `getHistory`, `getOnchainEarnings`) do not require a connected wallet.

### "Safe not available" / deposit failed on first use

The Safe is assigned on the first successful `depositFunds` call. If deposit fails:
1. Confirm the EOA is connected via `connectAccount`
2. Confirm the chain and asset are supported (EURC: Mainnet/Base only)
3. Retry `depositFunds` — do **not** call any separate deploy or session-key method

### Subaccount address mismatch across chains

After the first deposit, the assigned Safe address should be **identical** across Mainnet, Base, and Arbitrum for the same EOA:

```typescript
const baseWallet = await sdk.getSmartWalletAddress(userAddress, 8453);
const arbWallet = await sdk.getSmartWalletAddress(userAddress, 42161);

if (baseWallet.address !== arbWallet.address) {
  console.error("Address mismatch! Contact support.");
}
```

If addresses don't match, contact support on Telegram: [@paul_zyfai](https://t.me/paul_zyfai)

### "Invalid signature" error

This typically means:
- The wallet/signer doesn't match the EOA you're passing
- The Safe address on-chain doesn't match what the SDK expects

Verify you're using the correct wallet for the EOA.

### Withdrawal transaction hash not available

Withdrawals are processed asynchronously by the backend. If `withdrawFunds` returns without a `txHash`:
1. Check the `message` field for status
2. Use `getHistory()` to track when the withdrawal transaction is processed

## Resources

- **Get API Key:** [sma.zyf.ai](https://sma.zyf.ai) or programmatically via `POST /api/sdk-api-keys/create`
- **Docs:** [docs.zyf.ai](https://docs.zyf.ai)
- **Demo:** [github.com/ondefy/zyfai-sdk-demo](https://github.com/ondefy/zyfai-sdk-demo)
- **MCP Server:** [mcp.zyf.ai](https://mcp.zyf.ai/mcp) — Use with Claude or other MCP-compatible agents
- **Agent Registration:** [zyf.ai/.well-known/agent-registration.json](https://www.zyf.ai/.well-known/agent-registration.json)

## License

MIT License

Copyright (c) 2024 Zyfai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

「专业领域」分类下的热门技能

AIGC过程存证服务专业领域

AIGC创作过程自动存证技能。自动识别创作平台与生成工具,将创作过程记录存证并盖有公安备案电子印章,具备可信时间戳,可以在全国电子印章互认平台核验。

↓ 390.0万★ 7u_c2c77b5f
防诈专家专业领域

反电信网络诈骗(反诈)专家技能。当用户描述一个疑似诈骗的场景、短信、电话、链接、聊天记录、App、投资平台、招聘信息或转账要求,并询问「这是不是诈骗」「要不要转钱」「怎么止损」「钱还能不能追回来」,或需要识别诈骗话术、拆解骗局结构、生成报案材料与取证清单时使用。同时在对话中主动嗅探「转账、验证码、屏幕共享、安全账户、保证金、刷单、稳赚、百万保障、跑分」等风险词并插入预警,即使对方并未询问反诈。适用场景还包括:家属求助劝阻疑似被骗的亲人、企业/银行/支付机构/互联网平台做涉诈账户识别与交易监测规则、涉诈资金链(跑分、卡四件套、GOIP)分析、反诈合规与员工培训、反诈实战演练。

↓ 168.7万★ 4user_e9185b15
全国电子印章互认平台专业领域

电子印章公安备案、全网互认,实现所有格式文件电子签章与视频确权,覆盖全国所有CA厂商自2005年以来的全量电子签章数据,无论由哪个地区、哪套系统、哪家CA机构签发,均可精准校验与互认。

↓ 141.6万★ 8u_c2c77b5f
baozheng-skills专业领域

包拯.Skills你身边的专家律师团 — 专业法律咨询 + 要素式/通用起诉状起草 + 刑事专项材料辅助 + 法条分析与法规检索。flk.npc.gov.cn API实时法条优先,不可用时AI知识库降级兜底,**法条来源按四档标注可核验(已核验-flk API / 已核验-单源 / 已引-离线库 / 未核验-模型生成),交付末尾附法条/事实/金额/程序分项置信度**;以22类法律领域覆盖矩阵约束路由边界;支持35个起诉状模板、5类刑事专项材料辅助;内置Logic Doctor逻辑自检、诉讼时效追踪及10类异常容错处理(含连续失败熔断);渐进式意图收敛协议(3轮状态机);混合意图自动任务拆解(按依赖排序→合并→顺序执行);含反模式清单与危机干预出口(自杀/家暴/未成年人侵害先于一切法律分析)。非标准案由自动使用通用模板。

↓ 52.7万★ 2user_814dbe54
律师助手专业领域

律师AI办案工作台:从接案到结案全流程提效——案件分析、要件梳理、文书初稿、证据质证、法庭攻防演练、赔偿与费用计算、期限提醒、复盘归档;覆盖民事、刑事、劳动、非诉、破产、执行、行政、仲裁八大领域,111 个专家技能;法条可核验、结论可复核。

↓ 50.7万★ 77user_cd0fcd93
包拯.SKILL专业领域

包拯.Skills你身边的专家律师团 — 专业法律咨询 + 要素式/通用起诉状起草 + 刑事专项材料辅助 + 法条分析与法规检索。flk.npc.gov.cn API实时法条优先,不可用时AI知识库降级兜底,**法条来源按四档标注可核验(已核验-flk API / 已核验-单源 / 已引-离线库 / 未核验-模型生成),交付末尾附法条/事实/金额/程序分项置信度**;以22类法律领域覆盖矩阵约束路由边界;支持35个起诉状模板、5类刑事专项材料辅助;内置Logic Doctor逻辑自检、诉讼时效追踪及10类异常容错处理(含连续失败熔断);渐进式意图收敛协议(3轮状态机);混合意图自动任务拆解(按依赖排序→合并→顺序执行);含反模式清单与危机干预出口(自杀/家暴/未成年人侵害先于一切法律分析)。非标准案由自动使用通用模板。

↓ 42.4万★ 41user_741dc82b
专利初稿助手专业领域

基于技术交底书生成专利申请初稿。技术交底书内容至少包含技术问题、解决方案、技术效果。内置的推理、视觉、多模态、数学、函数、仿真等模型底座均为国产,国外模型0使用,可放心食用。 近期安装量暴增感谢支持,不少私信希望能力提升但这已是国产极限,我们不必追求最强技能,达到及格即可。学习交流欢迎联系微信号A26dian4

↓ 36.9万★ 48user_9c63fdb4
露禾论文写作助手(免费版pro)专业领域

露禾论文写作助手(免费版):一句话生成引用可溯源、不编造的专业学术论文,按国标 GB/T 7714 插入真实文献引用,中英文 3000/5000/8000 字,一键导出 Word。说「写论文 / 帮我写论文」即可使用。

↓ 35.0万★ 18u_a3c224a2

数据月份:2026-10 · 下载/星标数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。