diff --git a/mover/M2887/code/task2/M2887_coin/Move.lock b/mover/M2887/code/task2/M2887_coin/Move.lock new file mode 100644 index 000000000..d38988c7a --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/Move.lock @@ -0,0 +1,34 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "A3C48AC10A4DA68968B0E13A48727700DF3E5338373844B02767097F9C3C2AEE" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.38.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x5a3a556c1b4cb0d9e20595fc0819bef617de4a6b16c258e58f49e7d1c27d4cf9" +latest-published-id = "0x5a3a556c1b4cb0d9e20595fc0819bef617de4a6b16c258e58f49e7d1c27d4cf9" +published-version = "1" diff --git a/mover/M2887/code/task2/M2887_coin/Move.toml b/mover/M2887/code/task2/M2887_coin/Move.toml new file mode 100644 index 000000000..efc3531f0 --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "M2887_coin" +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://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# 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] +m2887_coin = "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/M2887/code/task2/M2887_coin/sources/m2887_coin.move b/mover/M2887/code/task2/M2887_coin/sources/m2887_coin.move new file mode 100644 index 000000000..f6ae56937 --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/sources/m2887_coin.move @@ -0,0 +1,64 @@ +/* +/// Module: m2887_coin +module m2887_coin::m2887_coin; +*/ +/* +/// Module: m2887_coin +module m2887_coin::m2887_coin; +*/ + +module m2887_coin::m2887_coin { // 定义模块 M2887_coin + use sui::coin::{Self, Coin, TreasuryCap}; // 引入 Coin 和 TreasuryCap 相关功能 + use sui::url::{Self, Url}; // 引入 URL 相关功能 + + // 定义一种新的货币类型 M2887_COIN,且具有可丢弃的特性 + public struct M2887_COIN has drop {} + + // 初始化函数,用于创建该货币 + fun init( + witness: M2887_COIN, // 货币的见证对象 + ctx: &mut TxContext // 交易上下文 + ) { + // 调用 coin 模块创建货币,并设置相关参数 + let (treasury_cap, metadata) = coin::create_currency( + witness, // 见证对象 + 9, // 小数位数 + b"M2887", // 货币符号 + b"M2887_COIN", // 货币代码 + b"M2887 Coin", // 货币名称 + option::some( // 货币相关的 URL + url::new_unsafe_from_bytes( + b"https://avatars.githubusercontent.com/u/49989931" // 头像链接 + ) + ), + ctx // 交易上下文 + ); + // 冻结元数据对象,确保其在交易过程中不会被修改 + transfer::public_freeze_object(metadata); + // 将国库资本转移到交易的发送者地址 + transfer::public_transfer( + treasury_cap, + tx_context::sender(ctx) // 获取发送者地址 + ) + } + + // 公共入口函数,用于铸造新的 M2887_COIN 货币 + public entry fun mint( + treasury_cap: &mut TreasuryCap, // 货币国库 + amount: u64, // 铸造的数量 + recipient: address, // 接收地址 + ctx: &mut TxContext // 交易上下文 + ) { + // 调用 coin 模块的铸造和转移函数 + coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); + } + + // 公共函数,用于销毁 M2887_COIN 货币 + public fun burn( + treasury_cap: &mut TreasuryCap, // 货币国库 + coin: Coin // 需要销毁的货币 + ) { + // 调用 coin 模块的销毁函数 + coin::burn(treasury_cap, coin); + } +} diff --git a/mover/M2887/code/task2/M2887_coin/tests/m2887_coin_tests.move b/mover/M2887/code/task2/M2887_coin/tests/m2887_coin_tests.move new file mode 100644 index 000000000..83dda0292 --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/tests/m2887_coin_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module m2887_coin::m2887_coin_tests; +// uncomment this line to import the module +// use m2887_coin::m2887_coin; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_m2887_coin() { + // pass +} + +#[test, expected_failure(abort_code = ::m2887_coin::m2887_coin_tests::ENotImplemented)] +fun test_m2887_coin_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/M2887/code/task2/M2887_faucet_coin/Move.lock b/mover/M2887/code/task2/M2887_faucet_coin/Move.lock new file mode 100644 index 000000000..b265786d2 --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/Move.lock @@ -0,0 +1,34 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "3A777708EF0279F6E6ACE0D9041A7E7BDAD519CF18475E902C51FEFD4A64DAAB" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.38.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x8526f8f3d7e23ca6e2c68c67855357745f03a9097d93a3dd3274a44290fc3faa" +latest-published-id = "0x8526f8f3d7e23ca6e2c68c67855357745f03a9097d93a3dd3274a44290fc3faa" +published-version = "1" diff --git a/mover/M2887/code/task2/M2887_faucet_coin/Move.toml b/mover/M2887/code/task2/M2887_faucet_coin/Move.toml new file mode 100644 index 000000000..3b642289e --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "M2887_faucet_coin" +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://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# 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] +m2887_faucet_coin = "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/M2887/code/task2/M2887_faucet_coin/sources/m2887_faucet_coin.move b/mover/M2887/code/task2/M2887_faucet_coin/sources/m2887_faucet_coin.move new file mode 100644 index 000000000..6bd6b7598 --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/sources/m2887_faucet_coin.move @@ -0,0 +1,50 @@ +/* +/// Module: m2887_faucet_coin +module m2887_faucet_coin::m2887_faucet_coin; +*/ +module m2887_faucet_coin::m2887_faucet_coin { + use sui::coin::{Self, Coin, TreasuryCap}; + use sui::url::{Self, Url}; + + public struct M2887_FAUCET_COIN has drop {} + + fun init( + witness: M2887_FAUCET_COIN, + ctx: &mut TxContext + ) { + let (treasury_cap, metadata) = coin::create_currency( + witness, + 9, + b"CRF", + b"M2887_FAUCET_COIN", + b"M2887 Faucet Coin", + option::some( + url::new_unsafe_from_bytes( + b"https://avatars.githubusercontent.com/u/49989931" + ) + ), + ctx + ); + transfer::public_freeze_object(metadata); + transfer::public_share_object(treasury_cap) + } + + public entry fun mint( + treasury_cap: &mut TreasuryCap, + amount: u64, + recipient: address, + ctx: &mut TxContext + ) { + coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); + } + + public fun burn( + treasury_cap: &mut TreasuryCap, + coin: Coin + ) { + coin::burn(treasury_cap, coin); + + } +} + + diff --git a/mover/M2887/code/task2/M2887_faucet_coin/tests/m2887_faucet_coin_tests.move b/mover/M2887/code/task2/M2887_faucet_coin/tests/m2887_faucet_coin_tests.move new file mode 100644 index 000000000..9785c3ce5 --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/tests/m2887_faucet_coin_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module m2887_faucet_coin::m2887_faucet_coin_tests; +// uncomment this line to import the module +// use m2887_faucet_coin::m2887_faucet_coin; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_m2887_faucet_coin() { + // pass +} + +#[test, expected_failure(abort_code = ::m2887_faucet_coin::m2887_faucet_coin_tests::ENotImplemented)] +fun test_m2887_faucet_coin_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/M2887/code/task3/M2887_NFT/Move.lock b/mover/M2887/code/task3/M2887_NFT/Move.lock new file mode 100644 index 000000000..307b3d959 --- /dev/null +++ b/mover/M2887/code/task3/M2887_NFT/Move.lock @@ -0,0 +1,122 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "626B61B466ECA1260F24FE1298C9CC4124587FB871F6BCF2B714095FE6E2B207" +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.38.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0xda51f62ad654d484ff0e2b23cabcf87a590bcdf5127bce3f4150f5499de6a7ed" +latest-published-id = "0xda51f62ad654d484ff0e2b23cabcf87a590bcdf5127bce3f4150f5499de6a7ed" +published-version = "1" diff --git a/mover/M2887/code/task3/M2887_NFT/Move.toml b/mover/M2887/code/task3/M2887_NFT/Move.toml new file mode 100644 index 000000000..924a507dc --- /dev/null +++ b/mover/M2887/code/task3/M2887_NFT/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "M2887_NFT" +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] +m2887_nft = "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/M2887/code/task3/M2887_NFT/sources/m2887_nft.move b/mover/M2887/code/task3/M2887_NFT/sources/m2887_nft.move new file mode 100644 index 000000000..b2539bb1e --- /dev/null +++ b/mover/M2887/code/task3/M2887_NFT/sources/m2887_nft.move @@ -0,0 +1,73 @@ +/* +/// Module: m2887_nft +module m2887_nft::m2887_nft; +*/ +module m2887_nft::m2887_nft { + 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 M2887_NFT 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: M2887_NFT, 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"M2887_NFT"), + string::utf8(b"A NFT collection of M2887_NFT 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/M2887/code/task3/M2887_NFT/tests/m2887_nft_tests.move b/mover/M2887/code/task3/M2887_NFT/tests/m2887_nft_tests.move new file mode 100644 index 000000000..37d65dc7b --- /dev/null +++ b/mover/M2887/code/task3/M2887_NFT/tests/m2887_nft_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module m2887_nft::m2887_nft_tests; +// uncomment this line to import the module +// use m2887_nft::m2887_nft; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_m2887_nft() { + // pass +} + +#[test, expected_failure(abort_code = ::m2887_nft::m2887_nft_tests::ENotImplemented)] +fun test_m2887_nft_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/M2887/code/task3/scan.png b/mover/M2887/code/task3/scan.png new file mode 100644 index 000000000..9cc4c48e9 Binary files /dev/null and b/mover/M2887/code/task3/scan.png differ diff --git a/mover/M2887/code/task4/move_game/Move.lock b/mover/M2887/code/task4/move_game/Move.lock new file mode 100644 index 000000000..a0d610dd4 --- /dev/null +++ b/mover/M2887/code/task4/move_game/Move.lock @@ -0,0 +1,43 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "CAFB1D92314A2DE3DC0D70458B44CD742C0CE92F284106A519675843C34B0BD9" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "M2887_faucet_coin", name = "M2887_faucet_coin" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "M2887_faucet_coin" +source = { local = "..\\..\\task2\\M2887_faucet_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.38.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x7e1792a1a41a30206da3198784b9285dfa1e66bf227d834eb5d2ac9495554a64" +latest-published-id = "0x7e1792a1a41a30206da3198784b9285dfa1e66bf227d834eb5d2ac9495554a64" +published-version = "1" diff --git a/mover/M2887/code/task4/move_game/Move.toml b/mover/M2887/code/task4/move_game/Move.toml new file mode 100644 index 000000000..3fe39d397 --- /dev/null +++ b/mover/M2887/code/task4/move_game/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "move_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] +Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } +M2887_faucet_coin = { local = "../../task2/M2887_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] +move_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/M2887/code/task4/move_game/sources/move_game.move b/mover/M2887/code/task4/move_game/sources/move_game.move new file mode 100644 index 000000000..e2be72f11 --- /dev/null +++ b/mover/M2887/code/task4/move_game/sources/move_game.move @@ -0,0 +1,89 @@ +/* +/// Module: move_game +module move_game::move_game; +*/ +/* +/// Module: move_game +module move_game::move_game; +*/ +module move_game::flip_coin { + + use sui::balance; + use sui::balance::Balance; + use sui::coin; + use sui::coin::{Coin, from_balance, into_balance}; + use sui::object; + use sui::random; + use sui::random::Random; + use sui::transfer::{share_object, transfer, public_transfer}; + use sui::tx_context::sender; + use m2887_faucet_coin::m2887_faucet_coin::M2887_FAUCET_COIN; + + public struct Game has key { + id: UID, + val: Balance + } + public struct AdminCap has key { + id: UID, + } + fun init(ctx: &mut TxContext) { + let game = Game { + id: object::new(ctx), + val: balance::zero() + }; + share_object(game); + + let admin = AdminCap { + id: object::new(ctx) + }; + + transfer(admin, sender(ctx)); + } + + entry fun play(game: &mut Game, flip_value: bool, in: Coin, rand: &Random, + ctx: &mut TxContext) { + let coin_value = coin::value(&in); + + let play_address = sender(ctx); + let game_val = balance::value(&game.val) ; + + if (game_val < coin_value) { + abort 100u64; + }; + + //防止 all in 战神 + //每次最大值 就是合约里面钱的10分之一就行了 + if (coin_value > game_val / 10) { + abort 101u64; + }; + + let mut gen = random::new_generator(rand, ctx); + + let mut flag = random::generate_bool(&mut gen); + + if (flip_value == flag) { + let win_balance = balance::split(&mut game.val, coin_value); + let win_coin = from_balance(win_balance, ctx); + public_transfer(win_coin, play_address); + public_transfer(in, play_address); + }else { + let in_balance = into_balance(in); + balance::join(&mut game.val, in_balance); + } + } + + // 存钱 + public entry fun add_sui(game: &mut Game, in: Coin, _ctx: &TxContext) { + let in_balance = into_balance(in); + balance::join(&mut game.val, in_balance); + } + + // 取钱 + public entry fun remove_sui(_: &AdminCap, game: &mut Game, + amt: u64, ctx: &mut TxContext) { + let win_balance = balance::split(&mut game.val, amt); + let win_coin = from_balance(win_balance, ctx); + public_transfer(win_coin, sender(ctx)); + } +} + diff --git a/mover/M2887/code/task4/move_game/tests/move_game_tests.move b/mover/M2887/code/task4/move_game/tests/move_game_tests.move new file mode 100644 index 000000000..c5ca6e5e8 --- /dev/null +++ b/mover/M2887/code/task4/move_game/tests/move_game_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module move_game::move_game_tests; +// uncomment this line to import the module +// use move_game::move_game; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_move_game() { + // pass +} + +#[test, expected_failure(abort_code = ::move_game::move_game_tests::ENotImplemented)] +fun test_move_game_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/M2887/code/task5/move_swap/Move.lock b/mover/M2887/code/task5/move_swap/Move.lock new file mode 100644 index 000000000..ebb9b4ba5 --- /dev/null +++ b/mover/M2887/code/task5/move_swap/Move.lock @@ -0,0 +1,52 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "381785A9309D0F5B5963238F71D082304B7837A6A7BC1F8FE2873781B9015B6B" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { id = "M2887_coin", name = "M2887_coin" }, + { id = "M2887_faucet_coin", name = "M2887_faucet_coin" }, + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "M2887_coin" +source = { local = "..\\..\\task2\\M2887_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "M2887_faucet_coin" +source = { local = "..\\..\\task2\\M2887_faucet_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.38.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x1789eb26b84f8b1c645888a738f3a869bfccee0b62ef227a8d5a3e7c05cc7be3" +latest-published-id = "0x1789eb26b84f8b1c645888a738f3a869bfccee0b62ef227a8d5a3e7c05cc7be3" +published-version = "1" diff --git a/mover/M2887/code/task5/move_swap/Move.toml b/mover/M2887/code/task5/move_swap/Move.toml new file mode 100644 index 000000000..802867624 --- /dev/null +++ b/mover/M2887/code/task5/move_swap/Move.toml @@ -0,0 +1,39 @@ +[package] +name = "m2887_swap" +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://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } +M2887_faucet_coin = { local = "../../task2/M2887_faucet_coin" } +M2887_coin = { local = "../../task2/M2887_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] +m2887_swap = "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/M2887/code/task5/move_swap/sources/move_swap.move b/mover/M2887/code/task5/move_swap/sources/move_swap.move new file mode 100644 index 000000000..df031da95 --- /dev/null +++ b/mover/M2887/code/task5/move_swap/sources/move_swap.move @@ -0,0 +1,164 @@ +/* +/// Module: m2887_swap +module m2887_swap::m2887_swap; +*/ + +module m2887_swap::m2887_swap; + +use m2887_faucet_coin::m2887_faucet_coin::M2887_FAUCET_COIN; +use m2887_coin::m2887_coin::M2887_COIN; +use sui::balance::{Self, Balance}; +use sui::coin::{Self, Coin}; + +const EInputNotEnough: u64 = 0; +const EPoolNotEnough: u64 = 1; + +public struct AdminCap has key { id: UID } + +public struct Pool has key { + // 如果需要,可以加上两种代币分别的存量属性,这里先不添加 + id: UID, + faucet_coin: Balance, + //faucet_coin_balance: u64, + my_coin: Balance, + //faucet_coin_balance: u64, +} + +fun init(ctx: &mut TxContext) { + let pool = Pool { + id: object::new(ctx), + faucet_coin: balance::zero(), + my_coin: balance::zero(), + }; + transfer::share_object(pool); // pool需要公开,通过AdminCap给予自己额外的管理员权限 + transfer::transfer(AdminCap { id: object::new(ctx) }, tx_context::sender(ctx)); +} + +public entry fun deposit_my_coin( + pool: &mut Pool, + input: Coin, + amount: u64, + ctx: &mut TxContext, +) { + let caller = tx_context::sender(ctx); + 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 pool.my_coin, + balance::split(&mut input_balance, amount), + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, caller); + } else { + balance::join(&mut pool.my_coin, input_balance); + }; +} + +public entry fun deposit__faucet_coin( + pool: &mut Pool, + input: Coin, + amount: u64, + ctx: &mut TxContext, +) { + let caller = tx_context::sender(ctx); + 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 pool.faucet_coin, + balance::split(&mut input_balance, amount), + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, caller); + } else { + balance::join(&mut pool.faucet_coin, input_balance); + }; +} + +// 我们可以编写一个withdraw函数,并限制只有拥有管理员权限才能提取资金 +public entry fun withdraw_zzf222_coin( + _: &AdminCap, + pool: &mut Pool, + amount: u64, + ctx: &mut TxContext, +) { + let my_coin_balance = balance::split(&mut pool.my_coin, amount); + let my_coin = coin::from_balance(my_coin_balance, ctx); + transfer::public_transfer(my_coin, tx_context::sender(ctx)); +} + +public entry fun withdraw_zzf222_faucet_coin( + _: &AdminCap, + pool: &mut Pool, + amount: u64, + ctx: &mut TxContext, +) { + let faucet_coin_balance = balance::split(&mut pool.faucet_coin, amount); + let faucet_coin = coin::from_balance(faucet_coin_balance, ctx); + transfer::public_transfer(faucet_coin, tx_context::sender(ctx)); +} + +// 在swap函数中,我们可以沿用部分上一节guess_game的代码 +public entry fun swap_faucet_coin_to_my_coin( + pool: &mut Pool, + input: Coin, + amount: u64, + ctx: &mut TxContext, +) { + + + let caller = tx_context::sender(ctx); + // get the input value and assert + let input_value = coin::value(&input); + let output_value = amount * 1000 / 2000; // amount千万不要写成input_value! + assert!(input_value >= amount, EInputNotEnough); + // transection the input value to Balance + let mut input_balance = coin::into_balance(input); + assert!(balance::value(&pool.my_coin) >= output_value, EPoolNotEnough); + // if input value much than amount, change the excess + if (input_value > amount) { + balance::join( + // join 函数用于接收代币 + &mut pool.faucet_coin, + balance::split(&mut input_balance, amount), + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, caller); + } else { + balance::join(&mut pool.faucet_coin, input_balance); + }; + let output_balance = balance::split(&mut pool.my_coin, output_value); + let output = coin::from_balance(output_balance, ctx); + transfer::public_transfer(output, caller); +} + +public entry fun swap_my_coin_to_faucet_coin( + pool: &mut Pool, + input: Coin, + amount: u64, + ctx: &mut TxContext, +) { + let caller = tx_context::sender(ctx); + let input_value = coin::value(&input); + let output_value = amount * 2000 / 1000; + assert!(input_value >= amount, EInputNotEnough); + let mut input_balance = coin::into_balance(input); + assert!(balance::value(&pool.faucet_coin) >= output_value, EPoolNotEnough); + if (input_value > amount) { + balance::join( + &mut pool.my_coin, + balance::split(&mut input_balance, amount), + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, caller); + } else { + balance::join(&mut pool.my_coin, input_balance); + }; + let output_balance = balance::split(&mut pool.faucet_coin, output_value); + let output = coin::from_balance(output_balance, ctx); + transfer::public_transfer(output, caller); +} + diff --git a/mover/M2887/code/task5/move_swap/tests/move_swap_tests.move b/mover/M2887/code/task5/move_swap/tests/move_swap_tests.move new file mode 100644 index 000000000..cfd3c3deb --- /dev/null +++ b/mover/M2887/code/task5/move_swap/tests/move_swap_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module move_swap::move_swap_tests; +// uncomment this line to import the module +// use move_swap::move_swap; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_move_swap() { + // pass +} + +#[test, expected_failure(abort_code = ::move_swap::move_swap_tests::ENotImplemented)] +fun test_move_swap_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/M2887/notes/readme.md b/mover/M2887/notes/readme.md index e69de29bb..18f56d57d 100755 --- a/mover/M2887/notes/readme.md +++ b/mover/M2887/notes/readme.md @@ -0,0 +1,18 @@ +##### task4 bash +```bash +sui client call --package 0x7e1792a1a41a30206da3198784b9285dfa1e66bf227d834eb5d2ac9495554a64 --module flip_coin --function play --args 0x62118895a58dbb94b3e27acb3b5d64e11bf95ba5a2f6edcc8df718a2cc3e60de true 0x05e1ef276631b526d3fd3429e8e900aa3bf758656557452167bf683e5175492b 0x8 --gas-budget 1000000 + +sui client call --package 0x7e1792a1a41a30206da3198784b9285dfa1e66bf227d834eb5d2ac9495554a64 --module flip_coin --function remove_sui --args 0x5a800a73fc12ab69963c4c2f8175ac99e89576c95c64b969ef8de56c1bc5674d 0x62118895a58dbb94b3e27acb3b5d64e11bf95ba5a2f6edcc8df718a2cc3e60de 100 --gas-budget 10000000 +``` + +##### task5 bash +```bash +coin mint +packageID:0x5a3a556c1b4cb0d9e20595fc0819bef617de4a6b16c258e58f49e7d1c27d4cf9 +TreasuryCap:0x2b50049a4b87eab90cd48c5d04d261fa179c5ea1026bb7fb2b74506b6b05d5d2 + +fauect_coin mint +packageID:0x8526f8f3d7e23ca6e2c68c67855357745f03a9097d93a3dd3274a44290fc3faa +TreasuryCap:0xff5d5b9c397db5e2c9fd8655140473ddc87f67970b7f460bf2c05a80c1a4c4e5 + +``` \ No newline at end of file diff --git a/mover/M2887/readme.md b/mover/M2887/readme.md index bc9e2d360..4ccbeb63e 100755 --- a/mover/M2887/readme.md +++ b/mover/M2887/readme.md @@ -13,34 +13,34 @@ ## 任务 ## 01 hello move -- [] Sui cli version: `sui 1.30.1-a4185da5659d` -- [] Sui钱包截图: ![Sui钱包截图](./images/SuiWallet.png) -- [] package id: `0xa204eb01017201ad502b283b60f582eb405914760c79513f35bd0edd89803210` -- [] package id 在 scan上的查看截图:![Scan截图](./images/SuiScan.png) +- [x] Sui cli version: `sui 1.30.1-a4185da5659d` +- [x] Sui钱包截图: ![Sui钱包截图](./images/SuiWallet.png) +- [x] package id: `0xa204eb01017201ad502b283b60f582eb405914760c79513f35bd0edd89803210` +- [x] package id 在 scan上的查看截图:![Scan截图](./images/SuiScan.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 : 0x5a3a556c1b4cb0d9e20595fc0819bef617de4a6b16c258e58f49e7d1c27d4cf9 +- [x] Faucet package id : 0x8526f8f3d7e23ca6e2c68c67855357745f03a9097d93a3dd3274a44290fc3faa +- [x] 转账 `My Coin` hash: E7n184sQfv9zPwZ5MZV2AAQoQPPnafXi1mTMqDwc8Uzp +- [x] `Faucet Coin` address1 mint hash: 447AsExCJqbPaYqo1wgZnXvNmDoToua5X33qARR1WHsq +- [x] `Faucet Coin` address2 mint hash: 97y7zWpdvJHN1u8bx1rn1QxhdhbM3UB8qfJ1sc2nCgAn ## 03 move NFT -- [] nft package id : -- [] nft object id : -- [] 转账 nft hash: -- [] scan上的NFT截图:![Scan截图](./images/你的图片地址) +- [x] nft package id : 0xda51f62ad654d484ff0e2b23cabcf87a590bcdf5127bce3f4150f5499de6a7ed +- [x] nft object id : 0x1edf87010b50139993e3dc1a625eabdec1e2fa318c1c25c77b9617a95af08753 +- [x] 转账 nft hash: CshAsuCoSHVB7P4i886froQfU9qCSWLsGHmJeE82e1sv +- [x] scan上的NFT截图:![Scan截图](./code/task3/scan.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [x] game package id : 0x7e1792a1a41a30206da3198784b9285dfa1e66bf227d834eb5d2ac9495554a64 +- [x] deposit Coin hash: 4zpRNznvDxaERdm2vqoqADWHQ4zzHMkR2Vo1thegUWW1 +- [x] withdraw `Coin` hash: DR23o9NKayA6GKe55oPcxeiEBJLs1saNsF5qPGb2yLqp +- [x] play game hash: GqrkVNG9KY3Rd6JeWEZMP59j4QAgBnU9CRBUhj5A44xR ## 05 Move Swap -- [] swap package id : -- [] call swap CoinA-> CoinB hash : -- [] call swap CoinB-> CoinA hash : +- [x] swap package id : 0x1789eb26b84f8b1c645888a738f3a869bfccee0b62ef227a8d5a3e7c05cc7be3 +- [x] call swap CoinA-> CoinB hash : Cn4ZFruTtYisva7gNcqtweo9gtyLPA5p3212L4exmbke +- [x] call swap CoinB-> CoinA hash : 5bevDEEeUMs1TxeRNMdncAt77uhAngaquBbRfpViNhDq ## 06 Dapp-kit SDK PTB - [] save hash :