diff --git a/scripts/settleCompetitionRound.ts b/scripts/settleCompetitionRound.ts index f179387..7ec2ac6 100644 --- a/scripts/settleCompetitionRound.ts +++ b/scripts/settleCompetitionRound.ts @@ -68,8 +68,8 @@ async function settleSweepstakesCompetition(provider) { const txSig = await competitionClient.settleAllCompetitors( competitionKey, competitionAccount.roundNumber, - 3, - 3 + 11, + 1 ); console.log(txSig); } @@ -105,6 +105,20 @@ async function settleSweepstakesCompetition(provider) { competitionAccount.status, 'winnerAndPrizeRandomnessComplete' ); + + if ( + competitionAccount.prizeRandomness.eq( + competitionAccount.prizeRandomnessMax + ) + ) { + console.log('PRIZE BUCKET #1 selected!'); + } else if ( + competitionAccount.prizeRandomness.lte(details.prizePoolOddsNumerator[0]) + ) { + console.log('PRIZE BUCKET #3 selected!'); + } else { + console.log('PRIZE BUCKET #2 selected!'); + } } if (isReadyForSettlement) { @@ -115,7 +129,7 @@ async function settleSweepstakesCompetition(provider) { console.log(txSig); - await sleep(1000); + await sleep(2000); competitionAccount = await program.account.competition.fetch( competitionKey ); @@ -125,6 +139,8 @@ async function settleSweepstakesCompetition(provider) { ); } } + + console.log('COMPLETE!'); } try { diff --git a/ts/sdk/src/competitionClient.ts b/ts/sdk/src/competitionClient.ts index 908d051..820693d 100644 --- a/ts/sdk/src/competitionClient.ts +++ b/ts/sdk/src/competitionClient.ts @@ -418,7 +418,7 @@ export class CompetitionsClient { instructions.push(initCompetitorIx); if (instructions.length >= chunkSize) { // no need to await - this.createAndSendTxn(instructions, { + await this.createAndSendTxn(instructions, { computeUnitParams: { units: 1_400_000, }, @@ -607,10 +607,23 @@ export class CompetitionsClient { maxPrize, ]; + let prizePoolTotal = new BN(0); // Start with a sum of 0 + prizePools.forEach((prize) => { + prizePoolTotal = prizePoolTotal.add(prize); // Add each prize to the sum + }); + + const prizePoolOddsNumerators = [ + prizePoolTotal.div(prizePools[0]), + prizePoolTotal.div(prizePools[1]), + new BN(1), + ]; + return { roundNumber: competitionAccount.roundNumber, roundEndTs: competitionAccount.nextRoundExpiryTs, prizePools: prizePools, + prizePoolOddsNumerator: prizePoolOddsNumerators, + prizePoolOddsDenominator: prizePoolTotal, }; } /** @@ -655,7 +668,6 @@ export class CompetitionsClient { let earliestPulledSlot = Number.MAX_SAFE_INTEGER; while (!fetchedAllLogs) { - const response = await fetchLogs( this.driftClient.connection, this.program.programId, @@ -663,7 +675,11 @@ export class CompetitionsClient { oldestFetchedTx ); - if (!response?.transactionLogs || response.transactionLogs.length === 0 || response?.earliestSlot >= earliestPulledSlot) { + if ( + !response?.transactionLogs || + response.transactionLogs.length === 0 || + response?.earliestSlot >= earliestPulledSlot + ) { fetchedAllLogs = true; break; }