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.
Example Code Snippets
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.
Retrieve lending rates for the different lending markets in neptune's lending market smart contract
const lendingRates = await neptuneService.getLendingRates({
limit: 10, // Optional: number of rates to fetch
})
console.log(lendingRates)
Fetch Lending Rate by Denomination
Get the lending rate for USDT for example
const denom = 'peggy0xdAC17F958D2ee523a2206206994597C13D831ec7' // USDT denom
const lendingRate = await neptuneService.getLendingRateByDenom({ denom })
if (lendingRate) {
console.log(`Lending Rate for USDT: ${lendingRate}`)
} else {
console.log('Lending Rate for USDT not found')
}
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.