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

evm-fork-launch

v0.2.0

Published

Modules to find holders and start ganache

Downloads

13

Readme

Start ganache

This module provides functionality for starting ganche and finding holders of tokens

There are two modules:

  • requests.js -> Performs requests to bloxy.info for obtaining toen info
  • start-ganache.js -> Starts ganache with provided parameters and info obtained from requests.js

How to basic (🥚)

Currently best example how to use these modules in a bundle is presented here:

Script to launch ganache

File with tokens for balancer

Example file with gathered token info for balancer

Also you can check examples in this repository by:

  • yarn test:requests
  • yarn test:start-ganache

Options for creating ganache string:

GanacheConfig structure:

/**
 * @typedef {Object} GanacheConfig
 * @property {String} fork
 * @property {Number} gasLimit
 * @property {String[]} accounts
 * @property {String[]} tokens
 * @property {GetTokensOptions} tokenSearchOptions
 */

Properties (all are optional):

  • fork -> fork to use (istanbul/berlin/...)
  • gasLimit -> gas limit for ganache (default - 9000000)
  • accounts -> accounts to unlock (for example in 0x it may be makers addresses)
  • tokens -> tokens array that is passed to getTokenInfo function for finding info
  • tokenSearchOptions -> options passed to getTokenInfo function

GetTokensOptions structure:

/**
 * @typedef {Object} GetTokensOptions
 * @property {Boolean} byAddress
 * @property {Boolean} cached
 * @property {Boolean} verbose
 * @property {String} writeToFile
 */

All options are optional (: D):

  • byAddress -> result object with token info will use token addresses as keys, recommended for usage if you are not sure which tokens will be used
  • cached -> function will try to retrive file at location writeToFile and skip gathering token info part
  • verbose -> function will output token address that is currently inspected
  • writeToFile -> file location to write resulting object

requests.js

Module's internal functions

These functions are present in module, but are not exported

Request holder info:

/**
 * @param {Object} param0
 * @param {String} param0.tokenAddress
 * @param {String} param0.apiKey
 * @returns {Promise<HolderInfo[]>}
 */
async function requestHolderInfo({tokenAddress, apiKey});

Performs request to bloxy to find top 200 holders of token tokenAddress using provided apiKey (there is api key included in module) and returns HolderInfo

HolderInfo structure:

/**
 * @typedef {Object} HolderInfo
 * @property {String} address
 * @property {String} address_type
 * @property {String} annotation
 * @property {String} balance
 */

Request token info:

/**
 * @param {Object} param0 
 * @param {String} param0.tokenAddress
 * @param {String} param0.apiKey
 * @returns {Promise<TokenInfo>}
 */
async function requestTokenInfo({tokenAddress, apiKey})

Performs request to get information about token tokenAddress using provided apiKey and returns TokenInfo

TokenInfo structure:

/**
 * @typedef {Object} GetTokensOptions
 * @property {Boolean} byAddress
 * @property {Boolean} cached
 * @property {Boolean} verbose
 * @property {String} writeToFile
 */

Find top holder wallet (which is not contract):

/**
 * @param {HolderInfo[]} tokenHolders 
 * @returns {HolderInfo}
 */
function findTopWallet(tokenHolders);

Finds top holder wallet in provided array and returns it.

Create output object:

/**
 * @param {Object} param0 
 * @param {HolderInfo[]} param0.holderInfo
 * @param {TokenInfo[]} param0.tokenInfo
 * @param {Boolean} param0.byAddress
 * @returns {Record<String, Token>}
 */
function constructTokenInfo({
    holderInfo,
    tokenInfo,
    byAddress = false
})

This functions takes HolderInfo array and corresponding TokenInfo array, i.e. HolderInfo -> TokenInfo pairs represented as arrays. If byAddress parameter is true then resulting object will have token addresses as keys, if set to false token's symbols will be used as keys for resulting object (more on that later 🙃).

Module exports

This module exports object:

{
    apiKey,
    getTokenInfo
}

Where:

  • apiKey - default apiKey for bloxy
  • getTokenInfo - function to retreive token info

Get token info function:

/**
 * @param {Object} param0 
 * @param {String} param0.tokens
 * @param {String} param0.apiKey
 * @param {GetTokensOptions} param0.options
 * @returns {Record<String, Token>}
 */
async function getTokenInfo({
    tokens,
    apiKey,
    options = {}
})

This function receives as input:

  • tokens -> array of token addresses represented as strings
  • apiKey -> apiKey to use, if you don't have one - pass default apiKey (exported from module)
  • options -> options for result representation (check GetTokensOptions type)

GetTokensOptions structure:

/**
 * @typedef {Object} GetTokensOptions
 * @property {Boolean} byAddress
 * @property {Boolean} cached
 * @property {Boolean} verbose
 * @property {String} writeToFile
 */

All options are optional (:D):

  • byAddress -> result object with token info will use token addresses as keys, recommended for usage if you are not sure which tokens will be used
  • cached -> function will try to retrive file at location writeToFile and skip gathering token info part
  • verbose -> function will output token address that is currently inspected
  • writeToFile -> file location to write resulting object

start-ganache.js

module's internal functions

Function to generate launch string for ganache:

function generateForkString()

This function uses .env file as parameters:

  • NETWORK -> can be ETH/POLYGON, for usage with requests.js only ETH is valid (default value)
  • INFURA_ID_PROJECT -> must be set if NETWORK == ETH (if not set - default value is used), for polygon - https://polygon-rpc.com/ is used and does not require api keys
  • PORT -> port to use, if not set - 8545 is used

Function to retreive accounts from generated tokens object:

/**
 * @param {Record<String, Token>} obj 
 * @returns {String[]}
 */
function getAccountsFromObj(obj)

Object in this function -> object that was generated by getTokenInfo function.

Token structure:

/**
 * @typedef {Object} Token
 * @property {String} address
 * @property {String} holder
 * @property {String} name
 * @property {String} symbol
 * @property {Number} decimals
 */

Properties:

  • address -> address of tokens
  • holder -> holder address
  • name -> name of token
  • symbol -> symbol of token
  • decimals -> token's decimals

Module exports

This module exports functions:

{
    createGanacheCliString,
    startGanache
}

Functions:

  • createGanacheCliString -> function used to create ganache launcing string
  • startGanache -> uses created string to launch ganache (recommended to start in separate terminal)

Function to create ganache string:

/**
 * @param {GanacheConfig} launchParams 
 * @returns {Promise<String>}
 */
async function createGanacheCliString(launchParams)

Function takes as input object of GanacheConfig type.

GanacheConfig structure:

/**
 * @typedef {Object} GanacheConfig
 * @property {String} fork
 * @property {Number} gasLimit
 * @property {String[]} accounts
 * @property {String[]} tokens
 * @property {GetTokensOptions} tokenSearchOptions
 */

Properties (all are optional):

  • fork -> fork to use (istanbul/berlin/...)
  • gasLimit -> gas limit for ganache (default - 9000000)
  • accounts -> accounts to unlock (for example in 0x it may be makers addresses)
  • tokens -> tokens array that is passed to getTokenInfo function for finding info
  • tokenSearchOptions -> options passed to getTokenInfo function

Function to start ganache:

/**
 * @param {String} ganacheString 
 * @returns {child_process.ChildProcess}
 */
function startGanache(ganacheString) 

Function takes as input created ganache string and returns object representing running ganche (for example with it ganache process may be killed)