New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

defi-utils

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defi-utils

> An Accessible Defi Utility for Defi

latest
Source
npmnpm
Version
2.5.1
Version published
Weekly downloads
24
-4%
Maintainers
0
Weekly downloads
 
Created
Source

Defi-Utils

An Accessible Defi Utility for Defi

NPM JavaScript Style Guide

Install

npm install --save defi-utils

or

yarn add defi-utils

Usage

  • Usage Example with TSX/Typescript
import DefiUtils from 'defi-utils'

/**
 * Convert a full decimals value into basic units
 *
 * @param decimals
 * @returns DefiUtils
 */
new DefiUtils("1").toBasicUnits(18).toString() // 100000000000000000000

/**
 * Convert a basic units value into full decimals
 *
 * @param decimals
 * @returns DefiUtils
 */
new DefiUtils("100000000000000000000").toFullDecimals(18).toString() // 1

/**
 * Convert a token amount into underlying amount
 * 
 * @param exchangeRate
 * @returns DefiUtils
 */
new DefiUtils("4999831433").toUnderlying("200006742877822").toString() // 1000000

/**
 * Convert a underlying amount into token amount
 *
 * @param exchangeRate
 * @returns DefiUtils
 */
new DefiUtils("1000000").toTokens("200006742877822").toString() // 4999831434

/**
 * Convert a value into a usd value
 *
 * @param priceUSD
 * @returns DefiUtils
 */
new DefiUtils("20").toUSD(2).toString() // 40

/**
 * Convert a value usd into a value
 *
 * @param priceUSD
 * @returns DefiUtils
 */
new DefiUtils("40").fromUSD(2).toString() // 20

License

MIT

Keywords

defi-utils

FAQs

Package last updated on 12 Mar 2025

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