@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.
- package/lib/stake.browser.js +54 -11
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +958 -0
- package/lib/stake.js +58 -11
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +54 -11
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/solana/solana.ts +107 -14
- package/src/staker.ts +1 -1
package/lib/stake.js
CHANGED
|
@@ -9152,7 +9152,7 @@ var __async$8 = (__this, __arguments, generator) => {
|
|
|
9152
9152
|
};
|
|
9153
9153
|
const commitment = "confirmed";
|
|
9154
9154
|
const SCALE = new anchor.BN("1000000000000");
|
|
9155
|
-
class
|
|
9155
|
+
const _SolanaStakingClient = class _SolanaStakingClient {
|
|
9156
9156
|
constructor(config) {
|
|
9157
9157
|
this.config = config;
|
|
9158
9158
|
const adapter = config.provider;
|
|
@@ -9232,6 +9232,7 @@ class SolanaStakingClient {
|
|
|
9232
9232
|
this.leaderboardClient = new LeaderboardClient(this.anchor);
|
|
9233
9233
|
this.outpostClient = new OutpostClient(this.anchor);
|
|
9234
9234
|
this.tokenClient = new TokenClient(this.anchor);
|
|
9235
|
+
this.program = new SolanaProgramService(this.anchor);
|
|
9235
9236
|
}
|
|
9236
9237
|
get solPubKey() {
|
|
9237
9238
|
if (!this.pubKey) throw new Error("pubKey is undefined");
|
|
@@ -9412,18 +9413,62 @@ class SolanaStakingClient {
|
|
|
9412
9413
|
}
|
|
9413
9414
|
getSystemAPY() {
|
|
9414
9415
|
return __async$8(this, null, function* () {
|
|
9415
|
-
const
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
const
|
|
9420
|
-
|
|
9421
|
-
const ratePerPeriod = avgPayRate.toNumber() / SCALE2.toNumber();
|
|
9422
|
-
const apyDecimal = ratePerPeriod * EPOCHS_PER_YEAR;
|
|
9416
|
+
const ratePerEpoch = yield this.getEpochRateDecimalFromProgram();
|
|
9417
|
+
console.log("epochRateDecimal", ratePerEpoch);
|
|
9418
|
+
const epochsPerYear = yield this.getEpochsPerYearFromCluster();
|
|
9419
|
+
console.log("epochsPerYear", epochsPerYear);
|
|
9420
|
+
const apyDecimal = Math.pow(1 + ratePerEpoch, epochsPerYear) - 1;
|
|
9421
|
+
console.log("apyDecimal", apyDecimal);
|
|
9423
9422
|
const apyPercent = apyDecimal * 100;
|
|
9423
|
+
console.log("apyPercent", apyPercent);
|
|
9424
9424
|
return apyPercent;
|
|
9425
9425
|
});
|
|
9426
9426
|
}
|
|
9427
|
+
getEpochRateDecimalFromProgram() {
|
|
9428
|
+
return __async$8(this, null, function* () {
|
|
9429
|
+
const liqSolCoreProgram = this.program.getProgram("liqsolCore");
|
|
9430
|
+
const stakeMetricsPda = deriveStakeMetricsPda();
|
|
9431
|
+
const stakeMetrics = yield liqSolCoreProgram.account.stakeMetrics.fetch(stakeMetricsPda);
|
|
9432
|
+
const raw = BigInt(stakeMetrics.solSystemPayRate.toString());
|
|
9433
|
+
const rateDecimal = Number(raw) / Number(PAY_RATE_SCALE_FACTOR);
|
|
9434
|
+
console.log("solSystemPayRate(raw)", raw.toString());
|
|
9435
|
+
console.log("epochRateDecimal(computed)", rateDecimal);
|
|
9436
|
+
return rateDecimal;
|
|
9437
|
+
});
|
|
9438
|
+
}
|
|
9439
|
+
getEpochsPerYearFromCluster() {
|
|
9440
|
+
return __async$8(this, null, function* () {
|
|
9441
|
+
const now = Date.now();
|
|
9442
|
+
if (this.epochsPerYearCache && now - this.epochsPerYearCache.fetchedAt < _SolanaStakingClient.EPOCHS_PER_YEAR_TTL_MS) {
|
|
9443
|
+
return this.epochsPerYearCache.value;
|
|
9444
|
+
}
|
|
9445
|
+
const connection = this.anchor.connection;
|
|
9446
|
+
const samples = yield connection.getRecentPerformanceSamples(
|
|
9447
|
+
60
|
|
9448
|
+
);
|
|
9449
|
+
if (!samples.length) {
|
|
9450
|
+
throw new Error("No performance samples available from cluster");
|
|
9451
|
+
}
|
|
9452
|
+
const totalSlots = samples.reduce((acc, s) => acc + s.numSlots, 0);
|
|
9453
|
+
const totalSecs = samples.reduce((acc, s) => acc + s.samplePeriodSecs, 0);
|
|
9454
|
+
if (totalSecs === 0) {
|
|
9455
|
+
throw new Error(
|
|
9456
|
+
"Cluster returned zero samplePeriodSecs in performance samples"
|
|
9457
|
+
);
|
|
9458
|
+
}
|
|
9459
|
+
const slotsPerSecond = totalSlots / totalSecs;
|
|
9460
|
+
const epochInfo = yield connection.getEpochInfo();
|
|
9461
|
+
const slotsPerEpoch = epochInfo.slotsInEpoch;
|
|
9462
|
+
const secondsPerEpoch = slotsPerEpoch / slotsPerSecond;
|
|
9463
|
+
const secondsPerYear = 365 * 24 * 60 * 60;
|
|
9464
|
+
const epochsPerYear = secondsPerYear / secondsPerEpoch;
|
|
9465
|
+
this.epochsPerYearCache = {
|
|
9466
|
+
value: epochsPerYear,
|
|
9467
|
+
fetchedAt: now
|
|
9468
|
+
};
|
|
9469
|
+
return epochsPerYear;
|
|
9470
|
+
});
|
|
9471
|
+
}
|
|
9427
9472
|
getDepositFee(amountLamports, windowSize = 5) {
|
|
9428
9473
|
return __async$8(this, null, function* () {
|
|
9429
9474
|
var _a, _b, _c;
|
|
@@ -9561,7 +9606,9 @@ class SolanaStakingClient {
|
|
|
9561
9606
|
);
|
|
9562
9607
|
}
|
|
9563
9608
|
}
|
|
9564
|
-
}
|
|
9609
|
+
};
|
|
9610
|
+
_SolanaStakingClient.EPOCHS_PER_YEAR_TTL_MS = 10 * 60 * 1e3;
|
|
9611
|
+
let SolanaStakingClient = _SolanaStakingClient;
|
|
9565
9612
|
|
|
9566
9613
|
var _format$q = "hh-sol-artifact-1";
|
|
9567
9614
|
var contractName$q = "Accounting";
|
|
@@ -36600,7 +36647,7 @@ class Staker {
|
|
|
36600
36647
|
if (!Array.isArray(config)) config = [config];
|
|
36601
36648
|
config.forEach((cfg) => {
|
|
36602
36649
|
switch (cfg.network.chainId) {
|
|
36603
|
-
case core.SolChainID.
|
|
36650
|
+
case core.SolChainID.Devnet:
|
|
36604
36651
|
this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
|
|
36605
36652
|
break;
|
|
36606
36653
|
case core.EvmChainID.Hoodi:
|