diff --git a/crates/iota-framework/docs/timelock/label.md b/crates/iota-framework/docs/timelock/label.md
index 87777215874..34912defefa 100644
--- a/crates/iota-framework/docs/timelock/label.md
+++ b/crates/iota-framework/docs/timelock/label.md
@@ -23,9 +23,9 @@ title: Module `0x10cf::label`
use 0x1::option ;
use 0x1::string ;
use 0x1::type_name ;
-use 0x2::object ;
-use 0x2::tx_context ;
-use 0x2::types ;
+use 0x2::object ;
+use 0x2::tx_context ;
+use 0x2::types ;
@@ -49,7 +49,7 @@ Can be publicly transferred like any other object.
+
+## Function `label`
+
+Function to get the label of a TimelockedStakedIota
.
+
+
+public fun label (self: &timelocked_staked_iota::TimelockedStakedIota ): &option::Option <label::Label >
+
+
+
+
+
+Implementation
+
+
+public fun label (self: &TimelockedStakedIota ): &Option<Label> {
+ &self.label
+}
+
+
+
+
@@ -235,6 +271,7 @@ All the other parameters of the object::new (ctx),
staked_iota: splitted_stake,
expiration_timestamp_ms: self.expiration_timestamp_ms,
+ label : label::clone_opt (&self.label ),
}
}
@@ -293,8 +330,11 @@ Aborts if some of the staking parameters are incompatible (pool id, stake activa
id,
staked_iota,
expiration_timestamp_ms: _,
+ label ,
} = other;
+ label::destroy_opt (label );
+
id.delete();
self.staked_iota.join(staked_iota);
@@ -323,7 +363,8 @@ Returns true if all the staking parameters of the staked iota except the princip
public fun is_equal_staking_metadata (self: &TimelockedStakedIota , other: &TimelockedStakedIota ): bool {
self.staked_iota.is_equal_staking_metadata (&other.staked_iota) &&
- (self.expiration_timestamp_ms == other.expiration_timestamp_ms)
+ (self.expiration_timestamp_ms == other.expiration_timestamp_ms) &&
+ (self.label () == other.label ())
}
@@ -335,10 +376,10 @@ Returns true if all the staking parameters of the staked iota except the princip
## Function `unpack`
-An utility function to destroy a TimelockedStakedIota
.
+A utility function to destroy a TimelockedStakedIota
.
-public (friend ) fun unpack (self: timelocked_staked_iota::TimelockedStakedIota ): (staking_pool::StakedIota , u64)
+public (friend ) fun unpack (self: timelocked_staked_iota::TimelockedStakedIota ): (staking_pool::StakedIota , u64, option::Option <label::Label >)
@@ -347,16 +388,17 @@ An utility function to destroy a unpack (self: TimelockedStakedIota ): (StakedIota, u64) {
+public (package) fun unpack (self: TimelockedStakedIota ): (StakedIota, u64, Option<Label>) {
let TimelockedStakedIota {
id,
staked_iota,
expiration_timestamp_ms,
+ label ,
} = self;
object::delete (id);
- (staked_iota, expiration_timestamp_ms)
+ (staked_iota, expiration_timestamp_ms, label )
}
diff --git a/crates/iota-framework/docs/timelock/timelocked_staking.md b/crates/iota-framework/docs/timelock/timelocked_staking.md
index a37490f449e..41382bfb1fb 100644
--- a/crates/iota-framework/docs/timelock/timelocked_staking.md
+++ b/crates/iota-framework/docs/timelock/timelocked_staking.md
@@ -13,8 +13,10 @@ title: Module `0x10cf::timelocked_staking`
- [Function `request_withdraw_stake_non_entry`](#0x10cf_timelocked_staking_request_withdraw_stake_non_entry)
-use 0x10cf::timelock ;
+use 0x10cf::label ;
+use 0x10cf::timelock ;
use 0x10cf::timelocked_staked_iota ;
+use 0x1::option ;
use 0x2::balance ;
use 0x2::coin ;
use 0x2::iota ;
@@ -101,7 +103,7 @@ The non-entry version of request_add_stake
, which returns the time-
assert !(timelocked_balance .is_locked(ctx), ETimeLockShouldNotBeExpired );
// Unpack the time-locked balance .
- let (balance , expiration_timestamp_ms) = timelock::unpack (timelocked_balance );
+ let (balance , expiration_timestamp_ms, label ) = timelock::unpack (timelocked_balance );
// Stake the time-locked balance .
let staked_iota = iota_system .request_add_stake_non_entry (
@@ -114,7 +116,8 @@ The non-entry version of request_add_stake
, which returns the time-
timelocked_staked_iota::create (
staked_iota,
expiration_timestamp_ms,
- ctx
+ label ,
+ ctx,
)
}
@@ -289,7 +292,7 @@ instead of transferring it to the sender.
ctx: &mut TxContext,
) : (TimeLock<Balance<IOTA>>, Balance<IOTA>) {
// Unpack the `TimelockedStakedIota` instance.
- let (staked_iota, expiration_timestamp_ms) = timelocked_staked_iota .unpack();
+ let (staked_iota, expiration_timestamp_ms, label ) = timelocked_staked_iota .unpack();
// Store the original stake amount.
let principal = staked_iota.staked_iota_amount();
@@ -302,7 +305,7 @@ instead of transferring it to the sender.
let principal = withdraw_stake.split(principal);
// Pack and return a time-locked balance , and the reward.
- (timelock::pack (principal, expiration_timestamp_ms, ctx), withdraw_stake)
+ (timelock::pack (principal, expiration_timestamp_ms, label , ctx), withdraw_stake)
}
diff --git a/crates/iota-framework/packages/timelock/sources/label.move b/crates/iota-framework/packages/timelock/sources/label.move
index 5fd69daeea8..7959582fa42 100644
--- a/crates/iota-framework/packages/timelock/sources/label.move
+++ b/crates/iota-framework/packages/timelock/sources/label.move
@@ -1,11 +1,12 @@
// Copyright (c) 2024 IOTA Stiftung
+// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
module timelock::label {
use std::string::{Self, String};
- use sui::types;
+ use iota::types;
// === Error codes ===
diff --git a/crates/iota-framework/packages/timelock/sources/stardust_upgrade_label.move b/crates/iota-framework/packages/timelock/sources/stardust_upgrade_label.move
index 78c7b9759bf..5c2b6bbdc06 100644
--- a/crates/iota-framework/packages/timelock/sources/stardust_upgrade_label.move
+++ b/crates/iota-framework/packages/timelock/sources/stardust_upgrade_label.move
@@ -1,4 +1,5 @@
// Copyright (c) 2024 IOTA Stiftung
+// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
/// All the vested rewards migrated from Stardust are labeled with this label.
diff --git a/crates/iota-framework/packages/timelock/sources/timelocked_staked_iota.move b/crates/iota-framework/packages/timelock/sources/timelocked_staked_iota.move
index 01947734b7a..137198c54ba 100644
--- a/crates/iota-framework/packages/timelock/sources/timelocked_staked_iota.move
+++ b/crates/iota-framework/packages/timelock/sources/timelocked_staked_iota.move
@@ -1,9 +1,10 @@
// Copyright (c) 2024 IOTA Stiftung
-// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
module timelock::timelocked_staked_iota {
+ use timelock::label::{Self, Label};
+
use iota_system::staking_pool::StakedIota;
const EIncompatibleTimelockedStakedIota: u64 = 0;
@@ -15,18 +16,22 @@ module timelock::timelocked_staked_iota {
staked_iota: StakedIota,
/// This is the epoch time stamp of when the lock expires.
expiration_timestamp_ms: u64,
+ /// Timelock related label.
+ label: Option,
}
/// Create a new instance of `TimelockedStakedIota`.
public(package) fun create(
staked_iota: StakedIota,
expiration_timestamp_ms: u64,
+ label: Option,
ctx: &mut TxContext
): TimelockedStakedIota {
TimelockedStakedIota {
id: object::new(ctx),
staked_iota,
- expiration_timestamp_ms
+ expiration_timestamp_ms,
+ label,
}
}
@@ -49,6 +54,11 @@ module timelock::timelocked_staked_iota {
self.expiration_timestamp_ms
}
+ /// Function to get the label of a `TimelockedStakedIota`.
+ public fun label(self: &TimelockedStakedIota): &Option {
+ &self.label
+ }
+
/// Split `TimelockedStakedIota` into two parts, one with principal `split_amount`,
/// and the remaining principal is left in `self`.
/// All the other parameters of the `TimelockedStakedIota` like `stake_activation_epoch` or `pool_id` remain the same.
@@ -59,6 +69,7 @@ module timelock::timelocked_staked_iota {
id: object::new(ctx),
staked_iota: splitted_stake,
expiration_timestamp_ms: self.expiration_timestamp_ms,
+ label: label::clone_opt(&self.label),
}
}
@@ -80,8 +91,11 @@ module timelock::timelocked_staked_iota {
id,
staked_iota,
expiration_timestamp_ms: _,
+ label,
} = other;
+ label::destroy_opt(label);
+
id.delete();
self.staked_iota.join(staked_iota);
@@ -93,20 +107,22 @@ module timelock::timelocked_staked_iota {
/// Returns true if all the staking parameters of the staked iota except the principal are identical
public fun is_equal_staking_metadata(self: &TimelockedStakedIota, other: &TimelockedStakedIota): bool {
self.staked_iota.is_equal_staking_metadata(&other.staked_iota) &&
- (self.expiration_timestamp_ms == other.expiration_timestamp_ms)
+ (self.expiration_timestamp_ms == other.expiration_timestamp_ms) &&
+ (self.label() == other.label())
}
- /// An utility function to destroy a `TimelockedStakedIota`.
- public(package) fun unpack(self: TimelockedStakedIota): (StakedIota, u64) {
+ /// A utility function to destroy a `TimelockedStakedIota`.
+ public(package) fun unpack(self: TimelockedStakedIota): (StakedIota, u64, Option) {
let TimelockedStakedIota {
id,
staked_iota,
expiration_timestamp_ms,
+ label,
} = self;
object::delete(id);
- (staked_iota, expiration_timestamp_ms)
+ (staked_iota, expiration_timestamp_ms, label)
}
/// An utility function to transfer a `TimelockedStakedIota`.
diff --git a/crates/iota-framework/packages/timelock/sources/timelocked_staking.move b/crates/iota-framework/packages/timelock/sources/timelocked_staking.move
index 4a6c686ffd5..ee4741b839c 100644
--- a/crates/iota-framework/packages/timelock/sources/timelocked_staking.move
+++ b/crates/iota-framework/packages/timelock/sources/timelocked_staking.move
@@ -147,15 +147,9 @@ module timelock::timelocked_staking {
iota_system: &mut IotaSystemState,
timelocked_staked_iota: TimelockedStakedIota,
ctx: &mut TxContext,
-<<<<<<< HEAD:crates/sui-framework/packages/timelock/sources/timelocked_staking.move
- ) : (TimeLock>, Balance) {
- // Unpack the `TimelockedStakedSui` instance.
- let (staked_sui, expiration_timestamp_ms, label) = timelocked_staked_sui.unpack();
-=======
) : (TimeLock>, Balance) {
// Unpack the `TimelockedStakedIota` instance.
- let (staked_iota, expiration_timestamp_ms) = timelocked_staked_iota.unpack();
->>>>>>> develop:crates/iota-framework/packages/timelock/sources/timelocked_staking.move
+ let (staked_iota, expiration_timestamp_ms, label) = timelocked_staked_iota.unpack();
// Store the original stake amount.
let principal = staked_iota.staked_iota_amount();
diff --git a/crates/iota-framework/packages/timelock/tests/label_test.move b/crates/iota-framework/packages/timelock/tests/label_test.move
index e8dfda0ee09..56a7759bf8c 100644
--- a/crates/iota-framework/packages/timelock/tests/label_test.move
+++ b/crates/iota-framework/packages/timelock/tests/label_test.move
@@ -1,4 +1,5 @@
// Copyright (c) 2024 IOTA Stiftung
+// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
#[test_only]
@@ -6,8 +7,8 @@ module timelock::label_tests {
use std::string;
- use sui::test_scenario;
- use sui::test_utils::assert_eq;
+ use iota::test_scenario;
+ use iota::test_utils::assert_eq;
use timelock::label::{Self, LabelerCap};
diff --git a/crates/iota-framework/packages/timelock/tests/test_label_one.move b/crates/iota-framework/packages/timelock/tests/test_label_one.move
index c4ec256d570..2634738e878 100644
--- a/crates/iota-framework/packages/timelock/tests/test_label_one.move
+++ b/crates/iota-framework/packages/timelock/tests/test_label_one.move
@@ -1,4 +1,5 @@
// Copyright (c) 2024 IOTA Stiftung
+// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
#[test_only]
diff --git a/crates/iota-framework/packages/timelock/tests/test_label_two.move b/crates/iota-framework/packages/timelock/tests/test_label_two.move
index f05cba64adb..119af9627c1 100644
--- a/crates/iota-framework/packages/timelock/tests/test_label_two.move
+++ b/crates/iota-framework/packages/timelock/tests/test_label_two.move
@@ -1,4 +1,5 @@
// Copyright (c) 2024 IOTA Stiftung
+// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
#[test_only]
diff --git a/crates/iota-framework/packages/timelock/tests/timelock_tests.move b/crates/iota-framework/packages/timelock/tests/timelock_tests.move
index 7d920749f59..cef0085204f 100644
--- a/crates/iota-framework/packages/timelock/tests/timelock_tests.move
+++ b/crates/iota-framework/packages/timelock/tests/timelock_tests.move
@@ -5,16 +5,10 @@
#[test_only]
module timelock::timelock_tests {
-<<<<<<< HEAD:crates/sui-framework/packages/timelock/tests/timelock_tests.move
- use sui::balance;
- use sui::sui::SUI;
- use sui::test_scenario;
- use sui::test_utils::{Self, assert_eq};
-=======
use iota::balance;
use iota::iota::IOTA;
use iota::test_scenario;
->>>>>>> develop:crates/iota-framework/packages/timelock/tests/timelock_tests.move
+ use iota::test_utils::{Self, assert_eq};
use timelock::label::LabelerCap;
use timelock::timelock;
@@ -86,7 +80,7 @@ module timelock::timelock_tests {
let labeler_one = scenario.take_from_sender>();
// Minting some IOTA.
- let iota = balance::create_for_testing(10);
+ let iota = balance::create_for_testing(10);
// Lock the IOTA balance.
let timelock = timelock::lock_with_label(&labeler_one, iota, 100, scenario.ctx());
diff --git a/crates/iota-framework/packages/timelock/tests/timelocked_balance_tests.move b/crates/iota-framework/packages/timelock/tests/timelocked_balance_tests.move
index 0100cae7c36..a83516fd4ff 100644
--- a/crates/iota-framework/packages/timelock/tests/timelocked_balance_tests.move
+++ b/crates/iota-framework/packages/timelock/tests/timelocked_balance_tests.move
@@ -5,16 +5,10 @@
#[test_only]
module timelock::timelocked_balance_tests {
-<<<<<<< HEAD:crates/sui-framework/packages/timelock/tests/timelocked_balance_tests.move
- use sui::balance;
- use sui::sui::SUI;
- use sui::test_scenario;
- use sui::test_utils::{Self, assert_eq};
-=======
use iota::balance;
use iota::iota::IOTA;
use iota::test_scenario;
->>>>>>> develop:crates/iota-framework/packages/timelock/tests/timelocked_balance_tests.move
+ use iota::test_utils::{Self, assert_eq};
use timelock::label::LabelerCap;
use timelock::timelock;
@@ -67,8 +61,8 @@ module timelock::timelocked_balance_tests {
let labeler_one = scenario.take_from_sender>();
// Minting some IOTA.
- let iota1 = balance::create_for_testing(10);
- let iota2 = balance::create_for_testing(15);
+ let iota1 = balance::create_for_testing(10);
+ let iota2 = balance::create_for_testing(15);
// Lock the IOTA balances.
let mut timelock1 = timelock::lock_with_label(&labeler_one, iota1, 100, scenario.ctx());
@@ -133,8 +127,8 @@ module timelock::timelocked_balance_tests {
let labeler_two = scenario.take_from_sender>();
// Minting some IOTA.
- let iota1 = balance::create_for_testing(10);
- let iota2 = balance::create_for_testing(15);
+ let iota1 = balance::create_for_testing(10);
+ let iota2 = balance::create_for_testing(15);
// Lock the IOTA balance.
let mut timelock1 = timelock::lock_with_label(&labeler_one, iota1, 100, scenario.ctx());
@@ -349,7 +343,7 @@ module timelock::timelocked_balance_tests {
let labeler_one = scenario.take_from_sender>();
// Minting some IOTA.
- let iota = balance::create_for_testing(10);
+ let iota = balance::create_for_testing(10);
// Lock the IOTA balance.
let mut original = timelock::lock_with_label(&labeler_one, iota, 100, scenario.ctx());
diff --git a/crates/iota-framework/packages/timelock/tests/timelocked_delegation_tests.move b/crates/iota-framework/packages/timelock/tests/timelocked_delegation_tests.move
index d32316ae438..fea515eb2dd 100644
--- a/crates/iota-framework/packages/timelock/tests/timelocked_delegation_tests.move
+++ b/crates/iota-framework/packages/timelock/tests/timelocked_delegation_tests.move
@@ -4,17 +4,7 @@
#[test_only]
module timelock::timelocked_stake_tests {
-<<<<<<< HEAD:crates/sui-framework/packages/timelock/tests/timelocked_delegation_tests.move
-
- use sui::balance;
- use sui::balance::Balance;
- use sui::coin::Coin;
- use sui::sui::SUI;
- use sui::table::Table;
- use sui::test_scenario::{Self, Scenario};
- use sui::test_utils::assert_eq;
- use sui::test_utils;
-=======
+
use iota::balance;
use iota::balance::Balance;
use iota::coin::Coin;
@@ -23,7 +13,6 @@ module timelock::timelocked_stake_tests {
use iota::test_scenario::{Self, Scenario};
use iota::test_utils::assert_eq;
use iota::test_utils;
->>>>>>> develop:crates/iota-framework/packages/timelock/tests/timelocked_delegation_tests.move
use iota_system::iota_system::IotaSystemState;
use iota_system::staking_pool::{Self, PoolTokenExchangeRate};
@@ -153,16 +142,15 @@ module timelock::timelocked_stake_tests {
}
#[test]
-<<<<<<< HEAD:crates/sui-framework/packages/timelock/tests/timelocked_delegation_tests.move
fun test_join_same_labels() {
- set_up_sui_system_state();
+ set_up_iota_system_state();
let mut scenario_val = test_scenario::begin(STAKER_ADDR_1);
let scenario = &mut scenario_val;
set_up_timelock_labeler_caps(STAKER_ADDR_1, scenario);
- // Create two instances of labeled staked sui w/ different amounts
+ // Create two instances of labeled staked iota w/ different amounts
scenario.next_tx(STAKER_ADDR_1);
{
let labeler_one = scenario.take_from_sender>();
@@ -176,13 +164,13 @@ module timelock::timelocked_stake_tests {
// Verify that these can be merged
scenario.next_tx(STAKER_ADDR_1);
{
- let staked_sui_ids = scenario.ids_for_sender();
- let mut part1 = scenario.take_from_sender_by_id(staked_sui_ids[0]);
- let part2 = scenario.take_from_sender_by_id(staked_sui_ids[1]);
+ let staked_iota_ids = scenario.ids_for_sender();
+ let mut part1 = scenario.take_from_sender_by_id(staked_iota_ids[0]);
+ let part2 = scenario.take_from_sender_by_id(staked_iota_ids[1]);
part1.join(part2);
- assert_eq(part1.staked_sui_amount(), 110 * MIST_PER_SUI);
+ assert_eq(part1.staked_iota_amount(), 110 * MICROS_PER_IOTA);
assert_eq(part1.expiration_timestamp_ms(), 10);
assert_eq(part1.label().borrow().is_type(), true);
@@ -192,16 +180,16 @@ module timelock::timelocked_stake_tests {
}
#[test]
- #[expected_failure(abort_code = timelocked_staked_sui::EIncompatibleTimelockedStakedSui)]
+ #[expected_failure(abort_code = timelocked_staked_iota::EIncompatibleTimelockedStakedIota)]
fun test_join_different_labels() {
- set_up_sui_system_state();
+ set_up_iota_system_state();
let mut scenario_val = test_scenario::begin(STAKER_ADDR_1);
let scenario = &mut scenario_val;
set_up_timelock_labeler_caps(STAKER_ADDR_1, scenario);
- // Create two instances of labeled staked sui w/ different labels
+ // Create two instances of labeled staked iota w/ different labels
scenario.next_tx(STAKER_ADDR_1);
{
let labeler_one = scenario.take_from_sender>();
@@ -217,9 +205,9 @@ module timelock::timelocked_stake_tests {
// Verify that these cannot be merged
scenario.next_tx(STAKER_ADDR_1);
{
- let staked_sui_ids = scenario.ids_for_sender();
- let mut part1 = scenario.take_from_sender_by_id(staked_sui_ids[0]);
- let part2 = scenario.take_from_sender_by_id(staked_sui_ids[1]);
+ let staked_iota_ids = scenario.ids_for_sender();
+ let mut part1 = scenario.take_from_sender_by_id(staked_iota_ids[0]);
+ let part2 = scenario.take_from_sender_by_id(staked_iota_ids[1]);
part1.join(part2);
@@ -230,14 +218,14 @@ module timelock::timelocked_stake_tests {
#[test]
fun test_split_with_labels() {
- set_up_sui_system_state();
+ set_up_iota_system_state();
let mut scenario_val = test_scenario::begin(STAKER_ADDR_1);
let scenario = &mut scenario_val;
set_up_timelock_labeler_caps(STAKER_ADDR_1, scenario);
- // Create one instance of labeled staked sui
+ // Create one instance of labeled staked iota
scenario.next_tx(STAKER_ADDR_1);
{
let labeler_one = scenario.take_from_sender>();
@@ -252,14 +240,14 @@ module timelock::timelocked_stake_tests {
// Verify that it can be splitted
scenario.next_tx(STAKER_ADDR_1);
{
- let mut original = scenario.take_from_sender();
- let splitted = original.split(20 * MIST_PER_SUI, scenario.ctx());
+ let mut original = scenario.take_from_sender();
+ let splitted = original.split(20 * MICROS_PER_IOTA, scenario.ctx());
- assert_eq(original.staked_sui_amount(), 40 * MIST_PER_SUI);
+ assert_eq(original.staked_iota_amount(), 40 * MICROS_PER_IOTA);
assert_eq(original.expiration_timestamp_ms(), 10);
assert_eq(original.label().borrow().is_type(), true);
- assert_eq(splitted.staked_sui_amount(), 20 * MIST_PER_SUI);
+ assert_eq(splitted.staked_iota_amount(), 20 * MICROS_PER_IOTA);
assert_eq(splitted.expiration_timestamp_ms(), 10);
assert_eq(splitted.label().borrow().is_type(), true);
@@ -270,10 +258,7 @@ module timelock::timelocked_stake_tests {
}
#[test]
- #[expected_failure(abort_code = staking_pool::EStakedSuiBelowThreshold)]
-=======
#[expected_failure(abort_code = staking_pool::EStakedIotaBelowThreshold)]
->>>>>>> develop:crates/iota-framework/packages/timelock/tests/timelocked_delegation_tests.move
fun test_split_below_threshold() {
set_up_iota_system_state();
let mut scenario_val = test_scenario::begin(STAKER_ADDR_1);
@@ -375,7 +360,7 @@ module timelock::timelocked_stake_tests {
#[test]
fun test_add_remove_labeled_stake_flow() {
- set_up_sui_system_state();
+ set_up_iota_system_state();
let mut scenario_val = test_scenario::begin(VALIDATOR_ADDR_1);
let scenario = &mut scenario_val;
@@ -385,7 +370,7 @@ module timelock::timelocked_stake_tests {
{
let labeler_one = scenario.take_from_sender>();
- let mut system_state = scenario.take_shared();
+ let mut system_state = scenario.take_shared();
let system_state_mut_ref = &mut system_state;
let ctx = scenario.ctx();
@@ -393,13 +378,13 @@ module timelock::timelocked_stake_tests {
// Create a stake to VALIDATOR_ADDR_1.
timelocked_staking::request_add_stake(
system_state_mut_ref,
- timelock::lock_with_label(&labeler_one, balance::create_for_testing(60 * MIST_PER_SUI), 10, ctx),
+ timelock::lock_with_label(&labeler_one, balance::create_for_testing(60 * MICROS_PER_IOTA), 10, ctx),
VALIDATOR_ADDR_1,
ctx
);
- assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1), 100 * MIST_PER_SUI);
- assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2), 100 * MIST_PER_SUI);
+ assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1), 100 * MICROS_PER_IOTA);
+ assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2), 100 * MICROS_PER_IOTA);
test_scenario::return_shared(system_state);
@@ -410,19 +395,19 @@ module timelock::timelocked_stake_tests {
scenario.next_tx(STAKER_ADDR_1);
{
- let staked_sui = scenario.take_from_sender();
- assert_eq(staked_sui.amount(), 60 * MIST_PER_SUI);
+ let staked_iota = scenario.take_from_sender();
+ assert_eq(staked_iota.amount(), 60 * MICROS_PER_IOTA);
- let mut system_state = scenario.take_shared();
+ let mut system_state = scenario.take_shared();
let system_state_mut_ref = &mut system_state;
- assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1), 160 * MIST_PER_SUI);
- assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2), 100 * MIST_PER_SUI);
+ assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1), 160 * MICROS_PER_IOTA);
+ assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2), 100 * MICROS_PER_IOTA);
// Unstake from VALIDATOR_ADDR_1
- timelocked_staking::request_withdraw_stake(system_state_mut_ref, staked_sui, scenario.ctx());
+ timelocked_staking::request_withdraw_stake(system_state_mut_ref, staked_iota, scenario.ctx());
- assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1), 160 * MIST_PER_SUI);
+ assert_eq(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1), 160 * MICROS_PER_IOTA);
test_scenario::return_shared(system_state);
};
@@ -430,14 +415,14 @@ module timelock::timelocked_stake_tests {
scenario.next_tx(STAKER_ADDR_1);
{
- let mut system_state = scenario.take_shared();
+ let mut system_state = scenario.take_shared();
- assert_eq(system_state.validator_stake_amount(VALIDATOR_ADDR_1), 100 * MIST_PER_SUI);
+ assert_eq(system_state.validator_stake_amount(VALIDATOR_ADDR_1), 100 * MICROS_PER_IOTA);
// Check the time-locked balance.
- let timelock = scenario.take_from_sender>>();
+ let timelock = scenario.take_from_sender>>();
- assert_eq(timelock.locked().value(), 60 * MIST_PER_SUI);
+ assert_eq(timelock.locked().value(), 60 * MICROS_PER_IOTA);
assert_eq(timelock.expiration_timestamp_ms(), 10);
assert_eq(timelock.label().borrow().is_type(), true);
@@ -944,7 +929,6 @@ module timelock::timelocked_stake_tests {
scenario_val.end();
}
-<<<<<<< HEAD:crates/sui-framework/packages/timelock/tests/timelocked_delegation_tests.move
fun set_up_timelock_labeler_caps(to: address, scenario: &mut Scenario) {
scenario.next_tx(to);
@@ -952,10 +936,7 @@ module timelock::timelocked_stake_tests {
test_label_two::assign_labeler_cap(to, scenario.ctx());
}
- fun set_up_sui_system_state_with_storage_fund() {
-=======
fun set_up_iota_system_state_with_storage_fund() {
->>>>>>> develop:crates/iota-framework/packages/timelock/tests/timelocked_delegation_tests.move
let mut scenario_val = test_scenario::begin(@0x0);
let scenario = &mut scenario_val;
let ctx = scenario.ctx();
@@ -998,14 +979,14 @@ module timelock::timelocked_stake_tests {
) {
scenario.next_tx(staker);
- let mut system_state = scenario.take_shared();
+ let mut system_state = scenario.take_shared();
let ctx = scenario.ctx();
timelocked_staking::request_add_stake(
&mut system_state,
timelock::lock_with_label(
cap,
- balance::create_for_testing(amount * MIST_PER_SUI),
+ balance::create_for_testing(amount * MICROS_PER_IOTA),
expiration_timestamp_ms,
ctx),
validator,
diff --git a/crates/sui-framework/docs/timelock/timelocked_staked_sui.md b/crates/sui-framework/docs/timelock/timelocked_staked_sui.md
deleted file mode 100644
index 900e0cd9f84..00000000000
--- a/crates/sui-framework/docs/timelock/timelocked_staked_sui.md
+++ /dev/null
@@ -1,432 +0,0 @@
----
-title: Module `0x10cf::timelocked_staked_sui`
----
-
-
-
-- [Resource `TimelockedStakedSui`](#0x10cf_timelocked_staked_sui_TimelockedStakedSui)
-- [Constants](#@Constants_0)
-- [Function `create`](#0x10cf_timelocked_staked_sui_create)
-- [Function `pool_id`](#0x10cf_timelocked_staked_sui_pool_id)
-- [Function `staked_sui_amount`](#0x10cf_timelocked_staked_sui_staked_sui_amount)
-- [Function `stake_activation_epoch`](#0x10cf_timelocked_staked_sui_stake_activation_epoch)
-- [Function `expiration_timestamp_ms`](#0x10cf_timelocked_staked_sui_expiration_timestamp_ms)
-- [Function `label`](#0x10cf_timelocked_staked_sui_label)
-- [Function `split`](#0x10cf_timelocked_staked_sui_split)
-- [Function `split_staked_sui`](#0x10cf_timelocked_staked_sui_split_staked_sui)
-- [Function `join_staked_sui`](#0x10cf_timelocked_staked_sui_join_staked_sui)
-- [Function `is_equal_staking_metadata`](#0x10cf_timelocked_staked_sui_is_equal_staking_metadata)
-- [Function `unpack`](#0x10cf_timelocked_staked_sui_unpack)
-- [Function `transfer`](#0x10cf_timelocked_staked_sui_transfer)
-
-
-use 0x10cf::label ;
-use 0x1::option ;
-use 0x2::object ;
-use 0x2::transfer ;
-use 0x2::tx_context ;
-use 0x3::staking_pool ;
-
-
-
-
-
-
-## Resource `TimelockedStakedSui`
-
-A self-custodial object holding the timelocked staked SUI tokens.
-
-
-struct TimelockedStakedSui has key
-
-
-
-
-
-Fields
-
-
-
-
-id: object::UID
-
-
-
-
-
-staked_sui: staking_pool::StakedSui
-
-
- A self-custodial object holding the staked SUI tokens.
-
-
-expiration_timestamp_ms: u64
-
-
- This is the epoch time stamp of when the lock expires.
-
-
-label : option::Option <label::Label >
-
-
- Timelock related label.
-
-
-
-
-
-
-
-
-## Constants
-
-
-
-
-
-
-const EIncompatibleTimelockedStakedSui : u64 = 0;
-
-
-
-
-
-
-## Function `create`
-
-Create a new instance of TimelockedStakedSui
.
-
-
-public (friend ) fun create (staked_sui: staking_pool::StakedSui , expiration_timestamp_ms: u64, label : option::Option <label::Label >, ctx: &mut tx_context::TxContext ): timelocked_staked_sui::TimelockedStakedSui
-
-
-
-
-
-Implementation
-
-
-public (package) fun create (
- staked_sui: StakedSui,
- expiration_timestamp_ms: u64,
- label : Option<Label>,
- ctx: &mut TxContext
-): TimelockedStakedSui {
- TimelockedStakedSui {
- id: object::new (ctx),
- staked_sui,
- expiration_timestamp_ms,
- label ,
- }
-}
-
-
-
-
-
-
-
-
-## Function `pool_id`
-
-Function to get the pool id of a TimelockedStakedSui
.
-
-
-public fun pool_id (self: &timelocked_staked_sui::TimelockedStakedSui ): object::ID
-
-
-
-
-
-Implementation
-
-
-public fun pool_id (self: &TimelockedStakedSui ): ID { self.staked_sui.pool_id () }
-
-
-
-
-
-
-
-
-## Function `staked_sui_amount`
-
-Function to get the staked sui amount of a TimelockedStakedSui
.
-
-
-public fun staked_sui_amount (self: &timelocked_staked_sui::TimelockedStakedSui ): u64
-
-
-
-
-
-Implementation
-
-
-public fun staked_sui_amount (self: &TimelockedStakedSui ): u64 { self.staked_sui.staked_sui_amount () }
-
-
-
-
-
-
-
-
-## Function `stake_activation_epoch`
-
-Function to get the stake activation epoch of a TimelockedStakedSui
.
-
-
-public fun stake_activation_epoch (self: &timelocked_staked_sui::TimelockedStakedSui ): u64
-
-
-
-
-
-Implementation
-
-
-public fun stake_activation_epoch (self: &TimelockedStakedSui ): u64 {
- self.staked_sui.stake_activation_epoch ()
-}
-
-
-
-
-
-
-
-
-## Function `expiration_timestamp_ms`
-
-Function to get the expiration timestamp of a TimelockedStakedSui
.
-
-
-public fun expiration_timestamp_ms (self: &timelocked_staked_sui::TimelockedStakedSui ): u64
-
-
-
-
-
-Implementation
-
-
-public fun expiration_timestamp_ms (self: &TimelockedStakedSui ): u64 {
- self.expiration_timestamp_ms
-}
-
-
-
-
-
-
-
-
-## Function `label`
-
-Function to get the label of a TimelockedStakedSui
.
-
-
-public fun label (self: &timelocked_staked_sui::TimelockedStakedSui ): &option::Option <label::Label >
-
-
-
-
-
-Implementation
-
-
-public fun label (self: &TimelockedStakedSui ): &Option<Label> {
- &self.label
-}
-
-
-
-
-
-
-
-
-## Function `split`
-
-Split TimelockedStakedSui
into two parts, one with principal split_amount
,
-and the remaining principal is left in self
.
-All the other parameters of the TimelockedStakedSui
like stake_activation_epoch
or pool_id
remain the same.
-
-
-public fun split (self: &mut timelocked_staked_sui::TimelockedStakedSui , split_amount: u64, ctx: &mut tx_context::TxContext ): timelocked_staked_sui::TimelockedStakedSui
-
-
-
-
-
-Implementation
-
-
-public fun split (self: &mut TimelockedStakedSui , split_amount: u64, ctx: &mut TxContext): TimelockedStakedSui {
- let splitted_stake = self.staked_sui.split (split_amount, ctx);
-
- TimelockedStakedSui {
- id: object::new (ctx),
- staked_sui: splitted_stake,
- expiration_timestamp_ms: self.expiration_timestamp_ms,
- label : label::clone_opt (&self.label ),
- }
-}
-
-
-
-
-
-
-
-
-## Function `split_staked_sui`
-
-Split the given TimelockedStakedSui
to the two parts, one with principal split_amount
,
-transfer the newly split part to the sender address.
-
-
-public entry fun split_staked_sui (stake: &mut timelocked_staked_sui::TimelockedStakedSui , split_amount: u64, ctx: &mut tx_context::TxContext )
-
-
-
-
-
-Implementation
-
-
-public entry fun split_staked_sui (stake: &mut TimelockedStakedSui , split_amount: u64, ctx: &mut TxContext) {
- transfer::transfer (split (stake, split_amount, ctx), ctx.sender());
-}
-
-
-
-
-
-
-
-
-## Function `join_staked_sui`
-
-Consume the staked sui other
and add its value to self
.
-Aborts if some of the staking parameters are incompatible (pool id, stake activation epoch, etc.)
-
-
-public entry fun join_staked_sui (self: &mut timelocked_staked_sui::TimelockedStakedSui , other: timelocked_staked_sui::TimelockedStakedSui )
-
-
-
-
-
-Implementation
-
-
-public entry fun join_staked_sui (self: &mut TimelockedStakedSui , other: TimelockedStakedSui ) {
- assert !(self.is_equal_staking_metadata (&other), EIncompatibleTimelockedStakedSui );
-
- let TimelockedStakedSui {
- id,
- staked_sui,
- expiration_timestamp_ms: _,
- label ,
- } = other;
-
- label::destroy_opt (label );
-
- id.delete();
-
- self.staked_sui.join(staked_sui);
-}
-
-
-
-
-
-
-
-
-## Function `is_equal_staking_metadata`
-
-Returns true if all the staking parameters of the staked sui except the principal are identical
-
-
-public fun is_equal_staking_metadata (self: &timelocked_staked_sui::TimelockedStakedSui , other: &timelocked_staked_sui::TimelockedStakedSui ): bool
-
-
-
-
-
-Implementation
-
-
-public fun is_equal_staking_metadata (self: &TimelockedStakedSui , other: &TimelockedStakedSui ): bool {
- self.staked_sui.is_equal_staking_metadata (&other.staked_sui) &&
- (self.expiration_timestamp_ms == other.expiration_timestamp_ms) &&
- (self.label () == other.label ())
-}
-
-
-
-
-
-
-
-
-## Function `unpack`
-
-A utility function to destroy a TimelockedStakedSui
.
-
-
-public (friend ) fun unpack (self: timelocked_staked_sui::TimelockedStakedSui ): (staking_pool::StakedSui , u64, option::Option <label::Label >)
-
-
-
-
-
-Implementation
-
-
-public (package) fun unpack (self: TimelockedStakedSui ): (StakedSui, u64, Option<Label>) {
- let TimelockedStakedSui {
- id,
- staked_sui,
- expiration_timestamp_ms,
- label ,
- } = self;
-
- object::delete (id);
-
- (staked_sui, expiration_timestamp_ms, label )
-}
-
-
-
-
-
-
-
-
-## Function `transfer`
-
-An utility function to transfer a TimelockedStakedSui
.
-
-
-public (friend ) fun transfer (stake: timelocked_staked_sui::TimelockedStakedSui , recipient: address )
-
-
-
-
-
-Implementation
-
-
-public (package) fun transfer (stake: TimelockedStakedSui , recipient: address ) {
- transfer::transfer (stake, recipient);
-}
-
-
-
-
-
diff --git a/crates/sui-framework/docs/timelock/timelocked_staking.md b/crates/sui-framework/docs/timelock/timelocked_staking.md
deleted file mode 100644
index 0042a15fc45..00000000000
--- a/crates/sui-framework/docs/timelock/timelocked_staking.md
+++ /dev/null
@@ -1,314 +0,0 @@
----
-title: Module `0x10cf::timelocked_staking`
----
-
-
-
-- [Constants](#@Constants_0)
-- [Function `request_add_stake`](#0x10cf_timelocked_staking_request_add_stake)
-- [Function `request_add_stake_non_entry`](#0x10cf_timelocked_staking_request_add_stake_non_entry)
-- [Function `request_add_stake_mul_bal`](#0x10cf_timelocked_staking_request_add_stake_mul_bal)
-- [Function `request_add_stake_mul_bal_non_entry`](#0x10cf_timelocked_staking_request_add_stake_mul_bal_non_entry)
-- [Function `request_withdraw_stake`](#0x10cf_timelocked_staking_request_withdraw_stake)
-- [Function `request_withdraw_stake_non_entry`](#0x10cf_timelocked_staking_request_withdraw_stake_non_entry)
-
-
-use 0x10cf::label ;
-use 0x10cf::timelock ;
-use 0x10cf::timelocked_staked_sui ;
-use 0x1::option ;
-use 0x2::balance ;
-use 0x2::coin ;
-use 0x2::sui ;
-use 0x2::transfer ;
-use 0x2::tx_context ;
-use 0x3::staking_pool ;
-use 0x3::sui_system ;
-
-
-
-
-
-
-## Constants
-
-
-
-
-For when trying to stake an expired time-locked balance.
-
-
-const ETimeLockShouldNotBeExpired : u64 = 0;
-
-
-
-
-
-
-## Function `request_add_stake`
-
-Add a time-locked stake to a validator's staking pool.
-
-
-public entry fun request_add_stake (sui_system : &mut sui_system::SuiSystemState , timelocked_balance : timelock::TimeLock <balance::Balance <sui::SUI >>, validator_address: address , ctx: &mut tx_context::TxContext )
-
-
-
-
-
-Implementation
-
-
-public entry fun request_add_stake (
- sui_system : &mut SuiSystemState,
- timelocked_balance : TimeLock<Balance<SUI>>,
- validator_address: address ,
- ctx: &mut TxContext,
-) {
- // Stake the time-locked balance .
- let timelocked_staked_sui = request_add_stake_non_entry (sui_system , timelocked_balance , validator_address, ctx);
-
- // Transfer the receipt to the sender.
- timelocked_staked_sui::transfer (timelocked_staked_sui , ctx.sender());
-}
-
-
-
-
-
-
-
-
-## Function `request_add_stake_non_entry`
-
-The non-entry version of request_add_stake
, which returns the time-locked staked SUI instead of transferring it to the sender.
-
-
-public fun request_add_stake_non_entry (sui_system : &mut sui_system::SuiSystemState , timelocked_balance : timelock::TimeLock <balance::Balance <sui::SUI >>, validator_address: address , ctx: &mut tx_context::TxContext ): timelocked_staked_sui::TimelockedStakedSui
-
-
-
-
-
-Implementation
-
-
-public fun request_add_stake_non_entry (
- sui_system : &mut SuiSystemState,
- timelocked_balance : TimeLock<Balance<SUI>>,
- validator_address: address ,
- ctx: &mut TxContext,
-) : TimelockedStakedSui {
- // Check the preconditions.
- assert !(timelocked_balance .is_locked(ctx), ETimeLockShouldNotBeExpired );
-
- // Unpack the time-locked balance .
- let (balance , expiration_timestamp_ms, label ) = timelock::unpack (timelocked_balance );
-
- // Stake the time-locked balance .
- let staked_sui = sui_system .request_add_stake_non_entry (
- balance .into_coin(ctx),
- validator_address,
- ctx,
- );
-
- // Create and return a receipt.
- timelocked_staked_sui::create (
- staked_sui,
- expiration_timestamp_ms,
- label ,
- ctx,
- )
-}
-
-
-
-
-
-
-
-
-## Function `request_add_stake_mul_bal`
-
-Add a time-locked stake to a validator's staking pool using multiple time-locked balances.
-
-
-public entry fun request_add_stake_mul_bal (sui_system : &mut sui_system::SuiSystemState , timelocked_balances: vector <timelock::TimeLock <balance::Balance <sui::SUI >>>, validator_address: address , ctx: &mut tx_context::TxContext )
-
-
-
-
-
-Implementation
-
-
-public entry fun request_add_stake_mul_bal (
- sui_system : &mut SuiSystemState,
- timelocked_balances: vector <TimeLock<Balance<SUI>>>,
- validator_address: address ,
- ctx: &mut TxContext,
-) {
- // Stake the time-locked balances.
- let mut receipts = request_add_stake_mul_bal_non_entry (sui_system , timelocked_balances, validator_address, ctx);
-
- // Create useful variables.
- let (mut i, len) = (0, receipts.length());
-
- // Send all the receipts to the sender.
- while (i < len) {
- // Take a receipt.
- let receipt = receipts.pop_back();
-
- // Transfer the receipt to the sender.
- timelocked_staked_sui::transfer (receipt, ctx.sender());
-
- i = i + 1
- };
-
- // Destroy the empty vector .
- vector::destroy_empty (receipts)
-}
-
-
-
-
-
-
-
-
-## Function `request_add_stake_mul_bal_non_entry`
-
-The non-entry version of request_add_stake_mul_bal
,
-which returns a list of the time-locked staked SUIs instead of transferring them to the sender.
-
-
-public fun request_add_stake_mul_bal_non_entry (sui_system : &mut sui_system::SuiSystemState , timelocked_balances: vector <timelock::TimeLock <balance::Balance <sui::SUI >>>, validator_address: address , ctx: &mut tx_context::TxContext ): vector <timelocked_staked_sui::TimelockedStakedSui >
-
-
-
-
-
-Implementation
-
-
-public fun request_add_stake_mul_bal_non_entry (
- sui_system : &mut SuiSystemState,
- mut timelocked_balances: vector <TimeLock<Balance<SUI>>>,
- validator_address: address ,
- ctx: &mut TxContext,
-) : vector <TimelockedStakedSui> {
- // Create a vector to store the results.
- let mut result = vector [];
-
- // Create useful variables.
- let (mut i, len) = (0, timelocked_balances.length());
-
- // Stake all the time-locked balances.
- while (i < len) {
- // Take a time-locked balance .
- let timelocked_balance = timelocked_balances.pop_back();
-
- // Stake the time-locked balance .
- let timelocked_staked_sui = request_add_stake_non_entry (sui_system , timelocked_balance , validator_address, ctx);
-
- // Store the created receipt.
- result.push_back(timelocked_staked_sui );
-
- i = i + 1
- };
-
- // Destroy the empty vector .
- vector::destroy_empty (timelocked_balances);
-
- result
-}
-
-
-
-
-
-
-
-
-## Function `request_withdraw_stake`
-
-Withdraw a time-locked stake from a validator's staking pool.
-
-
-public entry fun request_withdraw_stake (sui_system : &mut sui_system::SuiSystemState , timelocked_staked_sui : timelocked_staked_sui::TimelockedStakedSui , ctx: &mut tx_context::TxContext )
-
-
-
-
-
-Implementation
-
-
-public entry fun request_withdraw_stake (
- sui_system : &mut SuiSystemState,
- timelocked_staked_sui : TimelockedStakedSui,
- ctx: &mut TxContext,
-) {
- // Withdraw the time-locked balance .
- let (timelocked_balance , reward) = request_withdraw_stake_non_entry (sui_system , timelocked_staked_sui , ctx);
-
- // Transfer the withdrawn time-locked balance to the sender.
- timelock::transfer (timelocked_balance , ctx.sender());
-
- // Send coins only if the reward is not zero.
- if (reward.value() > 0) {
- transfer::public_transfer (reward.into_coin(ctx), ctx.sender());
- }
- else {
- balance::destroy_zero (reward);
- }
-}
-
-
-
-
-
-
-
-
-## Function `request_withdraw_stake_non_entry`
-
-Non-entry version of request_withdraw_stake
that returns the withdrawn time-locked SUI and reward
-instead of transferring it to the sender.
-
-
-public fun request_withdraw_stake_non_entry (sui_system : &mut sui_system::SuiSystemState , timelocked_staked_sui : timelocked_staked_sui::TimelockedStakedSui , ctx: &mut tx_context::TxContext ): (timelock::TimeLock <balance::Balance <sui::SUI >>, balance::Balance <sui::SUI >)
-
-
-
-
-
-Implementation
-
-
-public fun request_withdraw_stake_non_entry (
- sui_system : &mut SuiSystemState,
- timelocked_staked_sui : TimelockedStakedSui,
- ctx: &mut TxContext,
-) : (TimeLock<Balance<SUI>>, Balance<SUI>) {
- // Unpack the `TimelockedStakedSui` instance.
- let (staked_sui, expiration_timestamp_ms, label ) = timelocked_staked_sui .unpack();
-
- // Store the original stake amount.
- let principal = staked_sui.staked_sui_amount();
-
- // Withdraw the balance .
- let mut withdraw_stake = sui_system .request_withdraw_stake_non_entry (staked_sui, ctx);
-
- // The sui_system withdraw functions return a balance that consists of the original staked amount plus the reward amount;
- // In here, it splits the original staked balance to timelock it again.
- let principal = withdraw_stake.split(principal);
-
- // Pack and return a time-locked balance , and the reward.
- (timelock::pack (principal, expiration_timestamp_ms, label , ctx), withdraw_stake)
-}
-
-
-
-
-
diff --git a/crates/sui-framework/packages/timelock/sources/timelocked_staked_sui.move b/crates/sui-framework/packages/timelock/sources/timelocked_staked_sui.move
deleted file mode 100644
index e7f2d0ace3d..00000000000
--- a/crates/sui-framework/packages/timelock/sources/timelocked_staked_sui.move
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (c) 2024 IOTA Stiftung
-// SPDX-License-Identifier: Apache-2.0
-
-module timelock::timelocked_staked_sui {
-
- use timelock::label::{Self, Label};
-
- use sui_system::staking_pool::StakedSui;
-
- const EIncompatibleTimelockedStakedSui: u64 = 0;
-
- /// A self-custodial object holding the timelocked staked SUI tokens.
- public struct TimelockedStakedSui has key {
- id: UID,
- /// A self-custodial object holding the staked SUI tokens.
- staked_sui: StakedSui,
- /// This is the epoch time stamp of when the lock expires.
- expiration_timestamp_ms: u64,
- /// Timelock related label.
- label: Option,
- }
-
- /// Create a new instance of `TimelockedStakedSui`.
- public(package) fun create(
- staked_sui: StakedSui,
- expiration_timestamp_ms: u64,
- label: Option,
- ctx: &mut TxContext
- ): TimelockedStakedSui {
- TimelockedStakedSui {
- id: object::new(ctx),
- staked_sui,
- expiration_timestamp_ms,
- label,
- }
- }
-
- /// Function to get the pool id of a `TimelockedStakedSui`.
- public fun pool_id(self: &TimelockedStakedSui): ID { self.staked_sui.pool_id() }
-
- /// Function to get the staked sui amount of a `TimelockedStakedSui`.
- public fun staked_sui_amount(self: &TimelockedStakedSui): u64 { self.staked_sui.staked_sui_amount() }
-
- /// Allows calling `.amount()` on `TimelockedStakedSui` to invoke `staked_sui_amount`
- public use fun staked_sui_amount as TimelockedStakedSui.amount;
-
- /// Function to get the stake activation epoch of a `TimelockedStakedSui`.
- public fun stake_activation_epoch(self: &TimelockedStakedSui): u64 {
- self.staked_sui.stake_activation_epoch()
- }
-
- /// Function to get the expiration timestamp of a `TimelockedStakedSui`.
- public fun expiration_timestamp_ms(self: &TimelockedStakedSui): u64 {
- self.expiration_timestamp_ms
- }
-
- /// Function to get the label of a `TimelockedStakedSui`.
- public fun label(self: &TimelockedStakedSui): &Option {
- &self.label
- }
-
- /// Split `TimelockedStakedSui` into two parts, one with principal `split_amount`,
- /// and the remaining principal is left in `self`.
- /// All the other parameters of the `TimelockedStakedSui` like `stake_activation_epoch` or `pool_id` remain the same.
- public fun split(self: &mut TimelockedStakedSui, split_amount: u64, ctx: &mut TxContext): TimelockedStakedSui {
- let splitted_stake = self.staked_sui.split(split_amount, ctx);
-
- TimelockedStakedSui {
- id: object::new(ctx),
- staked_sui: splitted_stake,
- expiration_timestamp_ms: self.expiration_timestamp_ms,
- label: label::clone_opt(&self.label),
- }
- }
-
- /// Split the given `TimelockedStakedSui` to the two parts, one with principal `split_amount`,
- /// transfer the newly split part to the sender address.
- public entry fun split_staked_sui(stake: &mut TimelockedStakedSui, split_amount: u64, ctx: &mut TxContext) {
- transfer::transfer(split(stake, split_amount, ctx), ctx.sender());
- }
-
- /// Allows calling `.split_to_sender()` on `TimelockedStakedSui` to invoke `split_staked_sui`
- public use fun split_staked_sui as TimelockedStakedSui.split_to_sender;
-
- /// Consume the staked sui `other` and add its value to `self`.
- /// Aborts if some of the staking parameters are incompatible (pool id, stake activation epoch, etc.)
- public entry fun join_staked_sui(self: &mut TimelockedStakedSui, other: TimelockedStakedSui) {
- assert!(self.is_equal_staking_metadata(&other), EIncompatibleTimelockedStakedSui);
-
- let TimelockedStakedSui {
- id,
- staked_sui,
- expiration_timestamp_ms: _,
- label,
- } = other;
-
- label::destroy_opt(label);
-
- id.delete();
-
- self.staked_sui.join(staked_sui);
- }
-
- /// Allows calling `.join()` on `TimelockedStakedSui` to invoke `join_staked_sui`
- public use fun join_staked_sui as TimelockedStakedSui.join;
-
- /// Returns true if all the staking parameters of the staked sui except the principal are identical
- public fun is_equal_staking_metadata(self: &TimelockedStakedSui, other: &TimelockedStakedSui): bool {
- self.staked_sui.is_equal_staking_metadata(&other.staked_sui) &&
- (self.expiration_timestamp_ms == other.expiration_timestamp_ms) &&
- (self.label() == other.label())
- }
-
- /// A utility function to destroy a `TimelockedStakedSui`.
- public(package) fun unpack(self: TimelockedStakedSui): (StakedSui, u64, Option) {
- let TimelockedStakedSui {
- id,
- staked_sui,
- expiration_timestamp_ms,
- label,
- } = self;
-
- object::delete(id);
-
- (staked_sui, expiration_timestamp_ms, label)
- }
-
- /// An utility function to transfer a `TimelockedStakedSui`.
- public(package) fun transfer(stake: TimelockedStakedSui, recipient: address) {
- transfer::transfer(stake, recipient);
- }
-}