fix: stop using buggy account_creations for creation tagging. (#201)
the `call.account_creations` field had been deprecated by Substreams because of some edge cases where a new account wasn't detected. This commit removes the usage of this field in our sdk contract extraction logic and some others specific places. We decided to rely on the call type instead. This approach should be much more robust. Co-authored-by: zizou <111426680+flopell@users.noreply.github.com>
This commit is contained in:
34
substreams/Cargo.lock
generated
34
substreams/Cargo.lock
generated
@@ -300,7 +300,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ethereum-sfrax"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"ethabi 17.2.0",
|
||||
@@ -1377,7 +1377,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "substreams-ethereum-ambient"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@@ -1612,21 +1612,6 @@ dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tycho-substreams"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"ethabi 18.0.0",
|
||||
"hex",
|
||||
"itertools 0.12.1",
|
||||
"num-bigint",
|
||||
"prost 0.11.9",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"substreams",
|
||||
"substreams-ethereum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tycho-substreams"
|
||||
version = "0.2.0"
|
||||
@@ -1675,6 +1660,21 @@ dependencies = [
|
||||
"substreams-ethereum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tycho-substreams"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"ethabi 18.0.0",
|
||||
"hex",
|
||||
"itertools 0.12.1",
|
||||
"num-bigint",
|
||||
"prost 0.11.9",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"substreams",
|
||||
"substreams-ethereum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tycho-substreams"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
description = "Tycho substreams development kit, contains tycho-indexer block changes model and helper functions for common indexing tasks."
|
||||
repository = "https://github.com/propeller-heads/tycho-protocol-sdk/tree/main/substreams/crates/tycho-substreams"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
/// ## Warning
|
||||
/// ⚠️ These helpers *only* work if the **extended block model** is available,
|
||||
/// more [here](https://streamingfastio.medium.com/new-block-model-to-accelerate-chain-integration-9f65126e5425)
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::{
|
||||
models::{InterimContractChange, TransactionChanges},
|
||||
@@ -97,14 +97,11 @@ fn extract_contract_changes_generic<
|
||||
.transactions()
|
||||
.for_each(|block_tx| {
|
||||
// Collect all accounts created in this tx
|
||||
let created_accounts: HashMap<_, _> = block_tx
|
||||
let created_accounts: HashSet<_> = block_tx
|
||||
.calls
|
||||
.iter()
|
||||
.flat_map(|call| {
|
||||
call.account_creations
|
||||
.iter()
|
||||
.map(|ac| (&ac.account, ac.ordinal))
|
||||
})
|
||||
.filter(|call| call.call_type() == CallType::Create)
|
||||
.map(|call| call.address.clone())
|
||||
.collect();
|
||||
|
||||
let mut storage_changes = Vec::new();
|
||||
@@ -140,7 +137,7 @@ fn extract_contract_changes_generic<
|
||||
.or_insert_with(|| {
|
||||
InterimContractChange::new(
|
||||
&storage_change.address,
|
||||
created_accounts.contains_key(&storage_change.address),
|
||||
created_accounts.contains(&storage_change.address),
|
||||
)
|
||||
});
|
||||
|
||||
@@ -156,7 +153,7 @@ fn extract_contract_changes_generic<
|
||||
.or_insert_with(|| {
|
||||
InterimContractChange::new(
|
||||
&balance_change.address,
|
||||
created_accounts.contains_key(&balance_change.address),
|
||||
created_accounts.contains(&balance_change.address),
|
||||
)
|
||||
});
|
||||
|
||||
@@ -174,7 +171,7 @@ fn extract_contract_changes_generic<
|
||||
.or_insert_with(|| {
|
||||
InterimContractChange::new(
|
||||
&code_change.address,
|
||||
created_accounts.contains_key(&code_change.address),
|
||||
created_accounts.contains(&code_change.address),
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "substreams-ethereum-ambient"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use num_bigint::BigInt;
|
||||
use std::{
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
collections::{hash_map::Entry, HashMap, HashSet},
|
||||
str::FromStr,
|
||||
};
|
||||
use substreams::{
|
||||
pb::substreams::StoreDeltas,
|
||||
store::{StoreGet, StoreGetProto},
|
||||
};
|
||||
use substreams_ethereum::pb::eth::{self};
|
||||
use substreams_ethereum::pb::eth::{self, v2::CallType};
|
||||
|
||||
use tycho_substreams::prelude::*;
|
||||
|
||||
@@ -77,20 +77,22 @@ fn map_changes(
|
||||
balance_store: StoreDeltas,
|
||||
pool_store: StoreGetProto<ProtocolComponent>,
|
||||
) -> Result<BlockChanges, substreams::errors::Error> {
|
||||
// TODO: this needs to be refactored to use the tycho-substreams helper functions.
|
||||
// The current implementation probably suffers from the bug fixed in https://github.com/propeller-heads/tycho-protocol-sdk/pull/117
|
||||
let mut block_changes = BlockChanges::default();
|
||||
|
||||
let mut transaction_changes = TransactionChanges::default();
|
||||
|
||||
let mut changed_contracts: HashMap<Vec<u8>, InterimContractChange> = HashMap::new();
|
||||
|
||||
let created_accounts: HashMap<_, _> = block
|
||||
// collect all account creations in the block
|
||||
let created_accounts: HashSet<_> = block
|
||||
.transactions()
|
||||
.flat_map(|tx| {
|
||||
tx.calls.iter().flat_map(|call| {
|
||||
call.account_creations
|
||||
.iter()
|
||||
.map(|ac| (&ac.account, ac.ordinal))
|
||||
})
|
||||
tx.calls
|
||||
.iter()
|
||||
.filter(|call| call.call_type() == CallType::Create)
|
||||
.map(|call| call.address.clone())
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -161,7 +163,7 @@ fn map_changes(
|
||||
balance: Vec::new(),
|
||||
code: Vec::new(),
|
||||
slots,
|
||||
change: if created_accounts.contains_key(&storage_change.address) {
|
||||
change: if created_accounts.contains(&storage_change.address) {
|
||||
ChangeType::Creation
|
||||
} else {
|
||||
ChangeType::Update
|
||||
@@ -202,7 +204,7 @@ fn map_changes(
|
||||
balance: new_balance.bytes.clone(),
|
||||
code: Vec::new(),
|
||||
slots: HashMap::new(),
|
||||
change: if created_accounts.contains_key(&balance_change.address) {
|
||||
change: if created_accounts.contains(&balance_change.address) {
|
||||
ChangeType::Creation
|
||||
} else {
|
||||
ChangeType::Update
|
||||
@@ -241,7 +243,7 @@ fn map_changes(
|
||||
balance: Vec::new(),
|
||||
code: code_change.new_code.clone(),
|
||||
slots: HashMap::new(),
|
||||
change: if created_accounts.contains_key(&code_change.address) {
|
||||
change: if created_accounts.contains(&code_change.address) {
|
||||
ChangeType::Creation
|
||||
} else {
|
||||
ChangeType::Update
|
||||
@@ -315,7 +317,7 @@ fn map_changes(
|
||||
let pool_hash_hex = hex::encode(balance_delta.pool_hash);
|
||||
let pool = match pool_store.get_last(pool_hash_hex.clone()) {
|
||||
Some(pool) => pool,
|
||||
None => panic!("Pool not found in store for given hash: {}", pool_hash_hex),
|
||||
None => panic!("Pool not found in store for given hash: {pool_hash_hex}"),
|
||||
};
|
||||
let token_type = substreams::key::segment_at(&store_delta.key, 1);
|
||||
let token_index = if token_type == "quote" { 1 } else { 0 };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ethereum-sfrax"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::abi;
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use substreams::{
|
||||
hex,
|
||||
pb::substreams::StoreDeltas,
|
||||
@@ -87,7 +87,7 @@ pub fn map_relative_balances(
|
||||
let address_bytes_be = vault_log.address();
|
||||
let address_hex = format!("0x{}", hex::encode(address_bytes_be));
|
||||
if store
|
||||
.get_last(format!("pool:{}", address_hex))
|
||||
.get_last(format!("pool:{address_hex}"))
|
||||
.is_some()
|
||||
{
|
||||
deltas.extend_from_slice(&[
|
||||
@@ -122,7 +122,7 @@ pub fn map_relative_balances(
|
||||
let address_hex = format!("0x{}", hex::encode(address_bytes_be));
|
||||
|
||||
if store
|
||||
.get_last(format!("pool:{}", address_hex))
|
||||
.get_last(format!("pool:{address_hex}"))
|
||||
.is_some()
|
||||
{
|
||||
deltas.extend_from_slice(&[
|
||||
@@ -157,7 +157,7 @@ pub fn map_relative_balances(
|
||||
let address_hex = format!("0x{}", hex::encode(address_bytes_be));
|
||||
|
||||
if store
|
||||
.get_last(format!("pool:{}", address_hex))
|
||||
.get_last(format!("pool:{address_hex}"))
|
||||
.is_some()
|
||||
{
|
||||
deltas.extend_from_slice(&[BalanceDelta {
|
||||
@@ -260,17 +260,11 @@ fn is_deployment_tx(tx: ð::v2::TransactionTrace, vault_address: &[u8]) -> boo
|
||||
let created_accounts = tx
|
||||
.calls
|
||||
.iter()
|
||||
.flat_map(|call| {
|
||||
call.account_creations
|
||||
.iter()
|
||||
.map(|ac| ac.account.to_owned())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
.filter(|call| call.call_type() == eth::v2::CallType::Create)
|
||||
.map(|call| call.address.clone())
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
if let Some(deployed_address) = created_accounts.first() {
|
||||
return deployed_address.as_slice() == vault_address;
|
||||
}
|
||||
false
|
||||
created_accounts.contains(vault_address)
|
||||
}
|
||||
|
||||
fn find_deployed_underlying_address(vault_address: &[u8]) -> Option<[u8; 20]> {
|
||||
|
||||
Reference in New Issue
Block a user