Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat() : fetch strk price from oracle #368

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

azurwastaken
Copy link
Contributor

Pull Request type

Please add the labels corresponding to the type of changes your PR introduces:

Feature
What is the current behavior?

Resolves: #352

@azurwastaken azurwastaken self-assigned this Oct 28, 2024
Copy link
Member

@cchudant cchudant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, how would you run madara in production without oracle? Maybe, for chains which don't want an L2 token, only eth? if we set its price to zero, people would be able to send transactions without fees
That would be for later PR though

Comment on lines 48 to 61
pub async fn fetch_eth_strk_price(&self) -> anyhow::Result<(u128, u32)> {
let response = reqwest::Client::new()
.get(self.get_fetch_url(String::from("eth"), String::from("strk")))
.header("x-api-key", self.api_key.clone())
.send()
.await
.expect("failed to retrieve price from pragma oracle");

let oracle_api_response = response.json::<PragmaApiResponse>().await.expect("failed to parse api response");
let eth_strk_price = u128::from_str_radix(oracle_api_response.price.trim_start_matches("0x"), 16)?;

Ok((eth_strk_price, oracle_api_response.decimals))
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the node crash in case of unavailable service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes probably, my bad, i changed expect to context to propagate the error to crates/client/eth/src/l1_gas_price.rs:17

@azurwastaken
Copy link
Contributor Author

Just wondering, how would you run madara in production without oracle? Maybe, for chains which don't want an L2 token, only eth? if we set its price to zero, people would be able to send transactions without fees That would be for later PR though

Yes, oracle are just here to do live conversion between ETH and L2 token so, in my opinion, the solution would be to disable the ability to pay gas with STRK/L2token.

@EvolveArt
Copy link
Contributor

Just wondering, how would you run madara in production without oracle? Maybe, for chains which don't want an L2 token, only eth? if we set its price to zero, people would be able to send transactions without fees That would be for later PR though

That would fck up all the rpc endpoints that have the strk gas price tho so not a good idea.

@antiyro
Copy link
Member

antiyro commented Nov 4, 2024

Just wondering, how would you run madara in production without oracle? Maybe, for chains which don't want an L2 token, only eth? if we set its price to zero, people would be able to send transactions without fees That would be for later PR though

That would fck up all the rpc endpoints that have the strk gas price tho so not a good idea.

we could default it anyways

let (eth_strk_price, decimals) =
oracle_provider.fetch_eth_strk_price().await.context("failed to retrieve ETH/STRK price")?;
let strk_gas_price = (BigDecimal::new((*eth_gas_price).into(), decimals.into())
/ BigDecimal::new(eth_strk_price.into(), decimals.into()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if eth_strk_price price is 0 here there is a possible 0 division?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you are right, added a check

.context("failed to retrieve price from pragma oracle")?;

let oracle_api_response = response.json::<PragmaApiResponse>().await.context("failed to parse api response")?;
let eth_strk_price = u128::from_str_radix(oracle_api_response.price.trim_start_matches("0x"), 16)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the price is not fetched in the expected format what will happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it fail to parse and propagate an error without panicking

/ BigDecimal::new(eth_strk_price.into(), decimals.into()))
.as_bigint_and_exponent();

l1_gas_provider.update_strk_l1_gas_price(strk_gas_price.0.to_str_radix(10).parse::<u128>()?);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this not to overflow but would be great to ensure clean code


if l1_gas_setter.is_oracle_needed() && l1_gas_setter.oracle_provider.is_none() {
log::error!("STRK gas is not fixed and oracle is not provided");
panic!();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally handle the case where we dont want the strk price by defaulting it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

feat(): fetch strk price from pragma oracle
6 participants