@@ -175,6 +175,15 @@ Staking reward configurations that will be stored with the @aptos_framework acco
175
175
## Constants
176
176
177
177
178
+ <a name =" 0x1_staking_config_MAX_U64 " ></a >
179
+
180
+
181
+
182
+ <pre ><code ><b >const</b > <a href =" staking_config.md#0x1_staking_config_MAX_U64 " >MAX_U64</a >: u128 = 18446744073709551615;
183
+ </code ></pre >
184
+
185
+
186
+
178
187
<a name =" 0x1_staking_config_BPS_DENOMINATOR " ></a >
179
188
180
189
Denominator of number in basis points. 1 bps(basis points) = 0.01%.
@@ -536,8 +545,7 @@ withdraw all funds).
536
545
537
546
## Function ` get_reward_rate `
538
547
539
- DEPRECATING
540
- Return the reward rate.
548
+ Return the reward rate of this epoch.
541
549
542
550
543
551
<pre ><code ><b >public</b > <b >fun</b > <a href =" staking_config.md#0x1_staking_config_get_reward_rate " >get_reward_rate</a >(config: &<a href =" staking_config.md#0x1_staking_config_StakingConfig " >staking_config::StakingConfig</a >): (u64, u64)
@@ -549,9 +557,25 @@ Return the reward rate.
549
557
<summary >Implementation</summary >
550
558
551
559
552
- <pre ><code ><b >public</b > <b >fun</b > <a href =" staking_config.md#0x1_staking_config_get_reward_rate " >get_reward_rate</a >(config: &<a href =" staking_config.md#0x1_staking_config_StakingConfig " >StakingConfig</a >): (u64, u64) {
553
- <b >assert</b >!(!<a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_periodical_reward_rate_decrease_enabled " >features::periodical_reward_rate_decrease_enabled</a >(), <a href =" staking_config.md#0x1_staking_config_EDEPRECATED_FUNCTION " >EDEPRECATED_FUNCTION</a >);
554
- (config.rewards_rate, config.rewards_rate_denominator)
560
+ <pre ><code ><b >public</b > <b >fun</b > <a href =" staking_config.md#0x1_staking_config_get_reward_rate " >get_reward_rate</a >(config: &<a href =" staking_config.md#0x1_staking_config_StakingConfig " >StakingConfig</a >): (u64, u64) <b >acquires</b > <a href =" staking_config.md#0x1_staking_config_StakingRewardsConfig " >StakingRewardsConfig</a > {
561
+ <b >let</b > (rewards_rate, rewards_rate_denominator) = <b >if</b > (<a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_periodical_reward_rate_decrease_enabled " >features::periodical_reward_rate_decrease_enabled</a >()) {
562
+ <b >let</b > epoch_rewards_rate = <b >borrow_global</b >< ; <a href =" staking_config.md#0x1_staking_config_StakingRewardsConfig " >StakingRewardsConfig</a >> ; (@aptos_framework).rewards_rate;
563
+ <b >if</b > (<a href =" ../../aptos-stdlib/doc/fixed_point64.md#0x1_fixed_point64_is_zero " >fixed_point64::is_zero</a >(epoch_rewards_rate)) {
564
+ (0u64, 1u64)
565
+ } <b >else</b > {
566
+ // Maximize denominator for higher precision.
567
+ // Restriction: nominator < ; = <a href =" staking_config.md#0x1_staking_config_MAX_REWARDS_RATE " >MAX_REWARDS_RATE</a > && denominator < ; = <a href =" staking_config.md#0x1_staking_config_MAX_U64 " >MAX_U64</a >
568
+ <b >let</b > denominator = <a href =" ../../aptos-stdlib/doc/fixed_point64.md#0x1_fixed_point64_divide_u128 " >fixed_point64::divide_u128</a >((<a href =" staking_config.md#0x1_staking_config_MAX_REWARDS_RATE " >MAX_REWARDS_RATE</a > <b >as</b > u128), epoch_rewards_rate);
569
+ <b >if</b > (denominator > ; <a href =" staking_config.md#0x1_staking_config_MAX_U64 " >MAX_U64</a >) {
570
+ denominator = <a href =" staking_config.md#0x1_staking_config_MAX_U64 " >MAX_U64</a >
571
+ };
572
+ <b >let</b > nominator = (<a href =" ../../aptos-stdlib/doc/fixed_point64.md#0x1_fixed_point64_multiply_u128 " >fixed_point64::multiply_u128</a >(denominator, epoch_rewards_rate) <b >as</b > u64);
573
+ (nominator, (denominator <b >as</b > u64))
574
+ }
575
+ } <b >else</b > {
576
+ (config.rewards_rate, config.rewards_rate_denominator)
577
+ };
578
+ (rewards_rate, rewards_rate_denominator)
555
579
}
556
580
</code ></pre >
557
581
@@ -1146,7 +1170,7 @@ StakingRewardsConfig does not exist under the aptos_framework before creating it
1146
1170
1147
1171
1148
1172
1149
- <pre ><code ><b >aborts_if </b > <a href =" ../../aptos-stdlib/../move-stdlib/doc/features. md#0x1_features_spec_reward_rate_decrease_enabled " >features::spec_reward_rate_decrease_enabled </a >() ;
1173
+ <pre ><code ><b >include </b > <a href =" staking_config. md#0x1_staking_config_StakingRewardsConfigRequirement " >StakingRewardsConfigRequirement </a >;
1150
1174
</code ></pre >
1151
1175
1152
1176
@@ -1163,7 +1187,7 @@ StakingRewardsConfig does not exist under the aptos_framework before creating it
1163
1187
1164
1188
1165
1189
<pre ><code ><b >aborts_if</b > !<b >exists</b >< ; <a href =" staking_config.md#0x1_staking_config_StakingRewardsConfig " >StakingRewardsConfig</a >> ; (@aptos_framework);
1166
- <b >aborts_if</b > !<a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_reward_rate_decrease_enabled " >features::spec_reward_rate_decrease_enabled </a >();
1190
+ <b >aborts_if</b > !<a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_periodical_reward_rate_decrease_enabled " >features::spec_periodical_reward_rate_decrease_enabled </a >();
1167
1191
<b >include</b > <a href =" staking_config.md#0x1_staking_config_StakingRewardsConfigRequirement " >StakingRewardsConfigRequirement</a >;
1168
1192
</code ></pre >
1169
1193
@@ -1180,7 +1204,7 @@ StakingRewardsConfig does not exist under the aptos_framework before creating it
1180
1204
1181
1205
1182
1206
1183
- <pre ><code ><b >requires</b > <a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_reward_rate_decrease_enabled " >features::spec_reward_rate_decrease_enabled </a >();
1207
+ <pre ><code ><b >requires</b > <a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_periodical_reward_rate_decrease_enabled " >features::spec_periodical_reward_rate_decrease_enabled </a >();
1184
1208
<b >include</b > <a href =" staking_config.md#0x1_staking_config_StakingRewardsConfigRequirement " >StakingRewardsConfigRequirement</a >;
1185
1209
<b >aborts_if</b > !<b >exists</b >< ; <a href =" staking_config.md#0x1_staking_config_StakingRewardsConfig " >StakingRewardsConfig</a >> ; (@aptos_framework);
1186
1210
</code ></pre >
@@ -1247,7 +1271,7 @@ The <code>rewards_rate</code> which is the numerator is limited to be <code><
1247
1271
rewards_rate/rewards_rate_denominator <= 1.
1248
1272
1249
1273
1250
- <pre ><code ><b >aborts_if</b > <a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_reward_rate_decrease_enabled " >features::spec_reward_rate_decrease_enabled </a >();
1274
+ <pre ><code ><b >aborts_if</b > <a href =" ../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_periodical_reward_rate_decrease_enabled " >features::spec_periodical_reward_rate_decrease_enabled </a >();
1251
1275
<b >let</b > addr = <a href =" ../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of " >signer::address_of</a >(aptos_framework);
1252
1276
<b >aborts_if</b > addr != @aptos_framework;
1253
1277
<b >aborts_if</b > new_rewards_rate_denominator < ; = 0;
0 commit comments