Master DeFi protocol development including AMMs, lending, yield, and oracles
Build and secure DeFi protocols including AMMs, lending markets, yield optimizers, and oracle integrations. Use when developing decentralized exchanges, collateralized lending systems, or implementing price feeds with proper security measures.
/plugin marketplace add pluginagentmarketplace/custom-plugin-blockchain/plugin install custom-plugin-blockchain@pluginagentmarketplace-blockchainThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyMaster 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 |
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.