From d196d34181c15ad94393bc39db771bbb261b0214 Mon Sep 17 00:00:00 2001 From: qwrdxer <1944270374@qq.com> Date: Tue, 10 Dec 2024 12:04:58 +0000 Subject: [PATCH] task6 --- mover/qwrdxer/code/task6/core.tsx | 60 +++++++++++++++++++++++++++++++ mover/qwrdxer/readme.md | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 mover/qwrdxer/code/task6/core.tsx diff --git a/mover/qwrdxer/code/task6/core.tsx b/mover/qwrdxer/code/task6/core.tsx new file mode 100644 index 000000000..c292f8b18 --- /dev/null +++ b/mover/qwrdxer/code/task6/core.tsx @@ -0,0 +1,60 @@ + +import { useSignAndExecuteTransaction } from "@mysten/dapp-kit"; +import { Transaction } from "@mysten/sui/transactions"; +import { Box, Button, Container, Text } from "@radix-ui/themes"; +import { nUSDC, pool } from 'navi-sdk/dist/address'; +import { borrowCoin, depositCoin } from "navi-sdk/dist/libs/PTB"; + +//构建交易 +// 1.[存入Navi Protocol 1 SUI] +// 2.[借出当前日期的USDC 0.[月][天][小时] 的 USDC ] +// 3.[然后在存入等额的USDC] + + +//计算借款金额的函数 +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 ** nUSDC.decimal; +}; +export function Navitask() { + + // const currentAccount = useCurrentAccount(); + const { mutate: signAndExecuteTransaction } = useSignAndExecuteTransaction(); + + const navitaskexecute = async () => { + //变量定义 + const tx = new Transaction(); + const date = new Date(); // 获取当前日期 + const borrowamount = calculateBorrowAmount(date.getMonth() + 1, date.getDate(), date.getHours()); + try { + //1. 存入navi 1sui + const [depositcoin] = tx.splitCoins(tx.gas, [1_000_000_000]); + await depositCoin(tx, pool.Sui, depositcoin, 1_000_000_000); + //2. 借出nUSDC + const [borrowedcoin] = await borrowCoin(tx, pool.nUSDC, borrowamount); + //[然后在存入等额的USDC] + await depositCoin(tx, pool.nUSDC, borrowedcoin, borrowamount); + + //签名并交易 + signAndExecuteTransaction({ transaction: tx, chain: "sui:mainnet" }, { + onError: (error: any) => { + console.log(error) + } + }) + } catch (err) { + console.log(err) + } + + } + return ( + <> + + Navi任务:1.[存入Navi Protocol 1 SUI] 2.[借出当前日期的USDC 0.[月][天][小时] 的 USDC ] 3.[然后在存入等额的USDC] + + + + + + + ) +} \ No newline at end of file diff --git a/mover/qwrdxer/readme.md b/mover/qwrdxer/readme.md index fc8bed82b..fe0c977b8 100644 --- a/mover/qwrdxer/readme.md +++ b/mover/qwrdxer/readme.md @@ -44,7 +44,7 @@ - [√] call swap CoinB-> CoinA hash : F4vBUtrMMEJmtcUNvKfJEaPghYj37U3ehFkfVW5o155W ## 06 Dapp-kit SDK PTB -- [] save hash : +- [√] save hash : HTeRRRNEtcDRrPgmMov91kCTajBrZ72v5uGuFmLncaXg ## 07 Move CTF Check In - [] CLI call 截图 : ![截图](./images/你的图片地址)