Metadata-Version: 2.1
Name: dhkdao-airdrop
Version: 0.1.0
Summary: DHK dao airdrop scripts
Keywords: DHK,DHK dao,airdrop
Author-Email: Jimmy Chu <jimmychu0807@gmail.com>
License: MIT License
         
         Copyright (c) 2024 DHK dao
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
         
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.10
Project-URL: Homepage, https://github.com/dhkdao/airdrop-scripts
Project-URL: Documentation, https://github.com/dhkdao/airdrop-scripts/blob/main/README.md
Project-URL: Issues, https://github.com/dhkdao/airdrop-scripts/issues
Requires-Python: >=3.10
Requires-Dist: pandas>=2.2.3
Requires-Dist: python-dotenv
Requires-Dist: numpy>=2.1.0
Requires-Dist: typer>=0.12.5
Requires-Dist: requests>=2.32.3
Description-Content-Type: text/markdown

# DHK Tokens Airdrop Scripts

A Python script to retrieve historical token prices and compute DHK tokens to distribute out each month.

Output example

![ss-example](./docs/ss-example.png)

The key output is the table at the bottom. It can also be exported as csv or json.

It is fine to see error messages as above saying unable to fetch price and  staking apr for some tokens, as they may not be popular enough or not indexed by the service providers we used.

## Usage

```bash
pip install dhkdao-airdrop

# Get help
dhkdao-airdrop --help

# Run script with api keys set in config.json
dhkdao-airdrop config.json -o output -t type

# Run script with api keys set in env vars
CRYPTOCOMPARE_APIKEY="cc-apikey" MINTSCAN_APIKEY="ms-apikey" dhkdao-airdrop config.json -o output -t type
```

Options:

- `-o`: Output file path. If skipped, output is printed on screen.
- `-t`: [table|csv|json]. Output type.

You can have api keys set in the input config file or env var. Env vars will override the one set in config file.

### Input Config

An input config example is follows.

```json
{
    "dhk_distribution": 100000,
    "reference_date": "2024-08-27",
    "tokens": [
        { "token": "AKT", "network": "akash", "qty": 188787 },
        { "token": "ATOM", "network": "cosmos", "qty": 592015 }
    ],
    "apis": {
        "cryptocompare": {
            "endpoint": "https://min-api.cryptocompare.com/data/pricehistorical",
            "apikey": "cryptocompare-123456"
        },
        "mintscan": {
            "endpoint": "https://apis.mintscan.io/v1/:network/apr",
            "apikey": "mintscan-123456"
        }
    }
}
```

- The config used to run for **2024 Sep** output is [shown here](./configs/config-202409.json), with the two `apikey` values redacted.

- Most of the time, you only need to change the `reference_date` and the content inside `tokens`, after you have set the two `apikey` values correctly.

- For each token inside `tokens`, you also need to provide a `network` value, which is different from the token name. This is required by [Cosmostation API](https://docs.cosmostation.io/apis/reference/utilities/staking-apr). If an incorrect network value is provided, the staking APR will not be fetched. You can test the network value in the API panel provided by the link above. Another way is going to [Mintscan](https://www.mintscan.io/) and search for the token/network, the white label underneath it, as circled below, is the network value used in Cosmostation.

  ![network value](./docs/ss-networkvalue.png)

- If you couldn't get a network staking APR from Mintscan API but know it somewhere, you can set `{..., "staking-apr": 0.xxx}` manually. This will prevent the script from fetching it from Cosmostation.

  Same principle goes that if you couldn't get a token price from Cyptocompare API but know it somewhere, you can set `{..., "price": xx.xxx }` manually. This will override the token price.

  An example is [here](https://github.com/dhkdao/airdrop-scripts/blob/jc/dev/configs/config-202409.json#L10).

## Data Sources

- Token price: <https://www.cryptocompare.com/>
- Staking APR: <https://www.mintscan.io/> (operated by [Cosmostation](https://cosmostation.io/))
- [DHK airdrop template master speadsheet](https://docs.google.com/spreadsheets/d/1QliDXE6yMNnPxhqraLqhTDnRQ0vbpvapLYoMC0vFgSc/edit?usp=sharing)

## Development

```bash
# sync all the dependencies
pdm sync -d

# show the help text
pdm exe --help

# Run the regular command
pdm exe input.json -o output -t json

# Run test cases with no output capture
pdm test:no-capture
```

Please copy `.env.example` over to `.env` and fills in the API_KEYs inside before running `pdm test`. Otherwise, tests expected to pass will fail.
