feat: new pool->token function, renamed ERC20->erc20

This commit is contained in:
0xMochan
2024-05-29 14:39:32 -04:00
parent 194cfe5296
commit f64fcdf220
5 changed files with 42 additions and 16 deletions

View File

@@ -1 +1 @@
substreams gui -e mainnet.eth.streamingfast.io:443 substreams.yaml map_protocol_changes --start-block 19933736 --stop-block +50 -p map_components=`python params.py`
substreams gui -e mainnet.eth.streamingfast.io:443 substreams.yaml map_protocol_changes --start-block 19216042 --stop-block +50 -p map_components=`python params.py`

View File

@@ -12,6 +12,6 @@ pub mod pool;
pub mod tricrypto_factory;
pub mod main_registry;
pub mod pool_3pool;
pub mod ERC20;
pub mod erc20;
pub mod meta_pool_factory;
pub mod crypto_swap_registry;

View File

@@ -26,7 +26,7 @@ fn get_pool_tokens(pool_address: &Vec<u8>, tokens_store: &StoreGetString) -> Opt
/// TODO rewrite
pub fn emit_deltas(log: LogView, tokens_store: &StoreGetString) -> Option<BalanceDelta> {
let transfer = abi::ERC20::events::Transfer::match_and_decode(log)?;
let transfer = abi::erc20::events::Transfer::match_and_decode(log)?;
let (component_id, pool_tokens, is_incoming) =
if let Some(pool_tokens) = get_pool_tokens(&transfer.to, tokens_store) {

View File

@@ -311,10 +311,7 @@ pub fn address_map(
})?;
let component_id = &call.return_data[12..];
let get_lp_token =
abi::meta_registry::functions::GetLpToken1 { pool: add_pool.base_pool.clone() };
let lp_token = get_lp_token.call(META_REGISTRY.to_vec())?;
let lp_token = get_token_from_pool(&pool_added.base_pool);
Some(ProtocolComponent {
id: hex::encode(component_id),
@@ -415,10 +412,7 @@ pub fn address_map(
let add_pool =
abi::crypto_swap_ng_factory::functions::DeployMetapool::match_and_decode(call)?;
let component_id = &call.return_data[12..];
let get_lp_token =
abi::meta_registry::functions::GetLpToken1 { pool: add_pool.base_pool.clone() };
let lp_token = get_lp_token.call(META_REGISTRY.to_vec())?;
let lp_token = get_token_from_pool(&pool_added.base_pool);
Some(ProtocolComponent {
id: hex::encode(component_id),
@@ -665,3 +659,35 @@ pub fn address_map(
_ => None,
}
}
/// This function makes 3 attempts to confirm / get the LP token address from a pool address.
///
/// 1. We attempt to see if the pool address is a token address itself by calling an ERC 20 func.
/// - Some pools may not be the token themselves
/// 2. Then, we try to ping the `META_REGISTRY` address to see if it has a record of the pool.
/// - Older pools might have been created before the `META_REGISTRY` was created and therefore
/// would have registered much later
/// 3. Finally, we have a hardcoded map of pool address -> token address for some pools.
///
/// If all else fails, we force an `unwrap` to trigger a `panic` so that we can resolve this by
/// adding onto our map of `pool` -> `token` addresses.
fn get_token_from_pool(pool: &Vec<u8>) -> Vec<u8> {
abi::erc20::functions::Name {}
.call(pool.clone())
.and(Some(pool.clone()))
.or_else(|| {
abi::meta_registry::functions::GetLpToken1 { pool: pool.clone() }
.call(META_REGISTRY.to_vec())
})
.or_else(|| {
substreams::log::info!(format!("Using pool tree with pool {}", hex::encode(&pool)));
match hex::encode(&pool).as_str() {
// Curve.fi DAI/USDC/USDT (3Crv)
"bebc44782c7db0a1a60cb6fe97d0b483032ff1c7" => {
hex::decode("6c3F90f043a72FA612cbac8115EE7e52BDe6E490").ok()
}
_ => None,
}
})
.unwrap()
}

View File

@@ -20,7 +20,7 @@ binaries:
modules:
- name: map_components
kind: map
initialBlock: 19933736
initialBlock: 19216042
inputs:
- params: string
- source: sf.ethereum.type.v2.Block
@@ -29,7 +29,7 @@ modules:
- name: store_component_tokens
kind: store
initialBlock: 19933736
initialBlock: 19216042
updatePolicy: set
valueType: string
inputs:
@@ -37,7 +37,7 @@ modules:
- name: map_relative_balances
kind: map
initialBlock: 19933736 # An arbitrary block that should change based on your requirements
initialBlock: 19216042 # An arbitrary block that should change based on your requirements
inputs:
- source: sf.ethereum.type.v2.Block
- store: store_component_tokens
@@ -46,7 +46,7 @@ modules:
- name: store_balances
kind: store
initialBlock: 19933736
initialBlock: 19216042
updatePolicy: add
valueType: bigint
inputs:
@@ -54,7 +54,7 @@ modules:
- name: map_protocol_changes
kind: map
initialBlock: 19933736
initialBlock: 19216042
inputs:
- source: sf.ethereum.type.v2.Block
- map: map_components