diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index db320b98c3..afb2c143a0 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -33,8 +33,8 @@ mod mock; mod tests; // Re-export pallet items so that they can be accessed from the crate namespace. -use frame_support::{pallet_prelude::*, sp_runtime::MultiSignature, transactional}; -use node_primitives::{ParaId, TokenInfo, TokenSymbol}; +use frame_support::{pallet_prelude::*, transactional}; +use node_primitives::{TokenInfo, TokenSymbol}; use orml_traits::MultiCurrency; pub use pallet::*; use sp_std::convert::TryFrom; @@ -81,9 +81,7 @@ impl Default for FundStatus { /// (`Funds`). #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)] #[codec(dumb_trait_bound)] -pub struct FundInfo { - /// The owning account who placed the deposit. - depositor: AccountId, +pub struct FundInfo { /// The amount of deposit placed. deposit: Balance, /// The total amount raised. @@ -102,46 +100,6 @@ pub struct FundInfo { status: FundStatus, } -#[derive(Encode, Decode)] -pub enum CrowdloanContributeCall { - #[codec(index = 73)] - CrowdloanContribute(ContributeCall), -} - -#[derive(Encode, Decode)] -pub enum CrowdloanWithdrawCall { - #[codec(index = 73)] - CrowdloanWithdraw(WithdrawCall), -} - -#[derive(Debug, PartialEq, Encode, Decode)] -pub struct Contribution { - #[codec(compact)] - index: ParaId, - #[codec(compact)] - value: BalanceOf, - signature: Option, -} - -#[derive(Encode, Decode)] -pub enum ContributeCall { - #[codec(index = 1)] - Contribute(Contribution), -} - -#[derive(Debug, PartialEq, Encode, Decode)] -pub struct Withdraw { - who: AccountIdOf, - #[codec(compact)] - index: ParaId, -} - -#[derive(Encode, Decode)] -pub enum WithdrawCall { - #[codec(index = 2)] - Withdraw(Withdraw), -} - #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, Copy)] pub enum ContributionStatus { Idle, @@ -227,7 +185,7 @@ pub mod pallet { prelude::{XcmError, XcmResult}, Junction, MultiLocation, }; - use xcm_support::BifrostXcmExecutor; + use xcm_support::*; use super::*; @@ -310,6 +268,12 @@ pub mod pallet { type WithdrawWeight: Get; type WeightToFee: WeightToFeePolynomial>; + + #[pallet::constant] + type AddProxyWeight: Get; + + #[pallet::constant] + type RemoveProxyWeight: Get; } #[pallet::pallet] @@ -328,7 +292,7 @@ pub mod pallet { /// Fail on contribute to crowd sale. [who, fund_index, amount] ContributeFailed(AccountIdOf, ParaId, BalanceOf), /// Withdrawing full balance of a contributor. [who, fund_index, amount] - Withdrawing(AccountIdOf, ParaId, BalanceOf), + Withdrawing(ParaId, BalanceOf), /// Withdrew full balance of a contributor. [who, fund_index, amount] Withdrew(ParaId, BalanceOf), /// Fail on withdraw full balance of a contributor. [who, fund_index, amount] @@ -349,6 +313,9 @@ pub mod pallet { Dissolved(ParaId), /// The vsToken/vsBond was be unlocked. [who, fund_index, value] Unlocked(AccountIdOf, ParaId, BalanceOf), + /// Proxy + ProxyAdded(AccountIdOf), + ProxyRemoved(AccountIdOf), } #[pallet::error] @@ -411,7 +378,7 @@ pub mod pallet { _, Blake2_128Concat, ParaId, - Option, BalanceOf, LeasePeriod>>, + Option, LeasePeriod>>, ValueQuery, >; @@ -558,7 +525,11 @@ pub mod pallet { } /// Create a new crowdloaning campaign for a parachain slot deposit for the current auction. - #[pallet::weight(T::WeightInfo::create())] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn create( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -566,7 +537,7 @@ pub mod pallet { #[pallet::compact] first_slot: LeasePeriod, #[pallet::compact] last_slot: LeasePeriod, ) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; ensure!(!Funds::::contains_key(index), Error::::FundAlreadyCreated); @@ -579,12 +550,9 @@ pub mod pallet { let deposit = T::SubmissionDeposit::get(); - T::MultiCurrency::reserve(T::DepositToken::get(), &owner, deposit)?; - Funds::::insert( index, Some(FundInfo { - depositor: owner, deposit, raised: Zero::zero(), cap, @@ -610,6 +578,7 @@ pub mod pallet { origin: OriginFor, #[pallet::compact] index: ParaId, #[pallet::compact] value: BalanceOf, + is_proxy: bool, ) -> DispatchResult { let who = ensure_signed(origin.clone())?; @@ -624,7 +593,10 @@ pub mod pallet { let (contributed, status) = Self::contribution(fund.trie_index, &who); ensure!(status == ContributionStatus::Idle, Error::::InvalidContributionStatus); - Self::xcm_ump_contribute(origin, index, value).map_err(|_e| Error::::XcmFailed)?; + if is_proxy { + Self::xcm_ump_contribute(origin, index, value) + .map_err(|_e| Error::::XcmFailed)?; + } Self::put_contribution( fund.trie_index, @@ -706,23 +678,30 @@ pub mod pallet { Ok(()) } - /// Withdraw full balance of the parachain. this function may need to be called multiple - /// times + /// Withdraw full balance of the parachain. /// - `index`: The parachain to whose crowdloan the contribution was made. - #[pallet::weight(T::WeightInfo::withdraw())] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] #[transactional] - pub fn withdraw(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let owner = ensure_signed(origin.clone())?; + pub fn withdraw( + origin: OriginFor, + #[pallet::compact] index: ParaId, + is_proxy: bool, + ) -> DispatchResult { + T::EnsureConfirmAsMultiSig::ensure_origin(origin.clone())?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; let can = fund.status == FundStatus::Failed || fund.status == FundStatus::Retired; ensure!(can, Error::::InvalidFundStatus); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - - Self::xcm_ump_withdraw(origin, index).map_err(|_| Error::::XcmFailed)?; + if is_proxy { + Self::xcm_ump_withdraw(origin, index).map_err(|_| Error::::XcmFailed)?; + } - Self::deposit_event(Event::Withdrawing(owner, index, fund.raised)); + Self::deposit_event(Event::Withdrawing(index, fund.raised)); Ok(()) } @@ -769,7 +748,11 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::refund())] #[transactional] - pub fn refund(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { + pub fn refund( + origin: OriginFor, + #[pallet::compact] index: ParaId, + is_proxy: bool, + ) -> DispatchResult { let who = ensure_signed(origin.clone())?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; @@ -792,7 +775,10 @@ pub mod pallet { Error::::NotEnoughReservedAssetsToRefund ); - Self::xcm_ump_redeem(origin, index, contributed).map_err(|_| Error::::XcmFailed)?; + if is_proxy { + Self::xcm_ump_redeem(origin, index, contributed) + .map_err(|_| Error::::XcmFailed)?; + } RefundPool::::set(Self::refund_pool().saturating_sub(contributed)); @@ -866,42 +852,48 @@ pub mod pallet { pub fn redeem( origin: OriginFor, #[pallet::compact] index: ParaId, - #[pallet::compact] first_slot: LeasePeriod, - #[pallet::compact] last_slot: LeasePeriod, #[pallet::compact] value: BalanceOf, + is_proxy: bool, ) -> DispatchResult { let who = ensure_signed(origin.clone())?; + let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; + ensure!(fund.status == FundStatus::RedeemWithdrew, Error::::InvalidFundStatus); ensure!(Self::redeem_pool() >= value, Error::::NotEnoughBalanceInRedeemPool); - let cur_block = >::block_number(); - ensure!(!Self::is_expired(cur_block, last_slot), Error::::VSBondExpired); - if T::XcmTransferOrigin::get() != TransferOriginType::FromRelayChain { - ensure!(Self::can_redeem(cur_block, last_slot), Error::::UnRedeemableNow); - } + ensure!(!Self::is_expired(cur_block, fund.last_slot), Error::::VSBondExpired); + ensure!(Self::can_redeem(cur_block, fund.last_slot), Error::::UnRedeemableNow); #[allow(non_snake_case)] - let (vsToken, vsBond) = Self::vsAssets(index, first_slot, last_slot); + let (vsToken, vsBond) = Self::vsAssets(index, fund.first_slot, fund.last_slot); T::MultiCurrency::reserve(vsToken, &who, value) .map_err(|_| Error::::NotEnoughFreeAssetsToRedeem)?; T::MultiCurrency::reserve(vsBond, &who, value) .map_err(|_| Error::::NotEnoughFreeAssetsToRedeem)?; - let status = Self::redeem_status(who.clone(), (index, first_slot, last_slot)); + let status = Self::redeem_status(who.clone(), (index, fund.first_slot, fund.last_slot)); ensure!(status == RedeemStatus::Idle, Error::::InvalidRedeemStatus); - Self::xcm_ump_redeem(origin.clone(), index, value) - .map_err(|_| Error::::XcmFailed)?; + if is_proxy { + Self::xcm_ump_redeem(origin.clone(), index, value) + .map_err(|_| Error::::XcmFailed)?; + } RedeemPool::::set(Self::redeem_pool().saturating_sub(value)); RedeemExtras::::insert( who.clone(), - (index, first_slot, last_slot), + (index, fund.first_slot, fund.last_slot), RedeemStatus::Redeeming(value), ); - Self::deposit_event(Event::Redeeming(who, index, first_slot, last_slot, value)); + Self::deposit_event(Event::Redeeming( + who, + index, + fund.first_slot, + fund.last_slot, + value, + )); Ok(()) } @@ -915,20 +907,20 @@ pub mod pallet { origin: OriginFor, who: AccountIdOf, #[pallet::compact] index: ParaId, - #[pallet::compact] first_slot: LeasePeriod, - #[pallet::compact] last_slot: LeasePeriod, is_success: bool, ) -> DispatchResult { use RedeemStatus as RS; T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; + let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; + ensure!(fund.status == FundStatus::RedeemWithdrew, Error::::InvalidFundStatus); - let status = Self::redeem_status(who.clone(), (index, first_slot, last_slot)); + let status = Self::redeem_status(who.clone(), (index, fund.first_slot, fund.last_slot)); ensure!(status.is_redeeming(), Error::::InvalidRedeemStatus); let value = status.redeeming(); #[allow(non_snake_case)] - let (vsToken, vsBond) = Self::vsAssets(index, first_slot, last_slot); + let (vsToken, vsBond) = Self::vsAssets(index, fund.first_slot, fund.last_slot); if is_success { let balance = T::MultiCurrency::slash_reserved(vsToken, &who, value); @@ -936,9 +928,19 @@ pub mod pallet { let balance = T::MultiCurrency::slash_reserved(vsBond, &who, value); ensure!(balance == Zero::zero(), Error::::NotEnoughFreeAssetsToRedeem); - RedeemExtras::::insert(who.clone(), (index, first_slot, last_slot), RS::Idle); + RedeemExtras::::insert( + who.clone(), + (index, fund.first_slot, fund.last_slot), + RS::Idle, + ); - Self::deposit_event(Event::Redeemed(who, index, first_slot, last_slot, value)); + Self::deposit_event(Event::Redeemed( + who, + index, + fund.first_slot, + fund.last_slot, + value, + )); } else { let balance = T::MultiCurrency::unreserve(vsToken, &who, value); ensure!( @@ -953,24 +955,36 @@ pub mod pallet { RedeemPool::::set(Self::redeem_pool().saturating_add(value)); - RedeemExtras::::insert(who.clone(), (index, first_slot, last_slot), RS::Idle); + RedeemExtras::::insert( + who.clone(), + (index, fund.first_slot, fund.last_slot), + RS::Idle, + ); - Self::deposit_event(Event::RedeemFailed(who, index, first_slot, last_slot, value)); + Self::deposit_event(Event::RedeemFailed( + who, + index, + fund.first_slot, + fund.last_slot, + value, + )); } Ok(()) } /// Remove a fund after the retirement period has ended and all funds have been returned. - #[pallet::weight(T::WeightInfo::dissolve(T::RemoveKeysLimit::get()))] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn dissolve(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let depositor = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let mut fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::End, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); - // TODO: Delete element when iter? Fix it? let mut refund_count = 0u32; // Try killing the crowdloan child trie and Assume everyone will be refunded. @@ -988,13 +1002,48 @@ pub mod pallet { } if all_refunded == true { - T::MultiCurrency::unreserve(T::DepositToken::get(), &depositor, fund.deposit); Funds::::remove(index); Self::deposit_event(Event::::Dissolved(index)); } Ok(()) } + + /// Add proxy for parachain account + /// - `delegate`: The delegate proxy account + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] + #[transactional] + pub fn add_proxy(origin: OriginFor, delegate: AccountIdOf) -> DispatchResult { + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; + + Self::xcm_ump_add_proxy(delegate.clone()).map_err(|_| Error::::XcmFailed)?; + + Self::deposit_event(Event::ProxyAdded(delegate)); + + Ok(()) + } + + /// Add proxy for parachain account + /// - `delegate`: The delegate proxy account + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] + #[transactional] + pub fn remove_proxy(origin: OriginFor, delegate: AccountIdOf) -> DispatchResult { + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; + + Self::xcm_ump_remove_proxy(delegate.clone()).map_err(|_| Error::::XcmFailed)?; + + Self::deposit_event(Event::ProxyRemoved(delegate)); + + Ok(()) + } } #[pallet::hooks] @@ -1141,7 +1190,7 @@ pub mod pallet { .into(); T::BifrostXcmExecutor::ump_transact( - MultiLocation::X1(Junction::Parachain(index)), + MultiLocation::Null, call, T::ContributionWeight::get(), false, @@ -1177,5 +1226,39 @@ pub mod pallet { false, ) } + + fn xcm_ump_add_proxy(delegate: AccountIdOf) -> XcmResult { + let call = ProxyAddCall::ProxyAdd(AddProxyCall::Add(AddProxy { + delegate, + proxy_type: ProxyType::Any, + delay: T::BlockNumber::zero(), + })) + .encode() + .into(); + + T::BifrostXcmExecutor::ump_transact( + MultiLocation::Null, + call, + T::AddProxyWeight::get(), + false, + ) + } + + fn xcm_ump_remove_proxy(delegate: AccountIdOf) -> XcmResult { + let call = ProxyRemoveCall::ProxyRemove(RemoveProxyCall::Remove(RemoveProxy { + delegate, + proxy_type: ProxyType::Any, + delay: T::BlockNumber::zero(), + })) + .encode() + .into(); + + T::BifrostXcmExecutor::ump_transact( + MultiLocation::Null, + call, + T::AddProxyWeight::get(), + false, + ) + } } } diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index f90b121c0f..cdeef10fb4 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -198,6 +198,8 @@ parameter_types! { pub BaseXcmWeight:u64 = 1_000_000_000 as u64; pub ContributionWeight:u64 = 1_000_000_000 as u64; pub WithdrawWeight:u64 = 1_000_000_000 as u64; + pub AddProxyWeight:u64 = 1_000_000_000 as u64; + pub RemoveProxyWeight:u64 = 1_000_000_000 as u64; pub const SelfParaId: u32 = 2001; pub PrimaryAccount: AccountId = ALICE; pub ConfirmMuitiSigAccount: AccountId = Multisig::multi_account_id(&vec![ @@ -275,6 +277,8 @@ impl salp::Config for Test { type WithdrawWeight = WithdrawWeight; type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig; type WeightToFee = WeightToFee; + type AddProxyWeight = AddProxyWeight; + type RemoveProxyWeight = RemoveProxyWeight; } pub struct SalpWeightInfo; diff --git a/pallets/salp/src/tests.rs b/pallets/salp/src/tests.rs index 029873d174..3f4df5b3e5 100644 --- a/pallets/salp/src/tests.rs +++ b/pallets/salp/src/tests.rs @@ -210,7 +210,7 @@ fn set_fund_end_should_work() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_ok!(Salp::fund_end(Some(ALICE).into(), 3_000)); @@ -226,7 +226,7 @@ fn set_fund_end_with_wrong_origin_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_noop!(Salp::fund_end(Origin::root(), 3_000), DispatchError::BadOrigin); @@ -241,7 +241,7 @@ fn set_fund_end_with_wrong_wrong_para_id_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_noop!(Salp::fund_end(Some(ALICE).into(), 4_000), Error::::InvalidParaId); @@ -262,7 +262,7 @@ fn set_fund_end_with_wrong_fund_status_should_fail() { fn unlock_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -283,7 +283,7 @@ fn unlock_should_work() { fn unlock_with_wrong_fund_status_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); @@ -298,7 +298,7 @@ fn unlock_with_wrong_fund_status_should_fail() { fn unlock_when_already_unlocked_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -314,7 +314,7 @@ fn unlock_when_already_unlocked_should_fail() { fn unlock_without_enough_reserved_vsassets_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); @@ -341,7 +341,7 @@ fn unlock_without_enough_reserved_vsassets_should_fail() { fn contribute_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); let fund = Salp::funds(3_000).unwrap(); @@ -365,9 +365,9 @@ fn contribute_should_work() { fn double_contribute_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); // Check the contribution @@ -392,7 +392,7 @@ fn double_contribute_should_work() { fn contribute_when_xcm_error_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, false)); let fund = Salp::funds(3_000).unwrap(); @@ -416,7 +416,7 @@ fn contribute_when_xcm_error_should_work() { fn confirm_contribute_later_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); @@ -441,8 +441,8 @@ fn confirm_contribute_later_should_work() { fn contribute_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_noop!(Salp::contribute(Origin::root(), 3_000, 100), DispatchError::BadOrigin); - assert_noop!(Salp::contribute(Origin::none(), 3_000, 100), DispatchError::BadOrigin); + assert_noop!(Salp::contribute(Origin::root(), 3_000, 100, false), DispatchError::BadOrigin); + assert_noop!(Salp::contribute(Origin::none(), 3_000, 100, false), DispatchError::BadOrigin); assert_noop!( Salp::confirm_contribute(Origin::root(), BRUCE, 3000, true), @@ -464,7 +464,7 @@ fn contribute_with_low_contribution_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_noop!( - Salp::contribute(Some(BRUCE).into(), 3_000, MinContribution::get() - 1), + Salp::contribute(Some(BRUCE).into(), 3_000, MinContribution::get() - 1, false), Error::::ContributionTooSmall ); }); @@ -475,7 +475,7 @@ fn contribute_with_wrong_para_id_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_noop!( - Salp::contribute(Some(BRUCE).into(), 4_000, 100), + Salp::contribute(Some(BRUCE).into(), 4_000, 100, false), Error::::InvalidParaId ); }); @@ -487,7 +487,7 @@ fn contribute_with_wrong_fund_status_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000,)); assert_noop!( - Salp::contribute(Some(BRUCE).into(), 3_000, 100), + Salp::contribute(Some(BRUCE).into(), 3_000, 100, false), Error::::InvalidFundStatus ); }); @@ -498,7 +498,7 @@ fn contribute_exceed_cap_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_noop!( - Salp::contribute(Some(BRUCE).into(), 3_000, 1_001), + Salp::contribute(Some(BRUCE).into(), 3_000, 1_001, false), Error::::CapExceeded ); }); @@ -519,10 +519,10 @@ fn contribute_when_contributing_should_fail() { fn confirm_contribute_when_not_in_contributing_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_noop!( - Salp::contribute(Some(BRUCE).into(), 3_000, 100), + Salp::contribute(Some(BRUCE).into(), 3_000, 100, false), Error::::InvalidContributionStatus ); }); @@ -537,11 +537,11 @@ fn contribute_with_when_ump_wrong_should_fail() { fn withdraw_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); let fund = Salp::funds(3_000).unwrap(); @@ -550,10 +550,10 @@ fn withdraw_should_work() { assert_eq!(Salp::redeem_pool(), 100); assert_ok!(Salp::create(Some(ALICE).into(), 4_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 4_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 4_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 4_000, true)); let fund = Salp::funds(4_000).unwrap(); @@ -567,11 +567,11 @@ fn withdraw_should_work() { fn withdraw_when_xcm_error_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, false)); let fund = Salp::funds(3_000).unwrap(); @@ -580,10 +580,10 @@ fn withdraw_when_xcm_error_should_work() { assert_eq!(Salp::redeem_pool(), 0); assert_ok!(Salp::create(Some(ALICE).into(), 4_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 4_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 4_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 4_000, false)); let fund = Salp::funds(4_000).unwrap(); @@ -597,13 +597,16 @@ fn withdraw_when_xcm_error_should_work() { fn double_withdraw_same_fund_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_noop!(Salp::withdraw(Some(ALICE).into(), 3_000), Error::::InvalidFundStatus); + assert_noop!( + Salp::withdraw(Some(ALICE).into(), 3_000, false), + Error::::InvalidFundStatus + ); let fund = Salp::funds(3_000).unwrap(); assert_eq!(fund.status, FundStatus::RedeemWithdrew); @@ -611,12 +614,15 @@ fn double_withdraw_same_fund_should_fail() { assert_eq!(Salp::redeem_pool(), 100); assert_ok!(Salp::create(Some(ALICE).into(), 4_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 4_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 4_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 4_000, true)); - assert_noop!(Salp::withdraw(Some(ALICE).into(), 4_000), Error::::InvalidFundStatus); + assert_noop!( + Salp::withdraw(Some(ALICE).into(), 4_000, false), + Error::::InvalidFundStatus + ); let fund = Salp::funds(4_000).unwrap(); assert_eq!(fund.status, FundStatus::RefundWithdrew); @@ -629,13 +635,13 @@ fn double_withdraw_same_fund_should_fail() { fn double_withdraw_same_fund_when_one_of_xcm_error_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, false)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); let fund = Salp::funds(3_000).unwrap(); @@ -644,12 +650,12 @@ fn double_withdraw_same_fund_when_one_of_xcm_error_should_work() { assert_eq!(Salp::redeem_pool(), 100); assert_ok!(Salp::create(Some(ALICE).into(), 4_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 4_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 4_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 4_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 4_000, false)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 4_000, true)); let fund = Salp::funds(4_000).unwrap(); @@ -666,9 +672,9 @@ fn withdraw_with_wrong_origin_should_fail() { assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::withdraw(Origin::root(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::withdraw(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::withdraw(Some(BRUCE).into(), 3_000), Error::::UnauthorizedAccount); + assert_noop!(Salp::withdraw(Origin::root(), 3_000, false), DispatchError::BadOrigin); + assert_noop!(Salp::withdraw(Origin::none(), 3_000, false), DispatchError::BadOrigin); + assert_noop!(Salp::withdraw(Some(BRUCE).into(), 3_000, false), DispatchError::BadOrigin); }); } @@ -679,7 +685,10 @@ fn withdraw_with_wrong_para_id_should_fail() { assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::withdraw(Some(ALICE).into(), 4_000), Error::::InvalidParaId); + assert_noop!( + Salp::withdraw(Some(ALICE).into(), 4_000, false), + Error::::InvalidParaId + ); }); } @@ -689,7 +698,10 @@ fn withdraw_with_wrong_fund_status_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::withdraw(Some(ALICE).into(), 3_000), Error::::InvalidFundStatus); + assert_noop!( + Salp::withdraw(Some(ALICE).into(), 3_000, false), + Error::::InvalidFundStatus + ); }); } @@ -702,12 +714,12 @@ fn withdraw_with_when_ump_wrong_should_fail() { fn refund_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); + assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000, false)); assert_ok!(Salp::confirm_refund(Some(ALICE).into(), BRUCE, 3_000, true)); assert_eq!(Salp::refund_pool(), 0); @@ -732,12 +744,12 @@ fn refund_should_work() { fn refund_when_xcm_error_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); + assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000, false)); assert_ok!(Salp::confirm_refund(Some(ALICE).into(), BRUCE, 3_000, false)); assert_eq!(Salp::refund_pool(), 100); @@ -762,14 +774,14 @@ fn refund_when_xcm_error_should_work() { fn double_refund_when_one_of_xcm_error_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); + assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000, false)); assert_ok!(Salp::confirm_refund(Some(ALICE).into(), BRUCE, 3_000, false)); - assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); + assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000, false)); assert_ok!(Salp::confirm_refund(Some(ALICE).into(), BRUCE, 3_000, true)); assert_eq!(Salp::refund_pool(), 0); @@ -794,10 +806,10 @@ fn double_refund_when_one_of_xcm_error_should_work() { fn refund_without_enough_vsassets_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); #[allow(non_snake_case)] @@ -806,7 +818,7 @@ fn refund_without_enough_vsassets_should_fail() { assert_ok!(Tokens::repatriate_reserved(vsBond, &BRUCE, &ALICE, 50, BS::Reserved)); assert_noop!( - Salp::refund(Some(BRUCE).into(), 3_000), + Salp::refund(Some(BRUCE).into(), 3_000, false), Error::::NotEnoughReservedAssetsToRefund ); }); @@ -817,17 +829,17 @@ fn refund_without_enough_vsassets_should_fail() { fn refund_without_enough_balance_in_pool_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); // ABSOLUTELY NOT HAPPEN AT NORMAL PROCESS! crate::pallet::RefundPool::::set(50); assert_noop!( - Salp::refund(Some(BRUCE).into(), 3_000), + Salp::refund(Some(BRUCE).into(), 3_000, false), Error::::NotEnoughBalanceInRefundPool ); }); @@ -837,12 +849,12 @@ fn refund_without_enough_balance_in_pool_should_fail() { fn confirm_refund_without_enough_reserved_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); + assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000, false)); #[allow(non_snake_case)] let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); @@ -866,15 +878,15 @@ fn confirm_refund_without_enough_reserved_should_fail() { fn refund_when_refunding_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); + assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000, false)); assert_noop!( - Salp::refund(Some(BRUCE).into(), 3_000), + Salp::refund(Some(BRUCE).into(), 3_000, false), Error::::InvalidContributionStatus ); }); @@ -884,10 +896,10 @@ fn refund_when_refunding_should_fail() { fn confirm_refund_when_not_in_refunding_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_noop!( @@ -902,10 +914,13 @@ fn refund_with_zero_contribution_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_noop!(Salp::refund(Some(BRUCE).into(), 3_000), Error::::ZeroContribution); + assert_noop!( + Salp::refund(Some(BRUCE).into(), 3_000, false), + Error::::ZeroContribution + ); }); } @@ -913,16 +928,16 @@ fn refund_with_zero_contribution_should_fail() { fn refund_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_noop!(Salp::refund(Origin::root(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::refund(Origin::none(), 3_000), DispatchError::BadOrigin); + assert_noop!(Salp::refund(Origin::root(), 3_000, false), DispatchError::BadOrigin); + assert_noop!(Salp::refund(Origin::none(), 3_000, false), DispatchError::BadOrigin); - assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); + assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000, false)); assert_noop!( Salp::confirm_refund(Origin::root(), BRUCE, 3_000, true), DispatchError::BadOrigin @@ -943,10 +958,10 @@ fn refund_with_wrong_para_id_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_noop!(Salp::refund(Some(BRUCE).into(), 4_000), Error::::InvalidParaId); + assert_noop!(Salp::refund(Some(BRUCE).into(), 4_000, false), Error::::InvalidParaId); }); } @@ -955,19 +970,25 @@ fn refund_with_wrong_fund_status_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_ok!(Salp::fund_end(Some(ALICE).into(), 3_000)); - assert_noop!(Salp::refund(Some(BRUCE).into(), 3_000), Error::::InvalidFundStatus); + assert_noop!( + Salp::refund(Some(BRUCE).into(), 3_000, false), + Error::::InvalidFundStatus + ); assert_ok!(Salp::create(Some(ALICE).into(), 4_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 4_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 4_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 4_000, true)); - assert_noop!(Salp::refund(Some(BRUCE).into(), 4_000), Error::::InvalidFundStatus); + assert_noop!( + Salp::refund(Some(BRUCE).into(), 4_000, false), + Error::::InvalidFundStatus + ); }); } @@ -985,12 +1006,12 @@ fn dissolve_should_work() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 10_000, 1, SlotLength::get())); for i in 0..contribute_account_num { let ract = AccountId::new([(i as u8); 32]); - assert_ok!(Salp::contribute(Some(ract.clone()).into(), 3_000, 10)); + assert_ok!(Salp::contribute(Some(ract.clone()).into(), 3_000, 10, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), ract, 3_000, true)); } assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_ok!(Salp::fund_end(Some(ALICE).into(), 3_000)); @@ -1011,13 +1032,12 @@ fn dissolve_with_wrong_origin_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_ok!(Salp::fund_end(Some(ALICE).into(), 3_000)); assert_noop!(Salp::dissolve(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::dissolve(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::dissolve(Some(BRUCE).into(), 3_000), Error::::UnauthorizedAccount); }); } @@ -1027,7 +1047,7 @@ fn dissolve_with_wrong_para_id_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_ok!(Salp::fund_end(Some(ALICE).into(), 3_000)); @@ -1041,7 +1061,7 @@ fn dissolve_with_wrong_fund_status_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_noop!(Salp::dissolve(Some(ALICE).into(), 3_000), Error::::InvalidFundStatus); @@ -1052,7 +1072,7 @@ fn dissolve_with_wrong_fund_status_should_fail() { fn redeem_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1062,7 +1082,7 @@ fn redeem_should_work() { System::set_block_number(block_begin_redeem); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); #[allow(non_snake_case)] @@ -1071,15 +1091,8 @@ fn redeem_should_work() { assert_ok!(>::transfer(vsToken, &BRUCE, &CATHI, 50)); assert_ok!(>::transfer(vsBond, &BRUCE, &CATHI, 50)); - assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50)); - assert_ok!(Salp::confirm_redeem( - Some(ALICE).into(), - BRUCE, - 3_000, - 1, - SlotLength::get(), - true - )); + assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 50, false)); + assert_ok!(Salp::confirm_redeem(Some(ALICE).into(), BRUCE, 3_000, true)); assert_eq!(Salp::redeem_pool(), 50); @@ -1090,15 +1103,8 @@ fn redeem_should_work() { assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); - assert_ok!(Salp::redeem(Some(CATHI).into(), 3_000, 1, SlotLength::get(), 50)); - assert_ok!(Salp::confirm_redeem( - Some(ALICE).into(), - CATHI, - 3_000, - 1, - SlotLength::get(), - true - )); + assert_ok!(Salp::redeem(Some(CATHI).into(), 3_000, 50, false)); + assert_ok!(Salp::confirm_redeem(Some(ALICE).into(), CATHI, 3_000, true)); assert_eq!(Salp::redeem_pool(), 0); @@ -1115,7 +1121,7 @@ fn redeem_should_work() { fn redeem_when_xcm_error_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1125,21 +1131,14 @@ fn redeem_when_xcm_error_should_work() { System::set_block_number(block_begin_redeem); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); #[allow(non_snake_case)] let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50)); - assert_ok!(Salp::confirm_redeem( - Some(ALICE).into(), - BRUCE, - 3_000, - 1, - SlotLength::get(), - false - )); + assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 50, false)); + assert_ok!(Salp::confirm_redeem(Some(ALICE).into(), BRUCE, 3_000, false)); assert_eq!(Salp::redeem_pool(), 100); @@ -1156,7 +1155,7 @@ fn redeem_when_xcm_error_should_work() { fn redeem_when_redeeming_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1166,11 +1165,11 @@ fn redeem_when_redeeming_should_fail() { System::set_block_number(block_begin_redeem); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50)); + assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 50, false)); - let result = Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50); + let result = Salp::redeem(Some(BRUCE).into(), 3_000, 50, false); assert_noop!(result, Error::::InvalidRedeemStatus); }); } @@ -1179,7 +1178,7 @@ fn redeem_when_redeeming_should_fail() { fn confirm_redeem_when_not_in_redeeming_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1189,11 +1188,11 @@ fn confirm_redeem_when_not_in_redeeming_should_fail() { System::set_block_number(block_begin_redeem); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_noop!( - Salp::confirm_redeem(Some(ALICE).into(), BRUCE, 3_000, 1, SlotLength::get(), true), + Salp::confirm_redeem(Some(ALICE).into(), BRUCE, 3_000, true), Error::::InvalidRedeemStatus ); }); @@ -1203,7 +1202,7 @@ fn confirm_redeem_when_not_in_redeeming_should_fail() { fn redeem_with_wrong_origin_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1213,20 +1212,14 @@ fn redeem_with_wrong_origin_should_fail() { System::set_block_number(block_begin_redeem); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); - assert_noop!( - Salp::redeem(Origin::root(), 3_000, 1, SlotLength::get(), 50), - DispatchError::BadOrigin - ); - assert_noop!( - Salp::redeem(Origin::none(), 3_000, 1, SlotLength::get(), 50), - DispatchError::BadOrigin - ); + assert_noop!(Salp::redeem(Origin::root(), 3_000, 50, false), DispatchError::BadOrigin); + assert_noop!(Salp::redeem(Origin::none(), 3_000, 50, false), DispatchError::BadOrigin); assert_noop!( - Salp::confirm_redeem(Origin::none(), BRUCE, 3_000, 1, SlotLength::get(), true), + Salp::confirm_redeem(Origin::none(), BRUCE, 3_000, true), DispatchError::BadOrigin ); }); @@ -1236,7 +1229,7 @@ fn redeem_with_wrong_origin_should_fail() { fn redeem_with_expired_vsbond_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1247,7 +1240,7 @@ fn redeem_with_expired_vsbond_should_fail() { System::set_block_number(block_end_redeem); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); #[allow(non_snake_case)] @@ -1257,12 +1250,12 @@ fn redeem_with_expired_vsbond_should_fail() { assert_ok!(>::transfer(vsBond, &BRUCE, &CATHI, 50)); assert_noop!( - Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50), + Salp::redeem(Some(BRUCE).into(), 3_000, 50, false), Error::::VSBondExpired ); assert_noop!( - Salp::redeem(Some(CATHI).into(), 3_000, 1, SlotLength::get(), 50), + Salp::redeem(Some(CATHI).into(), 3_000, 50, false), Error::::VSBondExpired ); }); @@ -1275,7 +1268,7 @@ fn redeem_with_not_redeemable_vsbond_should_fail() { crate::pallet::RedeemPool::::set(100); assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1291,13 +1284,13 @@ fn redeem_with_not_redeemable_vsbond_should_fail() { assert_ok!(>::transfer(vsBond, &BRUCE, &CATHI, 50)); assert_noop!( - Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50), - Error::::UnRedeemableNow + Salp::redeem(Some(BRUCE).into(), 3_000, 50, false), + Error::::InvalidFundStatus ); assert_noop!( - Salp::redeem(Some(CATHI).into(), 3_000, 1, SlotLength::get(), 50), - Error::::UnRedeemableNow + Salp::redeem(Some(CATHI).into(), 3_000, 50, false), + Error::::InvalidFundStatus ); }); } @@ -1306,7 +1299,7 @@ fn redeem_with_not_redeemable_vsbond_should_fail() { fn redeem_without_enough_vsassets_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1316,7 +1309,7 @@ fn redeem_without_enough_vsassets_should_fail() { System::set_block_number(block_begin_redeem); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); #[allow(non_snake_case)] @@ -1326,12 +1319,12 @@ fn redeem_without_enough_vsassets_should_fail() { assert_ok!(>::transfer(vsBond, &BRUCE, &CATHI, 50)); assert_noop!( - Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 60), + Salp::redeem(Some(BRUCE).into(), 3_000, 60, false), Error::::NotEnoughFreeAssetsToRedeem ); assert_noop!( - Salp::redeem(Some(CATHI).into(), 3_000, 1, SlotLength::get(), 60), + Salp::redeem(Some(CATHI).into(), 3_000, 60, false), Error::::NotEnoughFreeAssetsToRedeem ); }); @@ -1341,7 +1334,7 @@ fn redeem_without_enough_vsassets_should_fail() { fn redeem_without_enough_balance_in_pool_should_fail() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -1354,11 +1347,11 @@ fn redeem_without_enough_balance_in_pool_should_fail() { // Before withdraw assert_noop!( - Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50), - Error::::NotEnoughBalanceInRedeemPool + Salp::redeem(Some(BRUCE).into(), 3_000, 50, false), + Error::::InvalidFundStatus ); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); }); } @@ -1383,12 +1376,12 @@ fn release_from_redeem_to_bancor_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100)); + assert_ok!(Salp::contribute(Some(BRUCE).into(), 3_000, 100, false)); assert_ok!(Salp::confirm_contribute(Some(ALICE).into(), BRUCE, 3_000, true)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); + assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000, false)); assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); run_to_block(ReleaseCycle::get()); diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 5f19e28108..aadfea9b02 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -967,8 +967,10 @@ parameter_types! { pub const SlotLength: BlockNumber = 8u32 as BlockNumber; pub const XcmTransferOrigin: TransferOriginType = TransferOriginType::FromRelayChain; pub XcmWeight: XcmBaseWeight = XCM_WEIGHT.into(); - pub ContributionWeight:u64 = XCM_WEIGHT.into(); - pub WithdrawWeight:u64 = XCM_WEIGHT.into(); + pub ContributionWeight:XcmBaseWeight = XCM_WEIGHT.into(); + pub WithdrawWeight:XcmBaseWeight = XCM_WEIGHT.into(); + pub AddProxyWeight:XcmBaseWeight = XCM_WEIGHT.into(); + pub RemoveProxyWeight:XcmBaseWeight = XCM_WEIGHT.into(); pub ConfirmMuitiSigAccount: AccountId = Multisig::multi_account_id(&vec![ hex!["20b8de78cf83088dd5d8f1e05aeb7122635e5f00015e4cf03e961fe8cc7b9935"].into(), hex!["0c5192dccfcab3a676d74d3aab838f4d1e6b4f490cf15703424c382c6a72401d"].into(), @@ -1026,6 +1028,8 @@ impl bifrost_salp::Config for Runtime { type EnsureConfirmAsMultiSig = EnsureOneOf; type WeightToFee = WeightToFee; + type AddProxyWeight = AddProxyWeight; + type RemoveProxyWeight = RemoveProxyWeight; } parameter_types! { diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index d7de0c2e6b..4cc1d1d127 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -942,8 +942,10 @@ parameter_types! { pub const SlotLength: BlockNumber = 8u32 as BlockNumber; pub const XcmTransferOrigin: TransferOriginType = TransferOriginType::FromRelayChain; pub XcmWeight: XcmBaseWeight = XCM_WEIGHT.into(); - pub ContributionWeight:u64 = XCM_WEIGHT.into(); - pub WithdrawWeight:u64 = XCM_WEIGHT.into(); + pub ContributionWeight:XcmBaseWeight = XCM_WEIGHT.into(); + pub WithdrawWeight:XcmBaseWeight = XCM_WEIGHT.into(); + pub AddProxyWeight:XcmBaseWeight = XCM_WEIGHT.into(); + pub RemoveProxyWeight:XcmBaseWeight = XCM_WEIGHT.into(); pub ConfirmMuitiSigAccount: AccountId = hex![ "ce6072037670ca8e974fd571eae4f215a58d0bf823b998f619c3f87a911c3541" ] @@ -997,6 +999,8 @@ impl bifrost_salp::Config for Runtime { type BaseXcmWeight = XcmWeight; type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig; type WeightToFee = WeightToFee; + type AddProxyWeight = AddProxyWeight; + type RemoveProxyWeight = RemoveProxyWeight; } parameter_types! { diff --git a/xcm-support/src/calls.rs b/xcm-support/src/calls.rs new file mode 100644 index 0000000000..19b00cb060 --- /dev/null +++ b/xcm-support/src/calls.rs @@ -0,0 +1,109 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use codec::{Decode, Encode}; +use node_primitives::ParaId; +use sp_runtime::MultiSignature; + +#[derive(Encode, Decode)] +pub enum CrowdloanContributeCall { + #[codec(index = 73)] + CrowdloanContribute(ContributeCall), +} + +#[derive(Encode, Decode)] +pub enum CrowdloanWithdrawCall { + #[codec(index = 73)] + CrowdloanWithdraw(WithdrawCall), +} + +#[derive(Debug, PartialEq, Encode, Decode)] +pub struct Contribution { + #[codec(compact)] + pub index: ParaId, + #[codec(compact)] + pub value: BalanceOf, + pub signature: Option, +} + +#[derive(Encode, Decode)] +pub enum ContributeCall { + #[codec(index = 1)] + Contribute(Contribution), +} + +#[derive(Debug, PartialEq, Encode, Decode)] +pub struct Withdraw { + pub who: AccountIdOf, + #[codec(compact)] + pub index: ParaId, +} + +#[derive(Encode, Decode)] +pub enum WithdrawCall { + #[codec(index = 2)] + Withdraw(Withdraw), +} + +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug)] +pub enum ProxyType { + Any, + NonTransfer, + Governance, + Staking, + IdentityJudgement, + CancelProxy, +} + +#[derive(Encode, Decode)] +pub enum ProxyAddCall { + #[codec(index = 30)] + ProxyAdd(AddProxyCall), +} + +#[derive(Encode, Decode)] +pub enum AddProxyCall { + #[codec(index = 1)] + Add(AddProxy), +} + +#[derive(Debug, PartialEq, Encode, Decode)] +pub struct AddProxy { + pub delegate: AccountIdOf, + pub proxy_type: ProxyType, + pub delay: BlockNumberOf, +} + +#[derive(Encode, Decode)] +pub enum ProxyRemoveCall { + #[codec(index = 30)] + ProxyRemove(RemoveProxyCall), +} + +#[derive(Encode, Decode)] +pub enum RemoveProxyCall { + #[codec(index = 1)] + Remove(RemoveProxy), +} + +#[derive(Debug, PartialEq, Encode, Decode)] +pub struct RemoveProxy { + pub delegate: AccountIdOf, + pub proxy_type: ProxyType, + pub delay: BlockNumberOf, +} diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index d630ad63f7..83774418a9 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -38,7 +38,7 @@ use sp_std::{ prelude::*, vec, }; -pub use xcm::{v0::prelude::*, VersionedXcm}; +pub use xcm::VersionedXcm; use xcm::{ v0::{ Error as XcmError, Junction, MultiAsset, MultiLocation, OriginKind, Result as XcmResult, @@ -48,10 +48,17 @@ use xcm::{ }; use xcm_executor::traits::{Convert as xcmConvert, MatchesFungible, TransactAsset}; pub use xcm_executor::XcmExecutor; +mod calls; mod traits; +pub use calls::*; use frame_support::weights::WeightToFeePolynomial; pub use node_primitives::XcmBaseWeight; pub use traits::{BifrostXcmExecutor, HandleDmpMessage, HandleUmpMessage, HandleXcmpMessage}; +#[allow(unused_imports)] +use xcm::v0::{ + prelude::{Parachain, Parent, X1, X2}, + Order, +}; #[cfg(test)] mod mock; @@ -213,7 +220,7 @@ impl< halt_on_error: false, xcm: vec![], }, - DepositAsset { assets: vec![All], dest }, + Order::DepositAsset { assets: vec![MultiAsset::All], dest }, ], };