Skip to content

Commit

Permalink
Fix xcmp_fee for automation-time (#366)
Browse files Browse the repository at this point in the history
* Add asset_location param to get_local_currency_instructions function

* Add Convert<MultiLocation, Option<TokenId>> to automationTime

* Deduct fees based on different currency ID

* Split DestinationAssetConfig into TransactInfoWithWeightLimit and DestinationAssetFeePerSecond

* Change the type of destination to VersionedMultiLocation

* Modify Mangata asset config

* Customize XCMP fee and weight.

* Fix typo

* Calculate xcmp fee for alternate flow

* Remove xcmp fee and weight calculation

* Fix benchmark and tests

* Fixing failed tests

* Add migration

* Code format

* Fix schedule_xcmp_task_full test

* Remove TransactInfo storage

* Rename XcmFlow to XcmTaskSupported

* Remove pallet_xcmp_handler storage in runtime configuration

* Rename enum XcmTaskSupported to InstructionSequence

* Change scheduleFee to MultiLcation

* Fix the comment of AssetPayment

* Extract instruction weight and fee to const variable in update_xcmp_task.rs

* Fix tests for the merged code

* Add calculate_schedule_fee_amount_works test

* Add calculate_schedule_fee_amount tests

* fixup: auto format Rust code

* Add tests for all types of automation-time action

* Set num_of_execution to a random number

* Add comment for schedule_xcmp_task , schedule_xcmp_task_through_proxy function

---------

Co-authored-by: oak-code-formatter <[email protected]>
  • Loading branch information
imstar15 and oak-code-formatter committed Jul 12, 2023
1 parent 6946450 commit 54272be
Show file tree
Hide file tree
Showing 31 changed files with 1,138 additions and 1,028 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

9 changes: 1 addition & 8 deletions node/src/chain_spec/neumann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use hex_literal::hex;
use std::time::SystemTime;

use cumulus_primitives_core::ParaId;
use frame_support::pallet_prelude::*;
use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
use sp_core::{crypto::UncheckedInto, sr25519};
Expand All @@ -16,9 +15,8 @@ use crate::chain_spec::{
use common_runtime::constants::currency::{DOLLAR, TOKEN_DECIMALS};
use neumann_runtime::{
CouncilConfig, PolkadotXcmConfig, SudoConfig, TechnicalMembershipConfig, ValveConfig,
VestingConfig, XcmpHandlerConfig,
VestingConfig,
};
use pallet_xcmp_handler::XcmFlow;
use primitives::{AccountId, AuraId, Balance};

static TOKEN_SYMBOL: &str = "NEU";
Expand Down Expand Up @@ -94,7 +92,6 @@ pub fn development_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
],
vec![],
)
},
Vec::new(),
Expand Down Expand Up @@ -186,7 +183,6 @@ pub fn local_testnet_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
],
vec![],
)
},
// Bootnodes
Expand Down Expand Up @@ -275,7 +271,6 @@ pub fn neumann_staging_testnet_config() -> ChainSpec {
// 669ocRxey7vxUJs1TTRWe31zwrpGr8B13zRfAHB6yhhfcMud
hex!["001fbcefa8c96f3d2e236688da5485a0af67988b78d61ea952f461255d1f4267"].into(),
],
vec![],
)
},
// Bootnodes
Expand Down Expand Up @@ -309,7 +304,6 @@ fn testnet_genesis(
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
general_councils: Vec<AccountId>,
technical_memberships: Vec<AccountId>,
xcmp_handler_asset_data: Vec<(Vec<u8>, u128, Weight, XcmFlow)>,
) -> neumann_runtime::GenesisConfig {
neumann_runtime::GenesisConfig {
system: neumann_runtime::SystemConfig {
Expand Down Expand Up @@ -363,7 +357,6 @@ fn testnet_genesis(
treasury: Default::default(),
valve: ValveConfig { start_with_valve_closed: false, closed_gates: pallet_gates_closed },
vesting: VestingConfig { vesting_schedule },
xcmp_handler: XcmpHandlerConfig { asset_data: xcmp_handler_asset_data },
asset_registry: Default::default(),
}
}
Expand Down
9 changes: 1 addition & 8 deletions node/src/chain_spec/oak.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use hex_literal::hex;

use cumulus_primitives_core::ParaId;
use frame_support::pallet_prelude::*;
use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
use sp_core::{crypto::UncheckedInto, sr25519};
Expand All @@ -16,9 +15,8 @@ use crate::chain_spec::{
use common_runtime::constants::currency::{DOLLAR, EXISTENTIAL_DEPOSIT, TOKEN_DECIMALS};
use oak_runtime::{
CouncilConfig, PolkadotXcmConfig, SudoConfig, TechnicalMembershipConfig, ValveConfig,
VestingConfig, XcmpHandlerConfig,
VestingConfig,
};
use pallet_xcmp_handler::XcmFlow;
use primitives::{AccountId, AuraId, Balance};

const TOKEN_SYMBOL: &str = "OAK";
Expand Down Expand Up @@ -88,7 +86,6 @@ pub fn oak_development_config() -> ChainSpec {
vec![],
vec![get_account_id_from_seed::<sr25519::Public>("Alice")],
vec![get_account_id_from_seed::<sr25519::Public>("Alice")],
vec![],
)
},
Vec::new(),
Expand Down Expand Up @@ -184,7 +181,6 @@ pub fn oak_staging() -> ChainSpec {
// 5C571x5GLRQwfA3aRtVcxZzD7JnzNb3JbtZEvJWfQozWE54K
hex!["004df6aeb14c73ef5cd2c57d9028afc402c4f101a8917bbb6cd19407c8bf8307"].into(),
],
vec![],
)
},
// Bootnodes
Expand Down Expand Up @@ -317,7 +313,6 @@ pub fn oak_live() -> ChainSpec {
// 67nmVh57G9yo7sqiGLjgNNqtUd7H2CSESTyQgp5272aMibwS
hex!["488ced7d199b4386081a52505962128da5a3f54f4665db3d78b6e9f9e89eea4d"].into(),
],
vec![],
)
},
// Bootnodes
Expand Down Expand Up @@ -347,7 +342,6 @@ fn testnet_genesis(
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
general_councils: Vec<AccountId>,
technical_memberships: Vec<AccountId>,
xcmp_handler_asset_data: Vec<(Vec<u8>, u128, Weight, XcmFlow)>,
) -> oak_runtime::GenesisConfig {
let candidate_stake =
std::cmp::max(oak_runtime::MinCollatorStk::get(), oak_runtime::MinCandidateStk::get());
Expand Down Expand Up @@ -403,7 +397,6 @@ fn testnet_genesis(
treasury: Default::default(),
valve: ValveConfig { start_with_valve_closed: false, closed_gates: pallet_gates_closed },
vesting: VestingConfig { vesting_schedule },
xcmp_handler: XcmpHandlerConfig { asset_data: xcmp_handler_asset_data },
asset_registry: Default::default(),
}
}
53 changes: 12 additions & 41 deletions node/src/chain_spec/turing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use cumulus_primitives_core::ParaId;
use frame_support::pallet_prelude::*;
use sc_service::ChainType;
use sp_core::sr25519;
use sp_runtime::{Perbill, Percent};
Expand All @@ -10,13 +9,12 @@ use crate::chain_spec::{
};
use codec::Encode;
use common_runtime::constants::currency::{DOLLAR, TOKEN_DECIMALS};
use pallet_xcmp_handler::XcmFlow;
use primitives::{assets::CustomMetadata, AccountId, AuraId, Balance, TokenId};
use turing_runtime::{
AssetRegistryConfig, CouncilConfig, PolkadotXcmConfig, TechnicalMembershipConfig, ValveConfig,
VestingConfig, XcmpHandlerConfig,
VestingConfig,
};
use xcm::{prelude::*, VersionedMultiLocation, VersionedMultiLocation::V3};
use xcm::{prelude::*, VersionedMultiLocation::V3};

const TOKEN_SYMBOL: &str = "TUR";
const SS_58_FORMAT: u32 = 51;
Expand Down Expand Up @@ -84,40 +82,6 @@ pub fn turing_development_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
],
vec![
(
<VersionedMultiLocation>::encode(
&(MultiLocation::new(1, X1(Parachain(1999))).into()),
),
419_000_000_000,
Weight::from_ref_time(1_000_000_000),
XcmFlow::Normal,
),
(
<VersionedMultiLocation>::encode(
&(MultiLocation::new(1, X1(Parachain(2110))).into()),
),
419_000_000_000,
Weight::from_ref_time(1_000_000_000),
XcmFlow::Normal,
),
(
<VersionedMultiLocation>::encode(
&(MultiLocation::new(1, X1(Parachain(2000))).into()),
),
10_000_000_000_000_000_000,
Weight::from_parts(1_000_000_000, 1024),
XcmFlow::Alternate,
),
(
<VersionedMultiLocation>::encode(
&(MultiLocation::new(1, X2(Parachain(1000), PalletInstance(3))).into()),
),
10_000_000_000_000_000_000,
Weight::from_ref_time(250_000_000),
XcmFlow::Alternate,
),
],
vec![
(
1,
Expand All @@ -127,7 +91,16 @@ pub fn turing_development_config() -> ChainSpec {
name: b"Mangata Rococo".to_vec(),
symbol: b"MGR".to_vec(),
existential_deposit: Default::default(),
location: Some(MultiLocation::new(1, X1(Parachain(2110))).into()),
location: Some(
MultiLocation::new(
1,
X2(
Parachain(2110),
GeneralKey { length: 4, data: [0; 32] },
),
)
.into(),
),
additional: CustomMetadata {
fee_per_second: Some(416_000_000_000),
conversion_rate: None,
Expand Down Expand Up @@ -234,7 +207,6 @@ fn testnet_genesis(
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
general_councils: Vec<AccountId>,
technical_memberships: Vec<AccountId>,
xcmp_handler_asset_data: Vec<(Vec<u8>, u128, Weight, XcmFlow)>,
additional_assets: Vec<(TokenId, Vec<u8>)>,
) -> turing_runtime::GenesisConfig {
let candidate_stake = std::cmp::max(
Expand Down Expand Up @@ -316,7 +288,6 @@ fn testnet_genesis(
treasury: Default::default(),
valve: ValveConfig { start_with_valve_closed: false, closed_gates: pallet_gates_closed },
vesting: VestingConfig { vesting_schedule },
xcmp_handler: XcmpHandlerConfig { asset_data: xcmp_handler_asset_data },
asset_registry: AssetRegistryConfig { assets, last_asset_id },
}
}
Expand Down
5 changes: 4 additions & 1 deletion pallets/automation-time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pallet-xcmp-handler = { path = "../xcmp-handler", default-features = false }
primitives = { path = "../../primitives", default-features = false }

[dev-dependencies]
rand = { version = "0.7.3" }
serde = { version = "1.0.144" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
Expand All @@ -67,6 +68,9 @@ pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "p
pallet-xcm = { git = 'https://github.com/paritytech/polkadot', default-features = false, branch = "release-v0.9.38" }
xcm-executor = { git = 'https://github.com/paritytech/polkadot', default-features = false, branch = "release-v0.9.38" }

# Cumulus dependencies
parachain-info = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.38' }

orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.38" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.38" }

Expand All @@ -75,7 +79,6 @@ default = ["std"]
runtime-benchmarks = [
"frame-benchmarking",
"pallet-parachain-staking/runtime-benchmarks",
"pallet-xcmp-handler/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
std = [
Expand Down
2 changes: 1 addition & 1 deletion pallets/automation-time/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub enum AutomationAction {
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub struct FeeDetails<Balance> {
pub schedule_fee: Balance,
pub execution_fee: Balance,
pub xcmp_fee: Balance,
}

sp_api::decl_runtime_apis! {
Expand Down
2 changes: 1 addition & 1 deletion pallets/automation-time/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ where
};

Ok(FeeDetails {
schedule_fee: try_into_rpc_balance(fee_details.schedule_fee)?,
execution_fee: try_into_rpc_balance(fee_details.execution_fee)?,
xcmp_fee: try_into_rpc_balance(fee_details.xcmp_fee)?,
})
}

Expand Down
27 changes: 17 additions & 10 deletions pallets/automation-time/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ fn schedule_xcmp_tasks<T: Config>(owner: T::AccountId, times: Vec<u64>, count: u
owner.clone(),
provided_id.clone(),
times.clone(),
para_id.clone().try_into().unwrap(),
T::GetNativeCurrencyId::get(),
MultiLocation::new(1, X1(Parachain(para_id))).into(),
MultiLocation::new(1, X1(Parachain(para_id))),
MultiLocation::default(),
AssetPayment {
asset_location: MultiLocation::new(1, X1(Parachain(para_id))).into(),
amount: 0,
},
vec![4, 5, 6],
Weight::from_ref_time(5_000),
Weight::from_ref_time(10_000),
InstructionSequence::PayThroughSovereignAccount,
)
.unwrap();
let task_id = AutomationTime::<T>::schedule_task(&task, provided_id.clone()).unwrap();
Expand Down Expand Up @@ -159,8 +164,11 @@ benchmarks! {
}
let schedule = ScheduleParam::Fixed { execution_times: times.clone() };

let asset_location = MultiLocation::new(1, X1(Parachain(para_id)));
T::XcmpTransactor::setup_chain_asset_data(asset_location.clone())?;
let destination = MultiLocation::new(1, X1(Parachain(para_id)));

let schedule_fee = T::CurrencyIdConvert::convert(currency_id).expect("IncoveribleCurrencyId");

let fee = AssetPayment { asset_location: MultiLocation::new(0, Here).into(), amount: 100u128 };

let mut provided_id = schedule_xcmp_tasks::<T>(caller.clone(), times, max_tasks_per_slot - 1);
provided_id = increment_provided_id(provided_id);
Expand All @@ -169,7 +177,7 @@ benchmarks! {
.saturating_mul(ED_MULTIPLIER.into())
.saturating_mul(DEPOSIT_MULTIPLIER.into());
let _ = T::MultiCurrency::deposit(currency_id.into(), &caller, foreign_currency_amount);
}: schedule_xcmp_task(RawOrigin::Signed(caller), provided_id, schedule, para_id.into(), currency_id, asset_location.into(), call, Weight::from_ref_time(1_000))
}: schedule_xcmp_task(RawOrigin::Signed(caller), provided_id, schedule, Box::new(destination.into()), Box::new(schedule_fee.into()), Box::new(fee), call, Weight::from_ref_time(1_000), Weight::from_ref_time(2_000))

schedule_auto_compound_delegated_stake_task_full {
let task_weight = <T as Config>::WeightInfo::run_auto_compound_delegated_stake_task().ref_time();
Expand Down Expand Up @@ -279,24 +287,23 @@ benchmarks! {

run_xcmp_task {
let caller: T::AccountId = account("caller", 0, SEED);
let currency_id: T::CurrencyId = T::GetNativeCurrencyId::get();
let time: u64 = 10800;
let para_id: u32 = 2001;
let call = vec![4,5,6];

let local_para_id: u32 = 2114;
let destination = MultiLocation::new(1, X1(Parachain(para_id)));
let local_sovereign_account: T::AccountId = Sibling::from(local_para_id).into_account_truncating();
T::Currency::deposit_creating(
&local_sovereign_account,
T::Currency::minimum_balance().saturating_mul(DEPOSIT_MULTIPLIER.into()),
);

let asset_location = MultiLocation::new(1, X1(Parachain(para_id)));
T::XcmpTransactor::setup_chain_asset_data(asset_location.clone())?;
let fee = AssetPayment { asset_location: MultiLocation::new(1, X1(Parachain(para_id))).into(), amount: 1000u128 };

let provided_id = schedule_xcmp_tasks::<T>(caller.clone(), vec![time], 1);
let task_id = Pallet::<T>::generate_task_id(caller.clone(), provided_id);
}: { AutomationTime::<T>::run_xcmp_task(para_id.clone().into(), caller, asset_location.into(), call, Weight::from_ref_time(100_000), task_id.clone()) }
}: { AutomationTime::<T>::run_xcmp_task(destination, caller, fee, call, Weight::from_ref_time(100_000), Weight::from_ref_time(200_000), task_id.clone(), InstructionSequence::PayThroughSovereignAccount) }

run_auto_compound_delegated_stake_task {
let delegator: T::AccountId = account("delegator", 0, SEED);
Expand Down
Loading

0 comments on commit 54272be

Please sign in to comment.