@streamflow/staking 7.0.0-alpha.9 → 7.0.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.
@@ -9,29 +9,16 @@
9
9
  "instructions": [
10
10
  {
11
11
  "name": "change_authority",
12
- "discriminator": [
13
- 50,
14
- 106,
15
- 66,
16
- 104,
17
- 99,
18
- 118,
19
- 145,
20
- 88
21
- ],
12
+ "discriminator": [50, 106, 66, 104, 99, 118, 145, 88],
22
13
  "accounts": [
23
14
  {
24
15
  "name": "stake_pool",
25
- "docs": [
26
- "Stake Pool"
27
- ],
16
+ "docs": ["Stake Pool"],
28
17
  "writable": true
29
18
  },
30
19
  {
31
20
  "name": "authority",
32
- "docs": [
33
- "Current Authority"
34
- ],
21
+ "docs": ["Current Authority"],
35
22
  "writable": true,
36
23
  "signer": true
37
24
  },
@@ -43,16 +30,7 @@
43
30
  },
44
31
  {
45
32
  "name": "create_pool",
46
- "discriminator": [
47
- 233,
48
- 146,
49
- 209,
50
- 142,
51
- 207,
52
- 104,
53
- 64,
54
- 188
55
- ],
33
+ "discriminator": [233, 146, 209, 142, 207, 104, 64, 188],
56
34
  "accounts": [
57
35
  {
58
36
  "name": "stake_pool",
@@ -61,18 +39,7 @@
61
39
  "seeds": [
62
40
  {
63
41
  "kind": "const",
64
- "value": [
65
- 115,
66
- 116,
67
- 97,
68
- 107,
69
- 101,
70
- 45,
71
- 112,
72
- 111,
73
- 111,
74
- 108
75
- ]
42
+ "value": [115, 116, 97, 107, 101, 45, 112, 111, 111, 108]
76
43
  },
77
44
  {
78
45
  "kind": "account",
@@ -91,9 +58,7 @@
91
58
  },
92
59
  {
93
60
  "name": "mint",
94
- "docs": [
95
- "Mint used for staking"
96
- ]
61
+ "docs": ["Mint used for staking"]
97
62
  },
98
63
  {
99
64
  "name": "vault",
@@ -102,19 +67,7 @@
102
67
  "seeds": [
103
68
  {
104
69
  "kind": "const",
105
- "value": [
106
- 115,
107
- 116,
108
- 97,
109
- 107,
110
- 101,
111
- 45,
112
- 118,
113
- 97,
114
- 117,
115
- 108,
116
- 116
117
- ]
70
+ "value": [115, 116, 97, 107, 101, 45, 118, 97, 117, 108, 116]
118
71
  },
119
72
  {
120
73
  "kind": "account",
@@ -130,18 +83,7 @@
130
83
  "seeds": [
131
84
  {
132
85
  "kind": "const",
133
- "value": [
134
- 115,
135
- 116,
136
- 97,
137
- 107,
138
- 101,
139
- 45,
140
- 109,
141
- 105,
142
- 110,
143
- 116
144
- ]
86
+ "value": [115, 116, 97, 107, 101, 45, 109, 105, 110, 116]
145
87
  },
146
88
  {
147
89
  "kind": "account",
@@ -152,9 +94,7 @@
152
94
  },
153
95
  {
154
96
  "name": "creator",
155
- "docs": [
156
- "Stake Pool creator"
157
- ],
97
+ "docs": ["Stake Pool creator"],
158
98
  "writable": true,
159
99
  "signer": true
160
100
  },
@@ -191,47 +131,22 @@
191
131
  },
192
132
  {
193
133
  "name": "stake",
194
- "discriminator": [
195
- 206,
196
- 176,
197
- 202,
198
- 18,
199
- 200,
200
- 209,
201
- 179,
202
- 108
203
- ],
134
+ "discriminator": [206, 176, 202, 18, 200, 209, 179, 108],
204
135
  "accounts": [
205
136
  {
206
137
  "name": "stake_pool",
207
- "docs": [
208
- "Stake Pool"
209
- ],
138
+ "docs": ["Stake Pool"],
210
139
  "writable": true
211
140
  },
212
141
  {
213
142
  "name": "stake_entry",
214
- "docs": [
215
- "Entry that will store Stake Metadata"
216
- ],
143
+ "docs": ["Entry that will store Stake Metadata"],
217
144
  "writable": true,
218
145
  "pda": {
219
146
  "seeds": [
220
147
  {
221
148
  "kind": "const",
222
- "value": [
223
- 115,
224
- 116,
225
- 97,
226
- 107,
227
- 101,
228
- 45,
229
- 101,
230
- 110,
231
- 116,
232
- 114,
233
- 121
234
- ]
149
+ "value": [115, 116, 97, 107, 101, 45, 101, 110, 116, 114, 121]
235
150
  },
236
151
  {
237
152
  "kind": "account",
@@ -250,33 +165,23 @@
250
165
  },
251
166
  {
252
167
  "name": "from",
253
- "docs": [
254
- "Token Account from which stake tokens will be transferred"
255
- ],
168
+ "docs": ["Token Account from which stake tokens will be transferred"],
256
169
  "writable": true
257
170
  },
258
171
  {
259
172
  "name": "vault",
260
- "docs": [
261
- "Stake Pool Vault that stores staked tokens"
262
- ],
173
+ "docs": ["Stake Pool Vault that stores staked tokens"],
263
174
  "writable": true,
264
- "relations": [
265
- "stake_pool"
266
- ]
175
+ "relations": ["stake_pool"]
267
176
  },
268
177
  {
269
178
  "name": "to",
270
- "docs": [
271
- "Token Account to transfer Stake Mint tokens to"
272
- ],
179
+ "docs": ["Token Account to transfer Stake Mint tokens to"],
273
180
  "writable": true
274
181
  },
275
182
  {
276
183
  "name": "payer",
277
- "docs": [
278
- "Owner of the Token Account from which tokens will be staked"
279
- ],
184
+ "docs": ["Owner of the Token Account from which tokens will be staked"],
280
185
  "writable": true,
281
186
  "signer": true
282
187
  },
@@ -285,23 +190,15 @@
285
190
  },
286
191
  {
287
192
  "name": "mint",
288
- "docs": [
289
- "Original mint of staked tokens"
290
- ],
193
+ "docs": ["Original mint of staked tokens"],
291
194
  "writable": true,
292
- "relations": [
293
- "stake_pool"
294
- ]
195
+ "relations": ["stake_pool"]
295
196
  },
296
197
  {
297
198
  "name": "stake_mint",
298
- "docs": [
299
- "Mint of stake tokens that will be minted in return for staking"
300
- ],
199
+ "docs": ["Mint of stake tokens that will be minted in return for staking"],
301
200
  "writable": true,
302
- "relations": [
303
- "stake_pool"
304
- ]
201
+ "relations": ["stake_pool"]
305
202
  },
306
203
  {
307
204
  "name": "token_program"
@@ -332,82 +229,51 @@
332
229
  },
333
230
  {
334
231
  "name": "unstake",
335
- "discriminator": [
336
- 90,
337
- 95,
338
- 107,
339
- 42,
340
- 205,
341
- 124,
342
- 50,
343
- 225
344
- ],
232
+ "discriminator": [90, 95, 107, 42, 205, 124, 50, 225],
345
233
  "accounts": [
346
234
  {
347
235
  "name": "stake_pool",
348
236
  "writable": true,
349
- "relations": [
350
- "stake_entry"
351
- ]
237
+ "relations": ["stake_entry"]
352
238
  },
353
239
  {
354
240
  "name": "stake_entry",
355
- "docs": [
356
- "Entry that stores Stake Metadata"
357
- ],
241
+ "docs": ["Entry that stores Stake Metadata"],
358
242
  "writable": true
359
243
  },
360
244
  {
361
245
  "name": "from",
362
- "docs": [
363
- "Stake Mint Token account"
364
- ],
246
+ "docs": ["Stake Mint Token account"],
365
247
  "writable": true
366
248
  },
367
249
  {
368
250
  "name": "vault",
369
- "docs": [
370
- "Escrow Account that stores Staked tokens"
371
- ],
251
+ "docs": ["Escrow Account that stores Staked tokens"],
372
252
  "writable": true,
373
- "relations": [
374
- "stake_pool"
375
- ]
253
+ "relations": ["stake_pool"]
376
254
  },
377
255
  {
378
256
  "name": "to",
379
- "docs": [
380
- "Token account to withdraw Staked tokens to"
381
- ],
257
+ "docs": ["Token account to withdraw Staked tokens to"],
382
258
  "writable": true
383
259
  },
384
260
  {
385
261
  "name": "authority",
386
- "docs": [
387
- "Stake Entry Authority"
388
- ],
262
+ "docs": ["Stake Entry Authority"],
389
263
  "writable": true,
390
264
  "signer": true
391
265
  },
392
266
  {
393
267
  "name": "mint",
394
- "docs": [
395
- "Original mint of staked tokens"
396
- ],
268
+ "docs": ["Original mint of staked tokens"],
397
269
  "writable": true,
398
- "relations": [
399
- "stake_pool"
400
- ]
270
+ "relations": ["stake_pool"]
401
271
  },
402
272
  {
403
273
  "name": "stake_mint",
404
- "docs": [
405
- "Stake Mint used to exchanged Staked tokens to"
406
- ],
274
+ "docs": ["Stake Mint used to exchanged Staked tokens to"],
407
275
  "writable": true,
408
- "relations": [
409
- "stake_pool"
410
- ]
276
+ "relations": ["stake_pool"]
411
277
  },
412
278
  {
413
279
  "name": "token_program"
@@ -419,29 +285,11 @@
419
285
  "accounts": [
420
286
  {
421
287
  "name": "StakeEntry",
422
- "discriminator": [
423
- 187,
424
- 127,
425
- 9,
426
- 35,
427
- 155,
428
- 68,
429
- 86,
430
- 40
431
- ]
288
+ "discriminator": [187, 127, 9, 35, 155, 68, 86, 40]
432
289
  },
433
290
  {
434
291
  "name": "StakePool",
435
- "discriminator": [
436
- 121,
437
- 34,
438
- 206,
439
- 21,
440
- 79,
441
- 127,
442
- 255,
443
- 28
444
- ]
292
+ "discriminator": [121, 34, 206, 21, 79, 127, 255, 28]
445
293
  }
446
294
  ],
447
295
  "errors": [
@@ -529,77 +377,54 @@
529
377
  "fields": [
530
378
  {
531
379
  "name": "nonce",
532
- "docs": [
533
- "Nonce to differentiate stakes for the same pool"
534
- ],
380
+ "docs": ["Nonce to differentiate stakes for the same pool"],
535
381
  "type": "u32"
536
382
  },
537
383
  {
538
384
  "name": "stake_pool",
539
- "docs": [
540
- "Stake Pool for which tokens were staked"
541
- ],
385
+ "docs": ["Stake Pool for which tokens were staked"],
542
386
  "type": "pubkey"
543
387
  },
544
388
  {
545
389
  "name": "payer",
546
- "docs": [
547
- "Original Owner of Staked tokens"
548
- ],
390
+ "docs": ["Original Owner of Staked tokens"],
549
391
  "type": "pubkey"
550
392
  },
551
393
  {
552
394
  "name": "authority",
553
- "docs": [
554
- "Authority of the Entry"
555
- ],
395
+ "docs": ["Authority of the Entry"],
556
396
  "type": "pubkey"
557
397
  },
558
398
  {
559
399
  "name": "amount",
560
- "docs": [
561
- "Amount of deposited funds"
562
- ],
400
+ "docs": ["Amount of deposited funds"],
563
401
  "type": "u64"
564
402
  },
565
403
  {
566
404
  "name": "duration",
567
- "docs": [
568
- "Duration of the lockup"
569
- ],
405
+ "docs": ["Duration of the lockup"],
570
406
  "type": "u64"
571
407
  },
572
408
  {
573
409
  "name": "effective_amount",
574
- "docs": [
575
- "Effective Amount staked, does not equal to deposited amount, accounts for Stake Weight"
576
- ],
410
+ "docs": ["Effective Amount staked, does not equal to deposited amount, accounts for Stake Weight"],
577
411
  "type": "u128"
578
412
  },
579
413
  {
580
414
  "name": "created_ts",
581
- "docs": [
582
- "Timestamp when Deposit was made"
583
- ],
415
+ "docs": ["Timestamp when Deposit was made"],
584
416
  "type": "u64"
585
417
  },
586
418
  {
587
419
  "name": "closed_ts",
588
- "docs": [
589
- "Flag whether entry has been already unstaked"
590
- ],
420
+ "docs": ["Flag whether entry has been already unstaked"],
591
421
  "type": "u64"
592
422
  },
593
423
  {
594
424
  "name": "_buffer",
595
- "docs": [
596
- "Buffer for additional fields"
597
- ],
425
+ "docs": ["Buffer for additional fields"],
598
426
  "type": {
599
- "array": [
600
- "u8",
601
- 64
602
- ]
427
+ "array": ["u8", 64]
603
428
  }
604
429
  }
605
430
  ]
@@ -612,37 +437,27 @@
612
437
  "fields": [
613
438
  {
614
439
  "name": "bump",
615
- "docs": [
616
- "Bump Seed used to sign transactions"
617
- ],
440
+ "docs": ["Bump Seed used to sign transactions"],
618
441
  "type": "u8"
619
442
  },
620
443
  {
621
444
  "name": "nonce",
622
- "docs": [
623
- "Nonce to differentiate pools for the same mint"
624
- ],
445
+ "docs": ["Nonce to differentiate pools for the same mint"],
625
446
  "type": "u8"
626
447
  },
627
448
  {
628
449
  "name": "mint",
629
- "docs": [
630
- "Mint of the Stake Pool"
631
- ],
450
+ "docs": ["Mint of the Stake Pool"],
632
451
  "type": "pubkey"
633
452
  },
634
453
  {
635
454
  "name": "creator",
636
- "docs": [
637
- "Initial Creator"
638
- ],
455
+ "docs": ["Initial Creator"],
639
456
  "type": "pubkey"
640
457
  },
641
458
  {
642
459
  "name": "authority",
643
- "docs": [
644
- "Current authority"
645
- ],
460
+ "docs": ["Current authority"],
646
461
  "type": "pubkey"
647
462
  },
648
463
  {
@@ -667,44 +482,32 @@
667
482
  },
668
483
  {
669
484
  "name": "min_duration",
670
- "docs": [
671
- "Min Duration of stake in seconds"
672
- ],
485
+ "docs": ["Min Duration of stake in seconds"],
673
486
  "type": "u64"
674
487
  },
675
488
  {
676
489
  "name": "max_duration",
677
- "docs": [
678
- "Max Duration of stake in seconds, the more duration, the more weight the stake has"
679
- ],
490
+ "docs": ["Max Duration of stake in seconds, the more duration, the more weight the stake has"],
680
491
  "type": "u64"
681
492
  },
682
493
  {
683
494
  "name": "permissionless",
684
- "docs": [
685
- "Whether anyone can add Reward Pools or just admin"
686
- ],
495
+ "docs": ["Whether anyone can add Reward Pools or just admin"],
687
496
  "type": "bool"
688
497
  },
689
498
  {
690
499
  "name": "vault",
691
- "docs": [
692
- "Escrow Account that stores staked tokens"
693
- ],
500
+ "docs": ["Escrow Account that stores staked tokens"],
694
501
  "type": "pubkey"
695
502
  },
696
503
  {
697
504
  "name": "stake_mint",
698
- "docs": [
699
- "Stake Mint, will be returned in exchange for stake tokens"
700
- ],
505
+ "docs": ["Stake Mint, will be returned in exchange for stake tokens"],
701
506
  "type": "pubkey"
702
507
  },
703
508
  {
704
509
  "name": "total_stake",
705
- "docs": [
706
- "Total number of Staked tokens"
707
- ],
510
+ "docs": ["Total number of Staked tokens"],
708
511
  "type": "u64"
709
512
  },
710
513
  {
@@ -717,14 +520,9 @@
717
520
  },
718
521
  {
719
522
  "name": "_buffer",
720
- "docs": [
721
- "Buffer for additional fields"
722
- ],
523
+ "docs": ["Buffer for additional fields"],
723
524
  "type": {
724
- "array": [
725
- "u8",
726
- 64
727
- ]
525
+ "array": ["u8", 64]
728
526
  }
729
527
  }
730
528
  ]
@@ -1,10 +1,8 @@
1
1
  import { TransferFeeConfig } from "@solana/spl-token";
2
2
  import { Connection } from "@solana/web3.js";
3
3
  import BN from "bn.js";
4
- export declare const calculateStakeWeight: (minDuration: BN, maxDuration: BN, maxWeight: BN, duration: BN) => BN;
5
4
  export declare const calculateFeeAmount: (amount: BN, fee?: BN) => BN;
6
5
  export declare const calculateDecimalsShift: (maxWeight: bigint, maxShift?: number) => number;
7
- export declare const divCeilN: (n: bigint, d: bigint) => bigint;
8
6
  export declare function calculateAmountWithTransferFees(connection: Connection, transferFeeConfig: TransferFeeConfig, transferAmount: bigint): Promise<{
9
7
  transferAmount: bigint;
10
8
  feeCharged: bigint;
@@ -1,16 +1,5 @@
1
- // eslint-disable-next-line no-restricted-imports
2
- import BN from "bn.js";
3
- import { DEFAULT_FEE_BN, FEE_PRECISION_FACTOR_BN, SCALE_PRECISION_FACTOR, SCALE_PRECISION_FACTOR_BN, U64_MAX, } from "./constants.js";
4
- export const calculateStakeWeight = (minDuration, maxDuration, maxWeight, duration) => {
5
- const durationSpan = maxDuration.sub(minDuration);
6
- if (durationSpan.eq(new BN(0))) {
7
- return SCALE_PRECISION_FACTOR_BN;
8
- }
9
- const durationExceedingMin = duration.sub(minDuration);
10
- const normalizedWeight = durationExceedingMin.mul(SCALE_PRECISION_FACTOR_BN).div(durationSpan);
11
- const weightDiff = maxWeight.sub(SCALE_PRECISION_FACTOR_BN);
12
- return BN.max(SCALE_PRECISION_FACTOR_BN.add(normalizedWeight.mul(weightDiff).div(SCALE_PRECISION_FACTOR_BN)), SCALE_PRECISION_FACTOR_BN);
13
- };
1
+ import { divCeilN } from "@streamflow/common";
2
+ import { DEFAULT_FEE_BN, FEE_PRECISION_FACTOR_BN, SCALE_PRECISION_FACTOR, U64_MAX } from "../constants.js";
14
3
  export const calculateFeeAmount = (amount, fee = DEFAULT_FEE_BN) => {
15
4
  if (fee.eq(FEE_PRECISION_FACTOR_BN)) {
16
5
  return amount;
@@ -30,7 +19,6 @@ export const calculateDecimalsShift = (maxWeight, maxShift = 999) => {
30
19
  }
31
20
  return decimalsShift;
32
21
  };
33
- export const divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
34
22
  export async function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
35
23
  const epoch = await connection.getEpochInfo();
36
24
  const transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch
@@ -1,10 +1,8 @@
1
1
  import { ProgramAccount } from "@coral-xyz/anchor";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  import BN from "bn.js";
4
- import { RewardEntry, StakeEntry, RewardPool } from "../types.js";
5
- export declare const REWARD_AMOUNT_PRECISION_FACTOR: BN;
4
+ import { RewardEntry, RewardPool, StakeEntry } from "../types.js";
6
5
  export declare class RewardEntryAccumulator implements RewardEntry {
7
- delegate: RewardEntry;
8
6
  lastAccountedTs: BN;
9
7
  claimedAmount: BN;
10
8
  accountedAmount: BN;
@@ -14,7 +12,8 @@ export declare class RewardEntryAccumulator implements RewardEntry {
14
12
  lastRewardAmount: BN;
15
13
  lastRewardPeriod: BN;
16
14
  buffer: number[];
17
- constructor(delegate: RewardEntry);
15
+ constructor(lastAccountedTs: BN, claimedAmount: BN, accountedAmount: BN, rewardPool: PublicKey, stakeEntry: PublicKey, createdTs: BN, lastRewardAmount: BN, lastRewardPeriod: BN, buffer: number[]);
16
+ static fromEntry(entry: RewardEntry): RewardEntryAccumulator;
18
17
  getAccountableAmount(stakedTs: BN, accountableTs: BN, effectiveStakedAmount: BN, rewardAmount: BN, rewardPeriod: BN): BN;
19
18
  getClaimableAmount(): BN;
20
19
  getLastAccountedTs(stakedTs: BN, claimableTs: BN, rewardPeriod: BN): BN;
@@ -22,3 +21,6 @@ export declare class RewardEntryAccumulator implements RewardEntry {
22
21
  addClaimedAmount(claimedAmount: BN): void;
23
22
  }
24
23
  export declare const calcRewards: (rewardEntryAccount: ProgramAccount<RewardEntry> | undefined, stakeEntryAccount: ProgramAccount<StakeEntry>, rewardPoolAccount: ProgramAccount<RewardPool>) => BN;
24
+ export declare const calculateRewardRateFromAmount: (rewardAmount: BN, stakeTokenDecimals: number, rewardTokenDecimals: number) => number;
25
+ export declare const calculateRewardAmountFromValue: (rewardTokenValue: BN, stakeTokenDecimals: number) => BN;
26
+ export declare const calculateRewardAmountFromRate: (rewardRate: number, stakeTokenDecimals: number, rewardTokenDecimals: number) => BN;