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

@forge-jig/core

v0.1.0

Published

Downloads

1

Readme

Jig: a tool used to expedite some repetitive task and ensure that the results do not vary from project to project.

Jig generates a helper contract that abstracts away all storage slot math.

For example:

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.4.22 <0.9.0;

contract Baby {
    uint256 public simple;

}

Turns into...

// THIS FILE WAS GENERATED
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

interface CheatCodes {
...
}

contract BabyJig {
    address internal target;
    CheatCodes public constant VM =
        CheatCodes(
            address(bytes20(uint160(uint256(keccak256("hevm cheat code")))))
        );

    constructor(address _contractAddress) {
        target = _contractAddress;
    }

    ...

    uint256 public simpleStorageSlot = uint256(0);

    function simple(uint256 value) public {
        VM.store(target, bytes32(simpleStorageSlot), bytes32(uint256(value)));
    }
}

which allows you to do things like...

contract BabyTest is DSTest {
    Baby baby;
    BabyJig jig;

    function setUp() public {
        baby = new Baby();
        jig = new BabyJig(address(b));
    }

    function testJig(uint256 rand) public {
        jig.simple(rand);
        assert(b.simple() == rand);
    }
}

Check out the sample contracts to see how far Jig can push this pattern.

Currently working on getting a working release deployed to NPM, but if you're feeling brave please clone the repository! You should be able to get the jig cli script added to your env by running npm run local yarn local pnpm local yada yada.

Usage

$ jig make src/Contract.sol

This will generate the helper contract at src/jig/ContractJig.sol

Quirks

  • Haven't tested on Windows/Linux
  • Haven't tested with Node version <16
  • You need to have a foundry.toml at the root of your repo so that jig can infer remappings correctly.
  • Jig currently doesn't handle Contracts as storage variables but will soooon.
  • Jig currently doesn't output prettier'ed code but will sooooooon.

How

Jig is built on top of the solc-type-ast library built by Consensys. By traversing the AST of your contract source, Jig is able to parse out the storage declarations, apply some math, and spit out this helper contract. In addition, if your storage variables are a struct, Jig will import the struct declaration into its contract file and use that struct as part of the function signature. This gets booooonkers, but allows users to quickly push complicated state into a contract.

Inspiration

forge-std is a major improvement over the native vm.store, we would not have been able to build up enough intuition for the edge cases in storage layouts without it.

Notes

Currently Jig only outputs a helper contract but could be reconfigured to output a json structure representing storage slots as well.