Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2c68387
delegates can set the claim type for all their delegates
Nov 20, 2025
6c50312
record flow
Nov 20, 2025
12b7af2
ran fmt
Nov 20, 2025
badae21
claim type
Nov 20, 2025
03908e3
fixes
Nov 20, 2025
13b2ee1
fmt
Nov 20, 2025
2f70212
Keep default
Nov 21, 2025
d12bcfc
add tests fix errors
Nov 21, 2025
857e59e
commit Cargo.lock
sam0x17 Nov 21, 2025
ad3a0d1
fix
sam0x17 Nov 21, 2025
f743b87
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 Nov 21, 2025
26c9a3e
bump spec version
sam0x17 Nov 21, 2025
665b72f
bump spec version
sam0x17 Nov 24, 2025
eaf07dc
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 Nov 24, 2025
43896e2
Merge branch 'root-claim-upgrade2' into delegate_set_claim_type
shamil-gadelshin Nov 24, 2025
9b34a03
Fix set_validator_claim_type
shamil-gadelshin Nov 24, 2025
c991786
Merge branch 'devnet-ready' into _delegate_set_claim_type
shamil-gadelshin Nov 25, 2025
d536c5f
Merge branch 'devnet-ready' into delegate_set_claim_type
shamil-gadelshin Nov 26, 2025
7ab6ade
Add SubnetTaoFlow test.
shamil-gadelshin Dec 4, 2025
c7c6747
Merge branch 'devnet-ready' into delegate_set_claim_type
shamil-gadelshin Dec 5, 2025
e55109d
Modify ValidatorClaimTypeSet event
shamil-gadelshin Dec 5, 2025
7b53c20
Bump spec version.
shamil-gadelshin Dec 5, 2025
897a623
Merge branch 'devnet-ready' into delegate_set_claim_type
shamil-gadelshin Dec 8, 2025
75f6845
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 Dec 8, 2025
6c38494
Merge remote-tracking branch 'origin/devnet-ready' into delegate_set_…
sam0x17 Dec 8, 2025
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
19 changes: 18 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ pub mod pallet {
Swap,
/// Keep all alpha emission.
Keep,
/// Delegate choice to subnet.
Delegated,
}

/// Enum for the per-coldkey root claim frequency setting.
Expand All @@ -359,7 +361,11 @@ pub mod pallet {
/// This is set by the user. Either swap to TAO or keep as alpha.
#[pallet::type_value]
pub fn DefaultRootClaimType<T: Config>() -> RootClaimTypeEnum {
RootClaimTypeEnum::default()
RootClaimTypeEnum::Delegated
}
#[pallet::type_value]
pub fn DefaultDelegateClaimType<T: Config>() -> RootClaimTypeEnum {
RootClaimTypeEnum::Keep
}

/// Default number of root claims per claim call.
Expand Down Expand Up @@ -2244,6 +2250,17 @@ pub mod pallet {
ValueQuery,
DefaultRootClaimType<T>,
>;
#[pallet::storage] // -- MAP ( hotkey, netuid ) --> delegate_claim_type enum
pub type DelegateClaimType<T: Config> = StorageMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,
u16,
RootClaimTypeEnum,
ValueQuery,
DefaultRootClaimType<T>,
>;
#[pallet::storage] // --- MAP ( u64 ) --> coldkey | Maps coldkeys that have stake to an index
pub type StakingColdkeysByIndex<T: Config> =
StorageMap<_, Identity, u64, T::AccountId, OptionQuery>;
Expand Down
36 changes: 36 additions & 0 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,5 +2421,41 @@ mod dispatches {

Ok(())
}

/// --- Sets delegate claim type for a hotkey on a subnet.
#[pallet::call_index(125)]
#[pallet::weight((
Weight::from_parts(5_711_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
DispatchClass::Operational,
Pays::Yes
))]
pub fn set_delegate_claim_type(
origin: OriginFor<T>,
hotkey: T::AccountId,
netuid: NetUid,
new_claim_type: RootClaimTypeEnum,
) -> DispatchResult {
let coldkey: T::AccountId = ensure_signed(origin)?;
ensure!(
Self::coldkey_owns_hotkey(coldkey.clone(), hotkey.clone()),
Error::<T>::NonAssociatedColdKey
);

// Ensure the delegate claim type is not Delegated.
ensure!(
matches!(
new_claim_type,
RootClaimTypeEnum::Swap | RootClaimTypeEnum::Keep
),
Error::<T>::InvalidRootClaimType
);

DelegateClaimType::<T>::insert((hotkey.clone(), netuid), new_claim_type.clone());
Self::deposit_event(Event::DelegateClaimTypeSet {
hotkey: hotkey.clone(),
root_claim_type: new_claim_type,
});
Ok(())
}
}
}
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,7 @@ mod errors {
InvalidRootClaimThreshold,
/// Exceeded subnet limit number or zero.
InvalidSubnetNumber,
/// Delegates cant set delegated as claim type
InvalidRootClaimType,
}
}
9 changes: 9 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,15 @@ mod events {
root_claim_type: RootClaimTypeEnum,
},

/// Root claim type for a coldkey has been set.
/// Parameters:
/// (coldkey, u8)
DelegateClaimTypeSet {
/// delegate hotkey
hotkey: T::AccountId,
root_claim_type: RootClaimTypeEnum,
},

/// Subnet lease dividends have been distributed.
SubnetLeaseDividendsDistributed {
/// The lease ID
Expand Down
19 changes: 16 additions & 3 deletions pallets/subtensor/src/staking/claim_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<T: Config> Pallet<T> {
hotkey: &T::AccountId,
coldkey: &T::AccountId,
netuid: NetUid,
root_claim_type: RootClaimTypeEnum,
mut root_claim_type: RootClaimTypeEnum,
ignore_minimum_condition: bool,
) {
// Subtract the root claimed.
Expand Down Expand Up @@ -157,6 +157,11 @@ impl<T: Config> Pallet<T> {
return; // no-op
}

// If root_claim_type is Delegated, switch to the delegate's actual claim type.
if (root_claim_type == RootClaimTypeEnum::Delegated) {
root_claim_type = DelegateClaimType::<T>::get(hotkey, netuid);
}

match root_claim_type {
// Increase stake on root
RootClaimTypeEnum::Swap => {
Expand All @@ -170,11 +175,13 @@ impl<T: Config> Pallet<T> {
Ok(owed_tao) => owed_tao,
Err(err) => {
log::error!("Error swapping alpha for TAO: {err:?}");

return;
}
};

// Importantly measures swap as flow.
Self::record_tao_outflow(netuid, owed_tao);

Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
hotkey,
coldkey,
Expand All @@ -189,14 +196,20 @@ impl<T: Config> Pallet<T> {
);
}
RootClaimTypeEnum::Keep => {
// Increase the stake with the alpha owned
// Increase the stake with the alpha owed
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
hotkey,
coldkey,
netuid,
owed_u64.into(),
);
}
// Add Delegated arm for completeness, but it should never reach here due to switch above.
RootClaimTypeEnum::Delegated => {
// Should not reach here. Added for completeness.
log::error!("Delegated root_claim_type should have been switched. Skipping.");
return;
}
};

// Increase root claimed by owed amount.
Expand Down
Loading