Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mstable/stablemath-js

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mstable/stablemath-js

TypeScript port of the [StableMath](https://github.com/mstable/mStable-contracts/blob/master/contracts/shared/StableMath.sol) library from mStable.

  • 0.1.0
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

StableMath JS

TypeScript port of the StableMath library from mStable.

Installation

yarn add @mstable/stablemath-js

Usage

import { BigNumber } from '@ethersproject/bignumber'
import {
  divPrecisely,
  mulTruncate,
  mulRatioTruncate,
  divRatioPrecisely,
  toSimple,
} from '@mstable/stablemath-js'

const a = BigNumber.from('1000000000000000000')

const b = BigNumber.from('2000000000000000000')

// Multiplies two precise units, and then truncates by the full scale.
mulTruncate(a, b)

// Multiplies and truncates a token ratio, essentially flooring the result
// i.e. How much mAsset is this bAsset worth?
mulRatioTruncate(a, b)

// Precisely divides two units, by first scaling the left hand operand.
// Useful for finding percentage weightings, i.e. 8e18/10e18 = 80% (or 8e17)
divPrecisely(b, a)

// Precisely divides two ratioed units, by first scaling the left hand operand
// i.e. How much bAsset is this mAsset worth?
divRatioPrecisely(b, a)

// Convert an exact BigNumber (with decimals) to a simple JavaScript number (losing precision)
toSimple(a, 18)

Local Development

This project was bootstrapped with TSDX.

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

FAQs

Package last updated on 05 Oct 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc