Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

navi-sdk

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

navi-sdk

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 man

  • 1.1.2
  • npm
  • Socket score

Version published
Weekly downloads
869
decreased by-20.06%
Maintainers
1
Weekly downloads
 
Created
Source

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 = ''; // Use an existing mnemonic or leave empty to generate a new one
const client = new NAVISDKClient({mnemonic, networkType: "mainnet", wordLength: 12}); //WordLength supports 12 or 24 words

Create/Delete a new Account

client.createNewAccount();
console.log(`index 1:`, client.getMnemonic(accountIndexNumber)); //You may print it out to check the mnemonic
client.deleteAccount(index = 0);

Use a specific 12|24 word Mnemonic

client.createNewAccount({mnemonic: 'potato potato potato potato potato potato potato potato potato potato potato potato'});
// Double check the index 2 account
console.log(`index 2:`, client.getMnemonic(2));

Return All Accounts under the Client

client.getAllAccounts()
client.getAllMnemonic()
//Return Sample
index:0, address: 0xa814b8c01b111f5e440e5d4785925a033961915c2f44d22ca71619ac73534ee7
index:1, address: 0xd8be370139dd297924e31f6a507ba3a1d5f52f98f04f144bb75100d179698f84
index:2, address: 0xca29dbf32047fba966fa5aca7e378ba11171b3817f53ad324489a138288cc02d

Create Account Cap

client.createAccountCap(index = 0) //Index 0 Account will create an Account Cap

Get Specific Account Address

client.getPublicKey(index = 0)
client.getMnemonic(index = 0)

Get Objs and Token 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';
client.getAllObjs(index = 0) //Return all Objects that account has

//Get all objs for this type of token
client.getTokenObjs(index = 0, coinType = "0x2::sui::SUI")
//Or you may import token address from address
client.getTokenObjs(index = 0, coinType = Sui)

Send Token or Objects

client.sendToken(index = 0, coinType = NAVX, your_recipient_address, amount)
client.sendTokenToMany(index = 0, coinType = NAVX, [addr1, addr2, .. addrN], [amount1, amount2, .. amountN])

client.transferObj(index = 0, obj = "0xerror", your_recipient_address)
client.transferObjToMany(index = 0, [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

client.getWalletBalance(index = 0)

Sample Output:

Token TypeBalance
USDC2.4994
Sui3.63103582
NAVX0

Navi Interaction

Get Current Supply/Borrow from Navi

client.getNAVIPortflolio(index=0)

This will return a table like the following:

Reserve NameBorrow BalanceSupply Balance
USDT00
CETUS00
NAVX00
USDC02.000057
WETH00
SUI555.009469205100.097918005
VoloSui00
HaedalSui00

Get Reserve

client.getReserves() //Get All reserve info

Get PoolInfo

client.getPoolInfo(poolId) //Get All pool info
//Sui - 0, USDC - 1, USDT - 2, WETH - 3, CETUS - 4
//vSui - 5, haSui - 6, NAVX - 7

Get Current Health Factor

client.getHealthFactor(address); //You may check any address

Predict new Health Factor by taking a supply/borrow action

client.getDynamicHealthFactor(address, coinType = 'USDC', supplyBalanceChange:100000, borrowBalanceChange: 0, is_increase: true)
//supplyBalanceChange and borrowBalanceChange needs to be an integer with token decimals
//Change is_increase to false if it's decrease

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

client.deposit(index = 0, coinType = "Sui"||Sui, amount)
client.depositWithAccountCap(index = 0, coinType = "NAVX"||NAVX, amount, accountCap_Address_that_you_own)


client.withdraw(index = 0, coinType = "NAVX", amount)
client.withdrawWithAccountCap(index = 0, coinType = NAVX, amount, accountCap_Address_that_you_own)

client.borrow(index = 0, coinType = "NAVX", amount)
client.repay(index = 0, coinType = NAVX, amount)

Customized PTB

Navi Flash Loan Sample

Sample TX: https://suiscan.xyz/mainnet/tx/fCFERvsTk7t6G4SJyuuwXU3HbVqYbQ1RKzTDaeRwM4A

import { NAVISDKClient } from 'navi-sdk'
import { TransactionBlock } from "@mysten/sui.js/transactions";
import {depositToken, borrowToken, flashloan,repayFlashLoan, SignAndSubmitTXB, mergeTokens} 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});

// Initialize the TransactionBlock
let txb = new TransactionBlock();
let sender = client.getPublicKey(0);
console.log(sender)
txb.setSender(sender);

const poolName = 'USDC'; // Supported: Sui/NAVX/vSui/USDC/USDT/WETH/CETUS/HAsui
const amount_to_borrow = 1*1e6; //Borrow 1 USDC

const USDC_Pool: PoolConfig = pool[poolName as keyof Pool];
const [balance, receipt] = flashloan(txb, USDC_Pool, amount_to_borrow); // Flashloan 1 usdc

//Transfer the flashloan money to the account
const this_coin = txb.moveCall({
    target: '0x2::coin::from_balance',
    arguments: [balance],
    typeArguments: [USDC_Pool.type],
});

//Get the repayment object
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); // Repay with USDC

//Extra token after repay
const e_coin = txb.moveCall({
    target: '0x2::coin::from_balance',
    arguments: [e_balance],
    typeArguments: [USDC_Pool.type],
});

//Transfer the borrowed money and left_money after repay to teh account
txb.transferObjects([e_coin, this_coin], client.getPublicKey(0));
const result = SignAndSubmitTXB(txb, client.client(0), client.keypair(0));
console.log("result: ", result);

FAQs

Package last updated on 17 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc