token sup
This commit is contained in:
parent
6779da9882
commit
f1ef2c4b8c
118
src/bets.json
118
src/bets.json
|
|
@ -54,30 +54,6 @@
|
||||||
{
|
{
|
||||||
"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": [
|
||||||
|
|
@ -150,20 +126,6 @@
|
||||||
{
|
{
|
||||||
"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": [
|
||||||
|
|
@ -182,20 +144,6 @@
|
||||||
{
|
{
|
||||||
"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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -271,20 +219,6 @@
|
||||||
{
|
{
|
||||||
"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": [
|
||||||
|
|
@ -331,20 +265,6 @@
|
||||||
{
|
{
|
||||||
"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": [
|
||||||
|
|
@ -386,28 +306,8 @@
|
||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"code": 6000,
|
"code": 6000,
|
||||||
"name": "BetNotFilled",
|
"name": "CustomError",
|
||||||
"msg": "Bet is not filled yet!"
|
"msg": "Custom error message"
|
||||||
},
|
|
||||||
{
|
|
||||||
"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": [
|
||||||
|
|
@ -439,20 +339,6 @@
|
||||||
{
|
{
|
||||||
"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,30 +60,6 @@ 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": [
|
||||||
|
|
@ -156,20 +132,6 @@ 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": [
|
||||||
|
|
@ -188,20 +150,6 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "nonce",
|
"name": "nonce",
|
||||||
"type": "u64"
|
"type": "u64"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "isNativeSol",
|
|
||||||
"type": "bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tokenMint",
|
|
||||||
"type": {
|
|
||||||
"option": "pubkey"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tokenDecimals",
|
|
||||||
"type": "u8"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -277,20 +225,6 @@ 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": [
|
||||||
|
|
@ -337,20 +271,6 @@ 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": [
|
||||||
|
|
@ -392,28 +312,8 @@ export type Bets = {
|
||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"code": 6000,
|
"code": 6000,
|
||||||
"name": "betNotFilled",
|
"name": "customError",
|
||||||
"msg": "Bet is not filled yet!"
|
"msg": "Custom error message"
|
||||||
},
|
|
||||||
{
|
|
||||||
"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": [
|
||||||
|
|
@ -445,20 +345,6 @@ export type Bets = {
|
||||||
{
|
{
|
||||||
"name": "wager",
|
"name": "wager",
|
||||||
"type": "u64"
|
"type": "u64"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "isNativeSol",
|
|
||||||
"type": "bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tokenMint",
|
|
||||||
"type": {
|
|
||||||
"option": "pubkey"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tokenDecimals",
|
|
||||||
"type": "u8"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
52
src/close.ts
52
src/close.ts
|
|
@ -1,7 +1,8 @@
|
||||||
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, getRandomInt, testerSk } from "./shared";
|
import { clusterUrl, cocSk, feeWallet, 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(){
|
||||||
|
|
@ -26,9 +27,48 @@ 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 [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;
|
const winner = betAcc.owner;
|
||||||
console.log(`Closing ${bet}`);
|
console.log(`Closing ${bet}`);
|
||||||
|
|
||||||
|
|
@ -36,9 +76,13 @@ async function close(){
|
||||||
betVault: bet,
|
betVault: bet,
|
||||||
betsList: bet_list_pda,
|
betsList: bet_list_pda,
|
||||||
winner: winner,
|
winner: winner,
|
||||||
feeWallet: new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"),
|
feeWallet: feeWallet,
|
||||||
ownerReferrer: new PublicKey("BaTgUMPsk8fZoEMwig81Pw1KHmPpoYt31oiR5Qr2c8XR"),
|
ownerReferrer: ownerRefferer,
|
||||||
joinerReferrer: new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"),
|
joinerReferrer: joinerRefferer,
|
||||||
|
betVaultTokenAccount: betAcc.isNativeSol ? null : betVaultTokenAccount,
|
||||||
|
feeWalletTokenAccount: betAcc.isNativeSol ? null : feeWalletTokenAccount,
|
||||||
|
ownerReferrerTokenAccount: betAcc.isNativeSol ? null : ownerReferrerTokenAccount,
|
||||||
|
joinerReferrerTokenAccount: betAcc.isNativeSol ? null : joinerReferrerTokenAccount,
|
||||||
}).rpc({
|
}).rpc({
|
||||||
skipPreflight: false,
|
skipPreflight: false,
|
||||||
maxRetries: 3
|
maxRetries: 3
|
||||||
|
|
|
||||||
|
|
@ -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 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