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

fix: add fees in TT price calculation #1990

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pallets/pool-system/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ impl<T: Config> TrancheTokenPrice<T::AccountId, T::CurrencyId> for Pallet<T> {
pool_id: Self::PoolId,
tranche_id: Self::TrancheId,
) -> Option<(T::BalanceRatio, Seconds)> {
let now = T::Time::now();
let mut pool = Pool::<T>::get(pool_id)?;

// Get cached nav as calculating current nav would be too computationally
// expensive
let (nav, nav_last_updated) = T::AssetsUnderManagementNAV::nav(pool_id)?;
let total_assets = pool.reserve.total.ensure_add(nav).ok()?;
let (nav_loans, nav_loans_updates) = T::AssetsUnderManagementNAV::nav(pool_id)?;
let (nav_fees, nav_fees_updated) = T::PoolFeesNAV::nav(pool_id)?;

let nav = Nav::new(nav_loans, nav_fees);
let total_assets = nav
.total(pool.reserve.total)
.unwrap_or(<T as Config>::Balance::zero());
Copy link
Contributor

Choose a reason for hiding this comment

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

Super NIT: unwrap_or_default()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not the biggest fan of default in these case. Zero is really explicit and also what we want.


let tranche_index: usize = pool
.tranches
Expand All @@ -81,12 +83,12 @@ impl<T: Config> TrancheTokenPrice<T::AccountId, T::CurrencyId> for Pallet<T> {
.ok()?;
let prices = pool
.tranches
.calculate_prices::<T::BalanceRatio, T::Tokens, _>(total_assets, now)
.calculate_prices::<T::BalanceRatio, T::Tokens, _>(total_assets, T::Time::now())
.ok()?;

let price = prices.get(tranche_index).cloned()?;

Some((price, nav_last_updated))
Some((price, sp_std::cmp::min(nav_fees_updated, nav_loans_updates)))
}
}

Expand Down
Loading