TokenTax Integration
TokenTax is a crypto tax service oriented toward advanced users: supports DeFi transactions, margin trading, futures, and NFT. Suitable for traders with complex portfolios.
Supported Formats
TokenTax accepts data in several formats:
// TokenTax Generic CSV
interface TokenTaxRow {
type: "Trade" | "Income" | "Mining" | "Gift" | "Expense" | "Transfer";
buyAmount: string;
buyCurrency: string;
sellAmount: string;
sellCurrency: string;
feeAmount: string;
feeCurrency: string;
exchange: string;
group: string; // for grouping related transactions
comment: string;
date: string; // "YYYY-MM-DD HH:mm:ss"
}
function exportToTokenTaxCSV(transactions: InternalTransaction[]): string {
const headers = [
"Type", "BuyAmount", "BuyCurrency", "SellAmount", "SellCurrency",
"FeeAmount", "FeeCurrency", "Exchange", "Group", "Comment", "Date"
];
const rows = transactions.map(tx => [
mapToTokenTaxType(tx.taxCategory),
tx.amountIn?.toString() ?? "",
tx.assetIn ?? "",
tx.amountOut?.toString() ?? "",
tx.assetOut ?? "",
tx.feeAmount?.toString() ?? "",
tx.feeCurrency ?? "",
tx.source ?? "",
tx.groupId ?? "", // group LP operations together
tx.notes ?? "",
format(tx.timestamp, "yyyy-MM-dd HH:mm:ss"),
].join(","));
return [headers.join(","), ...rows].join("\n");
}
function mapToTokenTaxType(category: TaxCategory): string {
const typeMap: Record<TaxCategory, string> = {
[TaxCategory.SWAP]: "Trade",
[TaxCategory.BUY]: "Trade",
[TaxCategory.SELL]: "Trade",
[TaxCategory.STAKING_REWARD]: "Income",
[TaxCategory.AIRDROP]: "Income",
[TaxCategory.MINING_REWARD]: "Mining",
[TaxCategory.TRANSFER]: "Transfer",
[TaxCategory.GAS_FEE]: "Expense",
};
return typeMap[category] || "Trade";
}
DeFi Grouping
TokenTax can handle complex DeFi operations if you group them correctly:
// For LP deposit — group related transactions
function exportLPOperationAsGroup(
lpDeposit: LiquidityDepositEvent,
groupId: string
): TokenTaxRow[] {
// Two tokens given → LP token received
return [
{
type: "Trade",
buyAmount: lpDeposit.lpTokenAmount.toString(),
buyCurrency: `${lpDeposit.token0}-${lpDeposit.token1}-LP`,
sellAmount: lpDeposit.token0Amount.toString(),
sellCurrency: lpDeposit.token0,
feeAmount: "",
feeCurrency: "",
exchange: "Uniswap",
group: groupId,
comment: "LP deposit token0",
date: format(lpDeposit.timestamp, "yyyy-MM-dd HH:mm:ss"),
},
// second token in separate row of same group
{
type: "Trade",
buyAmount: "",
buyCurrency: "",
sellAmount: lpDeposit.token1Amount.toString(),
sellCurrency: lpDeposit.token1,
feeAmount: lpDeposit.gasUSD?.toString() ?? "",
feeCurrency: "USD",
exchange: "Uniswap",
group: groupId,
comment: "LP deposit token1",
date: format(lpDeposit.timestamp, "yyyy-MM-dd HH:mm:ss"),
},
];
}
TokenTax integration via CSV export with DeFi grouping support — 2-4 business days.







