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

@protofire/subgraph-devkit

v2.5.2

Published

Happiness kit for subgraph developers

Downloads

3

Readme

ci

Subgraph Devkit

Happiness kit for subgraph developers

Features:

Tech Stack:

  • AssemblyScript
  • Matchstick

Installation:

yarn add @protofire/subgraph-devkit

Documentation

Oracles

import { Address } from "@graphprotocol/graph-ts";
import { oracles } from "@protofire/subgraph-devkit";

const tokenAddress = Address.fromString(
  "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"
);

// get token price in usd from ChainLink oracle
oracles.chainlink.fetchPriceUSD(tokenAddress);

// get token price in usd from YearnLens oracle
oracles.yearnLens.fetchPriceUSD(tokenAddress);

// get token price in usd from Uniswap oracle
oracles.uniswap.fetchPriceUSD(tokenAddress);

Numbers

import { BigDecimal, BigInt } from "@graphprotocol/graph-ts";
import { decimals, integers } from "@protofire/subgraph-devkit";

// number 0 in BigDecimal
decimals.ZERO;

// number 1 in BigDecimal
decimals.ONE;

// number 0 in BigInt
integers.ZERO;

// number 1 in BigInt
integers.ONE;

// number 10 in BigInt
integers.TEN;

// Get min/max value
const a = BigInt.fromI32(100);
const b = BigInt.fromI32(101);

integers.min(a, b); // => 100
integers.max(a, b); // => 101

// Convert BigInt into Bytes
const n = BigInt.fromI32(100);
integers.toBytes(n);

// Create BigDecimal from BigInt
const n = BigInt.fromI32(1000000);
decimals.fromBigInt(n, 6); // => 1

// Create BigDecimal from Float
decimals.fromFloat(1000000.123);

// Create BigDecimal from Integer
decimals.fromInt(9223372036854775807);

// Convert BigDecimal to BigInt
const n = BigDecimal.fromString("1234.56");
decimals.toBigInt(n); // => 123456

// Get min/max value
const a = BigDecimal.fromString("100.525678");
const b = BigDecimal.fromString("100.525679");

decimals.min(a, b); // => 100.525678
decimals.max(a, b); // => 100.525679

// MakerDAO

// Create BigDecimal from RAD BigInt
const rad = BigInt.fromString(
  "12500000000000000000000000000000000000000000000"
);
decimals.fromRad(rad); // => 12.5;

// Create BigDecimal from WAD BigInt
const wad = BigInt.fromString("12500000000000000000");
decimals.fromWad(wad); // => 12.5

// Create BigDecimal from RAY BigInt
const ray = BigInt.fromString("12500000000000000000000000000");
decimals.fromRay(ray); // => 12.5

const value = BigDecimal.fromString("12.5");

// Convert BigDecimal into RAD BigInt
decimals.toRad(value); // => 12500000000000000000000000000000000000000000000

// Convert BigDecimal into RAY BigInt
decimals.toRay(value); // => 12500000000000000000000000000

// Convert BigDecimal into WAD BigInt
decimals.toWad(value); // => 12500000000000000000

Bytes

import { bytes } from "@protofire/subgraph-devkit";

// Convert Bytes into Address
const stringAddress = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984";
const bytesAddress = Bytes.fromHexString(stringAddress);
const address = bytes.toAddress(bytesAddress);

// Convert unsigned number in Bytes into BigInt
const bytesData = Bytes.fromHexString("0x28fc");
bytes.toUnsignedBigInt(bytesData); // => 10492

// Convert signed number in Bytes into BigInt
const bytesData = Bytes.fromHexString("0xd704");
bytes.toSignedBigInt(bytesData); // => -10492

Testing

import { BigDecimal } from "@graphprotocol/graph-ts";
import { describe, test } from "matchstick-as/assembly/index";
import { tests } from "@protofire/subgraph-devkit";

describe("decimalEquals", () => {
  test("decimal equals to decimal", () => {
    const a = BigDeciaml.fromString("100");
    const b = BigDeciaml.fromString("100");

    tests.asserts.decimalEquals(a, b);
  });
});

Constants

import { constants } from "@protofire/subgraph-devkit";

// USDC contract address
constants.addresses.USDC;

// WETH contract address
constants.addresses.WETH;

// UNISWAP_V2_ROUTER_02 contract address
constants.addresses.UNISWAP_V2_ROUTER_02;

// CHAINLINK_FEED_REGISTRY contract address
constants.addresses.CHAINLINK_FEED_REGISTRY;

// YEARN_LENS_ORACLE contract address
constants.addresses.YEARN_LENS_ORACLE;

// USDC unit (BigInt): 1000000
constants.units.USDC;

// MakerDAO

// WAD unit (BigInt): 1000000000000000000
constants.units.WAD;

// RAY unit (BigInt): 1000000000000000000000000000
constants.units.RAY;

// RAD unit (BigInt): 1000000000000000000000000000000000000000000000
constants.units.RAD;

Contributing:

  • Fork the repo on GitHub
  • Clone the project to your own machine
  • Commit changes to your own branch
  • Push your work back up to your fork
  • Submit a Pull request so that we can review your changes

Running Tests

In order to be able to take advantage of matchstick testing library, we have added a dummy subgraph inside tests folder. Tests will live inside that dummy subgraph and you can run them as follows:

yarn test