Skip to content

Commit 3f973fc

Browse files
authored
Merge pull request #2018 from opentensor/apply-start-call-more-tx
apply subtoken enable to more extrinsic
2 parents 5dbe102 + 481852c commit 3f973fc

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub trait SubnetInfo<AccountId> {
174174
fn exists(netuid: NetUid) -> bool;
175175
fn mechanism(netuid: NetUid) -> u16;
176176
fn is_owner(account_id: &AccountId, netuid: NetUid) -> bool;
177+
fn is_subtoken_enabled(netuid: NetUid) -> bool;
177178
}
178179

179180
pub trait BalanceOps<AccountId> {

pallets/subtensor/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,10 @@ impl<T: Config + pallet_balances::Config<Balance = u64>>
20492049
fn is_owner(account_id: &T::AccountId, netuid: NetUid) -> bool {
20502050
SubnetOwner::<T>::get(netuid) == *account_id
20512051
}
2052+
2053+
fn is_subtoken_enabled(netuid: NetUid) -> bool {
2054+
SubtokenEnabled::<T>::get(netuid)
2055+
}
20522056
}
20532057

20542058
impl<T: Config + pallet_balances::Config<Balance = u64>>

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ mod dispatches {
761761

762762
/// Attempt to adjust the senate membership to include a hotkey
763763
#[pallet::call_index(63)]
764-
#[pallet::weight((Weight::from_parts(75_430_000, 0)
764+
#[pallet::weight((Weight::from_parts(58_980_000, 0)
765765
.saturating_add(T::DbWeight::get().reads(7))
766766
.saturating_add(T::DbWeight::get().writes(4)), DispatchClass::Normal, Pays::Yes))]
767767
pub fn adjust_senate(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
@@ -1640,7 +1640,7 @@ mod dispatches {
16401640
///
16411641
#[pallet::call_index(89)]
16421642
#[pallet::weight((Weight::from_parts(377_400_000, 0)
1643-
.saturating_add(T::DbWeight::get().reads(30))
1643+
.saturating_add(T::DbWeight::get().reads(30_u64))
16441644
.saturating_add(T::DbWeight::get().writes(14)), DispatchClass::Normal, Pays::Yes))]
16451645
pub fn remove_stake_limit(
16461646
origin: OriginFor<T>,

pallets/swap/src/mock.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub const OK_HOTKEY_ACCOUNT_ID_RICH: AccountId = 1005;
3636
pub const NOT_SUBNET_OWNER: AccountId = 666;
3737
pub const NON_EXISTENT_NETUID: u16 = 999;
3838
pub const WRAPPING_FEES_NETUID: u16 = 124;
39-
39+
pub const SUBTOKEN_DISABLED_NETUID: u16 = 13579;
4040
parameter_types! {
4141
pub const BlockHashCount: u64 = 250;
4242
pub const SS58Prefix: u8 = 42;
@@ -115,6 +115,11 @@ impl SubnetInfo<AccountId> for MockLiquidityProvider {
115115
fn is_owner(account_id: &AccountId, _netuid: NetUid) -> bool {
116116
*account_id != NOT_SUBNET_OWNER
117117
}
118+
119+
// Only disable one subnet for testing
120+
fn is_subtoken_enabled(netuid: NetUid) -> bool {
121+
netuid.inner() != SUBTOKEN_DISABLED_NETUID
122+
}
118123
}
119124

120125
pub struct MockBalanceOps;

pallets/swap/src/pallet/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ mod pallet {
269269

270270
/// User liquidity operations are disabled for this subnet
271271
UserLiquidityDisabled,
272+
273+
/// The subnet does not have subtoken enabled
274+
SubtokenDisabled,
272275
}
273276

274277
#[pallet::call]
@@ -366,6 +369,11 @@ mod pallet {
366369
Error::<T>::SubNetworkDoesNotExist
367370
);
368371

372+
ensure!(
373+
T::SubnetInfo::is_subtoken_enabled(netuid.into()),
374+
Error::<T>::SubtokenDisabled
375+
);
376+
369377
let (position_id, tao, alpha) = Self::do_add_liquidity(
370378
netuid.into(),
371379
&coldkey,
@@ -489,6 +497,11 @@ mod pallet {
489497
Error::<T>::SubNetworkDoesNotExist
490498
);
491499

500+
ensure!(
501+
T::SubnetInfo::is_subtoken_enabled(netuid.into()),
502+
Error::<T>::SubtokenDisabled
503+
);
504+
492505
// Add or remove liquidity
493506
let result =
494507
Self::do_modify_position(netuid, &coldkey, &hotkey, position_id, liquidity_delta)?;

pallets/swap/src/pallet/tests.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,3 +1944,40 @@ fn test_less_price_movement() {
19441944
});
19451945
});
19461946
}
1947+
1948+
#[test]
1949+
fn test_swap_subtoken_disabled() {
1950+
new_test_ext().execute_with(|| {
1951+
let netuid = NetUid::from(SUBTOKEN_DISABLED_NETUID); // Use a netuid not used elsewhere
1952+
let price_low = 0.1;
1953+
let price_high = 0.2;
1954+
let tick_low = price_to_tick(price_low);
1955+
let tick_high = price_to_tick(price_high);
1956+
let liquidity = 1_000_000_u64;
1957+
1958+
assert_ok!(Pallet::<Test>::maybe_initialize_v3(netuid));
1959+
1960+
assert_noop!(
1961+
Pallet::<Test>::add_liquidity(
1962+
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
1963+
OK_HOTKEY_ACCOUNT_ID,
1964+
netuid,
1965+
tick_low,
1966+
tick_high,
1967+
liquidity,
1968+
),
1969+
Error::<Test>::SubtokenDisabled
1970+
);
1971+
1972+
assert_noop!(
1973+
Pallet::<Test>::modify_position(
1974+
RuntimeOrigin::signed(OK_COLDKEY_ACCOUNT_ID),
1975+
OK_HOTKEY_ACCOUNT_ID,
1976+
netuid,
1977+
PositionId::from(0),
1978+
liquidity as i64,
1979+
),
1980+
Error::<Test>::SubtokenDisabled
1981+
);
1982+
});
1983+
}

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
220220
// `spec_version`, and `authoring_version` are the same between Wasm and native.
221221
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
222222
// the compatible custom types.
223-
spec_version: 310,
223+
spec_version: 311,
224224
impl_version: 1,
225225
apis: RUNTIME_API_VERSIONS,
226226
transaction_version: 1,

0 commit comments

Comments
 (0)