diff --git a/crates/issue/src/mock.rs b/crates/issue/src/mock.rs index b045e5bb67..3b6ce55313 100644 --- a/crates/issue/src/mock.rs +++ b/crates/issue/src/mock.rs @@ -170,6 +170,7 @@ impl vault_registry::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type GetGriefingCollateralCurrencyId = GetNativeCurrencyId; + type LoansApi = (); } impl nomination::Config for Test { diff --git a/crates/loans/src/lib.rs b/crates/loans/src/lib.rs index 61e859ff58..a8dcb00f26 100644 --- a/crates/loans/src/lib.rs +++ b/crates/loans/src/lib.rs @@ -43,7 +43,6 @@ use frame_support::{ use frame_system::pallet_prelude::*; use num_traits::cast::ToPrimitive; use orml_traits::{MultiCurrency, MultiReservableCurrency}; -pub use pallet::*; use primitives::{Balance, Rate, Ratio, Timestamp}; use sp_runtime::{ traits::{ @@ -53,13 +52,12 @@ use sp_runtime::{ ArithmeticError, FixedPointNumber, FixedU128, }; use sp_std::{marker, result::Result}; - -use traits::{ - ConvertToBigUint, LoansApi as LoansTrait, LoansMarketDataProvider, MarketInfo, MarketStatus, OnExchangeRateChange, -}; +use traits::{ConvertToBigUint, LoansMarketDataProvider, MarketInfo, MarketStatus, OnExchangeRateChange}; pub use default_weights::WeightInfo; pub use orml_traits::currency::{OnDeposit, OnSlash, OnTransfer}; +pub use pallet::*; +pub use traits::LoansApi; pub use types::{BorrowSnapshot, EarnedSnapshot, Market, MarketState, RewardMarketState}; #[cfg(feature = "runtime-benchmarks")] @@ -1875,8 +1873,8 @@ impl Pallet { } } -impl LoansTrait, AccountIdOf, Amount> for Pallet { - fn do_mint(supplier: &AccountIdOf, amount: &Amount) -> Result<(), DispatchError> { +impl LoansApi, AccountIdOf, Amount> for Pallet { + fn do_mint(supplier: &AccountIdOf, amount: &Amount) -> Result, DispatchError> { let asset_id = amount.currency(); Self::ensure_active_market(asset_id)?; Self::ensure_under_supply_cap(&amount)?; @@ -1899,7 +1897,7 @@ impl LoansTrait, AccountIdOf, Amount> for Pallet< currency_id: asset_id, amount: amount.amount(), }); - Ok(()) + Ok(voucher) } fn do_borrow(borrower: &AccountIdOf, borrow: &Amount) -> Result<(), DispatchError> { diff --git a/crates/nomination/src/mock.rs b/crates/nomination/src/mock.rs index c1e00c0811..1ed113d00b 100644 --- a/crates/nomination/src/mock.rs +++ b/crates/nomination/src/mock.rs @@ -176,6 +176,7 @@ impl vault_registry::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type GetGriefingCollateralCurrencyId = GetNativeCurrencyId; + type LoansApi = Loans; } pub struct CurrencyConvert; diff --git a/crates/redeem/src/mock.rs b/crates/redeem/src/mock.rs index 1f1294819d..9db98118fe 100644 --- a/crates/redeem/src/mock.rs +++ b/crates/redeem/src/mock.rs @@ -149,6 +149,7 @@ impl vault_registry::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type GetGriefingCollateralCurrencyId = GetNativeCurrencyId; + type LoansApi = Loans; } impl nomination::Config for Test { diff --git a/crates/replace/src/mock.rs b/crates/replace/src/mock.rs index ad728c297d..7a540d8526 100644 --- a/crates/replace/src/mock.rs +++ b/crates/replace/src/mock.rs @@ -196,6 +196,7 @@ impl vault_registry::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type GetGriefingCollateralCurrencyId = GetNativeCurrencyId; + type LoansApi = (); } impl nomination::Config for Test { diff --git a/crates/traits/src/loans.rs b/crates/traits/src/loans.rs index d3df296f6a..1e7a515877 100644 --- a/crates/traits/src/loans.rs +++ b/crates/traits/src/loans.rs @@ -23,7 +23,7 @@ use sp_runtime::{FixedU128, RuntimeDebug}; use sp_std::prelude::*; pub trait LoansApi { - fn do_mint(supplier: &AccountId, amount: &Amount) -> Result<(), DispatchError>; + fn do_mint(supplier: &AccountId, amount: &Amount) -> Result; fn do_borrow(borrower: &AccountId, borrow: &Amount) -> Result<(), DispatchError>; fn do_deposit_collateral(supplier: &AccountId, lend_tokens: &Amount) -> Result<(), DispatchError>; fn do_withdraw_collateral(supplier: &AccountId, voucher: &Amount) -> Result<(), DispatchError>; @@ -34,6 +34,36 @@ pub trait LoansApi { fn recompute_collateral_amount(underlying: &Amount) -> Result; } +impl LoansApi for () { + fn do_mint(_: &AccountId, _: &Amount) -> Result { + Err(DispatchError::Unavailable) + } + fn do_borrow(_: &AccountId, _: &Amount) -> Result<(), DispatchError> { + Err(DispatchError::Unavailable) + } + fn do_deposit_collateral(_: &AccountId, _: &Amount) -> Result<(), DispatchError> { + Err(DispatchError::Unavailable) + } + fn do_withdraw_collateral(_: &AccountId, _: &Amount) -> Result<(), DispatchError> { + Err(DispatchError::Unavailable) + } + fn do_repay_borrow(_: &AccountId, _: &Amount) -> Result<(), DispatchError> { + Err(DispatchError::Unavailable) + } + fn do_redeem(_: &AccountId, _: &Amount, _: &Amount) -> Result<(), DispatchError> { + Err(DispatchError::Unavailable) + } + fn recompute_underlying_amount(_: &Amount) -> Result { + Err(DispatchError::Unavailable) + } + fn underlying_id(_: CurrencyId) -> Result { + Err(DispatchError::Unavailable) + } + fn recompute_collateral_amount(_: &Amount) -> Result { + Err(DispatchError::Unavailable) + } +} + pub trait LoansMarketDataProvider { fn get_market_info(asset_id: CurrencyId) -> Result; fn get_market_status(asset_id: CurrencyId) -> Result, DispatchError>; diff --git a/crates/vault-registry/src/benchmarking.rs b/crates/vault-registry/src/benchmarking.rs index 4c29c63973..82c7e9e10d 100644 --- a/crates/vault-registry/src/benchmarking.rs +++ b/crates/vault-registry/src/benchmarking.rs @@ -125,7 +125,7 @@ pub fn activate_lending_and_get_vault_id() -> let account_id: T::AccountId = account("Vault", 0, 0); let lend_token = CurrencyId::LendToken(1); activate_lending_and_mint::(get_collateral_currency_id::(), lend_token.clone(), &account_id); - let vault_id = VaultId::new(account("Vault", 0, 0), lend_token, get_wrapped_currency_id::()); + let vault_id = VaultId::new(account_id, lend_token, get_wrapped_currency_id::()); set_collateral_config::(&vault_id); vault_id } @@ -273,6 +273,33 @@ pub mod benchmarks { recover_vault_id(RawOrigin::Signed(vault_id.account_id), vault_id.currencies.clone()); } + #[benchmark] + fn deposit_vault_collateral_in_lending_market() { + let old_vault_id = VaultId::new( + account("Vault", 0, 0), + get_collateral_currency_id::(), + get_wrapped_currency_id::(), + ); + set_collateral_config::(&old_vault_id); + + let new_vault_id = VaultId::new( + account("Vault", 0, 0), + CurrencyId::LendToken(1), + get_wrapped_currency_id::(), + ); + set_collateral_config::(&new_vault_id); + + register_vault_with_collateral::(old_vault_id.clone()); + + activate_market::(old_vault_id.collateral_currency(), new_vault_id.collateral_currency()); + + #[extrinsic_call] + _( + RawOrigin::Signed(old_vault_id.account_id), + old_vault_id.currencies.clone(), + ); + } + impl_benchmark_test_suite! { VaultRegistry, crate::mock::ExtBuilder::build_with(Default::default()), diff --git a/crates/vault-registry/src/default_weights.rs b/crates/vault-registry/src/default_weights.rs index 2febb0748b..e4fdf4d929 100644 --- a/crates/vault-registry/src/default_weights.rs +++ b/crates/vault-registry/src/default_weights.rs @@ -2,27 +2,27 @@ //! Autogenerated weights for vault_registry //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-05-05, STEPS: `100`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-06-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `interlay-hetzner-01`, CPU: `AMD EPYC 7502P 32-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kintsugi-testnet-latest"), DB CACHE: 1024 +//! HOSTNAME: ``, CPU: `Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kintsugi-dev"), DB CACHE: 1024 // Executed Command: -// target/release/interbtc-parachain +// target/debug/interbtc-parachain // benchmark // pallet -// --chain -// kintsugi-testnet-latest -// --execution=wasm -// --wasm-execution=compiled // --pallet -// vault_registry +// vault-registry // --extrinsic // * +// --chain +// kintsugi-dev +// --execution=wasm +// --wasm-execution=compiled // --steps -// 100 +// 50 // --repeat -// 10 +// 20 // --output // ./crates/vault-registry/src/default_weights.rs // --template @@ -48,6 +48,7 @@ pub trait WeightInfo { fn set_liquidation_collateral_threshold() -> Weight; fn report_undercollateralized_vault() -> Weight; fn recover_vault_id() -> Weight; + fn deposit_vault_collateral_in_lending_market() -> Weight; } /// Weights for vault_registry using the Substrate node and recommended hardware. @@ -133,10 +134,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn register_vault() -> Weight { // Proof Size summary in bytes: - // Measured: `4343` - // Estimated: `114663` - // Minimum execution time: 443_828_000 picoseconds. - Weight::from_parts(448_988_000, 114663) + // Measured: `2670` + // Estimated: `153273` + // Minimum execution time: 17_036_257_000 picoseconds. + Weight::from_parts(34_011_941_000, 153273) .saturating_add(T::DbWeight::get().reads(48_u64)) .saturating_add(T::DbWeight::get().writes(17_u64)) } @@ -144,10 +145,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: VaultRegistry VaultBitcoinPublicKey (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) fn register_public_key() -> Weight { // Proof Size summary in bytes: - // Measured: `1390` - // Estimated: `2556` - // Minimum execution time: 42_535_000 picoseconds. - Weight::from_parts(42_936_000, 2556) + // Measured: `365` + // Estimated: `3546` + // Minimum execution time: 1_006_692_000 picoseconds. + Weight::from_parts(1_117_847_000, 3546) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -209,10 +210,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) fn accept_new_issues() -> Weight { // Proof Size summary in bytes: - // Measured: `5150` - // Estimated: `83837` - // Minimum execution time: 353_838_000 picoseconds. - Weight::from_parts(359_510_000, 83837) + // Measured: `3476` + // Estimated: `111557` + // Minimum execution time: 13_797_248_000 picoseconds. + Weight::from_parts(15_725_680_000, 111557) .saturating_add(T::DbWeight::get().reads(36_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -274,10 +275,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) fn set_custom_secure_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `5150` - // Estimated: `83837` - // Minimum execution time: 355_441_000 picoseconds. - Weight::from_parts(359_740_000, 83837) + // Measured: `3476` + // Estimated: `111557` + // Minimum execution time: 13_878_928_000 picoseconds. + Weight::from_parts(26_775_507_000, 111557) .saturating_add(T::DbWeight::get().reads(36_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)) } @@ -285,50 +286,50 @@ impl WeightInfo for SubstrateWeight { /// Proof: VaultRegistry MinimumCollateralVault (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) fn set_minimum_collateral() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_745_000 picoseconds. - Weight::from_parts(12_866_000, 0) + // Minimum execution time: 385_934_000 picoseconds. + Weight::from_parts(415_383_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry SystemCollateralCeiling (r:0 w:1) /// Proof: VaultRegistry SystemCollateralCeiling (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_system_collateral_ceiling() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 13_006_000 picoseconds. - Weight::from_parts(13_277_000, 0) + // Minimum execution time: 358_491_000 picoseconds. + Weight::from_parts(424_057_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry SecureCollateralThreshold (r:0 w:1) /// Proof: VaultRegistry SecureCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_secure_collateral_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_865_000 picoseconds. - Weight::from_parts(13_217_000, 0) + // Minimum execution time: 656_131_000 picoseconds. + Weight::from_parts(733_727_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry PremiumRedeemThreshold (r:0 w:1) /// Proof: VaultRegistry PremiumRedeemThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_premium_redeem_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_926_000 picoseconds. - Weight::from_parts(13_206_000, 0) + // Minimum execution time: 647_145_000 picoseconds. + Weight::from_parts(685_776_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry LiquidationCollateralThreshold (r:0 w:1) /// Proof: VaultRegistry LiquidationCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_liquidation_collateral_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_885_000 picoseconds. - Weight::from_parts(13_066_000, 0) + // Minimum execution time: 622_663_000 picoseconds. + Weight::from_parts(686_930_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry Vaults (r:1 w:1) @@ -400,7 +401,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: VaultStaking RewardTally (r:2 w:2) /// Proof: VaultStaking RewardTally (max_values: None, max_size: Some(149), added: 2624, mode: MaxEncodedLen) /// Storage: VaultRewards RewardCurrencies (r:1 w:0) - /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(50), added: 2525, mode: MaxEncodedLen) /// Storage: VaultRegistry TotalUserVaultCollateral (r:1 w:1) /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) /// Storage: Loans RewardSupplyState (r:1 w:1) @@ -419,10 +420,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: VaultRegistry LiquidationVault (max_values: None, max_size: Some(124), added: 2599, mode: MaxEncodedLen) fn report_undercollateralized_vault() -> Weight { // Proof Size summary in bytes: - // Measured: `6659` - // Estimated: `140474` - // Minimum execution time: 1_239_670_000 picoseconds. - Weight::from_parts(1_254_621_000, 140474) + // Measured: `4729` + // Estimated: `182956` + // Minimum execution time: 48_560_047_000 picoseconds. + Weight::from_parts(53_861_204_000, 182956) .saturating_add(T::DbWeight::get().reads(58_u64)) .saturating_add(T::DbWeight::get().writes(30_u64)) } @@ -430,13 +431,116 @@ impl WeightInfo for SubstrateWeight { /// Proof: VaultRegistry Vaults (max_values: None, max_size: Some(260), added: 2735, mode: MaxEncodedLen) fn recover_vault_id() -> Weight { // Proof Size summary in bytes: - // Measured: `1411` - // Estimated: `2735` - // Minimum execution time: 35_101_000 picoseconds. - Weight::from_parts(35_621_000, 2735) + // Measured: `669` + // Estimated: `3725` + // Minimum execution time: 704_266_000 picoseconds. + Weight::from_parts(996_784_000, 3725) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: VaultStaking Nonce (r:2 w:0) + /// Proof: VaultStaking Nonce (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen) + /// Storage: VaultStaking Stake (r:2 w:2) + /// Proof: VaultStaking Stake (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashPerToken (r:2 w:0) + /// Proof: VaultStaking SlashPerToken (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashTally (r:2 w:2) + /// Proof: VaultStaking SlashTally (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(115), added: 2590, mode: MaxEncodedLen) + /// Storage: VaultRegistry TotalUserVaultCollateral (r:2 w:2) + /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultCapacity Stake (r:2 w:2) + /// Proof: VaultCapacity Stake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardPerToken (r:2 w:0) + /// Proof: VaultCapacity RewardPerToken (max_values: None, max_size: Some(59), added: 2534, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardTally (r:4 w:4) + /// Proof: VaultCapacity RewardTally (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalRewards (r:2 w:2) + /// Proof: VaultCapacity TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards Stake (r:2 w:2) + /// Proof: VaultRewards Stake (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardPerToken (r:4 w:0) + /// Proof: VaultRewards RewardPerToken (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardTally (r:4 w:4) + /// Proof: VaultRewards RewardTally (max_values: None, max_size: Some(124), added: 2599, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalRewards (r:2 w:2) + /// Proof: VaultRewards TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Fee Commission (r:2 w:0) + /// Proof: Fee Commission (max_values: None, max_size: Some(86), added: 2561, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalCurrentStake (r:2 w:2) + /// Proof: VaultStaking TotalCurrentStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardPerToken (r:4 w:2) + /// Proof: VaultStaking RewardPerToken (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalStake (r:2 w:2) + /// Proof: VaultStaking TotalStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardTally (r:4 w:4) + /// Proof: VaultStaking RewardTally (max_values: None, max_size: Some(149), added: 2624, mode: MaxEncodedLen) + /// Storage: VaultRegistry Vaults (r:2 w:2) + /// Proof: VaultRegistry Vaults (max_values: None, max_size: Some(260), added: 2735, mode: MaxEncodedLen) + /// Storage: VaultRegistry SecureCollateralThreshold (r:2 w:0) + /// Proof: VaultRegistry SecureCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalStake (r:2 w:2) + /// Proof: VaultRewards TotalStake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardCurrencies (r:2 w:0) + /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(50), added: 2525, mode: MaxEncodedLen) + /// Storage: Security ParachainStatus (r:1 w:0) + /// Proof: Security ParachainStatus (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) + /// Storage: Oracle Aggregate (r:1 w:0) + /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalStake (r:1 w:1) + /// Proof: VaultCapacity TotalStake (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardCurrencies (r:1 w:0) + /// Proof: VaultCapacity RewardCurrencies (max_values: None, max_size: Some(39), added: 2514, mode: MaxEncodedLen) + /// Storage: Loans Markets (r:2 w:0) + /// Proof: Loans Markets (max_values: None, max_size: Some(160), added: 2635, 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: Loans LastAccruedInterestTime (r:1 w:1) + /// Proof: Loans LastAccruedInterestTime (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplyState (r:1 w:1) + /// Proof: Loans RewardSupplyState (max_values: None, max_size: Some(47), added: 2522, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplySpeed (r:1 w:0) + /// Proof: Loans RewardSupplySpeed (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplierIndex (r:1 w:1) + /// Proof: Loans RewardSupplierIndex (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: Loans RewardAccrued (r:1 w:1) + /// Proof: Loans RewardAccrued (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + /// Storage: Loans UnderlyingAssetId (r:1 w:0) + /// Proof: Loans UnderlyingAssetId (max_values: None, max_size: Some(38), added: 2513, mode: MaxEncodedLen) + /// Storage: Tokens TotalIssuance (r:1 w:1) + /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Loans TotalBorrows (r:1 w:0) + /// Proof: Loans TotalBorrows (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans TotalReserves (r:1 w:0) + /// Proof: Loans TotalReserves (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans MinExchangeRate (r:1 w:0) + /// Proof: Loans MinExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Loans AccountDeposits (r:1 w:0) + /// Proof: Loans AccountDeposits (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: VaultRegistry PremiumRedeemThreshold (r:1 w:0) + /// Proof: VaultRegistry PremiumRedeemThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry LiquidationCollateralThreshold (r:1 w:0) + /// Proof: VaultRegistry LiquidationCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry MinimumCollateralVault (r:1 w:0) + /// Proof: VaultRegistry MinimumCollateralVault (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRegistry SystemCollateralCeiling (r:1 w:0) + /// Proof: VaultRegistry SystemCollateralCeiling (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry VaultBitcoinPublicKey (r:1 w:0) + /// Proof: VaultRegistry VaultBitcoinPublicKey (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Loans MaxExchangeRate (r:1 w:0) + /// Proof: Loans MaxExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + fn deposit_vault_collateral_in_lending_market() -> Weight { + // Proof Size summary in bytes: + // Measured: `4497` + // Estimated: `251048` + // Minimum execution time: 34_448_130_000 picoseconds. + Weight::from_parts(42_903_620_000, 251048) + .saturating_add(T::DbWeight::get().reads(83_u64)) + .saturating_add(T::DbWeight::get().writes(47_u64)) + } } // For backwards compatibility and tests @@ -521,10 +625,10 @@ impl WeightInfo for () { /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn register_vault() -> Weight { // Proof Size summary in bytes: - // Measured: `4343` - // Estimated: `114663` - // Minimum execution time: 443_828_000 picoseconds. - Weight::from_parts(448_988_000, 114663) + // Measured: `2670` + // Estimated: `153273` + // Minimum execution time: 17_036_257_000 picoseconds. + Weight::from_parts(34_011_941_000, 153273) .saturating_add(RocksDbWeight::get().reads(48_u64)) .saturating_add(RocksDbWeight::get().writes(17_u64)) } @@ -532,10 +636,10 @@ impl WeightInfo for () { /// Proof: VaultRegistry VaultBitcoinPublicKey (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) fn register_public_key() -> Weight { // Proof Size summary in bytes: - // Measured: `1390` - // Estimated: `2556` - // Minimum execution time: 42_535_000 picoseconds. - Weight::from_parts(42_936_000, 2556) + // Measured: `365` + // Estimated: `3546` + // Minimum execution time: 1_006_692_000 picoseconds. + Weight::from_parts(1_117_847_000, 3546) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -597,10 +701,10 @@ impl WeightInfo for () { /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) fn accept_new_issues() -> Weight { // Proof Size summary in bytes: - // Measured: `5150` - // Estimated: `83837` - // Minimum execution time: 353_838_000 picoseconds. - Weight::from_parts(359_510_000, 83837) + // Measured: `3476` + // Estimated: `111557` + // Minimum execution time: 13_797_248_000 picoseconds. + Weight::from_parts(15_725_680_000, 111557) .saturating_add(RocksDbWeight::get().reads(36_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -662,10 +766,10 @@ impl WeightInfo for () { /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) fn set_custom_secure_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `5150` - // Estimated: `83837` - // Minimum execution time: 355_441_000 picoseconds. - Weight::from_parts(359_740_000, 83837) + // Measured: `3476` + // Estimated: `111557` + // Minimum execution time: 13_878_928_000 picoseconds. + Weight::from_parts(26_775_507_000, 111557) .saturating_add(RocksDbWeight::get().reads(36_u64)) .saturating_add(RocksDbWeight::get().writes(12_u64)) } @@ -673,50 +777,50 @@ impl WeightInfo for () { /// Proof: VaultRegistry MinimumCollateralVault (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) fn set_minimum_collateral() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_745_000 picoseconds. - Weight::from_parts(12_866_000, 0) + // Minimum execution time: 385_934_000 picoseconds. + Weight::from_parts(415_383_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry SystemCollateralCeiling (r:0 w:1) /// Proof: VaultRegistry SystemCollateralCeiling (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_system_collateral_ceiling() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 13_006_000 picoseconds. - Weight::from_parts(13_277_000, 0) + // Minimum execution time: 358_491_000 picoseconds. + Weight::from_parts(424_057_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry SecureCollateralThreshold (r:0 w:1) /// Proof: VaultRegistry SecureCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_secure_collateral_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_865_000 picoseconds. - Weight::from_parts(13_217_000, 0) + // Minimum execution time: 656_131_000 picoseconds. + Weight::from_parts(733_727_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry PremiumRedeemThreshold (r:0 w:1) /// Proof: VaultRegistry PremiumRedeemThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_premium_redeem_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_926_000 picoseconds. - Weight::from_parts(13_206_000, 0) + // Minimum execution time: 647_145_000 picoseconds. + Weight::from_parts(685_776_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry LiquidationCollateralThreshold (r:0 w:1) /// Proof: VaultRegistry LiquidationCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) fn set_liquidation_collateral_threshold() -> Weight { // Proof Size summary in bytes: - // Measured: `711` + // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_885_000 picoseconds. - Weight::from_parts(13_066_000, 0) + // Minimum execution time: 622_663_000 picoseconds. + Weight::from_parts(686_930_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: VaultRegistry Vaults (r:1 w:1) @@ -788,7 +892,7 @@ impl WeightInfo for () { /// Storage: VaultStaking RewardTally (r:2 w:2) /// Proof: VaultStaking RewardTally (max_values: None, max_size: Some(149), added: 2624, mode: MaxEncodedLen) /// Storage: VaultRewards RewardCurrencies (r:1 w:0) - /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(50), added: 2525, mode: MaxEncodedLen) /// Storage: VaultRegistry TotalUserVaultCollateral (r:1 w:1) /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) /// Storage: Loans RewardSupplyState (r:1 w:1) @@ -807,10 +911,10 @@ impl WeightInfo for () { /// Proof: VaultRegistry LiquidationVault (max_values: None, max_size: Some(124), added: 2599, mode: MaxEncodedLen) fn report_undercollateralized_vault() -> Weight { // Proof Size summary in bytes: - // Measured: `6659` - // Estimated: `140474` - // Minimum execution time: 1_239_670_000 picoseconds. - Weight::from_parts(1_254_621_000, 140474) + // Measured: `4729` + // Estimated: `182956` + // Minimum execution time: 48_560_047_000 picoseconds. + Weight::from_parts(53_861_204_000, 182956) .saturating_add(RocksDbWeight::get().reads(58_u64)) .saturating_add(RocksDbWeight::get().writes(30_u64)) } @@ -818,11 +922,114 @@ impl WeightInfo for () { /// Proof: VaultRegistry Vaults (max_values: None, max_size: Some(260), added: 2735, mode: MaxEncodedLen) fn recover_vault_id() -> Weight { // Proof Size summary in bytes: - // Measured: `1411` - // Estimated: `2735` - // Minimum execution time: 35_101_000 picoseconds. - Weight::from_parts(35_621_000, 2735) + // Measured: `669` + // Estimated: `3725` + // Minimum execution time: 704_266_000 picoseconds. + Weight::from_parts(996_784_000, 3725) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + /// Storage: VaultStaking Nonce (r:2 w:0) + /// Proof: VaultStaking Nonce (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen) + /// Storage: VaultStaking Stake (r:2 w:2) + /// Proof: VaultStaking Stake (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashPerToken (r:2 w:0) + /// Proof: VaultStaking SlashPerToken (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashTally (r:2 w:2) + /// Proof: VaultStaking SlashTally (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(115), added: 2590, mode: MaxEncodedLen) + /// Storage: VaultRegistry TotalUserVaultCollateral (r:2 w:2) + /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultCapacity Stake (r:2 w:2) + /// Proof: VaultCapacity Stake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardPerToken (r:2 w:0) + /// Proof: VaultCapacity RewardPerToken (max_values: None, max_size: Some(59), added: 2534, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardTally (r:4 w:4) + /// Proof: VaultCapacity RewardTally (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalRewards (r:2 w:2) + /// Proof: VaultCapacity TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards Stake (r:2 w:2) + /// Proof: VaultRewards Stake (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardPerToken (r:4 w:0) + /// Proof: VaultRewards RewardPerToken (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardTally (r:4 w:4) + /// Proof: VaultRewards RewardTally (max_values: None, max_size: Some(124), added: 2599, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalRewards (r:2 w:2) + /// Proof: VaultRewards TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Fee Commission (r:2 w:0) + /// Proof: Fee Commission (max_values: None, max_size: Some(86), added: 2561, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalCurrentStake (r:2 w:2) + /// Proof: VaultStaking TotalCurrentStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardPerToken (r:4 w:2) + /// Proof: VaultStaking RewardPerToken (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalStake (r:2 w:2) + /// Proof: VaultStaking TotalStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardTally (r:4 w:4) + /// Proof: VaultStaking RewardTally (max_values: None, max_size: Some(149), added: 2624, mode: MaxEncodedLen) + /// Storage: VaultRegistry Vaults (r:2 w:2) + /// Proof: VaultRegistry Vaults (max_values: None, max_size: Some(260), added: 2735, mode: MaxEncodedLen) + /// Storage: VaultRegistry SecureCollateralThreshold (r:2 w:0) + /// Proof: VaultRegistry SecureCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalStake (r:2 w:2) + /// Proof: VaultRewards TotalStake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardCurrencies (r:2 w:0) + /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(50), added: 2525, mode: MaxEncodedLen) + /// Storage: Security ParachainStatus (r:1 w:0) + /// Proof: Security ParachainStatus (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) + /// Storage: Oracle Aggregate (r:1 w:0) + /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalStake (r:1 w:1) + /// Proof: VaultCapacity TotalStake (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardCurrencies (r:1 w:0) + /// Proof: VaultCapacity RewardCurrencies (max_values: None, max_size: Some(39), added: 2514, mode: MaxEncodedLen) + /// Storage: Loans Markets (r:2 w:0) + /// Proof: Loans Markets (max_values: None, max_size: Some(160), added: 2635, 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: Loans LastAccruedInterestTime (r:1 w:1) + /// Proof: Loans LastAccruedInterestTime (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplyState (r:1 w:1) + /// Proof: Loans RewardSupplyState (max_values: None, max_size: Some(47), added: 2522, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplySpeed (r:1 w:0) + /// Proof: Loans RewardSupplySpeed (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplierIndex (r:1 w:1) + /// Proof: Loans RewardSupplierIndex (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: Loans RewardAccrued (r:1 w:1) + /// Proof: Loans RewardAccrued (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + /// Storage: Loans UnderlyingAssetId (r:1 w:0) + /// Proof: Loans UnderlyingAssetId (max_values: None, max_size: Some(38), added: 2513, mode: MaxEncodedLen) + /// Storage: Tokens TotalIssuance (r:1 w:1) + /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Loans TotalBorrows (r:1 w:0) + /// Proof: Loans TotalBorrows (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans TotalReserves (r:1 w:0) + /// Proof: Loans TotalReserves (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans MinExchangeRate (r:1 w:0) + /// Proof: Loans MinExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Loans AccountDeposits (r:1 w:0) + /// Proof: Loans AccountDeposits (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: VaultRegistry PremiumRedeemThreshold (r:1 w:0) + /// Proof: VaultRegistry PremiumRedeemThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry LiquidationCollateralThreshold (r:1 w:0) + /// Proof: VaultRegistry LiquidationCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry MinimumCollateralVault (r:1 w:0) + /// Proof: VaultRegistry MinimumCollateralVault (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRegistry SystemCollateralCeiling (r:1 w:0) + /// Proof: VaultRegistry SystemCollateralCeiling (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry VaultBitcoinPublicKey (r:1 w:0) + /// Proof: VaultRegistry VaultBitcoinPublicKey (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Loans MaxExchangeRate (r:1 w:0) + /// Proof: Loans MaxExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + fn deposit_vault_collateral_in_lending_market() -> Weight { + // Proof Size summary in bytes: + // Measured: `4497` + // Estimated: `251048` + // Minimum execution time: 34_448_130_000 picoseconds. + Weight::from_parts(42_903_620_000, 251048) + .saturating_add(RocksDbWeight::get().reads(83_u64)) + .saturating_add(RocksDbWeight::get().writes(47_u64)) + } } diff --git a/crates/vault-registry/src/lib.rs b/crates/vault-registry/src/lib.rs index c6321504d0..2a522ca79d 100644 --- a/crates/vault-registry/src/lib.rs +++ b/crates/vault-registry/src/lib.rs @@ -52,6 +52,7 @@ use frame_system::{ ensure_signed, offchain::{SendTransactionTypes, SubmitTransaction}, }; +use loans::LoansApi; use sp_core::{H256, U256}; use sp_runtime::{ traits::*, @@ -101,6 +102,9 @@ pub mod pallet { /// Currency used for griefing collateral, e.g. DOT. #[pallet::constant] type GetGriefingCollateralCurrencyId: Get>; + + /// API of the loans pallet; used to atomically lock underlying in lending market. + type LoansApi: LoansApi, Self::AccountId, Amount>; } #[pallet::hooks] @@ -388,6 +392,55 @@ pub mod pallet { Ok(()) } + + /// Atomically lock vault collateral in lending market and re-lock as vault collateral. + /// + /// Preconditions: + /// - the Vault is not liquidated + /// - the Vault does not have `to_be_issued` or `to_be_redeemed` tokens + /// - a market exists for the underlying currency + /// + /// If the Vault has a pre-existing replace request this is cancelled. + /// + /// # Arguments + /// * `currency_pair` - the currency pair to change + #[pallet::call_index(11)] + #[pallet::weight(::WeightInfo::deposit_vault_collateral_in_lending_market())] + #[transactional] + pub fn deposit_vault_collateral_in_lending_market( + origin: OriginFor, + currency_pair: DefaultVaultCurrencyPair, + ) -> DispatchResult { + let account_id = ensure_signed(origin)?; + let old_vault_id = VaultId::new(account_id.clone(), currency_pair.collateral, currency_pair.wrapped); + + let collateral = Amount::new( + ext::staking::compute_stake::(&old_vault_id, &old_vault_id.account_id)?, + old_vault_id.collateral_currency(), + ); + Self::force_withdraw_collateral(&old_vault_id, &collateral)?; + + let lend_token_collateral = T::LoansApi::do_mint(&account_id, &collateral)?; + let new_vault_id = VaultId::new(account_id, lend_token_collateral.currency(), currency_pair.wrapped); + + if Self::vault_exists(&new_vault_id) { + Self::try_deposit_collateral(&new_vault_id, &lend_token_collateral)?; + } else { + Self::_register_vault(new_vault_id.clone(), lend_token_collateral.amount())?; + } + + let mut old_vault = Self::get_rich_vault_from_id(&old_vault_id)?; + let mut new_vault = Self::get_rich_vault_from_id(&new_vault_id)?; + + old_vault.migrate(&mut new_vault)?; + + ensure!( + !Self::is_vault_below_secure_threshold(&new_vault_id)?, + Error::::VaultBelowSecureThreshold + ); + + Ok(()) + } } #[pallet::event] @@ -566,6 +619,13 @@ pub mod pallet { // Minimum collateral was not found for the given currency MinimumCollateralNotSet, + + /// Vault has tokens to be issued + VaultHasToBeIssued, + /// Vault has tokens to be redeemed + VaultHasToBeRedeemed, + /// Vault below the global secure threshold + VaultBelowSecureThreshold, } /// The minimum collateral (e.g. DOT/KSM) a Vault needs to provide to register. diff --git a/crates/vault-registry/src/mock.rs b/crates/vault-registry/src/mock.rs index dbe11826e1..a677025ed4 100644 --- a/crates/vault-registry/src/mock.rs +++ b/crates/vault-registry/src/mock.rs @@ -281,6 +281,7 @@ impl Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type GetGriefingCollateralCurrencyId = GetNativeCurrencyId; + type LoansApi = Loans; } impl frame_system::offchain::SendTransactionTypes for Test diff --git a/crates/vault-registry/src/tests.rs b/crates/vault-registry/src/tests.rs index cd1dd05cc2..011af6e435 100644 --- a/crates/vault-registry/src/tests.rs +++ b/crates/vault-registry/src/tests.rs @@ -1430,3 +1430,95 @@ fn test_offchain_worker_unsigned_transaction_submission() { ); }) } + +mod loans_tests { + use super::{assert_eq, *}; + use loans::{InterestRateModel, JumpModel, Market, MarketState}; + use primitives::{CurrencyId::LendToken, Rate, Ratio}; + + const fn market_mock(lend_token_id: CurrencyId) -> Market { + Market { + close_factor: Ratio::from_percent(50), + collateral_factor: Ratio::from_percent(50), + liquidation_threshold: Ratio::from_percent(55), + liquidate_incentive: Rate::from_inner(Rate::DIV / 100 * 110), + liquidate_incentive_reserved_factor: Ratio::from_percent(3), + state: MarketState::Pending, + rate_model: InterestRateModel::Jump(JumpModel { + base_rate: Rate::from_inner(Rate::DIV / 100 * 2), + jump_rate: Rate::from_inner(Rate::DIV / 100 * 10), + full_rate: Rate::from_inner(Rate::DIV / 100 * 32), + jump_utilization: Ratio::from_percent(80), + }), + reserve_factor: Ratio::from_percent(15), + supply_cap: 1_000_000_000_000_000_000_000u128, // set to 1B + borrow_cap: 1_000_000_000_000_000_000_000u128, // set to 1B + lend_token_id, + } + } + + fn activate_market(underlying_id: CurrencyId, lend_token_id: CurrencyId) { + assert_ok!(Loans::add_market( + RuntimeOrigin::root(), + underlying_id, + market_mock(lend_token_id) + )); + assert_ok!(Loans::activate_market(RuntimeOrigin::root(), underlying_id)); + } + + #[test] + fn should_deposit_all_above_secure() { + run_test(|| { + let vault_id = create_sample_vault_and_issue_tokens(4); + activate_market(DEFAULT_COLLATERAL_CURRENCY, LendToken(1)); + + assert_ok!(VaultRegistry::deposit_vault_collateral_in_lending_market( + RuntimeOrigin::signed(vault_id.account_id.clone()), + vault_id.currencies.clone(), + )); + }) + } + + #[test] + fn should_deposit_after_register_vault() { + run_test(|| { + let vault_id = create_sample_vault_and_issue_tokens(4); + activate_market(DEFAULT_COLLATERAL_CURRENCY, LendToken(1)); + + assert_ok!(VaultRegistry::deposit_vault_collateral_in_lending_market( + RuntimeOrigin::signed(vault_id.account_id.clone()), + vault_id.currencies.clone(), + )); + + let collateral = Amount::new(100_000, DEFAULT_COLLATERAL_CURRENCY); + assert_ok!(collateral.mint_to(&vault_id.account_id)); + assert_ok!(VaultRegistry::try_deposit_collateral(&vault_id, &collateral)); + let mut vault = VaultRegistry::get_rich_vault_from_id(&vault_id).unwrap(); + assert_ok!(vault.increase_issued(&wrapped(100))); + + assert_ok!(VaultRegistry::deposit_vault_collateral_in_lending_market( + RuntimeOrigin::signed(vault_id.account_id.clone()), + vault_id.currencies.clone(), + )); + }) + } + + #[test] + fn should_not_deposit_all_below_secure() { + run_test(|| { + let vault_id = create_sample_vault_and_issue_tokens(100); + activate_market(DEFAULT_COLLATERAL_CURRENCY, LendToken(1)); + + let mut vault = VaultRegistry::get_rich_vault_from_id(&vault_id).unwrap(); + assert_ok!(vault.increase_issued(&wrapped(100_000))); + + assert_noop!( + VaultRegistry::deposit_vault_collateral_in_lending_market( + RuntimeOrigin::signed(vault_id.account_id.clone()), + vault_id.currencies.clone(), + ), + TestError::VaultBelowSecureThreshold + ); + }) + } +} diff --git a/crates/vault-registry/src/types.rs b/crates/vault-registry/src/types.rs index 7570ac6c6f..3bafec32a5 100644 --- a/crates/vault-registry/src/types.rs +++ b/crates/vault-registry/src/types.rs @@ -336,6 +336,10 @@ impl RichVault { Amount::new(self.data.to_be_issued_tokens, self.id().wrapped_currency()) } + pub(crate) fn replace_collateral(&self) -> Amount { + Amount::new(self.data.replace_collateral, self.id().collateral_currency()) + } + pub(crate) fn freely_redeemable_tokens(&self) -> Result, DispatchError> { Ok(self.issued_tokens().checked_sub(&self.to_be_redeemed_tokens())?) } @@ -367,6 +371,25 @@ impl RichVault { self.decrease_issued(tokens) } + pub(crate) fn migrate(&mut self, other: &mut Self) -> DispatchResult { + ensure!(!self.data.is_liquidated(), Error::::VaultLiquidated); + ensure!(self.data.to_be_issued_tokens.is_zero(), Error::::VaultHasToBeIssued); + // this is non-zero for redeem & replace + ensure!( + self.data.to_be_redeemed_tokens.is_zero(), + Error::::VaultHasToBeRedeemed + ); + + let issued_tokens = self.issued_tokens(); + self.decrease_issued(&issued_tokens)?; + other.increase_issued(&issued_tokens)?; + + self.set_to_be_replaced_amount(&Amount::zero(self.wrapped_currency()))?; + self.decrease_available_replace_collateral(&self.replace_collateral())?; + + Ok(()) + } + pub(crate) fn wrapped_currency(&self) -> CurrencyId { self.data.id.wrapped_currency() } diff --git a/parachain/runtime/interlay/src/lib.rs b/parachain/runtime/interlay/src/lib.rs index ab935702a2..569a9bec15 100644 --- a/parachain/runtime/interlay/src/lib.rs +++ b/parachain/runtime/interlay/src/lib.rs @@ -1103,6 +1103,7 @@ impl vault_registry::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::vault_registry::WeightInfo; type GetGriefingCollateralCurrencyId = GetNativeCurrencyId; + type LoansApi = Loans; } impl frame_system::offchain::SendTransactionTypes for Runtime diff --git a/parachain/runtime/interlay/src/weights/vault_registry.rs b/parachain/runtime/interlay/src/weights/vault_registry.rs index 5cb215bb7e..a627e61ab6 100644 --- a/parachain/runtime/interlay/src/weights/vault_registry.rs +++ b/parachain/runtime/interlay/src/weights/vault_registry.rs @@ -416,4 +416,107 @@ impl vault_registry::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: VaultStaking Nonce (r:2 w:0) + /// Proof: VaultStaking Nonce (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen) + /// Storage: VaultStaking Stake (r:2 w:2) + /// Proof: VaultStaking Stake (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashPerToken (r:2 w:0) + /// Proof: VaultStaking SlashPerToken (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashTally (r:2 w:2) + /// Proof: VaultStaking SlashTally (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(115), added: 2590, mode: MaxEncodedLen) + /// Storage: VaultRegistry TotalUserVaultCollateral (r:2 w:2) + /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultCapacity Stake (r:2 w:2) + /// Proof: VaultCapacity Stake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardPerToken (r:2 w:0) + /// Proof: VaultCapacity RewardPerToken (max_values: None, max_size: Some(59), added: 2534, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardTally (r:4 w:4) + /// Proof: VaultCapacity RewardTally (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalRewards (r:2 w:2) + /// Proof: VaultCapacity TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards Stake (r:2 w:2) + /// Proof: VaultRewards Stake (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardPerToken (r:4 w:0) + /// Proof: VaultRewards RewardPerToken (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardTally (r:4 w:4) + /// Proof: VaultRewards RewardTally (max_values: None, max_size: Some(124), added: 2599, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalRewards (r:2 w:2) + /// Proof: VaultRewards TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Fee Commission (r:2 w:0) + /// Proof: Fee Commission (max_values: None, max_size: Some(86), added: 2561, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalCurrentStake (r:2 w:2) + /// Proof: VaultStaking TotalCurrentStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardPerToken (r:4 w:2) + /// Proof: VaultStaking RewardPerToken (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalStake (r:2 w:2) + /// Proof: VaultStaking TotalStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardTally (r:4 w:4) + /// Proof: VaultStaking RewardTally (max_values: None, max_size: Some(149), added: 2624, mode: MaxEncodedLen) + /// Storage: VaultRegistry Vaults (r:2 w:2) + /// Proof: VaultRegistry Vaults (max_values: None, max_size: Some(260), added: 2735, mode: MaxEncodedLen) + /// Storage: VaultRegistry SecureCollateralThreshold (r:2 w:0) + /// Proof: VaultRegistry SecureCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalStake (r:2 w:2) + /// Proof: VaultRewards TotalStake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardCurrencies (r:2 w:0) + /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(50), added: 2525, mode: MaxEncodedLen) + /// Storage: Security ParachainStatus (r:1 w:0) + /// Proof: Security ParachainStatus (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) + /// Storage: Oracle Aggregate (r:1 w:0) + /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalStake (r:1 w:1) + /// Proof: VaultCapacity TotalStake (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardCurrencies (r:1 w:0) + /// Proof: VaultCapacity RewardCurrencies (max_values: None, max_size: Some(39), added: 2514, mode: MaxEncodedLen) + /// Storage: Loans Markets (r:2 w:0) + /// Proof: Loans Markets (max_values: None, max_size: Some(160), added: 2635, 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: Loans LastAccruedInterestTime (r:1 w:1) + /// Proof: Loans LastAccruedInterestTime (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplyState (r:1 w:1) + /// Proof: Loans RewardSupplyState (max_values: None, max_size: Some(47), added: 2522, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplySpeed (r:1 w:0) + /// Proof: Loans RewardSupplySpeed (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplierIndex (r:1 w:1) + /// Proof: Loans RewardSupplierIndex (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: Loans RewardAccrued (r:1 w:1) + /// Proof: Loans RewardAccrued (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + /// Storage: Loans UnderlyingAssetId (r:1 w:0) + /// Proof: Loans UnderlyingAssetId (max_values: None, max_size: Some(38), added: 2513, mode: MaxEncodedLen) + /// Storage: Tokens TotalIssuance (r:1 w:1) + /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Loans TotalBorrows (r:1 w:0) + /// Proof: Loans TotalBorrows (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans TotalReserves (r:1 w:0) + /// Proof: Loans TotalReserves (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans MinExchangeRate (r:1 w:0) + /// Proof: Loans MinExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Loans AccountDeposits (r:1 w:0) + /// Proof: Loans AccountDeposits (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: VaultRegistry PremiumRedeemThreshold (r:1 w:0) + /// Proof: VaultRegistry PremiumRedeemThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry LiquidationCollateralThreshold (r:1 w:0) + /// Proof: VaultRegistry LiquidationCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry MinimumCollateralVault (r:1 w:0) + /// Proof: VaultRegistry MinimumCollateralVault (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRegistry SystemCollateralCeiling (r:1 w:0) + /// Proof: VaultRegistry SystemCollateralCeiling (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry VaultBitcoinPublicKey (r:1 w:0) + /// Proof: VaultRegistry VaultBitcoinPublicKey (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Loans MaxExchangeRate (r:1 w:0) + /// Proof: Loans MaxExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + fn deposit_vault_collateral_in_lending_market () -> Weight { + // Proof Size summary in bytes: + // Measured: `4330` + // Estimated: `251048` + // Minimum execution time: 46_554_543_000 picoseconds. + Weight::from_parts(97_768_803_000, 251048) + .saturating_add(T::DbWeight::get().reads(83_u64)) + .saturating_add(T::DbWeight::get().writes(47_u64)) + } } \ No newline at end of file diff --git a/parachain/runtime/kintsugi/src/lib.rs b/parachain/runtime/kintsugi/src/lib.rs index 44761fc66c..14957408a0 100644 --- a/parachain/runtime/kintsugi/src/lib.rs +++ b/parachain/runtime/kintsugi/src/lib.rs @@ -1104,6 +1104,7 @@ impl vault_registry::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::vault_registry::WeightInfo; type GetGriefingCollateralCurrencyId = GetNativeCurrencyId; + type LoansApi = Loans; } impl frame_system::offchain::SendTransactionTypes for Runtime diff --git a/parachain/runtime/kintsugi/src/weights/vault_registry.rs b/parachain/runtime/kintsugi/src/weights/vault_registry.rs index 2a8fa6c922..508409bcd3 100644 --- a/parachain/runtime/kintsugi/src/weights/vault_registry.rs +++ b/parachain/runtime/kintsugi/src/weights/vault_registry.rs @@ -416,4 +416,107 @@ impl vault_registry::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: VaultStaking Nonce (r:2 w:0) + /// Proof: VaultStaking Nonce (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen) + /// Storage: VaultStaking Stake (r:2 w:2) + /// Proof: VaultStaking Stake (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashPerToken (r:2 w:0) + /// Proof: VaultStaking SlashPerToken (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking SlashTally (r:2 w:2) + /// Proof: VaultStaking SlashTally (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(115), added: 2590, mode: MaxEncodedLen) + /// Storage: VaultRegistry TotalUserVaultCollateral (r:2 w:2) + /// Proof: VaultRegistry TotalUserVaultCollateral (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultCapacity Stake (r:2 w:2) + /// Proof: VaultCapacity Stake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardPerToken (r:2 w:0) + /// Proof: VaultCapacity RewardPerToken (max_values: None, max_size: Some(59), added: 2534, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardTally (r:4 w:4) + /// Proof: VaultCapacity RewardTally (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalRewards (r:2 w:2) + /// Proof: VaultCapacity TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards Stake (r:2 w:2) + /// Proof: VaultRewards Stake (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardPerToken (r:4 w:0) + /// Proof: VaultRewards RewardPerToken (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardTally (r:4 w:4) + /// Proof: VaultRewards RewardTally (max_values: None, max_size: Some(124), added: 2599, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalRewards (r:2 w:2) + /// Proof: VaultRewards TotalRewards (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Fee Commission (r:2 w:0) + /// Proof: Fee Commission (max_values: None, max_size: Some(86), added: 2561, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalCurrentStake (r:2 w:2) + /// Proof: VaultStaking TotalCurrentStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardPerToken (r:4 w:2) + /// Proof: VaultStaking RewardPerToken (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VaultStaking TotalStake (r:2 w:2) + /// Proof: VaultStaking TotalStake (max_values: None, max_size: Some(106), added: 2581, mode: MaxEncodedLen) + /// Storage: VaultStaking RewardTally (r:4 w:4) + /// Proof: VaultStaking RewardTally (max_values: None, max_size: Some(149), added: 2624, mode: MaxEncodedLen) + /// Storage: VaultRegistry Vaults (r:2 w:2) + /// Proof: VaultRegistry Vaults (max_values: None, max_size: Some(260), added: 2735, mode: MaxEncodedLen) + /// Storage: VaultRegistry SecureCollateralThreshold (r:2 w:0) + /// Proof: VaultRegistry SecureCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRewards TotalStake (r:2 w:2) + /// Proof: VaultRewards TotalStake (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRewards RewardCurrencies (r:2 w:0) + /// Proof: VaultRewards RewardCurrencies (max_values: None, max_size: Some(50), added: 2525, mode: MaxEncodedLen) + /// Storage: Security ParachainStatus (r:1 w:0) + /// Proof: Security ParachainStatus (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) + /// Storage: Oracle Aggregate (r:1 w:0) + /// Proof: Oracle Aggregate (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Storage: VaultCapacity TotalStake (r:1 w:1) + /// Proof: VaultCapacity TotalStake (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) + /// Storage: VaultCapacity RewardCurrencies (r:1 w:0) + /// Proof: VaultCapacity RewardCurrencies (max_values: None, max_size: Some(39), added: 2514, mode: MaxEncodedLen) + /// Storage: Loans Markets (r:2 w:0) + /// Proof: Loans Markets (max_values: None, max_size: Some(160), added: 2635, 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: Loans LastAccruedInterestTime (r:1 w:1) + /// Proof: Loans LastAccruedInterestTime (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplyState (r:1 w:1) + /// Proof: Loans RewardSupplyState (max_values: None, max_size: Some(47), added: 2522, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplySpeed (r:1 w:0) + /// Proof: Loans RewardSupplySpeed (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans RewardSupplierIndex (r:1 w:1) + /// Proof: Loans RewardSupplierIndex (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: Loans RewardAccrued (r:1 w:1) + /// Proof: Loans RewardAccrued (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + /// Storage: Loans UnderlyingAssetId (r:1 w:0) + /// Proof: Loans UnderlyingAssetId (max_values: None, max_size: Some(38), added: 2513, mode: MaxEncodedLen) + /// Storage: Tokens TotalIssuance (r:1 w:1) + /// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(35), added: 2510, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Loans TotalBorrows (r:1 w:0) + /// Proof: Loans TotalBorrows (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans TotalReserves (r:1 w:0) + /// Proof: Loans TotalReserves (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: Loans MinExchangeRate (r:1 w:0) + /// Proof: Loans MinExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Loans AccountDeposits (r:1 w:0) + /// Proof: Loans AccountDeposits (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: VaultRegistry PremiumRedeemThreshold (r:1 w:0) + /// Proof: VaultRegistry PremiumRedeemThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry LiquidationCollateralThreshold (r:1 w:0) + /// Proof: VaultRegistry LiquidationCollateralThreshold (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry MinimumCollateralVault (r:1 w:0) + /// Proof: VaultRegistry MinimumCollateralVault (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen) + /// Storage: VaultRegistry SystemCollateralCeiling (r:1 w:0) + /// Proof: VaultRegistry SystemCollateralCeiling (max_values: None, max_size: Some(54), added: 2529, mode: MaxEncodedLen) + /// Storage: VaultRegistry VaultBitcoinPublicKey (r:1 w:0) + /// Proof: VaultRegistry VaultBitcoinPublicKey (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Loans MaxExchangeRate (r:1 w:0) + /// Proof: Loans MaxExchangeRate (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + fn deposit_vault_collateral_in_lending_market () -> Weight { + // Proof Size summary in bytes: + // Measured: `4497` + // Estimated: `251048` + // Minimum execution time: 34_975_842_000 picoseconds. + Weight::from_parts(40_755_750_000, 251048) + .saturating_add(T::DbWeight::get().reads(83_u64)) + .saturating_add(T::DbWeight::get().writes(47_u64)) + } } \ No newline at end of file