diff --git a/node/primitives/src/salp.rs b/node/primitives/src/salp.rs index 01d94a397d..97cb5dd9ca 100644 --- a/node/primitives/src/salp.rs +++ b/node/primitives/src/salp.rs @@ -75,3 +75,5 @@ impl Default for ContributionStatus { Self::Idle } } + +pub type MessageId = [u8; 32]; diff --git a/node/primitives/src/xcm.rs b/node/primitives/src/xcm.rs index 7484a03229..668e1de394 100644 --- a/node/primitives/src/xcm.rs +++ b/node/primitives/src/xcm.rs @@ -85,6 +85,3 @@ pub enum ParachainDerivedProxyAccountType { Salp = 0, Staking = 1, } - -/// Xcm Message Id -pub type MessageId = [u8; 32]; diff --git a/pallets/salp-lite/src/lib.rs b/pallets/salp-lite/src/lib.rs index 075db9ce7a..bea036c0e4 100644 --- a/pallets/salp-lite/src/lib.rs +++ b/pallets/salp-lite/src/lib.rs @@ -98,7 +98,7 @@ pub mod pallet { PalletId, }; use frame_system::pallet_prelude::*; - use node_primitives::{BancorHandler, CurrencyId, LeasePeriod, ParaId}; + use node_primitives::{BancorHandler, CurrencyId, LeasePeriod, MessageId, ParaId}; use orml_traits::{currency::TransferAll, MultiCurrency, MultiReservableCurrency}; use sp_arithmetic::Percent; use sp_std::prelude::*; @@ -164,7 +164,7 @@ pub mod pallet { /// Create a new crowdloaning campaign. [fund_index] Created(ParaId), /// Contributed to a crowd sale. [who, fund_index, amount] - Contributed(AccountIdOf, ParaId, BalanceOf), + Issued(AccountIdOf, ParaId, BalanceOf, MessageId), /// Withdrew full balance of a contributor. [who, fund_index, amount] Withdrew(ParaId, BalanceOf), /// refund to account. [who, fund_index,value] @@ -596,6 +596,7 @@ pub mod pallet { who: AccountIdOf, #[pallet::compact] index: ParaId, #[pallet::compact] value: BalanceOf, + message_id: MessageId, ) -> DispatchResult { T::EnsureConfirmAsMultiSig::ensure_origin(origin.clone())?; @@ -633,7 +634,7 @@ pub mod pallet { contributed_new, ContributionStatus::Idle, ); - Self::deposit_event(Event::Contributed(who, index, value)); + Self::deposit_event(Event::Issued(who, index, value, message_id)); Ok(()) } diff --git a/pallets/salp-lite/src/mock.rs b/pallets/salp-lite/src/mock.rs index 59fcac7f49..8d389b481f 100644 --- a/pallets/salp-lite/src/mock.rs +++ b/pallets/salp-lite/src/mock.rs @@ -24,7 +24,7 @@ use frame_support::{ PalletId, }; use frame_system::RawOrigin; -use node_primitives::{Amount, Balance, CurrencyId, TokenSymbol}; +use node_primitives::{Amount, Balance, CurrencyId, MessageId, TokenSymbol}; use sp_arithmetic::Percent; use sp_core::H256; use sp_runtime::{ @@ -298,3 +298,5 @@ pub(crate) const BRUCE: AccountId = AccountId::new([1u8; 32]); pub(crate) const CATHI: AccountId = AccountId::new([2u8; 32]); pub(crate) const INIT_BALANCE: Balance = 100_000; + +pub(crate) const CONTRIBUTON_INDEX: MessageId = [0; 32]; diff --git a/pallets/salp-lite/src/tests.rs b/pallets/salp-lite/src/tests.rs index 2a0d9fcbe1..eb7dfa4b12 100644 --- a/pallets/salp-lite/src/tests.rs +++ b/pallets/salp-lite/src/tests.rs @@ -247,7 +247,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX,)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -267,7 +267,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX,)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); assert_noop!( @@ -281,7 +281,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX,)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -296,7 +296,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); // ABSOLUTELY NOT HAPPEN AT NORMAL PROCESS! @@ -322,7 +322,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); let fund = Salp::funds(3_000).unwrap(); let (contributed, status) = Salp::contribution(fund.trie_index, &BRUCE); @@ -345,8 +345,8 @@ 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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); // Check the contribution let fund = Salp::funds(3_000).unwrap(); @@ -370,7 +370,7 @@ fn double_contribute_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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); let fund = Salp::funds(3_000).unwrap(); @@ -395,7 +395,13 @@ 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::issue(Some(ALICE).into(), BRUCE, 3_000, MinContribution::get() - 1), + Salp::issue( + Some(ALICE).into(), + BRUCE, + 3_000, + MinContribution::get() - 1, + CONTRIBUTON_INDEX + ), Error::::ContributionTooSmall ); }); @@ -406,7 +412,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::issue(Some(ALICE).into(), BRUCE, 4_000, 100), + Salp::issue(Some(ALICE).into(), BRUCE, 4_000, 100, CONTRIBUTON_INDEX), Error::::InvalidParaId ); }); @@ -418,7 +424,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100), + Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX), Error::::InvalidFundStatus ); }); @@ -429,7 +435,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::issue(Some(ALICE).into(), BRUCE, 3_000, 1_001), + Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 1_001, CONTRIBUTON_INDEX), Error::::CapExceeded ); }); @@ -444,7 +450,7 @@ 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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); 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)); @@ -453,7 +459,7 @@ fn withdraw_should_work() { assert_eq!(fund.status, FundStatus::RedeemWithdrew); assert_ok!(Salp::create(Some(ALICE).into(), 4_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 4_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 4_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 4_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); @@ -466,7 +472,7 @@ fn withdraw_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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); 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)); @@ -476,7 +482,7 @@ fn double_withdraw_same_fund_should_fail() { assert_eq!(fund.status, FundStatus::RedeemWithdrew); assert_ok!(Salp::create(Some(ALICE).into(), 4_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 4_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 4_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 4_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 4_000)); assert_noop!(Salp::withdraw(Some(ALICE).into(), 4_000), Error::::InvalidFundStatus); @@ -527,7 +533,7 @@ 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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); assert_ok!(Salp::refund(Some(BRUCE).into(), 3_000)); @@ -552,7 +558,7 @@ fn refund_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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); @@ -583,7 +589,7 @@ 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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); @@ -639,7 +645,7 @@ fn dissolve_should_work() { for i in 0..contribute_account_num { let ract = AccountId::new([(i as u8); 32]); assert_ok!(Tokens::deposit(RelayCurrencyId::get(), &ract, 10)); - assert_ok!(Salp::issue(Some(ALICE).into(), ract.clone(), 3_000, 10)); + assert_ok!(Salp::issue(Some(ALICE).into(), ract.clone(), 3_000, 10, CONTRIBUTON_INDEX)); } assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); @@ -697,7 +703,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -739,7 +745,7 @@ fn redeem_should_work() { fn redeem_with_speical_vsbond_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 2001, 1_000, 13, 20)); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 2001, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 2001, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 2001)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 2001)); @@ -781,7 +787,7 @@ fn redeem_with_speical_vsbond_should_work() { 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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -801,7 +807,7 @@ fn redeem_with_wrong_origin_should_fail() { fn redeem_with_not_redeemable_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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -825,7 +831,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -858,7 +864,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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); @@ -897,7 +903,7 @@ 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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); 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)); @@ -924,7 +930,7 @@ fn check_next_trie_index() { fn batch_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::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_ok!(Salp::batch_unlock(Some(ALICE).into(), 3_000)); }) @@ -934,7 +940,7 @@ fn batch_unlock_should_work() { fn batch_migrate_should_work() { new_test_ext().execute_with(|| { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100)); + assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); assert_ok!(Salp::edit( diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 15d937732d..e8829c5243 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -1205,9 +1205,9 @@ parameter_types! { pub ContributionWeight:XcmBaseWeight = XCM_WEIGHT.into(); pub AddProxyWeight:XcmBaseWeight = XCM_WEIGHT.into(); pub ConfirmMuitiSigAccount: AccountId = Multisig::multi_account_id(&vec![ - hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"].into(), // alice hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"].into(), // bob hex!["90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22"].into(), // charlie + hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"].into(), // alice ],2); pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16); pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;