NaviSDK Client Documentation
Introduction
The NaviSDK Client provides a set of tools for interacting with sui blockchain networks, specifically designed for handling transactions, accounts, and smart contracts in a streamlined and efficient manner. This documentation covers the setup, account management, and transaction handling within the NaviSDK ecosystem.
Getting Started
Installation
Before you can use the NaviSDK Client, you need to set up your project environment.
npm i navi-sdk
Creating and Managing Accounts
Creating a Default Account
To create a default account, you will need a mnemonic phrase or we will generate a new one for you.
We will never save user's mnemonic phrase
const mnemonic = '';
const client = new NAVISDKClient({mnemonic, networkType: "mainnet", wordLength: 12});
Create/Delete a new Account
const account0 = client.accounts[0];
const account1 = client.createNewAccount({mnemonic: ""});
console.log(account0.getPublicKey());
console.log(account1.getPublicKey());
const account2 = client.createNewAccount({mnemonic: ""});
client.deleteAccount(2);
Use a specific 12|24 word Mnemonic
const account = client.createNewAccount({mnemonic: 'potato potato potato potato potato potato potato potato potato potato potato potato'});
console.log(`index 0:`, account.getMnemonic());
Return All Accounts under the Client
client.getAllAccounts()
client.getAllMnemonic()
index:0, address: 0xa814b8c01b111f5e440e5d4785925a033961915c2f44d22ca71619ac73534ee7
index:1, address: 0xd8be370139dd297924e31f6a507ba3a1d5f52f98f04f144bb75100d179698f84
index:2, address: 0xca29dbf32047fba966fa5aca7e378ba11171b3817f53ad324489a138288cc02d
Create Account Cap for specific account
account1.createAccountCap()
Get Specific Account Address
account1.getPublicKey()
account2.getMnemonic()
Get Objs and Coin Info
We have prepare a token type for Sui/NAVX/vSui/USDT/USDC/WETH/CETUS/haSui
import {Sui, NAVX, vSui, USDT, USDC, WETH, CETUS, haSui} from 'navi-sdk/dist/address';
account.getAllObjs()
account.getCoinObjs(coinType = "0x2::sui::SUI")
account.getCoinObjs(coinType = Sui)
Send Coin or Objects
account1.sendCoin(coinType = NAVX, your_recipient_address, amount)
account2.sendCoinToMany(coinType = NAVX, [addr1, addr2, .. addrN], [amount1, amount2, .. amountN])
account3.transferObj(obj = "0xobjId", your_recipient_address)
account4.transferObjToMany([obj1, obj2, ...], [addr1, addr2, ...])
Get comprehensive Wallet Balance list
This will combine all the objects of the same token, and return a comprehensive balance table
account.getWalletBalance()
Sample Output:
Coin Type | Balance |
---|
USDC | 2.4994 |
Sui | 3.63103582 |
NAVX | 0 |
Navi Interaction
Get Current Supply/Borrow from Navi
account.getNAVIPortflolio()
This will return a table like the following:
Reserve Name | Borrow Balance | Supply Balance |
---|
USDT | 0 | 0 |
CETUS | 0 | 0 |
NAVX | 0 | 0 |
USDC | 0 | 2.000057 |
WETH | 0 | 0 |
SUI | 5.009469205 | 100.097918005 |
VoloSui | 0 | 0 |
HaedalSui | 0 | 0 |
Get Reserve
client.getReserves()
Get PoolInfo
client.getPoolInfo(poolId)
Get Current Health Factor
client.getHealthFactor(address);
Predict new Health Factor by taking a supply/borrow action
client.getDynamicHealthFactor(address, coinType = 'USDC', supplyBalanceChange:100000, borrowBalanceChange: 0, is_increase: true)
Supply/Withdraw/Borrow/Repay
You may Simply input 'NAVX' as a string or NAVX as a type imported from address.ts.
Current These Pools are supported: Sui | NAVX | vSui | USDC | USDT | WETH | CETUS | haSui
account.depositToNavi(Sui, amount)
account.depositToNaviWithAccountCap(NAVX, amount, accountCap_Address_that_you_own)
account.withdraw(coinType = NAVX, amount)
account.withdrawWithAccountCap(coinType = NAVX, amount, accountCap_Address_that_you_own)
account.borrow(coinType = NAVX, amount)
account.repay(coinType = NAVX, amount)
Customized PTB
Navi Flash Loan Sample
import { NAVISDKClient } from 'navi-sdk'
import { TransactionBlock } from "@mysten/sui.js/transactions";
import {depositCoin,withdrawCoin, borrowCoin, flashloan,repayFlashLoan, SignAndSubmitTXB, mergeCoins} from 'navi-sdk/dist/libs/PTB'
import { Pool, PoolConfig } from "navi-sdk/dist/types";
import { pool } from 'navi-sdk/dist/address'
const mnemonic = "";
const client = new NAVISDKClient({mnemonic: mnemonic, networkType: "mainnet", wordLength: 12});
let txb = new TransactionBlock();
const account1 = client.accounts[0]
let sender = account1.getPublickey();
console.log(sender)
txb.setSender(sender);
const poolName = 'USDC';
const amount_to_borrow = 1*1e6;
const USDC_Pool: PoolConfig = pool[poolName as keyof Pool];
const [balance, receipt] = flashloan(txb, USDC_Pool, amount_to_borrow);
const this_coin = txb.moveCall({
target: '0x2::coin::from_balance',
arguments: [balance],
typeArguments: [USDC_Pool.type],
});
txb.mergeCoins(txb.object("{source_USDC_obj}"), [this_coin]);
const amount = = 1*1e6;
depositCoin(txb, USDC_Pool, txb.obj("{source_USDC_obj}"), amount);
withdrawCoin(txb, USDC_Pool, amount);
const repayBalance = txb.moveCall({
target: '0x2::coin::into_balance',
arguments: [txb.object('{your_repay_coin_object_id}')],
typeArguments: [USDC_Pool.type],
});
const [e_balance] = repayFlashLoan(txb, USDC_Pool, receipt, repayBalance);
const e_coin = txb.moveCall({
target: '0x2::coin::from_balance',
arguments: [e_balance],
typeArguments: [USDC_Pool.type],
});
txb.transferObjects([e_coin], sender);
const result = SignAndSubmitTXB(txb, account1.client(), account1.keypair());
console.log("result: ", result);