Skip to content

Commit ad0a391

Browse files
authored
chore: clean up ambient (propeller-heads#136)
* fix: remove unnecessary tx field in ProtocolComponent * chore: move ambient protobuf files to ambient module * chore: remove dependency on common message types This allows us to isolate the ambient specific messages within the ambient module * feat: update ambient substream with new message structs * chore: update substream configs And remove use of deprecated BlockContractChanges. * feat: implement From for AmbientProtocolComponent to ProtocolComponent
1 parent 28dd2fc commit ad0a391

File tree

18 files changed

+170
-124
lines changed

18 files changed

+170
-124
lines changed

buf.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ modules:
33
- path: proto
44
excludes:
55
- proto/sf
6-
- path: substreams/ethereum-ambient/proto
76
lint:
87
use:
98
- BASIC

proto/tycho/evm/v1/common.proto

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ message ProtocolComponent {
9090
ChangeType change = 5;
9191
/// Represents the functionality of the component.
9292
ProtocolType protocol_type = 6;
93-
// Transaction where this component was created
94-
Transaction tx = 7;
9593
}
9694

9795
// A struct for following the changes of Total Value Locked (TVL) of a protocol component.

substreams/Cargo.lock

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substreams/crates/tycho-substreams/src/models.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
22
use substreams_ethereum::pb::eth::v2::{self as sf, StorageChange};
33

44
// re-export the protobuf types here.
5-
pub use crate::pb::tycho::{ambient::v1::*, evm::v1::*};
5+
pub use crate::pb::tycho::evm::v1::*;
66

77
impl TransactionContractChanges {
88
/// Creates a new empty `TransactionContractChanges` instance.
@@ -213,15 +213,14 @@ impl ProtocolComponent {
213213
/// ## Parameters
214214
/// - `id`: Identifier for the component.
215215
/// - `tx`: Reference to the associated transaction.
216-
pub fn new(id: &str, tx: &Transaction) -> Self {
216+
pub fn new(id: &str) -> Self {
217217
Self {
218218
id: id.to_string(),
219219
tokens: Vec::new(),
220220
contracts: Vec::new(),
221221
static_att: Vec::new(),
222222
change: ChangeType::Creation.into(),
223223
protocol_type: None,
224-
tx: Some(tx.clone()),
225224
}
226225
}
227226

@@ -233,15 +232,14 @@ impl ProtocolComponent {
233232
/// ## Parameters
234233
/// - `id`: Contract address to be encoded and set as the component's ID.
235234
/// - `tx`: Reference to the associated transaction.
236-
pub fn at_contract(id: &[u8], tx: &Transaction) -> Self {
235+
pub fn at_contract(id: &[u8]) -> Self {
237236
Self {
238237
id: format!("0x{}", hex::encode(id)),
239238
tokens: Vec::new(),
240239
contracts: vec![id.to_vec()],
241240
static_att: Vec::new(),
242241
change: ChangeType::Creation.into(),
243242
protocol_type: None,
244-
tx: Some(tx.clone()),
245243
}
246244
}
247245

substreams/crates/tycho-substreams/src/pb/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
// @generated
22
pub mod tycho {
3-
pub mod ambient {
4-
// @@protoc_insertion_point(attribute:tycho.ambient.v1)
5-
pub mod v1 {
6-
include!("tycho.ambient.v1.rs");
7-
// @@protoc_insertion_point(tycho.ambient.v1)
8-
}
9-
}
103
pub mod evm {
114
// @@protoc_insertion_point(attribute:tycho.evm.v1)
125
pub mod v1 {

substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ pub struct ProtocolComponent {
9595
/// / Represents the functionality of the component.
9696
#[prost(message, optional, tag="6")]
9797
pub protocol_type: ::core::option::Option<ProtocolType>,
98-
/// Transaction where this component was created
99-
#[prost(message, optional, tag = "7")]
100-
pub tx: ::core::option::Option<Transaction>,
10198
}
10299
/// A struct for following the changes of Total Value Locked (TVL) of a protocol component.
103100
/// Note that if a ProtocolComponent contains multiple contracts, the TVL is tracked for the component as a whole.

substreams/ethereum-ambient/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name = "substreams_ethereum_ambient"
88
crate-type = ["cdylib"]
99

1010
[dependencies]
11-
tycho-substreams = { git = "https://github.com/propeller-heads/tycho-protocol-sdk.git", rev = "b8aeaa3" }
11+
tycho-substreams = { git = "https://github.com/propeller-heads/tycho-protocol-sdk.git", rev = "f90c33b" }
1212
substreams = "0.5.22"
1313
substreams-ethereum = "0.9.9"
1414
prost = "0.11"

substreams/ethereum-ambient/Readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Modules Description
99
* **Type**: Map
1010
* **Purpose**: This module detects new pools within the Ethereum blockchain and balance changes.
1111
* **Inputs**: Ethereum block data (`sf.ethereum.type.v2.Block`).
12-
* **Output**: Emits data of type `proto:tycho.evm.state.v1.BlockPoolChanges`.
12+
* **Output**: Emits data of type `proto:tycho.ambient.v1.BlockPoolChanges`.
1313

1414
### `store_pools_balances`
1515

@@ -26,10 +26,10 @@ Modules Description
2626
### `map_changes`
2727

2828
* **Type**: Map
29-
* **Purpose**: This module integrates all the processed information to generate comprehensive `BlockContractChanges`. It considers new pools, balance changes and contract changes.
29+
* **Purpose**: This module integrates all the processed information to generate comprehensive `BlockChanges`. It considers new pools, balance changes and contract changes.
3030
* **Inputs**:
3131
* Ethereum block data (`sf.ethereum.type.v2.Block`).
3232
* Data from `map_pool_changes`.
3333
* Data from `store_pools_balances`.
3434
* Data from `store_pools`.
35-
* **Output**: Emits `proto:tycho.evm.state.v1.BlockContractChanges`.
35+
* **Output**: Emits `proto:tycho.evm.state.v1.BlockChanges`.

substreams/ethereum-ambient/proto/ambient.proto

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ syntax = "proto3";
22

33
package tycho.ambient.v1;
44

5-
import "tycho/evm/v1/common.proto";
6-
75
// A change to a pool's balance. Ambient specific.
86
message AmbientBalanceDelta {
97
// The address of the ERC20 token whose balance changed.
@@ -14,14 +12,25 @@ message AmbientBalanceDelta {
1412
bytes token_delta = 3;
1513
// Used to determine the order of the balance changes. Necessary for the balance store.
1614
uint64 ordinal = 4;
17-
// Transaction where the balance changed.
18-
tycho.evm.v1.Transaction tx = 5;
15+
// Transaction index of the balance change
16+
uint64 tx_index = 5;
17+
}
18+
19+
message AmbientProtocolComponent {
20+
// A unique identifier for the component within the protocol.
21+
string id = 1;
22+
// Addresses of the ERC20 tokens used by the component.
23+
repeated bytes tokens = 2;
24+
// Ambient pool index [static attribute for ambient pools]
25+
bytes pool_index = 3;
26+
// Transaction index for the component creation
27+
uint64 tx_index = 4;
1928
}
2029

2130
// Ambient pool changes within a single block
2231
message BlockPoolChanges {
2332
// New protocol components added in this block
24-
repeated tycho.evm.v1.ProtocolComponent protocol_components = 1;
25-
// Balance changes to pools in this block
33+
repeated AmbientProtocolComponent new_components = 1;
34+
// Balance changes on this block
2635
repeated AmbientBalanceDelta balance_deltas = 2;
2736
}

substreams/ethereum-ambient/src/contracts/main.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use anyhow::{anyhow, bail};
2+
use ethabi::{decode, ParamType};
3+
use hex_literal::hex;
4+
use substreams_ethereum::pb::eth::v2::Call;
5+
26
use tycho_substreams::models::{
37
Attribute, ChangeType, FinancialType, ImplementationType, ProtocolComponent, ProtocolType,
4-
Transaction,
58
};
69

7-
use crate::utils::{decode_flows_from_output, encode_pool_hash};
8-
use ethabi::{decode, ParamType};
9-
use hex_literal::hex;
10-
use substreams_ethereum::pb::eth::v2::Call;
10+
use crate::{
11+
pb::tycho::ambient::v1::AmbientProtocolComponent,
12+
utils::{decode_flows_from_output, encode_pool_hash},
13+
};
1114

1215
pub const AMBIENT_CONTRACT: [u8; 20] = hex!("aaaaaaaaa24eeeb8d57d431224f73832bc34f688");
1316
pub const USER_CMD_FN_SIG: [u8; 4] = hex!("a15112f9");
@@ -91,10 +94,11 @@ pub fn decode_direct_swap_call(
9194
bail!("Failed to decode swap call inputs.".to_string());
9295
}
9396
}
97+
9498
pub fn decode_pool_init(
9599
call: &Call,
96-
tx: Transaction,
97-
) -> Result<Option<ProtocolComponent>, anyhow::Error> {
100+
tx_index: u64,
101+
) -> Result<Option<AmbientProtocolComponent>, anyhow::Error> {
98102
// Decode external call to UserCmd
99103
if let Ok(external_params) = decode(USER_CMD_EXTERNAL_ABI, &call.input[4..]) {
100104
let cmd_bytes = external_params[1]
@@ -134,28 +138,14 @@ pub fn decode_pool_init(
134138
let pool_index = pool_index_buf.to_vec();
135139
let pool_hash = encode_pool_hash(base.clone(), quote.clone(), pool_index.clone());
136140

137-
let static_attribute = Attribute {
138-
name: String::from("pool_index"),
139-
value: pool_index,
140-
change: ChangeType::Creation.into(),
141-
};
142-
143141
let mut tokens: Vec<Vec<u8>> = vec![base.clone(), quote.clone()];
144142
tokens.sort();
145143

146-
let new_component = ProtocolComponent {
144+
let new_component = AmbientProtocolComponent {
147145
id: hex::encode(pool_hash),
148146
tokens,
149-
contracts: vec![AMBIENT_CONTRACT.to_vec()],
150-
static_att: vec![static_attribute],
151-
change: ChangeType::Creation.into(),
152-
protocol_type: Some(ProtocolType {
153-
name: "ambient_pool".to_string(),
154-
attribute_schema: vec![],
155-
financial_type: FinancialType::Swap.into(),
156-
implementation_type: ImplementationType::Vm.into(),
157-
}),
158-
tx: Some(tx.clone()),
147+
pool_index,
148+
tx_index,
159149
};
160150
Ok(Some(new_component))
161151
} else {
@@ -168,3 +158,25 @@ pub fn decode_pool_init(
168158
bail!("Failed to decode ABI external call.".to_string());
169159
}
170160
}
161+
162+
impl From<AmbientProtocolComponent> for ProtocolComponent {
163+
fn from(component: AmbientProtocolComponent) -> Self {
164+
ProtocolComponent {
165+
id: component.id,
166+
tokens: component.tokens,
167+
contracts: vec![AMBIENT_CONTRACT.to_vec()],
168+
static_att: vec![Attribute {
169+
name: "pool_index".to_string(),
170+
value: component.pool_index,
171+
change: ChangeType::Creation.into(),
172+
}],
173+
change: ChangeType::Creation.into(),
174+
protocol_type: Some(ProtocolType {
175+
name: "ambient_pool".to_string(),
176+
attribute_schema: vec![],
177+
financial_type: FinancialType::Swap.into(),
178+
implementation_type: ImplementationType::Vm.into(),
179+
}),
180+
}
181+
}
182+
}

0 commit comments

Comments
 (0)