diff --git a/mover/hellogaod/code/task3/nfts/.gitignore b/mover/hellogaod/code/task3/nfts/.gitignore new file mode 100644 index 000000000..a007feab0 --- /dev/null +++ b/mover/hellogaod/code/task3/nfts/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/mover/hellogaod/code/task3/nfts/Move.lock b/mover/hellogaod/code/task3/nfts/Move.lock new file mode 100644 index 000000000..e097367f8 --- /dev/null +++ b/mover/hellogaod/code/task3/nfts/Move.lock @@ -0,0 +1,122 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "1841A5F15674DE3FCBC769C1E7FF59DDC6A335646EF37F41D3FCAE032A9283F4" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "NftProtocol", name = "NftProtocol" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "Allowlist" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\allowlist" } + +dependencies = [ + { id = "Permissions", name = "Permissions" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "Authlist" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\authlist" } + +dependencies = [ + { id = "Permissions", name = "Permissions" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "Kiosk" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\kiosk" } + +dependencies = [ + { id = "Permissions", name = "Permissions" }, + { id = "Request", name = "Request" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet-v1.19.1", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "NftProtocol" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts/nft_protocol" } + +dependencies = [ + { id = "Allowlist", name = "Allowlist" }, + { id = "Authlist", name = "Authlist" }, + { id = "Kiosk", name = "Kiosk" }, + { id = "Originmate", name = "Originmate" }, + { id = "Permissions", name = "Permissions" }, + { id = "Pseudorandom", name = "Pseudorandom" }, + { id = "Request", name = "Request" }, + { id = "Sui", name = "Sui" }, + { id = "Utils", name = "Utils" }, +] + +[[move.package]] +id = "Originmate" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\originmate" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "Permissions" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\permissions" } + +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "Utils", name = "Utils" }, +] + +[[move.package]] +id = "Pseudorandom" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\pseudorandom" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "Request" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\request" } + +dependencies = [ + { id = "Permissions", name = "Permissions" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet-v1.19.1", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "Utils" +source = { git = "https://github.com/Origin-Byte/nft-protocol.git", rev = "main", subdir = "contracts\\utils" } + +dependencies = [ + { id = "Pseudorandom", name = "Pseudorandom" }, + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.48.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x4c5c1ff14e85bfbb84a7803de5054ed24abdca67afdfefe00e0e82e343c8a67b" +latest-published-id = "0x4c5c1ff14e85bfbb84a7803de5054ed24abdca67afdfefe00e0e82e343c8a67b" +published-version = "1" diff --git a/mover/hellogaod/code/task3/nfts/Move.toml b/mover/hellogaod/code/task3/nfts/Move.toml new file mode 100644 index 000000000..fd7cbe2a2 --- /dev/null +++ b/mover/hellogaod/code/task3/nfts/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "nfts" +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 = "mainnet-v1.19.1" } +NftProtocol = { git = "https://github.com/Origin-Byte/nft-protocol.git", subdir = "contracts/nft_protocol", rev = "main" } + +# 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] +nfts = "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/hellogaod/code/task3/nfts/sources/nfts.move b/mover/hellogaod/code/task3/nfts/sources/nfts.move new file mode 100644 index 000000000..7c011037d --- /dev/null +++ b/mover/hellogaod/code/task3/nfts/sources/nfts.move @@ -0,0 +1,69 @@ +module nfts::nfts { + use nft_protocol::attributes::{Self, Attributes}; + use nft_protocol::collection; + use std::ascii::String; + use std::string; + use sui::url::{Self, Url}; + use nft_protocol::display_info; + use nft_protocol::mint_cap::{Self, MintCap}; + use nft_protocol::mint_event; + use ob_permissions::witness; + + public struct NFTS has drop {} + + /// 可用于创建后授权其他操作。至关重要的是,这个结构体不能随意提供给任何合约,因为它充当了授权令牌。 + public struct Witness has drop {} + + public struct NFT has key, store { + id: UID, + name: String, + description: String, + url: Url, + attributes: Attributes, + } + + fun init(otw: NFTS, ctx: &mut TxContext) { + let (mut collection, mint_cap) = collection::create_with_mint_cap( + &otw, option::none(), ctx + ); + let delegated_witness = witness::from_witness(Witness {}); + + collection::add_domain( + delegated_witness, + &mut collection, + display_info::new( + string::utf8(b"NFTs"), + string::utf8(b"A NFT collection of NFTs on Sui"), + ), + ); + transfer::public_share_object(collection); + transfer::public_share_object(mint_cap); + } + + public entry fun mint_nft( + mint_cap: &MintCap, + name: String, + description: String, + url: String, + ctx: &mut TxContext, + ) { + let nft = NFT { + id: object::new(ctx), + name, + description, + url: url::new_unsafe(url), + attributes: attributes::from_vec(vector[], vector[]) + }; + + mint_event::emit_mint( + witness::from_witness(Witness {}), + mint_cap::collection_id(mint_cap), + &nft, + ); + transfer::public_transfer(nft, tx_context::sender(ctx)); + } + + public entry fun transfer_nft(nft: NFT, to: address) { + transfer::public_transfer(nft, to); + } +} diff --git a/mover/hellogaod/code/task3/nfts/tests/nfts_tests.move b/mover/hellogaod/code/task3/nfts/tests/nfts_tests.move new file mode 100644 index 000000000..8a6d7c4f2 --- /dev/null +++ b/mover/hellogaod/code/task3/nfts/tests/nfts_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module nfts::nfts_tests; +// uncomment this line to import the module +// use nfts::nfts; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_nfts() { + // pass +} + +#[test, expected_failure(abort_code = ::nfts::nfts_tests::ENotImplemented)] +fun test_nfts_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/hellogaod/code/task4/game/.gitignore b/mover/hellogaod/code/task4/game/.gitignore new file mode 100644 index 000000000..a007feab0 --- /dev/null +++ b/mover/hellogaod/code/task4/game/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/mover/hellogaod/code/task4/game/Move.lock b/mover/hellogaod/code/task4/game/Move.lock new file mode 100644 index 000000000..ea95b1dd4 --- /dev/null +++ b/mover/hellogaod/code/task4/game/Move.lock @@ -0,0 +1,68 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "F5E8D4DA4A646A9C4D17FFC36E23371A31548D863B8005D8F36679A45049E900" +deps_digest = "397E6A9F7A624706DBDFEE056CE88391A15876868FD18A88504DA74EB458D697" +dependencies = [ + { id = "Bridge", name = "Bridge" }, + { id = "MoveStdlib", name = "MoveStdlib" }, + { id = "Sui", name = "Sui" }, + { id = "SuiSystem", name = "SuiSystem" }, + { id = "hellogaod_faucet_coin", name = "hellogaod_faucet_coin" }, +] + +[[move.package]] +id = "Bridge" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "3802482bd4e3", subdir = "crates/sui-framework/packages/bridge" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, + { id = "Sui", name = "Sui" }, + { id = "SuiSystem", name = "SuiSystem" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "3802482bd4e3", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "3802482bd4e3", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "SuiSystem" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "3802482bd4e3", subdir = "crates/sui-framework/packages/sui-system" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "hellogaod_faucet_coin" +source = { local = "..\\..\\task2\\hellogaod_faucet_coin" } + +dependencies = [ + { id = "Bridge", name = "Bridge" }, + { id = "MoveStdlib", name = "MoveStdlib" }, + { id = "Sui", name = "Sui" }, + { id = "SuiSystem", name = "SuiSystem" }, +] + +[move.toolchain-version] +compiler-version = "1.48.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x01f1fc9a3226bb4d2579fb87aecd794c3aeaf6ec8a15a1dec89fe918bd5ab47e" +latest-published-id = "0x01f1fc9a3226bb4d2579fb87aecd794c3aeaf6ec8a15a1dec89fe918bd5ab47e" +published-version = "1" diff --git a/mover/hellogaod/code/task4/game/Move.toml b/mover/hellogaod/code/task4/game/Move.toml new file mode 100644 index 000000000..5ada7c92a --- /dev/null +++ b/mover/hellogaod/code/task4/game/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "game" +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] + +hellogaod_faucet_coin = { local = "../../task2/hellogaod_faucet_coin" } + +# 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] +game = "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/hellogaod/code/task4/game/sources/game.move b/mover/hellogaod/code/task4/game/sources/game.move new file mode 100644 index 000000000..9a325b576 --- /dev/null +++ b/mover/hellogaod/code/task4/game/sources/game.move @@ -0,0 +1,94 @@ +module game::game { + use sui::coin::{Self, Coin}; + use hellogaod_faucet_coin::hellogaod_faucet_coin::HELLOGAOD_FAUCET_COIN; + use sui::balance::{Self, Balance}; + use sui::random::{Self, Random}; + + const EUserInsufficientBalance: u64 = 1000; + const EGameInsufficientBalance: u64 = 1001; + + public struct Game has key { + id: UID, + balance: Balance, + } + + public struct Admin has key { + id: UID, + } + + fun init(ctx: &mut TxContext) { + let game = Game { + id: object::new(ctx), + balance: balance::zero(), + }; + transfer::share_object(game); + + let admin = Admin {id: object::new(ctx)}; + transfer::transfer(admin, ctx.sender()); + } + + public entry fun Deposit( + game: &mut Game, + coin: &mut Coin, + amount: u64, + ) { + assert!( + coin::value(coin) >= amount, + EUserInsufficientBalance + ); + let split_balance = balance::split(coin::balance_mut(coin), amount); + balance::join(&mut game.balance, split_balance); + } + + // 只有管理员能够提现 + public entry fun Withdraw( + game: &mut Game, + _: &Admin, + amount: u64, + ctx: &mut TxContext + ) { + assert!( + game.balance.value() >= amount, + EGameInsufficientBalance + ); + let cash = coin::take(&mut game.balance, amount, ctx); + transfer::public_transfer(cash, ctx.sender()); + } + + // 如果用户猜对了,获得双倍奖励。如果用户猜错了,损失投入的代币 + + public entry fun Play( + game: &mut Game, + rnd: &Random, + guess: bool, + coin: &mut Coin, + amount: u64, + ctx: &mut TxContext + ) { + // 检查合约余额是否充足,确保用户获胜时有足够金额奖励 + assert!( + game.balance.value() >= amount, + EGameInsufficientBalance + ); + // 检查用户的余额是否充足 + assert!( + coin::value(coin) >= amount, + EUserInsufficientBalance + ); + + // 生成随机数 + let mut gen = random::new_generator(rnd, ctx); + let flag = random::generate_bool(&mut gen); + + // 如果获胜 + if (flag == guess) { + // 投入的代币不变,另外奖励等额的代币 + let reward = coin::take(&mut game.balance, amount, ctx); + coin::join(coin, reward); + } + // 猜错了就损失投入的代币 + else { + Self::Deposit(game, coin, amount) + } + } +} diff --git a/mover/hellogaod/code/task4/game/tests/game_tests.move b/mover/hellogaod/code/task4/game/tests/game_tests.move new file mode 100644 index 000000000..9470e9c04 --- /dev/null +++ b/mover/hellogaod/code/task4/game/tests/game_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module game::game_tests; +// uncomment this line to import the module +// use game::game; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_game() { + // pass +} + +#[test, expected_failure(abort_code = ::game::game_tests::ENotImplemented)] +fun test_game_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/hellogaod/images/task3.png b/mover/hellogaod/images/task3.png new file mode 100644 index 000000000..e4ed57dd2 Binary files /dev/null and b/mover/hellogaod/images/task3.png differ diff --git a/mover/hellogaod/readme.md b/mover/hellogaod/readme.md index 3e65180c2..d1194003b 100644 --- a/mover/hellogaod/readme.md +++ b/mover/hellogaod/readme.md @@ -21,22 +21,22 @@ ## 02 move coin - [x] My Coin package id : 0x990153cb1e640274ee78eb7b36afcf57d98274eea039b5ae3278451645066c91 -- [] Faucet package id : 0x0f70c1a4c9098d2d9430da35032ecaeab7e0381e5e0a3bd40d9da595f7093048 +- [x] Faucet package id : 0x0f70c1a4c9098d2d9430da35032ecaeab7e0381e5e0a3bd40d9da595f7093048 - [x] 转账 `My Coin` hash: 4eM7PRgnRvLKYgUXL4dwyDYKxu8uzDQThbrrmec3G2kS -- [] `Faucet Coin` address1 mint hash:GTdHw31bvRAEDthPxxENdZGBD9HJRCmyDgkj6aZwCF8d -- [] `Faucet Coin` address2 mint hash:7FQLiY396DHmoxfSsX6F9sSWhYFWeQa3w8LxzS8giTbn +- [x] `Faucet Coin` address1 mint hash:GTdHw31bvRAEDthPxxENdZGBD9HJRCmyDgkj6aZwCF8d +- [x] `Faucet Coin` address2 mint hash:7FQLiY396DHmoxfSsX6F9sSWhYFWeQa3w8LxzS8giTbn ## 03 move NFT -- [] nft package id : -- [] nft object id : -- [] 转账 nft hash: -- [] scan上的NFT截图:![Scan截图](./images/你的图片地址) +- [x] nft package id : 0x4c5c1ff14e85bfbb84a7803de5054ed24abdca67afdfefe00e0e82e343c8a67b +- [x] nft object id : 0xe081c5cc3ddc6dbfb2a695b43d7a9743dd98ef8c89761e48b5594e052b3204a7 +- [x] 转账 nft hash: DA2tRzkz4C2gqnGss6immZpBMkUrqD1hBjDCKesqd5tb +- [x] scan上的NFT截图:![Scan截图](./images/task3.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [x] game package id : 0x01f1fc9a3226bb4d2579fb87aecd794c3aeaf6ec8a15a1dec89fe918bd5ab47e +- [x] deposit Coin hash: GiT9oEPv95UsEWekHSM36198ayLc7YFKj75UgrbTNXzF +- [x] withdraw `Coin` hash: 2VPU3FsjpYEzrA4unhsc6v8d19daFp58HLhYkMa1JanR +- [x] play game hash: FQpCSP9xxWJ8fvm1T7BqDY1trZ56TYkTk43DDFKygGNT ## 05 Move Swap - [] swap package id :