# VID Pool Software

### Background

VideoCoin Network workers get rewarded for the work they do. The amount of work they will get is related to the amount of VID tokens staked to the workers, including staked tokens from delegators. In order to incentivize delegators workers have to share payouts with them.

The Software in this repository is meant to share rewards with delegators and should be run by transcoder periodically.

### Install

Use `docker pull registry.videocoin.net/vidpool/vidpool:latest`.

### Build

To build use:

```
make build
```

You will get a binary for the current platform.

Or build a docker image with:

```
make vendor
make image
```

### Configuration

Config example:

```
{
    "DataDir": "/tmp/vidpooldata/",
    "KeyFile": "worker-key.json",
    "Password": "",
    "StreamManagerAddress": "0xee714E6f2686929AE33614aAA332D67EaC9f5ede",
    "StakingManagerAddress": "0xe535420fD393C202c5F47aAfDc210fF36f697584",
    "WorkerChainURL": "https://symphony.dev.videocoin.net/",
    "PaymentsChainURL": "https://rpc.tst.publicmint.io:8545/",
    "LogLevel": "debug",
    "PaymentURLSpec": "https://explorer.tst.publicmint.io/tx/%s/token_transfers"
    "Auth": {
        "ClientID": "69cf5e81-5301-414f-9cd9-a39bbe06c0ff",
        "AuthURL": "d.dev.videocoin.network:5008"
    }
}
```

**DataDir**

Application will need to store small amount of the persistent data, for transactions recovery and latest processed block.

**KeyFile**

Key in ethereum v3 format, encrypted with **Password**. It will be used for transactions on **PaymentsChain**.

Path must be absolute or relative to configuration file.

**StreamManagerAddress**

Used as a source for rewards.

**StakingManagerAddress**

Used as a source for delegation shares and transcoder reward.

**BlockContractAddress**

Application needs to store last processed block in a safe place. By default we will store this block in a file inside **DataDir**, but there is also an option to deploy a contract on videocoin blockchain and use it for storage.

To deploy:

```
./build/vidpool -c _assets/config.json deploy
```

Output:

```
Contract address: 0x6B14dfF51a349d3Eb430f48A783EBaA83153dbeB
```

If BlockContractAddress is defined application will be using a specified contract, otherwise, it will fall back to a file.

**WorkerChainURL**

ETH blockchain with StreamManager and StakingManager, in practice VideoCoin blockchain.

**PaymentsChainURL**

ETH blockchain where a worker has funds, in practice PublicMint blockchain.

**Auth**

**ClientID** is the one worker received in the VideoCoin console.

### Setup

Check out the dedicated guide for worker setup at [Setup](https://docs.videocoin.network/videocoin-pool-software/worker-setup-vidpool).

### Usage

**Public Mint integration**

To share payments with delegators you can use:

```
./build/vidpool -c _assets/config.json payout --dry-run
```

With `--dry-run` option transactions will be created but they won't be sent to blockchain To send transactions - remove `--dry-run` option.

User can specify `--csv=<file to path>` flag, in such case detailed information will be saved into csv file. If the file already exists - the file will be truncated, if doesn't exist - file will be created.

**Ethereum mainnet integration**

Since v0.2.0 release we support paying out to stakers flat percent over the period of time. For example, 8% over a year.

To learn more about the inner structure of such payments see [flat-payments](https://docs.videocoin.network/videocoin-pool-software/vidpool-flat-payments-percentage-based-payment-engine).

To make payments, setup configuration, and run:

```
vidpool flat --config <your config>
```

To see amounts before making payments use:

```
vidpool flat --config <your config> --dry-run --csv out.csv
```

### License
