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

Remove getters in lend-market. #1366

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions pallets/lend-market/src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<T: Config> Pallet<T> {
/// Accrue interest and update corresponding storage
pub(crate) fn accrue_interest(asset_id: AssetIdOf<T>) -> DispatchResult {
let now = T::UnixTime::now().as_secs();
let last_accrued_interest_time = Self::last_accrued_interest_time(asset_id);
let last_accrued_interest_time = LastAccruedInterestTime::<T>::get(asset_id);
if last_accrued_interest_time.is_zero() {
// For the initialization
Self::update_last_accrued_interest_time(asset_id, now)?;
Expand Down Expand Up @@ -59,11 +59,11 @@ impl<T: Config> Pallet<T> {
asset_id: AssetIdOf<T>,
) -> Result<(Rate, Rate, Rate, Ratio, BalanceOf<T>, BalanceOf<T>, FixedU128), DispatchError> {
let market = Self::market(asset_id)?;
let total_supply = Self::total_supply(asset_id);
let total_supply = TotalSupply::<T>::get(asset_id);
let total_cash = Self::get_total_cash(asset_id);
let mut total_borrows = Self::total_borrows(asset_id);
let mut total_reserves = Self::total_reserves(asset_id);
let mut borrow_index = Self::borrow_index(asset_id);
let mut total_borrows = TotalBorrows::<T>::get(asset_id);
let mut total_reserves = TotalReserves::<T>::get(asset_id);
let mut borrow_index = BorrowIndex::<T>::get(asset_id);

let util = Self::calc_utilization_ratio(total_cash, total_borrows, total_reserves)?;
let borrow_rate =
Expand All @@ -72,7 +72,7 @@ impl<T: Config> Pallet<T> {
InterestRateModel::get_supply_rate(borrow_rate, util, market.reserve_factor);

let now = T::UnixTime::now().as_secs();
let last_accrued_interest_time = Self::last_accrued_interest_time(asset_id);
let last_accrued_interest_time = LastAccruedInterestTime::<T>::get(asset_id);
if now > last_accrued_interest_time {
let delta_time = now - last_accrued_interest_time;
let interest_accumulated =
Expand Down Expand Up @@ -110,10 +110,10 @@ impl<T: Config> Pallet<T> {
/// This function does not accrue interest before calculating the exchange rate.
/// exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply
pub fn exchange_rate_stored(asset_id: AssetIdOf<T>) -> Result<Rate, DispatchError> {
let total_supply = Self::total_supply(asset_id);
let total_supply = TotalSupply::<T>::get(asset_id);
let total_cash = Self::get_total_cash(asset_id);
let total_borrows = Self::total_borrows(asset_id);
let total_reserves = Self::total_reserves(asset_id);
let total_borrows = TotalBorrows::<T>::get(asset_id);
let total_reserves = TotalReserves::<T>::get(asset_id);

Self::calculate_exchange_rate(total_supply, total_cash, total_borrows, total_reserves)
}
Expand Down
10 changes: 5 additions & 5 deletions pallets/lend-market/src/lend_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T: Config> Inspect<T::AccountId> for Pallet<T> {
/// The total amount of issuance in the system.
fn total_issuance(lend_token_id: Self::AssetId) -> Self::Balance {
if let Ok(underlying_id) = Self::underlying_id(lend_token_id) {
Self::total_supply(underlying_id)
TotalSupply::<T>::get(underlying_id)
} else {
Balance::default()
}
Expand All @@ -42,7 +42,7 @@ impl<T: Config> Inspect<T::AccountId> for Pallet<T> {
/// Get the lend token balance of `who`.
fn balance(lend_token_id: Self::AssetId, who: &T::AccountId) -> Self::Balance {
if let Ok(underlying_id) = Self::underlying_id(lend_token_id) {
Self::account_deposits(underlying_id, who).voucher_balance
AccountDeposits::<T>::get(underlying_id, who).voucher_balance
} else {
Balance::default()
}
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<T: Config> Inspect<T::AccountId> for Pallet<T> {
return res;
}

if Self::total_supply(underlying_id).checked_add(amount).is_none() {
if TotalSupply::<T>::get(underlying_id).checked_add(amount).is_none() {
return DepositConsequence::Overflow;
}

Expand Down Expand Up @@ -200,7 +200,7 @@ impl<T: Config> Pallet<T> {
) -> Result<BalanceOf<T>, DispatchError> {
let underlying_id = Self::underlying_id(lend_token_id)?;
let Deposits { is_collateral, voucher_balance } =
Self::account_deposits(underlying_id, who);
AccountDeposits::<T>::get(underlying_id, who);

if !is_collateral {
return Ok(voucher_balance);
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<T: Config> Pallet<T> {
.ok_or(ArithmeticError::Underflow)?
.into_inner();

let exchange_rate = Self::exchange_rate(underlying_id);
let exchange_rate = ExchangeRate::<T>::get(underlying_id);
let amount = Self::calc_collateral_amount(reducible_underlying_amount, exchange_rate)?;
Ok(amount)
}
Expand Down
Loading