You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@mstable/mstable-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
Package was removed
Sorry, it seems this package was removed from the registry

@mstable/mstable-js

Data processing and validation tools for the mStable Protocol.

0.1.0-alpha
unpublished
latest
npm
Version published
Maintainers
2
Created
Source

mStable JS

Data processing and validation tools for the mStable Protocol.

Installation

With Yarn:

yarn add @mstable/mstable-js

Or with npm:

npm install @mstable/mstable-js

Usage

Contracts

Deployed addresses

Deployed addresses are available on the mStable docs.

ABIs

ABIs can be obtained from the @mstable/protocol package.

Contracts

Detailed documentation is available on the mStable docs and the Solidity code is available on GitHub.

Data fetching

Subgraph

The mStable Protocol Subgraph can be used to fetch data such as mAssets, bAssets, swap transactions, etc.

Available subgraphs:

Example query:

query {
  masset(id: "0xe2f2a5c287993345a840db3b0845fbc70f5935a5") {
    address: id
    token {
      symbol
      decimals
      totalSupply
    }
    feeRate
    redemptionFeeRate
    basket {
      failed
      collateralisationRatio
      maxBassets
      bassets {
        address: id
        maxWeight
        status
        vaultBalance
        isTransferFeeCharged
        token {
          symbol
          decimals
        }
      }
    }
    savingsContracts {
      address: id
      totalSavings
      totalCredits
      exchangeRates(orderBy: timestamp, orderDirection: desc, first: 1) {
        exchangeRate
      }
    }
  }
}

Example usage:

import { ApolloClient, InMemoryCache, gql } from '@apollo/client'

const client = new ApolloClient({
  uri: 'https://api.thegraph.com/subgraphs/name/mstable/mstable-protocol',
  cache: new InMemoryCache(),
})

const query = gql`
  query {
    masset(id: "0xe2f2a5c287993345a840db3b0845fbc70f5935a5") {
      address: id
      # ...as above
    }
  }
`

const response = await client.query({ query })

Contracts

Data for mAssets can also be accessed directly from the contracts. This will generally involve more work than using the Subgraph.

Example:

import { ethers } from 'ethers'
import MassetABI from '@mstable/protocol/build/contracts/Masset.json'
import BasketManagerABI from '@mstable/protocol/build/contracts/BasketManager.json'

const provider = new ethers.providers.Web3Provider(window.ethereum)

const MUSD = new ethers.Contract(MUSDAddress, MassetABI, provider)

const basketManagerAddress = await MUSD.getBasketManager()

const basketManager = new ethers.Contract(basketManagerAddress, BasketManagerABI)

const basket = await basketManager.getBasket()

const bassets = await basketManager.getBassets()

Minting mAssets

Validation

import { validateMint } from '@mstable/mstable-js'

// TODO should make it easy to get this
const MUSD = await getMUSD()

{
  const [ok, reason] = validateMint(MUSD, { '0xDAI': '100000', '0xUSDC': '2000' })
  expect(ok).toBeTruthy()
  expect(reason).toBeUndefined()
}

{
  const [ok, reason] = validateMint(MUSD, { '0xDAI': '960000000' })
  expect(ok).toBeFalsy()
  expect(reason).toContain('DAI is overweight')
}

Simulation

import { simulateMint } from '@mstable/mstable-js'

const MUSD = await getMUSD()

{
  const [ok, simulation] = simulateMint(MUSD, { '0xDAI': '100000', '0xUSDC': '2000' })
  expect(ok).toBeTruthy()
  expect(simulation).toMatchObject({ bassets: { '0xDAI': '200000' } })
}

Redeeming mAssets

Validation

Swapping bAssets

Validation

Saving with an mAsset

Validation

Calculating APY

TODO

  • Interacting with staking rewards contracts (EARN)
  • Calculating APY (EARN)
  • Interacting with MTA Staking (v1)
  • Analytics

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 06 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