-
Notifications
You must be signed in to change notification settings - Fork 84
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/linear pricing #1812
Fix/linear pricing #1812
Conversation
@lemunozm I am not sure if I implemented it wrongly, but I can not figure out how to fix the test. ^^ |
Yeah, we should use different types. That was something pending I had in mind to do it.
I'll check it! |
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.
Much cleaner now!
Just a question to double-check
})) | ||
}); | ||
let price_value_after_half_year = MARKET_PRICE_VALUE + (NOTIONAL - MARKET_PRICE_VALUE) / 2; |
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 like more how you have tested this!
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.
Thanks for tackle my suggestions!
Probably |
pallets/loans/src/entities/input.rs
Outdated
@@ -61,6 +61,6 @@ impl<T: Config> RepaidInput<T> { | |||
#[scale_info(skip_type_params(T))] | |||
pub enum PriceCollectionInput<T: Config> { | |||
Empty, | |||
Custom(BoundedBTreeMap<T::PriceId, T::Balance, T::MaxActiveLoansPerPool>), | |||
Custom(BoundedBTreeMap<T::PriceId, (T::Balance, T::Moment), T::MaxActiveLoansPerPool>), |
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.
Custom(BoundedBTreeMap<T::PriceId, (T::Balance, T::Moment), T::MaxActiveLoansPerPool>), | |
Custom(BoundedBTreeMap<T::PriceId, PriceOf<T>, ::MaxActiveLoansPerPool>), |
To fix the clippy issue
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1812 +/- ##
==========================================
- Coverage 46.89% 46.53% -0.37%
==========================================
Files 165 167 +2
Lines 12950 13089 +139
==========================================
+ Hits 6073 6091 +18
- Misses 6877 6998 +121 ☔ View full report in Codecov by Sentry. |
), | ||
BadOrigin | ||
); | ||
T::AdminOrigin::ensure_origin(origin, &pool_id)?; |
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.
Nice! I didn't know about EnsureOriginWithArg
. Probably, I should have used it in oracle-collection
instead of PreConditions
there.
runtime/common/src/pool.rs
Outdated
<T as frame_system::Config>::RuntimeOrigin: From<RawOrigin<<T as frame_system::Config>::AccountId>> | ||
+ Into<Result<RawOrigin<<T as frame_system::Config>::AccountId>, T::RuntimeOrigin>>, |
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.
NIT. I think this is already satisfied by RuntimeOrigin
Thanks for the awesome PR description! ❤️ Very helpful |
@@ -76,6 +77,9 @@ pub struct ExternalPricing<T: Config> { | |||
/// borrow/repay and the current oracle price. | |||
/// See [`ExternalAmount::settlement_price`]. | |||
pub max_price_variation: T::Rate, | |||
|
|||
/// If the pricing is estimated with a linear pricing model. | |||
pub with_linear_pricing: bool, |
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.
With this, I think now is much more understandable what's happening 🎉
pallets/pool-system/src/mock.rs
Outdated
#[cfg(not(feature = "runtime-benchmarks"))] | ||
fn try_origin(o: RuntimeOrigin, _: &PoolId) -> Result<Self::Success, RuntimeOrigin> { | ||
<RuntimeOrigin as Into<Result<RawOrigin<AccountId>, RuntimeOrigin>>>::into(o).and_then( | ||
|r| match r { | ||
RawOrigin::Root => Ok(()), | ||
RawOrigin::Signed(account) => { | ||
if account == DEFAULT_POOL_OWNER { | ||
Ok(()) | ||
} else { | ||
Err(RawOrigin::Signed(account).into()) | ||
} | ||
} | ||
RawOrigin::None => Err(RawOrigin::None.into()), | ||
}, | ||
) | ||
} |
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 do we need this special implementation? Do not we want always Ok()
for testing?
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.
Mmmh. Good point. If this is covered in the integration test, probably not.
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.
Changed to an all version
) | ||
} | ||
|
||
fn current_price_inner( |
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.
The current on-chain behavior is:
- If oracle is found, use oracle price
- If not found, use linear accrual price.
That behavior can not be modeled right now. We need to choose between:
- Use oracle price or if not use settlement price (
with_linear_pricing = false
) - Use always linear accrual price (
with_linear_pricing = true
)
Do we want this? Don't we still want to model the current behavior?
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.
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.
No, we want to change that too.
Get the price:
- IF oracle → use oracle
- ELSE → use settlement price
Use the price:
- IF linear pricing → use linear pricing
- ELSE → just use price
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.
What's the difference between "Get the price" and "Use the price"?
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.
Get is either orale or settlement. Use is just for using whatever came out of the get.
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 would add new 2 test cases to check a loan configured with use_linear_price = true
always uses the linear accrual with oracle value and with settlement price
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.
Well, after the changes of this PR all loans comes with use_linear_price = true
, so we should check the false
version instead
@mustermeiszer I will do the migration and open a PR against this base. Context |
* not overpassing maturity * better fix * fix minor thing
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 few minor and NITs comments, but LGTM!
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.
Thank you so much for tackling my Nits ❤️
Description
Currently, linear pricing is only used with the latest settlement price. Rather we want the linear pricing to be used IF the feature is enabled and then
Changes and Descriptions
NOTE: We need that is with the current setup Anemoy will set the validity of its oracles to always be valid which would allow anyone to close an epoch.
Communicate with Apps
None
close epoch
fieldsExternalPricing
changed. There is now an additional fieldwith_linear_pricing
that allows to toggle that featureCommunicate with Embrio
LoanEvent::Created
needs to be filtered by block after the upgrade to include thewith_linear_pricing
infoChecklist: