-
Notifications
You must be signed in to change notification settings - Fork 888
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
9374796
commit 46e9922
Showing
3 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
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,58 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 3 | ||
manifest_digest = "465A802421E743DBF1F10DB36711C750373148B75F5675403655603937BD14A0" | ||
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" | ||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
{ id = "faucetcoin", name = "faucetcoin" }, | ||
{ id = "mycoin", name = "mycoin" }, | ||
] | ||
|
||
[[move.package]] | ||
id = "MoveStdlib" | ||
source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } | ||
|
||
[[move.package]] | ||
id = "Sui" | ||
source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", 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.1" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.testnet] | ||
chain-id = "4c78adac" | ||
original-published-id = "0xde9a45b9e568c4c687bada719f26de89da8a114ae72b17f8c278a88e520afdcd" | ||
latest-published-id = "0xde9a45b9e568c4c687bada719f26de89da8a114ae72b17f8c278a88e520afdcd" | ||
published-version = "1" | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x4f00d40b61ba1bfde5e59f930ef33222beb857502d2ba3622b8def7bef05287f" | ||
latest-published-id = "0x4f00d40b61ba1bfde5e59f930ef33222beb857502d2ba3622b8def7bef05287f" | ||
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,39 @@ | ||
[package] | ||
name = "swap" | ||
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://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } | ||
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] | ||
swap = "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,100 @@ | ||
module swap::swap; | ||
|
||
use faucetcoin::krypton_faucet_coin::KRYPTON_FAUCET_COIN; | ||
use mycoin::krypton_coin::KRYPTON_COIN; | ||
use sui::balance::{Self,Balance}; | ||
use sui::transfer::{transfer,share_object,public_transfer}; | ||
use sui::coin::{Self,Coin}; | ||
// 定义管理员能力 | ||
public struct AdminCap has key{ | ||
id: UID | ||
} | ||
|
||
// 定义银行结构体 | ||
public struct Bank has key{ | ||
id: UID, | ||
krypton:Balance<KRYPTON_COIN>, | ||
krypton_faucet_coin:Balance<KRYPTON_FAUCET_COIN> | ||
} | ||
|
||
fun init(ctx:&mut TxContext){ | ||
let bank = Bank { | ||
id:object::new(ctx), | ||
krypton:balance::zero<KRYPTON_COIN>(), | ||
krypton_faucet_coin:balance::zero<KRYPTON_FAUCET_COIN>() | ||
}; | ||
share_object(bank); | ||
let admin_cap = AdminCap { id:object::new(ctx) }; | ||
transfer(admin_cap,ctx.sender()); | ||
} | ||
|
||
public entry fun deposit( | ||
_:&AdminCap, | ||
bank:&mut Bank, | ||
krypton:Coin<KRYPTON_COIN>, | ||
_:&mut TxContext | ||
){ | ||
let krypton_balance = coin::into_balance(krypton); | ||
balance::join(&mut bank.krypton, krypton_balance); | ||
} | ||
|
||
public entry fun deposit_faucet( | ||
_:&AdminCap, | ||
bank:&mut Bank, | ||
krypton_faucet_coin:Coin<KRYPTON_FAUCET_COIN>, | ||
_:&mut TxContext | ||
){ | ||
let krypton_faucet_balance = coin::into_balance(krypton_faucet_coin); | ||
balance::join(&mut bank.krypton_faucet_coin, krypton_faucet_balance); | ||
} | ||
|
||
public entry fun withdraw( | ||
_:&AdminCap, | ||
bank:&mut Bank, | ||
amount:u64, | ||
ctx:&mut TxContext | ||
){ | ||
let krypton_balance = balance::split(&mut bank.krypton, amount); | ||
let krypton= coin::from_balance(krypton_balance, ctx); | ||
public_transfer(krypton,ctx.sender()); | ||
} | ||
|
||
public entry fun withdraw_krypton_faucet( | ||
_:&AdminCap, | ||
bank:&mut Bank, | ||
amount:u64, | ||
ctx:&mut TxContext | ||
){ | ||
let krypton_faucet_balance = balance::split(&mut bank.krypton_faucet_coin, amount); | ||
let krypton_faucet_coin= coin::from_balance(krypton_faucet_balance, ctx); | ||
public_transfer(krypton_faucet_coin,ctx.sender()); | ||
} | ||
|
||
public entry fun swap_a_to_b( | ||
bank:&mut Bank, | ||
krypton:Coin<KRYPTON_COIN>, | ||
ctx:&mut TxContext | ||
){ | ||
let amount = coin::value(&krypton); | ||
balance::join(&mut bank.krypton, coin::into_balance(krypton)); | ||
|
||
let amount_end = amount * 2; | ||
let faucet = balance::split(&mut bank.krypton_faucet_coin, amount_end); | ||
public_transfer(coin::from_balance(faucet, ctx), ctx.sender()); | ||
|
||
} | ||
|
||
|
||
public entry fun swap_b_to_a( | ||
bank:&mut Bank, | ||
krypton_faucet_coin:Coin<KRYPTON_FAUCET_COIN>, | ||
ctx:&mut TxContext | ||
){ | ||
let amount = coin::value(&krypton_faucet_coin); | ||
balance::join(&mut bank.krypton_faucet_coin, coin::into_balance(krypton_faucet_coin)); | ||
|
||
let amount_end = amount / 2; | ||
let krypton = balance::split(&mut bank.krypton, amount_end); | ||
public_transfer(coin::from_balance(krypton, ctx), ctx.sender()); | ||
|
||
} |