🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@pooltogether/draw-calculator-cli

Package Overview
Dependencies
Maintainers
6
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pooltogether/draw-calculator-cli

Draw Calculator to compute User winning picks.

latest
npmnpm
Version
0.1.0-beta.19
Version published
Maintainers
6
Created
Source

PoolTogether Brand


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

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

Usage

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

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

  • 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

FAQs

Package last updated on 01 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts