NaviSDK Client Documentation
For the latest updates and detailed information on how to interact with the NaviSDK contract, please refer to the Navi Protocol Developer Docs.
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
When you initialize client, you will need a mnemonic phrase or we will generate a new one for you.
1 mnemonic for 1 client
We will never save user's mnemonic phrase
const mnemonic = '';
const client = new NAVISDKClient({mnemonic, networkType: "mainnet", numberOfAccounts: 5});
Get the specific account
const account = client.accounts[0];
const account1 = client.accounts[1];
Check mnemonic for this client
console.log(client.getMnemonic());
client.mnemonic;
Return All Accounts under the Client
client.getAllAccounts()
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()
account1.address
Get Objs and Coin Info
We have prepared a token type for Sui/NAVX/vSui/USDT/USDC/WETH/CETUS/haSui
import {Sui, NAVX, vSui, USDT, USDC, WETH, CETUS, haSui} from '@navi-sdk/address';
account.getAllCoins()
account.getCoins(coinType = "0x2::sui::SUI")
account.getCoins(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
const balanceMap = account.getWalletBalance()
balanceMap.then((res) => {
console.log(res);
})
Sample Output:
Coin Type | Balance |
---|
USDC | 2.4994 |
Sui | 3.63103582 |
NAVX | 0 |
Get All Wallet Balances
Get all accounts' balance, summed together
const balances = client.getAllBalances();
balances.then((res) => {
console.log(res);
})
Navi Interaction
Get Current Supply/Borrow from Navi
account.getNAVIPortfolio()
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 All accounts portfolio info from Navi
const allPortfolio = client.getAllNaviPortfolios();
allPortfolio.then((res) => {
console.log(res);
})
Get Reserve
client.getReserves()
Get PoolInfo
import { USDC } from '@navi-sdk/address'
client.getPoolInfo(USDC)
Get Address Available Rewards to Claim
- OptionSupply = 1
- OptionWithdraw = 2
- OptionBorrow = 3
- OptionRepay = 4
- Option default is 1, you may leave it empty
account.getAvailableRewards()
client.checkAddressAvailableRewards(address);
Get Current Health Factor
account.getHealthFactor()
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/Liquidate/ClaimRewards
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)
account.claimAllRewards();
const debt_coin: CoinInfo = USDC;
const to_liquidate_address = 'address_to_liquidate';
const collateral_coin: CoinInfo = Sui;
account.liquidate(debt_coin, to_liquidate_address, collateral_coin);
let to_liquidate_amount = 10;
account.liquidate(debt_coin, to_liquidate_address, collateral_coin, to_liquidate_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/PTB'
import { Pool, PoolConfig } from "@navi-sdk/types";
import { pool } from '@navi-sdk/address'
import { USDC } from '@navi-sdk/address'
const mnemonic = "";
const client = new NAVISDKClient({mnemonic: mnemonic, networkType: "mainnet", numberOfAccounts: 1});
let txb = new TransactionBlock();
const account = client.accounts[0];
let sender = account.address;
console.log(sender)
txb.setSender(sender);
const amount_to_borrow = 1*1e6;
const USDC_Pool: PoolConfig = pool[USDC.symbol 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.object("{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, account.client, account.keypair);
console.log("result: ", result);