LogoNAVI Protocol SDKS

Account Manager Migration

This guide will help you migrate account-related features from the old navi-sdk package to the new @naviprotocol/wallet-client package.

Install New Package

First, uninstall the old package and install the new one:

npm uninstall navi-sdk
npm install @naviprotocol/wallet-client

Interface Migration Guide

init Account

Old Version:

  • NAVISDKClient
const client = new NAVISDKClient({
  mnemonic,
  networkType: "mainnet" || rpc, 
  numberOfAccounts: 5
}); 
const account = client.accounts[0];

New Version:

import { WalletClient, WatchSigner, WebSigner } from '@naviprotocol/wallet-client'
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";


// Private key wallet
const walletClient = new WalletClient({
    client: {
        url: '' // custom rpc url
    },
    signer: Ed25519Keypair.fromSecretKey(privateKey)
})


// Watch-only wallet (cannot perform on-chain operations, can only read on-chain asset data)
const walletClient = new WalletClient({
    client: {
        url: '' // custom rpc url
    },
    signer: new WatchSigner('0xc41d2d2b2988e00f9b64e7c41a5e70ef58a3ef835703eeb6bf1bd17a9497d9fe')
})

// Browser environment (PC, Mobile) extension wallet
class WebSignerAdapter extends WebSigner {
    signAndExecuteTransaction() {}
    signTransaction() {}
    signPersonalMessage() {}
}

const walletClient = new WalletClient({
    client: {
        url: '' // custom rpc url
    },
    signer: new WebSignerAdapter()
})

Retrieve Account Information

Get Account Address

Old Version:

account.address
account.getPublicKey()

New Version:

walletClient.address

Retrieve Address Coin Info Across Objects

Old Version:

  • getAllCoins
account.getAllCoins() 

New Version:

await walletClient.balance.updatePortfolio();

walletClient.balance.coins
waleetClient.balance.portfolio

Get Specific Token Info

Old Version:

  • getCoins
account.getCoins("0x2::sui::SUI")

New Version:

await walletClient.balance.updatePortfolio();

waleetClient.balance.portfolio.getBalance('0x2::sui::SUI')

Get Address Merged Coin Balance

Old Version:

  • getWalletBalance
account.getWalletBalance()

New Version:

await walletClient.balance.updatePortfolio();

waleetClient.balance.portfolio

Get NAVI Portfolio

Old Version:

  • getNAVIPortfolio
account.getNAVIPortfolio(address = account.address, prettyPrint = true)

New Version:

  • lending.getLendingState
await walletClient.lending.getLendingState();

Get NAVI Health Factor

Old Version:

  • getHealthFactor
account.getHealthFactor(address = account.address)

New Version:

  • lending.getHealthFactor
await walletClient.lending.getHealthFactor();

Get Available NAVI Rewards

Old Version:

  • getAddressAvailableRewards
client.getAddressAvailableRewards(address = account.address, option = [1,])

New Version:

  • lending.getAvailableRewards
await walletClient.lending.getAvailableRewards();

Retrieve Rewards Claimed History

Old Version:

  • getUserRewardHistory
client.getUserRewardHistory(userAddress, page = 1, size = 400)

New Version:

  • lending.getClaimedRewardHistory
await walletClient.lending.getClaimedRewardHistory({
    page: 1,
    size: 400
});

Interactions With NAVI

Supply to NAVI

Old Version:

  • depositToNavi
  • depositToNaviWithAccountCap
import { Sui, NAVX} from 'navi-sdk'

// Deposit tokens to NAVI
account.depositToNavi(Sui, amount)

// Deposit with account cap restrictions
account.depositToNaviWithAccountCap(NAVX, amount, accountCap_Address_that_account_own)

New Version:

  • lending.deposit
await walletClient.lending.deposit('0x2::sui::SUI', 1e9)

await walletClient.lending.deposit('0x2::sui::SUI', 1e9, {
    accountCap: '0x...'
})

Withdraw from NAVI

Old Version:

  • withdraw
  • withdrawWithAccountCap
import { Sui, NAVX} from 'navi-sdk'

// Deposit tokens to NAVI
account.withdraw(Sui, amount)

// Deposit with account cap restrictions
account.withdrawWithAccountCap(NAVX, amount, accountCap_Address_that_account_own)

New Version:

  • lending.withdraw
await walletClient.lending.withdraw('0x2::sui::SUI', 1e9)

await walletClient.lending.withdraw('0x2::sui::SUI', 1e9, {
    accountCap: '0x...'
})

Borrow from NAVI

Old Version:

  • borrow
import { Sui} from 'navi-sdk'

// Deposit tokens to NAVI
account.borrow(Sui, amount)

New Version:

  • lending.borrow
await walletClient.lending.borrow('0x2::sui::SUI', 1e9)

Repay Debt to NAVI

Old Version:

  • repay
import { Sui} from 'navi-sdk'

// Deposit tokens to NAVI
account.repay(coinType = Sui, amount)

New Version:

  • lending.repay
await walletClient.lending.repay('0x2::sui::SUI', 1e9)

Claim All Available Rewards

Old Version:

  • claimAllRewards
account.claimAllRewards()

New Version:

  • lending.claimAllRewards
await walletClient.lending.claimAllRewards()

Create Account Cap

Old Version:

  • createAccountCap
account.createAccountCap()

New Version:

  • lending.createAccountCap
await walletClient.lending.createAccountCap()

Liquidation

Old Version:

  • liquidate
account.liquidate(payCoinType: CoinInfo, liquidationAddress: string, collateralCoinType: CoinInfo, liquidationAmount: number = 0)

New Version:

  • lending.createAccountCap
await walletClient.lending.liquidate('0x2::sui::SUI', 1e9, '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT', liquidationAddress)

Interactions With Astros Swap

Swap

Old Version:

  • swap
await account.swap(fromCoinAddress, toCoinAddress, amountIn, minAmountOut, apiKey);

New Version:

  • swap.swap
const walletClient = new WalletClient({
    configs: {
        swap: {
            apiKey
        }
    }
   ...
})
await walletClient.swap.swap(fromCoinAddress, toCoinAddress, amountIn, minAmountOut)

Dry Run Swap

Old Version:

  • dryRunSwap
await account.dryRunSwap(fromCoinAddress, toCoinAddress, amountIn, minAmountOut, apiKey);

New Version:

  • swap.swap
const walletClient = new WalletClient({
    configs: {
        swap: {
            apiKey
        }
    }
   ...
})
await walletClient.swap.swap(fromCoinAddress, toCoinAddress, amountIn, minAmountOut, {
    dryRun: true
})

Support

If you encounter issues during migration, please refer to: