Skip to content

Commit ae25f59

Browse files
author
unconst
committed
add toggle off for transfers
1 parent 2a57be4 commit ae25f59

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

pallets/admin-utils/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,27 @@ pub mod pallet {
12871287
ensure_root(origin)?;
12881288
T::Grandpa::schedule_change(next_authorities, in_blocks, forced)
12891289
}
1290+
1291+
/// Enables or disables Liquid Alpha for a given subnet.
1292+
///
1293+
/// # Parameters
1294+
/// - `origin`: The origin of the call, which must be the root account or subnet owner.
1295+
/// - `netuid`: The unique identifier for the subnet.
1296+
/// - `enabled`: A boolean flag to enable or disable Liquid Alpha.
1297+
///
1298+
/// # Weight
1299+
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
1300+
#[pallet::call_index(61)]
1301+
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1302+
pub fn sudo_set_toggle_transfer(
1303+
origin: OriginFor<T>,
1304+
netuid: u16,
1305+
toggle: bool,
1306+
) -> DispatchResult {
1307+
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
1308+
pallet_subtensor::Pallet::<T>::toggle_transfer(netuid, toggle)
1309+
}
1310+
12901311
}
12911312
}
12921313

pallets/subtensor/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,9 @@ pub mod pallet {
10691069
/// ============================
10701070
/// ==== Subnet Locks =====
10711071
/// ============================
1072+
#[pallet::storage] // --- MAP ( netuid ) --> transfer_toggle
1073+
pub type TransferToggle<T: Config> =
1074+
StorageMap<_, Identity, u16, bool, ValueQuery, DefaultTrue<T>>;
10721075
#[pallet::storage] // --- MAP ( netuid ) --> total_subnet_locked
10731076
pub type SubnetLocked<T: Config> =
10741077
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;

pallets/subtensor/src/macros/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,7 @@ mod errors {
189189
InsufficientLiquidity,
190190
/// Slippage is too high for the transaction.
191191
SlippageTooHigh,
192+
/// Subnet disallows transfer.
193+
TransferDisallowed,
192194
}
193195
}

pallets/subtensor/src/macros/events.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,12 @@ mod events {
265265
/// Parameters:
266266
/// (coldkey, hotkey, origin_netuid, destination_netuid, amount)
267267
StakeSwapped(T::AccountId, T::AccountId, u16, u16, u64),
268+
269+
/// Event called when transfer is toggled on a subnet.
270+
///
271+
/// Parameters:
272+
/// (netuid, bool)
273+
TransferToggle(u16, bool),
274+
268275
}
269276
}

pallets/subtensor/src/staking/move_stake.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ impl<T: Config> Pallet<T> {
9696
///
9797
/// # Events
9898
/// Emits a `StakeTransferred` event upon successful completion of the transfer.
99+
pub fn toggle_transfer(
100+
netuid: u16,
101+
toggle: bool
102+
) -> dispatch::DispatchResult {
103+
TransferToggle::<T>::insert( netuid, toggle );
104+
log::debug!(
105+
"TransferToggle( netuid: {:?}, toggle: {:?} ) ",
106+
netuid,
107+
toggle
108+
);
109+
Self::deposit_event(Event::TransferToggle(
110+
netuid,
111+
toggle
112+
));
113+
Ok(())
114+
}
99115
pub fn do_transfer_stake(
100116
origin: T::RuntimeOrigin,
101117
destination_coldkey: T::AccountId,
@@ -107,6 +123,16 @@ impl<T: Config> Pallet<T> {
107123
// Ensure the extrinsic is signed by the origin_coldkey.
108124
let coldkey = ensure_signed(origin)?;
109125

126+
// Ensure transfer is toggled.
127+
ensure!(
128+
TransferToggle::<T>::get( origin_netuid ),
129+
Error::<T>::TransferDisallowed
130+
);
131+
ensure!(
132+
TransferToggle::<T>::get( destination_netuid ),
133+
Error::<T>::TransferDisallowed
134+
);
135+
110136
// Validate input and move stake
111137
let tao_moved = Self::transition_stake_internal(
112138
&coldkey,

0 commit comments

Comments
 (0)