Skip to content

Commit

Permalink
fix sign of balance
Browse files Browse the repository at this point in the history
  • Loading branch information
colindickson committed Nov 30, 2023
1 parent 570c22d commit 4b24391
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ fn find_erc20_balance_changes_algorithm1(
let change = BalanceChange {
contract: Hex::encode(&call.address),
owner: Hex::encode(keccak_address),
old_balance: BigInt::from_signed_bytes_be(&storage_change.old_value).to_string(),
new_balance: BigInt::from_signed_bytes_be(&storage_change.new_value).to_string(),
old_balance: BigInt::from_unsigned_bytes_be(&storage_change.old_value).to_string(),
new_balance: BigInt::from_unsigned_bytes_be(&storage_change.new_value).to_string(),
transaction: Hex::encode(&trx.hash),
storage_key: Hex::encode(&storage_change.key),
call_index: call.index,
Expand Down Expand Up @@ -266,8 +266,8 @@ fn find_erc20_balance_changes_algorithm2(
continue;
}

let old_balance = BigInt::from_signed_bytes_be(&storage_change.old_value);
let new_balance = BigInt::from_signed_bytes_be(&storage_change.new_value);
let old_balance = BigInt::from_unsigned_bytes_be(&storage_change.old_value);
let new_balance = BigInt::from_unsigned_bytes_be(&storage_change.new_value);

let balance_change = new_balance - old_balance;
if balance_change < BigInt::zero() {
Expand All @@ -279,8 +279,8 @@ fn find_erc20_balance_changes_algorithm2(
let change = BalanceChange {
contract: Hex::encode(&original_call.address),
owner: Hex::encode(keccak_address),
old_balance: BigInt::from_signed_bytes_be(&storage_change.old_value).to_string(),
new_balance: BigInt::from_signed_bytes_be(&storage_change.new_value).to_string(),
old_balance: BigInt::from_unsigned_bytes_be(&storage_change.old_value).to_string(),
new_balance: BigInt::from_unsigned_bytes_be(&storage_change.new_value).to_string(),
transaction: Hex::encode(&trx.hash),
storage_key: Hex::encode(&storage_change.key),
call_index: original_call.index,
Expand All @@ -307,8 +307,8 @@ fn find_erc20_balance_changes_algorithm2(
None => continue,
};

let old_balance = BigInt::from_signed_bytes_be(&storage_change.old_value);
let new_balance = BigInt::from_signed_bytes_be(&storage_change.new_value);
let old_balance = BigInt::from_unsigned_bytes_be(&storage_change.old_value);
let new_balance = BigInt::from_unsigned_bytes_be(&storage_change.new_value);

let mut balance_change = new_balance - old_balance;
if balance_change < BigInt::zero() {
Expand All @@ -322,8 +322,8 @@ fn find_erc20_balance_changes_algorithm2(
let change = BalanceChange {
contract: Hex::encode(&original_call.address),
owner: Hex::encode(keccak_address),
old_balance: BigInt::from_signed_bytes_be(&storage_change.old_value).to_string(),
new_balance: BigInt::from_signed_bytes_be(&storage_change.new_value).to_string(),
old_balance: BigInt::from_unsigned_bytes_be(&storage_change.old_value).to_string(),
new_balance: BigInt::from_unsigned_bytes_be(&storage_change.new_value).to_string(),
transaction: Hex::encode(&trx.hash),
storage_key: Hex::encode(&storage_change.key),
call_index: original_call.index,
Expand Down
2 changes: 1 addition & 1 deletion src/sinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use substreams_entity_change::pb::entity::EntityChanges;
use substreams_database_change::pb::database::DatabaseChanges;

#[substreams::handlers::map]
pub fn graph_out(clock: Clock, balance_changes: BalanceChanges) -> Result<EntityChanges, Error> {
pub fn graph_out(_clock: Clock, balance_changes: BalanceChanges) -> Result<EntityChanges, Error> {
let mut tables = substreams_entity_change::tables::Tables::new();

for balance_change in balance_changes.balance_changes {
Expand Down
2 changes: 1 addition & 1 deletion subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dataSources:
source:
package:
moduleName: graph_out
file: ./erc20-balance-changes-v1.1.0.spkg
file: ./erc20-balance-changes-v1.2.0.spkg
mapping:
kind: substreams/graph-entities
apiVersion: 0.0.7
2 changes: 1 addition & 1 deletion substreams.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
specVersion: v0.1.0
package:
name: erc20_balance_changes
version: v1.1.0
version: v1.2.0
url: https://github.com/streamingfast/erc20-balance-changes
image: logo.png
doc: |
Expand Down

0 comments on commit 4b24391

Please sign in to comment.