🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@leap-network/v4-utils-js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leap-network/v4-utils-js

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

latest
npmnpm
Version
0.1.10
Version published
Maintainers
1
Created
Source

PoolTogether Brand


🧰 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 @leap-network/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 @leap-network/v4-utils-js
yarn add @leap-network/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 '@leap-network/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 '@leap-network/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

FAQs

Package last updated on 12 Aug 2024

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