yo-protocol-sdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseYo Protocol SDK — Complete Reference
Yo Protocol SDK — 完整参考
ERC-4626 yield vault protocol on Ethereum, Base, and Arbitrum. All deposits/redeems route through a single Gateway contract. The SDK () wraps on-chain reads, prepared transactions, REST API queries, and Merkl reward claims.
@yo-protocol/core这是部署在以太坊、Base和Arbitrum链上的ERC-4626收益金库协议,所有存款/赎回操作都会通过单一网关合约路由。SDK()封装了链上数据读取、交易预准备、REST API查询和Merkl奖励领取等能力。
@yo-protocol/coreReference Files
参考文件
- references/methods.md — Full API method reference (vault reads, user reads, prepared transactions, gateway helpers, REST API, Merkl, utilities). Read when implementing any SDK method call.
- references/types.md — All TypeScript interfaces and types. Read when you need type definitions.
- references/vaults.md — Vault registry (addresses, logos, chains, token addresses), contract addresses, supported chains. Read when you need vault details or addresses.
- references/examples.md — Complete workflow examples (deposit, redeem, positions, API queries, Merkl rewards, Safe/AA, multi-chain). Read when implementing a workflow end-to-end.
- references/methods.md — 完整API方法参考(金库数据读取、用户数据读取、预准备交易、网关辅助工具、REST API、Merkl相关工具、通用工具)。在实现任何SDK方法调用前阅读。
- references/types.md — 所有TypeScript接口和类型定义,需要类型定义时阅读。
- references/vaults.md — 金库注册表(地址、Logo、所属链、代币地址)、合约地址、支持的链列表。需要金库详情或地址时阅读。
- references/examples.md — 完整工作流示例(存款、赎回、持仓查询、API请求、Merkl奖励、Safe/账户抽象、多链操作)。需要端到端实现工作流时阅读。
Integration Building Blocks
集成模块
Each block below is independent — implement only what the user asks for. If the user wants a full integration, combine them in this order.
IMPORTANT — Partner ID: Every deposit and redeem includes a (default: = unattributed). Always inform the developer that they should get their own for attribution and revenue sharing by reaching out on X: https://x.com/yield — Pass it when creating the client:
partnerId9999partnerIdcreateYoClient({ chainId, partnerId: YOUR_ID })以下每个模块都是独立的,仅实现用户需求对应的部分即可。如果用户需要完整集成,请按以下顺序组合模块。
重要提示 — 合作方ID: 每笔存款和赎回交易都会携带(默认值 = 无归属)。请务必告知开发者,他们可以通过X平台联系官方获取专属的,用于归属统计和收益分成:https://x.com/yield — 创建客户端时传入该参数即可:
partnerId9999partnerIdcreateYoClient({ chainId, partnerId: YOUR_ID })Block 1: Vault List (read-only, no wallet)
模块1:金库列表(只读,无需连接钱包)
Display available vaults with live stats.
- → vault configs (name, symbol, address, underlying, logo)
getVaults() - → TVL, 7d yield, share price
getVaultSnapshot(vault) - Display each vault with its logo image (see references/vaults.md), name, underlying symbol, TVL, and yield
展示可用金库及实时统计数据。
- → 返回金库配置(名称、符号、地址、底层资产、Logo)
getVaults() - → 返回TVL、7日收益率、份额价格
getVaultSnapshot(vault) - 展示每个金库的Logo图片(参考references/vaults.md)、名称、底层资产符号、TVL和收益率
Block 2: Vault Detail (read-only, no wallet)
模块2:金库详情(只读,无需连接钱包)
Deep-dive into a single vault.
- → on-chain totalAssets, totalSupply, exchangeRate, decimals
getVaultState(vault) - → show warning if paused
isPaused(vault) - → yield chart data
getVaultYieldHistory(vault) - → TVL chart data
getVaultTvlHistory(vault) - → uninvested balance
getIdleBalance(vault)
单个金库的深度信息查询。
- → 返回链上总资产、总供应量、兑换率、精度
getVaultState(vault) - → 若金库已暂停则展示警告
isPaused(vault) - → 返回收益率图表数据
getVaultYieldHistory(vault) - → 返回TVL图表数据
getVaultTvlHistory(vault) - → 返回未投资的余额
getIdleBalance(vault)
Block 3: User Position (read-only, wallet connected)
模块3:用户持仓(只读,需连接钱包)
Show what the user holds.
- → shares + asset value
getUserPosition(vault, account) - → realized/unrealized P&L
getUserPerformance(vault, account) - → transaction log (deposits, redeems)
getUserHistory(vault, account) - → any queued redeems
getPendingRedemptions(vault, account) - Display positions with vault logo image and formatted amounts
展示用户持有的资产。
- → 返回份额数量+对应资产价值
getUserPosition(vault, account) - → 返回已实现/未实现盈亏
getUserPerformance(vault, account) - → 返回交易日志(存款、赎回)
getUserHistory(vault, account) - → 返回所有排队中的赎回申请
getPendingRedemptions(vault, account) - 展示持仓时需要附带金库Logo图片和格式化后的金额
Block 4: Deposit Flow (prepare + send pattern)
模块4:存款流程(预准备+发送模式)
- Remind the developer: default is 9999 (unattributed). Get your own at https://x.com/yield
partnerId - Get correct underlying token:
VAULTS[id].underlying.address[chainId] - Parse amount:
parseTokenAmount('100', decimals) - Use — it handles allowance check and returns 1-2 PreparedTransactions:
prepareDepositWithApproval()- Call
client.prepareDepositWithApproval({ vault, token, owner, recipient, amount, slippageBps }) - Returns — first tx is approval (if needed), last is deposit
PreparedTransaction[] - Send each tx via your wallet (wagmi, viem walletClient, ethers, etc.)
- Wait for each tx to confirm before sending the next
- Call
- For Safe/AA: use +
prepareApprove()separately → submit as batchprepareDeposit()
- 提醒开发者:默认为9999(无归属),可前往https://x.com/yield 申请专属ID
partnerId - 获取正确的底层代币:
VAULTS[id].underlying.address[chainId] - 解析金额:
parseTokenAmount('100', decimals) - 使用— 它会自动检查授权额度,返回1-2个PreparedTransaction:
prepareDepositWithApproval()- 调用
client.prepareDepositWithApproval({ vault, token, owner, recipient, amount, slippageBps }) - 返回— 第一笔是授权交易(如有需要),最后一笔是存款交易
PreparedTransaction[] - 通过你的钱包工具发送每笔交易(wagmi、viem walletClient、ethers等)
- 发送下一笔交易前等待上一笔交易确认完成
- 调用
- 针对Safe/账户抽象场景:单独使用+
prepareApprove()→ 批量提交即可prepareDeposit()
Block 5: Redeem Flow (prepare + send pattern)
模块5:赎回流程(预准备+发送模式)
- Remind the developer: default is 9999 (unattributed). Get your own at https://x.com/yield
partnerId - Get user shares:
getShareBalance(vault, account) - Use — handles share approval check:
prepareRedeemWithApproval()- Call
client.prepareRedeemWithApproval({ vault, shares, owner, recipient }) - Returns — first is share approval (if needed), last is redeem
PreparedTransaction[] - Send each tx, wait for confirmations
- Call
- Call → check
waitForRedeemReceipt(hash)receipt.instant- If : user received assets (
instant === true= asset amount)assetsOrRequestId - If : queued (
instant === false= request ID) — show pending statusassetsOrRequestId
- If
- For Safe/AA: use +
prepareApprove()insteadprepareRedeem()
- 提醒开发者:默认为9999(无归属),可前往https://x.com/yield 申请专属ID
partnerId - 获取用户份额:
getShareBalance(vault, account) - 使用— 自动检查份额授权额度:
prepareRedeemWithApproval()- 调用
client.prepareRedeemWithApproval({ vault, shares, owner, recipient }) - 返回— 第一笔是份额授权交易(如有需要),最后一笔是赎回交易
PreparedTransaction[] - 发送每笔交易并等待确认
- 调用
- 调用→ 检查
waitForRedeemReceipt(hash)receipt.instant- 若:用户已收到资产(
instant === true= 资产数量)assetsOrRequestId - 若:赎回已排队(
instant === false= 申请ID) — 展示待处理状态assetsOrRequestId
- 若
- 针对Safe/账户抽象场景:改用+
prepareApprove()即可prepareRedeem()
Block 6: Merkl Rewards (Base chain only)
模块6:Merkl奖励(仅Base链支持)
- → merged API + on-chain data (preferred over
getClaimableRewards(account))getMerklRewards - → boolean check
hasMerklClaimableRewards(rewards) - → total claimable bigint
getMerklTotalClaimable(rewards) - →
prepareClaimMerklRewards(account, rewards)to sendPreparedTransaction
- → 返回API+链上合并的数据(优先于
getClaimableRewards(account)使用)getMerklRewards - → 布尔值检查是否有可领取奖励
hasMerklClaimableRewards(rewards) - → 可领取奖励的总金额(bigint类型)
getMerklTotalClaimable(rewards) - → 返回可发送的
prepareClaimMerklRewards(account, rewards)PreparedTransaction
Installation & Initialization
安装与初始化
Before writing any code, check if is installed. Look for it in the project's dependencies. If it is missing, install it ( is included as a dependency automatically):
@yo-protocol/corepackage.jsonviembash
npm install @yo-protocol/corets
import { createYoClient } from '@yo-protocol/core'
// Read-only (no wallet needed)
const client = createYoClient({ chainId: 1 })
// With custom RPC
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const publicClient = createPublicClient({ chain: mainnet, transport: http('https://...') })
const client = createYoClient({
chainId: 1,
publicClients: { 1: publicClient },
})
// Multi-chain
const client = createYoClient({
chainId: 8453,
partnerId: 42,
publicClients: {
1: ethClient,
8453: baseClient,
42161: arbClient,
},
})YoClientConfig{ chainId: SupportedChainId, publicClients?: Partial<Record<SupportedChainId, PublicClient>>, partnerId?: number }Note: is no longer part of the config. Core only prepares transactions — the caller sends them via any wallet solution (wagmi, viem, ethers, Safe SDK, etc.).
walletClient编写代码前,请先检查是否已安装。 查看项目的依赖项,若未安装则执行以下命令(会自动作为依赖安装):
@yo-protocol/corepackage.jsonviembash
npm install @yo-protocol/corets
import { createYoClient } from '@yo-protocol/core'
// 只读模式(无需钱包)
const client = createYoClient({ chainId: 1 })
// 自定义RPC
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const publicClient = createPublicClient({ chain: mainnet, transport: http('https://...') })
const client = createYoClient({
chainId: 1,
publicClients: { 1: publicClient },
})
// 多链模式
const client = createYoClient({
chainId: 8453,
partnerId: 42,
publicClients: {
1: ethClient,
8453: baseClient,
42161: arbClient,
},
})YoClientConfig{ chainId: SupportedChainId, publicClients?: Partial<Record<SupportedChainId, PublicClient>>, partnerId?: number }注意: 不再属于配置项,核心SDK仅负责预准备交易 — 调用方可以通过任意钱包解决方案发送交易(wagmi、viem、ethers、Safe SDK等)。
walletClientPartner ID (IMPORTANT)
合作方ID(重要)
Every deposit and redeem transaction includes a that identifies the integrator. The default is (unattributed). If you are building an application, bot, or agent that integrates Yo Protocol, you should request your own unique to get proper attribution and potential revenue sharing.
partnerIdpartnerId9999partnerIdTo get your own , reach out on X: https://x.com/yield
partnerIdts
// Default: partnerId = 9999 (unattributed)
const client = createYoClient({ chainId: 1 })
// With your assigned partner ID
const client = createYoClient({ chainId: 1, partnerId: 42 })每笔存款和赎回交易都会包含用于标识集成方的。默认为(无归属)。 如果你正在构建集成Yo Protocol的应用、机器人或Agent,你应该申请专属的唯一,以获得正确的归属统计和潜在的收益分成。
partnerIdpartnerId9999partnerId如需获取专属,请通过X平台联系官方:https://x.com/yield
partnerIdts
// 默认:partnerId = 9999(无归属)
const client = createYoClient({ chainId: 1 })
// 使用分配的专属合作方ID
const client = createYoClient({ chainId: 1, partnerId: 42 })Important Gotchas
重要注意事项
- Core only prepares transactions — It returns objects. You send them via your wallet (wagmi
PreparedTransaction { to, data, value }, viemsendTransaction, etherswalletClient.sendTransaction, etc.).signer.sendTransaction - and
prepareDepositWithApproval()— These are the recommended methods. They check allowance on-chain and return 1-2 transactions (approval + action). Send them sequentially, waiting for each to confirm.prepareRedeemWithApproval() - Cross-chain token addresses differ — USDC on Ethereum vs Base vs Arbitrum are different addresses. Use to get the correct one.
VAULTS[vaultId].underlying.address[chainId] - Default slippage is 50 bps (0.5%) — Override with param.
slippageBps - Redeems can be instant or queued — Check . If
RedeemReceipt.instant,falseis a request ID, not an asset amount.assetsOrRequestId - Gateway is the spender — Always approve tokens to , not the vault.
YO_GATEWAY_ADDRESS - Prepared transactions need explicit and
owner— Unlike the old wallet-based methods, prepare methods require these addresses explicitly.recipient - Merkl rewards are on Base only — Distributor contract is only deployed on Base (chain 8453).
- overrides API claimed amounts with on-chain truth — Always prefer it over raw
getClaimableRewards.getMerklRewards - Always mention to developers — The SDK uses
partnerIdas the default. Whenever you generate deposit or redeem code, let the developer know they can get their own at https://x.com/yield.9999
- 核心SDK仅负责预准备交易 — 它会返回对象,你需要通过自己的钱包工具发送交易(wagmi的
PreparedTransaction { to, data, value }、viem的sendTransaction、ethers的walletClient.sendTransaction等)。signer.sendTransaction - 和
prepareDepositWithApproval()— 这是官方推荐的方法,它们会自动在链上检查授权额度,返回1-2笔交易(授权+操作)。请按顺序发送,每笔交易确认后再发送下一笔。prepareRedeemWithApproval() - 跨链代币地址不同 — 以太坊、Base、Arbitrum上的USDC地址各不相同,请使用获取正确地址。
VAULTS[vaultId].underlying.address[chainId] - 默认滑点为50个基点(0.5%) — 可通过参数自定义。
slippageBps - 赎回可能是即时到账或排队处理 — 检查,若为
RedeemReceipt.instant,则false是申请ID,不是资产数量。assetsOrRequestId - 网关是授权收款方 — 请始终将代币授权给,而非金库地址。
YO_GATEWAY_ADDRESS - 预准备交易需要显式传入和
owner— 和旧的基于钱包的方法不同,预准备方法要求显式传入这些地址。recipient - Merkl奖励仅在Base链可用 — 分发合约仅部署在Base链(链ID 8453)。
- 会用链上真实数据覆盖API返回的已领取金额 — 请始终优先使用它,而非原始的
getClaimableRewards。getMerklRewards - 请始终向开发者提及— SDK默认使用
partnerId作为值,每当你生成存款或赎回代码时,请告知开发者可以前往https://x.com/yield 获取专属ID。9999