@wireio/stake 0.7.3 → 1.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.
- package/lib/stake.browser.js +451 -1057
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +131 -542
- package/lib/stake.js +451 -1059
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +451 -1057
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/assets/solana/idl/liqsol_core.json +114 -377
- package/src/assets/solana/idl/validator_leaderboard.json +0 -146
- package/src/assets/solana/types/liqsol_core.ts +114 -377
- package/src/assets/solana/types/validator_leaderboard.ts +0 -146
- package/src/networks/ethereum/contract.ts +66 -31
- package/src/networks/ethereum/ethereum.ts +53 -53
- package/src/networks/ethereum/types.ts +1 -2
- package/src/networks/solana/constants.ts +1 -1
- package/src/networks/solana/solana.ts +262 -220
- package/src/staker.ts +1 -3
|
@@ -207,14 +207,18 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
207
207
|
throw new Error('Deposit amount must be greater than zero.');
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
210
|
+
try {
|
|
211
|
+
const tx = await this.depositClient.buildDepositTx(amountLamports);
|
|
212
|
+
const { tx: prepared, blockhash, lastValidBlockHeight } =
|
|
213
|
+
await this.prepareTx(tx);
|
|
214
|
+
const signed = await this.signTransaction(prepared);
|
|
215
|
+
return await this.sendAndConfirmHttp(signed, {
|
|
216
|
+
blockhash,
|
|
217
|
+
lastValidBlockHeight,
|
|
218
|
+
});
|
|
219
|
+
} catch (err) {
|
|
220
|
+
throw new Error(`Failed to deposit Solana: ${err}`);
|
|
221
|
+
}
|
|
218
222
|
}
|
|
219
223
|
|
|
220
224
|
/**
|
|
@@ -233,14 +237,18 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
233
237
|
throw new Error('Withdraw amount must be greater than zero.');
|
|
234
238
|
}
|
|
235
239
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
try {
|
|
241
|
+
const tx = await this.depositClient.buildWithdrawTx(amountLamports);
|
|
242
|
+
const { tx: prepared, blockhash, lastValidBlockHeight } =
|
|
243
|
+
await this.prepareTx(tx);
|
|
244
|
+
const signed = await this.signTransaction(prepared);
|
|
245
|
+
return await this.sendAndConfirmHttp(signed, {
|
|
246
|
+
blockhash,
|
|
247
|
+
lastValidBlockHeight,
|
|
248
|
+
});
|
|
249
|
+
} catch (err) {
|
|
250
|
+
throw new Error(`Failed to withdraw Solana: ${err}`);
|
|
251
|
+
}
|
|
244
252
|
}
|
|
245
253
|
|
|
246
254
|
/**
|
|
@@ -253,20 +261,24 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
253
261
|
throw new Error('Stake amount must be greater than zero.');
|
|
254
262
|
}
|
|
255
263
|
|
|
256
|
-
|
|
264
|
+
try {
|
|
265
|
+
const user = this.solPubKey;
|
|
257
266
|
|
|
258
|
-
|
|
259
|
-
|
|
267
|
+
// Build compute budget increase instruction
|
|
268
|
+
const cuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 400_000 });
|
|
260
269
|
|
|
261
|
-
|
|
262
|
-
|
|
270
|
+
// Build the Outpost synd instruction
|
|
271
|
+
const ix = await this.outpostClient.buildStakeIx(amountLamports, user);
|
|
263
272
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
273
|
+
// Wrap in a transaction and send
|
|
274
|
+
const tx = new Transaction().add(cuIx, ix);
|
|
275
|
+
const prepared = await this.prepareTx(tx);
|
|
276
|
+
const signed = await this.signTransaction(prepared.tx);
|
|
268
277
|
|
|
269
|
-
|
|
278
|
+
return this.sendAndConfirmHttp(signed, prepared);
|
|
279
|
+
} catch (err) {
|
|
280
|
+
throw new Error(`Failed to stake Solana: ${err}`);
|
|
281
|
+
}
|
|
270
282
|
}
|
|
271
283
|
|
|
272
284
|
/**
|
|
@@ -279,20 +291,25 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
279
291
|
throw new Error('Unstake amount must be greater than zero.');
|
|
280
292
|
}
|
|
281
293
|
|
|
282
|
-
|
|
294
|
+
try {
|
|
295
|
+
const user = this.solPubKey;
|
|
283
296
|
|
|
284
|
-
|
|
285
|
-
|
|
297
|
+
// Build compute budget increase instruction
|
|
298
|
+
const cuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 400_000 });
|
|
286
299
|
|
|
287
|
-
|
|
288
|
-
|
|
300
|
+
// Build the Outpost desynd instruction
|
|
301
|
+
const ix = await this.outpostClient.buildUnstakeIx(amountLamports, user);
|
|
289
302
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
303
|
+
// Wrap in a transaction and send
|
|
304
|
+
const tx = new Transaction().add(cuIx, ix);
|
|
305
|
+
const prepared = await this.prepareTx(tx);
|
|
306
|
+
const signed = await this.signTransaction(prepared.tx);
|
|
294
307
|
|
|
295
|
-
|
|
308
|
+
return this.sendAndConfirmHttp(signed, prepared);
|
|
309
|
+
}
|
|
310
|
+
catch (err) {
|
|
311
|
+
throw new Error(`Failed to unstake Solana: ${err}`);
|
|
312
|
+
}
|
|
296
313
|
}
|
|
297
314
|
|
|
298
315
|
/**
|
|
@@ -307,17 +324,22 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
307
324
|
throw new Error('liqSOL pretoken purchase requires a positive amount.');
|
|
308
325
|
}
|
|
309
326
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
327
|
+
try {
|
|
328
|
+
const user = this.solPubKey;
|
|
329
|
+
const cuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 400_000 });
|
|
330
|
+
const ix = await this.tokenClient.buildPurchaseIx(amountLamports, user);
|
|
331
|
+
const tx = new Transaction().add(cuIx, ix);
|
|
332
|
+
const { tx: prepared, blockhash, lastValidBlockHeight } =
|
|
333
|
+
await this.prepareTx(tx);
|
|
334
|
+
const signed = await this.signTransaction(prepared);
|
|
335
|
+
return await this.sendAndConfirmHttp(signed, {
|
|
336
|
+
blockhash,
|
|
337
|
+
lastValidBlockHeight,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
throw new Error(`Failed to buy liqSOL pretokens: ${err}`);
|
|
342
|
+
}
|
|
321
343
|
}
|
|
322
344
|
|
|
323
345
|
/**
|
|
@@ -332,140 +354,145 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
332
354
|
async getPortfolio(): Promise<Portfolio> {
|
|
333
355
|
if (!this.pubKey) throw new Error('User pubKey is undefined');
|
|
334
356
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
// NOTE:
|
|
350
|
-
// - nativeLamports: wallet SOL
|
|
351
|
-
// - actualBalResp: liqSOL balance in user ATA
|
|
352
|
-
// - snapshot: Outpost + pretokens + global index/shares
|
|
353
|
-
const [nativeLamports, actualBalResp, snapshot] = await Promise.all([
|
|
354
|
-
this.connection.getBalance(user, 'confirmed'),
|
|
355
|
-
this.connection
|
|
356
|
-
.getTokenAccountBalance(userLiqsolAta, 'confirmed')
|
|
357
|
-
.catch(() => null),
|
|
358
|
-
this.outpostClient.fetchWireState(user).catch(() => null),
|
|
359
|
-
]);
|
|
357
|
+
try {
|
|
358
|
+
const user = this.solPubKey;
|
|
359
|
+
|
|
360
|
+
const reservePoolPDA = deriveReservePoolPda();
|
|
361
|
+
const vaultPDA = deriveVaultPda();
|
|
362
|
+
const liqsolMint = deriveLiqsolMintPda();
|
|
363
|
+
|
|
364
|
+
const userLiqsolAta = getAssociatedTokenAddressSync(
|
|
365
|
+
liqsolMint,
|
|
366
|
+
user,
|
|
367
|
+
false,
|
|
368
|
+
TOKEN_2022_PROGRAM_ID,
|
|
369
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
370
|
+
);
|
|
360
371
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
372
|
+
// NOTE:
|
|
373
|
+
// - nativeLamports: wallet SOL
|
|
374
|
+
// - actualBalResp: liqSOL balance in user ATA
|
|
375
|
+
// - snapshot: Outpost + pretokens + global index/shares
|
|
376
|
+
const [nativeLamports, actualBalResp, snapshot] = await Promise.all([
|
|
377
|
+
this.connection.getBalance(user, 'confirmed'),
|
|
378
|
+
this.connection
|
|
379
|
+
.getTokenAccountBalance(userLiqsolAta, 'confirmed')
|
|
380
|
+
.catch(() => null),
|
|
381
|
+
this.outpostClient.fetchWireState(user).catch(() => null),
|
|
382
|
+
]);
|
|
383
|
+
|
|
384
|
+
const LIQSOL_DECIMALS = 9;
|
|
385
|
+
|
|
386
|
+
const actualAmountStr = actualBalResp?.value?.amount ?? '0';
|
|
387
|
+
|
|
388
|
+
const globalState = snapshot?.globalState ?? null;
|
|
389
|
+
const outpostAccount = snapshot?.outpostAccount ?? null;
|
|
390
|
+
const trancheState = snapshot?.trancheState ?? null;
|
|
391
|
+
const userPretokenRecord = snapshot?.userPretokenRecord ?? null;
|
|
392
|
+
|
|
393
|
+
// -----------------------------
|
|
394
|
+
// Staked liqSOL (Outpost)
|
|
395
|
+
// -----------------------------
|
|
396
|
+
// This is the liqSOL that has been syndicated into Outpost via `synd`.
|
|
397
|
+
// It lives on the outpost account as `stakedLiqsol`.
|
|
398
|
+
const stakedLiqsolStr =
|
|
399
|
+
outpostAccount?.stakedLiqsol?.toString?.() ?? '0';
|
|
400
|
+
|
|
401
|
+
// -----------------------------
|
|
402
|
+
// WIRE pretokens (1e8 scale)
|
|
403
|
+
// -----------------------------
|
|
404
|
+
// This is NOT stake — it’s the prelaunch WIRE position.
|
|
405
|
+
const wirePretokensStr =
|
|
406
|
+
userPretokenRecord?.totalPretokensPurchased?.toString?.() ??
|
|
407
|
+
'0';
|
|
408
|
+
|
|
409
|
+
// -----------------------------
|
|
410
|
+
// Yield view (index + shares)
|
|
411
|
+
// -----------------------------
|
|
412
|
+
// We expose:
|
|
413
|
+
// - currentIndex: globalState.currentIndex (1e12 scale)
|
|
414
|
+
// - totalShares: globalState.totalShares
|
|
415
|
+
// - userShares: outpostAccount.stakedShares
|
|
416
|
+
// - estimatedClaimLiqsol: floor(userShares * index / INDEX_SCALE)
|
|
417
|
+
// - estimatedYield: max(0, estimatedClaim - stakedLiqsol)
|
|
418
|
+
//
|
|
419
|
+
// This matches the capital-staking math:
|
|
420
|
+
// sharesToTokens(shares, index) = shares * index / INDEX_SCALE
|
|
421
|
+
const currentIndexStr =
|
|
422
|
+
globalState?.currentIndex?.toString?.() ?? '0';
|
|
423
|
+
const totalSharesStr =
|
|
424
|
+
globalState?.totalShares?.toString?.() ?? '0';
|
|
425
|
+
const userSharesStr =
|
|
426
|
+
outpostAccount?.stakedShares?.toString?.() ?? '0';
|
|
427
|
+
|
|
428
|
+
const stakedLiqsol = BigInt(stakedLiqsolStr);
|
|
429
|
+
const currentIndex = BigInt(currentIndexStr);
|
|
430
|
+
const totalShares = BigInt(totalSharesStr);
|
|
431
|
+
const userShares = BigInt(userSharesStr);
|
|
432
|
+
|
|
433
|
+
let estimatedClaim = BigInt(0);
|
|
434
|
+
let estimatedYield = BigInt(0);
|
|
435
|
+
|
|
436
|
+
if (userShares > BigInt(0) && currentIndex > BigInt(0)) {
|
|
437
|
+
// sharesToTokens(userShares, currentIndex)
|
|
438
|
+
estimatedClaim = (userShares * currentIndex) / INDEX_SCALE;
|
|
439
|
+
|
|
440
|
+
if (estimatedClaim > stakedLiqsol) {
|
|
441
|
+
estimatedYield = estimatedClaim - stakedLiqsol;
|
|
442
|
+
}
|
|
419
443
|
}
|
|
420
|
-
}
|
|
421
444
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
445
|
+
return {
|
|
446
|
+
native: {
|
|
447
|
+
amount: BigInt(nativeLamports),
|
|
448
|
+
symbol: 'SOL',
|
|
449
|
+
decimals: 9,
|
|
450
|
+
},
|
|
451
|
+
liq: {
|
|
452
|
+
amount: BigInt(actualAmountStr),
|
|
453
|
+
symbol: 'LiqSOL',
|
|
454
|
+
decimals: LIQSOL_DECIMALS,
|
|
455
|
+
ata: userLiqsolAta,
|
|
456
|
+
},
|
|
457
|
+
staked: {
|
|
458
|
+
// liqSOL staked in Outpost via `synd`
|
|
459
|
+
amount: stakedLiqsol,
|
|
460
|
+
symbol: 'LiqSOL',
|
|
461
|
+
decimals: LIQSOL_DECIMALS,
|
|
462
|
+
},
|
|
463
|
+
wire: {
|
|
464
|
+
// Prelaunch WIRE pretokens (1e8 scale)
|
|
465
|
+
amount: BigInt(wirePretokensStr),
|
|
466
|
+
symbol: '$WIRE',
|
|
467
|
+
decimals: 8,
|
|
468
|
+
},
|
|
469
|
+
yield: {
|
|
470
|
+
// Raw primitives so the frontend can display curves, charts, etc.
|
|
471
|
+
currentIndex,
|
|
472
|
+
indexScale: INDEX_SCALE,
|
|
473
|
+
totalShares,
|
|
474
|
+
userShares,
|
|
475
|
+
// liqSOL amounts (lamports) implied by index/shares
|
|
476
|
+
estimatedClaim,
|
|
477
|
+
estimatedYield,
|
|
478
|
+
},
|
|
479
|
+
extras: {
|
|
480
|
+
userLiqsolAta: userLiqsolAta.toBase58(),
|
|
481
|
+
reservePoolPDA: reservePoolPDA.toBase58(),
|
|
482
|
+
vaultPDA: vaultPDA.toBase58(),
|
|
483
|
+
globalIndex: globalState?.currentIndex?.toString(),
|
|
484
|
+
totalShares: globalState?.totalShares?.toString(),
|
|
485
|
+
currentTrancheNumber:
|
|
486
|
+
trancheState?.currentTrancheNumber?.toString(),
|
|
487
|
+
currentTranchePriceUsd:
|
|
488
|
+
trancheState?.currentTranchePriceUsd?.toString(), // 1e8 USD
|
|
489
|
+
},
|
|
490
|
+
chainID: this.network.chainId,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
catch (err) {
|
|
494
|
+
throw new Error(`Failed to get Solana portfolio: ${err}`);
|
|
495
|
+
}
|
|
469
496
|
}
|
|
470
497
|
|
|
471
498
|
/**
|
|
@@ -497,29 +524,34 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
497
524
|
windowBefore?: number;
|
|
498
525
|
windowAfter?: number;
|
|
499
526
|
}): Promise<TrancheSnapshot> {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
527
|
+
try {
|
|
528
|
+
const {
|
|
529
|
+
chainID = SolChainID.WireTestnet,
|
|
530
|
+
windowBefore,
|
|
531
|
+
windowAfter,
|
|
532
|
+
} = options ?? {};
|
|
533
|
+
|
|
534
|
+
const [globalState, trancheState] = await Promise.all([
|
|
535
|
+
this.tokenClient.fetchGlobalState(),
|
|
536
|
+
this.tokenClient.fetchTrancheState(),
|
|
537
|
+
]);
|
|
538
|
+
|
|
539
|
+
const { price: solPriceUsd, timestamp } =
|
|
540
|
+
await this.tokenClient.getSolPriceUsdSafe();
|
|
541
|
+
|
|
542
|
+
return buildSolanaTrancheSnapshot({
|
|
543
|
+
chainID,
|
|
544
|
+
globalState,
|
|
545
|
+
trancheState,
|
|
546
|
+
solPriceUsd,
|
|
547
|
+
nativePriceTimestamp: timestamp,
|
|
548
|
+
ladderWindowBefore: windowBefore,
|
|
549
|
+
ladderWindowAfter: windowAfter,
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
catch (err) {
|
|
553
|
+
throw new Error(`Failed to build Solana tranche snapshot: ${err}`);
|
|
554
|
+
}
|
|
523
555
|
}
|
|
524
556
|
|
|
525
557
|
/**
|
|
@@ -528,16 +560,20 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
528
560
|
* cluster-derived epochs-per-year.
|
|
529
561
|
*/
|
|
530
562
|
async getSystemAPY(): Promise<number> {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
563
|
+
try {
|
|
564
|
+
// 1) Per-epoch rate (decimal) from on-chain stakeMetrics
|
|
565
|
+
const ratePerEpoch = await this.getEpochRateDecimalFromProgram();
|
|
566
|
+
// 2) Live epochs-per-year estimate from cluster
|
|
567
|
+
const epochsPerYear = await this.getEpochsPerYearFromCluster();
|
|
568
|
+
// 3) Compound: (1 + r)^N - 1
|
|
569
|
+
const apyDecimal = Math.pow(1 + ratePerEpoch, epochsPerYear) - 1;
|
|
570
|
+
// 4) Convert to percent
|
|
571
|
+
const apyPercent = apyDecimal * 100;
|
|
572
|
+
|
|
573
|
+
return apyPercent;
|
|
574
|
+
} catch (err) {
|
|
575
|
+
throw new Error(`Failed to compute Solana system APY: ${err}`);
|
|
576
|
+
}
|
|
541
577
|
}
|
|
542
578
|
|
|
543
579
|
/**
|
|
@@ -546,18 +582,24 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
546
582
|
* de-scaled using PAY_RATE_SCALE_FACTOR (1e12).
|
|
547
583
|
*/
|
|
548
584
|
private async getEpochRateDecimalFromProgram(): Promise<number> {
|
|
549
|
-
|
|
550
|
-
const stakeMetricsPda = deriveStakeMetricsPda();
|
|
551
|
-
const stakeMetrics =
|
|
552
|
-
await liqSolCoreProgram.account.stakeMetrics.fetch(stakeMetricsPda);
|
|
585
|
+
try {
|
|
553
586
|
|
|
554
|
-
|
|
555
|
-
|
|
587
|
+
const liqSolCoreProgram = this.program.getProgram('liqsolCore');
|
|
588
|
+
const stakeMetricsPda = deriveStakeMetricsPda();
|
|
589
|
+
const stakeMetrics =
|
|
590
|
+
await liqSolCoreProgram.account.stakeMetrics.fetch(stakeMetricsPda);
|
|
556
591
|
|
|
557
|
-
|
|
558
|
-
|
|
592
|
+
// solSystemPayRate is stored on-chain with PAY_RATE_SCALE_FACTOR (1e12)
|
|
593
|
+
const raw = BigInt(stakeMetrics.solSystemPayRate.toString());
|
|
559
594
|
|
|
560
|
-
|
|
595
|
+
// Convert to JS number in **decimal per epoch** units
|
|
596
|
+
const rateDecimal = Number(raw) / Number(PAY_RATE_SCALE_FACTOR);
|
|
597
|
+
|
|
598
|
+
return rateDecimal;
|
|
599
|
+
}
|
|
600
|
+
catch (err) {
|
|
601
|
+
throw new Error(`Failed to read stakeMetrics from program: ${err}`);
|
|
602
|
+
}
|
|
561
603
|
}
|
|
562
604
|
|
|
563
605
|
// Simple cache so we don’t hammer RPC
|
package/src/staker.ts
CHANGED
|
@@ -36,13 +36,11 @@ export class Staker {
|
|
|
36
36
|
|
|
37
37
|
config.forEach((cfg) => {
|
|
38
38
|
switch (cfg.network.chainId) {
|
|
39
|
-
case SolChainID.
|
|
40
|
-
case SolChainID.WireTestnet:
|
|
39
|
+
case SolChainID.Mainnet:
|
|
41
40
|
this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
|
|
42
41
|
break;
|
|
43
42
|
|
|
44
43
|
case EvmChainID.Ethereum:
|
|
45
|
-
case EvmChainID.Hoodi:
|
|
46
44
|
this.clients.set(cfg.network.chainId, new EthereumStakingClient(cfg));
|
|
47
45
|
break;
|
|
48
46
|
|