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
5 changes: 5 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions pallets/salp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-f
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"}
smallvec = "1.6.1"
sp-io = "3.0.0"
sp-core = "3.0.0"
sp-runtime = "3.0.0"
orml-tokens = "0.4.1-dev"
orml-currencies = "0.4.1-dev"
pallet-balances = "3.0.0"
Expand Down
92 changes: 31 additions & 61 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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};
use frame_support::{pallet_prelude::*, sp_runtime::MultiSignature, transactional};
use node_primitives::{ParaId, TokenInfo, TokenSymbol};
use orml_traits::MultiCurrency;
pub use pallet::*;
Expand All @@ -44,22 +44,12 @@ type TrieIndex = u32;
pub trait WeightInfo {
fn create() -> Weight;
fn contribute() -> Weight;
fn on_finalize(n: u32) -> Weight;
}

pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn create() -> Weight {
0
}

fn contribute() -> Weight {
0
}

fn on_finalize(_n: u32) -> Weight {
0
}
fn unlock() -> Weight;
fn withdraw() -> Weight;
fn refund() -> Weight;
fn redeem() -> Weight;
fn dissolve(n: u32) -> Weight;
fn on_initialize(n: u32) -> Weight;
}

#[allow(type_alias_bounds)]
Expand Down Expand Up @@ -224,6 +214,7 @@ 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 Down Expand Up @@ -317,6 +308,8 @@ pub mod pallet {

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

type WeightToFee: WeightToFeePolynomial<Balance = BalanceOf<Self>>;
}

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

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(
Expand All @@ -526,11 +519,7 @@ pub mod pallet {
}

/// Unlock the reserved vsToken/vsBond after fund success
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::unlock())]
pub fn unlock(
_origin: OriginFor<T>,
who: AccountIdOf<T>,
Expand Down Expand Up @@ -569,11 +558,7 @@ pub mod pallet {
}

/// Create a new crowdloaning campaign for a parachain slot deposit for the current auction.
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::create())]
pub fn create(
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
Expand Down Expand Up @@ -619,11 +604,8 @@ pub mod pallet {
/// Contribute to a crowd sale. This will transfer some balance over to fund a parachain
/// slot. It will be withdrawable in two instances: the parachain becomes retired; or the
/// slot is unable to be purchased and the timeout expires.
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::contribute())]
#[transactional]
pub fn contribute(
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
Expand Down Expand Up @@ -668,7 +650,7 @@ pub mod pallet {
#[pallet::compact] index: ParaId,
is_success: bool,
) -> DispatchResult {
let _owner = T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
let can_confirm = fund.status == FundStatus::Ongoing ||
Expand Down Expand Up @@ -727,11 +709,8 @@ pub mod pallet {
/// Withdraw full balance of the parachain. this function may need to be called multiple
/// times
/// - `index`: The parachain to whose crowdloan the contribution was made.
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::withdraw())]
#[transactional]
pub fn withdraw(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
let owner = ensure_signed(origin.clone())?;

Expand Down Expand Up @@ -788,11 +767,8 @@ pub mod pallet {
Ok(())
}

#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::refund())]
#[transactional]
pub fn refund(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
let who = ensure_signed(origin.clone())?;

Expand Down Expand Up @@ -885,11 +861,8 @@ pub mod pallet {
Ok(())
}

#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::redeem())]
#[transactional]
pub fn redeem(
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
Expand Down Expand Up @@ -989,11 +962,7 @@ pub mod pallet {
}

/// Remove a fund after the retirement period has ended and all funds have been returned.
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::dissolve(T::RemoveKeysLimit::get()))]
pub fn dissolve(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
let depositor = ensure_signed(origin)?;

Expand Down Expand Up @@ -1030,7 +999,7 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_finalize(n: BlockNumberFor<T>) {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
// Release x% KSM/DOT from redeem-pool to bancor-pool per cycle
if n != 0 && (n % T::ReleaseCycle::get()) == 0 {
if let Ok(rp_balance) = TryInto::<u128>::try_into(Self::redeem_pool()) {
Expand All @@ -1052,14 +1021,10 @@ pub mod pallet {
}
}
}
<T as Config>::WeightInfo::on_initialize(n)

// TODO: Auto unlock vsToken/vsBond?
}

fn on_initialize(_n: BlockNumberFor<T>) -> frame_support::weights::Weight {
// TODO estimate weight
Zero::zero()
}
}

impl<T: Config> Pallet<T> {
Expand Down Expand Up @@ -1160,8 +1125,13 @@ pub mod pallet {
fn xcm_ump_contribute(
_origin: OriginFor<T>,
index: ParaId,
value: BalanceOf<T>,
mut value: BalanceOf<T>,
) -> XcmResult {
let fee: BalanceOf<T> = T::WeightToFee::calc(&T::BifrostXcmExecutor::transact_weight(
T::ContributionWeight::get(),
));
value = value.saturating_sub(fee);

let contribution = Contribution { index, value, signature: None };

let call = CrowdloanContributeCall::CrowdloanContribute(ContributeCall::Contribute(
Expand Down
59 changes: 56 additions & 3 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use frame_support::{
construct_runtime, parameter_types,
traits::{EnsureOrigin, GenesisBuild},
weights::{WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial},
PalletId,
};
use frame_system::RawOrigin;
Expand All @@ -36,9 +37,10 @@ use xcm::{
DoubleEncoded,
};
use xcm_builder::{EnsureXcmOrigin, SignedToAccountId32};
use xcm_support::BifrostXcmExecutor;
use xcm_support::{BifrostXcmExecutor, Weight};

use crate as salp;
use crate::WeightInfo;

pub(crate) type AccountId = <<Signature as sp_runtime::traits::Verify>::Signer as sp_runtime::traits::IdentifyAccount>::AccountId;
pub(crate) type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -233,6 +235,21 @@ impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
}
}

use smallvec::smallvec;
pub use sp_runtime::Perbill;
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(90u32, 100u32),
coeff_integer: 1,
}]
}
}

impl salp::Config for Test {
type BancorPool = Bancor;
type BifrostXcmExecutor = MockXcmExecutor;
Expand All @@ -251,12 +268,48 @@ impl salp::Config for Test {
type SubmissionDeposit = SubmissionDeposit;
type VSBondValidPeriod = VSBondValidPeriod;
type XcmTransferOrigin = XcmTransferOrigin;
type WeightInfo = salp::TestWeightInfo;
type WeightInfo = SalpWeightInfo;
type SelfParaId = SelfParaId;
type BaseXcmWeight = BaseXcmWeight;
type ContributionWeight = ContributionWeight;
type WithdrawWeight = WithdrawWeight;
type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig;
type WeightToFee = WeightToFee;
}

pub struct SalpWeightInfo;
impl WeightInfo for SalpWeightInfo {
fn create() -> Weight {
0
}

fn contribute() -> Weight {
0
}

fn unlock() -> Weight {
0
}

fn withdraw() -> Weight {
0
}

fn redeem() -> Weight {
0
}

fn refund() -> Weight {
0
}

fn dissolve(_n: u32) -> Weight {
0
}

fn on_initialize(_n: u32) -> Weight {
0
}
}

// To control the result returned by `MockXcmExecutor`
Expand All @@ -266,7 +319,7 @@ pub(crate) static mut MOCK_XCM_RESULT: (bool, bool) = (true, true);
pub struct MockXcmExecutor;

impl BifrostXcmExecutor for MockXcmExecutor {
fn transact_weight() -> u64 {
fn transact_weight(_: u64) -> u64 {
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions runtime/asgard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ log = { version = "0.4.14", default-features = false }
serde = { version = "1.0.124", optional = true }
static_assertions = "1.1.0"
hex-literal = { version = "0.3.1"}
smallvec = "1.6.1"

# primitives
node-primitives = { default-features = false, path = "../../node/primitives" }
Expand Down Expand Up @@ -71,6 +72,7 @@ parachain-info = { git = "https://github.com/paritytech/cumulus", default-featur
pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.8" }

# Polkadot dependencies
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false,branch = "release-v0.9.8" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" }
Expand Down Expand Up @@ -164,6 +166,7 @@ std = [
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
"polkadot-primitives/std",
"polkadot-runtime-parachains/std",
"bifrost-bancor/std",
"bifrost-bancor-runtime-api/std",
Expand Down
Loading