Skip to content

Commit

Permalink
Merge pull request #77 from uvd/main
Browse files Browse the repository at this point in the history
move 2024
  • Loading branch information
uvd authored May 6, 2024
2 parents 322d935 + a3f10cb commit 0c9c5bd
Show file tree
Hide file tree
Showing 65 changed files with 179 additions and 104 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ unit-three/example_projects/generics
unit-three/example_projects/witness
unit-four/example_projects/collections
unit-four/example_projects/marketplace
unit-five/example_projects/flashloan
unit-five/example_projects/kiosk
advanced-topics/BCS_encoding/example_projects/bcs_move
advanced-topics/closed_loop_token/example_projects/closed_loop_token
);

for(( i=0;i<${#project_path[@]};i++)) do
Expand Down
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
Expand Up @@ -6,6 +6,8 @@ version = 0
dependencies = [
{ name = "Sui" },
]
manifest_digest = "D8515C9CED37C781262CB3B844AD9552149EF9827C7FB372E2E62816F3C2C6BF"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

[[move.package]]
name = "MoveStdlib"
Expand All @@ -18,3 +20,8 @@ source = { git = "https://github.com/MystenLabs/sui.git", rev = "devnet", subdir
dependencies = [
{ name = "MoveStdlib" },
]

[move.toolchain-version]
compiler-version = "1.24.1"
edition = "2024.beta"
flavor = "sui"
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
Expand Up @@ -2,7 +2,7 @@

[move]
version = 0
manifest_digest = "CF46C9A24109CFA3F138893B30EFF8A8CC19F54F02054795330F54BB3B9444E3"
manifest_digest = "FA732D23F5DAE83F5EDEB8ED57934DBFEB20A1106C9F4F5972EFDCFBC8C31627"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

dependencies = [
Expand All @@ -20,3 +20,8 @@ source = { git = "https://github.com/MystenLabs/sui.git", rev = "devnet", subdir
dependencies = [
{ name = "MoveStdlib" },
]

[move.toolchain-version]
compiler-version = "1.24.1"
edition = "2024.beta"
flavor = "sui"
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
6 changes: 3 additions & 3 deletions unit-five/example_projects/flashloan/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 0
manifest_digest = "FC84CCD33DE1E9661DA31B49398152B41FB6772CFBCD634619716A9823846811"
manifest_digest = "5AF76D6421F742DE4D1F6175ED0F52E3A74B283CFD6DECAA7DABA5E9780D4107"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

dependencies = [
Expand All @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.21.0"
edition = "legacy"
compiler-version = "1.24.1"
edition = "2024.beta"
flavor = "sui"
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
6 changes: 3 additions & 3 deletions unit-five/example_projects/kiosk/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 0
manifest_digest = "1FF626947D27118D75E5892ECC965B6EA5D58EF40C92513A237A9F1A2B5F5DDB"
manifest_digest = "00D2CACC4303A52D3E564B6DA3290FDA6A89B39D2820D120C2BE5B942BB863C3"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

dependencies = [
Expand All @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.21.0"
edition = "legacy"
compiler-version = "1.24.1"
edition = "2024.beta"
flavor = "sui"
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
7 changes: 7 additions & 0 deletions unit-four/example_projects/collections/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ version = 0
dependencies = [
{ name = "Sui" },
]
manifest_digest = "5C017484C02CE42775412AD1BB8BA5FDD8CF4E2C4CF09B901CD12A4A82547862"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

[[move.package]]
name = "MoveStdlib"
Expand All @@ -18,3 +20,8 @@ source = { git = "https://github.com/MystenLabs/sui.git", rev = "devnet", subdir
dependencies = [
{ name = "MoveStdlib" },
]

[move.toolchain-version]
compiler-version = "1.24.1"
edition = "2024.beta"
flavor = "sui"
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
Loading

0 comments on commit 0c9c5bd

Please sign in to comment.