-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
284 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>SDK Help</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "with-vite", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite --port 3000" | ||
}, | ||
"dependencies": { | ||
"@mysten/sui.js": "0.51.2", | ||
"@suiet/wallet-kit": "0.2.24", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"tweetnacl": "^1.0.3", | ||
"navi-sdk": "^1.1.21" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.22", | ||
"@types/react-dom": "^18.0.7", | ||
"@vitejs/plugin-react": "^2.2.0", | ||
"typescript": "^5.4.3", | ||
"vite": "^3.2.7" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.card { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} | ||
|
||
.btn-group button+button{ | ||
margin-left: 12px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import "./App.css"; | ||
import { | ||
ConnectButton, | ||
useAccountBalance, | ||
useWallet, | ||
ErrorCode, | ||
formatSUI, | ||
} from "@suiet/wallet-kit"; | ||
import "@suiet/wallet-kit/style.css"; | ||
import { TransactionBlock } from "@mysten/sui.js/transactions"; | ||
import {depositCoin, borrowCoin} from 'navi-sdk/dist/libs/PTB' | ||
import { Pool, PoolConfig } from "navi-sdk/dist/types"; | ||
import { pool } from 'navi-sdk/dist/address' | ||
import {Sui, USDC} from 'navi-sdk/dist/address'; | ||
|
||
function App() { | ||
const wallet = useWallet(); | ||
const { balance } = useAccountBalance(); | ||
|
||
function uint8arrayToHex(value: Uint8Array | undefined) { | ||
if (!value) return ""; | ||
// @ts-ignore | ||
return value.toString("hex"); | ||
} | ||
|
||
|
||
async function handleNAVISDK() { | ||
if (!wallet.account) return; | ||
const account = wallet.account; | ||
const sender = account.address; | ||
try { | ||
let txb = new TransactionBlock(); | ||
txb.setSender(sender); | ||
|
||
let getCoinInfo = balance; | ||
if (!getCoinInfo) { | ||
throw new Error("Insufficient balance"); | ||
} | ||
|
||
let deposit_amount = 1e9; | ||
let sui_symbol = Sui.symbol; | ||
const pool_sui: PoolConfig = pool[sui_symbol as keyof Pool]; | ||
const [to_deposit] = txb.splitCoins(txb.gas, [deposit_amount]); | ||
await depositCoin(txb, pool_sui, to_deposit, deposit_amount); | ||
|
||
const formatDateNumber = (num: number) => { | ||
return num < 10 ? `0${num}` : num; | ||
} | ||
const date = new Date(); | ||
const month = formatDateNumber(date.getMonth() + 1); | ||
const day = formatDateNumber(date.getDate()); | ||
const hour = formatDateNumber(date.getHours()); | ||
const usdcAmt = Number(`0.${month}${day}${hour}`); | ||
|
||
let borrow_amount = usdcAmt * 1e6; | ||
let usdc_symbol = USDC.symbol; | ||
const pool_usdc: PoolConfig = pool[usdc_symbol as keyof Pool]; | ||
const [borrow_coin] = await borrowCoin(txb, pool_usdc, borrow_amount); | ||
|
||
await depositCoin(txb, pool_usdc, borrow_coin, borrow_amount); | ||
|
||
const resData = await wallet.signAndExecuteTransactionBlock({ | ||
transactionBlock: txb, | ||
}); | ||
console.log("transaction digest: " + JSON.stringify(resData)); | ||
} catch (e) { | ||
console.error("failed", e); | ||
alert("failed (see response in the console)"); | ||
} | ||
} | ||
|
||
return ( | ||
<div className="App"> | ||
<div className="card"> | ||
<ConnectButton | ||
onConnectError={(error) => { | ||
if (error.code === ErrorCode.WALLET__CONNECT_ERROR__USER_REJECTED) { | ||
console.warn( | ||
"user rejected the connection to " + error.details?.wallet | ||
); | ||
} else { | ||
console.warn("unknown connect error: ", error); | ||
} | ||
}} | ||
/> | ||
|
||
{!wallet.connected ? ( | ||
<p>Connect wallet from now!</p> | ||
) : ( | ||
<div> | ||
<div> | ||
<p>current wallet: {wallet.adapter?.name}</p> | ||
<p> | ||
wallet status:{" "} | ||
{wallet.connecting | ||
? "connecting" | ||
: wallet.connected | ||
? "connected" | ||
: "disconnected"} | ||
</p> | ||
<p>wallet address: {wallet.account?.address}</p> | ||
<p>current network: {wallet.chain?.name}</p> | ||
<p> | ||
wallet balance:{" "} | ||
{formatSUI(balance ?? 0, { | ||
withAbbr: false, | ||
})}{" "} | ||
SUI | ||
</p> | ||
<p> | ||
wallet publicKey: {uint8arrayToHex(wallet.account?.publicKey)} | ||
</p> | ||
</div> | ||
<div className={"btn-group"} style={{ margin: "8px 0" }}> | ||
<button onClick={handleNAVISDK}>PTB_OP</button> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
:root { | ||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif; | ||
font-size: 16px; | ||
line-height: 24px; | ||
font-weight: 400; | ||
|
||
color-scheme: light dark; | ||
color: rgba(255, 255, 255, 0.87); | ||
background-color: #242424; | ||
|
||
font-synthesis: none; | ||
text-rendering: optimizeLegibility; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
-webkit-text-size-adjust: 100%; | ||
} | ||
|
||
a { | ||
font-weight: 500; | ||
color: #646cff; | ||
text-decoration: inherit; | ||
} | ||
a:hover { | ||
color: #535bf2; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
display: flex; | ||
place-items: center; | ||
min-width: 320px; | ||
min-height: 100vh; | ||
} | ||
|
||
h1 { | ||
font-size: 3.2em; | ||
line-height: 1.1; | ||
} | ||
|
||
button { | ||
border-radius: 8px; | ||
border: 1px solid transparent; | ||
padding: 0.6em 1.2em; | ||
font-size: 1em; | ||
font-weight: 500; | ||
font-family: inherit; | ||
background-color: #1a1a1a; | ||
cursor: pointer; | ||
transition: border-color 0.25s; | ||
} | ||
|
||
|
||
@media (prefers-color-scheme: light) { | ||
:root { | ||
color: #213547; | ||
background-color: #ffffff; | ||
} | ||
a:hover { | ||
color: #747bff; | ||
} | ||
button { | ||
background-color: #f9f9f9; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App' | ||
import './index.css' | ||
|
||
import { | ||
WalletProvider, | ||
} from '@suiet/wallet-kit'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<WalletProvider> | ||
<App/> | ||
</WalletProvider> | ||
</React.StrictMode> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters