Skip to content

Commit

Permalink
support new events format
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Oct 10, 2024
1 parent cdb1c01 commit 1d394b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion crates/starkwhale-alert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "starkwhale_alert"
version = "0.1.0"
edition = "2021"
# TODO ADD starknet-id = { git = "https://github.com/starknet-id/starknet-id.rs.git", branch = "master" }

[dependencies]
dotenv = "0.15.0"
reqwest = { version = "0.11.18", features = ["json"] }
Expand All @@ -11,6 +11,7 @@ rstest = "0.18.2"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.105"
starknet = "0.12.0"
# TODO Resume name resolving
# starknet-id = { git = "https://github.com/starknet-id/starknet-id.rs.git", branch = "master" }
koit = "0.2.0"
twitter-v2 = "0.1.8"
Expand Down
15 changes: 11 additions & 4 deletions crates/starkwhale-alert/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ use std::ops::Div;
use crate::{api, consts::Token, consts::ADDRESS_LIST, get_infura_client, starknet_id, to_u256};

pub async fn get_formatted_text(emitted_event: EmittedEvent, token: &Token) -> String {
let from = emitted_event.data[0];
let to: Felt = emitted_event.data[1];
let (from, to, amount_idx) = if emitted_event.keys.len() > 1 {
(emitted_event.keys[1], emitted_event.keys[2], 0)
} else {
(emitted_event.data[0], emitted_event.data[1], 2)
};
let mut amount = to_u256(
emitted_event.data[2].try_into().expect("Error: low"),
emitted_event.data[3].try_into().expect("Error: high"),
emitted_event.data[amount_idx]
.try_into()
.expect("Error: low"),
emitted_event.data[amount_idx + 1]
.try_into()
.expect("Error: high"),
);

amount = to_rounded(amount, token.decimals);
Expand Down
Binary file modified starkwhale_alert
Binary file not shown.

0 comments on commit 1d394b4

Please sign in to comment.