Skip to content

Commit

Permalink
Formalize the project to become a script runnable in CLI (#9)
Browse files Browse the repository at this point in the history
* Run for Sep airdrop

* Added date on the title

* Added pdm as dependencies manager

* Added github action as well

* updated CI

* Added a simple test case to pass the CI
  • Loading branch information
jimmychu0807 authored Sep 25, 2024
1 parent 06bcc29 commit 99caafb
Show file tree
Hide file tree
Showing 12 changed files with 557 additions and 459 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = true

[*]
indent_style=space
indent_size=2
indent_size=4
end_of_line=lf
charset=utf-8
trim_trailing_whitespace=true
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tests

on:
pull_request:
push:
branches: ["main"]

jobs:
tests:
strategy:
matrix:
python-version: ['3.10']
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pdm sync -d
- name: Run Tests
run: |
pdm run all
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ A [Python script](./notebooks/airdrop.ipynb) to retrieve historical token prices

- [DHK airdrop template master speadsheet](https://docs.google.com/spreadsheets/d/1QliDXE6yMNnPxhqraLqhTDnRQ0vbpvapLYoMC0vFgSc/edit?usp=sharing)

## Data Source
## Data Sources

Token price:
- <https://www.cryptocompare.com/>

Staking APR:
- <https://www.mintscan.io/> (operated by [Cosmostation](https://cosmostation.io/))

## Usage

Please copy `.env.example` over to `.env` and fills in the API_KEYs inside.
173 changes: 81 additions & 92 deletions notebooks/airdrop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"id": "2d32dcc5-6920-4853-a003-5dc1f2155f8f",
"metadata": {},
"source": [
"## DHK Airdrop Script"
"## DHK Airdrop Script (2024 Sep)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"id": "2d72cd3a-fe30-4b0d-a4c0-1c33d1bf773e",
"metadata": {},
"outputs": [],
Expand All @@ -24,22 +24,23 @@
"\n",
"DHK_DISTRIBUTION = 100000\n",
"# Date for the price reference\n",
"PRICE_REF_DATE = datetime(2024, 7, 29, 12, tzinfo=timezone.utc)\n",
"PRICE_REF_DATE = datetime(2024, 8, 27, 12, tzinfo=timezone.utc)\n",
"\n",
"TOKENS = [\n",
" { \"token\": \"AKT\", \"network\": \"akash\", \"qty\": 189628 },\n",
" { \"token\": \"ATOM\", \"network\": \"cosmos\", \"qty\": 592191 },\n",
" { \"token\": \"AKT\", \"network\": \"akash\", \"qty\": 188787 },\n",
" { \"token\": \"ATOM\", \"network\": \"cosmos\", \"qty\": 592015 },\n",
" { \"token\": \"JUNO\", \"network\": \"juno-1\", \"qty\": 84703 },\n",
"\n",
" # manual price and staking-apr\n",
" { \"token\": \"DSM\", \"price\": 0.002867, \"staking-apr\": 0, \"qty\": 3967661 },\n",
" { \"token\": \"EVMOS\", \"network\": \"evmos\", \"qty\": 248824 },\n",
" { \"token\": \"JUNO\", \"network\": \"juno\", \"qty\": 87290 },\n",
" { \"token\": \"OSMO\", \"network\": \"osmosis\", \"qty\": 984661 },\n",
" # manual price\n",
" # { \"token\": \"HASH\", \"price\": \"\", \"network\": \"hash\", \"qty\": 25020226 },\n",
" { \"token\": \"OSMO\", \"network\": \"osmosis-1\", \"qty\": 862867 },\n",
"\n",
" # manual price and staking-apr\n",
" { \"token\": \"STARS\", \"price\": 0.00717, \"staking-apr\": 0.1355, \"qty\": 1908776 },\n",
" { \"token\": \"STARS\", \"price\": (0.008472+0.007874)/2, \"staking-apr\": 0.1363, \"qty\": 779458 },\n",
" { \"token\": \"DSM\", \"price\": 0, \"staking-apr\": 0, \"qty\": 4010125 }, \n",
"]\n",
"\n",
"\n",
"APIS = {\n",
" \"cryptocompare\": {\n",
" \"endpoint\": \"https://min-api.cryptocompare.com/data/pricehistorical\",\n",
Expand All @@ -54,9 +55,11 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"id": "4c242dbe-8086-46a1-9c4d-49da4e08abde",
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -93,88 +96,77 @@
" <tr>\n",
" <th>0</th>\n",
" <td>AKT</td>\n",
" <td>3.225500</td>\n",
" <td>189628.0</td>\n",
" <td>611645.11</td>\n",
" <td>0.1434</td>\n",
" <td>87709.91</td>\n",
" <td>12.721</td>\n",
" <td>12721.0</td>\n",
" <td>2.860000</td>\n",
" <td>188787.0</td>\n",
" <td>539930.82</td>\n",
" <td>0.1438</td>\n",
" <td>77642.05</td>\n",
" <td>14.486</td>\n",
" <td>14485.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>ATOM</td>\n",
" <td>6.238000</td>\n",
" <td>592191.0</td>\n",
" <td>3694087.46</td>\n",
" <td>0.1507</td>\n",
" <td>556698.98</td>\n",
" <td>80.741</td>\n",
" <td>80740.0</td>\n",
" <td>4.764000</td>\n",
" <td>592015.0</td>\n",
" <td>2820359.46</td>\n",
" <td>0.1504</td>\n",
" <td>424182.06</td>\n",
" <td>79.141</td>\n",
" <td>79140.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>DSM</td>\n",
" <td>0.002867</td>\n",
" <td>3967661.0</td>\n",
" <td>11375.28</td>\n",
" <td>0.0000</td>\n",
" <td>0.0</td>\n",
" <td>0.000</td>\n",
" <td>0.0</td>\n",
" <td>JUNO</td>\n",
" <td>0.098000</td>\n",
" <td>84703.0</td>\n",
" <td>8300.89</td>\n",
" <td>0.1855</td>\n",
" <td>1539.82</td>\n",
" <td>0.287</td>\n",
" <td>287.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>EVMOS</td>\n",
" <td>0.029390</td>\n",
" <td>248824.0</td>\n",
" <td>7312.94</td>\n",
" <td>0.0219</td>\n",
" <td>160.15</td>\n",
" <td>0.023</td>\n",
" <td>23.0</td>\n",
" <td>OSMO</td>\n",
" <td>0.428400</td>\n",
" <td>862867.0</td>\n",
" <td>369652.22</td>\n",
" <td>0.0859</td>\n",
" <td>31753.13</td>\n",
" <td>5.924</td>\n",
" <td>5924.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>JUNO</td>\n",
" <td>0.108500</td>\n",
" <td>87290.0</td>\n",
" <td>9470.97</td>\n",
" <td>0.1782</td>\n",
" <td>1687.73</td>\n",
" <td>0.245</td>\n",
" <td>244.0</td>\n",
" <td>STARS</td>\n",
" <td>0.008173</td>\n",
" <td>779458.0</td>\n",
" <td>6370.51</td>\n",
" <td>0.1363</td>\n",
" <td>868.3</td>\n",
" <td>0.162</td>\n",
" <td>162.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>OSMO</td>\n",
" <td>0.485800</td>\n",
" <td>984661.0</td>\n",
" <td>478348.31</td>\n",
" <td>0.0865</td>\n",
" <td>41377.13</td>\n",
" <td>6.001</td>\n",
" <td>6001.0</td>\n",
" <td>DSM</td>\n",
" <td>0.000000</td>\n",
" <td>4010125.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0000</td>\n",
" <td>0.0</td>\n",
" <td>0.000</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>STARS</td>\n",
" <td>0.007170</td>\n",
" <td>1908776.0</td>\n",
" <td>13685.92</td>\n",
" <td>0.1355</td>\n",
" <td>1854.44</td>\n",
" <td>0.269</td>\n",
" <td>268.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>TOTAL</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>4825925.99</td>\n",
" <td>3744613.9</td>\n",
" <td>NaN</td>\n",
" <td>689488.34</td>\n",
" <td>535985.36</td>\n",
" <td>100.000</td>\n",
" <td>100000.0</td>\n",
" </tr>\n",
Expand All @@ -184,27 +176,25 @@
],
"text/plain": [
" token price staking-amt staking-val staking-apr reward \\\n",
"0 AKT 3.225500 189628.0 611645.11 0.1434 87709.91 \n",
"1 ATOM 6.238000 592191.0 3694087.46 0.1507 556698.98 \n",
"2 DSM 0.002867 3967661.0 11375.28 0.0000 0.0 \n",
"3 EVMOS 0.029390 248824.0 7312.94 0.0219 160.15 \n",
"4 JUNO 0.108500 87290.0 9470.97 0.1782 1687.73 \n",
"5 OSMO 0.485800 984661.0 478348.31 0.0865 41377.13 \n",
"6 STARS 0.007170 1908776.0 13685.92 0.1355 1854.44 \n",
"7 TOTAL NaN NaN 4825925.99 NaN 689488.34 \n",
"0 AKT 2.860000 188787.0 539930.82 0.1438 77642.05 \n",
"1 ATOM 4.764000 592015.0 2820359.46 0.1504 424182.06 \n",
"2 JUNO 0.098000 84703.0 8300.89 0.1855 1539.82 \n",
"3 OSMO 0.428400 862867.0 369652.22 0.0859 31753.13 \n",
"4 STARS 0.008173 779458.0 6370.51 0.1363 868.3 \n",
"5 DSM 0.000000 4010125.0 0.0 0.0000 0.0 \n",
"6 TOTAL NaN NaN 3744613.9 NaN 535985.36 \n",
"\n",
" dhk-distribution-pc dhk-distribution \n",
"0 12.721 12721.0 \n",
"1 80.741 80740.0 \n",
"2 0.000 0.0 \n",
"3 0.023 23.0 \n",
"4 0.245 244.0 \n",
"5 6.001 6001.0 \n",
"6 0.269 268.0 \n",
"7 100.000 100000.0 "
"0 14.486 14485.0 \n",
"1 79.141 79140.0 \n",
"2 0.287 287.0 \n",
"3 5.924 5924.0 \n",
"4 0.162 162.0 \n",
"5 0.000 0.0 \n",
"6 100.000 100000.0 "
]
},
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -241,7 +231,7 @@
" raise Exception(f\"fetch_price connection error: {e}\")\n",
"\n",
" if(from_symbol not in data):\n",
" raise Exception(f\"unable to fetch price, returning: {data}\")\n",
" raise Exception(f\"{from_symbol}: unable to fetch price for, returning: {data}\")\n",
" \n",
" return data[from_symbol][to_symbol] \n",
"\n",
Expand All @@ -266,7 +256,7 @@
" raise Exception(f\"fetch_staking_apr connection error: {e}\")\n",
"\n",
" if(\"apr\" not in data):\n",
" raise Exception(f\"unable to fetch staking_apr, returning: {data}\")\n",
" raise Exception(f\"{network}: unable to fetch staking_apr, returning: {data}\")\n",
" \n",
" return float(data[\"apr\"])\n",
" \n",
Expand Down Expand Up @@ -308,7 +298,6 @@
" \n",
" return mt\n",
"\n",
"\n",
"get_main_table()"
]
}
Expand Down
Loading

0 comments on commit 99caafb

Please sign in to comment.