Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task6 finish #2149

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading