defi-protocol-templates

Implements Solidity smart contract templates for staking, AMMs, governance, and flash loans.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill defi-protocol-templates-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: defi-protocol-templates
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/defi-protocol-templates
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill defi-protocol-templates-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @openzeppelin/contracts.

What problem does it solve? Writing DeFi smart contracts from scratch is error-prone and time-consuming, with risks like reentrancy bugs and incorrect reward math. This Skill provides ready-to-adapt Solidity contract templates for the most common DeFi protocol patterns. ## Core Features & Use Cases - Staking Rewards Contract: Implements token staking with time-based reward distribution, reentrancy protection, and per-user reward accounting using OpenZeppelin libraries. - AMM and Liquidity Pools: Provides a constant-product automated market maker with liquidity minting/burning, a 0.3% swap fee, and LP share tracking. - Governance and Flash Loans: Includes an ERC20Votes-based governance token with proposal voting, plus a flash loan provider and receiver pattern with fee enforcement. - Use Case: When building a yield farming platform, use the staking template for reward distribution and the AMM template for the liquidity pool, then adapt constructor parameters and fee rates to your tokenomics. ## Quick Start Use the defi-protocol-templates skill to generate a staking rewards contract for my ERC20 token with a configurable reward rate.

Frequently Asked Questions about defi-protocol-templates

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a staking rewards contract in Solidity?

Use the StakingRewards template, which tracks rewardPerToken over time and credits users proportionally to their staked balance. It inherits OpenZeppelin ReentrancyGuard and Ownable, and you configure the staking token, rewards token, and rewardRate in the constructor.

How to implement an AMM with liquidity pools in Solidity?

The SimpleAMM template implements a constant-product market maker with addLiquidity, removeLiquidity, and swap functions. It mints LP shares proportional to deposits and applies a 0.3% fee on swaps using the 997/1000 formula.

Does the governance template support token-based voting?

Yes, the Governor contract uses OpenZeppelin ERC20Votes to read historical voting power via getPastVotes at the proposal start block. It enforces a proposal threshold, a voting period of 17280 blocks, and one vote per address.

How do flash loans work in Solidity smart contracts?

The FlashLoanProvider transfers tokens to a receiver contract, calls its executeOperation callback, then verifies the balance increased by the fee. The receiver must implement the IFlashLoanReceiver interface and approve repayment of amount plus the 0.09% fee.

What are the limitations of these DeFi contract templates?

These templates are educational starting points, not audited production code. The AMM lacks slippage protection and oracle integration, and the Governor execute function contains no actual proposal execution logic, so you must extend and audit them before deployment.