Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub trait SubnetInfo<AccountId> {
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<AccountId> {
Expand Down
4 changes: 4 additions & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,10 @@ impl<T: Config + pallet_balances::Config<Balance = u64>>
fn is_owner(account_id: &T::AccountId, netuid: NetUid) -> bool {
SubnetOwner::<T>::get(netuid) == *account_id
}

fn is_subtoken_enabled(netuid: NetUid) -> bool {
SubtokenEnabled::<T>::get(netuid)
}
}

impl<T: Config + pallet_balances::Config<Balance = u64>>
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>, hotkey: T::AccountId) -> DispatchResult {
Expand Down Expand Up @@ -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<T>,
Expand Down
7 changes: 6 additions & 1 deletion pallets/swap/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,6 +115,11 @@ impl SubnetInfo<AccountId> 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;
Expand Down
13 changes: 13 additions & 0 deletions pallets/swap/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -366,6 +369,11 @@ mod pallet {
Error::<T>::SubNetworkDoesNotExist
);

ensure!(
T::SubnetInfo::is_subtoken_enabled(netuid.into()),
Error::<T>::SubtokenDisabled
);

let (position_id, tao, alpha) = Self::do_add_liquidity(
netuid.into(),
&coldkey,
Expand Down Expand Up @@ -489,6 +497,11 @@ mod pallet {
Error::<T>::SubNetworkDoesNotExist
);

ensure!(
T::SubnetInfo::is_subtoken_enabled(netuid.into()),
Error::<T>::SubtokenDisabled
);

// Add or remove liquidity
let result =
Self::do_modify_position(netuid, &coldkey, &hotkey, position_id, liquidity_delta)?;
Expand Down
37 changes: 37 additions & 0 deletions pallets/swap/src/pallet/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::maybe_initialize_v3(netuid));

assert_noop!(
Pallet::<Test>::add_liquidity(
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
OK_HOTKEY_ACCOUNT_ID,
netuid,
tick_low,
tick_high,
liquidity,
),
Error::<Test>::SubtokenDisabled
);

assert_noop!(
Pallet::<Test>::modify_position(
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
OK_HOTKEY_ACCOUNT_ID,
netuid,
PositionId::from(0),
liquidity as i64,
),
Error::<Test>::SubtokenDisabled
);
});
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down