Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xcmp_fee for automation-time #366

Merged
merged 32 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2ec380a
Add asset_location param to get_local_currency_instructions function
imstar15 Jun 7, 2023
5ff1c93
Add Convert<MultiLocation, Option<TokenId>> to automationTime
imstar15 Jun 9, 2023
34748a6
Deduct fees based on different currency ID
imstar15 Jun 15, 2023
d86c890
Split DestinationAssetConfig into TransactInfoWithWeightLimit and Des…
imstar15 Jun 16, 2023
5655f79
Change the type of destination to VersionedMultiLocation
imstar15 Jun 19, 2023
8de84b6
Modify Mangata asset config
imstar15 Jun 20, 2023
d549846
Customize XCMP fee and weight.
imstar15 Jun 21, 2023
d1698e2
Fix typo
imstar15 Jun 23, 2023
b90f278
Calculate xcmp fee for alternate flow
imstar15 Jun 26, 2023
8d0318e
Remove xcmp fee and weight calculation
imstar15 Jun 26, 2023
307514e
Fix benchmark and tests
imstar15 Jun 27, 2023
7907b84
Fixing failed tests
imstar15 Jun 28, 2023
02b9b7e
Add migration
imstar15 Jun 28, 2023
24a9e9b
Code format
imstar15 Jun 29, 2023
08c7d3c
Fix schedule_xcmp_task_full test
imstar15 Jun 30, 2023
0c308e8
Remove TransactInfo storage
imstar15 Jul 3, 2023
de05ef0
Rename XcmFlow to XcmTaskSupported
imstar15 Jul 3, 2023
726fed6
Remove pallet_xcmp_handler storage in runtime configuration
imstar15 Jul 3, 2023
1f71fd1
Rename enum XcmTaskSupported to InstructionSequence
imstar15 Jul 4, 2023
50a7755
Change scheduleFee to MultiLcation
imstar15 Jul 5, 2023
1004b04
Fix the comment of AssetPayment
imstar15 Jul 6, 2023
e3f9a52
Extract instruction weight and fee to const variable in update_xcmp_t…
imstar15 Jul 6, 2023
ee0304e
Merge branch 'master' into xcmp-fee
imstar15 Jul 7, 2023
f159237
Merge branch 'master' into xcmp-fee
imstar15 Jul 7, 2023
7181568
Fix tests for the merged code
imstar15 Jul 7, 2023
617511c
Add calculate_schedule_fee_amount_works test
imstar15 Jul 7, 2023
69b8455
Merge branch 'master' into xcmp-fee
imstar15 Jul 8, 2023
c87f79d
Add calculate_schedule_fee_amount tests
imstar15 Jul 10, 2023
51eca0a
fixup: auto format Rust code
Jul 10, 2023
ab435de
Add tests for all types of automation-time action
imstar15 Jul 11, 2023
e1c1e0e
Set num_of_execution to a random number
imstar15 Jul 12, 2023
f4f6132
Add comment for schedule_xcmp_task , schedule_xcmp_task_through_proxy…
imstar15 Jul 12, 2023
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
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),
v9n marked this conversation as resolved.
Show resolved Hide resolved
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to update our document (or oak.js) somewhere about this structure change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to do two things about these changes.

  1. Create a changelog list for existing dapp partners, and ask them to test the new extrinsics in Turing Staging.
  2. Update docs.oak.tech with the latest details of extrinsics.

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