Giter Club home page Giter Club logo

cointracking_polka's Introduction

cointracking_polka

1 Overview

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)

2 Installation

2.1 Prerequisites

These steps should only be carried out during the initial installation.

2.1.1 Repository

First you have to clone the repository:

git clone https://github.com/TheGoldenEye/cointracking_polka.git

2.1.2 Needed packages

We need some prerequisites:

sudo apt install node-typescript npm

2.1.3 Minimum node.js version

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.

2.1.4 yarn package manager

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

2.2 Installing the project dependencies

Please always run this when the sources have been updated from the git repository.

Use yarn to install the dependencies:

cd cointracking_polka
yarn

2.3 Installing the polka-store database(s)

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.

3 Configuration

3.1 config/config.json

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

4 Running

4.1 Compile Typescript

Now you have to build the code (compile typescript to javascript)

yarn build

4.2 Start program

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

5 CSV Output

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

6 Known issues

  • Currently no known issues

6 Contributions

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

7 Authors

  • GoldenEye

8 Please support me

If you like my work, please consider to support me in the Polkadot/Kusama networks and nominate my validators:

Polkadot:

  1. Validator GoldenEye
  2. Validator GoldenEye/2

Kusama:

  1. Validator GoldenEye
  2. Validator GoldenEye/2
  3. Validator GoldenEye/3

9 License

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.

cointracking_polka's People

Contributors

thegoldeneye avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

cointracking_polka's Issues

Reported 0.0 DOT for staking rewards

Curious if the main branch is suppose to work still? I have everything configured correctly but not getting the expected results. I noticed there is also a development branch being worked on.

% yarn polkadot
yarn run v1.22.10
$ node ./build/main.js Polkadot
---------------------------------------------------------------
cointracking-polka: v1.1.0
Chain:              Polkadot
---------------------------------------------------------------
Using transaction data until block: 8242688 (2021-12-21 23:59:54)
Query data from database...
  Progress: 100%
Write csv file...
  Progress: 100% 

Staking records:         0   Total: 0.0000000000 DOT
FeeReceived records:     0   Total: 0.0000000000 DOT
FeePaid records:        27   Total: -0.4049000914 DOT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.