MR
Mayur Rathi
@mayurrathi
⭐ 5 GitHub stars

Defi Protocol Templates

Implement DeFi protocols with production-ready templates for staking, AMMs, governance, and lending systems. Use when building decentralized finance applications or smart contract protocols.

mkdir -p ./skills/defi-protocol-templates && curl -sfL https://raw.githubusercontent.com/mayurrathi/awesome-agent-skills/main/skills/defi-protocol-templates/SKILL.md -o ./skills/defi-protocol-templates/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# DeFi Protocol Templates


Production-ready templates 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.

- If detailed examples are required, open `resources/implementation-playbook.md`.


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


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 pub

🎯 Best For

  • UI designers
  • Product designers
  • Claude users
  • Knowledge workers
  • Remote teams

💡 Use Cases

  • Generating component mockups
  • Creating design system tokens
  • Using Defi Protocol Templates in daily workflow
  • Automating repetitive productivity tasks

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Defi Protocol Templates to Your Work

    Provide context for your task — paste source material, describe your audience, or share existing work to guide the AI.

  4. 4

    Review and Refine

    Edit the AI output for accuracy, tone, and completeness. Add human insight where the AI lacks context.

❓ Frequently Asked Questions

Does this work with Figma?

Some design skills integrate with Figma plugins. Check the Works With section for supported tools.

How do I install Defi Protocol Templates?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/defi-protocol-templates/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping usability testing

AI-generated designs should be validated with real users before development.

Not reading the full skill

Skills contain important context and edge cases beyond the quick start.

🔗 Related Skills