@wireio/stake 0.9.1 → 0.9.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.
@@ -35121,6 +35121,30 @@ class ConvertClient {
35121
35121
  event
35122
35122
  };
35123
35123
  }
35124
+ async claimWithdraw(tokenId) {
35125
+ let tx, receipt;
35126
+ try {
35127
+ tx = await this.contract.DepositManager.claim(tokenId);
35128
+ receipt = await tx.wait(1);
35129
+ } catch (err) {
35130
+ let errorObj = formatContractErrors(err);
35131
+ throw new Error(errorObj.name ?? errorObj.raw);
35132
+ }
35133
+ let event;
35134
+ const ev = receipt.events?.find((e) => e.event === "Claimed");
35135
+ if (ev && ev.args) {
35136
+ const { sender, ethAmount } = ev.args;
35137
+ event = {
35138
+ sender,
35139
+ ethAmount: BigNumber.from(ethAmount)
35140
+ };
35141
+ }
35142
+ return {
35143
+ txHash: tx.hash,
35144
+ receipt,
35145
+ event
35146
+ };
35147
+ }
35124
35148
  }
35125
35149
 
35126
35150
  class StakeClient {
@@ -35141,12 +35165,13 @@ class StakeClient {
35141
35165
  async performStake(amountWei, signerAddress) {
35142
35166
  const depositor = this.contract.Depositor.address;
35143
35167
  const liqRead = this.contract.LiqEthToken;
35144
- await liqRead.balanceOf(signerAddress);
35168
+ const bal = await liqRead.balanceOf(signerAddress);
35145
35169
  const allowance = await liqRead.allowance(signerAddress, depositor);
35146
35170
  const paused = await this.contract.Depositor.paused();
35147
35171
  if (paused) {
35148
35172
  throw new Error("Error - Depositor is in a paused state");
35149
35173
  }
35174
+ if (bal.lt(amountWei)) throw new Error("Insufficient LiqETH balance");
35150
35175
  if (allowance.lt(amountWei)) {
35151
35176
  const liqWrite = this.contractService.getWrite("LiqEthToken");
35152
35177
  console.warn(`allowance insufficient (${allowance.toString()} < ${amountWei.toString()}); sending approve(${depositor}, ${amountWei.toString()})`);
@@ -35591,7 +35616,7 @@ class ReceiptClient {
35591
35616
  }
35592
35617
  async fetchPreLaunchReceipts(address, type) {
35593
35618
  const receiptContract = this.contract.ReceiptNFT;
35594
- const tokenIds = await this.getOwnedTokenIdsFor(address);
35619
+ const tokenIds = await this.getOwnedReceiptNFTsFor(address);
35595
35620
  const results = [];
35596
35621
  for (const idBN of tokenIds) {
35597
35622
  try {
@@ -35624,7 +35649,7 @@ class ReceiptClient {
35624
35649
  }
35625
35650
  return results;
35626
35651
  }
35627
- async getOwnedTokenIdsFor(owner, fromBlock = 0, toBlock = "latest") {
35652
+ async getOwnedReceiptNFTsFor(owner, fromBlock = 0, toBlock = "latest") {
35628
35653
  const receiptContract = this.contract.ReceiptNFT;
35629
35654
  const toLogs = await receiptContract.queryFilter(
35630
35655
  receiptContract.filters.Transfer(null, owner),
@@ -35649,6 +35674,56 @@ class ReceiptClient {
35649
35674
  }
35650
35675
  return Array.from(owned).map((id) => BigNumber.from(id));
35651
35676
  }
35677
+ async fetchWithdrawReceipts(address) {
35678
+ const tokenIds = await this.getOwnedWithdrawReceiptsFor(address);
35679
+ const results = [];
35680
+ for (const idBN of tokenIds) {
35681
+ try {
35682
+ const receiptData = await this.contract.WithdrawalQueue.info(idBN);
35683
+ results.push({
35684
+ tokenId: idBN.toBigInt(),
35685
+ receipt: {
35686
+ ethAmount: receiptData.ethAmount,
35687
+ ethBalance: {
35688
+ amount: receiptData.ethAmount.toBigInt(),
35689
+ decimals: 18,
35690
+ symbol: "ETH"
35691
+ },
35692
+ readyAt: new Date(Number(receiptData.readyAt.toString()) * 1e3).valueOf()
35693
+ }
35694
+ });
35695
+ } catch (err) {
35696
+ console.warn(`Failed to load receipt for tokenId=${idBN.toString()}`, err);
35697
+ continue;
35698
+ }
35699
+ }
35700
+ return results;
35701
+ }
35702
+ async getOwnedWithdrawReceiptsFor(owner, fromBlock = 0, toBlock = "latest") {
35703
+ const contract = this.contract.WithdrawalQueue;
35704
+ const toLogs = await contract.queryFilter(
35705
+ contract.filters.Transfer(null, owner),
35706
+ fromBlock,
35707
+ toBlock
35708
+ );
35709
+ const fromLogs = await contract.queryFilter(
35710
+ contract.filters.Transfer(owner, null),
35711
+ fromBlock,
35712
+ toBlock
35713
+ );
35714
+ const owned = new Set();
35715
+ for (const e of toLogs) {
35716
+ const tokenId = e.args?.tokenId;
35717
+ if (!tokenId) continue;
35718
+ owned.add(tokenId.toString());
35719
+ }
35720
+ for (const e of fromLogs) {
35721
+ const tokenId = e.args?.tokenId;
35722
+ if (!tokenId) continue;
35723
+ owned.delete(tokenId.toString());
35724
+ }
35725
+ return Array.from(owned).map((id) => BigNumber.from(id));
35726
+ }
35652
35727
  }
35653
35728
 
35654
35729
  const INITIAL_TRANCHE_SUPPLY = 35e3;
@@ -35695,6 +35770,17 @@ class EthereumStakingClient {
35695
35770
  const result = await this.convertClient.performWithdraw(address, amountWei);
35696
35771
  return result.txHash;
35697
35772
  }
35773
+ async loadPendingWithdraws() {
35774
+ this.ensureUser();
35775
+ const address = await this.signer.getAddress();
35776
+ return await this.receiptClient.fetchWithdrawReceipts(address);
35777
+ }
35778
+ async claimWithdraw(tokenId) {
35779
+ this.ensureUser();
35780
+ const tokenIdBigNum = BigNumber.from(tokenId);
35781
+ const result = await this.convertClient.claimWithdraw(tokenIdBigNum);
35782
+ return result.txHash;
35783
+ }
35698
35784
  async stake(amount) {
35699
35785
  this.ensureUser();
35700
35786
  const walletAddress = await this.signer.getAddress();
@@ -35754,6 +35840,12 @@ class EthereumStakingClient {
35754
35840
  }
35755
35841
  let estimatedClaim = BigInt(0);
35756
35842
  let estimatedYield = BigInt(0);
35843
+ if (userShares > BigInt(0) && currentIndex > BigInt(0)) {
35844
+ estimatedClaim = userShares * currentIndex / indexScale;
35845
+ if (estimatedClaim > stakeBalanceBN.toBigInt()) {
35846
+ estimatedYield = estimatedClaim - stakeBalanceBN.toBigInt();
35847
+ }
35848
+ }
35757
35849
  const portfolio = {
35758
35850
  native: {
35759
35851
  amount: nativeBalance.toBigInt(),