-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from astraly-labs/feat/fetch-price-from-pragma
Feat/fetch price from pragma
- Loading branch information
Showing
13 changed files
with
305 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
description = "Madara primitive for Oracles" | ||
name = "mp-oracle" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
homepage.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
|
||
# Other | ||
num-bigint = { workspace = true } | ||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
anyhow = { workspace = true } | ||
reqwest = { workspace = true } |
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,63 @@ | ||
use anyhow::bail; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
mod pragma; | ||
|
||
use pragma::*; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[serde(tag = "oracle_name", content = "config")] | ||
pub enum Oracle { | ||
Pragma(PragmaOracle), | ||
} | ||
|
||
impl Oracle { | ||
pub fn new(oracle_name: &str, url: String, key: String) -> anyhow::Result<Self> { | ||
match oracle_name { | ||
"Pragma" => Ok(Oracle::Pragma(PragmaOracle::new(url, key))), | ||
_ => bail!("Unknown Oracle name"), | ||
} | ||
} | ||
|
||
pub fn set_base_url(&mut self, url: String) { | ||
match self { | ||
Oracle::Pragma(pragma_oracle) => pragma_oracle.api_url = url, | ||
} | ||
} | ||
|
||
pub async fn fetch_eth_strk_price(&self) -> anyhow::Result<(u128, u32)> { | ||
match self { | ||
Oracle::Pragma(pragma_oracle) => pragma_oracle.fetch_eth_strk_price().await, | ||
} | ||
} | ||
|
||
pub fn set_api_key(&mut self, key: String) { | ||
match self { | ||
Oracle::Pragma(pragma_oracle) => pragma_oracle.api_key = key, | ||
} | ||
} | ||
|
||
pub fn get_fetch_url(&self, base: String, quote: String) -> String { | ||
match self { | ||
Oracle::Pragma(pragma_oracle) => pragma_oracle.get_fetch_url(base, quote), | ||
} | ||
} | ||
|
||
pub fn get_api_key(&self) -> &String { | ||
match self { | ||
Oracle::Pragma(oracle) => &oracle.api_key, | ||
} | ||
} | ||
|
||
pub fn is_in_bounds(&self, price: u128) -> bool { | ||
match self { | ||
Oracle::Pragma(oracle) => oracle.price_bounds.low <= price && price <= oracle.price_bounds.high, | ||
} | ||
} | ||
} | ||
|
||
impl Default for Oracle { | ||
fn default() -> Self { | ||
Self::Pragma(PragmaOracle::default()) | ||
} | ||
} |
Oops, something went wrong.