From 6b983dcf677667109a91075f530c0011e9d034df Mon Sep 17 00:00:00 2001 From: "ajin.liu" Date: Fri, 26 Jul 2024 15:48:33 +0800 Subject: [PATCH] task4 done --- .../code/task2/ajin_faucet_coin/Move.lock | 40 +++++++++ .../code/task2/ajin_faucet_coin/Move.toml | 37 +++++++++ .../sources/ajin_faucet_coin.move | 38 +++++++++ .../tests/ajin_faucet_coin_tests.move | 19 +++++ .../ajin8898/code/task4/taiSaiGame/Move.lock | 49 +++++++++++ .../ajin8898/code/task4/taiSaiGame/Move.toml | 38 +++++++++ .../task4/taiSaiGame/sources/taisaigame.move | 81 +++++++++++++++++++ .../code/task4/taiSaiGame/sources/task4.txt | 8 ++ .../taiSaiGame/tests/taisaigame_tests.move | 19 +++++ mover/ajin8898/readme.md | 16 ++-- 10 files changed, 338 insertions(+), 7 deletions(-) create mode 100644 mover/ajin8898/code/task2/ajin_faucet_coin/Move.lock create mode 100644 mover/ajin8898/code/task2/ajin_faucet_coin/Move.toml create mode 100644 mover/ajin8898/code/task2/ajin_faucet_coin/sources/ajin_faucet_coin.move create mode 100644 mover/ajin8898/code/task2/ajin_faucet_coin/tests/ajin_faucet_coin_tests.move create mode 100644 mover/ajin8898/code/task4/taiSaiGame/Move.lock create mode 100644 mover/ajin8898/code/task4/taiSaiGame/Move.toml create mode 100644 mover/ajin8898/code/task4/taiSaiGame/sources/taisaigame.move create mode 100644 mover/ajin8898/code/task4/taiSaiGame/sources/task4.txt create mode 100644 mover/ajin8898/code/task4/taiSaiGame/tests/taisaigame_tests.move diff --git a/mover/ajin8898/code/task2/ajin_faucet_coin/Move.lock b/mover/ajin8898/code/task2/ajin_faucet_coin/Move.lock new file mode 100644 index 000000000..f12a18ecf --- /dev/null +++ b/mover/ajin8898/code/task2/ajin_faucet_coin/Move.lock @@ -0,0 +1,40 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 2 +manifest_digest = "D46641486D6A8D6BBF0261E25607FA6E33DA8FAB9481199B043464314CFDE88F" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { name = "Sui" }, +] + +[[move.package]] +name = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +name = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.29.0" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x4123c8ba91d71254de2bc6de82ef9eef0507c3cbc3d8544e3ad71ee8474e65f7" +latest-published-id = "0x4123c8ba91d71254de2bc6de82ef9eef0507c3cbc3d8544e3ad71ee8474e65f7" +published-version = "1" + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x1925e6fbe5dab7b3c5e9b8ec92a2c97620765f12b41222d5a2ed9ba3e5b31999" +latest-published-id = "0x1925e6fbe5dab7b3c5e9b8ec92a2c97620765f12b41222d5a2ed9ba3e5b31999" +published-version = "1" diff --git a/mover/ajin8898/code/task2/ajin_faucet_coin/Move.toml b/mover/ajin8898/code/task2/ajin_faucet_coin/Move.toml new file mode 100644 index 000000000..96c86d3ea --- /dev/null +++ b/mover/ajin8898/code/task2/ajin_faucet_coin/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "ajin_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://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 +# 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] +ajin_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/ajin8898/code/task2/ajin_faucet_coin/sources/ajin_faucet_coin.move b/mover/ajin8898/code/task2/ajin_faucet_coin/sources/ajin_faucet_coin.move new file mode 100644 index 000000000..51437f1dc --- /dev/null +++ b/mover/ajin8898/code/task2/ajin_faucet_coin/sources/ajin_faucet_coin.move @@ -0,0 +1,38 @@ +module ajin_faucet_coin::ajin_faucet_coin { + + use sui::coin::create_currency; + use sui::transfer::{public_freeze_object, public_share_object}; + use sui::coin::{Self, Coin, TreasuryCap}; + use sui::url::{Url, Self}; + + public struct AJIN_FAUCET_COIN has drop {} + + fun init(witness: AJIN_FAUCET_COIN, ctx: &mut TxContext) { + let icon_url = option::none(); + let (treasury_cap, coin_metadata) = create_currency( + witness, + 8, + b"Ajin Faucet", + b"Ajin Faucet", + b"Ajin faucet coin", + icon_url, + ctx + ); + + // 所有权共享出去,不可变 + public_freeze_object(coin_metadata); + // 所有权共享出去 + 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 entry fun burn(treasury_cap: &mut TreasuryCap, coin: Coin) { + coin::burn(treasury_cap, coin); + } + +} \ No newline at end of file diff --git a/mover/ajin8898/code/task2/ajin_faucet_coin/tests/ajin_faucet_coin_tests.move b/mover/ajin8898/code/task2/ajin_faucet_coin/tests/ajin_faucet_coin_tests.move new file mode 100644 index 000000000..2ec319528 --- /dev/null +++ b/mover/ajin8898/code/task2/ajin_faucet_coin/tests/ajin_faucet_coin_tests.move @@ -0,0 +1,19 @@ +/* +#[test_only] +module ajin_faucet_coin::ajin_faucet_coin_tests { + // uncomment this line to import the module + // use ajin_faucet_coin::ajin_faucet_coin; + + const ENotImplemented: u64 = 0; + + #[test] + fun test_ajin_faucet_coin() { + // pass + } + + #[test, expected_failure(abort_code = ::ajin_faucet_coin::ajin_faucet_coin_tests::ENotImplemented)] + fun test_ajin_faucet_coin_fail() { + abort ENotImplemented + } +} +*/ diff --git a/mover/ajin8898/code/task4/taiSaiGame/Move.lock b/mover/ajin8898/code/task4/taiSaiGame/Move.lock new file mode 100644 index 000000000..dbc8e90c2 --- /dev/null +++ b/mover/ajin8898/code/task4/taiSaiGame/Move.lock @@ -0,0 +1,49 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 2 +manifest_digest = "008130794F614F874155EB75CEA43FC08EFC9615B49435BE86B974C978019ACE" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { name = "Sui" }, + { name = "ajin_faucet_coin" }, +] + +[[move.package]] +name = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +name = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { name = "MoveStdlib" }, +] + +[[move.package]] +name = "ajin_faucet_coin" +source = { local = "../../task2/ajin_faucet_coin" } + +dependencies = [ + { name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.29.0" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x81ab36916b0a2adc9b217027ad660481ff36170ee0ed2c5771952ad0afa2a8dc" +latest-published-id = "0x81ab36916b0a2adc9b217027ad660481ff36170ee0ed2c5771952ad0afa2a8dc" +published-version = "1" + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0" +latest-published-id = "0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0" +published-version = "1" diff --git a/mover/ajin8898/code/task4/taiSaiGame/Move.toml b/mover/ajin8898/code/task4/taiSaiGame/Move.toml new file mode 100644 index 000000000..6e784f8e0 --- /dev/null +++ b/mover/ajin8898/code/task4/taiSaiGame/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "taiSaiGame" +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" } +ajin_faucet_coin = { local = "../../task2/ajin_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] +taisaigame = "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/ajin8898/code/task4/taiSaiGame/sources/taisaigame.move b/mover/ajin8898/code/task4/taiSaiGame/sources/taisaigame.move new file mode 100644 index 000000000..e580d7df6 --- /dev/null +++ b/mover/ajin8898/code/task4/taiSaiGame/sources/taisaigame.move @@ -0,0 +1,81 @@ +/// Module: taisaigame +module taisaigame::taisaigame { + + use sui::sui::SUI; + use sui::balance::{Self, Balance}; + use sui::transfer; + use sui::tx_context::sender; + use ajin_faucet_coin::ajin_faucet_coin::{Self, AJIN_FAUCET_COIN}; + use sui::coin; + use sui::coin::{Coin, from_balance, into_balance}; + use sui::random; + use sui::random::Random; + use sui::transfer::{share_object, transfer, public_transfer}; + + + 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() + }; + transfer::share_object(game); + + let admin = AdminCap{ + id:object::new(ctx) + }; + transfer::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 1; + }; + + //防止 all in 战神,限制每次最大是合约里面钱的10分之一 + if (game_val < coin_value*10) { + abort 2; + }; + + 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 deposit(game: &mut Game, in: Coin, ctx: &TxContext) { + let in_balance = into_balance(in); + balance::join(&mut game.val, in_balance); + } + + public entry fun withdraw(_: &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/ajin8898/code/task4/taiSaiGame/sources/task4.txt b/mover/ajin8898/code/task4/taiSaiGame/sources/task4.txt new file mode 100644 index 000000000..4548e4ba4 --- /dev/null +++ b/mover/ajin8898/code/task4/taiSaiGame/sources/task4.txt @@ -0,0 +1,8 @@ +gameId:0x585a3deb820ebe94b42dd49aa12e1887a2cc27a67aaa4fd4e81c1160519f08fb +packageID:0x81ab36916b0a2adc9b217027ad660481ff36170ee0ed2c5771952ad0afa2a8dc +0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 +sui client call --function deposit --module taisaigame --package $PACKAGE_ID --gas-budget 3000000 --args $Game_Share_ID $Coin_ID +sui client call --function deposit --module taisaigame --package 0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 --gas-budget 3000000 --args 0x649658a65d4334c933bc1c65cabe7705c728c0b871f27b24b19b1289d4841098 0x634b1890e1c41e6c46ffb51fb2e60cdde5bcda98a2d8c06d160304a47701fb63 +sui client call --function withdraw --module taisaigame --package $GAME_PACKAGE_ID --gas-budget 3000000 --args $adminCap $Game_Share_ID 1000000 +sui client call --function withdraw --module taisaigame --package 0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 --gas-budget 3000000 --args 0x9d729e0aeab6130bc55b459e17b56f9d9fa704771ea8f02c891e4e5ba6ea7485 0x649658a65d4334c933bc1c65cabe7705c728c0b871f27b24b19b1289d4841098 100000000 +sui client call --function play --module taisaigame --package 0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 --gas-budget 3000000 --args 0x649658a65d4334c933bc1c65cabe7705c728c0b871f27b24b19b1289d4841098 true 0xe0777777dea58f72720f30aafb76391a259af8ddad5fece433f23bd036710fe9 0x8 \ No newline at end of file diff --git a/mover/ajin8898/code/task4/taiSaiGame/tests/taisaigame_tests.move b/mover/ajin8898/code/task4/taiSaiGame/tests/taisaigame_tests.move new file mode 100644 index 000000000..c4d1c02b9 --- /dev/null +++ b/mover/ajin8898/code/task4/taiSaiGame/tests/taisaigame_tests.move @@ -0,0 +1,19 @@ +/* +#[test_only] +module taisaigame::taisaigame_tests { + // uncomment this line to import the module + // use taisaigame::taisaigame; + + const ENotImplemented: u64 = 0; + + #[test] + fun test_taisaigame() { + // pass + } + + #[test, expected_failure(abort_code = ::taisaigame::taisaigame_tests::ENotImplemented)] + fun test_taisaigame_fail() { + abort ENotImplemented + } +} +*/ diff --git a/mover/ajin8898/readme.md b/mover/ajin8898/readme.md index 9e2124044..49a028a06 100644 --- a/mover/ajin8898/readme.md +++ b/mover/ajin8898/readme.md @@ -20,10 +20,12 @@ ## 02 move coin - [] My Coin package id : 0x045eff3eaf7a574b1607fb8fd930adfa634e06c2e9cffe28b8963ddb499dedde -- [] Faucet package id : 0x35492b3e019b3f5cec1e00190de1e751013114214b4e94dce2e4193215ef2d82 +- [] Faucet package id : +mainnet: 0x4123c8ba91d71254de2bc6de82ef9eef0507c3cbc3d8544e3ad71ee8474e65f7 +testnet: 0x1925e6fbe5dab7b3c5e9b8ec92a2c97620765f12b41222d5a2ed9ba3e5b31999 - [] 转账 `My Coin` hash: H5kJaD5DAHfN4Txp18jNvqAxgAJb8zPcC14L5qg4HvF1 -- [] `Faucet Coin` address1 mint hash: BiaM42QDMx9EY9cSEFfVy9is3ZDQUWtqvYdJkNyvWYt9 -- [] `Faucet Coin` address2 mint hash: 3omRmf1nsoDqRuwKyLXpo2sP9hoyPNoiSSXnwt1HpSDG +- [] `Faucet Coin` address1 mint hash: DqZyGWpLR9yDitVo7Y8XnbbNKdP8mnrd2JQGVox3gnLq +- [] `Faucet Coin` address2 mint hash: 3F7X5gZFG8P1MDCRbEBuNmomwDpdHrU5yDt8DZrahf9e ## 03 move NFT - [] nft package id : 0x93ff41e4086c4d855c2ee4ad3390049ea9b5cefa74d432d2d97043d34613329d @@ -32,10 +34,10 @@ - [] scan上的NFT截图:![Scan截图](./images/task03.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [] game package id : testnet: 0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 +- [] deposit Coin hash: testnet: GDLWXZadDgnqifT1qqMzLmhvodN3u4xvgHaV1uF7dXT5 +- [] withdraw `Coin` hash: testnet: F4JDCRPzZ6bSHLQ9D8tjVUYG2dj8AgDps3F94UJXMuUK +- [] play game hash: testnet: AZ5ESeWdH9ZgHLkBpShK2srdrhMG2sgw6i37ACB7UiBo ## 05 Move Swap - [] swap package id :