-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgcc_total_circulating_supply.py
95 lines (65 loc) · 2.43 KB
/
gcc_total_circulating_supply.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
This file is used for Google Cloud functions to serve circulating supply calculations
"""
import os
import json
from web3 import Web3
from utils.node import init_erc20
from utils.constants import TRI_ADDRESS
from gcc_utils import get_event_id, get_google_cloud_storage_blob
# Output file name
FILE_NAME = "circulating_supply.json"
FILES = [
{"content_type": "application/json", "path": "circulating_supply.json"},
{"content_type": "text/plain", "path": "circulating_supply.txt"},
]
# Google Cloud Storage
TRISOLARIS_APR_BUCKET = "trisolaris_public"
TRISOLARIS_APR_BUCKET_FILE_PATH = FILE_NAME
# This is the tx where 160MM TRI was locked
LOCKED_TRI_TRANSACTION_HASH = (
"0x93026b0e7150837de8180890d4f1790bf14f3bc36f771433717830647c1a0516"
)
TAG = "[GCC TOTAL CIRC]"
web3_url = os.getenv("AURORA_W3_URL", "https://mainnet.aurora.dev/")
w3 = Web3(Web3.HTTPProvider(web3_url))
tri = init_erc20(TRI_ADDRESS)
# Calculated total circulating supply of TRI
# Uploads result to gcc file storage
def gcc_total_circulating_supply(data, context):
event_id = get_event_id(context)
print(
TAG + "Beginning Google Cloud Fn processing for event_id: {0}".format(event_id)
)
circulating_supply = str(get_total_circulating_supply())
print(TAG + " TRI: {0}".format(circulating_supply))
for file in FILES:
upload_to_gcs(
TRISOLARIS_APR_BUCKET,
file["path"],
file["content_type"],
circulating_supply,
)
def upload_to_gcs(bucket, path, content_type, data):
blob = get_google_cloud_storage_blob(bucket, path)
blob.upload_from_string(data, content_type)
# Don't serve stale data
blob.cache_control = "no-cache"
# Allows file to be publicly accessible
blob.make_public()
# Save
blob.patch()
print(TAG + " Uploading to gcc location: {0}/{1} complete".format(bucket, path))
def get_locked_tri():
transaction_receipt = w3.eth.get_transaction_receipt(LOCKED_TRI_TRANSACTION_HASH)
data = transaction_receipt.logs[0].data
locked_tri = int(data, 16)
return locked_tri
def get_total_circulating_supply():
current_total_supply = tri.functions.totalSupply().call()
decimals = tri.functions.decimals().call()
locked_tri = get_locked_tri()
circulating_supply = current_total_supply - locked_tri
return circulating_supply / (10**decimals)
if __name__ == "__main__":
gcc_total_circulating_supply(None, None)