Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce protocol version 3 #4741

Merged
merged 16 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
236 changes: 118 additions & 118 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ members = [

[workspace.package]
# This version string will be inherited by iota-core, iota-faucet, iota-node, iota-tools, iota-sdk, iota-move-build, and iota crates.
version = "0.8.0-alpha"
version = "0.9.0-alpha"

[profile.release]
# debug = 1 means line charts only, which is minimum needed for good stack traces
Expand Down
6 changes: 3 additions & 3 deletions crates/iota-e2e-tests/tests/snapshot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ async fn basic_read_cmd_snapshot_tests() -> Result<(), anyhow::Error> {
"iota client objects 0x0000000000000000000000000000000000000000000000000000000000000000", /* empty addr */
"iota client object 0x5", // valid object
"iota client object 0x5 --bcs", // valid object BCS
"iota client object 0x9135cb3b5aca99a1555b742bd11ddc45fba33343be182bdc161be69da2c41be1", /* valid object */
"iota client object 0x9135cb3b5aca99a1555b742bd11ddc45fba33343be182bdc161be69da2c41be1 --bcs", /* valid object BCS */
"iota client object 0x4d03f39deb5e27a76a568adb591da553688e6df6fb053bc9ac069f2bd9495ae3", /* valid object */
"iota client object 0x4d03f39deb5e27a76a568adb591da553688e6df6fb053bc9ac069f2bd9495ae3 --bcs", /* valid object BCS */
"iota client object 0x0000000000000000000000000000000000000000000000000000000000000000", /* non-existent object */
"iota client tx-block E5Zp4QQ84PQEceSw4JRi4VTScSAQweKSgdwp9XH4aVPd", // valid tx digest
"iota client tx-block 88FqW2hyUgShTyLcGzbh6scZB45XZYmXpXSxydkBVTPu", // valid tx digest
"iota client tx-block 11111111111111111111111111111111", /* non-existent tx
* digest */
];
Expand Down
886 changes: 443 additions & 443 deletions crates/iota-e2e-tests/tests/snapshots/snapshot_tests__body_fn.snap

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions crates/iota-framework-snapshot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@
"0x000000000000000000000000000000000000000000000000000000000000000b",
"0x000000000000000000000000000000000000000000000000000000000000107a"
]
},
"3": {
"git_revision": "378e09e7aa88",
"package_ids": [
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000000000000000000000000000003",
"0x000000000000000000000000000000000000000000000000000000000000000b",
"0x000000000000000000000000000000000000000000000000000000000000107a"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ module iota::coin_manager {
/// The error returned if a attempt is made to change the maximum supply that is lower than the total supply
const EMaximumSupplyLowerThanTotalSupply: u64 = 2;

/// The error returned if additional metadata already exists and you try to overwrite
const EAdditionalMetadataAlreadyExists: u64 = 3;
/// The error returned if a attempt is made to change the maximum supply that is higher than the maximum possible supply
const EMaximumSupplyHigherThanPossible: u64 = 3;

/// The error returned if you try to edit nonexisting additional metadata
const EAdditionalMetadataDoesNotExist: u64 = 4;

/// The error returned if you try to edit immutable metadata
const ENoMutableMetadata: u64 = 5;
/// The maximum supply supported by `CoinManager`
const MAX_SUPPLY: u64 = 18_446_744_073_709_551_614u64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this decreased by 1 from the number used below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #4595


/// Holds all related objects to a Coin in a convenient shared function
public struct CoinManager<phantom T> has key, store {
Expand Down Expand Up @@ -196,7 +196,6 @@ module iota::coin_manager {
manager: &mut CoinManager<T>,
value: Value
) {
assert!(!df::exists_(&manager.id, b"additional_metadata"), EAdditionalMetadataAlreadyExists);
df::add(&mut manager.id, b"additional_metadata", value);
}

Expand Down Expand Up @@ -230,6 +229,7 @@ module iota::coin_manager {
maximum_supply: u64
) {
assert!(option::is_none(&manager.maximum_supply), EMaximumSupplyAlreadySet);
assert!(maximum_supply <= MAX_SUPPLY, EMaximumSupplyHigherThanPossible);
assert!(total_supply(manager) <= maximum_supply, EMaximumSupplyLowerThanTotalSupply);
option::fill(&mut manager.maximum_supply, maximum_supply);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ module iota::coin_manager {
/// Get the maximum supply possible as a number.
/// If no maximum set it's the maximum u64 possible
public fun maximum_supply<T>(manager: &CoinManager<T>): u64 {
option::get_with_default(&manager.maximum_supply, 18_446_744_073_709_551_615u64)
option::get_with_default(&manager.maximum_supply, MAX_SUPPLY)
}

/// Convenience function returning the remaining supply that can be minted still
Expand Down Expand Up @@ -383,7 +383,6 @@ module iota::coin_manager {
manager: &mut CoinManager<T>,
name: string::String
) {
assert!(manager.metadata_is_immutable(), ENoMutableMetadata);
coin::update_name(&manager.treasury_cap, option::borrow_mut(&mut manager.metadata), name)
}

Expand All @@ -393,7 +392,6 @@ module iota::coin_manager {
manager: &mut CoinManager<T>,
symbol: ascii::String
) {
assert!(manager.metadata_is_immutable(), ENoMutableMetadata);
coin::update_symbol(&manager.treasury_cap, option::borrow_mut(&mut manager.metadata), symbol)
}

Expand All @@ -403,7 +401,6 @@ module iota::coin_manager {
manager: &mut CoinManager<T>,
description: string::String
) {
assert!(manager.metadata_is_immutable(), ENoMutableMetadata);
coin::update_description(&manager.treasury_cap, option::borrow_mut(&mut manager.metadata), description)
}

Expand All @@ -413,7 +410,6 @@ module iota::coin_manager {
manager: &mut CoinManager<T>,
url: ascii::String
) {
assert!(manager.metadata_is_immutable(), ENoMutableMetadata);
coin::update_icon_url(&manager.treasury_cap, option::borrow_mut(&mut manager.metadata), url)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ module iota::timelock {
use std::string::{Self, String};

use iota::balance::Balance;
use iota::clock::Clock;
use iota::labeler::LabelerCap;
use iota::system_admin_cap::IotaSystemAdminCap;

/// Expiration timestamp of the lock is in the past.
const EExpireEpochIsPast: u64 = 0;

/// The lock has not expired yet.
const ENotExpiredYet: u64 = 1;
/// For when trying to join two time-locked balances with different expiration time.
Expand All @@ -34,9 +33,6 @@ module iota::timelock {

/// Function to lock an object till a unix timestamp in milliseconds.
public fun lock<T: store>(locked: T, expiration_timestamp_ms: u64, ctx: &mut TxContext): TimeLock<T> {
// Check that `expiration_timestamp_ms` is valid.
check_expiration_timestamp_ms(expiration_timestamp_ms, ctx);

// Create a timelock.
pack(locked, expiration_timestamp_ms, option::none(), ctx)
}
Expand All @@ -48,9 +44,6 @@ module iota::timelock {
expiration_timestamp_ms: u64,
ctx: &mut TxContext
): TimeLock<T> {
// Check that `expiration_timestamp_ms` is valid.
check_expiration_timestamp_ms(expiration_timestamp_ms, ctx);

// Calculate a label value.
let label = type_name<L>();

Expand Down Expand Up @@ -81,7 +74,7 @@ module iota::timelock {
transfer(lock_with_label(labeler, obj, expiration_timestamp_ms, ctx), to);
}

/// Function to unlock the object from a `TimeLock`.
/// Function to unlock the object from a `TimeLock` based on the epoch start time.
public fun unlock<T: store>(self: TimeLock<T>, ctx: &TxContext): T {
// Unpack the timelock.
let (locked, expiration_timestamp_ms, _) = unpack(self);
Expand All @@ -92,6 +85,17 @@ module iota::timelock {
locked
}

/// Function to unlock the object from a `TimeLock` based on the `Clock` object.
public fun unlock_with_clock<T: store>(self: TimeLock<T>, clock: &Clock): T {
// Unpack the timelock.
let (locked, expiration_timestamp_ms, _) = unpack(self);

// Check if the lock has expired.
assert!(expiration_timestamp_ms <= clock.timestamp_ms(), ENotExpiredYet);

locked
}

// === TimeLock balance functions ===

/// Join two `TimeLock<Balance<T>>` together.
Expand Down Expand Up @@ -174,24 +178,32 @@ module iota::timelock {
self.expiration_timestamp_ms
}

/// Function to check if a `TimeLock` is locked.
/// Function to check if a `TimeLock` is locked based on the epoch start time.
public fun is_locked<T: store>(self: &TimeLock<T>, ctx: &TxContext): bool {
self.remaining_time(ctx) > 0
}

/// Function to get the remaining time of a `TimeLock`.
/// Function to get the remaining time of a `TimeLock` based on the epoch start time.
/// Returns 0 if the lock has expired.
public fun remaining_time<T: store>(self: &TimeLock<T>, ctx: &TxContext): u64 {
// Get the epoch timestamp.
let current_timestamp_ms = ctx.epoch_timestamp_ms();

// Check if the lock has expired.
if (self.expiration_timestamp_ms < current_timestamp_ms) {
return 0
};
self.remaining_time_with_timestamp(current_timestamp_ms)
}

// Calculate the remaining time.
self.expiration_timestamp_ms - current_timestamp_ms
/// Function to check if a `TimeLock` is locked based on the `Clock` object.
public fun is_locked_with_clock<T: store>(self: &TimeLock<T>, clock: &Clock): bool {
self.remaining_time_with_clock(clock) > 0
}

/// Function to get the remaining time of a `TimeLock` based on the `Clock` object.
/// Returns 0 if the lock has expired.
public fun remaining_time_with_clock<T: store>(self: &TimeLock<T>, clock: &Clock): u64 {
// Get the clock's timestamp.
let current_timestamp_ms = clock.timestamp_ms();

self.remaining_time_with_timestamp(current_timestamp_ms)
}

/// Function to get the locked object of a `TimeLock`.
Expand Down Expand Up @@ -253,12 +265,14 @@ module iota::timelock {
transfer::transfer(lock, receiver);
}

/// An utility function to check that the `expiration_timestamp_ms` value is valid.
fun check_expiration_timestamp_ms(expiration_timestamp_ms: u64, ctx: &TxContext) {
// Get the epoch timestamp.
let epoch_timestamp_ms = ctx.epoch_timestamp_ms();
/// An utility function to get the remaining time of a `TimeLock`.
fun remaining_time_with_timestamp<T: store>(self: &TimeLock<T>, current_timestamp_ms: u64): u64 {
// Check if the lock has expired.
if (self.expiration_timestamp_ms < current_timestamp_ms) {
return 0
};

// Check that `expiration_timestamp_ms` is valid.
assert!(expiration_timestamp_ms > epoch_timestamp_ms, EExpireEpochIsPast);
// Calculate the remaining time.
self.expiration_timestamp_ms - current_timestamp_ms
}
}
Loading
Loading