@wireio/stake 0.7.0 → 0.7.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.
@@ -9232,23 +9232,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9232
9232
  }
9233
9233
  let gasBuffer = BigInt(0);
9234
9234
  try {
9235
- const dummyIx = SystemProgram.transfer({
9236
- fromPubkey: payer,
9237
- toPubkey: payer,
9238
- lamports: 0
9239
- });
9240
- const tx = new Transaction().add(dummyIx);
9241
- const { blockhash } = await this.connection.getLatestBlockhash(
9242
- commitment
9243
- );
9244
- tx.recentBlockhash = blockhash;
9245
- tx.feePayer = payer;
9246
- const message = tx.compileMessage();
9247
- const feeInfo = await this.connection.getFeeForMessage(
9248
- message,
9249
- commitment
9250
- );
9251
- const singleTxFeeLamports = BigInt(feeInfo.value ?? 5e3);
9235
+ const singleTxFeeLamports = await this.getSingleTxFeeLamports();
9252
9236
  const txCount = BigInt(options?.txCount ?? 2);
9253
9237
  const safetyMultiplier = options?.safetyMultiplier ?? 3;
9254
9238
  const safetyScaled = BigInt(Math.round(safetyMultiplier * 100));
@@ -9269,30 +9253,54 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9269
9253
  if (typeof this.getDepositFee !== "function") {
9270
9254
  return gasBuffer;
9271
9255
  }
9272
- let lo = BigInt(0);
9273
- let hi = spendable;
9274
- for (let i = 0; i < 20 && hi - lo > BigInt(1); i++) {
9275
- const mid = (lo + hi) / BigInt(2);
9276
- let fee;
9277
- try {
9278
- fee = await this.getDepositFee(mid);
9279
- } catch {
9280
- return gasBuffer;
9281
- }
9282
- if (mid + fee <= spendable) {
9283
- lo = mid;
9284
- } else {
9285
- hi = mid;
9286
- }
9256
+ let feeAtSpendable;
9257
+ try {
9258
+ feeAtSpendable = await this.getDepositFee(spendable);
9259
+ } catch {
9260
+ return gasBuffer;
9287
9261
  }
9288
- const fudge = BigInt(1e3);
9289
- let effectivePrincipal = lo > fudge ? lo - fudge : lo;
9262
+ if (feeAtSpendable <= BigInt(0)) {
9263
+ return gasBuffer;
9264
+ }
9265
+ const s = spendable;
9266
+ const f = feeAtSpendable;
9267
+ const denom = s + f;
9268
+ if (denom === BigInt(0)) {
9269
+ return gasBuffer;
9270
+ }
9271
+ let a = s * s / denom;
9272
+ const fudge = BigInt(1e4);
9273
+ let effectivePrincipal = a > fudge ? a - fudge : a;
9290
9274
  if (effectivePrincipal < BigInt(0)) {
9291
9275
  effectivePrincipal = BigInt(0);
9292
9276
  }
9293
9277
  const buffer = balanceLamports > effectivePrincipal ? balanceLamports - effectivePrincipal : balanceLamports;
9294
9278
  return buffer < gasBuffer ? gasBuffer : buffer;
9295
9279
  }
9280
+ async getSingleTxFeeLamports() {
9281
+ const now = Date.now();
9282
+ if (this.cachedTxFee && now - this.cachedTxFee.fetchedAt < _SolanaStakingClient.FEE_CACHE_TTL_MS) {
9283
+ return this.cachedTxFee.value;
9284
+ }
9285
+ const payer = this.solPubKey;
9286
+ const dummyIx = SystemProgram.transfer({
9287
+ fromPubkey: payer,
9288
+ toPubkey: payer,
9289
+ lamports: 0
9290
+ });
9291
+ const tx = new Transaction().add(dummyIx);
9292
+ const { blockhash } = await this.connection.getLatestBlockhash(commitment);
9293
+ tx.recentBlockhash = blockhash;
9294
+ tx.feePayer = payer;
9295
+ const message = tx.compileMessage();
9296
+ const feeInfo = await this.connection.getFeeForMessage(message, commitment);
9297
+ const singleTxFeeLamports = BigInt(feeInfo.value ?? 5e3);
9298
+ this.cachedTxFee = {
9299
+ value: singleTxFeeLamports,
9300
+ fetchedAt: now
9301
+ };
9302
+ return singleTxFeeLamports;
9303
+ }
9296
9304
  async sendAndConfirmHttp(signed, ctx) {
9297
9305
  this.ensureUser();
9298
9306
  const signature = await this.connection.sendRawTransaction(
@@ -9344,6 +9352,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9344
9352
  }
9345
9353
  };
9346
9354
  _SolanaStakingClient.EPOCHS_PER_YEAR_TTL_MS = 10 * 60 * 1e3;
9355
+ _SolanaStakingClient.FEE_CACHE_TTL_MS = 6e4;
9347
9356
  let SolanaStakingClient = _SolanaStakingClient;
9348
9357
 
9349
9358
  var _format$q = "hh-sol-artifact-1";
@@ -36001,7 +36010,7 @@ class EthereumStakingClient {
36001
36010
  const currentTrancheSupply = BigInt(trancheSupplyBn.toString()) / BigInt(1e10);
36002
36011
  const [roundId, answer, startedAt, updatedAt, answeredInRound] = await this.contract.MockAggregator.latestRoundData();
36003
36012
  let ethPriceUsdBn = await this.contract.EthUsdPriceConsumer.getPrice18Decimals();
36004
- let ethPriceUsd = BigInt(ethPriceUsdBn.toString()) / 10n;
36013
+ let ethPriceUsd = BigInt(ethPriceUsdBn.toString()) / BigInt(1e10);
36005
36014
  let nativePriceTimestamp = Number(updatedAt);
36006
36015
  const initialTrancheSupply = BigInt(INITIAL_TRANCHE_SUPPLY) * BigInt(1e8);
36007
36016
  return buildEthereumTrancheSnapshot({