Skip to content

Commit

Permalink
Add register ether command to control tool (#1361)
Browse files Browse the repository at this point in the history
* command boilerplate

* initial commit

* asset metadata

* comments

* make parameters default

* changed default symbol

* add governance update 2025
  • Loading branch information
alistair-singh authored Jan 20, 2025
1 parent e1bcd19 commit 01b2b53
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 27 deletions.
72 changes: 65 additions & 7 deletions control/preimage/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helpers::calculate_delivery_fee;
use crate::{
constants::*, Context, ForceCheckpointArgs, GatewayAddressArgs, GatewayOperatingModeEnum,
OperatingModeEnum, PricingParametersArgs, UpdateAssetArgs, UpgradeArgs,
OperatingModeEnum, PricingParametersArgs, RegisterEtherArgs, UpdateAssetArgs, UpgradeArgs,
};
use alloy_primitives::{utils::format_units, U256};
use codec::Encode;
Expand Down Expand Up @@ -31,9 +31,18 @@ use crate::bridge_hub_runtime::RuntimeCall as BridgeHubRuntimeCall;
#[cfg(feature = "polkadot")]
pub mod asset_hub_polkadot_types {
pub use crate::asset_hub_runtime::runtime_types::staging_xcm::v4::{
junction::Junction::AccountKey20, junction::Junction::GlobalConsensus, junction::NetworkId,
junctions::Junctions::X2, location::Location,
junction::Junction::AccountKey20,
junction::Junction::GlobalConsensus,
junction::NetworkId,
junctions::Junctions::{X1, X2},
location::Location,
};
pub fn get_ether_id(chain_id: u64) -> Location {
return Location {
parents: 2,
interior: X1([GlobalConsensus(NetworkId::Ethereum { chain_id })]),
};
}
pub fn get_asset_id(chain_id: u64, key: [u8; 20]) -> Location {
return Location {
parents: 2,
Expand All @@ -49,9 +58,17 @@ pub mod asset_hub_polkadot_types {
pub mod asset_hub_paseo_types {
pub use crate::asset_hub_runtime::runtime_types::staging_xcm::v3::multilocation::MultiLocation;
pub use crate::asset_hub_runtime::runtime_types::xcm::v3::{
junction::Junction::AccountKey20, junction::Junction::GlobalConsensus, junction::NetworkId,
junctions::Junctions::X2,
junction::Junction::AccountKey20,
junction::Junction::GlobalConsensus,
junction::NetworkId,
junctions::Junctions::{X1, X2},
};
pub fn get_ether_id(chain_id: u64) -> MultiLocation {
return MultiLocation {
parents: 2,
interior: X1(GlobalConsensus(NetworkId::Ethereum { chain_id })),
};
}
pub fn get_asset_id(chain_id: u64, key: [u8; 20]) -> MultiLocation {
return MultiLocation {
parents: 2,
Expand All @@ -66,9 +83,18 @@ pub mod asset_hub_paseo_types {
#[cfg(feature = "westend")]
pub mod asset_hub_westend_types {
pub use crate::asset_hub_runtime::runtime_types::staging_xcm::v5::{
junction::Junction::AccountKey20, junction::Junction::GlobalConsensus, junction::NetworkId,
junctions::Junctions::X2, location::Location,
junction::Junction::AccountKey20,
junction::Junction::GlobalConsensus,
junction::NetworkId,
junctions::Junctions::{X1, X2},
location::Location,
};
pub fn get_ether_id(chain_id: u64) -> Location {
return Location {
parents: 2,
interior: X1([GlobalConsensus(NetworkId::Ethereum { chain_id })]),
};
}
pub fn get_asset_id(chain_id: u64, key: [u8; 20]) -> Location {
return Location {
parents: 2,
Expand Down Expand Up @@ -309,3 +335,35 @@ pub fn force_set_metadata(params: &UpdateAssetArgs) -> AssetHubRuntimeCall {
is_frozen: params.is_frozen,
})
}

pub fn register_ether(params: &RegisterEtherArgs) -> (AssetHubRuntimeCall, AssetHubRuntimeCall) {
use subxt::utils::AccountId32;
let chain_id = crate::bridge_hub_runtime::CHAIN_ID;
#[cfg(feature = "paseo")]
use asset_hub_paseo_types::*;
#[cfg(feature = "polkadot")]
use asset_hub_polkadot_types::*;
#[cfg(feature = "westend")]
use asset_hub_westend_types::*;

let asset_id = get_ether_id(chain_id);
let owner = GlobalConsensusEthereumConvertsFor::<[u8; 32]>::from_chain_id(&chain_id);

let force_register =
AssetHubRuntimeCall::ForeignAssets(pallet_assets::pallet::Call2::force_create {
id: asset_id.clone(),
min_balance: params.ether_min_balance,
is_sufficient: true,
owner: MultiAddress::<AccountId32, ()>::Id(owner.into()),
});
let metadata =
AssetHubRuntimeCall::ForeignAssets(pallet_assets::pallet::Call2::force_set_metadata {
id: asset_id,
name: params.ether_name.as_bytes().to_vec(),
symbol: params.ether_symbol.as_bytes().to_vec(),
decimals: params.ether_decimals,
is_frozen: false,
});

return (force_register, metadata);
}
110 changes: 90 additions & 20 deletions control/preimage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ struct Cli {
#[arg(long, value_enum, default_value_t=Format::Hex)]
format: Format,

/// Wrap preimage in a sudo call
#[cfg(any(feature = "westend", feature = "paseo"))]
#[arg(long, default_value_t = false)]
sudo: bool,

#[command(flatten)]
api_endpoints: ApiEndpoints,

Expand All @@ -50,9 +55,14 @@ pub enum Command {
ForceCheckpoint(ForceCheckpointArgs),
/// Set the checkpoint for the beacon light client
HaltBridge(HaltBridgeArgs),
/// Register Ether
RegisterEther(RegisterEtherArgs),
/// Treasury proposal
TreasuryProposal2024(TreasuryProposal2024Args),
/// Governance update 202501
GovUpdate202501(GovUpdate202501Args),
}

#[derive(Debug, Args)]
pub struct InitializeArgs {
#[command(flatten)]
Expand All @@ -63,6 +73,8 @@ pub struct InitializeArgs {
force_checkpoint: ForceCheckpointArgs,
#[command(flatten)]
gateway_address: GatewayAddressArgs,
#[command(flatten)]
register_ether: RegisterEtherArgs,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -210,6 +222,30 @@ pub struct TreasuryProposal2024Args {
beneficiary: FixedBytes<32>,
}

#[derive(Debug, Args)]
pub struct GovUpdate202501Args {
#[command(flatten)]
pricing_parameters: PricingParametersArgs,
#[command(flatten)]
register_ether: RegisterEtherArgs,
}

#[derive(Debug, Args)]
pub struct RegisterEtherArgs {
/// The minimum balance of the Ether asset that users are allowed to hold
#[arg(long, value_name = "WEI", default_value_t = 1u128)]
ether_min_balance: u128,
/// The Ether asset display name
#[arg(long, value_name = "ASSET_DISPLAY_NAME", default_value_t = String::from("Ether"))]
ether_name: String,
/// The Ether asset symbol
#[arg(long, value_name = "ASSET_SYMBOL", default_value_t = String::from("ETH"))]
ether_symbol: String,
/// The Ether asset's number of decimal places
#[arg(long, value_name = "DECIMALS", default_value_t = 18u8)]
ether_decimals: u8,
}

#[derive(Debug, Args)]
pub struct ApiEndpoints {
#[arg(long, value_name = "URL")]
Expand Down Expand Up @@ -312,7 +348,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
Command::Initialize(params) => {
let (set_pricing_parameters, set_ethereum_fee) =
commands::pricing_parameters(&context, &params.pricing_parameters).await?;
let call1 = send_xcm_bridge_hub(
let bridge_hub_call = send_xcm_bridge_hub(
&context,
vec![
commands::set_gateway_address(&params.gateway_address),
Expand All @@ -324,29 +360,29 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
],
)
.await?;
let call2 =
send_xcm_asset_hub(&context, vec![force_xcm_version(), set_ethereum_fee]).await?;
#[cfg(any(feature = "westend", feature = "paseo"))]
let final_call = sudo(Box::new(utility_force_batch(vec![call1, call2])));
#[cfg(not(any(feature = "westend", feature = "paseo")))]
let final_call = utility_force_batch(vec![call1, call2]);
final_call
let (register_ether_call, set_ether_metadata_call) =
commands::register_ether(&params.register_ether);
let asset_hub_call = send_xcm_asset_hub(
&context,
vec![
register_ether_call,
set_ether_metadata_call,
force_xcm_version(),
set_ethereum_fee,
],
)
.await?;
utility_force_batch(vec![bridge_hub_call, asset_hub_call])
}
Command::UpdateAsset(params) => {
let call = send_xcm_asset_hub(
send_xcm_asset_hub(
&context,
vec![
commands::make_asset_sufficient(params),
commands::force_set_metadata(params),
],
)
.await?;

#[cfg(any(feature = "westend", feature = "paseo"))]
let final_call = sudo(Box::new(call));
#[cfg(not(any(feature = "westend", feature = "paseo")))]
let final_call = call;
final_call
.await?
}
Command::GatewayOperatingMode(params) => {
let call = commands::gateway_operating_mode(&params.gateway_operating_mode);
Expand All @@ -359,9 +395,10 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
Command::PricingParameters(params) => {
let (set_pricing_parameters, set_ethereum_fee) =
commands::pricing_parameters(&context, params).await?;
let call1 = send_xcm_bridge_hub(&context, vec![set_pricing_parameters]).await?;
let call2 = send_xcm_asset_hub(&context, vec![set_ethereum_fee]).await?;
utility_force_batch(vec![call1, call2])
let bridge_hub_call =
send_xcm_bridge_hub(&context, vec![set_pricing_parameters]).await?;
let asset_hub_call = send_xcm_asset_hub(&context, vec![set_ethereum_fee]).await?;
utility_force_batch(vec![bridge_hub_call, asset_hub_call])
}
Command::HaltBridge(params) => {
let mut bh_calls = vec![];
Expand Down Expand Up @@ -409,10 +446,43 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
utility_force_batch(vec![call1, call2])
}
}
Command::RegisterEther(params) => {
let (register_ether_call, set_ether_metadata_call) = commands::register_ether(&params);
send_xcm_asset_hub(&context, vec![register_ether_call, set_ether_metadata_call]).await?
}
Command::TreasuryProposal2024(params) => treasury_commands::treasury_proposal(&params),
Command::GovUpdate202501(GovUpdate202501Args {
pricing_parameters,
register_ether,
}) => {
let (set_pricing_parameters, set_ethereum_fee) =
commands::pricing_parameters(&context, pricing_parameters).await?;

let bh_set_pricing_call =
send_xcm_bridge_hub(&context, vec![set_pricing_parameters]).await?;

let ah_set_pricing_call = send_xcm_asset_hub(&context, vec![set_ethereum_fee]).await?;

let (register_ether_call, set_ether_metadata_call) =
commands::register_ether(&register_ether);
let ah_register_ether_call =
send_xcm_asset_hub(&context, vec![register_ether_call, set_ether_metadata_call])
.await?;

utility_force_batch(vec![
bh_set_pricing_call,
ah_set_pricing_call,
ah_register_ether_call,
])
}
};

let preimage = call.encode();
#[cfg(any(feature = "westend", feature = "paseo"))]
let final_call = if cli.sudo { sudo(Box::new(call)) } else { call };
#[cfg(not(any(feature = "westend", feature = "paseo")))]
let final_call = call;

let preimage = final_call.encode();

generate_chopsticks_script(&preimage, "chopsticks-execute-upgrade.js".into())?;

Expand Down

0 comments on commit 01b2b53

Please sign in to comment.