diff --git a/mover/Sy711/code/task2/faucet/Move.lock b/mover/Sy711/code/task2/faucet_coin/Move.lock similarity index 91% rename from mover/Sy711/code/task2/faucet/Move.lock rename to mover/Sy711/code/task2/faucet_coin/Move.lock index 087bdd220..9c4fd1213 100644 --- a/mover/Sy711/code/task2/faucet/Move.lock +++ b/mover/Sy711/code/task2/faucet_coin/Move.lock @@ -2,7 +2,7 @@ [move] version = 3 -manifest_digest = "F8CFCF256E2F1BB7CD401C27799A09C40777C5C100F0DFA253E86DD7F0D4ED1B" +manifest_digest = "D114DF7DF52A9D3C741C7581FE632CD523FA7CF67D588CE1448B9D40C141BCB8" deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" dependencies = [ { id = "Sui", name = "Sui" }, diff --git a/mover/Sy711/code/task2/faucet/Move.toml b/mover/Sy711/code/task2/faucet_coin/Move.toml similarity index 94% rename from mover/Sy711/code/task2/faucet/Move.toml rename to mover/Sy711/code/task2/faucet_coin/Move.toml index 1b517a2be..d5a63288e 100644 --- a/mover/Sy711/code/task2/faucet/Move.toml +++ b/mover/Sy711/code/task2/faucet_coin/Move.toml @@ -19,7 +19,7 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram # Override = { local = "../conflicting/version", override = true } [addresses] -faucet_coin = "0x0" +faucet_coin = "0xb3743a94cbc755521c27fb5d91e2c8b34ea5b0df899654c20d2f965d301bb7dd" # Named addresses will be accessible in Move as `@name`. They're also exported: # for example, `std = "0x1"` is exported by the Standard Library. diff --git a/mover/Sy711/code/task2/faucet/sources/faucet_coin.move b/mover/Sy711/code/task2/faucet_coin/sources/faucet_coin.move similarity index 100% rename from mover/Sy711/code/task2/faucet/sources/faucet_coin.move rename to mover/Sy711/code/task2/faucet_coin/sources/faucet_coin.move diff --git a/mover/Sy711/code/task2/mycoin/Move.toml b/mover/Sy711/code/task2/mycoin/Move.toml index e77f86f6a..5f53a6b5d 100644 --- a/mover/Sy711/code/task2/mycoin/Move.toml +++ b/mover/Sy711/code/task2/mycoin/Move.toml @@ -19,7 +19,7 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram # Override = { local = "../conflicting/version", override = true } [addresses] -mycoin = "0x0" +mycoin = "0xc1c3bc0379fb47eb69add8e7ea01acd42eaa65f6bb7ac5dcf2b5faa235dbd126" # Named addresses will be accessible in Move as `@name`. They're also exported: # for example, `std = "0x1"` is exported by the Standard Library. diff --git a/mover/Sy711/code/task4/Move.lock b/mover/Sy711/code/task4/Move.lock new file mode 100644 index 000000000..639e99564 --- /dev/null +++ b/mover/Sy711/code/task4/Move.lock @@ -0,0 +1,43 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "E47161DD567159FAADB592942330014AC6B1E47DA64573087150257F6F212777" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "faucet_coin", name = "faucet_coin" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "faucet_coin" +source = { local = "..\\task2\\faucet_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.35.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x57a309dc952c878fe9016bc53cbbd546ca9736e53734fe497b17cc8dae81990c" +latest-published-id = "0x57a309dc952c878fe9016bc53cbbd546ca9736e53734fe497b17cc8dae81990c" +published-version = "1" diff --git a/mover/Sy711/code/task4/Move.toml b/mover/Sy711/code/task4/Move.toml new file mode 100644 index 000000000..654fcb3c2 --- /dev/null +++ b/mover/Sy711/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/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 + faucet_coin = { local = "../task2/faucet_coin" } + +# 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" +faucet_coin="0xb3743a94cbc755521c27fb5d91e2c8b34ea5b0df899654c20d2f965d301bb7dd" +# 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/Sy711/code/task4/sources/task4.move b/mover/Sy711/code/task4/sources/task4.move new file mode 100644 index 000000000..3c1f079f6 --- /dev/null +++ b/mover/Sy711/code/task4/sources/task4.move @@ -0,0 +1,85 @@ +module task4::task4 { + + use sui::balance::{Self,Balance, zero}; + use sui::coin::{Self}; + use sui::random::{Self,Random}; + use sui::transfer::{share_object, transfer}; + use sui::tx_context::sender; + use faucet_coin::faucet_coin::{FAUCET_COIN}; + + const EUserInsufficientBalance :u64 =1; + public struct Game has key { + id: UID, + val: Balance + } + + public struct AdaminCap has key { + id: UID + } + + + fun init(ctx: &mut TxContext) { + let game = Game { + id: object::new(ctx), + val: zero() + }; + + share_object(game); + + let admin = AdaminCap { + id: object::new(ctx) + }; + + transfer(admin, sender(ctx)); + } + #[allow(lint(public_random))] + public entry fun play( + game: &mut Game, + flip_value: bool, + in: &mut coin::Coin, + rand: &Random, + amount: u64, + ctx: &mut TxContext + ) { + let mut gen = random::new_generator(rand, ctx); + let flag = random::generate_bool(&mut gen); + + // 如果获胜 + if (flag == flip_value) { + // 投入的代币不变,另外奖励等额的代币 + let reward = coin::take(&mut game.val, amount, ctx); + coin::join(in, reward); + } + // 猜错了就损失投入的代币 + else { + Self::public_deposit(game, in, amount) + } + } + + fun deposit(game: &mut Game, in: &mut coin::Coin, amount: u64) { + let split_balance = balance::split(coin::balance_mut(in), amount); + balance::join(&mut game.val, split_balance); + assert!( + coin::value(in) >= amount, + EUserInsufficientBalance + ); + } + + public entry fun public_deposit( + game: &mut Game, + in: &mut coin::Coin, + amount: u64 + ) { + deposit(game, in, amount); + } + + public entry fun Withdraw( + game: &mut Game, + _: &AdaminCap, + amount: u64, + ctx: &mut TxContext +) { + let cash = coin::take(&mut game.val, amount, ctx); + transfer::public_transfer(cash, ctx.sender()); +} +} \ No newline at end of file diff --git a/mover/Sy711/code/task4/tests/task4_tests.move b/mover/Sy711/code/task4/tests/task4_tests.move new file mode 100644 index 000000000..178d33b9e --- /dev/null +++ b/mover/Sy711/code/task4/tests/task4_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module task4::task4_tests; +// uncomment this line to import the module +// use task4::task4; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_task4() { + // pass +} + +#[test, expected_failure(abort_code = ::task4::task4_tests::ENotImplemented)] +fun test_task4_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/Sy711/code/task5/Move.lock b/mover/Sy711/code/task5/Move.lock new file mode 100644 index 000000000..d8c721e79 --- /dev/null +++ b/mover/Sy711/code/task5/Move.lock @@ -0,0 +1,52 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "C15B387DD5009DA1FA5359768830B6C2DF0D87565D4D16CF64DDECD4FFB0924B" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "faucet_coin", name = "faucet_coin" }, + { id = "mycoin", name = "mycoin" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "faucet_coin" +source = { local = "..\\task2\\faucet_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "mycoin" +source = { local = "..\\task2\\mycoin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.35.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x440e4f33eab2cc50852e7b6467b88d038a836daeb79313954e563f29645a7062" +latest-published-id = "0x440e4f33eab2cc50852e7b6467b88d038a836daeb79313954e563f29645a7062" +published-version = "1" diff --git a/mover/Sy711/code/task5/Move.toml b/mover/Sy711/code/task5/Move.toml new file mode 100644 index 000000000..e18df86c7 --- /dev/null +++ b/mover/Sy711/code/task5/Move.toml @@ -0,0 +1,39 @@ +[package] +name = "task5" +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/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 + faucet_coin = { local = "../task2/faucet_coin" } + mycoin = { local = "../task2/mycoin" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +task5 = "0x0" +faucet_coin="0xb3743a94cbc755521c27fb5d91e2c8b34ea5b0df899654c20d2f965d301bb7dd" +mycoin="0xc1c3bc0379fb47eb69add8e7ea01acd42eaa65f6bb7ac5dcf2b5faa235dbd126" +# 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/Sy711/code/task5/sources/task5.move b/mover/Sy711/code/task5/sources/task5.move new file mode 100644 index 000000000..3f87d4545 --- /dev/null +++ b/mover/Sy711/code/task5/sources/task5.move @@ -0,0 +1,88 @@ +module task5::task5 { + use faucet_coin::faucet_coin::{FAUCET_COIN}; + use mycoin::mycoin::{MYCOIN}; + use sui::balance::{Self,Balance, zero}; + use sui::object::{Self, UID}; + use sui::transfer::{ transfer, share_object, public_transfer }; + use sui::tx_context::{Self, TxContext}; + use sui::coin::{Self, Coin}; + use sui::event; + use std::string::{Self, String}; + + + public struct LiquidityEvent has copy, drop { + provider: address, + coin_a_amount: u64, + coin_b_amount: u64, + coin_a_type: String, + coin_b_type: String, + timestamp: u64, +} + + + // 流动性池结构体 +public struct Pool has key { + id: UID, + // 代币A的余额 + coin_a: Balance, + // 代币B的余额 + coin_b: Balance, + } + fun init(ctx: &mut TxContext) { + let pool = Pool { + id: object::new(ctx), + coin_a: balance::zero(), + coin_b: balance::zero(), + }; + transfer::share_object(pool); +} + public entry fun add_liquidity( pool: &mut Pool, coin_a: Coin,coin_b:Coin,ctx: &mut TxContext){ + let a_amount = coin::value(&coin_a); + let b_amount = coin::value(&coin_b); + balance::join(&mut pool.coin_a, coin::into_balance(coin_a)); + balance::join(&mut pool.coin_b, coin::into_balance(coin_b)); + + event::emit(LiquidityEvent + { + provider:tx_context::sender(ctx), + coin_a_amount: a_amount, + coin_b_amount: b_amount, + coin_a_type: string::utf8(b"SY711_FAUCET"), + coin_b_type: string::utf8(b"SY711Coin"), + timestamp: tx_context::epoch(ctx), + }) + } +// 代币A换代币B的函数 +public entry fun swap_a_to_b( + pool: &mut Pool, + coin_a_in: Coin, + ctx: &mut TxContext +) { + let amount = coin::value(&coin_a_in); + balance::join(&mut pool.coin_a, coin::into_balance(coin_a_in)); + + let amount_end = amount * 2; + let coin_b_balance = balance::split(&mut pool.coin_b, amount_end); + let movebcoin = coin::from_balance(coin_b_balance, ctx); + public_transfer(movebcoin, ctx.sender()); +} + +// 代币B换代币A的函数 +public entry fun swap_b_to_a( + pool: &mut Pool, + coin_b_in: Coin, + ctx: &mut TxContext +) { + let amount = coin::value(&coin_b_in); + balance::join(&mut pool.coin_b, coin::into_balance(coin_b_in)); + + let amount_end = amount * 2; + let coin_a_balance = balance::split(&mut pool.coin_a, amount_end); + let moveacoin = coin::from_balance(coin_a_balance, ctx); + public_transfer(moveacoin, ctx.sender()); + +} + + + +} \ No newline at end of file diff --git a/mover/Sy711/code/task5/tests/task5_tests.move b/mover/Sy711/code/task5/tests/task5_tests.move new file mode 100644 index 000000000..006cda1f9 --- /dev/null +++ b/mover/Sy711/code/task5/tests/task5_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module task5::task5_tests; +// uncomment this line to import the module +// use task5::task5; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_task5() { + // pass +} + +#[test, expected_failure(abort_code = ::task5::task5_tests::ENotImplemented)] +fun test_task5_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/Sy711/readme.md b/mover/Sy711/readme.md index e8f324ac4..931c76a28 100644 --- a/mover/Sy711/readme.md +++ b/mover/Sy711/readme.md @@ -32,15 +32,15 @@ - []scan上的NFT截图:![Scan截图](./images/nft.png ## 04 移动游戏 -- []游戏包 ID : -- []存入 Coin 哈希: -- []提取 'Coin' 哈希: -- []Play Game Hash 进行游戏哈希: +- []游戏包 ID : 0x57a309dc952c878fe9016bc53cbbd546ca9736e53734fe497b17cc8dae81990c +- []存入 Coin 哈希:FdLs6Qgw5P89KppcWfWh3BVkc8bLP4CF69z9rUsnFMxZ +- []提取 'Coin' 哈希:8BqdF8nwyhqvaQ5ECzdy8UAjdoMdH5k394wQgpuACJxD +- []Play Game Hash 进行游戏哈希:J3E8huLFUHVa4B9R3hADU3HdPaGGD9NUNCUcGFLH1YDM ## 05 移动交换 -- []交换包 ID : -- []call swap CoinA-> CoinB 哈希值 : -- []call swap CoinB-> CoinA 哈希值 : +- []交换包 ID :0x440e4f33eab2cc50852e7b6467b88d038a836daeb79313954e563f29645a7062 +- []call swap CoinA-> CoinB 哈希值 :6vLPzu3Q14r9sWjBkCQeooAT7nkzMqLw6c7rz8oFwGVL +- []call swap CoinB-> CoinA 哈希值 :GR4vMaWfRRwhLzpwiW26h4w1ohzWH1wy7H8Y8qzJjbje ## 06 SDK PTB 开发工具包 - []保存哈希 : \ No newline at end of file