Skip to content

Commit a5fc94a

Browse files
committed
cleanup and add sudo set for liquidity scale max
1 parent 4353aa9 commit a5fc94a

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

pallets/admin-utils/src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ pub mod pallet {
14481448
Ok(())
14491449
}
14501450

1451-
///
1451+
/// Change liquidity scale max for a given subnet.
14521452
///
14531453
/// # Arguments
14541454
/// * `origin` - The origin of the call, which must be the root account.
@@ -1476,6 +1476,36 @@ pub mod pallet {
14761476
);
14771477
Ok(())
14781478
}
1479+
1480+
///
1481+
///
1482+
/// # Arguments
1483+
/// * `origin` - The origin of the call, which must be the root account.
1484+
/// * `netuid` - The unique identifier for the subnet.
1485+
/// * `` -
1486+
///
1487+
/// # Errors
1488+
/// * `BadOrigin` - If the caller is not the root account.
1489+
///
1490+
/// # Weight
1491+
/// Weight is handled by the `#[pallet::weight]` attribute.
1492+
#[pallet::call_index(66)]
1493+
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1494+
pub fn sudo_set_liquidity_scale_max(
1495+
origin: OriginFor<T>,
1496+
netuid: u16,
1497+
liquidity_scale_max: u64,
1498+
) -> DispatchResult {
1499+
ensure_root(origin)?;
1500+
pallet_subtensor::LiquidityScaleMax::<T>::set(netuid, liquidity_scale_max);
1501+
1502+
log::debug!(
1503+
"LiquidityScaleMax( netuid: {:?}, liquidity_scale_max: {:?} )",
1504+
netuid,
1505+
liquidity_scale_max
1506+
);
1507+
Ok(())
1508+
}
14791509
}
14801510
}
14811511

pallets/admin-utils/src/tests/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,3 +1711,55 @@ fn test_sudo_set_ema_halving() {
17111711
assert_eq!(value_after_2, to_be_set);
17121712
});
17131713
}
1714+
1715+
#[test]
1716+
fn test_sudo_set_liquidity_scale_max() {
1717+
new_test_ext().execute_with(|| {
1718+
let netuid: u16 = 1;
1719+
let to_be_set: u64 = 1_234;
1720+
// install a subnet with owner = 10
1721+
add_network(netuid, 10);
1722+
1723+
// read the default
1724+
let before: u64 = pallet_subtensor::LiquidityScaleMax::<Test>::get(netuid);
1725+
1726+
// 1) wrong signed account → BadOrigin, no change
1727+
assert_eq!(
1728+
AdminUtils::sudo_set_liquidity_scale_max(
1729+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
1730+
netuid,
1731+
to_be_set
1732+
),
1733+
Err(DispatchError::BadOrigin)
1734+
);
1735+
assert_eq!(
1736+
pallet_subtensor::LiquidityScaleMax::<Test>::get(netuid),
1737+
before
1738+
);
1739+
1740+
// 2) subnet owner but not root → still BadOrigin
1741+
let owner = U256::from(10);
1742+
pallet_subtensor::SubnetOwner::<Test>::insert(netuid, owner);
1743+
assert_eq!(
1744+
AdminUtils::sudo_set_liquidity_scale_max(
1745+
<<Test as Config>::RuntimeOrigin>::signed(owner),
1746+
netuid,
1747+
to_be_set
1748+
),
1749+
Err(DispatchError::BadOrigin)
1750+
);
1751+
assert_eq!(
1752+
pallet_subtensor::LiquidityScaleMax::<Test>::get(netuid),
1753+
before
1754+
);
1755+
1756+
// 3) root origin → Ok, value updated
1757+
assert_ok!(AdminUtils::sudo_set_liquidity_scale_max(
1758+
<<Test as Config>::RuntimeOrigin>::root(),
1759+
netuid,
1760+
to_be_set
1761+
));
1762+
let after: u64 = pallet_subtensor::LiquidityScaleMax::<Test>::get(netuid);
1763+
assert_eq!(after, to_be_set);
1764+
});
1765+
}

pallets/subtensor/src/tests/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ parameter_types! {
185185
pub const InitialDissolveNetworkScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // Default as 5 days
186186
pub const InitialTaoWeight: u64 = 0; // 100% global weight.
187187
pub const InitialEmaPriceHalvingPeriod: u64 = 201_600_u64; // 4 weeks
188-
pub const LiquidityScaleMax: u64 = 2000; // TODO: figure out what this value should be
188+
pub const LiquidityScaleMax: u64 = 2000;
189189
pub const DurationOfStartCall: u64 = 7 * 24 * 60 * 60 / 12; // Default as 7 days
190190
}
191191

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ parameter_types! {
10441044
pub const InitialDissolveNetworkScheduleDuration: BlockNumber = 5 * 24 * 60 * 60 / 12; // 5 days
10451045
pub const SubtensorInitialTaoWeight: u64 = 971_718_665_099_567_868; // 0.05267697438728329% tao weight.
10461046
pub const InitialEmaPriceHalvingPeriod: u64 = 201_600_u64; // 4 weeks
1047-
pub const LiquidityScaleMax: u64 = 2000; // TODO: figure out what this should be
1047+
pub const LiquidityScaleMax: u64 = 2000;
10481048
pub const DurationOfStartCall: u64 = if cfg!(feature = "fast-blocks") {
10491049
10 // Only 10 blocks for fast blocks
10501050
} else {

0 commit comments

Comments
 (0)