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

@fractional-company/subgrapher

v1.0.2

Published

Simple utility for querying popular Subgraphs.

Downloads

81

Readme

@fractional-company/subgrapher

npm package Build Status Downloads Issues Code Coverage Semantic Release

Simple utility for querying popular Subgraphs.

Supported Subgraphs: Blocks, Uniswap V2, Uniswap V3 and Sushiswap.

Install

npm install @fractional-company/subgrapher

Usage

Ethereum Blocks

Get the nearest block based on a timestamp

import { Blocks, CHAINS } from '@fractional-company/subgrapher';

const service = new Blocks(CHAINS.MAINNET);
await service.getNearestBlockByTimestamp(1654313448);
//=> {id: '0xd357c32704daa1147461c786a9fd6ee29d2119b2f416aefe253b231b20b99a3a', number: 14901000, timestamp: 1654313446}

getNearestBlockByTimestamp(timestamp)

timestamp

Type: number - (timestamp)

Get blocks based on block numbers

import { Blocks, CHAINS } from '@fractional-company/subgrapher';

const service = new Blocks(CHAINS.MAINNET);
await service.getBlocksByNumbers([14901000]);
//=> [{id: '0xd357c32704daa1147461c786a9fd6ee29d2119b2f416aefe253b231b20b99a3a', number: 14901000, timestamp: 1654313446}]

getNearestBlockByTimestamp(blockNumbers)

blockNumbers

Type: array - (array of block numbers)

Get block based on current date sub one, two or seven day/s

import { Blocks, CHAINS } from '@fractional-company/subgrapher';

const service = new Blocks(CHAINS.MAINNET);

// now sub 1 day
await service.fetchOneDayBlock();
//=> {id: '0x0e7ae8b9cbdb9f12bc2add28f31e21fe2225f06d9a7d44a5eb2742b54f8b6321',number: 14919711,timestamp: 1654588984}

// now sub 2 days
await service.fetchTwoDayBlock();
//=> {id: '0xcaf1a8fe520abaaf4e5b0de91c4caeafcbea4add66192e45dd0310b9167d7058',number: 14913845,timestamp: 1654502582} 

// now sub 7 days
await service.fetchSevenDayBlock();
//=> {id: '0xd6e300ce35886708485d99c75211f22ca4747626e65187abb25d068923490d5f',number: 14883711,timestamp: 1654070592}

Dexes

Supported:

  • SUSHISWAP
  • UNISWAP V2
  • UNISWAP V3

Get current or historical ETH price

import { DEXES, CHAINS } from '@fractional-company/subgrapher';

const service = new DEXES(CHAINS.MAINNET);

// ETH price
const blockNumber = 14901000;
service.getEthPrice(blockNumber, method, sources)
//=> BigNumber

// Array of  ETH prices (across dexes) 
service.getEthPrices(blockNumber, sources)
//=> [BigNumber,BigNumber,BigNumber]

getEthPrice(blockNumber?, method?, sources?)

getEthPrices(blockNumber?, sources?)

blockNumber

Type: number - (block number)

method

Type: string

Default: max

sources

Type: array - (array of sources to fetch prices from)

Default: [SUSHISWAP_V1, UNISWAP_V2, UNISWAP_V3]

Get current or historical ERC20 token price

import { DEXES, CHAINS } from '@fractional-company/subgrapher';

const service = new DEXES(CHAINS.MAINNET);

// ETH price
const blockNumber = 14901000;
service.getTokenPrice(contractAddress, blockNumber, method, sources)
//=> BigNumber

// Array of  prices (across dexes) 
service.getTokenPrices(contractAddress, blockNumber, sources)
//=> [BigNumber,BigNumber,BigNumber]

getTokenPrice(contractAddress, blockNumber?, method?, sources?)

getTokenPrices(contractAddress, blockNumber?, sources?)

contractAddress

Type: string - (ERC 20 token contract Address)

blockNumber

Type: number - (the block number)

method

Type: string

Default: max

sources

Type: array - (array of sources to fetch prices from)

Default: [SUSHISWAP_V1, UNISWAP_V2, UNISWAP_V3]

Get ERC20 token pools

import { DEXES, CHAINS } from '@fractional-company/subgrapher';

const service = new DEXES(CHAINS.MAINNET);

service.getTokenPools(contractAddress)
//=> [{ weight?: number,  source: string,  address: string,  token0: TokenData,  token1: TokenData,  token0Price: BigNumber,  token1Price: BigNumber,  volumeUSD: BigNumber,  txCount: BigNumber,  totalValueLockedUSD: BigNumber,  totalValueLockedToken0: BigNumber,  totalValueLockedToken1: BigNumber}]

getTokenPools(contractAddress)

contractAddress

Type: string - (ERC 20 contract address)