@wireio/stake 0.5.1 → 0.5.2

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.
@@ -8880,7 +8880,7 @@ class TokenClient {
8880
8880
 
8881
8881
  const commitment = "confirmed";
8882
8882
  const SCALE = new BN("1000000000000");
8883
- class SolanaStakingClient {
8883
+ const _SolanaStakingClient = class _SolanaStakingClient {
8884
8884
  constructor(config) {
8885
8885
  this.config = config;
8886
8886
  const adapter = config.provider;
@@ -8952,6 +8952,7 @@ class SolanaStakingClient {
8952
8952
  this.leaderboardClient = new LeaderboardClient(this.anchor);
8953
8953
  this.outpostClient = new OutpostClient(this.anchor);
8954
8954
  this.tokenClient = new TokenClient(this.anchor);
8955
+ this.program = new SolanaProgramService(this.anchor);
8955
8956
  }
8956
8957
  get solPubKey() {
8957
8958
  if (!this.pubKey) throw new Error("pubKey is undefined");
@@ -9116,17 +9117,57 @@ class SolanaStakingClient {
9116
9117
  return this.distributionClient.getUserRecord(this.solPubKey);
9117
9118
  }
9118
9119
  async getSystemAPY() {
9119
- const avgPayRate = await this.distributionClient.getAverageScaledPayRate(5);
9120
- if (avgPayRate.isZero()) {
9121
- return 0;
9122
- }
9123
- const SCALE2 = new BN("1000000000000");
9124
- const EPOCHS_PER_YEAR = 365;
9125
- const ratePerPeriod = avgPayRate.toNumber() / SCALE2.toNumber();
9126
- const apyDecimal = ratePerPeriod * EPOCHS_PER_YEAR;
9120
+ const ratePerEpoch = await this.getEpochRateDecimalFromProgram();
9121
+ console.log("epochRateDecimal", ratePerEpoch);
9122
+ const epochsPerYear = await this.getEpochsPerYearFromCluster();
9123
+ console.log("epochsPerYear", epochsPerYear);
9124
+ const apyDecimal = Math.pow(1 + ratePerEpoch, epochsPerYear) - 1;
9125
+ console.log("apyDecimal", apyDecimal);
9127
9126
  const apyPercent = apyDecimal * 100;
9127
+ console.log("apyPercent", apyPercent);
9128
9128
  return apyPercent;
9129
9129
  }
9130
+ async getEpochRateDecimalFromProgram() {
9131
+ const liqSolCoreProgram = this.program.getProgram("liqsolCore");
9132
+ const stakeMetricsPda = deriveStakeMetricsPda();
9133
+ const stakeMetrics = await liqSolCoreProgram.account.stakeMetrics.fetch(stakeMetricsPda);
9134
+ const raw = BigInt(stakeMetrics.solSystemPayRate.toString());
9135
+ const rateDecimal = Number(raw) / Number(PAY_RATE_SCALE_FACTOR);
9136
+ console.log("solSystemPayRate(raw)", raw.toString());
9137
+ console.log("epochRateDecimal(computed)", rateDecimal);
9138
+ return rateDecimal;
9139
+ }
9140
+ async getEpochsPerYearFromCluster() {
9141
+ const now = Date.now();
9142
+ if (this.epochsPerYearCache && now - this.epochsPerYearCache.fetchedAt < _SolanaStakingClient.EPOCHS_PER_YEAR_TTL_MS) {
9143
+ return this.epochsPerYearCache.value;
9144
+ }
9145
+ const connection = this.anchor.connection;
9146
+ const samples = await connection.getRecentPerformanceSamples(
9147
+ 60
9148
+ );
9149
+ if (!samples.length) {
9150
+ throw new Error("No performance samples available from cluster");
9151
+ }
9152
+ const totalSlots = samples.reduce((acc, s) => acc + s.numSlots, 0);
9153
+ const totalSecs = samples.reduce((acc, s) => acc + s.samplePeriodSecs, 0);
9154
+ if (totalSecs === 0) {
9155
+ throw new Error(
9156
+ "Cluster returned zero samplePeriodSecs in performance samples"
9157
+ );
9158
+ }
9159
+ const slotsPerSecond = totalSlots / totalSecs;
9160
+ const epochInfo = await connection.getEpochInfo();
9161
+ const slotsPerEpoch = epochInfo.slotsInEpoch;
9162
+ const secondsPerEpoch = slotsPerEpoch / slotsPerSecond;
9163
+ const secondsPerYear = 365 * 24 * 60 * 60;
9164
+ const epochsPerYear = secondsPerYear / secondsPerEpoch;
9165
+ this.epochsPerYearCache = {
9166
+ value: epochsPerYear,
9167
+ fetchedAt: now
9168
+ };
9169
+ return epochsPerYear;
9170
+ }
9130
9171
  async getDepositFee(amountLamports, windowSize = 5) {
9131
9172
  if (amountLamports <= BigInt(0)) {
9132
9173
  return BigInt(0);
@@ -9248,7 +9289,9 @@ class SolanaStakingClient {
9248
9289
  );
9249
9290
  }
9250
9291
  }
9251
- }
9292
+ };
9293
+ _SolanaStakingClient.EPOCHS_PER_YEAR_TTL_MS = 10 * 60 * 1e3;
9294
+ let SolanaStakingClient = _SolanaStakingClient;
9252
9295
 
9253
9296
  var _format$q = "hh-sol-artifact-1";
9254
9297
  var contractName$q = "Accounting";
@@ -36046,7 +36089,7 @@ class Staker {
36046
36089
  if (!Array.isArray(config)) config = [config];
36047
36090
  config.forEach((cfg) => {
36048
36091
  switch (cfg.network.chainId) {
36049
- case SolChainID.WireTestnet:
36092
+ case SolChainID.Devnet:
36050
36093
  this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
36051
36094
  break;
36052
36095
  case EvmChainID.Hoodi: