Skip to content

Commit

Permalink
feat: move 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
uvd committed May 6, 2024
1 parent 322d935 commit 65c6b7b
Show file tree
Hide file tree
Showing 53 changed files with 108 additions and 89 deletions.
6 changes: 6 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ 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
}

public fun object_from_bytes(bcs_bytes: vector<u8>): 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!
Expand Down
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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<PARITY>`.
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
/// registered once.
fun init(witness: PARITY, ctx: &mut TxContext) {
let (treasury_cap, metadata) = coin::create_currency<PARITY>(witness, 2, b"PARITY", b"MNG", b"", option::none(), ctx);
transfer::public_freeze_object(metadata);
let (policy, policy_cap) = token::new_policy<PARITY>(&treasury_cap, ctx);
let (mut policy, policy_cap) = token::new_policy<PARITY>(&treasury_cap, ctx);
token::add_rule_for_action<PARITY, ParityRule>(&mut policy, &policy_cap, utf8(b"from_coin"), ctx);
token::share_policy(policy);
transfer::public_transfer(policy_cap,tx_context::sender(ctx));
Expand All @@ -47,7 +47,7 @@ module closed_loop_token::parity {
public fun policy_mint_token(treasury_cap: &mut TreasuryCap<PARITY>, policy: &TokenPolicy<PARITY>, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Protected actions generate an `ActionRequest` which need to be confirmed.

```rust
struct ActionRequest<phantom T> {
public struct ActionRequest<phantom T> {
/// 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.
Expand Down
6 changes: 3 additions & 3 deletions exercises/unit-four/locked_coin_df.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<LOCKED_COIN>
}

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,
Expand Down
1 change: 1 addition & 0 deletions unit-five/example_projects/flashloan/Move.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions unit-five/example_projects/flashloan/sources/flashloan.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ 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<SUI>,
}

/// 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<SUI>,
}
Expand Down
1 change: 1 addition & 0 deletions unit-five/example_projects/kiosk/Move.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions unit-five/example_projects/kiosk/sources/dummy_policy.move
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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<T: key + store>(policy: &TransferPolicy<T>, 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) {
Expand Down
4 changes: 2 additions & 2 deletions unit-five/example_projects/kiosk/sources/kiosk.move
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions unit-five/lessons/2_hot_potato_pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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<SUI>,
}
/// 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,
}
}
Expand Down Expand Up @@ -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<SUI>,
}
Expand Down
2 changes: 1 addition & 1 deletion unit-five/lessons/4_kiosk_basic_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
6 changes: 3 additions & 3 deletions unit-five/lessons/5_transfer_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions unit-four/example_projects/collections/Move.toml
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion unit-four/example_projects/collections/sources/bag.move
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions unit-four/example_projects/collections/sources/table.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, u8>
}

// Defining a table with generic types for the key and value
struct GenericTable<phantom K: copy + drop + store, phantom V: store> {
public struct GenericTable<phantom K: copy + drop + store, phantom V: store> {
table_values: Table<K, V>
}

Expand Down
6 changes: 3 additions & 3 deletions unit-four/example_projects/collections/sources/vector.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<Widget>
}

// Vector for a generic type
struct GenericVector<T> {
public struct GenericVector<T> {
values: vector<T>
}

Expand Down
1 change: 1 addition & 0 deletions unit-four/example_projects/marketplace/Move.toml
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
10 changes: 5 additions & 5 deletions unit-four/example_projects/marketplace/sources/marketplace.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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<phantom COIN> has key {
public struct Marketplace<phantom COIN> has key {
id: UID,
items: Bag,
payments: Table<address, Coin<COIN>>
}

/// A single listing which contains the listed item and its
/// price in [`Coin<COIN>`].
struct Listing has key, store {
public struct Listing has key, store {
id: UID,
ask: u64,
owner: address,
Expand All @@ -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),
Expand All @@ -72,7 +72,7 @@ module marketplace::marketplace {
ctx: &TxContext
): T {
let Listing {
id,
mut id,
owner,
ask: _,
} = bag::remove(&mut marketplace.items, item_id);
Expand Down Expand Up @@ -103,7 +103,7 @@ module marketplace::marketplace {
paid: Coin<COIN>,
): T {
let Listing {
id,
mut id,
ask,
owner
} = bag::remove(&mut marketplace.items, item_id);
Expand Down
2 changes: 1 addition & 1 deletion unit-four/example_projects/marketplace/sources/widget.move
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
Loading

0 comments on commit 65c6b7b

Please sign in to comment.