solotto 1.2.1 → 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.
- package/package.json +1 -1
- package/solotto.d.ts +37 -7
- package/solotto.js +31 -25
package/package.json
CHANGED
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);
|
|
@@ -277,7 +279,6 @@ class Lottery extends EventEmitter {
|
|
|
277
279
|
{ pubkey: new PublicKey(LOTTO.ticket.ticketPda), isSigner: false, isWritable: false },
|
|
278
280
|
{ pubkey: new PublicKey(LOTTO.prizePoolAddress), isSigner: false, isWritable: true },
|
|
279
281
|
{ pubkey: new PublicKey(LOTTO.authority), isSigner: false, isWritable: true },
|
|
280
|
-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
281
282
|
];
|
|
282
283
|
const ix = new TransactionInstruction({programId: this.program, keys, data: await claimData()});
|
|
283
284
|
const _tx_ = {};
|
|
@@ -285,11 +286,11 @@ class Lottery extends EventEmitter {
|
|
|
285
286
|
_tx_.instructions = [ix]; // array : required
|
|
286
287
|
_tx_.signers = false; // array : default false
|
|
287
288
|
_tx_.table = false; // array : default false
|
|
288
|
-
_tx_.tolerance =
|
|
289
|
+
_tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
|
|
289
290
|
_tx_.compute = true; // bool : default true
|
|
290
291
|
_tx_.fees = true; // bool : default true
|
|
291
|
-
_tx_.priority = "Low";
|
|
292
|
-
|
|
292
|
+
_tx_.priority = options.priority ?? this.priority ?? "Low";
|
|
293
|
+
if(encoded){
|
|
293
294
|
_tx_.serialize = true;
|
|
294
295
|
_tx_.encode = true;
|
|
295
296
|
}
|
|
@@ -317,7 +318,7 @@ class Lottery extends EventEmitter {
|
|
|
317
318
|
* @param {Number} amount - Ticket Qty 1-4
|
|
318
319
|
* @param {Boolean} encoded - true returns encoded transaction
|
|
319
320
|
*/
|
|
320
|
-
async BuyTickets(buyer, authority, lotteryId, amount = 1, encoded = false){
|
|
321
|
+
async BuyTickets(buyer, authority, lotteryId, amount = 1, encoded = false, options = {}){
|
|
321
322
|
const network = new LotteryNetwork(this.connection);
|
|
322
323
|
const result = await this.BundleTickets(authority, buyer, lotteryId, amount);
|
|
323
324
|
const _tx_ = {};
|
|
@@ -325,11 +326,11 @@ class Lottery extends EventEmitter {
|
|
|
325
326
|
_tx_.instructions = result.ixs; // array : required
|
|
326
327
|
_tx_.signers = result.signers; // array : default false
|
|
327
328
|
_tx_.table = false; // array : default false
|
|
328
|
-
_tx_.tolerance =
|
|
329
|
+
_tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
|
|
329
330
|
_tx_.compute = true; // bool : default true
|
|
330
331
|
_tx_.fees = true; // bool : default true
|
|
331
|
-
_tx_.priority = "Low";
|
|
332
|
-
|
|
332
|
+
_tx_.priority = options.priority ?? this.priority ?? "Low";
|
|
333
|
+
if(encoded){
|
|
333
334
|
_tx_.serialize = true;
|
|
334
335
|
_tx_.encode = true;
|
|
335
336
|
}
|
|
@@ -637,7 +638,7 @@ class Lottery extends EventEmitter {
|
|
|
637
638
|
* @param {Number} amount - The amount of sol to boost
|
|
638
639
|
* @param {Boolean} encoded - true returns encoded transaction
|
|
639
640
|
*/
|
|
640
|
-
async Boost(authority, lotteryId, booster, amount, message = false, encoded = false) {
|
|
641
|
+
async Boost(authority, lotteryId, booster, amount, message = false, encoded = false, options = {}) {
|
|
641
642
|
try{
|
|
642
643
|
async function boostData(lotId, amount) {
|
|
643
644
|
const lamports = parseInt(amount * LAMPORTS_PER_SOL);
|
|
@@ -665,10 +666,11 @@ class Lottery extends EventEmitter {
|
|
|
665
666
|
_tx_.instructions = [ix]; // array : required
|
|
666
667
|
_tx_.signers = false; // array : default false
|
|
667
668
|
_tx_.table = false; // array : default false
|
|
668
|
-
_tx_.tolerance =
|
|
669
|
+
_tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
|
|
669
670
|
_tx_.compute = true; // bool : default true
|
|
670
671
|
_tx_.fees = true; // bool : default true
|
|
671
|
-
_tx_.priority =
|
|
672
|
+
_tx_.priority = options.priority ?? this.priority ?? "Low";
|
|
673
|
+
|
|
672
674
|
_tx_.memo = message;
|
|
673
675
|
if(encoded){
|
|
674
676
|
_tx_.serialize = true;
|
|
@@ -822,7 +824,7 @@ class LotteryManager {
|
|
|
822
824
|
* @param {Connection} connection - Solana connection
|
|
823
825
|
* @param {PublicKey} program - Lottery Program Id
|
|
824
826
|
*/
|
|
825
|
-
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;}
|
|
826
828
|
|
|
827
829
|
/***
|
|
828
830
|
* @param {Keypair} authority - Keypair
|
|
@@ -830,7 +832,7 @@ class LotteryManager {
|
|
|
830
832
|
* @param {String} lotteryId - String
|
|
831
833
|
* @param {Boolean} encoded - true returns encoded transaction
|
|
832
834
|
*/
|
|
833
|
-
async Initialize(authority, ticketPrice, lotteryId, encoded = false){
|
|
835
|
+
async Initialize(authority, ticketPrice, lotteryId, encoded = false, options = {}){
|
|
834
836
|
const lottery = new Lottery(this.connection, false, this.program);
|
|
835
837
|
const network = new LotteryNetwork(this.connection);
|
|
836
838
|
async function initializeData(tketPrice, lotId) {
|
|
@@ -858,10 +860,11 @@ class LotteryManager {
|
|
|
858
860
|
_tx_.instructions = [ix]; // array : required
|
|
859
861
|
_tx_.signers = false; // array : default false
|
|
860
862
|
_tx_.table = false; // array : default false
|
|
861
|
-
_tx_.tolerance =
|
|
863
|
+
_tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
|
|
862
864
|
_tx_.compute = true; // bool : default true
|
|
863
865
|
_tx_.fees = true; // bool : default true
|
|
864
|
-
_tx_.priority =
|
|
866
|
+
_tx_.priority = options.priority ?? this.priority ?? "Low";
|
|
867
|
+
|
|
865
868
|
if(encoded){
|
|
866
869
|
_tx_.serialize = true;
|
|
867
870
|
_tx_.encode = true;
|
|
@@ -886,7 +889,7 @@ class LotteryManager {
|
|
|
886
889
|
* @param {String} lotteryId - The lottery id
|
|
887
890
|
* @param {Boolean} encoded - true returns encoded transaction
|
|
888
891
|
*/
|
|
889
|
-
async RandomDraw(authority, lotteryId, encoded = false) {
|
|
892
|
+
async RandomDraw(authority, lotteryId, encoded = false, options = {}) {
|
|
890
893
|
try{
|
|
891
894
|
async function randomnessData() {
|
|
892
895
|
const buffer = Buffer.alloc(1);
|
|
@@ -909,10 +912,11 @@ class LotteryManager {
|
|
|
909
912
|
_tx_.instructions = [ix]; // array : required
|
|
910
913
|
_tx_.signers = false; // array : default false
|
|
911
914
|
_tx_.table = false; // array : default false
|
|
912
|
-
_tx_.tolerance =
|
|
915
|
+
_tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
|
|
913
916
|
_tx_.compute = true; // bool : default true
|
|
914
917
|
_tx_.fees = true; // bool : default true
|
|
915
|
-
_tx_.priority =
|
|
918
|
+
_tx_.priority = options.priority ?? this.priority ?? "Low";
|
|
919
|
+
|
|
916
920
|
_tx_.memo = "draw";
|
|
917
921
|
if(encoded){
|
|
918
922
|
_tx_.serialize = true;
|
|
@@ -947,7 +951,7 @@ class LotteryManager {
|
|
|
947
951
|
* @param {Number} lockState - 0 = lock ticket sales, 1 = unlock (requires authority)
|
|
948
952
|
* @param {Boolean} encoded - true returns encoded transaction
|
|
949
953
|
*/
|
|
950
|
-
async LockLottery(authority, lotteryId, lockState, encoded = false) {
|
|
954
|
+
async LockLottery(authority, lotteryId, lockState, encoded = false, options = {}) {
|
|
951
955
|
try{
|
|
952
956
|
async function lockData(lock) {
|
|
953
957
|
const buffer = Buffer.alloc(2); // 1 byte discriminator + 1 bytes lock status
|
|
@@ -968,10 +972,11 @@ class LotteryManager {
|
|
|
968
972
|
_tx_.instructions = [ix]; // array : required
|
|
969
973
|
_tx_.signers = false; // array : default false
|
|
970
974
|
_tx_.table = false; // array : default false
|
|
971
|
-
_tx_.tolerance =
|
|
975
|
+
_tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
|
|
972
976
|
_tx_.compute = true; // bool : default true
|
|
973
977
|
_tx_.fees = true; // bool : default true
|
|
974
|
-
_tx_.priority =
|
|
978
|
+
_tx_.priority = options.priority ?? this.priority ?? "Low";
|
|
979
|
+
|
|
975
980
|
_tx_.memo = false;
|
|
976
981
|
if(encoded){
|
|
977
982
|
_tx_.serialize = true;
|
|
@@ -1005,7 +1010,7 @@ class LotteryManager {
|
|
|
1005
1010
|
* @param {String} lotteryId - The lottery id
|
|
1006
1011
|
* @param {Boolean} encoded - true returns encoded transaction
|
|
1007
1012
|
*/
|
|
1008
|
-
async ClaimExpired(authority, lotteryId, encoded = false) {
|
|
1013
|
+
async ClaimExpired(authority, lotteryId, encoded = false, options = {}) {
|
|
1009
1014
|
try{
|
|
1010
1015
|
async function expiredData() {
|
|
1011
1016
|
const buffer = Buffer.alloc(1); // 1 byte discriminator + 1 bytes lock status
|
|
@@ -1027,10 +1032,11 @@ class LotteryManager {
|
|
|
1027
1032
|
_tx_.instructions = [ix]; // array : required
|
|
1028
1033
|
_tx_.signers = false; // array : default false
|
|
1029
1034
|
_tx_.table = false; // array : default false
|
|
1030
|
-
_tx_.tolerance =
|
|
1035
|
+
_tx_.tolerance = options.tolerance ?? this.tolerance ?? 1.2;
|
|
1031
1036
|
_tx_.compute = true; // bool : default true
|
|
1032
1037
|
_tx_.fees = true; // bool : default true
|
|
1033
|
-
_tx_.priority =
|
|
1038
|
+
_tx_.priority = options.priority ?? this.priority ?? "Low";
|
|
1039
|
+
|
|
1034
1040
|
_tx_.memo = false;
|
|
1035
1041
|
if(encoded){
|
|
1036
1042
|
_tx_.serialize = true;
|