Merge pull request #42 from propeller-heads/zz/curve/curve-substreams-v2

Curve Substreams v2
This commit is contained in:
tvinagre
2024-07-19 18:55:39 +02:00
committed by GitHub
19 changed files with 5525 additions and 2293 deletions

6
substreams/Cargo.lock generated
View File

@@ -229,7 +229,7 @@ dependencies = [
[[package]]
name = "ethereum-curve"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"anyhow",
"bytes",
@@ -1097,10 +1097,12 @@ dependencies = [
[[package]]
name = "tycho-substreams"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"ethabi 18.0.0",
"hex",
"itertools 0.12.1",
"num-bigint",
"prost 0.11.9",
"substreams",
"substreams-ethereum",

View File

@@ -1,6 +1,6 @@
[package]
name = "tycho-substreams"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
[dependencies]
@@ -8,4 +8,6 @@ substreams-ethereum.workspace = true
substreams.workspace = true
prost.workspace = true
hex.workspace = true
itertools = "0.12.0"
itertools = "0.12.0"
ethabi.workspace = true
num-bigint = "0.4.4"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
#![allow(clippy::all)]
pub mod erc20;

View File

@@ -21,7 +21,11 @@
//! Through this sequence, the module ensures the transformation from relative to absolute
//! balances is conducted with high fidelity, upholding the integrity of transactional data.
use crate::pb::tycho::evm::v1::{BalanceChange, BlockBalanceDeltas, Transaction};
use crate::{
abi,
pb::tycho::evm::v1::{BalanceChange, BlockBalanceDeltas, Transaction},
prelude::BalanceDelta,
};
use itertools::Itertools;
use std::{collections::HashMap, str::FromStr};
use substreams::{
@@ -29,6 +33,7 @@ use substreams::{
pb::substreams::StoreDeltas,
prelude::{BigInt, StoreAdd},
};
use substreams_ethereum::{pb::eth::v2::TransactionTrace, Event};
/// Stores relative balance changes in an additive manner.
///
@@ -158,6 +163,74 @@ pub fn aggregate_balances_changes(
.collect()
}
/// Extracts balance deltas from a transaction trace based on a given address predicate.
///
/// This function processes the logs within a transaction trace to identify ERC-20 token transfer
/// events. It applies the given predicate to determine which addresses are of interest and extracts
/// the balance changes (deltas) for those addresses. The balance deltas are then returned as a
/// vector.
///
/// # Arguments
///
/// * `tx` - A reference to a `TransactionTrace` which contains the transaction logs and other
/// details.
/// * `address_predicate` - A predicate function that takes two byte slices representing a token and
/// a component and returns a boolean. This function is used to filter which addresses' balance
/// changes should be extracted.
///
/// # Returns
///
/// A vector of `BalanceDelta` structs, each representing a change in balance for a specific address
/// within the transaction.
///
/// # Example
///
/// ```
/// let predicate = |log_address: &[u8], transfer_address: &[u8]| -> bool {
/// // Your predicate logic here, e.g., checking if the address matches a specific pattern.
/// true
/// };
///
/// let balance_deltas = extract_balance_deltas_from_tx(&tx, predicate);
/// ```
///
/// # Notes
///
/// - It is assumed that the transactor is the component. If the protocol follows a different
/// design, this function may not be applicable.
/// - The `address_predicate` is applied to both the log address and the `from`/`to` addresses in
/// the transfer event.
pub fn extract_balance_deltas_from_tx<F: Fn(&[u8], &[u8]) -> bool>(
tx: &TransactionTrace,
address_predicate: F,
) -> Vec<BalanceDelta> {
let mut balance_deltas = vec![];
tx.logs_with_calls()
.for_each(|(log, _)| {
if let Some(transfer) = abi::erc20::events::Transfer::match_and_decode(log) {
let mut create_balance_delta = |transactor: &[u8], delta: BigInt| {
balance_deltas.push(BalanceDelta {
ord: log.ordinal,
tx: Some(tx.into()),
token: log.address.clone(),
delta: delta.to_signed_bytes_be(),
component_id: hex::encode(transactor).into(),
});
};
if address_predicate(&log.address, &transfer.from) {
create_balance_delta(&transfer.from, transfer.value.neg());
}
if address_predicate(&log.address, &transfer.to) {
create_balance_delta(&transfer.to, transfer.value);
}
}
});
balance_deltas
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -1,3 +1,4 @@
mod abi;
pub mod balances;
pub mod contract;
mod mock_store;

View File

@@ -1,6 +1,6 @@
[package]
name = "ethereum-curve"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
[lib]

View File

@@ -13,6 +13,7 @@ abis = {
"MainRegistry": "0x90E00ACe148ca3b23Ac1bC8C240C2a7Dd9c2d7f5",
"MetaPoolFactory": "0xB9fC157394Af804a3578134A6585C0dc9cc990d4",
"CryptoPoolFactory": "0xF18056Bbd320E96A48e3Fbf8bC061322531aac99",
"TwocryptoFactory": "0x98EE851a00abeE0d95D08cF4CA2BdCE32aeaAF7F",
# pool
"Pool": "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7",
"3Pool": "0x5F890841f657d90E081bAbdB532A05996Af79Fe6",

View File

@@ -1,940 +0,0 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "pool",
"type": "address"
},
{
"indexed": false,
"name": "rate_method_id",
"type": "bytes"
}
],
"name": "PoolAdded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "pool",
"type": "address"
}
],
"name": "PoolRemoved",
"type": "event"
},
{
"inputs": [
{
"name": "_address_provider",
"type": "address"
},
{
"name": "_gauge_controller",
"type": "address"
}
],
"outputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
}
],
"name": "find_pool_for_coins",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "i",
"type": "uint256"
}
],
"name": "find_pool_for_coins",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 1521,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_n_coins",
"outputs": [
{
"name": "",
"type": "uint256[2]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 12102,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_coins",
"outputs": [
{
"name": "",
"type": "address[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 12194,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_underlying_coins",
"outputs": [
{
"name": "",
"type": "address[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 7874,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_decimals",
"outputs": [
{
"name": "",
"type": "uint256[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 7966,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_underlying_decimals",
"outputs": [
{
"name": "",
"type": "uint256[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 36992,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_rates",
"outputs": [
{
"name": "",
"type": "uint256[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 20157,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_gauges",
"outputs": [
{
"name": "",
"type": "address[10]"
},
{
"name": "",
"type": "int128[10]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 16583,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_balances",
"outputs": [
{
"name": "",
"type": "uint256[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 162842,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_underlying_balances",
"outputs": [
{
"name": "",
"type": "uint256[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 1927,
"inputs": [
{
"name": "_token",
"type": "address"
}
],
"name": "get_virtual_price_from_lp_token",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 1045,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_A",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 6305,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_parameters",
"outputs": [
{
"name": "A",
"type": "uint256"
},
{
"name": "future_A",
"type": "uint256"
},
{
"name": "fee",
"type": "uint256"
},
{
"name": "admin_fee",
"type": "uint256"
},
{
"name": "future_fee",
"type": "uint256"
},
{
"name": "future_admin_fee",
"type": "uint256"
},
{
"name": "future_owner",
"type": "address"
},
{
"name": "initial_A",
"type": "uint256"
},
{
"name": "initial_A_time",
"type": "uint256"
},
{
"name": "future_A_time",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 1450,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_fees",
"outputs": [
{
"name": "",
"type": "uint256[2]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 36454,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_admin_balances",
"outputs": [
{
"name": "",
"type": "uint256[8]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 27131,
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
}
],
"name": "get_coin_indices",
"outputs": [
{
"name": "",
"type": "int128"
},
{
"name": "",
"type": "int128"
},
{
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 32004,
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
}
],
"name": "estimate_gas_used",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 1900,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "is_meta",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 8323,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_pool_name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 1951,
"inputs": [
{
"name": "_coin",
"type": "address"
}
],
"name": "get_coin_swap_count",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2090,
"inputs": [
{
"name": "_coin",
"type": "address"
},
{
"name": "_index",
"type": "uint256"
}
],
"name": "get_coin_swap_complement",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2011,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "get_pool_asset_type",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 61485845,
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_n_coins",
"type": "uint256"
},
{
"name": "_lp_token",
"type": "address"
},
{
"name": "_rate_info",
"type": "bytes32"
},
{
"name": "_decimals",
"type": "uint256"
},
{
"name": "_underlying_decimals",
"type": "uint256"
},
{
"name": "_has_initial_A",
"type": "bool"
},
{
"name": "_is_v1",
"type": "bool"
},
{
"name": "_name",
"type": "string"
}
],
"name": "add_pool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 31306062,
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_n_coins",
"type": "uint256"
},
{
"name": "_lp_token",
"type": "address"
},
{
"name": "_rate_info",
"type": "bytes32"
},
{
"name": "_decimals",
"type": "uint256"
},
{
"name": "_use_rates",
"type": "uint256"
},
{
"name": "_has_initial_A",
"type": "bool"
},
{
"name": "_is_v1",
"type": "bool"
},
{
"name": "_name",
"type": "string"
}
],
"name": "add_pool_without_underlying",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_n_coins",
"type": "uint256"
},
{
"name": "_lp_token",
"type": "address"
},
{
"name": "_decimals",
"type": "uint256"
},
{
"name": "_name",
"type": "string"
}
],
"name": "add_metapool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_n_coins",
"type": "uint256"
},
{
"name": "_lp_token",
"type": "address"
},
{
"name": "_decimals",
"type": "uint256"
},
{
"name": "_name",
"type": "string"
},
{
"name": "_base_pool",
"type": "address"
}
],
"name": "add_metapool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 779731418758,
"inputs": [
{
"name": "_pool",
"type": "address"
}
],
"name": "remove_pool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 390460,
"inputs": [
{
"name": "_addr",
"type": "address[5]"
},
{
"name": "_amount",
"type": "uint256[2][5]"
}
],
"name": "set_pool_gas_estimates",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 392047,
"inputs": [
{
"name": "_addr",
"type": "address[10]"
},
{
"name": "_amount",
"type": "uint256[10]"
}
],
"name": "set_coin_gas_estimates",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 72629,
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_estimator",
"type": "address"
}
],
"name": "set_gas_estimate_contract",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 400675,
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_liquidity_gauges",
"type": "address[10]"
}
],
"name": "set_liquidity_gauges",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 72667,
"inputs": [
{
"name": "_pool",
"type": "address"
},
{
"name": "_asset_type",
"type": "uint256"
}
],
"name": "set_pool_asset_type",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 1173447,
"inputs": [
{
"name": "_pools",
"type": "address[32]"
},
{
"name": "_asset_types",
"type": "uint256[32]"
}
],
"name": "batch_set_pool_asset_type",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"gas": 2048,
"inputs": [],
"name": "address_provider",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2078,
"inputs": [],
"name": "gauge_controller",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2217,
"inputs": [
{
"name": "arg0",
"type": "uint256"
}
],
"name": "pool_list",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2138,
"inputs": [],
"name": "pool_count",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2168,
"inputs": [],
"name": "coin_count",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2307,
"inputs": [
{
"name": "arg0",
"type": "uint256"
}
],
"name": "get_coin",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2443,
"inputs": [
{
"name": "arg0",
"type": "address"
}
],
"name": "get_pool_from_lp_token",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2473,
"inputs": [
{
"name": "arg0",
"type": "address"
}
],
"name": "get_lp_token",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"gas": 2288,
"inputs": [],
"name": "last_updated",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]

View File

@@ -1,760 +0,0 @@
[
{
"name": "TokenExchange",
"inputs": [
{
"type": "address",
"name": "buyer",
"indexed": true
},
{
"type": "int128",
"name": "sold_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_sold",
"indexed": false
},
{
"type": "int128",
"name": "bought_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_bought",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "TokenExchangeUnderlying",
"inputs": [
{
"type": "address",
"name": "buyer",
"indexed": true
},
{
"type": "int128",
"name": "sold_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_sold",
"indexed": false
},
{
"type": "int128",
"name": "bought_id",
"indexed": false
},
{
"type": "uint256",
"name": "tokens_bought",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "AddLiquidity",
"inputs": [
{
"type": "address",
"name": "provider",
"indexed": true
},
{
"type": "uint256[4]",
"name": "token_amounts",
"indexed": false
},
{
"type": "uint256[4]",
"name": "fees",
"indexed": false
},
{
"type": "uint256",
"name": "invariant",
"indexed": false
},
{
"type": "uint256",
"name": "token_supply",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "RemoveLiquidity",
"inputs": [
{
"type": "address",
"name": "provider",
"indexed": true
},
{
"type": "uint256[4]",
"name": "token_amounts",
"indexed": false
},
{
"type": "uint256[4]",
"name": "fees",
"indexed": false
},
{
"type": "uint256",
"name": "token_supply",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "RemoveLiquidityImbalance",
"inputs": [
{
"type": "address",
"name": "provider",
"indexed": true
},
{
"type": "uint256[4]",
"name": "token_amounts",
"indexed": false
},
{
"type": "uint256[4]",
"name": "fees",
"indexed": false
},
{
"type": "uint256",
"name": "invariant",
"indexed": false
},
{
"type": "uint256",
"name": "token_supply",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "CommitNewAdmin",
"inputs": [
{
"type": "uint256",
"name": "deadline",
"indexed": true,
"unit": "sec"
},
{
"type": "address",
"name": "admin",
"indexed": true
}
],
"anonymous": false,
"type": "event"
},
{
"name": "NewAdmin",
"inputs": [
{
"type": "address",
"name": "admin",
"indexed": true
}
],
"anonymous": false,
"type": "event"
},
{
"name": "CommitNewParameters",
"inputs": [
{
"type": "uint256",
"name": "deadline",
"indexed": true,
"unit": "sec"
},
{
"type": "uint256",
"name": "A",
"indexed": false
},
{
"type": "uint256",
"name": "fee",
"indexed": false
},
{
"type": "uint256",
"name": "admin_fee",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "NewParameters",
"inputs": [
{
"type": "uint256",
"name": "A",
"indexed": false
},
{
"type": "uint256",
"name": "fee",
"indexed": false
},
{
"type": "uint256",
"name": "admin_fee",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"outputs": [],
"inputs": [
{
"type": "address[4]",
"name": "_coins"
},
{
"type": "address[4]",
"name": "_underlying_coins"
},
{
"type": "address",
"name": "_pool_token"
},
{
"type": "uint256",
"name": "_A"
},
{
"type": "uint256",
"name": "_fee"
}
],
"constant": false,
"payable": false,
"type": "constructor"
},
{
"name": "get_virtual_price",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 1570535
},
{
"name": "calc_token_amount",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "uint256[4]",
"name": "amounts"
},
{
"type": "bool",
"name": "deposit"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 6103471
},
{
"name": "add_liquidity",
"outputs": [],
"inputs": [
{
"type": "uint256[4]",
"name": "amounts"
},
{
"type": "uint256",
"name": "min_mint_amount"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 9331701
},
{
"name": "get_dy",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 3489637
},
{
"name": "get_dy_underlying",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 3489467
},
{
"name": "exchange",
"outputs": [],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
},
{
"type": "uint256",
"name": "min_dy"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 7034253
},
{
"name": "exchange_underlying",
"outputs": [],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
},
{
"type": "uint256",
"name": "min_dy"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 7050488
},
{
"name": "remove_liquidity",
"outputs": [],
"inputs": [
{
"type": "uint256",
"name": "_amount"
},
{
"type": "uint256[4]",
"name": "min_amounts"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 241191
},
{
"name": "remove_liquidity_imbalance",
"outputs": [],
"inputs": [
{
"type": "uint256[4]",
"name": "amounts"
},
{
"type": "uint256",
"name": "max_burn_amount"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 9330864
},
{
"name": "commit_new_parameters",
"outputs": [],
"inputs": [
{
"type": "uint256",
"name": "amplification"
},
{
"type": "uint256",
"name": "new_fee"
},
{
"type": "uint256",
"name": "new_admin_fee"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 146045
},
{
"name": "apply_new_parameters",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 133452
},
{
"name": "revert_new_parameters",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 21775
},
{
"name": "commit_transfer_ownership",
"outputs": [],
"inputs": [
{
"type": "address",
"name": "_owner"
}
],
"constant": false,
"payable": false,
"type": "function",
"gas": 74452
},
{
"name": "apply_transfer_ownership",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 60508
},
{
"name": "revert_transfer_ownership",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 21865
},
{
"name": "withdraw_admin_fees",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 23448
},
{
"name": "kill_me",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 37818
},
{
"name": "unkill_me",
"outputs": [],
"inputs": [],
"constant": false,
"payable": false,
"type": "function",
"gas": 21955
},
{
"name": "coins",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "arg0"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 2130
},
{
"name": "underlying_coins",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "arg0"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 2160
},
{
"name": "balances",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "arg0"
}
],
"constant": true,
"payable": false,
"type": "function",
"gas": 2190
},
{
"name": "A",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2021
},
{
"name": "fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2051
},
{
"name": "admin_fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2081
},
{
"name": "owner",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2111
},
{
"name": "admin_actions_deadline",
"outputs": [
{
"type": "uint256",
"unit": "sec",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2141
},
{
"name": "transfer_ownership_deadline",
"outputs": [
{
"type": "uint256",
"unit": "sec",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2171
},
{
"name": "future_A",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2201
},
{
"name": "future_fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2231
},
{
"name": "future_admin_fee",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2261
},
{
"name": "future_owner",
"outputs": [
{
"type": "address",
"name": ""
}
],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 2291
}
]

View File

@@ -1,11 +1,9 @@
#![allow(clippy::all)]
pub mod crypto_pool_factory;
pub mod stableswap_factory;
pub mod susd;
pub mod crypto_swap_ng_factory;
pub mod meta_registry;
pub mod tricrypto_factory;
pub mod main_registry;
pub mod twocrypto_factory;
pub mod erc20;
pub mod meta_pool_factory;
pub mod crypto_swap_registry;

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,7 @@ pub const META_POOL_FACTORY: [u8; 20] = hex!("B9fC157394Af804a3578134A6585C0dc9c
pub const META_POOL_FACTORY_OLD: [u8; 20] = hex!("0959158b6040D32d04c301A72CBFD6b39E21c9AE");
pub const CRYPTO_SWAP_NG_FACTORY: [u8; 20] = hex!("6A8cbed756804B16E05E741eDaBd5cB544AE21bf");
pub const TRICRYPTO_FACTORY: [u8; 20] = hex!("0c0e5f2fF0ff18a3be9b835635039256dC4B4963");
pub const TWOCRYPTO_FACTORY: [u8; 20] = hex!("98ee851a00abee0d95d08cf4ca2bdce32aeaaf7f");
pub const STABLESWAP_FACTORY: [u8; 20] = hex!("4F8846Ae9380B90d2E71D5e3D042dff3E7ebb40d");
// Important addresses

View File

@@ -10,13 +10,11 @@ use substreams::{
use substreams_ethereum::pb::eth;
use crate::{
pool_changes::{emit_deltas, emit_eth_deltas},
pool_factories,
pools::emit_specific_pools,
};
use crate::{pool_changes::emit_eth_deltas, pool_factories, pools::emit_specific_pools};
use tycho_substreams::{
balances::store_balance_changes, contract::extract_contract_changes, prelude::*,
balances::{extract_balance_deltas_from_tx, store_balance_changes},
contract::extract_contract_changes,
prelude::*,
};
/// This struct purely exists to spoof the `PartialEq` trait for `Transaction` so we can use it in
@@ -115,7 +113,15 @@ pub fn map_relative_balances(
.flat_map(|tx| {
emit_eth_deltas(tx, &tokens_store)
.into_iter()
.chain(emit_deltas(tx, &tokens_store))
.chain(extract_balance_deltas_from_tx(tx, |token, transactor| {
let pool_key = format!("pool:{}", hex::encode(transactor));
if let Some(tokens) = tokens_store.get_last(pool_key) {
let token_id = hex::encode(token);
tokens.split(':').any(|t| t == token_id)
} else {
false
}
}))
})
.collect();

View File

@@ -2,13 +2,10 @@ use substreams::{
scalar::BigInt,
store::{StoreGet, StoreGetString},
};
use substreams_ethereum::{pb::eth::v2::TransactionTrace, Event};
use substreams_ethereum::pb::eth::v2::TransactionTrace;
use tycho_substreams::prelude::*;
use crate::{
abi,
consts::{ETH_ADDRESS, WETH_ADDRESS},
};
use crate::consts::{ETH_ADDRESS, WETH_ADDRESS};
fn get_pool_tokens(pool_address: &Vec<u8>, tokens_store: &StoreGetString) -> Option<Vec<String>> {
let pool_key = format!("pool:{}", hex::encode(pool_address));
@@ -21,42 +18,6 @@ fn get_pool_tokens(pool_address: &Vec<u8>, tokens_store: &StoreGetString) -> Opt
)
}
/// Tracks `Transfers` in and out of tracked pools if it matches the specific tokens.
pub fn emit_deltas(tx: &TransactionTrace, tokens_store: &StoreGetString) -> Vec<BalanceDelta> {
tx.logs_with_calls()
.filter_map(|(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) {
(hex::encode(&transfer.to), pool_tokens, true)
} else if let Some(pool_tokens) = get_pool_tokens(&transfer.from, tokens_store) {
(hex::encode(&transfer.from), pool_tokens, false)
} else {
return None;
};
let token_id = hex::encode(log.address.clone());
if pool_tokens.contains(&token_id) {
let delta = if is_incoming { transfer.value } else { transfer.value * -1 };
Some(BalanceDelta {
ord: log.ordinal,
tx: Some(Transaction {
to: tx.to.clone(),
from: tx.from.clone(),
hash: tx.hash.clone(),
index: tx.index.into(),
}),
token: hex::decode(token_id).unwrap(),
delta: delta.to_signed_bytes_be(),
component_id: component_id.into(),
})
} else {
None
}
})
.collect::<Vec<_>>()
}
/// Tracks ETH balance changes in and out of tracked pools if it matches the specific tokens.
/// Note: Pools might report as WETH or ETH. Some pools might even accept either WETH or ETH and
/// convert them on the fly (checkout pools with `WETHOptimized` in the name). It's a bit tricky

View File

@@ -566,7 +566,11 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens: pool_added.coins.into(),
tokens: pool_added
.coins
.into_iter()
.filter(|token| *token != [0; 20])
.collect(),
contracts: vec![component_id.into()],
static_att: vec![
Attribute {
@@ -677,6 +681,54 @@ pub fn address_map(
None
}
}
TWOCRYPTO_FACTORY => {
if let Some(pool_added) =
abi::twocrypto_factory::events::TwocryptoPoolDeployed::match_and_decode(log)
{
Some(ProtocolComponent {
id: hex::encode(&pool_added.pool),
tx: Some(Transaction {
to: tx.to.clone(),
from: tx.from.clone(),
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens: pool_added.coins.into(),
contracts: vec![pool_added.pool],
static_att: vec![
Attribute {
name: "pool_type".into(),
value: "twocrypto".into(),
change: ChangeType::Creation.into(),
},
Attribute {
name: "name".into(),
value: pool_added.name.into(),
change: ChangeType::Creation.into(),
},
Attribute {
name: "factory_name".into(),
value: "twocrypto_factory".into(),
change: ChangeType::Creation.into(),
},
Attribute {
name: "factory".into(),
value: address_to_bytes_with_0x(&TWOCRYPTO_FACTORY),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
name: "curve_pool".into(),
financial_type: FinancialType::Swap.into(),
attribute_schema: Vec::new(),
implementation_type: ImplementationType::Vm.into(),
}),
})
} else {
None
}
}
_ => None,
}
}
@@ -706,6 +758,10 @@ fn get_token_from_pool(pool: &Vec<u8>) -> Vec<u8> {
"bebc44782c7db0a1a60cb6fe97d0b483032ff1c7" => {
hex::decode("6c3F90f043a72FA612cbac8115EE7e52BDe6E490").ok()
}
// Curve.fi renBTC/wBTC/sBTC (crvRenWSBTC)
"7fc77b5c7614e1533320ea6ddc2eb61fa00a9714" => {
hex::decode("075b1bb99792c9e1041ba13afef80c91a1e70fb3").ok()
}
// Placeholder if we can't find the token. It will help us to detect these missing
// token easily with a SQL query.
_ => hex::decode("1111111111111111111111111111111111111111").ok(),

View File

@@ -1,7 +1,7 @@
specVersion: v0.1.0
package:
name: "substreams_curve"
version: v0.1.0
version: v0.2.0
protobuf:
files:

View File

@@ -104,3 +104,38 @@ tests:
- "0x0000000000000000000000000000000000000000"
static_attributes:
creation_tx: "0x2bd59c19f993b83729fb23498f897a58567c6f0b3ee2f00613ba515a7b19fe23"
- name: test_twocrypto_factory_creation
start_block: 19760009
stop_block: 19763634
expected_state:
protocol_components:
- id: "0x011e998d2d794424de95935d55a6ca81822ecb2b"
tokens:
- "0x6c4a8973e6633da2da7187669479c27830c7b1c4"
- "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
static_attributes:
creation_tx: "0x412b745a9467aed14f22d2a4cc30651939872d19cee65053f14dd3eb9d488003"
- id: "0x19d2b5ce188ca60790755204691e38102749297b"
tokens:
- "0x6c4a8973e6633da2da7187669479c27830c7b1c4"
- "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
static_attributes:
creation_tx: "0x61118d9903f8344e5971d1e7c781f76e855996408dac979d3a4971cefafa6587"
- id: "0xb3341ca63b6cecf1e1a0d1a99bf0587f4c305652"
tokens:
- "0x6c4a8973e6633da2da7187669479c27830c7b1c4"
- "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
static_attributes:
creation_tx: "0xc69332294313b3a8f260e0d5b6a50f0d83707f715fbd8016c32ca61a39ce7ad5"
- id: "0x99ca0fbaa278cd62e26f0e9b6d167b07d1f0d51b"
tokens:
- "0x6c4a8973e6633da2da7187669479c27830c7b1c4"
- "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
static_attributes:
creation_tx: "0xf2b0c697161f08384c642297e01b3a35f7ec00dd3871d4237a16ae4bb8a1ca99"
- id: "0xde73e407efc75edbafc5bcd62ebb1e7a9b38ebcd"
tokens:
- "0x0d86883faf4ffd7aeb116390af37746f45b6f378"
- "0x78da5799cf427fee11e9996982f4150ece7a99a7"
static_attributes:
creation_tx: "0xd4ad7efdcc16d797dd3494ba02b377da4127fd5b1bd25089858b66e5a7e456ab"