Development of Crypto Accounting Platform
Crypto accounting is more complex than traditional due to asset specifics: tokens don't have a single exchange, DeFi operations are non-standard, and each transaction requires fair market value at the moment of event. Platform should automate entire cycle: import transactions → classify → calculate cost basis → generate reporting.
Platform Architecture
Multi-source Import
class TransactionImportService {
async importFromSource(source: DataSource, accountId: string): Promise<ImportResult> {
switch (source.type) {
case "exchange_api":
return this.importFromExchangeAPI(source, accountId);
case "wallet_address":
return this.importFromBlockchain(source.address, source.blockchain, accountId);
case "csv_file":
return this.importFromCSV(source.file, source.format, accountId);
case "hardware_wallet":
return this.importFromHardwareWallet(source, accountId);
}
}
private async importFromExchangeAPI(source: ExchangeSource, accountId: string) {
const connector = this.getExchangeConnector(source.exchange);
// Get all transactions since last import
const lastImport = await db.getLastImportTime(accountId, source.exchange);
const transactions = await connector.getTransactions({ since: lastImport });
// Normalize to unified format
const normalized = transactions.map(tx => this.normalizeTransaction(tx, source.exchange));
await db.saveTransactions(accountId, normalized);
return { imported: normalized.length, source: source.exchange };
}
private async importFromBlockchain(
address: string,
blockchain: string,
accountId: string
): Promise<ImportResult> {
// Use The Graph or Moralis for indexed data
const indexer = this.getBlockchainIndexer(blockchain);
const transactions = await indexer.getAddressTransactions(address);
// DeFi specifics: decode calldata to understand what happened
const decoded = await Promise.all(
transactions.map(tx => this.decodeDeFiTransaction(tx, blockchain))
);
await db.saveTransactions(accountId, decoded.flat());
return { imported: decoded.flat().length };
}
}
Exchange Connectors
class BinanceConnector implements ExchangeConnector {
async getTransactions(params: { since: Date }): Promise<RawTransaction[]> {
const results: RawTransaction[] = [];
// Binance has different endpoints for different types
const [spot, futures, staking, savings] = await Promise.all([
this.binance.getSpotTrades(params.since),
this.binance.getFuturesTrades(params.since),
this.binance.getStakingHistory(params.since),
this.binance.getSavingsHistory(params.since),
]);
return [...spot, ...futures, ...staking, ...savings];
}
}
// Unified normalized format
function normalizeBinanceTrade(trade: BinanceTrade): UnifiedTransaction {
return {
id: trade.id.toString(),
timestamp: new Date(trade.time),
type: trade.isBuyer ? TransactionType.BUY : TransactionType.SELL,
assetIn: trade.isBuyer ? trade.symbol.replace("USDT", "") : "USDT",
amountIn: trade.isBuyer ? parseFloat(trade.qty) : parseFloat(trade.quoteQty),
assetOut: trade.isBuyer ? "USDT" : trade.symbol.replace("USDT", ""),
amountOut: trade.isBuyer ? parseFloat(trade.quoteQty) : parseFloat(trade.qty),
fee: parseFloat(trade.commission),
feeCurrency: trade.commissionAsset,
exchange: "BINANCE",
};
}
Automatic Classification
class TransactionClassifier {
async classify(tx: UnifiedTransaction): Promise<ClassifiedTransaction> {
// Simple cases
if (tx.assetOut === "USD" || tx.assetOut === "USDT" || tx.assetOut === "USDC") {
return { ...tx, taxCategory: TaxCategory.DISPOSAL, confidence: 0.95 };
}
if (tx.type === TransactionType.STAKING_REWARD || tx.type === TransactionType.INTEREST) {
return { ...tx, taxCategory: TaxCategory.INCOME, confidence: 0.95 };
}
if (tx.type === TransactionType.TRANSFER && await this.isSelfTransfer(tx)) {
return { ...tx, taxCategory: TaxCategory.NON_TAXABLE, confidence: 0.90 };
}
// DeFi operations — need additional analysis
if (tx.source === "defi") {
return this.classifyDeFiTransaction(tx);
}
// Crypto-to-crypto swap
if (this.isCryptoSwap(tx)) {
return { ...tx, taxCategory: TaxCategory.DISPOSAL, subType: "SWAP", confidence: 0.85 };
}
// Requires manual classification
return { ...tx, taxCategory: TaxCategory.UNCLASSIFIED, confidence: 0, requiresReview: true };
}
private async isSelfTransfer(tx: UnifiedTransaction): Promise<boolean> {
// Check if sender and receiver addresses belong to same user
if (!tx.fromAddress || !tx.toAddress) return false;
const user = tx.userId;
const [fromOwned, toOwned] = await Promise.all([
db.isUserAddress(user, tx.fromAddress),
db.isUserAddress(user, tx.toAddress),
]);
return fromOwned && toOwned;
}
}
DeFi Decoding
async function decodeDeFiTransaction(tx: BlockchainTx): Promise<UnifiedTransaction[]> {
// Decode input data for known protocols
const protocol = identifyProtocol(tx.to);
switch (protocol) {
case "UNISWAP_V3": {
const decoded = uniswapV3Interface.parseTransaction({ data: tx.data });
if (decoded.name === "exactInputSingle" || decoded.name === "exactInput") {
return [createSwapTransaction(tx, decoded)];
}
break;
}
case "AAVE_V3": {
const decoded = aaveV3Interface.parseTransaction({ data: tx.data });
if (decoded.name === "supply") {
return [createLendingDeposit(tx, decoded)];
}
if (decoded.name === "withdraw") {
return [createLendingWithdraw(tx, decoded), createInterestIncome(tx, decoded)];
}
break;
}
case "CURVE": {
return decodeCurveSwap(tx);
}
}
// Unknown protocol — return raw
return [createRawTransaction(tx)];
}
Multi-Jurisdiction Reporting
class TaxReportGenerator {
async generateReport(
accountId: string,
taxYear: number,
jurisdiction: string
): Promise<TaxReport> {
const events = await this.getTaxEvents(accountId, taxYear);
switch (jurisdiction) {
case "US": return this.generateUS8949(events, taxYear);
case "UK": return this.generateUKCGT(events, taxYear);
case "DE": return this.generateGermanReport(events, taxYear);
case "AU": return this.generateAUCGT(events, taxYear);
default: return this.generateGenericReport(events, taxYear);
}
}
private async generateUS8949(events: TaxEvent[], taxYear: number): Promise<TaxReport> {
// IRS Form 8949 format
const shortTerm = events.filter(e => !e.isLongTerm);
const longTerm = events.filter(e => e.isLongTerm);
return {
format: "IRS-8949",
year: taxYear,
shortTermGains: shortTerm.reduce((sum, e) => sum + e.gainOrLoss, 0),
longTermGains: longTerm.reduce((sum, e) => sum + e.gainOrLoss, 0),
transactions: events.map(this.formatFor8949),
summary: this.generateScheduleD(shortTerm, longTerm),
};
}
}
Stack
| Component | Technology |
|---|---|
| Exchange connectors | Node.js + official SDKs |
| Blockchain indexing | The Graph + Moralis |
| Cost basis engine | PostgreSQL + TimescaleDB |
| Price history | CoinGecko API + own cache |
| Report generation | PDFKit + ExcelJS + CSV |
| Frontend | React + Recharts (charts) |
| Queue | BullMQ (async import jobs) |
Complete crypto accounting platform with support for 10+ exchanges, DeFi decoding, and multi-jurisdiction reports: 3-4 months development.







