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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pallets/salp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-f
[dev-dependencies]
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" }
pallet-multisig = { version = "3.0.0"}
sp-io = "3.0.0"
sp-core = "3.0.0"
orml-tokens = "0.4.1-dev"
Expand Down
41 changes: 14 additions & 27 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ pub mod pallet {
Success = MultiLocation,
>;

type EnsureConfirmAsMultiSig: EnsureOrigin<<Self as frame_system::Config>::Origin>;

type BifrostXcmExecutor: BifrostXcmExecutor;

#[pallet::constant]
Expand Down Expand Up @@ -335,9 +337,9 @@ pub mod pallet {
/// Withdrawing full balance of a contributor. [who, fund_index, amount]
Withdrawing(AccountIdOf<T>, ParaId, BalanceOf<T>),
/// Withdrew full balance of a contributor. [who, fund_index, amount]
Withdrew(AccountIdOf<T>, ParaId, BalanceOf<T>),
Withdrew(ParaId, BalanceOf<T>),
/// Fail on withdraw full balance of a contributor. [who, fund_index, amount]
WithdrawFailed(AccountIdOf<T>, ParaId, BalanceOf<T>),
WithdrawFailed(ParaId, BalanceOf<T>),
/// Refunding to account. [who, fund_index, amount]
Refunding(AccountIdOf<T>, ParaId, BalanceOf<T>),
/// Refunded to account. [who, fund_index, amount]
Expand Down Expand Up @@ -453,13 +455,11 @@ pub mod pallet {
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(fund.status == FundStatus::Ongoing, Error::<T>::InvalidFundStatus);

ensure!(owner == fund.depositor, Error::<T>::UnauthorizedAccount);

let fund_new = FundInfo { status: FundStatus::Success, ..fund };
Funds::<T>::insert(index, Some(fund_new));

Expand All @@ -472,14 +472,12 @@ pub mod pallet {
Pays::No
))]
pub fn fund_fail(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
let owner = ensure_signed(origin)?;
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

// crownload is failed, so enable the withdrawal function of vsToken/vsBond
let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(fund.status == FundStatus::Ongoing, Error::<T>::InvalidFundStatus);

ensure!(owner == fund.depositor, Error::<T>::UnauthorizedAccount);

let fund_new = FundInfo { status: FundStatus::Failed, ..fund };
Funds::<T>::insert(index, Some(fund_new));

Expand All @@ -495,13 +493,11 @@ pub mod pallet {
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(fund.status == FundStatus::Success, Error::<T>::InvalidFundStatus);

ensure!(owner == fund.depositor, Error::<T>::UnauthorizedAccount);

let fund_new = FundInfo { status: FundStatus::Retired, ..fund };
Funds::<T>::insert(index, Some(fund_new));

Expand All @@ -514,7 +510,7 @@ pub mod pallet {
Pays::No
))]
pub fn fund_end(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
let owner = ensure_signed(origin)?;
let _owner = T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(
Expand All @@ -523,8 +519,6 @@ pub mod pallet {
Error::<T>::InvalidFundStatus
);

ensure!(owner == fund.depositor, Error::<T>::UnauthorizedAccount);

let fund_new = FundInfo { status: FundStatus::End, ..fund };
Funds::<T>::insert(index, Some(fund_new));

Expand Down Expand Up @@ -574,7 +568,6 @@ pub mod pallet {
Ok(())
}

/// TODO: Refactor the docs.
/// Create a new crowdloaning campaign for a parachain slot deposit for the current auction.
#[pallet::weight((
0,
Expand Down Expand Up @@ -675,16 +668,14 @@ pub mod pallet {
#[pallet::compact] index: ParaId,
is_success: bool,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
let _owner = T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
let can_confirm = fund.status == FundStatus::Ongoing ||
fund.status == FundStatus::Failed ||
fund.status == FundStatus::Success;
ensure!(can_confirm, Error::<T>::InvalidFundStatus);

ensure!(owner == fund.depositor, Error::<T>::UnauthorizedAccount);

let (contributed, status) = Self::contribution(fund.trie_index, &who);
ensure!(status.is_contributing(), Error::<T>::InvalidContributionStatus);
let contributing = status.contributing();
Expand Down Expand Up @@ -768,14 +759,12 @@ pub mod pallet {
#[pallet::compact] index: ParaId,
is_success: bool,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
let can = fund.status == FundStatus::Failed || fund.status == FundStatus::Retired;
ensure!(can, Error::<T>::InvalidFundStatus);

ensure!(owner == fund.depositor, Error::<T>::UnauthorizedAccount);

let amount_withdrew = fund.raised;

if is_success {
Expand All @@ -791,9 +780,9 @@ pub mod pallet {
Funds::<T>::insert(index, Some(fund_new));
}

Self::deposit_event(Event::Withdrew(owner, index, amount_withdrew));
Self::deposit_event(Event::Withdrew(index, amount_withdrew));
} else {
Self::deposit_event(Event::WithdrawFailed(owner, index, amount_withdrew));
Self::deposit_event(Event::WithdrawFailed(index, amount_withdrew));
}

Ok(())
Expand Down Expand Up @@ -854,13 +843,11 @@ pub mod pallet {
#[pallet::compact] index: ParaId,
is_success: bool,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(fund.status == FundStatus::RefundWithdrew, Error::<T>::InvalidFundStatus);

ensure!(owner == fund.depositor, Error::<T>::UnauthorizedAccount);

let (contributed, status) = Self::contribution(fund.trie_index, &who);
ensure!(status == ContributionStatus::Refunding, Error::<T>::InvalidContributionStatus);

Expand Down Expand Up @@ -961,7 +948,7 @@ pub mod pallet {
) -> DispatchResult {
use RedeemStatus as RS;

ensure_root(origin).map_err(|_| Error::<T>::UnauthorizedAccount)?;
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let status = Self::redeem_status(who.clone(), (index, first_slot, last_slot));
ensure!(status.is_redeeming(), Error::<T>::InvalidRedeemStatus);
Expand Down
54 changes: 52 additions & 2 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@

// Ensure we're `no_std` when compiling for Wasm.

use frame_support::{construct_runtime, parameter_types, traits::GenesisBuild, PalletId};
use frame_support::{
construct_runtime, parameter_types,
traits::{EnsureOrigin, GenesisBuild},
PalletId,
};
use frame_system::RawOrigin;
use node_primitives::{Amount, Balance, CurrencyId, TokenSymbol, TransferOriginType};
use sp_arithmetic::Percent;
use sp_core::H256;
Expand Down Expand Up @@ -53,6 +58,7 @@ construct_runtime!(
Currencies: orml_currencies::{Pallet, Call, Event<T>},
Tokens: orml_tokens::{Pallet, Call, Storage, Event<T>},
Bancor: bifrost_bancor::{Pallet, Call, Config<T>, Storage, Event<T>},
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>},
Salp: salp::{Pallet, Call, Storage, Event<T>},
}
);
Expand Down Expand Up @@ -118,6 +124,22 @@ impl pallet_balances::Config for Test {
type WeightInfo = pallet_balances::weights::SubstrateWeight<Test>;
}

parameter_types! {
pub const DepositBase: Balance = 0;
pub const DepositFactor: Balance = 0;
pub const MaxSignatories: u16 = 100;
}

impl pallet_multisig::Config for Test {
type Call = Call;
type Currency = Balances;
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type Event = Event;
type MaxSignatories = MaxSignatories;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Test>;
}

orml_traits::parameter_type_with_key! {
pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance {
0
Expand Down Expand Up @@ -165,7 +187,6 @@ parameter_types! {
pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#");
pub const RemoveKeysLimit: u32 = 50;
pub const SlotLength: BlockNumber = 8u32 as BlockNumber;

pub const LeasePeriod: BlockNumber = 6 * WEEKS;
pub const VSBondValidPeriod: BlockNumber = 30 * DAYS;
pub const ReleaseCycle: BlockNumber = 1 * DAYS;
Expand All @@ -176,6 +197,12 @@ parameter_types! {
pub ContributionWeight:u64 = 1_000_000_000 as u64;
pub WithdrawWeight:u64 = 1_000_000_000 as u64;
pub const SelfParaId: u32 = 2001;
pub PrimaryAccount: AccountId = ALICE;
pub ConfirmMuitiSigAccount: AccountId = Multisig::multi_account_id(&vec![
ALICE,
BRUCE,
CATHI
],2);
}

parameter_types! {
Expand All @@ -184,6 +211,28 @@ parameter_types! {

type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, AnyNetwork>,);

pub struct EnsureConfirmAsMultiSig;
impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
type Success = AccountId;

fn try_origin(o: Origin) -> Result<Self::Success, Origin> {
Into::<Result<RawOrigin<AccountId>, Origin>>::into(o).and_then(|o| match o {
RawOrigin::Signed(who) =>
if who == PrimaryAccount::get() || who == ConfirmMuitiSigAccount::get() {
Ok(who)
} else {
Err(Origin::from(Some(who)))
},
r => Err(Origin::from(r)),
})
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> Origin {
Origin::from(RawOrigin::Signed(ConfirmMuitiSigAccount::get()))
}
}

impl salp::Config for Test {
type BancorPool = Bancor;
type BifrostXcmExecutor = MockXcmExecutor;
Expand All @@ -207,6 +256,7 @@ impl salp::Config for Test {
type BaseXcmWeight = BaseXcmWeight;
type ContributionWeight = ContributionWeight;
type WithdrawWeight = WithdrawWeight;
type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig;
}

// To control the result returned by `MockXcmExecutor`
Expand Down
Loading