From 194cfe52966afb75d3a5e07a63a457428fb05c14 Mon Sep 17 00:00:00 2001 From: 0xMochan Date: Fri, 24 May 2024 17:51:49 -0400 Subject: [PATCH] feat: add WETH to ETH address swap --- substreams/ethereum-curve/.DS_Store | Bin 0 -> 6148 bytes .../ethereum-curve/src/pool_factories.rs | 25 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 substreams/ethereum-curve/.DS_Store diff --git a/substreams/ethereum-curve/.DS_Store b/substreams/ethereum-curve/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2a7ee52672d117f3b56dbae20d3361206119b013 GIT binary patch literal 6148 zcmeHKJ5Iwu5S<|@EYYN(pxi5@MHI#|C&&d*5($b#j)>?@#UVHk=YVri@#X_KGEh>$ z8)^1=XXfq7ukd(8M4P+yTx2F972HrBY#E#7%|~{WkttB^jQL{KZFe4RM%7;jj60FN z+{$WmJ>;LAe`dB_+b%cV5|OHVzJEM%>0LKOI` which is needed /// to be able to encode some of the `Attribute`s. This should also be handled by any downstream /// application. @@ -46,6 +49,20 @@ fn address_to_bytes_with_0x(address: &[u8; 20]) -> Vec { format!("0x{}", hex::encode(address)).into_bytes() } +/// Function that swaps `WETH` addresses for `ETH` address for specific factory types that decide +/// to use `WETH` address even though native `ETH` is stored. This is also extra weird bc ETH +/// doesn't even have a real address, so we use the standard `0xEEEee...`. +fn swap_weth_for_eth(tokens: Vec>) -> Vec> { + if tokens.contains(&WETH_ADDRESS.into()) { + tokens + .into_iter() + .map(|token| if token == WETH_ADDRESS { ETH_ADDRESS.into() } else { token }) + .collect::>() + } else { + tokens + } +} + /// This massive function matches factory address to specific logic to construct /// `ProtocolComponent`s. While, most of the logic is readily replicable, several factories differ /// in information density resulting in needing other information sources such as decoding calls @@ -74,6 +91,8 @@ pub fn address_map( let pool_added = abi::crypto_pool_factory::events::CryptoPoolDeployed::match_and_decode(log)?; + let tokens = swap_weth_for_eth(pool_added.coins.into()); + let component_id = &call.return_data[12..]; Some(ProtocolComponent { @@ -84,7 +103,7 @@ pub fn address_map( hash: tx.hash.clone(), index: tx.index.into(), }), - tokens: pool_added.coins.into(), + tokens, contracts: vec![component_id.into()], static_att: vec![ Attribute { @@ -449,6 +468,8 @@ pub fn address_map( if let Some(pool_added) = abi::tricrypto_factory::events::TricryptoPoolDeployed::match_and_decode(log) { + let tokens = swap_weth_for_eth(pool_added.coins.into()); + Some(ProtocolComponent { id: hex::encode(&pool_added.pool), tx: Some(Transaction { @@ -457,7 +478,7 @@ pub fn address_map( hash: tx.hash.clone(), index: tx.index.into(), }), - tokens: pool_added.coins.into(), + tokens, contracts: vec![pool_added.pool.into()], static_att: vec![ Attribute {