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

@pooltogether/draw-calculator-cli

v0.1.0-beta.19

Published

Draw Calculator to compute User winning picks.

Downloads

73

Readme

Draw Calculator CLI

CI npm version TypeScript definitions on DefinitelyTyped
A NodeJs CLI tool for calculating prizes for PoolTogether v4 draws.

Description

This CLI uses the TWAB subgraphs across networks to calculate TWABS for a given drawId, ticket and network (specified as CLI input args).

Then creates a thread for each address (using Piscina) to call the Draw Calculator JS library and outputs a prizes.json file (written to outputDir CLI arg) with structure:

[
    {
        address: "0x1a",
        pick: "1319",
        tier: 5,
        amount: "9999999",
    },
    {
        address: "0x1b",
        pick: "2636",
        tier: 5,
        amount: "9999999",
    },
];

alongside a <address>.json of similar structure for each winning address.

This tool can be run locally or in a cloud setting.

Status File (status.json)

{
  "status": "RUNNING",
  "createdAt": "11"
}

Success

{
  "status": "SUCCESS",
  "createdAt": "11",
  "updatedAt": "33",
  "runtime": "22",
  "meta": {
    "prizeLength": "10",
    "amountsTotal": "5000000"
  }
}

Failure

Provider Failure

{
  "status": "FAILURE",
  "createdAt": "11",
  "updatedAt": "33",
  "runtime": "22",
  "error": {
    "code": "1",
    "msg": "provider-error"
  }
}

Subgraph Failure

{
  "status": "FAILURE",
  "createdAt": "11",
  "updatedAt": "33",
  "runtime": "22",
  "error": {
    "code": "2",
    "msg": "subgraph-error"
  }
}

Unexpected Failure

{
  "status": "FAILURE",
  "createdAt": "11",
  "updatedAt": "33",
  "runtime": "22",
  "error": {
    "code": "3",
    "msg": "unexpected-error"
  }
}

Invalid Prize Schema Failure

{
  "status": "FAILURE",
  "createdAt": "11",
  "updatedAt": "33",
  "runtime": "22",
  "error": {
    "code": "4",
    "msg": "invalid-prize-schema"
  }
}

Adding a new network

  1. Create a (new subgraph)[https://github.com/pooltogether/twab-subgraph] for the network.
  2. Add the subgraph query endpoint to src/constants.ts and lookup logic to src/network/getSubgraphUrlForNetwork.ts
  3. Add Ethers Provider RPC URL to the .env and lookup logic to src/getters/getRpcProvider.ts

Usage

  1. Install the CLI tool by running yarn add @pooltogether/draw-calculator-cli

  2. Add the required env variables listed in .envrc.example to .envrc and run direnv allow.

  3. The CLI has a number of required args:

.requiredOption("-c, --chainId <string>", "select network (mainnet (1), rinkeby (4), polygon (137) or mumbai (80001) etc.)")

.requiredOption("-t, --ticket <string>", "ticket contract address")

.requiredOption("-d, --drawId <string>", "drawId to perform lookup for")

.requiredOption("-o, --outputDir <string>", "relative path to output resulting JSON blob");`

Run for Multiple Draws

A convience bash script for running the CLI tool over multiple runs is included at scripts/runLoop.sh. After modifying with the desired params, this can be run with:

chmod +x ./scripts/runLoop.sh

./scripts/runLoop

Example Use

Mainnet

node ./dist/index.js -c 1 -t 0xdd4d117723C257CEe402285D3aCF218E9A8236E1 -d 8 -o ./results will run the CLI for Mainnet ticket "0xdd4d117723C257CEe402285D3aCF218E9A8236E1" for drawId 8, and output the resulting JSON files in ./results directory.

Polygon

node ./dist/index.js -c 137 -t 0x6a304dFdb9f808741244b6bfEe65ca7B3b3A6076 -d 32 -o ./results will run the CLI for Polygon ticket "0xdd4d117723C257CEe402285D3aCF218E9A8236E1" for drawId 32, and output the resulting JSON files in ./results directory.

Avalanche

node ./dist/index.js -c 43114 -t 0xb27f379c050f6ed0973a01667458af6ecebc1d90 -d 1 -o ./results will run the CLI for Avalanche ticket "0xb27f379c050f6ed0973a01667458af6ecebc1d90" for drawId 1, and output the resulting JSON files in ./results directory.

Rinkeby

node ./dist/index.js -c 4 -t 0xF04E1400Cf4f0867880e88e2201EDecCDD36227c -d 1 -o ./results

Mumbai:

node ./dist/index.js -c 80001 -t 0x8c26F9526a0b9639Edb7080dFba596e8FeFafAcC -d 1 -o ./results