Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions node/primitives/src/salp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ impl<BalanceOf> Default for ContributionStatus<BalanceOf> {
Self::Idle
}
}

pub type MessageId = [u8; 32];
3 changes: 0 additions & 3 deletions node/primitives/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,3 @@ pub enum ParachainDerivedProxyAccountType {
Salp = 0,
Staking = 1,
}

/// Xcm Message Id
pub type MessageId = [u8; 32];
7 changes: 4 additions & 3 deletions pallets/salp-lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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<T>, ParaId, BalanceOf<T>),
Issued(AccountIdOf<T>, ParaId, BalanceOf<T>, MessageId),
/// Withdrew full balance of a contributor. [who, fund_index, amount]
Withdrew(ParaId, BalanceOf<T>),
/// refund to account. [who, fund_index,value]
Expand Down Expand Up @@ -596,6 +596,7 @@ pub mod pallet {
who: AccountIdOf<T>,
#[pallet::compact] index: ParaId,
#[pallet::compact] value: BalanceOf<T>,
message_id: MessageId,
) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin.clone())?;

Expand Down Expand Up @@ -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(())
}
Expand Down
4 changes: 3 additions & 1 deletion pallets/salp-lite/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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];
64 changes: 35 additions & 29 deletions pallets/salp-lite/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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!(
Expand All @@ -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));

Expand All @@ -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!
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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::<Test>::ContributionTooSmall
);
});
Expand All @@ -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::<Test>::InvalidParaId
);
});
Expand All @@ -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::<Test>::InvalidFundStatus
);
});
Expand All @@ -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::<Test>::CapExceeded
);
});
Expand All @@ -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));
Expand All @@ -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));

Expand All @@ -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));
Expand All @@ -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::<Test>::InvalidFundStatus);
Expand Down Expand Up @@ -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));
Expand All @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));

Expand All @@ -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));

Expand All @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));
Expand All @@ -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));
})
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down