This commit is contained in:
Sewmina 2025-06-27 09:35:29 +00:00
parent 9831d6c0ec
commit 523f48506d
4 changed files with 1940 additions and 26 deletions

View File

@ -22,7 +22,25 @@
"accounts": [
{
"name": "bets_list",
"writable": true
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
115,
95,
108,
105,
115,
116
]
}
]
}
},
{
"name": "payer",
@ -78,6 +96,218 @@
}
]
},
{
"name": "close_bet_token",
"discriminator": [
253,
179,
157,
65,
93,
13,
142,
130
],
"accounts": [
{
"name": "bets_list",
"writable": true
},
{
"name": "bet_vault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
95,
118,
97,
117,
108,
116
]
},
{
"kind": "arg",
"path": "owner"
},
{
"kind": "arg",
"path": "game_id"
},
{
"kind": "arg",
"path": "nonce"
}
]
}
},
{
"name": "winner",
"writable": true
},
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "token_mint"
},
{
"name": "token_vault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "bet_vault"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "winner_token_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "arg",
"path": "winner"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
},
{
"name": "token_program"
},
{
"name": "associated_token_program",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "winner",
"type": "pubkey"
},
{
"name": "userid",
"type": "string"
},
{
"name": "owner",
"type": "pubkey"
},
{
"name": "game_id",
"type": "string"
},
{
"name": "nonce",
"type": "u64"
}
]
},
{
"name": "create_bet",
"discriminator": [
@ -158,6 +388,210 @@
}
]
},
{
"name": "create_bet_token",
"discriminator": [
112,
150,
197,
85,
168,
49,
140,
199
],
"accounts": [
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "token_mint"
},
{
"name": "bets_list",
"writable": true
},
{
"name": "bet_vault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
95,
118,
97,
117,
108,
116
]
},
{
"kind": "account",
"path": "payer"
},
{
"kind": "arg",
"path": "game_id"
},
{
"kind": "arg",
"path": "_nonce"
}
]
}
},
{
"name": "payer_token_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "payer"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "token_vault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "bet_vault"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
},
{
"name": "token_program"
},
{
"name": "associated_token_program",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "wager",
"type": "u64"
},
{
"name": "user_id",
"type": "string"
},
{
"name": "game_id",
"type": "string"
},
{
"name": "nonce",
"type": "u64"
}
]
},
{
"name": "deduct_fees",
"discriminator": [
@ -212,6 +646,340 @@
}
]
},
{
"name": "deduct_fees_token",
"discriminator": [
92,
93,
60,
121,
30,
164,
148,
135
],
"accounts": [
{
"name": "bets_list",
"writable": true
},
{
"name": "bet_vault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
95,
118,
97,
117,
108,
116
]
},
{
"kind": "arg",
"path": "owner"
},
{
"kind": "arg",
"path": "game_id"
},
{
"kind": "arg",
"path": "nonce"
}
]
}
},
{
"name": "fee_wallet",
"writable": true
},
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "owner_referrer",
"writable": true
},
{
"name": "joiner_referrer",
"writable": true
},
{
"name": "token_mint"
},
{
"name": "token_vault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "bet_vault"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "fee_wallet_token_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "fee_wallet"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "owner_referrer_token_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "owner_referrer"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "joiner_referrer_token_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "joiner_referrer"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
},
{
"name": "token_program"
},
{
"name": "associated_token_program",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "winner",
"type": "pubkey"
},
{
"name": "userid",
"type": "string"
},
{
"name": "owner",
"type": "pubkey"
},
{
"name": "game_id",
"type": "string"
},
{
"name": "nonce",
"type": "u64"
}
]
},
{
"name": "initialize",
"discriminator": [
@ -297,6 +1065,168 @@
}
]
},
{
"name": "join_bet_token",
"discriminator": [
166,
253,
62,
118,
163,
87,
166,
204
],
"accounts": [
{
"name": "bet_vault",
"writable": true
},
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "token_mint"
},
{
"name": "payer_token_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "payer"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "token_vault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "bet_vault"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "token_mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
},
{
"name": "token_program"
},
{
"name": "associated_token_program",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "user_id",
"type": "string"
},
{
"name": "game_id",
"type": "string"
}
]
},
{
"name": "refund_bet",
"discriminator": [
@ -381,6 +1311,10 @@
"type": {
"kind": "struct",
"fields": [
{
"name": "nonce",
"type": "u64"
},
{
"name": "game_id",
"type": "string"
@ -401,6 +1335,10 @@
"name": "joiner_id",
"type": "string"
},
{
"name": "token_mint",
"type": "pubkey"
},
{
"name": "wager",
"type": "u64"

View File

@ -28,7 +28,25 @@ export type Bets = {
"accounts": [
{
"name": "betsList",
"writable": true
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
115,
95,
108,
105,
115,
116
]
}
]
}
},
{
"name": "payer",
@ -84,6 +102,218 @@ export type Bets = {
}
]
},
{
"name": "closeBetToken",
"discriminator": [
253,
179,
157,
65,
93,
13,
142,
130
],
"accounts": [
{
"name": "betsList",
"writable": true
},
{
"name": "betVault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
95,
118,
97,
117,
108,
116
]
},
{
"kind": "arg",
"path": "owner"
},
{
"kind": "arg",
"path": "gameId"
},
{
"kind": "arg",
"path": "nonce"
}
]
}
},
{
"name": "winner",
"writable": true
},
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "tokenMint"
},
{
"name": "tokenVault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "betVault"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "winnerTokenAccount",
"writable": true,
"pda": {
"seeds": [
{
"kind": "arg",
"path": "winner"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "systemProgram",
"address": "11111111111111111111111111111111"
},
{
"name": "tokenProgram"
},
{
"name": "associatedTokenProgram",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "winner",
"type": "pubkey"
},
{
"name": "userid",
"type": "string"
},
{
"name": "owner",
"type": "pubkey"
},
{
"name": "gameId",
"type": "string"
},
{
"name": "nonce",
"type": "u64"
}
]
},
{
"name": "createBet",
"discriminator": [
@ -164,6 +394,210 @@ export type Bets = {
}
]
},
{
"name": "createBetToken",
"discriminator": [
112,
150,
197,
85,
168,
49,
140,
199
],
"accounts": [
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "tokenMint"
},
{
"name": "betsList",
"writable": true
},
{
"name": "betVault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
95,
118,
97,
117,
108,
116
]
},
{
"kind": "account",
"path": "payer"
},
{
"kind": "arg",
"path": "gameId"
},
{
"kind": "arg",
"path": "nonce"
}
]
}
},
{
"name": "payerTokenAccount",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "payer"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "tokenVault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "betVault"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "systemProgram",
"address": "11111111111111111111111111111111"
},
{
"name": "tokenProgram"
},
{
"name": "associatedTokenProgram",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "wager",
"type": "u64"
},
{
"name": "userId",
"type": "string"
},
{
"name": "gameId",
"type": "string"
},
{
"name": "nonce",
"type": "u64"
}
]
},
{
"name": "deductFees",
"discriminator": [
@ -218,6 +652,340 @@ export type Bets = {
}
]
},
{
"name": "deductFeesToken",
"discriminator": [
92,
93,
60,
121,
30,
164,
148,
135
],
"accounts": [
{
"name": "betsList",
"writable": true
},
{
"name": "betVault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
98,
101,
116,
95,
118,
97,
117,
108,
116
]
},
{
"kind": "arg",
"path": "owner"
},
{
"kind": "arg",
"path": "gameId"
},
{
"kind": "arg",
"path": "nonce"
}
]
}
},
{
"name": "feeWallet",
"writable": true
},
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "ownerReferrer",
"writable": true
},
{
"name": "joinerReferrer",
"writable": true
},
{
"name": "tokenMint"
},
{
"name": "tokenVault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "betVault"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "feeWalletTokenAccount",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "feeWallet"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "ownerReferrerTokenAccount",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "ownerReferrer"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "joinerReferrerTokenAccount",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "joinerReferrer"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "systemProgram",
"address": "11111111111111111111111111111111"
},
{
"name": "tokenProgram"
},
{
"name": "associatedTokenProgram",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "winner",
"type": "pubkey"
},
{
"name": "userid",
"type": "string"
},
{
"name": "owner",
"type": "pubkey"
},
{
"name": "gameId",
"type": "string"
},
{
"name": "nonce",
"type": "u64"
}
]
},
{
"name": "initialize",
"discriminator": [
@ -303,6 +1071,168 @@ export type Bets = {
}
]
},
{
"name": "joinBetToken",
"discriminator": [
166,
253,
62,
118,
163,
87,
166,
204
],
"accounts": [
{
"name": "betVault",
"writable": true
},
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "tokenMint"
},
{
"name": "payerTokenAccount",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "payer"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "tokenVault",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "betVault"
},
{
"kind": "account",
"path": "tokenProgram"
},
{
"kind": "account",
"path": "tokenMint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "systemProgram",
"address": "11111111111111111111111111111111"
},
{
"name": "tokenProgram"
},
{
"name": "associatedTokenProgram",
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
}
],
"args": [
{
"name": "userId",
"type": "string"
},
{
"name": "gameId",
"type": "string"
}
]
},
{
"name": "refundBet",
"discriminator": [
@ -387,6 +1317,10 @@ export type Bets = {
"type": {
"kind": "struct",
"fields": [
{
"name": "nonce",
"type": "u64"
},
{
"name": "gameId",
"type": "string"
@ -407,6 +1341,10 @@ export type Bets = {
"name": "joinerId",
"type": "string"
},
{
"name": "tokenMint",
"type": "pubkey"
},
{
"name": "wager",
"type": "u64"

View File

@ -14,6 +14,8 @@ export const duelfiApiUrl = "https://api.duelfi.io/v1/";
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 TOKEN_PROGRAM_ID = new PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
export function getRandomInt(max) {
return Math.floor(Math.random() * max);
}

View File

@ -1,7 +1,7 @@
import { AnchorProvider, Wallet, Program } from "@coral-xyz/anchor";
import { Keypair, Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
import { Bets } from "./bets";
import { testerSk, cocSk, clusterUrl, duelfiApiUrl, feeWallet, GetReferreeWallet, add_new_activity } from "./shared";
import { testerSk, cocSk, clusterUrl, duelfiApiUrl, feeWallet, GetReferreeWallet, add_new_activity, TOKEN_PROGRAM_ID } from "./shared";
import { log } from "./logging_help";
const IDL = require("./bets.json");
@ -41,7 +41,9 @@ export async function fetchBets(){
owner_id: bet.ownerId,
joiner: bet.joiner ? bet.joiner.toBase58() : "Open",
joiner_id: bet.joinerId,
wager: bet.wager.toNumber() / LAMPORTS_PER_SOL
wager: bet.wager.toNumber() / LAMPORTS_PER_SOL,
token_mint: bet.tokenMint.toBase58(),
nonce: bet.nonce.toNumber()
});
} catch (err) {
log(`Error fetching bet ${betPubkey}: ${err}`, "solana");
@ -56,11 +58,21 @@ export async function fetchBets(){
export async function refundBet(bet:string):Promise<string>{
const betAcc = await program.account.betVault.fetch(bet);
const tx =await program.methods.closeBet(new PublicKey(betAcc.owner), betAcc.ownerId).accounts({
betVault: bet,
betsList: bet_list_pda,
winner: betAcc.owner
}).rpc();
let tx;
if(betAcc.tokenMint.toBase58() === "So11111111111111111111111111111111111111112"){
tx =await program.methods.closeBet(new PublicKey(betAcc.owner), betAcc.ownerId).accounts({
betVault: bet,
betsList: bet_list_pda,
winner: betAcc.owner
}).rpc();
}else{
tx = await program.methods.closeBetToken(new PublicKey(betAcc.owner), betAcc.ownerId, betAcc.owner, betAcc.gameId, betAcc.nonce).accounts({
betsList: bet_list_pda,
winner: betAcc.owner,
tokenMint: betAcc.tokenMint,
tokenProgram: TOKEN_PROGRAM_ID
}).rpc();
}
log(`refund tx: ${tx}`, "solana");
return tx;
@ -75,26 +87,50 @@ export async function close(bet:string, winner:string, uid:string, loser:string)
const loser_referree_wallet = await GetReferreeWallet(loser);
const bet_acc = await program.account.betVault.fetch(bet);
let tx,close_tx;
if(bet_acc.tokenMint.toBase58() === "So11111111111111111111111111111111111111112"){
log(`bet is in SOL`, "solana");
tx = await program.methods.deductFees(new PublicKey(winner), uid).accounts({
betVault: bet,
betsList: bet_list_pda,
feeWallet: feeWallet,
ownerReferrer: winner_referree_wallet,
joinerReferrer: loser_referree_wallet
}).rpc();
await connection.confirmTransaction(tx, 'confirmed');
close_tx = await program.methods.closeBet(new PublicKey(winner), uid).accounts({
betVault: bet,
betsList: bet_list_pda,
winner: winner
}).rpc();
await connection.confirmTransaction(close_tx, 'confirmed');
}else{
log(`bet is in token ${bet_acc.tokenMint.toBase58()}`, "solana");
const tx = await program.methods.deductFeesToken(new PublicKey(winner), uid, bet_acc.owner, bet_acc.gameId, bet_acc.nonce).accounts({
betsList: bet_list_pda,
feeWallet: feeWallet,
ownerReferrer: winner_referree_wallet,
joinerReferrer: loser_referree_wallet,
tokenMint: bet_acc.tokenMint,
tokenProgram: TOKEN_PROGRAM_ID,
}).rpc();
await connection.confirmTransaction(tx, 'confirmed');
const close_tx = await program.methods.closeBetToken(new PublicKey(winner), uid, bet_acc.owner, bet_acc.gameId, bet_acc.nonce).accounts({
betsList: bet_list_pda,
winner: winner,
tokenMint: bet_acc.tokenMint,
tokenProgram: TOKEN_PROGRAM_ID
}).rpc();
await connection.confirmTransaction(close_tx, 'confirmed');
}
const tx = await program.methods.deductFees(new PublicKey(winner), uid).accounts({
betVault: bet,
betsList: bet_list_pda,
feeWallet: feeWallet,
ownerReferrer: winner_referree_wallet,
joinerReferrer: loser_referree_wallet
}).rpc();
await connection.confirmTransaction(tx, 'confirmed');
const close_tx = await program.methods.closeBet(new PublicKey(winner), uid).accounts({
betVault: bet,
betsList: bet_list_pda,
winner: winner
}).rpc();
await connection.confirmTransaction(close_tx, 'confirmed');
if(!process.env.USE_DEVNET){
add_new_activity("won", uid, loser, bet_acc.gameId, bet_acc.wager.toNumber() / LAMPORTS_PER_SOL);
}
log(`close tx: ${close_tx}`, "solana");
return tx;
}