diff --git a/common/src/lib.rs b/common/src/lib.rs index 67fe4be51b..82f0916894 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -174,6 +174,7 @@ pub trait SubnetInfo { fn exists(netuid: NetUid) -> bool; fn mechanism(netuid: NetUid) -> u16; fn is_owner(account_id: &AccountId, netuid: NetUid) -> bool; + fn is_subtoken_enabled(netuid: NetUid) -> bool; } pub trait BalanceOps { diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 2a0d7e1de0..ba8a8b0370 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2049,6 +2049,10 @@ impl> fn is_owner(account_id: &T::AccountId, netuid: NetUid) -> bool { SubnetOwner::::get(netuid) == *account_id } + + fn is_subtoken_enabled(netuid: NetUid) -> bool { + SubtokenEnabled::::get(netuid) + } } impl> diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 6182444877..ad7b9fb107 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -761,7 +761,7 @@ mod dispatches { /// Attempt to adjust the senate membership to include a hotkey #[pallet::call_index(63)] - #[pallet::weight((Weight::from_parts(75_430_000, 0) + #[pallet::weight((Weight::from_parts(58_980_000, 0) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)), DispatchClass::Normal, Pays::Yes))] pub fn adjust_senate(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -1640,7 +1640,7 @@ mod dispatches { /// #[pallet::call_index(89)] #[pallet::weight((Weight::from_parts(377_400_000, 0) - .saturating_add(T::DbWeight::get().reads(30)) + .saturating_add(T::DbWeight::get().reads(30_u64)) .saturating_add(T::DbWeight::get().writes(14)), DispatchClass::Normal, Pays::Yes))] pub fn remove_stake_limit( origin: OriginFor, diff --git a/pallets/swap/src/mock.rs b/pallets/swap/src/mock.rs index 78a8f925c8..7a07cc7007 100644 --- a/pallets/swap/src/mock.rs +++ b/pallets/swap/src/mock.rs @@ -36,7 +36,7 @@ pub const OK_HOTKEY_ACCOUNT_ID_RICH: AccountId = 1005; pub const NOT_SUBNET_OWNER: AccountId = 666; pub const NON_EXISTENT_NETUID: u16 = 999; pub const WRAPPING_FEES_NETUID: u16 = 124; - +pub const SUBTOKEN_DISABLED_NETUID: u16 = 13579; parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; @@ -115,6 +115,11 @@ impl SubnetInfo for MockLiquidityProvider { fn is_owner(account_id: &AccountId, _netuid: NetUid) -> bool { *account_id != NOT_SUBNET_OWNER } + + // Only disable one subnet for testing + fn is_subtoken_enabled(netuid: NetUid) -> bool { + netuid.inner() != SUBTOKEN_DISABLED_NETUID + } } pub struct MockBalanceOps; diff --git a/pallets/swap/src/pallet/mod.rs b/pallets/swap/src/pallet/mod.rs index 894099de7f..442c4852aa 100644 --- a/pallets/swap/src/pallet/mod.rs +++ b/pallets/swap/src/pallet/mod.rs @@ -269,6 +269,9 @@ mod pallet { /// User liquidity operations are disabled for this subnet UserLiquidityDisabled, + + /// The subnet does not have subtoken enabled + SubtokenDisabled, } #[pallet::call] @@ -366,6 +369,11 @@ mod pallet { Error::::SubNetworkDoesNotExist ); + ensure!( + T::SubnetInfo::is_subtoken_enabled(netuid.into()), + Error::::SubtokenDisabled + ); + let (position_id, tao, alpha) = Self::do_add_liquidity( netuid.into(), &coldkey, @@ -489,6 +497,11 @@ mod pallet { Error::::SubNetworkDoesNotExist ); + ensure!( + T::SubnetInfo::is_subtoken_enabled(netuid.into()), + Error::::SubtokenDisabled + ); + // Add or remove liquidity let result = Self::do_modify_position(netuid, &coldkey, &hotkey, position_id, liquidity_delta)?; diff --git a/pallets/swap/src/pallet/tests.rs b/pallets/swap/src/pallet/tests.rs index 845acd957a..396bd656be 100644 --- a/pallets/swap/src/pallet/tests.rs +++ b/pallets/swap/src/pallet/tests.rs @@ -1944,3 +1944,40 @@ fn test_less_price_movement() { }); }); } + +#[test] +fn test_swap_subtoken_disabled() { + new_test_ext().execute_with(|| { + let netuid = NetUid::from(SUBTOKEN_DISABLED_NETUID); // Use a netuid not used elsewhere + let price_low = 0.1; + let price_high = 0.2; + let tick_low = price_to_tick(price_low); + let tick_high = price_to_tick(price_high); + let liquidity = 1_000_000_u64; + + assert_ok!(Pallet::::maybe_initialize_v3(netuid)); + + assert_noop!( + Pallet::::add_liquidity( + RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID), + OK_HOTKEY_ACCOUNT_ID, + netuid, + tick_low, + tick_high, + liquidity, + ), + Error::::SubtokenDisabled + ); + + assert_noop!( + Pallet::::modify_position( + RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID), + OK_HOTKEY_ACCOUNT_ID, + netuid, + PositionId::from(0), + liquidity as i64, + ), + Error::::SubtokenDisabled + ); + }); +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 644a85ebcd..a25f23482b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 310, + spec_version: 311, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,