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 Assets config type from Loans pallet #885

Merged
merged 2 commits into from
Jan 25, 2023
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
2 changes: 1 addition & 1 deletion crates/loans/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn transfer_initial_balance<T: Config + orml_tokens::Config<CurrencyId = Currenc
.unwrap();
}

fn set_account_borrows<T: Config>(who: T::AccountId, asset_id: AssetIdOf<T>, borrow_balance: BalanceOf<T>) {
fn set_account_borrows<T: Config>(who: T::AccountId, asset_id: CurrencyId, borrow_balance: BalanceOf<T>) {
AccountBorrows::<T>::insert(
asset_id,
&who,
Expand Down
10 changes: 5 additions & 5 deletions crates/loans/src/farming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<T: Config> Pallet<T> {
Ok(reward_delta)
}

pub(crate) fn update_reward_supply_index(asset_id: AssetIdOf<T>) -> DispatchResult {
pub(crate) fn update_reward_supply_index(asset_id: CurrencyId<T>) -> DispatchResult {
let current_block_number = <frame_system::Pallet<T>>::block_number();
RewardSupplyState::<T>::try_mutate(asset_id, |supply_state| -> DispatchResult {
let delta_block = current_block_number.saturating_sub(supply_state.block);
Expand All @@ -82,7 +82,7 @@ impl<T: Config> Pallet<T> {
})
}

pub(crate) fn update_reward_borrow_index(asset_id: AssetIdOf<T>) -> DispatchResult {
pub(crate) fn update_reward_borrow_index(asset_id: CurrencyId<T>) -> DispatchResult {
let current_block_number = <frame_system::Pallet<T>>::block_number();
RewardBorrowState::<T>::try_mutate(asset_id, |borrow_state| -> DispatchResult {
let delta_block = current_block_number.saturating_sub(borrow_state.block);
Expand All @@ -109,7 +109,7 @@ impl<T: Config> Pallet<T> {
})
}

pub(crate) fn distribute_supplier_reward(asset_id: AssetIdOf<T>, supplier: &T::AccountId) -> DispatchResult {
pub(crate) fn distribute_supplier_reward(asset_id: CurrencyId<T>, supplier: &T::AccountId) -> DispatchResult {
RewardSupplierIndex::<T>::try_mutate(asset_id, supplier, |supplier_index| -> DispatchResult {
let supply_state = RewardSupplyState::<T>::get(asset_id);
let delta_index = supply_state
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<T: Config> Pallet<T> {
})
}

pub(crate) fn distribute_borrower_reward(asset_id: AssetIdOf<T>, borrower: &T::AccountId) -> DispatchResult {
pub(crate) fn distribute_borrower_reward(asset_id: CurrencyId<T>, borrower: &T::AccountId) -> DispatchResult {
RewardBorrowerIndex::<T>::try_mutate(asset_id, borrower, |borrower_index| -> DispatchResult {
let borrow_state = RewardBorrowState::<T>::get(asset_id);
let delta_index = borrow_state
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<T: Config> Pallet<T> {
})
}

pub(crate) fn collect_market_reward(asset_id: AssetIdOf<T>, user: &T::AccountId) -> DispatchResult {
pub(crate) fn collect_market_reward(asset_id: CurrencyId<T>, user: &T::AccountId) -> DispatchResult {
Self::update_reward_supply_index(asset_id)?;
Self::distribute_supplier_reward(asset_id, user)?;

Expand Down
8 changes: 4 additions & 4 deletions crates/loans/src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::*;
impl<T: Config> Pallet<T> {
/// Accrue interest and update corresponding storage
#[cfg_attr(any(test, feature = "integration-tests"), visibility::make(pub))]
pub(crate) fn accrue_interest(asset_id: AssetIdOf<T>) -> DispatchResult {
pub(crate) fn accrue_interest(asset_id: CurrencyId<T>) -> DispatchResult {
let now = T::UnixTime::now().as_secs();
let last_accrued_interest_time = Self::last_accrued_interest_time(asset_id);
if last_accrued_interest_time.is_zero() {
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<T: Config> Pallet<T> {
}

pub fn get_market_status(
asset_id: AssetIdOf<T>,
asset_id: CurrencyId<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)?;
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<T: Config> Pallet<T> {
/// Update the exchange rate according to the totalCash, totalBorrows and totalSupply.
/// 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> {
pub fn exchange_rate_stored(asset_id: CurrencyId<T>) -> Result<Rate, DispatchError> {
let total_supply = Self::total_supply(asset_id)?;
let total_cash = Self::get_total_cash(asset_id);
let total_borrows = Self::total_borrows(asset_id);
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<T: Config> Pallet<T> {
Ok(())
}

pub(crate) fn update_last_accrued_interest_time(asset_id: AssetIdOf<T>, time: Timestamp) -> DispatchResult {
pub(crate) fn update_last_accrued_interest_time(asset_id: CurrencyId<T>, time: Timestamp) -> DispatchResult {
LastAccruedInterestTime::<T>::try_mutate(asset_id, |last_time| -> DispatchResult {
*last_time = time;
Ok(())
Expand Down
16 changes: 8 additions & 8 deletions crates/loans/src/lend_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{AssetIdOf, BalanceOf, *};
use crate::{BalanceOf, CurrencyId, *};

#[cfg(test)]
use frame_support::traits::tokens::{DepositConsequence, WithdrawConsequence};

#[cfg(test)]
impl<T: Config> Pallet<T> {
/// The total amount of issuance in the system.
pub fn total_issuance(lend_token_id: AssetIdOf<T>) -> BalanceOf<T> {
pub fn total_issuance(lend_token_id: CurrencyId<T>) -> BalanceOf<T> {
if let Ok(underlying_id) = Self::underlying_id(lend_token_id) {
if let Ok(supply) = Self::total_supply(underlying_id) {
return supply;
Expand All @@ -33,19 +33,19 @@ impl<T: Config> Pallet<T> {
}

/// The minimum balance any single account may have.
pub fn minimum_balance(_lend_token_id: AssetIdOf<T>) -> BalanceOf<T> {
pub fn minimum_balance(_lend_token_id: CurrencyId<T>) -> BalanceOf<T> {
Zero::zero()
}

/// Get the maximum amount that `who` can withdraw/transfer successfully.
/// For lend_token, We don't care if keep_alive is enabled
pub fn reducible_balance(lend_token_id: AssetIdOf<T>, who: &T::AccountId, _keep_alive: bool) -> BalanceOf<T> {
pub fn reducible_balance(lend_token_id: CurrencyId<T>, who: &T::AccountId, _keep_alive: bool) -> BalanceOf<T> {
Self::reducible_asset(lend_token_id, who).unwrap_or_default()
}

/// Returns `true` if the balance of `who` may be increased by `amount`.
pub fn can_deposit(
lend_token_id: AssetIdOf<T>,
lend_token_id: CurrencyId<T>,
who: &T::AccountId,
amount: BalanceOf<T>,
_mint: bool,
Expand Down Expand Up @@ -78,7 +78,7 @@ impl<T: Config> Pallet<T> {
/// Returns `Failed` if the balance of `who` may not be decreased by `amount`, otherwise
/// the consequence.
pub fn can_withdraw(
lend_token_id: AssetIdOf<T>,
lend_token_id: CurrencyId<T>,
who: &T::AccountId,
amount: BalanceOf<T>,
) -> WithdrawConsequence<BalanceOf<T>> {
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<T: Config> Pallet<T> {
/// For lend_token, We don't care if keep_alive is enabled
#[transactional]
pub fn transfer(
lend_token_id: AssetIdOf<T>,
lend_token_id: CurrencyId<T>,
source: &T::AccountId,
dest: &T::AccountId,
amount: BalanceOf<T>,
Expand All @@ -120,7 +120,7 @@ impl<T: Config> Pallet<T> {
Ok(amount)
}

fn reducible_asset(lend_token_id: AssetIdOf<T>, who: &T::AccountId) -> Result<BalanceOf<T>, DispatchError> {
fn reducible_asset(lend_token_id: CurrencyId<T>, who: &T::AccountId) -> Result<BalanceOf<T>, DispatchError> {
let voucher_balance = Self::account_deposits(lend_token_id, &who);

let underlying_id = Self::underlying_id(lend_token_id)?;
Expand Down
Loading