Merge pull request #19 from propeller-heads/zz/fix-balancer

Fix bugs in balance substreams
This commit is contained in:
Alan Höng
2024-03-25 23:28:43 +00:00
committed by GitHub
3 changed files with 25 additions and 15 deletions

View File

@@ -75,13 +75,10 @@ pub fn map_relative_balances(
if let Some(ev) =
abi::vault::events::PoolBalanceChanged::match_and_decode(vault_log.log)
{
let component_id =
format!("0x{}", String::from_utf8(ev.pool_id[..20].to_vec()).unwrap())
.as_bytes()
.to_vec();
let component_id = format!("0x{}", hex::encode(&ev.pool_id[..20]));
if store
.get_last(format!("pool:{}", hex::encode(&component_id)))
.get_last(format!("pool:{}", component_id))
.is_some()
{
for (token, delta) in ev.tokens.iter().zip(ev.deltas.iter()) {
@@ -90,18 +87,15 @@ pub fn map_relative_balances(
tx: Some(vault_log.receipt.transaction.into()),
token: token.to_vec(),
delta: delta.to_signed_bytes_be(),
component_id: component_id.clone(),
component_id: component_id.as_bytes().to_vec(),
});
}
}
} else if let Some(ev) = abi::vault::events::Swap::match_and_decode(vault_log.log) {
let component_id =
format!("0x{}", String::from_utf8(ev.pool_id[..20].to_vec()).unwrap())
.as_bytes()
.to_vec();
let component_id = format!("0x{}", hex::encode(&ev.pool_id[..20]));
if store
.get_last(format!("pool:{}", hex::encode(&component_id)))
.get_last(format!("pool:{}", component_id))
.is_some()
{
deltas.extend_from_slice(&[
@@ -110,14 +104,14 @@ pub fn map_relative_balances(
tx: Some(vault_log.receipt.transaction.into()),
token: ev.token_in.to_vec(),
delta: ev.amount_in.to_signed_bytes_be(),
component_id: component_id.clone(),
component_id: component_id.as_bytes().to_vec(),
},
BalanceDelta {
ord: vault_log.ordinal(),
tx: Some(vault_log.receipt.transaction.into()),
token: ev.token_out.to_vec(),
delta: ev.amount_out.neg().to_signed_bytes_be(),
component_id,
component_id: component_id.as_bytes().to_vec(),
},
]);
}
@@ -188,7 +182,7 @@ pub fn map_protocol_changes(
&block,
|addr| {
components_store
.get_last(format!("pool:{0}", hex::encode(addr)))
.get_last(format!("pool:0x{0}", hex::encode(addr)))
.is_some()
},
&mut transaction_contract_changes,

View File

@@ -3,6 +3,14 @@ package:
name: "ethereum_balancer"
version: v0.1.0
protobuf:
files:
- tycho/evm/v1/vm.proto
- tycho/evm/v1/common.proto
- tycho/evm/v1/utils.proto
importPaths:
- ../../proto
binaries:
default:
type: wasm/rust-v1
@@ -42,7 +50,7 @@ modules:
inputs:
- map: map_relative_balances
- name: map_changes
- name: map_protocol_changes
kind: map
initialBlock: 12369300
inputs:

View File

@@ -3,6 +3,14 @@ package:
name: "ethereum_template"
version: v0.1.0
protobuf:
files:
- tycho/evm/v1/vm.proto
- tycho/evm/v1/common.proto
- tycho/evm/v1/utils.proto
importPaths:
- ../../proto
binaries:
default:
type: wasm/rust-v1