From 7c75c8d3d60561fb21a32a5e255088007f572b81 Mon Sep 17 00:00:00 2001 From: 0xMochan Date: Thu, 11 Apr 2024 19:41:56 -0500 Subject: [PATCH] Initial `pools.rs` function for handling custom parameters --- substreams/Cargo.lock | 19 + substreams/ethereum-curve/Cargo.toml | 2 + .../ethereum-curve/abi/pools/3pool.json | 1356 +++++++++++++++++ substreams/ethereum-curve/src/lib.rs | 1 + substreams/ethereum-curve/src/modules.rs | 11 +- .../ethereum-curve/src/pool_factories.rs | 63 +- substreams/ethereum-curve/src/pools.rs | 80 + substreams/ethereum-curve/substreams.yaml | 12 +- substreams/ethereum-maverick/src/modules.rs | 9 +- 9 files changed, 1525 insertions(+), 28 deletions(-) create mode 100644 substreams/ethereum-curve/abi/pools/3pool.json create mode 100644 substreams/ethereum-curve/src/pools.rs diff --git a/substreams/Cargo.lock b/substreams/Cargo.lock index 6819137..55336e5 100644 --- a/substreams/Cargo.lock +++ b/substreams/Cargo.lock @@ -241,6 +241,8 @@ dependencies = [ "num-bigint", "prost 0.11.9", "prost-types 0.12.3", + "serde", + "serde_qs", "substreams", "substreams-ethereum", "tycho-substreams", @@ -572,6 +574,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "petgraph" version = "0.6.4" @@ -869,6 +877,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_qs" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd34f36fe4c5ba9654417139a9b3a20d2e1de6012ee678ad14d240c22c78d8d6" +dependencies = [ + "percent-encoding", + "serde", + "thiserror", +] + [[package]] name = "sha3" version = "0.10.8" diff --git a/substreams/ethereum-curve/Cargo.toml b/substreams/ethereum-curve/Cargo.toml index 5cd96fc..eefe0ed 100644 --- a/substreams/ethereum-curve/Cargo.toml +++ b/substreams/ethereum-curve/Cargo.toml @@ -20,6 +20,8 @@ anyhow = "1.0.75" num-bigint = "0.4.4" itertools = "0.12.0" tycho-substreams.workspace = true +serde = { version = "1.0", features = ["derive"] } +serde_qs = "0.13.0" [build-dependencies] anyhow = "1" diff --git a/substreams/ethereum-curve/abi/pools/3pool.json b/substreams/ethereum-curve/abi/pools/3pool.json new file mode 100644 index 0000000..e18b62c --- /dev/null +++ b/substreams/ethereum-curve/abi/pools/3pool.json @@ -0,0 +1,1356 @@ +[ + { + "name": "Transfer", + "inputs": [ + { + "type": "address", + "name": "sender", + "indexed": true + }, + { + "type": "address", + "name": "receiver", + "indexed": true + }, + { + "type": "uint256", + "name": "value", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "Approval", + "inputs": [ + { + "type": "address", + "name": "owner", + "indexed": true + }, + { + "type": "address", + "name": "spender", + "indexed": true + }, + { + "type": "uint256", + "name": "value", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "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[2]", + "name": "token_amounts", + "indexed": false + }, + { + "type": "uint256[2]", + "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[2]", + "name": "token_amounts", + "indexed": false + }, + { + "type": "uint256[2]", + "name": "fees", + "indexed": false + }, + { + "type": "uint256", + "name": "token_supply", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RemoveLiquidityOne", + "inputs": [ + { + "type": "address", + "name": "provider", + "indexed": true + }, + { + "type": "uint256", + "name": "token_amount", + "indexed": false + }, + { + "type": "uint256", + "name": "coin_amount", + "indexed": false + }, + { + "type": "uint256", + "name": "token_supply", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RemoveLiquidityImbalance", + "inputs": [ + { + "type": "address", + "name": "provider", + "indexed": true + }, + { + "type": "uint256[2]", + "name": "token_amounts", + "indexed": false + }, + { + "type": "uint256[2]", + "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 + }, + { + "type": "address", + "name": "admin", + "indexed": true + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "NewAdmin", + "inputs": [ + { + "type": "address", + "name": "admin", + "indexed": true + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "CommitNewFee", + "inputs": [ + { + "type": "uint256", + "name": "deadline", + "indexed": true + }, + { + "type": "uint256", + "name": "fee", + "indexed": false + }, + { + "type": "uint256", + "name": "admin_fee", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "NewFee", + "inputs": [ + { + "type": "uint256", + "name": "fee", + "indexed": false + }, + { + "type": "uint256", + "name": "admin_fee", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RampA", + "inputs": [ + { + "type": "uint256", + "name": "old_A", + "indexed": false + }, + { + "type": "uint256", + "name": "new_A", + "indexed": false + }, + { + "type": "uint256", + "name": "initial_time", + "indexed": false + }, + { + "type": "uint256", + "name": "future_time", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StopRampA", + "inputs": [ + { + "type": "uint256", + "name": "A", + "indexed": false + }, + { + "type": "uint256", + "name": "t", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "outputs": [], + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "name": "initialize", + "outputs": [], + "inputs": [ + { + "type": "string", + "name": "_name" + }, + { + "type": "string", + "name": "_symbol" + }, + { + "type": "address", + "name": "_coin" + }, + { + "type": "uint256", + "name": "_decimals" + }, + { + "type": "uint256", + "name": "_A" + }, + { + "type": "uint256", + "name": "_fee" + }, + { + "type": "address", + "name": "_admin" + } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 470049 + }, + { + "name": "decimals", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 291 + }, + { + "name": "transfer", + "outputs": [ + { + "type": "bool", + "name": "" + } + ], + "inputs": [ + { + "type": "address", + "name": "_to" + }, + { + "type": "uint256", + "name": "_value" + } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 75402 + }, + { + "name": "transferFrom", + "outputs": [ + { + "type": "bool", + "name": "" + } + ], + "inputs": [ + { + "type": "address", + "name": "_from" + }, + { + "type": "address", + "name": "_to" + }, + { + "type": "uint256", + "name": "_value" + } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 112037 + }, + { + "name": "approve", + "outputs": [ + { + "type": "bool", + "name": "" + } + ], + "inputs": [ + { + "type": "address", + "name": "_spender" + }, + { + "type": "uint256", + "name": "_value" + } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37854 + }, + { + "name": "get_previous_balances", + "outputs": [ + { + "type": "uint256[2]", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2254 + }, + { + "name": "get_balances", + "outputs": [ + { + "type": "uint256[2]", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2284 + }, + { + "name": "get_twap_balances", + "outputs": [ + { + "type": "uint256[2]", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256[2]", + "name": "_first_balances" + }, + { + "type": "uint256[2]", + "name": "_last_balances" + }, + { + "type": "uint256", + "name": "_time_elapsed" + } + ], + "stateMutability": "view", + "type": "function", + "gas": 1522 + }, + { + "name": "get_price_cumulative_last", + "outputs": [ + { + "type": "uint256[2]", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2344 + }, + { + "name": "admin_fee", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 621 + }, + { + "name": "A", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 5859 + }, + { + "name": "A_precise", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 5821 + }, + { + "name": "get_virtual_price", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 1011891 + }, + { + "name": "calc_token_amount", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256[2]", + "name": "_amounts" + }, + { + "type": "bool", + "name": "_is_deposit" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "calc_token_amount", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256[2]", + "name": "_amounts" + }, + { + "type": "bool", + "name": "_is_deposit" + }, + { + "type": "bool", + "name": "_previous" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "add_liquidity", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256[2]", + "name": "_amounts" + }, + { + "type": "uint256", + "name": "_min_mint_amount" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "add_liquidity", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256[2]", + "name": "_amounts" + }, + { + "type": "uint256", + "name": "_min_mint_amount" + }, + { + "type": "address", + "name": "_receiver" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "get_dy", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "get_dy", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + }, + { + "type": "uint256[2]", + "name": "_balances" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "get_dy_underlying", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "get_dy_underlying", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + }, + { + "type": "uint256[2]", + "name": "_balances" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "exchange", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + }, + { + "type": "uint256", + "name": "min_dy" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "exchange", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + }, + { + "type": "uint256", + "name": "min_dy" + }, + { + "type": "address", + "name": "_receiver" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "exchange_underlying", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + }, + { + "type": "uint256", + "name": "min_dy" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "exchange_underlying", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "int128", + "name": "i" + }, + { + "type": "int128", + "name": "j" + }, + { + "type": "uint256", + "name": "dx" + }, + { + "type": "uint256", + "name": "min_dy" + }, + { + "type": "address", + "name": "_receiver" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "remove_liquidity", + "outputs": [ + { + "type": "uint256[2]", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "_burn_amount" + }, + { + "type": "uint256[2]", + "name": "_min_amounts" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "remove_liquidity", + "outputs": [ + { + "type": "uint256[2]", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "_burn_amount" + }, + { + "type": "uint256[2]", + "name": "_min_amounts" + }, + { + "type": "address", + "name": "_receiver" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "remove_liquidity_imbalance", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256[2]", + "name": "_amounts" + }, + { + "type": "uint256", + "name": "_max_burn_amount" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "remove_liquidity_imbalance", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256[2]", + "name": "_amounts" + }, + { + "type": "uint256", + "name": "_max_burn_amount" + }, + { + "type": "address", + "name": "_receiver" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "calc_withdraw_one_coin", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "_burn_amount" + }, + { + "type": "int128", + "name": "i" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "calc_withdraw_one_coin", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "_burn_amount" + }, + { + "type": "int128", + "name": "i" + }, + { + "type": "bool", + "name": "_previous" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "name": "remove_liquidity_one_coin", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "_burn_amount" + }, + { + "type": "int128", + "name": "i" + }, + { + "type": "uint256", + "name": "_min_received" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "remove_liquidity_one_coin", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "_burn_amount" + }, + { + "type": "int128", + "name": "i" + }, + { + "type": "uint256", + "name": "_min_received" + }, + { + "type": "address", + "name": "_receiver" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "ramp_A", + "outputs": [], + "inputs": [ + { + "type": "uint256", + "name": "_future_A" + }, + { + "type": "uint256", + "name": "_future_time" + } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 152464 + }, + { + "name": "stop_ramp_A", + "outputs": [], + "inputs": [], + "stateMutability": "nonpayable", + "type": "function", + "gas": 149225 + }, + { + "name": "admin_balances", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "i" + } + ], + "stateMutability": "view", + "type": "function", + "gas": 3601 + }, + { + "name": "withdraw_admin_fees", + "outputs": [], + "inputs": [], + "stateMutability": "nonpayable", + "type": "function", + "gas": 11347 + }, + { + "name": "admin", + "outputs": [ + { + "type": "address", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2141 + }, + { + "name": "coins", + "outputs": [ + { + "type": "address", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "arg0" + } + ], + "stateMutability": "view", + "type": "function", + "gas": 2280 + }, + { + "name": "balances", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "uint256", + "name": "arg0" + } + ], + "stateMutability": "view", + "type": "function", + "gas": 2310 + }, + { + "name": "fee", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2231 + }, + { + "name": "block_timestamp_last", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2261 + }, + { + "name": "initial_A", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2291 + }, + { + "name": "future_A", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2321 + }, + { + "name": "initial_A_time", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2351 + }, + { + "name": "future_A_time", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2381 + }, + { + "name": "name", + "outputs": [ + { + "type": "string", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 8813 + }, + { + "name": "symbol", + "outputs": [ + { + "type": "string", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 7866 + }, + { + "name": "balanceOf", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "address", + "name": "arg0" + } + ], + "stateMutability": "view", + "type": "function", + "gas": 2686 + }, + { + "name": "allowance", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [ + { + "type": "address", + "name": "arg0" + }, + { + "type": "address", + "name": "arg1" + } + ], + "stateMutability": "view", + "type": "function", + "gas": 2931 + }, + { + "name": "totalSupply", + "outputs": [ + { + "type": "uint256", + "name": "" + } + ], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2531 + } +] \ No newline at end of file diff --git a/substreams/ethereum-curve/src/lib.rs b/substreams/ethereum-curve/src/lib.rs index c8233b2..3d610b6 100644 --- a/substreams/ethereum-curve/src/lib.rs +++ b/substreams/ethereum-curve/src/lib.rs @@ -1,3 +1,4 @@ mod abi; pub mod modules; mod pool_factories; +mod pools; diff --git a/substreams/ethereum-curve/src/modules.rs b/substreams/ethereum-curve/src/modules.rs index db95c6b..3372b32 100644 --- a/substreams/ethereum-curve/src/modules.rs +++ b/substreams/ethereum-curve/src/modules.rs @@ -16,7 +16,7 @@ use substreams_ethereum::{block_view::LogView, pb::eth}; use substreams_ethereum::Event; -use crate::{abi, pool_factories}; +use crate::{abi, pool_factories, pools::emit_specific_pools}; use tycho_substreams::{ balances::store_balance_changes, contract::extract_contract_changes, prelude::*, }; @@ -42,14 +42,17 @@ fn tx_from_log(log: &LogView) -> Transaction { } #[substreams::handlers::map] -pub fn map_components(block: eth::v2::Block) -> Result { +pub fn map_components( + params: String, + block: eth::v2::Block, +) -> Result { // Gather contract changes by indexing `PoolCreated` events and analysing the `Create` call // We store these as a hashmap by tx hash since we need to agg by tx hash later Ok(BlockTransactionProtocolComponents { tx_components: block .transactions() .filter_map(|tx| { - let components = tx + let mut components = tx .logs_with_calls() .filter(|(_, call)| !call.call.state_reverted) .filter_map(|(log, call)| { @@ -66,6 +69,8 @@ pub fn map_components(block: eth::v2::Block) -> Result>(); + components.extend(emit_specific_pools(¶ms, &block).expect("yur")); + if !components.is_empty() { Some(TransactionProtocolComponents { tx: Some(Transaction { diff --git a/substreams/ethereum-curve/src/pool_factories.rs b/substreams/ethereum-curve/src/pool_factories.rs index 02a92ad..35ff6d9 100644 --- a/substreams/ethereum-curve/src/pool_factories.rs +++ b/substreams/ethereum-curve/src/pool_factories.rs @@ -98,7 +98,7 @@ pub fn address_map( index: tx.index.into(), }), tokens: trimmed_coins, - contracts: vec![call_address.into(), pool_added.pool], + contracts: vec![pool_added.pool], static_att: vec![ Attribute { name: "pool_type".into(), @@ -117,7 +117,12 @@ pub fn address_map( }, ], change: ChangeType::Creation.into(), - ..Default::default() + protocol_type: Some(ProtocolType { + name: "curve_pool".into(), + financial_type: FinancialType::Swap.into(), + attribute_schema: Vec::new(), + implementation_type: ImplementationType::Vm.into(), + }), }) } MAIN_REGISTRY => { @@ -186,7 +191,7 @@ pub fn address_map( index: tx.index.into(), }), tokens: trimmed_coins, - contracts: vec![call_address.into(), pool_created.pool], + contracts: vec![pool_created.pool], static_att: vec![ Attribute { name: "pool_type".into(), @@ -205,7 +210,12 @@ pub fn address_map( }, ], change: ChangeType::Creation.into(), - ..Default::default() + protocol_type: Some(ProtocolType { + name: "curve_pool".into(), + financial_type: FinancialType::Swap.into(), + attribute_schema: Vec::new(), + implementation_type: ImplementationType::Vm.into(), + }), }) } CRYPTO_POOL_FACTORY => { @@ -214,8 +224,10 @@ pub fn address_map( let deploy_call = abi::crypto_pool_factory::functions::DeployPool::match_and_decode(call)?; + let component_id = &call.return_data[12..]; + Some(ProtocolComponent { - id: hex::encode(&call.return_data), + id: format!("0x{0}", hex::encode(component_id)), tx: Some(Transaction { to: tx.to.clone(), from: tx.from.clone(), @@ -223,7 +235,7 @@ pub fn address_map( index: tx.index.into(), }), tokens: pool_added.coins.into(), - contracts: vec![call_address.into(), call.return_data.clone()], + contracts: vec![component_id.into()], static_att: vec![ Attribute { name: "pool_type".into(), @@ -294,7 +306,12 @@ pub fn address_map( }, ], change: ChangeType::Creation.into(), - ..Default::default() + protocol_type: Some(ProtocolType { + name: "curve_pool".into(), + financial_type: FinancialType::Swap.into(), + attribute_schema: Vec::new(), + implementation_type: ImplementationType::Vm.into(), + }), }) } META_POOL_FACTORY => { @@ -333,8 +350,11 @@ pub fn address_map( call, ) })?; + + let component_id = &call.return_data[12..]; + Some(ProtocolComponent { - id: hex::encode(&call.return_data), + id: format!("0x{0}", hex::encode(component_id)), tx: Some(Transaction { to: tx.to.clone(), from: tx.from.clone(), @@ -342,7 +362,7 @@ pub fn address_map( index: tx.index.into(), }), tokens: pool_added.coins.into(), - contracts: vec![call_address.into(), call.return_data.clone()], + contracts: vec![component_id.into()], static_att: vec![ Attribute { name: "pool_type".into(), @@ -366,7 +386,12 @@ pub fn address_map( }, ], change: ChangeType::Creation.into(), - ..Default::default() + protocol_type: Some(ProtocolType { + name: "curve_pool".into(), + financial_type: FinancialType::Swap.into(), + attribute_schema: Vec::new(), + implementation_type: ImplementationType::Vm.into(), + }), }) } else if let Some(pool_added) = abi::meta_pool_factory::events::MetaPoolDeployed::match_and_decode(log) @@ -387,8 +412,11 @@ pub fn address_map( call, ) })?; + + let component_id = &call.return_data[12..]; + Some(ProtocolComponent { - id: hex::encode(&call.return_data), + id: hex::encode(component_id), tx: Some(Transaction { to: tx.to.clone(), from: tx.from.clone(), @@ -396,18 +424,19 @@ pub fn address_map( index: tx.index.into(), }), tokens: vec![pool_added.coin, add_pool.base_pool.clone()], - contracts: vec![ - call_address.into(), - call.return_data.clone(), - add_pool.base_pool.clone(), - ], + contracts: vec![component_id.into(), add_pool.base_pool.clone()], static_att: vec![Attribute { name: "pool_type".into(), value: "MetaPool".into(), change: ChangeType::Creation.into(), }], change: ChangeType::Creation.into(), - ..Default::default() + protocol_type: Some(ProtocolType { + name: "curve_pool".into(), + financial_type: FinancialType::Swap.into(), + attribute_schema: Vec::new(), + implementation_type: ImplementationType::Vm.into(), + }), }) } else { None diff --git a/substreams/ethereum-curve/src/pools.rs b/substreams/ethereum-curve/src/pools.rs new file mode 100644 index 0000000..4e40dba --- /dev/null +++ b/substreams/ethereum-curve/src/pools.rs @@ -0,0 +1,80 @@ +use std::collections::HashMap; + +use crate::abi::pool; +use anyhow::{self, Context, Result}; +use ethabi::token; +use serde::Deserialize; +use serde_qs; +use substreams_ethereum::{ + block_view::LogView, + pb::{eth, eth::v2::Block}, +}; +use tycho_substreams::prelude::*; + +const PARAMS_SEPERATOR: &str = ","; + +#[derive(Debug, Deserialize)] +struct PoolQueryParams { + address: String, + tx_hash: String, + tokens: Vec, + attributes: Vec<(String, String)>, +} + +pub fn emit_specific_pools( + params: &String, + block: ð::v2::Block, +) -> Result> { + let pools: HashMap = params + .split(PARAMS_SEPERATOR) + .map(|param| { + // TODO UNSAFE + let pool: PoolQueryParams = serde_qs::from_str(¶m).unwrap(); + (pool.tx_hash.clone(), pool) + }) + .collect::>(); + + let mut components: Vec = vec![]; + + for tx in block.transactions() { + let encoded_hash = hex::encode(tx.hash.clone()); + if let Some(pool) = pools.get(&encoded_hash) { + let component = ProtocolComponent { + id: pool.address.clone(), + tx: Some(Transaction { + to: tx.to.clone(), + from: tx.from.clone(), + hash: tx.hash.clone(), + index: tx.index.into(), + }), + tokens: pool + .tokens + .clone() + .into_iter() + .map(|token| Result::Ok(hex::decode(token)?)) + .collect::>>() + .with_context(|| "")?, + static_att: pool + .attributes + .clone() + .into_iter() + .map(|attr| Attribute { + name: attr.0, + value: attr.1.into(), + change: ChangeType::Creation.into(), + }) + .collect::>(), + contracts: vec![hex::decode(pool.address.clone()).with_context(|| "")?], + 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(), + }), + }; + components.push(component); + } + } + Ok(components) +} diff --git a/substreams/ethereum-curve/substreams.yaml b/substreams/ethereum-curve/substreams.yaml index 6432e0e..aadb072 100644 --- a/substreams/ethereum-curve/substreams.yaml +++ b/substreams/ethereum-curve/substreams.yaml @@ -19,7 +19,7 @@ binaries: modules: - name: map_components kind: map - initialBlock: 19128828 + initialBlock: 18838383 inputs: - source: sf.ethereum.type.v2.Block output: @@ -27,7 +27,7 @@ modules: - name: store_components kind: store - initialBlock: 19128828 + initialBlock: 18838383 updatePolicy: add valueType: int64 inputs: @@ -35,7 +35,7 @@ modules: - name: store_component_tokens kind: store - initialBlock: 19128828 + initialBlock: 18838383 updatePolicy: set valueType: string inputs: @@ -43,7 +43,7 @@ modules: - name: map_relative_balances kind: map - initialBlock: 19128828 # An arbitrary block that should change based on your requirements + initialBlock: 18838383 # An arbitrary block that should change based on your requirements inputs: - source: sf.ethereum.type.v2.Block - store: store_components @@ -53,7 +53,7 @@ modules: - name: store_balances kind: store - initialBlock: 19128828 + initialBlock: 18838383 updatePolicy: add valueType: bigint inputs: @@ -61,7 +61,7 @@ modules: - name: map_protocol_changes kind: map - initialBlock: 19128828 + initialBlock: 18838383 inputs: - source: sf.ethereum.type.v2.Block - map: map_components diff --git a/substreams/ethereum-maverick/src/modules.rs b/substreams/ethereum-maverick/src/modules.rs index c5be905..5f3c7be 100644 --- a/substreams/ethereum-maverick/src/modules.rs +++ b/substreams/ethereum-maverick/src/modules.rs @@ -17,7 +17,7 @@ use itertools::Itertools; use substreams_ethereum::Event; -use crate::{abi, pb}; +use crate::abi; use tycho_substreams::{ balances::store_balance_changes, contract::extract_contract_changes, prelude::*, @@ -95,7 +95,12 @@ pub fn map_components(block: eth::v2::Block) -> Result>();