forked from yearn/yearn-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexporter.py
37 lines (30 loc) · 1.18 KB
/
exporter.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
import logging
import os
import time
import sentry_sdk
from brownie import chain
from yearn.outputs.victoria import output_duration
from yearn.prices import constants
from yearn.yearn import Yearn
sentry_sdk.set_tag('script','exporter')
logger = logging.getLogger('yearn.exporter')
sleep_interval = int(os.environ.get('SLEEP_SECONDS', '0'))
def main():
yearn = Yearn()
for block in chain.new_blocks(height_buffer=1):
start_time = time.time()
yearn.export(block.number, block.timestamp)
duration = time.time() - start_time
output_duration.export(duration, 1, "forwards", block.timestamp)
time.sleep(sleep_interval)
def tvl():
yearn = Yearn()
for block in chain.new_blocks(height_buffer=1):
data = yearn.total_value_at(block.number)
products = list(data.keys())
if yearn.exclude_ib_tvl and block > constants.ib_snapshot_block:
products.remove('ib')
total = sum(sum(vaults.values()) for (product, vaults) in data.items() if product in products)
print(f"block={block.number} tvl={total}")
logger.info('exported block=%d tvl=%.0f', block.number, total)
time.sleep(sleep_interval)