@wireio/stake 1.0.0 → 1.1.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.m.js CHANGED
@@ -8567,13 +8567,12 @@ const _SolanaStakingClient = class _SolanaStakingClient {
8567
8567
  throw new Error("Deposit amount must be greater than zero.");
8568
8568
  }
8569
8569
  try {
8570
- const tx = await this.depositClient.buildDepositTx(amountLamports);
8571
- const { tx: prepared, blockhash, lastValidBlockHeight } = await this.prepareTx(tx);
8572
- const signed = await this.signTransaction(prepared);
8573
- return await this.sendAndConfirmHttp(signed, {
8574
- blockhash,
8575
- lastValidBlockHeight
8576
- });
8570
+ const cuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
8571
+ const ix = await this.depositClient.buildDepositTx(amountLamports);
8572
+ const tx = new Transaction().add(cuIx, ix);
8573
+ const prepared = await this.prepareTx(tx);
8574
+ const signed = await this.signTransaction(prepared.tx);
8575
+ return this.sendAndConfirmHttp(signed, prepared);
8577
8576
  } catch (err) {
8578
8577
  throw new Error(`Failed to deposit Solana: ${err}`);
8579
8578
  }
@@ -8584,13 +8583,12 @@ const _SolanaStakingClient = class _SolanaStakingClient {
8584
8583
  throw new Error("Withdraw amount must be greater than zero.");
8585
8584
  }
8586
8585
  try {
8587
- const tx = await this.depositClient.buildWithdrawTx(amountLamports);
8588
- const { tx: prepared, blockhash, lastValidBlockHeight } = await this.prepareTx(tx);
8589
- const signed = await this.signTransaction(prepared);
8590
- return await this.sendAndConfirmHttp(signed, {
8591
- blockhash,
8592
- lastValidBlockHeight
8593
- });
8586
+ const cuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
8587
+ const ix = await this.depositClient.buildWithdrawTx(amountLamports);
8588
+ const tx = new Transaction().add(cuIx, ix);
8589
+ const prepared = await this.prepareTx(tx);
8590
+ const signed = await this.signTransaction(prepared.tx);
8591
+ return this.sendAndConfirmHttp(signed, prepared);
8594
8592
  } catch (err) {
8595
8593
  throw new Error(`Failed to withdraw Solana: ${err}`);
8596
8594
  }
@@ -8639,12 +8637,9 @@ const _SolanaStakingClient = class _SolanaStakingClient {
8639
8637
  const cuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
8640
8638
  const ix = await this.tokenClient.buildPurchaseIx(amountLamports, user);
8641
8639
  const tx = new Transaction().add(cuIx, ix);
8642
- const { tx: prepared, blockhash, lastValidBlockHeight } = await this.prepareTx(tx);
8643
- const signed = await this.signTransaction(prepared);
8644
- return await this.sendAndConfirmHttp(signed, {
8645
- blockhash,
8646
- lastValidBlockHeight
8647
- });
8640
+ const prepared = await this.prepareTx(tx);
8641
+ const signed = await this.signTransaction(prepared.tx);
8642
+ return this.sendAndConfirmHttp(signed, prepared);
8648
8643
  } catch (err) {
8649
8644
  throw new Error(`Failed to buy liqSOL pretokens: ${err}`);
8650
8645
  }
@@ -34925,18 +34920,22 @@ class OPPClient {
34925
34920
  };
34926
34921
  }
34927
34922
  async getMessages(address) {
34928
- const oppMessageFilter = this.contract.OPP.filters.OPPMessage();
34929
- const events = await this.contract.OPP.queryFilter(oppMessageFilter, 0, "latest");
34930
- const allAssertions = [];
34931
- for (const event of events) {
34932
- const assertions = await this.extractAssertionsFromEvent(event);
34933
- allAssertions.push(...assertions);
34923
+ try {
34924
+ const oppMessageFilter = this.contract.OPP.filters.OPPMessage();
34925
+ const events = await this.contract.OPP.queryFilter(oppMessageFilter, 0, "latest");
34926
+ const allAssertions = [];
34927
+ for (const event of events) {
34928
+ const assertions = await this.extractAssertionsFromEvent(event);
34929
+ allAssertions.push(...assertions);
34930
+ }
34931
+ const normalized = address ? address.toLowerCase() : null;
34932
+ const filtered = allAssertions.filter(
34933
+ (a) => a.from && a.from.toLowerCase() === normalized || a.to && a.to.toLowerCase() === normalized
34934
+ );
34935
+ return filtered.reverse();
34936
+ } catch (error) {
34937
+ return [];
34934
34938
  }
34935
- const normalized = address ? address.toLowerCase() : null;
34936
- const filtered = allAssertions.filter(
34937
- (a) => a.from && a.from.toLowerCase() === normalized || a.to && a.to.toLowerCase() === normalized
34938
- );
34939
- return filtered.reverse();
34940
34939
  }
34941
34940
  async extractAssertionsFromEvent(event) {
34942
34941
  const header = event.args.header;
@@ -35172,7 +35171,12 @@ class ReceiptClient {
35172
35171
  return this.fetchPreLaunchReceipts(address);
35173
35172
  }
35174
35173
  async stakeReceipts(address) {
35175
- return this.fetchPreLaunchReceipts(address, ReceiptNFTKind.STAKE);
35174
+ try {
35175
+ const receipts = await this.fetchPreLaunchReceipts(address, ReceiptNFTKind.STAKE);
35176
+ return receipts;
35177
+ } catch (err) {
35178
+ return [];
35179
+ }
35176
35180
  }
35177
35181
  async pretokenReceipts(address) {
35178
35182
  return this.fetchPreLaunchReceipts(address, ReceiptNFTKind.PRETOKEN_PURCHASE);
@@ -35306,72 +35310,77 @@ class EthereumStakingClient {
35306
35310
  return result && result.txHash ? result.txHash : "Error - no resulting txHash";
35307
35311
  }
35308
35312
  async getPortfolio() {
35309
- if (!this.signer) return Promise.resolve(null);
35310
- const walletAddress = await this.signer.getAddress();
35311
- const nativeBalance = await this.provider.getBalance(walletAddress);
35312
- const nativeDecimals = this.network?.nativeCurrency?.decimals ?? 18;
35313
- const nativeSymbol = this.network?.nativeCurrency?.symbol ?? "ETH";
35314
- const liqBalance = await this.contract.LiqEthToken.balanceOf(walletAddress);
35315
- const liqSymbol = "Liq" + (this.network?.nativeCurrency?.symbol ?? "ETH");
35316
- let stakeReceipts = await this.receiptClient.stakeReceipts(walletAddress);
35317
- let stakeBalanceBN = BigNumber.from(0);
35318
- for (let r of stakeReceipts) {
35319
- stakeBalanceBN = stakeBalanceBN.add(BigNumber.from(r.receipt.principal.amount));
35320
- }
35321
- let stakeSharesBN = BigNumber.from(0);
35322
- for (let r of stakeReceipts) {
35323
- stakeSharesBN = stakeSharesBN.add(BigNumber.from(r.receipt.shares.amount));
35324
- }
35325
- const wireBalance = await this.contract.Pretoken.balanceOf(walletAddress);
35326
- let currentIndex = BigInt(0);
35327
- let totalShares = BigInt(0);
35328
- let userShares = BigInt(0);
35329
- const indexScale = BigInt(1e27);
35330
35313
  try {
35331
- const [indexBn, totalSharesBn] = await Promise.all([
35332
- this.contract.Depositor.index().catch(() => BigNumber.from(0)),
35333
- this.contract.Depositor.totalShares().catch(() => BigNumber.from(0))
35334
- ]);
35335
- const userSharesBn = stakeSharesBN;
35336
- currentIndex = BigInt(indexBn.toString());
35337
- totalShares = BigInt(totalSharesBn.toString());
35338
- userShares = BigInt(userSharesBn.toString());
35339
- } catch {
35314
+ if (!this.signer) return Promise.resolve(null);
35315
+ const walletAddress = await this.signer.getAddress();
35316
+ const nativeBalance = await this.provider.getBalance(walletAddress);
35317
+ const nativeDecimals = this.network?.nativeCurrency?.decimals ?? 18;
35318
+ const nativeSymbol = this.network?.nativeCurrency?.symbol ?? "ETH";
35319
+ const liqBalance = await this.contract.LiqEthToken.balanceOf(walletAddress);
35320
+ const liqSymbol = "Liq" + (this.network?.nativeCurrency?.symbol ?? "ETH");
35321
+ let stakeReceipts = await this.receiptClient.stakeReceipts(walletAddress);
35322
+ let stakeBalanceBN = BigNumber.from(0);
35323
+ for (let r of stakeReceipts) {
35324
+ stakeBalanceBN = stakeBalanceBN.add(BigNumber.from(r.receipt.principal.amount));
35325
+ }
35326
+ let stakeSharesBN = BigNumber.from(0);
35327
+ for (let r of stakeReceipts) {
35328
+ stakeSharesBN = stakeSharesBN.add(BigNumber.from(r.receipt.shares.amount));
35329
+ }
35330
+ const wireBalance = await this.contract.Pretoken.balanceOf(walletAddress);
35331
+ let currentIndex = BigInt(0);
35332
+ let totalShares = BigInt(0);
35333
+ let userShares = BigInt(0);
35334
+ const indexScale = BigInt(1e27);
35335
+ try {
35336
+ const [indexBn, totalSharesBn] = await Promise.all([
35337
+ this.contract.Depositor.index().catch(() => BigNumber.from(0)),
35338
+ this.contract.Depositor.totalShares().catch(() => BigNumber.from(0))
35339
+ ]);
35340
+ const userSharesBn = stakeSharesBN;
35341
+ currentIndex = BigInt(indexBn.toString());
35342
+ totalShares = BigInt(totalSharesBn.toString());
35343
+ userShares = BigInt(userSharesBn.toString());
35344
+ } catch (error) {
35345
+ console.log("Error fetching staking index/shares:", error);
35346
+ }
35347
+ let estimatedClaim = BigInt(0);
35348
+ let estimatedYield = BigInt(0);
35349
+ const portfolio = {
35350
+ native: {
35351
+ amount: nativeBalance.toBigInt(),
35352
+ decimals: nativeDecimals,
35353
+ symbol: nativeSymbol
35354
+ },
35355
+ liq: {
35356
+ amount: liqBalance.toBigInt(),
35357
+ decimals: nativeDecimals,
35358
+ symbol: liqSymbol
35359
+ },
35360
+ staked: {
35361
+ amount: stakeBalanceBN.toBigInt(),
35362
+ decimals: nativeDecimals,
35363
+ symbol: liqSymbol
35364
+ },
35365
+ wire: {
35366
+ amount: wireBalance.toBigInt(),
35367
+ decimals: 18,
35368
+ symbol: "$WIRE"
35369
+ },
35370
+ yield: {
35371
+ currentIndex,
35372
+ indexScale,
35373
+ totalShares,
35374
+ userShares,
35375
+ estimatedClaim,
35376
+ estimatedYield
35377
+ },
35378
+ chainID: this.network.chainId
35379
+ };
35380
+ return portfolio;
35381
+ } catch (error) {
35382
+ throw error;
35340
35383
  }
35341
- let estimatedClaim = BigInt(0);
35342
- let estimatedYield = BigInt(0);
35343
- const portfolio = {
35344
- native: {
35345
- amount: nativeBalance.toBigInt(),
35346
- decimals: nativeDecimals,
35347
- symbol: nativeSymbol
35348
- },
35349
- liq: {
35350
- amount: liqBalance.toBigInt(),
35351
- decimals: nativeDecimals,
35352
- symbol: liqSymbol
35353
- },
35354
- staked: {
35355
- amount: stakeBalanceBN.toBigInt(),
35356
- decimals: nativeDecimals,
35357
- symbol: liqSymbol
35358
- },
35359
- wire: {
35360
- amount: wireBalance.toBigInt(),
35361
- decimals: 18,
35362
- symbol: "$WIRE"
35363
- },
35364
- yield: {
35365
- currentIndex,
35366
- indexScale,
35367
- totalShares,
35368
- userShares,
35369
- estimatedClaim,
35370
- estimatedYield
35371
- },
35372
- chainID: this.network.chainId
35373
- };
35374
- return portfolio;
35375
35384
  }
35376
35385
  async fetchPrelaunchReceipts(address) {
35377
35386
  this.ensureUser();
@@ -35498,6 +35507,7 @@ class Staker {
35498
35507
  this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
35499
35508
  break;
35500
35509
  case EvmChainID.Ethereum:
35510
+ case EvmChainID.Hoodi:
35501
35511
  this.clients.set(cfg.network.chainId, new EthereumStakingClient(cfg));
35502
35512
  break;
35503
35513
  default: