-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
513b50a
commit 03855aa
Showing
7 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 3 | ||
manifest_digest = "47A34D68338E0923BF11A14349A8841445F79341A900C8A30148FB158C50862E" | ||
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" | ||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
{ 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 = "mycoin" | ||
source = { local = "../../02_coin/mycoin" } | ||
|
||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
] | ||
|
||
[move.toolchain-version] | ||
compiler-version = "1.38.1" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0xd80653d568c836a17a5bef6802bc109512fdc653c93ceb4399c9d557d83c872b" | ||
latest-published-id = "0xd80653d568c836a17a5bef6802bc109512fdc653c93ceb4399c9d557d83c872b" | ||
published-version = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "ch1hiro" | ||
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" } | ||
mycoin = { local = "../../02_coin/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] | ||
ch1hiro = "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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
module ch1hiro::ch1hiro { | ||
use sui::balance; | ||
use sui::balance::Balance; | ||
use sui::coin; | ||
use sui::coin::{Coin, into_balance, from_balance}; | ||
use sui::transfer::public_transfer; | ||
use sui::tx_context::sender; | ||
use mycoin::mycoin::MYCOIN; | ||
use mycoin::faucetcoin::FAUCETCOIN; | ||
|
||
// 创建银行 | ||
public struct Bank has key { | ||
id: UID, | ||
hiro: Balance<MYCOIN>, | ||
fct: Balance<FAUCETCOIN> | ||
} | ||
|
||
// 创建管理员权限 | ||
public struct AdminCap has key { | ||
id: UID, | ||
} | ||
|
||
// 实例化对象 | ||
fun init(ctx: &mut TxContext) { | ||
let bank = Bank { | ||
id: object::new(ctx), | ||
hiro: balance::zero<MYCOIN>(), | ||
fct: balance::zero<FAUCETCOIN>(), | ||
}; | ||
|
||
transfer::share_object(bank); | ||
|
||
let admincap = AdminCap { | ||
id: object::new(ctx), | ||
}; | ||
|
||
transfer::transfer(admincap, sender(ctx)); | ||
} | ||
|
||
// 将 hiro 转换为 balance 存入银行 | ||
public entry fun deposit_hiro(bank: &mut Bank, hiro: Coin<MYCOIN>) { | ||
let hiro_balance = into_balance(hiro); | ||
balance::join(&mut bank.hiro, hiro_balance); | ||
} | ||
|
||
// 将 fct 转换为 balance 存入银行 | ||
public entry fun deposit_fct(bank: &mut Bank, fct: Coin<FAUCETCOIN>) { | ||
let fct_balance = into_balance(fct); | ||
balance::join(&mut bank.fct, fct_balance); | ||
} | ||
|
||
// 将 hiro 转为 coin 并取出 | ||
public entry fun withdrawal_hiro(bank: &mut Bank, amt: u64, ctx: &mut TxContext) { | ||
let hiro_balance = balance::split(&mut bank.hiro, amt); | ||
let hiro_coin = from_balance(hiro_balance, ctx); | ||
public_transfer(hiro_coin, sender(ctx)); | ||
} | ||
|
||
// 1 hiro == 10 fct | ||
public entry fun swap_hiro_fct(bank: &mut Bank, hiro: Coin<MYCOIN>, ctx: &mut TxContext) { | ||
let amt = coin::value(&hiro); | ||
balance::join(&mut bank.hiro, into_balance(hiro)); | ||
let amt_fct = amt * 100 / 10; | ||
let fct_balance = balance::split(&mut bank.fct, amt_fct); | ||
let fct_coin = from_balance(fct_balance, ctx); | ||
public_transfer(fct_coin, sender(ctx)); | ||
} | ||
|
||
public entry fun swap_fct_hiro(bank: &mut Bank, fct: Coin<FAUCETCOIN>, ctx: &mut TxContext) { | ||
let amt = coin::value(&fct); | ||
balance::join(&mut bank.fct, into_balance(fct)); | ||
let amt_hiro = amt * 10 / 100; | ||
let hiro_balance = balance::split(&mut bank.hiro, amt_hiro); | ||
let hiro_coin = from_balance(hiro_balance, ctx); | ||
public_transfer(hiro_coin, sender(ctx)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters