Compare commits

...

2 Commits

Author SHA1 Message Date
warlock
0f9ea8018a referral 2025-05-18 20:32:12 +05:30
warlock
f1ef2c4b8c token sup 2025-05-18 15:57:14 +05:30
6 changed files with 22 additions and 284 deletions

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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,17 @@ 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 ownerRefferer = new PublicKey("BaTgUMPsk8fZoEMwig81Pw1KHmPpoYt31oiR5Qr2c8XR");
const joinerRefferer = feeWallet;
const winner = betAcc.owner;
console.log(`Closing ${bet}`);
@ -36,9 +45,9 @@ 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,
}).rpc({
skipPreflight: false,
maxRetries: 3

View File

@ -2,7 +2,7 @@ import { Connection, PublicKey, Keypair, clusterApiUrl, LAMPORTS_PER_SOL, System
import { Bets } from "./bets";
import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor";
import { clusterUrl, cocSk, getRandomInt, testerSk } from "./shared";
import { createAssociatedTokenAccountInstruction, getAccount, getAssociatedTokenAddress, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
// import { createAssociatedTokenAccountInstruction, getAccount, getAssociatedTokenAddress } from "@solana/spl-token";
const IDL = require('./bets.json');
async function create() {
@ -45,59 +45,17 @@ async function create() {
program.programId
);
// For native SOL bet
const isNativeSol = false;
const tokenMint = new PublicKey("8iFREvVdmLKxVeibpC5VLRr1S6X5dm7gYR3VCU1wpump");
// Create the bet vault token account if it doesn't exist
let betVaultTokenAccount;
if (!isNativeSol) {
// For SPL tokens, create the token account
betVaultTokenAccount = await getAssociatedTokenAddress(
tokenMint,
bet_vault_pda,
true // allowOwnerOffCurve = true because it's a PDA
);
// Create the token account if it doesn't exist
try {
await getAccount(connection, betVaultTokenAccount);
} catch {
const createAtaIx = createAssociatedTokenAccountInstruction(
keypair.publicKey, // payer
betVaultTokenAccount, // ata
bet_vault_pda, // owner
tokenMint // mint
);
const tx = await connection.sendTransaction(
new Transaction().add(createAtaIx),
[keypair]
);
await connection.confirmTransaction(tx);
}
}
// Get payer's token account
const payerTokenAccount = await getAssociatedTokenAddress(
tokenMint,
keypair.publicKey
);
// Create the bet
const tx = await program.methods.createBet(
new BN(100000000),
"tester",
"tetris",
new BN(nonce),
isNativeSol,
tokenMint,
9 // decimals for SOL
new BN(nonce)
).accounts({
betsList: bet_list_pda,
payer: keypair.publicKey,
payerTokenAccount: isNativeSol ? null : payerTokenAccount,
betVaultTokenAccount: isNativeSol ? null : betVaultTokenAccount,
}).rpc();
console.log(`create tx : ${tx}`);

View File

@ -25,10 +25,7 @@ async function get(){
owner: betAcc.owner + " : " + betAcc.ownerId,
joiner: betAcc.joiner + " : " + betAcc.joinerId,
wager: betAcc.wager.toNumber() + `: ${betAcc.wager.toNumber() / LAMPORTS_PER_SOL}SOL`,
balance: solBalance,
is_native_sol: betAcc.isNativeSol,
token_mint: betAcc.tokenMint,
token_decimals: betAcc.tokenDecimals,
balance: solBalance + " SOL",
});
})
}

View File

@ -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);
}