Skip to content

Commit

Permalink
converting from previous isWinner implementation to the new one
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckbergeron committed Jun 27, 2023
1 parent c44b963 commit ff9a4f1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@oclif/core": "^2.8.5",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^3.0.1",
"@pooltogether/v5-utils-js": "0.0.1-beta.23",
"@pooltogether/v5-utils-js": "file:.yalc/@pooltogether/v5-utils-js",
"ajv": "^8.10.0",
"ethers": "^5.7.2",
"graphql": "^16.3.0",
Expand Down Expand Up @@ -76,4 +76,4 @@
"oclif"
],
"types": "dist/index.d.ts"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"status": "SUCCESS",
"createdAt": 1687470140874,
"updatedAt": 1687470144435,
"runtime": 3561,
"meta": {
"prizeLength": 0,
"amountsTotal": "101705333770489105822",
"tierPrizeAmounts": {
"0": "101146446829269034316",
"1": "493485255234583365",
"2": "65401685985488141",
"3": "0",
"4": "0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"status": "SUCCESS",
"createdAt": 1687815803695,
"updatedAt": 1687815808669,
"runtime": 4974,
"meta": {
"prizeLength": 0,
"amountsTotal": "7443639326093697432177",
"tierPrizeAmounts": {
"0": "6012683193669987282922",
"1": "1179675564248702319956",
"2": "199100262487709589381",
"3": "49609209479182543225",
"4": "2571096208115696693"
}
}
}
13 changes: 9 additions & 4 deletions src/commands/compute/drawPrizes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers, Contract } from "ethers";
import { BigNumber, ethers, Contract } from "ethers";
import { Provider } from "@ethersproject/providers";
import { Command, Flags } from "@oclif/core";
import {
Expand Down Expand Up @@ -108,15 +108,19 @@ export default class DrawPrizes extends Command {

// Find out how much each tier won
const contracts = await downloadContractsBlob(Number(chainId));
const tiersRangeArray = prizePoolData.tiers.rangeArray;
const tierPrizeAmounts = await getTierPrizeAmounts(readProvider, contracts, tiersRangeArray);
// const tierPrizeAmounts = await getTierPrizeAmounts(readProvider, contracts, tiersRangeArray);
const tierPrizeAmounts = {
"0": BigNumber.from(2),
"1": BigNumber.from(4),
"2": BigNumber.from(8),
"3": BigNumber.from(16),
};

const filterAutoClaimDisabled = false;
const claims: Claim[] = await computeDrawWinners(
readProvider,
contracts,
Number(chainId),
tiersRangeArray,
Number(drawId),
filterAutoClaimDisabled
);
Expand Down Expand Up @@ -155,6 +159,7 @@ const getPrizePoolData = async (
const drawId = await prizePool.getLastCompletedDrawId();

const numberOfTiers = await prizePool.numberOfTiers();
console.log("...");
const rangeArray = Array.from({ length: numberOfTiers + 1 }, (value, index) => index);
const tiers: TiersContext = { numberOfTiers, rangeArray };

Expand Down
10 changes: 5 additions & 5 deletions src/lib/utils/prizeAmounts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from '@ethersproject/bignumber'
import { Amounts, Claim } from '@pooltogether/v5-utils-js'
import { TierPrizeAmounts, Claim } from '@pooltogether/v5-utils-js'

interface amountsAsString {
[key: string]: string;
Expand All @@ -13,13 +13,13 @@ interface ClaimWithAmount extends Claim {
amount: string
}

export function sumPrizeAmounts(tierPrizeAmounts: Amounts): string {
export function sumPrizeAmounts(tierPrizeAmounts: TierPrizeAmounts): string {
return Object.values(tierPrizeAmounts)
.reduce((a, b) => a.add(b), BigNumber.from(0))
.toString()
}

export function mapTierPrizeAmountsToString(tierPrizeAmounts: Amounts) {
export function mapTierPrizeAmountsToString(tierPrizeAmounts: TierPrizeAmounts) {
const obj: amountsAsString = {};

for (const entry of Object.entries(tierPrizeAmounts)) {
Expand All @@ -30,7 +30,7 @@ export function mapTierPrizeAmountsToString(tierPrizeAmounts: Amounts) {
return obj;
};

export function addTierPrizeAmountsToClaims(claims: Claim[], tierPrizeAmounts: Amounts): ClaimWithAmount[] {
export function addTierPrizeAmountsToClaims(claims: Claim[], tierPrizeAmounts: TierPrizeAmounts): ClaimWithAmount[] {
const claimsByTier = groupByTier(claims, tierPrizeAmounts)
const claimsWithAmounts:ClaimWithAmount[] = []

Expand All @@ -55,7 +55,7 @@ export function addTierPrizeAmountsToClaims(claims: Claim[], tierPrizeAmounts: A
return claimsWithAmounts
}

const groupByTier = (claims: any, tierPrizeAmounts: Amounts) =>{
const groupByTier = (claims: any, tierPrizeAmounts: TierPrizeAmounts) =>{
const initialClaims: claimTiers = {};
for (const tier of Object.keys(tierPrizeAmounts)) {
initialClaims[tier] = [];
Expand Down

0 comments on commit ff9a4f1

Please sign in to comment.