From 36cf31796a4972af5915662b89636a835d845194 Mon Sep 17 00:00:00 2001 From: wanghaonan Date: Thu, 5 Dec 2024 22:59:28 +0800 Subject: [PATCH 1/2] feat: task4 --- .../code/task2/whn_coin_facuet/Move.toml | 2 +- mover/PebblerWon/code/task4/game/Move.lock | 43 +++++++++++ mover/PebblerWon/code/task4/game/Move.toml | 40 +++++++++++ mover/PebblerWon/code/task4/game/call.sh | 40 +++++++++++ .../code/task4/game/sources/game.move | 55 ++++++++++++++ .../code/task4/game/sources/game_demo.move.ee | 72 +++++++++++++++++++ .../code/task4/game/tests/game_tests.move | 18 +++++ mover/PebblerWon/readme.md | 8 +-- 8 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 mover/PebblerWon/code/task4/game/Move.lock create mode 100644 mover/PebblerWon/code/task4/game/Move.toml create mode 100644 mover/PebblerWon/code/task4/game/call.sh create mode 100644 mover/PebblerWon/code/task4/game/sources/game.move create mode 100644 mover/PebblerWon/code/task4/game/sources/game_demo.move.ee create mode 100644 mover/PebblerWon/code/task4/game/tests/game_tests.move diff --git a/mover/PebblerWon/code/task2/whn_coin_facuet/Move.toml b/mover/PebblerWon/code/task2/whn_coin_facuet/Move.toml index abe119064..72f1443c2 100644 --- a/mover/PebblerWon/code/task2/whn_coin_facuet/Move.toml +++ b/mover/PebblerWon/code/task2/whn_coin_facuet/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] -whn_coin_facuet = "0x0" +whn_coin_facuet = "0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2" # 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/PebblerWon/code/task4/game/Move.lock b/mover/PebblerWon/code/task4/game/Move.lock new file mode 100644 index 000000000..10898d1fe --- /dev/null +++ b/mover/PebblerWon/code/task4/game/Move.lock @@ -0,0 +1,43 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "D23D9D30DA3F2FAC99EBC0898D66C4E2CC5C99CA29FF3A14A90F27C317261014" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "whn_coin_facuet", name = "whn_coin_facuet" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "whn_coin_facuet" +source = { local = "../../task2/whn_coin_facuet" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.37.1" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2" +latest-published-id = "0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2" +published-version = "1" diff --git a/mover/PebblerWon/code/task4/game/Move.toml b/mover/PebblerWon/code/task4/game/Move.toml new file mode 100644 index 000000000..c0c888600 --- /dev/null +++ b/mover/PebblerWon/code/task4/game/Move.toml @@ -0,0 +1,40 @@ +[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] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" } +whn_coin_facuet = { local = "../../task2/whn_coin_facuet"} + +# 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" +whn_coin_facuet = "0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2" + + +# 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/PebblerWon/code/task4/game/call.sh b/mover/PebblerWon/code/task4/game/call.sh new file mode 100644 index 000000000..e21b3a5b8 --- /dev/null +++ b/mover/PebblerWon/code/task4/game/call.sh @@ -0,0 +1,40 @@ +# testnet +# packageid: 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 +# gameObjectId: 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 +# whn_coin balance id: 0x070458113803a01856502677ba38bce5d9eb6f4ed36667af73e24974b8dfea83 +# gameGap object id: 0x677a1efe9f91c0bf4f11dcf7c2983fecc841e1dfec0c7f70b5867b74ec26f14b + +## add_sui +sui client call \ + --package 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 \ + --module game \ + --function add_sui \ + --args 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 0x05c0d8dfd7240318cb83aa30c661a829beaabc210e133fe226176d0291bd5904 \ + --gas-budget 10000000 + +## facuet +sui client call \ + --package 0x2 \ + --module coin \ + --function mint_and_transfer \ + --type-args '0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2::whn_coin::WHN_COIN' \ + --args 0x19e69a05953b0e065ebcd6a9705db902c21ac97f2bc14eb364ea79a889978d0c 10000 0x09be6b8995b7f56d8491a67f54519c56059d3fc24124470366b7ee5b51c27a91 + +## balance object id 0x05c0d8dfd7240318cb83aa30c661a829beaabc210e133fe226176d0291bd5904 + + +## play +sui client call \ + --package 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 \ + --module game \ + --function play \ + --args 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 true 0x05c0d8dfd7240318cb83aa30c661a829beaabc210e133fe226176d0291bd5904 0x8\ + --gas-budget 10000000 + +## withdraw +sui client call \ + --package 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 \ + --module game \ + --function withdraw \ + --args 0x677a1efe9f91c0bf4f11dcf7c2983fecc841e1dfec0c7f70b5867b74ec26f14b 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 8\ + --gas-budget 10000000 \ No newline at end of file diff --git a/mover/PebblerWon/code/task4/game/sources/game.move b/mover/PebblerWon/code/task4/game/sources/game.move new file mode 100644 index 000000000..a32723b2b --- /dev/null +++ b/mover/PebblerWon/code/task4/game/sources/game.move @@ -0,0 +1,55 @@ +module game::game; +use sui::balance::{Balance,zero}; +use sui::coin::{Coin, from_balance, into_balance}; +use sui::random; +use whn_coin_facuet::whn_coin::WHN_COIN; + +public struct Game has key{ + id: UID, + balance: Balance, + reward_rate: u64, +} +public struct GameCap has key { + id: UID, + +} +fun init(ctx: &mut TxContext){ + let game = Game{ + id:object::new(ctx), + balance: zero(), + reward_rate:1, + }; + let cap = GameCap{ + id:object::new(ctx) + }; + transfer::share_object(game); + transfer::transfer(cap, ctx.sender()); +} + +public entry fun play(game: &mut Game, flip_value:bool,in: Coin, rand:&random::Random,ctx:&mut TxContext){ + let in_balance_v = in.value(); + assert!(in_balance_v>0 && game.balance.value()>=in_balance_v * game.reward_rate,0x100); + + let mut gen = random::new_generator(rand, ctx); + + let b = gen.generate_bool(); + if(b==flip_value){ + let reward = in_balance_v*game.reward_rate; + let b = game.balance.split(reward); + let coin = from_balance(b, ctx); + transfer::public_transfer(coin, ctx.sender()); + transfer::public_transfer(in, ctx.sender()); + + }else{ + game.balance.join(into_balance(in)); + } +} + +public entry fun add_sui(game:&mut Game,in:Coin,_ctx:&mut TxContext){ + game.balance.join(into_balance(in)); +} +public entry fun withdraw(_: &GameCap, game: &mut Game,amount: u64, ctx: &mut TxContext){ + let b = game.balance.split(amount); + let coin = from_balance(b, ctx); + transfer::public_transfer(coin, ctx.sender()); +} diff --git a/mover/PebblerWon/code/task4/game/sources/game_demo.move.ee b/mover/PebblerWon/code/task4/game/sources/game_demo.move.ee new file mode 100644 index 000000000..bff157629 --- /dev/null +++ b/mover/PebblerWon/code/task4/game/sources/game_demo.move.ee @@ -0,0 +1,72 @@ +/// Module: game +module game::game; + +use sui::balance::Balance; +use sui::balance; +use sui::random; +use sui::coin::{Coin, from_balance, into_balance}; +use faucet_coin::faucetcoin::FAUCETCOIN; + +public struct Game has key { + id: UID, + balance: Balance, + reward_rate: u64, +} + +public struct GameCap has key { + id: UID, +} + +fun init(ctx: &mut TxContext) { + let game = Game { + id: object::new(ctx), + balance: balance::zero(), + reward_rate: 1, + }; + + let cap = GameCap { + id: object::new(ctx), + }; + + transfer::share_object(game); + transfer::transfer(cap, ctx.sender()); +} + +#[allow(lint(public_random))] +public entry fun play(game: &mut Game, flip_value: bool, in: Coin, + rand: &random::Random, ctx: &mut TxContext) { + let in_balance_v = in.value(); + assert!(in_balance_v > 0 && game.balance.value() >= in_balance_v * game.reward_rate, 100); + + let mut gen = random::new_generator(rand, ctx); + let b = gen.generate_bool(); + if (b == flip_value) { + let reward = in_balance_v * game.reward_rate; + let b = game.balance.split(reward); + let coin = from_balance(b, ctx); + transfer::public_transfer(coin, ctx.sender()); + transfer::public_transfer(in, ctx.sender()); + } else { + game.balance.join(into_balance(in)); + } +} + +public entry fun add_sui(game: &mut Game, in: Coin, _ctx: &mut TxContext) { + game.balance.join(into_balance(in)); +} + +public entry fun withdraw(_: &GameCap, game: &mut Game, amount: u64, ctx: &mut TxContext) { + let b = game.balance.split(amount); + let coin = from_balance(b, ctx); + transfer::public_transfer(coin, ctx.sender()) +} + +#[test_only] +public fun test_init(ctx: &mut TxContext) { + init(ctx); +} + +#[test_only] +public fun balance(game: &Game): u64 { + game.balance.value() +} \ No newline at end of file diff --git a/mover/PebblerWon/code/task4/game/tests/game_tests.move b/mover/PebblerWon/code/task4/game/tests/game_tests.move new file mode 100644 index 000000000..9470e9c04 --- /dev/null +++ b/mover/PebblerWon/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/PebblerWon/readme.md b/mover/PebblerWon/readme.md index e4a79f782..e090e1c68 100644 --- a/mover/PebblerWon/readme.md +++ b/mover/PebblerWon/readme.md @@ -32,10 +32,10 @@ - [✓] scan上的NFT截图:![Scan截图](./images/task3.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [✓] game package id :0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 +- [✓] deposit Coin hash: BE6CUsVXm3ygccVkojsyn7uCV1RaRX2T9dfxTUaW8iB6 +- [✓] withdraw `Coin` hash: DPme4ptDfqrN8Bf1TK2kFukFfYvo1dTSkjGUYADWWMSr +- [✓] play game hash: 3P4qvRqmuQp1i62aae1b7nWoq4v9XvUfuvc9NR3eihDg ## 05 Move Swap - [] swap package id : From 21a26f927930d66e82aceed267b428a084121479 Mon Sep 17 00:00:00 2001 From: wanghaonan Date: Sat, 7 Dec 2024 20:42:22 +0800 Subject: [PATCH 2/2] feat: task5 swap --- .../PebblerWon/code/task2/whn_coin/Move.toml | 8 +- mover/PebblerWon/code/task2/whn_coin/call.sh | 4 +- .../code/task2/whn_coin_facuet/Move.toml | 8 +- .../code/task2/whn_coin_facuet/call.sh | 1 + .../code/task5/pebblerwon/Move.lock | 58 ++++++++++++ .../code/task5/pebblerwon/Move.toml | 46 +++++++++ .../code/task5/pebblerwon/call.mainnet.sh | 64 +++++++++++++ .../code/task5/pebblerwon/call.testnet.sh | 63 +++++++++++++ .../task5/pebblerwon/sources/demo.move.ddd | 93 +++++++++++++++++++ .../task5/pebblerwon/sources/pebblerwon.move | 78 ++++++++++++++++ .../pebblerwon/tests/pebblerwon_tests.move | 18 ++++ mover/PebblerWon/readme.md | 6 +- 12 files changed, 438 insertions(+), 9 deletions(-) create mode 100644 mover/PebblerWon/code/task5/pebblerwon/Move.lock create mode 100644 mover/PebblerWon/code/task5/pebblerwon/Move.toml create mode 100644 mover/PebblerWon/code/task5/pebblerwon/call.mainnet.sh create mode 100644 mover/PebblerWon/code/task5/pebblerwon/call.testnet.sh create mode 100644 mover/PebblerWon/code/task5/pebblerwon/sources/demo.move.ddd create mode 100644 mover/PebblerWon/code/task5/pebblerwon/sources/pebblerwon.move create mode 100644 mover/PebblerWon/code/task5/pebblerwon/tests/pebblerwon_tests.move diff --git a/mover/PebblerWon/code/task2/whn_coin/Move.toml b/mover/PebblerWon/code/task2/whn_coin/Move.toml index b0100b0ce..6dffa3f66 100644 --- a/mover/PebblerWon/code/task2/whn_coin/Move.toml +++ b/mover/PebblerWon/code/task2/whn_coin/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 = "mainnet" } +Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" } # For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. # Revision can be a branch, a tag, and a commit hash. @@ -19,7 +19,11 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram # Override = { local = "../conflicting/version", override = true } [addresses] -whn_coin = "0x0" +# testnet +# whn_coin = "0x5bedaf1084a9f6a7c98a205ca56550c75bb13376cc34c07fc3c5bddc6b17d813" + +# mainnet +whn_coin = "0xd12d0dbe5c01f8ec8aff8b62d440b3b5c7ef9330e55878c3ee30381694ba57ef" # 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/PebblerWon/code/task2/whn_coin/call.sh b/mover/PebblerWon/code/task2/whn_coin/call.sh index ce1da15c6..4995fdd2e 100644 --- a/mover/PebblerWon/code/task2/whn_coin/call.sh +++ b/mover/PebblerWon/code/task2/whn_coin/call.sh @@ -7,8 +7,8 @@ --package 0x2 \ --module coin \ --function mint_and_transfer \ - --type-args '0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2::whn_coin::WHN_COIN' \ - --args 0x19e69a05953b0e065ebcd6a9705db902c21ac97f2bc14eb364ea79a889978d0c 10000 0x60364db3c6fa7128433ad62ce4e32649443a999ab6b54bdcbaf14194ec1a6203 + --type-args '0x5bedaf1084a9f6a7c98a205ca56550c75bb13376cc34c07fc3c5bddc6b17d813::whn_coin::WHN_COIN' \ + --args 0xbbe765228d36c58cbdfa1cd3ab90ac11ba280866fd5dbe3e1cad15f5571f5316 10000 0x09be6b8995b7f56d8491a67f54519c56059d3fc24124470366b7ee5b51c27a91 ## mainnet diff --git a/mover/PebblerWon/code/task2/whn_coin_facuet/Move.toml b/mover/PebblerWon/code/task2/whn_coin_facuet/Move.toml index 72f1443c2..6dcd02b84 100644 --- a/mover/PebblerWon/code/task2/whn_coin_facuet/Move.toml +++ b/mover/PebblerWon/code/task2/whn_coin_facuet/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 = "mainnet" } +Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" } # For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. # Revision can be a branch, a tag, and a commit hash. @@ -19,7 +19,11 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram # Override = { local = "../conflicting/version", override = true } [addresses] -whn_coin_facuet = "0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2" +# testnet +# whn_coin_facuet = "0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2" + +# mainnet +whn_coin_facuet = "0x498edfc9e864d78d244315e514569ae842cb26c14cea75acb55224f74e933bbd" # 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/PebblerWon/code/task2/whn_coin_facuet/call.sh b/mover/PebblerWon/code/task2/whn_coin_facuet/call.sh index 02600fb6d..b49d7b4e2 100644 --- a/mover/PebblerWon/code/task2/whn_coin_facuet/call.sh +++ b/mover/PebblerWon/code/task2/whn_coin_facuet/call.sh @@ -2,6 +2,7 @@ # --type-args 是我们自己合约的package id # --args 第一个参数是treasurycpa的object id +# testnet package id: 0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2 ## mainnet facuet address 1 sui client call \ --package 0x2 \ diff --git a/mover/PebblerWon/code/task5/pebblerwon/Move.lock b/mover/PebblerWon/code/task5/pebblerwon/Move.lock new file mode 100644 index 000000000..5d9279e9c --- /dev/null +++ b/mover/PebblerWon/code/task5/pebblerwon/Move.lock @@ -0,0 +1,58 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "D44E4A89CE616D7078615B368C1E985CD16409C6A9FBBB40826D9456F276DCF3" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "whn_coin", name = "whn_coin" }, + { id = "whn_coin_facuet", name = "whn_coin_facuet" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[[move.package]] +id = "whn_coin" +source = { local = "../../task2/whn_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "whn_coin_facuet" +source = { local = "../../task2/whn_coin_facuet" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.37.1" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5" +latest-published-id = "0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5" +published-version = "1" + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296" +latest-published-id = "0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296" +published-version = "1" diff --git a/mover/PebblerWon/code/task5/pebblerwon/Move.toml b/mover/PebblerWon/code/task5/pebblerwon/Move.toml new file mode 100644 index 000000000..e88f7027c --- /dev/null +++ b/mover/PebblerWon/code/task5/pebblerwon/Move.toml @@ -0,0 +1,46 @@ +[package] +name = "pebblerwon" +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 = "mainnet" } +whn_coin_facuet = { local = "../../task2/whn_coin_facuet"} +whn_coin = { local = "../../task2/whn_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] +pebblerwon = "0x0" + +# testnet addresses +#whn_coin_facuet="0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2" +#whn_coin="0x5bedaf1084a9f6a7c98a205ca56550c75bb13376cc34c07fc3c5bddc6b17d813" + +# mainnet addresses +whn_coin_facuet="0x498edfc9e864d78d244315e514569ae842cb26c14cea75acb55224f74e933bbd" +whn_coin="0xd12d0dbe5c01f8ec8aff8b62d440b3b5c7ef9330e55878c3ee30381694ba57ef" + +# 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/PebblerWon/code/task5/pebblerwon/call.mainnet.sh b/mover/PebblerWon/code/task5/pebblerwon/call.mainnet.sh new file mode 100644 index 000000000..86c6eba34 --- /dev/null +++ b/mover/PebblerWon/code/task5/pebblerwon/call.mainnet.sh @@ -0,0 +1,64 @@ +# mainnet +# pebblerwon packageid: 0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296 + +# client addresses 0x60364db3c6fa7128433ad62ce4e32649443a999ab6b54bdcbaf14194ec1a6203 +# bank id: 0x13e40067a462367a1a0d04504052f18cf1d7a53b2e337d2f90cbfba70dda755f + +## mint whn + sui client call \ + --package 0x2 \ + --module coin \ + --function mint_and_transfer \ + --type-args '0xd12d0dbe5c01f8ec8aff8b62d440b3b5c7ef9330e55878c3ee30381694ba57ef::whn_coin::WHN_COIN' \ + --args 0x402453b966e86168290e1f01b8c0fdaa92f6ea009258282ccbc33e873ddaba0c 888000 0x60364db3c6fa7128433ad62ce4e32649443a999ab6b54bdcbaf14194ec1a6203 + + +##>>> whn coin id: 0x4032ca8f17230d44653d49a4cdeb310dd7461fc85ab061594f10f09072532baf + + +## mint whn_facuet + sui client call \ + --package 0x2 \ + --module coin \ + --function mint_and_transfer \ + --type-args '0x498edfc9e864d78d244315e514569ae842cb26c14cea75acb55224f74e933bbd::whn_coin::WHN_COIN' \ + --args 0xcbd304d44a70d5a080b02b514122f9ca58d7e1481450377ac448d672dad0bbd9 888000 0x60364db3c6fa7128433ad62ce4e32649443a999ab6b54bdcbaf14194ec1a6203 + + + +##>>> whn_facuet id: 0x4ff2ab0c9ab266aadb4b9d6d175705838fd2212def149af953a41117de9ec766 + +# deposit_whn + sui client call \ + --package 0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296 \ + --module pebblerwon_swap \ + --function deposit_whn \ + --args 0x13e40067a462367a1a0d04504052f18cf1d7a53b2e337d2f90cbfba70dda755f 0x4032ca8f17230d44653d49a4cdeb310dd7461fc85ab061594f10f09072532baf + + +# deposit_whn_facuet + sui client call \ + --package 0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296 \ + --module pebblerwon_swap \ + --function deposit_whn_facuet \ + --args 0x13e40067a462367a1a0d04504052f18cf1d7a53b2e337d2f90cbfba70dda755f 0x4ff2ab0c9ab266aadb4b9d6d175705838fd2212def149af953a41117de9ec766 + + +# swap_coin_to_facuet +# whn_coin id:0xe7d4279199f3a45ebd762d941eae284a3e3ef8dcfafb872c9697f954f999e661 + sui client call \ + --package 0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296 \ + --module pebblerwon_swap \ + --function swap_coin_to_facuet \ + --args 0x13e40067a462367a1a0d04504052f18cf1d7a53b2e337d2f90cbfba70dda755f 0xe7d4279199f3a45ebd762d941eae284a3e3ef8dcfafb872c9697f954f999e661 + +##>>> transaction digest: AJxP2HgDoMtXMkVQBwnzHP25BQbEA1wGmpxhS6MXKhdx + +# swap_facuet_to_coin +# whn_coin_facuet id: 0x69b39219b3b1e2a097620d9d81afe38f362a2f25790586b18ec99c5c0616af71 + sui client call \ + --package 0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296 \ + --module pebblerwon_swap \ + --function swap_facuet_to_coin \ + --args 0x13e40067a462367a1a0d04504052f18cf1d7a53b2e337d2f90cbfba70dda755f 0x69b39219b3b1e2a097620d9d81afe38f362a2f25790586b18ec99c5c0616af71 +##>>> transaction digest: 5QRYxBrquAA7qc4PnFnRLmrpdAVAVJfeGkFcDBpwMhkG \ No newline at end of file diff --git a/mover/PebblerWon/code/task5/pebblerwon/call.testnet.sh b/mover/PebblerWon/code/task5/pebblerwon/call.testnet.sh new file mode 100644 index 000000000..cee29e3ef --- /dev/null +++ b/mover/PebblerWon/code/task5/pebblerwon/call.testnet.sh @@ -0,0 +1,63 @@ +# testnet +# pebblerwon packageid: 0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5 + +# testnet client addresses 0x09be6b8995b7f56d8491a67f54519c56059d3fc24124470366b7ee5b51c27a91 +# testnet bank id: 0x854d568bccf3bf1f6ff5e20f84bb005308db15551937cd083c6469c923f4559c +## mint whn + sui client call \ + --package 0x2 \ + --module coin \ + --function mint_and_transfer \ + --type-args '0x5bedaf1084a9f6a7c98a205ca56550c75bb13376cc34c07fc3c5bddc6b17d813::whn_coin::WHN_COIN' \ + --args 0xbbe765228d36c58cbdfa1cd3ab90ac11ba280866fd5dbe3e1cad15f5571f5316 999000 0x09be6b8995b7f56d8491a67f54519c56059d3fc24124470366b7ee5b51c27a91 + + +##>>> whn coin id: 0x37eb400f032abcf528b001d439f9e5e2a3f82591d5472b61a7e9ebed052f4784 + + +## mint whn_facuet + sui client call \ + --package 0x2 \ + --module coin \ + --function mint_and_transfer \ + --type-args '0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2::whn_coin::WHN_COIN' \ + --args 0x19e69a05953b0e065ebcd6a9705db902c21ac97f2bc14eb364ea79a889978d0c 999000 0x09be6b8995b7f56d8491a67f54519c56059d3fc24124470366b7ee5b51c27a91 + + + +##>>> whn_facuet id: 0xf27249f4b800c2a7f7dd86d6d3dc2ecfd6051e3716932ff2690299ea93b7a944 + +# deposit_whn + sui client call \ + --package 0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5 \ + --module pebblerwon_swap \ + --function deposit_whn \ + --args 0x854d568bccf3bf1f6ff5e20f84bb005308db15551937cd083c6469c923f4559c 0x37eb400f032abcf528b001d439f9e5e2a3f82591d5472b61a7e9ebed052f4784 + + +# deposit_whn_facuet + sui client call \ + --package 0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5 \ + --module pebblerwon_swap \ + --function deposit_whn_facuet \ + --args 0x854d568bccf3bf1f6ff5e20f84bb005308db15551937cd083c6469c923f4559c 0xf27249f4b800c2a7f7dd86d6d3dc2ecfd6051e3716932ff2690299ea93b7a944 + + +# swap_coin_to_facuet +# whn_coin id:0x04c38159baa572ca8c87505094e54645c9463bea4df2ced0163e3435c5283061 + sui client call \ + --package 0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5 \ + --module pebblerwon_swap \ + --function swap_coin_to_facuet \ + --args 0x854d568bccf3bf1f6ff5e20f84bb005308db15551937cd083c6469c923f4559c 0x04c38159baa572ca8c87505094e54645c9463bea4df2ced0163e3435c5283061 + +##>>> transaction digest: 7X9fabpBMxQM5Y9h8et9HEdSMueUphPmcJ9DLDNUwBDE + +# swap_facuet_to_coin +# whn_coin_facuet id: 0xd2c27ba848b0bfade9130349b424d8435b29591f2c0ffd810ef6a05b15d6e9d8 + sui client call \ + --package 0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5 \ + --module pebblerwon_swap \ + --function swap_facuet_to_coin \ + --args 0x854d568bccf3bf1f6ff5e20f84bb005308db15551937cd083c6469c923f4559c 0xd2c27ba848b0bfade9130349b424d8435b29591f2c0ffd810ef6a05b15d6e9d8 +##>>> transaction digest: 5yheKC53RXoHGp5j62JBHWxmikHwBYFJoTGAzt2zgXru \ No newline at end of file diff --git a/mover/PebblerWon/code/task5/pebblerwon/sources/demo.move.ddd b/mover/PebblerWon/code/task5/pebblerwon/sources/demo.move.ddd new file mode 100644 index 000000000..6553efd2c --- /dev/null +++ b/mover/PebblerWon/code/task5/pebblerwon/sources/demo.move.ddd @@ -0,0 +1,93 @@ +module swap::swap { + use sui::balance; + use sui::balance::Balance; + use sui::coin; + use sui::coin::Coin; + use sui::object; + use sui::object::UID; + use sui::transfer::{transfer, share_object, public_transfer}; + use sui::tx_context::{TxContext, sender}; + use coin_owner::usd::USD; + use coin_owner::rmb::RMB; + + + public struct AdminCap has key { + id: UID, + } + + public struct Bank has key { + id: UID, + rmb: Balance, + usd: Balance + } + + + fun init(ctx: &mut TxContext) { + + let bank = Bank { + id: object::new(ctx), + rmb: balance::zero<>(), + usd: balance::zero<>() + }; + + share_object(bank); + + let admin_cap = AdminCap { id: object::new(ctx) }; + + transfer(admin_cap, sender(ctx)); + } + + + + public entry fun deposit_rmb(bank:&mut Bank,rmb:Coin,_:&mut TxContext){ + let rmb_balance = coin::into_balance(rmb); + bank.rmb.join(rmb_balance); + } + + public entry fun deposit_usd(bank:&mut Bank,usd:Coin,_:&mut TxContext){ + let usd_balance = coin::into_balance(usd); + bank.usd.join(usd_balance); + } + + public entry fun withdraw_rmb(_:&AdminCap, bank:&mut Bank,amt:u64,ctx:&mut TxContext){ + let rmb_balance = bank.rmb.split(amt); + let rmb = coin::from_balance(rmb_balance,ctx); + public_transfer(rmb,sender(ctx)); + } + + + /// 1 usd = 1 rmb + public entry fun swap_rmb_usd(bank: &mut Bank, rmb: Coin, ctx: &mut TxContext) { + let amt = rmb.value(); + + bank.rmb.join(coin::into_balance(rmb)); + + + let amt_usd = amt * 10000 / 73000 ; + + + let usd_balance = bank.usd.split(amt_usd); + + + let usd = coin::from_balance(usd_balance, ctx); + + public_transfer(usd, sender(ctx)); + } + + public entry fun swap_usd_rmb(bank: &mut Bank, usd: Coin, ctx: &mut TxContext) { + let amt = usd.value(); + + bank.usd.join(coin::into_balance(usd)); + + + let amt_rmb = amt * 73000 / 10000; + + + let rmb_balance = bank.rmb.split(amt_rmb); + + let rmb = coin::from_balance(rmb_balance, ctx); + + public_transfer(rmb, sender(ctx)); + } + +} \ No newline at end of file diff --git a/mover/PebblerWon/code/task5/pebblerwon/sources/pebblerwon.move b/mover/PebblerWon/code/task5/pebblerwon/sources/pebblerwon.move new file mode 100644 index 000000000..4fd72555c --- /dev/null +++ b/mover/PebblerWon/code/task5/pebblerwon/sources/pebblerwon.move @@ -0,0 +1,78 @@ +module pebblerwon::pebblerwon_swap; + +use whn_coin::whn_coin::WHN_COIN; +use whn_coin_facuet::whn_coin::WHN_COIN as WHN_COIN_FACUET; +use sui::balance::{Balance,zero}; +use sui::coin; +use sui::coin::{Coin}; + + +public struct AdminCap has key { + id:UID +} + +public struct Bank has key { + id: UID, + whn_coin: Balance, + whn_coin_facuet: Balance, +} +fun init(ctx: &mut TxContext){ + let bank = Bank{ + id:object::new(ctx), + whn_coin:zero(), + whn_coin_facuet:zero() + }; + transfer::share_object(bank); + let admin_cap = AdminCap{ + id: object::new(ctx) + }; + transfer::transfer(admin_cap,ctx.sender()) +} + +public entry fun deposit_whn(bank: &mut Bank,in: Coin, _:&mut TxContext){ + let balance = coin::into_balance(in); + bank.whn_coin.join(balance); + +} +public entry fun deposit_whn_facuet(bank: &mut Bank, in: Coin,_:&mut TxContext){ + let balance = coin::into_balance(in); + bank.whn_coin_facuet.join(balance); +} +public entry fun withdraw_whn_coin(_: &AdminCap,bank:&mut Bank, amount:u64, ctx:&mut TxContext ){ + assert!(bank.whn_coin.value()>amount,0x100); + let b = bank.whn_coin.split(amount); + let c = coin::from_balance(b, ctx); + transfer::public_transfer(c, ctx.sender()); +} +public entry fun withdraw_whn_coin_facuet(_:&AdminCap,bank:&mut Bank,amount:u64, ctx: &mut TxContext){ + assert!(bank.whn_coin_facuet.value()>amount,0x101); + let b = bank.whn_coin_facuet.split(amount); + let c = coin::from_balance(b, ctx); + transfer::public_transfer(c, ctx.sender()); +} + +public entry fun swap_coin_to_facuet(bank:&mut Bank,w: Coin,ctx:&mut TxContext){ + let v = w.value(); + bank.whn_coin.join(coin::into_balance(w)); + + + + let facuet_amount = v*1; + let facuet_balance = bank.whn_coin_facuet.split(facuet_amount); + + let facuet_coin = coin::from_balance(facuet_balance, ctx); + transfer::public_transfer(facuet_coin, ctx.sender()); + +} + +public entry fun swap_facuet_to_coin(bank:&mut Bank,f: Coin,ctx:&mut TxContext){ + let v = f.value(); + bank.whn_coin_facuet.join(coin::into_balance(f)); + + let coin_amount = v/1; + + let coin_balance = bank.whn_coin.split(coin_amount); + let c = coin::from_balance(coin_balance, ctx); + + transfer::public_transfer(c, ctx.sender()); +} \ No newline at end of file diff --git a/mover/PebblerWon/code/task5/pebblerwon/tests/pebblerwon_tests.move b/mover/PebblerWon/code/task5/pebblerwon/tests/pebblerwon_tests.move new file mode 100644 index 000000000..5c6f2c7a0 --- /dev/null +++ b/mover/PebblerWon/code/task5/pebblerwon/tests/pebblerwon_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module pebblerwon::pebblerwon_tests; +// uncomment this line to import the module +// use pebblerwon::pebblerwon; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_pebblerwon() { + // pass +} + +#[test, expected_failure(abort_code = ::pebblerwon::pebblerwon_tests::ENotImplemented)] +fun test_pebblerwon_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/PebblerWon/readme.md b/mover/PebblerWon/readme.md index e090e1c68..4fbefdaa7 100644 --- a/mover/PebblerWon/readme.md +++ b/mover/PebblerWon/readme.md @@ -38,9 +38,9 @@ - [✓] play game hash: 3P4qvRqmuQp1i62aae1b7nWoq4v9XvUfuvc9NR3eihDg ## 05 Move Swap -- [] swap package id : -- [] call swap CoinA-> CoinB hash : -- [] call swap CoinB-> CoinA hash : +- [✓] swap package id : 0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296 +- [✓] call swap CoinA-> CoinB hash : AJxP2HgDoMtXMkVQBwnzHP25BQbEA1wGmpxhS6MXKhdx +- [✓] call swap CoinB-> CoinA hash : 5QRYxBrquAA7qc4PnFnRLmrpdAVAVJfeGkFcDBpwMhkG ## 06 Dapp-kit SDK PTB - [] save hash :