Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task4 done #1270

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions mover/ajin8898/code/task2/ajin_faucet_coin/Move.lock
Original file line number Diff line number Diff line change
@@ -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"
37 changes: 37 additions & 0 deletions mover/ajin8898/code/task2/ajin_faucet_coin/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

[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"

Original file line number Diff line number Diff line change
@@ -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<AJIN_FAUCET_COIN>, amount: u64, recipient: address, ctx: &mut TxContext) {
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx);
}

// 销毁代币
public entry fun burn(treasury_cap: &mut TreasuryCap<AJIN_FAUCET_COIN>, coin: Coin<AJIN_FAUCET_COIN>) {
coin::burn(treasury_cap, coin);
}

}
Original file line number Diff line number Diff line change
@@ -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
}
}
*/
49 changes: 49 additions & 0 deletions mover/ajin8898/code/task4/taiSaiGame/Move.lock
Original file line number Diff line number Diff line change
@@ -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"
38 changes: 38 additions & 0 deletions mover/ajin8898/code/task4/taiSaiGame/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

[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"

81 changes: 81 additions & 0 deletions mover/ajin8898/code/task4/taiSaiGame/sources/taisaigame.move
Original file line number Diff line number Diff line change
@@ -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<AJIN_FAUCET_COIN>
}

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<AJIN_FAUCET_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<AJIN_FAUCET_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));
}
}



8 changes: 8 additions & 0 deletions mover/ajin8898/code/task4/taiSaiGame/sources/task4.txt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions mover/ajin8898/code/task4/taiSaiGame/tests/taisaigame_tests.move
Original file line number Diff line number Diff line change
@@ -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
}
}
*/
16 changes: 9 additions & 7 deletions mover/ajin8898/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 :
Expand Down