Skip to content

Commit 795c9bc

Browse files
committed
get weight from pallet
1 parent 36a32f1 commit 795c9bc

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

chain-extensions/src/lib.rs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use frame_system::RawOrigin;
1414
use pallet_contracts::chain_extension::{
1515
BufInBufOutState, ChainExtension, Environment, Ext, InitState, RetVal, SysConfig,
1616
};
17+
use pallet_subtensor::weights::WeightInfo as SubtensorWeightInfo;
1718
use pallet_subtensor_proxy as pallet_proxy;
1819
use pallet_subtensor_proxy::WeightInfo;
1920
use sp_runtime::{DispatchError, Weight, traits::StaticLookup};
@@ -69,9 +70,8 @@ where
6970
Env: SubtensorExtensionEnv<T>,
7071
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
7172
{
72-
let weight = Weight::from_parts(340_800_000, 0)
73-
.saturating_add(T::DbWeight::get().reads(24_u64))
74-
.saturating_add(T::DbWeight::get().writes(15));
73+
let weight =
74+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::add_stake();
7575

7676
env.charge_weight(weight)?;
7777

@@ -133,9 +133,8 @@ where
133133
Env: SubtensorExtensionEnv<T>,
134134
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
135135
{
136-
let weight = Weight::from_parts(28_830_000, 0)
137-
.saturating_add(T::DbWeight::get().reads(6))
138-
.saturating_add(T::DbWeight::get().writes(0));
136+
let weight =
137+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::unstake_all();
139138

140139
env.charge_weight(weight)?;
141140

@@ -162,9 +161,9 @@ where
162161
Env: SubtensorExtensionEnv<T>,
163162
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
164163
{
165-
let weight = Weight::from_parts(358_500_000, 0)
166-
.saturating_add(T::DbWeight::get().reads(36_u64))
167-
.saturating_add(T::DbWeight::get().writes(21_u64));
164+
let weight =
165+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::unstake_all_alpha(
166+
);
168167

169168
env.charge_weight(weight)?;
170169

@@ -191,9 +190,8 @@ where
191190
Env: SubtensorExtensionEnv<T>,
192191
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
193192
{
194-
let weight = Weight::from_parts(164_300_000, 0)
195-
.saturating_add(T::DbWeight::get().reads(15_u64))
196-
.saturating_add(T::DbWeight::get().writes(7_u64));
193+
let weight =
194+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::move_stake();
197195

198196
env.charge_weight(weight)?;
199197

@@ -233,9 +231,8 @@ where
233231
Env: SubtensorExtensionEnv<T>,
234232
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
235233
{
236-
let weight = Weight::from_parts(160_300_000, 0)
237-
.saturating_add(T::DbWeight::get().reads(13_u64))
238-
.saturating_add(T::DbWeight::get().writes(6_u64));
234+
let weight =
235+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::transfer_stake();
239236

240237
env.charge_weight(weight)?;
241238

@@ -275,9 +272,8 @@ where
275272
Env: SubtensorExtensionEnv<T>,
276273
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
277274
{
278-
let weight = Weight::from_parts(351_300_000, 0)
279-
.saturating_add(T::DbWeight::get().reads(35_u64))
280-
.saturating_add(T::DbWeight::get().writes(22_u64));
275+
let weight =
276+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::swap_stake();
281277

282278
env.charge_weight(weight)?;
283279

@@ -315,9 +311,8 @@ where
315311
Env: SubtensorExtensionEnv<T>,
316312
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
317313
{
318-
let weight = Weight::from_parts(402_900_000, 0)
319-
.saturating_add(T::DbWeight::get().reads(24_u64))
320-
.saturating_add(T::DbWeight::get().writes(15));
314+
let weight =
315+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::add_stake_limit();
321316

322317
env.charge_weight(weight)?;
323318

@@ -357,9 +352,8 @@ where
357352
Env: SubtensorExtensionEnv<T>,
358353
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
359354
{
360-
let weight = Weight::from_parts(377_400_000, 0)
361-
.saturating_add(T::DbWeight::get().reads(28_u64))
362-
.saturating_add(T::DbWeight::get().writes(14));
355+
let weight =
356+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::remove_stake_limit();
363357

364358
env.charge_weight(weight)?;
365359

@@ -399,9 +393,9 @@ where
399393
Env: SubtensorExtensionEnv<T>,
400394
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
401395
{
402-
let weight = Weight::from_parts(411_500_000, 0)
403-
.saturating_add(T::DbWeight::get().reads(35_u64))
404-
.saturating_add(T::DbWeight::get().writes(22_u64));
396+
let weight =
397+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::swap_stake_limit(
398+
);
405399

406400
env.charge_weight(weight)?;
407401

@@ -443,9 +437,7 @@ where
443437
Env: SubtensorExtensionEnv<T>,
444438
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
445439
{
446-
let weight = Weight::from_parts(395_300_000, 0)
447-
.saturating_add(T::DbWeight::get().reads(28_u64))
448-
.saturating_add(T::DbWeight::get().writes(14_u64));
440+
let weight = <<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::remove_stake_full_limit();
449441

450442
env.charge_weight(weight)?;
451443

@@ -477,9 +469,7 @@ where
477469
Env: SubtensorExtensionEnv<T>,
478470
<<T as SysConfig>::Lookup as StaticLookup>::Source: From<<T as SysConfig>::AccountId>,
479471
{
480-
let weight = Weight::from_parts(29_930_000, 0)
481-
.saturating_add(T::DbWeight::get().reads(4_u64))
482-
.saturating_add(T::DbWeight::get().writes(2_u64));
472+
let weight = <<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::set_coldkey_auto_stake_hotkey();
483473

484474
env.charge_weight(weight)?;
485475

0 commit comments

Comments
 (0)