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(pyth-lazer-protocol): remove TMP_EXPONENT #2221

Merged
merged 2 commits into from
Jan 2, 2025
Merged

Conversation

keyvankhademi
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 8:44pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 8:44pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 8:44pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
component-library ⬜️ Ignored (Inspect) Visit Preview Jan 2, 2025 8:44pm
insights ⬜️ Ignored (Inspect) Visit Preview Jan 2, 2025 8:44pm

@@ -19,7 +19,7 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
pyth-lazer-protocol = { version = "0.1.2", path = "../../../../sdk/rust/protocol" }
pyth-lazer-protocol = "0.1.2"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we only use 0.1.2 for the contracts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think at the time of the implementation this was the latest.

@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-protocol"
version = "0.1.3"
version = "0.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

When should we be doing a minor version upgrade like here? Not sure why we are going to 2.0 instead of 1.4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing the traits is considered a breaking change.

@keyvankhademi keyvankhademi merged commit 48690ec into main Jan 2, 2025
9 checks passed
@keyvankhademi keyvankhademi deleted the tmp-exponent branch January 2, 2025 21:15
Comment on lines +78 to +90
pub fn to_f64(self, exponent: u32) -> anyhow::Result<f64> {
Ok(self.0.get() as f64 / 10i64.checked_pow(exponent).context("overflow")? as f64)
}

pub fn mul(self, rhs: Price, rhs_exponent: u32) -> anyhow::Result<Price> {
let left_value = i128::from(self.0.get());
let right_value = i128::from(rhs.0.get());

fn try_into(self) -> Result<f64, Self::Error> {
Ok(self.0.get() as f64 / 10i64.checked_pow(Self::TMP_EXPONENT).context("overflow")? as f64)
let value = left_value * right_value / 10i128.pow(rhs_exponent);
let value = value.try_into()?;
NonZeroI64::new(value)
.context("zero price is unsupported")
.map(Self)
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason you removed the traits?

Copy link
Contributor Author

@keyvankhademi keyvankhademi Jan 6, 2025

Choose a reason for hiding this comment

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

With the need to pass an exponent to the mul and f64 cast functionalities, the traits are no longer suitable. So it has been changed to functions.

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

Successfully merging this pull request may close these issues.

3 participants