From 755c9548c189592e48c1c3106aebc740848c395b Mon Sep 17 00:00:00 2001 From: Flax Date: Wed, 4 Dec 2024 23:48:41 +0800 Subject: [PATCH 1/2] task5 --- mover/flatflax/code/task5/Move.toml | 39 +++++ mover/flatflax/code/task5/sources/task5.move | 143 ++++++++++++++++++ .../code/task5/tests/task5_tests.move | 18 +++ mover/flatflax/readme.md | 6 +- 4 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 mover/flatflax/code/task5/Move.toml create mode 100644 mover/flatflax/code/task5/sources/task5.move create mode 100644 mover/flatflax/code/task5/tests/task5_tests.move diff --git a/mover/flatflax/code/task5/Move.toml b/mover/flatflax/code/task5/Move.toml new file mode 100644 index 000000000..5c9d8b5b4 --- /dev/null +++ b/mover/flatflax/code/task5/Move.toml @@ -0,0 +1,39 @@ +[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://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } +faucet_coin = { local = "../task2/faucet_coin" } +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] +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/flatflax/code/task5/sources/task5.move b/mover/flatflax/code/task5/sources/task5.move new file mode 100644 index 000000000..e291e2c4b --- /dev/null +++ b/mover/flatflax/code/task5/sources/task5.move @@ -0,0 +1,143 @@ +/* +/// Module: task5 +module task5::task5; +*/ +module task5::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 mycoin::my_coin::MY_COIN; + use faucet_coin::faucet_coin::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, // 代币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, // 时间戳 + } + + 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); // 将流动性池共享 + } + + 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"MY_COIN"), // 代币A的类型 + coin_b_type: string::utf8(b"FAUCET_COIN"), // 代币B的类型 + timestamp: tx_context::epoch(ctx), // 当前时间戳 + }); + } + + 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"MY_COIN"), // 输入的代币A的类型 + coin_out_type: string::utf8(b"FAUCET_COIN"), // 输出的代币B的类型 + timestamp: tx_context::epoch(ctx), // 当前时间戳 + }); + } + + 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); // 获取输入的代币B的数量 + assert!(b_amount > 0, E_ZERO_AMOUNT); // 确保输入的代币数量大于零 + + let a_reserve = balance::value(&pool.coin_a); // 获取代币A的储备量 + assert!(a_reserve > 0, E_INSUFFICIENT_LIQUIDITY); // 确保代币A的储备量大于零 + + let b_reserve = balance::value(&pool.coin_b); // 获取代币B的储备量 + let a_out = (b_amount * a_reserve) / (b_reserve + b_amount); // 计算可以换取的代币B的数量 + + assert!(a_out > 0 && a_out <= a_reserve, E_INSUFFICIENT_LIQUIDITY); // 确保可以换取的代币B数量有效 + + // 更新流动性池的余额 + balance::join(&mut pool.coin_b, coin::into_balance(coin_b_in)); // 将输入的代币A加入流动性池 + let coin_a_out = coin::take(&mut pool.coin_a, a_out, ctx); // 从流动性池中取出代币A + transfer::public_transfer(coin_a_out, tx_context::sender(ctx)); // 将代币A转给发起者 + + // 记录交换事件 + event::emit(SwapEvent { + sender: tx_context::sender(ctx), // 发起交换的地址 + coin_in_amount: b_amount, // 输入的代币B的数量 + coin_out_amount: a_out, // 输出的代币A的数量 + coin_in_type: string::utf8(b"FAUCET_COIN"), // 输入的代币B的类型 + coin_out_type: string::utf8(b"MY_COIN"), // 输出的代币A的类型 + timestamp: tx_context::epoch(ctx), // 当前时间戳 + }); + } +} \ No newline at end of file diff --git a/mover/flatflax/code/task5/tests/task5_tests.move b/mover/flatflax/code/task5/tests/task5_tests.move new file mode 100644 index 000000000..006cda1f9 --- /dev/null +++ b/mover/flatflax/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/flatflax/readme.md b/mover/flatflax/readme.md index 14d5c39dc..d5b31a0e0 100644 --- a/mover/flatflax/readme.md +++ b/mover/flatflax/readme.md @@ -37,9 +37,9 @@ - [✓] play game hash: G84JB8K1TBEQowPG1srqFLsWTQWANgrWThNjQYpjKaAz ## 05 Move Swap -- [] swap package id : -- [] call swap CoinA-> CoinB hash : -- [] call swap CoinB-> CoinA hash : +- [✓] swap package id : 0x7fed720b4f9239aeaee760eeda592afa07fc3a5ec806b7b3ed132172b30b0a35 +- [✓] call swap CoinA-> CoinB hash :E29EEZFJCer4vH7Wht7yPr1drnSNbrEtKU9YMBSxBJMd +- [✓] call swap CoinB-> CoinA hash :7bnqdQjufjw1fXdEKtfoEtJsETVHqQVJDZ5cjVUVk3wd ## 06 Dapp-kit SDK PTB - [] save hash : From 00834b48e3e5f0b11af37f790e26def2b415381a Mon Sep 17 00:00:00 2001 From: Flax Date: Fri, 6 Dec 2024 22:06:38 +0800 Subject: [PATCH 2/2] task6 --- .../code/task6/my-first-sui-dapp/README.md | 35 +++++ .../code/task6/my-first-sui-dapp/index.html | 59 ++++++++ .../code/task6/my-first-sui-dapp/package.json | 36 +++++ .../my-first-sui-dapp/prettier.config.cjs | 4 + .../code/task6/my-first-sui-dapp/src/App.tsx | 132 ++++++++++++++++++ .../my-first-sui-dapp/src/OwnedObjects.tsx | 42 ++++++ .../my-first-sui-dapp/src/WalletStatus.tsx | 23 +++ .../code/task6/my-first-sui-dapp/src/main.tsx | 26 ++++ .../my-first-sui-dapp/src/networkConfig.ts | 17 +++ .../task6/my-first-sui-dapp/src/vite-env.d.ts | 1 + .../task6/my-first-sui-dapp/tsconfig.json | 25 ++++ .../my-first-sui-dapp/tsconfig.node.json | 10 ++ .../task6/my-first-sui-dapp/vite.config.ts | 7 + mover/flatflax/code/task6/package-lock.json | 6 + mover/flatflax/readme.md | 2 +- 15 files changed, 424 insertions(+), 1 deletion(-) create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/README.md create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/index.html create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/package.json create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/prettier.config.cjs create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/src/App.tsx create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/src/OwnedObjects.tsx create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/src/WalletStatus.tsx create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/src/main.tsx create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/src/networkConfig.ts create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/src/vite-env.d.ts create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.json create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.node.json create mode 100644 mover/flatflax/code/task6/my-first-sui-dapp/vite.config.ts create mode 100644 mover/flatflax/code/task6/package-lock.json diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/README.md b/mover/flatflax/code/task6/my-first-sui-dapp/README.md new file mode 100644 index 000000000..d0889dcae --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/README.md @@ -0,0 +1,35 @@ +# Sui dApp Starter Template + +This dApp was created using `@mysten/create-dapp` that sets up a basic React +Client dApp using the following tools: + +- [React](https://react.dev/) as the UI framework +- [TypeScript](https://www.typescriptlang.org/) for type checking +- [Vite](https://vitejs.dev/) for build tooling +- [Radix UI](https://www.radix-ui.com/) for pre-built UI components +- [ESLint](https://eslint.org/) +- [`@mysten/dapp-kit`](https://sdk.mystenlabs.com/dapp-kit) for connecting to + wallets and loading data +- [pnpm](https://pnpm.io/) for package management + +## Starting your dApp + +To install dependencies you can run + +```bash +pnpm install +``` + +To start your dApp in development mode run + +```bash +pnpm dev +``` + +## Building + +To build your app for deployment you can run + +```bash +pnpm build +``` diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/index.html b/mover/flatflax/code/task6/my-first-sui-dapp/index.html new file mode 100644 index 000000000..bb7f75b16 --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/index.html @@ -0,0 +1,59 @@ + + + + + + + Sui dApp Starter + + + + +
+ + + diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/package.json b/mover/flatflax/code/task6/my-first-sui-dapp/package.json new file mode 100644 index 000000000..e9afb01ee --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/package.json @@ -0,0 +1,36 @@ +{ + "name": "my-first-sui-dapp", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "preview": "vite preview" + }, + "dependencies": { + "@mysten/dapp-kit": "0.14.40", + "@mysten/sui": "1.16.0", + "@radix-ui/colors": "^3.0.0", + "@radix-ui/react-icons": "^1.3.0", + "@radix-ui/themes": "^3.1.1", + "@tanstack/react-query": "^5.50.1", + "navi-sdk": "^1.4.7", + "react": "^18.3.1", + "react-dom": "^18.3.1" + }, + "devDependencies": { + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", + "@typescript-eslint/eslint-plugin": "^7.16.0", + "@typescript-eslint/parser": "^7.16.0", + "@vitejs/plugin-react-swc": "^3.7.0", + "eslint": "^9.6.0", + "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-react-refresh": "^0.4.7", + "prettier": "^3.3.2", + "typescript": "^5.5.3", + "vite": "^5.3.3" + } +} diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/prettier.config.cjs b/mover/flatflax/code/task6/my-first-sui-dapp/prettier.config.cjs new file mode 100644 index 000000000..c07541106 --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/prettier.config.cjs @@ -0,0 +1,4 @@ +// eslint-disable-next-line no-undef +module.exports = { + proseWrap: "always", +}; diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/src/App.tsx b/mover/flatflax/code/task6/my-first-sui-dapp/src/App.tsx new file mode 100644 index 000000000..65c68c97f --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/src/App.tsx @@ -0,0 +1,132 @@ +import { ConnectButton } from "@mysten/dapp-kit"; +import { WalletStatus } from "./WalletStatus"; +import { Button, Container, Flex, Text, Box, Heading } from "@radix-ui/themes"; // 导入 Radix UI 组件 +import { useCurrentAccount, useSignAndExecuteTransaction } from "@mysten/dapp-kit"; // 导入 Mysten DApp Kit 钩子 +import { Transaction } from "@mysten/sui/transactions"; // 导入 Sui 交易类 +import { Pool, PoolConfig } from "navi-sdk/dist/types"; // 导入 Navi SDK 中的池和池配置类型 +import { pool, Sui, wUSDC } from "navi-sdk/dist/address"; // 导入 Navi SDK 中的池地址和代币信息 +import { borrowCoin, depositCoin } from "navi-sdk/dist/libs/PTB"; // 导入 Navi SDK 中的借币和存币函数 +import { useState } from "react"; + +// 计算借款金额 +const calculateBorrowAmount = (month: number, day: number, hour: number): number => { + const borrowAmountStr = `0.${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${hour.toString().padStart(2, "0")}`; + return parseFloat(borrowAmountStr) * 10 ** wUSDC.decimal; +}; + +// 处理存款和借款的异步函数 +const depositAndBorrowSui = async (account: any, signAndExecuteTransaction: any, setMessage: any, setDigest: any) => { + if (!account) { + setMessage("Please connect your wallet first"); + return; + } + + try { + const date = new Date(); // 获取当前日期 + const borrowAmount = calculateBorrowAmount(date.getMonth() + 1, date.getDate(), date.getHours()); + + // 创建新的交易对象 + const tx = new Transaction(); + tx.setSender(account.address); + + // 获取池配置 + const suiPool: PoolConfig = pool[Sui.symbol as keyof Pool]; + const wusdcPool: PoolConfig = pool[wUSDC.symbol as keyof Pool]; + + if (!suiPool || !wusdcPool) { + throw new Error("Invalid pool configuration"); + } + + // 存款 SUI + const [suiCoin] = tx.splitCoins(tx.gas, [1_000_000_000]); // 分割 SUI 代币 + if (!suiCoin) throw new Error("Failed to split SUI coins"); + + await depositCoin(tx, suiPool, suiCoin, 1_000_000_000); // 存款 SUI + + // 借款 USDC + const [toBorrowCoin] = await borrowCoin(tx, wusdcPool, borrowAmount); + if (!toBorrowCoin) throw new Error("Failed to borrow USDC"); + + // 存款借出的 USDC + await depositCoin(tx, wusdcPool, toBorrowCoin, borrowAmount); + + // 清除之前的消息 + setMessage(""); + setDigest(""); + + // 签名并执行交易 + signAndExecuteTransaction( + { transaction: tx, chain: "sui:mainnet" }, + { + // onSuccess: (result: any) => { // 移除或注释掉 + // console.log("Transaction successful:", result); + // setDigest(result.digest); + // }, + onError: (error: any) => { // 为 error 参数指定类型 + console.error("Transaction failed:", error); + setMessage(error.message || "Transaction failed"); + }, + } + ); + } catch (error) { + console.error("Error in depositAndBorrowSui:", error); + setMessage(error instanceof Error ? error.message : "An unknown error occurred"); + } +}; + +export function NaviPTB() { + const account = useCurrentAccount(); + const { mutate: signAndExecuteTransaction } = useSignAndExecuteTransaction(); + const [digest, setDigest] = useState(""); + const [message, setMessage] = useState(""); + + return ( + <> + + + dApp Starter Template + + + + + + + + + + + + + + Navi Protocol 任务 + + 任务将会把 1 SUI 存入 Navi 协议,根据当前日期借出相应数量的 USDC,然后存入等额的 USDC。 + + + + {digest && Transaction submitted: {digest}} {/* 显示交易摘要 */} + {message && Error: {message}} {/* 显示错误消息 */} + + + + + ); +} + +export default NaviPTB; + diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/src/OwnedObjects.tsx b/mover/flatflax/code/task6/my-first-sui-dapp/src/OwnedObjects.tsx new file mode 100644 index 000000000..fa759db0a --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/src/OwnedObjects.tsx @@ -0,0 +1,42 @@ +import { useCurrentAccount, useSuiClientQuery } from "@mysten/dapp-kit"; +import { Flex, Heading, Text } from "@radix-ui/themes"; + +export function OwnedObjects() { + const account = useCurrentAccount(); + const { data, isPending, error } = useSuiClientQuery( + "getOwnedObjects", + { + owner: account?.address as string, + }, + { + enabled: !!account, + }, + ); + + if (!account) { + return; + } + + if (error) { + return Error: {error.message}; + } + + if (isPending || !data) { + return Loading...; + } + + return ( + + {data.data.length === 0 ? ( + No objects owned by the connected wallet + ) : ( + Objects owned by the connected wallet + )} + {data.data.map((object) => ( + + Object ID: {object.data?.objectId} + + ))} + + ); +} diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/src/WalletStatus.tsx b/mover/flatflax/code/task6/my-first-sui-dapp/src/WalletStatus.tsx new file mode 100644 index 000000000..21e734677 --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/src/WalletStatus.tsx @@ -0,0 +1,23 @@ +import { useCurrentAccount } from "@mysten/dapp-kit"; +import { Container, Flex, Heading, Text } from "@radix-ui/themes"; +import { OwnedObjects } from "./OwnedObjects"; + +export function WalletStatus() { + const account = useCurrentAccount(); + + return ( + + Wallet Status + + {account ? ( + + Wallet connected + Address: {account.address} + + ) : ( + Wallet not connected + )} + + + ); +} diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/src/main.tsx b/mover/flatflax/code/task6/my-first-sui-dapp/src/main.tsx new file mode 100644 index 000000000..f60810b51 --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/src/main.tsx @@ -0,0 +1,26 @@ +import React from "react"; +import ReactDOM from "react-dom/client"; +import "@mysten/dapp-kit/dist/index.css"; +import "@radix-ui/themes/styles.css"; + +import { SuiClientProvider, WalletProvider } from "@mysten/dapp-kit"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { Theme } from "@radix-ui/themes"; +import App from "./App.tsx"; +import { networkConfig } from "./networkConfig.ts"; + +const queryClient = new QueryClient(); + +ReactDOM.createRoot(document.getElementById("root")!).render( + + + + + + + + + + + , +); \ No newline at end of file diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/src/networkConfig.ts b/mover/flatflax/code/task6/my-first-sui-dapp/src/networkConfig.ts new file mode 100644 index 000000000..96de92158 --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/src/networkConfig.ts @@ -0,0 +1,17 @@ +import { getFullnodeUrl } from "@mysten/sui/client"; +import { createNetworkConfig } from "@mysten/dapp-kit"; + +const { networkConfig, useNetworkVariable, useNetworkVariables } = + createNetworkConfig({ + devnet: { + url: getFullnodeUrl("devnet"), + }, + testnet: { + url: getFullnodeUrl("testnet"), + }, + mainnet: { + url: getFullnodeUrl("mainnet"), + }, + }); + +export { useNetworkVariable, useNetworkVariables, networkConfig }; diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/src/vite-env.d.ts b/mover/flatflax/code/task6/my-first-sui-dapp/src/vite-env.d.ts new file mode 100644 index 000000000..11f02fe2a --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.json b/mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.json new file mode 100644 index 000000000..a7fc6fbf2 --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.node.json b/mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.node.json new file mode 100644 index 000000000..42872c59f --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/mover/flatflax/code/task6/my-first-sui-dapp/vite.config.ts b/mover/flatflax/code/task6/my-first-sui-dapp/vite.config.ts new file mode 100644 index 000000000..d366e8c8d --- /dev/null +++ b/mover/flatflax/code/task6/my-first-sui-dapp/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react-swc"; + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], +}); diff --git a/mover/flatflax/code/task6/package-lock.json b/mover/flatflax/code/task6/package-lock.json new file mode 100644 index 000000000..a66c74aff --- /dev/null +++ b/mover/flatflax/code/task6/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "task6", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/mover/flatflax/readme.md b/mover/flatflax/readme.md index d5b31a0e0..515d214a3 100644 --- a/mover/flatflax/readme.md +++ b/mover/flatflax/readme.md @@ -42,7 +42,7 @@ - [✓] call swap CoinB-> CoinA hash :7bnqdQjufjw1fXdEKtfoEtJsETVHqQVJDZ5cjVUVk3wd ## 06 Dapp-kit SDK PTB -- [] save hash : +- [✓] save hash :85pd6XVVtoRQuAisJK7YiQpEVaoF9tby4boCFAApPwrs ## 07 Move CTF Check In - [] CLI call 截图 : ![截图](./images/你的图片地址)