Skip to content

Commit

Permalink
remove unused deps
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Jan 8, 2025
1 parent 24a05a6 commit e324b6c
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 386 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

18 changes: 9 additions & 9 deletions modules/ismp/pallets/token-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ license = "Apache-2.0"
repository = "https://github.com/polytope-labs/hyperbridge"
homepage = "https://docs.hyperbridge.network/developers/polkadot/tokengateway"
documentation = "https://docs.rs/pallet-token-gateway"
keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability", "pallet-assets"]
keywords = [
"substrate",
"polkadot-sdk",
"ISMP",
"interoperability",
"pallet-assets",
]
readme = "./README.md"

[dependencies]
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-benchmarking = { workspace = true}
frame-benchmarking = { workspace = true }
sp-runtime = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
Expand All @@ -35,10 +41,6 @@ alloy-sol-types = { workspace = true }
token-gateway-primitives = { workspace = true }
pallet-hyperbridge = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true }
pallet-assets = { workspace = true}

[features]
default = ["std"]
std = [
Expand All @@ -57,13 +59,11 @@ std = [
"alloy-primitives/std",
"pallet-hyperbridge/std",
"token-gateway-primitives/std",
"pallet-balances/std",
"pallet-assets/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = []
try-runtime = []
281 changes: 122 additions & 159 deletions modules/ismp/pallets/token-gateway/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,190 +2,153 @@

use crate::*;
use frame_benchmarking::v2::*;
use frame_support::BoundedVec;
use frame_support::{
traits::{fungible, fungibles},
BoundedVec,
};
use frame_system::RawOrigin;
use ismp::host::StateMachine;
use pallet_balances::AdjustmentDirection;
use scale_info::prelude::collections::BTreeMap;
use sp_runtime::{traits::StaticLookup, AccountId32};
use sp_runtime::AccountId32;
use token_gateway_primitives::{GatewayAssetRegistration, GatewayAssetUpdate};

fn dummy_teleport_asset<T>(
asset_id: AssetId<T>,
) -> TeleportParams<AssetId<T>, <<T as Config>::NativeCurrency as Currency<T::AccountId>>::Balance>
where
T: Config,
<<T as Config>::Assets as fungibles::Inspect<T::AccountId>>::AssetId: From<H256>,
<<T as Config>::NativeCurrency as Currency<T::AccountId>>::Balance: From<u128>,
where
T: Config,
<<T as Config>::NativeCurrency as Currency<T::AccountId>>::Balance: From<u128>,
{
TeleportParams {
asset_id: <<T as Config>::Assets as fungibles::Inspect<T::AccountId>>::AssetId::from(
H256::zero(),
),
destination: StateMachine::Evm(100),
recepient: H256::from([1u8; 32]),
amount: 1100000000u128.into(),
timeout: 10,
token_gateway: vec![1, 2, 3, 4, 5],
relayer_fee: 1000000002u128.into(),
}
TeleportParams {
asset_id,
destination: StateMachine::Evm(100),
recepient: H256::from([1u8; 32]),
amount: 1100000000u128.into(),
timeout: 10,
token_gateway: vec![1, 2, 3, 4, 5],
relayer_fee: 1000000002u128.into(),
}
}

fn create_dummy_asset<T: Config>(
asset_details: GatewayAssetRegistration,
asset_details: GatewayAssetRegistration,
) -> AssetRegistration<AssetId<T>>
where
<<T as Config>::Assets as fungibles::Inspect<T::AccountId>>::AssetId: From<H256>,
where
{
AssetRegistration { local_id: H256::zero().into(), reg: asset_details }
let local_id = T::AssetIdFactory::create_asset_id(asset_details.symbol.to_vec()).unwrap();
AssetRegistration { local_id, reg: asset_details }
}

#[benchmarks(
where
T: pallet_balances::Config<Balance = u128>,
T: pallet_assets::Config<AssetIdParameter = sp_core::H256,Balance = u128>,
<<T as Config>::Assets as fungibles::Inspect<T::AccountId>>::AssetId: From<H256>,
<<T as Config>::NativeCurrency as Currency<T::AccountId>>::Balance: From<u128>,
<T as frame_system::Config>::AccountId: From<[u8; 32]>,
u128: From<<<T as Config>::NativeCurrency as Currency<T::AccountId>>::Balance>,
T::Balance: From<u128>,
<T as pallet_ismp::Config>::Balance: From<<<T as Config>::NativeCurrency as Currency<T::AccountId>>::Balance>,
<<T as Config>::Assets as fungibles::Inspect<T::AccountId>>::Balance: From<<<T as Config>::NativeCurrency as Currency<T::AccountId>>::Balance>,
<<T as Config>::Assets as fungibles::Inspect<T::AccountId>>::Balance: From<u128>,
[u8; 32]: From<<T as frame_system::Config>::AccountId>,
<T as frame_system::Config>::RuntimeOrigin: From<frame_system::RawOrigin<AccountId32>>,
)]
mod benches {
use super::*;

#[benchmark]
fn create_erc6160_asset() -> Result<(), BenchmarkError> {
let account: T::AccountId = whitelisted_caller();

let asset_details = GatewayAssetRegistration {
name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(),
symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(),
chains: vec![StateMachine::Evm(100)],
minimum_balance: Some(10),
};
let asset = create_dummy_asset::<T>(asset_details);

// Set balances
let ed = <T as pallet_balances::Config>::ExistentialDeposit::get();

// Adjust total issuance
pallet_balances::Pallet::<T>::force_adjust_total_issuance(
RawOrigin::Root.into(),
AdjustmentDirection::Increase,
ed * 1000,
)?;

let acc = <<T as frame_system::Config>::Lookup as StaticLookup>::unlookup(account.clone());

pallet_balances::Pallet::<T>::force_set_balance(RawOrigin::Root.into(), acc, ed * 100u128)?;

#[extrinsic_call]
_(RawOrigin::Signed(account), asset);

Ok(())
}

#[benchmark]
fn teleport() -> Result<(), BenchmarkError> {
let account: T::AccountId = whitelisted_caller();

let asset_details = GatewayAssetRegistration {
name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(),
symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(),
chains: vec![StateMachine::Evm(100)],
minimum_balance: None,
};
let asset = create_dummy_asset::<T>(asset_details);

Pallet::<T>::create_erc6160_asset(RawOrigin::Signed(account.clone()).into(), asset)?;

let dummy_teleport_params = dummy_teleport_asset::<T>();

// Set balances
let ed = <T as pallet_balances::Config>::ExistentialDeposit::get();

// Adjust total issuance
pallet_balances::Pallet::<T>::force_adjust_total_issuance(
RawOrigin::Root.into(),
AdjustmentDirection::Increase,
ed * 1000,
)?;

let acc = <<T as frame_system::Config>::Lookup as StaticLookup>::unlookup(account.clone());

pallet_balances::Pallet::<T>::force_set_balance(
RawOrigin::Root.into(),
acc.clone(),
ed * 100u128,
)?;

#[extrinsic_call]
teleport(RawOrigin::Signed(account), dummy_teleport_params);
Ok(())
}

#[benchmark]
fn set_token_gateway_addresses(x: Linear<5, 100>) -> Result<(), BenchmarkError> {
let mut addresses = BTreeMap::new();
for i in 0..x {
let addr = i.to_string().as_bytes().to_vec();
addresses.insert(StateMachine::Evm(100), addr);
}

#[extrinsic_call]
_(RawOrigin::Root, addresses);
Ok(())
}

#[benchmark]
fn update_erc6160_asset() -> Result<(), BenchmarkError> {
let acc_origin: T::AccountId = whitelisted_caller();

let asset_details = GatewayAssetRegistration {
name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(),
symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(),
chains: vec![StateMachine::Evm(100)],
minimum_balance: None,
};
let asset = create_dummy_asset::<T>(asset_details);
let asset_id: H256 = sp_io::hashing::keccak_256(asset.reg.symbol.as_ref()).into();

// set balances

let acc_o =
<<T as frame_system::Config>::Lookup as StaticLookup>::unlookup(acc_origin.clone());
let ed = <T as pallet_balances::Config>::ExistentialDeposit::get();
pallet_balances::Pallet::<T>::force_set_balance(
RawOrigin::Root.into(),
acc_o.clone(),
ed * 100u128,
)?;

// set asset balance
pallet_assets::Pallet::<T>::create(
RawOrigin::Signed(acc_origin.clone()).into(),
H256::zero().into(),
acc_o.clone(),
1000000000,
)?;

Pallet::<T>::create_erc6160_asset(
RawOrigin::Signed(acc_origin.clone()).into(),
asset.clone(),
)?;

let asset_update = GatewayAssetUpdate {
asset_id,
add_chains: BoundedVec::try_from(vec![StateMachine::Evm(200)]).unwrap(),
remove_chains: BoundedVec::try_from(Vec::new()).unwrap(),
new_admins: BoundedVec::try_from(Vec::new()).unwrap(),
};

#[extrinsic_call]
_(RawOrigin::Signed(acc_origin), asset_update);
Ok(())
}
use super::*;

#[benchmark]
fn create_erc6160_asset() -> Result<(), BenchmarkError> {
let account: T::AccountId = whitelisted_caller();

let asset_details = GatewayAssetRegistration {
name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(),
symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(),
chains: vec![StateMachine::Evm(100)],
minimum_balance: Some(10),
};
let asset = create_dummy_asset::<T>(asset_details);

<T::Currency as fungible::Mutate<T::AccountId>>::set_balance(&account, u128::MAX.into());

#[extrinsic_call]
_(RawOrigin::Signed(account), asset);

Ok(())
}

#[benchmark]
fn teleport() -> Result<(), BenchmarkError> {
let account: T::AccountId = whitelisted_caller();

let asset_details = GatewayAssetRegistration {
name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(),
symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(),
chains: vec![StateMachine::Evm(100)],
minimum_balance: None,
};
let asset = create_dummy_asset::<T>(asset_details);

Pallet::<T>::create_erc6160_asset(
RawOrigin::Signed(account.clone()).into(),
asset.clone(),
)?;

let dummy_teleport_params = dummy_teleport_asset::<T>(asset.local_id);

<T::Currency as fungible::Mutate<T::AccountId>>::set_balance(&account, u128::MAX.into());

#[extrinsic_call]
teleport(RawOrigin::Signed(account), dummy_teleport_params);
Ok(())
}

#[benchmark]
fn set_token_gateway_addresses(x: Linear<5, 100>) -> Result<(), BenchmarkError> {
let mut addresses = BTreeMap::new();
for i in 0..x {
let addr = i.to_string().as_bytes().to_vec();
addresses.insert(StateMachine::Evm(100), addr);
}

#[extrinsic_call]
_(RawOrigin::Root, addresses);
Ok(())
}

#[benchmark]
fn update_erc6160_asset() -> Result<(), BenchmarkError> {
let acc_origin: T::AccountId = whitelisted_caller();

let asset_details = GatewayAssetRegistration {
name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(),
symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(),
chains: vec![StateMachine::Evm(100)],
minimum_balance: None,
};
let asset = create_dummy_asset::<T>(asset_details.clone());

// set balances
<T::Currency as fungible::Mutate<T::AccountId>>::set_balance(&acc_origin, u128::MAX.into());
let asset_id = T::AssetIdFactory::create_asset_id(asset_details.symbol.to_vec()).unwrap();
<T::Assets as fungibles::Create<T::AccountId>>::create(
asset_id.into(),
acc_origin.clone(),
true,
1000000000u128.into(),
)?;

Pallet::<T>::create_erc6160_asset(
RawOrigin::Signed(acc_origin.clone()).into(),
asset.clone(),
)?;

let asset_update = GatewayAssetUpdate {
asset_id: H256::zero(),
add_chains: BoundedVec::try_from(vec![StateMachine::Evm(200)]).unwrap(),
remove_chains: BoundedVec::try_from(Vec::new()).unwrap(),
new_admins: BoundedVec::try_from(Vec::new()).unwrap(),
};

#[extrinsic_call]
_(RawOrigin::Signed(acc_origin), asset_update);
Ok(())
}
}
Loading

0 comments on commit e324b6c

Please sign in to comment.