@soltracer/nft-staking 0.2.0 → 0.2.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/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BN, Program } from "@coral-xyz/anchor";
2
2
  import { PublicKey, SystemProgram } from "@solana/web3.js";
3
- import { getStakeConfigPda, getStakePoolPda, getStakeEntryPda, getStakerAccountPda, getCollectionPda, getPoolAuthorityPda, getPoolSecondaryRewardsPda, getStakerSecondaryRewardsPda, getProjectPda, getUtilityConfigPda, getAta, decodeAccount, getFeeConfigPda, getTreasuryPda, PROJECT_MANAGEMENT_PROGRAM_ID, ADMIN_PROGRAM_ID, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, MPL_CORE_PROGRAM_ID, } from "@soltracer/core";
3
+ import { getStakeConfigPda, getStakePoolPda, getStakeEntryPda, getStakerAccountPda, getCollectionPda, getPoolAuthorityPda, getPoolSecondaryRewardsPda, getStakerSecondaryRewardsPda, getProjectPda, getUtilityConfigPda, getProgramRegistryPda, getAta, decodeAccount, getFeeConfigPda, getTreasuryPda, PROJECT_MANAGEMENT_PROGRAM_ID, ADMIN_PROGRAM_ID, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, MPL_CORE_PROGRAM_ID, } from "@soltracer/core";
4
4
  import NftStakingIDL from "./idl.json";
5
5
  /** Well-known program IDs for cNFT operations. */
6
6
  const BUBBLEGUM_PROGRAM_ID = new PublicKey("BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY");
@@ -32,6 +32,12 @@ function base58HashToArray(hash) {
32
32
  function getTreeConfigPda(merkleTree) {
33
33
  return PublicKey.findProgramAddressSync([merkleTree.toBytes()], BUBBLEGUM_PROGRAM_ID);
34
34
  }
35
+ function toPk(v) {
36
+ return typeof v === "string" ? new PublicKey(v) : v;
37
+ }
38
+ function toBN(v) {
39
+ return typeof v === "number" ? new BN(v) : v;
40
+ }
35
41
  export class NftStakingClient {
36
42
  program;
37
43
  provider;
@@ -136,6 +142,7 @@ export class NftStakingClient {
136
142
  resolveFeeAccounts(fee) {
137
143
  const programId = this.program.programId;
138
144
  const [feeConfig] = getFeeConfigPda(programId);
145
+ const [programRegistry] = getProgramRegistryPda(programId);
139
146
  const [treasury] = getTreasuryPda();
140
147
  let referralAccount = ADMIN_PROGRAM_ID;
141
148
  if (fee?.referralAccount) {
@@ -147,6 +154,7 @@ export class NftStakingClient {
147
154
  }
148
155
  return {
149
156
  feeConfig,
157
+ programRegistry,
150
158
  treasury,
151
159
  referralAccount,
152
160
  solUsdPriceFeed: NftStakingClient.PYTH_SOL_USD_FEED,
@@ -172,14 +180,14 @@ export class NftStakingClient {
172
180
  return this.applyPoolDecimals(pool, decimals);
173
181
  }
174
182
  async fetchStakeEntry(poolId, nftMint) {
175
- const [pda] = getStakeEntryPda(poolId, nftMint);
183
+ const [pda] = getStakeEntryPda(poolId, toPk(nftMint));
176
184
  const raw = await this.program.account.stakeEntry.fetchNullable(pda);
177
185
  if (!raw)
178
186
  return null;
179
187
  return decodeAccount(raw);
180
188
  }
181
189
  async fetchStakerAccount(poolId, wallet, rewardDecimals) {
182
- const [pda] = getStakerAccountPda(poolId, wallet);
190
+ const [pda] = getStakerAccountPda(poolId, toPk(wallet));
183
191
  const raw = await this.program.account.stakerAccount.fetchNullable(pda);
184
192
  if (!raw)
185
193
  return null;
@@ -211,8 +219,9 @@ export class NftStakingClient {
211
219
  }
212
220
  /** Fetch all active stake entries for a wallet in a specific pool via gPA. */
213
221
  async fetchStakeEntriesByOwner(_poolId, owner) {
222
+ const _owner = toPk(owner);
214
223
  const entries = await this.program.account.stakeEntry.all([
215
- { memcmp: { offset: 72, bytes: owner.toBase58() } },
224
+ { memcmp: { offset: 72, bytes: _owner.toBase58() } },
216
225
  ]);
217
226
  return entries
218
227
  .map(({ account }) => decodeAccount(account))
@@ -225,7 +234,7 @@ export class NftStakingClient {
225
234
  async fetchStakeEntriesForMints(poolId, nftMints) {
226
235
  if (nftMints.length === 0)
227
236
  return [];
228
- const pdas = nftMints.map((mint) => getStakeEntryPda(poolId, mint)[0]);
237
+ const pdas = nftMints.map((mint) => getStakeEntryPda(poolId, toPk(mint))[0]);
229
238
  const accounts = await this.program.account.stakeEntry.fetchMultiple(pdas);
230
239
  return accounts
231
240
  .filter((a) => a !== null)
@@ -270,11 +279,12 @@ export class NftStakingClient {
270
279
  return stakers.map(({ account }) => decodeAccount(account));
271
280
  }
272
281
  async closeLegacyCollection(collectionMint, projectId) {
282
+ const _collMint = toPk(collectionMint);
273
283
  const pid = this.resolveProjectId(projectId);
274
- const [collection] = PublicKey.findProgramAddressSync([Buffer.from("project_collection"), new BN(pid).toArrayLike(Buffer, "le", 8), collectionMint.toBuffer()], this.program.programId);
284
+ const [collection] = PublicKey.findProgramAddressSync([Buffer.from("project_collection"), new BN(pid).toArrayLike(Buffer, "le", 8), _collMint.toBuffer()], this.program.programId);
275
285
  const [project] = getProjectPda(pid);
276
286
  return this.program.methods
277
- .closeLegacyCollection(new BN(pid), collectionMint)
287
+ .closeLegacyCollection(new BN(pid), _collMint)
278
288
  .accountsStrict({
279
289
  collection,
280
290
  authority: this.provider.wallet.publicKey,
@@ -299,17 +309,19 @@ export class NftStakingClient {
299
309
  .instruction();
300
310
  }
301
311
  async createStakePool(stakingMode, rewardConfig, lockConfigs, collectionMint, opts) {
312
+ const _collMint = toPk(collectionMint);
313
+ const _rewardMint = toPk(rewardConfig.rewardMint);
302
314
  const pid = this.resolveProjectId(opts?.projectId);
303
315
  const rewardEndAt = opts?.rewardEndAt ?? 0;
304
316
  const maxStaked = opts?.maxStaked ?? 0;
305
317
  const config = await this.fetchStakeConfig(pid);
306
318
  const nextPoolId = config ? config.totalPools : 0;
307
- const tokenProgram = await this.resolveTokenProgram(rewardConfig.rewardMint);
308
- const decimals = await this.getMintDecimals(rewardConfig.rewardMint);
319
+ const tokenProgram = await this.resolveTokenProgram(_rewardMint);
320
+ const decimals = await this.getMintDecimals(_rewardMint);
309
321
  const multiplier = 10 ** decimals;
310
322
  const rawRewardConfig = {
311
323
  rewardType: rewardConfig.rewardType,
312
- rewardMint: rewardConfig.rewardMint,
324
+ rewardMint: _rewardMint,
313
325
  baseRate: new BN(Math.round(rewardConfig.baseRate * multiplier)),
314
326
  rateInterval: new BN(rewardConfig.rateInterval),
315
327
  traitBonusMode: rewardConfig.traitBonusMode,
@@ -322,9 +334,9 @@ export class NftStakingClient {
322
334
  }));
323
335
  const [configPda] = getStakeConfigPda(pid);
324
336
  const [poolPda] = getStakePoolPda(pid, nextPoolId);
325
- const [collectionConfigPda] = getCollectionPda(pid, collectionMint);
337
+ const [collectionConfigPda] = getCollectionPda(pid, _collMint);
326
338
  const [poolAuthority] = getPoolAuthorityPda(nextPoolId);
327
- const rewardVault = getAta(poolAuthority, rewardConfig.rewardMint, tokenProgram);
339
+ const rewardVault = getAta(poolAuthority, _rewardMint, tokenProgram);
328
340
  const [utilityConfig] = getUtilityConfigPda(pid, this.program.programId);
329
341
  return this.program.methods
330
342
  .createStakePool(new BN(pid), stakingMode, rawRewardConfig, rawLockConfigs, new BN(rewardEndAt), new BN(maxStaked))
@@ -333,8 +345,8 @@ export class NftStakingClient {
333
345
  pool: poolPda,
334
346
  collectionConfig: collectionConfigPda,
335
347
  poolAuthority,
336
- collectionMint,
337
- rewardMint: rewardConfig.rewardMint,
348
+ collectionMint: _collMint,
349
+ rewardMint: _rewardMint,
338
350
  rewardVault,
339
351
  utilityConfig,
340
352
  projectManagementProgram: PROJECT_MANAGEMENT_PROGRAM_ID,
@@ -350,7 +362,7 @@ export class NftStakingClient {
350
362
  const rewardConfig = updates.rewardConfig ?? null;
351
363
  const lockConfigs = updates.lockConfigs ?? null;
352
364
  const isActive = updates.isActive ?? null;
353
- const traitAuthority = updates.traitAuthority ?? null;
365
+ const traitAuthority = updates.traitAuthority != null ? toPk(updates.traitAuthority) : null;
354
366
  const canBurn = updates.canBurn ?? null;
355
367
  const merkleRoot = updates.merkleRoot ?? null;
356
368
  const gateType = updates.gateType ?? null;
@@ -359,11 +371,12 @@ export class NftStakingClient {
359
371
  let rawRewardConfig = null;
360
372
  let rawLockConfigs = null;
361
373
  if (rewardConfig) {
362
- const decimals = await this.getMintDecimals(rewardConfig.rewardMint);
374
+ const _rMint = toPk(rewardConfig.rewardMint);
375
+ const decimals = await this.getMintDecimals(_rMint);
363
376
  const multiplier = 10 ** decimals;
364
377
  rawRewardConfig = {
365
378
  rewardType: rewardConfig.rewardType,
366
- rewardMint: rewardConfig.rewardMint,
379
+ rewardMint: _rMint,
367
380
  baseRate: new BN(Math.round(rewardConfig.baseRate * multiplier)),
368
381
  rateInterval: new BN(rewardConfig.rateInterval),
369
382
  traitBonusMode: rewardConfig.traitBonusMode,
@@ -371,7 +384,7 @@ export class NftStakingClient {
371
384
  };
372
385
  }
373
386
  if (lockConfigs && rewardConfig) {
374
- const decimals = await this.getMintDecimals(rewardConfig.rewardMint);
387
+ const decimals = await this.getMintDecimals(toPk(rewardConfig.rewardMint));
375
388
  const multiplier = 10 ** decimals;
376
389
  rawLockConfigs = lockConfigs.map((lc) => ({
377
390
  lockDuration: new BN(lc.lockDuration),
@@ -402,14 +415,14 @@ export class NftStakingClient {
402
415
  async fundRewardVault(poolId, amount, opts) {
403
416
  const pid = this.resolveProjectId(opts?.projectId);
404
417
  const pool = await this.getPoolData(pid, poolId);
405
- const rewardMint = opts?.rewardMint ?? new PublicKey(pool.rewardConfig.rewardMint);
418
+ const rewardMint = opts?.rewardMint ? toPk(opts.rewardMint) : new PublicKey(pool.rewardConfig.rewardMint);
406
419
  const tokenProgram = await this.resolveTokenProgram(rewardMint);
407
420
  const [poolPda] = getStakePoolPda(pid, poolId);
408
421
  const [poolAuthority] = getPoolAuthorityPda(poolId);
409
422
  const rewardVault = getAta(poolAuthority, rewardMint, tokenProgram);
410
- const funderAta = opts?.funderTokenAccount ?? getAta(this.provider.wallet.publicKey, rewardMint, tokenProgram);
423
+ const funderAta = opts?.funderTokenAccount ? toPk(opts.funderTokenAccount) : getAta(this.provider.wallet.publicKey, rewardMint, tokenProgram);
411
424
  return this.program.methods
412
- .fundRewardVault(new BN(pid), new BN(poolId), amount)
425
+ .fundRewardVault(new BN(pid), new BN(poolId), toBN(amount))
413
426
  .accountsStrict({
414
427
  pool: poolPda,
415
428
  poolAuthority,
@@ -425,14 +438,14 @@ export class NftStakingClient {
425
438
  async withdrawRewardVault(poolId, amount, opts) {
426
439
  const pid = this.resolveProjectId(opts?.projectId);
427
440
  const pool = await this.getPoolData(pid, poolId);
428
- const rewardMint = opts?.rewardMint ?? new PublicKey(pool.rewardConfig.rewardMint);
441
+ const rewardMint = opts?.rewardMint ? toPk(opts.rewardMint) : new PublicKey(pool.rewardConfig.rewardMint);
429
442
  const tokenProgram = await this.resolveTokenProgram(rewardMint);
430
443
  const [poolPda] = getStakePoolPda(pid, poolId);
431
444
  const [poolAuthority] = getPoolAuthorityPda(poolId);
432
445
  const rewardVault = getAta(poolAuthority, rewardMint, tokenProgram);
433
- const destAta = opts?.destinationTokenAccount ?? getAta(this.provider.wallet.publicKey, rewardMint, tokenProgram);
446
+ const destAta = opts?.destinationTokenAccount ? toPk(opts.destinationTokenAccount) : getAta(this.provider.wallet.publicKey, rewardMint, tokenProgram);
434
447
  return this.program.methods
435
- .withdrawRewardVault(new BN(pid), new BN(poolId), amount)
448
+ .withdrawRewardVault(new BN(pid), new BN(poolId), toBN(amount))
436
449
  .accountsStrict({
437
450
  pool: poolPda,
438
451
  poolAuthority,
@@ -451,40 +464,44 @@ export class NftStakingClient {
451
464
  .closeStakePool(new BN(pid), new BN(poolId))
452
465
  .accountsStrict({
453
466
  pool: poolPda,
467
+ rewardVault: null,
468
+ tokenProgram: null,
454
469
  authority: this.provider.wallet.publicKey,
455
470
  })
456
471
  .instruction();
457
472
  }
458
473
  /** Stake a legacy/pNFT. Auto-resolves stakingMode from pool. */
459
474
  async stakeNft(poolId, nftMint, opts) {
475
+ const _nftMint = toPk(nftMint);
460
476
  const pid = this.resolveProjectId(opts?.projectId);
461
477
  const pool = await this.getPoolData(pid, poolId);
462
478
  const stakingMode = pool.stakingMode;
463
479
  const lockTierIndex = opts?.lockTierIndex ?? null;
464
480
  const gateProof = opts?.gateProof ?? [];
465
481
  const [poolPda] = getStakePoolPda(pid, poolId);
466
- const [stakeEntry] = getStakeEntryPda(poolId, nftMint);
482
+ const [stakeEntry] = getStakeEntryPda(poolId, _nftMint);
467
483
  const staker = this.provider.wallet.publicKey;
468
484
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
469
485
  const [poolAuthority] = getPoolAuthorityPda(poolId);
470
- const nftTokenProgram = await this.resolveTokenProgram(nftMint);
471
- const stakerNftAccount = getAta(staker, nftMint, nftTokenProgram);
486
+ const nftTokenProgram = await this.resolveTokenProgram(_nftMint);
487
+ const stakerNftAccount = getAta(staker, _nftMint, nftTokenProgram);
472
488
  const isEscrow = stakingMode !== 1;
473
489
  const escrowNftAccount = isEscrow
474
- ? getAta(poolAuthority, nftMint, nftTokenProgram)
490
+ ? getAta(poolAuthority, _nftMint, nftTokenProgram)
475
491
  : null;
476
- const nftMetadata = getMetadataPda(nftMint);
477
- const nftEdition = getEditionPda(nftMint);
492
+ const nftMetadata = getMetadataPda(_nftMint);
493
+ const nftEdition = getEditionPda(_nftMint);
478
494
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
495
+ const [project] = getProjectPda(pid);
479
496
  const [utilityConfig] = getUtilityConfigPda(pid, this.program.programId);
480
497
  return this.program.methods
481
- .stakeNft(new BN(pid), new BN(poolId), nftMint, lockTierIndex, gateProof)
498
+ .stakeNft(new BN(pid), new BN(poolId), _nftMint, lockTierIndex, gateProof)
482
499
  .accountsStrict({
483
500
  pool: poolPda,
484
501
  stakeEntry,
485
502
  stakerAccount,
486
503
  poolAuthority,
487
- nftMint,
504
+ nftMint: _nftMint,
488
505
  stakerNftAccount,
489
506
  escrowNftAccount,
490
507
  nftMetadata,
@@ -495,10 +512,12 @@ export class NftStakingClient {
495
512
  destinationTokenRecord: null,
496
513
  utilityConfig,
497
514
  feeConfig: feeAccts.feeConfig,
515
+ programRegistry: feeAccts.programRegistry,
498
516
  treasury: feeAccts.treasury,
499
517
  referralAccount: feeAccts.referralAccount,
500
518
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
501
519
  adminProgram: feeAccts.adminProgram,
520
+ project,
502
521
  staker,
503
522
  tokenProgram: nftTokenProgram,
504
523
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -508,35 +527,35 @@ export class NftStakingClient {
508
527
  }
509
528
  /** Unstake a legacy/pNFT. Auto-resolves rewardMint and stakingMode from pool. */
510
529
  async unstakeNft(poolId, nftMint, opts) {
530
+ const _nftMint = toPk(nftMint);
511
531
  const pid = this.resolveProjectId(opts?.projectId);
512
532
  const pool = await this.getPoolData(pid, poolId);
513
533
  const rewardMint = new PublicKey(pool.rewardConfig.rewardMint);
514
534
  const stakingMode = pool.stakingMode;
515
535
  const rewardTokenProgram = await this.resolveTokenProgram(rewardMint);
516
- const nftTokenProgram = await this.resolveTokenProgram(nftMint);
536
+ const nftTokenProgram = await this.resolveTokenProgram(_nftMint);
517
537
  const [poolPda] = getStakePoolPda(pid, poolId);
518
- const [stakeEntry] = getStakeEntryPda(poolId, nftMint);
538
+ const [stakeEntry] = getStakeEntryPda(poolId, _nftMint);
519
539
  const staker = this.provider.wallet.publicKey;
520
540
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
521
541
  const [poolAuthority] = getPoolAuthorityPda(poolId);
522
- const stakerNftAccount = getAta(staker, nftMint, nftTokenProgram);
542
+ const stakerNftAccount = getAta(staker, _nftMint, nftTokenProgram);
523
543
  const isEscrow = stakingMode !== 1;
524
544
  const escrowNftAccount = isEscrow
525
- ? getAta(poolAuthority, nftMint, nftTokenProgram)
545
+ ? getAta(poolAuthority, _nftMint, nftTokenProgram)
526
546
  : null;
527
547
  const rewardVault = getAta(poolAuthority, rewardMint, rewardTokenProgram);
528
548
  const stakerRewardAccount = getAta(staker, rewardMint, rewardTokenProgram);
529
- const nftMetadata = getMetadataPda(nftMint);
530
- const nftEdition = getEditionPda(nftMint);
531
- const feeAccts = this.resolveFeeAccounts(opts?.fee);
549
+ const nftMetadata = getMetadataPda(_nftMint);
550
+ const nftEdition = getEditionPda(_nftMint);
532
551
  return this.program.methods
533
- .unstakeNft(new BN(pid), new BN(poolId), nftMint)
552
+ .unstakeNft(new BN(pid), new BN(poolId), _nftMint)
534
553
  .accountsStrict({
535
554
  pool: poolPda,
536
555
  stakeEntry,
537
556
  stakerAccount,
538
557
  poolAuthority,
539
- nftMint,
558
+ nftMint: _nftMint,
540
559
  stakerNftAccount,
541
560
  escrowNftAccount,
542
561
  rewardVault,
@@ -548,11 +567,6 @@ export class NftStakingClient {
548
567
  sysvarInstructions: SYSVAR_INSTRUCTIONS_ID,
549
568
  tokenRecord: null,
550
569
  destinationTokenRecord: null,
551
- feeConfig: feeAccts.feeConfig,
552
- treasury: feeAccts.treasury,
553
- referralAccount: feeAccts.referralAccount,
554
- solUsdPriceFeed: feeAccts.solUsdPriceFeed,
555
- adminProgram: feeAccts.adminProgram,
556
570
  staker,
557
571
  tokenProgram: nftTokenProgram,
558
572
  rewardTokenProgram,
@@ -576,6 +590,7 @@ export class NftStakingClient {
576
590
  const stakerRewardAccount = getAta(staker, rewardMint, tokenProgram);
577
591
  const [stakeConfig] = getStakeConfigPda(pid);
578
592
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
593
+ const [project] = getProjectPda(pid);
579
594
  return this.program.methods
580
595
  .claimRewards(new BN(pid), new BN(poolId), traitBonusRate)
581
596
  .accountsStrict({
@@ -588,10 +603,12 @@ export class NftStakingClient {
588
603
  stakeConfig,
589
604
  instructionsSysvar: new PublicKey("Sysvar1nstructions1111111111111111111111111"),
590
605
  feeConfig: feeAccts.feeConfig,
606
+ programRegistry: feeAccts.programRegistry,
591
607
  treasury: feeAccts.treasury,
592
608
  referralAccount: feeAccts.referralAccount,
593
609
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
594
610
  adminProgram: feeAccts.adminProgram,
611
+ project,
595
612
  staker,
596
613
  tokenProgram,
597
614
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -601,34 +618,38 @@ export class NftStakingClient {
601
618
  }
602
619
  /** Stake a Core NFT. Auto-resolves collection from pool. */
603
620
  async stakeCoreNft(poolId, nftAsset, opts) {
621
+ const _nftAsset = toPk(nftAsset);
604
622
  const pid = this.resolveProjectId(opts?.projectId);
605
623
  const pool = await this.getPoolData(pid, poolId);
606
624
  const collection = new PublicKey(pool.collectionMint);
607
625
  const lockTierIndex = opts?.lockTierIndex ?? null;
608
626
  const gateProof = opts?.gateProof ?? [];
609
627
  const [poolPda] = getStakePoolPda(pid, poolId);
610
- const [stakeEntry] = getStakeEntryPda(poolId, nftAsset);
628
+ const [stakeEntry] = getStakeEntryPda(poolId, _nftAsset);
611
629
  const staker = this.provider.wallet.publicKey;
612
630
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
613
631
  const [poolAuthority] = getPoolAuthorityPda(poolId);
614
632
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
633
+ const [project] = getProjectPda(pid);
615
634
  const [utilityConfig] = getUtilityConfigPda(pid, this.program.programId);
616
635
  return this.program.methods
617
- .stakeCoreNft(new BN(pid), new BN(poolId), nftAsset, lockTierIndex, gateProof)
636
+ .stakeCoreNft(new BN(pid), new BN(poolId), _nftAsset, lockTierIndex, gateProof)
618
637
  .accountsStrict({
619
638
  pool: poolPda,
620
639
  stakeEntry,
621
640
  stakerAccount,
622
641
  poolAuthority,
623
- nftAsset,
642
+ nftAsset: _nftAsset,
624
643
  collection,
625
644
  mplCoreProgram: MPL_CORE_PROGRAM_ID,
626
645
  utilityConfig,
627
646
  feeConfig: feeAccts.feeConfig,
647
+ programRegistry: feeAccts.programRegistry,
628
648
  treasury: feeAccts.treasury,
629
649
  referralAccount: feeAccts.referralAccount,
630
650
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
631
651
  adminProgram: feeAccts.adminProgram,
652
+ project,
632
653
  staker,
633
654
  systemProgram: SystemProgram.programId,
634
655
  })
@@ -636,37 +657,32 @@ export class NftStakingClient {
636
657
  }
637
658
  /** Unstake a Core NFT. Auto-resolves collection and rewardMint from pool. */
638
659
  async unstakeCoreNft(poolId, nftAsset, opts) {
660
+ const _nftAsset = toPk(nftAsset);
639
661
  const pid = this.resolveProjectId(opts?.projectId);
640
662
  const pool = await this.getPoolData(pid, poolId);
641
663
  const collection = new PublicKey(pool.collectionMint);
642
664
  const rewardMint = new PublicKey(pool.rewardConfig.rewardMint);
643
665
  const rewardTokenProgram = await this.resolveTokenProgram(rewardMint);
644
666
  const [poolPda] = getStakePoolPda(pid, poolId);
645
- const [stakeEntry] = getStakeEntryPda(poolId, nftAsset);
667
+ const [stakeEntry] = getStakeEntryPda(poolId, _nftAsset);
646
668
  const staker = this.provider.wallet.publicKey;
647
669
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
648
670
  const [poolAuthority] = getPoolAuthorityPda(poolId);
649
671
  const rewardVault = getAta(poolAuthority, rewardMint, rewardTokenProgram);
650
672
  const stakerRewardAccount = getAta(staker, rewardMint, rewardTokenProgram);
651
- const feeAccts = this.resolveFeeAccounts(opts?.fee);
652
673
  return this.program.methods
653
- .unstakeCoreNft(new BN(pid), new BN(poolId), nftAsset)
674
+ .unstakeCoreNft(new BN(pid), new BN(poolId), _nftAsset)
654
675
  .accountsStrict({
655
676
  pool: poolPda,
656
677
  stakeEntry,
657
678
  stakerAccount,
658
679
  poolAuthority,
659
- nftAsset,
680
+ nftAsset: _nftAsset,
660
681
  collection,
661
682
  mplCoreProgram: MPL_CORE_PROGRAM_ID,
662
683
  rewardVault,
663
684
  stakerRewardAccount,
664
685
  rewardMint,
665
- feeConfig: feeAccts.feeConfig,
666
- treasury: feeAccts.treasury,
667
- referralAccount: feeAccts.referralAccount,
668
- solUsdPriceFeed: feeAccts.solUsdPriceFeed,
669
- adminProgram: feeAccts.adminProgram,
670
686
  staker,
671
687
  rewardTokenProgram,
672
688
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -691,6 +707,7 @@ export class NftStakingClient {
691
707
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
692
708
  const [poolAuthority] = getPoolAuthorityPda(poolId);
693
709
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
710
+ const [project] = getProjectPda(pid);
694
711
  const [utilityConfig] = getUtilityConfigPda(pid, this.program.programId);
695
712
  const remainingAccounts = proofNodes.map((node) => ({
696
713
  pubkey: new PublicKey(node),
@@ -711,10 +728,12 @@ export class NftStakingClient {
711
728
  bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
712
729
  utilityConfig,
713
730
  feeConfig: feeAccts.feeConfig,
731
+ programRegistry: feeAccts.programRegistry,
714
732
  treasury: feeAccts.treasury,
715
733
  referralAccount: feeAccts.referralAccount,
716
734
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
717
735
  adminProgram: feeAccts.adminProgram,
736
+ project,
718
737
  staker,
719
738
  systemProgram: SystemProgram.programId,
720
739
  })
@@ -738,7 +757,6 @@ export class NftStakingClient {
738
757
  const staker = this.provider.wallet.publicKey;
739
758
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
740
759
  const [poolAuthority] = getPoolAuthorityPda(poolId);
741
- const feeAccts = this.resolveFeeAccounts(opts?.fee);
742
760
  const rewardVaultPk = getAta(poolAuthority, rewardMintPk);
743
761
  const stakerRewardAccountPk = getAta(staker, rewardMintPk);
744
762
  const remainingAccounts = proofNodes.map((node) => ({
@@ -761,11 +779,6 @@ export class NftStakingClient {
761
779
  rewardVault: rewardVaultPk,
762
780
  stakerRewardAccount: stakerRewardAccountPk,
763
781
  rewardMint: rewardMintPk,
764
- feeConfig: feeAccts.feeConfig,
765
- treasury: feeAccts.treasury,
766
- referralAccount: feeAccts.referralAccount,
767
- solUsdPriceFeed: feeAccts.solUsdPriceFeed,
768
- adminProgram: feeAccts.adminProgram,
769
782
  staker,
770
783
  tokenProgram: TOKEN_PROGRAM_ID,
771
784
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -776,29 +789,31 @@ export class NftStakingClient {
776
789
  }
777
790
  /** Burn a permanently-locked legacy/pNFT. Auto-resolves stakingMode from pool. */
778
791
  async burnStakedNft(poolId, nftMint, opts) {
792
+ const _nftMint = toPk(nftMint);
779
793
  const pid = this.resolveProjectId(opts?.projectId);
780
794
  const pool = await this.getPoolData(pid, poolId);
781
795
  const stakingMode = pool.stakingMode;
782
- const nftTokenProgram = await this.resolveTokenProgram(nftMint);
796
+ const nftTokenProgram = await this.resolveTokenProgram(_nftMint);
783
797
  const [poolPda] = getStakePoolPda(pid, poolId);
784
- const [stakeEntry] = getStakeEntryPda(poolId, nftMint);
798
+ const [stakeEntry] = getStakeEntryPda(poolId, _nftMint);
785
799
  const staker = this.provider.wallet.publicKey;
786
800
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
787
801
  const [poolAuthority] = getPoolAuthorityPda(poolId);
788
802
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
803
+ const [project] = getProjectPda(pid);
789
804
  const isWalletLock = stakingMode === 1;
790
- const escrowNftAccount = isWalletLock ? null : getAta(poolAuthority, nftMint, nftTokenProgram);
791
- const stakerNftAccount = isWalletLock ? getAta(staker, nftMint, nftTokenProgram) : null;
792
- const nftMetadata = isWalletLock ? getMetadataPda(nftMint) : null;
793
- const nftEdition = isWalletLock ? getEditionPda(nftMint) : null;
805
+ const escrowNftAccount = isWalletLock ? null : getAta(poolAuthority, _nftMint, nftTokenProgram);
806
+ const stakerNftAccount = isWalletLock ? getAta(staker, _nftMint, nftTokenProgram) : null;
807
+ const nftMetadata = isWalletLock ? getMetadataPda(_nftMint) : null;
808
+ const nftEdition = isWalletLock ? getEditionPda(_nftMint) : null;
794
809
  return this.program.methods
795
- .burnStakedNft(new BN(pid), new BN(poolId), nftMint)
810
+ .burnStakedNft(new BN(pid), new BN(poolId), _nftMint)
796
811
  .accountsStrict({
797
812
  pool: poolPda,
798
813
  stakeEntry,
799
814
  stakerAccount,
800
815
  poolAuthority,
801
- nftMint,
816
+ nftMint: _nftMint,
802
817
  escrowNftAccount,
803
818
  stakerNftAccount,
804
819
  nftMetadata,
@@ -808,10 +823,12 @@ export class NftStakingClient {
808
823
  tokenRecord: null,
809
824
  collectionMetadata: null,
810
825
  feeConfig: feeAccts.feeConfig,
826
+ programRegistry: feeAccts.programRegistry,
811
827
  treasury: feeAccts.treasury,
812
828
  referralAccount: feeAccts.referralAccount,
813
829
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
814
830
  adminProgram: feeAccts.adminProgram,
831
+ project,
815
832
  staker,
816
833
  tokenProgram: nftTokenProgram,
817
834
  systemProgram: SystemProgram.programId,
@@ -820,30 +837,34 @@ export class NftStakingClient {
820
837
  }
821
838
  /** Burn a permanently-locked Core NFT. Auto-resolves collection from pool. */
822
839
  async burnStakedCoreNft(poolId, nftAsset, opts) {
840
+ const _nftAsset = toPk(nftAsset);
823
841
  const pid = this.resolveProjectId(opts?.projectId);
824
842
  const pool = await this.getPoolData(pid, poolId);
825
843
  const collection = new PublicKey(pool.collectionMint);
826
844
  const [poolPda] = getStakePoolPda(pid, poolId);
827
- const [stakeEntry] = getStakeEntryPda(poolId, nftAsset);
845
+ const [stakeEntry] = getStakeEntryPda(poolId, _nftAsset);
828
846
  const staker = this.provider.wallet.publicKey;
829
847
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
830
848
  const [poolAuthority] = getPoolAuthorityPda(poolId);
831
849
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
850
+ const [project] = getProjectPda(pid);
832
851
  return this.program.methods
833
- .burnStakedCoreNft(new BN(pid), new BN(poolId), nftAsset)
852
+ .burnStakedCoreNft(new BN(pid), new BN(poolId), _nftAsset)
834
853
  .accountsStrict({
835
854
  pool: poolPda,
836
855
  stakeEntry,
837
856
  stakerAccount,
838
857
  poolAuthority,
839
- nftAsset,
858
+ nftAsset: _nftAsset,
840
859
  collection,
841
860
  mplCoreProgram: MPL_CORE_PROGRAM_ID,
842
861
  feeConfig: feeAccts.feeConfig,
862
+ programRegistry: feeAccts.programRegistry,
843
863
  treasury: feeAccts.treasury,
844
864
  referralAccount: feeAccts.referralAccount,
845
865
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
846
866
  adminProgram: feeAccts.adminProgram,
867
+ project,
847
868
  staker,
848
869
  systemProgram: SystemProgram.programId,
849
870
  })
@@ -856,16 +877,19 @@ export class NftStakingClient {
856
877
  const staker = this.provider.wallet.publicKey;
857
878
  const [stakerAccount] = getStakerAccountPda(poolId, staker);
858
879
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
880
+ const [project] = getProjectPda(pid);
859
881
  return this.program.methods
860
- .spendPoints(new BN(pid), new BN(poolId), amount)
882
+ .spendPoints(new BN(pid), new BN(poolId), toBN(amount))
861
883
  .accountsStrict({
862
884
  pool: poolPda,
863
885
  stakerAccount,
864
886
  feeConfig: feeAccts.feeConfig,
887
+ programRegistry: feeAccts.programRegistry,
865
888
  treasury: feeAccts.treasury,
866
889
  referralAccount: feeAccts.referralAccount,
867
890
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
868
891
  adminProgram: feeAccts.adminProgram,
892
+ project,
869
893
  staker,
870
894
  systemProgram: SystemProgram.programId,
871
895
  })
@@ -879,7 +903,7 @@ export class NftStakingClient {
879
903
  return decodeAccount(raw);
880
904
  }
881
905
  async fetchStakerSecondaryRewards(poolId, wallet) {
882
- const [pda] = getStakerSecondaryRewardsPda(poolId, wallet);
906
+ const [pda] = getStakerSecondaryRewardsPda(poolId, toPk(wallet));
883
907
  const raw = await this.program.account.stakerSecondaryRewards.fetchNullable(pda);
884
908
  if (!raw)
885
909
  return null;
@@ -887,18 +911,19 @@ export class NftStakingClient {
887
911
  }
888
912
  async addPoolSecondaryReward(poolId, rewardMint, baseRate, lockTierRates, projectId) {
889
913
  const pid = this.resolveProjectId(projectId);
914
+ const _rewardMint = toPk(rewardMint);
890
915
  const [poolPda] = getStakePoolPda(pid, poolId);
891
916
  const [poolSecondary] = getPoolSecondaryRewardsPda(poolId);
892
917
  const [poolAuthority] = getPoolAuthorityPda(poolId);
893
- const tokenProgram = await this.resolveTokenProgram(rewardMint);
894
- const vault = getAta(poolAuthority, rewardMint, tokenProgram);
918
+ const tokenProgram = await this.resolveTokenProgram(_rewardMint);
919
+ const vault = getAta(poolAuthority, _rewardMint, tokenProgram);
895
920
  return this.program.methods
896
- .addPoolSecondaryReward(new BN(pid), new BN(poolId), baseRate, lockTierRates)
921
+ .addPoolSecondaryReward(new BN(pid), new BN(poolId), toBN(baseRate), lockTierRates.map(toBN))
897
922
  .accountsStrict({
898
923
  pool: poolPda,
899
924
  poolSecondary,
900
925
  poolAuthority,
901
- secondaryRewardMint: rewardMint,
926
+ secondaryRewardMint: _rewardMint,
902
927
  secondaryVault: vault,
903
928
  authority: this.provider.wallet.publicKey,
904
929
  tokenProgram,
@@ -922,21 +947,22 @@ export class NftStakingClient {
922
947
  }
923
948
  async fundSecondaryVault(poolId, rewardIndex, amount, rewardMint, opts) {
924
949
  const pid = this.resolveProjectId(opts?.projectId);
925
- const tokenProgram = await this.resolveTokenProgram(rewardMint);
950
+ const _rewardMint = toPk(rewardMint);
951
+ const tokenProgram = await this.resolveTokenProgram(_rewardMint);
926
952
  const [poolPda] = getStakePoolPda(pid, poolId);
927
953
  const [poolSecondary] = getPoolSecondaryRewardsPda(poolId);
928
954
  const [poolAuthority] = getPoolAuthorityPda(poolId);
929
- const vault = getAta(poolAuthority, rewardMint, tokenProgram);
930
- const funderAta = opts?.funderTokenAccount ?? getAta(this.provider.wallet.publicKey, rewardMint, tokenProgram);
955
+ const vault = getAta(poolAuthority, _rewardMint, tokenProgram);
956
+ const funderAta = opts?.funderTokenAccount ? toPk(opts.funderTokenAccount) : getAta(this.provider.wallet.publicKey, _rewardMint, tokenProgram);
931
957
  return this.program.methods
932
- .fundSecondaryVault(new BN(pid), new BN(poolId), rewardIndex, amount)
958
+ .fundSecondaryVault(new BN(pid), new BN(poolId), rewardIndex, toBN(amount))
933
959
  .accountsStrict({
934
960
  pool: poolPda,
935
961
  poolSecondary,
936
962
  poolAuthority,
937
963
  secondaryVault: vault,
938
964
  funderTokenAccount: funderAta,
939
- secondaryRewardMint: rewardMint,
965
+ secondaryRewardMint: _rewardMint,
940
966
  authority: this.provider.wallet.publicKey,
941
967
  tokenProgram,
942
968
  })
@@ -944,21 +970,22 @@ export class NftStakingClient {
944
970
  }
945
971
  async withdrawSecondaryVault(poolId, rewardIndex, amount, rewardMint, opts) {
946
972
  const pid = this.resolveProjectId(opts?.projectId);
947
- const tokenProgram = await this.resolveTokenProgram(rewardMint);
973
+ const _rewardMint = toPk(rewardMint);
974
+ const tokenProgram = await this.resolveTokenProgram(_rewardMint);
948
975
  const [poolPda] = getStakePoolPda(pid, poolId);
949
976
  const [poolSecondary] = getPoolSecondaryRewardsPda(poolId);
950
977
  const [poolAuthority] = getPoolAuthorityPda(poolId);
951
- const vault = getAta(poolAuthority, rewardMint, tokenProgram);
952
- const destAta = opts?.destinationTokenAccount ?? getAta(this.provider.wallet.publicKey, rewardMint, tokenProgram);
978
+ const vault = getAta(poolAuthority, _rewardMint, tokenProgram);
979
+ const destAta = opts?.destinationTokenAccount ? toPk(opts.destinationTokenAccount) : getAta(this.provider.wallet.publicKey, _rewardMint, tokenProgram);
953
980
  return this.program.methods
954
- .withdrawSecondaryVault(new BN(pid), new BN(poolId), rewardIndex, amount)
981
+ .withdrawSecondaryVault(new BN(pid), new BN(poolId), rewardIndex, toBN(amount))
955
982
  .accountsStrict({
956
983
  pool: poolPda,
957
984
  poolSecondary,
958
985
  poolAuthority,
959
986
  secondaryVault: vault,
960
987
  destinationTokenAccount: destAta,
961
- secondaryRewardMint: rewardMint,
988
+ secondaryRewardMint: _rewardMint,
962
989
  authority: this.provider.wallet.publicKey,
963
990
  tokenProgram,
964
991
  })
@@ -990,12 +1017,14 @@ export class NftStakingClient {
990
1017
  const [stakerSecondary] = getStakerSecondaryRewardsPda(poolId, staker);
991
1018
  const [poolAuthority] = getPoolAuthorityPda(poolId);
992
1019
  const feeAccts = this.resolveFeeAccounts(opts?.fee);
1020
+ const [project] = getProjectPda(pid);
993
1021
  const remainingAccounts = [];
994
1022
  for (const sr of secondaryRewards) {
995
- const tokenProgram = await this.resolveTokenProgram(sr.mint);
996
- const vault = getAta(poolAuthority, sr.mint, tokenProgram);
997
- const stakerAta = getAta(staker, sr.mint, tokenProgram);
998
- remainingAccounts.push({ pubkey: vault, isSigner: false, isWritable: true }, { pubkey: stakerAta, isSigner: false, isWritable: true }, { pubkey: sr.mint, isSigner: false, isWritable: false }, { pubkey: tokenProgram, isSigner: false, isWritable: false });
1023
+ const _srMint = toPk(sr.mint);
1024
+ const tokenProgram = await this.resolveTokenProgram(_srMint);
1025
+ const vault = getAta(poolAuthority, _srMint, tokenProgram);
1026
+ const stakerAta = getAta(staker, _srMint, tokenProgram);
1027
+ remainingAccounts.push({ pubkey: vault, isSigner: false, isWritable: true }, { pubkey: stakerAta, isSigner: false, isWritable: true }, { pubkey: _srMint, isSigner: false, isWritable: false }, { pubkey: tokenProgram, isSigner: false, isWritable: false });
999
1028
  }
1000
1029
  return this.program.methods
1001
1030
  .claimSecondaryRewards(new BN(pid), new BN(poolId))
@@ -1006,10 +1035,12 @@ export class NftStakingClient {
1006
1035
  stakerSecondary,
1007
1036
  poolAuthority,
1008
1037
  feeConfig: feeAccts.feeConfig,
1038
+ programRegistry: feeAccts.programRegistry,
1009
1039
  treasury: feeAccts.treasury,
1010
1040
  referralAccount: feeAccts.referralAccount,
1011
1041
  solUsdPriceFeed: feeAccts.solUsdPriceFeed,
1012
1042
  adminProgram: feeAccts.adminProgram,
1043
+ project,
1013
1044
  staker,
1014
1045
  tokenProgram: TOKEN_PROGRAM_ID,
1015
1046
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -1018,5 +1049,18 @@ export class NftStakingClient {
1018
1049
  .remainingAccounts(remainingAccounts)
1019
1050
  .instruction();
1020
1051
  }
1052
+ async updatePoolSecondaryReward(poolId, rewardIndex, baseRate, lockTierRates, projectId) {
1053
+ const pid = this.resolveProjectId(projectId);
1054
+ const [poolPda] = getStakePoolPda(pid, poolId);
1055
+ const [poolSecondary] = getPoolSecondaryRewardsPda(poolId);
1056
+ return this.program.methods
1057
+ .updatePoolSecondaryReward(new BN(pid), new BN(poolId), rewardIndex, toBN(baseRate), lockTierRates.map(toBN))
1058
+ .accountsStrict({
1059
+ pool: poolPda,
1060
+ poolSecondary,
1061
+ authority: this.provider.wallet.publicKey,
1062
+ })
1063
+ .instruction();
1064
+ }
1021
1065
  }
1022
1066
  //# sourceMappingURL=client.js.map