From 95a5cda59998ae083c8e7b36599c4134cc176f0e Mon Sep 17 00:00:00 2001 From: earthchen Date: Sat, 16 Nov 2024 16:17:25 +0800 Subject: [PATCH 1/4] task4 --- .../code/task4/earthchen_game/Move.lock | 43 +++++++ .../code/task4/earthchen_game/Move.toml | 38 ++++++ .../task4/earthchen_game/sources/Move.toml | 38 ++++++ .../sources/earthchen_game.move | 113 ++++++++++++++++++ 4 files changed, 232 insertions(+) create mode 100644 mover/EarthChen/code/task4/earthchen_game/Move.lock create mode 100644 mover/EarthChen/code/task4/earthchen_game/Move.toml create mode 100644 mover/EarthChen/code/task4/earthchen_game/sources/Move.toml create mode 100644 mover/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move diff --git a/mover/EarthChen/code/task4/earthchen_game/Move.lock b/mover/EarthChen/code/task4/earthchen_game/Move.lock new file mode 100644 index 000000000..68b065eec --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/Move.lock @@ -0,0 +1,43 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "3E7C99C33A2E20F63FB3D0534558440BAC3F2A5097CA4C5801FAED92F94005EE" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "faucetcoin", name = "faucetcoin" }, +] + +[[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 = "faucetcoin" +source = { local = "../../task2/faucetcoin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.37.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" +latest-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" +published-version = "1" diff --git a/mover/EarthChen/code/task4/earthchen_game/Move.toml b/mover/EarthChen/code/task4/earthchen_game/Move.toml new file mode 100644 index 000000000..d22f36f90 --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "guess_number" +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" } +faucetcoin = { local = "../../task2/faucetcoin" } + +# 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] +guess_number = "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/EarthChen/code/task4/earthchen_game/sources/Move.toml b/mover/EarthChen/code/task4/earthchen_game/sources/Move.toml new file mode 100644 index 000000000..4ad983435 --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/sources/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "guess_number" +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" } +faucetcoin = { local = "../faucetcoin" } + +# 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] +guess_number = "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/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move b/mover/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move new file mode 100644 index 000000000..7c539bc8e --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move @@ -0,0 +1,113 @@ +/// Module: guess_number +module guess_number::guess_number { + use sui::object::{Self, UID}; + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::transfer::{transfer, share_object, public_transfer}; + use sui::tx_context::{Self, sender}; + use sui::bcs; + use faucetcoin::faucetcoin::FAUCETCOIN; + use std::debug::print; + use std::string::utf8; + + const ENotAllow: u64 = 0; + const EInvalidStake: u64 = 1; + const Rate: u64 = 2; + const MaxStake: u64 = 1000; + const MinStake: u64 = 10; + + // otw + public struct GUESS_NUMBER has drop {} + + // 奖金池,管理员为earthchen + public struct PrizePool has key { + id: UID, + prize: Balance, + earthchen: address // my github id + } + + // 用于创建、初始化奖金池,之后删除 + public struct PrizePoolCap has key { + id: UID + } + + // 创建Cap,并发送给earthchen + fun init(_otw: GUESS_NUMBER, ctx: &mut TxContext) { + let prize_pool_cap = PrizePoolCap { + id: object::new(ctx) + }; + transfer(prize_pool_cap, tx_context::sender(ctx)); + } + + // earthchen用于创建奖金池,并注入初始奖金 + public entry fun initialize_pool(cap: PrizePoolCap, coin: Coin, ctx: &mut TxContext) { + let prize_pool = PrizePool { + id: object::new(ctx), + prize: coin.into_balance(), + earthchen: sender(ctx) + }; + share_object(prize_pool); + let PrizePoolCap { id } = cap; + object::delete(id); + } + + + + // 给奖金池注入更多奖金,任何人都有权限 + public entry fun top_up(pool: &mut PrizePool, coin: Coin) { + coin::put(&mut pool.prize, coin) + } + + // 在奖金池取出指定数量金额 + public entry fun withdraw(pool: &mut PrizePool, amount: u64, ctx: &mut TxContext) { + assert!(pool.earthchen == sender(ctx), ENotAllow); + let balance = pool.prize.split(amount); + let coin = coin::from_balance(balance, ctx); + public_transfer(coin, sender(ctx)); + } + + // 在奖金池取出所有奖金 + public fun withdraw_all(pool: &mut PrizePool, ctx: &mut TxContext) { + assert!(pool.earthchen == sender(ctx), ENotAllow); + let balance = pool.prize.withdraw_all(); + let coin = coin::from_balance(balance, ctx); + public_transfer(coin, sender(ctx)); + } + + // 查询奖金池中剩余的金额 + public fun query_prize(pool: &mut PrizePool):u64 { + pool.prize.value() + } + + // 通过交易hash的方式获取随机数 + fun get_random_num(ctx: &mut TxContext): u8 { + let tx_digest = tx_context::digest(ctx); + let tx_digest_u64= bcs::peel_u8(&mut bcs::new(*tx_digest)); + let random_index: u8 = tx_digest_u64 % 3; + random_index + } + + // 开始游戏 + public entry fun start_game(pool: &mut PrizePool, geuss_number: u8, stake: Coin, ctx: &mut TxContext): bool { + let balance = stake.into_balance(); + let value = balance.value(); + let mut res = false; + assert!(value < MaxStake && value > MinStake, EInvalidStake); + pool.prize.join(balance); + let the_number = get_random_num(ctx); + print(&utf8(b"The right number is:")); + print(&the_number); + if (geuss_number == the_number) { + let prize_value = pool.prize.split(Rate * value); + let prize_coin = coin::from_balance(prize_value, ctx); + public_transfer(prize_coin, sender(ctx)); + res = true; + }; + res + } + + #[test_only] + public fun init_for_testing(ctx: &mut TxContext) { + init(GUESS_NUMBER {}, ctx); + } +} From 85a0a5ff5a172c336e5554c7f400386fb17d6705 Mon Sep 17 00:00:00 2001 From: earthchen Date: Sat, 16 Nov 2024 16:18:46 +0800 Subject: [PATCH 2/4] task4 --- mover/EarthChen/code/readme.md | 7 +++++++ mover/EarthChen/code/task2/faucetcoin/Move.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mover/EarthChen/code/readme.md b/mover/EarthChen/code/readme.md index e69de29bb..c174e843b 100644 --- a/mover/EarthChen/code/readme.md +++ b/mover/EarthChen/code/readme.md @@ -0,0 +1,7 @@ +# 猜数游戏信息 + +## testnet + +* packageId: 0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd +* UpgradeCapID:0x3eea017ced2d484f0593b9b7a4bd7fd9da5504177cebccb7581ec18f39b99271 +* guess_number::PrizePoolCap: 0xc362a9db9ecfbe3fa4043dd00be11c1c0e52158554ff457c83d472ae6d49acd6 diff --git a/mover/EarthChen/code/task2/faucetcoin/Move.toml b/mover/EarthChen/code/task2/faucetcoin/Move.toml index e91d0de23..380370c8a 100644 --- a/mover/EarthChen/code/task2/faucetcoin/Move.toml +++ b/mover/EarthChen/code/task2/faucetcoin/Move.toml @@ -5,7 +5,7 @@ edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move # 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" } +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. From 2a590e6e4cf77ae8c8590cb0caf5907d2b9a7959 Mon Sep 17 00:00:00 2001 From: earthchen Date: Sat, 16 Nov 2024 17:25:08 +0800 Subject: [PATCH 3/4] task4 --- mover/EarthChen/code/readme.md | 20 +++++++++++++++++++ .../EarthChen/code/task2/faucetcoin/Move.lock | 12 +++++------ .../code/task4/earthchen_game/Move.lock | 6 ++++++ mover/EarthChen/readme.md | 8 ++++---- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/mover/EarthChen/code/readme.md b/mover/EarthChen/code/readme.md index c174e843b..42e5d05a0 100644 --- a/mover/EarthChen/code/readme.md +++ b/mover/EarthChen/code/readme.md @@ -5,3 +5,23 @@ * packageId: 0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd * UpgradeCapID:0x3eea017ced2d484f0593b9b7a4bd7fd9da5504177cebccb7581ec18f39b99271 * guess_number::PrizePoolCap: 0xc362a9db9ecfbe3fa4043dd00be11c1c0e52158554ff457c83d472ae6d49acd6 + + +### faucetcoin + +* pacakgeId: 0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf +* coin: 0x27b93ff04870aa99ce50ca35694fb66d5678629088cacefaa78c6d7d5f20763a + + +## mainnet + +* publish hash: BJT1Dga7cHKK6B5KKPq2JQe1RBzwcaUH3nsRZddMxPmQ +* packageId:0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee +* UpgradeCapID:0x05d90f14cd51264d703c84c837e7febb4f556e16cd0306f8646f265f0352a4ea +* guess_number::PrizePoolCap:0xf88111d290581033164f4222c2cc8f827594b8431406bf1e378f64b138bd72d3 +* inithash: HRaT2c1UsoXfAz5y9EhWLuhMuhqkWn3zzP8gZv5THatj +* poolId: 0x7dddecadd6f32cd78e5897991f12632ac02d9cbe9315835b5406e29c01b45b5f + + + + diff --git a/mover/EarthChen/code/task2/faucetcoin/Move.lock b/mover/EarthChen/code/task2/faucetcoin/Move.lock index 82d2037ad..52de34a46 100644 --- a/mover/EarthChen/code/task2/faucetcoin/Move.lock +++ b/mover/EarthChen/code/task2/faucetcoin/Move.lock @@ -2,7 +2,7 @@ [move] version = 3 -manifest_digest = "040FB3E59D8A1F2E682DCABB7B08CE36CD1FC73BDE7213AB39F548FED3A290C9" +manifest_digest = "36AAF1CDEC036D88764BAC3DCDE58C0D7D361D80DBC1ED0F543FFC7DC8AA1BA6" deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" dependencies = [ { id = "Sui", name = "Sui" }, @@ -10,18 +10,18 @@ dependencies = [ [[move.package]] id = "MoveStdlib" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } +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/mainnet", subdir = "crates/sui-framework/packages/sui-framework" } +source = { git = "https://github.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.37.1" +compiler-version = "1.37.3" edition = "2024.beta" flavor = "sui" @@ -29,8 +29,8 @@ flavor = "sui" [env.testnet] chain-id = "4c78adac" -original-published-id = "0x586cd3af1a22322f864d4f97aeb94287918e4e8cfe5f82906419ecef0e2df04a" -latest-published-id = "0x586cd3af1a22322f864d4f97aeb94287918e4e8cfe5f82906419ecef0e2df04a" +original-published-id = "0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf" +latest-published-id = "0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf" published-version = "1" [env.mainnet] diff --git a/mover/EarthChen/code/task4/earthchen_game/Move.lock b/mover/EarthChen/code/task4/earthchen_game/Move.lock index 68b065eec..7be1da240 100644 --- a/mover/EarthChen/code/task4/earthchen_game/Move.lock +++ b/mover/EarthChen/code/task4/earthchen_game/Move.lock @@ -41,3 +41,9 @@ chain-id = "4c78adac" original-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" latest-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" published-version = "1" + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee" +latest-published-id = "0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee" +published-version = "1" diff --git a/mover/EarthChen/readme.md b/mover/EarthChen/readme.md index dc3209d4f..2ebab3b63 100644 --- a/mover/EarthChen/readme.md +++ b/mover/EarthChen/readme.md @@ -32,10 +32,10 @@ - [x] scan上的NFT截图:![Scan截图](./images/nft_scan.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [x] game package id :0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee +- [x] deposit Coin hash: 8VXsjH2eVz1TWAc5DkAWrtPYVNoArEgVJZq8tCxnNscc +- [x] withdraw `Coin` hash: HizGTtY5FGAGuEQ3g9idAyFuP5BMh8dnH1hSKsTV9ZD8 +- [x] play game hash: AjYKT5oKewnDWv9fnDvYRvoeRDBzfGuYGmPSMXGpv2cY ## 05 Move Swap - [] swap package id : From 8c38b15f7f0a09cea059762614869fc6885bad5d Mon Sep 17 00:00:00 2001 From: earthchen Date: Mon, 18 Nov 2024 18:18:54 +0800 Subject: [PATCH 4/4] task5 --- mover/EarthChen/code/readme.md | 20 ++++- .../EarthChen/code/task2/faucetcoin/Move.toml | 2 +- .../EarthChen/code/task5/earthchen/Move.lock | 58 ++++++++++++++ .../EarthChen/code/task5/earthchen/Move.toml | 39 +++++++++ .../task5/earthchen/sources/earthchen.move | 80 +++++++++++++++++++ mover/EarthChen/readme.md | 6 +- 6 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 mover/EarthChen/code/task5/earthchen/Move.lock create mode 100644 mover/EarthChen/code/task5/earthchen/Move.toml create mode 100644 mover/EarthChen/code/task5/earthchen/sources/earthchen.move diff --git a/mover/EarthChen/code/readme.md b/mover/EarthChen/code/readme.md index 42e5d05a0..a882ab1ff 100644 --- a/mover/EarthChen/code/readme.md +++ b/mover/EarthChen/code/readme.md @@ -1,4 +1,4 @@ -# 猜数游戏信息 +# task4 猜数游戏信息 ## testnet @@ -10,6 +10,7 @@ ### faucetcoin * pacakgeId: 0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf +* 0x2::package::UpgradeCap: 0x1443e8d5e94f7080ae73e0c2b1c9907b3d16df740d98e361b5264f7325535b62 * coin: 0x27b93ff04870aa99ce50ca35694fb66d5678629088cacefaa78c6d7d5f20763a @@ -24,4 +25,21 @@ +# task5 bank +## testnet + +* packageId: 0xdd4c3f39b2446f596a0abb7c764266b43719adc4f4b8a9c488b81d096a8663c4 +* earthchen::Bank : 0x1965c930d133fc49dcdc1ac55b6b18a8ac5b782125796d94902ddbc52216f64a +* amdin: 0x15c02c340a6948e80fb74723a9c15af3192cbf4651dc603c879dbd7a9656d1dc +* deposit_mycoin hash: 8SPPuNUjoorqYQa4xo5P3jFYakjFFtky1EDyLFC8B33p +* deposit_faucetcoin hash: APpff8GhwNfd2Z494frcaLoDPuWNFkFfYFsPPgCqrtsD +* swap_mycoin hash: 3vLWRgDJMefi4449HS9KSjQS5PQwKjQmpLzdeZWHgBbX + + +## mainnet + +* packageId: 0x6d4dd7fffe36cce18887a19a935df4cd45633546c947756ce7d45d1fbca9766e +* bank: 0x0a307a8b9d0a97d911973ad395cdeb9e9e213b2370087e33dea48bee16b7e149 +* deposit_mycoin hash:C1MnhbfeTsnwdNRjf1jmaAcLRW71K6LDCb12LAk8GmMa +* swap_ diff --git a/mover/EarthChen/code/task2/faucetcoin/Move.toml b/mover/EarthChen/code/task2/faucetcoin/Move.toml index 380370c8a..e91d0de23 100644 --- a/mover/EarthChen/code/task2/faucetcoin/Move.toml +++ b/mover/EarthChen/code/task2/faucetcoin/Move.toml @@ -5,7 +5,7 @@ edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move # 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" } +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. diff --git a/mover/EarthChen/code/task5/earthchen/Move.lock b/mover/EarthChen/code/task5/earthchen/Move.lock new file mode 100644 index 000000000..d872c60c0 --- /dev/null +++ b/mover/EarthChen/code/task5/earthchen/Move.lock @@ -0,0 +1,58 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "BD917155367008DF694FFC9BE7067220688091408D96879871417DE548347128" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "faucetcoin", name = "faucetcoin" }, + { id = "mycoin", name = "mycoin" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "faucetcoin" +source = { local = "../../task2/faucetcoin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "mycoin" +source = { local = "../../task2/mycoin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.37.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0xdd4c3f39b2446f596a0abb7c764266b43719adc4f4b8a9c488b81d096a8663c4" +latest-published-id = "0xdd4c3f39b2446f596a0abb7c764266b43719adc4f4b8a9c488b81d096a8663c4" +published-version = "1" + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x6d4dd7fffe36cce18887a19a935df4cd45633546c947756ce7d45d1fbca9766e" +latest-published-id = "0x6d4dd7fffe36cce18887a19a935df4cd45633546c947756ce7d45d1fbca9766e" +published-version = "1" diff --git a/mover/EarthChen/code/task5/earthchen/Move.toml b/mover/EarthChen/code/task5/earthchen/Move.toml new file mode 100644 index 000000000..ed80fe515 --- /dev/null +++ b/mover/EarthChen/code/task5/earthchen/Move.toml @@ -0,0 +1,39 @@ +[package] +name = "earhchen" +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" } +faucetcoin = { local = "../../task2/faucetcoin" } +mycoin = { local = "../../task2/mycoin" } + +# 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] +earthchen = "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/EarthChen/code/task5/earthchen/sources/earthchen.move b/mover/EarthChen/code/task5/earthchen/sources/earthchen.move new file mode 100644 index 000000000..e69d0282a --- /dev/null +++ b/mover/EarthChen/code/task5/earthchen/sources/earthchen.move @@ -0,0 +1,80 @@ +/// Module: earthchen +module earthchen::earthchen { + use sui::coin::{Self, Coin}; + use sui::balance::{Self, Balance}; + use sui::transfer::{Self, transfer, share_object, public_transfer}; + use mycoin::mycoin::MYCOIN; + use faucetcoin::faucetcoin::FAUCETCOIN; + use sui::tx_context::sender; + + public struct Bank has key { + id: UID, + mycoin: Balance, + faucetcoin: Balance, + mc_prop: u64, + fc_prop: u64 + } + + public struct AdaminCap has key { + id: UID + } + + fun init(ctx: &mut TxContext) { + let bank = Bank { + id: object::new(ctx), + mycoin: balance::zero(), + faucetcoin: balance::zero(), + mc_prop: 1000, // mc : fc = mc_prop : fc_prop + fc_prop: 7300 + }; + share_object(bank); + let adamin_cap = AdaminCap { + id: object::new(ctx) + }; + transfer(adamin_cap, sender(ctx)); + } + + public entry fun deposit_mycoin(bank: &mut Bank, mycoin: Coin, _ctx: &mut TxContext) { + let balance = coin::into_balance(mycoin); + bank.mycoin.join(balance); + } + + public entry fun deposit_faucetcoin(bank: &mut Bank, faucetcoin: Coin, _ctx: &mut TxContext) { + let balance = coin::into_balance(faucetcoin); + bank.faucetcoin.join(balance); + } + + public entry fun withdraw_mycoin(_: &AdaminCap, bank: &mut Bank, amount: u64, ctx: &mut TxContext) { + let amount = bank.mycoin.split(amount); + let mycoin = coin::from_balance(amount, ctx); + public_transfer(mycoin, sender(ctx)); + } + + public entry fun withdraw_faucetcoin(_: &AdaminCap, bank: &mut Bank, amount: u64, ctx: &mut TxContext) { + let amount = bank.mycoin.split(amount); + let mycoin = coin::from_balance(amount, ctx); + public_transfer(mycoin, sender(ctx)); + } + + public entry fun swap_mycoin(bank: &mut Bank, faucetcoin: Coin, ctx: &mut TxContext) { + let fc_balance = faucetcoin.into_balance(); + let fc_amt = fc_balance.value(); + let mc_amt = bank.mycoin.split(fc_amt * bank.mc_prop / bank.fc_prop); + bank.faucetcoin.join(fc_balance); + public_transfer(coin::from_balance(mc_amt, ctx), sender(ctx)); + } + + public entry fun swap_faucetcoin(bank: &mut Bank, mycoin: Coin, ctx: &mut TxContext) { + let mc_balance = mycoin.into_balance(); + let mc_amt = mc_balance.value(); + let fc_amt = bank.faucetcoin.split(mc_amt * bank.fc_prop / bank.mc_prop); + bank.mycoin.join(mc_balance); + public_transfer(coin::from_balance(fc_amt, ctx), sender(ctx)); + } + + #[test_only] + public fun init_for_testing(ctx: &mut TxContext) { + init(ctx); + } +} + diff --git a/mover/EarthChen/readme.md b/mover/EarthChen/readme.md index 2ebab3b63..9966f9bd2 100644 --- a/mover/EarthChen/readme.md +++ b/mover/EarthChen/readme.md @@ -38,9 +38,9 @@ - [x] play game hash: AjYKT5oKewnDWv9fnDvYRvoeRDBzfGuYGmPSMXGpv2cY ## 05 Move Swap -- [] swap package id : -- [] call swap CoinA-> CoinB hash : -- [] call swap CoinB-> CoinA hash : +- [x] swap package id :0x6d4dd7fffe36cce18887a19a935df4cd45633546c947756ce7d45d1fbca9766e +- [x] call swap CoinA-> CoinB hash :DXUJPhgKCNc8oMdq9gNQxRvzKPhWrZHbEwpa9bEc72S8 +- [x] call swap CoinB-> CoinA hash :8u7wjB5V3FnE4kBXF6Y1CcCpc7XPZ5o6zN9r3oQvwfs2 ## 06 Dapp-kit SDK PTB - [] save hash :