From 2bda914cbae4961722d42c8322572e5a5ab45f91 Mon Sep 17 00:00:00 2001 From: catalyst17 <37663786+catalyst17@users.noreply.github.com> Date: Tue, 28 Nov 2023 19:32:43 +0100 Subject: [PATCH 1/5] feat: move chronicle addresses and chain name --- .env.example | 3 +++ src/map_filter_chronicle_transactions.rs | 25 +++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 6dfbfe9..4b085aa 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,6 @@ +CHAIN_NAME= +CHRONICLE_ADDRESSES= + ENDPOINT= SUBSTREAMS_API_TOKEN= diff --git a/src/map_filter_chronicle_transactions.rs b/src/map_filter_chronicle_transactions.rs index 7065bc8..35e8a67 100644 --- a/src/map_filter_chronicle_transactions.rs +++ b/src/map_filter_chronicle_transactions.rs @@ -11,7 +11,14 @@ struct TransactionsFilter { #[substreams::handlers::map] fn map_filter_chronicle_transactions(blk: Block) -> Result> { - let filter = compose_filters(); + let chain_name = option_env!("CHAIN_NAME").ok_or_else(|| { + vec![substreams::errors::Error::msg("CHAIN_NAME environment variable is not set")] + })?; + let chronicle_addresses_str = option_env!("CHRONICLE_ADDRESSES").ok_or_else(|| { + vec![substreams::errors::Error::msg("CHRONICLE_ADDRESSES environment variable is not set")] + })?; + + let filter = compose_filters(&chronicle_addresses_str); let header = blk.header.unwrap(); let transactions: Vec = blk @@ -21,7 +28,7 @@ fn map_filter_chronicle_transactions(blk: Block) -> Result Result TransactionsFilter { +fn compose_filters(chronicle_addresses_str: &str) -> TransactionsFilter { let filter = TransactionsFilter { - to: vec![ - "0xe0F30cb149fAADC7247E953746Be9BbBB6B5751f".to_lowercase(), // BTC / USD - "0x64de91f5a373cd4c28de3600cb34c7c6ce410c85".to_lowercase(), // ETH / USD - "0x31bfa908637c29707e155cfac3a50c9823bf8723".to_lowercase(), // GNO / USD - "0xdbbe5e9b1daa91430cf0772fcebe53f6c6f137df".to_lowercase(), // MKR / USD - "0xf86360f0127f8a441cfca332c75992d1c692b3d1".to_lowercase(), // RETH / USD - "0x2f73b6567b866302e132273f67661fb89b5a66f2".to_lowercase(), // WSTETH / USD - ] + to: chronicle_addresses_str + .split(',') + .map(|s| s.to_lowercase()) + .collect::>() }; return filter; From 32c86e21749705831c3dce5801f0f842cb0e950f Mon Sep 17 00:00:00 2001 From: catalyst17 <37663786+catalyst17@users.noreply.github.com> Date: Tue, 28 Nov 2023 19:38:35 +0100 Subject: [PATCH 2/5] feat: de-hardcode AA addresses --- .env.example | 2 ++ src/map_filter_aa_transactions.rs | 35 ++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 4b085aa..26d5bca 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,7 @@ CHAIN_NAME= CHRONICLE_ADDRESSES= +AA_ERC4337_ADDRESSES= +AA_SAFE_ADDRESSES= ENDPOINT= SUBSTREAMS_API_TOKEN= diff --git a/src/map_filter_aa_transactions.rs b/src/map_filter_aa_transactions.rs index 994f8df..1d9a5ff 100644 --- a/src/map_filter_aa_transactions.rs +++ b/src/map_filter_aa_transactions.rs @@ -5,7 +5,6 @@ use substreams_ethereum::{Function, Event}; use substreams_ethereum::block_view::{CallView, LogView}; use substreams_ethereum::pb::eth::v2::{Block, TransactionTrace, CallType}; -// #[derive(Deserialize)] struct TransactionFilters { filters: Vec } @@ -17,7 +16,17 @@ struct TransactionFilter { #[substreams::handlers::map] fn map_filter_aa_transactions(blk: Block) -> Result> { // let filters = parse_filters_from_params(params)?; - let filters = compose_filters(); + let chain_name = option_env!("CHAIN_NAME").ok_or_else(|| { + vec![substreams::errors::Error::msg("CHAIN_NAME environment variable is not set")] + })?; + let erc4337_addresses_str = option_env!("AA_ERC4337_ADDRESSES").ok_or_else(|| { + vec![substreams::errors::Error::msg("AA_ERC4337_ADDRESSES environment variable is not set")] + })?; + let safe_addresses_str = option_env!("AA_SAFE_ADDRESSES").ok_or_else(|| { + vec![substreams::errors::Error::msg("AA_SAFE_ADDRESSES environment variable is not set")] + })?; + + let filters = compose_filters(&erc4337_addresses_str, &safe_addresses_str); let header = blk.header.unwrap(); let transactions: Vec = blk @@ -29,7 +38,7 @@ fn map_filter_aa_transactions(blk: Block) -> Result Result TransactionFilters { +fn compose_filters(erc4337_addresses_str: &str, safe_addresses_str: &str) -> TransactionFilters { + + let erc4337_filter = TransactionFilter { - to: vec!["0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789".to_string()], + to: erc4337_addresses_str + .split(',') + .map(|s| s.to_lowercase()) + .collect::>(), account_abstraction_type: "erc4337".to_string(), }; let safe_filter = TransactionFilter { - to: vec![ - "0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A".to_string(), // v1.0.0 - "0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F".to_string(), // v1.1.1 - "0x6851D6fDFAfD08c0295C392436245E5bc78B0185".to_string(), // v1.2.0 - "0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552".to_string(), // v1.3.0 - "0x41675C099F32341bf84BFc5382aF534df5C7461a".to_string(), // v1.4.1 - ], + to: safe_addresses_str + .split(',') + .map(|s| s.to_lowercase()) + .collect::>(), account_abstraction_type: "safe".to_string(), }; From c1b983526bc0136b35f76d6ff654d32b86f2c297 Mon Sep 17 00:00:00 2001 From: catalyst17 <37663786+catalyst17@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:52:02 +0100 Subject: [PATCH 3/5] feat: add module producing combined trxs --- Makefile | 2 +- proto/combined_transactions.proto | 11 +++++++++++ src/lib.rs | 1 + src/map_combine_transactions.rs | 14 ++++++++++++++ src/pb/eth.transaction.v1.rs | 8 ++++++++ substreams.yaml | 10 ++++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 proto/combined_transactions.proto create mode 100644 src/map_combine_transactions.rs diff --git a/Makefile b/Makefile index bcf51ae..8057f37 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ build: .PHONY: run run: build - substreams run -e $(ENDPOINT) substreams.yaml db_out -s $(START_BLOCK) -t $(STOP_BLOCK) + substreams run -e $(ENDPOINT) substreams.yaml map_combine_transactions -s $(START_BLOCK) -t $(STOP_BLOCK) .PHONY: sink sink: build diff --git a/proto/combined_transactions.proto b/proto/combined_transactions.proto new file mode 100644 index 0000000..165c616 --- /dev/null +++ b/proto/combined_transactions.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package eth.transaction.v1; + +import "aa_transaction.proto"; +import "chronicle_transaction.proto"; + +message CombinedTransactions { + AccountAbstractionTransactions accountAbstractionTransactions = 1; + ChronicleTransactions chronicleTransactions = 2; +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index c860a32..f0d8d63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ mod map_filter_chronicle_transactions; mod map_filter_aa_transactions; +mod map_combine_transactions; mod db_out; mod pb; mod abi; diff --git a/src/map_combine_transactions.rs b/src/map_combine_transactions.rs new file mode 100644 index 0000000..46ce1d3 --- /dev/null +++ b/src/map_combine_transactions.rs @@ -0,0 +1,14 @@ +use crate::pb::eth::transaction::v1::{CombinedTransactions, AccountAbstractionTransactions, ChronicleTransactions}; + +#[substreams::handlers::map] +fn map_combine_transactions( + aa_trxs: AccountAbstractionTransactions, + chronicle_trxs: ChronicleTransactions +) -> Result> { + let transactions = CombinedTransactions { + account_abstraction_transactions: Some(aa_trxs), + chronicle_transactions: Some(chronicle_trxs) + }; + + Ok(transactions) +} \ No newline at end of file diff --git a/src/pb/eth.transaction.v1.rs b/src/pb/eth.transaction.v1.rs index 5afcb2f..9abd0a3 100644 --- a/src/pb/eth.transaction.v1.rs +++ b/src/pb/eth.transaction.v1.rs @@ -45,4 +45,12 @@ pub struct AccountAbstractionTransaction { #[prost(message, optional, tag="7")] pub timestamp: ::core::option::Option<::prost_types::Timestamp>, } +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CombinedTransactions { + #[prost(message, optional, tag="1")] + pub account_abstraction_transactions: ::core::option::Option, + #[prost(message, optional, tag="2")] + pub chronicle_transactions: ::core::option::Option, +} // @@protoc_insertion_point(module) diff --git a/substreams.yaml b/substreams.yaml index 562cf7f..ee6a805 100644 --- a/substreams.yaml +++ b/substreams.yaml @@ -12,6 +12,7 @@ protobuf: files: - chronicle_transaction.proto - aa_transaction.proto + - combined_transactions.proto importPaths: - ./proto @@ -36,6 +37,15 @@ modules: - source: sf.ethereum.type.v2.Block output: type: proto:eth.transaction.v1.ChronicleTransactions + + - name: map_combine_transactions + kind: map + initialBlock: 18664500 + inputs: + - map: map_filter_aa_transactions + - map: map_filter_chronicle_transactions + output: + type: proto:eth.transaction.v1.CombinedTransactions - name: db_out kind: map From 603cc8ba70c6b6581f866b13a86308f297837670 Mon Sep 17 00:00:00 2001 From: catalyst17 <37663786+catalyst17@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:23:49 +0100 Subject: [PATCH 4/5] feat: remove initialBlock to not depend on network --- substreams.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/substreams.yaml b/substreams.yaml index ee6a805..96487d2 100644 --- a/substreams.yaml +++ b/substreams.yaml @@ -24,7 +24,6 @@ binaries: modules: - name: map_filter_aa_transactions kind: map - initialBlock: 18664500 inputs: - source: sf.ethereum.type.v2.Block output: @@ -32,7 +31,6 @@ modules: - name: map_filter_chronicle_transactions kind: map - initialBlock: 18664500 inputs: - source: sf.ethereum.type.v2.Block output: @@ -40,7 +38,6 @@ modules: - name: map_combine_transactions kind: map - initialBlock: 18664500 inputs: - map: map_filter_aa_transactions - map: map_filter_chronicle_transactions @@ -49,7 +46,6 @@ modules: - name: db_out kind: map - initialBlock: 18664500 inputs: - map: map_filter_aa_transactions - map: map_filter_chronicle_transactions From e90e5bad39bb9d240d9e93f3121f2e4fbfb8048c Mon Sep 17 00:00:00 2001 From: catalyst17 <37663786+catalyst17@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:24:18 +0100 Subject: [PATCH 5/5] refactor: combined trxs format --- proto/combined_transactions.proto | 4 ++-- src/map_combine_transactions.rs | 7 +------ src/pb/eth.transaction.v1.rs | 8 ++++---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/proto/combined_transactions.proto b/proto/combined_transactions.proto index 165c616..4fc3284 100644 --- a/proto/combined_transactions.proto +++ b/proto/combined_transactions.proto @@ -6,6 +6,6 @@ import "aa_transaction.proto"; import "chronicle_transaction.proto"; message CombinedTransactions { - AccountAbstractionTransactions accountAbstractionTransactions = 1; - ChronicleTransactions chronicleTransactions = 2; + repeated AccountAbstractionTransaction accountAbstractionTransactions = 1; + repeated ChronicleTransaction chronicleTransactions = 2; } \ No newline at end of file diff --git a/src/map_combine_transactions.rs b/src/map_combine_transactions.rs index 46ce1d3..2567187 100644 --- a/src/map_combine_transactions.rs +++ b/src/map_combine_transactions.rs @@ -5,10 +5,5 @@ fn map_combine_transactions( aa_trxs: AccountAbstractionTransactions, chronicle_trxs: ChronicleTransactions ) -> Result> { - let transactions = CombinedTransactions { - account_abstraction_transactions: Some(aa_trxs), - chronicle_transactions: Some(chronicle_trxs) - }; - - Ok(transactions) + Ok(CombinedTransactions { account_abstraction_transactions: aa_trxs.transactions, chronicle_transactions: chronicle_trxs.transactions }) } \ No newline at end of file diff --git a/src/pb/eth.transaction.v1.rs b/src/pb/eth.transaction.v1.rs index 9abd0a3..8b840f5 100644 --- a/src/pb/eth.transaction.v1.rs +++ b/src/pb/eth.transaction.v1.rs @@ -48,9 +48,9 @@ pub struct AccountAbstractionTransaction { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CombinedTransactions { - #[prost(message, optional, tag="1")] - pub account_abstraction_transactions: ::core::option::Option, - #[prost(message, optional, tag="2")] - pub chronicle_transactions: ::core::option::Option, + #[prost(message, repeated, tag="1")] + pub account_abstraction_transactions: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag="2")] + pub chronicle_transactions: ::prost::alloc::vec::Vec, } // @@protoc_insertion_point(module)