AgentSkillsCN

defi-program

在 Solana 上打造免租费的 DeFi 项目。利用 Anchor 宏或 Pinocchio 模式构建 AMM、金库、借贷协议;涵盖状态结构体、账户创建、CPI 调用、测试,以及客户端 SDK 特性实现。

SKILL.md
--- frontmatter
name: defi-program
description: "Build rent-free DeFi programs on Solana. Anchor macros or Pinocchio patterns for AMMs, vaults, lending. Covers state structs, account creation, CPI, testing, and client SDK trait implementation."

Rent-Free DeFi Programs

The Light SDK pays rent-exemption for PDAs, token accounts, and mints (98% cost savings). Program logic stays the same.

Workflow

  1. Clarify intent
    • Recommend plan mode, if it's not activated
    • Use AskUserQuestion to resolve blind spots
    • All questions must be resolved before execution
  2. Identify references and skills
    • Match task to domain references below
    • Locate relevant documentation and examples
  3. Write plan file (YAML task format)
    • Use AskUserQuestion for anything unclear — never guess or assume
    • Identify blockers: permissions, dependencies, unknowns
    • Plan must be complete before execution begins
  4. Execute
    • Use Task tool with subagents for parallel research
    • Subagents load skills via Skill tool
    • Track progress with TodoWrite
  5. When stuck: spawn subagent with Read, Glob, Grep, DeepWiki MCP access and load skills/ask-mcp

Domain References

AudienceReference
Anchor patternreferences/anchor.md
Pinocchio patternreferences/pinocchio.md
Client SDK (LightProgramInterface)references/client-sdk.md
Testingreferences/testing.md
CPI instructionsreferences/instructions.md
FAQreferences/faq.md

When to use which

CriteriaAnchorPinocchio
Frameworkanchor-lang 0.31, #[light_program] macropinocchio 0.9, LightProgramPinocchio derive
State structOption<CompressionInfo> + LightAccount deriveCompressionInfo (non-optional) + bytemuck::Pod + Zeroable + #[repr(C)]
Account creation#[light_account(init, ...)] attribute or CreateTokenAccountCpiCreateTokenAccountCpi, CreateMints batch pattern
Compress/decompress handlersAuto-generated by #[light_program] macroRoute ProgramAccounts::COMPRESS_ACCOUNTS_IDEMPOTENT etc. in entrypoint
Program ID constantNot needed (macro derives it)pub const ID: Pubkey = pubkey_array!(...) + LIGHT_CPI_SIGNER required
Dependencieslight-sdk, light-sdk-macros, light-token, light-anchor-spllight-account-pinocchio, light-token-pinocchio, bytemuck

Hot vs Cold Model

After extended inactivity (multiple epochs without writes), accounts auto-compress to cold state. Programs only interact with hot accounts. Clients load cold accounts back on-chain via create_load_instructions.

Hot (active)Cold (inactive)
StorageOn-chainCompressed
LatencyNormal+0-200ms
Tx sizeNormal+100-2400 bytes
CUNormal+15k-400k CU
Program codeNo changeNo change

The hot path has zero overhead.

External References

ResourceLink
Anchor AMM referencecp-swap-reference
Pinocchio swap referencepinocchio-swap