NeptuneService
NeptuneService is a straightforward tool that interacts with the Neptune CosmWasm smart contracts on Injective. It allows you to fetch asset prices, calculate exchange ratios, create deposit and withdraw messages, and retrieve lending rates.
Below are examples of how to use each method in the NeptuneService class.
Initialize NeptuneService
Before using the service, create an instance of NeptuneService.
import { NeptuneService } from '@injectivelabs/sdk-ts'
import { Network } from '@injectivelabs/networks'
// Create a NeptuneService instance using the mainnet
const neptuneService = new NeptuneService(Network.MainnetSentry)Fetch Prices
Get the prices of specific assets from the Neptune Price Oracle contract. Use native_token for bank denoms and token with contract_addr for CW20 tokens.
const assets = [
{
native_token: {
denom: 'peggy0xdAC17F958D2ee523a2206206994597C13D831ec7', // peggy USDT bank denom
},
},
{
token: {
contract_addr: 'inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s', // nUSDT contract address
},
},
]
const prices = await neptuneService.fetchPrices(assets)
console.log(prices)Fetch Redemption Ratio
Calculate the redemption ratio between nUSDT (CW20 token) and USDT (bank token).
Convert CW20 nUSDT to Bank USDT
Calculate the amount in bank USDT from a given amount of CW20 nUSDT using the redemption ratio.
Convert Bank USDT to CW20 nUSDT
Calculate the amount in CW20 nUSDT from a given amount of bank USDT using the redemption ratio.
Fetch Lending Rates
Retrieve lending rates for the different lending markets in neptune's lending market smart contract
Fetch Lending Rate by Denomination
Get the lending rate for USDT for example
Calculate Annual Percentage Yield (APY)
Convert the annual percentage rate (APR) to the continuously compounded annual percentage yield (APY). Make sure to use the lending rate retried from neptuneService.getLendingRateByDenom to use as the apr.
Create and Broadcast a Deposit Message
Create a message to deposit USDT into the Neptune USDT lending market and broadcast it to the network.
Create and Broadcast a Withdraw Message
Create a message to withdraw USDT from the Neptune USDT lending market and broadcast it to the network
Last updated
