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/v4-utils-js

v0.1.7

Published

Utility library for PoolTogether V4 off-chain calculations, computations and core logic.

Downloads

494

Readme

🧰 Javascript Utilility Library - PoolTogether V4

Tests Coverage Status ts GPLv3 license npm

Application | Contracts | Documentation | Draw Calculator | Frontend Client | Static Cache

Calculations, Computations and Core Logic

The @pooltogether/v4-utils-js node module package provides calculations, computations and core logic for the PoolTogether V4 protocol.

Assisting with low-level tasks like hashing addresses to generate picks and calculating the total number of prizes for a prize tier. The calculations namespaced functions are modular: consuming low-level inputs/types to parity smart contract EVM operations.

High-order operations like filtering for a users winning picks and processing chain state (draws, prizeDistributions, etc..) to analyze/predict short and long term outcomes are included in the computations namespaced functions.

🧮 Caclulations:

Arithmetic and operations to match v4-core smart contract operations:

🖥️ Computations:

Consume protocol chain state and return computed outcomes:

🏆 Core:

Gain insights into the protocol state by analyzing and encoding historical and potential chain state.

🙋 Potential Additions:

  • poolAverageYieldBetweenTimestamps
  • userAverageYieldBetweenTimestamps
  • oddsPerPrizeTierUsingNormalizedBalance
  • encodeDrawPercentageRateAtomicUpdatesAcrossChains

Create Issue to request new features.Open Pull Request adhering to Contribution guidelines.

💾 Installation

This project is available as an NPM package:

npm install @pooltogether/v4-utils-js
yarn add @pooltogether/v4-utils-js

The repo can be cloned from Github for contributions.

git clone https://github.com/pooltogether/v4-utils-js

🏆 Quickstart (Claim Winning Picks)

Core utility functions like winningPicks(user, draw, prizeDistribution) calculate, compute and encode any EVM chain compatible transaction with the maximum number of winning picks using the input arguments.

In short, if you just need to calulcate winning picks and claim prizes the winningPicks function is for you 👋

import { Wallet } from '@ethersproject/wallet';
import { providers } from '@ethersproject/provider';
import { winningPicks, computeWinningPicks, encodeWinningPicks } from '@pooltogether/v4-utils-js';

// Compute and Encode Winning Picks Seperately
const computedPicks = computeWinningPicks(user, [draw], [prizeDistribution]);
const encodePicks = encodeWinningPicks(user, computedWinningPicks);

// Compute and Encode Winning Picks Together
const computedAndEncodedWinningPicks = winningPicks(user, [draw], [prizeDistribution]);

// Send Encoded Transaction to Mainnet
const wallet = Wallet.createRandom().connect(providers.getDefaultProvider())
wallet.send(computedAndEncodedWinningPicks.encodedWinningPickIndices)

🪜 Examples

import { BigNumber } from '@ethersproject/bignumber';
import { parseEther } from '@ethersproject/units';
import { winningPicks, utils } from '@pooltogether/v4-utils-js';

const user = {
    address: '0x0000000000000000000000000000000000000001',
    normalizedBalances: [
        parseEther('0.1'), // 10% of totalSupply
    ],
};

const draw = {
    drawId: 1,
    winningRandomNumber: BigNumber.from(
        '0x0000000000000000000000000000000000000000000000000000000000000001'
    ),
};

const prizeDistribution = {
    bitRangeSize: 4,
    matchCardinality: 10,
    numberOfPicks: 1000,
    prize: parseEther('1000'),
    maxPicksPerUser: 30,
    tiers: [
        // Tier prizeAmount is 100% split between 10 tiers. 
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        utils.formatTierPercentage('0.1'),
        0,
        0,
        0,
        0,
        0,
        0,
    ],
};

const generatedPicks = winningPicks(user, [draw], [prizeDistribution]);
/**
userAddress: string;
drawIds: number[];
winningPickIndices: BigNumber[][];
encodedWinningPickIndices: string;
* -------------------
userAddress: '0x0000000000000000000000000000000000000001',
drawIds: [1],
winningPickIndices: [[1]],
encodedWinningPickIndices: '0x000...2000...0001'
* /

💻 Developer Experience

The package is setup using the TSDX zero-config CLI which includes:

  • Typescript
  • Rollup
  • Jest
  • Prettier
  • ESLint

Minor changes have been made to extend the default configuration.

ESLint

The TSDX linting configuration is overwritten to include override(s)* for:

  • Import/Order (used to enforce consistent module import ordering)
*The ESLint overrides may incorrectly be interpreted by VSCode since the nested config file is ignored in the IDE

📖 Documentation

Namespaces

References