npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xtoken/js

v0.1.58

Published

JS helper library to interact with xToken contracts

Downloads

10

Readme

@xtoken/js

Helper library to interact with xToken contracts written in Typescript with full typing support. It allows access to the low level API to directly interact with the contracts.

Install

yarn add @xtoken/js

Dependencies

At the moment, @xtoken/js requires using @xtoken/abis and ethers.js v5.0.30

yarn add @xtoken/abis
yarn add [email protected]

Environment

We need to set up an environment variable for test address that'd be used to validate portfolio balances across all xAssets while running tests.

cp .env.sample .env # Fill in the `INFURA_API_KEY` and `TEST_ADDRESS` variables

Documentation

GitHub pages: https://xtokenmarket.github.io/js

Examples

import { ethers } from 'ethers'
import { X_KNC_A } from '@xtoken/abis'
import { XToken } from '@xtoken/js'

// Setup provider
const provider = new ethers.providers.InfuraProvider('homestead', '<API KEY>')

// Initialize XToken
const xToken = new XToken(provider)

// Calculate expected mint quantity for tokens
const expectedQty = await xToken.getExpectedQuantityOnMint(X_KNC_A, true, '1') // args: `symbol`, `tradeWithEth` & `amount`

Development

  • Generate API documentation (HTML or JSON) without a mess of JSDoc tags to maintain
  • Collocated, atomic, concurrent unit tests with AVA
  • Source-mapped code coverage reports with nyc
  • Configurable code coverage testing (for continuous integration)
  • Automatic linting and formatting using typescript-eslint and Prettier

Build

yarn watch:build

Link

Link @xtoken/js package via yarn for local development and testing the integration on the UI

$ cd js
$ yarn link # @xtoken/js package will be linked to the local copy

$ cd cafe
$ yarn link @xtoken/js # This will create a symlink named cafe/node_modules/@xtoken/js that links to the local copy of the xToken js project

$ yarn unlink # To unlink the installed package

Tests

yarn watch:test

In order to run a single test, you can use the name of the test or regex name to match the tests to be executed

yarn build && npx ava -m='*prices*'

Linting

To automatically fix eslint and prettier formatting issues, run:

yarn fix

Coverage

To generate and view test coverage, run:

yarn cov

This will create an HTML report of test coverage – source-mapped back to Typescript – and open it in your default browser.

Docs

The src folder is analyzed and documentation is automatically generated using TypeDoc.

yarn doc

This command generates the library documentation in HTML format and opens it in a browser.

Since types are tracked by Typescript, there's no need to indicate types in JSDoc format. For more information, see the TypeDoc documentation.

To generate and publish documentation to GitHub Pages use the following command:

yarn doc:publish

Once published, documentation should be available at the GitHub Pages

Publishing

Before publishing the package to NPM, prepare-release command builds, runs the tests, increases the package version automatically and publishes the docs to GitHub Pages.

yarn prepare-release

Once the above command runs successfully, you should then execute the below command which will tag the release version and publish the build to NPM.

Note: Before publishing the package, ensure that the package.json has the version field incremented and also the build folder has the compiled code.

git push --follow-tags origin main && npm publish

Created using typescript-starter