From 65ee0b6d2655e51038e8e4ade15f4119f8a1f660 Mon Sep 17 00:00:00 2001 From: Shubh Agarwal Date: Sun, 25 Aug 2024 00:23:43 -0400 Subject: [PATCH 1/3] filter out revert txs --- src/helpers/blockchain_data.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/helpers/blockchain_data.py b/src/helpers/blockchain_data.py index 2c152ea..45620e8 100644 --- a/src/helpers/blockchain_data.py +++ b/src/helpers/blockchain_data.py @@ -41,12 +41,14 @@ def get_tx_hashes_blocks( involving the settlement contract. """ tx_hashes_blocks = [] - for block_number in range(start_block, end_block + 1): block = self.web3.eth.get_block(block_number, full_transactions=True) for tx in block.transactions: # type: ignore[attr-defined] if tx.to and tx.to.lower() == SETTLEMENT_CONTRACT_ADDRESS.lower(): - tx_hashes_blocks.append((tx.hash.to_0x_hex(), block_number)) + receipt = self.web3.eth.get_transaction_receipt(tx.hash) + # status = 0 indicates a reverted tx, status = 1 is successful tx + if receipt.status == 1: # type: ignore[attr-defined] + tx_hashes_blocks.append((tx.hash.to_0x_hex(), block_number)) return tx_hashes_blocks def get_auction_id(self, tx_hash: str) -> int: From cdba94cda09e4d2a3496a7a1e990e9950865c50f Mon Sep 17 00:00:00 2001 From: Shubh Agarwal Date: Sun, 25 Aug 2024 12:46:49 -0400 Subject: [PATCH 2/3] fix sql errors --- src/sql/delete_entries_max_block.sql | 3 +++ src/sql/select_max_block.sql | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/sql/delete_entries_max_block.sql b/src/sql/delete_entries_max_block.sql index c5ceee0..ce3eb15 100644 --- a/src/sql/delete_entries_max_block.sql +++ b/src/sql/delete_entries_max_block.sql @@ -8,4 +8,7 @@ DELETE FROM slippage_prices WHERE chain_name = :chain_name AND block_number >= :block_number; +DELETE FROM fees +WHERE chain_name = :chain_name +AND block_number >= :block_number; COMMIT; diff --git a/src/sql/select_max_block.sql b/src/sql/select_max_block.sql index fb70653..17e16cd 100644 --- a/src/sql/select_max_block.sql +++ b/src/sql/select_max_block.sql @@ -8,4 +8,8 @@ FROM ( SELECT MAX(block_number) AS max_block_number FROM slippage_prices WHERE chain_name = :chain_name + UNION ALL + SELECT MAX(block_number) AS max_block_number + FROM fees + WHERE chain_name = :chain_name ) AS max_blocks; From 24168b12c362476c62de9733529bdcb6a98b6aee Mon Sep 17 00:00:00 2001 From: Shubh Agarwal Date: Mon, 26 Aug 2024 17:01:46 -0400 Subject: [PATCH 3/3] ignore-invalidated orders --- src/constants.py | 4 ++++ src/helpers/blockchain_data.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/constants.py b/src/constants.py index 3eeafec..16e9a08 100644 --- a/src/constants.py +++ b/src/constants.py @@ -14,6 +14,10 @@ "0x83F20F44975D03b1b09e64809B757c47f942BEeA" ) +INVALIDATED_ORDER_TOPIC = ( + "0x875b6cb035bbd4ac6500fabc6d1e4ca5bdc58a3e2b424ccb5c24cdbebeb009a9" +) + REQUEST_TIMEOUT = 5 # Time limit, currently set to 1 full day, after which Coingecko Token List is re-fetched (in seconds) diff --git a/src/helpers/blockchain_data.py b/src/helpers/blockchain_data.py index 45620e8..361b050 100644 --- a/src/helpers/blockchain_data.py +++ b/src/helpers/blockchain_data.py @@ -1,7 +1,7 @@ from hexbytes import HexBytes from web3 import Web3 from src.helpers.config import logger -from src.constants import SETTLEMENT_CONTRACT_ADDRESS +from src.constants import SETTLEMENT_CONTRACT_ADDRESS, INVALIDATED_ORDER_TOPIC class BlockchainData: @@ -46,6 +46,12 @@ def get_tx_hashes_blocks( for tx in block.transactions: # type: ignore[attr-defined] if tx.to and tx.to.lower() == SETTLEMENT_CONTRACT_ADDRESS.lower(): receipt = self.web3.eth.get_transaction_receipt(tx.hash) + # ignore txs that trigger the OrderInvalidated event + if any( + log.topics[0].to_0x_hex() == INVALIDATED_ORDER_TOPIC + for log in receipt.logs # type: ignore[attr-defined] + ): + continue # status = 0 indicates a reverted tx, status = 1 is successful tx if receipt.status == 1: # type: ignore[attr-defined] tx_hashes_blocks.append((tx.hash.to_0x_hex(), block_number))