Compare commits
No commits in common. "0f9ea8018aaa0ce471c4125b0ff2ab21a3da3578" and "6779da9882a398090e6c63f2c71e14d335a94dc5" have entirely different histories.
0f9ea8018a
...
6779da9882
118
src/bets.json
118
src/bets.json
|
|
@ -54,6 +54,30 @@
|
||||||
{
|
{
|
||||||
"name": "system_program",
|
"name": "system_program",
|
||||||
"address": "11111111111111111111111111111111"
|
"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": [
|
"args": [
|
||||||
|
|
@ -126,6 +150,20 @@
|
||||||
{
|
{
|
||||||
"name": "system_program",
|
"name": "system_program",
|
||||||
"address": "11111111111111111111111111111111"
|
"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": [
|
"args": [
|
||||||
|
|
@ -144,6 +182,20 @@
|
||||||
{
|
{
|
||||||
"name": "nonce",
|
"name": "nonce",
|
||||||
"type": "u64"
|
"type": "u64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_native_sol",
|
||||||
|
"type": "bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "token_mint",
|
||||||
|
"type": {
|
||||||
|
"option": "pubkey"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "token_decimals",
|
||||||
|
"type": "u8"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -219,6 +271,20 @@
|
||||||
{
|
{
|
||||||
"name": "system_program",
|
"name": "system_program",
|
||||||
"address": "11111111111111111111111111111111"
|
"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": [
|
"args": [
|
||||||
|
|
@ -265,6 +331,20 @@
|
||||||
{
|
{
|
||||||
"name": "system_program",
|
"name": "system_program",
|
||||||
"address": "11111111111111111111111111111111"
|
"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": [
|
"args": [
|
||||||
|
|
@ -306,8 +386,28 @@
|
||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"code": 6000,
|
"code": 6000,
|
||||||
"name": "CustomError",
|
"name": "BetNotFilled",
|
||||||
"msg": "Custom error message"
|
"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": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
|
|
@ -339,6 +439,20 @@
|
||||||
{
|
{
|
||||||
"name": "wager",
|
"name": "wager",
|
||||||
"type": "u64"
|
"type": "u64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_native_sol",
|
||||||
|
"type": "bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "token_mint",
|
||||||
|
"type": {
|
||||||
|
"option": "pubkey"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "token_decimals",
|
||||||
|
"type": "u8"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
118
src/bets.ts
118
src/bets.ts
|
|
@ -60,6 +60,30 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "systemProgram",
|
"name": "systemProgram",
|
||||||
"address": "11111111111111111111111111111111"
|
"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": [
|
"args": [
|
||||||
|
|
@ -132,6 +156,20 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "systemProgram",
|
"name": "systemProgram",
|
||||||
"address": "11111111111111111111111111111111"
|
"address": "11111111111111111111111111111111"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "payerTokenAccount",
|
||||||
|
"writable": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "betVaultTokenAccount",
|
||||||
|
"writable": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tokenProgram",
|
||||||
|
"address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"args": [
|
"args": [
|
||||||
|
|
@ -150,6 +188,20 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "nonce",
|
"name": "nonce",
|
||||||
"type": "u64"
|
"type": "u64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "isNativeSol",
|
||||||
|
"type": "bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tokenMint",
|
||||||
|
"type": {
|
||||||
|
"option": "pubkey"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tokenDecimals",
|
||||||
|
"type": "u8"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -225,6 +277,20 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "systemProgram",
|
"name": "systemProgram",
|
||||||
"address": "11111111111111111111111111111111"
|
"address": "11111111111111111111111111111111"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "payerTokenAccount",
|
||||||
|
"writable": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "betVaultTokenAccount",
|
||||||
|
"writable": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tokenProgram",
|
||||||
|
"address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"args": [
|
"args": [
|
||||||
|
|
@ -271,6 +337,20 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "systemProgram",
|
"name": "systemProgram",
|
||||||
"address": "11111111111111111111111111111111"
|
"address": "11111111111111111111111111111111"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "betVaultTokenAccount",
|
||||||
|
"writable": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "joinerTokenAccount",
|
||||||
|
"writable": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tokenProgram",
|
||||||
|
"address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"args": [
|
"args": [
|
||||||
|
|
@ -312,8 +392,28 @@ export type Bets = {
|
||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"code": 6000,
|
"code": 6000,
|
||||||
"name": "customError",
|
"name": "betNotFilled",
|
||||||
"msg": "Custom error message"
|
"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": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
|
|
@ -345,6 +445,20 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "wager",
|
"name": "wager",
|
||||||
"type": "u64"
|
"type": "u64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "isNativeSol",
|
||||||
|
"type": "bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tokenMint",
|
||||||
|
"type": {
|
||||||
|
"option": "pubkey"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "tokenDecimals",
|
||||||
|
"type": "u8"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
src/close.ts
17
src/close.ts
|
|
@ -1,8 +1,7 @@
|
||||||
import { Connection, PublicKey, Keypair, clusterApiUrl, LAMPORTS_PER_SOL, SystemProgram } from "@solana/web3.js";
|
import { Connection, PublicKey, Keypair, clusterApiUrl, LAMPORTS_PER_SOL, SystemProgram } from "@solana/web3.js";
|
||||||
import { Bets } from "./bets";
|
import { Bets } from "./bets";
|
||||||
import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor";
|
import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor";
|
||||||
import { clusterUrl, cocSk, feeWallet, getRandomInt, testerSk } from "./shared";
|
import { clusterUrl, cocSk, getRandomInt, testerSk } from "./shared";
|
||||||
import { getAssociatedTokenAddress } from "@solana/spl-token";
|
|
||||||
const IDL = require('./bets.json');
|
const IDL = require('./bets.json');
|
||||||
|
|
||||||
async function close(){
|
async function close(){
|
||||||
|
|
@ -27,17 +26,9 @@ async function close(){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const bet_list = await program.account.betsList.fetch(bet_list_pda);
|
const bet_list = await program.account.betsList.fetch(bet_list_pda);
|
||||||
|
|
||||||
|
|
||||||
for (const bet of bet_list.bets) {
|
for (const bet of bet_list.bets) {
|
||||||
try {
|
try {
|
||||||
const betAcc = await program.account.betVault.fetch(bet);
|
const betAcc = await program.account.betVault.fetch(bet);
|
||||||
|
|
||||||
const ownerRefferer = new PublicKey("BaTgUMPsk8fZoEMwig81Pw1KHmPpoYt31oiR5Qr2c8XR");
|
|
||||||
const joinerRefferer = feeWallet;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const winner = betAcc.owner;
|
const winner = betAcc.owner;
|
||||||
console.log(`Closing ${bet}`);
|
console.log(`Closing ${bet}`);
|
||||||
|
|
||||||
|
|
@ -45,9 +36,9 @@ async function close(){
|
||||||
betVault: bet,
|
betVault: bet,
|
||||||
betsList: bet_list_pda,
|
betsList: bet_list_pda,
|
||||||
winner: winner,
|
winner: winner,
|
||||||
feeWallet: feeWallet,
|
feeWallet: new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"),
|
||||||
ownerReferrer: ownerRefferer,
|
ownerReferrer: new PublicKey("BaTgUMPsk8fZoEMwig81Pw1KHmPpoYt31oiR5Qr2c8XR"),
|
||||||
joinerReferrer: joinerRefferer,
|
joinerReferrer: new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"),
|
||||||
}).rpc({
|
}).rpc({
|
||||||
skipPreflight: false,
|
skipPreflight: false,
|
||||||
maxRetries: 3
|
maxRetries: 3
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { Connection, PublicKey, Keypair, clusterApiUrl, LAMPORTS_PER_SOL, System
|
||||||
import { Bets } from "./bets";
|
import { Bets } from "./bets";
|
||||||
import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor";
|
import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor";
|
||||||
import { clusterUrl, cocSk, getRandomInt, testerSk } from "./shared";
|
import { clusterUrl, cocSk, getRandomInt, testerSk } from "./shared";
|
||||||
// import { createAssociatedTokenAccountInstruction, getAccount, getAssociatedTokenAddress } from "@solana/spl-token";
|
import { createAssociatedTokenAccountInstruction, getAccount, getAssociatedTokenAddress, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||||
const IDL = require('./bets.json');
|
const IDL = require('./bets.json');
|
||||||
|
|
||||||
async function create() {
|
async function create() {
|
||||||
|
|
@ -45,17 +45,59 @@ async function create() {
|
||||||
program.programId
|
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
|
// Create the bet
|
||||||
const tx = await program.methods.createBet(
|
const tx = await program.methods.createBet(
|
||||||
new BN(100000000),
|
new BN(100000000),
|
||||||
"tester",
|
"tester",
|
||||||
"tetris",
|
"tetris",
|
||||||
new BN(nonce)
|
new BN(nonce),
|
||||||
|
isNativeSol,
|
||||||
|
tokenMint,
|
||||||
|
9 // decimals for SOL
|
||||||
).accounts({
|
).accounts({
|
||||||
betsList: bet_list_pda,
|
betsList: bet_list_pda,
|
||||||
payer: keypair.publicKey,
|
payer: keypair.publicKey,
|
||||||
|
payerTokenAccount: isNativeSol ? null : payerTokenAccount,
|
||||||
|
betVaultTokenAccount: isNativeSol ? null : betVaultTokenAccount,
|
||||||
}).rpc();
|
}).rpc();
|
||||||
|
|
||||||
console.log(`create tx : ${tx}`);
|
console.log(`create tx : ${tx}`);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ async function get(){
|
||||||
owner: betAcc.owner + " : " + betAcc.ownerId,
|
owner: betAcc.owner + " : " + betAcc.ownerId,
|
||||||
joiner: betAcc.joiner + " : " + betAcc.joinerId,
|
joiner: betAcc.joiner + " : " + betAcc.joinerId,
|
||||||
wager: betAcc.wager.toNumber() + `: ${betAcc.wager.toNumber() / LAMPORTS_PER_SOL}SOL`,
|
wager: betAcc.wager.toNumber() + `: ${betAcc.wager.toNumber() / LAMPORTS_PER_SOL}SOL`,
|
||||||
balance: solBalance + " SOL",
|
balance: solBalance,
|
||||||
|
is_native_sol: betAcc.isNativeSol,
|
||||||
|
token_mint: betAcc.tokenMint,
|
||||||
|
token_decimals: betAcc.tokenDecimals,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ 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 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 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) {
|
export function getRandomInt(max) {
|
||||||
return Math.floor(Math.random() * max);
|
return Math.floor(Math.random() * max);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user