diff --git a/crates/iota-framework/docs/iota-system/iota_system.md b/crates/iota-framework/docs/iota-system/iota_system.md index 0d030e5f8a8..6d0a26cd061 100644 --- a/crates/iota-framework/docs/iota-system/iota_system.md +++ b/crates/iota-framework/docs/iota-system/iota_system.md @@ -1362,7 +1362,7 @@ gas coins. 4. Update all validators. -
fun advance_epoch(storage_reward: balance::Balance<iota::IOTA>, computation_reward: balance::Balance<iota::IOTA>, wrapper: &mut iota_system::IotaSystemState, new_epoch: u64, next_protocol_version: u64, storage_rebate: u64, non_refundable_storage_fee: u64, storage_fund_reinvest_rate: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &mut tx_context::TxContext): balance::Balance<iota::IOTA>
+
fun advance_epoch(storage_reward: balance::Balance<iota::IOTA>, computation_reward: balance::Balance<iota::IOTA>, wrapper: &mut iota_system::IotaSystemState, new_epoch: u64, next_protocol_version: u64, storage_rebate: u64, non_refundable_storage_fee: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &mut tx_context::TxContext): balance::Balance<iota::IOTA>
 
@@ -1379,8 +1379,6 @@ gas coins. next_protocol_version: u64, storage_rebate: u64, non_refundable_storage_fee: u64, - storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested - // into storage fund, in basis point. reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps. epoch_start_timestamp_ms: u64, // Timestamp of the epoch start ctx: &mut TxContext, @@ -1395,7 +1393,6 @@ gas coins. computation_reward, storage_rebate, non_refundable_storage_fee, - storage_fund_reinvest_rate, reward_slashing_rate, epoch_start_timestamp_ms, ctx, diff --git a/crates/iota-framework/docs/iota-system/iota_system_state_inner.md b/crates/iota-framework/docs/iota-system/iota_system_state_inner.md index d9229cd6374..b06adfc8c54 100644 --- a/crates/iota-framework/docs/iota-system/iota_system_state_inner.md +++ b/crates/iota-framework/docs/iota-system/iota_system_state_inner.md @@ -560,12 +560,6 @@ the epoch advancement transaction.
-
-
-storage_fund_reinvestment: u64 -
-
-
storage_charge: u64 @@ -2076,7 +2070,7 @@ gas coins. 4. Update all validators. -
public(friend) fun advance_epoch(self: &mut iota_system_state_inner::IotaSystemStateInnerV2, new_epoch: u64, next_protocol_version: u64, storage_reward: balance::Balance<iota::IOTA>, computation_reward: balance::Balance<iota::IOTA>, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64, storage_fund_reinvest_rate: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &mut tx_context::TxContext): balance::Balance<iota::IOTA>
+
public(friend) fun advance_epoch(self: &mut iota_system_state_inner::IotaSystemStateInnerV2, new_epoch: u64, next_protocol_version: u64, storage_reward: balance::Balance<iota::IOTA>, computation_reward: balance::Balance<iota::IOTA>, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &mut tx_context::TxContext): balance::Balance<iota::IOTA>
 
@@ -2093,8 +2087,6 @@ gas coins. mut computation_reward: Balance<IOTA>, mut storage_rebate_amount: u64, mut non_refundable_storage_fee_amount: u64, - storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested - // into storage fund, in basis point. reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps. epoch_start_timestamp_ms: u64, // Timestamp of the epoch start ctx: &mut TxContext, @@ -2104,11 +2096,7 @@ gas coins. let bps_denominator_u64 = BASIS_POINT_DENOMINATOR as u64; // Rates can't be higher than 100%. - assert!( - storage_fund_reinvest_rate <= bps_denominator_u64 - && reward_slashing_rate <= bps_denominator_u64, - EBpsTooLarge, - ); + assert!(reward_slashing_rate <= bps_denominator_u64, EBpsTooLarge); // TODO: remove this in later upgrade. if (self.parameters.stake_subsidy_start_epoch > 0) { @@ -2152,11 +2140,6 @@ gas coins. let storage_fund_reward_amount = storage_fund_balance as u128 * computation_charge_u128 / total_stake_u128; let mut storage_fund_reward = computation_reward.split(storage_fund_reward_amount as u64); - let storage_fund_reinvestment_amount = - storage_fund_reward_amount * (storage_fund_reinvest_rate as u128) / BASIS_POINT_DENOMINATOR; - let storage_fund_reinvestment = storage_fund_reward.split( - storage_fund_reinvestment_amount as u64, - ); self.epoch = self.epoch + 1; // Sanity check to make sure we are advancing to the right epoch. @@ -2194,11 +2177,10 @@ gas coins. leftover_staking_rewards.join(computation_reward); let leftover_storage_fund_inflow = leftover_staking_rewards.value(); + self.iota_treasury_cap.supply_mut().decrease_supply(leftover_staking_rewards); let refunded_storage_rebate = self.storage_fund.advance_epoch( storage_reward, - storage_fund_reinvestment, - leftover_staking_rewards, storage_rebate_amount, non_refundable_storage_fee_amount, ); @@ -2210,7 +2192,6 @@ gas coins. reference_gas_price: self.reference_gas_price, total_stake: new_total_stake, storage_charge, - storage_fund_reinvestment: storage_fund_reinvestment_amount as u64, storage_rebate: storage_rebate_amount, storage_fund_balance: self.storage_fund.total_balance(), stake_subsidy_amount, diff --git a/crates/iota-framework/docs/iota-system/storage_fund.md b/crates/iota-framework/docs/iota-system/storage_fund.md index a9205a960c8..4b21add2aa6 100644 --- a/crates/iota-framework/docs/iota-system/storage_fund.md +++ b/crates/iota-framework/docs/iota-system/storage_fund.md @@ -94,7 +94,7 @@ Called by iota_system Called by iota_system at epoch change times to process the inflows and outflows of storage fund. -
public(friend) fun advance_epoch(self: &mut storage_fund::StorageFund, storage_charges: balance::Balance<iota::IOTA>, storage_fund_reinvestment: balance::Balance<iota::IOTA>, leftover_staking_rewards: balance::Balance<iota::IOTA>, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64): balance::Balance<iota::IOTA>
+
public(friend) fun advance_epoch(self: &mut storage_fund::StorageFund, storage_charges: balance::Balance<iota::IOTA>, storage_rebate_amount: u64, _non_refundable_storage_fee_amount: u64): balance::Balance<iota::IOTA>
 
@@ -106,24 +106,15 @@ Called by iota_system
public(package) fun advance_epoch(
     self: &mut StorageFund,
     storage_charges: Balance<IOTA>,
-    storage_fund_reinvestment: Balance<IOTA>,
-    leftover_staking_rewards: Balance<IOTA>,
     storage_rebate_amount: u64,
-    non_refundable_storage_fee_amount: u64,
+    //TODO: try the way to configure
+    _non_refundable_storage_fee_amount: u64,
 ) : Balance<IOTA> {
-    // Both the reinvestment and leftover rewards are not to be refunded so they go to the non-refundable balance.
-    self.non_refundable_balance.join(storage_fund_reinvestment);
-    self.non_refundable_balance.join(leftover_staking_rewards);
-
     // The storage charges for the epoch come from the storage rebate of the new objects created
     // and the new storage rebates of the objects modified during the epoch so we put the charges
     // into `total_object_storage_rebates`.
     self.total_object_storage_rebates.join(storage_charges);
 
-    // Split out the non-refundable portion of the storage rebate and put it into the non-refundable balance.
-    let non_refundable_storage_fee = self.total_object_storage_rebates.split(non_refundable_storage_fee_amount);
-    self.non_refundable_balance.join(non_refundable_storage_fee);
-
     // `storage_rebates` include the already refunded rebates of deleted objects and old rebates of modified objects and
     // should be taken out of the `total_object_storage_rebates`.
     let storage_rebate = self.total_object_storage_rebates.split(storage_rebate_amount);
diff --git a/crates/iota-framework/packages/iota-system/sources/iota_system.move b/crates/iota-framework/packages/iota-system/sources/iota_system.move
index 4f01e7cf08f..e5f44f4c3a1 100644
--- a/crates/iota-framework/packages/iota-system/sources/iota_system.move
+++ b/crates/iota-framework/packages/iota-system/sources/iota_system.move
@@ -545,8 +545,6 @@ module iota_system::iota_system {
         next_protocol_version: u64,
         storage_rebate: u64,
         non_refundable_storage_fee: u64,
-        storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested
-                                         // into storage fund, in basis point.
         reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps.
         epoch_start_timestamp_ms: u64, // Timestamp of the epoch start
         ctx: &mut TxContext,
@@ -561,7 +559,6 @@ module iota_system::iota_system {
             computation_reward,
             storage_rebate,
             non_refundable_storage_fee,
-            storage_fund_reinvest_rate,
             reward_slashing_rate,
             epoch_start_timestamp_ms,
             ctx,
@@ -750,7 +747,6 @@ module iota_system::iota_system {
         computation_charge: u64,
         storage_rebate: u64,
         non_refundable_storage_fee: u64,
-        storage_fund_reinvest_rate: u64,
         reward_slashing_rate: u64,
         epoch_start_timestamp_ms: u64,
         ctx: &mut TxContext,
@@ -765,7 +761,6 @@ module iota_system::iota_system {
             next_protocol_version,
             storage_rebate,
             non_refundable_storage_fee,
-            storage_fund_reinvest_rate,
             reward_slashing_rate,
             epoch_start_timestamp_ms,
             ctx,
diff --git a/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move b/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move
index ceaf0a25532..cbc0d854cf5 100644
--- a/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move
+++ b/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move
@@ -207,7 +207,6 @@ module iota_system::iota_system_state_inner {
         protocol_version: u64,
         reference_gas_price: u64,
         total_stake: u64,
-        storage_fund_reinvestment: u64,
         storage_charge: u64,
         storage_rebate: u64,
         storage_fund_balance: u64,
@@ -831,8 +830,6 @@ module iota_system::iota_system_state_inner {
         mut computation_reward: Balance,
         mut storage_rebate_amount: u64,
         mut non_refundable_storage_fee_amount: u64,
-        storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested
-                                         // into storage fund, in basis point.
         reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps.
         epoch_start_timestamp_ms: u64, // Timestamp of the epoch start
         ctx: &mut TxContext,
@@ -842,11 +839,7 @@ module iota_system::iota_system_state_inner {
 
         let bps_denominator_u64 = BASIS_POINT_DENOMINATOR as u64;
         // Rates can't be higher than 100%.
-        assert!(
-            storage_fund_reinvest_rate <= bps_denominator_u64
-            && reward_slashing_rate <= bps_denominator_u64,
-            EBpsTooLarge,
-        );
+        assert!(reward_slashing_rate <= bps_denominator_u64, EBpsTooLarge);
 
         // TODO: remove this in later upgrade.
         if (self.parameters.stake_subsidy_start_epoch > 0) {
@@ -890,11 +883,6 @@ module iota_system::iota_system_state_inner {
 
         let storage_fund_reward_amount = storage_fund_balance as u128 * computation_charge_u128 / total_stake_u128;
         let mut storage_fund_reward = computation_reward.split(storage_fund_reward_amount as u64);
-        let storage_fund_reinvestment_amount =
-            storage_fund_reward_amount * (storage_fund_reinvest_rate as u128) / BASIS_POINT_DENOMINATOR;
-        let storage_fund_reinvestment = storage_fund_reward.split(
-            storage_fund_reinvestment_amount as u64,
-        );
 
         self.epoch = self.epoch + 1;
         // Sanity check to make sure we are advancing to the right epoch.
@@ -931,12 +919,11 @@ module iota_system::iota_system_state_inner {
         let mut leftover_staking_rewards = storage_fund_reward;
         leftover_staking_rewards.join(computation_reward);
         let leftover_storage_fund_inflow = leftover_staking_rewards.value();
-
+        
+        self.iota_treasury_cap.supply_mut().decrease_supply(leftover_staking_rewards);
         let refunded_storage_rebate =
             self.storage_fund.advance_epoch(
                 storage_reward,
-                storage_fund_reinvestment,
-                leftover_staking_rewards,
                 storage_rebate_amount,
                 non_refundable_storage_fee_amount,
             );
@@ -948,7 +935,6 @@ module iota_system::iota_system_state_inner {
                 reference_gas_price: self.reference_gas_price,
                 total_stake: new_total_stake,
                 storage_charge,
-                storage_fund_reinvestment: storage_fund_reinvestment_amount as u64,
                 storage_rebate: storage_rebate_amount,
                 storage_fund_balance: self.storage_fund.total_balance(),
                 stake_subsidy_amount,
diff --git a/crates/iota-framework/packages/iota-system/sources/storage_fund.move b/crates/iota-framework/packages/iota-system/sources/storage_fund.move
index 02b1187b07d..4dd3d552afa 100644
--- a/crates/iota-framework/packages/iota-system/sources/storage_fund.move
+++ b/crates/iota-framework/packages/iota-system/sources/storage_fund.move
@@ -34,24 +34,15 @@ module iota_system::storage_fund {
     public(package) fun advance_epoch(
         self: &mut StorageFund,
         storage_charges: Balance,
-        storage_fund_reinvestment: Balance,
-        leftover_staking_rewards: Balance,
         storage_rebate_amount: u64,
-        non_refundable_storage_fee_amount: u64,
+        //TODO: try the way to configure
+        _non_refundable_storage_fee_amount: u64,
     ) : Balance {
-        // Both the reinvestment and leftover rewards are not to be refunded so they go to the non-refundable balance.
-        self.non_refundable_balance.join(storage_fund_reinvestment);
-        self.non_refundable_balance.join(leftover_staking_rewards);
-
         // The storage charges for the epoch come from the storage rebate of the new objects created
         // and the new storage rebates of the objects modified during the epoch so we put the charges
         // into `total_object_storage_rebates`.
         self.total_object_storage_rebates.join(storage_charges);
 
-        // Split out the non-refundable portion of the storage rebate and put it into the non-refundable balance.
-        let non_refundable_storage_fee = self.total_object_storage_rebates.split(non_refundable_storage_fee_amount);
-        self.non_refundable_balance.join(non_refundable_storage_fee);
-
         // `storage_rebates` include the already refunded rebates of deleted objects and old rebates of modified objects and
         // should be taken out of the `total_object_storage_rebates`.
         let storage_rebate = self.total_object_storage_rebates.split(storage_rebate_amount);
diff --git a/crates/iota-framework/packages/iota-system/tests/governance_test_utils.move b/crates/iota-framework/packages/iota-system/tests/governance_test_utils.move
index 2a3f4fee26c..703619ce618 100644
--- a/crates/iota-framework/packages/iota-system/tests/governance_test_utils.move
+++ b/crates/iota-framework/packages/iota-system/tests/governance_test_utils.move
@@ -126,7 +126,7 @@ module iota_system::governance_test_utils {
         let ctx = scenario.ctx();
 
         let storage_rebate = system_state.advance_epoch_for_testing(
-            new_epoch, 1, storage_charge, computation_charge, stoarge_rebate, non_refundable_storage_rebate, 0, 0, 0, ctx,
+            new_epoch, 1, storage_charge, computation_charge, stoarge_rebate, non_refundable_storage_rebate, 0, 0, ctx,
         );
         test_scenario::return_shared(system_state);
         scenario.next_epoch(@0x0);
@@ -153,7 +153,7 @@ module iota_system::governance_test_utils {
         let ctx = scenario.ctx();
 
         let storage_rebate = system_state.advance_epoch_for_testing(
-            new_epoch, 1, storage_charge * MICROS_PER_IOTA, computation_charge * MICROS_PER_IOTA, 0, 0, 0, reward_slashing_rate, 0, ctx
+            new_epoch, 1, storage_charge * MICROS_PER_IOTA, computation_charge * MICROS_PER_IOTA, 0, 0, reward_slashing_rate, 0, ctx
         );
         test_utils::destroy(storage_rebate);
         test_scenario::return_shared(system_state);
diff --git a/crates/iota-framework/packages/iota-system/tests/iota_system_tests.move b/crates/iota-framework/packages/iota-system/tests/iota_system_tests.move
index 0761eab8301..f51f8bdd4ec 100644
--- a/crates/iota-framework/packages/iota-system/tests/iota_system_tests.move
+++ b/crates/iota-framework/packages/iota-system/tests/iota_system_tests.move
@@ -996,7 +996,7 @@ module iota_system::iota_system_tests {
         let prev_counter = system_state.get_stake_subsidy_distribution_counter();
 
         let rebate = system_state.advance_epoch_for_testing(
-            new_epoch, 1, 0, 0, 0, 0, 0, 0, prev_epoch_time + epoch_length, scenario.ctx()
+            new_epoch, 1, 0, 0, 0, 0, 0, prev_epoch_time + epoch_length, scenario.ctx()
         );
         destroy(rebate);
         assert_eq(system_state.get_stake_subsidy_distribution_counter(), prev_counter + (if (should_increment_counter) 1 else 0));
diff --git a/crates/iota-framework/packages/iota-system/tests/rewards_distribution_tests.move b/crates/iota-framework/packages/iota-system/tests/rewards_distribution_tests.move
index 11c6fa0d8c1..618913bb1f8 100644
--- a/crates/iota-framework/packages/iota-system/tests/rewards_distribution_tests.move
+++ b/crates/iota-framework/packages/iota-system/tests/rewards_distribution_tests.move
@@ -308,7 +308,7 @@ module iota_system::rewards_distribution_tests {
     #[test]
     fun test_everyone_slashed() {
         // This test is to make sure that if everyone is slashed, our protocol works as expected without aborting
-        // and all rewards go to the storage fund.
+        // and rewards are burned, and no tokens go to the storage fund.
         set_up_iota_system_state();
         let mut scenario_val = test_scenario::begin(VALIDATOR_ADDR_1);
         let scenario = &mut scenario_val;
@@ -327,16 +327,16 @@ module iota_system::rewards_distribution_tests {
         report_validator(VALIDATOR_ADDR_4, VALIDATOR_ADDR_1, scenario);
 
         advance_epoch_with_reward_amounts_and_slashing_rates(
-            1000, 3000, 10_000, scenario
+            1000, 1000, 10_000, scenario
         );
 
         // All validators should have 0 rewards added so their stake stays the same.
         assert_validator_self_stake_amounts(validator_addrs(), vector[100 * MICROS_PER_IOTA, 200 * MICROS_PER_IOTA, 300 * MICROS_PER_IOTA, 400 * MICROS_PER_IOTA], scenario);
 
         scenario.next_tx(@0x0);
-        // Storage fund balance should increase by 4000 IOTA.
+        // Storage fund balance should be the same as before.
         let mut system_state = scenario.take_shared();
-        assert_eq(system_state.get_storage_fund_total_balance(), 4000 * MICROS_PER_IOTA);
+        assert_eq(system_state.get_storage_fund_total_balance(), 1000 * MICROS_PER_IOTA);
 
         // The entire 1000 IOTA of storage rewards should go to the object rebate portion of the storage fund.
         assert_eq(system_state.get_storage_fund_object_rebates(), 1000 * MICROS_PER_IOTA);