diff --git a/config/indexer-config.yaml b/config/indexer-config.yaml index a829315a5..fa0ba309f 100644 --- a/config/indexer-config.yaml +++ b/config/indexer-config.yaml @@ -31,10 +31,56 @@ opensea_job: - "0x5b3256965e7c3cf26e11fcaf296dfc8807c01073" export_tokens_and_transfers_job: - weth_address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" + weth_address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" -eigen_layer_job: +export_eigen_layer_job: STRATEGY_MANAGER: address: "0x858646372cc42e1a627fce94aa7a7033e7cf075a" DELEGATION: address: "0x39053d51b77dc0d36036fc1fcc8cb819df8ef37a" + +deposit_to_l2_job: + contract_info: + 10: + - contract: "0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1" + ABIFunction: + - token: "eth" + abi: "op_deposit_eth" + - token: "eth" + abi: "op_bridge_eth_to" + - token: "_l1Token" + abi: "op_deposit_erc20_to" + ABIEvent: + - abi: "op_transaction_deposited" + 8453: + - contract: "0x3154Cf16ccdb4C6d922629664174b904d80F2C35" + ABIFunction: + - token: "eth" + abi: "op_deposit_eth" + - token: "eth" + abi: "op_bridge_eth_to" + 42161: + - contract: "0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef" + ABIFunction: + - token: "_l1Token" + abi: "arbitrum_outbound_transfer" + - contract: "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f" + ABIFunction: + - token: "eth" + method_id: "0x439370b1" + 59144: + - contract: "0xd19d4B5d358258f05D7B411E21A1460D11B0876F" + ABIFunction: + - token: "eth" + abi: "linea_send_message" + - contract: "0x051F1D88f0aF5763fB888eC4378b4D8B29ea3319" + ABIFunction: + - token: "_l1Token" + abi: "linea_bridge_token" + - contract: "0x504A330327A089d8364C4ab3811Ee26976d388ce" + ABIFunction: + - token: "usdc" + abi: "linea_deposit_to" + cache_config: + clean_mode: blocks + clean_limit_value: 1000 diff --git a/enumeration/entity_type.py b/enumeration/entity_type.py index d06a3b4f2..f9dfcedfc 100644 --- a/enumeration/entity_type.py +++ b/enumeration/entity_type.py @@ -19,8 +19,8 @@ from indexer.modules.custom.address_index.domain.address_nft_1155_holders import AddressNft1155Holder from indexer.modules.custom.all_features_value_record import AllFeatureValueRecordBlueChipHolders from indexer.modules.custom.blue_chip.domain.feature_blue_chip import BlueChipHolder -from indexer.modules.custom.deposit_to_l2.domain.address_token_deposit import AddressTokenDeposit -from indexer.modules.custom.deposit_to_l2.domain.token_deposit_transaction import TokenDepositTransaction +from indexer.modules.custom.deposit_to_l2.domains.address_token_deposit import AddressTokenDeposit +from indexer.modules.custom.deposit_to_l2.domains.token_deposit_transaction import TokenDepositTransaction from indexer.modules.custom.eigen_layer.domains.eigen_layer_domain import EigenLayerAction, EigenLayerAddressCurrent from indexer.modules.custom.hemera_ens.ens_domain import ( ENSAddressChangeD, diff --git a/indexer/modules/custom/deposit_to_l2/domain/__init__.py b/indexer/modules/custom/deposit_to_l2/abi/__init__.py similarity index 100% rename from indexer/modules/custom/deposit_to_l2/domain/__init__.py rename to indexer/modules/custom/deposit_to_l2/abi/__init__.py diff --git a/indexer/modules/custom/deposit_to_l2/abi/event.py b/indexer/modules/custom/deposit_to_l2/abi/event.py new file mode 100644 index 000000000..0b7918da4 --- /dev/null +++ b/indexer/modules/custom/deposit_to_l2/abi/event.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Time : 2024/10/21 下午5:50 +Author : xuzh +Project : hemera_indexer +""" +from common.utils.abi_code_utils import Event + +OP_PROTOCOL_TRANSACTION_DEPOSITED_EVENT = Event( + { + "anonymous": False, + "inputs": [ + {"indexed": True, "internalType": "address", "name": "from", "type": "address"}, + {"indexed": True, "internalType": "address", "name": "to", "type": "address"}, + {"indexed": True, "internalType": "uint256", "name": "version", "type": "uint256"}, + {"indexed": False, "internalType": "bytes", "name": "opaqueData", "type": "bytes"}, + ], + "name": "TransactionDeposited", + "type": "event", + } +) + +event_mapping = {"op_transaction_deposited": OP_PROTOCOL_TRANSACTION_DEPOSITED_EVENT} diff --git a/indexer/modules/custom/deposit_to_l2/abi/function.py b/indexer/modules/custom/deposit_to_l2/abi/function.py new file mode 100644 index 000000000..be272be88 --- /dev/null +++ b/indexer/modules/custom/deposit_to_l2/abi/function.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Time : 2024/10/21 下午5:50 +Author : xuzh +Project : hemera_indexer +""" +from common.utils.abi_code_utils import Function + +OP_PROTOCOL_DEPOSIT_ETH_FUNCTION = Function( + { + "inputs": [ + {"internalType": "uint32", "name": "_minGasLimit", "type": "uint32"}, + {"internalType": "bytes", "name": "_extraData", "type": "bytes"}, + ], + "name": "depositETH", + "outputs": [], + "stateMutability": "payable", + "type": "function", + } +) + +OP_PROTOCOL_BRIDGE_ETH_TO_FUNCTION = Function( + { + "inputs": [ + {"internalType": "address", "name": "_to", "type": "address"}, + {"internalType": "uint32", "name": "_minGasLimit", "type": "uint32"}, + {"internalType": "bytes", "name": "_extraData", "type": "bytes"}, + ], + "name": "bridgeETHTo", + "outputs": [], + "stateMutability": "payable", + "type": "function", + } +) + +OP_PROTOCOL_DEPOSIT_ERC20_TO_FUNCTION = Function( + { + "inputs": [ + {"internalType": "address", "name": "_l1Token", "type": "address"}, + {"internalType": "address", "name": "_l2Token", "type": "address"}, + {"internalType": "address", "name": "_to", "type": "address"}, + {"internalType": "uint256", "name": "_amount", "type": "uint256"}, + {"internalType": "uint32", "name": "_minGasLimit", "type": "uint32"}, + {"internalType": "bytes", "name": "_extraData", "type": "bytes"}, + ], + "name": "depositERC20To", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + } +) + +ARBITRUM_OUTBOUND_TRANSFER_FUNCTION = Function( + { + "inputs": [ + {"name": "_l1Token", "type": "address", "internalType": "address"}, + {"name": "_to", "type": "address", "internalType": "address"}, + {"name": "_amount", "type": "uint256", "internalType": "uint256"}, + {"name": "_maxGas", "type": "uint256", "internalType": "uint256"}, + {"name": "_gasPriceBid", "type": "uint256", "internalType": "uint256"}, + {"name": "_data", "type": "bytes", "internalType": "bytes"}, + ], + "name": "outboundTransfer", + "outputs": [], + "payable": False, + "stateMutability": "nonpayable", + "type": "function", + } +) + +LINEA_PROTOCOL_SEND_MESSAGE_FUNCTION = Function( + { + "inputs": [ + {"internalType": "address", "name": "_to", "type": "address"}, + {"internalType": "uint256", "name": "_fee", "type": "uint256"}, + {"internalType": "bytes", "name": "_calldata", "type": "bytes"}, + ], + "name": "sendMessage", + "outputs": [], + "stateMutability": "payable", + "type": "function", + } +) + +LINEA_PROTOCOL_BRIDGE_TOKEN_FUNCTION = Function( + { + "inputs": [ + {"internalType": "address", "name": "_l1Token", "type": "address"}, + {"internalType": "uint256", "name": "_amount", "type": "uint256"}, + {"internalType": "address", "name": "_recipient", "type": "address"}, + ], + "name": "bridgeToken", + "outputs": [], + "stateMutability": "payable", + "type": "function", + } +) + +LINEA_PROTOCOL_DEPOSIT_FUNCTION = Function( + { + "inputs": [ + {"internalType": "uint256", "name": "_amount", "type": "uint256"}, + {"internalType": "address", "name": "_to", "type": "address"}, + ], + "name": "depositTo", + "outputs": [], + "stateMutability": "payable", + "type": "function", + } +) + +function_mapping = { + "op_deposit_eth": OP_PROTOCOL_DEPOSIT_ETH_FUNCTION, + "op_bridge_eth_to": OP_PROTOCOL_BRIDGE_ETH_TO_FUNCTION, + "op_deposit_erc20_to": OP_PROTOCOL_DEPOSIT_ERC20_TO_FUNCTION, + "arbitrum_outbound_transfer": ARBITRUM_OUTBOUND_TRANSFER_FUNCTION, + "linea_send_message": LINEA_PROTOCOL_SEND_MESSAGE_FUNCTION, + "linea_bridge_token": LINEA_PROTOCOL_BRIDGE_TOKEN_FUNCTION, + "linea_deposit_to": LINEA_PROTOCOL_DEPOSIT_FUNCTION, +} diff --git a/indexer/modules/custom/deposit_to_l2/deposit_parser.py b/indexer/modules/custom/deposit_to_l2/deposit_parser.py index 94ac16cc1..24610a32d 100644 --- a/indexer/modules/custom/deposit_to_l2/deposit_parser.py +++ b/indexer/modules/custom/deposit_to_l2/deposit_parser.py @@ -1,109 +1,14 @@ -import json -from typing import List, cast - -from eth_typing import HexStr -from web3._utils.contracts import decode_transaction_data -from web3.types import ABIEvent, ABIFunction +from typing import List +from common.utils.abi_code_utils import Function from indexer.domain.transaction import Transaction -from indexer.modules.custom.deposit_to_l2.domain.token_deposit_transaction import TokenDepositTransaction -from indexer.utils.abi import event_log_abi_to_topic, function_abi_to_4byte_selector_str +from indexer.modules.custom.deposit_to_l2.domains.token_deposit_transaction import TokenDepositTransaction ETH_ADDRESS = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" USDC_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" -ETH_DEPOSIT_INITIATED_EVENT = cast( - ABIEvent, - json.loads( - """{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"extraData","type":"bytes"}],"name":"ETHDepositInitiated","type":"event"}""" - ), -) -ETH_DEPOSIT_INITIATED_EVENT_SIG = event_log_abi_to_topic(ETH_DEPOSIT_INITIATED_EVENT) - -ETH_BRIDGE_INITIATED_EVENT = cast( - ABIEvent, - json.loads( - """{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"extraData","type":"bytes"}],"name":"ETHBridgeInitiated","type":"event"}""" - ), -) -ETH_BRIDGE_INITIATED_EVENT_SIG = event_log_abi_to_topic(ETH_BRIDGE_INITIATED_EVENT) - -TRANSACTION_DEPOSITED_EVENT = cast( - ABIEvent, - json.loads( - """{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"version","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"opaqueData","type":"bytes"}],"name":"TransactionDeposited","type":"event"}""" - ), -) -TRANSACTION_DEPOSITED_EVENT_SIG = event_log_abi_to_topic(TRANSACTION_DEPOSITED_EVENT) - -DEPOSIT_ETH_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"internalType":"uint32","name":"_minGasLimit","type":"uint32"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"depositETH","outputs":[],"stateMutability":"payable","type":"function"}""" - ), -) -DEPOSIT_ETH_FUNCTION_SIG = function_abi_to_4byte_selector_str(DEPOSIT_ETH_FUNCTION) - -BRIDGE_ETH_TO_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint32","name":"_minGasLimit","type":"uint32"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"bridgeETHTo","outputs":[],"stateMutability":"payable","type":"function"}""" - ), -) -BRIDGE_ETH_TO_FUNCTION_SIG = function_abi_to_4byte_selector_str(BRIDGE_ETH_TO_FUNCTION) - -DEPOSIT_ERC20_TO_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"internalType":"address","name":"_l1Token","type":"address"},{"internalType":"address","name":"_l2Token","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint32","name":"_minGasLimit","type":"uint32"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"depositERC20To","outputs":[],"stateMutability":"nonpayable","type":"function"}""" - ), -) -DEPOSIT_ERC20_TO_FUNCTION_SIG = function_abi_to_4byte_selector_str(DEPOSIT_ERC20_TO_FUNCTION) - -DEPOSIT_TRANSACTION_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint64","name":"_gasLimit","type":"uint64"},{"internalType":"bool","name":"_isCreation","type":"bool"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"depositTransaction","outputs":[],"stateMutability":"payable","type":"function"}""" - ), -) -DEPOSIT_TRANSACTION_FUNCTION_SIG = function_abi_to_4byte_selector_str(DEPOSIT_TRANSACTION_FUNCTION) - -DEPOSIT_ETH_TO_ARBI_FUNCTION_SIG = "0x439370b1" - -OUT_BOUND_TRANSFER_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"name":"_l1Token","type":"address","internalType":"address"},{"name":"_to","type":"address","internalType":"address"},{"name":"_amount","type":"uint256","internalType":"uint256"},{"name":"_maxGas","type":"uint256","internalType":"uint256"},{"name":"_gasPriceBid","type":"uint256","internalType":"uint256"},{"name":"_data","type":"bytes","internalType":"bytes"}],"name":"outboundTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}""" - ), -) -OUT_BOUND_TRANSFER_FUNCTION_SIG = function_abi_to_4byte_selector_str(OUT_BOUND_TRANSFER_FUNCTION) - -DEPOSIT_ETH_TO_LINEA_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_fee","type":"uint256"},{"internalType":"bytes","name":"_calldata","type":"bytes"}],"name":"sendMessage","outputs":[],"stateMutability":"payable","type":"function"}""" - ), -) -DEPOSIT_ETH_TO_LINEA_FUNCTION_SIG = function_abi_to_4byte_selector_str(DEPOSIT_ETH_TO_LINEA_FUNCTION) - -BRIDGE_TOKEN_TO_LINEA_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"internalType":"address","name":"_l1Token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"bridgeToken","outputs":[],"stateMutability":"payable","type":"function"}""" - ), -) -BRIDGE_TOKEN_TO_LINEA_FUNCTION_SIG = function_abi_to_4byte_selector_str(BRIDGE_TOKEN_TO_LINEA_FUNCTION) - -DEPOSIT_USDC_TO_LINEA_FUNCTION = cast( - ABIFunction, - json.loads( - """{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"depositTo","outputs":[],"stateMutability":"payable","type":"function"}""" - ), -) -DEPOSIT_USDC_TO_LINEA_FUNCTION_SIG = function_abi_to_4byte_selector_str(DEPOSIT_USDC_TO_LINEA_FUNCTION) - -def eth_deposit_parse(transaction: Transaction, chain_mapping: dict, function: ABIFunction) -> TokenDepositTransaction: +def eth_deposit_parse(transaction: Transaction, chain_mapping: dict, function: Function) -> TokenDepositTransaction: return TokenDepositTransaction( transaction_hash=transaction.hash, wallet_address=transaction.from_address, @@ -116,8 +21,8 @@ def eth_deposit_parse(transaction: Transaction, chain_mapping: dict, function: A ) -def usdc_deposit_parse(transaction: Transaction, chain_mapping: dict, function: ABIFunction) -> TokenDepositTransaction: - decoded_input = decode_transaction_data(function, HexStr(transaction.input)) +def usdc_deposit_parse(transaction: Transaction, chain_mapping: dict, function: Function) -> TokenDepositTransaction: + decoded_input = function.decode_function_input_data(transaction.input) return TokenDepositTransaction( transaction_hash=transaction.hash, wallet_address=transaction.from_address, @@ -130,10 +35,8 @@ def usdc_deposit_parse(transaction: Transaction, chain_mapping: dict, function: ) -def token_deposit_parse( - transaction: Transaction, chain_mapping: dict, function: ABIFunction -) -> TokenDepositTransaction: - decoded_input = decode_transaction_data(function, HexStr(transaction.input)) +def token_deposit_parse(transaction: Transaction, chain_mapping: dict, function: Function) -> TokenDepositTransaction: + decoded_input = function.decode_function_input_data(transaction.input) return TokenDepositTransaction( transaction_hash=transaction.hash, wallet_address=transaction.from_address, @@ -175,9 +78,4 @@ def parse_deposit_transaction_function( if __name__ == "__main__": - print(BRIDGE_ETH_TO_FUNCTION_SIG) - print(DEPOSIT_ERC20_TO_FUNCTION_SIG) - print(DEPOSIT_ETH_FUNCTION_SIG) - print(DEPOSIT_ETH_TO_LINEA_FUNCTION_SIG) - print(BRIDGE_TOKEN_TO_LINEA_FUNCTION_SIG) - print(DEPOSIT_USDC_TO_LINEA_FUNCTION_SIG) + pass diff --git a/indexer/modules/custom/deposit_to_l2/deposit_to_l2_job.py b/indexer/modules/custom/deposit_to_l2/deposit_to_l2_job.py index 772a8c08f..daa1f8610 100644 --- a/indexer/modules/custom/deposit_to_l2/deposit_to_l2_job.py +++ b/indexer/modules/custom/deposit_to_l2/deposit_to_l2_job.py @@ -1,25 +1,27 @@ import configparser -import json -import os -from typing import List, cast +import logging +from typing import List, Union from eth_utils import to_normalized_address from sqlalchemy import and_ -from web3.types import ABIFunction from common.utils.cache_utils import BlockToLiveDict, TimeToLiveDict from common.utils.exception_control import FastShutdownError from common.utils.format_utils import bytes_to_hex_str, hex_str_to_bytes +from indexer.domain.block import Block from indexer.domain.transaction import Transaction from indexer.jobs import FilterTransactionDataJob +from indexer.jobs.base_job import Collector +from indexer.modules.custom.deposit_to_l2.abi.function import function_mapping from indexer.modules.custom.deposit_to_l2.deposit_parser import parse_deposit_transaction_function, token_parse_mapping -from indexer.modules.custom.deposit_to_l2.domain.address_token_deposit import AddressTokenDeposit -from indexer.modules.custom.deposit_to_l2.domain.token_deposit_transaction import TokenDepositTransaction +from indexer.modules.custom.deposit_to_l2.domains.address_token_deposit import AddressTokenDeposit +from indexer.modules.custom.deposit_to_l2.domains.token_deposit_transaction import TokenDepositTransaction from indexer.modules.custom.deposit_to_l2.models.af_token_deposits_current import AFTokenDepositsCurrent from indexer.specification.specification import ToAddressSpecification, TransactionFilterByTransactionInfo -from indexer.utils.abi import function_abi_to_4byte_selector_str from indexer.utils.collection_utils import distinct_collections_by_group +logger = logging.getLogger(__name__) + class DepositToL2Job(FilterTransactionDataJob): dependency_types = [Transaction] @@ -35,7 +37,7 @@ def __init__(self, **kwargs): self._sig_function_mapping = {} self._sig_parse_mapping = {} - self._load_config("config.ini") + self._load_config() if self._service is None: raise FastShutdownError("-pg or --postgres-url is required to run DepositToL2Job") @@ -51,18 +53,19 @@ def __init__(self, **kwargs): *[ToAddressSpecification(address=contract) for contract in self._contracts] ) - def _load_config(self, filename): - base_path = os.path.dirname(os.path.abspath(__file__)) - full_path = os.path.join(base_path, filename) - config = configparser.ConfigParser() - config.read(full_path) - + def _load_config(self): try: - self._deposit_contracts = json.loads(config.get("chain_deposit_info", "contract_info")) - self._clean_mode = config.get("cache_config", "clean_mode") - self._clean_limit_value = int(config.get("cache_config", "clean_limit_value")) - except (configparser.NoOptionError, configparser.NoSectionError) as e: - raise ValueError(f"Missing required configuration in {filename}: {str(e)}") + self._deposit_contracts = self.user_defined_config["contract_info"] + self._clean_mode = self.user_defined_config["cache_config"].get("clean_mode", "blocks") + self._clean_limit_value = int(self.user_defined_config["cache_config"].get("clean_limit_value", 1000)) + except Exception as e: + message = ( + "Missing required configuration in config file. " + "The possible reason are either that the configuration file is not specified by --config-file " + "or the configuration for deposit_to_l2_job is missing." + ) + logging.error(message) + raise FastShutdownError(message) for chain in self._deposit_contracts.keys(): for contract_info in self._deposit_contracts[chain]: @@ -71,9 +74,9 @@ def _load_config(self, filename): self._contract_chain_mapping[contract_address] = int(chain) for function in contract_info["ABIFunction"]: abi_function = None - if "json" in function: - abi_function = cast(ABIFunction, function["json"]) - sig = function_abi_to_4byte_selector_str(abi_function) + if "abi" in function: + abi_function = function_mapping[function["abi"]] + sig = abi_function.get_signature() else: sig = function["method_id"] @@ -83,33 +86,37 @@ def _load_config(self, filename): def get_filter(self): return self._filter - def _process(self, **kwargs): + def _udf(self, blocks: List[Block], output: Collector[Union[TokenDepositTransaction, AddressTokenDeposit]]): transactions = list( filter( self._filter.get_or_specification().is_satisfied_by, [ transaction - for transaction in self._data_buff[Transaction.type()] + for block in blocks + for transaction in block.transactions if transaction.receipt and transaction.receipt.status != 0 ], ) ) - deposit_tokens = parse_deposit_transaction_function( + + deposit_transactions = parse_deposit_transaction_function( transactions=transactions, contract_set=self._contracts, chain_mapping=self._contract_chain_mapping, sig_function_mapping=self._sig_function_mapping, sig_parse_mapping=self._sig_parse_mapping, ) - self._collect_items(TokenDepositTransaction.type(), deposit_tokens) + + output.collects(deposit_transactions) if not self._reorg: - for deposit in pre_aggregate_deposit_in_same_block(deposit_tokens): + address_deposits = [] + for deposit in pre_aggregate_deposit_in_same_block(deposit_transactions): cache_key = (deposit.wallet_address, deposit.chain_id, deposit.contract_address, deposit.token_address) cache_value = self.cache.get(cache_key) if cache_value and cache_value.block_number < deposit.block_number: # add and save 2 cache - token_deposit = AddressTokenDeposit( + address_deposit = AddressTokenDeposit( wallet_address=deposit.wallet_address, chain_id=deposit.chain_id, contract_address=deposit.contract_address, @@ -119,8 +126,8 @@ def _process(self, **kwargs): block_timestamp=deposit.block_timestamp, ) - self.cache.set(cache_key, token_deposit) - self._collect_item(AddressTokenDeposit.type(), token_deposit) + self.cache.set(cache_key, address_deposit) + address_deposits.append(address_deposit) elif cache_value is None: # check from db and save 2 cache @@ -128,7 +135,7 @@ def _process(self, **kwargs): deposit.wallet_address, deposit.chain_id, deposit.token_address ) if history_deposit is None or history_deposit.block_number < deposit.block_number: - token_deposit = AddressTokenDeposit( + address_deposit = AddressTokenDeposit( wallet_address=deposit.wallet_address, chain_id=deposit.chain_id, contract_address=deposit.contract_address, @@ -137,13 +144,15 @@ def _process(self, **kwargs): block_number=deposit.block_number, block_timestamp=deposit.block_timestamp, ) - self.cache.set(cache_key, token_deposit) - self._collect_item(AddressTokenDeposit.type(), token_deposit) - - self._data_buff[AddressTokenDeposit.type()] = distinct_collections_by_group( - collections=self._data_buff[AddressTokenDeposit.type()], - group_by=["wallet_address", "chain_id", "contract_address", "token_address"], - max_key="block_number", + self.cache.set(cache_key, address_deposit) + address_deposits.append(address_deposit) + + output.collects( + distinct_collections_by_group( + collections=address_deposits, + group_by=["wallet_address", "chain_id", "contract_address", "token_address"], + max_key="block_number", + ) ) def check_history_deposit_from_db( @@ -204,7 +213,3 @@ def pre_aggregate_deposit_in_same_block(deposit_events: List[TokenDepositTransac ) return [event for event in aggregated_deposit_events.values()] - - -if __name__ == "__main__": - pass diff --git a/indexer/modules/custom/deposit_to_l2/domains/__init__.py b/indexer/modules/custom/deposit_to_l2/domains/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/indexer/modules/custom/deposit_to_l2/domain/address_token_deposit.py b/indexer/modules/custom/deposit_to_l2/domains/address_token_deposit.py similarity index 100% rename from indexer/modules/custom/deposit_to_l2/domain/address_token_deposit.py rename to indexer/modules/custom/deposit_to_l2/domains/address_token_deposit.py diff --git a/indexer/modules/custom/deposit_to_l2/domain/token_deposit_transaction.py b/indexer/modules/custom/deposit_to_l2/domains/token_deposit_transaction.py similarity index 100% rename from indexer/modules/custom/deposit_to_l2/domain/token_deposit_transaction.py rename to indexer/modules/custom/deposit_to_l2/domains/token_deposit_transaction.py diff --git a/indexer/modules/custom/deposit_to_l2/models/af_token_deposits__transactions.py b/indexer/modules/custom/deposit_to_l2/models/af_token_deposits__transactions.py index 0820c7e90..d9bfbcce1 100644 --- a/indexer/modules/custom/deposit_to_l2/models/af_token_deposits__transactions.py +++ b/indexer/modules/custom/deposit_to_l2/models/af_token_deposits__transactions.py @@ -2,7 +2,7 @@ from sqlalchemy.dialects.postgresql import BIGINT, BOOLEAN, BYTEA, NUMERIC, TIMESTAMP from common.models import HemeraModel, general_converter -from indexer.modules.custom.deposit_to_l2.domain.token_deposit_transaction import TokenDepositTransaction +from indexer.modules.custom.deposit_to_l2.domains.token_deposit_transaction import TokenDepositTransaction class AFTokenDepositsTransactions(HemeraModel): diff --git a/indexer/modules/custom/deposit_to_l2/models/af_token_deposits_current.py b/indexer/modules/custom/deposit_to_l2/models/af_token_deposits_current.py index ec5e75c50..e4bc78e49 100644 --- a/indexer/modules/custom/deposit_to_l2/models/af_token_deposits_current.py +++ b/indexer/modules/custom/deposit_to_l2/models/af_token_deposits_current.py @@ -2,7 +2,7 @@ from sqlalchemy.dialects.postgresql import BIGINT, BYTEA, NUMERIC, TIMESTAMP from common.models import HemeraModel, general_converter -from indexer.modules.custom.deposit_to_l2.domain.address_token_deposit import AddressTokenDeposit +from indexer.modules.custom.deposit_to_l2.domains.address_token_deposit import AddressTokenDeposit class AFTokenDepositsCurrent(HemeraModel): diff --git a/indexer/tests/deposit/__init__.py b/indexer/tests/deposit/__init__.py new file mode 100644 index 000000000..e69de29bb