DeFi Accounting Made Simple: Tracking Yield Farming, Liquidity Pools, and Staking Rewards with Plain-Text Accounting
Decentralized Finance (DeFi) has revolutionized how we interact with financial services, offering unprecedented opportunities for yield generation, liquidity provision, and decentralized trading. However, with these opportunities comes the challenge of accurately tracking complex transactions for tax compliance and portfolio management.
Traditional accounting methods struggle with DeFi's unique characteristics: automated market makers, liquidity mining, impermanent loss, and multi-token rewards. This comprehensive guide shows you how to master DeFi accounting using Beancount.io's powerful plain-text accounting system.
Understanding DeFi Accounting Challenges
The Complexity of DeFi Transactions
DeFi protocols create accounting challenges that don't exist in traditional finance:
- Multi-token transactions: Single operations involving multiple cryptocurrencies
- Automated compounding: Rewards automatically reinvested
- Impermanent loss: Value changes due to price divergence in liquidity pools
- Gas fee optimization: Complex fee structures across different networks
- Protocol governance: Voting rights and governance token distributions
- Cross-protocol interactions: Transactions spanning multiple DeFi platforms
Tax Implications of DeFi Activities
The IRS treats DeFi activities as taxable events:
- Liquidity provision: May trigger taxable events when depositing assets
- Yield farming rewards: Taxable as ordinary income at fair market value
- Impermanent loss: Potential tax implications when withdrawing from pools
- Governance tokens: Airdrops and rewards taxable as income
- Staking rewards: Taxable as income when received
Setting Up DeFi Accounts in Beancount.io
Comprehensive Account Structure
Create a detailed account hierarchy that captures all DeFi activities:
; Wallet Accounts
1970-01-01 open Assets:Crypto:Wallet:MetaMask:ETH
1970-01-01 open Assets:Crypto:Wallet:MetaMask:USDC
1970-01-01 open Assets:Crypto:Wallet:MetaMask:DAI
1970-01-01 open Assets:Crypto:Wallet:MetaMask:WBTC
; Uniswap V3 Liquidity Pools
1970-01-01 open Assets:DeFi:Uniswap:ETH-USDC-LP
1970-01-01 open Assets:DeFi:Uniswap:DAI-USDC-LP
1970-01-01 open Assets:DeFi:Uniswap:WBTC-ETH-LP
; Compound Protocol
1970-01-01 open Assets:DeFi:Compound:cUSDC
1970-01-01 open Assets:DeFi:Compound:cETH
1970-01-01 open Assets:DeFi:Compound:cDAI
; Aave Protocol
1970-01-01 open Assets:DeFi:Aave:aUSDC
1970-01-01 open Assets:DeFi:Aave:aETH
1970-01-01 open Assets:DeFi:Aave:DebtETH
; Staking Protocols
1970-01-01 open Assets:Staking:Ethereum:ETH
1970-01-01 open Assets:Staking:Lido:stETH
1970-01-01 open Assets:Staking:RocketPool:rETH
; Income Accounts
1970-01-01 open Income:DeFi:Yield:Uniswap
1970-01-01 open Income:DeFi:Yield:Compound
1970-01-01 open Income:DeFi:Yield:Aave
1970-01-01 open Income:DeFi:Staking:Ethereum
1970-01-01 open Income:DeFi:Governance:Tokens
1970-01-01 open Income:DeFi:Airdrops
; Expense Accounts
1970-01-01 open Expenses:DeFi:Gas:Ethereum
1970-01-01 open Expenses:DeFi:Gas:Polygon
1970-01-01 open Expenses:DeFi:Gas:Arbitrum
1970-01-01 open Expenses:DeFi:ImpermanentLoss
DeFi-Specific Commodities
Define tokens and LP tokens with proper metadata:
1970-01-01 commodity UNI-V3-ETH-USDC
name: "Uniswap V3 ETH-USDC LP Token"
asset-class: "liquidity-pool"
protocol: "uniswap-v3"
1970-01-01 commodity cUSDC
name: "Compound USDC"
asset-class: "lending-token"
protocol: "compound"
1970-01-01 commodity stETH
name: "Lido Staked Ethereum"
asset-class: "staking-derivative"
protocol: "lido"
Tracking Common DeFi Activities
1. Uniswap Liquidity Provision
Adding Liquidity to a Pool
2024-01-15 * "Add liquidity to ETH-USDC Uniswap V3 pool"
Assets:Crypto:Wallet:MetaMask:ETH -5.0 ETH {2500.00 USD}
Assets:Crypto:Wallet:MetaMask:USDC -12500 USDC
Assets:DeFi:Uniswap:ETH-USDC-LP 100 UNI-V3-ETH-USDC {250.00 USD}
Expenses:DeFi:Gas:Ethereum 0.01 ETH {2500.00 USD}
Assets:Crypto:Wallet:MetaMask:ETH -0.01 ETH {2500.00 USD}
Claiming LP Fees
2024-02-15 * "Claim Uniswap LP fees"
Assets:Crypto:Wallet:MetaMask:ETH 0.2 ETH {2600.00 USD}
Assets:Crypto:Wallet:MetaMask:USDC 300 USDC
Income:DeFi:Yield:Uniswap 820.00 USD
Expenses:DeFi:Gas:Ethereum 0.005 ETH {2600.00 USD}
Assets:Crypto:Wallet:MetaMask:ETH -0.005 ETH {2600.00 USD}
Removing Liquidity with Impermanent Loss
2024-03-15 * "Remove liquidity from ETH-USDC pool"
Assets:DeFi:Uniswap:ETH-USDC-LP -100 UNI-V3-ETH-USDC {250.00 USD}
Assets:Crypto:Wallet:MetaMask:ETH 4.8 ETH {2800.00 USD}
Assets:Crypto:Wallet:MetaMask:USDC 12800 USDC
Expenses:DeFi:ImpermanentLoss 240.00 USD ; IL calculation
Expenses:DeFi:Gas:Ethereum 0.008 ETH {2800.00 USD}
Assets:Crypto:Wallet:MetaMask:ETH -0.008 ETH {2800.00 USD}
2. Compound Protocol Lending
Supplying Assets to Compound
2024-01-20 * "Supply USDC to Compound"
Assets:Crypto:Wallet:MetaMask:USDC -10000 USDC
Assets:DeFi:Compound:cUSDC 500 cUSDC {20.00 USD}
Expenses:DeFi:Gas:Ethereum 0.008 ETH {2500.00 USD}
Assets:Crypto:Wallet:MetaMask:ETH -0.008 ETH {2500.00 USD}
Earning Compound Interest
2024-02-20 * "Compound interest accrual"
Assets:DeFi:Compound:cUSDC 5.2 cUSDC {20.50 USD}
Income:DeFi:Yield:Compound 106.60 USD