solotto 1.1.0 → 1.1.2
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.
- package/README.md +34 -3
- package/package.json +1 -1
- package/solotto.d.ts +18 -2
- package/solotto.js +35 -2
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ A JavaScript SDK for interacting with the Solotto on-chain lottery program on So
|
|
|
25
25
|
- [Boost](#boost)
|
|
26
26
|
- [GetBoosters](#getboosters)
|
|
27
27
|
- [GetLottery](#getlottery)
|
|
28
|
+
- [GetLotteries](#getlotteries)
|
|
28
29
|
- [GetTicket](#getticket)
|
|
29
30
|
- [GetTickets](#gettickets)
|
|
30
31
|
- [WatchDraw](#watchdraw)
|
|
@@ -340,6 +341,7 @@ const grouped = await lottery.GetBoosters(authority, lotteryId, true);
|
|
|
340
341
|
authority: "Pubkey...", // Lottery authority public key
|
|
341
342
|
amount: 0.5, // Boost amount in SOL
|
|
342
343
|
message: "Good luck!", // Optional memo message (empty string if none)
|
|
344
|
+
time: 1700000000, // Unix block timestamp of the boost transaction
|
|
343
345
|
signature: "TxSignature...",
|
|
344
346
|
},
|
|
345
347
|
// ...
|
|
@@ -352,7 +354,7 @@ const grouped = await lottery.GetBoosters(authority, lotteryId, true);
|
|
|
352
354
|
{
|
|
353
355
|
"BoosterPubkey...": {
|
|
354
356
|
boost: [
|
|
355
|
-
{ booster: "Pubkey...", lotteryId: 1, authority: "Pubkey...", amount: 0.5, message: "...", signature: "TxSig..." },
|
|
357
|
+
{ booster: "Pubkey...", lotteryId: 1, authority: "Pubkey...", amount: 0.5, message: "...", time: 1700000000, signature: "TxSig..." },
|
|
356
358
|
// ...
|
|
357
359
|
],
|
|
358
360
|
total: 1.5, // Sum of all boost amounts in SOL
|
|
@@ -400,6 +402,30 @@ const state = await lottery.GetLottery(authority, lotteryId, fees);
|
|
|
400
402
|
|
|
401
403
|
---
|
|
402
404
|
|
|
405
|
+
#### GetLotteries
|
|
406
|
+
|
|
407
|
+
Fetches all lottery accounts from the program, optionally filtered by authority. Returns an array of lottery state objects sorted descending by lottery ID.
|
|
408
|
+
|
|
409
|
+
```js
|
|
410
|
+
// Get all lotteries across all authorities
|
|
411
|
+
const allLotteries = await lottery.GetLotteries();
|
|
412
|
+
|
|
413
|
+
// Get all lotteries for a specific authority
|
|
414
|
+
const myLotteries = await lottery.GetLotteries(authority);
|
|
415
|
+
|
|
416
|
+
// Get all lotteries with raw prize pool (no fee deduction)
|
|
417
|
+
const raw = await lottery.GetLotteries(authority, false);
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
| Parameter | Type | Default | Description |
|
|
421
|
+
|---|---|---|---|
|
|
422
|
+
| `authority` | `{publicKey} \| false` | `false` | Filter by lottery authority. Pass `false` to include all authorities. |
|
|
423
|
+
| `fees` | `Boolean` | `true` | If `true`, `prizePoolBalance` reflects a 10% fee deduction. |
|
|
424
|
+
|
|
425
|
+
**Returns:** An array of `LotteryState` objects (same shape as `GetLottery`), sorted descending by `lotteryId`.
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
403
429
|
#### GetTicket
|
|
404
430
|
|
|
405
431
|
Fetches a single ticket by its ticket number.
|
|
@@ -432,7 +458,7 @@ const ticket = await lottery.GetTicket(authority, lotteryId, ticketNumber);
|
|
|
432
458
|
|
|
433
459
|
#### GetTickets
|
|
434
460
|
|
|
435
|
-
Fetches all tickets for a lottery, optionally filtered by buyer and/or
|
|
461
|
+
Fetches all tickets for a lottery, optionally filtered by buyer, grouped by owner, and/or enriched with purchase timestamps.
|
|
436
462
|
|
|
437
463
|
```js
|
|
438
464
|
// Get all tickets
|
|
@@ -443,6 +469,9 @@ const myTickets = await lottery.GetTickets(authority, lotteryId, buyer);
|
|
|
443
469
|
|
|
444
470
|
// Get all tickets grouped by owner
|
|
445
471
|
const grouped = await lottery.GetTickets(authority, lotteryId, false, true);
|
|
472
|
+
|
|
473
|
+
// Get all tickets with purchase timestamps
|
|
474
|
+
const withTime = await lottery.GetTickets(authority, lotteryId, false, false, true);
|
|
446
475
|
```
|
|
447
476
|
|
|
448
477
|
| Parameter | Type | Default | Description |
|
|
@@ -451,6 +480,7 @@ const grouped = await lottery.GetTickets(authority, lotteryId, false, true);
|
|
|
451
480
|
| `lotteryId` | `Number` | — | The lottery ID. |
|
|
452
481
|
| `buyer` | `{publicKey} \| false` | `false` | Optional buyer to filter by. |
|
|
453
482
|
| `group` | `Boolean` | `false` | If `true`, groups tickets by owner. |
|
|
483
|
+
| `time` | `Boolean` | `false` | If `true`, fetches the block timestamp for each ticket (slower — requires extra RPC calls). |
|
|
454
484
|
|
|
455
485
|
**Returns (ungrouped):**
|
|
456
486
|
|
|
@@ -467,6 +497,7 @@ const grouped = await lottery.GetTickets(authority, lotteryId, false, true);
|
|
|
467
497
|
ticketReceipt: "Pubkey...",
|
|
468
498
|
ticketNumber: 42,
|
|
469
499
|
ticketPda: "Pubkey...",
|
|
500
|
+
time: null, // Unix timestamp when time=true, null otherwise
|
|
470
501
|
},
|
|
471
502
|
// ... sorted descending by ticket number
|
|
472
503
|
],
|
|
@@ -486,7 +517,7 @@ const grouped = await lottery.GetTickets(authority, lotteryId, false, true);
|
|
|
486
517
|
owner: "Pubkey...",
|
|
487
518
|
ticketCount: 3,
|
|
488
519
|
tickets: [
|
|
489
|
-
{ owner: "Pubkey...", lottery: "Pubkey...", ticketReceipt: "Pubkey...", ticketNumber: 42, ticketPda: "Pubkey..." },
|
|
520
|
+
{ owner: "Pubkey...", lottery: "Pubkey...", ticketReceipt: "Pubkey...", ticketNumber: 42, ticketPda: "Pubkey...", time: null },
|
|
490
521
|
// ...
|
|
491
522
|
],
|
|
492
523
|
},
|
package/package.json
CHANGED
package/solotto.d.ts
CHANGED
|
@@ -105,6 +105,8 @@ declare module "solotto" {
|
|
|
105
105
|
ticketReceipt: string;
|
|
106
106
|
ticketNumber: number;
|
|
107
107
|
ticketPda: string;
|
|
108
|
+
/** Unix block timestamp of ticket purchase, or `null` when `time=false`. */
|
|
109
|
+
time: number | null;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
interface GroupedTicketOwner {
|
|
@@ -160,6 +162,8 @@ declare module "solotto" {
|
|
|
160
162
|
amount: number;
|
|
161
163
|
/** Optional memo message from the booster. */
|
|
162
164
|
message: string;
|
|
165
|
+
/** Unix block timestamp of the boost transaction. */
|
|
166
|
+
time: number;
|
|
163
167
|
/** Transaction signature. */
|
|
164
168
|
signature: string;
|
|
165
169
|
}
|
|
@@ -292,6 +296,17 @@ declare module "solotto" {
|
|
|
292
296
|
fees?: boolean
|
|
293
297
|
): Promise<LotteryState>;
|
|
294
298
|
|
|
299
|
+
/**
|
|
300
|
+
* Fetch all lottery accounts, optionally filtered by authority.
|
|
301
|
+
* @param authority - Filter by lottery authority, or `false` for all.
|
|
302
|
+
* @param fees - If `true`, deduct 10% from prize pool balance.
|
|
303
|
+
* @returns Array of lottery states sorted descending by lotteryId.
|
|
304
|
+
*/
|
|
305
|
+
GetLotteries(
|
|
306
|
+
authority?: HasPublicKey | false,
|
|
307
|
+
fees?: boolean
|
|
308
|
+
): Promise<LotteryState[]>;
|
|
309
|
+
|
|
295
310
|
/** Fetch a single ticket by its ticket number. */
|
|
296
311
|
GetTicket(
|
|
297
312
|
authority: HasPublicKey,
|
|
@@ -299,12 +314,13 @@ declare module "solotto" {
|
|
|
299
314
|
ticket: number
|
|
300
315
|
): Promise<TicketInfo>;
|
|
301
316
|
|
|
302
|
-
/** Fetch all tickets for a lottery, optionally filtered by buyer and/or
|
|
317
|
+
/** Fetch all tickets for a lottery, optionally filtered by buyer, grouped by owner, and/or with timestamps. */
|
|
303
318
|
GetTickets(
|
|
304
319
|
authority: HasPublicKey,
|
|
305
320
|
lotteryId: number,
|
|
306
321
|
buyer?: HasPublicKey | false,
|
|
307
|
-
group?: boolean
|
|
322
|
+
group?: boolean,
|
|
323
|
+
time?: boolean
|
|
308
324
|
): Promise<TicketListResult>;
|
|
309
325
|
|
|
310
326
|
/**
|
package/solotto.js
CHANGED
|
@@ -441,7 +441,7 @@ class Lottery extends EventEmitter {
|
|
|
441
441
|
* @param {Number} lotteryId - Lottery Id
|
|
442
442
|
* @param {PublicKey} buyer - Ticket Buyer Optional
|
|
443
443
|
*/
|
|
444
|
-
async GetTickets(authority, lotteryId, buyer = false, group = false) {
|
|
444
|
+
async GetTickets(authority, lotteryId, buyer = false, group = false, time = false) {
|
|
445
445
|
const [lotteryPDA] = await this.DeriveLotteryPDA(authority.publicKey, lotteryId);
|
|
446
446
|
const filters = [];
|
|
447
447
|
filters.push({dataSize: 104});
|
|
@@ -459,6 +459,11 @@ class Lottery extends EventEmitter {
|
|
|
459
459
|
newTicket.ticketReceipt = new PublicKey(decoded.ticketReceipt).toString();
|
|
460
460
|
newTicket.ticketNumber = parseInt(new BN(decoded.ticketNumber, 10, "le"));
|
|
461
461
|
newTicket.ticketPda = data.pubkey.toString();
|
|
462
|
+
newTicket.time = null;
|
|
463
|
+
if(time){
|
|
464
|
+
const dat = await this.connection.getSignaturesForAddress(data.pubkey, "finalized");
|
|
465
|
+
newTicket.time = dat[0].blockTime;
|
|
466
|
+
}
|
|
462
467
|
tickets.push(newTicket);
|
|
463
468
|
i++;
|
|
464
469
|
}
|
|
@@ -502,6 +507,32 @@ class Lottery extends EventEmitter {
|
|
|
502
507
|
const account = await this.connection.getAccountInfo(lotteryPDA);
|
|
503
508
|
return await this.DecodeLotteryState(account.data, fees);
|
|
504
509
|
}
|
|
510
|
+
|
|
511
|
+
/***
|
|
512
|
+
* @param {PublicKey} authority - Keypair with no secretKey
|
|
513
|
+
* @param {Boolean} fees - true = prize pool - 10% (for display before drawing)
|
|
514
|
+
*/
|
|
515
|
+
async GetLotteries(authority=false, fees=true) {
|
|
516
|
+
try{
|
|
517
|
+
const result = [];
|
|
518
|
+
let filters;
|
|
519
|
+
if(authority){
|
|
520
|
+
filters = [
|
|
521
|
+
{dataSize: 150},
|
|
522
|
+
{memcmp:{offset: 0, bytes: authority.publicKey.toString(),},}
|
|
523
|
+
];
|
|
524
|
+
}
|
|
525
|
+
else{filters = [{dataSize: 150}];}
|
|
526
|
+
const data = await this.connection.getProgramAccounts(this.program, {filters:filters,});
|
|
527
|
+
for await (const datum of data) {
|
|
528
|
+
const decoded = await this.DecodeLotteryState(datum.account.data, fees);
|
|
529
|
+
result.push(decoded);
|
|
530
|
+
}
|
|
531
|
+
return result.sort((a, b) => b.lotteryId - a.lotteryId);
|
|
532
|
+
}
|
|
533
|
+
catch(err){return result;}
|
|
534
|
+
}
|
|
535
|
+
|
|
505
536
|
async DecodeLotteryState(buffer, fees = true){
|
|
506
537
|
let offset = 0;
|
|
507
538
|
// Helper to handle the 1-byte Option flag
|
|
@@ -552,7 +583,7 @@ class Lottery extends EventEmitter {
|
|
|
552
583
|
releaseTime = readOption(() => {
|
|
553
584
|
const val = buffer.readBigUInt64LE(offset);
|
|
554
585
|
offset += 8;
|
|
555
|
-
return Number(
|
|
586
|
+
return Number(val);
|
|
556
587
|
});
|
|
557
588
|
}catch{}
|
|
558
589
|
const prizePoolAddress = await this.DerivePrizePoolPDA();
|
|
@@ -706,6 +737,7 @@ class Lottery extends EventEmitter {
|
|
|
706
737
|
else if(log.includes("Program log: Memo ")){
|
|
707
738
|
const parts = log.split(":booster:");
|
|
708
739
|
item.message = parts[1].slice(0, -1).trim();
|
|
740
|
+
item.message = item.message.replace(new RegExp("\\\\", "g"), "");
|
|
709
741
|
}
|
|
710
742
|
else if(log.includes("Program log: Authority ")){
|
|
711
743
|
item.authority = log.replace("Program log: Authority ","").trim();
|
|
@@ -715,6 +747,7 @@ class Lottery extends EventEmitter {
|
|
|
715
747
|
const matchesAuthority = authority ? (item.authority && authority.publicKey.toString() === item.authority) : true;
|
|
716
748
|
const matchesLotteryId = lotteryId ? (item.lotteryId !== undefined && lotteryId.toString() === item.lotteryId.toString()) : true;
|
|
717
749
|
if(matchesAuthority && matchesLotteryId && item.amount >= 0.0001){
|
|
750
|
+
item.time = init.blockTime;
|
|
718
751
|
item.signature = init.signature;
|
|
719
752
|
result.push(item);
|
|
720
753
|
}
|