Staking in Polkadot is a tax-relevant process. But how do I find out what income
I have generated?
Maybe you already use https://cointracking.info, the
"Leader for Cryptocurrency Tracking and Tax Reporting".
If you do so, you have to import your staking data in the Cointracking Service.
This is where cointracking_polka comes into play, it generates reports on staking income and fees for accounts to be freely defined.
cointracking_polka is a Node.js program written in typescript to create
staking reports usable with https://cointracking.info, the service which helps
you with tax return.
The created csv files can be imported in the cointracking database using the menu:
Enter Coins | Bulk Imports | CSV Import
The following coins are supported:
- Polkadot
- Kusama
- Westend (testnet, therefore not relevant for cointracking)
These steps should only be carried out during the initial installation.
First you have to clone the repository:
git clone https://github.com/TheGoldenEye/cointracking_polka.git
We need some prerequisites:
sudo apt install node-typescript npm
Now its time to check the nodejs version:
node -v
If your node version is minimum v10.4.0, its fine. Otherwise you have to install
a newer version, because of the missing BigInt support in Node.js prior to v10.4.
You can do it with the 'n node installer':
sudo npm install -g n
sudo n lts
Now you should have a current node version installed.
This repo uses yarn workspaces to organise the code.
As such, after cloning, its dependencies should be installed via yarn package manager,
not via npm, the latter will result in broken dependencies.
Install yarn, if you haven't already:
sudo npm install -g yarn
Please always run this when the sources have been updated from the git repository.
Use yarn to install the dependencies:
cd cointracking_polka
yarn
The tool requires access to all transactions of the accounts to be analyzed.
Unfortunately, this is not possible in the Polkadot universe, since transaction
data cannot be queried directly there.
Therefore cointracking_polka uses the transaction database of polka-store
https://github.com/TheGoldenEye/polka-store. Polka-store scans a Polkadot chain
(Polkadot/Kusama/Westend) and stores balance-relevant transactions in a SQLite database.
If you want, you can download the latest versions of the transaction databases
here.
Alternatively you can install polka-store and create the transaction databases yourself.
Please copy the Polkadot.db and/or Kusama.db to the data directory.
You can find a template for configuration in config/config_tpl.json
.
Instead, the file used by the tool is config/config.json
.
If the file does not exist, config/config_tpl.json
is copied to
config/config.json
during the program start phase.
You can adapt this file (config.json
) to your needs.
Here are the parameters defined for the different chains.
In the accounts
list you can define the accounts to analyze (stash accounts
for staking rewards or any other accounts for tracking the fees).
Besides the accounts list there is currently no need to change the default configuration.
config.json:
{
"staking": "day",
"feeReceived": "day",
"feePaid": "day",
"defchain": "Polkadot",
"chains": {
"Polkadot": {
"database": "data/Polkadot.db",
"unit": "DOT",
"ticker": "DOT2",
"decimals": 10,
"accounts": [
{ "name": "Example1", "account": "15kUt2i86LHRWCkE3D9Bg1HZAoc2smhn1fwPzDERTb1BXAkX" },
{ "name": "Example2", "account": "12xtAYsRUrmbniiWQqJtECiBQrMn8AypQcXhnQAc6RB6XkLW" }
]
},
"Kusama": {
"database": "data/Kusama.db",
"unit": "KSM",
"ticker": "KSM",
"decimals": 12,
"accounts": [
{ "name": "Example1", "account": "HmFYPT1btmi1T9qqs5WtuNJK93yNdnjjhReZh6emgNQvCHa" },
{ "name": "Example2", "account": "GXPPBuUaZYYYvsEquX55AQ1MRvgZ96kniEKyAVDSdv1SX96" }
]
},
"Westend": {
"database": "data/Westend.db",
"unit": "WND",
"ticker": "WND",
"decimals": 12,
"accounts": [
{ "name": "Example1", "account": "5FnD6fKjTFLDKwBvrieQ6ZthZbgMjppynLhKqiRUft9yr8Nf" },
{ "name": "Example2", "account": "5DfdW2r2hyXzGdXFqAVJKGrtxV2UaacnVNr3sAdgCUDc9N9g" }
]
}
},
"csv": {
"header": "\"Type\",\"Buy\",\"Cur.\",\"Sell\",\"Cur.\",\"Fee\",\"Cur.\",\"Exchange\",\"Group\",\"Comment\",\"Date\",\"TradeID\",\"BuyValue\",\"SellValue\"",
"staking": "\n\"Staking\",\"%s\",\"%s\",,,,,\"Staking_%s\",\"%s\",\"stash: %s tx:%s\",\"%s\",\"Staking_%s_%s\"",
"feeReceived": "\n\"Staking\",\"%s\",\"%s\",,,,,\"Staking_%s\",\"%s\",\"Fee received: tx:%s\",\"%s\",\"Staking_%s_%s\"",
"feePaid": "\n\"Trade\",\"0\",\"EUR\",\"%s\",\"%s\",\"%s\",\"%s\",\"Staking_%s\",\"%s\",\"Fee paid: tx:%s\",\"%s\",\"Staking_%s_%s\",\"0.00000001\",\"0.00000001\""
}
}
Global settings:
staking: Please define the aggregation level of the staking records.
Valid values: [ "individual", "time", "day", "none" ]
- "individual": no aggregation
- "time": all staking records with the same time are combined
- "day": all staking records of a day are combined
- "none": disables staking records
feeReceived: Please define the aggregation level of the records based on
fees you got as block author (validators only).
Valid values: [ "individual", "time", "day", "none" ]
The values have the same meaning as in staking
feePaid: Please define the aggregation level of the records based on
fees you paid in various transactions.
Valid values: [ "individual", "time", "day", "none" ]
The values have the same meaning as in staking
defchain: The chain which is used (if no chain is given in the command line)
Chain specific settings:
database: The path to the sqlite transaction database (input) from polka-store
unit: The unit of the coin
ticker: The associated ticker symbol in cointracking
decimals: Defines the number of decimal places
accounts: A list of accounts to analyze
Now you have to build the code (compile typescript to javascript)
yarn build
One of the following commands starts the tool, collecting data from the given chain:
yarn polkadot
yarn kusama
Your console will show information like this:
---------------------------------------------------------------
cointracking-polka: v1.0.0
Chain: Polkadot
---------------------------------------------------------------
Using transaction data until block: 3139419 (2020-12-31 15:39:06)
Query data from database...
Progress: 100%
Write csv file...
Progress: 100%
Staking records: 112 Total: 94.5173137605 DOT
FeeReceived records: 0 Total: 0.0000000000 DOT
FeePaid records: 27 Total: -0.7801000000 DOT
The created csv file you can find in the output directory. You con import it
in https://cointracking.info using the menu:
Enter Coins | Bulk Imports | CSV Import
- Currently no known issues
I welcome contributions. Before submitting your PR, make sure to run the following commands:
yarn lint
: Make sure your code follows the linting rules.yarn lint --fix
: Automatically fix linting errors.
https://github.com/TheGoldenEye/cointracking_polka/graphs/contributors
- GoldenEye
If you like my work, please consider to support me in the Polkadot/Kusama networks and nominate my validators:
Polkadot:
Kusama:
Apache 2.0 License
Copyright (c) 2021 GoldenEye
Disclaimer: The tool is provided as-is. I cannot give a guarantee for accuracy and I assume NO LIABILITY.