catalog/repos/0xlayerghost--solidity-agent-kit.md

294 lines
12 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Solidity智能合约AI技能包
`Solidity` `智能合约` `AI编程助手` `DeFi安全` `Foundry` `EVM`
<div align="center">
# solidity-agent-kit
**经过实战检验的 Solidity 智能合约开发 AI 代理技能集**
*为你的编程代理装备专业级 Solidity 实践 —— 从编码规范到 DeFi 安全。*
<br/>
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat&logo=opensourceinitiative&logoColor=white)](https://opensource.org/licenses/MIT)
[![Solidity](https://img.shields.io/badge/Solidity-%5E0.8.20-363636?style=flat&logo=solidity&logoColor=white)](https://soliditylang.org)
[![Foundry](https://img.shields.io/badge/built%20with-Foundry-orange?style=flat&logo=ethereum&logoColor=white)](https://getfoundry.sh)
[![Skills](https://img.shields.io/badge/9%20skills-blueviolet?style=flat&logo=bookstack&logoColor=white)](https://skills.sh/0xlayerghost/solidity-agent-kit)
[![Agents](https://img.shields.io/badge/8%2B%20agents-informational?style=flat&logo=probot&logoColor=white)](#supported-agents)
<br/>
**EVM 兼容链**
[![Ethereum](https://img.shields.io/badge/Ethereum-3C3C3D?style=flat&logo=ethereum&logoColor=white)](https://ethereum.org)
[![Polygon](https://img.shields.io/badge/Polygon-8247E5?style=flat&logo=polygon&logoColor=white)](https://polygon.technology)
[![Arbitrum](https://img.shields.io/badge/Arbitrum-28A0F0?style=flat&logo=ethereum&logoColor=white)](https://arbitrum.io)
[![Optimism](https://img.shields.io/badge/Optimism-FF0420?style=flat&logo=optimism&logoColor=white)](https://optimism.io)
[![Base](https://img.shields.io/badge/Base-0052FF?style=flat&logo=coinbase&logoColor=white)](https://base.org)
[![Avalanche](https://img.shields.io/badge/Avalanche-E84142?style=flat&logo=avalanche&logoColor=white)](https://avax.network)
[![BNB Chain](https://img.shields.io/badge/BNB%20Chain-F0B90B?style=flat&logo=binance&logoColor=black)](https://bnbchain.org)
[![zkSync](https://img.shields.io/badge/zkSync-1E69FF?style=flat&logo=ethereum&logoColor=white)](https://zksync.io)
[![Linea](https://img.shields.io/badge/Linea-121212?style=flat&logo=consensys&logoColor=white)](https://linea.build)
</div>
---
## 什么是 solidity-agent-kit
`solidity-agent-kit` 是一套 **AI 代理技能集合**,为你的编程代理注入专业级 Solidity 开发知识。无需每次手写提示词,也不必寄希望于 AI 代理自行了解最佳实践 —— 一次安装,即可在所有项目中获得一致、经过实战验证的开发行为。
> 为你的 AI 编程代理装备经过实战检验的 Solidity 开发实践 —— 从编码规范到 DeFi 安全。
```
未使用 solidity-agent-kit 使用 solidity-agent-kit
───────────────────────── ─────────────────────────
AI 代理直接写代码... AI 代理调用 /solidity-coding
❌ 风格不一致 ✅ 强制 NatSpec、自定义错误
❌ 遗漏安全检查 ✅ 执行 /solidity-security 规则
❌ 无部署验证流程 ✅ 强制部署前检查清单
❌ 测试覆盖率低 ✅ 模糊测试、100% 分支覆盖
❌ 存在 DeFi 漏洞 ✅ 反闪电贷、反鲸鱼操控保护
```
---
## 目录
- [安装](#安装)
- [内置技能](#内置技能)
- [EVM 链支持](#evm-链支持)
- [架构说明](#架构说明)
- [支持的代理](#支持的代理)
- [技术栈](#技术栈)
- [项目结构](#项目结构)
- [许可证](#许可证)
---
## 安装
### 快速安装
```bash
# 交互模式 —— 选择要安装的技能
npx skills add 0xlayerghost/solidity-agent-kit
# 一次性安装所有技能(无需确认)
npx skills add 0xlayerghost/solidity-agent-kit -y
```
自动检测机器上所有 AI 代理并逐一安装。会创建 `.agents/``.claude/``.cursor/``.windsurf/` 目录 —— `.agents/` 存放实际文件,其余为符号链接。
### 指定代理安装
```bash
# Claude Code
npx skills add 0xlayerghost/solidity-agent-kit -y --agent claude-code
# Cursor
npx skills add 0xlayerghost/solidity-agent-kit -y --agent cursor
# Windsurf
npx skills add 0xlayerghost/solidity-agent-kit -y --agent windsurf
```
### 安装后配置
`CLAUDE.md` 模板复制到项目根目录,技能将自动触发 —— 无需手动输入 `/斜杠命令`
```bash
curl -sL https://raw.githubusercontent.com/0xlayerghost/solidity-agent-kit/main/CLAUDE.md.template -o CLAUDE.md
```
或手动将 [`CLAUDE.md.template`](./CLAUDE.md.template) 复制为项目根目录下的 `CLAUDE.md`
> `CLAUDE.md` 在每次 Claude Code 会话启动时自动加载,告诉代理**何时**自动调用各项技能。
添加到 `.gitignore` 保持仓库整洁:
```gitignore
# 代理技能(本地安装,不提交到仓库)
.agents/
.claude/
.cursor/
.trae/
.windsurf/
```
### 卸载
```bash
npx skills remove 0xlayerghost/solidity-agent-kit
```
---
## 内置技能
| # | 技能 | 触发时机 | 说明 | 链接 |
|---|------|----------|------|------|
| 1 | **solidity-coding** | 编写/编辑 `.sol` 文件 | Pragma 声明、命名规范、NatSpec 注释、自定义错误、反模式、OZ 导入 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/solidity-coding) |
| 2 | **solidity-security** | 编写/编辑任意合约 | 私钥保护、访问控制、重入防护、Gas 限制 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/solidity-security) |
| 3 | **solidity-testing** | 编写/编辑 `*.t.sol` | 测试布局、覆盖率 ≥90%、模糊测试、Foundry 不变量测试 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/solidity-testing) |
| 4 | **solidity-deploy** | 编写 `*.s.sol` / 部署合约 | 部署前检查清单、环境变量、构造参数、部署后工作流 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/solidity-deploy) |
| 5 | **solidity-debug** | 调试失败交易 | Cast 调用数据解码、回滚分析、Gas 诊断、追踪读取 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/solidity-debug) |
| 6 | **solidity-audit** | 安全审计 | 手动审计检查清单存储、访问控制、算术运算、ERC 兼容性 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/solidity-audit) |
| 7 | **defi-security** | DeFi 协议开发 | 反鲸鱼、反闪电贷、上线检查清单、紧急暂停、MEV 防护 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/defi-security) |
| 8 | **git-workflow** | 提交/PR 前 | 约定式提交、分支命名、Solidity 项目 PR 模板 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/git-workflow) |
| 9 | **claude-code-usage** | 每次 `/clear` 后 | 上下文恢复、子代理策略、计划模式、TodoWrite 使用模式 | [查看](https://skills.sh/0xlayerghost/solidity-agent-kit/claude-code-usage) |
---
## EVM 链支持
技能专为 **EVM 兼容链**设计,与 Foundry 多链工具链开箱即用:
```
主网 / L2 测试网
────────────── ──────────────
Ethereum (ETH) Sepolia
Polygon (MATIC) Mumbai
Arbitrum One Arbitrum Sepolia
Optimism OP Sepolia
Base Base Sepolia
Avalanche C-Chain Fuji
BNB Smart Chain BSC Testnet
zkSync Era zkSync Sepolia
Linea Linea Sepolia
```
部署和调试技能中涵盖了链特定的 `foundry.toml` 配置、RPC URL 管理及 `cast` 命令。
---
## 架构说明
```
你的项目
├── CLAUDE.md ◄── 技能自动触发规则
└── .agents/
└── 0xlayerghost/
└── solidity-agent-kit/
├── solidity-coding/ ──► 强制代码风格与 NatSpec
├── solidity-security/ ──► 访问控制与重入防护
├── solidity-testing/ ──► 模糊测试 + 不变量覆盖
├── solidity-deploy/ ──► 部署前后检查清单
├── solidity-debug/ ──► 基于 Cast 的交易分析
├── solidity-audit/ ──► 手动安全审计
├── defi-security/ ──► DeFi 特定攻击向量
├── git-workflow/ ──► 约定式提交与 PR
└── claude-code-usage/ ──► 代理上下文策略
AI 代理工作流:
─────────────────────────────────────────────────────────────
用户请求 ──► CLAUDE.md 检测任务类型
┌────────────┼────────────┐
▼ ▼ ▼
编写 .sol 测试 .t.sol 部署 .s.sol
│ │ │
/solidity-coding /solidity- /solidity-deploy
/solidity-security testing /defi-security
│ │ │
└────────────┴────────────┘
forge build
forge test
✅ 验证通过
```
---
## 支持的代理
| 代理 | 状态 | 备注 |
|------|------|------|
| **Claude Code** | ✅ 完整支持 | 最佳体验 —— CLAUDE.md 自动触发 |
| **Cursor** | ✅ 完整支持 | `.cursor/rules` 集成 |
| **Windsurf** | ✅ 完整支持 | `.windsurf/rules` 集成 |
| **Trae** | ✅ 支持 | `.trae` 集成 |
| **OpenCode** | ✅ 支持 | — |
| **Gemini CLI** | ✅ 支持 | — |
| **GitHub Copilot** | 🚧 部分支持 | 需手动调用 |
| **Codex CLI** | ✅ 支持 | — |
---
## 技术栈
| 工具 | 版本 | 用途 |
|------|------|------|
| **Solidity** | `^0.8.20` | 智能合约语言 |
| **Foundry** | 最新版 | 构建、测试、部署(`forge``cast``anvil` |
| **OpenZeppelin** | `4.9.x` | 安全合约标准ERC20/721/1155/Governor |
| **Slither** | 最新版 | 静态分析90+ 漏洞检测器) |
| **skills.sh** | 最新版 | 技能包管理与分发 |
---
## 项目结构
```
solidity-agent-kit/
├── CLAUDE.md.template ← 复制到项目根目录并重命名为 CLAUDE.md
├── skills/
│ ├── solidity-coding/ ← 编码规范与命名约定
│ │ └── SKILL.md
│ ├── solidity-security/ ← 安全最佳实践
│ │ └── SKILL.md
│ ├── solidity-testing/ ← 测试组织与覆盖率
│ │ └── SKILL.md
│ ├── solidity-deploy/ ← 部署工作流与检查
│ │ └── SKILL.md
│ ├── solidity-debug/ ← 链上交易调试
│ │ └── SKILL.md
│ ├── solidity-audit/ ← 手动安全审计检查清单
│ │ └── SKILL.md
│ ├── defi-security/ ← DeFi 特定攻击防护
│ │ └── SKILL.md
│ ├── git-workflow/ ← Solidity 项目 Git 规范
│ │ └── SKILL.md
│ └── claude-code-usage/ ← AI 代理上下文策略
│ └── SKILL.md
├── openai/
├── LICENSE
└── README.md
```
---
## 适用人群
- 使用 **Foundry**`forge``cast``anvil`)的 Solidity 开发者
- 构建 **DeFi 协议**、NFT 项目和 DAO 治理的团队
- 希望获得一致、安全输出的 **AI 编程代理**用户
- 使用 Slither + 手动检查清单进行**自动化审计**的安全工程师
- 在 **EVM 兼容链**上部署合约的任何开发者
---
## 许可证
MIT —— 详见 [LICENSE](./LICENSE)
---
<div align="center">
**由 [0xlayerghost](https://github.com/0xlayerghost) 构建**
*区块链与 Solidity 工程师*
[![GitHub](https://img.shields.io/badge/GitHub-0xlayerghost-181717?style=flat&logo=github)](https://github.com/0xlayerghost)
[![skills.sh](https://img.shields.io/badge/skills.sh-profile-blue?style=flat&logo=bookstack&logoColor=white)](https://skills.sh/0xlayerghost)
*如果这个项目帮助你交付了更安全的合约,请给一个 ⭐*
</div>