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 :