@@ -19,6 +19,7 @@ use codec::{Decode, Encode};
1919use frame_support:: sp_runtime:: transaction_validity:: InvalidTransaction ;
2020use frame_support:: sp_runtime:: transaction_validity:: ValidTransaction ;
2121use scale_info:: TypeInfo ;
22+ use sp_core:: Get ;
2223use sp_runtime:: {
2324 traits:: { DispatchInfoOf , Dispatchable , PostDispatchInfoOf , SignedExtension } ,
2425 transaction_validity:: { TransactionValidity , TransactionValidityError } ,
@@ -165,6 +166,8 @@ pub mod pallet {
165166 type InitialServingRateLimit : Get < u64 > ;
166167 #[ pallet:: constant] // Initial transaction rate limit.
167168 type InitialTxRateLimit : Get < u64 > ;
169+ #[ pallet:: constant] // Initial delegate take transaction rate limit.
170+ type InitialTxDelegateTakeRateLimit : Get < u64 > ;
168171 #[ pallet:: constant] // Initial percentage of total stake required to join senate.
169172 type InitialSenateRequiredStakePercentage : Get < u64 > ;
170173 #[ pallet:: constant] // Initial adjustment alpha on burn and pow.
@@ -582,15 +585,24 @@ pub mod pallet {
582585 T :: InitialTxRateLimit :: get ( )
583586 }
584587 #[ pallet:: type_value]
588+ pub fn DefaultTxDelegateTakeRateLimit < T : Config > ( ) -> u64 {
589+ T :: InitialTxDelegateTakeRateLimit :: get ( )
590+ }
591+ #[ pallet:: type_value]
585592 pub fn DefaultLastTxBlock < T : Config > ( ) -> u64 {
586593 0
587594 }
588595
589596 #[ pallet:: storage] // --- ITEM ( tx_rate_limit )
590597 pub ( super ) type TxRateLimit < T > = StorageValue < _ , u64 , ValueQuery , DefaultTxRateLimit < T > > ;
598+ #[ pallet:: storage] // --- ITEM ( tx_rate_limit )
599+ pub ( super ) type TxDelegateTakeRateLimit < T > = StorageValue < _ , u64 , ValueQuery , DefaultTxDelegateTakeRateLimit < T > > ;
591600 #[ pallet:: storage] // --- MAP ( key ) --> last_block
592601 pub ( super ) type LastTxBlock < T : Config > =
593602 StorageMap < _ , Identity , T :: AccountId , u64 , ValueQuery , DefaultLastTxBlock < T > > ;
603+ #[ pallet:: storage] // --- MAP ( key ) --> last_block
604+ pub ( super ) type LastTxBlockDelegateTake < T : Config > =
605+ StorageMap < _ , Identity , T :: AccountId , u64 , ValueQuery , DefaultLastTxBlock < T > > ;
594606
595607 #[ pallet:: type_value]
596608 pub fn DefaultServingRateLimit < T : Config > ( ) -> u64 {
@@ -899,6 +911,7 @@ pub mod pallet {
899911 MaxBurnSet ( u16 , u64 ) , // --- Event created when setting max burn on a network.
900912 MinBurnSet ( u16 , u64 ) , // --- Event created when setting min burn on a network.
901913 TxRateLimitSet ( u64 ) , // --- Event created when setting the transaction rate limit.
914+ TxDelegateTakeRateLimitSet ( u64 ) , // --- Event created when setting the delegate take transaction rate limit.
902915 Sudid ( DispatchResult ) , // --- Event created when a sudo call is done.
903916 RegistrationAllowed ( u16 , bool ) , // --- Event created when registration is allowed/disallowed for a subnet.
904917 PowRegistrationAllowed ( u16 , bool ) , // --- Event created when POW registration is allowed/disallowed for a subnet.
@@ -914,6 +927,8 @@ pub mod pallet {
914927 NetworkMinLockCostSet ( u64 ) , // Event created when the network minimum locking cost is set.
915928 SubnetLimitSet ( u16 ) , // Event created when the maximum number of subnets is set
916929 NetworkLockCostReductionIntervalSet ( u64 ) , // Event created when the lock cost reduction is set
930+ TakeDecreased ( T :: AccountId , T :: AccountId , u16 ) , // Event created when the take for a delegate is decreased.
931+ TakeIncreased ( T :: AccountId , T :: AccountId , u16 ) , // Event created when the take for a delegate is increased.
917932 HotkeySwapped {
918933 coldkey : T :: AccountId ,
919934 old_hotkey : T :: AccountId ,
@@ -986,6 +1001,7 @@ pub mod pallet {
9861001 NoNeuronIdAvailable , // -- Thrown when no neuron id is available
9871002 /// Thrown a stake would be below the minimum threshold for nominator validations
9881003 NomStakeBelowMinimumThreshold ,
1004+ InvalidTake , // --- Thrown when delegate take is being set out of bounds
9891005 }
9901006
9911007 // ==================
@@ -1325,6 +1341,89 @@ pub mod pallet {
13251341 Self :: do_become_delegate ( origin, hotkey, Self :: get_default_take ( ) )
13261342 }
13271343
1344+ // --- Allows delegates to decrease its take value.
1345+ //
1346+ // # Args:
1347+ // * 'origin': (<T as frame_system::Config>::Origin):
1348+ // - The signature of the caller's coldkey.
1349+ //
1350+ // * 'hotkey' (T::AccountId):
1351+ // - The hotkey we are delegating (must be owned by the coldkey.)
1352+ //
1353+ // * 'netuid' (u16):
1354+ // - Subnet ID to decrease take for
1355+ //
1356+ // * 'take' (u16):
1357+ // - The new stake proportion that this hotkey takes from delegations.
1358+ // The new value can be between 0 and 11_796 and should be strictly
1359+ // lower than the previous value. It T is the new value (rational number),
1360+ // the the parameter is calculated as [65535 * T]. For example, 1% would be
1361+ // [0.01 * 65535] = [655.35] = 655
1362+ //
1363+ // # Event:
1364+ // * TakeDecreased;
1365+ // - On successfully setting a decreased take for this hotkey.
1366+ //
1367+ // # Raises:
1368+ // * 'NotRegistered':
1369+ // - The hotkey we are delegating is not registered on the network.
1370+ //
1371+ // * 'NonAssociatedColdKey':
1372+ // - The hotkey we are delegating is not owned by the calling coldkey.
1373+ //
1374+ // * 'InvalidTransaction':
1375+ // - The delegate is setting a take which is not lower than the previous.
1376+ //
1377+ #[ pallet:: call_index( 65 ) ]
1378+ #[ pallet:: weight( ( 0 , DispatchClass :: Normal , Pays :: No ) ) ]
1379+ pub fn decrease_take (
1380+ origin : OriginFor < T > ,
1381+ hotkey : T :: AccountId ,
1382+ take : u16 ,
1383+ ) -> DispatchResult {
1384+ Self :: do_decrease_take ( origin, hotkey, take)
1385+ }
1386+
1387+ // --- Allows delegates to increase its take value. This call is rate-limited.
1388+ //
1389+ // # Args:
1390+ // * 'origin': (<T as frame_system::Config>::Origin):
1391+ // - The signature of the caller's coldkey.
1392+ //
1393+ // * 'hotkey' (T::AccountId):
1394+ // - The hotkey we are delegating (must be owned by the coldkey.)
1395+ //
1396+ // * 'take' (u16):
1397+ // - The new stake proportion that this hotkey takes from delegations.
1398+ // The new value can be between 0 and 11_796 and should be strictly
1399+ // greater than the previous value. It T is the new value (rational number),
1400+ // the the parameter is calculated as [65535 * T]. For example, 1% would be
1401+ // [0.01 * 65535] = [655.35] = 655
1402+ //
1403+ // # Event:
1404+ // * TakeDecreased;
1405+ // - On successfully setting a decreased take for this hotkey.
1406+ //
1407+ // # Raises:
1408+ // * 'NotRegistered':
1409+ // - The hotkey we are delegating is not registered on the network.
1410+ //
1411+ // * 'NonAssociatedColdKey':
1412+ // - The hotkey we are delegating is not owned by the calling coldkey.
1413+ //
1414+ // * 'InvalidTransaction':
1415+ // - The delegate is setting a take which is not lower than the previous.
1416+ //
1417+ #[ pallet:: call_index( 66 ) ]
1418+ #[ pallet:: weight( ( 0 , DispatchClass :: Normal , Pays :: No ) ) ]
1419+ pub fn increase_take (
1420+ origin : OriginFor < T > ,
1421+ hotkey : T :: AccountId ,
1422+ take : u16 ,
1423+ ) -> DispatchResult {
1424+ Self :: do_increase_take ( origin, hotkey, take)
1425+ }
1426+
13281427 // --- Adds stake to a hotkey. The call is made from the
13291428 // coldkey account linked in the hotkey.
13301429 // Only the associated coldkey is allowed to make staking and
0 commit comments