@triadxyz/poseidons-protocol 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,11 +17,12 @@ export default class Game {
17
17
  * @param spins - The number of spins to add
18
18
  * @returns The transaction signature or versioned transaction
19
19
  */
20
- addSpin({ users, refer }: {
20
+ addSpin({ users, refer, isUsdc }: {
21
21
  users: {
22
22
  user: PublicKey;
23
23
  spins: number;
24
24
  }[];
25
25
  refer: PublicKey;
26
+ isUsdc: boolean;
26
27
  }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
27
28
  }
@@ -17,9 +17,6 @@ const chest_1 = __importDefault(require("./chest"));
17
17
  const wheel_1 = __importDefault(require("./wheel"));
18
18
  const sendVersionedTransaction_1 = __importDefault(require("../utils/sendVersionedTransaction"));
19
19
  const pda_1 = require("../utils/pda");
20
- const getTokenBalance_1 = require("../utils/getTokenBalance");
21
- const constants_1 = require("../utils/constants");
22
- const swap_1 = require("../utils/swap");
23
20
  class Game {
24
21
  constructor(program, rpcOptions) {
25
22
  this.program = program;
@@ -33,42 +30,12 @@ class Game {
33
30
  * @param spins - The number of spins to add
34
31
  * @returns The transaction signature or versioned transaction
35
32
  */
36
- addSpin({ users, refer }) {
33
+ addSpin({ users, refer, isUsdc }) {
37
34
  return __awaiter(this, void 0, void 0, function* () {
38
35
  const ixs = [];
39
36
  const addressLookupTableAccounts = [];
40
37
  for (const user of users) {
41
38
  const userPDA = (0, pda_1.getUserPDA)(user.user);
42
- const userSolBalance = yield (0, getTokenBalance_1.getBalanceSol)(user.user.toBase58(), this.program.provider.connection);
43
- const totalCost = user.spins * 0.0015;
44
- const feeBuffer = Math.max(totalCost * 0.1, 0.0001);
45
- const totalCostWithFees = totalCost + feeBuffer;
46
- if (userSolBalance !== undefined && userSolBalance < totalCostWithFees) {
47
- const solNeeded = totalCostWithFees - userSolBalance;
48
- const solPrice = yield (0, swap_1.getPrice)(constants_1.SOL_MINT.toString());
49
- const usdcNeeded = solNeeded * solPrice * 1.05;
50
- const userUsdcBalance = yield (0, getTokenBalance_1.getTokenBalance)(constants_1.USDC_MINT.toString(), user.user.toBase58(), this.program.provider.connection);
51
- if (userUsdcBalance < usdcNeeded) {
52
- throw new Error(`The user does not have enough USDC. Necessary: ${usdcNeeded.toFixed(2)} USDC, Available: ${userUsdcBalance.toFixed(2)} USDC`);
53
- }
54
- const { swapIxs, closeAccountIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
55
- connection: this.program.provider.connection,
56
- wallet: user.user.toBase58(),
57
- inToken: constants_1.USDC_MINT.toString(),
58
- outToken: constants_1.SOL_MINT.toString(),
59
- amount: usdcNeeded,
60
- payer: this.rpcOptions.payer.toBase58()
61
- });
62
- if (swapIxs.length === 0) {
63
- return;
64
- }
65
- ixs.push(...setupInstructions);
66
- ixs.push(...swapIxs);
67
- if (closeAccountIxs && closeAccountIxs.length > 0) {
68
- ixs.push(...closeAccountIxs);
69
- }
70
- addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
71
- }
72
39
  try {
73
40
  yield this.program.account.user.fetch(userPDA, this.rpcOptions.commitment);
74
41
  }
@@ -82,7 +49,10 @@ class Game {
82
49
  .instruction());
83
50
  }
84
51
  ixs.push(yield this.program.methods
85
- .addSpin(new anchor_1.BN(user.spins))
52
+ .addSpin({
53
+ isUsdc,
54
+ spins: new anchor_1.BN(user.spins)
55
+ })
86
56
  .accounts({
87
57
  signer: this.program.provider.publicKey,
88
58
  user: userPDA
@@ -290,6 +290,75 @@
290
290
  "name": "user",
291
291
  "writable": true
292
292
  },
293
+ {
294
+ "name": "mint",
295
+ "writable": true,
296
+ "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
297
+ },
298
+ {
299
+ "name": "user_ata",
300
+ "writable": true,
301
+ "pda": {
302
+ "seeds": [
303
+ {
304
+ "kind": "account",
305
+ "path": "signer"
306
+ },
307
+ {
308
+ "kind": "account",
309
+ "path": "token_program"
310
+ },
311
+ {
312
+ "kind": "account",
313
+ "path": "mint"
314
+ }
315
+ ],
316
+ "program": {
317
+ "kind": "const",
318
+ "value": [
319
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
320
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
321
+ 219, 233, 248, 89
322
+ ]
323
+ }
324
+ }
325
+ },
326
+ {
327
+ "name": "squads_ata",
328
+ "writable": true,
329
+ "pda": {
330
+ "seeds": [
331
+ {
332
+ "kind": "account",
333
+ "path": "squads"
334
+ },
335
+ {
336
+ "kind": "account",
337
+ "path": "token_program"
338
+ },
339
+ {
340
+ "kind": "account",
341
+ "path": "mint"
342
+ }
343
+ ],
344
+ "program": {
345
+ "kind": "const",
346
+ "value": [
347
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
348
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
349
+ 219, 233, 248, 89
350
+ ]
351
+ }
352
+ }
353
+ },
354
+ {
355
+ "name": "token_program",
356
+ "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
357
+ },
358
+ {
359
+ "name": "associated_token_program",
360
+ "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
361
+ },
293
362
  {
294
363
  "name": "system_program",
295
364
  "address": "11111111111111111111111111111111"
@@ -297,8 +366,12 @@
297
366
  ],
298
367
  "args": [
299
368
  {
300
- "name": "spins",
301
- "type": "u64"
369
+ "name": "args",
370
+ "type": {
371
+ "defined": {
372
+ "name": "AddSpinArgs"
373
+ }
374
+ }
302
375
  }
303
376
  ]
304
377
  },
@@ -1104,6 +1177,22 @@
1104
1177
  ]
1105
1178
  }
1106
1179
  },
1180
+ {
1181
+ "name": "AddSpinArgs",
1182
+ "type": {
1183
+ "kind": "struct",
1184
+ "fields": [
1185
+ {
1186
+ "name": "is_usdc",
1187
+ "type": "bool"
1188
+ },
1189
+ {
1190
+ "name": "spins",
1191
+ "type": "u64"
1192
+ }
1193
+ ]
1194
+ }
1195
+ },
1107
1196
  {
1108
1197
  "name": "AddWheelPrizeArgs",
1109
1198
  "type": {
@@ -395,6 +395,133 @@ export type PoseidonsProtocol = {
395
395
  name: 'user';
396
396
  writable: true;
397
397
  },
398
+ {
399
+ name: 'mint';
400
+ writable: true;
401
+ address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
402
+ },
403
+ {
404
+ name: 'userAta';
405
+ writable: true;
406
+ pda: {
407
+ seeds: [
408
+ {
409
+ kind: 'account';
410
+ path: 'signer';
411
+ },
412
+ {
413
+ kind: 'account';
414
+ path: 'tokenProgram';
415
+ },
416
+ {
417
+ kind: 'account';
418
+ path: 'mint';
419
+ }
420
+ ];
421
+ program: {
422
+ kind: 'const';
423
+ value: [
424
+ 140,
425
+ 151,
426
+ 37,
427
+ 143,
428
+ 78,
429
+ 36,
430
+ 137,
431
+ 241,
432
+ 187,
433
+ 61,
434
+ 16,
435
+ 41,
436
+ 20,
437
+ 142,
438
+ 13,
439
+ 131,
440
+ 11,
441
+ 90,
442
+ 19,
443
+ 153,
444
+ 218,
445
+ 255,
446
+ 16,
447
+ 132,
448
+ 4,
449
+ 142,
450
+ 123,
451
+ 216,
452
+ 219,
453
+ 233,
454
+ 248,
455
+ 89
456
+ ];
457
+ };
458
+ };
459
+ },
460
+ {
461
+ name: 'squadsAta';
462
+ writable: true;
463
+ pda: {
464
+ seeds: [
465
+ {
466
+ kind: 'account';
467
+ path: 'squads';
468
+ },
469
+ {
470
+ kind: 'account';
471
+ path: 'tokenProgram';
472
+ },
473
+ {
474
+ kind: 'account';
475
+ path: 'mint';
476
+ }
477
+ ];
478
+ program: {
479
+ kind: 'const';
480
+ value: [
481
+ 140,
482
+ 151,
483
+ 37,
484
+ 143,
485
+ 78,
486
+ 36,
487
+ 137,
488
+ 241,
489
+ 187,
490
+ 61,
491
+ 16,
492
+ 41,
493
+ 20,
494
+ 142,
495
+ 13,
496
+ 131,
497
+ 11,
498
+ 90,
499
+ 19,
500
+ 153,
501
+ 218,
502
+ 255,
503
+ 16,
504
+ 132,
505
+ 4,
506
+ 142,
507
+ 123,
508
+ 216,
509
+ 219,
510
+ 233,
511
+ 248,
512
+ 89
513
+ ];
514
+ };
515
+ };
516
+ },
517
+ {
518
+ name: 'tokenProgram';
519
+ address: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
520
+ },
521
+ {
522
+ name: 'associatedTokenProgram';
523
+ address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
524
+ },
398
525
  {
399
526
  name: 'systemProgram';
400
527
  address: '11111111111111111111111111111111';
@@ -402,8 +529,12 @@ export type PoseidonsProtocol = {
402
529
  ];
403
530
  args: [
404
531
  {
405
- name: 'spins';
406
- type: 'u64';
532
+ name: 'args';
533
+ type: {
534
+ defined: {
535
+ name: 'addSpinArgs';
536
+ };
537
+ };
407
538
  }
408
539
  ];
409
540
  },
@@ -1395,6 +1526,22 @@ export type PoseidonsProtocol = {
1395
1526
  ];
1396
1527
  };
1397
1528
  },
1529
+ {
1530
+ name: 'addSpinArgs';
1531
+ type: {
1532
+ kind: 'struct';
1533
+ fields: [
1534
+ {
1535
+ name: 'isUsdc';
1536
+ type: 'bool';
1537
+ },
1538
+ {
1539
+ name: 'spins';
1540
+ type: 'u64';
1541
+ }
1542
+ ];
1543
+ };
1544
+ },
1398
1545
  {
1399
1546
  name: 'addWheelPrizeArgs';
1400
1547
  type: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/poseidons-protocol",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",