defi-protocol-templates — скилл для Claude Code: DeFi-шаблоны
Скилл даёт Solidity-шаблоны для стейкинга и AMM, а также систем управления и flash loan. Пригодится при создании DeFi-протокола.
/plugin marketplace add wshobson/agents
/plugin install blockchain-web3@claude-code-workflowsЧто делает defi-protocol-templates
Внутри есть примеры контрактов на Solidity для стейкинга с распределением наград и AMM с добавлением ликвидности, обменом и долями поставщиков. В описании также перечислены шаблоны для управления токенами и flash loan.
Примеры используют OpenZeppelin для ERC-20 и защиты от повторного входа в контракт стейкинга. Это стартовые шаблоны, а не готовая спецификация протокола: перед запуском проверьте логику под свой проект. Ставьте скилл, если пишете DeFi-контракты на Solidity; для задач вне этой области он не нужен.
Какие задачи решает
- создать контракт стейкинга с выдачей наград
- добавить AMM с пулами ликвидности и обменом токенов
- набросать систему управления с токенами
- подключить механику flash loan
Примеры запросов агенту
- Создай контракт стейкинга с распределением наград по шаблону defi-protocol-templates.
- Добавь в проект AMM с добавлением и снятием ликвидности.
- Подготовь шаблон для DeFi-управления и объясни, что нужно адаптировать.
Как установить defi-protocol-templates
1Через маркетплейс плагинов
/plugin marketplace add wshobson/agents/plugin install blockchain-web3@claude-code-workflowsКоманда ставит плагин blockchain-web3 целиком, со всеми его скиллами
2Через Skills CLI (Vercel)
npx skills add wshobson/agents --skill defi-protocol-templates -a claude-code3Вручную: положить файлы
~/.claude/skills/defi-protocol-templates/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/defi-protocol-templates/
1Через Skills CLI (Vercel)
npx skills add wshobson/agents --skill defi-protocol-templates -a codex2Вручную: положить файлы
.agents/skills/defi-protocol-templates/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add wshobson/agents --skill defi-protocol-templates -a cursor2Вручную: положить файлы
.cursor/skills/defi-protocol-templates/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install wshobson/agents defi-protocol-templates2Вручную: положить файлы
.github/skills/defi-protocol-templates/SKILL.mdКомандой платформы
gemini skills install https://github.com/wshobson/agents --path plugins/blockchain-web3/skills/defi-protocol-templatesВручную: положить файлы
.devin/skills/defi-protocol-templates/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Claude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
Из того же набора213
Весь набор →Похожие
Вопросы о defi-protocol-templates
Как установить defi-protocol-templates в Claude Code?
Выполните npx skills add wshobson/agents --skill defi-protocol-templates -a claude-code. Файл скилла находится в ~/.claude/skills/defi-protocol-templates/SKILL.md.
Что делает defi-protocol-templates?
Предоставляет Solidity-шаблоны для стейкинга, AMM, управления токенами и flash loan. Пример стейкинга учитывает награды пользователей, а AMM поддерживает ликвидность и обмен.
Какие библиотеки используются в шаблонах?
Контракт стейкинга импортирует IERC20, ReentrancyGuard и Ownable из OpenZeppelin. В примере AMM используется IERC20.
Исходный текст
SKILL.md · MIT
---
name: defi-protocol-templates
description: Implement DeFi protocols with production-ready templates for staking, AMMs, governance, and flash loans. Use when building decentralized finance applications or smart contract protocols.
---
# DeFi Protocol Templates
Production-ready templates for common DeFi protocols including staking, AMMs, governance, and flash loans.
## When to Use This Skill
- Building staking platforms with reward distribution
- Implementing AMM (Automated Market Maker) protocols
- Creating governance token systems
- Integrating flash loan functionality
## Staking Contract
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract StakingRewards is ReentrancyGuard, Ownable {
IERC20 public stakingToken;
IERC20 public rewardsToken;
uint256 public rewardRate = 100; // Rewards per second
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
mapping(address => uint256) public balances;
uint256 private _totalSupply;
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(address indexed user, uint256 reward);
constructor(address _stakingToken, address _rewardsToken) {
stakingToken = IERC20(_stakingToken);
rewardsToken = IERC20(_rewardsToken);
}
modifier updateReward(address account) {
rewardPerTokenStored = rewardPerToken();
lastUpdateTime = block.timestamp;
if (account != address(0)) {
rewards[account] = earned(account);
userRewardPerTokenPaid[account] = rewardPerTokenStored;
}
_;
}
function rewardPerToken() public view returns (uint256) {
if (_totalSupply == 0) {
return rewardPerTokenStored;
}
return rewardPerTokenStored +
((block.timestamp - lastUpdateTime) * rewardRate * 1e18) / _totalSupply;
}
function earned(address account) public view returns (uint256) {
return (balances[account] *
(rewardPerToken() - userRewardPerTokenPaid[account])) / 1e18 +
rewards[account];
}
function stake(uint256 amount) external nonReentrant updateReward(msg.sender) {
require(amount > 0, "Cannot stake 0");
_totalSupply += amount;
balances[msg.sender] += amount;
stakingToken.transferFrom(msg.sender, address(this), amount);
emit Staked(msg.sender, amount);
}
function withdraw(uint256 amount) public nonReentrant updateReward(msg.sender) {
require(amount > 0, "Cannot withdraw 0");
_totalSupply -= amount;
balances[msg.sender] -= amount;
stakingToken.transfer(msg.sender, amount);
emit Withdrawn(msg.sender, amount);
}
function getReward() public nonReentrant updateReward(msg.sender) {
uint256 reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
rewardsToken.transfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
}
function exit() external {
withdraw(balances[msg.sender]);
getReward();
}
}
```
## AMM (Automated Market Maker)
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract SimpleAMM {
IERC20 public token0;
IERC20 public token1;
uint256 public reserve0;
uint256 public reserve1;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
event Mint(address indexed to, uint256 amount);
event Burn(address indexed from, uint256 amount);
event Swap(address indexed trader, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out);
constructor(address _token0, address _token1) {
token0 = IERC20(_token0);
token1 = IERC20(_token1);
}
function addLiquidity(uint256 amount0, uint256 amount1) external returns (uint256 shares) {
token0.transferFrom(msg.sender, address(this), amount0);
token1.transferFrom(msg.sender, address(this), amount1);
if (totalSupply == 0) {
shares = sqrt(amount0 * amount1);
} else {
shares = min(
(amount0 * totalSupply) / reserve0,
(amount1 * totalSupply) / reserve1
);
}
require(shares > 0, "Shares = 0");
_mint(msg.sender, shares);
_update(
token0.balanceOf(address(this)),
token1.balanceOf(address(this))
);
emit Mint(msg.sender, shares);
}
function removeLiquidity(uint256 shares) external returns (uint256 amount0, uint256 amount1) {
uint256 bal0 = token0.balanceOf(address(this));
uint256 bal1 = token1.balanceOf(address(this));
amount0 = (shares * bal0) / totalSupply;
amount1 = (shares * bal1) / totalSupply;
require(amount0 > 0 && amount1 > 0, "Amount0 or amount1 = 0");
_burn(msg.sender, shares);
_update(bal0 - amount0, bal1 - amount1);
token0.transfer(msg.sender, amount0);
token1.transfer(msg.sender, amount1);
emit Burn(msg.sender, shares);
}
function swap(address tokenIn, uint256 amountIn) external returns (uint256 amountOut) {
require(tokenIn == address(token0) || tokenIn == address(token1), "Invalid token");
bool isToken0 = tokenIn == address(token0);
(IERC20 tokenIn_, IERC20 tokenOut, uint256 resIn, uint256 resOut) = isToken0
? (token0, token1, reserve0, reserve1)
: (token1, token0, reserve1, reserve0);
tokenIn_.transferFrom(msg.sender, address(this), amountIn);
// 0.3% fee
uint256 amountInWithFee = (amountIn * 997) / 1000;
amountOut = (resOut * amountInWithFee) / (resIn + amountInWithFee);
tokenOut.transfer(msg.sender, amountOut);
_update(
token0.balanceOf(address(this)),
token1.balanceOf(address(this))
);
emit Swap(msg.sender, isToken0 ? amountIn : 0, isToken0 ? 0 : amountIn, isToken0 ? 0 : amountOut, isToken0 ? amountOut : 0);
}
function _mint(address to, uint256 amount) private {
balanceOf[to] += amount;
totalSupply += amount;
}
function _burn(address from, uint256 amount) private {
balanceOf[from] -= amount;
totalSupply -= amount;
}
function _update(uint256 res0, uint256 res1) private {
reserve0 = res0;
reserve1 = res1;
}
function sqrt(uint256 y) private pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
function min(uint256 x, uint256 y) private pure returns (uint256) {
return x <= y ? x : y;
}
}
```
## Additional patterns and templates
More detailed templates and worked examples live in `references/details.md`. Read that file for the full pattern library.
© Seth Hobson · MIT · wshobson/agents