diff --git a/mover/LeonDev1024/co-learn-2411/images/x_guanzhu.jpg b/mover/LeonDev1024/co-learn-2411/images/x_guanzhu.jpg new file mode 100644 index 000000000..9ca23155b Binary files /dev/null and b/mover/LeonDev1024/co-learn-2411/images/x_guanzhu.jpg differ diff --git "a/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\270\200\345\221\250\345\255\246\344\271\240\350\256\260\345\275\225.png" "b/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\270\200\345\221\250\345\255\246\344\271\240\350\256\260\345\275\225.png" new file mode 100644 index 000000000..1294399af Binary files /dev/null and "b/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\270\200\345\221\250\345\255\246\344\271\240\350\256\260\345\275\225.png" differ diff --git "a/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\270\211\345\221\250\347\233\264\346\222\255\345\255\246\344\271\240.png" "b/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\270\211\345\221\250\347\233\264\346\222\255\345\255\246\344\271\240.png" new file mode 100644 index 000000000..a22dad604 Binary files /dev/null and "b/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\270\211\345\221\250\347\233\264\346\222\255\345\255\246\344\271\240.png" differ diff --git "a/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\272\214\345\221\250\345\255\246\344\271\240\346\210\252\345\233\276.png" "b/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\272\214\345\221\250\345\255\246\344\271\240\346\210\252\345\233\276.png" new file mode 100644 index 000000000..4d0f6ce9e Binary files /dev/null and "b/mover/LeonDev1024/co-learn-2411/images/\347\254\254\344\272\214\345\221\250\345\255\246\344\271\240\346\210\252\345\233\276.png" differ diff --git a/mover/LeonDev1024/co-learn-2411/readme.md b/mover/LeonDev1024/co-learn-2411/readme.md index 889a8819f..3ff2a0cfb 100644 --- a/mover/LeonDev1024/co-learn-2411/readme.md +++ b/mover/LeonDev1024/co-learn-2411/readme.md @@ -10,9 +10,9 @@ ## 每周课程学习 -- [] 第一周:![学习记录截图](./images/你的图片地址) -- [] 第二周:![学习记录截图](./images/你的图片地址) -- [] 第三周:![学习记录截图](./images/你的图片地址) +- [x] 第一周:![学习记录截图](./images/第一周学习记录.png) +- [x] 第二周:![学习记录截图](./images/第二周学习截图.png) +- [x] 第三周:![学习记录截图](./images/第三周直播学习.png) - [] 第四周:![学习记录截图](./images/你的图片地址) ## 参加直播答疑 @@ -25,14 +25,14 @@ ## 群里分享学习笔记 - [x] [第一篇笔记](../notes/task4/readme.md) -- [] 第二篇笔记 +- [x] [第二篇笔记](../notes/taskt/readme.md) - [] 第三篇笔记 - [] 第四篇笔记 ## 对外输出学习笔记 - [x] 第一篇笔记【https://learnblockchain.cn/article/9899】 -- [] 第二篇笔记【学习笔记链接】 +- [x] 第二篇笔记【https://learnblockchain.cn/article/9968】 - [] 第三篇笔记【学习笔记链接】 - [] 第四篇笔记【学习笔记链接】 diff --git a/mover/LeonDev1024/code/task5/LeonDev1024/Move.lock b/mover/LeonDev1024/code/task5/LeonDev1024/Move.lock new file mode 100644 index 000000000..3e61a4640 --- /dev/null +++ b/mover/LeonDev1024/code/task5/LeonDev1024/Move.lock @@ -0,0 +1,52 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "1049038A46FD51A3B4DFB943C2E8C4D463DEFCDC8A02216DD081D0491C946185" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "faucet_coin", name = "faucet_coin" }, + { id = "my_coin", name = "my_coin" }, +] + +[[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 = "faucet_coin" +source = { local = "..\\faucet_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "my_coin" +source = { local = "..\\my_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 = "0xea75b8e26aefbace54c8c434070c1c655c0341f5dbb1aed28b229761393bb958" +latest-published-id = "0xea75b8e26aefbace54c8c434070c1c655c0341f5dbb1aed28b229761393bb958" +published-version = "1" diff --git a/mover/LeonDev1024/code/task5/LeonDev1024/Move.toml b/mover/LeonDev1024/code/task5/LeonDev1024/Move.toml new file mode 100644 index 000000000..e84e939b3 --- /dev/null +++ b/mover/LeonDev1024/code/task5/LeonDev1024/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "LeonDev1024" +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://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } +faucet_coin = { local = "../faucet_coin" } +my_coin = { local = "../my_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] +leondev1024 = "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/LeonDev1024/code/task5/LeonDev1024/sources/leondev1024.move b/mover/LeonDev1024/code/task5/LeonDev1024/sources/leondev1024.move new file mode 100644 index 000000000..61d032291 --- /dev/null +++ b/mover/LeonDev1024/code/task5/LeonDev1024/sources/leondev1024.move @@ -0,0 +1,153 @@ +/* +/// Module: leondev1024 +module leondev1024::leondev1024; +swap 必须是 swap 自己发行的 task2 两个 Coin的互换,包名必须是自己的github id +task2铸造的my_coin和faucet_coin的swap, +*/ +module leondev1024::leondev1024 { + // 导入必要的模块 + use sui::object::{Self, UID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + use sui::coin::{Self, Coin}; + use sui::balance::{Self, Balance}; + use sui::event; + use std::string::{Self, String}; + + // 导入自定义的代币模块 + use my_coin::leon_dev_1024_coin::LEON_DEV_1024_COIN; + use faucet_coin::leon_dev_1024_faucet_coin::LEON_DEV_1024_FAUCET_COIN; + + // 定义错误码, 流动性不足,金额为零 + const E_INSUFFICIENT_LIQUIDITY: u64 = 0; + const E_ZERO_AMOUNT: u64 = 1; + + // 流动性池结构体 + public struct Pool has key { + id: UID, + // 代币A的余额 + coin_a: Balance, + // 代币B的余额 + coin_b: Balance, + } + + // 添加流动性事件结构体 + public struct LiquidityEvent has copy, drop { + provider: address, + coin_a_amount: u64, + coin_b_amount: u64, + coin_a_type: String, + coin_b_type: String, + timestamp: u64, + } + + // 交换事件结构体 + public struct SwapEvent has copy, drop { + sender: address, + coin_in_amount: u64, + coin_out_amount: u64, + coin_in_type: String, + coin_out_type: String, + timestamp: u64, + } + + // 初始化函数,创建一个新的流动性池 + fun init(ctx: &mut TxContext) { + let pool = Pool { + id: object::new(ctx), + coin_a: balance::zero(), + coin_b: balance::zero(), + }; + transfer::share_object(pool); + } + + // 添加流动性函数 + public entry fun add_liquidity( + pool: &mut Pool, + coin_a: Coin, + coin_b: Coin, + ctx: &mut TxContext + ) { + let a_amount = coin::value(&coin_a); + let b_amount = coin::value(&coin_b); + + // 确保提供的代币数量大于零 + assert!(a_amount > 0 && b_amount > 0, E_ZERO_AMOUNT); + + balance::join(&mut pool.coin_a, coin::into_balance(coin_a)); + balance::join(&mut pool.coin_b, coin::into_balance(coin_b)); + + // 记录添加流动性的事件 + event::emit(LiquidityEvent + { + provider: tx_context::sender(ctx), + coin_a_amount: a_amount, + coin_b_amount: b_amount, + coin_a_type: string::utf8(b"LEON_DEV_1024_COIN"), + coin_b_type: string::utf8(b"LEON_DEV_1024_FAUCET_COIN"), + timestamp: tx_context::epoch(ctx), + }) + } + + // 代币A换代币B的函数 + public entry fun swap_a_to_b(pool: &mut Pool, coin_a_in: Coin, ctx: &mut TxContext) { + let a_amount = coin::value(&coin_a_in); + assert!(a_amount > 0, E_ZERO_AMOUNT); + + let b_reserve = balance::value(&pool.coin_b); + assert!(b_reserve > 0, E_INSUFFICIENT_LIQUIDITY); + + let a_reserve = balance::value(&pool.coin_a); + let b_out = (a_amount * b_reserve) / (a_reserve + a_amount); + + assert!(b_out > 0 && b_out <= b_reserve, E_INSUFFICIENT_LIQUIDITY); + + // change + balance::join(&mut pool.coin_a, coin::into_balance(coin_a_in)); + let coin_b_out = coin::take(&mut pool.coin_b, b_out, ctx); + transfer::public_transfer(coin_b_out, tx_context::sender(ctx)); + + event::emit(SwapEvent { + sender: tx_context::sender(ctx), + coin_in_amount: a_amount, + coin_out_amount: b_out, + coin_in_type: string::utf8(b"LEON_DEV_1024_COIN"), + coin_out_type: string::utf8(b"LEON_DEV_1024_FAUCET_COIN"), + timestamp: tx_context::epoch(ctx), + }); + } + + // 代币B LEON_DEV_1024_FAUCET_COIN 换代币A LEON_DEV_1024_COIN的函数 + public entry fun swap_b_to_a(pool: &mut Pool, coin_b_in: Coin, + ctx: &mut TxContext) { + let b_amount = coin::value(&coin_b_in); + // 确保输入的代币数量大于零 + assert!(b_amount > 0, E_ZERO_AMOUNT); + + let a_reserve = balance::value(&pool.coin_a); + // 确保可以换取的代币A数量有效 + assert!(a_reserve > 0, E_INSUFFICIENT_LIQUIDITY); + + let b_reserve = balance::value(&pool.coin_b); + let a_out = (b_amount * a_reserve) / (b_reserve + b_amount); + + assert!(a_out > 0 && a_out <= a_reserve, E_INSUFFICIENT_LIQUIDITY); + + // 更新流动性池的余额 + balance::join(&mut pool.coin_b, coin::into_balance(coin_b_in)); + let coin_a_out = coin::take(&mut pool.coin_a, a_out, ctx); + transfer::public_transfer(coin_a_out, tx_context::sender(ctx)); + + event::emit(SwapEvent { + sender: tx_context::sender(ctx), + coin_in_amount: b_amount, + coin_out_amount: a_out, + coin_in_type: string::utf8(b"LEON_DEV_1024_FAUCET_COIN"), + coin_out_type: string::utf8(b"LEON_DEV_1024_COIN"), + timestamp: tx_context::epoch(ctx), + }); + } +} + + + diff --git a/mover/LeonDev1024/code/task5/LeonDev1024/tests/leondev1024_tests.move b/mover/LeonDev1024/code/task5/LeonDev1024/tests/leondev1024_tests.move new file mode 100644 index 000000000..e3195e98c --- /dev/null +++ b/mover/LeonDev1024/code/task5/LeonDev1024/tests/leondev1024_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module leondev1024::leondev1024_tests; +// uncomment this line to import the module +// use leondev1024::leondev1024; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_leondev1024() { + // pass +} + +#[test, expected_failure(abort_code = ::leondev1024::leondev1024_tests::ENotImplemented)] +fun test_leondev1024_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/LeonDev1024/notes/task5/asserts/add_liquidity.png b/mover/LeonDev1024/notes/task5/asserts/add_liquidity.png new file mode 100644 index 000000000..4a62ef74c Binary files /dev/null and b/mover/LeonDev1024/notes/task5/asserts/add_liquidity.png differ diff --git a/mover/LeonDev1024/notes/task5/asserts/balance.png b/mover/LeonDev1024/notes/task5/asserts/balance.png new file mode 100644 index 000000000..5d8c5cdb5 Binary files /dev/null and b/mover/LeonDev1024/notes/task5/asserts/balance.png differ diff --git a/mover/LeonDev1024/notes/task5/asserts/coin_a_object.png b/mover/LeonDev1024/notes/task5/asserts/coin_a_object.png new file mode 100644 index 000000000..12420b514 Binary files /dev/null and b/mover/LeonDev1024/notes/task5/asserts/coin_a_object.png differ diff --git a/mover/LeonDev1024/notes/task5/asserts/coin_b_object.png b/mover/LeonDev1024/notes/task5/asserts/coin_b_object.png new file mode 100644 index 000000000..ac6a3507d Binary files /dev/null and b/mover/LeonDev1024/notes/task5/asserts/coin_b_object.png differ diff --git a/mover/LeonDev1024/notes/task5/asserts/swap_a_to_b.png b/mover/LeonDev1024/notes/task5/asserts/swap_a_to_b.png new file mode 100644 index 000000000..279141709 Binary files /dev/null and b/mover/LeonDev1024/notes/task5/asserts/swap_a_to_b.png differ diff --git a/mover/LeonDev1024/notes/task5/asserts/swap_b_to_a.png b/mover/LeonDev1024/notes/task5/asserts/swap_b_to_a.png new file mode 100644 index 000000000..0679402cb Binary files /dev/null and b/mover/LeonDev1024/notes/task5/asserts/swap_b_to_a.png differ diff --git a/mover/LeonDev1024/notes/task5/readme.md b/mover/LeonDev1024/notes/task5/readme.md new file mode 100644 index 000000000..45ebe01ef --- /dev/null +++ b/mover/LeonDev1024/notes/task5/readme.md @@ -0,0 +1,264 @@ +# 05. move_swap + +# **实现一个最简单的swap** + +- 上链网络: 主网(mainnet) + +## **需求** + +- 完成 Swap相关知识的学习 +- 完成第一个Swap合约的上链部署 +- swap 必须是 swap 自己发行的 task2 两个 Coin的互换,包名必须是自己的`github id` + +## **一、Swap合约基本概念** + +Swap合约通常用于实现两种或多种代币之间的交换。以下是Swap合约的一些基本概念: + +### **1.1. 交易池(Liquidity Pools)** + +- 交易池是 Swap 操作的核心基础设施。它通常包含两种不同类型的资产(比如两种不同的加密货币或数字资产),这些资产由用户提供流动性而汇聚在池中。 +- 例如,一个常见的交易池可能包含资产 A 和资产 B,用户可以将自己持有的一定数量的资产 A 和资产 B 存入池中,增加池的流动性,以便后续其他用户进行交换操作。 + +### **1.2. 流动性提供者(Liquidity Providers)** + +- 流动性提供者是向交易池注入资产的用户或合约。他们通过存入两种相关资产到交易池,使得池中有足够的资产可供其他用户进行交换。 +- 作为回报,流动性提供者通常会获得交易手续费的一部分或者其他形式的激励,具体取决于 Swap 机制的设计。 + +### **1.3. 交换比率(Swap Ratio)** + +- 在 Swap 操作中,交换比率决定了一种资产可以换取另一种资产的数量。它不是固定不变的,而是根据交易池中两种资产的储备量动态变化。 +- 例如,如果交易池中资产 A 的储备量相对较多,资产 B 的储备量相对较少,那么用资产 A 换取资产 B 时,可能需要付出相对较多的资产 A 才能换取到一定量的资产 B,反之亦然。这个比率的计算通常基于数学公式,比如恒定乘积公式(Constant Product Formula)等,以确保交易池的总价值在每次交换后保持相对稳定。 + +## **二、Sui Move 中实现 Swap 的关键要素** + +### **2.1. 资产类型定义** + +在 Sui Move 代码中,首先需要明确定义参与 Swap 的资产类型。这通常涉及到创建自定义的资源类型来代表不同的数字资产。 + +```rust + // 导入自定义的代币模块 + use my_coin::leon_dev_1024_coin::LEON_DEV_1024_COIN; + use faucet_coin::leon_dev_1024_faucet_coin::LEON_DEV_1024_FAUCET_COIN; +``` + +### **2.2. 交易池结构体定义** + +```rust + // 流动性池结构体 + public struct Pool has key { + id: UID, + // 代币A的余额 + coin_a: Balance, + // 代币B的余额 + coin_b: Balance, + } +``` + +### **2.3. 交换函数实现** + +实现 Swap 操作的核心是编写交换函数。以从资产 A 交换到资产 B 为例 + +## **三、Swap 操作的流程** + +### 3.1 **定义模块和导入必要的库** + +```rust +module leondev1024::swap { + use sui::object::{Self, UID}; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + use sui::coin::{Self, Coin}; + use sui::balance::{Self, Balance}; + use sui::event; + use std::string::{Self, String}; + + // 导入自定义的代币模块 + use my_coin::leon_dev_1024_coin::LEON_DEV_1024_COIN; + use faucet_coin::leon_dev_1024_faucet_coin::LEON_DEV_1024_FAUCET_COIN; +} +``` + +### 3.1. **定义错误码** + +定义一些常量来表示可能的错误情况,例如流动性不足或金额为零。 + +```rust +const E_INSUFFICIENT_LIQUIDITY: u64 = 0; +const E_ZERO_AMOUNT: u64 = 1; +``` + +### **3.3. 定义结构体** + +定义一个结构体来表示流动性池,并定义事件结构体来记录添加流动性和交换代币的操作。 + +```rust +// 流动性池结构体 +public struct Pool has key { + id: UID, // 流动性池的唯一标识符 + coin_a: Balance, // 代币A的余额 + coin_b: Balance, // 代币B的余额 +} + +// 添加流动性事件结构体 +public struct LiquidityEvent has copy, drop { + provider: address, // 提供流动性的地址 + coin_a_amount: u64, // 代币A的数量 + coin_b_amount: u64, // 代币B的数量 + coin_a_type: String, // 代币A的类型 + coin_b_type: String, // 代币B的类型 + timestamp: u64, // 时间戳 +} + +// 交换事件结构体 +public struct SwapEvent has copy, drop { + sender: address, // 发起交换的地址 + coin_in_amount: u64, // 输入代币的数量 + coin_out_amount: u64, // 输出代币的数量 + coin_in_type: String, // 输入代币的类型 + coin_out_type: String, // 输出代币的类型 + timestamp: u64, // 时间戳 +} +``` + +### 3.4. **初始化函数** + +定义一个初始化函数来创建一个新的流动性池。 + +```rust +// 初始化函数,创建一个新的流动性池 +fun init(ctx: &mut TxContext) { + let pool = Pool { + id: object::new(ctx), // 生成新的唯一标识符 + coin_a: balance::zero(), // 初始代币A的余额为零 + coin_b: balance::zero(), // 初始代币B的余额为零 + }; + transfer::share_object(pool); // 将流动性池共享 +} +``` + +### 3.5  **添加流动性函数** + +定义一个函数来允许用户向流动性池中添加两种代币。 + +```rust +// 添加流动性函数 +public entry fun add_liquidity( + pool: &mut Pool, + coin_a: Coin, + coin_b: Coin, + ctx: &mut TxContext +) { + let a_amount = coin::value(&coin_a); // 获取代币A的数量 + let b_amount = coin::value(&coin_b); // 获取代币B的数量 + + assert!(a_amount > 0 && b_amount > 0, E_ZERO_AMOUNT); // 确保提供的代币数量大于零 + + balance::join(&mut pool.coin_a, coin::into_balance(coin_a)); // 将代币A加入流动性池 + balance::join(&mut pool.coin_b, coin::into_balance(coin_b)); // 将代币B加入流动性池 + + // 记录添加流动性的事件 + event::emit(LiquidityEvent { + provider: tx_context::sender(ctx), // 提供流动性的地址 + coin_a_amount: a_amount, // 代币A的数量 + coin_b_amount: b_amount, // 代币B的数量 + coin_a_type: string::utf8(b"LEON_DEV_1024_COIN"), // 代币A的类型 + coin_b_type: string::utf8(b"LEON_DEV_1024_FAUCET_COIN"), // 代币B的类型 + timestamp: tx_context::epoch(ctx), // 当前时间戳 + }); +} +``` + +### 3.6 **代币交换函数** + +定义两个函数来实现代币A换代币B和代币B换代币A的功能。 + +```rust +// 代币A换代币B的函数 +public entry fun swap_a_to_b( + pool: &mut Pool, + coin_a_in: Coin, + ctx: &mut TxContext +) { + let a_amount = coin::value(&coin_a_in); // 获取输入的代币A的数量 + assert!(a_amount > 0, E_ZERO_AMOUNT); // 确保输入的代币数量大于零 + + let b_reserve = balance::value(&pool.coin_b); // 获取代币B的储备量 + assert!(b_reserve > 0, E_INSUFFICIENT_LIQUIDITY); // 确保代币B的储备量大于零 + + let a_reserve = balance::value(&pool.coin_a); // 获取代币A的储备量 + let b_out = (a_amount * b_reserve) / (a_reserve + a_amount); // 计算可以换取的代币B的数量 + + assert!(b_out > 0 && b_out <= b_reserve, E_INSUFFICIENT_LIQUIDITY); // 确保可以换取的代币B数量有效 + + // 更新流动性池的余额 + balance::join(&mut pool.coin_a, coin::into_balance(coin_a_in)); // 将输入的代币A加入流动性池 + let coin_b_out = coin::take(&mut pool.coin_b, b_out, ctx); // 从流动性池中取出代币B + transfer::public_transfer(coin_b_out, tx_context::sender(ctx)); // 将代币B转给发起者 + + // 记录交换事件 + event::emit(SwapEvent { + sender: tx_context::sender(ctx), // 发起交换的地址 + coin_in_amount: a_amount, // 输入的代币A的数量 + coin_out_amount: b_out, // 输出的代币B的数量 + coin_in_type: string::utf8(b"LEON_DEV_1024_COIN"), // 输入的代币A的类型 + coin_out_type: string::utf8(b"LEON_DEV_1024_FAUCET_COIN"), // 输出的代币B的类型 + timestamp: tx_context::epoch(ctx), // 当前时间戳 + }); +} + +// 代币B换代币A的函数 +public entry fun swap_b_to_a( + pool: &mut Pool, + coin_b_in: Coin, + ctx: &mut TxContext +) { + // 流程同上省略 + …… +} +``` + +## **四、任务指南** + +1. build发布到主网 + +```rust +sui client envs +sui client switch --env mainnet +sui move build --skip-fetch-latest-git-deps +sui client publish --gas-budget 100000000 --skip-fetch-latest-git-deps --skip-dependency-verification +``` + +发布成功后交易摘要 + +Skipping dependency verification +Transaction Digest: 3mKvRG1T5mRyVeEmh7pV12dWnFKfwCvxSjMJimUBkejv + +packageId: 0xea75b8e26aefbace54c8c434070c1c655c0341f5dbb1aed28b229761393bb958 + +pool: 0x95bd6375a79ecc3968af02ce2d9a73a3d852fa29abb3b55b0ce417f761b0725b + +1. 查看余额详细信息 sui client balance --with-coins + + ![image.png](./asserts/balance.png) + +2. 查看coin A 和coin B的详细信息 + + ![image.png](./asserts/coin_b_object.png) + + ![image.png](./asserts/coin_a_object.png) + +3. 加入流通池 + + coin A: 0x63cb0ffd72f6c915f900b3eb65b4fcd01d889187f18a85bec1d9f37078f1b1d1 + + coin B: 0xe312bd896a849be4de39d6ce18dd9d0464b77e7590074b209d24b1edcfd35077 + + ```rust + sui client call --gas-budget 10000000 --package --module swap --function add_liquidity --args + ``` + ![image.png](./asserts/add_liquidity.png) + +4. swap A to B +![image.png](./asserts/swap_a_to_b.png) +5. swap B to A +![image.png](./asserts/swap_b_to_a.png) diff --git a/mover/LeonDev1024/readme.md b/mover/LeonDev1024/readme.md index 8e7285775..560c1b75f 100644 --- a/mover/LeonDev1024/readme.md +++ b/mover/LeonDev1024/readme.md @@ -36,9 +36,9 @@ - [x] play game hash: FD42jvTYqq59CUrMyDC4dLYBc8WvXdC5tjdjQ6XqFryE ## 05 Move Swap -- [] swap package id : -- [] call swap CoinA-> CoinB hash : -- [] call swap CoinB-> CoinA hash : +- [x] swap package id : 0xea75b8e26aefbace54c8c434070c1c655c0341f5dbb1aed28b229761393bb958 +- [x] call swap CoinA-> CoinB hash : Af8PQqaHyWY2aJBkLoCoXq7cn3JdKm5FssvxVV2fJ2Fj +- [x] call swap CoinB-> CoinA hash : 69hyPuAkgFth66EGZ6AC7agkZEwdcr8XjZTaawo6Mbrm ## 06 Dapp-kit SDK PTB - [] save hash :