yo-protocol-react-sdk
ALWAYS use this skill when the user is working with React components or hooks that interact with Yo Protocol vaults, or imports from `@yo-protocol/react`. This skill covers the full React SDK: YieldProvider setup, query hooks (useVaultState, useVaultSnapshot, useUserPosition, useTokenBalance, useShareBalance, useAllowance, useMerklRewards, useLeaderboard, usePrices, etc.), action hooks (useDeposit, useRedeem, useApprove, useClaimMerklRewards), and migration from the old API (useVault→useVaultState, useUserBalance→useUserPosition, inputToken→token, account→owner, partnerId string→number, publicClient→publicClients). Trigger whenever the user mentions yo protocol React hooks, vault dashboard components, deposit/redeem UI flows, YieldProvider, useYoClient, @yo-protocol/react, yo-kit, or asks to build React components for yoETH, yoUSD, yoBTC, yoEUR, yoGOLD, or yoUSDT vaults. Also trigger when the user has broken imports or API changes after upgrading @yo-protocol/react. Do NOT use for CLI shell commands (use yo-protocol-cli) or server-side Node.js scripts without React (use yo-protocol-sdk).
- License 许可
- MIT
- 最近更新
- 2026-06-02
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- yo-protocol-react-sdk
- author
- yoprotocol
- source
- https://github.com/yoprotocol/yo-protocol-skills/tree/main/skills/yo-protocol-react
- homepage
- https://github.com/yoprotocol/yo-protocol-skills
- description
- ALWAYS use this skill when the user is working with React components or hooks that interact with Yo Protocol vaults, or imports from `@yo-protocol/react`. This skill covers the full React SDK: YieldProvider setup, query hooks (useVaultState, useVaultSnapshot, useUserPosition, useTokenBalance, useShareBalance, useAllowance, useMerklRewards, useLeaderboard, usePrices, etc.), action hooks (useDeposit, useRedeem, useApprove, useClaimMerklRewards), and migration from the old API (useVault→useVaultState, useUserBalance→useUserPosition, inputToken→token, account→owner, partnerId string→number, publicClient→publicClients). Trigger whenever the user mentions yo protocol React hooks, vault dashboard components, deposit/redeem UI flows, YieldProvider, useYoClient, @yo-protocol/react, yo-kit, or asks to build React components for yoETH, yoUSD, yoBTC, yoEUR, yoGOLD, or yoUSDT vaults. Also trigger when the user has broken imports or API changes after upgrading @yo-protocol/react. Do NOT use for CLI shell commands (use yo-protocol-cli) or server-side Node.js scripts without React (use yo-protocol-sdk).
02 资源文件 2
- 参考文档references/hooks-api.md13.7 KB
- 参考文档references/migration.md8.2 KB
03 SKILL.md 正文
Official Yo Protocol skill. Canonical repository: https://github.com/yoprotocol/yo-protocol-skills
@yo-protocol/react SDK
Architecture
Three layers:
- Provider —
YieldProviderwraps app, provides config.useYoClient()createsYoClientfrom@yo-protocol/core - Query hooks (32) — Read data via
useQuery+client.getX(). Return{ data, isLoading, isError, error, refetch } - Action hooks (4) — Mutate via
client.prepareX()+ wagmisendTransactionAsync(). Return{ mutate, step, hash, reset }
Core only prepares transactions (PreparedTransaction { to, data, value }). React sends them via wagmi. No walletClient needed.
Quick Start
// Provider setup
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<YieldProvider partnerId={9999} defaultSlippageBps={50}>
<App />
</YieldProvider>
</QueryClientProvider>
</WagmiProvider>
// Read vault state
const { vaultState } = useVaultState("yoUSD")
// Read user position
const { position } = useUserPosition("yoUSD") // auto-uses connected wallet
// Deposit with auto-approval and chain switching
const { deposit, step } = useDeposit({ vault: "yoUSD", slippageBps: 50 })
await deposit({ token: usdcAddress, amount: 1_000_000n, chainId: 8453 })
// Redeem with auto-approval
const { redeem, instant, assetsOrRequestId } = useRedeem({ vault: "yoUSD" })
await redeem(500_000n)
Migration
When encountering code using the old API, consult references/migration.md for the complete migration guide.
Quick migration checklist — search and replace:
| Find | Replace with |
|---|---|
useVault( |
useVaultState( |
useUserBalance( |
useUserPosition( |
useWeeklyRewards( |
useLeaderboard("weekly", |
useAllTimeRewards( |
useLeaderboard("allTime", |
{ vault: vaultState } |
{ vaultState } |
{ position } = useUserBalance |
{ position } = useUserPosition |
inputToken: (in deposit) |
token: |
account: (in deposit/redeem params) |
owner: |
fromChainId: / toChainId: |
chainId: |
partnerId: " |
partnerId: (number, not string) |
publicClient: (in createYoClient) |
publicClients: { [chainId]: |
useWalletClient import |
Remove — no longer needed |
walletClient param |
Remove — core only prepares txs |
Import updates
// Old imports to find and remove
import { useVault } from '*/useVault'
import { useUserBalance } from '*/useUserBalance'
import { useWeeklyRewards } from '*/useWeeklyRewards'
import { useAllTimeRewards } from '*/useAllTimeRewards'
// New imports
import { useVaultState } from '@yo-protocol/react'
import { useUserPosition } from '@yo-protocol/react'
import { useLeaderboard } from '@yo-protocol/react'
Hooks Reference
For complete API signatures and query keys, see references/hooks-api.md.
Hook → Client Method Map
Vault on-chain: useVaultState → getVaultState(), usePreviewDeposit → previewDeposit(), usePreviewRedeem → previewRedeem()
Vault API: useVaults → getVaults(), useVaultStats → getVaultStats(), useVaultSnapshot → getVaultSnapshot(), useVaultSnapshots → getVaultSnapshots(), useVaultHistory → getVaultYieldHistory() + getVaultTvlHistory(), useVaultTransactionHistory → getVaultHistory() | getVaultHistoryAllNetworks(), useGlobalVaultHistory → getGlobalVaultHistory(), useVaultPerformance → getVaultPerformance(), useVaultPercentile → getVaultPercentile(), usePerformanceBenchmark → getPerformanceBenchmark(), useVaultAllocations → getVaultAllocationsTimeSeries(), useVaultPendingRedeems → getVaultPendingRedeems(), useSharePriceHistory → getSharePriceHistory(), useTotalTvl → getTotalTvlTimeseries(), usePrices → getPrices()
User on-chain: useUserPosition → getUserPosition(), useUserPositions → getUserPositionsAllChains(), useTokenBalance → getTokenBalance(), useShareBalance → getShareBalance(), useAllowance → getAllowance()
User API: useUserHistory → getUserHistory(), useUserPerformance → getUserPerformance(), useUserSnapshots → getUserSnapshots(), useUserBalances → getUserBalances(), usePendingRedemptions → getPendingRedemptions(), useUserRewards → getUserRewardsByAsset()
Leaderboard: useLeaderboard("weekly"|"allTime", tokenAddr) → getWeeklyRewards() | getAllTimeRewards()
Merkl: useMerklCampaigns → getMerklCampaigns(), useMerklRewards → getClaimableRewards()
Actions: useDeposit → prepareDepositWithApproval(), useRedeem → prepareRedeemWithApproval(), useApprove → prepareApprove(), useClaimMerklRewards → prepareClaimMerklRewards()
Creating New Query Hooks
Follow this pattern for any new query hook:
import { useQuery } from '@tanstack/react-query'
import type { VaultId } from '@yo-protocol/core'
import type { Address } from 'viem'
import { useYoClient } from '../context'
import { resolveVaultAddress } from '../utils/vault'
export function useNewHook(vault: Address | VaultId, options?: { enabled?: boolean }) {
const { enabled = true } = options ?? {}
const client = useYoClient()
const vaultAddress = resolveVaultAddress(vault)
const { data, isLoading, isError, error, refetch } = useQuery({
queryKey: ['yo-new-hook', vaultAddress, client?.chainId],
queryFn: () => {
if (!client) throw new Error('Client not available')
return client.newMethod(vaultAddress)
},
enabled: enabled && !!client,
staleTime: 30_000,
})
return { result: data, isLoading, isError, error: error ?? null, refetch }
}
Rules:
- Query key prefix:
'yo-'for protocol hooks,'merkl-'for Merkl hooks - Always include
client?.chainIdas last key segment - Guard with
enabled && !!client(add!!userAddressfor user-specific hooks) - Return
error ?? null(not raw error) - User-scoped hooks should default to connected wallet via
useAccount()
Creating New Action Hooks
Follow this pattern — prepare+send with step tracking:
import { useCallback, useState } from 'react'
import { useSendTransaction, useWaitForTransactionReceipt, useAccount } from 'wagmi'
import { useQueryClient } from '@tanstack/react-query'
import { useYieldConfig, useYoClient } from '../context'
export function useNewAction(options: { onSubmitted?, onConfirmed?, onError? }) {
const client = useYoClient()
const { address: account } = useAccount()
const { sendTransactionAsync } = useSendTransaction()
const queryClient = useQueryClient()
const [hash, setHash] = useState<Hash>()
const [step, setStep] = useState<string>('idle')
const [error, setError] = useState<Error | null>(null)
const { isSuccess } = useWaitForTransactionReceipt({ hash, query: { enabled: !!hash } })
// Invalidate on confirmation
useEffect(() => {
if (isSuccess && hash) {
queryClient.invalidateQueries({ queryKey: ['yo-relevant-key'] })
options.onConfirmed?.(hash)
}
}, [isSuccess, hash])
const execute = useCallback(async (params) => {
const txs = await client.prepareX(params) // PreparedTransaction[]
for (const tx of txs) {
const h = await sendTransactionAsync({ to: tx.to, data: tx.data, value: tx.value })
if (tx !== txs[txs.length - 1]) await client.waitForTransaction(h)
}
}, [client, account, sendTransactionAsync])
return { execute, step, isLoading: step !== 'idle' && step !== 'success' && step !== 'error', hash, error, reset }
}
Key Types
// Client config
interface YoClientConfig {
chainId: SupportedChainId
partnerId?: number
publicClients?: Partial<Record<SupportedChainId, PublicClient>>
}
// Prepared transaction (core output, wagmi input)
interface PreparedTransaction { to: Address; data: Hex; value: bigint }
// Deposit params
interface PrepareDepositWithApprovalParams {
vault: Address; token: Address; owner: Address
recipient?: Address; amount: bigint
slippageBps?: number; partnerId?: number; minShares?: bigint; chainId?: number
}
// Redeem params
interface PrepareRedeemWithApprovalParams {
vault: Address; shares: bigint; owner: Address
recipient?: Address; slippageBps?: number; partnerId?: number; minAssetsOut?: bigint
}
// Vault state
interface VaultState {
address: Address; name: string; symbol: string; decimals: number
totalAssets: bigint; totalSupply: bigint; asset: Address; assetDecimals: number; exchangeRate: bigint
}
// User position
interface UserVaultPosition { shares: bigint; assets: bigint }
04 同仓库更多 Skills
yo-protocol-sdk
ALWAYS use this skill when the user writes TypeScript or JavaScript code that imports from `@yo-protocol/core`, uses `createYoClient`, or programmatically interacts with Yo Protocol vaults (yoETH, yoUSD, yoBTC, yoEUR, yoGOLD, yoUSDT) via the SDK. This skill covers the complete `@yo-protocol/core` SDK: client initialization (createYoClient, multi-chain publicClients, partnerId), vault reads (getVaultState, previewDeposit, previewRedeem, isPaused), user reads (getUserPosition, getShareBalance, getTokenBalance, getAllowance), prepared transactions (prepareDepositWithApproval, prepareRedeemWithApproval, prepareApprove), REST API queries (getVaultSnapshot, getVaultYieldHistory, getVaultTvlHistory, getUserHistory, getUserPerformance), Merkl reward claims (getClaimableRewards, prepareClaimMerklRewards), and utilities (parseTokenAmount, formatTokenAmount, VAULTS registry, gateway address). Trigger for Node.js scripts, backend services, bots, Safe/AA batch transaction builders, or any non-React TypeScript code that interacts with Yo Protocol. Also trigger when the user mentions the Yo gateway, PreparedTransaction, ERC-4626 vault interactions specific to Yo, or asks about vault addresses and token addresses per chain. Do NOT use for React hooks (use yo-protocol-react) or CLI shell commands (use yo-protocol-cli).
yo-protocol-cli
ALWAYS use this skill when the user mentions the YO Protocol CLI, the `yo` command, `@yo-protocol/cli`, or wants to interact with YO Protocol vaults (yoETH, yoUSD, yoBTC, yoEUR, yoGOLD, yoUSDT) from a shell script, terminal, or command line. The `yo` binary is an agent-first interface for ERC-4626 yield vaults on Ethereum (1), Base (8453), and Arbitrum (42161). It outputs structured JSON to stdout, never requires or accepts private keys, and produces unsigned calldata routed through the YO Gateway — ready for Safe/AA wallets and Base MCP `send_calls`. Use it for: building unsigned transactions (`yo prepare {approve,deposit,redeem,deposit-with-approval}`), reading positions and rewards (`yo position`, `yo portfolio`, `yo pending-redeems`, `yo rewards`, `yo yo-rewards`, `yo user-perf`), listing vaults and history (`yo vaults`, `yo vault`, `yo history`, `yo prices`, `yo yield`, `yo tvl`, `yo share-price`, `yo perf`, `yo leaderboard`), self-describing the command surface for an agent (`yo schema`), setting up `YO_RPC_URL`, or piping output into jq or other tools. Do NOT use for React hooks (`@yo-protocol/react`) or TypeScript SDK code (`@yo-protocol/core`) — those have dedicated skills.
yo-design
Create distinctive, production-grade React + Tailwind v4 interfaces in YO's dark-theme aesthetic (#000 background, #D6FF34 neon accent, Space Grotesk). Use this skill when the user asks to build web components, pages, dashboards, or applications for YO — including vault displays, DeFi interfaces, landing pages, or any UI that should follow the YO brand. Also use when the user mentions "YO theme", "YO style", "YO brand", or asks to style something with the neon-on-black look.
yo-base-mcp-plugin
Base MCP plugin for YO Protocol — ERC-4626 yield vaults with ERC-7540 async redemption on Ethereum (1), Base (8453), and Arbitrum (42161). Both deposit and withdraw route through the YO Gateway. Use when the user wants to view YO vaults, check positions/balances/rewards, deposit, request a redeem (instant or async), or claim Merkl rewards via Base MCP's `send_calls`. Triggers on YO Protocol, yoUSD, yoETH, yoBTC, yoEUR, yoGOLD, yoUSDT, "deposit into yo", "withdraw from yo", "yo vault", or "claim yo rewards".
risk-graph
Use Risk Graph's paid agent API (`/api/v1/agent/*`) — a DeFi risk-intelligence graph covering pools, assets, protocols, and chains, monetised via the [x402](https://x402.org) micropayment standard over USDC on Base mainnet (chain id `8453`). Every endpoint costs between $0.001 and $0.75 per call; the payer pays no gas — settlement is EIP-3009 `transferWithAuthorization` via the Coinbase CDP facilitator. Use whenever an agent needs structured, programmatic DeFi-risk data and is willing to pay per call: ranking pools by risk, comparing protocols, fetching chain-level risk signals, mapping dependency chains between pools/assets, extracting subgraphs around a node, explaining why a node is risky, or building an autonomous agent that consumes on-chain risk intelligence. Make sure to use this skill whenever the user mentions Risk Graph, risk-graph, DeFi risk score, pool risk, protocol risk, chain risk, asset risk, node risk explain, subgraph extraction, dependency chain, `/api/v1/agent/`, x402, paid agent API, USDC paywall, EIP-3009 paywall, Coinbase CDP facilitator, or building AI agents that consume on-chain risk intelligence — even if they don't explicitly name "Risk Graph". Triggers on mentions of Risk Graph, risk-graph API, DeFi risk scoring, x402 paywall, USDC micropayments on Base, agent-facing DeFi data, pool/protocol/asset/chain risk lookup, dependency-graph traversal, subgraph extraction, or paid `/api/v1/agent/*` endpoints.
yo-protocol-skills
Official Yo Protocol skills bundle (SDK, CLI, React)