Skip to content

Commit 28dd2fc

Browse files
authored
feat: add AccountBalanceChange proto message (propeller-heads#137)
1 parent 53f7649 commit 28dd2fc

File tree

3 files changed

+102
-79
lines changed

3 files changed

+102
-79
lines changed

proto/tycho/evm/v1/common.proto

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ enum FinancialType{
5555
PSM = 3;
5656
}
5757

58-
5958
enum ImplementationType {
6059
VM = 0;
6160
CUSTOM = 1;
@@ -128,6 +127,14 @@ message ContractSlot {
128127
bytes value = 3;
129128
}
130129

130+
// A struct for following the token balance changes for a contract.
131+
message AccountBalanceChange {
132+
// The address of the ERC20 token whose balance changed.
133+
bytes token = 1;
134+
// The new balance of the token. Note: it must be a big endian encoded int.
135+
bytes balance = 2;
136+
}
137+
131138
// Changes made to a single contract's state.
132139
message ContractChange {
133140
// The contract's address
@@ -140,6 +147,8 @@ message ContractChange {
140147
repeated ContractSlot slots = 4;
141148
// Whether this is an update, a creation or a deletion.
142149
ChangeType change = 5;
150+
// The new ERC20 balances of the contract.
151+
repeated AccountBalanceChange token_balances = 6;
143152
}
144153

145154
// Aggregate entities

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ pub struct InterimContractChange {
467467
code: Vec<u8>,
468468
slots: HashMap<Vec<u8>, SlotValue>,
469469
change: ChangeType,
470+
token_balances: HashMap<Vec<u8>, Vec<u8>>,
470471
}
471472

472473
impl InterimContractChange {
@@ -477,6 +478,7 @@ impl InterimContractChange {
477478
code: vec![],
478479
slots: Default::default(),
479480
change: if creation { ChangeType::Creation } else { ChangeType::Update },
481+
token_balances: Default::default(),
480482
}
481483
}
482484

@@ -530,6 +532,11 @@ impl From<InterimContractChange> for Option<ContractChange> {
530532
.map(|(slot, value)| ContractSlot { slot, value: value.new_value })
531533
.collect(),
532534
change: value.change.into(),
535+
token_balances: value
536+
.token_balances
537+
.into_iter()
538+
.map(|(k, v)| AccountBalanceChange { token: k, balance: v })
539+
.collect(),
533540
};
534541
if contract_change.is_empty() {
535542
None

0 commit comments

Comments
 (0)