Simple utility for querying popular Subgraphs.
Supported Subgraphs: Blocks, Uniswap V2, Uniswap V3 and Sushiswap.
npm install @fractional-company/subgrapher
import { Blocks, CHAINS } from '@fractional-company/subgrapher';
const service = new Blocks(CHAINS.MAINNET);
await service.getNearestBlockByTimestamp(1654313448);
//=> {id: '0xd357c32704daa1147461c786a9fd6ee29d2119b2f416aefe253b231b20b99a3a', number: 14901000, timestamp: 1654313446}
Type: number
- (timestamp)
import { Blocks, CHAINS } from '@fractional-company/subgrapher';
const service = new Blocks(CHAINS.MAINNET);
await service.getBlocksByNumbers([14901000]);
//=> [{id: '0xd357c32704daa1147461c786a9fd6ee29d2119b2f416aefe253b231b20b99a3a', number: 14901000, timestamp: 1654313446}]
Type: array
- (array of block numbers)
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}
Supported:
- SUSHISWAP
- UNISWAP V2
- UNISWAP V3
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]
Type: number
- (block number)
Type: string
Default: max
Type: array
- (array of sources to fetch prices from)
Default: [SUSHISWAP_V1, UNISWAP_V2, UNISWAP_V3]
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]
Type: string
- (ERC 20 token contract Address)
Type: number
- (the block number)
Type: string
Default: max
Type: array
- (array of sources to fetch prices from)
Default: [SUSHISWAP_V1, UNISWAP_V2, UNISWAP_V3]
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}]
Type: string
- (ERC 20 contract address)