Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9e01b9

Browse files
committed
improve sanity check, reduce claim precision
1 parent a8fc2c0 commit b9e01b9

File tree

3 files changed

+26
-47
lines changed

3 files changed

+26
-47
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ Starting on week 57 of the liquidity mining program (June 28th 2021), pools can
1515

1616
## Requirements
1717
* Python 3 + Jupyter Notebook
18-
* An ethereum node (for querying blocks timestamps and token decimals)
1918
* A [service account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-console) with read access to Google BigQuery
2019

2120
## Setup
2221
* Install required packages: `pip install -r requirements.txt`
23-
* Configure environment variables:
24-
* `ENDPOINT_URL`: URL to an ethereum node that can be queried via Websockets
22+
* Configure environment variable:
2523
* `GOOGLE_APPLICATION_CREDENTIALS`: path to a JSON file that contains a service account key with read access to Google BigQuery
2624

2725
## Usage
2826
1. Start Jupyter Notebook: `jupyter notebook`
2927
1. Open the `bal-mining.ipynb` notebook
3028
1. Run all cells
31-
2. Plots are displayed throughout the notebook. JSON reports are stored in the `reports` directory, with a final tally of user address to BAL received stored in the report week folder at `_totals.json`
29+
2. Plots are displayed throughout the notebook. JSON reports are stored in the `reports` directory as described above.
3230

3331
## Weekly distributions
3432

bal-mining.ipynb

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"outputs": [],
88
"source": [
99
"REALTIME_ESTIMATOR = False\n",
10-
"WEEK = 57"
10+
"WEEK = 58"
1111
]
1212
},
1313
{
@@ -46,7 +46,7 @@
4646
" 1: 'ethereum',\n",
4747
" 137: 'polygon'\n",
4848
"}\n",
49-
"CLAIM_PRECISION = 18 # leave out of results addresses that mined less than CLAIM_THRESHOLD\n",
49+
"CLAIM_PRECISION = 12 # leave out of results addresses that mined less than CLAIM_THRESHOLD\n",
5050
"CLAIM_THRESHOLD = 10**(-CLAIM_PRECISION)\n",
5151
"reports_dir = f'reports/{WEEK}'\n",
5252
"if not os.path.exists(reports_dir):\n",
@@ -132,7 +132,7 @@
132132
" '{0}'\n",
133133
" ];\n",
134134
"\n",
135-
" SELECT block_number, token_address, SUM(balance) AS supply\n",
135+
" SELECT block_number, token_address, SUM(balance)/1e18 AS supply\n",
136136
" FROM `{1}`\n",
137137
" WHERE token_address IN UNNEST(pool_addresses)\n",
138138
" AND address <> '0x0000000000000000000000000000000000000000'\n",
@@ -163,6 +163,7 @@
163163
"outputs": [],
164164
"source": [
165165
"def get_bpt_supply_subgraph(pools_addresses,\n",
166+
" time_travel_block,\n",
166167
" network):\n",
167168
"\n",
168169
" endpoint = {\n",
@@ -173,7 +174,8 @@
173174
" query = '''\n",
174175
" {\n",
175176
" pools(\n",
176-
" where:{address_in:\n",
177+
" block: {number: {}},\n",
178+
" where:{address_in:\n",
177179
" [\"{}\"]\n",
178180
" }\n",
179181
" ) {\n",
@@ -182,6 +184,7 @@
182184
" }\n",
183185
" }\n",
184186
" '''.replace('{','{{').replace('}','}}').replace('{{}}','{}').format(\n",
187+
" time_travel_block,\n",
185188
" '\",\"'.join(pools_addresses)\n",
186189
" )\n",
187190
" r = requests.post(endpoint[network], json = {'query':query})\n",
@@ -303,19 +306,20 @@
303306
" supply_gbq = get_bpt_supply_gbq(df.index, chain['chainId'])\n",
304307
" supply_gbq.set_index('token_address', inplace=True)\n",
305308
" supply_gbq.index.name = 'pool_address'\n",
306-
" supply_subgraph = get_bpt_supply_subgraph(df.index, chain['chainId'])\n",
309+
" gbq_block_number = int(supply_gbq.iloc[0]['block_number'])\n",
310+
" supply_subgraph = get_bpt_supply_subgraph(df.index, gbq_block_number, chain['chainId'])\n",
307311
" supply_subgraph.set_index('address', inplace=True)\n",
308312
" supply_subgraph.index.name = 'pool_address'\n",
309313
" all_good = True\n",
310314
" for i,r in supply_subgraph.join(supply_gbq).iterrows():\n",
311-
" error = (r.supply/1e18 / r.totalShares)\n",
315+
" error = (r.supply / r.totalShares)\n",
312316
" if abs(error-1) > 1e-3:\n",
313317
" all_good = False\n",
314318
" print(f'{i} : {error:.3f}')\n",
315319
" if all_good:\n",
316-
" print(' All good')\n",
320+
" print(' All good\\n')\n",
317321
" else:\n",
318-
" print('other than that, all good') \n",
322+
" print('other than that, all good\\n') \n",
319323
" \n",
320324
" chain_export = v2_liquidity_mining(WEEK, df, chain['chainId'])\n",
321325
" chain_export['chain_id'] = chain['chainId']\n",
@@ -423,10 +427,6 @@
423427
" full_export['timestamp'] = week_end_timestamp\n",
424428
" full_export['week'] = WEEK\n",
425429
" full_export.reset_index(inplace=True)\n",
426-
"# full_export.dropna(inplace=True)\n",
427-
"# full_export.to_gbq('bal_mining_estimates.lp_estimates_multitoken', \n",
428-
"# project_id=os.environ['GCP_PROJECT'], \n",
429-
"# if_exists='replace')\n",
430430
" full_export.to_gbq('bal_mining_estimates.lp_estimates_multitoken_staging', \n",
431431
" project_id=os.environ['GCP_PROJECT'], \n",
432432
" if_exists='replace')\n",
@@ -453,17 +453,6 @@
453453
" query.result()"
454454
]
455455
},
456-
{
457-
"cell_type": "code",
458-
"execution_count": null,
459-
"metadata": {},
460-
"outputs": [],
461-
"source": [
462-
"pd.read_json(\n",
463-
" f'https://raw.githubusercontent.com/balancer-labs/assets/master/lists/ui-not-eligible.json', \n",
464-
" orient='index').loc['homestead'].values.tolist()"
465-
]
466-
},
467456
{
468457
"cell_type": "markdown",
469458
"metadata": {},

bal-mining.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
REALTIME_ESTIMATOR = False
8-
WEEK = 57
8+
WEEK = 58
99

1010

1111
# In[ ]:
@@ -38,7 +38,7 @@
3838
1: 'ethereum',
3939
137: 'polygon'
4040
}
41-
CLAIM_PRECISION = 18 # leave out of results addresses that mined less than CLAIM_THRESHOLD
41+
CLAIM_PRECISION = 12 # leave out of results addresses that mined less than CLAIM_THRESHOLD
4242
CLAIM_THRESHOLD = 10**(-CLAIM_PRECISION)
4343
reports_dir = f'reports/{WEEK}'
4444
if not os.path.exists(reports_dir):
@@ -115,7 +115,7 @@ def get_bpt_supply_gbq(pools_addresses,
115115
'{0}'
116116
];
117117
118-
SELECT block_number, token_address, SUM(balance) AS supply
118+
SELECT block_number, token_address, SUM(balance)/1e18 AS supply
119119
FROM `{1}`
120120
WHERE token_address IN UNNEST(pool_addresses)
121121
AND address <> '0x0000000000000000000000000000000000000000'
@@ -143,6 +143,7 @@ def get_bpt_supply_gbq(pools_addresses,
143143

144144

145145
def get_bpt_supply_subgraph(pools_addresses,
146+
time_travel_block,
146147
network):
147148

148149
endpoint = {
@@ -153,7 +154,8 @@ def get_bpt_supply_subgraph(pools_addresses,
153154
query = '''
154155
{
155156
pools(
156-
where:{address_in:
157+
block: {number: {}},
158+
where:{address_in:
157159
["{}"]
158160
}
159161
) {
@@ -162,6 +164,7 @@ def get_bpt_supply_subgraph(pools_addresses,
162164
}
163165
}
164166
'''.replace('{','{{').replace('}','}}').replace('{{}}','{}').format(
167+
time_travel_block,
165168
'","'.join(pools_addresses)
166169
)
167170
r = requests.post(endpoint[network], json = {'query':query})
@@ -275,19 +278,20 @@ def v2_liquidity_mining(week,
275278
supply_gbq = get_bpt_supply_gbq(df.index, chain['chainId'])
276279
supply_gbq.set_index('token_address', inplace=True)
277280
supply_gbq.index.name = 'pool_address'
278-
supply_subgraph = get_bpt_supply_subgraph(df.index, chain['chainId'])
281+
gbq_block_number = int(supply_gbq.iloc[0]['block_number'])
282+
supply_subgraph = get_bpt_supply_subgraph(df.index, gbq_block_number, chain['chainId'])
279283
supply_subgraph.set_index('address', inplace=True)
280284
supply_subgraph.index.name = 'pool_address'
281285
all_good = True
282286
for i,r in supply_subgraph.join(supply_gbq).iterrows():
283-
error = (r.supply/1e18 / r.totalShares)
287+
error = (r.supply / r.totalShares)
284288
if abs(error-1) > 1e-3:
285289
all_good = False
286290
print(f'{i} : {error:.3f}')
287291
if all_good:
288-
print(' All good')
292+
print(' All good\n')
289293
else:
290-
print('other than that, all good')
294+
print('other than that, all good\n')
291295

292296
chain_export = v2_liquidity_mining(WEEK, df, chain['chainId'])
293297
chain_export['chain_id'] = chain['chainId']
@@ -378,10 +382,6 @@ def v2_liquidity_mining(week,
378382
full_export['timestamp'] = week_end_timestamp
379383
full_export['week'] = WEEK
380384
full_export.reset_index(inplace=True)
381-
# full_export.dropna(inplace=True)
382-
# full_export.to_gbq('bal_mining_estimates.lp_estimates_multitoken',
383-
# project_id=os.environ['GCP_PROJECT'],
384-
# if_exists='replace')
385385
full_export.to_gbq('bal_mining_estimates.lp_estimates_multitoken_staging',
386386
project_id=os.environ['GCP_PROJECT'],
387387
if_exists='replace')
@@ -408,14 +408,6 @@ def v2_liquidity_mining(week,
408408
query.result()
409409

410410

411-
# In[ ]:
412-
413-
414-
pd.read_json(
415-
f'https://raw.githubusercontent.com/balancer-labs/assets/master/lists/ui-not-eligible.json',
416-
orient='index').loc['homestead'].values.tolist()
417-
418-
419411
# # Gas Reimbursement Program
420412

421413
# In[ ]:

0 commit comments

Comments
 (0)