-
Notifications
You must be signed in to change notification settings - Fork 87
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
fix(core, proto): use i128 for price instead of u128 #1991
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments on testing, but looks fine to me.
Note on the PR title: this should probably be fix(proto, core)
.
Also is there some interaction anywhere where you have to convert u128 to i128 or vice versa? Or will the price always "stand by itself"?
assert_eq!(expected, actual); | ||
} | ||
#[test] | ||
fn i128_roundtrips_work() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should contain the case of i128::MIN
, -1
, and other distinct negative i128 values.
#[test] | ||
fn can_parse_negative_price() { | ||
let price = "-1".parse::<Price>().unwrap(); | ||
assert_eq!(price.get(), -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO compare on Price::new(-1)
instead.
@SuperFluffy no, there shouldn't be any case where prices are turned into a u128, the |
Summary
it's theoretically possible for the price of an asset to become negative, although rare. in the case where a price became negative, the oracle would be unable to decode the price from the sidecar.
Background
resolves issue 3.2 "Price can become negative" in the zellic audit of the sequencer-side oracle implementation.
Changes
Int128
proto type, similar to our existing primitiveUint128
Price
in core to bei128
internally, instead ofu128
Testing
unit tests