From fd4d7e3b4f6e6999dbec197629888b209ba658ba Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 8 May 2024 13:44:07 +0300 Subject: [PATCH] Feature/total collateral (#1031) * feature(kensetsu): adds field `total_collateral` that aggregates collateral locked for cdp type * feature(kensetsu): migration --- pallets/kensetsu/benchmarking/src/lib.rs | 1 + pallets/kensetsu/src/lib.rs | 188 +++++++++---------- pallets/kensetsu/src/migrations.rs | 137 ++++++++++++-- pallets/kensetsu/src/tests.rs | 94 +++++++--- pallets/kensetsu/src/weights.rs | 218 +++++++++++------------ runtime/src/migrations.rs | 3 +- 6 files changed, 407 insertions(+), 234 deletions(-) diff --git a/pallets/kensetsu/benchmarking/src/lib.rs b/pallets/kensetsu/benchmarking/src/lib.rs index 6343acd1f5..25fc1c2643 100644 --- a/pallets/kensetsu/benchmarking/src/lib.rs +++ b/pallets/kensetsu/benchmarking/src/lib.rs @@ -75,6 +75,7 @@ fn set_xor_as_collateral_type() { stability_fee_rate: FixedU128::from_perbill(Perbill::from_percent(10)), minimal_collateral_deposit: balance!(0), }, + total_collateral: balance!(0), kusd_supply: balance!(0), last_fee_update_time: Default::default(), interest_coefficient: FixedU128::one(), diff --git a/pallets/kensetsu/src/lib.rs b/pallets/kensetsu/src/lib.rs index 66f11f20eb..41c66fa5f4 100644 --- a/pallets/kensetsu/src/lib.rs +++ b/pallets/kensetsu/src/lib.rs @@ -110,6 +110,9 @@ pub struct CollateralInfo { /// Collateral Risk parameters set by risk management pub risk_parameters: CollateralRiskParameters, + /// Total collateral locked in all CDPs + pub total_collateral: Balance, + /// Amount of KUSD issued for the collateral pub kusd_supply: Balance, @@ -788,7 +791,13 @@ pub mod pallet { #[pallet::weight(::WeightInfo::donate())] pub fn donate(origin: OriginFor, kusd_amount: Balance) -> DispatchResult { let who = ensure_signed(origin)?; - Self::cover_bad_debt(&who, kusd_amount)?; + technical::Pallet::::transfer_in( + &T::KusdAssetId::get(), + &who, + &T::TreasuryTechAccount::get(), + kusd_amount, + )?; + Self::cover_bad_debt(kusd_amount)?; Self::deposit_event(Event::Donation { debt_asset_id: T::KusdAssetId::get(), amount: kusd_amount, @@ -1037,19 +1046,11 @@ pub mod pallet { // stablecoin minted is taxed by `borrow_tax` to buy back and burn KEN, the tax // increases debt Self::incentivize_ken_token(borrow_tax)?; - let new_debt = cdp - .debt - .checked_add(borrow_amount_with_tax) - .ok_or(Error::::ArithmeticError)?; Self::ensure_collateral_cap(cdp.collateral_asset_id, borrow_amount_with_tax)?; Self::ensure_protocol_cap(borrow_amount_with_tax)?; Self::mint_to(who, borrow_amount)?; - Self::update_cdp_debt(cdp_id, new_debt)?; - Self::increase_collateral_kusd_supply( - &cdp.collateral_asset_id, - borrow_amount_with_tax, - )?; + Self::increase_cdp_debt(cdp_id, borrow_amount_with_tax)?; Self::deposit_event(Event::DebtIncreased { cdp_id, owner: who.clone(), @@ -1072,13 +1073,7 @@ pub mod pallet { // if repaying amount exceeds debt, leftover is not burned let to_cover_debt = amount.min(cdp.debt); Self::burn_from(&cdp.owner, to_cover_debt)?; - Self::update_cdp_debt( - cdp_id, - cdp.debt - .checked_sub(to_cover_debt) - .ok_or(Error::::ArithmeticError)?, - )?; - Self::decrease_collateral_kusd_supply(&cdp.collateral_asset_id, to_cover_debt)?; + Self::decrease_cdp_debt(cdp_id, to_cover_debt)?; Self::deposit_event(Event::DebtPayment { cdp_id, owner: cdp.owner, @@ -1095,27 +1090,14 @@ pub mod pallet { /// /// ## Parameters /// - /// - `from`: The account from which the stablecoin will be used to cover bad debt. /// - `kusd_amount`: The amount of stablecoin to cover bad debt. - fn cover_bad_debt(from: &AccountIdOf, kusd_amount: Balance) -> DispatchResult { + fn cover_bad_debt(kusd_amount: Balance) -> DispatchResult { let bad_debt = BadDebt::::get(); - let to_cover_debt = if kusd_amount <= bad_debt { - kusd_amount - } else { - technical::Pallet::::transfer_in( - &T::KusdAssetId::get(), - from, - &T::TreasuryTechAccount::get(), - kusd_amount - .checked_sub(bad_debt) - .ok_or(Error::::ArithmeticError)?, - )?; - bad_debt - }; - Self::burn_from(from, to_cover_debt)?; + let bad_debt_change = bad_debt.min(kusd_amount); + Self::burn_treasury(bad_debt_change)?; BadDebt::::try_mutate(|bad_debt| { *bad_debt = bad_debt - .checked_sub(to_cover_debt) + .checked_sub(bad_debt_change) .ok_or(Error::::ArithmeticError)?; DispatchResult::Ok(()) })?; @@ -1240,7 +1222,7 @@ pub mod pallet { DispatchResult::Ok(()) })?; } - Self::increase_collateral_kusd_supply(&cdp.collateral_asset_id, stability_fee)?; + Self::increase_collateral_stablecoin_supply(&cdp.collateral_asset_id, stability_fee)?; Self::mint_treasury(&T::KusdAssetId::get(), stability_fee)?; Ok(cdp) @@ -1376,6 +1358,7 @@ pub mod pallet { // penalty is a protocol profit which stays on treasury tech account let penalty = Self::liquidation_penalty() * kusd_swapped.min(cdp.debt); + Self::cover_bad_debt(penalty)?; let proceeds = kusd_swapped - penalty; Self::update_cdp_collateral( cdp_id, @@ -1383,33 +1366,27 @@ pub mod pallet { .checked_sub(collateral_liquidated) .ok_or(Error::::ArithmeticError)?, )?; - // stablecoin supply change for collateral. - let kusd_supply_change: Balance; if cdp.debt > proceeds { Self::burn_treasury(proceeds)?; - let shortage = cdp - .debt - .checked_sub(proceeds) - .ok_or(Error::::ArithmeticError)?; if cdp.collateral_amount <= collateral_liquidated { // no collateral, total default // CDP debt is not covered with liquidation, now it is a protocol bad debt - let profit_burnt = Self::cover_with_protocol(shortage)?; + let shortage = cdp + .debt + .checked_sub(proceeds) + .ok_or(Error::::ArithmeticError)?; + Self::cover_with_protocol(shortage)?; // close empty CDP, debt == 0, collateral == 0 + Self::decrease_cdp_debt(cdp_id, cdp.debt)?; Self::delete_cdp(cdp_id)?; - kusd_supply_change = proceeds - .checked_add(profit_burnt) - .ok_or(Error::::ArithmeticError)?; } else { // partly covered - Self::update_cdp_debt(cdp_id, shortage)?; - kusd_supply_change = proceeds; + Self::decrease_cdp_debt(cdp_id, proceeds)?; } } else { Self::burn_treasury(cdp.debt)?; // CDP debt is covered - Self::update_cdp_debt(cdp_id, 0)?; - kusd_supply_change = cdp.debt; + Self::decrease_cdp_debt(cdp_id, cdp.debt)?; // There is more stablecoins than to cover debt and penalty, leftover goes to cdp.owner let leftover = proceeds .checked_sub(cdp.debt) @@ -1421,7 +1398,6 @@ pub mod pallet { leftover, )?; }; - Self::decrease_collateral_kusd_supply(&cdp.collateral_asset_id, kusd_supply_change)?; LiquidatedThisBlock::::put(true); Ok((collateral_liquidated, proceeds, penalty)) @@ -1462,7 +1438,7 @@ pub mod pallet { /// Cover CDP debt with protocol balance /// If protocol balance is less than amount to cover, it is a bad debt - fn cover_with_protocol(amount: Balance) -> Result { + fn cover_with_protocol(amount: Balance) -> DispatchResult { let treasury_account_id = technical::Pallet::::tech_account_id_to_account_id( &T::TreasuryTechAccount::get(), )?; @@ -1485,7 +1461,7 @@ pub mod pallet { }; Self::burn_treasury(to_burn)?; - Ok(to_burn) + Ok(()) } /// Increments CDP Id counter, changes storage state. @@ -1512,17 +1488,54 @@ pub mod pallet { fn update_cdp_collateral(cdp_id: CdpId, collateral_amount: Balance) -> DispatchResult { CDPDepository::::try_mutate(cdp_id, |cdp| { let cdp = cdp.as_mut().ok_or(Error::::CDPNotFound)?; + let old_collateral = cdp.collateral_amount; + CollateralInfos::::try_mutate(cdp.collateral_asset_id, |collateral_info| { + let collateral_info = collateral_info + .as_mut() + .ok_or(Error::::CollateralInfoNotFound)?; + collateral_info.total_collateral = collateral_info + .total_collateral + .checked_sub(old_collateral) + .ok_or(Error::::ArithmeticError)? + .checked_add(collateral_amount) + .ok_or(Error::::ArithmeticError)?; + Ok::<(), Error>(()) + })?; cdp.collateral_amount = collateral_amount; Ok(()) }) } - /// Updates CDP debt balance - fn update_cdp_debt(cdp_id: CdpId, debt: Balance) -> DispatchResult { + /// Updates CDP debt by increasing the value. + fn increase_cdp_debt(cdp_id: CdpId, debt_change: Balance) -> DispatchResult { CDPDepository::::try_mutate(cdp_id, |cdp| { let cdp = cdp.as_mut().ok_or(Error::::CDPNotFound)?; - cdp.debt = debt; - Ok(()) + cdp.debt = cdp + .debt + .checked_add(debt_change) + .ok_or(Error::::ArithmeticError)?; + Self::increase_collateral_stablecoin_supply(&cdp.collateral_asset_id, debt_change) + }) + } + + /// Updates CDP debt by decreasing the value. + fn decrease_cdp_debt(cdp_id: CdpId, debt_change: Balance) -> DispatchResult { + CDPDepository::::try_mutate(cdp_id, |cdp| { + let cdp = cdp.as_mut().ok_or(Error::::CDPNotFound)?; + cdp.debt = cdp + .debt + .checked_sub(debt_change) + .ok_or(Error::::ArithmeticError)?; + CollateralInfos::::try_mutate(cdp.collateral_asset_id, |collateral_info| { + let collateral_info = collateral_info + .as_mut() + .ok_or(Error::::CollateralInfoNotFound)?; + collateral_info.kusd_supply = collateral_info + .kusd_supply + .checked_sub(debt_change) + .ok_or(Error::::ArithmeticError)?; + Ok(()) + }) }) } @@ -1536,6 +1549,16 @@ pub mod pallet { &cdp.owner, transfer_out, )?; + CollateralInfos::::try_mutate(cdp.collateral_asset_id, |collateral_info| { + let collateral_info = collateral_info + .as_mut() + .ok_or(Error::::CollateralInfoNotFound)?; + collateral_info.total_collateral = collateral_info + .total_collateral + .checked_sub(transfer_out) + .ok_or(Error::::ArithmeticError)?; + Ok::<(), Error>(()) + })?; if let Some(mut cdp_ids) = CdpOwnerIndex::::take(&cdp.owner) { cdp_ids.retain(|&x| x != cdp_id); if !cdp_ids.is_empty() { @@ -1551,40 +1574,6 @@ pub mod pallet { Ok(()) } - /// Increases tracker of KUSD supply for collateral asset - fn increase_collateral_kusd_supply( - collateral_asset_id: &AssetIdOf, - additional_kusd_supply: Balance, - ) -> DispatchResult { - CollateralInfos::::try_mutate(collateral_asset_id, |collateral_info| { - let collateral_info = collateral_info - .as_mut() - .ok_or(Error::::CollateralInfoNotFound)?; - collateral_info.kusd_supply = collateral_info - .kusd_supply - .checked_add(additional_kusd_supply) - .ok_or(Error::::ArithmeticError)?; - Ok(()) - }) - } - - /// Decreases tracker of KUSD supply for collateral asset - fn decrease_collateral_kusd_supply( - collateral_asset_id: &AssetIdOf, - seized_kusd_supply: Balance, - ) -> DispatchResult { - CollateralInfos::::try_mutate(collateral_asset_id, |collateral_info| { - let collateral_info = collateral_info - .as_mut() - .ok_or(Error::::CollateralInfoNotFound)?; - collateral_info.kusd_supply = collateral_info - .kusd_supply - .checked_sub(seized_kusd_supply) - .ok_or(Error::::ArithmeticError)?; - Ok(()) - }) - } - /// Inserts or updates `CollateralRiskParameters` for collateral asset id. /// If `CollateralRiskParameters` exists for asset id, then updates them. /// Else if `CollateralRiskParameters` does not exist, inserts a new value. @@ -1611,7 +1600,8 @@ pub mod pallet { None => { let _ = option_collateral_info.insert(CollateralInfo { risk_parameters: new_risk_parameters, - kusd_supply: balance!(0), + total_collateral: Balance::zero(), + kusd_supply: Balance::zero(), last_fee_update_time: Timestamp::::get(), interest_coefficient: FixedU128::one(), }); @@ -1621,6 +1611,22 @@ pub mod pallet { }) } + fn increase_collateral_stablecoin_supply( + collateral_asset_id: &T::AssetId, + supply_change: Balance, + ) -> DispatchResult { + CollateralInfos::::try_mutate(collateral_asset_id, |collateral_info| { + let collateral_info = collateral_info + .as_mut() + .ok_or(Error::::CollateralInfoNotFound)?; + collateral_info.kusd_supply = collateral_info + .kusd_supply + .checked_add(supply_change) + .ok_or(Error::::ArithmeticError)?; + Ok(()) + }) + } + /// Returns CDP ids where the account id is owner pub fn get_account_cdp_ids( account_id: &AccountIdOf, diff --git a/pallets/kensetsu/src/migrations.rs b/pallets/kensetsu/src/migrations.rs index 8c657a3006..a1098e1297 100644 --- a/pallets/kensetsu/src/migrations.rs +++ b/pallets/kensetsu/src/migrations.rs @@ -101,7 +101,7 @@ pub mod init { /// Due to bug in stability fee update some extra KUSD were minted, this migration burns and sets /// correct amounts. pub mod stage_correction { - use crate::{CDPDepository, CollateralInfos, Config, Error}; + use crate::{BadDebt, CDPDepository, CollateralInfos, Config, Error}; use common::AssetInfoProvider; use common::Balance; use core::marker::PhantomData; @@ -142,21 +142,64 @@ pub mod stage_correction { total_debt += accumulated_debt_for_collateral; } - // burn KUSD on tech account + let bad_debt = BadDebt::::get(); + total_debt += bad_debt; + + // kusd supply must be equal to aggregated debt: + // kusd_supply == sum(cdp.debt) + bad_debt + let kusd_supply = T::AssetInfoProvider::total_issuance(&T::KusdAssetId::get())?; + *weight += ::DbWeight::get().reads(1); + + let (surplus, shortage) = if kusd_supply > total_debt { + (kusd_supply - total_debt, 0) + } else { + (0, total_debt - kusd_supply) + }; + let treasury_account_id = technical::Pallet::::tech_account_id_to_account_id( &T::TreasuryTechAccount::get(), )?; - let balance = + let profit = T::AssetInfoProvider::free_balance(&T::KusdAssetId::get(), &treasury_account_id)?; - let to_burn = balance - total_debt; - assets::Pallet::::burn_from( - &T::KusdAssetId::get(), - &treasury_account_id, - &treasury_account_id, - to_burn, - )?; + *weight += ::DbWeight::get().reads(1); + + // burn KUSD surplus on tech acc profit or add to bad debt + if surplus > 0 { + let (to_burn, to_bad_debt) = if profit > surplus { + (surplus, 0) + } else { + (profit, surplus - profit) + }; + assets::Pallet::::burn_from( + &T::KusdAssetId::get(), + &treasury_account_id, + &treasury_account_id, + to_burn, + )?; + + BadDebt::::set(bad_debt + to_bad_debt); + + *weight += ::DbWeight::get().writes(2); + } + + // mint KUSD shortage to tech acc or cover bad debt + if shortage > 0 { + let (from_bad_debt, to_mint) = if bad_debt > shortage { + (shortage, 0) + } else { + (bad_debt, shortage - bad_debt) + }; + + technical::Pallet::::mint( + &T::KusdAssetId::get(), + &T::TreasuryTechAccount::get(), + to_mint, + )?; - *weight += ::DbWeight::get().writes(1); + BadDebt::::set(bad_debt - from_bad_debt); + + *weight += ::DbWeight::get().writes(2); + } Ok(()) } @@ -175,6 +218,78 @@ pub mod stage_correction { } } +pub mod storage_add_total_collateral { + use crate::{CDPDepository, CollateralInfos, Config}; + use common::Balance; + use core::marker::PhantomData; + use frame_support::dispatch::Weight; + use frame_support::traits::OnRuntimeUpgrade; + use sp_arithmetic::traits::Zero; + use sp_core::Get; + + mod old { + use crate::CollateralRiskParameters; + use codec::{Decode, Encode, MaxEncodedLen}; + use common::Balance; + use frame_support::dispatch::TypeInfo; + use sp_arithmetic::FixedU128; + + /// Old format without `total_collateral` field. + #[derive( + Debug, Clone, Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq, Eq, PartialOrd, Ord, + )] + pub struct CollateralInfo { + /// Collateral Risk parameters set by risk management + pub risk_parameters: CollateralRiskParameters, + + /// Amount of KUSD issued for the collateral + pub kusd_supply: Balance, + + /// the last timestamp when stability fee was accrued + pub last_fee_update_time: Moment, + + /// Interest accrued for collateral for all time + pub interest_coefficient: FixedU128, + } + + impl CollateralInfo { + // Returns new format with provided `total_collateral`. + pub fn into_new(self, total_collateral: Balance) -> crate::CollateralInfo { + crate::CollateralInfo { + risk_parameters: self.risk_parameters, + total_collateral, + kusd_supply: self.kusd_supply, + last_fee_update_time: self.last_fee_update_time, + interest_coefficient: self.interest_coefficient, + } + } + } + } + + pub struct StorageAddTotalCollateral(PhantomData); + + impl OnRuntimeUpgrade for StorageAddTotalCollateral { + fn on_runtime_upgrade() -> Weight { + let mut weight = Weight::zero(); + CollateralInfos::::translate::, _>( + |collateral_asset_id, old_collateral_info| { + let accumulated_collateral = CDPDepository::::iter() + .filter(|(_, cdp)| { + weight += ::DbWeight::get().reads(1); + cdp.collateral_asset_id == collateral_asset_id + }) + .fold(Balance::zero(), |accumulated_collateral, (_, cdp)| { + accumulated_collateral + cdp.collateral_amount + }); + weight += ::DbWeight::get().writes(1); + Some(old_collateral_info.into_new(accumulated_collateral)) + }, + ); + weight + } + } +} + pub mod remove_managers { mod old { diff --git a/pallets/kensetsu/src/tests.rs b/pallets/kensetsu/src/tests.rs index 8f02e3e1ff..b5b0339633 100644 --- a/pallets/kensetsu/src/tests.rs +++ b/pallets/kensetsu/src/tests.rs @@ -202,6 +202,7 @@ fn test_create_cdp_sunny_day() { ); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, debt); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Shall create CDP"); assert_eq!(cdp.owner, alice_account_id()); assert_eq!(cdp.collateral_asset_id, XOR); @@ -334,6 +335,9 @@ fn test_close_cdp_sunny_day() { .into(), ); assert_balance(&alice_account_id(), &XOR, balance!(10)); + let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); + assert_eq!(collateral_info.kusd_supply, balance!(0)); + assert_eq!(collateral_info.total_collateral, balance!(0)); assert_eq!(KensetsuPallet::cdp(cdp_id), None); assert_eq!(KensetsuPallet::cdp_owner_index(alice_account_id()), None); }); @@ -467,6 +471,8 @@ fn test_deposit_collateral_zero() { } .into(), ); + let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); + assert_eq!(collateral_info.total_collateral, amount); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.collateral_amount, amount); }); @@ -498,6 +504,8 @@ fn test_deposit_collateral_sunny_day() { .into(), ); assert_balance(&alice_account_id(), &XOR, balance!(0)); + let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("Must exists"); + assert_eq!(collateral_info.total_collateral, amount); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.collateral_amount, amount); }); @@ -683,7 +691,8 @@ fn test_borrow_sunny_day() { FixedU128::from_float(0.0), balance!(0), ); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), balance!(0)); + let collateral = balance!(100); + let cdp_id = create_cdp_for_xor(alice(), collateral, balance!(0)); let to_borrow = balance!(10); let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, balance!(0)); @@ -704,8 +713,9 @@ fn test_borrow_sunny_day() { } .into(), ); - let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); + let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("Must exists"); assert_eq!(collateral_info.kusd_supply, to_borrow); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, to_borrow); assert_balance(&alice_account_id(), &KUSD, to_borrow); @@ -725,7 +735,8 @@ fn test_borrow_max_amount() { FixedU128::from_float(0.0), balance!(0), ); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), balance!(0)); + let collateral = balance!(100); + let cdp_id = create_cdp_for_xor(alice(), collateral, balance!(0)); let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, balance!(0)); @@ -742,8 +753,9 @@ fn test_borrow_max_amount() { } .into(), ); - let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); + let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("Must exists"); assert_eq!(collateral_info.kusd_supply, expected_debt); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, expected_debt); assert_balance(&alice_account_id(), &KUSD, expected_debt); @@ -765,7 +777,8 @@ fn borrow_with_ken_incentivization() { FixedU128::from_float(0.0), balance!(0), ); - let cdp_id = create_cdp_for_xor(alice(), balance!(1000), balance!(0)); + let collateral = balance!(1000); + let cdp_id = create_cdp_for_xor(alice(), collateral, balance!(0)); let to_borrow = balance!(100); let borrow_tax = balance!(1); let initial_total_kusd_supply = get_total_supply(&KUSD); @@ -790,8 +803,9 @@ fn borrow_with_ken_incentivization() { .into(), ); - let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); + let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("Must exists"); assert_eq!(collateral_info.kusd_supply, to_borrow + borrow_tax); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, to_borrow + borrow_tax); assert_balance(&alice_account_id(), &KUSD, to_borrow); @@ -819,7 +833,8 @@ fn borrow_max_with_ken_incentivization() { FixedU128::from_float(0.0), balance!(0), ); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), balance!(0)); + let collateral = balance!(100); + let cdp_id = create_cdp_for_xor(alice(), collateral, balance!(0)); let to_borrow_min = balance!(99); let to_borrow_max = balance!(100); // user receives @@ -851,6 +866,7 @@ fn borrow_max_with_ken_incentivization() { let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, actual_loan + borrow_tax); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, actual_loan + borrow_tax); assert_balance(&alice_account_id(), &KUSD, actual_loan); @@ -877,7 +893,8 @@ fn test_borrow_cdp_accrue() { balance!(0), ); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let collateral = balance!(100); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); pallet_timestamp::Pallet::::set_timestamp(1); let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, balance!(10)); @@ -894,6 +911,7 @@ fn test_borrow_cdp_accrue() { let interest = balance!(1); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, debt + interest); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt + interest); assert_balance(&alice_account_id(), &KUSD, balance!(10)); @@ -944,8 +962,9 @@ fn test_repay_debt_amount_less_debt() { FixedU128::from_float(0.0), balance!(0), ); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); let to_repay = balance!(1); let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, debt); @@ -963,6 +982,7 @@ fn test_repay_debt_amount_less_debt() { ); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, debt - to_repay); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt - to_repay); let total_kusd_supply = get_total_supply(&KUSD); @@ -981,8 +1001,9 @@ fn test_repay_debt_amount_eq_debt() { FixedU128::from_float(0.0), balance!(0), ); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, debt); @@ -999,6 +1020,7 @@ fn test_repay_debt_amount_eq_debt() { ); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, balance!(0)); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, balance!(0)); let total_kusd_supply = get_total_supply(&KUSD); @@ -1017,11 +1039,12 @@ fn test_repay_debt_amount_gt_debt() { FixedU128::from_float(0.0), balance!(0), ); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); // create 2nd CDP and borrow for KUSD surplus on Alice account let kusd_surplus = balance!(5); - create_cdp_for_xor(alice(), balance!(100), kusd_surplus); + create_cdp_for_xor(alice(), collateral, kusd_surplus); let total_kusd_balance = debt + kusd_surplus; let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, total_kusd_balance); @@ -1043,6 +1066,7 @@ fn test_repay_debt_amount_gt_debt() { ); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, kusd_surplus); + assert_eq!(collateral_info.total_collateral, 2 * collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, balance!(0)); let total_kusd_supply = get_total_supply(&KUSD); @@ -1062,8 +1086,9 @@ fn test_repay_debt_zero_amount() { FixedU128::from_float(0.0), balance!(0), ); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, debt); @@ -1080,6 +1105,7 @@ fn test_repay_debt_zero_amount() { ); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, debt); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt); let total_kusd_supply = get_total_supply(&KUSD); @@ -1098,8 +1124,9 @@ fn test_repay_debt_accrue() { FixedU128::from_float(0.1), balance!(0), ); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); let initial_total_kusd_supply = get_total_supply(&KUSD); assert_eq!(initial_total_kusd_supply, debt); pallet_timestamp::Pallet::::set_timestamp(1); @@ -1111,6 +1138,7 @@ fn test_repay_debt_accrue() { let interest = balance!(1); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, debt + interest); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt + interest); assert_balance(&alice_account_id(), &KUSD, balance!(10)); @@ -1152,8 +1180,8 @@ fn test_liquidate_cdp_safe() { }); } -/// Given: CDP with collateral 10000 XOR and it is unsafe -/// @When: Liquidation triggered that sell 1000 XOR and doesn't change debt +/// Given: CDP with collateral 10000 XOR and it is unsafe. +/// @When: Liquidation triggered that doesn't change debt. /// Success, debt increased and KUSD is minted to tech treasury account. #[test] fn test_liquidate_accrue() { @@ -1165,8 +1193,9 @@ fn test_liquidate_accrue() { balance!(0), ); // the CDP will be unsafe in the next millisecond + let collateral = balance!(10000); let debt = balance!(1000); - let cdp_id = create_cdp_for_xor(alice(), balance!(10000), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); pallet_timestamp::Pallet::::set_timestamp(1); MockLiquidityProxy::set_amounts_for_the_next_exchange(KUSD, balance!(0)); let initial_total_kusd_supply = get_total_supply(&KUSD); @@ -1179,6 +1208,7 @@ fn test_liquidate_accrue() { let interest = balance!(100); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, debt + interest); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt + interest); assert_balance(&alice_account_id(), &KUSD, debt); @@ -1237,6 +1267,10 @@ fn test_liquidate_kusd_amount_covers_cdp_debt_and_penalty() { assert_balance(&tech_account_id(), &KUSD, penalty); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, balance!(0)); + assert_eq!( + collateral_info.total_collateral, + collateral - collateral_liquidated + ); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); // initial collateral 2000 XOR, 200 XOR sold during liquidation assert_eq!(cdp.collateral_amount, balance!(1800)); @@ -1302,6 +1336,10 @@ fn test_liquidate_kusd_amount_eq_cdp_debt_and_penalty() { assert_balance(&tech_account_id(), &KUSD, penalty); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, balance!(0)); + assert_eq!( + collateral_info.total_collateral, + collateral - collateral_liquidated + ); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); // initial collateral 2000 XOR, 110 XOR sold during liquidation assert_eq!(cdp.collateral_amount, collateral - collateral_liquidated); @@ -1366,6 +1404,10 @@ fn test_liquidate_kusd_amount_covers_cdp_debt_and_partly_penalty() { assert_balance(&tech_account_id(), &KUSD, penalty); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, balance!(50)); + assert_eq!( + collateral_info.total_collateral, + collateral - collateral_liquidated + ); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); // initial collateral 2000 XOR, 1050 XOR sold during liquidation assert_eq!(cdp.collateral_amount, collateral - collateral_liquidated); @@ -1443,6 +1485,7 @@ fn test_liquidate_kusd_amount_does_not_cover_cdp_debt() { assert_bad_debt(balance!(0)); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, balance!(0)); + assert_eq!(collateral_info.total_collateral, balance!(0)); assert_eq!(KensetsuPallet::cdp(cdp_id), None); assert_eq!(KensetsuPallet::cdp_owner_index(alice_account_id()), None); assert_balance(&alice_account_id(), &KUSD, debt); @@ -1529,7 +1572,8 @@ fn test_liquidate_kusd_bad_debt() { assert_bad_debt(balance!(10)); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); // 10 KUSD minted by the protocol (accounted in bad debt) - assert_eq!(collateral_info.kusd_supply, balance!(10)); + assert_eq!(collateral_info.kusd_supply, balance!(0)); + assert_eq!(collateral_info.total_collateral, balance!(0)); assert_eq!(KensetsuPallet::cdp(cdp_id), None); assert_eq!(KensetsuPallet::cdp_owner_index(alice_account_id()), None); assert_balance(&bob_account_id(), &KUSD, interest); @@ -1662,8 +1706,9 @@ fn test_accrue_profit() { FixedU128::from_float(0.1), balance!(0), ); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); // 1 sec passed pallet_timestamp::Pallet::::set_timestamp(1); let initial_kusd_supply = get_total_supply(&KUSD); @@ -1675,6 +1720,7 @@ fn test_accrue_profit() { let interest = balance!(1); let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); assert_eq!(collateral_info.kusd_supply, debt + interest); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt + interest); let total_kusd_supply = get_total_supply(&KUSD); @@ -1725,8 +1771,9 @@ fn test_accrue_interest_less_bad_debt() { balance!(0), ); set_bad_debt(balance!(2)); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); // 1 sec passed pallet_timestamp::Pallet::::set_timestamp(1); let initial_kusd_supply = get_total_supply(&KUSD); @@ -1741,6 +1788,7 @@ fn test_accrue_interest_less_bad_debt() { let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); // fee is burned as bad debt, no KUSD minted assert_eq!(collateral_info.kusd_supply, debt); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt + interest); let total_kusd_supply = get_total_supply(&KUSD); @@ -1765,8 +1813,9 @@ fn test_accrue_interest_eq_bad_debt() { balance!(0), ); set_bad_debt(balance!(1)); + let collateral = balance!(100); let debt = balance!(10); - let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); + let cdp_id = create_cdp_for_xor(alice(), collateral, debt); let initial_kusd_supply = get_total_supply(&KUSD); // 1 sec passed pallet_timestamp::Pallet::::set_timestamp(1); @@ -1780,6 +1829,7 @@ fn test_accrue_interest_eq_bad_debt() { let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); // supply doesn't change, fee is burned as bad debt assert_eq!(collateral_info.kusd_supply, debt); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt + interest); let total_kusd_supply = get_total_supply(&KUSD); @@ -1804,6 +1854,7 @@ fn test_accrue_interest_gt_bad_debt() { balance!(0), ); set_bad_debt(balance!(1)); + let collateral = balance!(100); let debt = balance!(10); let cdp_id = create_cdp_for_xor(alice(), balance!(100), debt); // 1 sec passed @@ -1820,6 +1871,7 @@ fn test_accrue_interest_gt_bad_debt() { let collateral_info = KensetsuPallet::collateral_infos(XOR).expect("must exists"); // 1 KUSD goes to profit and 1 is burned as bad debt assert_eq!(collateral_info.kusd_supply, debt + profit); + assert_eq!(collateral_info.total_collateral, collateral); let cdp = KensetsuPallet::cdp(cdp_id).expect("Must exist"); assert_eq!(cdp.debt, debt + interest); let total_kusd_supply = get_total_supply(&KUSD); diff --git a/pallets/kensetsu/src/weights.rs b/pallets/kensetsu/src/weights.rs index ee59229145..f2541efcd3 100644 --- a/pallets/kensetsu/src/weights.rs +++ b/pallets/kensetsu/src/weights.rs @@ -31,7 +31,7 @@ //! Autogenerated weights for kensetsu //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-05-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `MacBook-Pro-Alexey.local`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("local"), DB CACHE: 1024 @@ -84,7 +84,7 @@ pub trait WeightInfo { pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Kensetsu NextCDPId (r:1 w:1) /// Proof: Kensetsu NextCDPId (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Kensetsu CdpOwnerIndex (r:1 w:1) @@ -115,17 +115,17 @@ impl WeightInfo for SubstrateWeight { /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn create_cdp() -> Weight { // Proof Size summary in bytes: - // Measured: `5743` - // Estimated: `213351` - // Minimum execution time: 119_000_000 picoseconds. - Weight::from_parts(120_000_000, 213351) + // Measured: `5759` + // Estimated: `213431` + // Minimum execution time: 123_000_000 picoseconds. + Weight::from_parts(131_000_000, 213431) .saturating_add(T::DbWeight::get().reads(16_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -140,10 +140,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Kensetsu CdpOwnerIndex (max_values: None, max_size: Some(160034), added: 162509, mode: MaxEncodedLen) fn close_cdp() -> Weight { // Proof Size summary in bytes: - // Measured: `2253` - // Estimated: `185400` - // Minimum execution time: 69_000_000 picoseconds. - Weight::from_parts(70_000_000, 185400) + // Measured: `2269` + // Estimated: `185464` + // Minimum execution time: 75_000_000 picoseconds. + Weight::from_parts(77_000_000, 185464) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -153,19 +153,21 @@ impl WeightInfo for SubstrateWeight { /// Proof Skipped: Technical TechAccounts (max_values: None, max_size: None, mode: Measured) /// Storage: System Account (r:2 w:2) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Kensetsu CollateralInfos (r:1 w:1) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) fn deposit_collateral() -> Weight { // Proof Size summary in bytes: - // Measured: `1491` - // Estimated: `11775` - // Minimum execution time: 41_000_000 picoseconds. - Weight::from_parts(42_000_000, 11775) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `1669` + // Estimated: `14584` + // Minimum execution time: 46_000_000 picoseconds. + Weight::from_parts(49_000_000, 14584) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -188,17 +190,17 @@ impl WeightInfo for SubstrateWeight { /// Proof: Tokens Accounts (max_values: None, max_size: Some(136), added: 2611, mode: MaxEncodedLen) fn borrow() -> Weight { // Proof Size summary in bytes: - // Measured: `5553` - // Estimated: `46968` - // Minimum execution time: 81_000_000 picoseconds. - Weight::from_parts(83_000_000, 46968) + // Measured: `5569` + // Estimated: `47048` + // Minimum execution time: 85_000_000 picoseconds. + Weight::from_parts(92_000_000, 47048) .saturating_add(T::DbWeight::get().reads(13_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -215,10 +217,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) fn repay_debt() -> Weight { // Proof Size summary in bytes: - // Measured: `3143` - // Estimated: `30703` - // Minimum execution time: 67_000_000 picoseconds. - Weight::from_parts(70_000_000, 30703) + // Measured: `3159` + // Estimated: `30767` + // Minimum execution time: 71_000_000 picoseconds. + Weight::from_parts(76_000_000, 30767) .saturating_add(T::DbWeight::get().reads(10_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -227,10 +229,10 @@ impl WeightInfo for SubstrateWeight { /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) - /// Storage: Kensetsu BadDebt (r:1 w:0) + /// Storage: Kensetsu BadDebt (r:1 w:1) /// Proof: Kensetsu BadDebt (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Technical TechAccounts (r:3 w:0) /// Proof Skipped: Technical TechAccounts (max_values: None, max_size: None, mode: Measured) @@ -268,17 +270,17 @@ impl WeightInfo for SubstrateWeight { /// Proof Skipped: PoolXYK Reserves (max_values: None, max_size: None, mode: Measured) fn liquidate() -> Weight { // Proof Size summary in bytes: - // Measured: `8024` - // Estimated: `155447` - // Minimum execution time: 277_000_000 picoseconds. - Weight::from_parts(284_000_000, 155447) + // Measured: `8040` + // Estimated: `155655` + // Minimum execution time: 294_000_000 picoseconds. + Weight::from_parts(318_000_000, 155655) .saturating_add(T::DbWeight::get().reads(29_u64)) - .saturating_add(T::DbWeight::get().writes(11_u64)) + .saturating_add(T::DbWeight::get().writes(12_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -297,25 +299,25 @@ impl WeightInfo for SubstrateWeight { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn accrue() -> Weight { // Proof Size summary in bytes: - // Measured: `3152` - // Estimated: `33333` - // Minimum execution time: 67_000_000 picoseconds. - Weight::from_parts(68_000_000, 33333) + // Measured: `3168` + // Estimated: `33397` + // Minimum execution time: 70_000_000 picoseconds. + Weight::from_parts(75_000_000, 33397) .saturating_add(T::DbWeight::get().reads(11_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: Assets AssetOwners (r:1 w:0) /// Proof Skipped: Assets AssetOwners (max_values: None, max_size: None, mode: Measured) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn update_collateral_risk_parameters() -> Weight { // Proof Size summary in bytes: // Measured: `776` - // Estimated: `6369` - // Minimum execution time: 15_000_000 picoseconds. - Weight::from_parts(16_000_000, 6369) + // Estimated: `6385` + // Minimum execution time: 16_000_000 picoseconds. + Weight::from_parts(16_000_000, 6385) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -325,7 +327,7 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `147` // Estimated: `511` - // Minimum execution time: 7_000_000 picoseconds. + // Minimum execution time: 8_000_000 picoseconds. Weight::from_parts(8_000_000, 511) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) @@ -362,30 +364,28 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1361` // Estimated: `14264` - // Minimum execution time: 41_000_000 picoseconds. - Weight::from_parts(42_000_000, 14264) + // Minimum execution time: 42_000_000 picoseconds. + Weight::from_parts(44_000_000, 14264) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } - /// Storage: Kensetsu BadDebt (r:1 w:1) - /// Proof: Kensetsu BadDebt (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Technical TechAccounts (r:1 w:0) /// Proof Skipped: Technical TechAccounts (max_values: None, max_size: None, mode: Measured) /// Storage: Tokens Accounts (r:2 w:2) /// Proof: Tokens Accounts (max_values: None, max_size: Some(136), added: 2611, mode: MaxEncodedLen) /// Storage: System Account (r:2 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Permissions Permissions (r:2 w:0) - /// Proof Skipped: Permissions Permissions (max_values: None, max_size: None, mode: Measured) + /// Storage: Kensetsu BadDebt (r:1 w:1) + /// Proof: Kensetsu BadDebt (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Tokens TotalIssuance (r:1 w:1) /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) fn donate() -> Weight { // Proof Size summary in bytes: - // Measured: `2340` - // Estimated: `25575` - // Minimum execution time: 64_000_000 picoseconds. - Weight::from_parts(65_000_000, 25575) - .saturating_add(T::DbWeight::get().reads(9_u64)) + // Measured: `1929` + // Estimated: `17874` + // Minimum execution time: 60_000_000 picoseconds. + Weight::from_parts(61_000_000, 17874) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } } @@ -393,7 +393,7 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Kensetsu NextCDPId (r:1 w:1) /// Proof: Kensetsu NextCDPId (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Kensetsu CdpOwnerIndex (r:1 w:1) @@ -424,17 +424,17 @@ impl WeightInfo for () { /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn create_cdp() -> Weight { // Proof Size summary in bytes: - // Measured: `5743` - // Estimated: `213351` - // Minimum execution time: 119_000_000 picoseconds. - Weight::from_parts(120_000_000, 213351) + // Measured: `5759` + // Estimated: `213431` + // Minimum execution time: 123_000_000 picoseconds. + Weight::from_parts(131_000_000, 213431) .saturating_add(RocksDbWeight::get().reads(16_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -449,10 +449,10 @@ impl WeightInfo for () { /// Proof: Kensetsu CdpOwnerIndex (max_values: None, max_size: Some(160034), added: 162509, mode: MaxEncodedLen) fn close_cdp() -> Weight { // Proof Size summary in bytes: - // Measured: `2253` - // Estimated: `185400` - // Minimum execution time: 69_000_000 picoseconds. - Weight::from_parts(70_000_000, 185400) + // Measured: `2269` + // Estimated: `185464` + // Minimum execution time: 75_000_000 picoseconds. + Weight::from_parts(77_000_000, 185464) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -462,19 +462,21 @@ impl WeightInfo for () { /// Proof Skipped: Technical TechAccounts (max_values: None, max_size: None, mode: Measured) /// Storage: System Account (r:2 w:2) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Kensetsu CollateralInfos (r:1 w:1) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) fn deposit_collateral() -> Weight { // Proof Size summary in bytes: - // Measured: `1491` - // Estimated: `11775` - // Minimum execution time: 41_000_000 picoseconds. - Weight::from_parts(42_000_000, 11775) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) + // Measured: `1669` + // Estimated: `14584` + // Minimum execution time: 46_000_000 picoseconds. + Weight::from_parts(49_000_000, 14584) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -497,17 +499,17 @@ impl WeightInfo for () { /// Proof: Tokens Accounts (max_values: None, max_size: Some(136), added: 2611, mode: MaxEncodedLen) fn borrow() -> Weight { // Proof Size summary in bytes: - // Measured: `5553` - // Estimated: `46968` - // Minimum execution time: 81_000_000 picoseconds. - Weight::from_parts(83_000_000, 46968) + // Measured: `5569` + // Estimated: `47048` + // Minimum execution time: 85_000_000 picoseconds. + Weight::from_parts(92_000_000, 47048) .saturating_add(RocksDbWeight::get().reads(13_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -524,10 +526,10 @@ impl WeightInfo for () { /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) fn repay_debt() -> Weight { // Proof Size summary in bytes: - // Measured: `3143` - // Estimated: `30703` - // Minimum execution time: 67_000_000 picoseconds. - Weight::from_parts(70_000_000, 30703) + // Measured: `3159` + // Estimated: `30767` + // Minimum execution time: 71_000_000 picoseconds. + Weight::from_parts(76_000_000, 30767) .saturating_add(RocksDbWeight::get().reads(10_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -536,10 +538,10 @@ impl WeightInfo for () { /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) - /// Storage: Kensetsu BadDebt (r:1 w:0) + /// Storage: Kensetsu BadDebt (r:1 w:1) /// Proof: Kensetsu BadDebt (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Technical TechAccounts (r:3 w:0) /// Proof Skipped: Technical TechAccounts (max_values: None, max_size: None, mode: Measured) @@ -577,17 +579,17 @@ impl WeightInfo for () { /// Proof Skipped: PoolXYK Reserves (max_values: None, max_size: None, mode: Measured) fn liquidate() -> Weight { // Proof Size summary in bytes: - // Measured: `8024` - // Estimated: `155447` - // Minimum execution time: 277_000_000 picoseconds. - Weight::from_parts(284_000_000, 155447) + // Measured: `8040` + // Estimated: `155655` + // Minimum execution time: 294_000_000 picoseconds. + Weight::from_parts(318_000_000, 155655) .saturating_add(RocksDbWeight::get().reads(29_u64)) - .saturating_add(RocksDbWeight::get().writes(11_u64)) + .saturating_add(RocksDbWeight::get().writes(12_u64)) } /// Storage: Kensetsu CDPDepository (r:1 w:1) /// Proof: Kensetsu CDPDepository (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: Kensetsu BadDebt (r:1 w:0) @@ -606,25 +608,25 @@ impl WeightInfo for () { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn accrue() -> Weight { // Proof Size summary in bytes: - // Measured: `3152` - // Estimated: `33333` - // Minimum execution time: 67_000_000 picoseconds. - Weight::from_parts(68_000_000, 33333) + // Measured: `3168` + // Estimated: `33397` + // Minimum execution time: 70_000_000 picoseconds. + Weight::from_parts(75_000_000, 33397) .saturating_add(RocksDbWeight::get().reads(11_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } /// Storage: Assets AssetOwners (r:1 w:0) /// Proof Skipped: Assets AssetOwners (max_values: None, max_size: None, mode: Measured) /// Storage: Kensetsu CollateralInfos (r:1 w:1) - /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(140), added: 2615, mode: MaxEncodedLen) + /// Proof: Kensetsu CollateralInfos (max_values: None, max_size: Some(156), added: 2631, mode: MaxEncodedLen) /// Storage: Timestamp Now (r:1 w:0) /// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) fn update_collateral_risk_parameters() -> Weight { // Proof Size summary in bytes: // Measured: `776` - // Estimated: `6369` - // Minimum execution time: 15_000_000 picoseconds. - Weight::from_parts(16_000_000, 6369) + // Estimated: `6385` + // Minimum execution time: 16_000_000 picoseconds. + Weight::from_parts(16_000_000, 6385) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -634,7 +636,7 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `147` // Estimated: `511` - // Minimum execution time: 7_000_000 picoseconds. + // Minimum execution time: 8_000_000 picoseconds. Weight::from_parts(8_000_000, 511) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) @@ -671,30 +673,28 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1361` // Estimated: `14264` - // Minimum execution time: 41_000_000 picoseconds. - Weight::from_parts(42_000_000, 14264) + // Minimum execution time: 42_000_000 picoseconds. + Weight::from_parts(44_000_000, 14264) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } - /// Storage: Kensetsu BadDebt (r:1 w:1) - /// Proof: Kensetsu BadDebt (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Technical TechAccounts (r:1 w:0) /// Proof Skipped: Technical TechAccounts (max_values: None, max_size: None, mode: Measured) /// Storage: Tokens Accounts (r:2 w:2) /// Proof: Tokens Accounts (max_values: None, max_size: Some(136), added: 2611, mode: MaxEncodedLen) /// Storage: System Account (r:2 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Permissions Permissions (r:2 w:0) - /// Proof Skipped: Permissions Permissions (max_values: None, max_size: None, mode: Measured) + /// Storage: Kensetsu BadDebt (r:1 w:1) + /// Proof: Kensetsu BadDebt (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) /// Storage: Tokens TotalIssuance (r:1 w:1) /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) fn donate() -> Weight { // Proof Size summary in bytes: - // Measured: `2340` - // Estimated: `25575` - // Minimum execution time: 64_000_000 picoseconds. - Weight::from_parts(65_000_000, 25575) - .saturating_add(RocksDbWeight::get().reads(9_u64)) + // Measured: `1929` + // Estimated: `17874` + // Minimum execution time: 60_000_000 picoseconds. + Weight::from_parts(61_000_000, 17874) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } } diff --git a/runtime/src/migrations.rs b/runtime/src/migrations.rs index c4aacc59e8..e3e035a8c2 100644 --- a/runtime/src/migrations.rs +++ b/runtime/src/migrations.rs @@ -36,8 +36,7 @@ pub type Migrations = (); #[cfg(feature = "ready-to-test")] // kensetsu pub type Migrations = ( - kensetsu::migrations::init::RegisterTreasuryTechAccount, - kensetsu::migrations::init::GrantPermissionsTreasuryTechAccount, kensetsu::migrations::stage_correction::CorrectKusdBalances, + kensetsu::migrations::storage_add_total_collateral::StorageAddTotalCollateral, kensetsu::migrations::remove_managers::RemoveManagers, );