Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6ae4835
feat: add convert to liquid dispatchable call
mattsse Jul 13, 2021
e3a39de
Merge branch 'main' into matt/convert-to-liquid
mattsse Jul 20, 2021
e0b7bf7
add convert to liquid extrinsic
mattsse Jul 20, 2021
56e4f36
update tests
mattsse Jul 20, 2021
7f6ed2e
cleanup
mattsse Jul 20, 2021
c213d78
use std feature
mattsse Jul 20, 2021
712cf99
bump orml
mattsse Jul 20, 2021
0317ba5
add weight
mattsse Jul 20, 2021
2865c19
feat: add transaction payment pallet
mattsse Jul 20, 2021
177be94
Merge branch 'main' into matt/payment-pallet
mattsse Aug 5, 2021
46221cc
Merge branch 'main' into matt/payment-pallet
mattsse Aug 18, 2021
23380f7
modify default tx payment module
mattsse Aug 18, 2021
d77044b
chore(deps): update to polkadot-v0.9.12
mattsse Oct 31, 2021
bebaf3d
chore(remote-asset-manager): use xcm v2
clearloop Nov 1, 2021
6765902
fix: pallet-xcm feaute
mattsse Nov 1, 2021
494d085
fix: breaking changes
mattsse Nov 1, 2021
8e169f2
fix: update calls
mattsse Nov 1, 2021
4cf3787
fix: features
mattsse Nov 2, 2021
bd5ca46
fix: tests
mattsse Nov 2, 2021
91b2f28
make everything compile
mattsse Nov 2, 2021
5451ed7
feat(pallets): remove forced runtime-benchmarks features in pallets
clearloop Nov 2, 2021
bc0d278
fix: failing tests
mattsse Nov 10, 2021
5a721b0
Merge branch 'matt/polkadot-v0.9.12' into matt/payment-pallet
mattsse Nov 10, 2021
189ea49
use asset tx pallet
mattsse Nov 10, 2021
68508f4
use asset tx pallet
mattsse Nov 10, 2021
0334d98
Merge branch 'main' into matt/asset-tx-payment
mattsse Nov 10, 2021
b74f31e
cleanup
mattsse Nov 10, 2021
bdc3602
Merge branch 'main' into matt/buy-execution
mattsse Nov 10, 2021
5479bd6
Merge branch 'matt/asset-tx-payment' into matt/buy-execution
mattsse Nov 10, 2021
ba9f556
add utility call
mattsse Nov 10, 2021
7fe2a96
feat: add asset unbonding
mattsse Nov 10, 2021
f6086b8
feat: add utility bindings
mattsse Nov 10, 2021
685db5c
feat: add wrap into xcm call
mattsse Nov 11, 2021
85e6e4c
Merge branch 'main' into matt/buy-execution
mattsse Nov 11, 2021
9b005f7
feat: wrap calls
mattsse Nov 11, 2021
08b6245
rustfmt
mattsse Nov 11, 2021
0359616
feat: barrier
mattsse Nov 11, 2021
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
493 changes: 260 additions & 233 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pallets/committee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ pub mod pallet {
let votes = maybe_votes.as_mut().ok_or(Error::<T>::NoProposalWithHash)?;

// Can only vote within the allowed range of blocks for this proposal
ensure!(Self::within_voting_period(&votes), Error::<T>::NotInVotingPeriod);
ensure!(Self::within_voting_period(votes), Error::<T>::NotInVotingPeriod);
// members can vote only once
ensure!(!votes.has_voted(&voter.account_id), Error::<T>::DuplicateVote);
votes.cast_vote(MemberVote::new(voter.clone(), vote.clone())); // mutates votes in place
Expand Down
4 changes: 2 additions & 2 deletions pallets/committee/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ fn member_can_vote_aye() {
new_test_ext(ASHLEY_RANGE).execute_with(|| {
let expected_votes = VoteAggregate::<AccountId, u64>::new(vec![ASHLEY_COUNCIL], vec![], vec![], START_OF_V1);
let proposal = submit_proposal(123);
assert_eq!(VotingEligibility::<Test>::get(ASHLEY), Some(0u64.into()));
assert_eq!(VotingEligibility::<Test>::get(ASHLEY), Some(0u64));

run_to_block(START_OF_S1);

// first block in voting period
assert_ok!(Committee::vote(Origin::signed(ASHLEY), proposal.hash(), VoteKind::Aye));
assert_eq!(VotingEligibility::<Test>::get(ASHLEY), Some(0u64.into()));
assert_eq!(VotingEligibility::<Test>::get(ASHLEY), Some(0u64));
assert_eq!(Committee::get_votes_for(&proposal.hash()), Some(expected_votes));
});
}
Expand Down
133 changes: 90 additions & 43 deletions pallets/remote-asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ pub mod pallet {
};
use frame_system::pallet_prelude::*;
use orml_traits::{MultiCurrency, XcmTransfer};
use xcm::latest::{
Error as XcmError, ExecuteXcm, Instruction, MultiLocation, OriginKind, Result as XcmResult, SendXcm, Xcm,
};
use xcm::latest::{prelude::*, Error as XcmError, Result as XcmResult};

use primitives::traits::{MaybeAssetIdConvert, RemoteAssetManager};
use xcm_calls::{
Expand Down Expand Up @@ -127,6 +125,10 @@ pub mod pallet {
#[pallet::constant]
type RelayChainAssetId: Get<Self::AssetId>;

/// Unbonding slashing spans for unbonding on the relaychain.
#[pallet::constant]
type AssetUnbondingSlashingSpans: Get<u32>;

/// Determines the threshold amounts when operating with staked assets.
type AssetStakingCap: StakingCap<Self::AssetId, Self::Balance>;

Expand Down Expand Up @@ -208,6 +210,12 @@ pub mod pallet {
pub type Proxies<T: Config> =
StorageDoubleMap<_, Blake2_128Concat, T::AssetId, Twox64Concat, AccountIdFor<T>, ProxyState, ValueQuery>;

/// The extra weight for cross-chain XCM transfers.
/// xcm_dest_weight: value: Weight
#[pallet::storage]
#[pallet::getter(fn xcm_dest_weight)]
pub type XcmDestWeight<T: Config> = StorageValue<_, Weight, ValueQuery>;

/// The config of the statemint parachain.
///
/// Provides information that is required when sending XCM calls to transfer PINT:,
Expand All @@ -216,6 +224,7 @@ pub mod pallet {
/// - `parachain id`: the parachain of the statemint chain
/// - `weights`: the weights to use for the call
#[pallet::storage]
#[pallet::getter(fn statemint_para_config)]
pub type StatemintParaConfig<T> = StorageValue<_, StatemintConfig, OptionQuery>;

#[pallet::genesis_config]
Expand Down Expand Up @@ -299,6 +308,8 @@ pub mod pallet {
Frozen(T::AssetId),
/// The asset was thawed for XCM related operations. \[asset id\]
Thawed(T::AssetId),
/// A new weight for XCM transfers has been set.\[new_weight\]
XcmDestWeightSet(Weight),
}

#[pallet::error]
Expand Down Expand Up @@ -384,8 +395,9 @@ pub mod pallet {
///
/// The maximum number of separate xcm calls we send here is limited to the number of liquid
/// assets with staking support.
fn on_finalize(now: T::BlockNumber) {
fn on_idle(now: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
// check all assets with enabled cross chain staking support and a valid destination
// TODO handle weight
for (asset, config, dest) in PalletStakingConfig::<T>::iter()
.filter_map(|(asset, config)| Self::asset_destination(asset).ok().map(|dest| (asset, config, dest)))
{
Expand Down Expand Up @@ -452,6 +464,8 @@ pub mod pallet {
AssetBalance::<T>::insert(asset, balances);
}
}

remaining_weight
}
}

Expand Down Expand Up @@ -491,13 +505,11 @@ pub mod pallet {
let call = PalletStakingCall::<T>::Bond(Bond { controller: controller.clone(), value, payee });
let encoder = call.encoder::<T::PalletStakingCallEncoder>(&asset);

let transact = Instruction::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: config.weights.bond,
call: encoder.encode_runtime_call(config.pallet_index).encode().into(),
};
let mut xcm = Xcm::new();
xcm.0.push(transact);
let xcm = Self::wrap_call_into_xcm(
encoder.encode_runtime_call(config.pallet_index).encode(),
config.weights.bond,
Self::xcm_dest_weight().into(),
);

let result = T::XcmSender::send_xcm(dest, xcm);
log::info!(target: "pint_xcm", "sent pallet_staking::bond xcm: {:?} ",result);
Expand Down Expand Up @@ -546,13 +558,11 @@ pub mod pallet {
});
let encoder = call.encoder::<T::PalletProxyCallEncoder>(&asset);

let transact = Instruction::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: config.weights.add_proxy,
call: encoder.encode_runtime_call(config.pallet_index).encode().into(),
};
let mut xcm = Xcm::new();
xcm.0.push(transact);
let xcm = Self::wrap_call_into_xcm(
encoder.encode_runtime_call(config.pallet_index).encode(),
config.weights.add_proxy,
Self::xcm_dest_weight().into(),
);

let result = T::XcmSender::send_xcm(dest, xcm);
log::info!(target: "pint_xcm", "sent pallet_proxy::add_proxy xcm: {:?} ",result);
Expand Down Expand Up @@ -658,6 +668,22 @@ pub mod pallet {
Ok(())
}

/// Sets the `xcm_dest_weight` for XCM transfers.
///
/// Callable by the admin origin
///
/// Parameters:
/// - `xcm_dest_weight`: The new weight for XCM transfers.
#[pallet::weight(< T as Config >::WeightInfo::set_xcm_dest_weight())]
#[transactional]
pub fn set_xcm_dest_weight(origin: OriginFor<T>, #[pallet::compact] xcm_dest_weight: Weight) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;

XcmDestWeight::<T>::put(xcm_dest_weight);
Self::deposit_event(Event::<T>::XcmDestWeightSet(xcm_dest_weight));
Ok(())
}

/// Enables XCM transactions for the statemint parachain, if configured.
///
/// This is a noop if it's already enabled
Expand Down Expand Up @@ -725,7 +751,7 @@ pub mod pallet {
who.clone(),
config.multi_asset(amount.into()),
config.parahain_location(),
100_000_000,
Self::xcm_dest_weight().into(),
)?;

Self::deposit_event(Event::StatemintTransfer(who, amount));
Expand Down Expand Up @@ -782,13 +808,11 @@ pub mod pallet {
let call = PalletStakingCall::<T>::BondExtra(amount);
let encoder = call.encoder::<T::PalletStakingCallEncoder>(&asset);

let transact = Instruction::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: config.weights.bond_extra,
call: encoder.encode_runtime_call(config.pallet_index).encode().into(),
};
let mut xcm = Xcm::new();
xcm.0.push(transact);
let xcm = Self::wrap_call_into_xcm(
encoder.encode_runtime_call(config.pallet_index).encode(),
config.weights.bond_extra,
Self::xcm_dest_weight().into(),
);

let result = T::XcmSender::send_xcm(dest, xcm);
log::info!(target: "pint_xcm", "sent pallet_staking::bond_extra xcm: {:?} ",result);
Expand Down Expand Up @@ -845,13 +869,11 @@ pub mod pallet {
let call = PalletStakingCall::<T>::Unbond(amount);
let encoder = call.encoder::<T::PalletStakingCallEncoder>(&asset);

let transact = Instruction::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: config.weights.unbond,
call: encoder.encode_runtime_call(config.pallet_index).encode().into(),
};
let mut xcm = Xcm::new();
xcm.0.push(transact);
let xcm = Self::wrap_call_into_xcm(
encoder.encode_runtime_call(config.pallet_index).encode(),
config.weights.unbond,
Self::xcm_dest_weight().into(),
);

let result = T::XcmSender::send_xcm(dest, xcm);
log::info!(target: "pint_xcm", "sent pallet_staking::unbond xcm: {:?} ",result);
Expand All @@ -863,15 +885,19 @@ pub mod pallet {
/// Remove any unlocked chunks from the `unlocking` queue.
/// An `withdraw_unbonded` call must be signed by the controller
/// account.
/// This essentially gives the PNIT's sovereign hold of the balance
/// This essentially gives the PINT's reserve account hold of the balance
pub fn do_send_withdraw_unbonded(asset: T::AssetId) -> DispatchResult {
let dest = Self::asset_destination(asset)?;

// ensures that the call is encodable for the destination
ensure!(T::PalletProxyCallEncoder::can_encode(&asset), Error::<T>::NotEncodableForLocation);

// get the config for how staking is configured
let config = PalletStakingConfig::<T>::get(&asset).ok_or(Error::<T>::NoPalletConfigFound)?;

let mut ledger = PalletStakingLedger::<T>::get(&asset).ok_or(Error::<T>::NotBonded)?;

// only controller account is allowed to send unbonded
Self::ensure_staking_controller(ledger.controller.clone())?;

// ensure that at least one chunk is withdrawable
Expand All @@ -880,17 +906,14 @@ pub mod pallet {
Error::<T>::NothingToWithdraw
);

// NOTE: this sets `num_slashing_spans` to 0, to not clear slashing metadata
let call = PalletStakingCall::<T>::WithdrawUnbonded(0);
let call = PalletStakingCall::<T>::WithdrawUnbonded(T::AssetUnbondingSlashingSpans::get());
let encoder = call.encoder::<T::PalletStakingCallEncoder>(&asset);

let transact = Instruction::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: config.weights.withdraw_unbonded,
call: encoder.encode_runtime_call(config.pallet_index).encode().into(),
};
let mut xcm = Xcm::new();
xcm.0.push(transact);
let xcm = Self::wrap_call_into_xcm(
encoder.encode_runtime_call(config.pallet_index).encode(),
config.weights.withdraw_unbonded,
Self::xcm_dest_weight().into(),
);

let result = T::XcmSender::send_xcm(dest, xcm);
log::info!(target: "pint_xcm", "sent pallet_staking::withdraw_unbonded xcm: {:?} ",result);
Expand All @@ -911,10 +934,30 @@ pub mod pallet {
Ok(())
}

/// The destination address of the asset's native location
fn asset_destination(asset: T::AssetId) -> Result<MultiLocation, DispatchError> {
let dest = T::AssetIdConvert::convert(asset).ok_or(Error::<T>::InvalidAssetChainLocation)?;
Ok(dest)
}

/// Wrap the call into a Xcm instance.
/// params:
/// - call: The encoded call to be executed
/// - fee: fee (in remote currency) used to buy the `weight` and `debt`.
/// - require_weight_at_most: the weight limit used for the xcm transacted call.
fn wrap_call_into_xcm(call: Vec<u8>, require_weight_at_most: Weight, fee: u128) -> Xcm<()> {
let asset = MultiAsset { id: Concrete(MultiLocation::here()), fun: Fungibility::Fungible(fee) };
Xcm(vec![
WithdrawAsset(asset.clone().into()),
BuyExecution { fees: asset, weight_limit: Unlimited },
Transact { origin_type: OriginKind::SovereignAccount, require_weight_at_most, call: call.into() },
DepositAsset {
assets: All.into(),
max_assets: u32::MAX,
beneficiary: MultiLocation { parents: 1, interior: X1(Parachain(T::SelfParaId::get().into())) },
},
])
}
}

impl<T: Config> RemoteAssetManager<T::AccountId, T::AssetId, T::Balance> for Pallet<T> {
Expand Down Expand Up @@ -967,6 +1010,7 @@ pub mod pallet {
fn transfer() -> Weight;
fn freeze() -> Weight;
fn thaw() -> Weight;
fn set_xcm_dest_weight() -> Weight;
}

/// For backwards compatibility and tests
Expand All @@ -980,5 +1024,8 @@ pub mod pallet {
fn thaw() -> Weight {
Default::default()
}
fn set_xcm_dest_weight() -> Weight {
Default::default()
}
}
}
2 changes: 1 addition & 1 deletion pallets/saft-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub mod pallet {
nav: T::Balance,
units: T::Balance,
) -> DispatchResult {
Self::do_add_saft(T::AdminOrigin::ensure_origin(origin.clone())?, asset_id, nav, units)
Self::do_add_saft(T::AdminOrigin::ensure_origin(origin)?, asset_id, nav, units)
}

/// Adds saft with root origin
Expand Down
1 change: 1 addition & 0 deletions primitives/xcm-calls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ frame-election-provider-support = { git = 'https://github.com/paritytech/substra
pallet-assets = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12' }
pallet-staking = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12' }
pallet-proxy = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12' }
pallet-utility = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12' }
pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12'}
pallet-staking-reward-curve = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12' }
pallet-timestamp = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12' }
Expand Down
Loading