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

@generationsoftware/js-winner-calc

v1.2.1

Published

Calculates PoolTogether V5 winners in JavaScript.

Downloads

6,928

Readme

PoolTogether JS Winner Calculator

This library calculates PoolTogether V5 winners completely in JavaScript for use in NodeJS or in a browser.

Installation

This library is installable as an NPM package using the following command:

npm i @generationsoftware/js-winner-calc

How to Calculate Winners for a Vault

[!Important] This script batches RPC queries for a given vault, so you'll need to run it for each vault that you want to check prizes for. If you are querying results for many users, it is recommended to use a private RPC endpoint to avoid public rate limits.

import { computeWinners } from "@generationsoftware/js-winner-calc";

const winners = await computeWinners({
  chainId: 10,
  rpcUrl: "https://mainnet.optimism.io/",
  prizePoolAddress: "0xF35fE10ffd0a9672d0095c435fd8767A7fe29B55",
  vaultAddress: "0xa52e38a9147f5eA9E0c5547376c21c9E3F3e5e1f",
  userAddresses: ["0xe24bC6c67fEF2FFe40283c1359dCE44bd19c72C4"],
})

The results will look like the following, with an array of winners and a mapping of prize tier to prize indices for each winner:

[
  {
    "user": "0xe24bC6c67fEF2FFe40283c1359dCE44bd19c72C4",
    "prizes": {
      "4": [
        11
      ],
      "5": [
        451,
        685,
        941
      ]
    }
  }
]

Optional Arguments

prizeTiers

Enables the calculation to be limited to only the listed prize tiers. Calculating wins for lower tiers only can significantly speed up the calculation. If this list is not passed to the function call, all active tiers will be computed.

[!Note] There is no validation of the tier numbers provided.

Example:

const winners = await computeWinners({
  ...,
  prizeTiers: [0,1,5]
})

multicallBatchSize

Set the multicallBatchSize argument in the input json file to limit multicall size (in bytes) for RPC calls. Different RPCs may have harsher limits than others.

Example:

const winners = await computeWinners({
  ...,
  multicallBatchSize: 2048
})

multicallAddress

Set the multicallAddress argument in the input json file to use a custom Multicall contract for RPC calls.

Example:

const winners = await computeWinners({
  ...,
  multicallAddress: '0xcA11bde05977b3631167028862bE2a173976CA11' // Gnosis Chiado testnet Multicall3 address
})

blockNumber

The blockNumber argument can be set to run the script at a specific block number instead of the current block. Must be either a number or string that can be parsed into a BigInt.

Example:

const winners = await computeWinners({
  ...,
  blockNumber: 121970626n
})

debug

The debug argument is an optional boolean. When set, some extra logs will be included to help debug issues.

Example:

const winners = await computeWinners({
  ...,
  debug: true
})

Local Development

  1. clone this repo
  2. run npm i
  3. run npm run dev