Skip to content
Back to skills

Defi Smart Contracts

ASecurity

Use when building DeFi smart contracts.

  • 2 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 10, 2026
ai-agentssecurity

Security analysis

A100/100

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill defi-smart-contracts --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Defi Smart Contracts?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Defi Smart Contracts
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-defi-smart-contracts/badge)](https://www.skillsdirectory.com/skills/loopyluci-defi-smart-contracts)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: defi-smart-contracts
description: "Use when building DeFi smart contracts."
version: 1.0.0
author: Hermes Agent
license: MIT
metadata:
  hermes:
    tags: [DeFi, smart-contracts, AMM, lending, staking, yield, Solidity]
    related_skills: [blockchain-development-solidity, tokenomics-design, zero-knowledge-proofs, agent-economics-markets]
---

# DeFi Smart Contracts

Building DeFi smart contracts — from AMMs and lending protocols through staking, yield optimization, and security patterns for DeFi.

## When to Use

- Building decentralized exchange (DEX) contracts
- Implementing lending/borrowing protocols
- Staking and yield farming contracts
- DeFi security (flash loan attacks, oracle manipulation)

## DeFi Patterns

```solidity
// Simple AMM (constant product)
contract ConstantProductAMM {
    uint public reserve0;
    uint public reserve1;
    
    function swap(uint amountIn, address tokenIn) external returns (uint) {
        (uint r0, uint r1) = tokenIn == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
        uint amountOut = (amountIn * r1) / (r0 + amountIn);  // x*y=k invariant
        _transfer(tokenOut, amountOut);
        (reserve0, reserve1) = tokenIn == token0 ? 
            (r0 + amountIn, r1 - amountOut) : (r0 - amountOut, r1 + amountIn);
        return amountOut;
    }
    
    // Flash loan pattern
    function flashLoan(uint amount, address token) external {
        uint balanceBefore = IERC20(token).balanceOf(address(this));
        IERC20(token).transfer(msg.sender, amount);
        IFlashBorrower(msg.sender).execute();  // arbitrary callback
        require(IERC20(token).balanceOf(address(this)) >= balanceBefore, "Not repaid");
    }
}
```

## Verification Checklist

- [ ] Contract audited by third-party firm
- [ ] Oracle manipulation resistance (TWAP or multiple oracles)
- [ ] Flash loan attack vectors mitigated
- [ ] Reentrancy guard on all state-changing functions
- [ ] Access control (admin, pause, emergency functions)
- [ ] Economic parameters validated (fees, slippage, reserves)
- [ ] Testnet deployment verified before mainnet

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.