Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigz/improve-competition-settle-bundling #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions scripts/settleCompetitionRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ async function settleSweepstakesCompetition(provider) {
const txSig = await competitionClient.settleAllCompetitors(
competitionKey,
competitionAccount.roundNumber,
3,
3
11,
1
);
console.log(txSig);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -115,7 +129,7 @@ async function settleSweepstakesCompetition(provider) {

console.log(txSig);

await sleep(1000);
await sleep(2000);
competitionAccount = await program.account.competition.fetch(
competitionKey
);
Expand All @@ -125,6 +139,8 @@ async function settleSweepstakesCompetition(provider) {
);
}
}

console.log('COMPLETE!');
}

try {
Expand Down
22 changes: 19 additions & 3 deletions ts/sdk/src/competitionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
};
}
/**
Expand Down Expand Up @@ -655,15 +668,18 @@ export class CompetitionsClient {
let earliestPulledSlot = Number.MAX_SAFE_INTEGER;

while (!fetchedAllLogs) {

const response = await fetchLogs(
this.driftClient.connection,
this.program.programId,
'confirmed',
oldestFetchedTx
);

if (!response?.transactionLogs || response.transactionLogs.length === 0 || response?.earliestSlot >= earliestPulledSlot) {
if (
!response?.transactionLogs ||
response.transactionLogs.length === 0 ||
response?.earliestSlot >= earliestPulledSlot
) {
fetchedAllLogs = true;
break;
}
Expand Down