diff --git a/SUMMARY.md b/SUMMARY.md index ae290d8..8629d10 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -28,5 +28,11 @@ - [Heterogeneous Collections](./unit-four/lessons/3_heterogeneous_collections.md) - [Marketplace Contract](./unit-four/lessons/4_marketplace_contract.md) - [Deployment and Testing](./unit-four/lessons/5_deployment_and_testing.md) +- [Unit Five: Sui Kiosk](./unit-four/readme.md) + - [Programmable Transaction Block](./unit-five/lessons/1_programmable_transaction_block.md) + - [Hot Potato Design Pattern](./unit-five/lessons/2_hot_potato_pattern.md) + - [Sui Kiosk Basic Concepts](./unit-five/lessons/3_kiosk_basics.md) + - [Sui Kiosk Basic Usage](./unit-five/lessons/4_kiosk_basic_usage.md) + - [Transfer Policy](./unit-five/lessons/5_transfer_policy.md) - [Advanced Topics](./advanced-topics/readme.md) - [BCS Encoding](./advanced-topics/BCS_encoding/lessons/BCS_encoding.md) diff --git a/advanced-topics/BCS_encoding/example_projects/bcs_move/Move.toml b/advanced-topics/BCS_encoding/example_projects/bcs_move/Move.toml index 8bc8ba5..af99aa6 100644 --- a/advanced-topics/BCS_encoding/example_projects/bcs_move/Move.toml +++ b/advanced-topics/BCS_encoding/example_projects/bcs_move/Move.toml @@ -1,6 +1,7 @@ [package] name = "bcs_move" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/advanced-topics/BCS_encoding/example_projects/bcs_move/sources/bcs_object.move b/advanced-topics/BCS_encoding/example_projects/bcs_move/sources/bcs_object.move index 3932bc1..7e6cb3a 100644 --- a/advanced-topics/BCS_encoding/example_projects/bcs_move/sources/bcs_object.move +++ b/advanced-topics/BCS_encoding/example_projects/bcs_move/sources/bcs_object.move @@ -4,11 +4,11 @@ module bcs_move::bcs_object { use sui::object::{Self, ID}; use sui::event; - struct Metadata has drop, copy { + public struct Metadata has drop, copy { name: std::ascii::String } - struct BCSObject has drop, copy { + public struct BCSObject has drop, copy { id: ID, owner: address, meta: Metadata @@ -16,7 +16,7 @@ module bcs_move::bcs_object { public fun object_from_bytes(bcs_bytes: vector): BCSObject { - let bcs = bcs::new(bcs_bytes); + let mut bcs = bcs::new(bcs_bytes); // Use `peel_*` functions to peel values from the serialized bytes. // Order has to be the same as we used in serialization! diff --git a/advanced-topics/closed_loop_token/example_projects/closed_loop_token/Move.toml b/advanced-topics/closed_loop_token/example_projects/closed_loop_token/Move.toml index 70ad172..76be07b 100644 --- a/advanced-topics/closed_loop_token/example_projects/closed_loop_token/Move.toml +++ b/advanced-topics/closed_loop_token/example_projects/closed_loop_token/Move.toml @@ -1,6 +1,7 @@ [package] name = "closed_loop_token" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity.move b/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity.move index 6d7b6fe..603637c 100644 --- a/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity.move +++ b/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity.move @@ -13,7 +13,7 @@ module closed_loop_token::parity { /// Name of the coin. By convention, this type has the same name as its parent module /// and has no fields. The full type of the coin defined by this module will be `COIN`. - struct PARITY has drop {} + public struct PARITY has drop {} /// Register the PARITY currency to acquire its `TreasuryCap`. Because /// this is a module initializer, it ensures the currency only gets @@ -21,7 +21,7 @@ module closed_loop_token::parity { fun init(witness: PARITY, ctx: &mut TxContext) { let (treasury_cap, metadata) = coin::create_currency(witness, 2, b"PARITY", b"MNG", b"", option::none(), ctx); transfer::public_freeze_object(metadata); - let (policy, policy_cap) = token::new_policy(&treasury_cap, ctx); + let (mut policy, policy_cap) = token::new_policy(&treasury_cap, ctx); token::add_rule_for_action(&mut policy, &policy_cap, utf8(b"from_coin"), ctx); token::share_policy(policy); transfer::public_transfer(policy_cap,tx_context::sender(ctx)); @@ -47,7 +47,7 @@ module closed_loop_token::parity { public fun policy_mint_token(treasury_cap: &mut TreasuryCap, policy: &TokenPolicy, amount: u64, ctx: &mut TxContext ) { let _coin = coin::mint(treasury_cap, amount, ctx); - let (_token, _request) = token::from_coin(_coin, ctx); + let (_token, mut _request) = token::from_coin(_coin, ctx); parity_rule::verify(policy, &mut _request, ctx); token::confirm_request(policy, _request, ctx); token::keep(_token, ctx) diff --git a/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity_rule.move b/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity_rule.move index 3f4a365..d0824c7 100644 --- a/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity_rule.move +++ b/advanced-topics/closed_loop_token/example_projects/closed_loop_token/sources/parity_rule.move @@ -11,7 +11,7 @@ module closed_loop_token::parity_rule { const EWrongParity: u64 = 0; /// The Rule witness. - struct ParityRule has drop {} + public struct ParityRule has drop {} /// Verifies that the sender and the recipient (if set) are not on the /// denylist for the given action. diff --git a/advanced-topics/closed_loop_token/lessons/closed_loop_token.md b/advanced-topics/closed_loop_token/lessons/closed_loop_token.md index 4b3fb19..2acbd29 100644 --- a/advanced-topics/closed_loop_token/lessons/closed_loop_token.md +++ b/advanced-topics/closed_loop_token/lessons/closed_loop_token.md @@ -26,7 +26,7 @@ Protected actions generate an `ActionRequest` which need to be confirmed. ```rust - struct ActionRequest { + public struct ActionRequest { /// Name of the Action to look up in the Policy. Name can be one of the /// default actions: `transfer`, `spend`, `to_coin`, `from_coin` or a /// custom action. diff --git a/exercises/unit-four/locked_coin_df.move b/exercises/unit-four/locked_coin_df.move index 290dd04..181a110 100644 --- a/exercises/unit-four/locked_coin_df.move +++ b/exercises/unit-four/locked_coin_df.move @@ -9,14 +9,14 @@ module locked_coin::locked_coin_df { /// Shared objected used to attach the lockers /// - struct Registry has key { + public struct Registry has key { id: UID, metadata: CoinMetadata } - struct LOCKED_COIN has drop {} + public struct LOCKED_COIN has drop {} - struct Locker has store { + public struct Locker has store { start_date: u64, final_date: u64, original_balance: u64, diff --git a/unit-five/example_projects/flashloan/Move.toml b/unit-five/example_projects/flashloan/Move.toml index 524ad2a..44dfe59 100644 --- a/unit-five/example_projects/flashloan/Move.toml +++ b/unit-five/example_projects/flashloan/Move.toml @@ -1,6 +1,7 @@ [package] name = "flashloan" version = "0.0.1" +edition = "2024.beta" # edition = "2024.alpha" # To use the Move 2024 edition, currently in alpha # license = "" # e.g., "MIT", "GPL", "Apache 2.0" diff --git a/unit-five/example_projects/flashloan/sources/flashloan.move b/unit-five/example_projects/flashloan/sources/flashloan.move index f748d1a..6aedf7c 100644 --- a/unit-five/example_projects/flashloan/sources/flashloan.move +++ b/unit-five/example_projects/flashloan/sources/flashloan.move @@ -21,7 +21,7 @@ module flashloan::flashloan { /// A "shared" loan pool. /// For demonstration purpose, we assume the loan pool only allows SUI. - struct LoanPool has key { + public struct LoanPool has key { id: UID, amount: Balance, } @@ -29,12 +29,12 @@ module flashloan::flashloan { /// A loan position. /// This is a hot potato struct, it enforces the users /// to repay the loan in the end of the transaction or within the same PTB. - struct Loan { + public struct Loan { amount: u64, } /// A dummy NFT to represent the flashloan functionality - struct NFT has key{ + public struct NFT has key{ id: UID, price: Balance, } diff --git a/unit-five/example_projects/kiosk/Move.toml b/unit-five/example_projects/kiosk/Move.toml index 94ca44d..59f10a4 100644 --- a/unit-five/example_projects/kiosk/Move.toml +++ b/unit-five/example_projects/kiosk/Move.toml @@ -1,6 +1,7 @@ [package] name = "kiosk" version = "0.0.1" +edition = "2024.beta" # edition = "2024.alpha" # To use the Move 2024 edition, currently in alpha # license = "" # e.g., "MIT", "GPL", "Apache 2.0" diff --git a/unit-five/example_projects/kiosk/sources/dummy_policy.move b/unit-five/example_projects/kiosk/sources/dummy_policy.move index e8f8fe7..552e57b 100644 --- a/unit-five/example_projects/kiosk/sources/dummy_policy.move +++ b/unit-five/example_projects/kiosk/sources/dummy_policy.move @@ -15,11 +15,11 @@ module kiosk::dummy_rule { /// The Rule Witness; has no fields and is used as a /// static authorization method for the rule. - struct Rule has drop {} + public struct Rule has drop {} /// Configuration struct with any fields (as long as it /// has `drop`). Managed by the Rule module. - struct Config has store, drop {} + public struct Config has store, drop {} /// Function that adds a Rule to the `TransferPolicy`. /// Requires `TransferPolicyCap` to make sure the rules are diff --git a/unit-five/example_projects/kiosk/sources/fixed_royalty_rule.move b/unit-five/example_projects/kiosk/sources/fixed_royalty_rule.move index 536e6ea..2dd7599 100644 --- a/unit-five/example_projects/kiosk/sources/fixed_royalty_rule.move +++ b/unit-five/example_projects/kiosk/sources/fixed_royalty_rule.move @@ -22,10 +22,10 @@ module kiosk::fixed_royalty_rule { const MAX_BPS: u16 = 10_000; /// The Rule Witness to authorize the policy - struct Rule has drop {} + public struct Rule has drop {} /// Configuration for the Rule - struct Config has store, drop { + public struct Config has store, drop { /// Percentage of the transfer amount to be paid as royalty fee amount_bp: u16, /// This is used as royalty fee if the calculated fee is smaller than `min_amount` @@ -65,7 +65,7 @@ module kiosk::fixed_royalty_rule { /// Can be used dry-runned to estimate the fee amount based on the Kiosk listing price. public fun fee_amount(policy: &TransferPolicy, paid: u64): u64 { let config: &Config = transfer_policy::get_rule(Rule {}, policy); - let amount = (((paid as u128) * (config.amount_bp as u128) / 10_000) as u64); + let mut amount = (((paid as u128) * (config.amount_bp as u128) / 10_000) as u64); // If the amount is less than the minimum, use the minimum if (amount < config.min_amount) { diff --git a/unit-five/example_projects/kiosk/sources/kiosk.move b/unit-five/example_projects/kiosk/sources/kiosk.move index cc9d76c..c0daa8c 100644 --- a/unit-five/example_projects/kiosk/sources/kiosk.move +++ b/unit-five/example_projects/kiosk/sources/kiosk.move @@ -11,11 +11,11 @@ module kiosk::kiosk { use sui::package::{Self, Publisher}; use sui::transfer::{Self}; - struct TShirt has key, store { + public struct TShirt has key, store { id: UID, } - struct KIOSK has drop {} + public struct KIOSK has drop {} fun init(otw: KIOSK, ctx: &mut TxContext) { let publisher = package::claim(otw, ctx); diff --git a/unit-five/lessons/2_hot_potato_pattern.md b/unit-five/lessons/2_hot_potato_pattern.md index e0173ff..040fa21 100644 --- a/unit-five/lessons/2_hot_potato_pattern.md +++ b/unit-five/lessons/2_hot_potato_pattern.md @@ -20,7 +20,7 @@ module flashloan::flashloan { /// A "shared" loan pool. /// For demonstration purpose, we assume the loan pool only allows SUI. - struct LoanPool has key { + public struct LoanPool has key { id: UID, amount: Balance, } @@ -28,7 +28,7 @@ module flashloan::flashloan { /// A loan position. /// This is a hot potato struct, it enforces the users /// to repay the loan in the end of the transaction or within the same PTB. - struct Loan { + public struct Loan { amount: u64, } } @@ -77,7 +77,7 @@ Let's try to create an example with flashloan where we borrow some SUI amount, u ```move /// A dummy NFT to represent the flashloan functionality -struct NFT has key{ +public struct NFT has key{ id: UID, price: Balance, } diff --git a/unit-five/lessons/4_kiosk_basic_usage.md b/unit-five/lessons/4_kiosk_basic_usage.md index 5452268..a26e4e5 100644 --- a/unit-five/lessons/4_kiosk_basic_usage.md +++ b/unit-five/lessons/4_kiosk_basic_usage.md @@ -40,7 +40,7 @@ _💡Note: Kiosk is heterogeneous collection by default so that's why it doesn't ## Place Item inside Kiosk ```move -struct TShirt has key, store { +public struct TShirt has key, store { id: UID, } diff --git a/unit-five/lessons/5_transfer_policy.md b/unit-five/lessons/5_transfer_policy.md index d805cbc..d1cf151 100644 --- a/unit-five/lessons/5_transfer_policy.md +++ b/unit-five/lessons/5_transfer_policy.md @@ -13,7 +13,7 @@ use sui::transfer_policy::{Self, TransferRequest, TransferPolicy, TransferPolicy use sui::package::{Self, Publisher}; use sui::transfer::{Self}; -struct KIOSK has drop {} +public struct KIOSK has drop {} fun init(witness: KIOSK, ctx: &mut TxContext) { let publisher = package::claim(otw, ctx); @@ -67,10 +67,10 @@ module kiosk::fixed_royalty_rule { const MAX_BPS: u16 = 10_000; /// The Rule Witness to authorize the policy - struct Rule has drop {} + public struct Rule has drop {} /// Configuration for the Rule - struct Config has store, drop { + public struct Config has store, drop { /// Percentage of the transfer amount to be paid as royalty fee amount_bp: u16, /// This is used as royalty fee if the calculated fee is smaller than `min_amount` diff --git a/unit-four/example_projects/collections/Move.toml b/unit-four/example_projects/collections/Move.toml index 88ca123..7ca83ab 100644 --- a/unit-four/example_projects/collections/Move.toml +++ b/unit-four/example_projects/collections/Move.toml @@ -1,6 +1,7 @@ [package] name = "collection" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/unit-four/example_projects/collections/sources/bag.move b/unit-four/example_projects/collections/sources/bag.move index b710999..76c029c 100644 --- a/unit-four/example_projects/collections/sources/bag.move +++ b/unit-four/example_projects/collections/sources/bag.move @@ -7,7 +7,7 @@ module collection::bag { use sui::tx_context::{TxContext}; // Defining a table with generic types for the key and value - struct GenericBag { + public struct GenericBag { items: Bag } diff --git a/unit-four/example_projects/collections/sources/dynamic_fields.move b/unit-four/example_projects/collections/sources/dynamic_fields.move index 3e0a3e6..2d4e75c 100644 --- a/unit-four/example_projects/collections/sources/dynamic_fields.move +++ b/unit-four/example_projects/collections/sources/dynamic_fields.move @@ -11,17 +11,17 @@ module collection::dynamic_fields { use sui::tx_context::{Self, TxContext}; // Parent struct - struct Parent has key { + public struct Parent has key { id: UID, } // Dynamic field child struct type containing a counter - struct DFChild has store { + public struct DFChild has store { count: u64 } // Dynamic object field child struct type containing a counter - struct DOFChild has key, store { + public struct DOFChild has key, store { id: UID, count: u64, } diff --git a/unit-four/example_projects/collections/sources/table.move b/unit-four/example_projects/collections/sources/table.move index b69bc82..83a4984 100644 --- a/unit-four/example_projects/collections/sources/table.move +++ b/unit-four/example_projects/collections/sources/table.move @@ -9,12 +9,12 @@ module collection::table { #[allow(unused_field)] // Defining a table with specified types for the key and value - struct IntegerTable { + public struct IntegerTable { table_values: Table } // Defining a table with generic types for the key and value - struct GenericTable { + public struct GenericTable { table_values: Table } diff --git a/unit-four/example_projects/collections/sources/vector.move b/unit-four/example_projects/collections/sources/vector.move index bc93662..d012ddd 100644 --- a/unit-four/example_projects/collections/sources/vector.move +++ b/unit-four/example_projects/collections/sources/vector.move @@ -6,17 +6,17 @@ module collection::vector { use std::vector; - struct Widget { + public struct Widget { } #[allow(unused_field)] // Vector for a specified type - struct WidgetVector { + public struct WidgetVector { widgets: vector } // Vector for a generic type - struct GenericVector { + public struct GenericVector { values: vector } diff --git a/unit-four/example_projects/marketplace/Move.toml b/unit-four/example_projects/marketplace/Move.toml index 8467fa8..846fe81 100644 --- a/unit-four/example_projects/marketplace/Move.toml +++ b/unit-four/example_projects/marketplace/Move.toml @@ -1,6 +1,7 @@ [package] name = "marketplace" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/unit-four/example_projects/marketplace/sources/marketplace.move b/unit-four/example_projects/marketplace/sources/marketplace.move index 4598d1c..50607b8 100644 --- a/unit-four/example_projects/marketplace/sources/marketplace.move +++ b/unit-four/example_projects/marketplace/sources/marketplace.move @@ -21,7 +21,7 @@ module marketplace::marketplace { /// A shared `Marketplace`. Can be created by anyone using the /// `create` function. One instance of `Marketplace` accepts /// only one type of Coin - `COIN` for all its listings. - struct Marketplace has key { + public struct Marketplace has key { id: UID, items: Bag, payments: Table> @@ -29,7 +29,7 @@ module marketplace::marketplace { /// A single listing which contains the listed item and its /// price in [`Coin`]. - struct Listing has key, store { + public struct Listing has key, store { id: UID, ask: u64, owner: address, @@ -55,7 +55,7 @@ module marketplace::marketplace { ctx: &mut TxContext ) { let item_id = object::id(&item); - let listing = Listing { + let mut listing = Listing { ask, id: object::new(ctx), owner: tx_context::sender(ctx), @@ -72,7 +72,7 @@ module marketplace::marketplace { ctx: &TxContext ): T { let Listing { - id, + mut id, owner, ask: _, } = bag::remove(&mut marketplace.items, item_id); @@ -103,7 +103,7 @@ module marketplace::marketplace { paid: Coin, ): T { let Listing { - id, + mut id, ask, owner } = bag::remove(&mut marketplace.items, item_id); diff --git a/unit-four/example_projects/marketplace/sources/widget.move b/unit-four/example_projects/marketplace/sources/widget.move index 421a8bc..3a46aac 100644 --- a/unit-four/example_projects/marketplace/sources/widget.move +++ b/unit-four/example_projects/marketplace/sources/widget.move @@ -11,7 +11,7 @@ module marketplace::widget { use sui::transfer; use sui::tx_context::{Self, TxContext}; - struct Widget has key, store { + public struct Widget has key, store { id: UID, } diff --git a/unit-four/lessons/1_homogeneous_collections.md b/unit-four/lessons/1_homogeneous_collections.md index 0b454e8..307d184 100644 --- a/unit-four/lessons/1_homogeneous_collections.md +++ b/unit-four/lessons/1_homogeneous_collections.md @@ -13,16 +13,16 @@ module collection::vector { use std::vector; - struct Widget { + public struct Widget { } // Vector for a specified type - struct WidgetVector { + public struct WidgetVector { widgets: vector } // Vector for a generic type - struct GenericVector { + public struct GenericVector { values: vector } @@ -72,12 +72,12 @@ module collection::table { use sui::tx_context::{TxContext}; // Defining a table with specified types for the key and value - struct IntegerTable { + public struct IntegerTable { table_values: Table } // Defining a table with generic types for the key and value - struct GenericTable { + public struct GenericTable { table_values: Table } diff --git a/unit-four/lessons/2_dynamic_fields.md b/unit-four/lessons/2_dynamic_fields.md index 5e7c6fd..488bfc2 100644 --- a/unit-four/lessons/2_dynamic_fields.md +++ b/unit-four/lessons/2_dynamic_fields.md @@ -15,17 +15,17 @@ To illustrate how to work with dynamic fields, we define the following structs: ```rust // Parent struct - struct Parent has key { + public struct Parent has key { id: UID, } // Dynamic field child struct type containing a counter - struct DFChild has store { + public struct DFChild has store { count: u64 } // Dynamic object field child struct type containing a counter - struct DOFChild has key, store { + public struct DOFChild has key, store { id: UID, count: u64, } diff --git a/unit-four/lessons/3_heterogeneous_collections.md b/unit-four/lessons/3_heterogeneous_collections.md index 72dcfac..63b65ef 100644 --- a/unit-four/lessons/3_heterogeneous_collections.md +++ b/unit-four/lessons/3_heterogeneous_collections.md @@ -19,7 +19,7 @@ module collection::bag { use sui::tx_context::{TxContext}; // Defining a table with generic types for the key and value - struct GenericBag { + public struct GenericBag { items: Bag } diff --git a/unit-four/lessons/4_marketplace_contract.md b/unit-four/lessons/4_marketplace_contract.md index 94f102b..2673a19 100644 --- a/unit-four/lessons/4_marketplace_contract.md +++ b/unit-four/lessons/4_marketplace_contract.md @@ -14,7 +14,7 @@ First, we define the overall `Marketplace` struct: /// A shared `Marketplace`. Can be created by anyone using the /// `create` function. One instance of `Marketplace` accepts /// only one type of Coin - `COIN` for all its listings. - struct Marketplace has key { + public struct Marketplace has key { id: UID, items: Bag, payments: Table> @@ -34,7 +34,7 @@ Next, we define a `Listing` type: ```rust /// A single listing that contains the listed item and its /// price in [`Coin`]. - struct Listing has key, store { + public struct Listing has key, store { id: UID, ask: u64, owner: address, diff --git a/unit-four/lessons/5_deployment_and_testing.md b/unit-four/lessons/5_deployment_and_testing.md index b88d5e5..4de664b 100644 --- a/unit-four/lessons/5_deployment_and_testing.md +++ b/unit-four/lessons/5_deployment_and_testing.md @@ -11,7 +11,7 @@ module marketplace::widget { use sui::transfer; use sui::tx_context::{Self, TxContext}; - struct Widget has key, store { + public struct Widget has key, store { id: UID, } diff --git a/unit-one/example_projects/hello_world/Move.toml b/unit-one/example_projects/hello_world/Move.toml index cea21ec..4183bf3 100644 --- a/unit-one/example_projects/hello_world/Move.toml +++ b/unit-one/example_projects/hello_world/Move.toml @@ -1,6 +1,7 @@ [package] name = "hello_world" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/unit-one/example_projects/hello_world/sources/hello_world.move b/unit-one/example_projects/hello_world/sources/hello_world.move index 85d1ff4..df433c4 100644 --- a/unit-one/example_projects/hello_world/sources/hello_world.move +++ b/unit-one/example_projects/hello_world/sources/hello_world.move @@ -12,7 +12,7 @@ module hello_world::hello_world { use sui::tx_context::{Self, TxContext}; /// An object that contains an arbitrary string - struct HelloWorldObject has key, store { + public struct HelloWorldObject has key, store { id: UID, /// A string contained in the object text: string::String diff --git a/unit-one/lessons/2_sui_project_structure.md b/unit-one/lessons/2_sui_project_structure.md index 27f69ec..aee0e91 100644 --- a/unit-one/lessons/2_sui_project_structure.md +++ b/unit-one/lessons/2_sui_project_structure.md @@ -52,6 +52,8 @@ This is the `Move.toml` generated by the Sui CLI with the package name `hello_wo [package] name = "hello_world" version = "0.0.1" +edition = "2024.beta" + [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } diff --git a/unit-one/lessons/3_custom_types_and_abilities.md b/unit-one/lessons/3_custom_types_and_abilities.md index defa169..f2be831 100644 --- a/unit-one/lessons/3_custom_types_and_abilities.md +++ b/unit-one/lessons/3_custom_types_and_abilities.md @@ -64,7 +64,7 @@ We define the object in our Hello World example as the following: ```rust /// An object that contains an arbitrary string -struct HelloWorldObject has key, store { +public struct HelloWorldObject has key, store { id: UID, /// A string contained in the object text: string::String diff --git a/unit-one/lessons/4_functions.md b/unit-one/lessons/4_functions.md index 56be2a5..a539f71 100644 --- a/unit-one/lessons/4_functions.md +++ b/unit-one/lessons/4_functions.md @@ -8,7 +8,7 @@ Sui Move functions have three types of visibility: - **private**: the default visibility of a function; it can only be accessed by functions inside the same module - **public**: the function is accessible by functions inside the same module and by functions defined in another module -- **public(friend)**: the function is accessible by functions inside the same module and by functions defined in modules that are included on [the module's friends list](https://diem.github.io/move/friends.html). +- **public(package)**: the function is accessible by functions inside the same module ## Return Value diff --git a/unit-three/example_projects/fungible_tokens/Move.toml b/unit-three/example_projects/fungible_tokens/Move.toml index afafc65..250247f 100644 --- a/unit-three/example_projects/fungible_tokens/Move.toml +++ b/unit-three/example_projects/fungible_tokens/Move.toml @@ -1,6 +1,7 @@ [package] name = "fungible_tokens" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/unit-three/example_projects/fungible_tokens/sources/managed.move b/unit-three/example_projects/fungible_tokens/sources/managed.move index 56b5cb8..bcb9adc 100644 --- a/unit-three/example_projects/fungible_tokens/sources/managed.move +++ b/unit-three/example_projects/fungible_tokens/sources/managed.move @@ -12,7 +12,7 @@ module fungible_tokens::managed { /// Name of the coin. By convention, this type has the same name as its parent module /// and has no fields. The full type of the coin defined by this module will be `COIN`. - struct MANAGED has drop {} + public struct MANAGED has drop {} /// Register the managed currency to acquire its `TreasuryCap`. Because /// this is a module initializer, it ensures the currency only gets diff --git a/unit-three/example_projects/fungible_tokens/sources/managed_tests.move b/unit-three/example_projects/fungible_tokens/sources/managed_tests.move index eee73cd..16275fc 100644 --- a/unit-three/example_projects/fungible_tokens/sources/managed_tests.move +++ b/unit-three/example_projects/fungible_tokens/sources/managed_tests.move @@ -14,7 +14,7 @@ module fungible_tokens::managed_tests { let addr1 = @0xA; // Begins a multi transaction scenario with addr1 as the sender - let scenario = test_scenario::begin(addr1); + let mut scenario = test_scenario::begin(addr1); // Run the managed coin module init function { @@ -24,7 +24,7 @@ module fungible_tokens::managed_tests { // Mint a `Coin` object next_tx(&mut scenario, addr1); { - let treasurycap = test_scenario::take_from_sender>(&scenario); + let mut treasurycap = test_scenario::take_from_sender>(&scenario); managed::mint(&mut treasurycap, 100, addr1, test_scenario::ctx(&mut scenario)); test_scenario::return_to_address>(addr1, treasurycap); }; @@ -33,7 +33,7 @@ module fungible_tokens::managed_tests { next_tx(&mut scenario, addr1); { let coin = test_scenario::take_from_sender>(&scenario); - let treasurycap = test_scenario::take_from_sender>(&scenario); + let mut treasurycap = test_scenario::take_from_sender>(&scenario); managed::burn(&mut treasurycap, coin); test_scenario::return_to_address>(addr1, treasurycap); }; diff --git a/unit-three/example_projects/generics/Move.toml b/unit-three/example_projects/generics/Move.toml index d8a3eff..55c7528 100644 --- a/unit-three/example_projects/generics/Move.toml +++ b/unit-three/example_projects/generics/Move.toml @@ -1,6 +1,7 @@ [package] name = "generics" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/unit-three/example_projects/generics/sources/generics.move b/unit-three/example_projects/generics/sources/generics.move index b033dc2..cde020b 100644 --- a/unit-three/example_projects/generics/sources/generics.move +++ b/unit-three/example_projects/generics/sources/generics.move @@ -10,17 +10,17 @@ module generics::generics { use sui::object::{Self, UID}; use sui::tx_context::{Self, TxContext}; - struct Box has key, store { + public struct Box has key, store { id: UID, value: T } - struct SimpleBox has key, store { + public struct SimpleBox has key, store { id: UID, value: u8 } - struct PhantomBox has key { + public struct PhantomBox has key { id: UID, } diff --git a/unit-three/example_projects/witness/Move.toml b/unit-three/example_projects/witness/Move.toml index 261741d..df1f6ae 100644 --- a/unit-three/example_projects/witness/Move.toml +++ b/unit-three/example_projects/witness/Move.toml @@ -1,6 +1,7 @@ [package] name = "witness" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/unit-three/example_projects/witness/sources/peace.move b/unit-three/example_projects/witness/sources/peace.move index b14c340..93ebd25 100644 --- a/unit-three/example_projects/witness/sources/peace.move +++ b/unit-three/example_projects/witness/sources/peace.move @@ -7,12 +7,12 @@ /// Phantom parameter T can only be initialized in the `create_guardian` /// function. But the types passed here must have `drop`. - struct Guardian has key, store { + public struct Guardian has key, store { id: UID } /// This type is the witness resource and is intended to be used only once. - struct PEACE has drop {} + public struct PEACE has drop {} /// The first argument of this function is an actual instance of the /// type T with `drop` ability. It is dropped as soon as received. diff --git a/unit-three/lessons/2_intro_to_generics.md b/unit-three/lessons/2_intro_to_generics.md index f8a2552..e3f77ed 100644 --- a/unit-three/lessons/2_intro_to_generics.md +++ b/unit-three/lessons/2_intro_to_generics.md @@ -14,7 +14,7 @@ First, without generics, we can define a `Box` that holds a `u64` type as the fo ```rust module generics::storage { - struct Box { + public struct Box { value: u64 } } @@ -24,7 +24,7 @@ However, this type will only be able to hold a value of type `u64`. To make our ```rust module generics::storage { - struct Box { + public struct Box { value: T } } @@ -37,7 +37,7 @@ We can add conditions to enforce that the type passed into the generic must have ```rust module generics::storage { // T must be copyable and droppable - struct Box has key, store { + public struct Box has key, store { value: T } } diff --git a/unit-three/lessons/3_witness_design_pattern.md b/unit-three/lessons/3_witness_design_pattern.md index 38b0321..1dcff46 100644 --- a/unit-three/lessons/3_witness_design_pattern.md +++ b/unit-three/lessons/3_witness_design_pattern.md @@ -20,12 +20,12 @@ The `witness` resource type must have the `drop` keyword so that this resource c /// Phantom parameter T can only be initialized in the `create_guardian` /// function. But the types passed here must have `drop`. - struct Guardian has key, store { + public struct Guardian has key, store { id: UID } /// This type is the witness resource and is intended to be used only once. - struct PEACE has drop {} + public struct PEACE has drop {} /// The first argument of this function is an actual instance of the /// type T with `drop` ability. It is dropped as soon as received. diff --git a/unit-three/lessons/4_the_coin_resource_and_create_currency.md b/unit-three/lessons/4_the_coin_resource_and_create_currency.md index d52dd22..3cafc2e 100644 --- a/unit-three/lessons/4_the_coin_resource_and_create_currency.md +++ b/unit-three/lessons/4_the_coin_resource_and_create_currency.md @@ -7,7 +7,7 @@ Now we know how generics and witness patterns work, let's revisit the `Coin` res Now we understand how generics work. We can revisit the `Coin` resource from `sui::coin`. It's [defined](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/packages/sui-framework/sources/coin.move#L28) as the following: ```rust -struct Coin has key, store { +public struct Coin has key, store { id: UID, balance: Balance } @@ -18,7 +18,7 @@ The `Coin` resource type is a struct that has a generic type `T` and two fields, `balance` is of the type [`sui::balance::Balance`](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/docs/sui-framework/balance.md#0x2_balance_Balance), and is [defined](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/packages/sui-framework/sources/balance.move#L29) as: ```rust -struct Balance has store { +public struct Balance has store { value: u64 } ``` @@ -77,7 +77,7 @@ The `TreasuryCap` is an asset and is guaranteed to be a singleton object by the ```rust /// Capability allowing the bearer to mint and burn /// coins of type `T`. Transferable - struct TreasuryCap has key, store { + public struct TreasuryCap has key, store { id: UID, total_supply: Supply } @@ -88,7 +88,7 @@ It wraps a singleton field `total_supply` of type `Balance::Supply`: ```rust /// A Supply of T. Used for minting and burning. /// Wrapped into a `TreasuryCap` in the `Coin` module. - struct Supply has store { + public struct Supply has store { value: u64 } ``` diff --git a/unit-three/lessons/6_clock_and_locked_coin.md b/unit-three/lessons/6_clock_and_locked_coin.md index 180d2da..6fb0424 100644 --- a/unit-three/lessons/6_clock_and_locked_coin.md +++ b/unit-three/lessons/6_clock_and_locked_coin.md @@ -27,7 +27,7 @@ Now that we know how to access time on-chain through `clock`, implementing a ves ```rust /// Transferrable object for storing the vesting coins /// - struct Locker has key, store { + public struct Locker has key, store { id: UID, start_date: u64, final_date: u64, diff --git a/unit-two/example_projects/transcript/Move.toml b/unit-two/example_projects/transcript/Move.toml index 2a86a08..f66066a 100644 --- a/unit-two/example_projects/transcript/Move.toml +++ b/unit-two/example_projects/transcript/Move.toml @@ -1,6 +1,7 @@ [package] name = "transcript" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "devnet" } diff --git a/unit-two/example_projects/transcript/sources/transcript.move b/unit-two/example_projects/transcript/sources/transcript.move index 2c83f0c..5f1547b 100644 --- a/unit-two/example_projects/transcript/sources/transcript.move +++ b/unit-two/example_projects/transcript/sources/transcript.move @@ -11,25 +11,25 @@ module sui_intro_unit_two::transcript { use sui::transfer; use sui::event; - struct WrappableTranscript has key, store { + public struct WrappableTranscript has key, store { id: UID, history: u8, math: u8, literature: u8, } - struct Folder has key { + public struct Folder has key { id: UID, transcript: WrappableTranscript, intended_address: address } - struct TeacherCap has key { + public struct TeacherCap has key { id: UID } /// Event marking when a transcript has been requested - struct TranscriptRequestEvent has copy, drop { + public struct TranscriptRequestEvent has copy, drop { // The Object ID of the transcript wrapper wrapper_id: ID, // The requester of the transcript diff --git a/unit-two/lessons/1_working_with_sui_objects.md b/unit-two/lessons/1_working_with_sui_objects.md index ed41582..d52c02d 100644 --- a/unit-two/lessons/1_working_with_sui_objects.md +++ b/unit-two/lessons/1_working_with_sui_objects.md @@ -7,7 +7,7 @@ Sui Move is a fully object-centric language. Transactions on Sui are expressed a Let's first start with an example that represents a transcript recording a student's grades: ```rust -struct Transcript { +public struct Transcript { history: u8, math: u8, literature: u8, @@ -19,7 +19,7 @@ The above definition is a regular Move struct, but it is not a Sui object. In or ```rust use sui::object::{UID}; -struct TranscriptObject has key { +public struct TranscriptObject has key { id: UID, history: u8, math: u8, diff --git a/unit-two/lessons/4_object_wrapping.md b/unit-two/lessons/4_object_wrapping.md index 46b3e5d..79d28a1 100644 --- a/unit-two/lessons/4_object_wrapping.md +++ b/unit-two/lessons/4_object_wrapping.md @@ -5,13 +5,13 @@ There are multiple ways of nesting an object inside of another object in Sui Mov Let's continue our transcript example. We define a new `WrappableTranscript` type, and the associated wrapper type `Folder`. ```rust -struct WrappableTranscript has store { +public struct WrappableTranscript has store { history: u8, math: u8, literature: u8, } -struct Folder has key { +public struct Folder has key { id: UID, transcript: WrappableTranscript, } diff --git a/unit-two/lessons/5_object_wrapping_example.md b/unit-two/lessons/5_object_wrapping_example.md index 1e6612e..f813ae8 100644 --- a/unit-two/lessons/5_object_wrapping_example.md +++ b/unit-two/lessons/5_object_wrapping_example.md @@ -11,7 +11,7 @@ First, we need to make some adjustments to our two custom types `WrappableTransc Remember that custom types with the abilities `key` and `store` are considered to be assets in Sui Move. ```rust -struct WrappableTranscript has key, store { +public struct WrappableTranscript has key, store { id: UID, history: u8, math: u8, @@ -22,7 +22,7 @@ struct WrappableTranscript has key, store { 2. We need to add an additional field `intended_address` to the `Folder` struct that indicates the address of the intended viewer of the wrapped transcript. ``` rust -struct Folder has key { +public struct Folder has key { id: UID, transcript: WrappableTranscript, intended_address: address diff --git a/unit-two/lessons/6_capability_design_pattern.md b/unit-two/lessons/6_capability_design_pattern.md index 3ee528c..7929352 100644 --- a/unit-two/lessons/6_capability_design_pattern.md +++ b/unit-two/lessons/6_capability_design_pattern.md @@ -6,7 +6,7 @@ Capability is a commonly used pattern in Move that allows fine-tuned access cont ```rust // Type that marks the capability to create, update, and delete transcripts - struct TeacherCap has key { +public struct TeacherCap has key { id: UID } ``` diff --git a/unit-two/lessons/7_events.md b/unit-two/lessons/7_events.md index 33ba2b8..44bf758 100644 --- a/unit-two/lessons/7_events.md +++ b/unit-two/lessons/7_events.md @@ -14,7 +14,7 @@ Developers can also define custom events on Sui. We can define a custom event ma ```rust /// Event marking when a transcript has been requested - struct TranscriptRequestEvent has copy, drop { + public struct TranscriptRequestEvent has copy, drop { // The Object ID of the transcript wrapper wrapper_id: ID, // The requester of the transcript