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

@samwitch/erc1155-orderbook

v1.1.3

Published

EFficient on-chain orderbook for ERC1155 tokens

Downloads

33

Readme

SWOB (SamWitchOrderBook) for ERC1155 NFTs

Continuous integration

swob

overall statements branches functions lines

This efficient order book utilises the BokkyPooBahsRedBlackTreeLibrary library for sorting prices allowing O(log n) for tree segment insertion, traversal, and deletion. It supports batch orders and batch cancelling, ERC2981 royalties, and a dev and burn fee on each trade.

It is kept gas efficient by packing data in many areas:

  • Four orders (uint24 quantity + uint40 order id) into a 256bit word giving a 4x improvement compared to using 1 storage slot per order
  • When taking from the order book no tokens/nfts are transferred. Instead the orderId is stored in a claimable array
  • The tokens claimable are packed with 3 orders per storage slot

The order book is kept healthy by requiring a minimum quantity that can be added - partial quantities can still be taken from the order book. Cancelling orders shifts all entries at that price level to remove gaps.

Constraints:

  • The order quantity to be added to the book is limited to ~16mil
  • The maximum number of orders in the book that can ever be added is limited to 1 trillion
  • The maximum number of orders that can be added to a specific price level in its lifetime is 16 billion
  • Cannot change tick for a tokenId after it's been set

While this order book was created for ERC1155 NFTs it could be adapted for ERC20 tokens.

Potential improvements:

  • TokenInfo could use uint64 for both members and packed 2 in an array if tokenIds are sequential and limited
  • Range delete of the red-black tree using split/join
  • When cancelling an order some of the shifting logic can be improved to move some orders in segments in 1 go.

To start copy the .env.sample file to .env and fill in PRIVATE_KEY at a minimum (starts with 0x).

yarn install

# To compile the contracts
yarn compile

# To run the tests
yarn test

# To get code coverage
yarn coverage

# To deploy all contracts
yarn deploy --network <network>
yarn deploy --network fantom_testnet

# Export abi
yarn abi

# To fork or open a node connection
yarn fork
yarn fork --fork <rpc_url>
yarn fork --fork https://rpc.ftm.tools

# To impersonate an account on a forked or local blockchain for debugging
yarn impersonate