All skills
Skillintermediate

Common Dimensions in DeFi

This document catalogs standard dimensional units used across DeFi protocols. While examples use Solidity syntax, the dimensional vocabulary is protocol-agnostic and applies equally to Rust (Anchor, CosmWasm), TypeScript, Python, or any other language implementing DeFi logic.

Claude Code Knowledge Pack7/10/2026

Overview

Common Dimensions in DeFi

This document catalogs standard dimensional units used across DeFi protocols. While examples use Solidity syntax, the dimensional vocabulary is protocol-agnostic and applies equally to Rust (Anchor, CosmWasm), TypeScript, Python, or any other language implementing DeFi logic.

Universal Base Units

Token Amounts: {tok}

Represents a quantity of tokens.

uint256 public totalSupply;      // {tok}
uint256 public balanceOf;        // {tok}
uint256 amount;                  // {tok}

Typical precision: D6 (USDC, USDT), D8 (WBTC), D18 (most ERC20)

Share Amounts: {share}

Represents vault/pool shares.

uint256 public totalShares;      // {share}
uint256 userShares;              // {share}

Typical precision: D18

Time: {s}

Timestamps and durations in seconds.

uint256 public lastUpdate;       // {s}
uint256 elapsed;                 // {s}
uint256 duration;                // {s}
block.timestamp                  // {s}

Precision: Integer (no decimals)

Dimensionless: {1}

Pure ratios, percentages, multipliers.

uint256 public feeRate;          // D18{1}
uint256 percent;                 // D18{1} or D4{1} for basis points
uint256 multiplier;              // D18{1}

Typical precision: D18 or D4 (basis points)

Unit of Account: {UoA}

Abstract value unit, typically USD-equivalent.

uint256 public totalValue;       // {UoA}
uint256 price;                   // {UoA} (absolute)

Note: Often implicit in price dimensions like {UoA/tok}

Standard Derived Units

Exchange Rate: {tok/share} or {share/tok}

Conversion ratio between tokens and shares.

uint256 public exchangeRate;     // D18{tok/share}
uint256 sharePrice;              // D18{tok/share}

Price: {UoA/tok}

Value per token in unit of account.

uint256 public tokenPrice;       // D8{UoA/tok} (Chainlink)
uint256 oraclePrice;             // D18{UoA/tok} or D27{UoA/tok}

Cross Price: {tokA/tokB}

Exchange rate between two tokens.

uint256 public swapRate;         // D18{tokA/tokB}

Rate Per Second: {1/s}

Time-based rate (fees, interest).

uint256 public interestRate;     // D18{1/s}
uint256 feePerSecond;            // D27{1/s}

Value Per Share: {UoA/share}

Share value in unit of account.

uint256 public nav;              // D18{UoA/share}
uint256 shareValue;              // D27{UoA/share}

Protocol-Specific Units

Reserve Protocol

UnitDescriptionExample
{BU}Basket UnitTarget basket composition
{tok/BU}Tokens per basketWeight in basket
{UoA/BU}Basket valueBasket price
{BU/share}Baskets per shareRToken backing
{RToken}RToken amountAlias for {share}
{RSR}RSR token amountStaking token
uint256 public basketsNeeded;    // {BU}
uint256 weight;                  // D27{tok/BU}
uint256 price;                   // D27{UoA/tok}

Lending Protocols (Aave, Compound)

UnitDescriptionExample
{debt}Debt token amountBorrowed amount
{collateral}Collateral amountDeposited collateral
{aToken}Aave interest-bearing tokenDeposit receipt
{cToken}Compound interest-bearing tokenDeposit receipt
{1}Health factor, LTVRisk metrics
uint256 public totalDebt;        // {debt}
uint256 healthFactor;            // D18{1}
uint256 ltv;                     // D4{1} (basis points)

AMM Protocols (Uniswap, Curve)

UnitDescriptionExample
{liq}Liquidity unitsPool liquidity
{LP}LP token amountLiquidity provider shares
{sqrtP}Square root priceUniswap V3
uint256 public liquidity;        // {liq}
uint256 lpBalance;               // {LP}
uint160 sqrtPriceX96;            // Q96{sqrtP}

Staking Protocols

UnitDescriptionExample
{staked}Staked token amountDeposited stake
{reward}Reward token amountEarned rewards
{reward/staked}Reward ratePer-token rewards
uint256 public totalStaked;      // {staked}
uint256 rewardPerToken;          // D18{reward/staked}

Standard Precision Levels

PrefixValueCommon Usage
D41e4Basis points
D61e6USDC, USDT decimals
D81e8WBTC, Chainlink prices
D181e18Standard ERC20, most calculations
D271e27High-precision prices (Reserve)
Q962^96Uniswap V3 fixed-point

Interface Dimensions

ERC20

function totalSupply() external view returns (uint256);        // {tok}
function balanceOf(address) external view returns (uint256);   // {tok}
function decimals() external view returns (uint8);             // precision info
function transfer(address, uint256 amount) external;           // amount: {tok}
function approve(address, uint256 amount) external;            // amount: {tok}
function transferFrom(address, address, uint256 amount);       // amount: {tok}
function allowance(address, address) returns (uint256);        // {tok}

ERC4626

function asset() external view returns (address);              // underlying token
function totalAssets() external view returns (uint256);        // {tok}
function convertToShares(uint256 assets) returns (uint256);    // {tok} → {share}
function convertToAssets(uint256 shares) returns (uint256);    // {share} → {tok}
function maxDeposit(address) external view returns (uint256);  // {tok}
function maxMint(address) external view returns (uint256);     // {share}
function maxWithdraw(address) external view returns (uint256); // {tok}
function maxRedeem(address) external view returns (uint256);   // {share}
function previewDeposit(uint256 assets) returns (uint256);     // {tok} → {share}
function previewMint(uint256 shares) returns (uint256);        // {share} → {tok}
function previewWithdraw(uint256 assets) returns (uint256);    // {tok} → {share}
function previewRedeem(uint256 shares) returns (uint256);      // {share} → {tok}
function deposit(uint256 assets, address) returns (uint256);   // {tok} → {share}
function mint(uint256 shares, address) returns (uint256);      // {share} → {tok}
function withdraw(uint256 assets, ...) returns (uint256);      // {tok} → {share}
function redeem(uint256 shares, ...) returns (uint256);        // {share} → {tok}

Chainlink

function decimals() external view returns (uint8);             // usually 8
function latestRoundData() external view returns (
    uint80 roundId,
    int256 answer,      // D8{UoA/tok} typically
    uint256 startedAt,  // {s}
    uint256 updatedAt,  // {s}
    uint80 answeredInRound
);

Naming Convention Hints

PatternLikely Dimension
*Balance, *Amount{tok}
*Shares, share*{share}
*Price, price*{UoA/tok}
*Rate, rate*{1} or {1/s}
*Time, *Timestamp{s}
*Duration, *Period{s}
*Fee, fee*{1}
*Ratio, ratio*{1}
*Value, value*{UoA}
*Per*derived unit
total*aggregate amount
max*, min*bounds (same as base)