refactor(uniswap_v4): remove costly clone calls (#169)
* Removed costly `TransactionTrace` clones calls and `.clone()` at a few other places * style: formatting * chore: bump uniswap v4 versions to 0.2.1 * fix: fix double referencing --------- Co-authored-by: Matthieu Vachon <matt@streamingfast.io>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
specVersion: v0.1.0
|
||||
package:
|
||||
name: "base_uniswap_v4"
|
||||
version: v0.2.0
|
||||
version: v0.2.1
|
||||
|
||||
protobuf:
|
||||
files:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
specVersion: v0.1.0
|
||||
package:
|
||||
name: "ethereum_uniswap_v4"
|
||||
version: v0.2.0
|
||||
version: v0.2.1
|
||||
|
||||
protobuf:
|
||||
files:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
specVersion: v0.1.0
|
||||
package:
|
||||
name: "ethereum_uniswap_v4"
|
||||
version: v0.1.1
|
||||
version: v0.2.1
|
||||
|
||||
protobuf:
|
||||
files:
|
||||
|
||||
@@ -23,11 +23,15 @@ pub fn map_events(
|
||||
.into_iter()
|
||||
.filter(|tx| tx.status == 1)
|
||||
.flat_map(|tx| {
|
||||
tx.clone()
|
||||
let receipt = tx
|
||||
.receipt
|
||||
.into_iter()
|
||||
.flat_map(|receipt| receipt.logs)
|
||||
.filter_map(|log| log_to_event(&log, tx.clone(), &pools_store))
|
||||
.as_ref()
|
||||
.expect("all transaction traces have a receipt");
|
||||
|
||||
receipt
|
||||
.logs
|
||||
.iter()
|
||||
.filter_map(|log| log_to_event(log, &tx, &pools_store))
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -39,7 +43,7 @@ pub fn map_events(
|
||||
|
||||
fn log_to_event(
|
||||
event: &Log,
|
||||
tx: TransactionTrace,
|
||||
tx: &TransactionTrace,
|
||||
pools_store: &StoreGetProto<Pool>,
|
||||
) -> Option<PoolEvent> {
|
||||
if let Some(init) = Initialize::match_and_decode(event) {
|
||||
|
||||
@@ -58,33 +58,24 @@ fn event_to_balance_deltas(
|
||||
get_amount_delta(current_sqrt_price, e.tick_lower, e.tick_upper, e.liquidity_delta);
|
||||
Some(vec![
|
||||
BalanceDelta {
|
||||
token: hex::decode(
|
||||
event
|
||||
.currency0
|
||||
.clone()
|
||||
.trim_start_matches("0x"),
|
||||
)
|
||||
.unwrap(),
|
||||
token: hex::decode(event.currency0.trim_start_matches("0x")).unwrap(),
|
||||
delta: delta0.to_signed_bytes_be(),
|
||||
component_id: address.clone(),
|
||||
ord: event.log_ordinal,
|
||||
tx: event
|
||||
.transaction
|
||||
.clone()
|
||||
.as_ref()
|
||||
.map(Into::into),
|
||||
},
|
||||
BalanceDelta {
|
||||
token: hex::decode(
|
||||
event
|
||||
.currency1
|
||||
.clone()
|
||||
.trim_start_matches("0x"),
|
||||
)
|
||||
.unwrap(),
|
||||
token: hex::decode(event.currency1.trim_start_matches("0x")).unwrap(),
|
||||
delta: delta1.to_signed_bytes_be(),
|
||||
component_id: address,
|
||||
ord: event.log_ordinal,
|
||||
tx: event.transaction.map(Into::into),
|
||||
tx: event
|
||||
.transaction
|
||||
.as_ref()
|
||||
.map(Into::into),
|
||||
},
|
||||
])
|
||||
}
|
||||
@@ -123,33 +114,24 @@ fn event_to_balance_deltas(
|
||||
|
||||
Some(vec![
|
||||
BalanceDelta {
|
||||
token: hex::decode(
|
||||
event
|
||||
.currency0
|
||||
.clone()
|
||||
.trim_start_matches("0x"),
|
||||
)
|
||||
.unwrap(),
|
||||
token: hex::decode(event.currency0.trim_start_matches("0x")).unwrap(),
|
||||
delta: delta0.to_signed_bytes_be(),
|
||||
component_id: address.clone(),
|
||||
ord: event.log_ordinal,
|
||||
tx: event
|
||||
.transaction
|
||||
.clone()
|
||||
.as_ref()
|
||||
.map(Into::into),
|
||||
},
|
||||
BalanceDelta {
|
||||
token: hex::decode(
|
||||
event
|
||||
.currency1
|
||||
.clone()
|
||||
.trim_start_matches("0x"),
|
||||
)
|
||||
.unwrap(),
|
||||
token: hex::decode(event.currency1.trim_start_matches("0x")).unwrap(),
|
||||
delta: delta1.to_signed_bytes_be(),
|
||||
component_id: address.clone(),
|
||||
component_id: address,
|
||||
ord: event.log_ordinal,
|
||||
tx: event.transaction.map(Into::into),
|
||||
tx: event
|
||||
.transaction
|
||||
.as_ref()
|
||||
.map(Into::into),
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn map_ticks_changes(events: Events) -> Result<TickDeltas, anyhow::Error> {
|
||||
|
||||
#[substreams::handlers::store]
|
||||
pub fn store_ticks_liquidity(ticks_deltas: TickDeltas, store: StoreAddBigInt) {
|
||||
let mut deltas = ticks_deltas.deltas.clone();
|
||||
let mut deltas = ticks_deltas.deltas;
|
||||
|
||||
deltas.sort_unstable_by_key(|delta| delta.ordinal);
|
||||
|
||||
|
||||
@@ -169,16 +169,10 @@ fn event_to_attributes_updates(event: PoolEvent) -> Vec<(Transaction, PoolAddres
|
||||
(
|
||||
event
|
||||
.transaction
|
||||
.clone()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.into(),
|
||||
hex::decode(
|
||||
event
|
||||
.pool_id
|
||||
.clone()
|
||||
.trim_start_matches("0x"),
|
||||
)
|
||||
.unwrap(),
|
||||
hex::decode(event.pool_id.trim_start_matches("0x")).unwrap(),
|
||||
Attribute {
|
||||
name: "sqrt_price_x96".to_string(),
|
||||
value: BigInt::from_str(&swap.sqrt_price_x96)
|
||||
@@ -208,16 +202,10 @@ fn event_to_attributes_updates(event: PoolEvent) -> Vec<(Transaction, PoolAddres
|
||||
(
|
||||
event
|
||||
.transaction
|
||||
.clone()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.into(),
|
||||
hex::decode(
|
||||
event
|
||||
.pool_id
|
||||
.clone()
|
||||
.trim_start_matches("0x"),
|
||||
)
|
||||
.unwrap(),
|
||||
hex::decode(event.pool_id.trim_start_matches("0x")).unwrap(),
|
||||
Attribute {
|
||||
name: "protocol_fees/zero2one".to_string(),
|
||||
value: BigInt::from(lower_12_bits).to_signed_bytes_be(),
|
||||
|
||||
@@ -36,8 +36,30 @@ impl From<TransactionTrace> for Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&TransactionTrace> for Transaction {
|
||||
fn from(value: &TransactionTrace) -> Self {
|
||||
Self {
|
||||
hash: value.hash.clone(),
|
||||
from: value.from.clone(),
|
||||
to: value.to.clone(),
|
||||
index: value.index.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Transaction> for tycho_substreams::prelude::Transaction {
|
||||
fn from(value: Transaction) -> Self {
|
||||
Self { hash: value.hash, from: value.from, to: value.to, index: value.index }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Transaction> for tycho_substreams::prelude::Transaction {
|
||||
fn from(value: &Transaction) -> Self {
|
||||
Self {
|
||||
hash: value.hash.clone(),
|
||||
from: value.from.clone(),
|
||||
to: value.to.clone(),
|
||||
index: value.index,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use num_bigint::BigInt;
|
||||
use std::ops::Shr;
|
||||
|
||||
/// Calculates the amounts of token0 and token1 for a given position
|
||||
///
|
||||
/// Source: https://github.com/Uniswap/v4-core/blob/main/src/libraries/Pool.sol
|
||||
|
||||
Reference in New Issue
Block a user