-
Notifications
You must be signed in to change notification settings - Fork 78
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
Liquidity pools: Add UTs to for update_token_price()
#1890
Changes from all commits
55d661f
3557b4f
2060f44
1d9d4a6
b0b3ce4
15424a8
0868b0a
d311c90
5f87cba
662b8a1
94b8f46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ use core::convert::TryFrom; | |
|
||
use cfg_traits::{ | ||
liquidity_pools::{InboundQueue, OutboundQueue}, | ||
swaps::TokenSwaps, | ||
PreConditions, | ||
}; | ||
use cfg_types::{ | ||
|
@@ -60,7 +61,7 @@ use frame_support::{ | |
use orml_traits::asset_registry::{self, Inspect as _}; | ||
pub use pallet::*; | ||
use sp_runtime::{ | ||
traits::{AtLeast32BitUnsigned, Convert}, | ||
traits::{AtLeast32BitUnsigned, Convert, EnsureMul}, | ||
FixedPointNumber, SaturatedConversion, | ||
}; | ||
use sp_std::{convert::TryInto, vec}; | ||
|
@@ -271,6 +272,13 @@ pub mod pallet { | |
Result = DispatchResult, | ||
>; | ||
|
||
/// Type used to retrive market ratio information about currencies | ||
type MarketRatio: TokenSwaps< | ||
Self::AccountId, | ||
CurrencyId = Self::CurrencyId, | ||
Ratio = Self::BalanceRatio, | ||
>; | ||
|
||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
} | ||
|
||
|
@@ -435,12 +443,15 @@ pub mod pallet { | |
) -> DispatchResult { | ||
let who = ensure_signed(origin.clone())?; | ||
|
||
// TODO(future): Once we diverge from 1-to-1 conversions for foreign and pool | ||
// currencies, this price must be first converted into the currency_id and then | ||
// re-denominated to 18 decimals (i.e. `Ratio` precision) | ||
let price_value = T::TrancheTokenPrice::get(pool_id, tranche_id) | ||
let (price, computed_at) = T::TrancheTokenPrice::get_price(pool_id, tranche_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lemunozm can we in the same run also close this todo and computed the conversion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it's super straightforward. Do we need to add the order-book dependency to know the market price used for foreign/pool currencies? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it isn't. But we are not only touching the UTs here but also chaning the return types, naming etc. Then we could also close the todo IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done here: 15424a8 @mustermeiszer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, thanks a lot! |
||
.ok_or(Error::<T>::MissingTranchePrice)?; | ||
|
||
let foreign_price = T::MarketRatio::market_ratio( | ||
currency_id, | ||
T::PoolInspect::currency_for(pool_id).ok_or(Error::<T>::PoolNotFound)?, | ||
)? | ||
.ensure_mul(price)?; | ||
|
||
// Check that the registered asset location matches the destination | ||
match Self::try_get_wrapped_token(¤cy_id)? { | ||
LiquidityPoolsWrappedToken::EVM { chain_id, .. } => { | ||
|
@@ -459,8 +470,8 @@ pub mod pallet { | |
pool_id: pool_id.into(), | ||
tranche_id: tranche_id.into(), | ||
currency, | ||
price: price_value.price.into_inner(), | ||
computed_at: price_value.last_updated, | ||
price: foreign_price.into_inner(), | ||
computed_at, | ||
}, | ||
)?; | ||
|
||
|
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 is not used, but if it's intended to be used very soon, I can revert this. Otherwise, I would left removed.