Skip to content

Commit 636367c

Browse files
committed
end of January updates (#3)
* update delegate date format to ISO * update gitignore to exclude venv folder * add contract counter * add requirements.txt * add web3.py for conversions * update readme file
1 parent ba35943 commit 636367c

File tree

5 files changed

+120
-62
lines changed

5 files changed

+120
-62
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ __pycache__/
1212
.env.development.local
1313
.env.test.local
1414
.env.production.local
15+
/venv
1516

1617
# Dependency directories
1718
/node_modules/

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
# Delegate Tracking
22

3-
This repository stores a Python Script for monitoring delegated MKR to Aligned Delegates at MakerDAO.
3+
This repository contains a Python script for monitoring MKR delegated to Aligned Delegates at MakerDAO.
44

5-
Since it utilizes Etherscan's API, an Etherscan API Key is required.
5+
## Important Note
6+
- The script is not compatible with Python 3.12 due to the deprecation of certain datetime functions used in the code.
67

7-
It will generate the amount of MKR delegated to each AD for each date in the selected range, as well as calculate the rank of that AD compared to all other ADs. This can be exported as a csv for ease of use.
8+
## Current Functionality
9+
- Retrieves delegation logs from Etherscan.
10+
- Allows querying of delegation data for specific dates or ranges.
11+
- Option to export results to a CSV file.
812

9-
AD information should be loaded as a CSV called "Aligned Delegates.csv" in the data folder. An example is provided that is correct as of 2024-01-04.
13+
## Requirements
14+
- An Etherscan API Key is required.
15+
- Python 3.x (versions prior to 3.12) and dependencies listed in `requirements.txt`.
1016

11-
## To Dos
17+
## Installation
18+
Follow these steps to set up the project:
19+
1. Clone the repository:
20+
```bash
21+
git clone https://github.com/0xldr/delegate-tracking.git
22+
```
23+
1. Navigate to the cloned directory:
24+
```bash
25+
cd delegate-tracking
26+
```
27+
1. Install the required dependencies:
28+
```bash
29+
pip install -r requirements.txt
30+
```
31+
32+
## Usage
33+
1. Install the required dependencies from `requirements.txt`.
34+
2. Run `delegate_tracking.py` and follow the on-screen prompts.
1235

13-
* General code clean up.
14-
* Add support for GSL end dates - currently this needs to be checked manually.
15-
* Automatically source participation data for votes.
36+
## To Dos
37+
- [ ] General code clean up.
38+
- [ ] Add support for GSL end dates.
39+
- [ ] Automatically source participation data for votes.

delegate_data/Aligned Delegates.csv

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
Delegate Name,Delegate Contract,Aligned Voter Committee,Start Date,End Date,End Reason
2-
BLUE,0xb18680092734394295d0591bb42f2bd3c184517e,KISS AVC,28/09/2023,,
3-
BONAPUBLICA,0xFE61acc408b63a5a03507A224398fa1FE8143F28,KISS AVC,04/07/2023,,
4-
Nimsen,0x907fea3a32215993cd6734402044f0957e1a3078,KISS AVC,29/08/2023,,
5-
Penguin Soldier,0x4d8c9c2cd8846533967b07becfc437542196ad6a, KISS AVC,17/07/2023,,
6-
vigilant,0xc2daea14891fc47ee76368ce7c54c7b200fba672,KISS AVC,02/04/2023,,
7-
Vision,0x918d368ea7bbe3af0f4ec9172802f8badae01284,KISS AVC,27/08/2023,,
8-
PBG,0x952dc79bcee652aad8cc9268d9c614fa166d0c1d,Neutral,09/04/2023,,
9-
Pf,0x62060879dfbb6def3b73cfc48f1f0595c0fed505,Neutral,11/04/2023,,
10-
QGov,0xca0c8bedc85c2ec9b0dfb42b3f2763486ddea1b6,Neutral,10/04/2023,,
11-
WBC,0xb086ec4303dc1514c09618c6c68ee444d6eee041,Neutral,11/05/2023,,
12-
0xDefensor,0xa67f820945da8634d5b54fe09ca74b1559b7ff39,Regenerative Finance AVC,07/04/2023,,
13-
BONAPUBLICA,0xe2bfda5e1f59325e4b8df5feaa30e4ab6516bf28,Regenerative Finance AVC,04/07/2023,,
14-
Byteron,0xa346C2EEa05bB32c986FF755b2F19d2f0ba8d14C,Regenerative Finance AVC,31/10/2023,,
15-
Cloaky,0x475efac48a0a18660a7a26ee6bd5febf466930f8,Regenerative Finance AVC,06/06/2023,,
16-
Ikagai,0xC0E23144db36101453BA5c426445ca5Bf20f6b71,Regenerative Finance AVC,13/08/2023,,
17-
PBG,0xc3b85930deca88e5bcb48fa8ebe935f97d5e412b,Regenerative Finance AVC,09/04/2023,,
18-
QGov,0x1dd6c65e6e22f196d5c2209f439d1f07d02ba7a4,Regenerative Finance AVC,07/07/2023,,
19-
Shanah,0x1D71861f54Aa6E63add5AcfC70E0E4bA9Fd9f259,Regenerative Finance AVC,02/10/2023,,
20-
Skynet,0xb6ca415fc42b3f96641d14280c3f3a0f078e50e5,Regenerative Finance AVC,06/06/2023,,
21-
TRUE NAME,0xddecead383f2c22b4755ab32f56d48a4a1415258,Regenerative Finance AVC,30/03/2023,,
22-
UPMaker,0x8cC777Ed9eb3A3b9087591697eCb7F60f256CE4F,Regenerative Finance AVC,17/04/2023,,
23-
WBC,0x58dc40b5f9f0758ee43b0a208fe362c90fdfad4d,Regenerative Finance AVC,11/05/2023,,
24-
0xDefensor,0xa4b28dd898a885cce88caa00261d9fe6ceed32bb,Resiliency AVC,07/04/2023,,
25-
Byteron,0x8Ea48C2264F1E5998c3aB3DF3037903F8FAe0cAa,Resiliency AVC,31/10/2023,,
26-
Ikagai,0xAB3fD902E4dad36c6b31E3954A8dE14Dd829533c,Resiliency AVC,13/08/2023,,
27-
JAG,0xfbec297af3f4925966ab295a0771c420a9e85e08,Resiliency AVC,25/05/2023,,
28-
Nimsen,0xa2c669dc868be0a2a8d6c0ad715e17f45035ba76,Resiliency AVC,29/08/2023,,
29-
PBG,0x69b576a7e193a15a570ee5bb2149deb3f03537a2,Resiliency AVC,11/07/2023,,
30-
Penguin Soldier,0x5b4870014313c808c374F8eD1AB5b78813EB9c7f,Resiliency AVC,25/09/2023,,
31-
Pipkin,0x45C52826EFA13A6DE713528BF42B520C9fA50081,Resiliency AVC,17/01/2024,,
32-
QGov,0x0a907fe3adb890db7db27a7f21e188a4127b2e7c,Resiliency AVC,10/04/2023,,
33-
Shanah,0xdbb451BFd4e6E461caa2C8bf0dC83346A211c29C,Resiliency AVC,02/10/2023,,
34-
Skynet,0x644c092a5ccafc425ebf133123299a6397ae97d9,Resiliency AVC,06/06/2023,,
35-
TRUE NAME,0x87686C4Dd2FFd8e0b01f716EEA1573f829737e97,Resiliency AVC,30/03/2023,,
36-
UPMaker,0x27194176525a0088e3dc96973b22b01b15376ebd,Resiliency AVC,17/04/2023,,
37-
vigilant,0x51f3067cb6a1185d1e8316332921d9501fc4c006,Resiliency AVC,10/07/2023,,
38-
Vision,0x3200c191cc245b3e2de3fd3b3087104f3f313f57,Resiliency AVC,26/08/2023,,
39-
WBC,0x5b0a4932dc9e253f9b15fd69f07b68e9874ea794,Resiliency AVC,10/07/2023,,
40-
BLUE,0x445cb6c63c502fdbebd1b273f6aea1aad691e0aa,Sovereign Finance AVC,19/05/2023,,
41-
Cloaky,0xb335e8b70f95f28e79acf58491751f83b0050888,Sovereign Finance AVC,06/06/2023,,
42-
JAG,0x36124cee63ae786eea41bda0fb61b1b946e4c08c,Sovereign Finance AVC,25/05/2023,,
43-
Pipkin,0x47EcD8e9f8F299cE47E3aB891a874707d70A3aF9,Sovereign Finance AVC, 17/01/2024,,
2+
BLUE,0xb18680092734394295d0591bb42f2bd3c184517e,KISS AVC,2023-09-28,,
3+
BONAPUBLICA,0xFE61acc408b63a5a03507A224398fa1FE8143F28,KISS AVC,2023-07-04,,
4+
Nimsen,0x907fea3a32215993cd6734402044f0957e1a3078,KISS AVC,2023-08-29,,
5+
Penguin Soldier,0x4d8c9c2cd8846533967b07becfc437542196ad6a, KISS AVC,2023-07-17,,
6+
vigilant,0xc2daea14891fc47ee76368ce7c54c7b200fba672,KISS AVC,2023-04-02,,
7+
Vision,0x918d368ea7bbe3af0f4ec9172802f8badae01284,KISS AVC,2023-08-27,,
8+
PBG,0x952dc79bcee652aad8cc9268d9c614fa166d0c1d,Neutral,2023-04-09,,
9+
Pf,0x62060879dfbb6def3b73cfc48f1f0595c0fed505,Neutral,2023-04-11,,
10+
QGov,0xca0c8bedc85c2ec9b0dfb42b3f2763486ddea1b6,Neutral,2023-04-10,,
11+
WBC,0xb086ec4303dc1514c09618c6c68ee444d6eee041,Neutral,2023-05-11,,
12+
0xDefensor,0xa67f820945da8634d5b54fe09ca74b1559b7ff39,Regenerative Finance AVC,2023-04-07,,
13+
BONAPUBLICA,0xe2bfda5e1f59325e4b8df5feaa30e4ab6516bf28,Regenerative Finance AVC,2023-07-04,,
14+
Byteron,0xa346C2EEa05bB32c986FF755b2F19d2f0ba8d14C,Regenerative Finance AVC,2023-10-31,,
15+
Cloaky,0x475efac48a0a18660a7a26ee6bd5febf466930f8,Regenerative Finance AVC,2023-06-06,,
16+
Ikagai,0xC0E23144db36101453BA5c426445ca5Bf20f6b71,Regenerative Finance AVC,2023-08-13,,
17+
PBG,0xc3b85930deca88e5bcb48fa8ebe935f97d5e412b,Regenerative Finance AVC,2023-04-09,,
18+
QGov,0x1dd6c65e6e22f196d5c2209f439d1f07d02ba7a4,Regenerative Finance AVC,2023-07-07,,
19+
Shanah,0x1D71861f54Aa6E63add5AcfC70E0E4bA9Fd9f259,Regenerative Finance AVC,2023-10-02,,
20+
Skynet,0xb6ca415fc42b3f96641d14280c3f3a0f078e50e5,Regenerative Finance AVC,2023-06-06,,
21+
TRUE NAME,0xddecead383f2c22b4755ab32f56d48a4a1415258,Regenerative Finance AVC,2023-03-30,,
22+
UPMaker,0x8cC777Ed9eb3A3b9087591697eCb7F60f256CE4F,Regenerative Finance AVC,2023-04-17,,
23+
WBC,0x58dc40b5f9f0758ee43b0a208fe362c90fdfad4d,Regenerative Finance AVC,2023-05-11,,
24+
0xDefensor,0xa4b28dd898a885cce88caa00261d9fe6ceed32bb,Resiliency AVC,2023-04-07,,
25+
Byteron,0x8Ea48C2264F1E5998c3aB3DF3037903F8FAe0cAa,Resiliency AVC,2023-10-31,,
26+
Ikagai,0xAB3fD902E4dad36c6b31E3954A8dE14Dd829533c,Resiliency AVC,2023-08-13,,
27+
JAG,0xfbec297af3f4925966ab295a0771c420a9e85e08,Resiliency AVC,2023-05-25,,
28+
Nimsen,0xa2c669dc868be0a2a8d6c0ad715e17f45035ba76,Resiliency AVC,2023-08-29,,
29+
PBG,0x69b576a7e193a15a570ee5bb2149deb3f03537a2,Resiliency AVC,2023-07-11,,
30+
Penguin Soldier,0x5b4870014313c808c374F8eD1AB5b78813EB9c7f,Resiliency AVC,2023-09-25,,
31+
Pipkin,0x45C52826EFA13A6DE713528BF42B520C9fA50081,Resiliency AVC,2024-01-17,,
32+
QGov,0x0a907fe3adb890db7db27a7f21e188a4127b2e7c,Resiliency AVC,2023-04-10,,
33+
Shanah,0xdbb451BFd4e6E461caa2C8bf0dC83346A211c29C,Resiliency AVC,2023-10-02,,
34+
Skynet,0x644c092a5ccafc425ebf133123299a6397ae97d9,Resiliency AVC,2023-06-06,,
35+
TRUE NAME,0x87686C4Dd2FFd8e0b01f716EEA1573f829737e97,Resiliency AVC,2023-03-30,,
36+
UPMaker,0x27194176525a0088e3dc96973b22b01b15376ebd,Resiliency AVC,2023-04-17,,
37+
vigilant,0x51f3067cb6a1185d1e8316332921d9501fc4c006,Resiliency AVC,2023-07-10,,
38+
Vision,0x3200c191cc245b3e2de3fd3b3087104f3f313f57,Resiliency AVC,2023-08-26,,
39+
WBC,0x5b0a4932dc9e253f9b15fd69f07b68e9874ea794,Resiliency AVC,2023-07-10,,
40+
BLUE,0x445cb6c63c502fdbebd1b273f6aea1aad691e0aa,Sovereign Finance AVC,2023-05-19,,
41+
Cloaky,0xb335e8b70f95f28e79acf58491751f83b0050888,Sovereign Finance AVC,2023-06-06,,
42+
JAG,0x36124cee63ae786eea41bda0fb61b1b946e4c08c,Sovereign Finance AVC,2023-05-25,,
43+
Pipkin,0x47EcD8e9f8F299cE47E3aB891a874707d70A3aF9,Sovereign Finance AVC,2024-01-17,,

delegate_tracking.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import csv
66
import logging
77
from dotenv import load_dotenv
8+
from web3 import Web3
89

910
# Load environment variables
1011
load_dotenv()
@@ -38,19 +39,10 @@ def get_logs(api_key, base_url, contract_address, start_block, end_block, event_
3839
except requests.exceptions.RequestException as e:
3940
logging.error(f"Error during requests to {base_url}: {e}")
4041

41-
def convert_hex_to_decimal(hex_value):
42-
return int(hex_value, 16)
43-
44-
def convert_hex_to_eth_address(hex_value):
45-
return '0x' + hex_value[-40:]
46-
4742
def convert_hex_to_datetime(hex_value):
4843
timestamp = int(hex_value, 16)
4944
return datetime.datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d') # Only return the date part
5045

51-
def convert_wei_to_ether(wei_value):
52-
return wei_value / 1e18
53-
5446
def get_closest_delegation(delegation_data, query_datetime):
5547
closest_delegation = 0
5648
query_date = query_datetime.date() # Convert datetime to date for comparison
@@ -148,7 +140,10 @@ def calculate_rankings(delegate_data):
148140
end_block = 'latest'
149141

150142
# Process each contract from CSV data
143+
contract_number = 0
151144
for contract in contracts_data:
145+
contract_number += 1
146+
print(f'Processing contract {contract_number}')
152147
address = contract['contract']
153148
# Initialize storage for each contract and delegate
154149
contract_delegations[address] = {}
@@ -158,9 +153,9 @@ def calculate_rankings(delegate_data):
158153
logs = get_logs(etherscan_api_key, etherscan_base_url, address, start_block, end_block, event_hash)
159154
for log in logs['result']:
160155
hex_data = log['data']
161-
decimal_data = convert_hex_to_decimal(hex_data)
162-
ether_value = convert_wei_to_ether(decimal_data)
163-
delegate_address = convert_hex_to_eth_address(log['topics'][1])
156+
decimal_data = Web3.to_int(hexstr=log['data'])
157+
ether_value = Web3.from_wei(decimal_data, 'ether')
158+
delegate_address = Web3.to_checksum_address(log['topics'][1][-40:])
164159
timestamp = convert_hex_to_datetime(log['timeStamp'])
165160

166161
# Initialize delegate storage

requirements.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
aiohttp==3.9.3
2+
aiosignal==1.3.1
3+
attrs==23.2.0
4+
bitarray==2.9.2
5+
certifi==2023.11.17
6+
charset-normalizer==3.3.2
7+
cytoolz==0.12.3
8+
eth-account==0.10.0
9+
eth-hash==0.6.0
10+
eth-keyfile==0.7.0
11+
eth-keys==0.5.0
12+
eth-rlp==1.0.1
13+
eth-typing==4.0.0
14+
eth-utils==3.0.0
15+
eth_abi==5.0.0
16+
frozenlist==1.4.1
17+
hexbytes==0.3.1
18+
idna==3.6
19+
jsonschema==4.21.1
20+
jsonschema-specifications==2023.12.1
21+
lru-dict==1.2.0
22+
multidict==6.0.4
23+
parsimonious==0.9.0
24+
protobuf==4.25.2
25+
pycryptodome==3.20.0
26+
python-dotenv==1.0.1
27+
pyunormalize==15.1.0
28+
referencing==0.33.0
29+
regex==2023.12.25
30+
requests==2.31.0
31+
rlp==4.0.0
32+
rpds-py==0.17.1
33+
toolz==0.12.1
34+
typing_extensions==4.9.0
35+
urllib3==2.2.0
36+
web3==6.15.0
37+
websockets==12.0
38+
yarl==1.9.4

0 commit comments

Comments
 (0)