Skip to content

Commit

Permalink
revert job + fix when rate is less than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Nov 9, 2023
1 parent 9e62404 commit cd08255
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86_64-unknown-linux-gnu]
linker = "x86_64-unknown-linux-gnu-gcc"
25 changes: 2 additions & 23 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
toolchain: stable

- name: Step 3 - Run cargo check
run: mv .env.example .env && cargo check
run: mv .env.example .env && rm -rf .cargo && cargo check

fmt:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,25 +45,4 @@ jobs:
toolchain: stable

- name: Step 3 - Run cargo clippy
run: mv .env.example .env && cargo clippy

create-binary:
runs-on: ubuntu-latest
needs: check
steps:
- name: Step 1 - Check out main branch
uses: actions/checkout@v3

- name: Step 2 - Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Step 3 - Run cargo build
run: mv .env.example .env && cargo build --bin starkwhale_alert --release

- name: Step 4 - Publish starkwhale_alert binary to artifacts
uses: actions/upload-artifact@v3
with:
name: starkwhale_alert
path: target/release/starkwhale_alert
run: mv .env.example .env && rm -rf .cargo && cargo clippy
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ coincap io conversion token <=> $ value https://docs.coincap.io/
## Installation
use `cargo install --path crates/crate-name`

build for linux: `cargo build --bin starkwhale_alert --release --target=x86_64-unknown-linux-gnu`



## Contribution

Expand Down
3 changes: 2 additions & 1 deletion crates/starkwhale-alert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ bigdecimal = "0.4.1"
log = "0.4.20"
chrono = "0.4.29"
dotenv_codegen = "0.15.0"
num-bigint = "0.4.4"
num-bigint = "0.4.4"
openssl = { version = "0.10", features = ["vendored"] }
6 changes: 4 additions & 2 deletions crates/starkwhale-alert/src/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bigdecimal::{FromPrimitive, ToPrimitive};
use num_bigint::BigUint;
use starknet::core::types::{EmittedEvent, FieldElement};
use std::ops::Div;

use crate::{api, consts::Token, consts::ADDRESS_LIST, get_infura_client, starknet_id, to_u256};

Expand All @@ -22,8 +23,8 @@ pub async fn get_formatted_text(emitted_event: EmittedEvent, token: &Token) -> S
.unwrap()
.join(".");
let rate = api::fetch_coin(token.rate_api_id).await.unwrap();
let rate = BigUint::new(vec![rate.to_u32().unwrap()]);
let usd_value = amount * rate;
let rate = BigUint::new(vec![(rate * 10000_f64).to_u32().unwrap()]);
let usd_value = (amount * rate).div(BigUint::new(vec![10000]));
let usd_value_string = usd_value
.to_string()
.as_bytes()
Expand Down Expand Up @@ -99,6 +100,7 @@ async fn format_address(address: FieldElement) -> String {

#[cfg(test)]
mod tests {

use super::{format_address, get_formatted_text, to_rounded};
use crate::{consts::USDC, to_u256};
use starknet::core::types::{EmittedEvent, FieldElement};
Expand Down

0 comments on commit cd08255

Please sign in to comment.