0.0.1-beta.0 • Published 2 years ago

@pooltogether/v4-js v0.0.1-beta.0

Weekly downloads
-
License
GPL-3.0-only
Repository
-
Last release
2 years ago

PoolTogether V4 JS

Tests Coverage Status GPLv3 license

The v4-js module is a general purpose JS library for reading/writing to the Pooltogether V4 protocol.

Installation

This project is available as an NPM package:

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

The repo can be cloned from Github for contributions.

git clone https://github.com/pooltogether/v4-core

Overview

Setup

Core

Config

Fetching

Utils

Getting Started

Initializing

The v4-js module must be initialized with providers and a contract list.

Current mainnet and testnet contract lists can be used via the @pooltogether/v4-pool-data NPM package

The v4-js module must be initialized before blockchain read requests be executed.

import PoolTogetherV4, { config } from 'pooltogether/v4-js';

const ptv4 = new PoolTogetherV4(config.providersMainnet, mainnetContractList)

or

import { initialize, config } from 'pooltogether/v4-js';

const ptv4 = initialize(config.providersMainnet, mainnetContractList)

Providers

Providers being passed must inherit the Provider type interface from @ethersproject/abstract-provider. In other words, ethers provider interfaces like JsonRpcProvider, InfuraProvider, FallbackProvider, etc... are usable as Provider interfaces.

const providerMainnet = ethers.getDefaultProvider('mainnet');
const providerRinkeby = new ethers.providers.InfuraProvider('rinkeby', key)
const providerMumbai = new ethers.providers.JsonRpcProvider("https://rpc-mumbai.maticvigil.com");
const providers = { 1: providerMainnet, 4: providerRinkeby, 80001: providerMumbai }

computePrizeDistribution

To compute a PrizeDistribution for a specific PrizePool/Ticket supply a Draw (from the DrawBuffer) and contract addresses for L1 PrizeTierHistory and the target Ticket contract, plus secondary Ticket contract addresses in a list.

import { computePrizeDistribution } from '../src';

const draw = {
  winningRandomNumber: BigNumber.from('21288413488180966377126236036201345909019919575750940621513526137694302720820'),
  drawId: 1,
  timestamp: 1634410924,
  beaconPeriodStartedAt: 1634324400,
  beaconPeriodSeconds: 86400,
}

const prizeTierHistory = '0xdD1cba915Be9c7a1e60c4B99DADE1FC49F67f80D'
const ticketL1 = '0xdd4d117723C257CEe402285D3aCF218E9A8236E1'
const ticketL2 = '0x6a304dFdb9f808741244b6bfEe65ca7B3b3A6076'

const results = await computePrizeDistribution(draw, prizeTierHistory, ticketL1, [ticketL2])