@streamflow/staking 11.2.2 → 11.3.1

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 CHANGED
@@ -8,6 +8,7 @@ This package allows you to
8
8
  - `stake`;
9
9
  - `unstake`;
10
10
  - `fund rewards pools`;
11
+ - `claw back unclaimed tokens from expired fixed reward pools`;
11
12
 
12
13
  with the Streamflow Staking protocol.
13
14
 
@@ -66,6 +67,7 @@ const client = new SolanaStakingClient({
66
67
  > - Withdraw/Unstake - staker's ATAs for stake mint and stake mint (see deriveStakeMintPDA fn)
67
68
  > - Claim rewards - staker's ATAs for reward mint
68
69
  > - Fund Reward Pool - signer creates Streamflow Treasury's ATA for holding fee if defined
70
+ > - Clawback - authority's ATA for reward mint
69
71
 
70
72
  #### Read operations
71
73
  ```typescript
@@ -377,6 +379,26 @@ const { tokenAccount } = await client.createFundDelegate({
377
379
 
378
380
  After creating the delegate, transfer reward tokens to the `tokenAccount`, which is an ATA for the fund delegate PDA address. The worker will periodically fund the reward pool from these tokens according to the schedule.
379
381
 
382
+ ### Clawback fixed reward pool funds
383
+
384
+ `clawback` lets the reward pool authority recover any tokens still left in the reward pool vault after the stake pool has expired and the cooldown has passed.
385
+
386
+ - It is available only for the fixed reward pool program.
387
+ - Dynamic reward pools do not support clawback.
388
+ - The program enforces a 7 day delay after `stakePool.expiryTs` before clawback is allowed.
389
+ - When it succeeds, the remaining reward tokens are transferred to the authority's ATA for the reward mint and the reward vault is closed.
390
+
391
+ ```typescript
392
+ await client.clawback({
393
+ stakePool,
394
+ stakePoolMint: mint,
395
+ nonce: rewardPoolNonce,
396
+ rewardMint,
397
+ }, extParams);
398
+ ```
399
+
400
+ Use `prepareClawbackInstructions` if you want to include the clawback instruction in a larger custom transaction.
401
+
380
402
  ### Set Token Metadata
381
403
 
382
404
  SolanaStakingClient also exposes original IDL of all programs, so you can use some additional instructions, that are not wrapped by the client. Currently there is no method to update Token Metadata of the Staking Mint that stakers get in return for their stake, but you can call the instructions from the original IDL like so:
@@ -8134,6 +8134,29 @@ var SolanaStakingClient = class {
8134
8134
  }).instruction();
8135
8135
  return { ixs: treasuryATA ? treasuryATA.concat([instruction]) : [instruction] };
8136
8136
  }
8137
+ async clawback(data, extParams) {
8138
+ const { ixs } = await this.prepareClawbackInstructions(data, extParams);
8139
+ const { signature } = await this.execute(ixs, extParams);
8140
+ return {
8141
+ ixs,
8142
+ txId: signature
8143
+ };
8144
+ }
8145
+ async prepareClawbackInstructions({ nonce, rewardMint, stakePool, tokenProgramId = splToken.TOKEN_PROGRAM_ID }, extParams) {
8146
+ const { rewardPoolProgram } = this.programs;
8147
+ const authority = extParams.invoker.publicKey;
8148
+ common.invariant(authority, "Undefined invoker publicKey");
8149
+ const rewardMintPk = common.pk(rewardMint);
8150
+ const tokenProgramPk = common.pk(tokenProgramId);
8151
+ const rewardPoolPda = deriveRewardPoolPDA(rewardPoolProgram.programId, common.pk(stakePool), rewardMintPk, nonce);
8152
+ const instruction = await rewardPoolProgram.methods.clawback().accountsPartial({
8153
+ rewardPool: rewardPoolPda,
8154
+ authority,
8155
+ tokenProgram: tokenProgramId,
8156
+ to: splToken.getAssociatedTokenAddressSync(rewardMintPk, authority, true, tokenProgramPk)
8157
+ }).instruction();
8158
+ return { ixs: [instruction] };
8159
+ }
8137
8160
  async createRewardEntry(data, extParams) {
8138
8161
  const { ixs } = await this.prepareCreateRewardEntryInstructions(data, extParams);
8139
8162
  const { signature } = await this.execute(ixs, extParams);