@@ -159,12 +159,16 @@ pub mod pallet {
159
159
type InitialMaxAllowedValidators : Get < u16 > ;
160
160
#[ pallet:: constant] // Initial default delegation take.
161
161
type InitialDefaultTake : Get < u16 > ;
162
+ #[ pallet:: constant] // Initial minimum delegation take.
163
+ type InitialMinTake : Get < u16 > ;
162
164
#[ pallet:: constant] // Initial weights version key.
163
165
type InitialWeightsVersionKey : Get < u64 > ;
164
166
#[ pallet:: constant] // Initial serving rate limit.
165
167
type InitialServingRateLimit : Get < u64 > ;
166
168
#[ pallet:: constant] // Initial transaction rate limit.
167
169
type InitialTxRateLimit : Get < u64 > ;
170
+ #[ pallet:: constant] // Initial delegate take transaction rate limit.
171
+ type InitialTxDelegateTakeRateLimit : Get < u64 > ;
168
172
#[ pallet:: constant] // Initial percentage of total stake required to join senate.
169
173
type InitialSenateRequiredStakePercentage : Get < u64 > ;
170
174
#[ pallet:: constant] // Initial adjustment alpha on burn and pow.
@@ -211,6 +215,10 @@ pub mod pallet {
211
215
T :: InitialDefaultTake :: get ( )
212
216
}
213
217
#[ pallet:: type_value]
218
+ pub fn DefaultMinTake < T : Config > ( ) -> u16 {
219
+ T :: InitialMinTake :: get ( )
220
+ }
221
+ #[ pallet:: type_value]
214
222
pub fn DefaultAccountTake < T : Config > ( ) -> u64 {
215
223
0
216
224
}
@@ -247,7 +255,9 @@ pub mod pallet {
247
255
#[ pallet:: storage] // --- ITEM ( total_stake )
248
256
pub type TotalStake < T > = StorageValue < _ , u64 , ValueQuery > ;
249
257
#[ 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 > > ;
251
261
#[ pallet:: storage] // --- ITEM ( global_block_emission )
252
262
pub type BlockEmission < T > = StorageValue < _ , u64 , ValueQuery , DefaultBlockEmission < T > > ;
253
263
#[ pallet:: storage] // --- ITEM ( total_issuance )
@@ -584,15 +594,25 @@ pub mod pallet {
584
594
T :: InitialTxRateLimit :: get ( )
585
595
}
586
596
#[ pallet:: type_value]
597
+ pub fn DefaultTxDelegateTakeRateLimit < T : Config > ( ) -> u64 {
598
+ T :: InitialTxDelegateTakeRateLimit :: get ( )
599
+ }
600
+ #[ pallet:: type_value]
587
601
pub fn DefaultLastTxBlock < T : Config > ( ) -> u64 {
588
602
0
589
603
}
590
604
591
605
#[ pallet:: storage] // --- ITEM ( tx_rate_limit )
592
606
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 > > ;
593
610
#[ pallet:: storage] // --- MAP ( key ) --> last_block
594
611
pub ( super ) type LastTxBlock < T : Config > =
595
612
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 > > ;
596
616
597
617
#[ pallet:: type_value]
598
618
pub fn DefaultServingRateLimit < T : Config > ( ) -> u64 {
@@ -902,7 +922,8 @@ pub mod pallet {
902
922
MaxBurnSet ( u16 , u64 ) , // --- Event created when setting max burn on a network.
903
923
MinBurnSet ( u16 , u64 ) , // --- Event created when setting min burn on a network.
904
924
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.
906
927
RegistrationAllowed ( u16 , bool ) , // --- Event created when registration is allowed/disallowed for a subnet.
907
928
PowRegistrationAllowed ( u16 , bool ) , // --- Event created when POW registration is allowed/disallowed for a subnet.
908
929
TempoSet ( u16 , u16 ) , // --- Event created when setting tempo on a network
@@ -917,11 +938,15 @@ pub mod pallet {
917
938
NetworkMinLockCostSet ( u64 ) , // Event created when the network minimum locking cost is set.
918
939
SubnetLimitSet ( u16 ) , // Event created when the maximum number of subnets is set
919
940
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.
920
943
HotkeySwapped {
921
944
coldkey : T :: AccountId ,
922
945
old_hotkey : T :: AccountId ,
923
946
new_hotkey : T :: AccountId ,
924
947
} , // 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
925
950
}
926
951
927
952
// Errors inform users that something went wrong.
@@ -989,6 +1014,7 @@ pub mod pallet {
989
1014
NoNeuronIdAvailable , // -- Thrown when no neuron id is available
990
1015
/// Thrown a stake would be below the minimum threshold for nominator validations
991
1016
NomStakeBelowMinimumThreshold ,
1017
+ InvalidTake , // --- Thrown when delegate take is being set out of bounds
992
1018
}
993
1019
994
1020
// ==================
@@ -1335,6 +1361,89 @@ pub mod pallet {
1335
1361
Self :: do_become_delegate ( origin, hotkey, Self :: get_default_take ( ) )
1336
1362
}
1337
1363
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
+
1338
1447
// --- Adds stake to a hotkey. The call is made from the
1339
1448
// coldkey account linked in the hotkey.
1340
1449
// Only the associated coldkey is allowed to make staking and
0 commit comments