Skip to content

Commit

Permalink
Merge pull request #2149 from qwrdxer/main
Browse files Browse the repository at this point in the history
task6 finish
  • Loading branch information
Sifotd authored Dec 12, 2024
2 parents cd908c4 + d196d34 commit 44e6ae9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
60 changes: 60 additions & 0 deletions mover/qwrdxer/code/task6/core.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Container>
<Text>Navi任务:1.[存入Navi Protocol 1 SUI] 2.[借出当前日期的USDC 0.[月][天][小时] 的 USDC ] 3.[然后在存入等额的USDC]</Text>
<Box>
<Button onClick={() => navitaskexecute()}>任务执行</Button>
</Box>
</Container>
</>

)
}
2 changes: 1 addition & 1 deletion mover/qwrdxer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/你的图片地址)
Expand Down

0 comments on commit 44e6ae9

Please sign in to comment.