Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXP-16-218] Treasury and SMS on fantom #218

Merged
merged 84 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
bcdf4be
feat: add tx exporter
BobTheBuidler Jan 31, 2022
d6992ec
feat: add skeleton
BobTheBuidler Jan 31, 2022
5d81a0c
fix: temporarily disable victoria
BobTheBuidler Jan 31, 2022
3e695d4
feat: add total users
BobTheBuidler Jan 31, 2022
3a2cd22
feat: count wallets by # vaults used
BobTheBuidler Jan 31, 2022
ca0512c
feat: add total users by vault
BobTheBuidler Jan 31, 2022
f3322e9
fix: use Decimal instead of float
BobTheBuidler Jan 31, 2022
72736cf
feat: use pickle instead of csv for tx cache
BobTheBuidler Jan 31, 2022
202017f
chore: refactor
BobTheBuidler Jan 31, 2022
d7bcf98
chore: checkpoint tx pickle thru block 10949751
BobTheBuidler Jan 31, 2022
3135fc9
feat: parallelism
BobTheBuidler Jan 31, 2022
697c421
fix: accept new transfer event field labels
BobTheBuidler Jan 31, 2022
a588e6f
fix: handle reverts in price magic
BobTheBuidler Jan 31, 2022
5ebfb5d
fix: etherscan rate limit handler
BobTheBuidler Jan 31, 2022
9dade81
chore: refactor dataframe
BobTheBuidler Jan 31, 2022
850701b
chore: increase dop
BobTheBuidler Jan 31, 2022
2f89eae
chore: refactor
BobTheBuidler Jan 31, 2022
ac2acdf
chore: checkpoint tx pickle thru block 13398262
BobTheBuidler Jan 31, 2022
6416766
feat:user balances (#2)
BobTheBuidler Jan 31, 2022
e8b25a1
feat: merge tx analysis with existing exporter
BobTheBuidler Jan 16, 2022
c3de1c5
chore: wallets not users
BobTheBuidler Jan 16, 2022
cc9adb6
chore: cleanup
BobTheBuidler Jan 16, 2022
44e6757
chore: wallets not users
BobTheBuidler Jan 16, 2022
d6795a5
chore: refactor
BobTheBuidler Jan 16, 2022
88d5932
feat: env variable to skip wallet stats for speed
BobTheBuidler Jan 16, 2022
81bf2a5
chore: cleanup
BobTheBuidler Jan 16, 2022
5bd9df4
fix: skip transfers
BobTheBuidler Jan 16, 2022
249a8d6
fix: typo
BobTheBuidler Jan 16, 2022
9a40cf4
feat: treasury exporter
BobTheBuidler Jan 16, 2022
6f2d352
feat: add buckets
BobTheBuidler Jan 16, 2022
6f04d25
fix: add details to revert message when can't decode logs
BobTheBuidler Jan 16, 2022
2153390
feat: postgres tx caching
BobTheBuidler Jan 16, 2022
736e535
chore: cleanup reverted changes
BobTheBuidler Jan 16, 2022
7bddd74
feat: yearn.describe_wallets
BobTheBuidler Jan 16, 2022
971b0cc
feat: wallet exporter
BobTheBuidler Jan 16, 2022
5c5a047
feat: specify new agg stats
BobTheBuidler Jan 16, 2022
1763923
feat: skip middleware if already setup
BobTheBuidler Jan 16, 2022
d7f527d
chore: cleanup
BobTheBuidler Jan 16, 2022
1967534
chore: black
BobTheBuidler Jan 16, 2022
d8659f9
chore: cleanup
BobTheBuidler Jan 16, 2022
3515fbe
chore: cleanup
BobTheBuidler Jan 16, 2022
957e739
fix: setup middleware
BobTheBuidler Jan 16, 2022
ab23068
chore: revert changes to create_filter
BobTheBuidler Jan 16, 2022
faa0853
chore: revert silent kwarg on magic.get_price
BobTheBuidler Jan 16, 2022
e4a38e6
chore: refactor
BobTheBuidler Jan 16, 2022
6faf7e7
feat: sms exporter
BobTheBuidler Jan 16, 2022
16addd3
feat: replace pyodbc with ponyorm
BobTheBuidler Jan 16, 2022
786afcf
feat: wallet exporter for earn, ib, special
BobTheBuidler Jan 16, 2022
f761f43
fix: sms exporter
BobTheBuidler Jan 16, 2022
4033474
fix: wallet exporter
BobTheBuidler Jan 16, 2022
f91520b
fix: vault wallet exporter
BobTheBuidler Jan 16, 2022
fc344cc
fix: yearn registry
BobTheBuidler Jan 16, 2022
097d63f
fix: victoria
BobTheBuidler Jan 16, 2022
e00020b
chore: remove unnecessary caching
BobTheBuidler Jan 16, 2022
4c7b97d
chore: remove artifact from testing
BobTheBuidler Jan 16, 2022
68ca984
chore: better utilize ponyorm queries
BobTheBuidler Jan 16, 2022
2becf0a
chore: remove unneeded infura env vars
BobTheBuidler Jan 16, 2022
d9aa3aa
chore: remove dev artifacts
BobTheBuidler Jan 16, 2022
5062d9b
chore: extract variable
BobTheBuidler Jan 16, 2022
382fd81
chore: remove old code
BobTheBuidler Jan 16, 2022
69a4f8d
chore: remove unused imports
BobTheBuidler Jan 16, 2022
3dc2398
chore: cleanup logging
BobTheBuidler Jan 16, 2022
ab7e6bc
feat: magic.get_price for curve v2
BobTheBuidler Jan 16, 2022
60ea408
fix: price edge cases for wallet exporter
BobTheBuidler Jan 16, 2022
f62a8d3
fix: null data display bug
BobTheBuidler Jan 16, 2022
3e6e76a
Revert "feat: magic.get_price for curve v2"
BobTheBuidler Jan 16, 2022
ab86d05
feat: treasury and sms on fantom v1
BobTheBuidler Jan 18, 2022
ae2bb42
feat: add new exporters to make logs
BobTheBuidler Jan 18, 2022
f295885
fix: treasury params for multichain
BobTheBuidler Jan 18, 2022
3dd2544
feat: make wallet exporter loop instead of restarting container
BobTheBuidler Jan 18, 2022
d1777fc
fix: start block for ftm treasury and sms
BobTheBuidler Feb 1, 2022
030a3dc
fix: fantom env vars
BobTheBuidler Feb 1, 2022
131f8e8
feat: adapt transactions_exporter for multichain
BobTheBuidler Feb 1, 2022
2a774f7
chore: use contract util in postgres utils
BobTheBuidler Feb 1, 2022
310c6ab
fix: remove memory.cache in postgres utils, pony already handles
BobTheBuidler Feb 1, 2022
a5681b4
chore: remove unused import
BobTheBuidler Feb 1, 2022
d23d12f
feat: make logs-all
BobTheBuidler Feb 1, 2022
84667f3
fix: broken import
BobTheBuidler Feb 1, 2022
67e199e
feat: temporarily remove ftm transactions and wallet exporter
BobTheBuidler Feb 1, 2022
8cf3503
chore: temporarily remove ftm transactions and wallet exporter from m…
BobTheBuidler Feb 1, 2022
65779b7
chore: remove unused files
BobTheBuidler Feb 1, 2022
21f65b5
chore: refactor
BobTheBuidler Feb 2, 2022
6cca489
chore: refactor
BobTheBuidler Feb 2, 2022
86449e9
fix: raise syntax
BobTheBuidler Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ rebuild: down build up
scratch: clean-volumes build up

logs:
$(dashboards_command) logs -f -t eth-exporter historical-eth-exporter ftm-exporter historical-ftm-exporter treasury-exporter historical-treasury-exporter transactions-exporter wallet-exporter sms-exporter historical-sms-exporter
$(dashboards_command) logs -f -t eth-exporter historical-eth-exporter ftm-exporter historical-ftm-exporter treasury-exporter historical-treasury-exporter ftm-treasury-exporter historical-ftm-treasury-exporter sms-exporter historical-sms-exporter ftm-sms-exporter historical-ftm-sms-exporter transactions-exporter

test:
$(test_command) up

all:
$(all_command) down && $(all_command) build --no-cache && $(all_command) up $(flags)

logs-all:
$(dashboards_command) logs -f -t eth-exporter historical-eth-exporter ftm-exporter historical-ftm-exporter treasury-exporter historical-treasury-exporter ftm-treasury-exporter historical-ftm-treasury-exporter sms-exporter historical-sms-exporter ftm-sms-exporter historical-ftm-sms-exporter transactions-exporter wallet-exporter
15 changes: 12 additions & 3 deletions scripts/historical_sms_exporter.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import logging
from datetime import datetime, timezone

from brownie import chain
from yearn.historical_helper import export_historical, time_tracking
from yearn.networks import Network
from yearn.treasury.treasury import StrategistMultisig
from yearn.utils import closest_block_after_timestamp

logger = logging.getLogger('yearn.historical_sms_exporter')

def main():
start = datetime.now(tz=timezone.utc)
# end: 2021-01-28 09:09:48 first inbound sms tx
end = datetime(2021, 1, 28, 9, 10, tzinfo=timezone.utc)
if Network(chain.id) == Network.Fantom:
BobTheBuidler marked this conversation as resolved.
Show resolved Hide resolved
# end: 2021-06-17 Fantom SMS deployed
end = datetime(2021, 6, 17, tzinfo=timezone.utc)
data_query = 'sms_assets{network="FTM"}'
else:
BobTheBuidler marked this conversation as resolved.
Show resolved Hide resolved
# end: 2021-01-28 09:09:48 first inbound sms tx
end = datetime(2021, 1, 28, 9, 10, tzinfo=timezone.utc)
data_query = 'sms_assets{network="ETH"}'

export_historical(
start,
end,
export_chunk,
export_snapshot,
'sms_assets'
data_query
)


Expand Down
15 changes: 12 additions & 3 deletions scripts/historical_treasury_exporter.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import logging
from datetime import datetime, timezone

from brownie import chain
from yearn.historical_helper import export_historical, time_tracking
from yearn.networks import Network
from yearn.treasury.treasury import YearnTreasury
from yearn.utils import closest_block_after_timestamp

logger = logging.getLogger('yearn.historical_treasury_exporter')

def main():
start = datetime.now(tz=timezone.utc)
# end: 2020-07-21 first treasury tx
end = datetime(2020, 7, 21, 10, 1, tzinfo=timezone.utc)
if Network(chain.id) == Network.Fantom:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same two comments apply here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix'd, commit pending

Copy link
Collaborator Author

@BobTheBuidler BobTheBuidler Feb 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used dict(details)[chain.id] syntax instead of dict(details).get(chain.id) syntax to show we require chainid to be supported, have no fallback

# end: 2021-10-12 Fantom Multisig deployed
end = datetime(2021, 10, 12, tzinfo=timezone.utc)
data_query = 'treasury_assets{network="FTM"}'
else:
# end: 2020-07-21 first treasury tx
end = datetime(2020, 7, 21, 10, 1, tzinfo=timezone.utc)
data_query = 'treasury_assets{network="ETH"}'

export_historical(
start,
end,
export_chunk,
export_snapshot,
'treasury_assets'
data_query
)


Expand Down
11 changes: 8 additions & 3 deletions scripts/transactions_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from brownie import ZERO_ADDRESS, Contract, chain, web3
from brownie.exceptions import BrownieEnvironmentWarning
from pony.orm import db_session
from joblib import Parallel, delayed
from web3._utils.abi import filter_by_name
from web3._utils.events import construct_event_topic_set
from yearn.entities import UserTx # , TreasuryTx
from yearn.events import decode_logs, get_logs_asap
from yearn.networks import Network
from yearn.outputs.postgres.utils import (cache_address, cache_token,
last_recorded_block)
from yearn.prices import magic
Expand All @@ -25,6 +25,11 @@

BATCH_SIZE = 5000

FIRST_END_BLOCK = {
Network.Mainnet: 9480000, # NOTE block some arbitrary time after iearn's first deployment
Network.Fantom: 5000000, # NOTE block some arbitrary time after v2's first deployment
}[chain.id]

def main():
for block in chain.new_blocks(height_buffer=1):
process_and_cache_user_txs(last_recorded_block(UserTx))
Expand All @@ -36,7 +41,7 @@ def process_and_cache_user_txs(last_saved_block=None):
max_block_to_cache = chain.height - 50
start_block = last_saved_block + 1 if last_saved_block else None
end_block = (
9480000 if start_block is None # NOTE block some arbitrary time after iearn's first deployment
FIRST_END_BLOCK if start_block is None
else start_block + BATCH_SIZE if start_block + BATCH_SIZE < max_block_to_cache
else max_block_to_cache
)
Expand Down Expand Up @@ -130,7 +135,7 @@ def _get_price(event, token_entity):
logger.warn('trying again...')
time.sleep(5)
else:
logger.warn(f'vault: {token_entity.token.address}')
logger.warn(f'vault: {token_entity.address.address}')
raise Exception(str(e))


Expand Down
23 changes: 12 additions & 11 deletions scripts/wallet_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
logger = logging.getLogger('yearn.wallet_exporter')

def main():
start = datetime.now(tz=timezone.utc)
# end: 2020-02-12 first iearn deployment
end = datetime(2020, 2, 12, tzinfo=timezone.utc)
export_historical(
start,
end,
export_chunk,
export_snapshot,
'aggregate{param="total wallets"}',
_generate_snapshot_range
)
while True:
start = datetime.now(tz=timezone.utc)
# end: 2020-02-12 first iearn deployment
end = datetime(2020, 2, 12, tzinfo=timezone.utc)
export_historical(
start,
end,
export_chunk,
export_snapshot,
'aggregate{param="total wallets"}',
_generate_snapshot_range
)


def export_chunk(chunk, export_snapshot_func):
Expand Down
121 changes: 107 additions & 14 deletions services/dashboard/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,31 @@ services:
- yearn-exporter
restart: on-failure

wallet-exporter:
treasury-exporter:
image: yearn-exporter
command: wallet_exporter
command: treasury_exporter
environment:
- WEB3_PROVIDER
- ETHERSCAN_TOKEN
- EXPLORER
- SLEEP_SECONDS
- PGHOST=postgres
- PGDATABASE=postgres
- PGUSER=postgres
- PGPASSWORD=yearn-exporter
- POOL_SIZE
- CHUNK_SIZE
- RESOLUTION
volumes:
- solidity_compilers:/root/.solcx
- vyper_compilers:/root/.vvm
- brownie:/root/.brownie
- cache:/app/yearn-exporter/cache
networks:
- yearn-exporter
restart: always
restart: on-failure
depends_on:
- postgres

treasury-exporter:
historical-treasury-exporter:
image: yearn-exporter
command: treasury_exporter
command: historical_treasury_exporter
environment:
- WEB3_PROVIDER
- ETHERSCAN_TOKEN
Expand All @@ -123,6 +124,28 @@ services:
- POOL_SIZE
- CHUNK_SIZE
- RESOLUTION
- SKIP_WALLET_STATS
volumes:
- solidity_compilers:/root/.solcx
- vyper_compilers:/root/.vvm
- brownie:/root/.brownie
- cache:/app/yearn-exporter/cache
networks:
- yearn-exporter
restart: on-failure

ftm-treasury-exporter:
image: yearn-exporter
command: treasury_exporter
environment:
- WEB3_PROVIDER=$FTM_WEB3_PROVIDER
- EXPLORER=$FTM_EXPLORER
- FTMSCAN_TOKEN
- SLEEP_SECONDS
- NETWORK=ftm-main
- POOL_SIZE
- CHUNK_SIZE
- RESOLUTION
volumes:
- solidity_compilers:/root/.solcx
- vyper_compilers:/root/.vvm
Expand All @@ -134,18 +157,18 @@ services:
depends_on:
- postgres

historical-treasury-exporter:
historical-ftm-treasury-exporter:
image: yearn-exporter
command: historical_treasury_exporter
environment:
- WEB3_PROVIDER
- ETHERSCAN_TOKEN
- EXPLORER
- WEB3_PROVIDER=$FTM_WEB3_PROVIDER
- EXPLORER=$FTM_EXPLORER
- FTMSCAN_TOKEN
- SLEEP_SECONDS
- NETWORK=ftm-main
- POOL_SIZE
- CHUNK_SIZE
- RESOLUTION
- SKIP_WALLET_STATS
volumes:
- solidity_compilers:/root/.solcx
- vyper_compilers:/root/.vvm
Expand Down Expand Up @@ -189,10 +212,55 @@ services:
- yearn-exporter
restart: on-failure

ftm-sms-exporter:
image: yearn-exporter
command: sms_exporter
environment:
- WEB3_PROVIDER=$FTM_WEB3_PROVIDER
- EXPLORER=$FTM_EXPLORER
- FTMSCAN_TOKEN
- SLEEP_SECONDS
- NETWORK=ftm-main
- POOL_SIZE
- CHUNK_SIZE
- RESOLUTION
volumes:
- solidity_compilers:/root/.solcx
- vyper_compilers:/root/.vvm
- brownie:/root/.brownie
- cache:/app/yearn-exporter/cache
networks:
- yearn-exporter
restart: on-failure

historical-ftm-sms-exporter:
image: yearn-exporter
command: historical_sms_exporter
environment:
- WEB3_PROVIDER=$FTM_WEB3_PROVIDER
- EXPLORER=$FTM_EXPLORER
- FTMSCAN_TOKEN
- SLEEP_SECONDS
- NETWORK=ftm-main
- POOL_SIZE
- CHUNK_SIZE
- RESOLUTION
volumes:
- solidity_compilers:/root/.solcx
- vyper_compilers:/root/.vvm
- brownie:/root/.brownie
- cache:/app/yearn-exporter/cache
networks:
- yearn-exporter
restart: on-failure

transactions-exporter:
image: yearn-exporter
command: transactions_exporter
environment:
- WEB3_PROVIDER
- ETHERSCAN_TOKEN
- EXPLORER
- PGHOST=postgres
- PGDATABASE=postgres
- PGUSER=postgres
Expand All @@ -208,6 +276,31 @@ services:
depends_on:
- postgres

wallet-exporter:
image: yearn-exporter
command: wallet_exporter
environment:
- WEB3_PROVIDER
- ETHERSCAN_TOKEN
- EXPLORER
- SLEEP_SECONDS
- PGHOST=postgres
- PGDATABASE=postgres
- PGUSER=postgres
- PGPASSWORD=yearn-exporter
- POOL_SIZE
- CHUNK_SIZE
- RESOLUTION
volumes:
- solidity_compilers:/root/.solcx
- vyper_compilers:/root/.vvm
- brownie:/root/.brownie
- cache:/app/yearn-exporter/cache
networks:
- yearn-exporter
restart: always


vmagent:
image: victoriametrics/vmagent
volumes:
Expand Down
2 changes: 1 addition & 1 deletion yearn/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@
Network.Fantom: {
"0x72a34AbafAB09b15E7191822A679f28E067C4a16",
}
}.get(chain.id,set())
}.get(chain.id,set())
4 changes: 2 additions & 2 deletions yearn/outputs/describers/vault.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging

from brownie import chain
from yearn.exceptions import PriceError
from yearn.networks import Network

from yearn.outputs.postgres.utils import fetch_balances
from yearn.prices import magic
from yearn.exceptions import PriceError

logger = logging.getLogger(__name__)

Expand Down
14 changes: 5 additions & 9 deletions yearn/outputs/postgres/utils.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
from brownie import Contract, chain, ZERO_ADDRESS
from pony.orm import ObjectNotFound, db_session, TransactionIntegrityError, select
from yearn.cache import memory
import logging
from brownie import chain, ZERO_ADDRESS
from pony.orm import db_session, select
from yearn.entities import Address, Token, UserTx, db
from yearn.multicall2 import fetch_multicall
from yearn.utils import is_contract
from yearn.utils import is_contract, contract

@db_session
@memory.cache()
def cache_address(address: str) -> Address:
address_entity = Address.get(chainid=chain.id, address=address)
if not address_entity:
address_entity = Address(chainid=chain.id, address=address, is_contract=is_contract(address))
return address_entity

@db_session
@memory.cache()
def cache_token(address: str) -> Token:
address_entity = cache_address(address)
token = Token.get(address=address_entity)
if not token:
contract = Contract(address)
symbol, name, decimals = fetch_multicall([contract,'symbol'],[contract,'name'],[contract,'decimals'])
token = contract(address)
symbol, name, decimals = fetch_multicall([token,'symbol'],[token,'name'],[token,'decimals'])
token = Token(address=address_entity, symbol=symbol, name=name, decimals=decimals)
print(f'token {symbol} added to postgres')
return token
Expand Down
Loading