@wireio/stake 0.7.1 → 0.7.3
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 +44 -35
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +4 -1
- package/lib/stake.js +51 -39
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +44 -35
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/solana/solana.ts +75 -52
- package/src/staker.ts +1 -1
package/lib/stake.browser.js
CHANGED
|
@@ -9232,23 +9232,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
9232
9232
|
}
|
|
9233
9233
|
let gasBuffer = BigInt(0);
|
|
9234
9234
|
try {
|
|
9235
|
-
const
|
|
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
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
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
|
-
|
|
9289
|
-
|
|
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";
|
|
@@ -36094,7 +36103,7 @@ class Staker {
|
|
|
36094
36103
|
break;
|
|
36095
36104
|
case EvmChainID.Ethereum:
|
|
36096
36105
|
case EvmChainID.Hoodi:
|
|
36097
|
-
this.clients.set(
|
|
36106
|
+
this.clients.set(cfg.network.chainId, new EthereumStakingClient(cfg));
|
|
36098
36107
|
break;
|
|
36099
36108
|
default:
|
|
36100
36109
|
console.log(`No staking client available for chain ${cfg.network.chainId}`);
|