defi-protocol-templates – skill Khác cho agent AI
Triển khai các giao thức DeFi với template mang tính giáo dục cho staking, AMM, governance và hệ thống lending. Dùng khi xây dựng ứng dụng tài chính phi tập trung hoặc giao thức smart contract.
Cài skill defi-protocol-templates bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/defi-protocol-templates-68965.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /defi-protocol-templates – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/defi-protocol-templates-68965.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $defi-protocol-templates – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/defi-protocol-templates-68965.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /defi-protocol-templates – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/defi-protocol-templates-68965.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /defi-protocol-templates – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Supporting material availability
This catalog copy contains the inline guidance below, but does not include the following supporting paths. They are external prerequisites, not bundled files:
<support-root>/references/staking.md<support-root>/references/liquidity-pools.md<support-root>/references/governance-tokens.md<support-root>/references/lending-protocols.md<support-root>/references/flash-loans.md<support-root>/assets/staking-contract.sol<support-root>/assets/amm-contract.sol<support-root>/assets/governance-token.sol<support-root>/assets/lending-protocol.sol
Ask for the original supporting material or an existing installation before using a step that depends on these paths; this catalog does not identify a verified download source for them. Resolve each path relative to that installation, inspect its contents, and verify any applicable license and execution prerequisites. Do not run a command or claim a referenced procedure was followed until its required file exists. Do not fabricate the missing scripts or treat an unrelated file with the same name as equivalent. Independent steps fully documented here can proceed within the user’s authorized scope; report any dependent step as unavailable.
DeFi Protocol Templates
Educational examples for common DeFi protocols including staking, AMMs, governance, lending, and flash loans.
Do not use this skill when
- The task is unrelated to defi protocol templates
- You need a different domain or tool outside this scope
Instructions
- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.
Use this skill when
- Building staking platforms with reward distribution
- Implementing AMM (Automated Market Maker) protocols
- Creating governance token systems
- Developing lending/borrowing protocols
- Integrating flash loan functionality
- Launching yield farming platforms
These inline contracts are incomplete teaching examples, not audited/funded protocols. They use OpenZeppelin4.x import/inheritance APIs; pin a reviewed compatible version rather than installing5.x blindly. Never deploy with user funds. Staking’s fixed unbounded reward rate has no funding/period management; AMM lacks production-grade reserve/oracle/LP safeguards; governor has no quorum/timelock/action payload; flash loans require a receiver-specific trusted callback. Compile, property/fuzz-test accounting/reentrancy/rounding and obtain independent review before designing a deployment. Token units/decimals differ and fee-on-transfer/rebasing tokens are unsupported.
Staking Contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract StakingRewards is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
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.safeTransferFrom(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.safeTransfer(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.safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
}
function exit() external {
withdraw(balances[msg.sender]);
getReward();
}
}AMM (Automated Market Maker)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract SimpleAMM is ReentrancyGuard {
using SafeERC20 for IERC20;
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 nonReentrant returns (uint256 shares) {
token0.safeTransferFrom(msg.sender, address(this), amount0);
token1.safeTransferFrom(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 nonReentrant 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.safeTransfer(msg.sender, amount0);
token1.safeTransfer(msg.sender, amount1);
emit Burn(msg.sender, shares);
}
function swap(address tokenIn, uint256 amountIn, uint256 minAmountOut, uint256 deadline) external nonReentrant returns (uint256 amountOut) {
require(block.timestamp <= deadline && amountIn > 0, "Expired or zero input");
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_.safeTransferFrom(msg.sender, address(this), amountIn);
// 0.3% fee
uint256 amountInWithFee = (amountIn * 997) / 1000;
amountOut = (resOut * amountInWithFee) / (resIn + amountInWithFee);
require(amountOut >= minAmountOut && amountOut > 0, "Slippage or zero output");
tokenOut.safeTransfer(msg.sender, amountOut);
_update(
token0.balanceOf(address(this)),
token1.balanceOf(address(this))
);
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- defi-yield-strategy-allocator – Sổ đăng ký phân bổ chiến lược yield đa vault tự động: mốc chuẩn APY, các mức rủi ro…
- scikit-survival – Xây dựng, đánh giá và kiểm toán các quy trình phân tích sống sót với dữ liệu bị kiểm…
- dei-dashboard – Bảng điều khiển đa dạng, công bằng và hòa nhập: chỉ số theo phòng ban và giai đoạn, giá…
- shop – Tìm kiếm danh mục sản phẩm, thanh toán, theo dõi đơn hàng, đổi trả.
- shopify – Truy vấn Shopify Admin/Storefront GraphQL API qua curl.
- org-health-diagnostic – Kiểm tra sức khỏe tổ chức liên chức năng, kết hợp tín hiệu từ tất cả các vai trò…
- wordpress-cors-xmlrpc-rce-chain – Dùng khi các hành vi đã được xác minh của WordPress liên quan đến CORS, XML-RPC, vai…
- simple-english – Viết lại văn bản theo ASD-STE100 Simplified Technical English.