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.
-id: object::UID +id: object::UID
@@ -112,7 +112,7 @@ Create a LabelerCap Can be created only by consuming a one time witness. -
public fun create_labeler_cap<L: drop>(witness: L, ctx: &mut tx_context::TxContext): label::LabelerCap<L>
+
public fun create_labeler_cap<L: drop>(witness: L, ctx: &mut tx_context::TxContext): label::LabelerCap<L>
 
@@ -122,10 +122,10 @@ Can be created only by consuming a one time witness.
public fun create_labeler_cap<L: drop>(witness: L, ctx: &mut TxContext): LabelerCap<L> {
-    assert!(types::is_one_time_witness(&witness), ENotOneTimeWitness);
+    assert!(types::is_one_time_witness(&witness), ENotOneTimeWitness);
 
     LabelerCap<L> {
-        id: object::new(ctx),
+        id: object::new(ctx),
     }
 }
 
@@ -156,7 +156,7 @@ If a capability is destroyed, it is impossible to add the related labels. id, } = cap; - object::delete(id); + object::delete(id); }
diff --git a/crates/iota-framework/docs/timelock/timelock.md b/crates/iota-framework/docs/timelock/timelock.md index ab4d0fe843f..11e650f43ec 100644 --- a/crates/iota-framework/docs/timelock/timelock.md +++ b/crates/iota-framework/docs/timelock/timelock.md @@ -22,17 +22,11 @@ A timelock implementation. - [Function `check_expiration_timestamp_ms`](#0x10cf_timelock_check_expiration_timestamp_ms) -<<<<<<< HEAD:crates/sui-framework/docs/timelock/timelock.md
use 0x10cf::label;
 use 0x1::option;
-use 0x2::object;
-use 0x2::transfer;
-use 0x2::tx_context;
-=======
-
use 0x2::object;
+use 0x2::object;
 use 0x2::transfer;
 use 0x2::tx_context;
->>>>>>> develop:crates/iota-framework/docs/timelock/timelock.md
 
@@ -144,7 +138,7 @@ Function to lock an object till a unix timestamp in milliseconds. Function to lock a labeled object till a unix timestamp in milliseconds. -
public fun lock_with_label<T: store, L>(cap: &label::LabelerCap<L>, locked: T, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
+
public fun lock_with_label<T: store, L>(cap: &label::LabelerCap<L>, locked: T, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
 
@@ -181,11 +175,7 @@ Function to lock a labeled object till a unix timestamp in milliseconds. Function to unlock the object from a TimeLock. -<<<<<<< HEAD:crates/sui-framework/docs/timelock/timelock.md -
public fun unlock<T: store>(self: timelock::TimeLock<T>, ctx: &tx_context::TxContext): T
-=======
-
public fun unlock<T: store>(self: timelock::TimeLock<T>, ctx: &mut tx_context::TxContext): T
->>>>>>> develop:crates/iota-framework/docs/timelock/timelock.md
+
public fun unlock<T: store>(self: timelock::TimeLock<T>, ctx: &tx_context::TxContext): T
 
@@ -244,11 +234,7 @@ Function to get the expiration timestamp of a TimeLock is locked. -<<<<<<< HEAD:crates/sui-framework/docs/timelock/timelock.md -
public fun is_locked<T: store>(self: &timelock::TimeLock<T>, ctx: &tx_context::TxContext): bool
-=======
-
public fun is_locked<T: store>(self: &timelock::TimeLock<T>, ctx: &mut tx_context::TxContext): bool
->>>>>>> develop:crates/iota-framework/docs/timelock/timelock.md
+
public fun is_locked<T: store>(self: &timelock::TimeLock<T>, ctx: &tx_context::TxContext): bool
 
@@ -274,11 +260,7 @@ Function to get the remaining time of a remaining_time<T: store>(self: &timelock::TimeLock<T>, ctx: &tx_context::TxContext): u64 -======= -
public fun remaining_time<T: store>(self: &timelock::TimeLock<T>, ctx: &mut tx_context::TxContext): u64
->>>>>>> develop:crates/iota-framework/docs/timelock/timelock.md
+
public fun remaining_time<T: store>(self: &timelock::TimeLock<T>, ctx: &tx_context::TxContext): u64
 
@@ -363,11 +345,7 @@ Must not be callable from the outside, as one could modify the locked object. Function to get the label of a TimeLock. -<<<<<<< HEAD:crates/sui-framework/docs/timelock/timelock.md
public fun label<T: store>(self: &timelock::TimeLock<T>): &option::Option<label::Label>
-=======
-
public(friend) fun pack<T: store>(locked: T, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
->>>>>>> develop:crates/iota-framework/docs/timelock/timelock.md
 
@@ -392,7 +370,7 @@ Function to get the label of a TimeLock. -
public(friend) fun pack<T: store>(locked: T, expiration_timestamp_ms: u64, label: option::Option<label::Label>, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
+
public(friend) fun pack<T: store>(locked: T, expiration_timestamp_ms: u64, label: option::Option<label::Label>, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
 
@@ -489,7 +467,7 @@ An utility function to transfer a check_expiration_timestamp_ms(expiration_timestamp_ms: u64, ctx: &tx_context::TxContext) +
fun check_expiration_timestamp_ms(expiration_timestamp_ms: u64, ctx: &tx_context::TxContext)
 
diff --git a/crates/iota-framework/docs/timelock/timelocked_balance.md b/crates/iota-framework/docs/timelock/timelocked_balance.md index b41c6c567c7..396b2ff83b4 100644 --- a/crates/iota-framework/docs/timelock/timelocked_balance.md +++ b/crates/iota-framework/docs/timelock/timelocked_balance.md @@ -11,17 +11,11 @@ Utility functions for time-locked balance. - [Function `split`](#0x10cf_timelocked_balance_split) -<<<<<<< HEAD:crates/sui-framework/docs/timelock/timelocked_balance.md
use 0x10cf::label;
 use 0x10cf::timelock;
 use 0x1::option;
-use 0x2::balance;
-use 0x2::tx_context;
-=======
-
use 0x10cf::timelock;
 use 0x2::balance;
 use 0x2::tx_context;
->>>>>>> develop:crates/iota-framework/docs/timelock/timelocked_balance.md
 
@@ -72,16 +66,11 @@ Join two TimeLock<Balance<T>> together. assert!(self.expiration_timestamp_ms() == other.expiration_timestamp_ms(), EDifferentExpirationTime); assert!(self.label() == other.label(), EDifferentLabels); -<<<<<<< HEAD:crates/sui-framework/docs/timelock/timelocked_balance.md - // Unpack the time-locked balance. + // Unpack the time-locked balance. let (value, _, label) = timelock::unpack(other); // Destroy the labels. label::destroy_opt(label); -======= - // Unpack the time-locked balance. - let (value, _) = timelock::unpack(other); ->>>>>>> develop:crates/iota-framework/docs/timelock/timelocked_balance.md // Join the balances. self.locked_mut().join(value); @@ -148,13 +137,8 @@ Split a TimeLock<Balance<T>> and take a sub balance fro // Split the locked balance. let value = self.locked_mut().split(value); -<<<<<<< HEAD:crates/sui-framework/docs/timelock/timelocked_balance.md - // Pack the splitted balance into a timelock. - timelock::pack(value, self.expiration_timestamp_ms(), label::clone_opt(self.label()), ctx) -======= // Pack the splitted balance into a timelock. - timelock::pack(value, self.expiration_timestamp_ms(), ctx) ->>>>>>> develop:crates/iota-framework/docs/timelock/timelocked_balance.md + timelock::pack(value, self.expiration_timestamp_ms(), label::clone_opt(self.label()), ctx) }
diff --git a/crates/iota-framework/docs/timelock/timelocked_staked_iota.md b/crates/iota-framework/docs/timelock/timelocked_staked_iota.md index fcdceae876d..57fb7d6be21 100644 --- a/crates/iota-framework/docs/timelock/timelocked_staked_iota.md +++ b/crates/iota-framework/docs/timelock/timelocked_staked_iota.md @@ -11,6 +11,7 @@ title: Module `0x10cf::timelocked_staked_iota` - [Function `staked_iota_amount`](#0x10cf_timelocked_staked_iota_staked_iota_amount) - [Function `stake_activation_epoch`](#0x10cf_timelocked_staked_iota_stake_activation_epoch) - [Function `expiration_timestamp_ms`](#0x10cf_timelocked_staked_iota_expiration_timestamp_ms) +- [Function `label`](#0x10cf_timelocked_staked_iota_label) - [Function `split`](#0x10cf_timelocked_staked_iota_split) - [Function `split_staked_iota`](#0x10cf_timelocked_staked_iota_split_staked_iota) - [Function `join_staked_iota`](#0x10cf_timelocked_staked_iota_join_staked_iota) @@ -19,7 +20,9 @@ title: Module `0x10cf::timelocked_staked_iota` - [Function `transfer`](#0x10cf_timelocked_staked_iota_transfer) -
use 0x2::object;
+
use 0x10cf::label;
+use 0x1::option;
+use 0x2::object;
 use 0x2::transfer;
 use 0x2::tx_context;
 use 0x3::staking_pool;
@@ -62,6 +65,12 @@ A self-custodial object holding the timelocked staked IOTA tokens.
 
This is the epoch time stamp of when the lock expires.
+
+label: option::Option<label::Label> +
+
+ Timelock related label. +
@@ -88,7 +97,7 @@ A self-custodial object holding the timelocked staked IOTA tokens. Create a new instance of TimelockedStakedIota. -
public(friend) fun create(staked_iota: staking_pool::StakedIota, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext): timelocked_staked_iota::TimelockedStakedIota
+
public(friend) fun create(staked_iota: staking_pool::StakedIota, expiration_timestamp_ms: u64, label: option::Option<label::Label>, ctx: &mut tx_context::TxContext): timelocked_staked_iota::TimelockedStakedIota
 
@@ -100,12 +109,14 @@ Create a new instance of create( staked_iota: StakedIota, expiration_timestamp_ms: u64, + label: Option<Label>, ctx: &mut TxContext ): TimelockedStakedIota { TimelockedStakedIota { id: object::new(ctx), staked_iota, - expiration_timestamp_ms + expiration_timestamp_ms, + label, } }
@@ -208,6 +219,31 @@ Function to get the expiration timestamp of a + +## 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