Created
December 7, 2024 06:29
-
-
Save ducphamle2/52c159c8b4ee6328a8b09fc12d22979f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const moderators = [ | |
| new PublicKey("FcfgHRQPs8ZNnNegVQpHcY1czcb9vgci2JNZpFaxoMQe"), | |
| new PublicKey("GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU"), | |
| ]; | |
| const maxAddress = new PublicKey( | |
| "6EPdGj7TgLjCPth3XSkWFuoTjGXSR6pV6Sn7LKmKCDYE" | |
| ); | |
| const maxAta = getAssociatedTokenAddressSync(currencyMint, maxAddress); | |
| const maxTokenAccount = await connection.getTokenAccountBalance(maxAta); | |
| let currentMaxTokenValue = maxTokenAccount.value.uiAmount; | |
| for (const moderator of moderators) { | |
| const [eventConfigPda] = PublicKey.findProgramAddressSync( | |
| [ | |
| Buffer.from(EVENT_CONFIG), | |
| eventAuthority.toBytes(), | |
| moderator.toBytes(), | |
| currencyMint.toBytes(), | |
| chainlinkProgram.toBytes(), | |
| chainlinkFeed.toBytes(), | |
| ], | |
| program.programId | |
| ); | |
| let firstRound = 0; | |
| let unclaimedRounds = []; | |
| const config = await program.account.eventConfig.fetch(eventConfigPda); | |
| const currentRound = config.nextRoundId.toNumber() - 1; | |
| for (let i = firstRound; i <= currentRound; i++) { | |
| const [event] = PublicKey.findProgramAddressSync( | |
| [ | |
| Buffer.from(EVENT), | |
| eventConfigPda.toBytes(), | |
| new BN(i).toBuffer("le", 8), | |
| ], | |
| program.programId | |
| ); | |
| const [order] = PublicKey.findProgramAddressSync( | |
| [Buffer.from(ORDER), event.toBytes(), maxAddress.toBytes()], | |
| program.programId | |
| ); | |
| try { | |
| const orderData = await program.account.order.fetch(order); | |
| const eventData = await program.account.event.fetch(event); | |
| // if max bet wrong -> lose money, else we accumulate | |
| if ( | |
| (orderData.outcome.down && eventData.outcome.up) || | |
| (orderData.outcome.up && eventData.outcome.down) | |
| ) { | |
| continue; | |
| } | |
| const orderAmount = orderData.amount.toNumber() / Math.pow(10, 6); | |
| currentMaxTokenValue += orderAmount; | |
| unclaimedRounds.push(i); | |
| } catch (error) { | |
| console.log("Found no order for event " + i); | |
| } | |
| } | |
| console.log( | |
| `unclaimed rounds for mod ${moderator}: ${JSON.stringify( | |
| unclaimedRounds | |
| )}; ${unclaimedRounds.length}` | |
| ); | |
| } | |
| console.log("current max token value: ", currentMaxTokenValue); | |
| return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment