diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..97855fb0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "config"] + path = config + url = https://github.com/PowerLoom/snapshotter-configs/ +[submodule "snapshotter/modules/boost"] + path = snapshotter/modules/boost + url = https://github.com/PowerLoom/snapshotter-computes/ diff --git a/config b/config new file mode 160000 index 00000000..98be9ea0 --- /dev/null +++ b/config @@ -0,0 +1 @@ +Subproject commit 98be9ea0d4d55b1b869135132818c1b6f325b9c1 diff --git a/config/aggregator.example.json b/config/aggregator.example.json deleted file mode 100644 index da31ba46..00000000 --- a/config/aggregator.example.json +++ /dev/null @@ -1,114 +0,0 @@ -{ - "config": [{ - "project_type": "aggregate_pairContract_24h_trade_volume", - "aggregate_on": "SingleProject", - "filters": { - "projectId": "pairContract_trade_volume" - }, - "processor": { - "module": "snapshotter.modules.pooler.uniswapv2.aggregate.single_uniswap_trade_volume_24h", - "class_name": "AggreagateTradeVolumeProcessor" - } - }, - { - "project_type": "aggregate_pairContract_7d_trade_volume", - "aggregate_on": "SingleProject", - "filters": { - "projectId": "aggregate_pairContract_24h_trade_volume" - }, - "processor": { - "module": "snapshotter.modules.pooler.uniswapv2.aggregate.single_uniswap_trade_volume_7d", - "class_name": "AggreagateTradeVolumeProcessor" - } - }, - { - "project_type": "aggregate_24h_top_pairs_lite", - "aggregate_on": "MultiProject", - "projects_to_wait_for": [ - "aggregate_pairContract_24h_trade_volume:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2", - "pairContract_pair_total_reserves:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5:UNISWAPV2", - "pairContract_pair_total_reserves:0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852:UNISWAPV2", - "pairContract_pair_total_reserves:0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0x3041cbd36888becc7bbcbc0045e3b1f144466f5f:UNISWAPV2", - "pairContract_pair_total_reserves:0x3041cbd36888becc7bbcbc0045e3b1f144466f5f:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xd3d2e2692501a5c9ca623199d38826e513033a17:UNISWAPV2", - "pairContract_pair_total_reserves:0xd3d2e2692501a5c9ca623199d38826e513033a17:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xbb2b8038a1640196fbe3e38816f3e67cba72d940:UNISWAPV2", - "pairContract_pair_total_reserves:0xbb2b8038a1640196fbe3e38816f3e67cba72d940:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xa478c2975ab1ea89e8196811f51a7b7ade33eb11:UNISWAPV2", - "pairContract_pair_total_reserves:0xa478c2975ab1ea89e8196811f51a7b7ade33eb11:UNISWAPV2" - ], - "processor": { - "module": "snapshotter.modules.pooler.uniswapv2.aggregate.multi_uniswap_top_pairs_24h", - "class_name": "AggreagateTopPairsProcessor" - } - }, - { - "project_type": "aggregate_24h_top_tokens_lite", - "aggregate_on": "MultiProject", - "projects_to_wait_for": [ - "aggregate_pairContract_24h_trade_volume:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2", - "pairContract_pair_total_reserves:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5:UNISWAPV2", - "pairContract_pair_total_reserves:0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852:UNISWAPV2", - "pairContract_pair_total_reserves:0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0x3041cbd36888becc7bbcbc0045e3b1f144466f5f:UNISWAPV2", - "pairContract_pair_total_reserves:0x3041cbd36888becc7bbcbc0045e3b1f144466f5f:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xd3d2e2692501a5c9ca623199d38826e513033a17:UNISWAPV2", - "pairContract_pair_total_reserves:0xd3d2e2692501a5c9ca623199d38826e513033a17:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xbb2b8038a1640196fbe3e38816f3e67cba72d940:UNISWAPV2", - "pairContract_pair_total_reserves:0xbb2b8038a1640196fbe3e38816f3e67cba72d940:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xa478c2975ab1ea89e8196811f51a7b7ade33eb11:UNISWAPV2", - "pairContract_pair_total_reserves:0xa478c2975ab1ea89e8196811f51a7b7ade33eb11:UNISWAPV2" - ], - "processor": { - "module": "snapshotter.modules.pooler.uniswapv2.aggregate.multi_uniswap_top_tokens", - "class_name": "AggreagateTopTokensProcessor" - } - }, - { - "project_type": "aggregate_7d_top_pairs_lite", - "aggregate_on": "MultiProject", - "projects_to_wait_for": [ - "aggregate_pairContract_7d_trade_volume:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2", - "aggregate_pairContract_7d_trade_volume:0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5:UNISWAPV2", - "aggregate_pairContract_7d_trade_volume:0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852:UNISWAPV2", - "aggregate_pairContract_7d_trade_volume:0x3041cbd36888becc7bbcbc0045e3b1f144466f5f:UNISWAPV2", - "aggregate_pairContract_7d_trade_volume:0xd3d2e2692501a5c9ca623199d38826e513033a17:UNISWAPV2", - "aggregate_pairContract_7d_trade_volume:0xbb2b8038a1640196fbe3e38816f3e67cba72d940:UNISWAPV2", - "aggregate_pairContract_7d_trade_volume:0xa478c2975ab1ea89e8196811f51a7b7ade33eb11:UNISWAPV2" - ], - "processor": { - "module": "snapshotter.modules.pooler.uniswapv2.aggregate.multi_uniswap_top_pairs_7d", - "class_name": "AggreagateTopPairsProcessor" - } - }, - { - "project_type": "aggregate_24h_stats_lite", - "aggregate_on": "MultiProject", - "projects_to_wait_for": [ - "aggregate_pairContract_24h_trade_volume:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2", - "pairContract_pair_total_reserves:0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5:UNISWAPV2", - "pairContract_pair_total_reserves:0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852:UNISWAPV2", - "pairContract_pair_total_reserves:0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0x3041cbd36888becc7bbcbc0045e3b1f144466f5f:UNISWAPV2", - "pairContract_pair_total_reserves:0x3041cbd36888becc7bbcbc0045e3b1f144466f5f:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xd3d2e2692501a5c9ca623199d38826e513033a17:UNISWAPV2", - "pairContract_pair_total_reserves:0xd3d2e2692501a5c9ca623199d38826e513033a17:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xbb2b8038a1640196fbe3e38816f3e67cba72d940:UNISWAPV2", - "pairContract_pair_total_reserves:0xbb2b8038a1640196fbe3e38816f3e67cba72d940:UNISWAPV2", - "aggregate_pairContract_24h_trade_volume:0xa478c2975ab1ea89e8196811f51a7b7ade33eb11:UNISWAPV2", - "pairContract_pair_total_reserves:0xa478c2975ab1ea89e8196811f51a7b7ade33eb11:UNISWAPV2" - ], - "processor": { - "module": "snapshotter.modules.pooler.uniswapv2.aggregate.multi_uniswap_stats", - "class_name": "AggreagateStatsProcessor" - } - } - ] -} diff --git a/config/auth_settings.example.json b/config/auth_settings.example.json deleted file mode 100644 index b6d0e8f3..00000000 --- a/config/auth_settings.example.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "redis": { - "host": "redis", - "port": 6379, - "db": 0, - "password": null - }, - "bind": { - "host": "0.0.0.0", - "port": 8555 - } -} diff --git a/config/preloader.json b/config/preloader.json deleted file mode 100644 index 24cd4b79..00000000 --- a/config/preloader.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "preloaders": [ - { - "task_type": "block_transactions", - "module": "snapshotter.utils.preloaders.tx_receipts.preloader", - "class_name": "TxPreloadWorker" - }, - { - "task_type": "block_details", - "module": "snapshotter.utils.preloaders.block_details.preloader", - "class_name": "BlockDetailsPreloader" - }, - { - "task_type": "eth_price", - "module": "snapshotter.utils.preloaders.eth_price.preloader", - "class_name": "EthPricePreloader" - } - ], - "delegate_tasks": [ - { - "task_type": "txreceipt", - "module": "snapshotter.utils.preloaders.tx_receipts.delegated_worker.tx_receipts", - "class_name": "TxReceiptProcessor" - } - ], - "timeout": 60 -} diff --git a/config/projects.example.json b/config/projects.example.json deleted file mode 100644 index 71444425..00000000 --- a/config/projects.example.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "config": [{ - "project_type": "pairContract_pair_total_reserves", - "preload_tasks":[ - "eth_price", - "block_details" - ], - "projects":[ - "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", - "0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5", - "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852", - "0x3041cbd36888becc7bbcbc0045e3b1f144466f5f", - "0xd3d2e2692501a5c9ca623199d38826e513033a17", - "0xbb2b8038a1640196fbe3e38816f3e67cba72d940", - "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11" - ], - "processor":{ - "module": "snapshotter.modules.pooler.uniswapv2.pair_total_reserves", - "class_name": "PairTotalReservesProcessor" - } - }, - { - "project_type": "pairContract_trade_volume", - "preload_tasks":[ - "eth_price", - "block_details" - ], - "projects":[ - "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", - "0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5", - "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852", - "0x3041cbd36888becc7bbcbc0045e3b1f144466f5f", - "0xd3d2e2692501a5c9ca623199d38826e513033a17", - "0xbb2b8038a1640196fbe3e38816f3e67cba72d940", - "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11" - ], - "processor":{ - "module": "snapshotter.modules.pooler.uniswapv2.trade_volume", - "class_name": "TradeVolumeProcessor" - } - } - ] -} diff --git a/config/settings.example.json b/config/settings.example.json deleted file mode 100644 index 8776978a..00000000 --- a/config/settings.example.json +++ /dev/null @@ -1,144 +0,0 @@ -{ - "namespace": "relevant-namespace", - "core_api": { - "host": "0.0.0.0", - "port": 8002, - "auth": { - "enabled": false, - "header_key": "X-API-KEY" - }, - "public_rate_limit": "20000/day;300/minute;10/second" - }, - "instance_id": "account-address", - "rpc": { - "full_nodes": [{ - "url": "https://rpc-url", - "rate_limit": "100000000/day;20000/minute;1000/second" - }], - "archive_nodes": [], - "force_archive_blocks": 100, - "retry": 5, - "request_time_out": 5, - "skip_epoch_threshold_blocks": 30, - "polling_interval": 10, - "connection_limits":{ - "max_connections": 100, - "max_keepalive_connections": 50, - "keepalive_expiry": 300 - } - }, - "rlimit": { - "file_descriptors": 2048 - }, - "rabbitmq": { - "user": "guest", - "password": "guest", - "host": "rabbitmq", - "port": 5672, - "setup": { - "core": { - "exchange": "powerloom-backend" - }, - "callbacks": { - "exchange": "powerloom-backend-callbacks" - }, - "commit_payload": { - "exchange": "powerloom-backend-commit-payload" - }, - "event_detector": { - "exchange": "powerloom-backend-event-detector" - }, - "delegated_worker": { - "exchange": "powerloom-backend-delegated-worker" - } - } - }, - "reporting": { - "slack_url": "https://slack-reporting-url", - "service_url": "https://powerloom-reporting-url" - }, - "redis": { - "host": "redis", - "port": 6379, - "db": 0, - "password": null, - "ssl": false, - "cluster_mode": false - }, - "redis_reader": { - "host": "redis", - "port": 6379, - "db": 0, - "password": null - }, - "logs": { - "trace_enabled": false, - "write_to_files": true - }, - "projects_config_path": "config/projects.json", - "aggregator_config_path": "config/aggregator.json", - "preloader_config_path": "config/preloader.json", - "pair_contract_abi": "snapshotter/static/abis/UniswapV2Pair.json", - "protocol_state": { - "abi": "snapshotter/static/abis/ProtocolContract.json", - "address": "protocol-state-contract" - }, - "callback_worker_config": { - "num_delegate_workers": 0, - "num_snapshot_workers": 8, - "num_aggregation_workers": 12 - }, - "ipfs": { - "url": "ipfs-writer-url", - "url_auth": { - "apiKey": "ipfs-writer-key", - "apiSecret": "ipfs-writer-secret" - }, - "reader_url": "ipfs-reader-url", - "reader_url_auth": { - "apiKey": "ipfs-reader-key", - "apiSecret": "ipfs-reader-secret" - }, - "write_rate_limit": { - "req_per_sec": 10, - "burst": 10 - }, - "timeout": 60, - "local_cache_path": "/home/ubuntu/local_cache/", - "connection_limits":{ - "max_connections": 100, - "max_keepalive_connections": 50, - "keepalive_expiry": 300 - }, - "remote_pinning": { - "enabled": false, - "service_name": "", - "service_endpoint": "", - "service_token": "", - "background_pinning": false - } - }, - "web3storage":{ - "upload_snapshots": false, - "upload_aggregates": true, - "url": "https://api.web3.storage", - "upload_url_suffix": "/upload", - "api_token": "web3-storage-token", - "timeout": 30, - "max_idle_conns": 5, - "idle_conn_timeout": 300 - }, - "anchor_chain_rpc": { - "full_nodes": [{ - "url": "https://prost-rpc-url", - "rate_limit": "100000000/day;20000/minute;1000/second" - }], - "retry": 5, - "request_time_out": 5, - "connection_limits":{ - "max_connections": 100, - "max_keepalive_connections": 50, - "keepalive_expiry": 300 - } - } -} diff --git a/snapshotter/modules/boost b/snapshotter/modules/boost new file mode 160000 index 00000000..9abfc33d --- /dev/null +++ b/snapshotter/modules/boost @@ -0,0 +1 @@ +Subproject commit 9abfc33d94fa2cf1033f8be1472f37b4fe133ee0 diff --git a/snapshotter/modules/pooler/uniswapv2/__init__.py b/snapshotter/modules/pooler/uniswapv2/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/snapshotter/modules/pooler/uniswapv2/aggregate/__init__.py b/snapshotter/modules/pooler/uniswapv2/aggregate/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_stats.py b/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_stats.py deleted file mode 100644 index 0b5090d5..00000000 --- a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_stats.py +++ /dev/null @@ -1,114 +0,0 @@ -from ipfs_client.main import AsyncIPFSClient -from redis import asyncio as aioredis - -from ..utils.models.message_models import UniswapPairTotalReservesSnapshot -from ..utils.models.message_models import UniswapStatsSnapshot -from ..utils.models.message_models import UniswapTradesAggregateSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorAggregate -from snapshotter.utils.data_utils import get_project_epoch_snapshot -from snapshotter.utils.data_utils import get_submission_data_bulk -from snapshotter.utils.data_utils import get_tail_epoch_id -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomCalculateAggregateMessage -from snapshotter.utils.rpc import RpcHelper - - -class AggreagateStatsProcessor(GenericProcessorAggregate): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [] - self._logger = logger.bind(module='AggregateStatsProcessor') - - async def compute( - self, - msg_obj: PowerloomCalculateAggregateMessage, - redis: aioredis.Redis, - rpc_helper: RpcHelper, - anchor_rpc_helper: RpcHelper, - ipfs_reader: AsyncIPFSClient, - protocol_state_contract, - project_id: str, - - ): - self._logger.info(f'Calculating unswap stats for {msg_obj}') - - epoch_id = msg_obj.epochId - - snapshot_mapping = {} - - snapshot_data = await get_submission_data_bulk( - redis, [msg.snapshotCid for msg in msg_obj.messages], ipfs_reader, [ - msg.projectId for msg in msg_obj.messages - ], - ) - - complete_flags = [] - for msg, data in zip(msg_obj.messages, snapshot_data): - if not data: - continue - if 'reserves' in msg.projectId: - snapshot = UniswapPairTotalReservesSnapshot.parse_obj(data) - elif 'volume' in msg.projectId: - snapshot = UniswapTradesAggregateSnapshot.parse_obj(data) - complete_flags.append(snapshot.complete) - snapshot_mapping[msg.projectId] = snapshot - - stats_data = { - 'volume24h': 0, - 'tvl': 0, - 'fee24h': 0, - 'volumeChange24h': 0, - 'tvlChange24h': 0, - 'feeChange24h': 0, - } - # iterate over all snapshots and generate stats data - for snapshot_project_id in snapshot_mapping.keys(): - snapshot = snapshot_mapping[snapshot_project_id] - - if 'reserves' in snapshot_project_id: - max_epoch_block = snapshot.chainHeightRange.end - - stats_data['tvl'] += snapshot.token0ReservesUSD[f'block{max_epoch_block}'] + \ - snapshot.token1ReservesUSD[f'block{max_epoch_block}'] - - elif 'volume' in snapshot_project_id: - stats_data['volume24h'] += snapshot.totalTrade - stats_data['fee24h'] += snapshot.totalFee - - # source project tail epoch - tail_epoch_id, extrapolated_flag = await get_tail_epoch_id( - redis, protocol_state_contract, anchor_rpc_helper, msg_obj.epochId, 86400, project_id, - ) - if not extrapolated_flag: - previous_stats_snapshot_data = await get_project_epoch_snapshot( - redis, protocol_state_contract, anchor_rpc_helper, ipfs_reader, tail_epoch_id, project_id, - ) - - if previous_stats_snapshot_data: - previous_stats_snapshot = UniswapStatsSnapshot.parse_obj(previous_stats_snapshot_data) - - # calculate change in percentage - stats_data['volumeChange24h'] = (stats_data['volume24h'] - previous_stats_snapshot.volume24h) / \ - previous_stats_snapshot.volume24h * 100 - - stats_data['tvlChange24h'] = (stats_data['tvl'] - previous_stats_snapshot.tvl) / \ - previous_stats_snapshot.tvl * 100 - - stats_data['feeChange24h'] = (stats_data['fee24h'] - previous_stats_snapshot.fee24h) / \ - previous_stats_snapshot.fee24h * 100 - - stats_snapshot = UniswapStatsSnapshot( - epochId=epoch_id, - volume24h=stats_data['volume24h'], - tvl=stats_data['tvl'], - fee24h=stats_data['fee24h'], - volumeChange24h=stats_data['volumeChange24h'], - tvlChange24h=stats_data['tvlChange24h'], - feeChange24h=stats_data['feeChange24h'], - ) - - if not all(complete_flags): - stats_snapshot.complete = False - - return stats_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_pairs_24h.py b/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_pairs_24h.py deleted file mode 100644 index 382f30f4..00000000 --- a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_pairs_24h.py +++ /dev/null @@ -1,107 +0,0 @@ -from ipfs_client.main import AsyncIPFSClient -from redis import asyncio as aioredis - -from ..utils.helpers import get_pair_metadata -from ..utils.models.message_models import UniswapPairTotalReservesSnapshot -from ..utils.models.message_models import UniswapTopPair24hSnapshot -from ..utils.models.message_models import UniswapTopPairs24hSnapshot -from ..utils.models.message_models import UniswapTradesAggregateSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorAggregate -from snapshotter.utils.data_utils import get_submission_data_bulk -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomCalculateAggregateMessage -from snapshotter.utils.rpc import RpcHelper - - -class AggreagateTopPairsProcessor(GenericProcessorAggregate): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [] - - async def compute( - self, - msg_obj: PowerloomCalculateAggregateMessage, - redis: aioredis.Redis, - rpc_helper: RpcHelper, - anchor_rpc_helper: RpcHelper, - ipfs_reader: AsyncIPFSClient, - protocol_state_contract, - project_id: str, - - ): - self._logger = logger.bind(module='AggregateTopPairsProcessor') - self._logger.info(f'Calculating 24h top pairs trade volume and reserves data') - - epoch_id = msg_obj.epochId - - snapshot_mapping = {} - all_pair_metadata = {} - - snapshot_data = await get_submission_data_bulk( - redis, [msg.snapshotCid for msg in msg_obj.messages], ipfs_reader, [ - msg.projectId for msg in msg_obj.messages - ], - ) - - complete_flags = [] - for msg, data in zip(msg_obj.messages, snapshot_data): - if not data: - continue - if 'reserves' in msg.projectId: - snapshot = UniswapPairTotalReservesSnapshot.parse_obj(data) - elif 'volume' in msg.projectId: - snapshot = UniswapTradesAggregateSnapshot.parse_obj(data) - complete_flags.append(snapshot.complete) - snapshot_mapping[msg.projectId] = snapshot - - contract_address = msg.projectId.split(':')[-2] - if contract_address not in all_pair_metadata: - pair_metadata = await get_pair_metadata( - contract_address, - redis_conn=redis, - rpc_helper=rpc_helper, - ) - - all_pair_metadata[contract_address] = pair_metadata - - # iterate over all snapshots and generate pair data - pair_data = {} - for snapshot_project_id in snapshot_mapping.keys(): - snapshot = snapshot_mapping[snapshot_project_id] - contract = snapshot_project_id.split(':')[-2] - pair_metadata = all_pair_metadata[contract] - - if contract not in pair_data: - pair_data[contract] = { - 'address': contract, - 'name': pair_metadata['pair']['symbol'], - 'liquidity': 0, - 'volume24h': 0, - 'fee24h': 0, - } - - if 'reserves' in snapshot_project_id: - max_epoch_block = snapshot.chainHeightRange.end - pair_data[contract]['liquidity'] += snapshot.token0ReservesUSD[f'block{max_epoch_block}'] + \ - snapshot.token1ReservesUSD[f'block{max_epoch_block}'] - - elif 'volume' in snapshot_project_id: - pair_data[contract]['volume24h'] += snapshot.totalTrade - pair_data[contract]['fee24h'] += snapshot.totalFee - - top_pairs = [] - for pair in pair_data.values(): - top_pairs.append(UniswapTopPair24hSnapshot.parse_obj(pair)) - - top_pairs = sorted(top_pairs, key=lambda x: x.liquidity, reverse=True) - - top_pairs_snapshot = UniswapTopPairs24hSnapshot( - epochId=epoch_id, - pairs=top_pairs, - ) - - if not all(complete_flags): - top_pairs_snapshot.complete = False - - return top_pairs_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_pairs_7d.py b/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_pairs_7d.py deleted file mode 100644 index 86cbc15f..00000000 --- a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_pairs_7d.py +++ /dev/null @@ -1,96 +0,0 @@ -from ipfs_client.main import AsyncIPFSClient -from redis import asyncio as aioredis - -from ..utils.helpers import get_pair_metadata -from ..utils.models.message_models import UniswapTopPair7dSnapshot -from ..utils.models.message_models import UniswapTopPairs7dSnapshot -from ..utils.models.message_models import UniswapTradesAggregateSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorAggregate -from snapshotter.utils.data_utils import get_submission_data_bulk -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomCalculateAggregateMessage -from snapshotter.utils.rpc import RpcHelper - - -class AggreagateTopPairsProcessor(GenericProcessorAggregate): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [] - self._logger = logger.bind(module='AggregateTopPairsProcessor') - - async def compute( - self, - msg_obj: PowerloomCalculateAggregateMessage, - redis: aioredis.Redis, - rpc_helper: RpcHelper, - anchor_rpc_helper: RpcHelper, - ipfs_reader: AsyncIPFSClient, - protocol_state_contract, - project_id: str, - - ): - self._logger.info(f'Calculating 7d top pairs trade volume data for {msg_obj}') - - epoch_id = msg_obj.epochId - - snapshot_mapping = {} - all_pair_metadata = {} - - snapshot_data = await get_submission_data_bulk( - redis, [msg.snapshotCid for msg in msg_obj.messages], ipfs_reader, [ - msg.projectId for msg in msg_obj.messages - ], - ) - - complete_flags = [] - for msg, data in zip(msg_obj.messages, snapshot_data): - if not data: - continue - snapshot = UniswapTradesAggregateSnapshot.parse_obj(data) - complete_flags.append(snapshot.complete) - snapshot_mapping[msg.projectId] = snapshot - - contract_address = msg.projectId.split(':')[-2] - if contract_address not in all_pair_metadata: - pair_metadata = await get_pair_metadata( - contract_address, - redis_conn=redis, - rpc_helper=rpc_helper, - ) - - all_pair_metadata[contract_address] = pair_metadata - - # iterate over all snapshots and generate pair data - pair_data = {} - for snapshot_project_id in snapshot_mapping.keys(): - snapshot = snapshot_mapping[snapshot_project_id] - contract = snapshot_project_id.split(':')[-2] - pair_metadata = all_pair_metadata[contract] - - if contract not in pair_data: - pair_data[contract] = { - 'address': contract, - 'name': pair_metadata['pair']['symbol'], - 'volume7d': 0, - 'fee7d': 0, - } - - pair_data[contract]['volume7d'] += snapshot.totalTrade - pair_data[contract]['fee7d'] += snapshot.totalFee - - top_pairs = [] - for pair in pair_data.values(): - top_pairs.append(UniswapTopPair7dSnapshot.parse_obj(pair)) - - top_pairs = sorted(top_pairs, key=lambda x: x.volume7d, reverse=True) - - top_pairs_snapshot = UniswapTopPairs7dSnapshot( - epochId=epoch_id, - pairs=top_pairs, - ) - - if not all(complete_flags): - top_pairs_snapshot.complete = False - - return top_pairs_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_tokens.py b/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_tokens.py deleted file mode 100644 index fbb3d294..00000000 --- a/snapshotter/modules/pooler/uniswapv2/aggregate/multi_uniswap_top_tokens.py +++ /dev/null @@ -1,149 +0,0 @@ -from ipfs_client.main import AsyncIPFSClient -from redis import asyncio as aioredis - -from ..utils.helpers import get_pair_metadata -from ..utils.models.message_models import UniswapPairTotalReservesSnapshot -from ..utils.models.message_models import UniswapTopTokenSnapshot -from ..utils.models.message_models import UniswapTopTokensSnapshot -from ..utils.models.message_models import UniswapTradesAggregateSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorAggregate -from snapshotter.utils.data_utils import get_project_epoch_snapshot -from snapshotter.utils.data_utils import get_submission_data_bulk -from snapshotter.utils.data_utils import get_tail_epoch_id -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomCalculateAggregateMessage -from snapshotter.utils.rpc import RpcHelper - - -class AggreagateTopTokensProcessor(GenericProcessorAggregate): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [] - - async def compute( - self, - msg_obj: PowerloomCalculateAggregateMessage, - redis: aioredis.Redis, - rpc_helper: RpcHelper, - anchor_rpc_helper: RpcHelper, - ipfs_reader: AsyncIPFSClient, - protocol_state_contract, - project_id: str, - - ): - self._logger = logger.bind(module='AggregateTopTokensProcessor') - - self._logger.info(f'Calculating top tokens data for {msg_obj}') - epoch_id = msg_obj.epochId - - snapshot_mapping = {} - projects_metadata = {} - - snapshot_data = await get_submission_data_bulk( - redis, [msg.snapshotCid for msg in msg_obj.messages], ipfs_reader, [ - msg.projectId for msg in msg_obj.messages - ], - ) - - complete_flags = [] - for msg, data in zip(msg_obj.messages, snapshot_data): - if not data: - continue - if 'reserves' in msg.projectId: - snapshot = UniswapPairTotalReservesSnapshot.parse_obj(data) - elif 'volume' in msg.projectId: - snapshot = UniswapTradesAggregateSnapshot.parse_obj(data) - complete_flags.append(snapshot.complete) - snapshot_mapping[msg.projectId] = snapshot - - contract_address = msg.projectId.split(':')[-2] - pair_metadata = await get_pair_metadata( - contract_address, - redis_conn=redis, - rpc_helper=rpc_helper, - ) - - projects_metadata[msg.projectId] = pair_metadata - - # iterate over all snapshots and generate token data - token_data = {} - for snapshot_project_id in snapshot_mapping.keys(): - snapshot = snapshot_mapping[snapshot_project_id] - project_metadata = projects_metadata[snapshot_project_id] - - token0 = project_metadata['token0'] - token1 = project_metadata['token1'] - - if token0['address'] not in token_data: - token_data[token0['address']] = { - 'address': token0['address'], - 'name': token0['name'], - 'symbol': token0['symbol'], - 'decimals': token0['decimals'], - 'price': 0, - 'volume24h': 0, - 'liquidity': 0, - 'priceChange24h': 0, - } - - if token1['address'] not in token_data: - token_data[token1['address']] = { - 'address': token1['address'], - 'name': token1['name'], - 'symbol': token1['symbol'], - 'decimals': token1['decimals'], - 'price': 0, - 'volume24h': 0, - 'liquidity': 0, - 'priceChange24h': 0, - } - - if 'reserves' in snapshot_project_id: - max_epoch_block = snapshot.chainHeightRange.end - - token_data[token0['address']]['price'] = snapshot.token0Prices[f'block{max_epoch_block}'] - token_data[token1['address']]['price'] = snapshot.token1Prices[f'block{max_epoch_block}'] - - token_data[token0['address']]['liquidity'] += snapshot.token0ReservesUSD[f'block{max_epoch_block}'] - token_data[token1['address']]['liquidity'] += snapshot.token1ReservesUSD[f'block{max_epoch_block}'] - - elif 'volume' in snapshot_project_id: - - token_data[token0['address']]['volume24h'] += snapshot.token0TradeVolumeUSD - token_data[token1['address']]['volume24h'] += snapshot.token1TradeVolumeUSD - - tail_epoch_id, extrapolated_flag = await get_tail_epoch_id( - redis, protocol_state_contract, anchor_rpc_helper, msg_obj.epochId, 86400, project_id, - ) - - if not extrapolated_flag: - previous_top_tokens_snapshot_data = await get_project_epoch_snapshot( - redis, protocol_state_contract, anchor_rpc_helper, ipfs_reader, tail_epoch_id, project_id, - ) - - if previous_top_tokens_snapshot_data: - previous_top_tokens_snapshot = UniswapTopTokensSnapshot.parse_obj(previous_top_tokens_snapshot_data) - for token in previous_top_tokens_snapshot.tokens: - if token.address in token_data: - price_before_24h = token.price - - if price_before_24h > 0: - token_data[token.address]['priceChange24h'] = ( - token_data[token.address]['price'] - price_before_24h - ) / price_before_24h * 100 - - top_tokens = [] - for token in token_data.values(): - top_tokens.append(UniswapTopTokenSnapshot.parse_obj(token)) - - top_tokens = sorted(top_tokens, key=lambda x: x.liquidity, reverse=True) - - top_tokens_snapshot = UniswapTopTokensSnapshot( - epochId=epoch_id, - tokens=top_tokens, - ) - if not all(complete_flags): - top_tokens_snapshot.complete = False - - return top_tokens_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/aggregate/single_uniswap_trade_volume_24h.py b/snapshotter/modules/pooler/uniswapv2/aggregate/single_uniswap_trade_volume_24h.py deleted file mode 100644 index 3edff4e5..00000000 --- a/snapshotter/modules/pooler/uniswapv2/aggregate/single_uniswap_trade_volume_24h.py +++ /dev/null @@ -1,268 +0,0 @@ -import asyncio -import json - -from ipfs_client.main import AsyncIPFSClient -from redis import asyncio as aioredis - -from ..utils.models.message_models import UniswapTradesAggregateSnapshot -from ..utils.models.message_models import UniswapTradesSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorAggregate -from snapshotter.utils.data_utils import get_project_epoch_snapshot_bulk -from snapshotter.utils.data_utils import get_project_first_epoch -from snapshotter.utils.data_utils import get_submission_data -from snapshotter.utils.data_utils import get_tail_epoch_id -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomSnapshotSubmittedMessage -from snapshotter.utils.redis.redis_keys import project_finalized_data_zset -from snapshotter.utils.redis.redis_keys import submitted_base_snapshots_key -from snapshotter.utils.rpc import RpcHelper - - -class AggreagateTradeVolumeProcessor(GenericProcessorAggregate): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [] - - def _add_aggregate_snapshot( - self, - previous_aggregate_snapshot: UniswapTradesAggregateSnapshot, - current_snapshot: UniswapTradesSnapshot, - ): - - previous_aggregate_snapshot.totalTrade += current_snapshot.totalTrade - previous_aggregate_snapshot.totalFee += current_snapshot.totalFee - previous_aggregate_snapshot.token0TradeVolume += current_snapshot.token0TradeVolume - previous_aggregate_snapshot.token1TradeVolume += current_snapshot.token1TradeVolume - previous_aggregate_snapshot.token0TradeVolumeUSD += current_snapshot.token0TradeVolumeUSD - previous_aggregate_snapshot.token1TradeVolumeUSD += current_snapshot.token1TradeVolumeUSD - - return previous_aggregate_snapshot - - def _remove_aggregate_snapshot( - self, - previous_aggregate_snapshot: UniswapTradesAggregateSnapshot, - current_snapshot: UniswapTradesSnapshot, - ): - - previous_aggregate_snapshot.totalTrade -= current_snapshot.totalTrade - previous_aggregate_snapshot.totalFee -= current_snapshot.totalFee - previous_aggregate_snapshot.token0TradeVolume -= current_snapshot.token0TradeVolume - previous_aggregate_snapshot.token1TradeVolume -= current_snapshot.token1TradeVolume - previous_aggregate_snapshot.token0TradeVolumeUSD -= current_snapshot.token0TradeVolumeUSD - previous_aggregate_snapshot.token1TradeVolumeUSD -= current_snapshot.token1TradeVolumeUSD - - return previous_aggregate_snapshot - - async def _calculate_from_scratch( - self, - msg_obj: PowerloomSnapshotSubmittedMessage, - redis: aioredis.Redis, - rpc_helper: RpcHelper, - anchor_rpc_helper: RpcHelper, - ipfs_reader: AsyncIPFSClient, - protocol_state_contract, - project_id: str, - ): - calculate_from_scratch_in_progress = await redis.get(f'calculate_from_scratch:{project_id}') - if calculate_from_scratch_in_progress: - self._logger.info('calculate_from_scratch already in progress, skipping') - return - - self._logger.info('building aggregate from scratch') - await redis.set( - name=f'calculate_from_scratch:{project_id}', - value='true', - ex=300, - ) - # source project tail epoch - tail_epoch_id, extrapolated_flag = await get_tail_epoch_id( - redis, protocol_state_contract, anchor_rpc_helper, msg_obj.epochId, 86400, msg_obj.projectId, - ) - - # for the first epoch, using submitted cid - current_epoch_underlying_data = await get_submission_data( - redis, msg_obj.snapshotCid, ipfs_reader, project_id, - ) - - snapshots_data = await get_project_epoch_snapshot_bulk( - redis, protocol_state_contract, anchor_rpc_helper, ipfs_reader, - tail_epoch_id, msg_obj.epochId - 1, msg_obj.projectId, - ) - - aggregate_snapshot = UniswapTradesAggregateSnapshot.parse_obj({'epochId': msg_obj.epochId}) - if extrapolated_flag: - aggregate_snapshot.complete = False - if current_epoch_underlying_data: - current_snapshot = UniswapTradesSnapshot.parse_obj(current_epoch_underlying_data) - aggregate_snapshot = self._add_aggregate_snapshot(aggregate_snapshot, current_snapshot) - - for snapshot_data in snapshots_data: - if snapshot_data: - snapshot = UniswapTradesSnapshot.parse_obj(snapshot_data) - aggregate_snapshot = self._add_aggregate_snapshot(aggregate_snapshot, snapshot) - - await redis.delete(f'calculate_from_scratch:{project_id}') - - return aggregate_snapshot - - async def compute( - self, - msg_obj: PowerloomSnapshotSubmittedMessage, - redis: aioredis.Redis, - rpc_helper: RpcHelper, - anchor_rpc_helper: RpcHelper, - ipfs_reader: AsyncIPFSClient, - protocol_state_contract, - project_id: str, - - ): - self._logger = logger.bind(module='AggregateTradeVolumeProcessor24h') - self._logger.info(f'Building trade volume aggregate snapshot for {msg_obj}') - - # aggregate project first epoch - project_first_epoch = await get_project_first_epoch( - redis, protocol_state_contract, anchor_rpc_helper, project_id, - ) - - # If no past snapshots exist, then aggregate will be current snapshot - if project_first_epoch == 0: - return await self._calculate_from_scratch( - msg_obj, redis, rpc_helper, anchor_rpc_helper, ipfs_reader, protocol_state_contract, project_id, - ) - - else: - self._logger.info('project_first_epoch is not 0, building aggregate from previous aggregate') - - # get key with highest score - project_last_finalized = await redis.zrevrangebyscore( - project_finalized_data_zset(project_id), - max='+inf', - min='-inf', - withscores=True, - start=0, - num=1, - ) - - if project_last_finalized: - project_last_finalized_cid, project_last_finalized_epoch = project_last_finalized[0] - project_last_finalized_epoch = int(project_last_finalized_epoch) - project_last_finalized_cid = project_last_finalized_cid.decode('utf-8') - else: - self._logger.info('project_last_finalized is None, trying to fetch from contract') - return await self._calculate_from_scratch( - msg_obj, redis, rpc_helper, anchor_rpc_helper, ipfs_reader, protocol_state_contract, project_id, - ) - - tail_epoch_id, extrapolated_flag = await get_tail_epoch_id( - redis, protocol_state_contract, anchor_rpc_helper, msg_obj.epochId, 86400, msg_obj.projectId, - ) - - if extrapolated_flag: - aggregate_complete_flag = False - else: - aggregate_complete_flag = True - - if project_last_finalized_epoch <= tail_epoch_id: - self._logger.error('last finalized epoch is too old, building aggregate from scratch') - return await self._calculate_from_scratch( - msg_obj, redis, rpc_helper, anchor_rpc_helper, ipfs_reader, protocol_state_contract, project_id, - ) - - project_last_finalized_data = await get_submission_data( - redis, project_last_finalized_cid, ipfs_reader, project_id, - ) - - if not project_last_finalized_data: - self._logger.info('project_last_finalized_data is None, building aggregate from scratch') - return await self._calculate_from_scratch( - msg_obj, redis, rpc_helper, anchor_rpc_helper, ipfs_reader, protocol_state_contract, project_id, - ) - - aggregate_snapshot = UniswapTradesAggregateSnapshot.parse_obj(project_last_finalized_data) - # updating epochId to current epoch - aggregate_snapshot.epochId = msg_obj.epochId - - base_project_last_finalized = await redis.zrevrangebyscore( - project_finalized_data_zset(msg_obj.projectId), - max='+inf', - min='-inf', - withscores=True, - start=0, - num=1, - ) - - if base_project_last_finalized: - _, base_project_last_finalized_epoch_ = base_project_last_finalized[0] - base_project_last_finalized_epoch = int(base_project_last_finalized_epoch_) - else: - base_project_last_finalized_epoch = 0 - - if base_project_last_finalized_epoch and project_last_finalized_epoch < base_project_last_finalized_epoch: - # fetch base finalized snapshots if they exist and are within 5 epochs of current epoch - base_finalized_snapshot_range = ( - project_last_finalized_epoch + 1, - base_project_last_finalized_epoch, - ) - - base_finalized_snapshots = await get_project_epoch_snapshot_bulk( - redis, protocol_state_contract, anchor_rpc_helper, ipfs_reader, - base_finalized_snapshot_range[0], base_finalized_snapshot_range[1], msg_obj.projectId, - ) - else: - base_finalized_snapshots = [] - base_finalized_snapshot_range = (0, project_last_finalized_epoch) - - base_unfinalized_tasks = [] - for epoch_id in range(base_finalized_snapshot_range[1] + 1, msg_obj.epochId + 1): - base_unfinalized_tasks.append( - redis.get(submitted_base_snapshots_key(epoch_id=epoch_id, project_id=msg_obj.projectId)), - ) - - base_unfinalized_snapshots_raw = await asyncio.gather(*base_unfinalized_tasks, return_exceptions=True) - - base_unfinalized_snapshots = [] - for snapshot_data in base_unfinalized_snapshots_raw: - # check if not exception and not None - if not isinstance(snapshot_data, Exception) and snapshot_data: - base_unfinalized_snapshots.append( - json.loads(snapshot_data), - ) - else: - self._logger.error( - f'Error fetching base unfinalized snapshot, cancelling aggregation for epoch {msg_obj.epochId}', - ) - return None - - base_snapshots = base_finalized_snapshots + base_unfinalized_snapshots - - for snapshot_data in base_snapshots: - if snapshot_data: - snapshot = UniswapTradesSnapshot.parse_obj(snapshot_data) - aggregate_snapshot = self._add_aggregate_snapshot(aggregate_snapshot, snapshot) - - # Remove from tail if needed - tail_epochs_to_remove = [] - for epoch_id in range(project_last_finalized_epoch, msg_obj.epochId): - tail_epoch_id, extrapolated_flag = await get_tail_epoch_id( - redis, protocol_state_contract, anchor_rpc_helper, epoch_id, 86400, msg_obj.projectId, - ) - if not extrapolated_flag: - tail_epochs_to_remove.append(tail_epoch_id) - if tail_epochs_to_remove: - tail_epoch_snapshots = await get_project_epoch_snapshot_bulk( - redis, protocol_state_contract, anchor_rpc_helper, ipfs_reader, - tail_epochs_to_remove[0], tail_epochs_to_remove[-1], msg_obj.projectId, - ) - - for snapshot_data in tail_epoch_snapshots: - if snapshot_data: - snapshot = UniswapTradesSnapshot.parse_obj(snapshot_data) - aggregate_snapshot = self._remove_aggregate_snapshot(aggregate_snapshot, snapshot) - - if aggregate_complete_flag: - aggregate_snapshot.complete = True - else: - aggregate_snapshot.complete = False - - return aggregate_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/aggregate/single_uniswap_trade_volume_7d.py b/snapshotter/modules/pooler/uniswapv2/aggregate/single_uniswap_trade_volume_7d.py deleted file mode 100644 index 8ac8442d..00000000 --- a/snapshotter/modules/pooler/uniswapv2/aggregate/single_uniswap_trade_volume_7d.py +++ /dev/null @@ -1,125 +0,0 @@ -import asyncio - -import pydantic -from ipfs_client.main import AsyncIPFSClient -from redis import asyncio as aioredis - -from ..utils.models.message_models import UniswapTradesAggregateSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorAggregate -from snapshotter.utils.data_utils import get_project_epoch_snapshot -from snapshotter.utils.data_utils import get_submission_data -from snapshotter.utils.data_utils import get_tail_epoch_id -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomSnapshotSubmittedMessage -from snapshotter.utils.rpc import RpcHelper - - -class AggreagateTradeVolumeProcessor(GenericProcessorAggregate): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [] - self._logger = logger.bind(module='AggregateTradeVolumeProcessor7d') - - def _add_aggregate_snapshot( - self, - previous_aggregate_snapshot: UniswapTradesAggregateSnapshot, - current_snapshot: UniswapTradesAggregateSnapshot, - ): - - previous_aggregate_snapshot.totalTrade += current_snapshot.totalTrade - previous_aggregate_snapshot.totalFee += current_snapshot.totalFee - previous_aggregate_snapshot.token0TradeVolume += current_snapshot.token0TradeVolume - previous_aggregate_snapshot.token1TradeVolume += current_snapshot.token1TradeVolume - previous_aggregate_snapshot.token0TradeVolumeUSD += current_snapshot.token0TradeVolumeUSD - previous_aggregate_snapshot.token1TradeVolumeUSD += current_snapshot.token1TradeVolumeUSD - - return previous_aggregate_snapshot - - def _remove_aggregate_snapshot( - self, - previous_aggregate_snapshot: UniswapTradesAggregateSnapshot, - current_snapshot: UniswapTradesAggregateSnapshot, - ): - - previous_aggregate_snapshot.totalTrade -= current_snapshot.totalTrade - previous_aggregate_snapshot.totalFee -= current_snapshot.totalFee - previous_aggregate_snapshot.token0TradeVolume -= current_snapshot.token0TradeVolume - previous_aggregate_snapshot.token1TradeVolume -= current_snapshot.token1TradeVolume - previous_aggregate_snapshot.token0TradeVolumeUSD -= current_snapshot.token0TradeVolumeUSD - previous_aggregate_snapshot.token1TradeVolumeUSD -= current_snapshot.token1TradeVolumeUSD - - return previous_aggregate_snapshot - - async def compute( - self, - msg_obj: PowerloomSnapshotSubmittedMessage, - redis: aioredis.Redis, - rpc_helper: RpcHelper, - anchor_rpc_helper: RpcHelper, - ipfs_reader: AsyncIPFSClient, - protocol_state_contract, - project_id: str, - - ): - self._logger.info(f'Building 7 day trade volume aggregate snapshot against {msg_obj}') - - contract = project_id.split(':')[-2] - - aggregate_snapshot = UniswapTradesAggregateSnapshot( - epochId=msg_obj.epochId, - ) - # 24h snapshots fetches - snapshot_tasks = list() - self._logger.debug('fetching 24hour aggregates spaced out by 1 day over 7 days...') - count = 1 - self._logger.debug( - 'fetch # {}: queueing task for 24h aggregate snapshot for project ID {}' - ' at currently received epoch ID {} with snasphot CID {}', - count, msg_obj.projectId, msg_obj.epochId, msg_obj.snapshotCid, - ) - - snapshot_tasks.append( - get_submission_data( - redis, msg_obj.snapshotCid, ipfs_reader, msg_obj.projectId, - ), - ) - - seek_stop_flag = False - head_epoch = msg_obj.epochId - # 2. if not extrapolated, attempt to seek further back - while not seek_stop_flag and count < 7: - tail_epoch_id, seek_stop_flag = await get_tail_epoch_id( - redis, protocol_state_contract, anchor_rpc_helper, head_epoch, 86400, msg_obj.projectId, - ) - count += 1 - snapshot_tasks.append( - get_project_epoch_snapshot( - redis, protocol_state_contract, anchor_rpc_helper, - ipfs_reader, tail_epoch_id, msg_obj.projectId, - ), - ) - head_epoch = tail_epoch_id - 1 - - all_snapshots = await asyncio.gather(*snapshot_tasks, return_exceptions=True) - self._logger.debug( - 'for 7d aggregated trade volume calculations: fetched {} ' - '24h aggregated trade volume snapshots for project ID {}: {}', - len(all_snapshots), msg_obj.projectId, all_snapshots, - ) - complete_flags = [] - for single_24h_snapshot in all_snapshots: - if not isinstance(single_24h_snapshot, BaseException): - try: - snapshot = UniswapTradesAggregateSnapshot.parse_obj(single_24h_snapshot) - complete_flags.append(snapshot.complete) - except pydantic.ValidationError: - pass - else: - aggregate_snapshot = self._add_aggregate_snapshot(aggregate_snapshot, snapshot) - - if not all(complete_flags) or count < 7: - aggregate_snapshot.complete = False - else: - aggregate_snapshot.complete = True - return aggregate_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/pair_total_reserves.py b/snapshotter/modules/pooler/uniswapv2/pair_total_reserves.py deleted file mode 100644 index e79664ea..00000000 --- a/snapshotter/modules/pooler/uniswapv2/pair_total_reserves.py +++ /dev/null @@ -1,114 +0,0 @@ -import time -from typing import Dict -from typing import Optional -from typing import Union - -from redis import asyncio as aioredis - -from .utils.core import get_pair_reserves -from .utils.models.message_models import EpochBaseSnapshot -from .utils.models.message_models import UniswapPairTotalReservesSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorSnapshot -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomSnapshotProcessMessage -from snapshotter.utils.rpc import RpcHelper - - -class PairTotalReservesProcessor(GenericProcessorSnapshot): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [] - self._logger = logger.bind(module='PairTotalReservesProcessor') - - async def compute( - self, - epoch: PowerloomSnapshotProcessMessage, - redis_conn: aioredis.Redis, - rpc_helper: RpcHelper, - - ) -> Optional[Dict[str, Union[int, float]]]: - - min_chain_height = epoch.begin - max_chain_height = epoch.end - - data_source_contract_address = epoch.data_source - - epoch_reserves_snapshot_map_token0 = dict() - epoch_prices_snapshot_map_token0 = dict() - epoch_prices_snapshot_map_token1 = dict() - epoch_reserves_snapshot_map_token1 = dict() - epoch_usd_reserves_snapshot_map_token0 = dict() - epoch_usd_reserves_snapshot_map_token1 = dict() - max_block_timestamp = int(time.time()) - - self._logger.debug(f'pair reserves {data_source_contract_address} computation init time {time.time()}') - pair_reserve_total = await get_pair_reserves( - pair_address=data_source_contract_address, - from_block=min_chain_height, - to_block=max_chain_height, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - fetch_timestamp=True, - ) - - for block_num in range(min_chain_height, max_chain_height + 1): - block_pair_total_reserves = pair_reserve_total.get(block_num) - fetch_ts = True if block_num == max_chain_height else False - - epoch_reserves_snapshot_map_token0[ - f'block{block_num}' - ] = block_pair_total_reserves['token0'] - epoch_reserves_snapshot_map_token1[ - f'block{block_num}' - ] = block_pair_total_reserves['token1'] - epoch_usd_reserves_snapshot_map_token0[ - f'block{block_num}' - ] = block_pair_total_reserves['token0USD'] - epoch_usd_reserves_snapshot_map_token1[ - f'block{block_num}' - ] = block_pair_total_reserves['token1USD'] - - epoch_prices_snapshot_map_token0[ - f'block{block_num}' - ] = block_pair_total_reserves['token0Price'] - - epoch_prices_snapshot_map_token1[ - f'block{block_num}' - ] = block_pair_total_reserves['token1Price'] - - if fetch_ts: - if not block_pair_total_reserves.get('timestamp', None): - self._logger.error( - ( - 'Could not fetch timestamp against max block' - ' height in epoch {} - {}to calculate pair' - ' reserves for contract {}. Using current time' - ' stamp for snapshot construction' - ), - data_source_contract_address, - min_chain_height, - max_chain_height, - ) - else: - max_block_timestamp = block_pair_total_reserves.get( - 'timestamp', - ) - pair_total_reserves_snapshot = UniswapPairTotalReservesSnapshot( - **{ - 'token0Reserves': epoch_reserves_snapshot_map_token0, - 'token1Reserves': epoch_reserves_snapshot_map_token1, - 'token0ReservesUSD': epoch_usd_reserves_snapshot_map_token0, - 'token1ReservesUSD': epoch_usd_reserves_snapshot_map_token1, - 'token0Prices': epoch_prices_snapshot_map_token0, - 'token1Prices': epoch_prices_snapshot_map_token1, - 'chainHeightRange': EpochBaseSnapshot( - begin=min_chain_height, end=max_chain_height, - ), - 'timestamp': max_block_timestamp, - 'contract': data_source_contract_address, - }, - ) - self._logger.debug(f'pair reserves {data_source_contract_address}, computation end time {time.time()}') - - return pair_total_reserves_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/redis_keys.py b/snapshotter/modules/pooler/uniswapv2/redis_keys.py deleted file mode 100644 index c6b526c0..00000000 --- a/snapshotter/modules/pooler/uniswapv2/redis_keys.py +++ /dev/null @@ -1,49 +0,0 @@ -from snapshotter.settings.config import settings - -uniswap_pair_contract_tokens_addresses = ( - 'uniswap:pairContract:' + settings.namespace + ':{}:PairContractTokensAddresses' -) -uniswap_pair_contract_tokens_data = ( - 'uniswap:pairContract:' + settings.namespace + ':{}:PairContractTokensData' -) - -uinswap_token_pair_contract_mapping = ( - 'uniswap:tokens:' + settings.namespace + ':PairContractAddress' -) - -uniswap_V2_summarized_snapshots_zset = ( - 'uniswap:V2PairsSummarySnapshot:' + settings.namespace + ':snapshotsZset' -) -uniswap_V2_snapshot_at_blockheight = ( - 'uniswap:V2PairsSummarySnapshot:' + settings.namespace + ':snapshot:{}' -) # block_height -uniswap_v2_daily_stats_snapshot_zset = ( - 'uniswap:V2DailyStatsSnapshot:' + settings.namespace + ':snapshotsZset' -) -uniswap_V2_daily_stats_at_blockheight = ( - 'uniswap:V2DailyStatsSnapshot:' + settings.namespace + ':snapshot:{}' -) # block_height -uniswap_v2_tokens_snapshot_zset = ( - 'uniswap:V2TokensSummarySnapshot:' + settings.namespace + ':snapshotsZset' -) -uniswap_V2_tokens_at_blockheight = ( - 'uniswap:V2TokensSummarySnapshot:' + settings.namespace + ':{}' -) # block_height - -uniswap_pair_cached_recent_logs = ( - 'uniswap:pairContract:' + settings.namespace + ':{}:recentLogs' -) - -uniswap_tokens_pair_map = ( - 'uniswap:pairContract:' + settings.namespace + ':tokensPairMap' -) - -uniswap_pair_cached_block_height_token_price = ( - 'uniswap:pairContract:' + settings.namespace + - ':{}:cachedPairBlockHeightTokenPrice' -) - -uniswap_token_derived_eth_cached_block_height = ( - 'uniswap:token:' + settings.namespace + - ':{}:cachedDerivedEthBlockHeight' -) diff --git a/snapshotter/modules/pooler/uniswapv2/settings/__init__.py b/snapshotter/modules/pooler/uniswapv2/settings/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/snapshotter/modules/pooler/uniswapv2/settings/config.py b/snapshotter/modules/pooler/uniswapv2/settings/config.py deleted file mode 100644 index 79c54b60..00000000 --- a/snapshotter/modules/pooler/uniswapv2/settings/config.py +++ /dev/null @@ -1,10 +0,0 @@ -import json -import os - -from .settings_model import Settings - -dir_path = os.path.dirname(os.path.realpath(__file__)) -settings_file = open(os.path.join(dir_path, 'settings.json'), 'r') -settings_dict = json.load(settings_file) - -settings: Settings = Settings(**settings_dict) diff --git a/snapshotter/modules/pooler/uniswapv2/settings/settings.json b/snapshotter/modules/pooler/uniswapv2/settings/settings.json deleted file mode 100644 index 28edb26d..00000000 --- a/snapshotter/modules/pooler/uniswapv2/settings/settings.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "uniswap_contract_abis":{ - "factory":"snapshotter/modules/pooler/uniswapv2/static/abis/IUniswapV2Factory.json", - "router":"snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Router.json", - "pair_contract":"snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Pair.json", - "erc20":"snapshotter/modules/pooler/uniswapv2/static/abis/IERC20.json", - "trade_events":"snapshotter/modules/pooler/uniswapv2/static/abis/UniswapTradeEvents.json" - }, - "contract_addresses": { - "iuniswap_v2_factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", - "iuniswap_v2_router": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", - "iuniswap_v2_pair": "0x3356c9A8f40F8E9C1d192A4347A76D18243fABC5", - "USDT": "0xdac17f958d2ee523a2206206994597c13d831ec7", - "DAI": "0x6b175474e89094c44da98b954eedeac495271d0f", - "USDC": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", - "WETH": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", - "MAKER": "0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2", - "WETH_USDT": "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852", - "FRAX": "0x853d955aCEf822Db058eb8505911ED77F175b99e", - "SYN": "0x0f2D719407FdBeFF09D87557AbB7232601FD9F29", - "FEI": "0x956F47F50A910163D8BF957Cf5846D573E7f87CA", - "agEUR": "0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8", - "DAI_WETH_PAIR": "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11", - "USDC_WETH_PAIR": "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", - "USDT_WETH_PAIR": "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852" - }, - "uniswap_v2_whitelist": [ - "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", - "0x6b175474e89094c44da98b954eedeac495271d0f", - "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", - "0xdac17f958d2ee523a2206206994597c13d831ec7", - "0x0000000000085d4780b73119b644ae5ecd22b376", - "0x5d3a536e4d6dbd6114cc1ead35777bab948e3643", - "0x39aa39c021dfbae8fac545936693ac917d5e7563", - "0x57ab1ec28d129707052df4df418d58a2d46d5f51", - "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", - "0xc00e94cb662c3520282e6f5717214004a7f26888", - "0x514910771af9ca656af840dff83e8264ecf986ca", - "0x960b236a07cf122663c4303350609a66a7b288c0", - "0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f", - "0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e", - "0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8", - "0x853d955acef822db058eb8505911ed77f175b99e", - "0xa47c8bf37f92abed4a126bda807a7b7498661acd", - "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984", - "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599", - "0x956f47f50a910163d8bf957cf5846d573e7f87ca" - ] -} diff --git a/snapshotter/modules/pooler/uniswapv2/settings/settings_model.py b/snapshotter/modules/pooler/uniswapv2/settings/settings_model.py deleted file mode 100644 index 2650cfac..00000000 --- a/snapshotter/modules/pooler/uniswapv2/settings/settings_model.py +++ /dev/null @@ -1,58 +0,0 @@ -from typing import List - -from pydantic import BaseModel -from pydantic import Field - - -class UniswapContractAbis(BaseModel): - factory: str = Field( - ..., example='pooler/modules/uniswapv2static/abis/IUniswapV2Factory.json', - ) - router: str = Field(..., example='pooler/modules/uniswapv2/static/abis/UniswapV2Router.json') - pair_contract: str = Field( - ..., example='pooler/modules/uniswapv2/static/abis/UniswapV2Pair.json', - ) - erc20: str = Field(..., example='pooler/modules/uniswapv2/static/abis/IERC20.json') - trade_events: str = Field( - ..., example='pooler/modules/uniswapv2/static/abis/UniswapTradeEvents.json', - ) - - -class ContractAddresses(BaseModel): - iuniswap_v2_factory: str = Field( - ..., example='0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32', - ) - iuniswap_v2_router: str = Field( - ..., example='0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff', - ) - MAKER: str = Field( - ..., example='0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2', - ) - USDT: str = Field(..., example='0xc2132d05d31c914a87c6611c10748aeb04b58e8f') - DAI: str = Field(..., example='0x8f3cf7ad23cd3cadbd9735aff958023239c6a063') - USDC: str = Field(..., example='0x2791bca1f2de4661ed88a30c99a7a9449aa84174') - WETH: str = Field(..., example='0x7ceb23fd6bc0add59e62ac25578270cff1b9f619') - WETH_USDT: str = Field( - ..., example='0xf6422b997c7f54d1c6a6e103bcb1499eea0a7046', - ) - FRAX: str = Field(..., example='0x853d955aCEf822Db058eb8505911ED77F175b99e') - SYN: str = Field(..., example='0x0f2D719407FdBeFF09D87557AbB7232601FD9F29') - FEI: str = Field(..., example='0x956F47F50A910163D8BF957Cf5846D573E7f87CA') - agEUR: str = Field( - ..., example='0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8', - ) - DAI_WETH_PAIR: str = Field( - ..., example='0xa478c2975ab1ea89e8196811f51a7b7ade33eb11', - ) - USDC_WETH_PAIR: str = Field( - ..., example='0xb4e16d0168e52d35cacd2c6185b44281ec28c9', - ) - USDT_WETH_PAIR: str = Field( - ..., example='0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852', - ) - - -class Settings(BaseModel): - uniswap_contract_abis: UniswapContractAbis - contract_addresses: ContractAddresses - uniswap_v2_whitelist: List[str] diff --git a/snapshotter/modules/pooler/uniswapv2/static/abis/IERC20.json b/snapshotter/modules/pooler/uniswapv2/static/abis/IERC20.json deleted file mode 100644 index b3eb93c9..00000000 --- a/snapshotter/modules/pooler/uniswapv2/static/abis/IERC20.json +++ /dev/null @@ -1,224 +0,0 @@ -[ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "address", - "name": "spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "decimals", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/snapshotter/modules/pooler/uniswapv2/static/abis/ISushiswapFactory.json b/snapshotter/modules/pooler/uniswapv2/static/abis/ISushiswapFactory.json deleted file mode 100644 index 91a3b89c..00000000 --- a/snapshotter/modules/pooler/uniswapv2/static/abis/ISushiswapFactory.json +++ /dev/null @@ -1,215 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "address", - "name": "_feeToSetter", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "pair", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "PairCreated", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "allPairs", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "allPairsLength", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenA", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenB", - "type": "address" - } - ], - "name": "createPair", - "outputs": [ - { - "internalType": "address", - "name": "pair", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "feeTo", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "feeToSetter", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "getPair", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "migrator", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pairCodeHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_feeTo", - "type": "address" - } - ], - "name": "setFeeTo", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_feeToSetter", - "type": "address" - } - ], - "name": "setFeeToSetter", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_migrator", - "type": "address" - } - ], - "name": "setMigrator", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/snapshotter/modules/pooler/uniswapv2/static/abis/IUniswapV2Factory.json b/snapshotter/modules/pooler/uniswapv2/static/abis/IUniswapV2Factory.json deleted file mode 100644 index 75e9bd5d..00000000 --- a/snapshotter/modules/pooler/uniswapv2/static/abis/IUniswapV2Factory.json +++ /dev/null @@ -1,193 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "address", - "name": "_feeToSetter", - "type": "address" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "pair", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "PairCreated", - "type": "event" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "allPairs", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "allPairsLength", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "tokenA", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenB", - "type": "address" - } - ], - "name": "createPair", - "outputs": [ - { - "internalType": "address", - "name": "pair", - "type": "address" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "feeTo", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "feeToSetter", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "getPair", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "_feeTo", - "type": "address" - } - ], - "name": "setFeeTo", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "_feeToSetter", - "type": "address" - } - ], - "name": "setFeeToSetter", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/snapshotter/modules/pooler/uniswapv2/static/abis/SushiswapPair.json b/snapshotter/modules/pooler/uniswapv2/static/abis/SushiswapPair.json deleted file mode 100644 index 61c709c4..00000000 --- a/snapshotter/modules/pooler/uniswapv2/static/abis/SushiswapPair.json +++ /dev/null @@ -1,658 +0,0 @@ -[ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "Burn", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1", - "type": "uint256" - } - ], - "name": "Mint", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0In", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1In", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0Out", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1Out", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "Swap", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint112", - "name": "reserve0", - "type": "uint112" - }, - { - "indexed": false, - "internalType": "uint112", - "name": "reserve1", - "type": "uint112" - } - ], - "name": "Sync", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "inputs": [], - "name": "DOMAIN_SEPARATOR", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MINIMUM_LIQUIDITY", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "PERMIT_TYPEHASH", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "burn", - "outputs": [ - { - "internalType": "uint256", - "name": "amount0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amount1", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "decimals", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "factory", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getReserves", - "outputs": [ - { - "internalType": "uint112", - "name": "_reserve0", - "type": "uint112" - }, - { - "internalType": "uint112", - "name": "_reserve1", - "type": "uint112" - }, - { - "internalType": "uint32", - "name": "_blockTimestampLast", - "type": "uint32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_token0", - "type": "address" - }, - { - "internalType": "address", - "name": "_token1", - "type": "address" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "kLast", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "mint", - "outputs": [ - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "nonces", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - } - ], - "name": "permit", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "price0CumulativeLast", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "price1CumulativeLast", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "skim", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount0Out", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amount1Out", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "name": "swap", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "sync", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "token0", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "token1", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapTradeEvents.json b/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapTradeEvents.json deleted file mode 100644 index 7dd79cd9..00000000 --- a/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapTradeEvents.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "Swap": { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0In", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1In", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0Out", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1Out", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "Swap", - "type": "event" - }, - "Mint": { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1", - "type": "uint256" - } - ], - "name": "Mint", - "type": "event" - }, - "Burn": { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "Burn", - "type": "event" - } -} diff --git a/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Pair.json b/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Pair.json deleted file mode 100644 index 6a6ef031..00000000 --- a/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Pair.json +++ /dev/null @@ -1 +0,0 @@ -[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint112","name":"reserve0","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"reserve1","type":"uint112"}],"name":"Sync","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":true,"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MINIMUM_LIQUIDITY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getReserves","outputs":[{"internalType":"uint112","name":"_reserve0","type":"uint112"},{"internalType":"uint112","name":"_reserve1","type":"uint112"},{"internalType":"uint32","name":"_blockTimestampLast","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_token0","type":"address"},{"internalType":"address","name":"_token1","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"kLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"liquidity","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"price0CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"price1CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"skim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount0Out","type":"uint256"},{"internalType":"uint256","name":"amount1Out","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swap","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"sync","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] diff --git a/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Router.json b/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Router.json deleted file mode 100644 index c1d05c2c..00000000 --- a/snapshotter/modules/pooler/uniswapv2/static/abis/UniswapV2Router.json +++ /dev/null @@ -1,973 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "address", - "name": "_factory", - "type": "address" - }, - { - "internalType": "address", - "name": "_WETH", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [], - "name": "WETH", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenA", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenB", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amountADesired", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountBDesired", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountAMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountBMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "addLiquidity", - "outputs": [ - { - "internalType": "uint256", - "name": "amountA", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountB", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amountTokenDesired", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountTokenMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETHMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "addLiquidityETH", - "outputs": [ - { - "internalType": "uint256", - "name": "amountToken", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETH", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [], - "name": "factory", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "reserveIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "reserveOut", - "type": "uint256" - } - ], - "name": "getAmountIn", - "outputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "reserveIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "reserveOut", - "type": "uint256" - } - ], - "name": "getAmountOut", - "outputs": [ - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - } - ], - "name": "getAmountsIn", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - } - ], - "name": "getAmountsOut", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountA", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "reserveA", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "reserveB", - "type": "uint256" - } - ], - "name": "quote", - "outputs": [ - { - "internalType": "uint256", - "name": "amountB", - "type": "uint256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenA", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenB", - "type": "address" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountAMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountBMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "removeLiquidity", - "outputs": [ - { - "internalType": "uint256", - "name": "amountA", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountB", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountTokenMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETHMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "removeLiquidityETH", - "outputs": [ - { - "internalType": "uint256", - "name": "amountToken", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETH", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountTokenMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETHMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "removeLiquidityETHSupportingFeeOnTransferTokens", - "outputs": [ - { - "internalType": "uint256", - "name": "amountETH", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountTokenMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETHMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "approveMax", - "type": "bool" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - } - ], - "name": "removeLiquidityETHWithPermit", - "outputs": [ - { - "internalType": "uint256", - "name": "amountToken", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETH", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountTokenMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountETHMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "approveMax", - "type": "bool" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - } - ], - "name": "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens", - "outputs": [ - { - "internalType": "uint256", - "name": "amountETH", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenA", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenB", - "type": "address" - }, - { - "internalType": "uint256", - "name": "liquidity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountAMin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountBMin", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "approveMax", - "type": "bool" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - } - ], - "name": "removeLiquidityWithPermit", - "outputs": [ - { - "internalType": "uint256", - "name": "amountA", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountB", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapETHForExactTokens", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountOutMin", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapExactETHForTokens", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountOutMin", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapExactETHForTokensSupportingFeeOnTransferTokens", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOutMin", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapExactTokensForETH", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOutMin", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapExactTokensForETHSupportingFeeOnTransferTokens", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOutMin", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapExactTokensForTokens", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOutMin", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapExactTokensForTokensSupportingFeeOnTransferTokens", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountInMax", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapTokensForExactETH", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountInMax", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "path", - "type": "address[]" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - } - ], - "name": "swapTokensForExactTokens", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "stateMutability": "payable", - "type": "receive" - } -] diff --git a/snapshotter/modules/pooler/uniswapv2/tests/liquidity_test.py b/snapshotter/modules/pooler/uniswapv2/tests/liquidity_test.py deleted file mode 100644 index ffd78f43..00000000 --- a/snapshotter/modules/pooler/uniswapv2/tests/liquidity_test.py +++ /dev/null @@ -1,92 +0,0 @@ -import asyncio -import json - -import httpx -from redis import asyncio as aioredis - -from ..utils.core import get_pair_reserves -from snapshotter.utils.redis.rate_limiter import load_rate_limiter_scripts -from snapshotter.utils.redis.redis_conn import provide_async_redis_conn_insta - - -@provide_async_redis_conn_insta -async def fetch_liquidityUSD_rpc( - pair_address, - block_num, - redis_conn: aioredis.Redis = None, -): - rate_limiting_lua_scripts = await load_rate_limiter_scripts(redis_conn) - data = await get_pair_reserves( - loop, - rate_limiting_lua_scripts, - pair_address, - block_num, - block_num, - redis_conn=redis_conn, - ) - block_pair_total_reserves = data.get(block_num) - return ( - block_pair_total_reserves['token0USD'] + - block_pair_total_reserves['token1USD'] - ) - - -def fetch_liquidityUSD_graph(pair_address, block_num): - uniswap_url = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2' - uniswap_payload = ( - '{"query":"{\\n pair(id: \\"' + - str(pair_address) + - '\\",block:{number:' + - str( - block_num, - ) + - '}) {\\n reserveUSD \\n token0 { \\n symbol \\n } \\n token1 {' - ' \\n symbol \\n }\\n } \\n }" }' - ) - print(uniswap_payload) - headers = {'Content-Type': 'application/plain'} - response = httpx.post( - url=uniswap_url, - headers=headers, - data=uniswap_payload, - timeout=30, - ) - if response.status_code == 200: - data = json.loads(response.text) - print('Response', data) - data = data['data'] - return float(data['pair']['reserveUSD']) - else: - print('Error fetching data from uniswap THE GRAPH %s', response) - return 0 - - -async def compare_liquidity(): - total_liquidity_usd_graph = 0 - total_liquidity_usd_rpc = 0 - block_num = 16046250 - - contracts = list() - contracts.append('0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5') - for contract in contracts: - liquidity_usd_graph = fetch_liquidityUSD_graph(contract, block_num) - liquidity_usd_rpc = await fetch_liquidityUSD_rpc(contract, block_num) - print( - f'Contract {contract}, liquidityUSD_graph is' - f' {liquidity_usd_graph} , liquidityUSD_rpc {liquidity_usd_rpc},' - ' liquidityUSD difference' - f' {(liquidity_usd_rpc - liquidity_usd_graph)}', - ) - total_liquidity_usd_graph += liquidity_usd_graph - total_liquidity_usd_rpc += liquidity_usd_rpc - - print( - f'{len(contracts)} contracts compared, liquidityUSD_rpc_total is' - f' {total_liquidity_usd_rpc}, liquidityUSD_graph_total is' - f' {total_liquidity_usd_graph}', - ) - - -if __name__ == '__main__': - loop = asyncio.get_event_loop() - loop.run_until_complete(compare_liquidity()) diff --git a/snapshotter/modules/pooler/uniswapv2/tests/token_price_test.py b/snapshotter/modules/pooler/uniswapv2/tests/token_price_test.py deleted file mode 100644 index 345bb4ca..00000000 --- a/snapshotter/modules/pooler/uniswapv2/tests/token_price_test.py +++ /dev/null @@ -1,490 +0,0 @@ -import asyncio -import json -from functools import partial - -from redis import asyncio as aioredis -from web3 import Web3 - -from ..settings.config import enabled_projects -from ..settings.config import settings -from ..settings.config import settings as worker_settings -from ..utils.helpers import get_pair_metadata -from snapshotter.utils.redis.rate_limiter import load_rate_limiter_scripts -from snapshotter.utils.redis.redis_conn import provide_async_redis_conn_insta - -w3 = Web3(Web3.HTTPProvider(settings.rpc.full_nodes[0].url)) -pair_address = Web3.toChecksumAddress( - '0x97c4adc5d28a86f9470c70dd91dc6cc2f20d2d4d', -) - - -def read_json_file(file_path: str): - """Read given json file and return its content as a dictionary.""" - try: - f_ = open(file_path, 'r', encoding='utf-8') - except Exception as exc: - print(f'Unable to open the {file_path} file') - raise exc - else: - json_data = json.loads(f_.read()) - return json_data - - -router_contract_abi = read_json_file( - worker_settings.uniswap_contract_abis.router, -) -pair_contract_abi = read_json_file( - worker_settings.uniswap_contract_abis.pair_contract, -) -all_contracts = enabled_projects - - -async def get_token_price_at_block_height( - token_contract_obj, - token_metadata, - block_height, - loop: asyncio.AbstractEventLoop, - redis_conn=None, - debug_log=True, -): - """ - returns the price of a token at a given block height - """ - try: - token_price = 0 - - # else fetch from rpc - stable_coins_addresses = { - 'USDC': Web3.toChecksumAddress( - worker_settings.contract_addresses.USDC, - ), - 'DAI': Web3.toChecksumAddress( - worker_settings.contract_addresses.DAI, - ), - 'USDT': Web3.toChecksumAddress( - worker_settings.contract_addresses.USDT, - ), - } - stable_coins_decimals = { - 'USDT': 6, - 'DAI': 18, - 'USDC': 6, - } - non_stable_coins_addresses = { - Web3.toChecksumAddress(worker_settings.contract_addresses.agEUR): { - 'token0': Web3.toChecksumAddress( - worker_settings.contract_addresses.agEUR, - ), - 'token1': Web3.toChecksumAddress( - worker_settings.contract_addresses.FEI, - ), - 'decimals': 18, - }, - Web3.toChecksumAddress(worker_settings.contract_addresses.SYN): { - 'token0': Web3.toChecksumAddress( - worker_settings.contract_addresses.SYN, - ), - 'token1': Web3.toChecksumAddress( - worker_settings.contract_addresses.FRAX, - ), - 'decimals': 18, - }, - } - - # this is used to avoid INSUFFICIENT_INPUT_AMOUNT error - token_amount_multiplier = 10**18 - - # check if token is a stable coin if so then ignore price fetch call - if Web3.toChecksumAddress(token_metadata['address']) in list( - stable_coins_addresses.values(), - ): - token_price = 1 - if debug_log: - print( - ( - f"## {token_metadata['symbol']}: ignored stablecoin" - f" calculation for token0: {token_metadata['symbol']} -" - f' WETH - USDT conversion: {token_price}' - ), - ) - - # check if token has no pair with stablecoin and weth if so then use hardcoded path - elif non_stable_coins_addresses.get( - Web3.toChecksumAddress(token_metadata['address']), - ): - contract_metadata = non_stable_coins_addresses.get( - Web3.toChecksumAddress(token_metadata['address']), - ) - if not contract_metadata: - return None - price_function_token0 = partial( - token_contract_obj.functions.getAmountsOut( - 10 ** int(contract_metadata['decimals']), - [ - contract_metadata['token0'], - contract_metadata['token1'], - Web3.toChecksumAddress( - worker_settings.contract_addresses.USDC, - ), - ], - ).call, - block_identifier=block_height, - ) - temp_token_price = await loop.run_in_executor( - func=price_function_token0, - executor=None, - ) - if temp_token_price: - # USDC decimals - temp_token_price = ( - temp_token_price[2] / 10 ** stable_coins_decimals['USDC'] - if temp_token_price[2] != 0 - else 0 - ) - token_price = ( - temp_token_price if token_price < temp_token_price else token_price - ) - - # 1. if is not equals to weth then check its price against each stable coin take out heighest - # 2. if price is still 0/None then pass path as token->weth-usdt - # 3. if price is still 0/None then increase token amount in path (token->weth-usdc) - elif Web3.toChecksumAddress( - token_metadata['address'], - ) != Web3.toChecksumAddress(worker_settings.contract_addresses.WETH): - # iterate over all stable coin to find price - stable_coins_len = len(stable_coins_addresses) - for key, value in stable_coins_addresses.items(): - try: - price_function_token0 = partial( - token_contract_obj.functions.getAmountsOut( - 10 ** int(token_metadata['decimals']), - [ - Web3.toChecksumAddress( - token_metadata['address'], - ), - value, - ], - ).call, - block_identifier=block_height, - ) - temp_token_price = await loop.run_in_executor( - func=price_function_token0, - executor=None, - ) - if temp_token_price: - # USDT decimals - temp_token_price = ( - temp_token_price[1] / - 10 ** stable_coins_decimals[key] - if temp_token_price[1] != 0 - else 0 - ) - - print( - ( - f"## {token_metadata['symbol']}->{key}: token" - f' price: {temp_token_price}' - ), - ) - - token_price = ( - temp_token_price - if token_price < temp_token_price - else token_price - ) - except Exception as error: - # if reverted then it means token do not have pair with this stablecoin, try another - if 'execution reverted' in str(error): - temp_token_price = 0 - else: - # if there was no exception and price is still 0 - # then increase token amount in path (token->stablecoin) - if temp_token_price == 0: - price_function_token0 = partial( - token_contract_obj.functions.getAmountsOut( - 10 ** int(token_metadata['decimals']) * - token_amount_multiplier, - [ - Web3.toChecksumAddress( - token_metadata['address'], - ), - value, - ], - ).call, - block_identifier=block_height, - ) - temp_token_price = await loop.run_in_executor( - func=price_function_token0, - executor=None, - ) - if temp_token_price: - # USDT decimals - temp_token_price = ( - temp_token_price[1] / - 10 ** stable_coins_decimals[key] - if temp_token_price[1] != 0 - else 0 - ) - temp_token_price = ( - temp_token_price / token_amount_multiplier - ) - - print( - ( - f"## {token_metadata['symbol']}->{key}:" - ' (increased_input_amount) token price :' - f' {temp_token_price}' - ), - ) - - token_price = ( - temp_token_price - if token_price < temp_token_price - else token_price - ) - - stable_coins_len -= 1 - if stable_coins_len <= 0: - break - - print( - ( - f"## {token_metadata['symbol']}: chosed token price after" - f' all stable coin conversions: {token_price}' - ), - ) - - # After iterating over all stable coin, check if - # path conversion by token->weth->usdt give a higher price of token - # if so then replace it, as for some tokens we get accurate price - # by token->weth->usdt path only - try: - price_function_token0 = partial( - token_contract_obj.functions.getAmountsOut( - 10 ** int(token_metadata['decimals']), - [ - Web3.toChecksumAddress(token_metadata['address']), - Web3.toChecksumAddress( - worker_settings.contract_addresses.WETH, - ), - Web3.toChecksumAddress( - worker_settings.contract_addresses.USDT, - ), - ], - ).call, - block_identifier=block_height, - ) - temp_token_price = await loop.run_in_executor( - func=price_function_token0, - executor=None, - ) - if temp_token_price: - # USDT decimals - temp_token_price = ( - temp_token_price[2] / - 10 ** stable_coins_decimals['USDT'] - if temp_token_price[2] != 0 - else 0 - ) - print( - ( - f"## {token_metadata['symbol']}: token price after" - f' weth->stablecoin: {temp_token_price}' - ), - ) - token_price = ( - temp_token_price - if token_price < temp_token_price - else token_price - ) - except Exception: - # there might be INSUFFICIENT_INPUT_AMOUNT/execution_reverted - # error which can break program flow, so pass it - pass - - # after going through all stablecoins and weth conversion if price is still 0 - # then increase token amount in path (token->weth-usdt) - if token_price == 0: - price_function_token0 = partial( - token_contract_obj.functions.getAmountsOut( - 10 ** int( - token_metadata['decimals'], - ) * token_amount_multiplier, - [ - Web3.toChecksumAddress(token_metadata['address']), - Web3.toChecksumAddress( - worker_settings.contract_addresses.WETH, - ), - Web3.toChecksumAddress( - worker_settings.contract_addresses.USDT, - ), - ], - ).call, - block_identifier=block_height, - ) - temp_token_price = await loop.run_in_executor( - func=price_function_token0, - executor=None, - ) - - if temp_token_price: - # USDT decimals - temp_token_price = ( - temp_token_price[2] / - 10 ** stable_coins_decimals['USDT'] - if temp_token_price[2] != 0 - else 0 - ) - temp_token_price = temp_token_price / token_amount_multiplier - print( - ( - f"## {token_metadata['symbol']}: token price after" - ' weth->stablecoin (increased_input_amount):' - f' {temp_token_price}' - ), - ) - token_price = ( - temp_token_price - if token_price < temp_token_price - else token_price - ) - - if debug_log: - print( - f"## {token_metadata['symbol']}: final price: {token_price}", - ) - - # if token is weth then directly check its price against stable coin - else: - price_function_token0 = partial( - token_contract_obj.functions.getAmountsOut( - 10 ** int(token_metadata['decimals']), - [ - Web3.toChecksumAddress( - worker_settings.contract_addresses.WETH, - ), - Web3.toChecksumAddress( - worker_settings.contract_addresses.USDT, - ), - ], - ).call, - block_identifier=block_height, - ) - token_price = await loop.run_in_executor( - func=price_function_token0, - executor=None, - ) - token_price = ( - token_price[1] / 10 ** stable_coins_decimals['USDT'] - ) # USDT decimals - if debug_log: - print( - f"## {token_metadata['symbol']}: final prices:" f' {token_price}', - ) - except Exception as err: - print( - ( - f'Error: failed to fetch token price | error_msg: {str(err)} |' - f" contract: {token_metadata['address']}" - ), - ) - finally: - return float(token_price) - - -async def get_all_pairs_token_price(loop, redis_conn: aioredis.Redis = None): - router_contract_obj = w3.eth.contract( - address=Web3.toChecksumAddress( - worker_settings.contract_addresses.iuniswap_v2_router, - ), - abi=router_contract_abi, - ) - rate_limiting_lua_scripts = await load_rate_limiter_scripts(redis_conn) - - for contract in all_contracts: - pair_per_token_metadata = await get_pair_metadata( - rate_limit_lua_script_shas=rate_limiting_lua_scripts, - pair_address=contract, - loop=loop, - redis_conn=redis_conn, - ) - token0, token1 = await asyncio.gather( - get_token_price_at_block_height( - router_contract_obj, - pair_per_token_metadata['token0'], - 'latest', - loop, - redis_conn, - ), - get_token_price_at_block_height( - router_contract_obj, - pair_per_token_metadata['token1'], - 'latest', - loop, - redis_conn, - ), - ) - print('\n') - print( - { - pair_per_token_metadata['token0']['symbol']: token0, - pair_per_token_metadata['token1']['symbol']: token1, - 'contract': contract, - }, - ) - print('\n') - - -@provide_async_redis_conn_insta -async def get_pair_tokens_price(pair, loop, redis_conn: aioredis.Redis = None): - router_contract_obj = w3.eth.contract( - address=Web3.toChecksumAddress( - worker_settings.contract_addresses.iuniswap_v2_router, - ), - abi=router_contract_abi, - ) - - pair_address = Web3.toChecksumAddress(pair) - rate_limiting_lua_scripts = await load_rate_limiter_scripts(redis_conn) - pair_per_token_metadata = await get_pair_metadata( - rate_limit_lua_script_shas=rate_limiting_lua_scripts, - pair_address=pair_address, - loop=loop, - redis_conn=redis_conn, - ) - print('\n') - print('\n') - token0, token1 = await asyncio.gather( - get_token_price_at_block_height( - router_contract_obj, - pair_per_token_metadata['token0'], - 'latest', - loop, - redis_conn, - ), - get_token_price_at_block_height( - router_contract_obj, - pair_per_token_metadata['token1'], - 'latest', - loop, - redis_conn, - ), - ) - print('\n') - print( - { - pair_per_token_metadata['token0']['symbol']: token0, - pair_per_token_metadata['token1']['symbol']: token1, - }, - ) - print('\n') - await redis_conn.close() - - -if __name__ == '__main__': - pair_address = '0x7b73644935b8e68019ac6356c40661e1bc315860' - loop = asyncio.get_event_loop() - data = loop.run_until_complete( - get_pair_tokens_price(pair_address, loop), - ) - print(f'\n\n{data}\n') diff --git a/snapshotter/modules/pooler/uniswapv2/trade_volume.py b/snapshotter/modules/pooler/uniswapv2/trade_volume.py deleted file mode 100644 index 2dcd48f5..00000000 --- a/snapshotter/modules/pooler/uniswapv2/trade_volume.py +++ /dev/null @@ -1,89 +0,0 @@ -import time - -from redis import asyncio as aioredis - -from .utils.core import get_pair_trade_volume -from .utils.models.message_models import EpochBaseSnapshot -from .utils.models.message_models import UniswapTradesSnapshot -from snapshotter.utils.callback_helpers import GenericProcessorSnapshot -from snapshotter.utils.default_logger import logger -from snapshotter.utils.models.message_models import PowerloomSnapshotProcessMessage -from snapshotter.utils.rpc import RpcHelper - - -class TradeVolumeProcessor(GenericProcessorSnapshot): - transformation_lambdas = None - - def __init__(self) -> None: - self.transformation_lambdas = [ - self.transform_processed_epoch_to_trade_volume, - ] - self._logger = logger.bind(module='TradeVolumeProcessor') - - async def compute( - self, - epoch: PowerloomSnapshotProcessMessage, - redis_conn: aioredis.Redis, - rpc_helper: RpcHelper, - ): - - min_chain_height = epoch.begin - max_chain_height = epoch.end - - data_source_contract_address = epoch.data_source - - self._logger.debug(f'trade volume {data_source_contract_address}, computation init time {time.time()}') - result = await get_pair_trade_volume( - data_source_contract_address=data_source_contract_address, - min_chain_height=min_chain_height, - max_chain_height=max_chain_height, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - self._logger.debug(f'trade volume {data_source_contract_address}, computation end time {time.time()}') - return result - - def transform_processed_epoch_to_trade_volume( - self, - snapshot, - data_source_contract_address, - epoch_begin, - epoch_end, - ): - self._logger.debug( - 'Trade volume processed snapshot: {}', snapshot, - ) - - # Set effective trade volume at top level - total_trades_in_usd = snapshot['Trades'][ - 'totalTradesUSD' - ] - total_fee_in_usd = snapshot['Trades']['totalFeeUSD'] - total_token0_vol = snapshot['Trades'][ - 'token0TradeVolume' - ] - total_token1_vol = snapshot['Trades'][ - 'token1TradeVolume' - ] - total_token0_vol_usd = snapshot['Trades'][ - 'token0TradeVolumeUSD' - ] - total_token1_vol_usd = snapshot['Trades'][ - 'token1TradeVolumeUSD' - ] - - max_block_timestamp = snapshot.get('timestamp') - snapshot.pop('timestamp', None) - trade_volume_snapshot = UniswapTradesSnapshot( - contract=data_source_contract_address, - chainHeightRange=EpochBaseSnapshot(begin=epoch_begin, end=epoch_end), - timestamp=max_block_timestamp, - totalTrade=float(f'{total_trades_in_usd: .6f}'), - totalFee=float(f'{total_fee_in_usd: .6f}'), - token0TradeVolume=float(f'{total_token0_vol: .6f}'), - token1TradeVolume=float(f'{total_token1_vol: .6f}'), - token0TradeVolumeUSD=float(f'{total_token0_vol_usd: .6f}'), - token1TradeVolumeUSD=float(f'{total_token1_vol_usd: .6f}'), - events=snapshot, - ) - return trade_volume_snapshot diff --git a/snapshotter/modules/pooler/uniswapv2/utils/__init__.py b/snapshotter/modules/pooler/uniswapv2/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/snapshotter/modules/pooler/uniswapv2/utils/constants.py b/snapshotter/modules/pooler/uniswapv2/utils/constants.py deleted file mode 100644 index 44d7f4e1..00000000 --- a/snapshotter/modules/pooler/uniswapv2/utils/constants.py +++ /dev/null @@ -1,86 +0,0 @@ -from web3 import Web3 - -from ..settings.config import settings as worker_settings -from snapshotter.utils.default_logger import logger -from snapshotter.utils.file_utils import read_json_file -from snapshotter.utils.rpc import RpcHelper - -constants_logger = logger.bind(module='PowerLoom|Uniswap|Constants') -# Getting current node - -rpc_helper = RpcHelper() -current_node = rpc_helper.get_current_node() - -# LOAD ABIs -pair_contract_abi = read_json_file( - worker_settings.uniswap_contract_abis.pair_contract, - constants_logger, -) -erc20_abi = read_json_file( - worker_settings.uniswap_contract_abis.erc20, - constants_logger, -) -router_contract_abi = read_json_file( - worker_settings.uniswap_contract_abis.router, - constants_logger, -) -uniswap_trade_events_abi = read_json_file( - worker_settings.uniswap_contract_abis.trade_events, - constants_logger, -) -factory_contract_abi = read_json_file( - worker_settings.uniswap_contract_abis.factory, - constants_logger, -) - - -# Init Uniswap V2 Core contract Objects -router_contract_obj = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress( - worker_settings.contract_addresses.iuniswap_v2_router, - ), - abi=router_contract_abi, -) -factory_contract_obj = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress( - worker_settings.contract_addresses.iuniswap_v2_factory, - ), - abi=factory_contract_abi, -) -dai_eth_contract_obj = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress( - worker_settings.contract_addresses.DAI_WETH_PAIR, - ), - abi=pair_contract_abi, -) -usdc_eth_contract_obj = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress( - worker_settings.contract_addresses.USDC_WETH_PAIR, - ), - abi=pair_contract_abi, -) -eth_usdt_contract_obj = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress( - worker_settings.contract_addresses.USDT_WETH_PAIR, - ), - abi=pair_contract_abi, -) - - -# FUNCTION SIGNATURES and OTHER CONSTANTS -UNISWAP_TRADE_EVENT_SIGS = { - 'Swap': 'Swap(address,uint256,uint256,uint256,uint256,address)', - 'Mint': 'Mint(address,uint256,uint256)', - 'Burn': 'Burn(address,uint256,uint256,address)', -} -UNISWAP_EVENTS_ABI = { - 'Swap': usdc_eth_contract_obj.events.Swap._get_event_abi(), - 'Mint': usdc_eth_contract_obj.events.Mint._get_event_abi(), - 'Burn': usdc_eth_contract_obj.events.Burn._get_event_abi(), -} -tokens_decimals = { - 'USDT': 6, - 'DAI': 18, - 'USDC': 6, - 'WETH': 18, -} diff --git a/snapshotter/modules/pooler/uniswapv2/utils/core.py b/snapshotter/modules/pooler/uniswapv2/utils/core.py deleted file mode 100644 index 55ebcb46..00000000 --- a/snapshotter/modules/pooler/uniswapv2/utils/core.py +++ /dev/null @@ -1,481 +0,0 @@ -import asyncio -import json - -from redis import asyncio as aioredis -from web3 import Web3 - -from .constants import pair_contract_abi -from .constants import UNISWAP_EVENTS_ABI -from .constants import UNISWAP_TRADE_EVENT_SIGS -from .helpers import get_pair_metadata -from .models.data_models import epoch_event_trade_data -from .models.data_models import event_trade_data -from .models.data_models import trade_data -from .pricing import ( - get_token_price_in_block_range, -) -from snapshotter.utils.default_logger import logger -from snapshotter.utils.rpc import get_contract_abi_dict -from snapshotter.utils.rpc import get_event_sig_and_abi -from snapshotter.utils.rpc import RpcHelper -from snapshotter.utils.snapshot_utils import ( - get_block_details_in_block_range, -) - -core_logger = logger.bind(module='PowerLoom|UniswapCore') - - -async def get_pair_reserves( - pair_address, - from_block, - to_block, - redis_conn: aioredis.Redis, - rpc_helper: RpcHelper, - fetch_timestamp=False, -): - core_logger.debug( - f'Starting pair total reserves query for: {pair_address}', - ) - pair_address = Web3.toChecksumAddress(pair_address) - - if fetch_timestamp: - try: - block_details_dict = await get_block_details_in_block_range( - from_block, - to_block, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - except Exception as err: - core_logger.opt(exception=True).error( - ( - 'Error attempting to get block details of block-range' - ' {}-{}: {}, retrying again' - ), - from_block, - to_block, - err, - ) - raise err - else: - block_details_dict = dict() - - pair_per_token_metadata = await get_pair_metadata( - pair_address=pair_address, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - - core_logger.debug( - ( - 'total pair reserves fetched block details for epoch for:' - f' {pair_address}' - ), - ) - - token0_price_map, token1_price_map = await asyncio.gather( - get_token_price_in_block_range( - token_metadata=pair_per_token_metadata['token0'], - from_block=from_block, - to_block=to_block, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - debug_log=False, - ), - get_token_price_in_block_range( - token_metadata=pair_per_token_metadata['token1'], - from_block=from_block, - to_block=to_block, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - debug_log=False, - ), - ) - - core_logger.debug( - f'Total reserves fetched token prices for: {pair_address}', - ) - - # create dictionary of ABI {function_name -> {signature, abi, input, output}} - pair_abi_dict = get_contract_abi_dict(pair_contract_abi) - # get token price function takes care of its own rate limit - - reserves_array = await rpc_helper.batch_eth_call_on_block_range( - abi_dict=pair_abi_dict, - function_name='getReserves', - contract_address=pair_address, - from_block=from_block, - to_block=to_block, - redis_conn=redis_conn, - ) - - core_logger.debug( - f'Total reserves fetched getReserves results: {pair_address}', - ) - token0_decimals = pair_per_token_metadata['token0']['decimals'] - token1_decimals = pair_per_token_metadata['token1']['decimals'] - - pair_reserves_arr = dict() - block_count = 0 - for block_num in range(from_block, to_block + 1): - token0Amount = ( - reserves_array[block_count][0] / 10 ** int(token0_decimals) - if reserves_array[block_count][0] - else 0 - ) - token1Amount = ( - reserves_array[block_count][1] / 10 ** int(token1_decimals) - if reserves_array[block_count][1] - else 0 - ) - - token0USD = token0Amount * token0_price_map.get(block_num, 0) - token1USD = token1Amount * token1_price_map.get(block_num, 0) - - token0Price = token0_price_map.get(block_num, 0) - token1Price = token1_price_map.get(block_num, 0) - - current_block_details = block_details_dict.get(block_num, None) - timestamp = ( - current_block_details.get( - 'timestamp', - None, - ) - if current_block_details - else None - ) - - pair_reserves_arr[block_num] = { - 'token0': token0Amount, - 'token1': token1Amount, - 'token0USD': token0USD, - 'token1USD': token1USD, - 'token0Price': token0Price, - 'token1Price': token1Price, - 'timestamp': timestamp, - } - block_count += 1 - - core_logger.debug( - ( - 'Calculated pair total reserves for epoch-range:' - f' {from_block} - {to_block} | pair_contract: {pair_address}' - ), - ) - return pair_reserves_arr - - -def extract_trade_volume_log( - event_name, - log, - pair_per_token_metadata, - token0_price_map, - token1_price_map, - block_details_dict, -): - token0_amount = 0 - token1_amount = 0 - token0_amount_usd = 0 - token1_amount_usd = 0 - - def token_native_and_usd_amount(token, token_type, token_price_map): - if log.args.get(token_type) <= 0: - return 0, 0 - - token_amount = log.args.get(token_type) / 10 ** int( - pair_per_token_metadata[token]['decimals'], - ) - token_usd_amount = token_amount * token_price_map.get( - log.get('blockNumber'), 0, - ) - return token_amount, token_usd_amount - - if event_name == 'Swap': - amount0In, amount0In_usd = token_native_and_usd_amount( - token='token0', - token_type='amount0In', - token_price_map=token0_price_map, - ) - amount0Out, amount0Out_usd = token_native_and_usd_amount( - token='token0', - token_type='amount0Out', - token_price_map=token0_price_map, - ) - amount1In, amount1In_usd = token_native_and_usd_amount( - token='token1', - token_type='amount1In', - token_price_map=token1_price_map, - ) - amount1Out, amount1Out_usd = token_native_and_usd_amount( - token='token1', - token_type='amount1Out', - token_price_map=token1_price_map, - ) - - token0_amount = abs(amount0Out - amount0In) - token1_amount = abs(amount1Out - amount1In) - - token0_amount_usd = abs(amount0Out_usd - amount0In_usd) - token1_amount_usd = abs(amount1Out_usd - amount1In_usd) - - elif event_name == 'Mint' or event_name == 'Burn': - token0_amount, token0_amount_usd = token_native_and_usd_amount( - token='token0', - token_type='amount0', - token_price_map=token0_price_map, - ) - token1_amount, token1_amount_usd = token_native_and_usd_amount( - token='token1', - token_type='amount1', - token_price_map=token1_price_map, - ) - - trade_volume_usd = 0 - trade_fee_usd = 0 - - block_details = block_details_dict.get(int(log.get('blockNumber', 0)), {}) - log = json.loads(Web3.toJSON(log)) - log['token0_amount'] = token0_amount - log['token1_amount'] = token1_amount - log['timestamp'] = block_details.get('timestamp', '') - # pop unused log props - log.pop('blockHash', None) - log.pop('transactionIndex', None) - - # if event is 'Swap' then only add single token in total volume calculation - if event_name == 'Swap': - # set one side token value in swap case - if token1_amount_usd and token0_amount_usd: - trade_volume_usd = ( - token1_amount_usd - if token1_amount_usd > token0_amount_usd - else token0_amount_usd - ) - else: - trade_volume_usd = ( - token1_amount_usd if token1_amount_usd else token0_amount_usd - ) - - # calculate uniswap LP fee - trade_fee_usd = ( - token1_amount_usd * 0.003 - if token1_amount_usd - else token0_amount_usd * 0.003 - ) # uniswap LP fee rate - - # set final usd amount for swap - log['trade_amount_usd'] = trade_volume_usd - - return ( - trade_data( - totalTradesUSD=trade_volume_usd, - totalFeeUSD=trade_fee_usd, - token0TradeVolume=token0_amount, - token1TradeVolume=token1_amount, - token0TradeVolumeUSD=token0_amount_usd, - token1TradeVolumeUSD=token1_amount_usd, - ), - log, - ) - - trade_volume_usd = token0_amount_usd + token1_amount_usd - - # set final usd amount for other events - log['trade_amount_usd'] = trade_volume_usd - - return ( - trade_data( - totalTradesUSD=trade_volume_usd, - totalFeeUSD=0.0, - token0TradeVolume=token0_amount, - token1TradeVolume=token1_amount, - token0TradeVolumeUSD=token0_amount_usd, - token1TradeVolumeUSD=token1_amount_usd, - ), - log, - ) - - -# asynchronously get trades on a pair contract -async def get_pair_trade_volume( - data_source_contract_address, - min_chain_height, - max_chain_height, - redis_conn: aioredis.Redis, - rpc_helper: RpcHelper, - fetch_timestamp=True, -): - - data_source_contract_address = Web3.toChecksumAddress( - data_source_contract_address, - ) - block_details_dict = dict() - - if fetch_timestamp: - try: - block_details_dict = await get_block_details_in_block_range( - from_block=min_chain_height, - to_block=max_chain_height, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - except Exception as err: - core_logger.opt(exception=True).error( - ( - 'Error attempting to get block details of to_block {}:' - ' {}, retrying again' - ), - max_chain_height, - err, - ) - raise err - - pair_per_token_metadata = await get_pair_metadata( - pair_address=data_source_contract_address, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - token0_price_map, token1_price_map = await asyncio.gather( - get_token_price_in_block_range( - token_metadata=pair_per_token_metadata['token0'], - from_block=min_chain_height, - to_block=max_chain_height, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - debug_log=False, - ), - get_token_price_in_block_range( - token_metadata=pair_per_token_metadata['token1'], - from_block=min_chain_height, - to_block=max_chain_height, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - debug_log=False, - ), - ) - - # fetch logs for swap, mint & burn - event_sig, event_abi = get_event_sig_and_abi( - UNISWAP_TRADE_EVENT_SIGS, - UNISWAP_EVENTS_ABI, - ) - - events_log = await rpc_helper.get_events_logs( - **{ - 'contract_address': data_source_contract_address, - 'to_block': max_chain_height, - 'from_block': min_chain_height, - 'topics': [event_sig], - 'event_abi': event_abi, - 'redis_conn': redis_conn, - }, - ) - - # group logs by txHashs ==> {txHash: [logs], ...} - grouped_by_tx = dict() - [ - grouped_by_tx[log.transactionHash.hex()].append(log) - if log.transactionHash.hex() in grouped_by_tx - else grouped_by_tx.update({log.transactionHash.hex(): [log]}) - for log in events_log - ] - - # init data models with empty/0 values - epoch_results = epoch_event_trade_data( - Swap=event_trade_data( - logs=[], - trades=trade_data( - totalTradesUSD=float(), - totalFeeUSD=float(), - token0TradeVolume=float(), - token1TradeVolume=float(), - token0TradeVolumeUSD=float(), - token1TradeVolumeUSD=float(), - recent_transaction_logs=list(), - ), - ), - Mint=event_trade_data( - logs=[], - trades=trade_data( - totalTradesUSD=float(), - totalFeeUSD=float(), - token0TradeVolume=float(), - token1TradeVolume=float(), - token0TradeVolumeUSD=float(), - token1TradeVolumeUSD=float(), - recent_transaction_logs=list(), - ), - ), - Burn=event_trade_data( - logs=[], - trades=trade_data( - totalTradesUSD=float(), - totalFeeUSD=float(), - token0TradeVolume=float(), - token1TradeVolume=float(), - token0TradeVolumeUSD=float(), - token1TradeVolumeUSD=float(), - recent_transaction_logs=list(), - ), - ), - Trades=trade_data( - totalTradesUSD=float(), - totalFeeUSD=float(), - token0TradeVolume=float(), - token1TradeVolume=float(), - token0TradeVolumeUSD=float(), - token1TradeVolumeUSD=float(), - recent_transaction_logs=list(), - ), - ) - - # prepare final trade logs structure - for tx_hash, logs in grouped_by_tx.items(): - # init temporary trade object to track trades at txHash level - tx_hash_trades = trade_data( - totalTradesUSD=float(), - totalFeeUSD=float(), - token0TradeVolume=float(), - token1TradeVolume=float(), - token0TradeVolumeUSD=float(), - token1TradeVolumeUSD=float(), - recent_transaction_logs=list(), - ) - # shift Burn logs in end of list to check if equal size of mint already exist - # and then cancel out burn with mint - logs = sorted(logs, key=lambda x: x.event, reverse=True) - - # iterate over each txHash logs - for log in logs: - # fetch trade value fog log - trades_result, processed_log = extract_trade_volume_log( - event_name=log.event, - log=log, - pair_per_token_metadata=pair_per_token_metadata, - token0_price_map=token0_price_map, - token1_price_map=token1_price_map, - block_details_dict=block_details_dict, - ) - - if log.event == 'Swap': - epoch_results.Swap.logs.append(processed_log) - epoch_results.Swap.trades += trades_result - tx_hash_trades += ( - trades_result # swap in single txHash should be added - ) - - elif log.event == 'Mint': - epoch_results.Mint.logs.append(processed_log) - epoch_results.Mint.trades += trades_result - - elif log.event == 'Burn': - epoch_results.Burn.logs.append(processed_log) - epoch_results.Burn.trades += trades_result - - # At the end of txHash logs we must normalize trade values, so it don't affect result of other txHash logs - epoch_results.Trades += abs(tx_hash_trades) - epoch_trade_logs = epoch_results.dict() - max_block_details = block_details_dict.get(max_chain_height, {}) - max_block_timestamp = max_block_details.get('timestamp', None) - epoch_trade_logs.update({'timestamp': max_block_timestamp}) - return epoch_trade_logs diff --git a/snapshotter/modules/pooler/uniswapv2/utils/helpers.py b/snapshotter/modules/pooler/uniswapv2/utils/helpers.py deleted file mode 100644 index 5d6a9160..00000000 --- a/snapshotter/modules/pooler/uniswapv2/utils/helpers.py +++ /dev/null @@ -1,243 +0,0 @@ -import asyncio - -from redis import asyncio as aioredis -from web3 import Web3 -from snapshotter.settings.config import settings -from ..redis_keys import uniswap_pair_contract_tokens_addresses -from ..redis_keys import uniswap_pair_contract_tokens_data -from ..redis_keys import uniswap_tokens_pair_map -from ..settings.config import settings as worker_settings -from .constants import current_node -from .constants import erc20_abi -from .constants import pair_contract_abi -from snapshotter.utils.default_logger import logger -from snapshotter.utils.rpc import RpcHelper - - -helper_logger = logger.bind(module='PowerLoom|Uniswap|Helpers') - - -def get_maker_pair_data(prop): - prop = prop.lower() - if prop.lower() == 'name': - return 'Maker' - elif prop.lower() == 'symbol': - return 'MKR' - else: - return 'Maker' - - -async def get_pair( - factory_contract_obj, - token0, - token1, - redis_conn: aioredis.Redis, - rpc_helper: RpcHelper, -): - # check if pair cache exists - pair_address_cache = await redis_conn.hget( - uniswap_tokens_pair_map, - f'{Web3.toChecksumAddress(token0)}-{Web3.toChecksumAddress(token1)}', - ) - if pair_address_cache: - pair_address_cache = pair_address_cache.decode('utf-8') - return Web3.toChecksumAddress(pair_address_cache) - - tasks = [ - factory_contract_obj.functions.getPair( - Web3.toChecksumAddress(token0), - Web3.toChecksumAddress(token1), - ), - ] - - result = await rpc_helper.web3_call(tasks, redis_conn=redis_conn) - pair = result[0] - # cache the pair address - await redis_conn.hset( - name=uniswap_tokens_pair_map, - mapping={ - f'{Web3.toChecksumAddress(token0)}-{Web3.toChecksumAddress(token1)}': Web3.toChecksumAddress( - pair, - ), - }, - ) - - return pair - - -async def get_pair_metadata( - pair_address, - redis_conn: aioredis.Redis, - rpc_helper: RpcHelper, -): - """ - returns information on the tokens contained within a pair contract - name, symbol, decimals of token0 and token1 - also returns pair symbol by concatenating {token0Symbol}-{token1Symbol} - """ - try: - pair_address = Web3.toChecksumAddress(pair_address) - - # check if cache exist - ( - pair_token_addresses_cache, - pair_tokens_data_cache, - ) = await asyncio.gather( - redis_conn.hgetall( - uniswap_pair_contract_tokens_addresses.format(pair_address), - ), - redis_conn.hgetall( - uniswap_pair_contract_tokens_data.format(pair_address), - ), - ) - - # parse addresses cache or call eth rpc - token0Addr = None - token1Addr = None - if pair_token_addresses_cache: - token0Addr = Web3.toChecksumAddress( - pair_token_addresses_cache[b'token0Addr'].decode('utf-8'), - ) - token1Addr = Web3.toChecksumAddress( - pair_token_addresses_cache[b'token1Addr'].decode('utf-8'), - ) - else: - pair_contract_obj = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress(pair_address), - abi=pair_contract_abi, - ) - token0Addr, token1Addr = await rpc_helper.web3_call( - [ - pair_contract_obj.functions.token0(), - pair_contract_obj.functions.token1(), - ], - redis_conn=redis_conn, - ) - - await redis_conn.hset( - name=uniswap_pair_contract_tokens_addresses.format( - pair_address, - ), - mapping={ - 'token0Addr': token0Addr, - 'token1Addr': token1Addr, - }, - ) - - # token0 contract - token0 = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress(token0Addr), - abi=erc20_abi, - ) - # token1 contract - token1 = current_node['web3_client'].eth.contract( - address=Web3.toChecksumAddress(token1Addr), - abi=erc20_abi, - ) - - # parse token data cache or call eth rpc - if pair_tokens_data_cache: - token0_decimals = pair_tokens_data_cache[b'token0_decimals'].decode( - 'utf-8', - ) - token1_decimals = pair_tokens_data_cache[b'token1_decimals'].decode( - 'utf-8', - ) - token0_symbol = pair_tokens_data_cache[b'token0_symbol'].decode( - 'utf-8', - ) - token1_symbol = pair_tokens_data_cache[b'token1_symbol'].decode( - 'utf-8', - ) - token0_name = pair_tokens_data_cache[b'token0_name'].decode('utf-8') - token1_name = pair_tokens_data_cache[b'token1_name'].decode('utf-8') - else: - tasks = list() - - # special case to handle maker token - maker_token0 = None - maker_token1 = None - if Web3.toChecksumAddress( - worker_settings.contract_addresses.MAKER, - ) == Web3.toChecksumAddress(token0Addr): - token0_name = get_maker_pair_data('name') - token0_symbol = get_maker_pair_data('symbol') - maker_token0 = True - else: - tasks.append(token0.functions.name()) - tasks.append(token0.functions.symbol()) - tasks.append(token0.functions.decimals()) - - if Web3.toChecksumAddress( - worker_settings.contract_addresses.MAKER, - ) == Web3.toChecksumAddress(token1Addr): - token1_name = get_maker_pair_data('name') - token1_symbol = get_maker_pair_data('symbol') - maker_token1 = True - else: - tasks.append(token1.functions.name()) - tasks.append(token1.functions.symbol()) - tasks.append(token1.functions.decimals()) - - if maker_token1: - [ - token0_name, - token0_symbol, - token0_decimals, - token1_decimals, - ] = await rpc_helper.web3_call(tasks, redis_conn=redis_conn) - elif maker_token0: - [ - token0_decimals, - token1_name, - token1_symbol, - token1_decimals, - ] = await rpc_helper.web3_call(tasks, redis_conn=redis_conn) - else: - [ - token0_name, - token0_symbol, - token0_decimals, - token1_name, - token1_symbol, - token1_decimals, - ] = await rpc_helper.web3_call(tasks, redis_conn=redis_conn) - - await redis_conn.hset( - name=uniswap_pair_contract_tokens_data.format(pair_address), - mapping={ - 'token0_name': token0_name, - 'token0_symbol': token0_symbol, - 'token0_decimals': token0_decimals, - 'token1_name': token1_name, - 'token1_symbol': token1_symbol, - 'token1_decimals': token1_decimals, - 'pair_symbol': f'{token0_symbol}-{token1_symbol}', - }, - ) - - return { - 'token0': { - 'address': token0Addr, - 'name': token0_name, - 'symbol': token0_symbol, - 'decimals': token0_decimals, - }, - 'token1': { - 'address': token1Addr, - 'name': token1_name, - 'symbol': token1_symbol, - 'decimals': token1_decimals, - }, - 'pair': { - 'symbol': f'{token0_symbol}-{token1_symbol}', - }, - } - except Exception as err: - # this will be retried in next cycle - helper_logger.opt(exception=settings.logs.trace_enabled).error( - ( - f'RPC error while fetcing metadata for pair {pair_address},' - f' error_msg:{err}' - ), - ) - raise err diff --git a/snapshotter/modules/pooler/uniswapv2/utils/models/data_models.py b/snapshotter/modules/pooler/uniswapv2/utils/models/data_models.py deleted file mode 100644 index 1b8ee2c6..00000000 --- a/snapshotter/modules/pooler/uniswapv2/utils/models/data_models.py +++ /dev/null @@ -1,52 +0,0 @@ -from typing import Dict -from typing import List - -from pydantic import BaseModel - - -class trade_data(BaseModel): - totalTradesUSD: float - totalFeeUSD: float - token0TradeVolume: float - token1TradeVolume: float - token0TradeVolumeUSD: float - token1TradeVolumeUSD: float - - def __add__(self, other: 'trade_data') -> 'trade_data': - self.totalTradesUSD += other.totalTradesUSD - self.totalFeeUSD += other.totalFeeUSD - self.token0TradeVolume += other.token0TradeVolume - self.token1TradeVolume += other.token1TradeVolume - self.token0TradeVolumeUSD += other.token0TradeVolumeUSD - self.token1TradeVolumeUSD += other.token1TradeVolumeUSD - return self - - def __sub__(self, other: 'trade_data') -> 'trade_data': - self.totalTradesUSD -= other.totalTradesUSD - self.totalFeeUSD -= other.totalFeeUSD - self.token0TradeVolume -= other.token0TradeVolume - self.token1TradeVolume -= other.token1TradeVolume - self.token0TradeVolumeUSD -= other.token0TradeVolumeUSD - self.token1TradeVolumeUSD -= other.token1TradeVolumeUSD - return self - - def __abs__(self) -> 'trade_data': - self.totalTradesUSD = abs(self.totalTradesUSD) - self.totalFeeUSD = abs(self.totalFeeUSD) - self.token0TradeVolume = abs(self.token0TradeVolume) - self.token1TradeVolume = abs(self.token1TradeVolume) - self.token0TradeVolumeUSD = abs(self.token0TradeVolumeUSD) - self.token1TradeVolumeUSD = abs(self.token1TradeVolumeUSD) - return self - - -class event_trade_data(BaseModel): - logs: List[Dict] - trades: trade_data - - -class epoch_event_trade_data(BaseModel): - Swap: event_trade_data - Mint: event_trade_data - Burn: event_trade_data - Trades: trade_data diff --git a/snapshotter/modules/pooler/uniswapv2/utils/models/message_models.py b/snapshotter/modules/pooler/uniswapv2/utils/models/message_models.py deleted file mode 100644 index 947d35ec..00000000 --- a/snapshotter/modules/pooler/uniswapv2/utils/models/message_models.py +++ /dev/null @@ -1,115 +0,0 @@ -from typing import Dict -from typing import List - -from pydantic import BaseModel - -from snapshotter.utils.models.message_models import AggregateBase - - -class EpochBaseSnapshot(BaseModel): - begin: int - end: int - - -class SnapshotBase(BaseModel): - contract: str - chainHeightRange: EpochBaseSnapshot - timestamp: int - - -class UniswapPairTotalReservesSnapshot(SnapshotBase): - token0Reserves: Dict[ - str, - float, - ] # block number to corresponding total reserves - token1Reserves: Dict[ - str, - float, - ] # block number to corresponding total reserves - token0ReservesUSD: Dict[str, float] - token1ReservesUSD: Dict[str, float] - token0Prices: Dict[str, float] - token1Prices: Dict[str, float] - - -class logsTradeModel(BaseModel): - logs: List - trades: Dict[str, float] - - -class UniswapTradeEvents(BaseModel): - Swap: logsTradeModel - Mint: logsTradeModel - Burn: logsTradeModel - Trades: Dict[str, float] - - -class UniswapTradesSnapshot(SnapshotBase): - totalTrade: float # in USD - totalFee: float # in USD - token0TradeVolume: float # in token native decimals supply - token1TradeVolume: float # in token native decimals supply - token0TradeVolumeUSD: float - token1TradeVolumeUSD: float - events: UniswapTradeEvents - - -class UniswapTradesAggregateSnapshot(AggregateBase): - totalTrade: float = 0 # in USD - totalFee: float = 0 # in USD - token0TradeVolume: float = 0 # in token native decimals supply - token1TradeVolume: float = 0 # in token native decimals supply - token0TradeVolumeUSD: float = 0 - token1TradeVolumeUSD: float = 0 - complete: bool = True - - -class UniswapTopTokenSnapshot(BaseModel): - name: str - symbol: str - decimals: int - address: str - price: float - priceChange24h: float - volume24h: float - liquidity: float - - -class UniswapTopTokensSnapshot(AggregateBase): - tokens: List[UniswapTopTokenSnapshot] = [] - complete: bool = True - - -class UniswapTopPair24hSnapshot(BaseModel): - name: str - address: str - liquidity: float - volume24h: float - fee24h: float - - -class UniswapTopPairs24hSnapshot(AggregateBase): - pairs: List[UniswapTopPair24hSnapshot] = [] - complete: bool = True - - -class UniswapTopPair7dSnapshot(BaseModel): - name: str - address: str - volume7d: float - fee7d: float - - -class UniswapTopPairs7dSnapshot(AggregateBase): - pairs: List[UniswapTopPair7dSnapshot] = [] - complete: bool = True - - -class UniswapStatsSnapshot(AggregateBase): - volume24h: float = 0 - tvl: float = 0 - fee24h: float = 0 - volumeChange24h: float = 0 - tvlChange24h: float = 0 - feeChange24h: float = 0 - complete: bool = True diff --git a/snapshotter/modules/pooler/uniswapv2/utils/pricing.py b/snapshotter/modules/pooler/uniswapv2/utils/pricing.py deleted file mode 100644 index 1171237c..00000000 --- a/snapshotter/modules/pooler/uniswapv2/utils/pricing.py +++ /dev/null @@ -1,367 +0,0 @@ -import asyncio -import json - -from redis import asyncio as aioredis -from web3 import Web3 - -from snapshotter.settings.config import settings - -from ..redis_keys import ( - uniswap_pair_cached_block_height_token_price, -) -from ..redis_keys import ( - uniswap_token_derived_eth_cached_block_height, -) -from ..settings.config import settings as worker_settings -from .constants import factory_contract_obj -from .constants import pair_contract_abi -from .constants import router_contract_abi -from .constants import tokens_decimals -from .helpers import get_pair -from .helpers import get_pair_metadata -from snapshotter.utils.default_logger import logger -from snapshotter.utils.redis.redis_keys import source_chain_epoch_size_key -from snapshotter.utils.rpc import get_contract_abi_dict -from snapshotter.utils.rpc import RpcHelper -from snapshotter.utils.snapshot_utils import get_eth_price_usd - -pricing_logger = logger.bind(module='PowerLoom|Uniswap|Pricing') - - -async def get_token_pair_price_and_white_token_reserves( - pair_address, - from_block, - to_block, - pair_metadata, - white_token, - redis_conn, - rpc_helper: RpcHelper, -): - """ - Function to get: - 1. token price based on pair reserves of both token: token0Price = token1Price/token0Price - 2. whitelisted token reserves - - We can write different function for each value, but to optimize we are reusing reserves value - """ - token_price_dict = dict() - white_token_reserves_dict = dict() - - # get white - pair_abi_dict = get_contract_abi_dict(pair_contract_abi) - pair_reserves_list = await rpc_helper.batch_eth_call_on_block_range( - abi_dict=pair_abi_dict, - function_name='getReserves', - contract_address=pair_address, - from_block=from_block, - to_block=to_block, - redis_conn=redis_conn, - ) - - if len(pair_reserves_list) < to_block - (from_block - 1): - pricing_logger.trace( - ( - 'Unable to get pair price and white token reserves' - 'from_block: {}, to_block: {}, pair_reserves_list: {}' - ), - from_block, - to_block, - pair_reserves_list, - ) - - raise Exception( - 'Unable to get pair price and white token reserves' - f'from_block: {from_block}, to_block: {to_block}, ' - f'got result: {pair_reserves_list}', - ) - - index = 0 - for block_num in range(from_block, to_block + 1): - token_price = 0 - - pair_reserve_token0 = pair_reserves_list[index][0] / 10 ** int( - pair_metadata['token0']['decimals'], - ) - pair_reserve_token1 = pair_reserves_list[index][1] / 10 ** int( - pair_metadata['token1']['decimals'], - ) - - if float(pair_reserve_token0) == float(0) or float( - pair_reserve_token1, - ) == float(0): - token_price_dict[block_num] = token_price - white_token_reserves_dict[block_num] = 0 - elif ( - Web3.toChecksumAddress(pair_metadata['token0']['address']) == - white_token - ): - token_price_dict[block_num] = float( - pair_reserve_token0 / pair_reserve_token1, - ) - white_token_reserves_dict[block_num] = pair_reserve_token0 - else: - token_price_dict[block_num] = float( - pair_reserve_token1 / pair_reserve_token0, - ) - white_token_reserves_dict[block_num] = pair_reserve_token1 - - index += 1 - - return token_price_dict, white_token_reserves_dict - - -async def get_token_derived_eth( - from_block, - to_block, - token_metadata, - redis_conn, - rpc_helper: RpcHelper, -): - token_derived_eth_dict = dict() - token_address = Web3.toChecksumAddress( - token_metadata['address'], - ) - if token_address == Web3.toChecksumAddress(worker_settings.contract_addresses.WETH): - # set derived eth as 1 if token is weth - for block_num in range(from_block, to_block + 1): - token_derived_eth_dict[block_num] = 1 - - return token_derived_eth_dict - - cached_derived_eth_dict = await redis_conn.zrangebyscore( - name=uniswap_token_derived_eth_cached_block_height.format( - token_address, - ), - min=int(from_block), - max=int(to_block), - ) - if cached_derived_eth_dict and len(cached_derived_eth_dict) == to_block - ( - from_block - 1 - ): - token_derived_eth_dict = { - json.loads( - price.decode( - 'utf-8', - ), - )[ - 'blockHeight' - ]: json.loads(price.decode('utf-8'))['price'] - for price in cached_derived_eth_dict - } - return token_derived_eth_dict - # get white - router_abi_dict = get_contract_abi_dict(router_contract_abi) - token_derived_eth_list = await rpc_helper.batch_eth_call_on_block_range( - abi_dict=router_abi_dict, - function_name='getAmountsOut', - contract_address=worker_settings.contract_addresses.iuniswap_v2_router, - from_block=from_block, - to_block=to_block, - redis_conn=redis_conn, - params=[ - 10 ** int(token_metadata['decimals']), - [ - Web3.toChecksumAddress(token_metadata['address']), - Web3.toChecksumAddress(worker_settings.contract_addresses.WETH), - ], - ], - ) - - if len(token_derived_eth_list) < to_block - (from_block - 1): - pricing_logger.trace( - ( - 'Unable to get token derived eth' - 'from_block: {}, to_block: {}, token_derived_eth_list: {}' - ), - from_block, - to_block, - token_derived_eth_list, - ) - - raise Exception( - 'Unable to get token derived eth' - f'from_block: {from_block}, to_block: {to_block}, ' - f'got result: {token_derived_eth_list}', - ) - - index = 0 - for block_num in range(from_block, to_block + 1): - if not token_derived_eth_list[index]: - token_derived_eth_dict[block_num] = 0 - - _, derivedEth = token_derived_eth_list[index][0] - token_derived_eth_dict[block_num] = ( - derivedEth / 10 ** tokens_decimals['WETH'] if derivedEth != 0 else 0 - ) - index += 1 - - if ( - len(token_derived_eth_dict) > 0 - ): - redis_cache_mapping = { - json.dumps({'blockHeight': height, 'price': price}): int( - height, - ) - for height, price in token_derived_eth_dict.items() - } - source_chain_epoch_size = int(await redis_conn.get(source_chain_epoch_size_key())) - await asyncio.gather( - redis_conn.zadd( - name=uniswap_token_derived_eth_cached_block_height.format( - token_address, - ), - # timestamp so zset do not ignore same height on multiple heights - mapping=redis_cache_mapping, - ), - - redis_conn.zremrangebyscore( - name=uniswap_token_derived_eth_cached_block_height.format( - token_address, - ), - min=0, - max=int(from_block) - source_chain_epoch_size * 4, - ), - ) - - return token_derived_eth_dict - - -async def get_token_price_in_block_range( - token_metadata, - from_block, - to_block, - redis_conn: aioredis.Redis, - rpc_helper: RpcHelper, - debug_log=True, -): - """ - returns the price of a token at a given block range - """ - try: - token_price_dict = dict() - token_address = Web3.toChecksumAddress(token_metadata['address']) - # check if cahce exist for given epoch - cached_price_dict = await redis_conn.zrangebyscore( - name=uniswap_pair_cached_block_height_token_price.format( - token_address, - ), - min=int(from_block), - max=int(to_block), - ) - if cached_price_dict and len(cached_price_dict) == to_block - (from_block - 1): - price_dict = { - json.loads( - price.decode( - 'utf-8', - ), - )['blockHeight']: json.loads(price.decode('utf-8'))['price'] for price in cached_price_dict - } - return price_dict - - if token_address == Web3.toChecksumAddress(worker_settings.contract_addresses.WETH): - token_price_dict = await get_eth_price_usd( - from_block=from_block, to_block=to_block, - redis_conn=redis_conn, rpc_helper=rpc_helper, - ) - else: - token_eth_price_dict = dict() - - for white_token in worker_settings.uniswap_v2_whitelist: - white_token = Web3.toChecksumAddress(white_token) - pairAddress = await get_pair( - factory_contract_obj, white_token, token_metadata['address'], - redis_conn, rpc_helper, - ) - if pairAddress != '0x0000000000000000000000000000000000000000': - new_pair_metadata = await get_pair_metadata( - pair_address=pairAddress, - redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - white_token_metadata = new_pair_metadata['token0'] if white_token == new_pair_metadata[ - 'token0' - ]['address'] else new_pair_metadata['token1'] - - ( - white_token_price_dict, - white_token_reserves_dict, - ) = await get_token_pair_price_and_white_token_reserves( - pair_address=pairAddress, from_block=from_block, to_block=to_block, - pair_metadata=new_pair_metadata, white_token=white_token, redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - white_token_derived_eth_dict = await get_token_derived_eth( - from_block=from_block, to_block=to_block, token_metadata=white_token_metadata, - redis_conn=redis_conn, rpc_helper=rpc_helper, - ) - - less_than_minimum_liquidity = False - for block_num in range(from_block, to_block + 1): - - white_token_reserves = white_token_reserves_dict.get( - block_num, - ) * white_token_derived_eth_dict.get(block_num) - - # ignore if reservers are less than threshold - if white_token_reserves < 1: - less_than_minimum_liquidity = True - break - - # else store eth price in dictionary - token_eth_price_dict[block_num] = white_token_price_dict.get( - block_num, - ) * white_token_derived_eth_dict.get(block_num) - - # if reserves are less than threshold then try next whitelist token pair - if less_than_minimum_liquidity: - token_eth_price_dict = {} - continue - - break - - if len(token_eth_price_dict) > 0: - eth_usd_price_dict = await get_eth_price_usd( - from_block=from_block, to_block=to_block, redis_conn=redis_conn, - rpc_helper=rpc_helper, - ) - for block_num in range(from_block, to_block + 1): - token_price_dict[block_num] = token_eth_price_dict.get( - block_num, 0, - ) * eth_usd_price_dict.get(block_num, 0) - else: - for block_num in range(from_block, to_block + 1): - token_price_dict[block_num] = 0 - - if debug_log: - pricing_logger.debug( - f"{token_metadata['symbol']}: price is {token_price_dict}" - f' | its eth price is {token_eth_price_dict}', - ) - - # cache price at height - if len(token_price_dict) > 0: - redis_cache_mapping = { - json.dumps({'blockHeight': height, 'price': price}): int( - height, - ) for height, price in token_price_dict.items() - } - - await redis_conn.zadd( - name=uniswap_pair_cached_block_height_token_price.format( - Web3.toChecksumAddress(token_metadata['address']), - ), - mapping=redis_cache_mapping, # timestamp so zset do not ignore same height on multiple heights - ) - - return token_price_dict - - except Exception as err: - pricing_logger.opt(exception=settings.logs.trace_enabled, lazy=True).trace( - ( - 'Error while calculating price of token:' - f" {token_metadata['symbol']} | {token_metadata['address']}|" - ' err: {err}' - ), - err=lambda: str(err), - ) - raise err