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
43 changes: 4 additions & 39 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ impl Default for FundStatus {
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
#[codec(dumb_trait_bound)]
pub struct FundInfo<Balance, LeasePeriod> {
/// The amount of deposit placed.
deposit: Balance,
/// The total amount raised.
raised: Balance,
/// A hard-cap on the amount that may be contributed.
Expand All @@ -98,18 +96,11 @@ pub struct FundInfo<Balance, LeasePeriod> {
status: FundStatus,
}

#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
#[codec(dumb_trait_bound)]
pub struct ContributionMemoInfo {
index: TrieIndex,
}

#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, Copy)]
pub enum ContributionStatus<BalanceOf> {
Idle,
Refunded,
Unlocked,
Refunding,
Contributing(BalanceOf),
}

Expand Down Expand Up @@ -146,7 +137,6 @@ pub mod pallet {
pallet_prelude::{storage::child, *},
sp_runtime::traits::{AccountIdConversion, CheckedAdd, Hash, Saturating, Zero},
storage::ChildTriePrefixIterator,
weights::WeightToFeePolynomial,
PalletId,
};
use frame_system::pallet_prelude::*;
Expand All @@ -171,9 +161,6 @@ pub mod pallet {
#[pallet::constant]
type PalletId: Get<PalletId>;

/// The amount to be held on deposit by the depositor of a crowdloan.
type SubmissionDeposit: Get<BalanceOf<Self>>;

/// The minimum amount that may be contributed into a crowdloan. Should almost certainly be
/// at least ExistentialDeposit.
#[pallet::constant]
Expand All @@ -182,9 +169,6 @@ pub mod pallet {
#[pallet::constant]
type RelayChainToken: Get<CurrencyId>;

#[pallet::constant]
type DepositToken: Get<CurrencyId>;

/// The number of blocks over which a single period lasts.
#[pallet::constant]
type LeasePeriod: Get<BlockNumberFor<Self>>;
Expand Down Expand Up @@ -214,11 +198,6 @@ pub mod pallet {

type BancorPool: BancorHandler<BalanceOf<Self>>;

type ExecuteXcmOrigin: EnsureOrigin<
<Self as frame_system::Config>::Origin,
Success = MultiLocation,
>;

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

type BifrostXcmExecutor: BifrostXcmExecutor;
Expand All @@ -232,25 +211,16 @@ pub mod pallet {
/// Parachain Id
type SelfParaId: Get<u32>;

/// Weight to Fee calculator
type WeightToFee: WeightToFeePolynomial<Balance = BalanceOf<Self>>;

/// Xcm weight
#[pallet::constant]
type BaseXcmWeight: Get<u64>;

#[pallet::constant]
type ContributionWeight: Get<u64>;

#[pallet::constant]
type WithdrawWeight: Get<u64>;

#[pallet::constant]
type AddProxyWeight: Get<u64>;

#[pallet::constant]
type RemoveProxyWeight: Get<u64>;

/// The interface to Cross-chain transfer.
type XcmTransfer: XcmTransfer<AccountIdOf<Self>, BalanceOf<Self>, CurrencyId>;

Expand Down Expand Up @@ -320,8 +290,6 @@ pub mod pallet {
InvalidContributionStatus,
/// Contributions exceed maximum amount.
CapExceeded,
/// The origin of this call is invalid.
UnauthorizedAccount,
/// The fund has been registered.
FundAlreadyCreated,
/// Crosschain xcm failed
Expand All @@ -338,12 +306,8 @@ pub mod pallet {
UnRedeemableNow,
/// Dont have enough vsToken/vsBond to redeem
NotEnoughFreeAssetsToRedeem,
/// Dont have enough vsToken/vsBond to unlock when redeem failed
NotEnoughReservedAssetsToUnlockWhenRedeemFailed,
/// Don't have enough token to redeem by users
NotEnoughBalanceInRedeemPool,
/// Invalid redeem status
InvalidRedeemStatus,
}

/// Tracker for the next available fund index
Expand Down Expand Up @@ -462,6 +426,7 @@ pub mod pallet {

/// Unlock the reserved vsToken/vsBond after fund success
#[pallet::weight(T::WeightInfo::unlock())]
#[transactional]
pub fn unlock(
_origin: OriginFor<T>,
who: AccountIdOf<T>,
Expand Down Expand Up @@ -505,6 +470,7 @@ pub mod pallet {
DispatchClass::Normal,
Pays::No
))]
#[transactional]
pub fn batch_unlock(
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
Expand Down Expand Up @@ -580,12 +546,9 @@ pub mod pallet {
.ok_or(Error::<T>::FirstSlotTooFarInFuture)?;
ensure!(last_slot <= last_slot_limit, Error::<T>::LastSlotTooFarInFuture);

let deposit = T::SubmissionDeposit::get();

Funds::<T>::insert(
index,
Some(FundInfo {
deposit,
raised: Zero::zero(),
cap,
first_slot,
Expand Down Expand Up @@ -658,6 +621,7 @@ pub mod pallet {
DispatchClass::Normal,
Pays::No
))]
#[transactional]
pub fn confirm_contribute(
origin: OriginFor<T>,
who: AccountIdOf<T>,
Expand Down Expand Up @@ -875,6 +839,7 @@ pub mod pallet {
DispatchClass::Normal,
Pays::No
))]
#[transactional]
pub fn dissolve(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

Expand Down
13 changes: 0 additions & 13 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use xcm::{
v0::{MultiLocation, NetworkId},
DoubleEncoded,
};
use xcm_builder::{EnsureXcmOrigin, SignedToAccountId32};
use xcm_support::{BifrostXcmExecutor, Weight};

use crate as salp;
Expand Down Expand Up @@ -194,7 +193,6 @@ pub fn create_x2_parachain_multilocation(_index: u16) -> MultiLocation {
}

parameter_types! {
pub const SubmissionDeposit: u32 = 1;
pub const MinContribution: Balance = 10;
pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#");
pub const RemoveKeysLimit: u32 = 50;
Expand All @@ -203,13 +201,10 @@ parameter_types! {
pub const VSBondValidPeriod: BlockNumber = 30 * DAYS;
pub const ReleaseCycle: BlockNumber = 1 * DAYS;
pub const ReleaseRatio: Percent = Percent::from_percent(50);
pub const DepositTokenType: CurrencyId = CurrencyId::Token(TokenSymbol::ASG);
pub const XcmTransferOrigin: TransferOriginType = TransferOriginType::FromRelayChain;
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![
Expand All @@ -226,8 +221,6 @@ parameter_types! {
pub const AnyNetwork: NetworkId = NetworkId::Any;
}

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

pub struct EnsureConfirmAsMultiSig;
impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
type Success = AccountId;
Expand Down Expand Up @@ -298,9 +291,7 @@ impl XcmTransfer<AccountId, Balance, CurrencyId> for MockXTokens {
impl salp::Config for Test {
type BancorPool = Bancor;
type BifrostXcmExecutor = MockXcmExecutor;
type DepositToken = NativeCurrencyId;
type Event = Event;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type LeasePeriod = LeasePeriod;
type MinContribution = MinContribution;
type MultiCurrency = Tokens;
Expand All @@ -310,18 +301,14 @@ impl salp::Config for Test {
type ReleaseRatio = ReleaseRatio;
type RemoveKeysLimit = RemoveKeysLimit;
type SlotLength = SlotLength;
type SubmissionDeposit = SubmissionDeposit;
type VSBondValidPeriod = VSBondValidPeriod;
type XcmTransferOrigin = XcmTransferOrigin;
type WeightInfo = SalpWeightInfo;
type SelfParaId = SelfParaId;
type BaseXcmWeight = BaseXcmWeight;
type ContributionWeight = ContributionWeight;
type WithdrawWeight = WithdrawWeight;
type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig;
type WeightToFee = WeightToFee;
type AddProxyWeight = AddProxyWeight;
type RemoveProxyWeight = RemoveProxyWeight;
type XcmTransfer = MockXTokens;
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
type TransactProxyType = SalpTransactProxyType;
Expand Down
11 changes: 1 addition & 10 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ use xcm_builder::{
EnsureXcmOrigin, FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, LocationInverter,
ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, UsingComponents,
SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
};
use xcm_executor::{Config, XcmExecutor};
use xcm_support::{BifrostCurrencyAdapter, BifrostXcmAdaptor};
Expand Down Expand Up @@ -1011,7 +1011,6 @@ impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
}

parameter_types! {
pub const SubmissionDeposit: Balance = 100 * DOLLARS;
pub const MinContribution: Balance = 1 * DOLLARS;
pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#");
pub const RemoveKeysLimit: u32 = 500;
Expand All @@ -1023,9 +1022,7 @@ parameter_types! {
pub const XcmTransferOrigin: TransferOriginType = TransferOriginType::FromRelayChain;
pub XcmWeight: XcmBaseWeight = 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!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"].into(), // alice
hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"].into(), // bob
Expand All @@ -1038,11 +1035,8 @@ parameter_types! {

impl bifrost_salp::Config for Runtime {
type BancorPool = Bancor;
type WeightToFee = IdentityFee<Balance>;
type BifrostXcmExecutor = BifrostXcmAdaptor<XcmRouter, XcmWeight, IdentityFee<Balance>>;
type DepositToken = NativeCurrencyId;
type Event = Event;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type LeasePeriod = LeasePeriod;
type MinContribution = MinContribution;
type MultiCurrency = Currencies;
Expand All @@ -1052,18 +1046,15 @@ impl bifrost_salp::Config for Runtime {
type ReleaseRatio = ReleaseRatio;
type RemoveKeysLimit = RemoveKeysLimit;
type SlotLength = SlotLength;
type SubmissionDeposit = SubmissionDeposit;
type VSBondValidPeriod = VSBondValidPeriod;
type XcmTransferOrigin = XcmTransferOrigin;
type WeightInfo = weights::bifrost_salp::WeightInfo<Runtime>;
type SelfParaId = SelfParaId;
type ContributionWeight = ContributionWeight;
type WithdrawWeight = WithdrawWeight;
type BaseXcmWeight = XcmWeight;
type EnsureConfirmAsMultiSig =
EnsureOneOf<AccountId, MoreThanHalfCouncil, EnsureConfirmAsMultiSig>;
type AddProxyWeight = AddProxyWeight;
type RemoveProxyWeight = RemoveProxyWeight;
type XcmTransfer = XTokens;
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
type TransactProxyType = SalpProxyType;
Expand Down
20 changes: 6 additions & 14 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ use frame_support::{
use frame_system::{EnsureOneOf, EnsureRoot, RawOrigin};
use hex_literal::hex;
use node_primitives::{
Amount, CurrencyId, Moment, Nonce, ParaId, ParachainDerivedProxyAccountType,
Amount, CurrencyId, Moment, Nonce, ParachainDerivedProxyAccountType,
ParachainTransactProxyType, ParachainTransactType, TokenSymbol, TransferOriginType,
XcmBaseWeight,
};
Expand All @@ -99,7 +99,7 @@ use xcm_builder::{
EnsureXcmOrigin, FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, LocationInverter,
ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, UsingComponents,
SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
};
use xcm_executor::{Config, XcmExecutor};
use xcm_support::{BifrostCurrencyAdapter, BifrostXcmAdaptor, Get};
Expand Down Expand Up @@ -192,10 +192,11 @@ parameter_types! {

parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"bf/trsry");
pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#");
}

pub fn get_all_pallet_accounts() -> Vec<AccountId> {
vec![TreasuryPalletId::get().into_account()]
vec![TreasuryPalletId::get().into_account(), BifrostCrowdloanId::get().into_account()]
}

impl frame_system::Config for Runtime {
Expand All @@ -211,7 +212,7 @@ impl frame_system::Config for Runtime {
type BlockWeights = RuntimeBlockWeights;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
type DbWeight = ();
type DbWeight = RocksDbWeight;
/// The ubiquitous event type.
type Event = Event;
/// The type for hashing blocks and tries.
Expand Down Expand Up @@ -822,6 +823,7 @@ orml_traits::parameter_type_with_key! {
&CurrencyId::Token(TokenSymbol::KSM) => 10 * MILLICENTS,
&CurrencyId::VSToken(TokenSymbol::KSM) => 10 * MILLICENTS,
&CurrencyId::VSBond(TokenSymbol::BNC, ..) => 10 * MILLICENTS,
&CurrencyId::VSBond(TokenSymbol::KSM, ..) => 10 * MILLICENTS,
_ => Balance::max_value() // unsupported
}
};
Expand Down Expand Up @@ -921,9 +923,7 @@ impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
}

parameter_types! {
pub const SubmissionDeposit: Balance = 100 * DOLLARS;
pub const MinContribution: Balance = 1 * DOLLARS;
pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#");
pub const RemoveKeysLimit: u32 = 500;
pub const VSBondValidPeriod: BlockNumber = 30 * DAYS;
pub const ReleaseCycle: BlockNumber = 1 * DAYS;
Expand All @@ -933,9 +933,7 @@ parameter_types! {
pub const XcmTransferOrigin: TransferOriginType = TransferOriginType::FromRelayChain;
pub XcmWeight: XcmBaseWeight = 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!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"].into();
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_parachain_multilocation(ParachainDerivedProxyAccountType::Salp as u16);
pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;
Expand All @@ -944,11 +942,8 @@ parameter_types! {

impl bifrost_salp::Config for Runtime {
type BancorPool = Bancor;
type WeightToFee = IdentityFee<Balance>;
type BifrostXcmExecutor = BifrostXcmAdaptor<XcmRouter, XcmWeight, IdentityFee<Balance>>;
type DepositToken = NativeCurrencyId;
type Event = Event;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type LeasePeriod = LeasePeriod;
type MinContribution = MinContribution;
type MultiCurrency = Currencies;
Expand All @@ -958,18 +953,15 @@ impl bifrost_salp::Config for Runtime {
type ReleaseRatio = ReleaseRatio;
type RemoveKeysLimit = RemoveKeysLimit;
type SlotLength = SlotLength;
type SubmissionDeposit = SubmissionDeposit;
type VSBondValidPeriod = VSBondValidPeriod;
type XcmTransferOrigin = XcmTransferOrigin;
type WeightInfo = weights::bifrost_salp::WeightInfo<Runtime>;
type SelfParaId = SelfParaId;
type ContributionWeight = ContributionWeight;
type WithdrawWeight = WithdrawWeight;
type BaseXcmWeight = XcmWeight;
type EnsureConfirmAsMultiSig =
EnsureOneOf<AccountId, MoreThanHalfCouncil, EnsureConfirmAsMultiSig>;
type AddProxyWeight = AddProxyWeight;
type RemoveProxyWeight = RemoveProxyWeight;
type XcmTransfer = XTokens;
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
type TransactProxyType = SalpProxyType;
Expand Down
Loading