diff --git a/mover/Erikaibble/code/task2/Move.toml b/mover/Erikaibble/code/task2/Move.toml new file mode 100644 index 000000000..d06aa9b3a --- /dev/null +++ b/mover/Erikaibble/code/task2/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "task2" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +task2 = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/Erikaibble/code/task2/sources/coin.move b/mover/Erikaibble/code/task2/sources/coin.move new file mode 100644 index 000000000..5e1067ff0 --- /dev/null +++ b/mover/Erikaibble/code/task2/sources/coin.move @@ -0,0 +1,26 @@ +module task2::erikaibble_coin { + use sui::coin; + use sui::coin::{TreasuryCap}; + use sui::transfer::{public_transfer, public_freeze_object}; + + public struct ERIKAIBBLE_COIN has drop{} + fun init(witness: ERIKAIBBLE_COIN, ctx: &mut TxContext){ + let (treasuryCap, denyCap ,metadata) = coin::create_regulated_currency( + witness, + 8, + b"ERIKAIBBLE", + b"ERIKAIBBLE Coin", + b"move coin", + option::none(), + ctx + ); + public_transfer(treasuryCap, tx_context::sender(ctx)); + public_transfer(denyCap, tx_context::sender(ctx)); + public_freeze_object(metadata); + } + + public entry fun mint(cap: &mut TreasuryCap, amount: u64, recipient: address, ctx: &mut TxContext){ + let coin = coin::mint(cap, amount, ctx); + public_transfer(coin, recipient); + } +} \ No newline at end of file diff --git a/mover/Erikaibble/code/task2/sources/faucet.move b/mover/Erikaibble/code/task2/sources/faucet.move new file mode 100644 index 000000000..d1df64285 --- /dev/null +++ b/mover/Erikaibble/code/task2/sources/faucet.move @@ -0,0 +1,24 @@ +module task2::erikaibble_faucet_coin { + use sui::coin; + use sui::coin::TreasuryCap; + use sui::transfer::{ public_share_object, public_freeze_object}; + + public struct ERIKAIBBLE_FAUCET_COIN has drop{} + fun init(witness: ERIKAIBBLE_FAUCET_COIN, ctx: &mut TxContext){ + let (treasury, metadata) = coin::create_currency( + witness, + 8, + b"ERIKAIBBLE_PUBLIC", + b"erikaibble Faucet coin", + b"test faucet coin", + option::none(), + ctx + ); + public_share_object(treasury); + public_freeze_object(metadata); + } + + public entry fun mint(cap: &mut TreasuryCap, value: u64, recipient: address, ctx: &mut TxContext){ + coin::mint_and_transfer(cap, value, recipient, ctx); + } +} \ No newline at end of file diff --git a/mover/Erikaibble/code/task3/Move.toml b/mover/Erikaibble/code/task3/Move.toml new file mode 100644 index 000000000..63e66c4e5 --- /dev/null +++ b/mover/Erikaibble/code/task3/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "task3" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +task3 = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/Erikaibble/code/task3/sources/task3.move b/mover/Erikaibble/code/task3/sources/task3.move new file mode 100644 index 000000000..5008e51c2 --- /dev/null +++ b/mover/Erikaibble/code/task3/sources/task3.move @@ -0,0 +1,47 @@ +module task3::erikaibble_nft { + use std::ascii::String; + use std::string::utf8; + use sui::display; + use sui::object; + use sui::object::{UID}; + use sui::package; + use sui::transfer; + use sui::transfer::public_transfer; + use sui::tx_context; + use sui::tx_context::{TxContext}; + + public struct ERIKAIBBLE_NFT has drop {} + + public struct NFT has key,store { + id: UID, + name: String, + } + + fun init(otw: ERIKAIBBLE_NFT, ctx: &mut sui::tx_context::TxContext) { + let keys = vector[ + utf8(b"name"), + utf8(b"image_url"), + ]; + + let values = vector[ + utf8(b"{name}"), + utf8(b"https://avatars.githubusercontent.com/u/169317715?v=4"), + ]; + + let publisher = package::claim(otw, ctx); + let mut display = display::new_with_fields(&publisher, keys, values,ctx); + + display::update_version(&mut display); + + transfer::public_transfer(publisher, tx_context::sender(ctx)); + transfer::public_transfer(display, tx_context::sender(ctx)); + } + + public entry fun mint_to(name: String, recipient: address,ctx: &mut TxContext) { + let nft = NFT{ + id: object::new(ctx), + name, + }; + public_transfer(nft, recipient) + } +} \ No newline at end of file diff --git a/mover/Erikaibble/code/task4/Move.toml b/mover/Erikaibble/code/task4/Move.toml new file mode 100644 index 000000000..a63b7a511 --- /dev/null +++ b/mover/Erikaibble/code/task4/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "task4" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +task4 = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/Erikaibble/code/task4/sources/task4.move b/mover/Erikaibble/code/task4/sources/task4.move new file mode 100644 index 000000000..cc242854b --- /dev/null +++ b/mover/Erikaibble/code/task4/sources/task4.move @@ -0,0 +1,170 @@ +module task4::erikaibble_game { + use std::string::{Self, String}; + use sui::event; + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::tx_context::sender; + use std::hash; + use sui::bcs; + + const EPoolNotEnough: u64 = 1; + const EInputNotEnough: u64 = 2; + const ERR_HIGH_ARG_GREATER_THAN_LOW_ARG: u64 = 101; + + public struct GameResult has copy, drop { + result: String, + is_winner: bool, + } + + public struct Game has key { + id: UID, + pool: Balance, + ticket: u64, + reward: u64, + } + + public struct SpinResult has copy, drop, store { + spin1: u8, + spin2: u8, + spin3: u8, + } + + public fun game_pool(game: &Game): u64 { + balance::value(&game.pool) + } + + public fun game_ticket(game: &Game): u64 { + game.ticket + } + + public fun game_reward(game: &Game): u64 { + game.reward + } + + public struct AdminCap has key { + id: UID, + } + + fun init(_ctx: &mut TxContext) { + } + + entry fun creat_game(ctx: &mut TxContext) { + let game = Game { + id: object::new(ctx), + pool: balance::zero(), + ticket: 1000, + reward: 2000, + }; + transfer::share_object(game); + + let admin_cap = AdminCap { id: object::new(ctx) }; + transfer::transfer(admin_cap, sender(ctx)); + } + + fun get_spin_result(ctx: &mut TxContext) : SpinResult { + let spin1 = (rand_u64_range(0, 5, ctx) as u8); + let spin2 = (rand_u64_range(0, 5, ctx) as u8); + let spin3 = (rand_u64_range(0, 5, ctx) as u8); + SpinResult { spin1, spin2, spin3 } + } + + public entry fun play(game: &mut Game, input: Coin, ctx: &mut TxContext) { + assert!(balance::value(&game.pool) >= game.reward - game.ticket, EPoolNotEnough); + + let player_spins = get_spin_result(ctx); + let winning_combination = SpinResult { spin1: 2, spin2: 2, spin3: 2 }; + + let input_value = coin::value(&input); + assert!(input_value >= game.ticket, EInputNotEnough); + + let mut input_balance = coin::into_balance(input); + if (input_value > game.ticket) { + balance::join( + &mut game.pool, + balance::split(&mut input_balance, game.ticket) + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, sender(ctx)); + } else { + balance::join(&mut game.pool, input_balance); + }; + + let (result, is_winner) = if (player_spins.spin1 == winning_combination.spin1 && player_spins.spin2 == winning_combination.spin2 && player_spins.spin3 == winning_combination.spin3) { + ( string::utf8(b"Congratulations, you hit the jackpot! Collect your coins😄"), true) + } else { + ( string::utf8(b"Try again, better luck next time!💔"), false) + }; + + if (is_winner) { + let reward_balance = balance::split(&mut game.pool, game.reward); + let reward = coin::from_balance(reward_balance, ctx); + transfer::public_transfer(reward, sender(ctx)); + }; + + event::emit(GameResult { + result, + is_winner, + }); + } + + public entry fun deposit(game: &mut Game, input: Coin, amount: u64, ctx: &mut TxContext) { + let input_value = coin::value(&input); + assert!(input_value >= amount, EInputNotEnough); + + let mut input_balance = coin::into_balance(input); + if (input_value > amount) { + balance::join( + &mut game.pool, + balance::split(&mut input_balance, amount) + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, sender(ctx)); + } else { + balance::join(&mut game.pool, input_balance); + } + } + + public entry fun withdraw(_: &AdminCap, game: &mut Game, amount: u64, ctx: &mut TxContext) { + let output_balance = balance::split(&mut game.pool, amount); + let output = coin::from_balance(output_balance, ctx); + transfer::public_transfer(output, sender(ctx)); + } + + fun seed(ctx: &mut TxContext): vector { + let ctx_bytes = bcs::to_bytes(ctx); + let uid = object::new(ctx); + let uid_bytes: vector = object::uid_to_bytes(&uid); + object::delete(uid); + + let mut info: vector = vector::empty(); + vector::append(&mut info, ctx_bytes); + vector::append(&mut info, uid_bytes); + + let hash: vector = hash::sha3_256(info); + hash + } + + fun bytes_to_u64(bytes: vector): u64 { + let mut value = 0u64; + let mut i = 0u64; + while (i < 8) { + value = value | ((*vector::borrow(&bytes, i) as u64) << ((8 * (7 - i)) as u8)); + i = i + 1; + }; + return value + } + + fun rand_u64_with_seed(_seed: vector): u64 { + bytes_to_u64(_seed) + } + + fun rand_u64_range_with_seed(_seed: vector, low: u64, high: u64): u64 { + assert!(high > low, ERR_HIGH_ARG_GREATER_THAN_LOW_ARG); + let value = rand_u64_with_seed(_seed); + (value % (high - low)) + low + } + + public fun rand_u64_range(low: u64, high: u64, ctx: &mut TxContext): u64 { + rand_u64_range_with_seed(seed(ctx), low, high) + } +} \ No newline at end of file diff --git a/mover/Erikaibble/img/scan3.png b/mover/Erikaibble/img/scan3.png new file mode 100644 index 000000000..d340f17b8 Binary files /dev/null and b/mover/Erikaibble/img/scan3.png differ diff --git a/mover/Erikaibble/readme.md b/mover/Erikaibble/readme.md index b3a58d59f..893f202f3 100644 --- a/mover/Erikaibble/readme.md +++ b/mover/Erikaibble/readme.md @@ -19,23 +19,23 @@ - [x] package id 在 scan上的查看截图:![Scan截图](./img/scan2.png) ## 02 move coin -- [] My Coin package id : -- [] Faucet package id : -- [] 转账 `My Coin` hash: -- [] `Faucet Coin` address1 mint hash: -- [] `Faucet Coin` address2 mint hash: +- [x] My Coin package id : 0x00cba092a7037174b482be3ee3b44cd9be4544ebe0f5397902264de5ab27cf94 +- [x] Faucet package id : 0x00cba092a7037174b482be3ee3b44cd9be4544ebe0f5397902264de5ab27cf94 +- [x] 转账 `My Coin` hash: Gn4sxyHyM3WzQxdmpekfU8QZR6orGDGuzB6rJDpNvcTH +- [x] `Faucet Coin` address1 mint hash: 3JibGxyMVFRVy5Kd5G6ziCjvkbQewqmixp1RiphszXkF +- [x] `Faucet Coin` address2 mint hash: 7zFEegXoFRvea3u7aPxrFXQAYC2r2VX8jzaFs9tG65B ## 03 move NFT -- [] nft package id : -- [] nft object id : -- [] 转账 nft hash: -- [] scan上的NFT截图:![Scan截图](./images/你的图片地址) +- [x] nft package id : 0x93b8a9f76de0f8bcd084e32575ef5b48c22e43065688a3a888190a681ab54af1 +- [x] nft object id : 0x4a706ff4e9585f8df6314930164f03e30b68655f8accf3d97e84a55dd6351de0 +- [x] 转账 nft hash: FaoQ4L7Fj8q9qADGgoQxejrg2BC6EPzmqLYTLXkuJtA2 +- [x] scan上的NFT截图:![Scan截图](./img/scan3.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [x] game package id : 0xedf9aad195e01bbb8e421df49f69b15a5328141b7514e4c11d40d83437fa74c2 +- [x] deposit Coin hash: GBo5xh21HNiZVet4wcCWDD1wbk5T9M2T8yMtVpPFwGL2 +- [x] withdraw `Coin` hash: 4GbCUiaJj7z15iMgiizXNQjLRooSKFNNrixYWzJ2xpC6 +- [x] play game hash: 5R4WmD4CY2YCg8Scpbzqebb5EqJTaEi9pgWAcKPtEyiV ## 05 Move Swap - [] swap package id :