You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: update staking idls, support new methods, add groupped methods (#297)
- update staking idls to support rent sponsor account in methods and support `close_entry` in stake-pool;
- add reward pool dynamic IDL with basic exposure in the StakingClient;
- add higher level methods to group staking/unstaking with reward pool actions;
- update anchor to 0.31.1 - no major changes, better error handling;
- update README;
- make `execute` public method, move all tx estimation and base ixs logic into it - I think this method is good enough to be used for any kind of transactions;
`rewardAmount` represents a 10^9 fraction of a raw token distributed for every **effective staked raw token** - it's important to account for both reward and stake token decimals when creating staking pool because of that.
@@ -215,9 +218,31 @@ We recommend to use the `calculateRewardAmountFromRate` function exposed by the
215
218
const nonce =0;
216
219
const amount =newBN(1000); // tokens to stake
217
220
const duration =newBN(86400*2) // 2 days, must be in the range of stakePool's min and max durations
> For every Reward Pool a Reward entry should be created prior to claim and ideally at the same time when user stakes. Without a Reward Entry pool won't be able to properly track reward distribution.
229
+
230
+
You can also bundle multiple instructions with `prepare` calls to stake and create entries in one transaction:
// Done separately, returns rent fee back to the user
261
+
awaitclient.closeStakeEntry({ stakePool, nonce })
234
262
```
235
263
236
264
#### Claim a reward
@@ -251,6 +279,65 @@ await client.claimRewards({
251
279
> For instance, prepareClaimRewardsInstructions.
252
280
> These APIs allow to aggregate multiple operations in a single transaction according to the app needs.
253
281
282
+
### Grouped actions
283
+
284
+
Client also exposes methods to group staking/unstaking with reward pool actions.
285
+
286
+
```typescript
287
+
/// Will stake into a Stake Pool and create Reward Entries for every passed pool - reward entries are used to track rewards, ideally should be created right after staking.
// Performs multiple actions needed to fully unstake:
305
+
// 1. Claims all unclaimed rewards from all passed pools
306
+
// 2. Unstakes from a Stake Pool and closes the stake entry
307
+
// 3. Closes Reward Entries, returning the rent fee back
308
+
{
309
+
const { txId } =awaitclient.unstakeAndClaim({
310
+
stakePool,
311
+
stakePoolMint: mint,
312
+
nonce: stakeNonce,
313
+
rewardPools: [{
314
+
nonce: 0,
315
+
mint,
316
+
rewardPoolType: "fixed"
317
+
}]
318
+
}, extParams);
319
+
console.log("Unstake signature: ", txId);
320
+
}
321
+
322
+
// Useful when user can't claim rewards, but wants to unstake and close all created entries.
323
+
{
324
+
const { txId } =awaitclient.unstakeAndClose({
325
+
stakePool,
326
+
stakePoolMint: mint,
327
+
nonce: stakeNonce,
328
+
rewardPools: [{
329
+
nonce: 0,
330
+
mint,
331
+
rewardPoolType: "fixed"
332
+
}]
333
+
}, extParams);
334
+
console.log("Unstake signature: ", txId);
335
+
}
336
+
```
337
+
338
+
> [!Note]
339
+
> Transactions can become quite large if you have many rewards pools, that can make it impossible to do all actions in 1 transaction - in this case please stick with `prepare` methods to build custom instructions and execute them with `execute`.
340
+
254
341
### Set Token Metadata
255
342
256
343
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:
@@ -274,9 +361,8 @@ ix = await program.methods.setTokenMetadataT22("sToken", "sTST", "https://arweav
0 commit comments