Skip to content

fractional-company/subgrapher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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)