-
Notifications
You must be signed in to change notification settings - Fork 7
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
Change price conversion function in oracle pallet to work for assets with different decimals #490
Change price conversion function in oracle pallet to work for assets with different decimals #490
Conversation
d69ddf0
to
1e55298
Compare
1e55298
to
4fbeed1
Compare
CurrencyId::Stellar(asset) => asset.decimals(), | ||
CurrencyId::XCM(index) => match index { |
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.
I did not check whether this is correct.
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.
d4a2b3b
to
e427fbd
Compare
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 all looks great @ebma. I like the use of the DecimalsLookup
type, I hope we can keep up with updating it properly.
Just left some comments that are more like questions so I understand fully.
pallets/vault-registry/src/tests.rs
Outdated
)), | ||
); | ||
assert!(max_wrapped_for_min_collateral.amount() + tolerance >= wrapped_amount); | ||
assert!(max_wrapped_for_below_min_collateral.amount() < wrapped_amount); |
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.
Why don't we need the tolerance in the second assertion?
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.
Good question. From empiric testing I can tell you that it is not problematic and the bound holds even without the tolerance. But it would make sense to add the tolerance both ways.
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.
I added that tolerance also to the other check now
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.
Great changes 👍🏼 I already got the answers to my questions from the threads created by @gianfra-t
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.
Looks all good to me now. Thanks!
This PR adds changes so that the prices of assets are converted taking their respective decimals into account.
This is achieved through an extra trait
DecimalsLookup
. Unfortunately, it was not possible to implement thedecimals()
directly on theCurrencyId
struct since they vary per network, ie we need to have a different implementation for Pendulum compared to Amplitude and Foucoco. The nameDecimalsLookup
might not be ideal because it implementsdecimals()
andone()
.I decided to implement this trait for Pendulum and Amplitude in the Spacewalk repository already. This is debatable but the vault client needs to be able to have access to the decimals used on the chain it connects to which is easiest to do if we define them in this repository and re-use them in Pendulum. Otherwise, we have to duplicate the same code.
The price conversion is adopted from this function used by Nabla. I kept the functions to convert an asset to USD and vice versa around because they are nice to have in the portal since they are exposed by the RPC of our nodes.
Some tests had to be changed because they were taking simplified assumptions about the relation of price and decimals for the collateral and wrapped currency. They were mostly fixed by increasing the used numbers (because the numbers should have at least two trailing
0
s in order not to face issues due to rounding) and using the price conversion in the Oracle pallet to convert between collateral and wrapped asset, taking the decimal difference into account.Closes #489.