solotto 1.2.2 → 1.3.0

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/solotto.d.ts +37 -7
  3. package/solotto.js +31 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solotto",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "Solana lottery client",
5
5
  "type": "module",
6
6
  "types": "./solotto.d.ts",
package/solotto.d.ts CHANGED
@@ -6,6 +6,14 @@ declare module "solotto" {
6
6
 
7
7
  type PriorityLevel = "Low" | "Medium" | "High" | "VeryHigh" | "Extreme";
8
8
 
9
+ /** Per-call overrides for transaction priority and compute tolerance. */
10
+ interface TxOptions {
11
+ /** Priority fee level. Overrides instance default. */
12
+ priority?: PriorityLevel;
13
+ /** Compute unit safety multiplier. Overrides instance default. */
14
+ tolerance?: number;
15
+ }
16
+
9
17
  interface TxParams {
10
18
  /** Payer public key as a base-58 string. */
11
19
  account: string;
@@ -257,6 +265,10 @@ declare module "solotto" {
257
265
  connection: Connection;
258
266
  wss: string | false;
259
267
  program: PublicKey;
268
+ /** Default priority fee level for all transactions. Defaults to `"Low"`. */
269
+ priority: PriorityLevel;
270
+ /** Default compute unit safety multiplier for all transactions. Defaults to `1.2`. */
271
+ tolerance: number;
260
272
 
261
273
  constructor(connection: Connection, wss: string | false, program: PublicKey);
262
274
 
@@ -277,13 +289,15 @@ declare module "solotto" {
277
289
  * @param lotteryId - Lottery numeric identifier.
278
290
  * @param amount - Number of tickets to buy (1–4, default `1`).
279
291
  * @param encoded - If `true`, return a base64-encoded transaction.
292
+ * @param options - Per-call overrides for priority and tolerance.
280
293
  */
281
294
  BuyTickets(
282
295
  buyer: Keypair,
283
296
  authority: HasPublicKey,
284
297
  lotteryId: number,
285
298
  amount?: number,
286
- encoded?: boolean
299
+ encoded?: boolean,
300
+ options?: TxOptions
287
301
  ): Promise<string | TxResult>;
288
302
 
289
303
  /**
@@ -292,12 +306,14 @@ declare module "solotto" {
292
306
  * @param lotteryId - Lottery numeric identifier.
293
307
  * @param winner - The winning ticket owner's keypair.
294
308
  * @param encoded - If `true`, return a base64-encoded transaction.
309
+ * @param options - Per-call overrides for priority and tolerance.
295
310
  */
296
311
  ClaimTicket(
297
312
  authority: HasPublicKey,
298
313
  lotteryId: number,
299
314
  winner: Keypair,
300
- encoded?: boolean
315
+ encoded?: boolean,
316
+ options?: TxOptions
301
317
  ): Promise<string | string[] | TxResult>;
302
318
 
303
319
  /** Fetch the on-chain state of a lottery. */
@@ -343,6 +359,7 @@ declare module "solotto" {
343
359
  * @param amount - Amount of SOL to boost (e.g. `0.5` for 0.5 SOL).
344
360
  * @param message - Optional memo string attached to the transaction.
345
361
  * @param encoded - If `true`, return a base64-encoded transaction.
362
+ * @param options - Per-call overrides for priority and tolerance.
346
363
  */
347
364
  Boost(
348
365
  authority: HasPublicKey,
@@ -350,7 +367,8 @@ declare module "solotto" {
350
367
  booster: Keypair,
351
368
  amount: number,
352
369
  message?: string | false,
353
- encoded?: boolean
370
+ encoded?: boolean,
371
+ options?: TxOptions
354
372
  ): Promise<string | TxResult | undefined>;
355
373
 
356
374
  /**
@@ -412,6 +430,10 @@ declare module "solotto" {
412
430
  export class LotteryManager {
413
431
  connection: Connection;
414
432
  program: PublicKey;
433
+ /** Default priority fee level for all transactions. Defaults to `"Low"`. */
434
+ priority: PriorityLevel;
435
+ /** Default compute unit safety multiplier for all transactions. Defaults to `1.2`. */
436
+ tolerance: number;
415
437
 
416
438
  constructor(connection: Connection, program: PublicKey);
417
439
 
@@ -421,12 +443,14 @@ declare module "solotto" {
421
443
  * @param ticketPrice - Ticket price in lamports.
422
444
  * @param lotteryId - A unique numeric lottery identifier.
423
445
  * @param encoded - If `true`, return a base64-encoded transaction.
446
+ * @param options - Per-call overrides for priority and tolerance.
424
447
  */
425
448
  Initialize(
426
449
  authority: Keypair,
427
450
  ticketPrice: number,
428
451
  lotteryId: number,
429
- encoded?: boolean
452
+ encoded?: boolean,
453
+ options?: TxOptions
430
454
  ): Promise<string | TxResult>;
431
455
 
432
456
  /**
@@ -434,11 +458,13 @@ declare module "solotto" {
434
458
  * @param authority - The lottery authority keypair.
435
459
  * @param lotteryId - Lottery numeric identifier.
436
460
  * @param encoded - If `true`, return a base64-encoded transaction.
461
+ * @param options - Per-call overrides for priority and tolerance.
437
462
  */
438
463
  RandomDraw(
439
464
  authority: Keypair,
440
465
  lotteryId: number,
441
- encoded?: boolean
466
+ encoded?: boolean,
467
+ options?: TxOptions
442
468
  ): Promise<LotteryState | string | TxResult | undefined>;
443
469
 
444
470
  /**
@@ -447,12 +473,14 @@ declare module "solotto" {
447
473
  * @param lotteryId - Lottery numeric identifier.
448
474
  * @param lockState - `0` to lock (stop sales), `1` to unlock.
449
475
  * @param encoded - If `true`, return a base64-encoded transaction.
476
+ * @param options - Per-call overrides for priority and tolerance.
450
477
  */
451
478
  LockLottery(
452
479
  authority: Keypair,
453
480
  lotteryId: number,
454
481
  lockState: 0 | 1,
455
- encoded?: boolean
482
+ encoded?: boolean,
483
+ options?: TxOptions
456
484
  ): Promise<LotteryState | string | TxResult | undefined>;
457
485
 
458
486
  /**
@@ -460,11 +488,13 @@ declare module "solotto" {
460
488
  * @param authority - The lottery authority keypair.
461
489
  * @param lotteryId - Lottery numeric identifier.
462
490
  * @param encoded - If `true`, return a base64-encoded transaction.
491
+ * @param options - Per-call overrides for priority and tolerance.
463
492
  */
464
493
  ClaimExpired(
465
494
  authority: Keypair,
466
495
  lotteryId: number,
467
- encoded?: boolean
496
+ encoded?: boolean,
497
+ options?: TxOptions
468
498
  ): Promise<LotteryState | string | TxResult | undefined>;
469
499
  }
470
500
  }
package/solotto.js CHANGED
@@ -188,6 +188,8 @@ class Lottery extends EventEmitter {
188
188
  this.connection=connection;
189
189
  this.wss=wss;
190
190
  this.program=program;
191
+ this.priority="Low";
192
+ this.tolerance=1.2;
191
193
  this.TICKET_STATE = BufferLayout.struct([
192
194
  publicKey("owner"),
193
195
  publicKey("lottery"),
@@ -260,7 +262,7 @@ class Lottery extends EventEmitter {
260
262
  * @param {PublicKey} winner - Keypair with no secretKey
261
263
  * @param {Boolean} encoded - true returns encoded transaction
262
264
  */
263
- async ClaimTicket(authority, lotteryId, winner, encoded = false){
265
+ async ClaimTicket(authority, lotteryId, winner, encoded = false, options = {}){
264
266
  async function claimData() {
265
267
  const buffer = Buffer.alloc(1);
266
268
  buffer.writeUInt8(INSTRUCTIONS.CLAIM_PRIZE, 0);
@@ -284,11 +286,11 @@ class Lottery extends EventEmitter {
284
286
  _tx_.instructions = [ix]; // array : required
285
287
  _tx_.signers = false; // array : default false
286
288
  _tx_.table = false; // array : default false
287
- _tx_.tolerance = 1.2; // int : default 1.1
289
+ _tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
288
290
  _tx_.compute = true; // bool : default true
289
291
  _tx_.fees = true; // bool : default true
290
- _tx_.priority = "Low";
291
- if(encoded){
292
+ _tx_.priority = options.priority ?? this.priority ?? "Low";
293
+ if(encoded){
292
294
  _tx_.serialize = true;
293
295
  _tx_.encode = true;
294
296
  }
@@ -316,7 +318,7 @@ class Lottery extends EventEmitter {
316
318
  * @param {Number} amount - Ticket Qty 1-4
317
319
  * @param {Boolean} encoded - true returns encoded transaction
318
320
  */
319
- async BuyTickets(buyer, authority, lotteryId, amount = 1, encoded = false){
321
+ async BuyTickets(buyer, authority, lotteryId, amount = 1, encoded = false, options = {}){
320
322
  const network = new LotteryNetwork(this.connection);
321
323
  const result = await this.BundleTickets(authority, buyer, lotteryId, amount);
322
324
  const _tx_ = {};
@@ -324,11 +326,11 @@ class Lottery extends EventEmitter {
324
326
  _tx_.instructions = result.ixs; // array : required
325
327
  _tx_.signers = result.signers; // array : default false
326
328
  _tx_.table = false; // array : default false
327
- _tx_.tolerance = 1.2; // int : default 1.1
329
+ _tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
328
330
  _tx_.compute = true; // bool : default true
329
331
  _tx_.fees = true; // bool : default true
330
- _tx_.priority = "Low";
331
- if(encoded){
332
+ _tx_.priority = options.priority ?? this.priority ?? "Low";
333
+ if(encoded){
332
334
  _tx_.serialize = true;
333
335
  _tx_.encode = true;
334
336
  }
@@ -636,7 +638,7 @@ class Lottery extends EventEmitter {
636
638
  * @param {Number} amount - The amount of sol to boost
637
639
  * @param {Boolean} encoded - true returns encoded transaction
638
640
  */
639
- async Boost(authority, lotteryId, booster, amount, message = false, encoded = false) {
641
+ async Boost(authority, lotteryId, booster, amount, message = false, encoded = false, options = {}) {
640
642
  try{
641
643
  async function boostData(lotId, amount) {
642
644
  const lamports = parseInt(amount * LAMPORTS_PER_SOL);
@@ -664,10 +666,11 @@ class Lottery extends EventEmitter {
664
666
  _tx_.instructions = [ix]; // array : required
665
667
  _tx_.signers = false; // array : default false
666
668
  _tx_.table = false; // array : default false
667
- _tx_.tolerance = 1.2; // int : default 1.1
669
+ _tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
668
670
  _tx_.compute = true; // bool : default true
669
671
  _tx_.fees = true; // bool : default true
670
- _tx_.priority = "Low"; // string : default Low
672
+ _tx_.priority = options.priority ?? this.priority ?? "Low";
673
+
671
674
  _tx_.memo = message;
672
675
  if(encoded){
673
676
  _tx_.serialize = true;
@@ -821,7 +824,7 @@ class LotteryManager {
821
824
  * @param {Connection} connection - Solana connection
822
825
  * @param {PublicKey} program - Lottery Program Id
823
826
  */
824
- constructor(connection, program){this.connection=connection;this.program=program;}
827
+ constructor(connection, program){this.connection=connection;this.program=program;this.priority="Low";this.tolerance=1.2;}
825
828
 
826
829
  /***
827
830
  * @param {Keypair} authority - Keypair
@@ -829,7 +832,7 @@ class LotteryManager {
829
832
  * @param {String} lotteryId - String
830
833
  * @param {Boolean} encoded - true returns encoded transaction
831
834
  */
832
- async Initialize(authority, ticketPrice, lotteryId, encoded = false){
835
+ async Initialize(authority, ticketPrice, lotteryId, encoded = false, options = {}){
833
836
  const lottery = new Lottery(this.connection, false, this.program);
834
837
  const network = new LotteryNetwork(this.connection);
835
838
  async function initializeData(tketPrice, lotId) {
@@ -857,10 +860,11 @@ class LotteryManager {
857
860
  _tx_.instructions = [ix]; // array : required
858
861
  _tx_.signers = false; // array : default false
859
862
  _tx_.table = false; // array : default false
860
- _tx_.tolerance = 1.2; // int : default 1.1
863
+ _tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
861
864
  _tx_.compute = true; // bool : default true
862
865
  _tx_.fees = true; // bool : default true
863
- _tx_.priority = "Low"; // string : default Low
866
+ _tx_.priority = options.priority ?? this.priority ?? "Low";
867
+
864
868
  if(encoded){
865
869
  _tx_.serialize = true;
866
870
  _tx_.encode = true;
@@ -885,7 +889,7 @@ class LotteryManager {
885
889
  * @param {String} lotteryId - The lottery id
886
890
  * @param {Boolean} encoded - true returns encoded transaction
887
891
  */
888
- async RandomDraw(authority, lotteryId, encoded = false) {
892
+ async RandomDraw(authority, lotteryId, encoded = false, options = {}) {
889
893
  try{
890
894
  async function randomnessData() {
891
895
  const buffer = Buffer.alloc(1);
@@ -908,10 +912,11 @@ class LotteryManager {
908
912
  _tx_.instructions = [ix]; // array : required
909
913
  _tx_.signers = false; // array : default false
910
914
  _tx_.table = false; // array : default false
911
- _tx_.tolerance = 1.2; // int : default 1.1
915
+ _tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
912
916
  _tx_.compute = true; // bool : default true
913
917
  _tx_.fees = true; // bool : default true
914
- _tx_.priority = "Low"; // string : default Low
918
+ _tx_.priority = options.priority ?? this.priority ?? "Low";
919
+
915
920
  _tx_.memo = "draw";
916
921
  if(encoded){
917
922
  _tx_.serialize = true;
@@ -946,7 +951,7 @@ class LotteryManager {
946
951
  * @param {Number} lockState - 0 = lock ticket sales, 1 = unlock (requires authority)
947
952
  * @param {Boolean} encoded - true returns encoded transaction
948
953
  */
949
- async LockLottery(authority, lotteryId, lockState, encoded = false) {
954
+ async LockLottery(authority, lotteryId, lockState, encoded = false, options = {}) {
950
955
  try{
951
956
  async function lockData(lock) {
952
957
  const buffer = Buffer.alloc(2); // 1 byte discriminator + 1 bytes lock status
@@ -967,10 +972,11 @@ class LotteryManager {
967
972
  _tx_.instructions = [ix]; // array : required
968
973
  _tx_.signers = false; // array : default false
969
974
  _tx_.table = false; // array : default false
970
- _tx_.tolerance = 1.2; // int : default 1.1
975
+ _tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
971
976
  _tx_.compute = true; // bool : default true
972
977
  _tx_.fees = true; // bool : default true
973
- _tx_.priority = "Low"; // string : default Low
978
+ _tx_.priority = options.priority ?? this.priority ?? "Low";
979
+
974
980
  _tx_.memo = false;
975
981
  if(encoded){
976
982
  _tx_.serialize = true;
@@ -1004,7 +1010,7 @@ class LotteryManager {
1004
1010
  * @param {String} lotteryId - The lottery id
1005
1011
  * @param {Boolean} encoded - true returns encoded transaction
1006
1012
  */
1007
- async ClaimExpired(authority, lotteryId, encoded = false) {
1013
+ async ClaimExpired(authority, lotteryId, encoded = false, options = {}) {
1008
1014
  try{
1009
1015
  async function expiredData() {
1010
1016
  const buffer = Buffer.alloc(1); // 1 byte discriminator + 1 bytes lock status
@@ -1026,10 +1032,11 @@ class LotteryManager {
1026
1032
  _tx_.instructions = [ix]; // array : required
1027
1033
  _tx_.signers = false; // array : default false
1028
1034
  _tx_.table = false; // array : default false
1029
- _tx_.tolerance = 1.2; // int : default 1.1
1035
+ _tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
1030
1036
  _tx_.compute = true; // bool : default true
1031
1037
  _tx_.fees = true; // bool : default true
1032
- _tx_.priority = "Low"; // string : default Low
1038
+ _tx_.priority = options.priority ?? this.priority ?? "Low";
1039
+
1033
1040
  _tx_.memo = false;
1034
1041
  if(encoded){
1035
1042
  _tx_.serialize = true;