referrals
This commit is contained in:
parent
0f9ea8018a
commit
c0b46f2ecf
|
|
@ -8,6 +8,7 @@
|
|||
"join": "ts-node src/join.ts",
|
||||
"get": "ts-node src/get.ts",
|
||||
"close": "ts-node src/close.ts",
|
||||
"clear": "ts-node src/clear.ts",
|
||||
"build": "tsc"
|
||||
},
|
||||
"keywords": [],
|
||||
|
|
|
|||
|
|
@ -7,6 +7,31 @@
|
|||
"description": "Created with Anchor"
|
||||
},
|
||||
"instructions": [
|
||||
{
|
||||
"name": "clear_bets_list",
|
||||
"discriminator": [
|
||||
128,
|
||||
73,
|
||||
20,
|
||||
28,
|
||||
69,
|
||||
26,
|
||||
247,
|
||||
185
|
||||
],
|
||||
"accounts": [
|
||||
{
|
||||
"name": "bets_list",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "payer",
|
||||
"writable": true,
|
||||
"signer": true
|
||||
}
|
||||
],
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"name": "close_bet",
|
||||
"discriminator": [
|
||||
|
|
@ -28,10 +53,6 @@
|
|||
"name": "bet_vault",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "fee_wallet",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "winner",
|
||||
"writable": true
|
||||
|
|
@ -41,16 +62,6 @@
|
|||
"writable": true,
|
||||
"signer": true
|
||||
},
|
||||
{
|
||||
"name": "owner_referrer",
|
||||
"writable": true,
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "joiner_referrer",
|
||||
"writable": true,
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "system_program",
|
||||
"address": "11111111111111111111111111111111"
|
||||
|
|
@ -147,6 +158,60 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "deduct_fees",
|
||||
"discriminator": [
|
||||
249,
|
||||
7,
|
||||
117,
|
||||
167,
|
||||
160,
|
||||
108,
|
||||
235,
|
||||
14
|
||||
],
|
||||
"accounts": [
|
||||
{
|
||||
"name": "bets_list",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "bet_vault",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "fee_wallet",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "payer",
|
||||
"writable": true,
|
||||
"signer": true
|
||||
},
|
||||
{
|
||||
"name": "owner_referrer",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "joiner_referrer",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "system_program",
|
||||
"address": "11111111111111111111111111111111"
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "winner",
|
||||
"type": "pubkey"
|
||||
},
|
||||
{
|
||||
"name": "userid",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "initialize",
|
||||
"discriminator": [
|
||||
|
|
|
|||
93
src/bets.ts
93
src/bets.ts
|
|
@ -13,6 +13,31 @@ export type Bets = {
|
|||
"description": "Created with Anchor"
|
||||
},
|
||||
"instructions": [
|
||||
{
|
||||
"name": "clearBetsList",
|
||||
"discriminator": [
|
||||
128,
|
||||
73,
|
||||
20,
|
||||
28,
|
||||
69,
|
||||
26,
|
||||
247,
|
||||
185
|
||||
],
|
||||
"accounts": [
|
||||
{
|
||||
"name": "betsList",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "payer",
|
||||
"writable": true,
|
||||
"signer": true
|
||||
}
|
||||
],
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"name": "closeBet",
|
||||
"discriminator": [
|
||||
|
|
@ -34,10 +59,6 @@ export type Bets = {
|
|||
"name": "betVault",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "feeWallet",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "winner",
|
||||
"writable": true
|
||||
|
|
@ -47,16 +68,6 @@ export type Bets = {
|
|||
"writable": true,
|
||||
"signer": true
|
||||
},
|
||||
{
|
||||
"name": "ownerReferrer",
|
||||
"writable": true,
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "joinerReferrer",
|
||||
"writable": true,
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "systemProgram",
|
||||
"address": "11111111111111111111111111111111"
|
||||
|
|
@ -153,6 +164,60 @@ export type Bets = {
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "deductFees",
|
||||
"discriminator": [
|
||||
249,
|
||||
7,
|
||||
117,
|
||||
167,
|
||||
160,
|
||||
108,
|
||||
235,
|
||||
14
|
||||
],
|
||||
"accounts": [
|
||||
{
|
||||
"name": "betsList",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "betVault",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "feeWallet",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "payer",
|
||||
"writable": true,
|
||||
"signer": true
|
||||
},
|
||||
{
|
||||
"name": "ownerReferrer",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "joinerReferrer",
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"name": "systemProgram",
|
||||
"address": "11111111111111111111111111111111"
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "winner",
|
||||
"type": "pubkey"
|
||||
},
|
||||
{
|
||||
"name": "userid",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "initialize",
|
||||
"discriminator": [
|
||||
|
|
|
|||
44
src/clear.ts
Normal file
44
src/clear.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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, feeWallet, getRandomInt, testerSk } from "./shared";
|
||||
import { getAssociatedTokenAddress } from "@solana/spl-token";
|
||||
const IDL = require('./bets.json');
|
||||
|
||||
async function close(){
|
||||
const keypair = Keypair.fromSecretKey(Uint8Array.from(cocSk));
|
||||
|
||||
const connection = new Connection(clusterUrl, {
|
||||
commitment: 'confirmed',
|
||||
confirmTransactionInitialTimeout: 60000
|
||||
});
|
||||
const provider = new AnchorProvider(connection, new Wallet(keypair), {
|
||||
commitment: 'confirmed',
|
||||
preflightCommitment: 'confirmed',
|
||||
});
|
||||
const program:Program<Bets> = new Program<Bets>(IDL, provider);
|
||||
|
||||
let solBalance = (await connection.getBalance(keypair.publicKey))/ LAMPORTS_PER_SOL;
|
||||
console.log(`Tester ${keypair.publicKey} has ${solBalance} SOL`);
|
||||
|
||||
const [bet_list_pda] = await PublicKey.findProgramAddress([Buffer.from("bets_list")], program.programId);
|
||||
console.log(`Bets list PDA : ${bet_list_pda}`);
|
||||
|
||||
const tx = await program.methods.clearBetsList().accounts({
|
||||
betsList: bet_list_pda
|
||||
}).rpc();
|
||||
console.log(`clear tx: ${tx}`);
|
||||
|
||||
const confirmation = await connection.confirmTransaction(tx);
|
||||
|
||||
if (confirmation.value.err) {
|
||||
console.error(`Transaction failed: ${confirmation.value.err}`);
|
||||
}
|
||||
|
||||
console.log(`tx complete: ${tx}`);
|
||||
}
|
||||
|
||||
close().catch(err => {
|
||||
console.error('Fatal error:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
18
src/close.ts
18
src/close.ts
|
|
@ -41,10 +41,9 @@ async function close(){
|
|||
const winner = betAcc.owner;
|
||||
console.log(`Closing ${bet}`);
|
||||
|
||||
const tx = await program.methods.closeBet(winner, betAcc.ownerId).accounts({
|
||||
const tx = await program.methods.deductFees(winner, betAcc.ownerId).accounts({
|
||||
betVault: bet,
|
||||
betsList: bet_list_pda,
|
||||
winner: winner,
|
||||
feeWallet: feeWallet,
|
||||
ownerReferrer: ownerRefferer,
|
||||
joinerReferrer: joinerRefferer,
|
||||
|
|
@ -52,9 +51,20 @@ async function close(){
|
|||
skipPreflight: false,
|
||||
maxRetries: 3
|
||||
});
|
||||
console.log(`tx: ${tx}`);
|
||||
await connection.confirmTransaction(tx);
|
||||
console.log(`fee tx: ${tx}`);
|
||||
|
||||
const tx2 = await program.methods.closeBet(winner, betAcc.ownerId).accounts({
|
||||
betVault: bet,
|
||||
betsList: bet_list_pda,
|
||||
winner: winner,
|
||||
}).rpc({
|
||||
skipPreflight: false,
|
||||
maxRetries: 3
|
||||
});
|
||||
console.log(`close tx: ${tx2}`);
|
||||
|
||||
const confirmation = await connection.confirmTransaction(tx);
|
||||
const confirmation = await connection.confirmTransaction(tx2);
|
||||
|
||||
if (confirmation.value.err) {
|
||||
console.error(`Transaction failed: ${confirmation.value.err}`);
|
||||
|
|
|
|||
|
|
@ -25,7 +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 + " SOL",
|
||||
balance: solBalance + " SOL"
|
||||
});
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { clusterApiUrl, PublicKey } from "@solana/web3.js";
|
||||
export const clusterUrl = clusterApiUrl("devnet");
|
||||
export const clusterUrl = clusterApiUrl("mainnet-beta");
|
||||
|
||||
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];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user