Skip to content

Commit

Permalink
submit task4&task5
Browse files Browse the repository at this point in the history
  • Loading branch information
SherryW0918 committed Nov 26, 2024
1 parent a0742b4 commit 9df37d8
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 8 deletions.
58 changes: 58 additions & 0 deletions mover/hwen227/code/task5/hwen_swap/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 = "30FA6C9D98F6B608CA698A5643BAFA93A1FDAB773E878CD03639FABADC4B98C5"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "hwen_coin", name = "hwen_coin" },
{ id = "hwen_faucet_coin", name = "hwen_faucet_coin" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
id = "hwen_coin"
source = { local = "..\\..\\task2\\hwen_coin" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[[move.package]]
id = "hwen_faucet_coin"
source = { local = "..\\..\\task2\\hwen_faucet_coin" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.36.2"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0xcde791168671576e4ad49da511f31aca896aa87540ee6020fad114fa1c00744e"
latest-published-id = "0xcde791168671576e4ad49da511f31aca896aa87540ee6020fad114fa1c00744e"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x3fb5d5b05557c3fe832c720dec96c6f6f622879fa0586b5c8b5eb8252e3f2dbc"
latest-published-id = "0x3fb5d5b05557c3fe832c720dec96c6f6f622879fa0586b5c8b5eb8252e3f2dbc"
published-version = "1"
42 changes: 42 additions & 0 deletions mover/hwen227/code/task5/hwen_swap/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "hwen_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://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
hwen_coin = { local = "../../task2/hwen_coin" }
hwen_faucet_coin = { local = "../../task2/hwen_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]
hwen_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"
113 changes: 113 additions & 0 deletions mover/hwen227/code/task5/hwen_swap/sources/hwen_swap.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/// Module: hwen_swap
module hwen_swap::hwen_swap{
use hwen_faucet_coin::hwen_faucet_coin::HWEN_FAUCET_COIN;
use hwen_coin::hwen_coin::HWEN_COIN;
use sui::coin::{Self, Coin};
use sui::transfer::{transfer, share_object, public_transfer};
use sui::balance::{Self, Balance};

const EXCHANGE_RATE: u64 = 2 ;

public struct AdminCap has key {
id: UID
}

public struct MySwap has key {
id: UID,
hwen_coin:Balance<HWEN_COIN>,

faucet_coin:Balance<HWEN_FAUCET_COIN>
}

/// 初始化函数,创建并分享一个新的 MySwap 对象和 AdminCap 对象
fun init(ctx:&mut TxContext){
let admin_cap = AdminCap{id: object::new(ctx)};
let swap = MySwap{
id: object::new(ctx),
hwen_coin: balance::zero<HWEN_COIN>(),
faucet_coin: balance::zero<HWEN_FAUCET_COIN>()
};

share_object(swap);
transfer(admin_cap, ctx.sender());
}

/// 存入 HWEN_COIN 到 MySwap 中
entry fun deposit_hwen_coin(
swap: &mut MySwap,
hwen: Coin<HWEN_COIN>)
{
let hwen_balance = coin::into_balance(hwen);
swap.hwen_coin.join(hwen_balance);
//balance::join(&mut swap.hwen_coin, hwen_balance);
}

/// 存入 HWEN_FAUCET_COIN 到 MySwap 中
public entry fun deposit_faucet_coin(
swap: &mut MySwap,
faucet: Coin<HWEN_FAUCET_COIN>)
{
let faucet_balance = coin::into_balance(faucet);
balance::join(&mut swap.faucet_coin, faucet_balance);
}

/// 从 MySwap 中提取指定数量的 HWEN_COIN
public entry fun withdraw_hwen_coin(
_unused: &AdminCap,
swap: &mut MySwap,
amount: u64,
ctx : &mut TxContext)
{
let hwen_balance = balance::split(&mut swap.hwen_coin, amount);
let hwen_coin = coin::from_balance(hwen_balance, ctx);
public_transfer(hwen_coin, ctx.sender())
}

/// 从 MySwap 中提取指定数量的 HWEN_FAUCET_COIN
entry fun withdraw_faucet_coin(
_unused: &AdminCap,
swap: &mut MySwap,
amount: u64,
ctx : &mut TxContext)
{
let faucet_balance = balance::split(&mut swap.faucet_coin, amount);
let faucet_coin = coin::from_balance(faucet_balance, ctx);
public_transfer(faucet_coin, ctx.sender())
}

/// 将 HWEN_COIN 交换为 HWEN_FAUCET_COIN
entry fun swap_hwen_to_faucet(
swap: &mut MySwap,
input: Coin<HWEN_COIN>,
ctx : &mut TxContext
){

let hwen_amount = coin::value(&input);
let hwen_balance = coin::into_balance(input);
balance::join(&mut swap.hwen_coin, hwen_balance);

let faucet_amount = hwen_amount * EXCHANGE_RATE;

let faucet_balance = balance::split(&mut swap.faucet_coin,faucet_amount);
let faucet_coin = coin::from_balance(faucet_balance,ctx);
public_transfer(faucet_coin,ctx.sender())
}

/// 将 HWEN_FAUCET_COIN 交换为 HWEN_COIN
entry fun swap_faucet_to_hwen(
swap: &mut MySwap,
input: Coin<HWEN_FAUCET_COIN>,
ctx : &mut TxContext)
{
let faucet_amount = coin::value(&input);
let faucet_balance = coin::into_balance(input);
balance::join(&mut swap.faucet_coin, faucet_balance,);

let hwen_amount = faucet_amount / EXCHANGE_RATE;

let hwen_balance = balance::split(&mut swap.hwen_coin, hwen_amount);
let hwen_coin = coin::from_balance(hwen_balance, ctx);
public_transfer(hwen_coin, ctx.sender())
}

}
18 changes: 18 additions & 0 deletions mover/hwen227/code/task5/hwen_swap/tests/hwen_swap_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module hwen_swap::hwen_swap_tests;
// uncomment this line to import the module
// use hwen_swap::hwen_swap;
const ENotImplemented: u64 = 0;
#[test]
fun test_hwen_swap() {
// pass
}
#[test, expected_failure(abort_code = ::hwen_swap::hwen_swap_tests::ENotImplemented)]
fun test_hwen_swap_fail() {
abort ENotImplemented
}
*/
16 changes: 8 additions & 8 deletions mover/hwen227/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- github: `hwen227`

## 个人简介
- 计算机专业,未参加工作
- 计算机专业
- 技术栈: `java` `javascript` `python` `c++`
- 正在学习使用solidity编写智能合约,参加共学营来了解move语言以及sui生态,加深对区块链的理解
- 寻找远程工作中
Expand Down Expand Up @@ -31,15 +31,15 @@
- [] scan上的NFT截图:![Scan截图](./images/myNFT.png)

## 04 Move Game
- [] game package id : 0x5d530517d4fee43180fd1ea82ea1f6c7afc8dbde3e052cc24e2942b382fbb82a
- [] deposit Coin hash: Gpzu4SvSSz8MoQ6SpkJoRHbj3FCMpLEvqnJcqjzyocyX
- [] withdraw `Hwen Faucet Coin` hash: 4g1fYE6XFmCxZhiYbZqqk5tU1TU757PzXTpgpnbPPohT
- [] play game hash: AATCc2d2pME3NAF2uXVvBZiZ8VHam5hjmieQBBSukovd
- [] game package id : 0x5d530517d4fee43180fd1ea82ea1f6c7afc8dbde3e052cc24e2942b382fbb82a
- [] deposit Coin hash: Gpzu4SvSSz8MoQ6SpkJoRHbj3FCMpLEvqnJcqjzyocyX
- [] withdraw `Hwen Faucet Coin` hash: 4g1fYE6XFmCxZhiYbZqqk5tU1TU757PzXTpgpnbPPohT
- [] play game hash: AATCc2d2pME3NAF2uXVvBZiZ8VHam5hjmieQBBSukovd

## 05 Move Swap
- [] swap package id :
- [] call swap CoinA-> CoinB hash :
- [] call swap CoinB-> CoinA hash :
- [] swap package id : 0x3fb5d5b05557c3fe832c720dec96c6f6f622879fa0586b5c8b5eb8252e3f2dbc
- [] call swap CoinA-> CoinB hash : DtWSweEj3RNcCsKq6udvNyPfHpfmczYi8hjtEUwVZWYo
- [] call swap CoinB-> CoinA hash : DaWSAdBts9WPjwK5kdijCXiCho5YCxcQN5kz12wxHJQQ

## 06 Dapp-kit SDK PTB
- [] save hash :
Expand Down

0 comments on commit 9df37d8

Please sign in to comment.