Crypto currencies experienced record-breaking growth in recent years. I decided to build my own software to help me in the preparation of my taxes.

Cryptocurrencies according to the IRS

The IRS addressed the taxation of cryptocurrency transactions in Notice 2014-21. According to that notice crypto currencies are treated as property for tax purposes and taxpayers must recognize gain or loss on the exchange of cryptocurrency for cash or other property. Gain or loss is also recognized every time a cryptocurrency is sold or used to purchase goods or services.

Types of transactions:

Settled for cash

A taxpayer who sells a crypto currency position for cash must report a capital gain on Form 8949. A position held for one year or less is considered a short-term capital gain taxed at ordinary tax rates. A position held for more than one year is considered a long-term capital gain.

As with stock trades, capital losses offset capital gains in full, and a net capital loss is limited to $3,000 ($1,500 for married taxpayers filing separately) against other types of income on an individual tax return. An excess capital loss is carried forward to the subsequent tax year.

Under IRS rules the default for stock transactions is the first-in first-out (FIFO) method of accounting.

Exchanged for other cryptocurrencies

Crypto-to-crypto trades generate tax liability.

Cryptocurrency mining

When a taxpayer mines a cryptocurrency the fair market value of the coins mined should be included in gross income. The amount of the income equals the market price of the coins on the day they were awarded on the blockchain.

Payment for goods and services

Paying for coffee with crypto currencies is a taxable event.

Chain forks and airdrops

Have to report taxable income using the market value on the day of the split or airdrop.

Donating cryptocurrency

Cryptocurrency can be donated directly to a charity. The tax deduction will be equal to the fair market value of the donated coins and the donor will not pay tax on the gain.

Building the crypto currency tax preparation software (Pine Tree Tax)

I decided to build Pine Tree Tax(PTT) in Rust). I want to learn Rust and I want to learn by doing. Rust is one of my favorite programming languages.

Pine Tree Tax

PTT uses the FIFO (first in, first out) method of accounting. It considers every transaction between two different cryptocurrencies as a taxable event. It tracks the cost basis from the price of the original purchase and transferrs that cost basis from the original token to the new token.

Capital gains or losses events are triggered when a cryptocurrency is sold for USD or when a quantity is transferred to an account not owned by me.

PTT is a command line application that reads the crypto currency transactions from an input .csv file. Example transaction file:

| id | datetime | origin_wallet | origin_asset | origin_quantity | destination_wallet | destination_asset | destination_quantity | usd_value | usd_fee |
|----+--------------------------+---------------+--------------+-----------------+--------------------+-------------------+----------------------+-----------+---------+
| 1 | 2016-05-10T13:01:00.000Z | External | BTC | 0.18312594 | Coinbase | BTC | 0.18312594 | 83.23 | |
| 2 | 2016-05-12T20:59:00.000Z | Coinbase | BTC | 0.01000000 | External | BTC | 0.01000000 | 4.56 | |
| 3 | 2016-05-12T23:12:00.000Z | Coinbase | BTC | 0.08788000 | External | BTC | 0.08788000 | 40.00 | |
| 4 | 2016-06-02T08:09:00.000Z | Bank | USD | 2475.25000000 | Coinbase | BTC | 4.61456003 | 2475.25 | 24.75 |
| 5 | 2016-06-05T18:57:00.000Z | External | BTC | 0.04112000 | Coinbase | BTC | 0.04112000 | 23.72 | |
| 6 | 2016-06-05T19:50:00.000Z | Coinbase | BTC | 0.02000000 | External | BTC | 0.02000000 | 11.51 | |
| 7 | 2016-06-07T15:37:00.000Z | External | BTC | 0.07062000 | Coinbase | BTC | 0.07062000 | 40.77 | |
| 8 | 2016-06-14T12:23:36.000Z | Gdax | BTC | 1.49551345 | Gdax | ETH | 55.22575516 | 1033.61 | 3.10 |

The value in the field “usd_value” represents the market value of the transaction at the time the exchange took place.


The application generates 2 output files in .csv format (long and short term capitail gains). Example output file:

| quantity | asset | buy_date | sell_date | cost_basis | proceeds | gain |
|--------------------|-------|----------------------|----------------------|------------|----------|----------|
| 0.00084522 | BTC | 2016-06-24T13:10:00Z | 2017-07-31T16:10:00Z | 0.56 | 2.42 | 1.86 |
| 0.39549275 | BTC | 2016-06-24T13:10:00Z | 2017-10-13T10:57:24Z | 259.83 | 2216.62 | 1956.79 |
| 3.5656486000000003 | BTC | 2016-06-24T13:29:33Z | 2017-10-13T10:57:24Z | 2388.88 | 19984.39 | 17595.51 |
| 0.05 | BTC | 2016-06-24T13:29:33Z | 2017-12-04T00:40:00Z | 33.5 | 566.8 | 533.3 |
| 5 | BTC | 2016-06-24T13:29:33Z | 2017-12-10T15:02:00Z | 3349.85 | 77000 | 73650.15 |
| 0.16960901 | BTC | 2016-06-24T13:29:33Z | 2017-12-18T16:55:00Z | 113.63 | 3218.38 | 3104.75 |


The main component of PTT is the Account class:

#[derive(Debug)]
pub struct Account {
name: String,
balance: f64,
deposits: Vec<Deposit>,
}

The transaction class gets populated with values from the transactions csv file using the Serde library:

#[derive(Debug, Deserialize)]
struct Transaction {
id: i32,
datetime: DateTime<Utc>,
origin_wallet: String,
origin_asset: String,
origin_quantity: f64,
destination_wallet: String,
destination_asset: String,
destination_quantity: f64,
usd_value: f64,
usd_fee: Option<f64>,
spot: Option<f64>,
}

A list of tax event structs gets serialized to .csv as output of the application:

#[derive(Debug, Serialize)]
struct TaxEvent {
quantity: f64,
asset: String,
buy_date: DateTime<Utc>,
sell_date: DateTime<Utc>,
cost_basis: f64,
proceeds: f64,
gain: f64,
}

The source code of PTT can be found at: Github

Comments