Skip to content

Commit

Permalink
Merge pull request #1909 from EarthChen/task5
Browse files Browse the repository at this point in the history
Task5
  • Loading branch information
Sifotd authored Nov 19, 2024
2 parents ea57c27 + 8c38b15 commit 9c771d2
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 5 deletions.
20 changes: 19 additions & 1 deletion mover/EarthChen/code/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 猜数游戏信息
# task4 猜数游戏信息

## testnet

Expand All @@ -10,6 +10,7 @@
### faucetcoin

* pacakgeId: 0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf
* 0x2::package::UpgradeCap: 0x1443e8d5e94f7080ae73e0c2b1c9907b3d16df740d98e361b5264f7325535b62
* coin: 0x27b93ff04870aa99ce50ca35694fb66d5678629088cacefaa78c6d7d5f20763a


Expand All @@ -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_
2 changes: 1 addition & 1 deletion mover/EarthChen/code/task2/faucetcoin/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# 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" }
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.
Expand Down
58 changes: 58 additions & 0 deletions mover/EarthChen/code/task5/earthchen/Move.lock
Original file line number Diff line number Diff line change
@@ -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"
39 changes: 39 additions & 0 deletions mover/EarthChen/code/task5/earthchen/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

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

80 changes: 80 additions & 0 deletions mover/EarthChen/code/task5/earthchen/sources/earthchen.move
Original file line number Diff line number Diff line change
@@ -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<MYCOIN>,
faucetcoin: Balance<FAUCETCOIN>,
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<MYCOIN>(),
faucetcoin: balance::zero<FAUCETCOIN>(),
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<MYCOIN>, _ctx: &mut TxContext) {
let balance = coin::into_balance(mycoin);
bank.mycoin.join(balance);
}

public entry fun deposit_faucetcoin(bank: &mut Bank, faucetcoin: Coin<FAUCETCOIN>, _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<FAUCETCOIN>, 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<MYCOIN>, 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);
}
}

6 changes: 3 additions & 3 deletions mover/EarthChen/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down

0 comments on commit 9c771d2

Please sign in to comment.