LogoNAVI Protocol SDKS

Lending Migration

This guide will help you migrate from the old version of the navi-sdk package to the new @naviprotocol/lending package. The new version provides a clearer API design, better type support, and more complete functionality.

Install New Package

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

npm uninstall navi-sdk
npm install @naviprotocol/lending

Interface Migration Guide

Interface Optional Parameters

The last options parameter of the new version interface is usually an optional object used to customize interface behavior. Common optional parameters include but are not limited to:

  • client: Sui network client instance (such as SuiClient), used for customizing network requests, suitable for scenarios that require custom RPC nodes or multi-network environments.
  • env: Specify environment (such as 'prod''dev'), affecting data sources and on-chain contract addresses, ensuring data isolation and compatibility in different deployment environments.
  • cacheTime: Custom cache time in milliseconds. By setting cache time, you can reduce duplicate requests and improve performance. For example, cacheTime: 60000 means cache for 60 seconds.
  • disableCache: Whether to disable cache
  • accountCap: In ptb-related operations, use account cap

Usage Recommendations:

  • If you don't pass options, the SDK will automatically use default configuration, suitable for most regular scenarios.
  • When you need to customize network, environment, or cache strategy, it's recommended to pass corresponding parameters for more flexible control.

Coin Variables

The new version no longer provides coin variables. Please directly use the coin type or asset id corresponding to the coin.

Old Version:

import { Sui, USDT, WETH, vSui, haSui, 
         CETUS, NAVX, WBTC, AUSD, wUSDC, 
         nUSDC, ETH, USDY, NS, LorenzoBTC, 
         DEEP, FDUSD, BLUE, BUCK, suiUSDT } from 'navi-sdk'

client.getPoolInfo(USDC) 

New Version:

import { getPool } from '@naviprotocol/lending'

await getPool('0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC')

Retrieve Address Information

Retrieve Address All Coins

Old Version:

  • getAllCoins
account.getAllCoins(prettyPrint = true) 

New Version:

import { getCoins } from '@naviprotocol/lending'

await getCoins(address)

Retrieve Address Specific Coins

Old Version:

account.getCoins(coinType = "0x2::sui::SUI")

New Version:

import { getCoins } from '@naviprotocol/lending'

await getCoins(address, {
    coinType: "0x2::sui::SUI"
})

Get NAVI Portfolio

Old Version:

  • getNAVIPortfolio
const naviPortfolio = account.getNAVIPortfolio(address)

New Version:

import { getLendingState } from '@naviprotocol/lending'

const lendingStates = await getLendingState(address)
The data structures returned by old and new interfaces are different, please adjust accordingly

Get NAVI Health Factor

Old Version:

account.getHealthFactor(address)

New Version:

import { getHealthFactor } from '@naviprotocol/lending'

await getHealthFactor(address)

Get Available NAVI Rewards

Old Version:

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

New Version:

import { getUserAvailableLendingRewards } from '@naviprotocol/lending'

await getUserAvailableLendingRewards(address)
The data structures returned by old and new interfaces are different, please adjust accordingly

Retrieve Rewards Claimed History

Old Version:

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

New Version:

import { getUserClaimedRewardHistory } from '@naviprotocol/lending'

await getUserClaimedRewardHistory(address, {
    page: 1,
    size: 400
})
The data structures returned by old and new interfaces are different, please adjust accordingly

Retrieve Pool Information

Get Pool Information

Old Version:

  • getPoolInfo
import { USDC } from 'navi-sdk/dist/address'
client.getPoolInfo(USDC) 

New Version:

import { getPool } from '@naviprotocol/lending'
// get pool by coin type
await getPool('0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC')
// get pool by asset id
await getPool(10)
The data structures returned by old and new interfaces are different, please adjust accordingly

Get Reserve Information

Old Version:

  • getReserves
import { USDC } from 'navi-sdk/dist/address'
client.getReserves(USDC)
// Leave empty to retrieve reserves for all pools
client.getReserves()

New Version:

import { getPool, getPools } from '@naviprotocol/lending'
// get pool by coin type
await getPool('0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC')
// get pool by asset id
await getPool(10)
// retrieve all pools
await getPools()
The data structures returned by old and new interfaces are different, please adjust accordingly

PTB Functions

Deposit Coin

Old Version:

  • depositCoin
  • depositCoinWithAccountCap
depositCoin(txb: Transaction, _pool: PoolConfig, coinObject: any, amount: any)
depositCoinWithAccountCap(txb: Transaction, _pool: PoolConfig, coinObject: any, accountCapAddress: string)

New Version:

import { depositCoinPTB } from '@naviprotocol/lending'

await depositCoinPTB(
  txb,
  '0x2::sui::SUI',
  coinObject,
  {
    // use account cap
    accountCap: accountCapObject,
    // If amount is not specified, all balance in coinObject will be deposited
    amount: 1000000000
  }
)

Withdraw Coin

Old Version:

  • withdrawCoin
  • withdrawCoinWithAccountCap
const [returnedCoin] = withdrawCoin(txb: Transaction, _pool: PoolConfig, amount: number)
const [returnedCoin] = withdrawCoinWithAccountCap(txb: Transaction, _pool: PoolConfig, account: string, withdrawAmount: number, sender: string)

New Version:

import { withdrawCoinPTB } from '@naviprotocol/lending'

const returnedCoin = await withdrawCoinPTB(
  txb,
  '0x2::sui::SUI',
  1000000000, 
  {
    accountCap: accountCapObject
  }
)

Borrow Coin

Old Version:

  • borrowCoin
const [returnedCoin] = borrowCoin(txb: Transaction, _pool: PoolConfig, borrowAmount: number)

New Version:

import { borrowCoinPTB } from '@naviprotocol/lending'

const returnedCoin = await borrowCoinPTB(
  txb,
  '0x2::sui::SUI',
  1000000000, 
  {
    accountCap: accountCapObject
  }
)

Repay Debt

Old Version:

  • repayDebt
repayDebt(txb: Transaction, _pool: PoolConfig, coinObject: any, repayAmount: n)

New Version:

import { repayCoinPTB } from '@naviprotocol/lending'

const returnedCoin = await repayCoinPTB(
  txb,
  '0x2::sui::SUI',
  coinObject, 
  {
    accountCap: accountCapObject,
    amount: 1000000
  }
)

Flashloan

Old Version:

  • flashloan
  • repayFlashLoan
const [balance, receipt] = flashloan(txb: Transaction, _pool: PoolConfig, amount: number)
const [e_balance] = repayFlashLoan(txb: Transaction, _pool: PoolConfig, receipt: any, repayCoin: any)

New Version:

import { flashloanPTB, repayFlashLoanPTB } from '@naviprotocol/lending'

const [balance, receipt] = await flashloanPTB(tx, '0x2::sui::SUI', 1e9)
const [e_balance] = await repayFlashLoanPTB(tx, '0x2::sui::SUI', receipt, repayCoin)

Liquidation

Old Version:

  • liquidateFunction
const [collateralBalance, remainDebtBalance] = liquidateFunction(txb: Transaction, payCoinType: CoinInfo, payCoinObj: any, collateralCoinType: CoinInfo, to_liquidate_address: string)

New Version:

import { liquidatePTB } from '@naviprotocol/lending'

const [collateralBalance, remainDebtBalance] = liquidatePTB(txb, '0x2::sui::SUI', payCoinObj, '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC', to_liquidate_address)

Claim Single Assert Reward

Old Version:

  • claimRewardsByAssetIdPTB
claimRewardsByAssetIdPTB(    
    client: SuiClient, 
    address, 
    assetId, 
    txb
)

New Version:

import { claimLendingRewardsPTB, getUserAvailableLendingRewards } from '@naviprotocol/lending'

const rewards = await getUserAvailableLendingRewards(address);

const filterRewards = rewards.filter((reward) => {
    return reward.assetId === assetId
})

await claimLendingRewardsPTB(txb, filterRewards)

Claim All Reward

Old Version:

  • claimAllRewardsPTB
claimAllRewardsPTB(    
    client: SuiClient, 
    address, 
    txb
)

New Version:

import { claimLendingRewardsPTB, getUserAvailableLendingRewards } from '@naviprotocol/lending'

const rewards = await getUserAvailableLendingRewards(address);

await claimLendingRewardsPTB(txb, rewards)

Claim All Reward and Resupply

Old Version:

  • claimAllRewardsResupplyPTB
claimAllRewardsResupplyPTB(    
    client: SuiClient, 
    address, 
    txb
)

New Version:

import { claimLendingRewardsPTB, getUserAvailableLendingRewards } from '@naviprotocol/lending'

const rewards = await getUserAvailableLendingRewards(address);

await claimLendingRewardsPTB(txb, rewards, {
    customCoinReceive: {
        type: 'depositNAVI',
    }
})

Update Oracle PTB

Old Version:

  • updateOraclePTB
updateOraclePTB(client: SuiClient, txb: Transaction)

New Version:

import { updateOraclePricesPTB, getPriceFeeds } from '@naviprotocol/lending'

const priceFeeds = await getPriceFeeds();

await updateOraclePricesPTB(txb, priceFeeds, {
    updatePythPriceFeeds: true
})

Support

If you encounter issues during migration, please refer to: