diff --git a/mover/looikaizhi/code/task5/swapToken/Move.lock b/mover/looikaizhi/code/task5/swapToken/Move.lock deleted file mode 100644 index 2b6c39dd7..000000000 --- a/mover/looikaizhi/code/task5/swapToken/Move.lock +++ /dev/null @@ -1,40 +0,0 @@ -# @generated by Move, please check-in and do not edit manually. - -[move] -version = 3 -manifest_digest = "350D36428AF0462D1E0B80838030324B93938CE450C6D56F72E8C77586BB3312" -deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" -dependencies = [ - { id = "Sui", name = "Sui" }, -] - -[[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.toolchain-version] -compiler-version = "1.36.2" -edition = "2024.beta" -flavor = "sui" - -[env] - -[env.testnet] -chain-id = "4c78adac" -original-published-id = "0xae4645de8b60924743fc235a4f40dcee5962ac25da8aefd320f37b2e73abbda7" -latest-published-id = "0xae4645de8b60924743fc235a4f40dcee5962ac25da8aefd320f37b2e73abbda7" -published-version = "1" - -[env.mainnet] -chain-id = "35834a8a" -original-published-id = "0x7dc5327fca61071f686cfe891049b92921f886ec698d6c86ccdba6fe9c350693" -latest-published-id = "0x7dc5327fca61071f686cfe891049b92921f886ec698d6c86ccdba6fe9c350693" -published-version = "1" diff --git a/mover/looikaizhi/code/task6/dapp/src/App.tsx b/mover/looikaizhi/code/task6/dapp/src/App.tsx new file mode 100644 index 000000000..589ee9885 --- /dev/null +++ b/mover/looikaizhi/code/task6/dapp/src/App.tsx @@ -0,0 +1,40 @@ +import { ConnectButton} from "@mysten/dapp-kit"; +import { Box, Container, Flex, Heading } from "@radix-ui/themes"; +import NaviProtocol from "./NaviProtocol.tsx"; + +function App() { + + return ( + <> + + + NaviProtocol + + + + + + + + + + + + + ); +} + +export default App; diff --git a/mover/looikaizhi/code/task6/dapp/src/NaviProtocol.tsx b/mover/looikaizhi/code/task6/dapp/src/NaviProtocol.tsx new file mode 100644 index 000000000..50e673e93 --- /dev/null +++ b/mover/looikaizhi/code/task6/dapp/src/NaviProtocol.tsx @@ -0,0 +1,76 @@ +import {useCurrentAccount, useSignAndExecuteTransaction} from "@mysten/dapp-kit"; +import {Transaction} from "@mysten/sui/transactions"; +import {pool, wUSDC, Sui, depositCoin, borrowCoin} from "navi-sdk"; +import {Pool} from "navi-sdk/dist/types"; +import {Button} from "@radix-ui/themes"; + +const NaviProtocol = () =>{ + const {mutate: signAndExecuteTransaction} = useSignAndExecuteTransaction(); + const account = useCurrentAccount(); + + const handleButtonClick = async () =>{ + if(!account){ + alert("Please connect wallet"); + return; + } + + const txb = new Transaction(); + if(account?.address){ + txb.setSender(account?.address); + }else{ + console.error("No account address found"); + alert("Wallet connection error"); + return; + } + + try{ + const deposit_Amount = 1_000_000_000; + const suiPool = pool[Sui.symbol as keyof Pool]; + const coin = txb.splitCoins(txb.gas, [deposit_Amount]); + + // 1. 先存入 SUI + await depositCoin(txb, suiPool, coin, deposit_Amount); + + // 2. 计算 USDC 金额 + const date_Format = (num: number) => (num < 10 ? `0${num}` : num); + const date = new Date(); + const month = date_Format(date.getMonth()); + const day = date_Format(date.getDate()); + const hour = date_Format(date.getHours()); + const amount = Number(`0.${month}${day}${hour}`); + + // 3. 借入并直接存入 USDC + const wusdcPool = pool[wUSDC.symbol as keyof Pool]; + const borrow_amount = amount * Math.pow(10, wUSDC.decimal); + const [borrowedCoin] = await borrowCoin(txb, wusdcPool, borrow_amount); + + // 4. 直接将借到的 USDC 存入池子,不经过钱包 + await depositCoin(txb, wusdcPool, borrowedCoin, borrow_amount); + + await signAndExecuteTransaction( + { transaction: txb }, + { + onSuccess: (response) => { + console.log("Transaction successful:", response); + alert("Successfully deposited SUI and USDC!"); + }, + onError: (error) => { + console.error("Transaction failed:", error); + alert(`Transaction failed: ${error.message}`); + }, + } + ); + } catch(error) { + console.error("Transaction error:", error); + alert(`Failed to execute transaction: ${error.message}`); + } + }; + return( +
+ +
+ ) +} +export default NaviProtocol; diff --git a/mover/looikaizhi/code/task6/dapp/src/main.tsx b/mover/looikaizhi/code/task6/dapp/src/main.tsx new file mode 100644 index 000000000..db3a81acc --- /dev/null +++ b/mover/looikaizhi/code/task6/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( + + + + + + + + + + + , +); diff --git a/mover/looikaizhi/code/task6/dapp/src/task7.ts b/mover/looikaizhi/code/task6/dapp/src/task7.ts new file mode 100644 index 000000000..e69de29bb diff --git a/mover/looikaizhi/code/task6/dapp/src/task8.ts b/mover/looikaizhi/code/task6/dapp/src/task8.ts new file mode 100644 index 000000000..e69de29bb diff --git a/mover/looikaizhi/readme.md b/mover/looikaizhi/readme.md index 5b8d719bf..a5d5a92c3 100644 --- a/mover/looikaizhi/readme.md +++ b/mover/looikaizhi/readme.md @@ -44,7 +44,7 @@ - [x] call swap CoinB-> CoinA hash : `HgdnAhdH6Z24UmpAQ5PEScNCVpzvdKpvzEREhoB9yBjk` ## 06 Dapp-kit SDK PTB -- [] save hash : +- [x] save hash : `4tXQJ9i55KWrTbp3to2xtSeckkAVTrkbEuq32iY5dLds` ## 07 Move CTF Check In - [] CLI call 截图 : ![截图](./images/你的图片地址)