feat(curve): add coins in static attributes (#205)

* feat(curve): add coins in static attributes

This will be used by tycho-execution when executing swaps on the pool. It is needed because the `exchange` function takes token indexes and not addresses as input.

* style: make clippy happy with `format!`

---------

Co-authored-by: zizou <111426680+flopell@users.noreply.github.com>
This commit is contained in:
Zizou
2025-05-13 18:57:06 +02:00
committed by GitHub
parent 2a77cf965c
commit 62b178ad8f
6 changed files with 78 additions and 23 deletions

View File

@@ -26,10 +26,10 @@ fn main() -> Result<()> {
let contract_name = file_name.split('.').next().unwrap();
let input_path = format!("{}/{}", abi_folder, file_name);
let output_path = format!("{}/{}.rs", output_folder, contract_name);
let input_path = format!("{abi_folder}/{file_name}");
let output_path = format!("{output_folder}/{contract_name}.rs");
mod_rs_content.push_str(&format!("pub mod {};\n", contract_name));
mod_rs_content.push_str(&format!("pub mod {contract_name};\n"));
if std::path::Path::new(&output_path).exists() {
continue;
@@ -40,7 +40,7 @@ fn main() -> Result<()> {
.write_to_file(&output_path)?;
}
let mod_rs_path = format!("{}/mod.rs", output_folder);
let mod_rs_path = format!("{output_folder}/mod.rs");
let mut mod_rs_file = fs::File::create(mod_rs_path)?;
mod_rs_file.write_all(mod_rs_content.as_bytes())?;

View File

@@ -7,7 +7,10 @@
"6b175474e89094c44da98b954eedeac495271d0f",
"a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"dac17f958d2ee523a2206206994597c13d831ec7"
]
],
"static_attributes": {
"coins": "[\"0x6b175474e89094c44da98b954eedeac495271d0f\",\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"0xdac17f958d2ee523a2206206994597c13d831ec7\"]"
}
},
{
"name": "steth",
@@ -16,7 +19,10 @@
"tokens": [
"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"ae7ab96520de3a18e5e111b5eaab095312d7fe84"
]
],
"static_attributes": {
"coins": "[\"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"0xae7ab96520de3a18e5e111b5eaab095312d7fe84\"]"
}
},
{
"name": "tricrypto2",
@@ -33,6 +39,9 @@
],
"attributes": {
"stateless_contract_addr_0": "0x8F68f4810CcE3194B6cB6F3d50fa58c2c9bDD1d5"
},
"static_attributes": {
"coins": "[\"0xdac17f958d2ee523a2206206994597c13d831ec7\",\"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599\",\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\"]"
}
},
{
@@ -44,7 +53,10 @@
"a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"dac17f958d2ee523a2206206994597c13d831ec7",
"57ab1ec28d129707052df4df418d58a2d46d5f51"
]
],
"static_attributes": {
"coins": "[\"0x6b175474e89094c44da98b954eedeac495271d0f\",\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"0xdac17f958d2ee523a2206206994597c13d831ec7\",\"0x57ab1ec28d129707052df4df418d58a2d46d5f51\"]"
}
},
{
"name": "fraxusdc",
@@ -53,6 +65,9 @@
"tokens": [
"853d955acef822db058eb8505911ed77f175b99e",
"a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
]
],
"static_attributes": {
"coins": "[\"0x853d955acef822db058eb8505911ed77f175b99e\",\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\"]"
}
}
]
]

View File

@@ -51,7 +51,7 @@ def encode_json_to_query_params(params: list[dict[str, Any]]):
f"Index `{i}` object missing parameters.\n\n" + err.args[0]
)
return ",".join(encoded_params)
return "#".join(encoded_params)
def main():

View File

@@ -4,7 +4,10 @@ use substreams_ethereum::{
};
use crate::abi;
use tycho_substreams::{attributes::json_serialize_bigint_list, prelude::*};
use tycho_substreams::{
attributes::{json_serialize_address_list, json_serialize_bigint_list},
prelude::*,
};
use crate::consts::*;
use substreams::scalar::BigInt;
@@ -103,7 +106,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens,
tokens: tokens.clone(),
contracts: vec![
component_id.into(),
pool_added.token.clone(),
@@ -135,6 +138,11 @@ pub fn address_map(
value: pool_added.token,
change: ChangeType::Creation.into(),
},
Attribute {
name: "coins".into(),
value: json_serialize_address_list(&tokens),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
@@ -216,7 +224,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens,
tokens: tokens.clone(),
contracts: vec![component_id.into()],
static_att: vec![
Attribute {
@@ -239,6 +247,11 @@ pub fn address_map(
value: address_to_bytes_with_0x(&META_POOL_FACTORY),
change: ChangeType::Creation.into(),
},
Attribute {
name: "coins".into(),
value: json_serialize_address_list(&tokens),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
@@ -328,6 +341,7 @@ pub fn address_map(
// ),
// change: ChangeType::Creation.into(),
// },
// TODO:ADD COINS
// ],
// change: ChangeType::Creation.into(),
// protocol_type: Some(ProtocolType {
@@ -416,6 +430,7 @@ pub fn address_map(
// ),
// change: ChangeType::Creation.into(),
// },
// TODO:ADD COINS
// ],
// change: ChangeType::Creation.into(),
// protocol_type: Some(ProtocolType {
@@ -456,7 +471,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens: pool_added.coins,
tokens: pool_added.coins.clone(),
contracts: vec![component_id.into(), CRYPTO_SWAP_NG_FACTORY.into()],
static_att: vec![
Attribute {
@@ -484,6 +499,11 @@ pub fn address_map(
value: json_serialize_bigint_list(&add_pool.asset_types),
change: ChangeType::Creation.into(),
},
Attribute {
name: "coins".into(),
value: json_serialize_address_list(&pool_added.coins),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
@@ -524,7 +544,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens: vec![pool_added.coin, lp_token],
tokens: vec![pool_added.coin.clone(), lp_token.clone()],
contracts: vec![
component_id.into(),
CRYPTO_SWAP_NG_FACTORY.into(),
@@ -563,6 +583,11 @@ pub fn address_map(
value: add_pool.asset_type.to_signed_bytes_be(),
change: ChangeType::Creation.into(),
},
Attribute {
name: "coins".into(),
value: json_serialize_address_list(&[pool_added.coin, lp_token]),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
@@ -618,7 +643,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens,
tokens: tokens.clone(),
contracts: vec![pool_added.pool, TRICRYPTO_FACTORY.into()],
static_att: vec![
Attribute {
@@ -641,6 +666,11 @@ pub fn address_map(
value: address_to_bytes_with_0x(&TRICRYPTO_FACTORY),
change: ChangeType::Creation.into(),
},
Attribute {
name: "coins".into(),
value: json_serialize_address_list(&tokens),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
@@ -651,7 +681,7 @@ pub fn address_map(
}),
},
vec![EntityChanges {
component_id: format!("0x{}", id),
component_id: format!("0x{id}"),
attributes: vec![
Attribute {
name: "stateless_contract_addr_0".into(),
@@ -734,7 +764,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens,
tokens: tokens.clone(),
contracts: vec![component_id.into()],
static_att: vec![
Attribute {
@@ -757,6 +787,11 @@ pub fn address_map(
value: address_to_bytes_with_0x(&STABLESWAP_FACTORY),
change: ChangeType::Creation.into(),
},
Attribute {
name: "coins".into(),
value: json_serialize_address_list(&tokens),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
@@ -874,7 +909,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens: pool_added.coins.into(),
tokens: pool_added.coins.clone().into(),
contracts: vec![pool_added.pool, TWOCRYPTO_FACTORY.into()],
static_att: vec![
Attribute {
@@ -897,6 +932,11 @@ pub fn address_map(
value: address_to_bytes_with_0x(&TWOCRYPTO_FACTORY),
change: ChangeType::Creation.into(),
},
Attribute {
name: "coins".into(),
value: json_serialize_address_list(&pool_added.coins),
change: ChangeType::Creation.into(),
},
],
change: ChangeType::Creation.into(),
protocol_type: Some(ProtocolType {
@@ -907,7 +947,7 @@ pub fn address_map(
}),
},
vec![EntityChanges {
component_id: format!("0x{}", id),
component_id: format!("0x{id}"),
attributes: vec![
Attribute {
name: "stateless_contract_addr_0".into(),

View File

@@ -4,7 +4,7 @@ use std::{collections::HashMap, iter::zip};
use substreams_ethereum::pb::eth::v2::TransactionTrace;
use tycho_substreams::prelude::*;
const PARAMS_SEPERATOR: &str = ",";
const PARAMS_SEPERATOR: &str = "#";
#[derive(Debug, Deserialize, PartialEq)]
struct PoolQueryParams {
@@ -127,7 +127,7 @@ fn parse_params(params: &str) -> Result<HashMap<String, PoolQueryParams>, anyhow
.split(PARAMS_SEPERATOR)
.map(|param| {
let pool: PoolQueryParams = serde_qs::from_str(param)
.with_context(|| format!("Failed to parse pool query params: {0}", param))?;
.with_context(|| format!("Failed to parse pool query params: {param}"))?;
Ok((pool.tx_hash.clone(), pool))
})
.collect::<Result<HashMap<_, _>>>()

View File

@@ -75,4 +75,4 @@ modules:
type: proto:tycho.evm.v1.BlockChanges
params:
map_components: "address=bebc44782c7db0a1a60cb6fe97d0b483032ff1c7&tx_hash=20793bbf260912aae189d5d261ff003c9b9166da8191d8f9d63ff1c7722f3ac6&tokens[]=6b175474e89094c44da98b954eedeac495271d0f&tokens[]=a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&tokens[]=dac17f958d2ee523a2206206994597c13d831ec7&&static_attribute_keys[]=name&static_attribute_vals[]=3pool&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000,address=dc24316b9ae028f1497c275eb9192a3ea0f67022&tx_hash=fac67ecbd423a5b915deff06045ec9343568edaec34ae95c43d35f2c018afdaa&tokens[]=eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&tokens[]=ae7ab96520de3a18e5e111b5eaab095312d7fe84&&static_attribute_keys[]=name&static_attribute_vals[]=steth&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000,address=d51a44d3fae010294c616388b506acda1bfaae46&contracts[]=c4ad29ba4b3c580e6d59105fff484999997675ff&contracts[]=40745803c2faa8e8402e2ae935933d07ca8f355c&tx_hash=dafb6385ed988ce8aacecfe1d97b38ea5e60b1ebce74d2423f71ddd621680138&tokens[]=dac17f958d2ee523a2206206994597c13d831ec7&tokens[]=2260fac5e5542a773aa44fbcfedf7c193bc2c599&tokens[]=c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&attribute_keys[]=stateless_contract_addr_0&attribute_vals[]=0x8F68f4810CcE3194B6cB6F3d50fa58c2c9bDD1d5&static_attribute_keys[]=name&static_attribute_vals[]=tricrypto2&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000,address=a5407eae9ba41422680e2e00537571bcc53efbfd&tx_hash=51aca4a03a395de8855fa2ca59b7febe520c2a223e69c502066162f7c1a95ec2&tokens[]=6b175474e89094c44da98b954eedeac495271d0f&tokens[]=a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&tokens[]=dac17f958d2ee523a2206206994597c13d831ec7&tokens[]=57ab1ec28d129707052df4df418d58a2d46d5f51&&static_attribute_keys[]=name&static_attribute_vals[]=susd&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000,address=dcef968d416a41cdac0ed8702fac8128a64241a2&tx_hash=1f4254004ce9e19d4eb742ee5a69d30f29085902d976f73e97c44150225ef775&tokens[]=853d955acef822db058eb8505911ed77f175b99e&tokens[]=a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&&static_attribute_keys[]=name&static_attribute_vals[]=fraxusdc&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000"
map_components: 'address=bebc44782c7db0a1a60cb6fe97d0b483032ff1c7&tx_hash=20793bbf260912aae189d5d261ff003c9b9166da8191d8f9d63ff1c7722f3ac6&tokens[]=6b175474e89094c44da98b954eedeac495271d0f&tokens[]=a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&tokens[]=dac17f958d2ee523a2206206994597c13d831ec7&&static_attribute_keys[]=coins&static_attribute_vals[]=["0x6b175474e89094c44da98b954eedeac495271d0f","0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0xdac17f958d2ee523a2206206994597c13d831ec7"]&static_attribute_keys[]=name&static_attribute_vals[]=3pool&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000#address=dc24316b9ae028f1497c275eb9192a3ea0f67022&tx_hash=fac67ecbd423a5b915deff06045ec9343568edaec34ae95c43d35f2c018afdaa&tokens[]=eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&tokens[]=ae7ab96520de3a18e5e111b5eaab095312d7fe84&&static_attribute_keys[]=coins&static_attribute_vals[]=["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","0xae7ab96520de3a18e5e111b5eaab095312d7fe84"]&static_attribute_keys[]=name&static_attribute_vals[]=steth&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000#address=d51a44d3fae010294c616388b506acda1bfaae46&contracts[]=c4ad29ba4b3c580e6d59105fff484999997675ff&contracts[]=40745803c2faa8e8402e2ae935933d07ca8f355c&tx_hash=dafb6385ed988ce8aacecfe1d97b38ea5e60b1ebce74d2423f71ddd621680138&tokens[]=dac17f958d2ee523a2206206994597c13d831ec7&tokens[]=2260fac5e5542a773aa44fbcfedf7c193bc2c599&tokens[]=c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&attribute_keys[]=stateless_contract_addr_0&attribute_vals[]=0x8F68f4810CcE3194B6cB6F3d50fa58c2c9bDD1d5&static_attribute_keys[]=coins&static_attribute_vals[]=["0xdac17f958d2ee523a2206206994597c13d831ec7","0x2260fac5e5542a773aa44fbcfedf7c193bc2c599","0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"]&static_attribute_keys[]=name&static_attribute_vals[]=tricrypto2&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000#address=a5407eae9ba41422680e2e00537571bcc53efbfd&tx_hash=51aca4a03a395de8855fa2ca59b7febe520c2a223e69c502066162f7c1a95ec2&tokens[]=6b175474e89094c44da98b954eedeac495271d0f&tokens[]=a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&tokens[]=dac17f958d2ee523a2206206994597c13d831ec7&tokens[]=57ab1ec28d129707052df4df418d58a2d46d5f51&&static_attribute_keys[]=coins&static_attribute_vals[]=["0x6b175474e89094c44da98b954eedeac495271d0f","0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0xdac17f958d2ee523a2206206994597c13d831ec7","0x57ab1ec28d129707052df4df418d58a2d46d5f51"]&static_attribute_keys[]=name&static_attribute_vals[]=susd&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000#address=dcef968d416a41cdac0ed8702fac8128a64241a2&tx_hash=1f4254004ce9e19d4eb742ee5a69d30f29085902d976f73e97c44150225ef775&tokens[]=853d955acef822db058eb8505911ed77f175b99e&tokens[]=a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&&static_attribute_keys[]=coins&static_attribute_vals[]=["0x853d955acef822db058eb8505911ed77f175b99e","0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"]&static_attribute_keys[]=name&static_attribute_vals[]=fraxusdc&static_attribute_keys[]=factory_name&static_attribute_vals[]=NA&static_attribute_keys[]=factory&static_attribute_vals[]=0x0000000000000000000000000000000000000000'