Agent skill

Yield Vault Patterns

by ccashwell in ccashwell/evm-cortex

A skill your agent uses when building ERC-4626 tokenized vaults, yield aggregators, or share-based deposit/withdraw systems.

MITAuto-check passed

Install Yield Vault Patterns

skills CLI
$ npx skills add ccashwell/evm-cortex --skill yield-vault-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ccashwell/evm-cortex yield-vault-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ccashwell/evm-cortex.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/yield-vault-patterns .claude/skills/yield-vault-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
yield-vault-patterns
GitHub stars
131
Token cost
~1.8k tokens
SKILL.md length
181 words
Files
1
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when building ERC-4626 tokenized vaults, yield aggregators, or share-based deposit/withdraw systems.

  • Works in 3 steps: Deposit 1 wei to get 1 share → Donate a large amount directly to… → Next depositor gets 0 shares due to…
  • Building ERC-4626 tokenized vaults
  • SKILL.md covers Overview, Share Price Math, Complete ERC-4626 Implementation and First Depositor Attack…, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Yield Vault Patterns is an agent skill from ccashwell/evm-cortex. Use when building ERC-4626 tokenized vaults, yield aggregators, or share-based deposit/withdraw systems. Covers share math, rounding, first depositor attack mitigation, and complete implementation patterns.

Its SKILL.md is about 1.8k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

The repository describes itself as: Ethereum protocol engineering squad for AI coding assistants. The licence is MIT.

When your agent uses it

  • Building ERC-4626 tokenized vaults
  • Yield aggregators
  • Share-based deposit/withdraw systems

Example prompts

  • “/yield-vault-patterns”

Workflow steps

3 steps, taken from the first numbered list in SKILL.md.

  1. Deposit 1 wei to get 1 share
  2. Donate a large amount directly to inflate totalAssets
  3. Next depositor gets 0 shares due to rounding

What it can do on your machine

Read from SKILL.md and the folder at commit f8f3301. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are solidity).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Yield Vault Patterns loads about 1.8k tokens when it runs. Until then it costs about 57 tokens; SKILL.md has 181 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~57
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ccashwell/evm-cortex at commit f8f3301, republished under its MIT licence (© ccashwell). 181 words, ~1,768 tokens.

Download SKILL.mdSave it as .claude/skills/yield-vault-patterns/SKILL.md (or your agent's skills folder).
name
yield-vault-patterns
description
Use when building ERC-4626 tokenized vaults, yield aggregators, or share-based deposit/withdraw systems. Covers share math, rounding, first depositor attack mitigation, and complete implementation patterns.

ERC-4626 Tokenized Vault Patterns

Overview

ERC-4626 standardizes yield-bearing vaults. Depositors receive shares proportional to their deposit. Shares appreciate as the vault earns yield.

Core Invariant: shares * totalAssets / totalShares = user's assets

Share Price Math

deposit:   shares = assets * totalSupply / totalAssets    (round DOWN)
mint:      assets = shares * totalAssets / totalSupply     (round UP)
withdraw:  shares = assets * totalSupply / totalAssets     (round UP)
redeem:    assets = shares * totalAssets / totalSupply     (round DOWN)

Rounding rule: Always round in favor of the vault (against the user) to prevent value extraction.

Complete ERC-4626 Implementation

solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";

contract YieldVault is ERC20, IERC4626 {
    using SafeERC20 for IERC20;
    using Math for uint256;

    IERC20 public immutable asset_;
    uint8 private immutable _decimals;

    // Virtual shares/assets to prevent first depositor attack
    uint256 internal constant VIRTUAL_SHARES = 1e3;
    uint256 internal constant VIRTUAL_ASSETS = 1;

    constructor(IERC20 _asset, string memory name, string memory symbol)
        ERC20(name, symbol)
    {
        asset_ = _asset;
        _decimals = ERC20(address(_asset)).decimals();
    }

    function asset() external view returns (address) { return address(asset_); }
    function decimals() public view override returns (uint8) { return _decimals; }

    function totalAssets() public view returns (uint256) {
        return asset_.balanceOf(address(this));
    }

    function convertToShares(uint256 assets) public view returns (uint256) {
        return assets.mulDiv(
            totalSupply() + VIRTUAL_SHARES,
            totalAssets() + VIRTUAL_ASSETS,
            Math.Rounding.Floor
        );
    }

    function convertToAssets(uint256 shares) public view returns (uint256) {
        return shares.mulDiv(
            totalAssets() + VIRTUAL_ASSETS,
            totalSupply() + VIRTUAL_SHARES,
            Math.Rounding.Floor
        );
    }

    function maxDeposit(address) external pure returns (uint256) {
        return type(uint256).max;
    }

    function maxMint(address) external pure returns (uint256) {
        return type(uint256).max;
    }

    function maxWithdraw(address owner) external view returns (uint256) {
        return convertToAssets(balanceOf(owner));
    }

    function maxRedeem(address owner) external view returns (uint256) {
        return balanceOf(owner);
    }

    function previewDeposit(uint256 assets) public view returns (uint256) {
        return convertToShares(assets);
    }

    function previewMint(uint256 shares) public view returns (uint256) {
        return shares.mulDiv(
            totalAssets() + VIRTUAL_ASSETS,
            totalSupply() + VIRTUAL_SHARES,
            Math.Rounding.Ceil // round UP against user
        );
    }

    function previewWithdraw(uint256 assets) public view returns (uint256) {
        return assets.mulDiv(
            totalSupply() + VIRTUAL_SHARES,
            totalAssets() + VIRTUAL_ASSETS,
            Math.Rounding.Ceil // round UP against user
        );
    }

    function previewRedeem(uint256 shares) public view returns (uint256) {
        return convertToAssets(shares);
    }

    function deposit(uint256 assets, address receiver) external returns (uint256 shares) {
        shares = previewDeposit(assets);
        require(shares > 0, "zero shares");
        asset_.safeTransferFrom(msg.sender, address(this), assets);
        _mint(receiver, shares);
        emit Deposit(msg.sender, receiver, assets, shares);
    }

    function mint(uint256 shares, address receiver) external returns (uint256 assets) {
        assets = previewMint(shares);
        asset_.safeTransferFrom(msg.sender, address(this), assets);
        _mint(receiver, shares);
        emit Deposit(msg.sender, receiver, assets, shares);
    }

    function withdraw(uint256 assets, address receiver, address owner_)
        external returns (uint256 shares)
    {
        shares = previewWithdraw(assets);
        if (msg.sender != owner_) {
            _spendAllowance(owner_, msg.sender, shares);
        }
        _burn(owner_, shares);
        asset_.safeTransfer(receiver, assets);
        emit Withdraw(msg.sender, receiver, owner_, assets, shares);
    }

    function redeem(uint256 shares, address receiver, address owner_)
        external returns (uint256 assets)
    {
        assets = previewRedeem(shares);
        if (msg.sender != owner_) {
            _spendAllowance(owner_, msg.sender, shares);
        }
        _burn(owner_, shares);
        asset_.safeTransfer(receiver, assets);
        emit Withdraw(msg.sender, receiver, owner_, assets, shares);
    }
}

First Depositor Attack Mitigation

Without protection, an attacker can:

  1. Deposit 1 wei to get 1 share
  2. Donate a large amount directly to inflate totalAssets
  3. Next depositor gets 0 shares due to rounding

Virtual shares/assets solve this by ensuring the exchange rate always has a floor:

solidity
uint256 internal constant VIRTUAL_SHARES = 1e3;
uint256 internal constant VIRTUAL_ASSETS = 1;

// Share calculation uses (totalSupply + VIRTUAL_SHARES) / (totalAssets + VIRTUAL_ASSETS)
// Cost of attack = VIRTUAL_SHARES * donation_amount / VIRTUAL_ASSETS

OpenZeppelin's ERC4626 uses _decimalsOffset() which is equivalent.

Yield Strategy Integration

solidity
function totalAssets() public view override returns (uint256) {
    // Include assets deployed to yield strategies
    return asset_.balanceOf(address(this)) + _deployedAssets();
}

function harvest() external {
    // Collect yield from strategy, increasing totalAssets
    // Share price automatically increases for all holders
    strategy.claim();
}

Checklist

  • Round DOWN for deposit and redeem (favors vault)
  • Round UP for mint and withdraw (favors vault)
  • Implement first depositor attack mitigation (virtual shares or minimum deposit)
  • totalAssets() includes all assets under management (not just balance)
  • preview* functions match actual execution (same rounding)
  • max* functions account for strategy liquidity limits
  • Handle ERC-20 tokens with non-standard decimals
  • Test share price manipulation via direct token transfers
  • Emit Deposit and Withdraw events per spec

© ccashwell, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/yield-vault-patterns of ccashwell/evm-cortex.

Open the folder on GitHubat commit f8f3301

Compare with similar skills

Yield Vault Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Yield Vault Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Yield Vault Patterns this skillccashwell/evm-cortex131—~1.8kAutomated safety check: PassMIT
Token Budget Advisoraffaan-m/ECC274k—~910Automated safety check: PassMIT
Token Budget Advisoraffaan-m/ECC274k—~927Automated safety check: PassMIT
UI Tokenssickn33/agentic-awesome-skills47k1 repos~691Automated safety check: PassMIT
Yield Intelligencesickn33/agentic-awesome-skills47k1 repos~1.1kAutomated safety check: PassMIT
Token Mapnexu-io/open-design100k—~1.4kAutomated safety check: PassApache-2.0

Similar skills

  • 回答する前に、どれだけの回答深度を消費するかについてユーザーに情報に基づいた選択を提供する。ユーザーが回答の長さ、深さ、またはトークンバジェットを明示的に制御したい場合にこのスキルを使用する。トリガー条件:"token budget", "token count", "token usage", "token limit", "response length", "answer depth"…

    274k GitHub stars~910 tokensUpdated 2 days ago
    AI & LLM EngineeringAuto-check passed
  • 在回答前,为用户提供关于消耗多少响应深度的知情选择。当用户明确希望控制响应长度、深度或令牌预算时使用此技能。触发条件:"token budget", "token count", "token usage", "token limit", "response length", "answer depth", "short version", "brief answer", "detailed…

    274k GitHub stars~927 tokensUpdated 2 days ago
    AI & LLM EngineeringAuto-check passed
  • UI Tokens

    sickn33/agentic-awesome-skills

    View, add, or modify design tokens in the StyleSeed design system

    47k GitHub starsUsed in 1 repo~691 tokens
    Frontend & DesignAuto-check passed
  • Yield Intelligence

    sickn33/agentic-awesome-skills

    Passive income portfolio analysis — activate when user asks about dividend yields, Treasury rates, REIT income, monthly passive income goals, or portfolio yield optimization.

    47k GitHub starsUsed in 1 repo~1.1k tokens
    Business, Finance & HRAuto-check passed
  • Token Map

    nexu-io/open-design

    Map an extracted Figma / source-code token bag onto the active OD design system, producing a deterministic mapping the generate stage can consume.

    100k GitHub stars~1.4k tokensUpdated today
    Frontend & DesignAuto-check passed
  • Ddd Aggregate

    ruvnet/ruflo

    Scaffold an aggregate root with entity, value objects, repository interface, domain events, and test stubs.

    74k GitHub stars~774 tokensUpdated today
    DevelopmentAuto-check: notes

More from ccashwell/evm-cortex

All 89 skills in this repo
  • Xray Pre Audit

    ccashwell/evm-cortex

    A skill your agent uses when preparing for a security audit, performing reconnaissance on a new codebase, or creating a protocol overview.

    131 GitHub stars~25k tokensUpdated 7 days ago
    Auto-check passed
  • Aave Integration

    ccashwell/evm-cortex

    A skill your agent uses when integrating with Aave V3 for lending, borrowing, flash loans, or building on top of Aave markets.

    131 GitHub stars~1.3k tokensUpdated 7 days ago
    Auto-check passed
  • Access Control Patterns

    ccashwell/evm-cortex

    Access control design patterns for Solidity protocols. An agent skill from ccashwell/evm-cortex.

    131 GitHub stars~1.8k tokensUpdated 7 days ago
    Auto-check passed
  • Anvil Patterns

    ccashwell/evm-cortex

    A skill your agent uses when running a local Ethereum node with Anvil.

    131 GitHub stars~1.3k tokensUpdated 7 days ago
    Auto-check passed
  • Audit Breadth Scan

    ccashwell/evm-cortex

    A skill your agent uses when performing systematic breadth-first review of all contracts during a security audit.

    131 GitHub stars~1.4k tokensUpdated 7 days ago
    Auto-check passed
  • Audit Depth Analysis

    ccashwell/evm-cortex

    A skill your agent uses when performing deep analysis of specific findings or high-risk areas during a security audit.

    131 GitHub stars~1.6k tokensUpdated 7 days ago
    Auto-check passed

Questions about Yield Vault Patterns

What does Yield Vault Patterns do?

A skill your agent uses when building ERC-4626 tokenized vaults, yield aggregators, or share-based deposit/withdraw systems. Yield Vault Patterns is an agent skill from ccashwell/evm-cortex. Use when building ERC-4626 tokenized vaults, yield aggregators, or share-based deposit/withdraw systems.

When should I use Yield Vault Patterns?

Yield Vault Patterns fits situations like: building ERC-4626 tokenized vaults; yield aggregators; share-based deposit/withdraw systems.

How do I install Yield Vault Patterns in Claude Code?

Run `npx skills add ccashwell/evm-cortex --skill yield-vault-patterns -a claude-code`. Or copy the skill folder (skills/yield-vault-patterns in ccashwell/evm-cortex) into .claude/skills/yield-vault-patterns in your project. Claude Code loads it when a task matches its description.

How do I install Yield Vault Patterns in Codex?

Run `npx skills add ccashwell/evm-cortex --skill yield-vault-patterns -a codex`. Or copy the skill folder (skills/yield-vault-patterns in ccashwell/evm-cortex) into .agents/skills/yield-vault-patterns in your project. Codex loads it when a task matches its description.

Can I use Yield Vault Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ccashwell/evm-cortex --skill yield-vault-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/yield-vault-patterns, .gemini/skills/yield-vault-patterns, .github/skills/yield-vault-patterns and .opencode/skills/yield-vault-patterns in your project.

What does Yield Vault Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: Yield Vault Patterns is instructions for the agent only.

Does Yield Vault Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Yield Vault Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Yield Vault Patterns use?

Yield Vault Patterns is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Yield Vault Patterns use?

About 1.8k tokens (SKILL.md is roughly 7.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Yield Vault Patterns?

Skills that share tags, products or a category with Yield Vault Patterns: Token Budget Advisor (affaan-m/ECC, 274k stars), Token Budget Advisor (affaan-m/ECC, 274k stars), UI Tokens (sickn33/agentic-awesome-skills, 47k stars) and Yield Intelligence (sickn33/agentic-awesome-skills, 47k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Yield Vault Patterns?

ccashwell (a GitHub user) maintains it in ccashwell/evm-cortex, which has 131 GitHub stars. The repository holds 89 skills in this directory. The repository was last updated on September 30, 2026.

Source: ccashwell/evm-cortex on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.