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,分享笔记和截图 #2048

Merged
merged 3 commits into from
Nov 30, 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
Binary file added mover/Ch1hiro/co-learn-2411/images/09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mover/Ch1hiro/co-learn-2411/images/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions mover/Ch1hiro/co-learn-2411/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
- [x] 第一周:![学习记录截图](./images/03.png)
- [x] 第二周:![学习记录截图](./images/05.png)
- [x] 第三周:![学习记录截图](./images/07.png)
- [] 第四周:![学习记录截图](./images/你的图片地址)
- [x] 第四周:![学习记录截图](./images/09.png)

## 参加直播答疑

- [x] 第一周:![学习记录截图](./images/04.png)
- [x] 第二周:![学习记录截图](./images/06.png)
- [x] 第三周:![学习记录截图](./images/08.png)
- [] 第四周:![学习记录截图](./images/你的图片地址)
- [x] 第四周:![学习记录截图](./images/10.png)

## 群里分享学习笔记

Expand All @@ -35,7 +35,7 @@
- [x] 第一篇笔记【https://learnblockchain.cn/article/9832】
- [x] 第二篇笔记【https://learnblockchain.cn/article/9916】
- [x] 第三篇笔记【https://learnblockchain.cn/article/10010】
- [] 第四篇笔记【学习笔记链接
- [x] 第四篇笔记【https://learnblockchain.cn/article/10088

## 在HOH社区公众号发布自己的技术文章

Expand Down
39 changes: 39 additions & 0 deletions mover/Ch1hiro/code/task6/navi_protocol/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ConnectButton } from "@mysten/dapp-kit";
import { Box, Container, Flex, Heading } from "@radix-ui/themes";
import Exec from "./exec.tsx"

function App() {
return (
<>
<Flex
position="sticky"
px="4"
py="2"
justify="between"
style={{
borderBottom: "1px solid var(--gray-a2)",
}}
>
<Box>
<Heading>dApp Starter Template</Heading>
</Box>

<Box>
<ConnectButton />
</Box>
</Flex>
<Container>
<Container
mt="5"
pt="2"
px="4"
style={{ background: "var(--gray-a2)", minHeight: 500 }}
>
<Exec />
</Container>
</Container>
</>
);
}

export default App;
67 changes: 67 additions & 0 deletions mover/Ch1hiro/code/task6/navi_protocol/src/exec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { useCurrentAccount, useSignAndExecuteTransaction } from "@mysten/dapp-kit";
import { Container, Flex, Heading, Text, Button } from "@radix-ui/themes";
import { loan } from "./transaction/navi.ts";

const DateNumber = (num: number) => {
let new_num;
if( num < 10 ) {
new_num = `0${num}`;
} else {
new_num = num;
}
return new_num;
}

const Exec = () => {
const account = useCurrentAccount();
const { mutate: signAndExecute } = useSignAndExecuteTransaction();

const date = new Date(); // 获取当前的日期和时间
const month = DateNumber(date.getMonth() + 1); // 获取月份并格式化,`getMonth()` 返回的范围是 0-11,所以要加 1
const day = DateNumber(date.getDate()); // 获取日期并格式化
const hour = DateNumber(date.getHours()); // 获取小时并格式化
const usdc_amt = Number(`0.${month}${day}${hour}`); // 拼接出一个形如 '0.051215' 的字符串,并转换为数字

return(
<Container my={"2"}>
<Heading mb={"2"}>Wallet Status</Heading>


{ account ? (
<Flex direction={"column"}>
<Text>Wallet connected</Text>
<Text>Address: {account.address}</Text>
</Flex>
): (
<Text>Wallet not Connected</Text>
) }


{ account ? (
<Flex direction="column">
<Flex direction={"column"}>
<Text>1、存入 1 SUI</Text>
<Text>2、借出当前日期 {`${usdc_amt}`} 的 USDC </Text>
<Text>3、存入等额的USDC</Text>
</Flex>

<Button
onClick={ () => {
loan({signAndExecute,
usdc_amt,
onError(error) {
console.log(error, '++++error++++')
},
});
}}
style={{cursor: 'pointer'}} // 将鼠标变为小手
>
<Text>执行交易</Text>
</Button>
</Flex>
): null}

</Container>
);
}
export default Exec;
26 changes: 26 additions & 0 deletions mover/Ch1hiro/code/task6/navi_protocol/src/main.tsx
Original file line number Diff line number Diff line change
@@ -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(
<React.StrictMode>
<Theme appearance="dark">
<QueryClientProvider client={queryClient}>
<SuiClientProvider networks={networkConfig} defaultNetwork="mainnet">
<WalletProvider autoConnect>
<App />
</WalletProvider>
</SuiClientProvider>
</QueryClientProvider>
</Theme>
</React.StrictMode>,
);
17 changes: 17 additions & 0 deletions mover/Ch1hiro/code/task6/navi_protocol/src/networkConfig.ts
Original file line number Diff line number Diff line change
@@ -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 };
38 changes: 38 additions & 0 deletions mover/Ch1hiro/code/task6/navi_protocol/src/transaction/navi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Transaction } from "@mysten/sui/transactions";
import { depositCoin, borrowCoin } from "navi-sdk/dist/libs/PTB";
import { Sui, wUSDC, pool } from "navi-sdk/dist/address";
import { Pool, PoolConfig } from "navi-sdk/dist/types";

export const loan = async ( {
signAndExecute,
usdc_amt,
onError = () => { }
}: {
signAndExecute: any;
usdc_amt: number;
onError?: (result: any) => void;
} ) => {
let tx = new Transaction();
console.log(usdc_amt);
// 分离出 Sui
const [sp_sui] = tx.splitCoins(tx.gas, [1_000_000_000]);

// 将sui存入navi
const Sui_Pool: PoolConfig = pool[Sui.symbol as keyof Pool];
await depositCoin(tx as any, Sui_Pool, sp_sui, 1_000_000_000); // await 用于异步处理

// 借出USDC
const USDC_Pool: PoolConfig = pool[wUSDC.symbol as keyof Pool];
const [usdc_coin] = await borrowCoin(tx as any, USDC_Pool, usdc_amt * Math.pow(10, wUSDC.decimal));

// 存入 USDC
await depositCoin(tx as any, USDC_Pool, usdc_coin, usdc_amt * Math.pow(10,wUSDC.decimal));


// 进行签名交易
await signAndExecute({
transaction: tx,
}, {
onError,
});
}
2 changes: 1 addition & 1 deletion mover/Ch1hiro/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
- [x] call swap CoinB-> CoinA hash : BhYxRmP98LAWuALRb6vvsHh3oDhAQNT9NokGVnL1XvBV

## 06 Dapp-kit SDK PTB
- [] save hash :
- [x] save hash : 2nR4BxTBPwV57jcwdpuTV72iCDDcBBas5gSxGcCPvgc9

## 07 Move CTF Check In

Expand Down