-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Publishers Balance Monitoring (#12)
* init * add actual publishers address * lint * fix: fmt * clippy * fix: minor refactoring * fix: renaming + update readme --------- Co-authored-by: 0xevolve <[email protected]>
- Loading branch information
Showing
7 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub mod price_deviation; | ||
pub mod publisher_balance; | ||
pub mod source_deviation; | ||
pub mod time_since_last_update; | ||
|
||
pub use price_deviation::price_deviation; | ||
pub use publisher_balance::publisher_balance; | ||
pub use source_deviation::source_deviation; | ||
pub use time_since_last_update::time_since_last_update; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use bigdecimal::ToPrimitive; | ||
use starknet::{ | ||
core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, | ||
macros::selector, | ||
providers::Provider, | ||
}; | ||
|
||
use crate::constants::{FEE_TOKEN_ADDRESS, FEE_TOKEN_DECIMALS}; | ||
use crate::{config::get_config, error::MonitoringError}; | ||
|
||
/// Returns the balance of a given publisher address | ||
/// Note: Currently only reads ETH balance | ||
pub async fn publisher_balance(publisher_address: FieldElement) -> Result<f64, MonitoringError> { | ||
let config = get_config(None).await; | ||
|
||
let client = &config.network().provider; | ||
let token_balance = client | ||
.call( | ||
FunctionCall { | ||
contract_address: FieldElement::from_hex_be(FEE_TOKEN_ADDRESS) | ||
.expect("failed to convert token address"), | ||
entry_point_selector: selector!("balanceOf"), | ||
calldata: vec![publisher_address], | ||
}, | ||
BlockId::Tag(BlockTag::Latest), | ||
) | ||
.await | ||
.map_err(|e| MonitoringError::OnChain(e.to_string()))?; | ||
|
||
let on_chain_balance = token_balance | ||
.first() | ||
.ok_or(MonitoringError::OnChain("No data".to_string()))? | ||
.to_big_decimal(FEE_TOKEN_DECIMALS) | ||
.to_f64() | ||
.ok_or(MonitoringError::Conversion( | ||
"Failed to convert to f64".to_string(), | ||
))?; | ||
|
||
Ok(on_chain_balance) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters