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

unfold-lang

v0.1.2

Published

Unfold is a lightweight, domain-specific language for querying crypto wallets. It currently supports various operations, such as checking the ETH, ERC20, or ERC721 balance, on a single wallet address.

Downloads

4

Readme

Unfold

Unfold is a lightweight, domain-specific language for querying crypto wallets. It currently supports various operations, such as checking the ETH, ERC20, or ERC721 balance, on a single wallet address.

The primary benefit of Unfold is its simplicity in usage. You can learn the entire grammar in < 5 minutes, making it a perfect low-code environment for tokengating your storefront or community. Moreover, every runtime is sandboxed and isolated from the rest of the environment. This prevents malicious users from injecting Javascript into your websites.

Sounds interesting? Check out the demo!

Want to try it out? I've set up a playground just for you!

Installation

Unfold is available on npm. Just run the following command in your project.

You can also manually install Unfold. This is useful if you want to make significant changes to the interpreter architecture. Just clone the repo (or manually install it) and run npm install in the directory.

Set Up

After installation, you can get started in < 15 lines of code.

Under the Hood

Every time any Unfold code is written, a separate runtime instance needs to be created to execute the code.

To maintain generalizability to other L1/L2 chains, Unfold runtimes expect two inputs: the written code and a wallet context. Wallet contexts are responsible for providing methods and attributes that interact with the chain, such as address, queryNativeToken(), queryToken(tokenType, tokenAddress), and setChain(chainId).

The lexing/parsing of Unfold is handled by nearleyjs, which returns an abstract syntax tree in JSON. This tree is passed off to simple interpreter written in vanilla Javascript.

An example of an AST (for the first example in example_queries.txt) is shown below.

Writing Scripts

Every Unfold script is composed of statements. The Unfold runtime expects at most one statement per line. Unfold supports the usual comparators and conditional operations, as well as boolean values.

The syntax for an conditional statement is as follows.

A condition includes all of the usual comparators, logical symbols, and boolean values. Conditions can compare numbers (i.e. amount of USDC in a wallet) or addresses (i.e. for whitelisting).

A directive can be a return statement, a token assignment, a chain change, or another conditional statement.

The only type of variable in Unfold is a token. A token can be defined as follows.

TokenName can be any string. This identifier is stored a global state that can be reused by future statements.

TokenObject can be created by either specifying ERC20 or ERC721 with a contract address.

There is also a special TokenObject ETH that queries the amount of Ether in a given wallet address.

Any condition or value can be returned from the Unfold runtime through the return command.

Comments are prefaced with a pound symbol #. A comment must occupy its own line with no other code.

Roadmap

I'm not actively working on this project, but I'll be adding features as I need them.

I'll happily merge new contexts for other L1s, for example, Solana (with the help of @solana/web3js). I want this project to be as extensible and general-purpose as possible.

Adding new primitives to the grammar would be helpful. I'm currently thinking about lists, dicts, etc. Adding types like these would increase complexity by quite a bit (adding for loops, for example), but maybe the tradeoff is worth it.

A cool idea I've been having is to extend the grammar to call methods on contracts directly. Definitely an interesting exercise in language design!