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:
@@ -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(),
|
||||
|
||||
@@ -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<_, _>>>()
|
||||
|
||||
Reference in New Issue
Block a user