@zebec-network/zebec-stake-sdk 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.
@@ -61,7 +61,20 @@ export type ZebecStake = {
61
61
  seeds: [
62
62
  {
63
63
  kind: "const";
64
- value: [114, 101, 119, 97, 114, 100, 95, 118, 97, 117, 108, 116];
64
+ value: [
65
+ 114,
66
+ 101,
67
+ 119,
68
+ 97,
69
+ 114,
70
+ 100,
71
+ 95,
72
+ 118,
73
+ 97,
74
+ 117,
75
+ 108,
76
+ 116
77
+ ];
65
78
  },
66
79
  {
67
80
  kind: "account";
@@ -650,7 +663,20 @@ export type ZebecStake = {
650
663
  seeds: [
651
664
  {
652
665
  kind: "const";
653
- value: [114, 101, 119, 97, 114, 100, 95, 118, 97, 117, 108, 116];
666
+ value: [
667
+ 114,
668
+ 101,
669
+ 119,
670
+ 97,
671
+ 114,
672
+ 100,
673
+ 95,
674
+ 118,
675
+ 97,
676
+ 117,
677
+ 108,
678
+ 116
679
+ ];
654
680
  },
655
681
  {
656
682
  kind: "account";
@@ -23,7 +23,9 @@
23
23
  "seeds": [
24
24
  {
25
25
  "kind": "const",
26
- "value": [122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112]
26
+ "value": [
27
+ 122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112
28
+ ]
27
29
  },
28
30
  {
29
31
  "kind": "arg",
@@ -55,7 +57,9 @@
55
57
  "seeds": [
56
58
  {
57
59
  "kind": "const",
58
- "value": [114, 101, 119, 97, 114, 100, 95, 118, 97, 117, 108, 116]
60
+ "value": [
61
+ 114, 101, 119, 97, 114, 100, 95, 118, 97, 117, 108, 116
62
+ ]
59
63
  },
60
64
  {
61
65
  "kind": "account",
@@ -115,7 +119,9 @@
115
119
  "seeds": [
116
120
  {
117
121
  "kind": "const",
118
- "value": [122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112]
122
+ "value": [
123
+ 122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112
124
+ ]
119
125
  },
120
126
  {
121
127
  "kind": "account",
@@ -176,8 +182,9 @@
176
182
  {
177
183
  "kind": "const",
178
184
  "value": [
179
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95,
180
- 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169
185
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
186
+ 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
187
+ 245, 133, 126, 255, 0, 169
181
188
  ]
182
189
  },
183
190
  {
@@ -188,8 +195,9 @@
188
195
  "program": {
189
196
  "kind": "const",
190
197
  "value": [
191
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16,
192
- 132, 4, 142, 123, 216, 219, 233, 248, 89
198
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
199
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
200
+ 219, 233, 248, 89
193
201
  ]
194
202
  }
195
203
  }
@@ -222,8 +230,9 @@
222
230
  {
223
231
  "kind": "const",
224
232
  "value": [
225
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95,
226
- 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169
233
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
234
+ 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
235
+ 245, 133, 126, 255, 0, 169
227
236
  ]
228
237
  },
229
238
  {
@@ -234,8 +243,9 @@
234
243
  "program": {
235
244
  "kind": "const",
236
245
  "value": [
237
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16,
238
- 132, 4, 142, 123, 216, 219, 233, 248, 89
246
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
247
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
248
+ 219, 233, 248, 89
239
249
  ]
240
250
  }
241
251
  }
@@ -285,7 +295,9 @@
285
295
  "seeds": [
286
296
  {
287
297
  "kind": "const",
288
- "value": [122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112]
298
+ "value": [
299
+ 122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112
300
+ ]
289
301
  },
290
302
  {
291
303
  "kind": "account",
@@ -333,8 +345,9 @@
333
345
  {
334
346
  "kind": "const",
335
347
  "value": [
336
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95,
337
- 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169
348
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
349
+ 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
350
+ 245, 133, 126, 255, 0, 169
338
351
  ]
339
352
  },
340
353
  {
@@ -345,8 +358,9 @@
345
358
  "program": {
346
359
  "kind": "const",
347
360
  "value": [
348
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16,
349
- 132, 4, 142, 123, 216, 219, 233, 248, 89
361
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
362
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
363
+ 219, 233, 248, 89
350
364
  ]
351
365
  }
352
366
  }
@@ -363,8 +377,9 @@
363
377
  {
364
378
  "kind": "const",
365
379
  "value": [
366
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95,
367
- 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169
380
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
381
+ 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
382
+ 245, 133, 126, 255, 0, 169
368
383
  ]
369
384
  },
370
385
  {
@@ -375,8 +390,9 @@
375
390
  "program": {
376
391
  "kind": "const",
377
392
  "value": [
378
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16,
379
- 132, 4, 142, 123, 216, 219, 233, 248, 89
393
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
394
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
395
+ 219, 233, 248, 89
380
396
  ]
381
397
  }
382
398
  }
@@ -404,7 +420,9 @@
404
420
  "seeds": [
405
421
  {
406
422
  "kind": "const",
407
- "value": [114, 101, 119, 97, 114, 100, 95, 118, 97, 117, 108, 116]
423
+ "value": [
424
+ 114, 101, 119, 97, 114, 100, 95, 118, 97, 117, 108, 116
425
+ ]
408
426
  },
409
427
  {
410
428
  "kind": "account",
@@ -425,8 +443,9 @@
425
443
  {
426
444
  "kind": "const",
427
445
  "value": [
428
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95,
429
- 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169
446
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
447
+ 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
448
+ 245, 133, 126, 255, 0, 169
430
449
  ]
431
450
  },
432
451
  {
@@ -437,8 +456,9 @@
437
456
  "program": {
438
457
  "kind": "const",
439
458
  "value": [
440
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16,
441
- 132, 4, 142, 123, 216, 219, 233, 248, 89
459
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
460
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
461
+ 219, 233, 248, 89
442
462
  ]
443
463
  }
444
464
  }
@@ -455,8 +475,9 @@
455
475
  {
456
476
  "kind": "const",
457
477
  "value": [
458
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95,
459
- 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169
478
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
479
+ 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
480
+ 245, 133, 126, 255, 0, 169
460
481
  ]
461
482
  },
462
483
  {
@@ -467,8 +488,9 @@
467
488
  "program": {
468
489
  "kind": "const",
469
490
  "value": [
470
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16,
471
- 132, 4, 142, 123, 216, 219, 233, 248, 89
491
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
492
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
493
+ 219, 233, 248, 89
472
494
  ]
473
495
  }
474
496
  }
@@ -489,8 +511,9 @@
489
511
  {
490
512
  "kind": "const",
491
513
  "value": [
492
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95,
493
- 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169
514
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
515
+ 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
516
+ 245, 133, 126, 255, 0, 169
494
517
  ]
495
518
  },
496
519
  {
@@ -501,8 +524,9 @@
501
524
  "program": {
502
525
  "kind": "const",
503
526
  "value": [
504
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16,
505
- 132, 4, 142, 123, 216, 219, 233, 248, 89
527
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
528
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
529
+ 219, 233, 248, 89
506
530
  ]
507
531
  }
508
532
  }
@@ -543,7 +567,9 @@
543
567
  "seeds": [
544
568
  {
545
569
  "kind": "const",
546
- "value": [122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112]
570
+ "value": [
571
+ 122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112
572
+ ]
547
573
  },
548
574
  {
549
575
  "kind": "account",
@@ -581,7 +607,9 @@
581
607
  "seeds": [
582
608
  {
583
609
  "kind": "const",
584
- "value": [122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112]
610
+ "value": [
611
+ 122, 101, 98, 101, 99, 95, 108, 111, 99, 107, 117, 112
612
+ ]
585
613
  },
586
614
  {
587
615
  "kind": "account",
@@ -7,3 +7,4 @@ export declare const ZEBEC_STAKE_PROGRAM: {
7
7
  /** Devnet Program Id */
8
8
  devnet: string;
9
9
  };
10
+ export declare const STAKE_LOOKUP_TABLE_ADDRESS: Record<"mainnet-beta" | "devnet", string>;
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZEBEC_STAKE_PROGRAM = void 0;
3
+ exports.STAKE_LOOKUP_TABLE_ADDRESS = exports.ZEBEC_STAKE_PROGRAM = void 0;
4
4
  /**
5
5
  * Zebec Card Program Ids
6
6
  */
@@ -10,3 +10,7 @@ exports.ZEBEC_STAKE_PROGRAM = {
10
10
  /** Devnet Program Id */
11
11
  devnet: "zSTKzGLiN6T6EVzhBiL6sjULXMahDavAS2p4R62afGv",
12
12
  };
13
+ exports.STAKE_LOOKUP_TABLE_ADDRESS = {
14
+ "mainnet-beta": "EoKjJejKr4XsBdtUuYwzZcYd6tpGNijxCGgQocxtxQ8t",
15
+ devnet: "C4R2sL6yj7bzKfbdfwCfH68DZZ3QnzdmedE9wQqTfAAA",
16
+ };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./constants";
2
1
  export * from "./artifacts";
3
- export * from "./service";
4
- export * from "./providers";
2
+ export * from "./constants";
5
3
  export * from "./pda";
4
+ export * from "./providers";
6
5
  export * from "./rateLimitQueue";
6
+ export * from "./service";
package/dist/index.js CHANGED
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants"), exports);
18
17
  __exportStar(require("./artifacts"), exports);
19
- __exportStar(require("./service"), exports);
20
- __exportStar(require("./providers"), exports);
18
+ __exportStar(require("./constants"), exports);
21
19
  __exportStar(require("./pda"), exports);
20
+ __exportStar(require("./providers"), exports);
22
21
  __exportStar(require("./rateLimitQueue"), exports);
22
+ __exportStar(require("./service"), exports);
package/dist/pda.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Address } from "@coral-xyz/anchor";
1
+ import { type Address } from "@coral-xyz/anchor";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  export declare function deriveStakeAddress(staker: Address, lockup: Address, nonce: bigint, programId?: Address): PublicKey;
4
4
  export declare function deriveLockupAddress(name: string, programId?: Address): PublicKey;
package/dist/pda.js CHANGED
@@ -30,10 +30,16 @@ function deriveUserNonceAddress(user, lockup, programId = constants_1.ZEBEC_STAK
30
30
  return userNonceAddress;
31
31
  }
32
32
  function deriveStakeVaultAddress(lockup, programId = constants_1.ZEBEC_STAKE_PROGRAM.mainnet) {
33
- const [stakeVault] = web3_js_1.PublicKey.findProgramAddressSync([anchor_1.utils.bytes.utf8.encode(SEEDS.stakeVault), (0, anchor_1.translateAddress)(lockup).toBuffer()], (0, anchor_1.translateAddress)(programId));
33
+ const [stakeVault] = web3_js_1.PublicKey.findProgramAddressSync([
34
+ anchor_1.utils.bytes.utf8.encode(SEEDS.stakeVault),
35
+ (0, anchor_1.translateAddress)(lockup).toBuffer(),
36
+ ], (0, anchor_1.translateAddress)(programId));
34
37
  return stakeVault;
35
38
  }
36
39
  function deriveRewardVaultAddress(lockup, programId = constants_1.ZEBEC_STAKE_PROGRAM.mainnet) {
37
- const [rewardVault] = web3_js_1.PublicKey.findProgramAddressSync([anchor_1.utils.bytes.utf8.encode(SEEDS.rewardVault), (0, anchor_1.translateAddress)(lockup).toBuffer()], (0, anchor_1.translateAddress)(programId));
40
+ const [rewardVault] = web3_js_1.PublicKey.findProgramAddressSync([
41
+ anchor_1.utils.bytes.utf8.encode(SEEDS.rewardVault),
42
+ (0, anchor_1.translateAddress)(lockup).toBuffer(),
43
+ ], (0, anchor_1.translateAddress)(programId));
38
44
  return rewardVault;
39
45
  }
@@ -1,5 +1,5 @@
1
- import { Address, AnchorProvider } from "@coral-xyz/anchor";
2
- import { ConfirmOptions, Connection, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
1
+ import { type Address, AnchorProvider } from "@coral-xyz/anchor";
2
+ import type { ConfirmOptions, Connection, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
3
3
  export declare class ReadonlyProvider {
4
4
  readonly connection: Connection;
5
5
  readonly walletAddress?: PublicKey;
package/dist/providers.js CHANGED
@@ -9,7 +9,9 @@ class ReadonlyProvider {
9
9
  walletAddress;
10
10
  constructor(connection, walletAddress) {
11
11
  this.connection = connection;
12
- this.walletAddress = walletAddress ? (0, anchor_1.translateAddress)(walletAddress) : undefined;
12
+ this.walletAddress = walletAddress
13
+ ? (0, anchor_1.translateAddress)(walletAddress)
14
+ : undefined;
13
15
  }
14
16
  }
15
17
  exports.ReadonlyProvider = ReadonlyProvider;
package/dist/service.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { Address, AnchorProvider, BN, Program, Provider } from "@coral-xyz/anchor";
2
- import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
1
+ import { type Address, AnchorProvider, BN, Program, type Provider } from "@coral-xyz/anchor";
2
+ import { Connection, type PublicKey, type TransactionInstruction } from "@solana/web3.js";
3
3
  import { TransactionPayload } from "@zebec-network/solana-common";
4
- import { ZebecStakeIdlV1 } from "./artifacts";
5
- import { ReadonlyProvider } from "./providers";
4
+ import { type ZebecStakeIdlV1 } from "./artifacts";
5
+ import { type ReadonlyProvider } from "./providers";
6
+ import type { InitLockupInstructionData, LockupInfo, Numeric, RewardScheme, StakeInfo, StakeInfoWithHash, StakeInstructionData, UpdateLockupInstructionData, UserNonceInfo } from "./types";
6
7
  type ProgramCreateFunction = (provider: ReadonlyProvider | AnchorProvider) => Program<ZebecStakeIdlV1>;
7
8
  /**
8
9
  * StakeServiceBuilder is a builder class for creating a StakeService instance.
@@ -92,69 +93,4 @@ export declare class StakeService {
92
93
  get programId(): PublicKey;
93
94
  get connection(): Connection;
94
95
  }
95
- export type InitLockupInstructionData = {
96
- rewardSchemes: ParsedRewardScheme[];
97
- fee: BN;
98
- feeVault: PublicKey;
99
- name: string;
100
- minimumStake: BN;
101
- };
102
- export type UpdateLockupInstructionData = {
103
- rewardSchemes: ParsedRewardScheme[];
104
- fee: BN;
105
- feeVault: PublicKey;
106
- minimumStake: BN;
107
- };
108
- export type ParsedRewardScheme = {
109
- duration: BN;
110
- reward: BN;
111
- };
112
- type Numeric = string | number;
113
- export type RewardScheme = {
114
- duration: number;
115
- rewardRate: Numeric;
116
- };
117
- export type StakeInstructionData = {
118
- amount: BN;
119
- lockPeriod: BN;
120
- nonce: BN;
121
- };
122
- export type LockupInfo = {
123
- address: string;
124
- feeInfo: {
125
- fee: string;
126
- feeVault: string;
127
- };
128
- rewardToken: {
129
- tokenAddress: string;
130
- };
131
- stakeToken: {
132
- tokenAdress: string;
133
- totalStaked: string;
134
- };
135
- stakeInfo: {
136
- name: string;
137
- creator: string;
138
- rewardSchemes: RewardScheme[];
139
- minimumStake: string;
140
- };
141
- };
142
- export type StakeInfo = {
143
- address: string;
144
- nonce: bigint;
145
- createdTime: number;
146
- stakedAmount: string;
147
- rewardAmount: string;
148
- stakeClaimed: boolean;
149
- lockPeriod: number;
150
- staker: string;
151
- lockup: string;
152
- };
153
- export type UserNonceInfo = {
154
- address: string;
155
- nonce: bigint;
156
- };
157
- export type StakeInfoWithHash = StakeInfo & {
158
- hash: string;
159
- };
160
96
  export {};
package/dist/service.js CHANGED
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.StakeService = exports.StakeServiceBuilder = void 0;
7
- const assert_1 = __importDefault(require("assert"));
8
- const bignumber_js_1 = require("bignumber.js");
9
7
  const anchor_1 = require("@coral-xyz/anchor");
10
8
  const web3_js_1 = require("@solana/web3.js");
11
9
  const core_utils_1 = require("@zebec-network/core-utils");
12
10
  const solana_common_1 = require("@zebec-network/solana-common");
11
+ const assert_1 = __importDefault(require("assert"));
12
+ const bignumber_js_1 = require("bignumber.js");
13
13
  const artifacts_1 = require("./artifacts");
14
14
  const pda_1 = require("./pda");
15
15
  const providers_1 = require("./providers");
@@ -89,7 +89,9 @@ class StakeServiceBuilder {
89
89
  if (!this._provider) {
90
90
  throw new Error("InvalidOperation: Provider is not set. Please set the provider before setting the program.");
91
91
  }
92
- this._program = !createProgram ? new anchor_1.Program(artifacts_1.ZEBEC_STAKE_IDL_V1, this._provider) : createProgram(this._provider);
92
+ this._program = !createProgram
93
+ ? new anchor_1.Program(artifacts_1.ZEBEC_STAKE_IDL_V1, this._provider)
94
+ : createProgram(this._provider);
93
95
  return this;
94
96
  }
95
97
  build() {
@@ -117,8 +119,8 @@ class StakeService {
117
119
  }
118
120
  async _createPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
119
121
  const errorMap = new Map();
120
- this.program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
121
- let signTransaction = undefined;
122
+ this.program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
123
+ let signTransaction;
122
124
  const provider = this.provider;
123
125
  if (provider instanceof anchor_1.AnchorProvider) {
124
126
  signTransaction = async (tx) => {
@@ -193,7 +195,9 @@ class StakeService {
193
195
  .instruction();
194
196
  }
195
197
  async initLockup(params) {
196
- const creator = params.creator ? (0, anchor_1.translateAddress)(params.creator) : this.provider.publicKey;
198
+ const creator = params.creator
199
+ ? (0, anchor_1.translateAddress)(params.creator)
200
+ : this.provider.publicKey;
197
201
  if (!creator) {
198
202
  throw new Error("MissingArgument: Please provide either creator address or publicKey in provider");
199
203
  }
@@ -223,7 +227,9 @@ class StakeService {
223
227
  return this._createPayload(creator, [instruction]);
224
228
  }
225
229
  async updateLockup(params) {
226
- const updater = params.updater ? (0, anchor_1.translateAddress)(params.updater) : this.provider.publicKey;
230
+ const updater = params.updater
231
+ ? (0, anchor_1.translateAddress)(params.updater)
232
+ : this.provider.publicKey;
227
233
  if (!updater) {
228
234
  throw new Error("MissingArgument: Please provide either updater address or publicKey in provider");
229
235
  }
@@ -250,19 +256,23 @@ class StakeService {
250
256
  return this._createPayload(updater, [instruction]);
251
257
  }
252
258
  async stake(params) {
253
- const staker = params.staker ? (0, anchor_1.translateAddress)(params.staker) : this.provider.publicKey;
259
+ const staker = params.staker
260
+ ? (0, anchor_1.translateAddress)(params.staker)
261
+ : this.provider.publicKey;
254
262
  if (!staker) {
255
263
  throw new Error("MissingArgument: Please provide either staker address or publicKey in provider");
256
264
  }
257
- const feePayer = params.feePayer ? (0, anchor_1.translateAddress)(params.feePayer) : staker;
265
+ const feePayer = params.feePayer
266
+ ? (0, anchor_1.translateAddress)(params.feePayer)
267
+ : staker;
258
268
  const lockup = (0, pda_1.deriveLockupAddress)(params.lockupName, this.programId);
259
269
  const lockupAccount = await this.program.account.lockup.fetchNullable(lockup, this.connection.commitment);
260
270
  if (!lockupAccount) {
261
- throw new Error("Lockup account does not exists for address: " + lockup);
271
+ throw new Error(`Lockup account does not exists for address: ${lockup}`);
262
272
  }
263
273
  const lockPeriods = lockupAccount.stakeInfo.durationMap.map((item) => item.duration.toNumber());
264
274
  if (!lockPeriods.includes(params.lockPeriod)) {
265
- throw new Error("Invalid lockperiod. Available options are: " + lockPeriods.map((l) => l.toString()).concat(", "));
275
+ throw new Error(`Invalid lockperiod. Available options are: ${lockPeriods.map((l) => l.toString()).join(", ")}`);
266
276
  }
267
277
  const stakeToken = lockupAccount.stakedToken.tokenAddress;
268
278
  const stakeVault = (0, pda_1.deriveStakeVaultAddress)(lockup, this.programId);
@@ -284,11 +294,15 @@ class StakeService {
284
294
  return this._createPayload(feePayer, [instruction]);
285
295
  }
286
296
  async unstake(params) {
287
- const staker = params.staker ? (0, anchor_1.translateAddress)(params.staker) : this.provider.publicKey;
297
+ const staker = params.staker
298
+ ? (0, anchor_1.translateAddress)(params.staker)
299
+ : this.provider.publicKey;
288
300
  if (!staker) {
289
301
  throw new Error("MissingArgument: Please provide either staker address or publicKey in provider");
290
302
  }
291
- const feePayer = params.feePayer ? (0, anchor_1.translateAddress)(params.feePayer) : staker;
303
+ const feePayer = params.feePayer
304
+ ? (0, anchor_1.translateAddress)(params.feePayer)
305
+ : staker;
292
306
  const lockup = (0, pda_1.deriveLockupAddress)(params.lockupName, this.programId);
293
307
  const lockupAccount = await this.program.account.lockup.fetchNullable(lockup, this.connection.commitment);
294
308
  if (!lockupAccount) {
@@ -315,7 +329,9 @@ class StakeService {
315
329
  return {
316
330
  address: lockupAddress.toString(),
317
331
  feeInfo: {
318
- fee: (0, bignumber_js_1.BigNumber)(lockupAccount.feeInfo.fee.toString()).div(UNITS_PER_STAKE_TOKEN).toFixed(),
332
+ fee: (0, bignumber_js_1.BigNumber)(lockupAccount.feeInfo.fee.toString())
333
+ .div(UNITS_PER_STAKE_TOKEN)
334
+ .toFixed(),
319
335
  feeVault: lockupAccount.feeInfo.feeVault.toString(),
320
336
  },
321
337
  rewardToken: {
@@ -323,7 +339,9 @@ class StakeService {
323
339
  },
324
340
  stakeToken: {
325
341
  tokenAdress: lockupAccount.stakedToken.tokenAddress.toString(),
326
- totalStaked: (0, bignumber_js_1.BigNumber)(lockupAccount.stakedToken.totalStaked.toString()).div(UNITS_PER_STAKE_TOKEN).toFixed(),
342
+ totalStaked: (0, bignumber_js_1.BigNumber)(lockupAccount.stakedToken.totalStaked.toString())
343
+ .div(UNITS_PER_STAKE_TOKEN)
344
+ .toFixed(),
327
345
  },
328
346
  stakeInfo: {
329
347
  name: lockupAccount.stakeInfo.name,
@@ -332,7 +350,9 @@ class StakeService {
332
350
  duration: value.duration.toNumber(),
333
351
  rewardRate: (0, core_utils_1.bpsToPercent)(value.reward.toString()),
334
352
  })),
335
- minimumStake: (0, bignumber_js_1.BigNumber)(lockupAccount.stakeInfo.minimumStake.toString()).div(UNITS_PER_STAKE_TOKEN).toFixed(),
353
+ minimumStake: (0, bignumber_js_1.BigNumber)(lockupAccount.stakeInfo.minimumStake.toString())
354
+ .div(UNITS_PER_STAKE_TOKEN)
355
+ .toFixed(),
336
356
  },
337
357
  };
338
358
  }
@@ -355,8 +375,12 @@ class StakeService {
355
375
  address: stakeAddress.toString(),
356
376
  nonce: BigInt(stakeAccount.nonce.toString()),
357
377
  createdTime: stakeAccount.createdTime.toNumber(),
358
- stakedAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.stakedAmount.toString()).div(UNITS_PER_STAKE_TOKEN).toFixed(),
359
- rewardAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.rewardAmount.toString()).div(UNITS_PER_REWARD_TOKEN).toFixed(),
378
+ stakedAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.stakedAmount.toString())
379
+ .div(UNITS_PER_STAKE_TOKEN)
380
+ .toFixed(),
381
+ rewardAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.rewardAmount.toString())
382
+ .div(UNITS_PER_REWARD_TOKEN)
383
+ .toFixed(),
360
384
  stakeClaimed: stakeAccount.stakeClaimed,
361
385
  lockPeriod: stakeAccount.lockPeriod.toNumber(),
362
386
  lockup: stakeAccount.lockup.toString(),
@@ -393,20 +417,27 @@ class StakeService {
393
417
  const nonces = Array.from({ length: currentNonce }, (_, i) => BigInt(i));
394
418
  const stakeAddresses = nonces.map((nonce) => (0, pda_1.deriveStakeAddress)(userAdress, lockupAddress, nonce, this.programId));
395
419
  const stakeAddressesChunks = (0, utils_1.chunkArray)(stakeAddresses, 100);
396
- let stakeWithHash2D = [];
420
+ const stakeWithHash2D = [];
397
421
  for (const stakeAddresses of stakeAddressesChunks) {
398
422
  const accountInfos = await this.connection.getMultipleAccountsInfo(stakeAddresses, {
399
423
  commitment: this.connection.commitment,
400
424
  });
401
425
  const stakeAccountsInfo = accountInfos.map((value, i) => {
402
- (0, assert_1.default)(value, "Account does not exists for stake address: " + stakeAddresses[i] + " at nonce: " + nonces[i]);
426
+ (0, assert_1.default)(value, "Account does not exists for stake address: " +
427
+ stakeAddresses[i] +
428
+ " at nonce: " +
429
+ nonces[i]);
403
430
  const stakeAccount = this.program.coder.accounts.decode(this.program.idl.accounts[2].name, value.data);
404
431
  const info = {
405
432
  address: stakeAddresses[i].toString(),
406
433
  nonce: BigInt(stakeAccount.nonce.toString()),
407
434
  createdTime: stakeAccount.createdTime.toNumber(),
408
- stakedAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.stakedAmount.toString()).div(UNITS_PER_STAKE_TOKEN).toFixed(),
409
- rewardAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.rewardAmount.toString()).div(UNITS_PER_REWARD_TOKEN).toFixed(),
435
+ stakedAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.stakedAmount.toString())
436
+ .div(UNITS_PER_STAKE_TOKEN)
437
+ .toFixed(),
438
+ rewardAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.rewardAmount.toString())
439
+ .div(UNITS_PER_REWARD_TOKEN)
440
+ .toFixed(),
410
441
  stakeClaimed: stakeAccount.stakeClaimed,
411
442
  lockPeriod: stakeAccount.lockPeriod.toNumber(),
412
443
  lockup: stakeAccount.lockup.toString(),
@@ -414,7 +445,7 @@ class StakeService {
414
445
  };
415
446
  return info;
416
447
  });
417
- let stakesWithHash = new Array(stakeAccountsInfo.length);
448
+ const stakesWithHash = new Array(stakeAccountsInfo.length);
418
449
  const { maxConcurrent = 3, minDelayMs = 400 } = options;
419
450
  const queue = new rateLimitQueue_1.RateLimitedQueue(maxConcurrent, minDelayMs); // Max 3 concurrent, 300ms between requests
420
451
  const promises = stakeAccountsInfo.map((stakeInfo, index) => queue.add(async () => {
@@ -492,8 +523,12 @@ class StakeService {
492
523
  address: accountInfo.pubkey.toString(),
493
524
  nonce: BigInt(stakeAccount.nonce.toString()),
494
525
  createdTime: stakeAccount.createdTime.toNumber(),
495
- stakedAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.stakedAmount.toString()).div(UNITS_PER_STAKE_TOKEN).toFixed(),
496
- rewardAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.rewardAmount.toString()).div(UNITS_PER_REWARD_TOKEN).toFixed(),
526
+ stakedAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.stakedAmount.toString())
527
+ .div(UNITS_PER_STAKE_TOKEN)
528
+ .toFixed(),
529
+ rewardAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.rewardAmount.toString())
530
+ .div(UNITS_PER_REWARD_TOKEN)
531
+ .toFixed(),
497
532
  stakeClaimed: stakeAccount.stakeClaimed,
498
533
  lockPeriod: stakeAccount.lockPeriod.toNumber(),
499
534
  lockup: stakeAccount.lockup.toString(),
@@ -0,0 +1,67 @@
1
+ import type { PublicKey } from "@solana/web3.js";
2
+ import type BN from "bn.js";
3
+ export type InitLockupInstructionData = {
4
+ rewardSchemes: ParsedRewardScheme[];
5
+ fee: BN;
6
+ feeVault: PublicKey;
7
+ name: string;
8
+ minimumStake: BN;
9
+ };
10
+ export type UpdateLockupInstructionData = {
11
+ rewardSchemes: ParsedRewardScheme[];
12
+ fee: BN;
13
+ feeVault: PublicKey;
14
+ minimumStake: BN;
15
+ };
16
+ export type ParsedRewardScheme = {
17
+ duration: BN;
18
+ reward: BN;
19
+ };
20
+ export type Numeric = string | number;
21
+ export type RewardScheme = {
22
+ duration: number;
23
+ rewardRate: Numeric;
24
+ };
25
+ export type StakeInstructionData = {
26
+ amount: BN;
27
+ lockPeriod: BN;
28
+ nonce: BN;
29
+ };
30
+ export type LockupInfo = {
31
+ address: string;
32
+ feeInfo: {
33
+ fee: string;
34
+ feeVault: string;
35
+ };
36
+ rewardToken: {
37
+ tokenAddress: string;
38
+ };
39
+ stakeToken: {
40
+ tokenAdress: string;
41
+ totalStaked: string;
42
+ };
43
+ stakeInfo: {
44
+ name: string;
45
+ creator: string;
46
+ rewardSchemes: RewardScheme[];
47
+ minimumStake: string;
48
+ };
49
+ };
50
+ export type StakeInfo = {
51
+ address: string;
52
+ nonce: bigint;
53
+ createdTime: number;
54
+ stakedAmount: string;
55
+ rewardAmount: string;
56
+ stakeClaimed: boolean;
57
+ lockPeriod: number;
58
+ staker: string;
59
+ lockup: string;
60
+ };
61
+ export type UserNonceInfo = {
62
+ address: string;
63
+ nonce: bigint;
64
+ };
65
+ export type StakeInfoWithHash = StakeInfo & {
66
+ hash: string;
67
+ };
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/utils.js CHANGED
@@ -17,9 +17,11 @@ async function callWithEnhancedBackoff(fn, maxRetries = MAX_RETRIES, backoffFact
17
17
  catch (error) {
18
18
  if (attempt === maxRetries)
19
19
  throw error;
20
- let delay = Math.min(baseDelay * Math.pow(backoffFactor, attempt), maxDelay);
20
+ let delay = Math.min(baseDelay * backoffFactor ** attempt, maxDelay);
21
21
  // Handle 429 specifically with longer delays
22
- if (error?.status === 429 || error?.code === 429 || error?.message?.includes("429")) {
22
+ if (error?.status === 429 ||
23
+ error?.code === 429 ||
24
+ error?.message?.includes("429")) {
23
25
  delay = Math.min(delay * backoffFactor, maxDelay); // Double delay for rate limits
24
26
  console.warn(`Rate limit hit, waiting ${delay}ms before retry ${attempt + 1}/${maxRetries}`);
25
27
  }
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
- {
2
- "name": "@zebec-network/zebec-stake-sdk",
3
- "version": "1.2.2",
4
- "description": "An SDK for zebec network stake solana program",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "author": "Zebec Network | Ashish Sapkota",
8
- "license": "MIT",
9
- "files": [
10
- "dist"
11
- ],
12
- "keywords": [
13
- "solana",
14
- "zebec",
15
- "zebec network",
16
- "stake",
17
- "staking"
18
- ],
19
- "scripts": {
20
- "build": "npm run clean && tsc",
21
- "clean": "rimraf ./dist",
22
- "format": "prettier --write .",
23
- "start": "ts-node src/index.ts",
24
- "test": "ts-mocha -p ./tsconfig.json -t 1000000000 test/**/*.test.ts",
25
- "test:single": "ts-mocha -p ./tsconfig.json -t 1000000000"
26
- },
27
- "dependencies": {
28
- "@coral-xyz/anchor": "^0.31.1",
29
- "@solana/web3.js": "^1.98.2",
30
- "@zebec-network/core-utils": "^1.1.1",
31
- "@zebec-network/solana-common": "^2.3.1",
32
- "bignumber.js": "^9.3.1",
33
- "buffer": "^6.0.3"
34
- },
35
- "devDependencies": {
36
- "@types/bn.js": "^5.2.0",
37
- "@types/mocha": "^10.0.10",
38
- "@types/node": "^25.0.3",
39
- "dotenv": "^17.2.3",
40
- "mocha": "^11.7.5",
41
- "prettier": "^3.6.2",
42
- "rimraf": "^6.1.2",
43
- "ts-mocha": "^11.1.0",
44
- "ts-node": "^10.9.2",
45
- "typescript": "^5.9.2"
46
- }
1
+ {
2
+ "author": "Zebec Network | Ashish Sapkota",
3
+ "dependencies": {
4
+ "@coral-xyz/anchor": "^0.31.1",
5
+ "@solana/web3.js": "^1.98.2",
6
+ "@zebec-network/core-utils": "^1.1.1",
7
+ "@zebec-network/solana-common": "^2.3.1",
8
+ "bignumber.js": "^9.3.1",
9
+ "buffer": "^6.0.3"
10
+ },
11
+ "description": "An SDK for zebec network stake solana program",
12
+ "devDependencies": {
13
+ "@types/bn.js": "^5.2.0",
14
+ "@types/mocha": "^10.0.10",
15
+ "@types/node": "^25.0.3",
16
+ "dotenv": "^17.2.3",
17
+ "mocha": "^11.7.5",
18
+ "prettier": "^3.6.2",
19
+ "rimraf": "^6.1.2",
20
+ "ts-mocha": "^11.1.0",
21
+ "ts-node": "^10.9.2",
22
+ "typescript": "^5.9.2"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "keywords": [
28
+ "solana",
29
+ "zebec",
30
+ "zebec network",
31
+ "stake",
32
+ "staking"
33
+ ],
34
+ "license": "MIT",
35
+ "main": "dist/index.js",
36
+ "name": "@zebec-network/zebec-stake-sdk",
37
+ "scripts": {
38
+ "build": "npm run clean && tsc",
39
+ "clean": "rimraf ./dist",
40
+ "format": "npx @biomejs/biome format --write",
41
+ "start": "ts-node src/index.ts",
42
+ "test": "ts-mocha -p ./tsconfig.json -t 1000000000 test/**/*.test.ts",
43
+ "test:single": "ts-mocha -p ./tsconfig.json -t 1000000000"
44
+ },
45
+ "types": "dist/index.d.ts",
46
+ "version": "1.3.0"
47
47
  }