重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
defi-protocols by pluginagentmarketplace/custom-plugin-blockchain
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-blockchain --skill defi-protocols掌握 DeFi 协议开发,包括 AMM 机制、借贷系统、收益优化和预言机集成。
# 调用此技能进行 DeFi 开发
Skill("defi-protocols", protocol_type="amm", chain="ethereum")
构建去中心化交易所:
创建借贷市场:
最大化回报:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
安全的价格数据源:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
library SwapMath {
uint256 constant FEE_NUMERATOR = 997;
uint256 constant FEE_DENOMINATOR = 1000;
/// @notice 计算恒定乘积 AMM 的输出金额
function getAmountOut(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) internal pure returns (uint256) {
uint256 amountInWithFee = amountIn * FEE_NUMERATOR;
uint256 numerator = amountInWithFee * reserveOut;
uint256 denominator = reserveIn * FEE_DENOMINATOR + amountInWithFee;
return numerator / denominator;
}
/// @notice 计算价格影响百分比(基点)
function getPriceImpact(
uint256 amountIn,
uint256 reserveIn
) internal pure returns (uint256) {
return (amountIn * 10000) / (reserveIn + amountIn);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceOracle {
AggregatorV3Interface public immutable priceFeed;
uint256 public constant STALENESS_THRESHOLD = 1 hours;
error StalePrice();
error InvalidPrice();
constructor(address feed) {
priceFeed = AggregatorV3Interface(feed);
}
function getPrice() external view returns (uint256) {
(, int256 price,, uint256 updatedAt,) = priceFeed.latestRoundData();
if (block.timestamp - updatedAt > STALENESS_THRESHOLD) {
revert StalePrice();
}
if (price <= 0) revert InvalidPrice();
return uint256(price);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@aave/v3-core/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
contract Arbitrage is FlashLoanSimpleReceiverBase {
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address,
bytes calldata
) external override returns (bool) {
// 在此处执行套利逻辑
// 偿还:金额 + 溢价
IERC20(asset).approve(address(POOL), amount + premium);
return true;
}
}
不变式: x * y = k
输出: dy = y - k/(x + dx)
价格: p = y/x
滑点: dx/(x + dx) * 100%
利用率: U = 借款 / (存款 + 借款)
借款利率: R = 基础利率 + 斜率 * U (当 U < 最优值时)
存款利率: R_存款 = R_借款 * U * (1 - 储备因子)
健康因子 = (抵押品 * 清算阈值) / 债务
当 健康因子 < 1 时触发清算
| 陷阱 | 风险 | 预防措施 |
|---|---|---|
| 现货价格预言机 | 闪电贷操纵 | 使用 TWAP |
| 无滑点检查 | 三明治攻击 | 强制执行最小输出 |
| 价格陈旧 | 错误清算 | 检查 updatedAt |
| 重入攻击 | 资金流失 | CEI 模式 + 防护 |
# 比较预言机与 DEX 价格
cast call $ORACLE "latestRoundData()" --rpc-url $RPC
cast call $POOL "slot0()" --rpc-url $RPC
添加最小输出强制执行:
require(amountOut >= minAmountOut, "Slippage exceeded");
| 协议 | 合约地址 |
|---|---|
| Uniswap V3 Router | 0xE592427A0AEce92De3Edee1F18E0157C05861564 |
| Aave V3 Pool | 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 |
| Chainlink ETH/USD | 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 |
04-defi-specialistsolidity-development, smart-contract-security| 版本 | 日期 | 变更 |
|---|---|---|
| 2.0.0 | 2025-01 | 生产级,包含数学和安全内容 |
| 1.0.0 | 2024-12 | 初始发布 |
每周安装次数
52
代码仓库
GitHub 星标数
1
首次出现
2026年1月24日
安全审计
安装于
opencode39
gemini-cli37
github-copilot34
codex34
amp29
cursor29
Master DeFi protocol development including AMM mechanics, lending systems, yield optimization, and oracle integration.
# Invoke this skill for DeFi development
Skill("defi-protocols", protocol_type="amm", chain="ethereum")
Build decentralized exchanges:
Create lending markets:
Maximize returns:
Secure price feeds:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
library SwapMath {
uint256 constant FEE_NUMERATOR = 997;
uint256 constant FEE_DENOMINATOR = 1000;
/// @notice Calculate output amount for constant product AMM
function getAmountOut(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) internal pure returns (uint256) {
uint256 amountInWithFee = amountIn * FEE_NUMERATOR;
uint256 numerator = amountInWithFee * reserveOut;
uint256 denominator = reserveIn * FEE_DENOMINATOR + amountInWithFee;
return numerator / denominator;
}
/// @notice Calculate price impact percentage (basis points)
function getPriceImpact(
uint256 amountIn,
uint256 reserveIn
) internal pure returns (uint256) {
return (amountIn * 10000) / (reserveIn + amountIn);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceOracle {
AggregatorV3Interface public immutable priceFeed;
uint256 public constant STALENESS_THRESHOLD = 1 hours;
error StalePrice();
error InvalidPrice();
constructor(address feed) {
priceFeed = AggregatorV3Interface(feed);
}
function getPrice() external view returns (uint256) {
(, int256 price,, uint256 updatedAt,) = priceFeed.latestRoundData();
if (block.timestamp - updatedAt > STALENESS_THRESHOLD) {
revert StalePrice();
}
if (price <= 0) revert InvalidPrice();
return uint256(price);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@aave/v3-core/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
contract Arbitrage is FlashLoanSimpleReceiverBase {
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address,
bytes calldata
) external override returns (bool) {
// Execute arbitrage logic here
// Repay: amount + premium
IERC20(asset).approve(address(POOL), amount + premium);
return true;
}
}
Invariant: x * y = k
Output: dy = y - k/(x + dx)
Price: p = y/x
Slippage: dx/(x + dx) * 100%
Utilization: U = borrows / (deposits + borrows)
Borrow Rate: R = base + slope * U (when U < optimal)
Supply Rate: R_supply = R_borrow * U * (1 - reserve_factor)
HF = (collateral * liquidation_threshold) / debt
Liquidation when HF < 1
| Pitfall | Risk | Prevention |
|---|---|---|
| Spot price oracle | Flash loan manipulation | Use TWAP |
| No slippage check | Sandwich attacks | Enforce min output |
| Stale prices | Wrong liquidations | Check updatedAt |
| Reentrancy | Fund drainage | CEI + guards |
# Compare oracle vs DEX price
cast call $ORACLE "latestRoundData()" --rpc-url $RPC
cast call $POOL "slot0()" --rpc-url $RPC
Add minimum output enforcement:
require(amountOut >= minAmountOut, "Slippage exceeded");
| Protocol | Contract |
|---|---|
| Uniswap V3 Router | 0xE592427A0AEce92De3Edee1F18E0157C05861564 |
| Aave V3 Pool | 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 |
| Chainlink ETH/USD | 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 |
04-defi-specialistsolidity-development, smart-contract-security| Version | Date | Changes |
|---|---|---|
| 2.0.0 | 2025-01 | Production-grade with math, security |
| 1.0.0 | 2024-12 | Initial release |
Weekly Installs
52
Repository
GitHub Stars
1
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode39
gemini-cli37
github-copilot34
codex34
amp29
cursor29
CoinGecko API 集成 - 实时加密货币价格、市场数据与区块链分析工具
4,200 周安装
高级研究工程师AI助手 | 严谨代码实现与学术分析 | 高性能计算与算法优化
302 周安装
价值投资股票分析工具 - 巴菲特/段永平投资理念与五维分析框架
304 周安装
Alchemy API 集成指南:AI 代理使用 API 密钥访问区块链数据与服务的完整教程
306 周安装
Tailwind CSS 开发指南:v3 特性、深色模式、Flexbox/Grid 布局与最佳实践
308 周安装
QQ Bot 智能定时提醒设置与管理教程 - 支持私聊群聊的AI助手
304 周安装
CloudFormation 转 Pulumi 迁移指南:完整工作流与关键成功要求
305 周安装