diff --git a/src/bets.json b/src/bets.json index 5cf0a76..933ec8c 100644 --- a/src/bets.json +++ b/src/bets.json @@ -54,30 +54,6 @@ { "name": "system_program", "address": "11111111111111111111111111111111" - }, - { - "name": "bet_vault_token_account", - "writable": true, - "optional": true - }, - { - "name": "fee_wallet_token_account", - "writable": true, - "optional": true - }, - { - "name": "owner_referrer_token_account", - "writable": true, - "optional": true - }, - { - "name": "joiner_referrer_token_account", - "writable": true, - "optional": true - }, - { - "name": "token_program", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -150,20 +126,6 @@ { "name": "system_program", "address": "11111111111111111111111111111111" - }, - { - "name": "payer_token_account", - "writable": true, - "optional": true - }, - { - "name": "bet_vault_token_account", - "writable": true, - "optional": true - }, - { - "name": "token_program", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -182,20 +144,6 @@ { "name": "nonce", "type": "u64" - }, - { - "name": "is_native_sol", - "type": "bool" - }, - { - "name": "token_mint", - "type": { - "option": "pubkey" - } - }, - { - "name": "token_decimals", - "type": "u8" } ] }, @@ -271,20 +219,6 @@ { "name": "system_program", "address": "11111111111111111111111111111111" - }, - { - "name": "payer_token_account", - "writable": true, - "optional": true - }, - { - "name": "bet_vault_token_account", - "writable": true, - "optional": true - }, - { - "name": "token_program", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -331,20 +265,6 @@ { "name": "system_program", "address": "11111111111111111111111111111111" - }, - { - "name": "bet_vault_token_account", - "writable": true, - "optional": true - }, - { - "name": "joiner_token_account", - "writable": true, - "optional": true - }, - { - "name": "token_program", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -386,28 +306,8 @@ "errors": [ { "code": 6000, - "name": "BetNotFilled", - "msg": "Bet is not filled yet!" - }, - { - "code": 6001, - "name": "BetAlreadyFilled", - "msg": "Bet is already filled" - }, - { - "code": 6002, - "name": "InvalidWinner", - "msg": "The winner must be either the owner or the joiner of the bet." - }, - { - "code": 6003, - "name": "InvalidFeeCollector", - "msg": "Please use the correct fee collector address" - }, - { - "code": 6004, - "name": "JoinerAccountNotProvided", - "msg": "" + "name": "CustomError", + "msg": "Custom error message" } ], "types": [ @@ -439,20 +339,6 @@ { "name": "wager", "type": "u64" - }, - { - "name": "is_native_sol", - "type": "bool" - }, - { - "name": "token_mint", - "type": { - "option": "pubkey" - } - }, - { - "name": "token_decimals", - "type": "u8" } ] } diff --git a/src/bets.ts b/src/bets.ts index 3e55451..4942794 100644 --- a/src/bets.ts +++ b/src/bets.ts @@ -60,30 +60,6 @@ export type Bets = { { "name": "systemProgram", "address": "11111111111111111111111111111111" - }, - { - "name": "betVaultTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "feeWalletTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "ownerReferrerTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "joinerReferrerTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "tokenProgram", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -156,20 +132,6 @@ export type Bets = { { "name": "systemProgram", "address": "11111111111111111111111111111111" - }, - { - "name": "payerTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "betVaultTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "tokenProgram", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -188,20 +150,6 @@ export type Bets = { { "name": "nonce", "type": "u64" - }, - { - "name": "isNativeSol", - "type": "bool" - }, - { - "name": "tokenMint", - "type": { - "option": "pubkey" - } - }, - { - "name": "tokenDecimals", - "type": "u8" } ] }, @@ -277,20 +225,6 @@ export type Bets = { { "name": "systemProgram", "address": "11111111111111111111111111111111" - }, - { - "name": "payerTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "betVaultTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "tokenProgram", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -337,20 +271,6 @@ export type Bets = { { "name": "systemProgram", "address": "11111111111111111111111111111111" - }, - { - "name": "betVaultTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "joinerTokenAccount", - "writable": true, - "optional": true - }, - { - "name": "tokenProgram", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ], "args": [ @@ -392,28 +312,8 @@ export type Bets = { "errors": [ { "code": 6000, - "name": "betNotFilled", - "msg": "Bet is not filled yet!" - }, - { - "code": 6001, - "name": "betAlreadyFilled", - "msg": "Bet is already filled" - }, - { - "code": 6002, - "name": "invalidWinner", - "msg": "The winner must be either the owner or the joiner of the bet." - }, - { - "code": 6003, - "name": "invalidFeeCollector", - "msg": "Please use the correct fee collector address" - }, - { - "code": 6004, - "name": "joinerAccountNotProvided", - "msg": "" + "name": "customError", + "msg": "Custom error message" } ], "types": [ @@ -445,20 +345,6 @@ export type Bets = { { "name": "wager", "type": "u64" - }, - { - "name": "isNativeSol", - "type": "bool" - }, - { - "name": "tokenMint", - "type": { - "option": "pubkey" - } - }, - { - "name": "tokenDecimals", - "type": "u8" } ] } diff --git a/src/close.ts b/src/close.ts index 60e039b..06fc427 100644 --- a/src/close.ts +++ b/src/close.ts @@ -1,7 +1,8 @@ import { Connection, PublicKey, Keypair, clusterApiUrl, LAMPORTS_PER_SOL, SystemProgram } from "@solana/web3.js"; import { Bets } from "./bets"; import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor"; -import { clusterUrl, cocSk, getRandomInt, testerSk } from "./shared"; +import { clusterUrl, cocSk, feeWallet, getRandomInt, testerSk } from "./shared"; +import { getAssociatedTokenAddress } from "@solana/spl-token"; const IDL = require('./bets.json'); async function close(){ @@ -26,9 +27,48 @@ async function close(){ try { const bet_list = await program.account.betsList.fetch(bet_list_pda); + + for (const bet of bet_list.bets) { try { const betAcc = await program.account.betVault.fetch(bet); + + const [betVaultPda] = await PublicKey.findProgramAddress( + [ + Buffer.from("bet_vault"), + keypair.publicKey.toBuffer(), + Buffer.from(betAcc.gameId), + ], + program.programId + ); + + const ownerRefferer = new PublicKey("BaTgUMPsk8fZoEMwig81Pw1KHmPpoYt31oiR5Qr2c8XR"); + const joinerRefferer = feeWallet; + + const betVaultTokenAccount = await getAssociatedTokenAddress( + betAcc.tokenMint, + betVaultPda, + true + ); + + const feeWalletTokenAccount = await getAssociatedTokenAddress( + betAcc.tokenMint, + feeWallet, + true + ); + + const ownerReferrerTokenAccount = await getAssociatedTokenAddress( + betAcc.tokenMint, + ownerRefferer, + true + ); + + const joinerReferrerTokenAccount = await getAssociatedTokenAddress( + betAcc.tokenMint, + joinerRefferer, + true + ); + const winner = betAcc.owner; console.log(`Closing ${bet}`); @@ -36,9 +76,13 @@ async function close(){ betVault: bet, betsList: bet_list_pda, winner: winner, - feeWallet: new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"), - ownerReferrer: new PublicKey("BaTgUMPsk8fZoEMwig81Pw1KHmPpoYt31oiR5Qr2c8XR"), - joinerReferrer: new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"), + feeWallet: feeWallet, + ownerReferrer: ownerRefferer, + joinerReferrer: joinerRefferer, + betVaultTokenAccount: betAcc.isNativeSol ? null : betVaultTokenAccount, + feeWalletTokenAccount: betAcc.isNativeSol ? null : feeWalletTokenAccount, + ownerReferrerTokenAccount: betAcc.isNativeSol ? null : ownerReferrerTokenAccount, + joinerReferrerTokenAccount: betAcc.isNativeSol ? null : joinerReferrerTokenAccount, }).rpc({ skipPreflight: false, maxRetries: 3 diff --git a/src/shared.ts b/src/shared.ts index 7b80384..0942f7c 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -4,6 +4,8 @@ export const clusterUrl = clusterApiUrl("devnet"); export const testerSk = [0,86,239,216,67,18,45,223,17,96,119,58,187,90,175,61,72,117,44,13,224,255,64,74,222,14,50,134,240,250,14,212,13,59,115,13,19,107,33,227,1,184,184,96,20,214,181,23,53,244,82,197,36,189,83,82,134,211,83,200,67,14,143,90]; export const cocSk = [202,150,67,41,155,133,176,172,9,100,150,190,239,37,69,73,18,16,76,65,164,197,99,134,240,151,112,65,61,122,95,41,9,44,6,237,108,123,86,90,144,27,1,160,101,95,239,35,53,91,195,220,22,214,2,84,132,37,20,236,133,242,104,197]; +export const feeWallet = new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"); + export function getRandomInt(max) { return Math.floor(Math.random() * max); } \ No newline at end of file