@@ -159,12 +159,16 @@ pub mod pallet {
159159 type InitialMaxAllowedValidators : Get < u16 > ;
160160 #[ pallet:: constant] // Initial default delegation take.
161161 type InitialDefaultTake : Get < u16 > ;
162+ #[ pallet:: constant] // Initial minimum delegation take.
163+ type InitialMinTake : Get < u16 > ;
162164 #[ pallet:: constant] // Initial weights version key.
163165 type InitialWeightsVersionKey : Get < u64 > ;
164166 #[ pallet:: constant] // Initial serving rate limit.
165167 type InitialServingRateLimit : Get < u64 > ;
166168 #[ pallet:: constant] // Initial transaction rate limit.
167169 type InitialTxRateLimit : Get < u64 > ;
170+ #[ pallet:: constant] // Initial delegate take transaction rate limit.
171+ type InitialTxDelegateTakeRateLimit : Get < u64 > ;
168172 #[ pallet:: constant] // Initial percentage of total stake required to join senate.
169173 type InitialSenateRequiredStakePercentage : Get < u64 > ;
170174 #[ pallet:: constant] // Initial adjustment alpha on burn and pow.
@@ -211,6 +215,10 @@ pub mod pallet {
211215 T :: InitialDefaultTake :: get ( )
212216 }
213217 #[ pallet:: type_value]
218+ pub fn DefaultMinTake < T : Config > ( ) -> u16 {
219+ T :: InitialMinTake :: get ( )
220+ }
221+ #[ pallet:: type_value]
214222 pub fn DefaultAccountTake < T : Config > ( ) -> u64 {
215223 0
216224 }
@@ -247,7 +255,9 @@ pub mod pallet {
247255 #[ pallet:: storage] // --- ITEM ( total_stake )
248256 pub type TotalStake < T > = StorageValue < _ , u64 , ValueQuery > ;
249257 #[ pallet:: storage] // --- ITEM ( default_take )
250- pub type DefaultTake < T > = StorageValue < _ , u16 , ValueQuery , DefaultDefaultTake < T > > ;
258+ pub type MaxTake < T > = StorageValue < _ , u16 , ValueQuery , DefaultDefaultTake < T > > ;
259+ #[ pallet:: storage] // --- ITEM ( min_take )
260+ pub type MinTake < T > = StorageValue < _ , u16 , ValueQuery , DefaultMinTake < T > > ;
251261 #[ pallet:: storage] // --- ITEM ( global_block_emission )
252262 pub type BlockEmission < T > = StorageValue < _ , u64 , ValueQuery , DefaultBlockEmission < T > > ;
253263 #[ pallet:: storage] // --- ITEM ( total_issuance )
@@ -584,15 +594,25 @@ pub mod pallet {
584594 T :: InitialTxRateLimit :: get ( )
585595 }
586596 #[ pallet:: type_value]
597+ pub fn DefaultTxDelegateTakeRateLimit < T : Config > ( ) -> u64 {
598+ T :: InitialTxDelegateTakeRateLimit :: get ( )
599+ }
600+ #[ pallet:: type_value]
587601 pub fn DefaultLastTxBlock < T : Config > ( ) -> u64 {
588602 0
589603 }
590604
591605 #[ pallet:: storage] // --- ITEM ( tx_rate_limit )
592606 pub ( super ) type TxRateLimit < T > = StorageValue < _ , u64 , ValueQuery , DefaultTxRateLimit < T > > ;
607+ #[ pallet:: storage] // --- ITEM ( tx_rate_limit )
608+ pub ( super ) type TxDelegateTakeRateLimit < T > =
609+ StorageValue < _ , u64 , ValueQuery , DefaultTxDelegateTakeRateLimit < T > > ;
593610 #[ pallet:: storage] // --- MAP ( key ) --> last_block
594611 pub ( super ) type LastTxBlock < T : Config > =
595612 StorageMap < _ , Identity , T :: AccountId , u64 , ValueQuery , DefaultLastTxBlock < T > > ;
613+ #[ pallet:: storage] // --- MAP ( key ) --> last_block
614+ pub ( super ) type LastTxBlockDelegateTake < T : Config > =
615+ StorageMap < _ , Identity , T :: AccountId , u64 , ValueQuery , DefaultLastTxBlock < T > > ;
596616
597617 #[ pallet:: type_value]
598618 pub fn DefaultServingRateLimit < T : Config > ( ) -> u64 {
@@ -902,7 +922,8 @@ pub mod pallet {
902922 MaxBurnSet ( u16 , u64 ) , // --- Event created when setting max burn on a network.
903923 MinBurnSet ( u16 , u64 ) , // --- Event created when setting min burn on a network.
904924 TxRateLimitSet ( u64 ) , // --- Event created when setting the transaction rate limit.
905- Sudid ( DispatchResult ) , // --- Event created when a sudo call is done.
925+ TxDelegateTakeRateLimitSet ( u64 ) , // --- Event created when setting the delegate take transaction rate limit.
926+ Sudid ( DispatchResult ) , // --- Event created when a sudo call is done.
906927 RegistrationAllowed ( u16 , bool ) , // --- Event created when registration is allowed/disallowed for a subnet.
907928 PowRegistrationAllowed ( u16 , bool ) , // --- Event created when POW registration is allowed/disallowed for a subnet.
908929 TempoSet ( u16 , u16 ) , // --- Event created when setting tempo on a network
@@ -917,11 +938,15 @@ pub mod pallet {
917938 NetworkMinLockCostSet ( u64 ) , // Event created when the network minimum locking cost is set.
918939 SubnetLimitSet ( u16 ) , // Event created when the maximum number of subnets is set
919940 NetworkLockCostReductionIntervalSet ( u64 ) , // Event created when the lock cost reduction is set
941+ TakeDecreased ( T :: AccountId , T :: AccountId , u16 ) , // Event created when the take for a delegate is decreased.
942+ TakeIncreased ( T :: AccountId , T :: AccountId , u16 ) , // Event created when the take for a delegate is increased.
920943 HotkeySwapped {
921944 coldkey : T :: AccountId ,
922945 old_hotkey : T :: AccountId ,
923946 new_hotkey : T :: AccountId ,
924947 } , // Event created when a hotkey is swapped
948+ MaxDelegateTakeSet ( u16 ) , // Event emitted when maximum delegate take is set by sudo/admin transaction
949+ MinDelegateTakeSet ( u16 ) , // Event emitted when minimum delegate take is set by sudo/admin transaction
925950 }
926951
927952 // Errors inform users that something went wrong.
@@ -989,6 +1014,7 @@ pub mod pallet {
9891014 NoNeuronIdAvailable , // -- Thrown when no neuron id is available
9901015 /// Thrown a stake would be below the minimum threshold for nominator validations
9911016 NomStakeBelowMinimumThreshold ,
1017+ InvalidTake , // --- Thrown when delegate take is being set out of bounds
9921018 }
9931019
9941020 // ==================
@@ -1335,6 +1361,89 @@ pub mod pallet {
13351361 Self :: do_become_delegate ( origin, hotkey, Self :: get_default_take ( ) )
13361362 }
13371363
1364+ // --- Allows delegates to decrease its take value.
1365+ //
1366+ // # Args:
1367+ // * 'origin': (<T as frame_system::Config>::Origin):
1368+ // - The signature of the caller's coldkey.
1369+ //
1370+ // * 'hotkey' (T::AccountId):
1371+ // - The hotkey we are delegating (must be owned by the coldkey.)
1372+ //
1373+ // * 'netuid' (u16):
1374+ // - Subnet ID to decrease take for
1375+ //
1376+ // * 'take' (u16):
1377+ // - The new stake proportion that this hotkey takes from delegations.
1378+ // The new value can be between 0 and 11_796 and should be strictly
1379+ // lower than the previous value. It T is the new value (rational number),
1380+ // the the parameter is calculated as [65535 * T]. For example, 1% would be
1381+ // [0.01 * 65535] = [655.35] = 655
1382+ //
1383+ // # Event:
1384+ // * TakeDecreased;
1385+ // - On successfully setting a decreased take for this hotkey.
1386+ //
1387+ // # Raises:
1388+ // * 'NotRegistered':
1389+ // - The hotkey we are delegating is not registered on the network.
1390+ //
1391+ // * 'NonAssociatedColdKey':
1392+ // - The hotkey we are delegating is not owned by the calling coldkey.
1393+ //
1394+ // * 'InvalidTransaction':
1395+ // - The delegate is setting a take which is not lower than the previous.
1396+ //
1397+ #[ pallet:: call_index( 65 ) ]
1398+ #[ pallet:: weight( ( 0 , DispatchClass :: Normal , Pays :: No ) ) ]
1399+ pub fn decrease_take (
1400+ origin : OriginFor < T > ,
1401+ hotkey : T :: AccountId ,
1402+ take : u16 ,
1403+ ) -> DispatchResult {
1404+ Self :: do_decrease_take ( origin, hotkey, take)
1405+ }
1406+
1407+ // --- Allows delegates to increase its take value. This call is rate-limited.
1408+ //
1409+ // # Args:
1410+ // * 'origin': (<T as frame_system::Config>::Origin):
1411+ // - The signature of the caller's coldkey.
1412+ //
1413+ // * 'hotkey' (T::AccountId):
1414+ // - The hotkey we are delegating (must be owned by the coldkey.)
1415+ //
1416+ // * 'take' (u16):
1417+ // - The new stake proportion that this hotkey takes from delegations.
1418+ // The new value can be between 0 and 11_796 and should be strictly
1419+ // greater than the previous value. It T is the new value (rational number),
1420+ // the the parameter is calculated as [65535 * T]. For example, 1% would be
1421+ // [0.01 * 65535] = [655.35] = 655
1422+ //
1423+ // # Event:
1424+ // * TakeDecreased;
1425+ // - On successfully setting a decreased take for this hotkey.
1426+ //
1427+ // # Raises:
1428+ // * 'NotRegistered':
1429+ // - The hotkey we are delegating is not registered on the network.
1430+ //
1431+ // * 'NonAssociatedColdKey':
1432+ // - The hotkey we are delegating is not owned by the calling coldkey.
1433+ //
1434+ // * 'InvalidTransaction':
1435+ // - The delegate is setting a take which is not lower than the previous.
1436+ //
1437+ #[ pallet:: call_index( 66 ) ]
1438+ #[ pallet:: weight( ( 0 , DispatchClass :: Normal , Pays :: No ) ) ]
1439+ pub fn increase_take (
1440+ origin : OriginFor < T > ,
1441+ hotkey : T :: AccountId ,
1442+ take : u16 ,
1443+ ) -> DispatchResult {
1444+ Self :: do_increase_take ( origin, hotkey, take)
1445+ }
1446+
13381447 // --- Adds stake to a hotkey. The call is made from the
13391448 // coldkey account linked in the hotkey.
13401449 // Only the associated coldkey is allowed to make staking and
0 commit comments