From def6e4f744c908ea306d70c31c4be6199610b63a Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Wed, 21 Jun 2023 21:35:44 +0000 Subject: [PATCH 1/2] test: can't withdraw all due to rounding Signed-off-by: Gregory Hill --- crates/nomination/src/tests.rs | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/nomination/src/tests.rs b/crates/nomination/src/tests.rs index 62a632bea6..e344bd11c8 100644 --- a/crates/nomination/src/tests.rs +++ b/crates/nomination/src/tests.rs @@ -2,6 +2,7 @@ use crate::{ext, mock::*}; use currency::Amount; use frame_support::{assert_err, assert_ok}; use mocktopus::mocking::*; +use sp_arithmetic::FixedI128; #[test] fn should_not_deposit_against_invalid_vault() { @@ -12,6 +13,7 @@ fn should_not_deposit_against_invalid_vault() { ); }) } + fn collateral(amount: u128) -> Amount { Amount::new(amount, DEFAULT_COLLATERAL_CURRENCY) } @@ -32,3 +34,54 @@ fn should_deposit_against_valid_vault() { assert_ok!(Nomination::_deposit_collateral(&ALICE, &BOB.account_id, 100)); }) } + +#[test] +fn should_not_withdraw_collateral() { + use orml_traits::MultiCurrency; + + run_test(|| { + assert_ok!(Tokens::deposit( + ALICE.currencies.collateral, + &ALICE.account_id, + 24_609_778_406_619_232 + )); + VaultRegistry::_set_system_collateral_ceiling(ALICE.currencies, u128::MAX); + assert_ok!(VaultRegistry::register_public_key( + RuntimeOrigin::signed(ALICE.account_id), + vault_registry::BtcPublicKey::dummy() + )); + assert_ok!(VaultRegistry::register_vault( + RuntimeOrigin::signed(ALICE.account_id), + ALICE.currencies, + 24_609_778_406_619_232 + )); + + staking::SlashPerToken::::insert(0, ALICE, FixedI128::from_inner(25_210_223_519_649_666)); + staking::SlashTally::::insert( + 0, + (ALICE, ALICE.account_id), + FixedI128::from_inner(100_834_580_684_768_029_667_333_677_168), + ); + staking::Stake::::insert( + 0, + (ALICE, ALICE.account_id), + FixedI128::from_inner(3_999_749_570_096_999_994_120_799_432_121), + ); + staking::TotalCurrentStake::::insert( + 0, + ALICE, + FixedI128::from_inner(3_999_749_570_097_000_000_000_000_000_000), + ); + staking::TotalStake::::insert( + 0, + ALICE, + FixedI128::from_inner(3_999_749_570_096_999_994_120_799_432_121), + ); + + // should not withdraw all + assert_err!( + Nomination::_withdraw_collateral(&ALICE, &ALICE.account_id, 3999749570097, 0), + staking::Error::::InsufficientFunds + ); + }); +} From 9cfca0b357c7f7f7a8ee23ce7ca787667a27aa2a Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Wed, 12 Jul 2023 18:03:58 +0000 Subject: [PATCH 2/2] fix: allow vault to withdraw all collateral Signed-off-by: Gregory Hill --- crates/nomination/Cargo.toml | 1 + crates/nomination/src/benchmarking.rs | 7 +++++- crates/nomination/src/ext.rs | 9 ++++---- crates/nomination/src/lib.rs | 21 ++++++++++------- crates/nomination/src/tests.rs | 12 +++++++++- crates/replace/src/ext.rs | 2 +- crates/replace/src/lib.rs | 2 +- crates/reward/src/lib.rs | 12 ++++++---- crates/staking/src/lib.rs | 23 ++++++++++++++++++- crates/vault-registry/src/ext.rs | 12 +++++++--- crates/vault-registry/src/lib.rs | 16 ++++++++----- crates/vault-registry/src/pool_manager.rs | 10 ++++---- crates/vault-registry/src/tests.rs | 6 ++--- crates/vault-registry/src/types.rs | 4 ++-- .../runtime-tests/src/parachain/issue.rs | 2 +- .../runtime-tests/src/parachain/nomination.rs | 12 +++++----- .../src/parachain/vault_registry.rs | 10 ++++---- .../src/utils/nomination_utils.rs | 4 ++-- 18 files changed, 111 insertions(+), 54 deletions(-) diff --git a/crates/nomination/Cargo.toml b/crates/nomination/Cargo.toml index 91c7febc7e..afeb13d1a3 100644 --- a/crates/nomination/Cargo.toml +++ b/crates/nomination/Cargo.toml @@ -82,6 +82,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "traits/runtime-benchmarks", "vault-registry/runtime-benchmarks", "orml-tokens", diff --git a/crates/nomination/src/benchmarking.rs b/crates/nomination/src/benchmarking.rs index 6fc87bd1f4..2320ad8d02 100644 --- a/crates/nomination/src/benchmarking.rs +++ b/crates/nomination/src/benchmarking.rs @@ -184,7 +184,12 @@ pub mod benchmarks { let balance_before = >::reserved_balance(collateral_currency, &vault_id.account_id); #[extrinsic_call] - _(RawOrigin::Signed(nominator.clone()), vault_id.clone(), amount, None); + _( + RawOrigin::Signed(nominator.clone()), + vault_id.clone(), + Some(amount), + None, + ); let balance_after = >::reserved_balance(collateral_currency, &vault_id.account_id); assert_eq!(balance_before - amount, balance_after); diff --git a/crates/nomination/src/ext.rs b/crates/nomination/src/ext.rs index 0c91d9bdab..5124274e3f 100644 --- a/crates/nomination/src/ext.rs +++ b/crates/nomination/src/ext.rs @@ -22,7 +22,7 @@ pub(crate) mod vault_registry { pub fn is_allowed_to_withdraw_collateral( vault_id: &DefaultVaultId, - amount: &Amount, + amount: Option>, ) -> Result { >::is_allowed_to_withdraw_collateral(vault_id, amount) } @@ -55,10 +55,10 @@ pub(crate) mod vault_registry { pub fn withdraw_collateral( vault_id: &DefaultVaultId, nominator_id: &T::AccountId, - amount: &Amount, + maybe_amount: Option>, nonce: Option<::Index>, - ) -> Result<(), DispatchError> { - >::withdraw_collateral(vault_id, nominator_id, amount, nonce) + ) -> Result, DispatchError> { + >::withdraw_collateral(vault_id, nominator_id, maybe_amount, nonce) } pub fn kick_nominators(vault_id: &DefaultVaultId) -> Result, DispatchError> { @@ -77,6 +77,7 @@ pub(crate) mod staking { pub fn nonce(vault_id: &DefaultVaultId) -> T::Index { T::VaultStaking::nonce(vault_id) } + pub fn compute_stake( vault_id: &DefaultVaultId, nominator_id: &T::AccountId, diff --git a/crates/nomination/src/lib.rs b/crates/nomination/src/lib.rs index 61f5001bfd..2dfe9a2a05 100644 --- a/crates/nomination/src/lib.rs +++ b/crates/nomination/src/lib.rs @@ -197,7 +197,7 @@ pub mod pallet { pub fn withdraw_collateral( origin: OriginFor, vault_id: DefaultVaultId, - amount: BalanceOf, + amount: Option>, index: Option, ) -> DispatchResultWithPostInfo { let nominator_id = ensure_signed(origin)?; @@ -228,20 +228,20 @@ impl Pallet { pub fn _withdraw_collateral( vault_id: &DefaultVaultId, nominator_id: &T::AccountId, - amount: BalanceOf, + maybe_amount: Option>, index: T::Index, ) -> DispatchResult { let nonce = ext::staking::nonce::(vault_id); let index = sp_std::cmp::min(index, nonce); - let amount = Amount::new(amount, vault_id.collateral_currency()); + let maybe_amount = maybe_amount.map(|x| Amount::::new(x, vault_id.collateral_currency())); // nominators are always allowed to withdraw from stale staking pools if index == nonce { // we can only withdraw nominated collateral if the vault is still // above the secure threshold for issued + to_be_issued tokens ensure!( - ext::vault_registry::is_allowed_to_withdraw_collateral::(vault_id, &amount)?, + ext::vault_registry::is_allowed_to_withdraw_collateral::(vault_id, maybe_amount.clone())?, Error::::CannotWithdrawCollateral ); @@ -251,13 +251,18 @@ impl Pallet { } } - ext::vault_registry::decrease_total_backing_collateral(&vault_id.currencies, &amount)?; - // withdraw `amount` of stake from the vault staking pool - ext::vault_registry::pool_manager::withdraw_collateral::(vault_id, nominator_id, &amount, Some(index))?; + let amount = ext::vault_registry::pool_manager::withdraw_collateral::( + vault_id, + nominator_id, + maybe_amount, + Some(index), + )?; amount.unlock_on(&vault_id.account_id)?; amount.transfer(&vault_id.account_id, &nominator_id)?; + ext::vault_registry::decrease_total_backing_collateral(&vault_id.currencies, &amount)?; + Self::deposit_event(Event::::WithdrawCollateral { vault_id: vault_id.clone(), nominator_id: nominator_id.clone(), @@ -326,7 +331,7 @@ impl Pallet { ensure!(Self::is_opted_in(&vault_id), Error::::VaultNotOptedInToNomination); let total_nominated_collateral = Self::get_total_nominated_collateral(&vault_id)?; ensure!( - ext::vault_registry::is_allowed_to_withdraw_collateral::(&vault_id, &total_nominated_collateral)?, + ext::vault_registry::is_allowed_to_withdraw_collateral::(&vault_id, Some(total_nominated_collateral))?, Error::::CollateralizationTooLow ); diff --git a/crates/nomination/src/tests.rs b/crates/nomination/src/tests.rs index e344bd11c8..616fc49306 100644 --- a/crates/nomination/src/tests.rs +++ b/crates/nomination/src/tests.rs @@ -80,8 +80,18 @@ fn should_not_withdraw_collateral() { // should not withdraw all assert_err!( - Nomination::_withdraw_collateral(&ALICE, &ALICE.account_id, 3999749570097, 0), + Nomination::_withdraw_collateral(&ALICE, &ALICE.account_id, Some(3999749570097), 0), staking::Error::::InsufficientFunds ); + + // should withdraw all + assert_ok!(Nomination::_withdraw_collateral(&ALICE, &ALICE.account_id, None, 0)); + + // stake is now zero + assert_ok!(ext::staking::compute_stake::(&ALICE, &ALICE.account_id), 0); + assert_ok!( + VaultRegistry::get_backing_collateral(&ALICE), + Amount::new(0, ALICE.collateral_currency()) + ); }); } diff --git a/crates/replace/src/ext.rs b/crates/replace/src/ext.rs index bfbfdf204b..dc8d2a77d2 100644 --- a/crates/replace/src/ext.rs +++ b/crates/replace/src/ext.rs @@ -133,7 +133,7 @@ pub(crate) mod vault_registry { pub fn is_allowed_to_withdraw_collateral( vault_id: &DefaultVaultId, - amount: &Amount, + amount: Option>, ) -> Result { >::is_allowed_to_withdraw_collateral(vault_id, amount) } diff --git a/crates/replace/src/lib.rs b/crates/replace/src/lib.rs index ba741b8beb..3187c8d4a3 100644 --- a/crates/replace/src/lib.rs +++ b/crates/replace/src/lib.rs @@ -598,7 +598,7 @@ impl Pallet { // if the new_vault locked additional collateral especially for this replace, // release it if it does not cause them to be undercollateralized if !ext::vault_registry::is_vault_liquidated::(&new_vault_id)? - && ext::vault_registry::is_allowed_to_withdraw_collateral::(&new_vault_id, &collateral)? + && ext::vault_registry::is_allowed_to_withdraw_collateral::(&new_vault_id, Some(collateral.clone()))? { ext::vault_registry::force_withdraw_collateral::(&new_vault_id, &collateral)?; } diff --git a/crates/reward/src/lib.rs b/crates/reward/src/lib.rs index 12518d7132..a66614a21a 100644 --- a/crates/reward/src/lib.rs +++ b/crates/reward/src/lib.rs @@ -359,7 +359,7 @@ impl, I: 'static> Pallet { pub trait RewardsApi where - Balance: Saturating + PartialOrd, + Balance: Saturating + PartialOrd + Copy, { type CurrencyId; @@ -389,8 +389,10 @@ where fn withdraw_stake(pool_id: &PoolId, stake_id: &StakeId, amount: Balance) -> DispatchResult; /// Withdraw all stake for an account. - fn withdraw_all_stake(pool_id: &PoolId, stake_id: &StakeId) -> DispatchResult { - Self::withdraw_stake(pool_id, stake_id, Self::get_stake(pool_id, stake_id)?) + fn withdraw_all_stake(pool_id: &PoolId, stake_id: &StakeId) -> Result { + let amount = Self::get_stake(pool_id, stake_id)?; + Self::withdraw_stake(pool_id, stake_id, amount)?; + Ok(amount) } /// Return the stake associated with the `pool_id`. @@ -418,7 +420,7 @@ impl RewardsApi for Pallet where T: Config, I: 'static, - Balance: BalanceToFixedPoint> + Saturating + PartialOrd, + Balance: BalanceToFixedPoint> + Saturating + PartialOrd + Copy, ::Inner: TryInto, { type CurrencyId = T::CurrencyId; @@ -490,7 +492,7 @@ where impl RewardsApi for () where - Balance: Saturating + PartialOrd + Default, + Balance: Saturating + PartialOrd + Default + Copy, { type CurrencyId = (); diff --git a/crates/staking/src/lib.rs b/crates/staking/src/lib.rs index 77f0c9037e..9183b6880b 100644 --- a/crates/staking/src/lib.rs +++ b/crates/staking/src/lib.rs @@ -641,6 +641,12 @@ impl Pallet { checked_sub_mut!(TotalStake, nonce, vault_id, &amount); checked_sub_mut!(TotalCurrentStake, nonce, vault_id, &amount); + if Self::total_stake_at_index(nonce, vault_id).is_zero() { + // may be non-zero due to rounding, will truncate to zero + // but cleanup anyway + TotalCurrentStake::::remove(nonce, vault_id); + } + >::mutate(nonce, (vault_id, nominator_id), |slash_tally| { let slash_per_token = Self::slash_per_token_at_index(nonce, vault_id); let slash_per_token_mul_amount = slash_per_token.checked_mul(&amount).ok_or(ArithmeticError::Overflow)?; @@ -772,7 +778,7 @@ impl Pallet { impl RewardsApi<(Option, DefaultVaultId), T::AccountId, Balance> for Pallet where T: Config, - Balance: BalanceToFixedPoint> + Saturating + PartialOrd, + Balance: BalanceToFixedPoint> + Saturating + PartialOrd + Copy, ::Inner: TryInto, { type CurrencyId = T::CurrencyId; @@ -845,6 +851,21 @@ where ) } + fn withdraw_all_stake( + (nonce, vault_id): &(Option, DefaultVaultId), + nominator_id: &T::AccountId, + ) -> Result { + let nonce = nonce.unwrap_or(Pallet::::nonce(vault_id)); + // use the precise stake to avoid rounding issues + let amount = Self::compute_precise_stake_at_index(nonce, vault_id, nominator_id)?; + Pallet::::withdraw_stake(vault_id, nominator_id, amount, Some(nonce))?; + amount + .truncate_to_inner() + .ok_or(Error::::TryIntoIntError)? + .try_into() + .map_err(|_| Error::::TryIntoIntError.into()) + } + fn get_total_stake((_, vault_id): &(Option, DefaultVaultId)) -> Result { Pallet::::total_current_stake(vault_id)? .try_into() diff --git a/crates/vault-registry/src/ext.rs b/crates/vault-registry/src/ext.rs index 003452e378..299c0acdc7 100644 --- a/crates/vault-registry/src/ext.rs +++ b/crates/vault-registry/src/ext.rs @@ -40,10 +40,16 @@ pub(crate) mod staking { pub fn withdraw_stake( vault_id: &DefaultVaultId, nominator_id: &T::AccountId, - amount: &Amount, + maybe_amount: Option>, nonce: Option<::Index>, - ) -> DispatchResult { - T::VaultStaking::withdraw_stake(&(nonce, vault_id.clone()), nominator_id, amount.amount()) + ) -> Result, DispatchError> { + if let Some(amount) = maybe_amount { + T::VaultStaking::withdraw_stake(&(nonce, vault_id.clone()), nominator_id, amount.amount())?; + Ok(amount) + } else { + let balance = T::VaultStaking::withdraw_all_stake(&(nonce, vault_id.clone()), nominator_id)?; + Ok(Amount::new(balance, vault_id.collateral_currency())) + } } pub fn slash_stake(vault_id: &DefaultVaultId, amount: &Amount) -> DispatchResult { diff --git a/crates/vault-registry/src/lib.rs b/crates/vault-registry/src/lib.rs index a6215eb29c..c6321504d0 100644 --- a/crates/vault-registry/src/lib.rs +++ b/crates/vault-registry/src/lib.rs @@ -825,7 +825,7 @@ impl Pallet { Self::decrease_total_backing_collateral(&vault_id.currencies, amount)?; // Withdraw `amount` of stake from the pool - PoolManager::::withdraw_collateral(vault_id, &vault_id.account_id, amount, None)?; + PoolManager::::withdraw_collateral(vault_id, &vault_id.account_id, Some(amount.clone()), None)?; Ok(()) } @@ -833,14 +833,18 @@ impl Pallet { /// Checks if the vault would be above the secure threshold after withdrawing collateral pub fn is_allowed_to_withdraw_collateral( vault_id: &DefaultVaultId, - amount: &Amount, + amount: Option>, ) -> Result { let vault = Self::get_rich_vault_from_id(vault_id)?; - let new_collateral = match Self::get_backing_collateral(vault_id)?.checked_sub(&amount) { - Ok(x) => x, - Err(x) if x == ArithmeticError::Underflow.into() => return Ok(false), - Err(x) => return Err(x), + let new_collateral = if let Some(amount) = amount { + match Self::get_backing_collateral(vault_id)?.checked_sub(&amount) { + Ok(x) => x, + Err(x) if x == ArithmeticError::Underflow.into() => return Ok(false), + Err(x) => return Err(x), + } + } else { + Amount::::zero(vault_id.collateral_currency()) }; ensure!( diff --git a/crates/vault-registry/src/pool_manager.rs b/crates/vault-registry/src/pool_manager.rs index 55bb39af14..09bb0597bd 100644 --- a/crates/vault-registry/src/pool_manager.rs +++ b/crates/vault-registry/src/pool_manager.rs @@ -19,14 +19,16 @@ impl PoolManager { pub fn withdraw_collateral( vault_id: &DefaultVaultId, nominator_id: &T::AccountId, - amount: &Amount, + maybe_amount: Option>, nonce: Option<::Index>, - ) -> Result<(), DispatchError> { + ) -> Result, DispatchError> { ext::fee::distribute_all_vault_rewards::(vault_id)?; - ext::staking::withdraw_stake(vault_id, nominator_id, amount, nonce)?; + let amount = ext::staking::withdraw_stake(vault_id, nominator_id, maybe_amount, nonce)?; // also propagate to reward & capacity pools - Self::update_reward_stake(vault_id) + Self::update_reward_stake(vault_id)?; + + Ok(amount) } pub fn slash_collateral(vault_id: &DefaultVaultId, amount: &Amount) -> Result<(), DispatchError> { diff --git a/crates/vault-registry/src/tests.rs b/crates/vault-registry/src/tests.rs index 1a41a81212..cd1dd05cc2 100644 --- a/crates/vault-registry/src/tests.rs +++ b/crates/vault-registry/src/tests.rs @@ -202,17 +202,17 @@ fn should_check_withdraw_collateral() { // should allow withdraw all assert_ok!( - VaultRegistry::is_allowed_to_withdraw_collateral(&DEFAULT_ID, &amount(DEFAULT_COLLATERAL)), + VaultRegistry::is_allowed_to_withdraw_collateral(&DEFAULT_ID, Some(amount(DEFAULT_COLLATERAL))), true, ); // should allow withdraw above minimum assert_ok!( - VaultRegistry::is_allowed_to_withdraw_collateral(&DEFAULT_ID, &amount(DEFAULT_COLLATERAL / 4)), + VaultRegistry::is_allowed_to_withdraw_collateral(&DEFAULT_ID, Some(amount(DEFAULT_COLLATERAL / 4))), true, ); // should not allow withdraw above zero, below minimum assert_err!( - VaultRegistry::is_allowed_to_withdraw_collateral(&DEFAULT_ID, &amount(DEFAULT_COLLATERAL / 4 * 3)), + VaultRegistry::is_allowed_to_withdraw_collateral(&DEFAULT_ID, Some(amount(DEFAULT_COLLATERAL / 4 * 3))), TestError::InsufficientVaultCollateralAmount, ); }); diff --git a/crates/vault-registry/src/types.rs b/crates/vault-registry/src/types.rs index fe2e967493..7570ac6c6f 100644 --- a/crates/vault-registry/src/types.rs +++ b/crates/vault-registry/src/types.rs @@ -538,8 +538,8 @@ impl RichVault { pub(crate) fn slash_for_to_be_redeemed(&mut self, amount: &Amount) -> DispatchResult { let vault_id = self.id(); let collateral = self.get_vault_collateral()?.min(amount)?; - PoolManager::::withdraw_collateral(&vault_id, &vault_id.account_id, &collateral, None)?; self.increase_liquidated_collateral(&collateral)?; + PoolManager::::withdraw_collateral(&vault_id, &vault_id.account_id, Some(collateral), None)?; Ok(()) } @@ -554,7 +554,7 @@ impl RichVault { .unwrap_or((amount.clone(), None)); // "slash" vault first - PoolManager::::withdraw_collateral(&vault_id, &vault_id.account_id, &to_withdraw, None)?; + PoolManager::::withdraw_collateral(&vault_id, &vault_id.account_id, Some(to_withdraw), None)?; // take remainder from nominators if let Some(to_slash) = to_slash { PoolManager::::slash_collateral(&vault_id, &to_slash)?; diff --git a/parachain/runtime/runtime-tests/src/parachain/issue.rs b/parachain/runtime/runtime-tests/src/parachain/issue.rs index 420539a826..8e32f60bff 100644 --- a/parachain/runtime/runtime-tests/src/parachain/issue.rs +++ b/parachain/runtime/runtime-tests/src/parachain/issue.rs @@ -564,7 +564,7 @@ fn integration_test_withdraw_after_request_issue() { assert!(RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), index: None, - amount: collateral_vault.amount() + amount: Some(collateral_vault.amount()) }) .dispatch(origin_of(account_of(vault))) .is_err()); diff --git a/parachain/runtime/runtime-tests/src/parachain/nomination.rs b/parachain/runtime/runtime-tests/src/parachain/nomination.rs index d25b5b98e1..28b40fcbfc 100644 --- a/parachain/runtime/runtime-tests/src/parachain/nomination.rs +++ b/parachain/runtime/runtime-tests/src/parachain/nomination.rs @@ -257,7 +257,7 @@ mod spec_based_tests { assert_noop!( RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), - amount: 1, + amount: Some(1), index: None }) .dispatch(origin_of(account_of(USER))), @@ -267,7 +267,7 @@ mod spec_based_tests { assert_noop!( RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id_of(CAROL, vault_id.collateral_currency()), - amount: 1, + amount: Some(1), index: None }) .dispatch(origin_of(account_of(USER))), @@ -276,7 +276,7 @@ mod spec_based_tests { assert_noop!( RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), - amount: 1, + amount: Some(1), index: None }) .dispatch(origin_of(account_of(USER))), @@ -286,7 +286,7 @@ mod spec_based_tests { assert_noop!( RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), - amount: DEFAULT_BACKING_COLLATERAL, + amount: Some(DEFAULT_BACKING_COLLATERAL), index: None }) .dispatch(origin_of(account_of(USER))), @@ -302,7 +302,7 @@ mod spec_based_tests { assert_ok!(RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), index: None, - amount: 750000 + amount: Some(750000) }) .dispatch(origin_of(account_of(VAULT)))); assert_nomination_opt_in(&vault_id); @@ -510,7 +510,7 @@ fn integration_test_nominator_withdrawal_below_collateralization_threshold_fails assert_ok!(RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), index: None, - amount: 750000 + amount: Some(750000) }) .dispatch(origin_of(account_of(VAULT)))); assert_nomination_opt_in(&vault_id); diff --git a/parachain/runtime/runtime-tests/src/parachain/vault_registry.rs b/parachain/runtime/runtime-tests/src/parachain/vault_registry.rs index 0da71e3542..e8cdc6fbc0 100644 --- a/parachain/runtime/runtime-tests/src/parachain/vault_registry.rs +++ b/parachain/runtime/runtime-tests/src/parachain/vault_registry.rs @@ -194,7 +194,7 @@ mod withdraw_collateral_test { assert_ok!(RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), - amount: amount.amount(), + amount: Some(amount.amount()), index: None, }) .dispatch(origin_of(account_of(VAULT)))); @@ -218,7 +218,7 @@ mod withdraw_collateral_test { assert_ok!(RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), index: None, - amount: amount.amount() + amount: Some(amount.amount()) }) .dispatch(origin_of(account_of(VAULT)))); @@ -244,7 +244,7 @@ mod withdraw_collateral_test { RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), index: None, - amount: amount + amount: Some(amount) }) .dispatch(origin_of(account_of(VAULT))), NominationError::CannotWithdrawCollateral @@ -270,7 +270,7 @@ mod withdraw_collateral_test { RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), index: None, - amount: amount.amount() + amount: Some(amount.amount()) }) .dispatch(origin_of(account_of(VAULT))), NominationError::CannotWithdrawCollateral @@ -287,7 +287,7 @@ mod withdraw_collateral_test { assert_ok!(RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), index: None, - amount: amount.amount() + amount: Some(amount.amount()) }) .dispatch(origin_of(account_of(VAULT)))); diff --git a/parachain/runtime/runtime-tests/src/utils/nomination_utils.rs b/parachain/runtime/runtime-tests/src/utils/nomination_utils.rs index 2cad47a2c3..ed83e9846d 100644 --- a/parachain/runtime/runtime-tests/src/utils/nomination_utils.rs +++ b/parachain/runtime/runtime-tests/src/utils/nomination_utils.rs @@ -78,7 +78,7 @@ pub fn withdraw_vault_collateral(vault_id: &VaultId, amount_collateral: Amount DispatchResultWithPostInfo { RuntimeCall::Nomination(NominationCall::withdraw_collateral { vault_id: vault_id.clone(), - amount: amount_collateral.amount(), + amount: Some(amount_collateral.amount()), index: None, }) .dispatch(origin_of(nominator_id))