Prompt
How do I set up on-chain accounting software for reconciling LP positions, staking rewards, and wallet balances?
Latest observation
To set up on-chain accounting software for reconciling LP positions, staking rewards, and wallet balances, you want a system that can do three things reliably:
- Ingest on-chain data
- Classify every transaction and position change
- Map it into accounting records that reconcile to wallet and protocol balances
Here’s a practical setup approach.
1) Define the scope first
Decide which chains, protocols, and assets you need to support.
Track at minimum:
- Wallet balances
- Native coins
- ERC-20 / SPL / other token balances
- LP positions
- Uniswap-style AMM LP tokens
- V3 concentrated liquidity positions
- Vault shares / yield-bearing LP wrappers
- Staking rewards
- Auto-compounding or claimable rewards
- Emissions paid in native token or reward token
- Transfers
- Deposits, withdrawals, bridges
- Fees and yield
- Trading fees, protocol rewards, incentive distributions
Decide accounting basis:
- Cash basis: recognize income when received/claimed
- Accrual basis: recognize when earned
- Fair market value (FMV) at transaction time
For most on-chain accounting, FMV + lot tracking is the most useful.
2) Choose your data sources
You need both on-chain raw data and pricing data.
On-chain sources
Use one or more of:
- RPC / archive nodes for direct chain reads
- Indexers like:
- The Graph
- Covalent
- Alchemy
- Moralis
- Bitquery
- Subsquid
- Protocol subgraphs / APIs
- Uniswap, Curve, Aave, Lido, etc.
Pricing sources
For valuation and reconciliation:
- CoinGecko / CoinMarketCap
- Chainlink price feeds
- DEX TWAP
- Internal pricing oracle if you need auditability
Why you need both
On-chain data tells you:
- what happened
Pricing data tells you:
- what it was worth in reporting currency at that time
3) Build a canonical transaction model
Normalize all activity into a common schema.
Suggested fields
chain_idwallet_addresstx_hashblock_numbertimestampevent_typeasset_inasset_outamount_inamount_outprotocolcounterpartyposition_idusd_valuegas_feememo/reference
Core event types
transfer_intransfer_outswaplp_mintlp_burnstakeunstakereward_accrualreward_claimfee_accrualfee_distributionwrapunwrapbridge
This normalized layer is the foundation for reconciliation.
4) Separate balances into three layers
You should reconcile:
A. Wallet balances
The actual token balances held by the wallet.
B. Protocol balances
Balances held in:
- LP pools
- staking contracts
- lending positions
- vaults
C. Accounting balances
What your books say you own/are owed.
This separation is important because:
- wallet balance may not reflect staked assets
- LP position value is not just token balance
- rewards may be accrued but not yet claimed
5) Handle LP positions correctly
LP positions are often the trickiest part.
For constant-product LPs
When a wallet deposits two tokens into a pool:
- record a transfer out of the two tokens
- record an LP position acquisition
- the LP token becomes the asset held
When burning LP:
- record LP disposal
- record receipt of underlying tokens
For concentrated liquidity (e.g., Uniswap V3)
Track:
tokenId- deposited token amounts
- liquidity
- fees accrued
- fees collected
- withdrawals
You need to reconstruct position state from contract events:
MintIncreaseLiquidityDecreaseLiquidityCollectBurn
Accounting treatment
Usually:
- LP shares are an asset
- underlying exposure changes with market prices
- fees earned are income when accrued or collected, depending on policy
6) Handle staking and reward flows
Common staking lifecycle
- Deposit token into staking contract
- Token is locked or represented by receipt token
- Rewards accrue over time
- Rewards are claimed or auto-compounded
- Principal is withdrawn later
Accounting rules to encode
- Stake deposit: reclassify asset from wallet to staked asset
- Reward accrual: recognize income as earned if using accrual basis
- Reward claim: increase wallet balance; do not double-count income if already accrued
- Auto-compound: treat reward as income + reinvestment
Edge case
If rewards are paid in a different token than the staked token, you need:
- FMV at time of receipt
- potential gain/loss on subsequent disposal
7) Add wallet reconciliation logic
To reconcile wallet balances:
Step-by-step
- Pull current balances from chain
- Aggregate all indexed transfers and protocol interactions
- Compute expected balances by asset
- Compare expected vs actual chain balances
- Investigate:
- missing transactions
- failed txs
- token rebases
- airdrops
- dust
- internal protocol transfers
Important edge cases
- Rebasing tokens: balance changes without transfers
- Fee-on-transfer tokens: sent amount differs from received amount
- Wrapped assets: need unwrap/wrap conversion
- Bridges: asset leaves one chain and arrives on another
- Airdrops: may appear without user action
8) Build a position engine
For LPs and staking, you need a state engine that updates holdings over time.
Inputs
- event stream
- contract state snapshots
- token prices
- exchange rates
Outputs
- current holdings
- cost basis
- unrealized gains/losses
- accrued rewards
- realized P/L on exits
This can be implemented as:
- event-sourced ledger
- periodic snapshots + deltas
- hybrid model
A hybrid model is often best:
- use events for accuracy
- use snapshots to validate reconciliation
9) Accounting entries you’ll need
At minimum, support these journal entries:
Wallet deposit
- Dr Crypto Asset
- Cr Deposit/Equity/Income Source
LP mint
- Dr LP Token / Position Asset
- Cr Underlying Assets
LP burn
- Dr Underlying Assets
- Cr LP Token / Position Asset
Reward accrual
- Dr Reward Receivable
- Cr Reward Income
Reward claim
- Dr Wallet Token
- Cr Reward Receivable
Fees collected
- Dr Wallet Token
- Cr Fee Income or Reward Income
Gas fees
- Dr Gas Expense
- Cr Native Token / Cash
Use a consistent chart of accounts:
- Assets
- Liabilities
- Income
- Expenses
- Equity
- Receivables
10) Choose your software stack
If building in-house
Common stack:
- Indexer: Python, TypeScript, or Rust
- Database: PostgreSQL
- ETL/orchestration: Airflow, Dagster, Prefect
- Blockchain access: web3.py / ethers.js / viem
- Accounting layer: custom ledger service
- Dashboarding: Metabase, Superset, Power BI
If buying software
Look for support for:
- wallet address ingestion
- DeFi protocol parsing
- LP and staking support
- multi-chain reconciliation
- tax lots and FMV
- export to ERP/accounting tools
Be careful: many tools handle transfers well but struggle with:
- Uniswap V3
- auto-compounding vaults
- multi-step staking
- rebasing assets
11) Reconciliation workflow
A good workflow is:
- Ingest raw chain data daily or near-real-time
- Normalize events
- Classify protocol interactions
- Value transactions
- Update ledger
- Reconcile balances
- Flag exceptions
- Review manual adjustments
- Lock reporting period
Exception categories
- missing pricing data
- unknown contract
- failed transaction
- partial fill
- unrecognized token
- contract upgrade / proxy change
- mismatched LP state
12) Auditability and controls
For finance-grade accounting, make sure every number is traceable.
Keep:
- tx hash
- log index
- block number
- contract address
- ABI/event signature
- price source
- valuation timestamp
- manual adjustment log
Controls to add:
- immutable raw event store
- versioned classification rules
- approvals for manual edits
- period close snapshots
- reconciliation reports
13) Practical implementation order
If you’re starting from scratch, do it in this order:
- Wallet balance tracking
- ERC-20 transfers
- LP deposits and withdrawals
- Simple staking rewards
- Price valuation
- Fee/reward accrual
- Uniswap V3 / advanced LPs
- Cross-chain bridges
- Auto-compounding vaults
- ERP export and reporting
Start simple; DeFi complexity compounds quickly.
14) Recommended minimum viable setup
If you want a lean first version:
- One chain
- One wallet group
- ERC-20 + native assets
- One or two major LP protocols
- One staking protocol
- Daily sync
- USD valuation
- Journal export to CSV/QuickBooks/Xero
That gets you a working reconciliation pipeline without overengineering.
15) Questions to answer before implementation
- Which chains are in scope?
- Which protocols do you use?
- Do you need tax reporting or just accounting?
- Cash basis or accrual basis?
- Do you need real-time or month-end?
- How many wallets?
- Do you need consolidated entity reporting?
- Do you need audit-ready controls?
If you want, I can also help you with either:
- a reference architecture diagram,
- a database schema for on-chain accounting, or
- a step-by-step implementation plan in Python/SQL.