
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@pooltogether/draw-calculator-js
Advanced tools
This library includes a stateless Typescript model of the Solidity DrawCalculator. It is intended to be uses as a tool to easily check if a User has won a prize for a particular draw. This could also be calculated on-chain through the DrawCalculator::calculate()
view function but this library is much faster.
This project is available as an NPM package:
$ yarn add @pooltogether/draw-calculator-js
To create a claim or calculate winnings for an address:
yarn add @pooltogether/draw-calculator-js
in your project to install the package.import {drawCalculator, Draw, PrizeDistribution, DrawResults, filterResultsByValue, generatePicks, prepareClaims } from "@pooltogether/draw-calculator-js"
Starting with a particular drawId
and userAddress
, fetch the Draw information from the DrawBuffer contract:
const drawBuffer: Contract = new ethers.Contract(address, drawBufferAbi, signerOrProvider);
const drawId: number = await drawBuffer.getNewestDraw(); // can go back cardinality in time (8 draws)
const draw: Draw = await drawBuffer.functions.getDraw(drawId); // read-only rpc call
Next fetch the PrizeDistribution for the drawId
from the PrizeDistributionBuffer contract:
// get PrizeDistribution from the DrawCalculatorHistory contract for a particular drawId
const PrizeDistributionBufferContract: Contract = new ethers.Contract(
address,
prizeDistributionAbi,
signerOrProvider,
);
const prizeDistribution = await PrizeDistributionBufferContract.functions.getPrizeDistribution(
drawId,
); // read-only rpc call
Next, get the users balance using the convenient getNormalizedBalancesForDrawIds(address _user, uint32[] calldata _drawIds)
view method
on the DrawCalculator contract which returns an array of balances for drawIds:
W
const drawCalculator: Contract = new ethers.Contract(address, drawCalculatorAbi, signerOrProvider);
const balances = await drawCalculator.functions.getNormalizedBalancesForDrawIds(userAddress, [
drawId,
]); // read-only rpc call
Run this draw-calculator-js
library locally to see the user has any prizes to claim:
const exampleUser: User = {
address: userAddress // user address we want to calculate for
normalizedBalances: balances
}
let results: DrawResults = batchCalculateDrawResults([prizeDistribution], [draw], exampleUser)
The results.totalValue
field should indicate the total amount of prize available for userAddress
for the drawId
.
These results may then need to be filtered by value, since the user can only claim prizeDistribution.maxPicksPerUser
number of prizes per draw.
results = filterResultsByValue(results, prizeDistribution.maxPicksPerUser);
Finally, to claim a prize, forward these DrawResults
to prepareClaims(user: User, drawResult: DrawResults[])
to generate the data for the on-chain PrizeDistributor claim()
call:
const claim: Claim = prepareClaims(user, [results]);
The on-chain call to PrizeDistributor::claim(address _user, uint32[] calldata _drawIds, bytes calldata _data)
can then be populated and called with this data:
const PrizeDistributorContract = new ethers.Contract(
address,
PrizeDistributorAbi,
signerOrProvider,
);
await PrizeDistributorContract.functions.claim(
claim.userAddress,
claim.drawIds,
claim.encodedWinningPickIndices,
); //write rpc call
Congratulations you have now claimed a prize!
todo.
A full breakdown of the types can be found here
Unit tests can be run using:
$ yarn test
Fork/clone this repo. Create a pull request with the changes you would like to make. Unit tests must be passing.
FAQs
PoolTogether Draw Calculator
The npm package @pooltogether/draw-calculator-js receives a total of 80 weekly downloads. As such, @pooltogether/draw-calculator-js popularity was classified as not popular.
We found that @pooltogether/draw-calculator-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.