From 79c2165cba37ec00cc70a269d9e06838211503a8 Mon Sep 17 00:00:00 2001 From: Emma Zhong Date: Sat, 11 Mar 2023 11:20:42 -0800 Subject: [PATCH] remove locked coin staking (#9046) ## Description This PR removes support for locked coin staking in various places. ## Test Plan cargo test --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [x] user-visible impact - [x] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [x] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes --- .changeset/thin-cheetahs-live.md | 5 + crates/sui-framework/docs/genesis.md | 2 - crates/sui-framework/docs/staking_pool.md | 83 +++-------- crates/sui-framework/docs/sui_system.md | 133 +----------------- crates/sui-framework/docs/validator.md | 31 +--- crates/sui-framework/docs/validator_set.md | 8 +- .../sources/governance/genesis.move | 1 - .../sources/governance/staking_pool.move | 73 ++-------- .../sources/governance/sui_system.move | 71 +--------- .../sources/governance/validator.move | 20 +-- .../sources/governance/validator_set.move | 6 +- .../sui-framework/tests/delegation_tests.move | 24 ---- .../tests/governance_test_utils.move | 28 ---- .../sui-framework/tests/sui_system_tests.move | 2 - .../tests/validator_set_tests.move | 4 - .../sui-framework/tests/validator_tests.move | 3 +- .../sui-json-rpc-types/src/sui_governance.rs | 1 - crates/sui-json-rpc/src/governance_api.rs | 1 - .../src/unit_tests/rpc_server_tests.rs | 92 ------------ crates/sui-open-rpc/spec/openrpc.json | 8 -- crates/sui-rosetta/src/account.rs | 6 +- crates/sui-rosetta/src/construction.rs | 8 +- crates/sui-rosetta/src/operations.rs | 18 +-- crates/sui-rosetta/src/types.rs | 26 +--- .../unit_tests/balance_changing_tx_tests.rs | 1 - crates/sui-transaction-builder/src/lib.rs | 20 +-- crates/sui-types/src/governance.rs | 7 - sdk/typescript/src/types/validator.ts | 1 - 28 files changed, 72 insertions(+), 611 deletions(-) create mode 100644 .changeset/thin-cheetahs-live.md diff --git a/.changeset/thin-cheetahs-live.md b/.changeset/thin-cheetahs-live.md new file mode 100644 index 0000000000000..88e4495020f95 --- /dev/null +++ b/.changeset/thin-cheetahs-live.md @@ -0,0 +1,5 @@ +--- +"@mysten/sui.js": patch +--- + +Remove locked coin staking diff --git a/crates/sui-framework/docs/genesis.md b/crates/sui-framework/docs/genesis.md index f0e7ca535511a..0fd80de8ece71 100644 --- a/crates/sui-framework/docs/genesis.md +++ b/crates/sui-framework/docs/genesis.md @@ -13,7 +13,6 @@ use 0x2::balance; use 0x2::clock; use 0x2::coin; -use 0x2::epoch_time_lock; use 0x2::sui; use 0x2::sui_system; use 0x2::tx_context; @@ -141,7 +140,6 @@ all the information we need in the system. worker_address, // Initialize all validators with uniform stake taken from the subsidy fund. option::some(balance::split(&mut subsidy_fund, initial_validator_stake_mist)), - option::none(), gas_price, commission_rate, true, // validator is active right away diff --git a/crates/sui-framework/docs/staking_pool.md b/crates/sui-framework/docs/staking_pool.md index 56ac4141233c3..178ec4c27370a 100644 --- a/crates/sui-framework/docs/staking_pool.md +++ b/crates/sui-framework/docs/staking_pool.md @@ -45,8 +45,6 @@
use 0x1::option;
 use 0x2::balance;
 use 0x2::coin;
-use 0x2::epoch_time_lock;
-use 0x2::locked_coin;
 use 0x2::math;
 use 0x2::object;
 use 0x2::sui;
@@ -226,13 +224,6 @@ A self-custodial object holding the staked SUI tokens.
 
The staked SUI tokens.
-
-sui_token_lock: option::Option<epoch_time_lock::EpochTimeLock> -
-
- If the stake comes from a Coin, this field is None. If it comes from a LockedCoin, this - field will record the original lock expiration epoch, to be used when unstaking. -
@@ -449,7 +440,7 @@ Create a new, empty staking pool. Request to stake to a staking pool. The stake starts counting at the beginning of the next epoch, -
public(friend) fun request_add_stake(pool: &mut staking_pool::StakingPool, stake: balance::Balance<sui::SUI>, sui_token_lock: option::Option<epoch_time_lock::EpochTimeLock>, validator_address: address, staker: address, stake_activation_epoch: u64, ctx: &mut tx_context::TxContext)
+
public(friend) fun request_add_stake(pool: &mut staking_pool::StakingPool, stake: balance::Balance<sui::SUI>, validator_address: address, staker: address, stake_activation_epoch: u64, ctx: &mut tx_context::TxContext)
 
@@ -461,7 +452,6 @@ Request to stake to a staking pool. The stake starts counting at the beginning o
public(friend) fun request_add_stake(
     pool: &mut StakingPool,
     stake: Balance<SUI>,
-    sui_token_lock: Option<EpochTimeLock>,
     validator_address: address,
     staker: address,
     stake_activation_epoch: u64,
@@ -476,7 +466,6 @@ Request to stake to a staking pool. The stake starts counting at the beginning o
         validator_address,
         stake_activation_epoch,
         principal: stake,
-        sui_token_lock,
     };
     pool.pending_stake = pool.pending_stake + sui_amount;
     transfer::transfer(staked_sui, staker);
@@ -510,7 +499,7 @@ A proportional amount of pool tokens is burnt.
     staked_sui: StakedSui,
     ctx: &mut TxContext
 ) : u64 {
-    let (pool_token_withdraw_amount, principal_withdraw, time_lock) =
+    let (pool_token_withdraw_amount, principal_withdraw) =
         withdraw_from_principal(pool, staked_sui);
     let staker = tx_context::sender(ctx);
     let principal_withdraw_amount = balance::value(&principal_withdraw);
@@ -527,21 +516,9 @@ A proportional amount of pool tokens is burnt.
     if (is_inactive(pool)) process_pending_stake_withdraw(pool);
 
     // TODO: implement withdraw bonding period here.
-    if (option::is_some(&time_lock)) {
-        locked_coin::new_from_balance(principal_withdraw, option::destroy_some(time_lock), staker, ctx);
-        if (balance::value(&rewards_withdraw) > 0) {
-            transfer::transfer(coin::from_balance(rewards_withdraw, ctx), staker);
-        } else {
-            balance::destroy_zero(rewards_withdraw);
-        }
-    } else {
-        balance::join(&mut principal_withdraw, rewards_withdraw);
-        transfer::transfer(coin::from_balance(principal_withdraw, ctx), staker);
-        option::destroy_none(time_lock);
-    };
+    balance::join(&mut principal_withdraw, rewards_withdraw);
+    transfer::transfer(coin::from_balance(principal_withdraw, ctx), staker);
     total_sui_withdraw_amount
-
-    // payment_amount
 }
 
@@ -554,12 +531,11 @@ A proportional amount of pool tokens is burnt. ## Function `withdraw_from_principal` Withdraw the principal SUI stored in the StakedSui object, and calculate the corresponding amount of pool -tokens using exchange rate at stake epoch. -Returns values are amount of pool tokens withdrawn, withdrawn principal portion of SUI, and its -time lock if applicable. +tokens using exchange rate at staking epoch. +Returns values are amount of pool tokens withdrawn and withdrawn principal portion of SUI. -
public(friend) fun withdraw_from_principal(pool: &mut staking_pool::StakingPool, staked_sui: staking_pool::StakedSui): (u64, balance::Balance<sui::SUI>, option::Option<epoch_time_lock::EpochTimeLock>)
+
public(friend) fun withdraw_from_principal(pool: &mut staking_pool::StakingPool, staked_sui: staking_pool::StakedSui): (u64, balance::Balance<sui::SUI>)
 
@@ -571,19 +547,18 @@ time lock if applicable.
public(friend) fun withdraw_from_principal(
     pool: &mut StakingPool,
     staked_sui: StakedSui,
-) : (u64, Balance<SUI>, Option<EpochTimeLock>) {
+) : (u64, Balance<SUI>) {
 
     // Check that the stake information matches the pool.
     assert!(staked_sui.pool_id == object::id(pool), EWrongPool);
 
     let exchange_rate_at_staking_epoch = pool_token_exchange_rate_at_epoch(pool, staked_sui.stake_activation_epoch);
-    let (principal_withdraw, time_lock) = unwrap_staked_sui(staked_sui);
+    let principal_withdraw = unwrap_staked_sui(staked_sui);
     let pool_token_withdraw_amount = get_token_amount(&exchange_rate_at_staking_epoch, balance::value(&principal_withdraw));
 
     (
         pool_token_withdraw_amount,
         principal_withdraw,
-        time_lock
     )
 }
 
@@ -598,7 +573,7 @@ time lock if applicable. -
fun unwrap_staked_sui(staked_sui: staking_pool::StakedSui): (balance::Balance<sui::SUI>, option::Option<epoch_time_lock::EpochTimeLock>)
+
fun unwrap_staked_sui(staked_sui: staking_pool::StakedSui): balance::Balance<sui::SUI>
 
@@ -607,17 +582,16 @@ time lock if applicable. Implementation -
fun unwrap_staked_sui(staked_sui: StakedSui): (Balance<SUI>, Option<EpochTimeLock>) {
+
fun unwrap_staked_sui(staked_sui: StakedSui): Balance<SUI> {
     let StakedSui {
         id,
         pool_id: _,
         validator_address: _,
         stake_activation_epoch: _,
         principal,
-        sui_token_lock
     } = staked_sui;
     object::delete(id);
-    (principal, sui_token_lock)
+    principal
 }
 
@@ -850,18 +824,12 @@ portion because the principal portion was already taken out of the staker's self let staker = tx_context::sender(ctx); - let (principal, time_lock) = unwrap_staked_sui(staked_sui); + let principal = unwrap_staked_sui(staked_sui); let withdraw_amount = balance::value(&principal); pool.sui_balance = pool.sui_balance - withdraw_amount; pool.pool_token_balance = pool.pool_token_balance - withdraw_amount; - // TODO: consider sharing code with `request_withdraw_stake` - if (option::is_some(&time_lock)) { - locked_coin::new_from_balance(principal, option::destroy_some(time_lock), staker, ctx); - } else { - transfer::transfer(coin::from_balance(principal, ctx), staker); - option::destroy_none(time_lock); - }; + transfer::transfer(coin::from_balance(principal, ctx), staker); withdraw_amount }
@@ -1064,7 +1032,6 @@ All the other parameters of the StakedSui like stake_activation_epochbalance::split(&mut self.principal, split_amount), - sui_token_lock: self.sui_token_lock, } }
@@ -1124,15 +1091,9 @@ Aborts if some of the staking parameters are incompatible (pool id, stake activa validator_address: _, stake_activation_epoch: _, principal, - sui_token_lock } = other; object::delete(id); - if (option::is_some(&sui_token_lock)) { - epoch_time_lock::destroy_unchecked(option::destroy_some(sui_token_lock)); - } else { - option::destroy_none(sui_token_lock); - }; balance::join(&mut self.principal, principal); }
@@ -1158,19 +1119,9 @@ Returns true if all the staking parameters of the staked sui except the principa
public fun is_equal_staking_metadata(self: &StakedSui, other: &StakedSui): bool {
-    if ((self.pool_id != other.pool_id) ||
-        (self.validator_address != other.validator_address) ||
-        (self.stake_activation_epoch != other.stake_activation_epoch)) {
-        return false
-    };
-    if (option::is_none(&self.sui_token_lock) && option::is_none(&other.sui_token_lock)) {
-        return true
-    };
-    if (option::is_some(&self.sui_token_lock) && option::is_some(&other.sui_token_lock)) {
-        epoch_time_lock::epoch(option::borrow(&self.sui_token_lock)) ==
-            epoch_time_lock::epoch(option::borrow(&other.sui_token_lock))
-    } else
-        false // locked coin in one and unlocked in another
+    (self.pool_id == other.pool_id) &&
+    (self.validator_address == other.validator_address) &&
+    (self.stake_activation_epoch == other.stake_activation_epoch)
 }
 
diff --git a/crates/sui-framework/docs/sui_system.md b/crates/sui-framework/docs/sui_system.md index bba975adf6193..02f4a8e3ff4d2 100644 --- a/crates/sui-framework/docs/sui_system.md +++ b/crates/sui-framework/docs/sui_system.md @@ -19,8 +19,6 @@ - [Function `request_set_commission_rate`](#0x2_sui_system_request_set_commission_rate) - [Function `request_add_stake`](#0x2_sui_system_request_add_stake) - [Function `request_add_stake_mul_coin`](#0x2_sui_system_request_add_stake_mul_coin) -- [Function `request_add_stake_with_locked_coin`](#0x2_sui_system_request_add_stake_with_locked_coin) -- [Function `request_add_stake_mul_locked_coin`](#0x2_sui_system_request_add_stake_mul_locked_coin) - [Function `request_withdraw_stake`](#0x2_sui_system_request_withdraw_stake) - [Function `report_validator`](#0x2_sui_system_report_validator) - [Function `undo_report_validator`](#0x2_sui_system_undo_report_validator) @@ -51,7 +49,6 @@ - [Function `load_system_state_mut`](#0x2_sui_system_load_system_state_mut) - [Function `upgrade_system_state`](#0x2_sui_system_upgrade_system_state) - [Function `extract_coin_balance`](#0x2_sui_system_extract_coin_balance) -- [Function `extract_locked_coin_balance`](#0x2_sui_system_extract_locked_coin_balance) - [Function `validators`](#0x2_sui_system_validators) - [Function `active_validator_by_address`](#0x2_sui_system_active_validator_by_address) - [Function `pending_validator_by_address`](#0x2_sui_system_pending_validator_by_address) @@ -64,9 +61,7 @@ use 0x2::clock; use 0x2::coin; use 0x2::dynamic_field; -use 0x2::epoch_time_lock; use 0x2::event; -use 0x2::locked_coin; use 0x2::object; use 0x2::pay; use 0x2::stake_subsidy; @@ -563,7 +558,6 @@ To produce a valid PoP, run [fn test_proof_of_possession]. primary_address, worker_address, option::none(), - option::none(), gas_price, commission_rate, false, // not an initial validator active at genesis @@ -778,7 +772,6 @@ Add stake to a validator's staking pool. &mut self.validators, validator_address, coin::into_balance(stake), - option::none(), ctx, ); } @@ -813,78 +806,7 @@ Add stake to a validator's staking pool using multiple coins. ) { let self = load_system_state_mut(wrapper); let balance = extract_coin_balance(stakes, stake_amount, ctx); - validator_set::request_add_stake(&mut self.validators, validator_address, balance, option::none(), ctx); -} -
- - - - - - - -## Function `request_add_stake_with_locked_coin` - -Add stake to a validator's staking pool using a locked SUI coin. - - -
public entry fun request_add_stake_with_locked_coin(wrapper: &mut sui_system::SuiSystemState, stake: locked_coin::LockedCoin<sui::SUI>, validator_address: address, ctx: &mut tx_context::TxContext)
-
- - - -
-Implementation - - -
public entry fun request_add_stake_with_locked_coin(
-    wrapper: &mut SuiSystemState,
-    stake: LockedCoin<SUI>,
-    validator_address: address,
-    ctx: &mut TxContext,
-) {
-    let self = load_system_state_mut(wrapper);
-    let (balance, lock) = locked_coin::into_balance(stake);
-    validator_set::request_add_stake(&mut self.validators, validator_address, balance, option::some(lock), ctx);
-}
-
- - - -
- - - -## Function `request_add_stake_mul_locked_coin` - -Add stake to a validator's staking pool using multiple locked SUI coins. - - -
public entry fun request_add_stake_mul_locked_coin(wrapper: &mut sui_system::SuiSystemState, stakes: vector<locked_coin::LockedCoin<sui::SUI>>, stake_amount: option::Option<u64>, validator_address: address, ctx: &mut tx_context::TxContext)
-
- - - -
-Implementation - - -
public entry fun request_add_stake_mul_locked_coin(
-    wrapper: &mut SuiSystemState,
-    stakes: vector<LockedCoin<SUI>>,
-    stake_amount: option::Option<u64>,
-    validator_address: address,
-    ctx: &mut TxContext,
-) {
-    let self = load_system_state_mut(wrapper);
-    let (balance, lock) = extract_locked_coin_balance(stakes, stake_amount, ctx);
-    validator_set::request_add_stake(
-        &mut self.validators,
-        validator_address,
-        balance,
-        option::some(lock),
-        ctx
-    );
+    validator_set::request_add_stake(&mut self.validators, validator_address, balance, ctx);
 }
 
@@ -1957,59 +1879,6 @@ Extract required Balance from vector of Coin, transfer the remainder back t -
- - - -## Function `extract_locked_coin_balance` - -Extract required Balance from vector of LockedCoin, transfer the remainder back to sender. - - -
fun extract_locked_coin_balance(coins: vector<locked_coin::LockedCoin<sui::SUI>>, amount: option::Option<u64>, ctx: &mut tx_context::TxContext): (balance::Balance<sui::SUI>, epoch_time_lock::EpochTimeLock)
-
- - - -
-Implementation - - -
fun extract_locked_coin_balance(
-    coins: vector<LockedCoin<SUI>>,
-    amount: option::Option<u64>,
-    ctx: &mut TxContext
-): (Balance<SUI>, EpochTimeLock) {
-    let (total_balance, first_lock) = locked_coin::into_balance(vector::pop_back(&mut coins));
-    let (i, len) = (0, vector::length(&coins));
-    while (i < len) {
-        let (balance, lock) = locked_coin::into_balance(vector::pop_back(&mut coins));
-        // Make sure all time locks are the same
-        assert!(epoch_time_lock::epoch(&lock) == epoch_time_lock::epoch(&first_lock), 0);
-        epoch_time_lock::destroy_unchecked(lock);
-        balance::join(&mut total_balance, balance);
-        i = i + 1
-    };
-    vector::destroy_empty(coins);
-
-    // return the full amount if amount is not specified
-    if (option::is_some(&amount)){
-        let amount = option::destroy_some(amount);
-        let balance = balance::split(&mut total_balance, amount);
-        if (balance::value(&total_balance) > 0) {
-            locked_coin::new_from_balance(total_balance, first_lock, tx_context::sender(ctx), ctx);
-        } else {
-            balance::destroy_zero(total_balance);
-        };
-        (balance, first_lock)
-    } else{
-        (total_balance, first_lock)
-    }
-}
-
- - -
diff --git a/crates/sui-framework/docs/validator.md b/crates/sui-framework/docs/validator.md index 4869fb5bfcf55..597bab9ad6b5b 100644 --- a/crates/sui-framework/docs/validator.md +++ b/crates/sui-framework/docs/validator.md @@ -80,7 +80,6 @@ use 0x1::option; use 0x1::string; use 0x2::balance; -use 0x2::epoch_time_lock; use 0x2::event; use 0x2::object; use 0x2::staking_pool; @@ -386,16 +385,6 @@ Commission rate set by the validator is higher than the threshold - - -No stake balance is provided but an epoch time lock for the stake is provided. - - -
const EEmptyStakeWithNonEmptyTimeLock: u64 = 9;
-
- - - Capability code is not valid @@ -572,7 +561,7 @@ New Capability is not created by the validator itself -
public(friend) fun new(sui_address: address, protocol_pubkey_bytes: vector<u8>, network_pubkey_bytes: vector<u8>, worker_pubkey_bytes: vector<u8>, proof_of_possession: vector<u8>, name: vector<u8>, description: vector<u8>, image_url: vector<u8>, project_url: vector<u8>, net_address: vector<u8>, p2p_address: vector<u8>, primary_address: vector<u8>, worker_address: vector<u8>, initial_stake_option: option::Option<balance::Balance<sui::SUI>>, coin_locked_until_epoch: option::Option<epoch_time_lock::EpochTimeLock>, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, ctx: &mut tx_context::TxContext): validator::Validator
+
public(friend) fun new(sui_address: address, protocol_pubkey_bytes: vector<u8>, network_pubkey_bytes: vector<u8>, worker_pubkey_bytes: vector<u8>, proof_of_possession: vector<u8>, name: vector<u8>, description: vector<u8>, image_url: vector<u8>, project_url: vector<u8>, net_address: vector<u8>, p2p_address: vector<u8>, primary_address: vector<u8>, worker_address: vector<u8>, initial_stake_option: option::Option<balance::Balance<sui::SUI>>, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, ctx: &mut tx_context::TxContext): validator::Validator
 
@@ -596,7 +585,6 @@ New Capability is not created by the validator itself primary_address: vector<u8>, worker_address: vector<u8>, initial_stake_option: Option<Balance<SUI>>, - coin_locked_until_epoch: Option<EpochTimeLock>, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, @@ -634,7 +622,6 @@ New Capability is not created by the validator itself new_from_metadata( metadata, initial_stake_option, - coin_locked_until_epoch, gas_price, commission_rate, is_active_at_genesis, @@ -729,7 +716,7 @@ Process pending stake and pending withdraws, and update the gas price. Request to add stake to the validator's staking pool, processed at the end of the epoch. -
public(friend) fun request_add_stake(self: &mut validator::Validator, stake: balance::Balance<sui::SUI>, locking_period: option::Option<epoch_time_lock::EpochTimeLock>, staker_address: address, ctx: &mut tx_context::TxContext)
+
public(friend) fun request_add_stake(self: &mut validator::Validator, stake: balance::Balance<sui::SUI>, staker_address: address, ctx: &mut tx_context::TxContext)
 
@@ -741,7 +728,6 @@ Request to add stake to the validator's staking pool, processed at the end of th
public(friend) fun request_add_stake(
     self: &mut Validator,
     stake: Balance<SUI>,
-    locking_period: Option<EpochTimeLock>,
     staker_address: address,
     ctx: &mut TxContext,
 ) {
@@ -749,7 +735,7 @@ Request to add stake to the validator's staking pool, processed at the end of th
     assert!(stake_amount > 0, 0);
     let stake_epoch = tx_context::epoch(ctx) + 1;
     staking_pool::request_add_stake(
-        &mut self.staking_pool, stake, locking_period, self.metadata.sui_address, staker_address, stake_epoch, ctx
+        &mut self.staking_pool, stake, self.metadata.sui_address, staker_address, stake_epoch, ctx
     );
     // Process stake right away if staking pool is preactive.
     if (staking_pool::is_preactive(&self.staking_pool)) {
@@ -2265,7 +2251,7 @@ Aborts if validator metadata is valid
 Create a new validator from the given ValidatorMetadata, called by both new and new_for_testing.
 
 
-
fun new_from_metadata(metadata: validator::ValidatorMetadata, initial_stake_option: option::Option<balance::Balance<sui::SUI>>, coin_locked_until_epoch: option::Option<epoch_time_lock::EpochTimeLock>, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, ctx: &mut tx_context::TxContext): validator::Validator
+
fun new_from_metadata(metadata: validator::ValidatorMetadata, initial_stake_option: option::Option<balance::Balance<sui::SUI>>, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, ctx: &mut tx_context::TxContext): validator::Validator
 
@@ -2277,7 +2263,6 @@ Create a new validator from the given new_from_metadata( metadata: ValidatorMetadata, initial_stake_option: Option<Balance<SUI>>, - coin_locked_until_epoch: Option<EpochTimeLock>, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, @@ -2299,8 +2284,7 @@ Create a new validator from the given option::is_some(&initial_stake_option)) { staking_pool::request_add_stake( &mut staking_pool, - option::destroy_some(initial_stake_option), - coin_locked_until_epoch, + option::extract(&mut initial_stake_option), sui_address, sui_address, tx_context::epoch(ctx), @@ -2308,11 +2292,8 @@ Create a new validator from the given validator setup time and this is the validator staking with itself. staking_pool::process_pending_stake(&mut staking_pool); - } else { - assert!(option::is_none(&coin_locked_until_epoch), EEmptyStakeWithNonEmptyTimeLock); - option::destroy_none(coin_locked_until_epoch); - option::destroy_none(initial_stake_option); }; + option::destroy_none(initial_stake_option); let operation_cap_id = validator_cap::new_unverified_validator_operation_cap_and_transfer(sui_address, ctx); Validator { diff --git a/crates/sui-framework/docs/validator_set.md b/crates/sui-framework/docs/validator_set.md index 09d60791501a4..bfd7eccd6bedc 100644 --- a/crates/sui-framework/docs/validator_set.md +++ b/crates/sui-framework/docs/validator_set.md @@ -66,7 +66,6 @@
use 0x1::option;
 use 0x1::vector;
 use 0x2::balance;
-use 0x2::epoch_time_lock;
 use 0x2::event;
 use 0x2::object;
 use 0x2::priority_queue;
@@ -630,7 +629,7 @@ This request is added to the validator's staking pool's pending stake entries, p
 of the epoch.
 
 
-
public(friend) fun request_add_stake(self: &mut validator_set::ValidatorSet, validator_address: address, stake: balance::Balance<sui::SUI>, locking_period: option::Option<epoch_time_lock::EpochTimeLock>, ctx: &mut tx_context::TxContext)
+
public(friend) fun request_add_stake(self: &mut validator_set::ValidatorSet, validator_address: address, stake: balance::Balance<sui::SUI>, ctx: &mut tx_context::TxContext)
 
@@ -643,11 +642,10 @@ of the epoch. self: &mut ValidatorSet, validator_address: address, stake: Balance<SUI>, - locking_period: Option<EpochTimeLock>, ctx: &mut TxContext, ) { let validator = get_preactive_or_active_validator_mut(self, validator_address); - validator::request_add_stake(validator, stake, locking_period, tx_context::sender(ctx), ctx); + validator::request_add_stake(validator, stake, tx_context::sender(ctx), ctx); }
@@ -2153,7 +2151,7 @@ The staking rewards are shared with the stakers while the storage fund ones are // Add rewards to the validator. Don't try and distribute rewards though if the payout is zero. if (balance::value(&validator_reward) > 0) { let validator_address = validator::sui_address(validator); - validator::request_add_stake(validator, validator_reward, option::none(), validator_address, ctx); + validator::request_add_stake(validator, validator_reward, validator_address, ctx); } else { balance::destroy_zero(validator_reward); }; diff --git a/crates/sui-framework/sources/governance/genesis.move b/crates/sui-framework/sources/governance/genesis.move index f5cfb30f459fc..57357183a3023 100644 --- a/crates/sui-framework/sources/governance/genesis.move +++ b/crates/sui-framework/sources/governance/genesis.move @@ -98,7 +98,6 @@ module sui::genesis { worker_address, // Initialize all validators with uniform stake taken from the subsidy fund. option::some(balance::split(&mut subsidy_fund, initial_validator_stake_mist)), - option::none(), gas_price, commission_rate, true, // validator is active right away diff --git a/crates/sui-framework/sources/governance/staking_pool.move b/crates/sui-framework/sources/governance/staking_pool.move index 45513ff91c43a..f37d9df71e8a1 100644 --- a/crates/sui-framework/sources/governance/staking_pool.move +++ b/crates/sui-framework/sources/governance/staking_pool.move @@ -7,9 +7,7 @@ module sui::staking_pool { use std::option::{Self, Option}; use sui::tx_context::{Self, TxContext}; use sui::transfer; - use sui::epoch_time_lock::{Self, EpochTimeLock}; use sui::object::{Self, ID, UID}; - use sui::locked_coin; use sui::coin; use sui::math; use sui::table::{Self, Table}; @@ -82,9 +80,6 @@ module sui::staking_pool { stake_activation_epoch: u64, /// The staked SUI tokens. principal: Balance, - /// If the stake comes from a Coin, this field is None. If it comes from a LockedCoin, this - /// field will record the original lock expiration epoch, to be used when unstaking. - sui_token_lock: Option, } // ==== initializer ==== @@ -112,7 +107,6 @@ module sui::staking_pool { public(friend) fun request_add_stake( pool: &mut StakingPool, stake: Balance, - sui_token_lock: Option, validator_address: address, staker: address, stake_activation_epoch: u64, @@ -127,7 +121,6 @@ module sui::staking_pool { validator_address, stake_activation_epoch, principal: stake, - sui_token_lock, }; pool.pending_stake = pool.pending_stake + sui_amount; transfer::transfer(staked_sui, staker); @@ -141,7 +134,7 @@ module sui::staking_pool { staked_sui: StakedSui, ctx: &mut TxContext ) : u64 { - let (pool_token_withdraw_amount, principal_withdraw, time_lock) = + let (pool_token_withdraw_amount, principal_withdraw) = withdraw_from_principal(pool, staked_sui); let staker = tx_context::sender(ctx); let principal_withdraw_amount = balance::value(&principal_withdraw); @@ -158,57 +151,42 @@ module sui::staking_pool { if (is_inactive(pool)) process_pending_stake_withdraw(pool); // TODO: implement withdraw bonding period here. - if (option::is_some(&time_lock)) { - locked_coin::new_from_balance(principal_withdraw, option::destroy_some(time_lock), staker, ctx); - if (balance::value(&rewards_withdraw) > 0) { - transfer::transfer(coin::from_balance(rewards_withdraw, ctx), staker); - } else { - balance::destroy_zero(rewards_withdraw); - } - } else { - balance::join(&mut principal_withdraw, rewards_withdraw); - transfer::transfer(coin::from_balance(principal_withdraw, ctx), staker); - option::destroy_none(time_lock); - }; + balance::join(&mut principal_withdraw, rewards_withdraw); + transfer::transfer(coin::from_balance(principal_withdraw, ctx), staker); total_sui_withdraw_amount - - // payment_amount } /// Withdraw the principal SUI stored in the StakedSui object, and calculate the corresponding amount of pool - /// tokens using exchange rate at stake epoch. - /// Returns values are amount of pool tokens withdrawn, withdrawn principal portion of SUI, and its - /// time lock if applicable. + /// tokens using exchange rate at staking epoch. + /// Returns values are amount of pool tokens withdrawn and withdrawn principal portion of SUI. public(friend) fun withdraw_from_principal( pool: &mut StakingPool, staked_sui: StakedSui, - ) : (u64, Balance, Option) { + ) : (u64, Balance) { // Check that the stake information matches the pool. assert!(staked_sui.pool_id == object::id(pool), EWrongPool); let exchange_rate_at_staking_epoch = pool_token_exchange_rate_at_epoch(pool, staked_sui.stake_activation_epoch); - let (principal_withdraw, time_lock) = unwrap_staked_sui(staked_sui); + let principal_withdraw = unwrap_staked_sui(staked_sui); let pool_token_withdraw_amount = get_token_amount(&exchange_rate_at_staking_epoch, balance::value(&principal_withdraw)); ( pool_token_withdraw_amount, principal_withdraw, - time_lock ) } - fun unwrap_staked_sui(staked_sui: StakedSui): (Balance, Option) { + fun unwrap_staked_sui(staked_sui: StakedSui): Balance { let StakedSui { id, pool_id: _, validator_address: _, stake_activation_epoch: _, principal, - sui_token_lock } = staked_sui; object::delete(id); - (principal, sui_token_lock) + principal } // ==== functions called at epoch boundaries === @@ -306,18 +284,12 @@ module sui::staking_pool { let staker = tx_context::sender(ctx); - let (principal, time_lock) = unwrap_staked_sui(staked_sui); + let principal = unwrap_staked_sui(staked_sui); let withdraw_amount = balance::value(&principal); pool.sui_balance = pool.sui_balance - withdraw_amount; pool.pool_token_balance = pool.pool_token_balance - withdraw_amount; - // TODO: consider sharing code with `request_withdraw_stake` - if (option::is_some(&time_lock)) { - locked_coin::new_from_balance(principal, option::destroy_some(time_lock), staker, ctx); - } else { - transfer::transfer(coin::from_balance(principal, ctx), staker); - option::destroy_none(time_lock); - }; + transfer::transfer(coin::from_balance(principal, ctx), staker); withdraw_amount } @@ -364,7 +336,6 @@ module sui::staking_pool { validator_address: self.validator_address, stake_activation_epoch: self.stake_activation_epoch, principal: balance::split(&mut self.principal, split_amount), - sui_token_lock: self.sui_token_lock, } } @@ -384,33 +355,17 @@ module sui::staking_pool { validator_address: _, stake_activation_epoch: _, principal, - sui_token_lock } = other; object::delete(id); - if (option::is_some(&sui_token_lock)) { - epoch_time_lock::destroy_unchecked(option::destroy_some(sui_token_lock)); - } else { - option::destroy_none(sui_token_lock); - }; balance::join(&mut self.principal, principal); } /// Returns true if all the staking parameters of the staked sui except the principal are identical public fun is_equal_staking_metadata(self: &StakedSui, other: &StakedSui): bool { - if ((self.pool_id != other.pool_id) || - (self.validator_address != other.validator_address) || - (self.stake_activation_epoch != other.stake_activation_epoch)) { - return false - }; - if (option::is_none(&self.sui_token_lock) && option::is_none(&other.sui_token_lock)) { - return true - }; - if (option::is_some(&self.sui_token_lock) && option::is_some(&other.sui_token_lock)) { - epoch_time_lock::epoch(option::borrow(&self.sui_token_lock)) == - epoch_time_lock::epoch(option::borrow(&other.sui_token_lock)) - } else - false // locked coin in one and unlocked in another + (self.pool_id == other.pool_id) && + (self.validator_address == other.validator_address) && + (self.stake_activation_epoch == other.stake_activation_epoch) } diff --git a/crates/sui-framework/sources/governance/sui_system.move b/crates/sui-framework/sources/governance/sui_system.move index 29076e498336f..794b99411cee6 100644 --- a/crates/sui-framework/sources/governance/sui_system.move +++ b/crates/sui-framework/sources/governance/sui_system.move @@ -7,7 +7,6 @@ module sui::sui_system { use sui::coin::{Self, Coin}; use sui::object::{Self, ID, UID}; use sui::staking_pool::{stake_activation_epoch, StakedSui}; - use sui::locked_coin::{Self, LockedCoin}; use sui::sui::SUI; use sui::transfer; use sui::tx_context::{Self, TxContext}; @@ -19,8 +18,6 @@ module sui::sui_system { use sui::vec_set::{Self, VecSet}; use std::option; use std::vector; - use sui::epoch_time_lock::EpochTimeLock; - use sui::epoch_time_lock; use sui::pay; use sui::event; use sui::table::Table; @@ -212,7 +209,6 @@ module sui::sui_system { primary_address, worker_address, option::none(), - option::none(), gas_price, commission_rate, false, // not an initial validator active at genesis @@ -307,7 +303,6 @@ module sui::sui_system { &mut self.validators, validator_address, coin::into_balance(stake), - option::none(), ctx, ); } @@ -322,38 +317,7 @@ module sui::sui_system { ) { let self = load_system_state_mut(wrapper); let balance = extract_coin_balance(stakes, stake_amount, ctx); - validator_set::request_add_stake(&mut self.validators, validator_address, balance, option::none(), ctx); - } - - /// Add stake to a validator's staking pool using a locked SUI coin. - public entry fun request_add_stake_with_locked_coin( - wrapper: &mut SuiSystemState, - stake: LockedCoin, - validator_address: address, - ctx: &mut TxContext, - ) { - let self = load_system_state_mut(wrapper); - let (balance, lock) = locked_coin::into_balance(stake); - validator_set::request_add_stake(&mut self.validators, validator_address, balance, option::some(lock), ctx); - } - - /// Add stake to a validator's staking pool using multiple locked SUI coins. - public entry fun request_add_stake_mul_locked_coin( - wrapper: &mut SuiSystemState, - stakes: vector>, - stake_amount: option::Option, - validator_address: address, - ctx: &mut TxContext, - ) { - let self = load_system_state_mut(wrapper); - let (balance, lock) = extract_locked_coin_balance(stakes, stake_amount, ctx); - validator_set::request_add_stake( - &mut self.validators, - validator_address, - balance, - option::some(lock), - ctx - ); + validator_set::request_add_stake(&mut self.validators, validator_address, balance, ctx); } /// Withdraw some portion of a stake from a validator's staking pool. @@ -826,39 +790,6 @@ module sui::sui_system { } } - /// Extract required Balance from vector of LockedCoin, transfer the remainder back to sender. - fun extract_locked_coin_balance( - coins: vector>, - amount: option::Option, - ctx: &mut TxContext - ): (Balance, EpochTimeLock) { - let (total_balance, first_lock) = locked_coin::into_balance(vector::pop_back(&mut coins)); - let (i, len) = (0, vector::length(&coins)); - while (i < len) { - let (balance, lock) = locked_coin::into_balance(vector::pop_back(&mut coins)); - // Make sure all time locks are the same - assert!(epoch_time_lock::epoch(&lock) == epoch_time_lock::epoch(&first_lock), 0); - epoch_time_lock::destroy_unchecked(lock); - balance::join(&mut total_balance, balance); - i = i + 1 - }; - vector::destroy_empty(coins); - - // return the full amount if amount is not specified - if (option::is_some(&amount)){ - let amount = option::destroy_some(amount); - let balance = balance::split(&mut total_balance, amount); - if (balance::value(&total_balance) > 0) { - locked_coin::new_from_balance(total_balance, first_lock, tx_context::sender(ctx), ctx); - } else { - balance::destroy_zero(total_balance); - }; - (balance, first_lock) - } else{ - (total_balance, first_lock) - } - } - /// Return the current validator set public fun validators(wrapper: &SuiSystemState): &ValidatorSet { let self = load_system_state(wrapper); diff --git a/crates/sui-framework/sources/governance/validator.move b/crates/sui-framework/sources/governance/validator.move index 1503fc9511178..e8c02ac928e76 100644 --- a/crates/sui-framework/sources/governance/validator.move +++ b/crates/sui-framework/sources/governance/validator.move @@ -9,7 +9,6 @@ module sui::validator { use sui::balance::{Self, Balance}; use sui::sui::SUI; use sui::tx_context::{Self, TxContext}; - use sui::epoch_time_lock::EpochTimeLock; use sui::validator_cap::{Self, ValidatorOperationCap}; use sui::object::{Self, ID}; use std::option::{Option, Self}; @@ -59,9 +58,6 @@ module sui::validator { /// Commission rate set by the validator is higher than the threshold const ECommissionRateTooHigh: u64 = 8; - /// No stake balance is provided but an epoch time lock for the stake is provided. - const EEmptyStakeWithNonEmptyTimeLock: u64 = 9; - /// New Capability is not created by the validator itself const ENewCapNotCreatedByValidatorItself: u64 = 100; @@ -197,7 +193,6 @@ module sui::validator { primary_address: vector, worker_address: vector, initial_stake_option: Option>, - coin_locked_until_epoch: Option, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, @@ -235,7 +230,6 @@ module sui::validator { new_from_metadata( metadata, initial_stake_option, - coin_locked_until_epoch, gas_price, commission_rate, is_active_at_genesis, @@ -262,7 +256,6 @@ module sui::validator { public(friend) fun request_add_stake( self: &mut Validator, stake: Balance, - locking_period: Option, staker_address: address, ctx: &mut TxContext, ) { @@ -270,7 +263,7 @@ module sui::validator { assert!(stake_amount > 0, 0); let stake_epoch = tx_context::epoch(ctx) + 1; staking_pool::request_add_stake( - &mut self.staking_pool, stake, locking_period, self.metadata.sui_address, staker_address, stake_epoch, ctx + &mut self.staking_pool, stake, self.metadata.sui_address, staker_address, stake_epoch, ctx ); // Process stake right away if staking pool is preactive. if (staking_pool::is_preactive(&self.staking_pool)) { @@ -634,7 +627,6 @@ module sui::validator { fun new_from_metadata( metadata: ValidatorMetadata, initial_stake_option: Option>, - coin_locked_until_epoch: Option, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, @@ -656,8 +648,7 @@ module sui::validator { if (option::is_some(&initial_stake_option)) { staking_pool::request_add_stake( &mut staking_pool, - option::destroy_some(initial_stake_option), - coin_locked_until_epoch, + option::extract(&mut initial_stake_option), sui_address, sui_address, tx_context::epoch(ctx), @@ -665,11 +656,8 @@ module sui::validator { ); // We immediately process this stake as they are at validator setup time and this is the validator staking with itself. staking_pool::process_pending_stake(&mut staking_pool); - } else { - assert!(option::is_none(&coin_locked_until_epoch), EEmptyStakeWithNonEmptyTimeLock); - option::destroy_none(coin_locked_until_epoch); - option::destroy_none(initial_stake_option); }; + option::destroy_none(initial_stake_option); let operation_cap_id = validator_cap::new_unverified_validator_operation_cap_and_transfer(sui_address, ctx); Validator { @@ -709,7 +697,6 @@ module sui::validator { primary_address: vector, worker_address: vector, initial_stake_option: Option>, - coin_locked_until_epoch: Option, gas_price: u64, commission_rate: u64, is_active_at_genesis: bool, @@ -732,7 +719,6 @@ module sui::validator { worker_address, ), initial_stake_option, - coin_locked_until_epoch, gas_price, commission_rate, is_active_at_genesis, diff --git a/crates/sui-framework/sources/governance/validator_set.move b/crates/sui-framework/sources/governance/validator_set.move index 92472b39a3a8a..9946e1bb6c751 100644 --- a/crates/sui-framework/sources/governance/validator_set.move +++ b/crates/sui-framework/sources/governance/validator_set.move @@ -11,7 +11,6 @@ module sui::validator_set { use sui::validator::{Self, Validator, staking_pool_id, sui_address}; use sui::validator_cap::{Self, UnverifiedValidatorOperationCap, ValidatorOperationCap}; use sui::staking_pool::{PoolTokenExchangeRate, StakedSui, pool_id}; - use sui::epoch_time_lock::EpochTimeLock; use sui::object::{Self, ID}; use sui::priority_queue as pq; use sui::vec_map::{Self, VecMap}; @@ -224,11 +223,10 @@ module sui::validator_set { self: &mut ValidatorSet, validator_address: address, stake: Balance, - locking_period: Option, ctx: &mut TxContext, ) { let validator = get_preactive_or_active_validator_mut(self, validator_address); - validator::request_add_stake(validator, stake, locking_period, tx_context::sender(ctx), ctx); + validator::request_add_stake(validator, stake, tx_context::sender(ctx), ctx); } /// Called by `sui_system`, to withdraw some share of a stake from the validator. The share to withdraw @@ -964,7 +962,7 @@ module sui::validator_set { // Add rewards to the validator. Don't try and distribute rewards though if the payout is zero. if (balance::value(&validator_reward) > 0) { let validator_address = validator::sui_address(validator); - validator::request_add_stake(validator, validator_reward, option::none(), validator_address, ctx); + validator::request_add_stake(validator, validator_reward, validator_address, ctx); } else { balance::destroy_zero(validator_reward); }; diff --git a/crates/sui-framework/tests/delegation_tests.move b/crates/sui-framework/tests/delegation_tests.move index db6cb33bf9fc1..f7b71d4b14f89 100644 --- a/crates/sui-framework/tests/delegation_tests.move +++ b/crates/sui-framework/tests/delegation_tests.move @@ -103,30 +103,6 @@ module sui::stake_tests { test_scenario::end(scenario_val); } - #[test] - #[expected_failure(abort_code = staking_pool::EIncompatibleStakedSui)] - fun test_join_different_locked_coins() { - let scenario_val = test_scenario::begin(STAKER_ADDR_1); - let scenario = &mut scenario_val; - set_up_sui_system_state(scenario); - // Create staked sui w/ locked coin and regular staked sui - governance_test_utils::stake_with(STAKER_ADDR_1, VALIDATOR_ADDR_1, 60, scenario); - governance_test_utils::stake_locked_to(STAKER_ADDR_1, VALIDATOR_ADDR_1, 60, 2, scenario); - - // Verify that these cannot be merged - test_scenario::next_tx(scenario, STAKER_ADDR_1); - { - let staked_sui_ids = test_scenario::ids_for_sender(scenario); - let part1 = test_scenario::take_from_sender_by_id(scenario, *vector::borrow(&staked_sui_ids, 0)); - let part2 = test_scenario::take_from_sender_by_id(scenario, *vector::borrow(&staked_sui_ids, 1)); - - staking_pool::join_staked_sui(&mut part1, part2); - - test_scenario::return_to_sender(scenario, part1); - }; - test_scenario::end(scenario_val); - } - #[test] fun test_add_remove_stake_flow() { let scenario_val = test_scenario::begin(VALIDATOR_ADDR_1); diff --git a/crates/sui-framework/tests/governance_test_utils.move b/crates/sui-framework/tests/governance_test_utils.move index 22c0f3ccd91cb..a71731435e719 100644 --- a/crates/sui-framework/tests/governance_test_utils.move +++ b/crates/sui-framework/tests/governance_test_utils.move @@ -7,7 +7,6 @@ module sui::governance_test_utils { use sui::balance; use sui::sui::SUI; use sui::coin::{Self, Coin}; - use sui::locked_coin::{Self, LockedCoin}; use sui::staking_pool::{Self, StakedSui, StakingPool}; use sui::test_utils::assert_eq; use sui::tx_context::{Self, TxContext}; @@ -36,7 +35,6 @@ module sui::governance_test_utils { x"FFFF", x"FFFF", option::some(balance::create_for_testing(init_stake_amount)), - option::none(), 1, 0, true, @@ -147,32 +145,6 @@ module sui::governance_test_utils { test_scenario::return_shared(system_state); } - public fun stake_locked_to( - staker: address, validator: address, amount: u64, locked_until_epoch: u64, scenario: &mut Scenario - ) { - // First lock the coin - test_scenario::next_tx(scenario, staker); - { - let ctx = test_scenario::ctx(scenario); - locked_coin::lock_coin(coin::mint_for_testing(amount, ctx), staker, locked_until_epoch, ctx); - }; - - // Next stake the locked coin - test_scenario::next_tx(scenario, staker); - { - let system_state = test_scenario::take_shared(scenario); - let locked_val = test_scenario::take_from_sender>(scenario); - let ctx = test_scenario::ctx(scenario); - sui_system::request_add_stake_with_locked_coin( - &mut system_state, - locked_val, - validator, - ctx - ); - test_scenario::return_shared(system_state); - }; - } - public fun unstake( staker: address, staked_sui_idx: u64, scenario: &mut Scenario ) { diff --git a/crates/sui-framework/tests/sui_system_tests.move b/crates/sui-framework/tests/sui_system_tests.move index f2a37e1450690..02360d5af2211 100644 --- a/crates/sui-framework/tests/sui_system_tests.move +++ b/crates/sui-framework/tests/sui_system_tests.move @@ -468,7 +468,6 @@ module sui::sui_system_tests { vector[4, 127, 0, 0, 1], vector[4, 127, 0, 0, 1], option::some(balance::create_for_testing(100)), - option::none(), 1, 0, true, @@ -725,7 +724,6 @@ module sui::sui_system_tests { vector[4, 127, 0, 0, 1], vector[4, 127, 0, 0, 1], option::some(balance::create_for_testing(100)), - option::none(), 1, 0, true, diff --git a/crates/sui-framework/tests/validator_set_tests.move b/crates/sui-framework/tests/validator_set_tests.move index 284f881082de9..8c23b92c0303e 100644 --- a/crates/sui-framework/tests/validator_set_tests.move +++ b/crates/sui-framework/tests/validator_set_tests.move @@ -52,7 +52,6 @@ module sui::validator_set_tests { &mut validator_set, @0x1, coin::into_balance(coin::mint_for_testing(500, ctx1)), - option::none(), ctx1, ); // Adding stake to existing active validator during the epoch @@ -167,7 +166,6 @@ module sui::validator_set_tests { &mut validator_set, @0x2, balance::create_for_testing(500), - option::none(), ctx, ); // Adding stake to a preactive validator should not change total stake. @@ -205,7 +203,6 @@ module sui::validator_set_tests { &mut validator_set, @0x2, balance::create_for_testing(500), - option::none(), ctx, ); // Adding stake to a preactive validator should not change total stake. @@ -268,7 +265,6 @@ module sui::validator_set_tests { vector[hint], vector[hint], option::some(balance::create_for_testing(stake_value)), - option::none(), gas_price, 0, is_initial_validator, diff --git a/crates/sui-framework/tests/validator_tests.move b/crates/sui-framework/tests/validator_tests.move index 22111a7e9f7dc..eff9d483b7688 100644 --- a/crates/sui-framework/tests/validator_tests.move +++ b/crates/sui-framework/tests/validator_tests.move @@ -51,7 +51,6 @@ module sui::validator_tests { VALID_CONSENSUS_ADDR, VALID_WORKER_ADDR, option::some(init_stake), - option::none(), 1, 0, true, @@ -98,7 +97,7 @@ module sui::validator_tests { { let ctx = test_scenario::ctx(scenario); let new_stake = coin::into_balance(coin::mint_for_testing(30, ctx)); - validator::request_add_stake(&mut validator, new_stake, option::none(), sender, ctx); + validator::request_add_stake(&mut validator, new_stake, sender, ctx); assert!(validator::total_stake(&validator) == 10, 0); assert!(validator::pending_stake_amount(&validator) == 30, 0); diff --git a/crates/sui-json-rpc-types/src/sui_governance.rs b/crates/sui-json-rpc-types/src/sui_governance.rs index 28edda5f05941..8c37ef60f99d0 100644 --- a/crates/sui-json-rpc-types/src/sui_governance.rs +++ b/crates/sui-json-rpc-types/src/sui_governance.rs @@ -52,7 +52,6 @@ pub struct Stake { pub stake_request_epoch: EpochId, pub stake_active_epoch: EpochId, pub principal: u64, - pub token_lock: Option, #[serde(flatten)] pub status: StakeStatus, } diff --git a/crates/sui-json-rpc/src/governance_api.rs b/crates/sui-json-rpc/src/governance_api.rs index f9142343b4dba..4581a26b3107b 100644 --- a/crates/sui-json-rpc/src/governance_api.rs +++ b/crates/sui-json-rpc/src/governance_api.rs @@ -86,7 +86,6 @@ impl GovernanceReadApi { // TODO: this might change when we implement warm up period. stake_active_epoch: stake.request_epoch() + 1, principal: stake.principal(), - token_lock: stake.sui_token_lock(), status, }) } diff --git a/crates/sui-json-rpc/src/unit_tests/rpc_server_tests.rs b/crates/sui-json-rpc/src/unit_tests/rpc_server_tests.rs index 1bae3548a5229..2f904757d0ec2 100644 --- a/crates/sui-json-rpc/src/unit_tests/rpc_server_tests.rs +++ b/crates/sui-json-rpc/src/unit_tests/rpc_server_tests.rs @@ -888,7 +888,6 @@ async fn test_staking() -> Result<(), anyhow::Error> { let staked_sui: Vec = http_client.get_delegated_stakes(*address).await?; assert_eq!(1, staked_sui.len()); assert_eq!(1000000, staked_sui[0].stakes[0].principal); - assert!(staked_sui[0].stakes[0].token_lock.is_none()); assert!(matches!( staked_sui[0].stakes[0].status, StakeStatus::Pending @@ -950,7 +949,6 @@ async fn test_staking_multiple_coins() -> Result<(), anyhow::Error> { let staked_sui: Vec = http_client.get_delegated_stakes(*address).await?; assert_eq!(1, staked_sui.len()); assert_eq!(1000000, staked_sui[0].stakes[0].principal); - assert!(staked_sui[0].stakes[0].token_lock.is_none()); assert!(matches!( staked_sui[0].stakes[0].status, StakeStatus::Pending @@ -970,93 +968,3 @@ async fn test_staking_multiple_coins() -> Result<(), anyhow::Error> { Ok(()) } - -#[sim_test] -async fn test_delegation_with_locked_sui() -> Result<(), anyhow::Error> { - let cluster = TestClusterBuilder::new().build().await?; - - let http_client = cluster.rpc_client(); - let address = cluster.accounts.first().unwrap(); - - let objects: Vec = http_client.get_objects_owned_by_address(*address).await?; - assert_eq!(5, objects.len()); - - // lock some SUI - let transaction_bytes: TransactionBytes = http_client - .move_call( - *address, - SUI_FRAMEWORK_ADDRESS.into(), - LOCKED_COIN_MODULE_NAME.to_string(), - "lock_coin".to_string(), - vec![parse_sui_type_tag("0x2::sui::SUI")?.into()], - vec![ - SuiJsonValue::from_str(&objects[0].object_id.to_string())?, - SuiJsonValue::from_str(&format!("{address}"))?, - SuiJsonValue::from_bcs_bytes(&bcs::to_bytes(&"20")?)?, - ], - None, - 1000, - None, - ) - .await?; - let keystore_path = cluster.swarm.dir().join(SUI_KEYSTORE_FILENAME); - let keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?); - let tx = to_sender_signed_transaction(transaction_bytes.to_data()?, keystore.get_key(address)?); - - let (tx_bytes, signatures) = tx.to_tx_bytes_and_signatures(); - - http_client - .execute_transaction( - tx_bytes, - signatures, - ExecuteTransactionRequestType::WaitForLocalExecution, - ) - .await?; - - let validator = http_client - .get_latest_sui_system_state() - .await? - .active_validators[0] - .sui_address; - // Delegate some locked SUI - let coins: CoinPage = http_client.get_coins(*address, None, None, None).await?; - let locked_sui = coins - .data - .iter() - .find_map(|coin| coin.locked_until_epoch.map(|_| coin.coin_object_id)) - .unwrap(); - - let transaction_bytes: TransactionBytes = http_client - .request_add_stake( - *address, - vec![locked_sui], - Some(1000000), - validator, - None, - 10000, - ) - .await?; - let tx = to_sender_signed_transaction(transaction_bytes.to_data()?, keystore.get_key(address)?); - let (tx_bytes, signatures) = tx.to_tx_bytes_and_signatures(); - - http_client - .execute_transaction( - tx_bytes, - signatures, - ExecuteTransactionRequestType::WaitForLocalExecution, - ) - .await?; - - // Check StakedSui object - let staked_sui: Vec = http_client.get_delegated_stakes(*address).await?; - assert_eq!(1, staked_sui.len()); - assert_eq!(1000000, staked_sui[0].stakes[0].principal); - assert_eq!(Some(20), staked_sui[0].stakes[0].token_lock); - - assert!(matches!( - staked_sui[0].stakes[0].status, - StakeStatus::Pending - )); - - Ok(()) -} diff --git a/crates/sui-open-rpc/spec/openrpc.json b/crates/sui-open-rpc/spec/openrpc.json index ddda6a48efb2b..f42abfe77f50f 100644 --- a/crates/sui-open-rpc/spec/openrpc.json +++ b/crates/sui-open-rpc/spec/openrpc.json @@ -5189,14 +5189,6 @@ "$ref": "#/components/schemas/ObjectID" } ] - }, - "tokenLock": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 } } }, diff --git a/crates/sui-rosetta/src/account.rs b/crates/sui-rosetta/src/account.rs index 2fa4b7f4430f0..bced60be9492d 100644 --- a/crates/sui-rosetta/src/account.rs +++ b/crates/sui-rosetta/src/account.rs @@ -72,8 +72,7 @@ async fn get_sub_account_balances( .fold(HashMap::new(), |mut balances, stakes| { for delegation in &stakes.stakes { if let StakeStatus::Active { .. } = delegation.status { - *balances.entry(delegation.token_lock).or_default() += - delegation.principal as u128; + *balances.entry(None).or_default() += delegation.principal as u128; } } balances @@ -89,8 +88,7 @@ async fn get_sub_account_balances( .fold(HashMap::new(), |mut balances, stakes| { for delegation in &stakes.stakes { if let StakeStatus::Pending = delegation.status { - *balances.entry(delegation.token_lock).or_default() += - delegation.principal as u128; + *balances.entry(None).or_default() += delegation.principal as u128; } } balances diff --git a/crates/sui-rosetta/src/construction.rs b/crates/sui-rosetta/src/construction.rs index b363c28de7df5..0a433554380f8 100644 --- a/crates/sui-rosetta/src/construction.rs +++ b/crates/sui-rosetta/src/construction.rs @@ -228,12 +228,11 @@ pub async fn metadata( sender, validator, amount, - locked_until_epoch, } => { let coins = context .client .coin_read_api() - .select_coins(*sender, None, *amount, *locked_until_epoch, vec![]) + .select_coins(*sender, None, *amount, None, vec![]) .await? .into_iter() .map(|coin| coin.object_ref()) @@ -253,10 +252,7 @@ pub async fn metadata( .await?; ( - TransactionMetadata::Delegation { - coins, - locked_until_epoch: *locked_until_epoch, - }, + TransactionMetadata::Delegation { coins }, data.gas().to_vec(), 13000, ) diff --git a/crates/sui-rosetta/src/operations.rs b/crates/sui-rosetta/src/operations.rs index 039484f4145c2..b23849865c8cd 100644 --- a/crates/sui-rosetta/src/operations.rs +++ b/crates/sui-rosetta/src/operations.rs @@ -18,10 +18,9 @@ use sui_sdk::rpc_types::{ }; use sui_types::base_types::{SequenceNumber, SuiAddress}; -use sui_types::committee::EpochId; use sui_types::event::BalanceChangeType; use sui_types::gas_coin::{GasCoin, GAS}; -use sui_types::governance::{ADD_STAKE_LOCKED_COIN_FUN_NAME, ADD_STAKE_MUL_COIN_FUN_NAME}; +use sui_types::governance::ADD_STAKE_MUL_COIN_FUN_NAME; use sui_types::messages::TransactionData; use sui_types::object::Owner; use sui_types::sui_system_state::SUI_SYSTEM_MODULE_NAME; @@ -90,11 +89,7 @@ impl Operations { metadata, ) { (OperationType::PaySui, _) => self.pay_sui_ops_to_internal(), - ( - OperationType::Delegation, - Some(PreprocessMetadata::Delegation { locked_until_epoch }), - ) => self.delegation_ops_to_internal(locked_until_epoch), - (OperationType::Delegation, _) => self.delegation_ops_to_internal(None), + (OperationType::Delegation, _) => self.delegation_ops_to_internal(), (op, _) => Err(Error::UnsupportedOperation(op)), } } @@ -127,10 +122,7 @@ impl Operations { }) } - fn delegation_ops_to_internal( - self, - locked_until_epoch: Option, - ) -> Result { + fn delegation_ops_to_internal(self) -> Result { let mut ops = self .0 .into_iter() @@ -165,7 +157,6 @@ impl Operations { sender, validator, amount, - locked_until_epoch, }) } @@ -350,8 +341,7 @@ impl Operations { fn is_delegation_call(tx: &SuiProgrammableMoveCall) -> bool { tx.package == SUI_FRAMEWORK_OBJECT_ID && tx.module == SUI_SYSTEM_MODULE_NAME.as_str() - && (tx.function == ADD_STAKE_LOCKED_COIN_FUN_NAME.as_str() - || tx.function == ADD_STAKE_MUL_COIN_FUN_NAME.as_str()) + && tx.function == ADD_STAKE_MUL_COIN_FUN_NAME.as_str() } fn get_balance_operation_from_events( diff --git a/crates/sui-rosetta/src/types.rs b/crates/sui-rosetta/src/types.rs index cac7c638773a9..36244edaaabde 100644 --- a/crates/sui-rosetta/src/types.rs +++ b/crates/sui-rosetta/src/types.rs @@ -24,7 +24,7 @@ use sui_types::base_types::{ObjectID, ObjectRef, SequenceNumber, SuiAddress, Tra use sui_types::committee::EpochId; use sui_types::crypto::PublicKey as SuiPublicKey; use sui_types::crypto::SignatureScheme; -use sui_types::governance::{ADD_STAKE_LOCKED_COIN_FUN_NAME, ADD_STAKE_MUL_COIN_FUN_NAME}; +use sui_types::governance::ADD_STAKE_MUL_COIN_FUN_NAME; use sui_types::messages::{CallArg, Command, ObjectArg, TransactionData}; use sui_types::messages_checkpoint::CheckpointDigest; use sui_types::sui_system_state::SUI_SYSTEM_MODULE_NAME; @@ -535,16 +535,14 @@ pub struct ConstructionPreprocessRequest { #[derive(Serialize, Deserialize)] pub enum PreprocessMetadata { PaySui, - Delegation { locked_until_epoch: Option }, + Delegation, } impl From for PreprocessMetadata { fn from(tx_metadata: TransactionMetadata) -> Self { match tx_metadata { TransactionMetadata::PaySui => Self::PaySui, - TransactionMetadata::Delegation { - locked_until_epoch, .. - } => Self::Delegation { locked_until_epoch }, + TransactionMetadata::Delegation { .. } => Self::Delegation, } } } @@ -606,10 +604,7 @@ impl IntoResponse for ConstructionMetadataResponse { #[derive(Serialize, Deserialize, Clone, Debug)] pub enum TransactionMetadata { PaySui, - Delegation { - coins: Vec, - locked_until_epoch: Option, - }, + Delegation { coins: Vec }, } #[derive(Deserialize)] @@ -858,7 +853,6 @@ pub enum InternalOperation { sender: SuiAddress, validator: SuiAddress, amount: u128, - locked_until_epoch: Option, }, } @@ -886,18 +880,10 @@ impl InternalOperation { } ( InternalOperation::Delegation { - validator, - amount, - locked_until_epoch, - .. + validator, amount, .. }, TransactionMetadata::Delegation { coins, .. }, ) => { - let function = if locked_until_epoch.is_some() { - ADD_STAKE_LOCKED_COIN_FUN_NAME.to_owned() - } else { - ADD_STAKE_MUL_COIN_FUN_NAME.to_owned() - }; let mut builder = ProgrammableTransactionBuilder::new(); let arguments = vec![ builder @@ -920,7 +906,7 @@ impl InternalOperation { builder.command(Command::move_call( SUI_FRAMEWORK_OBJECT_ID, SUI_SYSTEM_MODULE_NAME.to_owned(), - function, + ADD_STAKE_MUL_COIN_FUN_NAME.to_owned(), vec![], arguments, )); diff --git a/crates/sui-rosetta/src/unit_tests/balance_changing_tx_tests.rs b/crates/sui-rosetta/src/unit_tests/balance_changing_tx_tests.rs index ef02ebb375473..a8fe11465c018 100644 --- a/crates/sui-rosetta/src/unit_tests/balance_changing_tx_tests.rs +++ b/crates/sui-rosetta/src/unit_tests/balance_changing_tx_tests.rs @@ -521,7 +521,6 @@ async fn test_delegation_parsing() -> Result<(), anyhow::Error> { let metadata = ConstructionMetadata { tx_metadata: TransactionMetadata::Delegation { coins: vec![coin1, coin2], - locked_until_epoch: None, }, sender, gas: vec![gas], diff --git a/crates/sui-transaction-builder/src/lib.rs b/crates/sui-transaction-builder/src/lib.rs index 4418327ee50a7..014b65a07d55c 100644 --- a/crates/sui-transaction-builder/src/lib.rs +++ b/crates/sui-transaction-builder/src/lib.rs @@ -10,6 +10,7 @@ use async_trait::async_trait; use futures::future::join_all; use anyhow::{anyhow, ensure}; +use move_binary_format::file_format::SignatureToken; use move_core_types::identifier::Identifier; use move_core_types::language_storage::TypeTag; @@ -24,15 +25,10 @@ use sui_protocol_config::ProtocolConfig; use sui_types::base_types::{ObjectID, ObjectRef, ObjectType, SuiAddress}; use sui_types::error::UserInputError; use sui_types::gas_coin::GasCoin; +use sui_types::governance::{ADD_STAKE_MUL_COIN_FUN_NAME, WITHDRAW_STAKE_FUN_NAME}; use sui_types::messages::{ Argument, CallArg, Command, InputObjectKind, ObjectArg, TransactionData, TransactionKind, }; - -use move_binary_format::file_format::SignatureToken; - -use sui_types::governance::{ - ADD_STAKE_LOCKED_COIN_FUN_NAME, ADD_STAKE_MUL_COIN_FUN_NAME, WITHDRAW_STAKE_FUN_NAME, -}; use sui_types::move_package::MovePackage; use sui_types::object::{Object, Owner}; use sui_types::programmable_transaction_builder::ProgrammableTransactionBuilder; @@ -663,8 +659,8 @@ impl TransactionBuilder { return Err(anyhow!("Provided object [{coin}] is not a move object.")) }; ensure!( - type_.is_coin() || type_.is_locked_coin(), - "Expecting either Coin or LockedCoin as input coin objects. Received [{type_}]" + type_.is_coin(), + "Expecting either Coin input coin objects. Received [{type_}]" ); for coin in coins { @@ -676,12 +672,6 @@ impl TransactionBuilder { obj_vec.push(ObjectArg::ImmOrOwnedObject(oref)) } obj_vec.push(ObjectArg::ImmOrOwnedObject(oref)); - let function = if type_.is_coin() { - ADD_STAKE_MUL_COIN_FUN_NAME - } else { - ADD_STAKE_LOCKED_COIN_FUN_NAME - } - .to_owned(); let pt = { let mut builder = ProgrammableTransactionBuilder::new(); @@ -704,7 +694,7 @@ impl TransactionBuilder { builder.command(Command::move_call( SUI_FRAMEWORK_OBJECT_ID, SUI_SYSTEM_MODULE_NAME.to_owned(), - function, + ADD_STAKE_MUL_COIN_FUN_NAME.to_owned(), vec![], arguments, )); diff --git a/crates/sui-types/src/governance.rs b/crates/sui-types/src/governance.rs index a6d837be4f0c0..f778d2b62b5f2 100644 --- a/crates/sui-types/src/governance.rs +++ b/crates/sui-types/src/governance.rs @@ -23,8 +23,6 @@ pub const STAKED_SUI_STRUCT_NAME: &IdentStr = ident_str!("StakedSui"); pub const ADD_STAKE_MUL_COIN_FUN_NAME: &IdentStr = ident_str!("request_add_stake_mul_coin"); pub const ADD_STAKE_FUN_NAME: &IdentStr = ident_str!("request_add_stake_mul_coin"); -pub const ADD_STAKE_LOCKED_COIN_FUN_NAME: &IdentStr = - ident_str!("request_add_stake_mul_locked_coin"); pub const WITHDRAW_STAKE_FUN_NAME: &IdentStr = ident_str!("request_withdraw_stake"); #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] @@ -34,7 +32,6 @@ pub struct StakedSui { validator_address: SuiAddress, stake_activation_epoch: u64, principal: Balance, - sui_token_lock: Option, } impl StakedSui { @@ -73,10 +70,6 @@ impl StakedSui { pub fn validator_address(&self) -> SuiAddress { self.validator_address } - - pub fn sui_token_lock(&self) -> Option { - self.sui_token_lock - } } impl TryFrom<&Object> for StakedSui { diff --git a/sdk/typescript/src/types/validator.ts b/sdk/typescript/src/types/validator.ts index b802833e69c34..ced7eeee10e3b 100644 --- a/sdk/typescript/src/types/validator.ts +++ b/sdk/typescript/src/types/validator.ts @@ -34,7 +34,6 @@ export const StakeObject = object({ stakeRequestEpoch: EpochId, stakeActiveEpoch: EpochId, principal: number(), - tokenLock: nullable(EpochId), status: union([literal('Active'), literal('Pending')]), estimatedReward: optional(number()), });