fix: BalanceChange encoding
This commit is contained in:
@@ -100,7 +100,7 @@ message ProtocolComponent {
|
|||||||
message BalanceChange {
|
message BalanceChange {
|
||||||
// The address of the ERC20 token whose balance changed.
|
// The address of the ERC20 token whose balance changed.
|
||||||
bytes token = 1;
|
bytes token = 1;
|
||||||
// The new balance of the token.
|
// The new balance of the token. Note: it must be a big endian encoded int.
|
||||||
bytes balance = 2;
|
bytes balance = 2;
|
||||||
// The id of the component whose TVL is tracked. Note: This MUST be utf8 encoded.
|
// The id of the component whose TVL is tracked. Note: This MUST be utf8 encoded.
|
||||||
// If the protocol component includes multiple contracts, the balance change must be aggregated to reflect how much tokens can be traded.
|
// If the protocol component includes multiple contracts, the balance change must be aggregated to reflect how much tokens can be traded.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use substreams::hex;
|
use substreams::hex;
|
||||||
@@ -200,12 +201,17 @@ pub fn map_changes(
|
|||||||
.map(|(store_delta, balance_delta)| {
|
.map(|(store_delta, balance_delta)| {
|
||||||
let pool_id = key::segment_at(&store_delta.key, 1);
|
let pool_id = key::segment_at(&store_delta.key, 1);
|
||||||
let token_id = key::segment_at(&store_delta.key, 3);
|
let token_id = key::segment_at(&store_delta.key, 3);
|
||||||
|
// store_delta.new_value is an ASCII string representing an integer
|
||||||
|
let ascii_string =
|
||||||
|
String::from_utf8(store_delta.new_value.clone()).expect("Invalid UTF-8 sequence");
|
||||||
|
let balance = BigInt::from_str(&ascii_string).expect("Failed to parse integer");
|
||||||
|
let big_endian_bytes_balance = balance.to_bytes_be().1;
|
||||||
|
|
||||||
(
|
(
|
||||||
balance_delta.tx.unwrap(),
|
balance_delta.tx.unwrap(),
|
||||||
tycho::BalanceChange {
|
tycho::BalanceChange {
|
||||||
token: hex::decode(token_id).expect("Token ID not valid hex"),
|
token: hex::decode(token_id).expect("Token ID not valid hex"),
|
||||||
balance: store_delta.new_value,
|
balance: big_endian_bytes_balance,
|
||||||
component_id: hex::decode(pool_id).expect("Token ID not valid hex"),
|
component_id: hex::decode(pool_id).expect("Token ID not valid hex"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user