valdiate: 3pool and steth-eth

This commit is contained in:
0xMochan
2024-05-08 15:56:41 -05:00
parent 7c49d3e813
commit ec07703090
6 changed files with 259 additions and 757 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,23 @@
[
{
"name": "3pool",
"address": "bEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7",
"tx_hash": "20793bbf260912aae189d5d261ff003c9b9166da8191d8f9d63ff1c7722f3ac6",
"address": "bebc44782c7db0a1a60cb6fe97d0b483032ff1c7",
"tx_hash": "e90adc0e0a1ae9dde6c240b348adef761444e61f4194245a2096f7ca8310ac2f",
"tokens": [
"6b175474e89094c44da98b954eedeac495271d0f",
"a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"dac17f958d2ee523a2206206994597c13d831ec7"
],
"attributes": {}
},
{
"name": "steth",
"address": "dc24316b9ae028f1497c275eb9192a3ea0f67022",
"tx_hash": "d844051b63ce310f0f354e29e8c7f550a02fcd3bc642592a2eae6a2804e17d9c",
"tokens": [
"EeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"ae7ab96520DE3A18E5e111B5EaAb095312D7fE84"
],
"attributes": {}
}
]

View File

@@ -4,6 +4,7 @@ use anyhow::Result;
use itertools::Itertools;
use substreams::{
pb::substreams::StoreDeltas,
scalar::BigInt,
store::{
StoreAdd, StoreAddBigInt, StoreAddInt64, StoreGet, StoreGetInt64, StoreGetString, StoreNew,
StoreSet, StoreSetString,
@@ -179,7 +180,7 @@ pub fn map_protocol_changes(
.extend_from_slice(&tx_component.components);
});
// Balance changes are gathered by the `StoreDelta` based on `PoolBalanceChanged` creating
// Balance changes are gathered by the `StoreDelta` based on `TokenExchange`, etc. creating
// `BalanceDeltas`. We essentially just process the changes that occured to the `store` this
// block. Then, these balance changes are merged onto the existing map of tx contract changes,
// inserting a new one if it doesn't exist.
@@ -188,14 +189,16 @@ pub fn map_protocol_changes(
.into_iter()
.zip(deltas.balance_deltas)
.map(|(store_delta, balance_delta)| {
let pool_id = key::segment_at(&store_delta.key, 1);
let token_id = key::segment_at(&store_delta.key, 3);
let new_value_string = String::from_utf8_lossy(&store_delta.new_value).to_string();
(
balance_delta.tx.unwrap(),
BalanceChange {
token: hex::decode(token_id).expect("Token ID not valid hex"),
balance: store_delta.new_value,
component_id: hex::decode(pool_id).expect("Token ID not valid hex"),
token: balance_delta.token,
balance: BigInt::try_from(new_value_string)
.unwrap()
.to_signed_bytes_be(),
component_id: hex::decode(balance_delta.component_id)
.expect("Pool ID not valid hex"),
},
)
})

View File

@@ -1,4 +1,5 @@
use substreams::{
hex,
scalar::BigInt,
store::{StoreGet, StoreGetInt64, StoreGetString},
};
@@ -37,9 +38,10 @@ pub fn emit_deltas(
.collect::<Vec<_>>();
if let Some(event) = abi::pool::events::TokenExchange::match_and_decode(log) {
token_change_deltas(event, log)
token_change_deltas(tokens, event, log)
} else if let Some(event) = abi::pool_3pool::events::TokenExchange::match_and_decode(log) {
token_change_deltas(
tokens,
abi::pool::events::TokenExchange {
sold_id: event.sold_id,
bought_id: event.bought_id,
@@ -51,6 +53,7 @@ pub fn emit_deltas(
)
} else if let Some(event) = abi::pool_steth::events::TokenExchange::match_and_decode(log) {
token_change_deltas(
tokens,
abi::pool::events::TokenExchange {
sold_id: event.sold_id,
bought_id: event.bought_id,
@@ -62,6 +65,7 @@ pub fn emit_deltas(
)
} else if let Some(event) = abi::pool_tricrypto::events::TokenExchange::match_and_decode(log) {
token_change_deltas(
tokens,
abi::pool::events::TokenExchange {
sold_id: event.sold_id,
bought_id: event.bought_id,
@@ -94,24 +98,27 @@ pub fn emit_deltas(
}
fn token_change_deltas(
tokens: Vec<String>,
event: abi::pool::events::TokenExchange,
log: LogView<'_>,
) -> Option<Vec<BalanceDelta>> {
let tokens_bought_delta: BigInt = event.tokens_bought * -1;
let sold_token_id = &tokens[event.sold_id.to_u64() as usize];
let bought_token_id = &tokens[event.bought_id.to_u64() as usize];
Some(vec![
BalanceDelta {
ord: log.log.ordinal,
tx: Some(tx_from_log(&log)),
token: event.sold_id.to_signed_bytes_be(),
token: hex::decode(sold_token_id.clone()).unwrap(),
delta: event.tokens_sold.to_signed_bytes_be(),
component_id: log.address().into(),
component_id: hex::encode(log.address()).into(),
},
BalanceDelta {
ord: log.log.ordinal,
tx: Some(tx_from_log(&log)),
token: event.bought_id.to_signed_bytes_be(),
token: hex::decode(bought_token_id.clone()).unwrap(),
delta: tokens_bought_delta.to_signed_bytes_be(),
component_id: log.address().into(),
component_id: hex::encode(log.address()).into(),
},
])
}
@@ -128,9 +135,9 @@ fn add_liquidity_deltas(
.map(move |(token_amount, token_id)| BalanceDelta {
ord: log.log.ordinal,
tx: Some(tx_from_log(&log)),
token: token_id.as_str().into(),
token: hex::decode(token_id).unwrap(),
delta: token_amount.to_signed_bytes_be(),
component_id: log.address().into(),
component_id: hex::encode(log.address()).into(),
})
.collect::<Vec<_>>(),
)
@@ -148,9 +155,9 @@ fn remove_liquidity_deltas(
.map(move |(token_amount, token_id)| BalanceDelta {
ord: log.log.ordinal,
tx: Some(tx_from_log(&log)),
token: token_id.as_str().into(),
token: hex::decode(token_id).unwrap(),
delta: token_amount.to_signed_bytes_be(),
component_id: log.address().into(),
component_id: hex::encode(log.address()).into(),
})
.collect::<Vec<_>>(),
)

View File

@@ -24,7 +24,7 @@ struct PoolQueryParams {
/// Static attributes are defined as a vector of tuples with the name and value of the attribute.
/// These contain things like the pool type, specific pool fees, etc. You can see
/// `pool_factories.rs` for an example of the modern curve pool attributes and also the ones chosen
/// for 3pool, etc.
/// for 3pool, etc.
///
/// This function can error based on some basic parsing errors and deeper down hex decoding errors
/// if various addresses are not formatted properly.

View File

@@ -19,7 +19,7 @@ binaries:
modules:
- name: map_components
kind: map
initialBlock: 10809473
initialBlock: 19355224
inputs:
- params: string
- source: sf.ethereum.type.v2.Block
@@ -28,7 +28,7 @@ modules:
- name: store_components
kind: store
initialBlock: 10809473
initialBlock: 19355224
updatePolicy: add
valueType: int64
inputs:
@@ -36,7 +36,7 @@ modules:
- name: store_component_tokens
kind: store
initialBlock: 10809473
initialBlock: 19355224
updatePolicy: set
valueType: string
inputs:
@@ -44,7 +44,7 @@ modules:
- name: map_relative_balances
kind: map
initialBlock: 10809473 # An arbitrary block that should change based on your requirements
initialBlock: 19355224 # An arbitrary block that should change based on your requirements
inputs:
- source: sf.ethereum.type.v2.Block
- store: store_components
@@ -54,7 +54,7 @@ modules:
- name: store_balances
kind: store
initialBlock: 10809473
initialBlock: 19355224
updatePolicy: add
valueType: bigint
inputs:
@@ -62,7 +62,7 @@ modules:
- name: map_protocol_changes
kind: map
initialBlock: 10809473
initialBlock: 19355224
inputs:
- source: sf.ethereum.type.v2.Block
- map: map_components