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

juice-token-resolver

v0.0.1

Published

Creates onchain SVG Metadata for all Juicebox projects on [JBDirectory V3](https://docs.juicebox.money/dev/api/contracts/jbdirectory/).

Downloads

2

Readme

Juicebox Token Resolver

Creates onchain SVG Metadata for all Juicebox projects on JBDirectory V3.

Example output

Deployed contracts

Mainnet

Goerli

Getting started

This repo relies on Mainnet forking for its tests. This approach allows tests to surface real chain data, and avoids the need to redeploy the entire Juicebox protocol, Juicebox Project Handles, and ENS protocol, as well as instantiating projects, .eth addresses, and handles, before running its own test. The tradeoff is that you need access to an RPC to test the repo.

Installation

  1. git clone [email protected]:jbx-protocol/juice-token-resolver.git or git clone https://github.com/jbx-protocol/juice-token-resolver.git this repo.
  2. Install Foundry, or update Foundry with foundryup.
  3. cd into the directory and call forge install && yarn install to install dependencies.
  4. Rename .env-example to .env and fill out the fields. You can generate a throwaway private key with cast wallet. You can get a free RPC API key from Infura, Alchemy, and other providers listed on https://ethereumnodes.com/.

Testing

⚠️ Security note ⚠️ This repo's tests use forge's ffi to save SVG images to disk and open them in your default SVG reader (usually the browser). This rendering approach means that malicious updates to this repo, or forks thereof, could allow Node to execute code on your system with filesystem access, and open files in your browser or other applications. Please be careful to check that no malicious changes have been introduced to the code before running tests. A dead giveaway would be unverified commits to the repo, or commits from an unexpected contributor. This code is provided as-is with no guarantee or warranty.

Run all tests

Run forge test -v --ffi to run all test.

Test only the default SVG output

Run forge test -v --ffi --match-test testGetDefaultMetadataDirectoryV3Controller3_1

This test outputs the default SVG for a JBDirectoryV3 Controller3_1 project to src/onchain.svg.

Deploying

Deploy all contracts to Goerli: forge script script/Goerli_Deploy.s.sol --rpc-url $GOERLI_RPC_URL --broadcast --verify

Deploy only the DefaultTokenUriResolver to Goerli: forge script script/Goerli_Deploy_DeafultResolverOnly.s --rpc-url $GOERLI_RPC_URL --broadcast --verify

Deploy all contracts to Mainnet: forge script script/Mainnet_Deploy.s.sol --rpc-url $MAINNET_RPC_URL --broadcast --verify

Deploy only the DefaultTokenUriResolver to Mainnet: forge script script/Mainnet_Deploy_DefaultResolverOnly.s.sol --rpc-url $MAINNET_RPC_URL --broadcast --verify

Design

TokenUriResolver.sol

JBProjects's tokenURI(uint256 _projectId) function will call this contract's getUri(uint256 _projectId) function. TokenUriResolver will check if the given project has a custom resolver set. If so, it will call getUri(uint256 _projectId) on that contract. If not, or if that call to the custom resolver fails, it will call the getUri function on the DefaultUriResovler.

DefaultUriResolver.sol

This resolver generates metadata including an onchain SVG for each JBProject using the JBDirectory v3 based on values returned form its primary ETH terminal. This Default resolver allows project owners to customize the color of their project's NFT metadata with three theme colors.

For projects that are not configured to use this directory, the resolver will return a basic metadata description informing the project owner that they can get rich realtime metadata by upgrading to JBDirectory V3.

Layout

Each row of the output SVG is 30 characters long. The Capsules typeface is monospaced, so as long as each row is composed of 30 characters, it will fit the image perfectly. Each row begins and ends with two space characters for visual symmetry.

Unicode and small cap characters are used to enhance aesthetics of the output SVG. These characters are sometimes composed of multiple bytes. For example, while the character L is one byte, the small cap ʟ is two bytes. The version of the Capsules typeface that was stored on Ethereum did not include intelligent small caps assignment, and so we are forced to manually specify the small caps variant.

String length is calculated onchain using bytes(string).length. As a result, naively counting each byte as a single display character would fail for unicode and small caps, which may constitute more bytes, but only one monospaced visual character output. Thus calls to the pad function rely on passing desired targetLength values. If we're drawing the left side of a row, we might concatenate a string composed of two spaces with a right-padded string of 13 characters. If the string has no special characters, then we can simply call pad(false, "L", 13), but if the string contains a special character, we'll have to add the number of extra bytes needed to represent it to the third argument: pad (false, "ʟ", 14).

Additional resources

  • Useful byte length checker https://mothereff.in/byte-counter

Credits

This project would not have been possible without the following contributions. Thank you!

  • Capsules is an onchain typeface by Peripheralist.
  • The ffi script and open.js was developed by Jeton Connu.
  • Dr.Gorilla provided devops support during the development of this project.
  • Jango and the Juicebox Contract Crew created the Juicebox protocol.