From 38178d9cbf1782e0db4f682e32495921623610fb Mon Sep 17 00:00:00 2001 From: Subc <626058035@qq.com> Date: Wed, 11 Dec 2024 00:53:03 +0800 Subject: [PATCH] feat: init --- .../code/task2/suiceber_coin/Move.lock | 4 +- .../code/task2/suiceber_faucet_coin/Move.lock | 4 +- mover/suiceber/code/task5/Move.lock | 52 +++++++++++ mover/suiceber/code/task5/Move.toml | 38 ++++++++ mover/suiceber/code/task5/sources/task5.move | 93 +++++++++++++++++++ .../code/task5/tests/task5_tests.move | 18 ++++ mover/suiceber/readme.md | 6 +- 7 files changed, 208 insertions(+), 7 deletions(-) create mode 100644 mover/suiceber/code/task5/Move.lock create mode 100644 mover/suiceber/code/task5/Move.toml create mode 100644 mover/suiceber/code/task5/sources/task5.move create mode 100644 mover/suiceber/code/task5/tests/task5_tests.move diff --git a/mover/suiceber/code/task2/suiceber_coin/Move.lock b/mover/suiceber/code/task2/suiceber_coin/Move.lock index 486968730..4db969da3 100644 --- a/mover/suiceber/code/task2/suiceber_coin/Move.lock +++ b/mover/suiceber/code/task2/suiceber_coin/Move.lock @@ -29,6 +29,6 @@ flavor = "sui" [env.mainnet] chain-id = "35834a8a" -original-published-id = "0x1d7b599b6057756f0a080cbae63637f4960d4dbfc34b084d0984475e298ad95f" -latest-published-id = "0x1d7b599b6057756f0a080cbae63637f4960d4dbfc34b084d0984475e298ad95f" +original-published-id = "0x9dba80f1aa2bb039b7da5aecdde81e4569757470c7080f0c04e32ef2a1023b56" +latest-published-id = "0x9dba80f1aa2bb039b7da5aecdde81e4569757470c7080f0c04e32ef2a1023b56" published-version = "1" diff --git a/mover/suiceber/code/task2/suiceber_faucet_coin/Move.lock b/mover/suiceber/code/task2/suiceber_faucet_coin/Move.lock index 56af22046..707fe3973 100644 --- a/mover/suiceber/code/task2/suiceber_faucet_coin/Move.lock +++ b/mover/suiceber/code/task2/suiceber_faucet_coin/Move.lock @@ -29,6 +29,6 @@ flavor = "sui" [env.mainnet] chain-id = "35834a8a" -original-published-id = "0xab47221259f13914137fd9a4b1a1c5ffd278d1b2f24dc2b86cf3c2a6ed96c478" -latest-published-id = "0xab47221259f13914137fd9a4b1a1c5ffd278d1b2f24dc2b86cf3c2a6ed96c478" +original-published-id = "0x9dff1c645fdafdd15d37ba988544aa08955e28fad6783c21d2b539bc216efd4e" +latest-published-id = "0x9dff1c645fdafdd15d37ba988544aa08955e28fad6783c21d2b539bc216efd4e" published-version = "1" diff --git a/mover/suiceber/code/task5/Move.lock b/mover/suiceber/code/task5/Move.lock new file mode 100644 index 000000000..bb98b48d2 --- /dev/null +++ b/mover/suiceber/code/task5/Move.lock @@ -0,0 +1,52 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "B6B1B214F7D9C1D99F0033646BB86CC59A9DDF3F8564699CEA8D0F6A0B4DC9EB" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "suiceber_coin", name = "suiceber_coin" }, + { id = "suiceber_faucet_coin", name = "suiceber_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 = "suiceber_coin" +source = { local = "C:\\Users\\62605\\Desktop\\sui\\letsmove\\mover\\suiceber\\code\\task2\\suiceber_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "suiceber_faucet_coin" +source = { local = "C:\\Users\\62605\\Desktop\\sui\\letsmove\\mover\\suiceber\\code\\task2\\suiceber_faucet_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.37.1" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0xde56fb47cbbfa4dbe2dcd014c7d81c1b510c442b10f573b4f79e028129e33733" +latest-published-id = "0xde56fb47cbbfa4dbe2dcd014c7d81c1b510c442b10f573b4f79e028129e33733" +published-version = "1" diff --git a/mover/suiceber/code/task5/Move.toml b/mover/suiceber/code/task5/Move.toml new file mode 100644 index 000000000..b3943e708 --- /dev/null +++ b/mover/suiceber/code/task5/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "task5" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } +suiceber_faucet_coin = { local = "C:/Users/62605/Desktop/sui/letsmove/mover/suiceber/code/task2/suiceber_faucet_coin" } +suiceber_coin = { local = "C:/Users/62605/Desktop/sui/letsmove/mover/suiceber/code/task2/suiceber_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] +task5 = "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" + diff --git a/mover/suiceber/code/task5/sources/task5.move b/mover/suiceber/code/task5/sources/task5.move new file mode 100644 index 000000000..63e063d90 --- /dev/null +++ b/mover/suiceber/code/task5/sources/task5.move @@ -0,0 +1,93 @@ + +module task5::task5 { + use sui::coin::{Self, Coin}; + use suiceber_coin::suiceber_coin::SUICEBER_COIN; + use suiceber_faucet_coin::suiceber_faucet_coin::SUICEBER_FAUCET_COIN; + use sui::balance::{Self, Balance}; + + const EInsufficientBalance: u64 = 1000; + + public struct Pool has key { + id: UID, + coin_balance: Balance, + faucet_balance: Balance, + } + + fun init(ctx: &mut TxContext) { + let pool = Pool { + id: object::new(ctx), + coin_balance: balance::zero(), + faucet_balance: balance::zero() + }; + transfer::share_object(pool); + } + + // 填充资金池 + public entry fun Deposit( + pool: &mut Pool, + coin: &mut Coin, + faucet: &mut Coin, + coin_amount: u64, + faucet_amount: u64 + + ) { + let split_coin_balance = balance::split( + coin::balance_mut(coin), + coin_amount + ); + balance::join( + &mut pool.coin_balance, + split_coin_balance + ); + let split_faucet_balance = balance::split( + coin::balance_mut(faucet), + faucet_amount + ); + balance::join( + &mut pool.faucet_balance, + split_faucet_balance + ); + } + + public entry fun swap_coin_to_faucet( + pool: &mut Pool, + coin: &mut Coin, + amount: u64, + ctx: &mut TxContext + ) { + assert!( + pool.faucet_balance.value() >= amount, + EInsufficientBalance + ); + let split_coin_balance = balance::split(coin::balance_mut(coin), amount); + balance::join( + &mut pool.coin_balance, + split_coin_balance + ); + let faucet = coin::take( + &mut pool.faucet_balance, + amount, + ctx + ); + transfer::public_transfer(faucet, ctx.sender()); + } + + public entry fun swap_faucet_to_coin( + pool: &mut Pool, + faucet: &mut Coin, + amount: u64, + ctx: &mut TxContext + ) { + assert!( + pool.coin_balance.value() >= amount, + EInsufficientBalance + ); + let split_faucet_balance = balance::split(coin::balance_mut(faucet), amount); + balance::join( + &mut pool.faucet_balance, + split_faucet_balance + ); + let coin = coin::take(&mut pool.coin_balance, amount, ctx); + transfer::public_transfer(coin, ctx.sender()); + } +} diff --git a/mover/suiceber/code/task5/tests/task5_tests.move b/mover/suiceber/code/task5/tests/task5_tests.move new file mode 100644 index 000000000..006cda1f9 --- /dev/null +++ b/mover/suiceber/code/task5/tests/task5_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module task5::task5_tests; +// uncomment this line to import the module +// use task5::task5; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_task5() { + // pass +} + +#[test, expected_failure(abort_code = ::task5::task5_tests::ENotImplemented)] +fun test_task5_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/suiceber/readme.md b/mover/suiceber/readme.md index 885fa4344..9e293e14f 100644 --- a/mover/suiceber/readme.md +++ b/mover/suiceber/readme.md @@ -38,9 +38,9 @@ - [x] play game hash:GfC2CX23tMhDTD18byRcVqc86iEU1NEXLahApo1zqSvK ## 05 Move Swap -- [] swap package id : -- [] call swap CoinA-> CoinB hash : -- [] call swap CoinB-> CoinA hash : +- [x] swap package id :0xde56fb47cbbfa4dbe2dcd014c7d81c1b510c442b10f573b4f79e028129e33733 +- [x] call swap CoinA-> CoinB hash :BmVRb9mDEuhBzZuYEJ18JCJUxekGmYc1D6R5JNqghCEj +- [x] call swap CoinB-> CoinA hash :CfJUAgymfN1Dwm6H2BJWJr475XThqAWpzKZifwwfiHzF ## 06 Dapp-kit SDK PTB - [] save hash :