@wireio/stake 0.9.0 → 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.
package/lib/stake.js CHANGED
@@ -4,8 +4,28 @@ var core = require('@wireio/core');
4
4
  var web3_js = require('@solana/web3.js');
5
5
  var anchor = require('@coral-xyz/anchor');
6
6
  var splToken = require('@solana/spl-token');
7
+ var multisig = require('@sqds/multisig');
7
8
  var ethers = require('ethers');
8
9
 
10
+ function _interopNamespaceDefault(e) {
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var multisig__namespace = /*#__PURE__*/_interopNamespaceDefault(multisig);
28
+
9
29
  var address$3 = "5nBtmutQLrRKBUxNfHJPDjiW5u8id6QM9Hhjg1D1g1XH";
10
30
  var metadata$3 = {
11
31
  name: "liqsol_core",
@@ -7502,6 +7522,9 @@ class DepositClient {
7502
7522
  const svc = new SolanaProgramService(provider);
7503
7523
  this.program = svc.getProgram("liqsolCore");
7504
7524
  }
7525
+ get connection() {
7526
+ return this.provider.connection;
7527
+ }
7505
7528
  get wallet() {
7506
7529
  return this.provider.wallet;
7507
7530
  }
@@ -7530,7 +7553,7 @@ class DepositClient {
7530
7553
  const userAta = splToken.getAssociatedTokenAddressSync(
7531
7554
  liqsolMint,
7532
7555
  user,
7533
- false,
7556
+ true,
7534
7557
  splToken.TOKEN_2022_PROGRAM_ID
7535
7558
  );
7536
7559
  const distributionState = deriveDistributionStatePda();
@@ -7543,7 +7566,7 @@ class DepositClient {
7543
7566
  );
7544
7567
  const seed = Math.floor(Math.random() * __pow(2, 32));
7545
7568
  const ephemeralStake = yield deriveEphemeralStakeAddress(user, seed);
7546
- const ix = yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
7569
+ return yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
7547
7570
  user,
7548
7571
  depositAuthority,
7549
7572
  systemProgram: web3_js.SystemProgram.programId,
@@ -7570,7 +7593,64 @@ class DepositClient {
7570
7593
  rent: web3_js.SYSVAR_RENT_PUBKEY,
7571
7594
  globalConfig
7572
7595
  }).instruction();
7573
- return new web3_js.Transaction().add(ix);
7596
+ });
7597
+ }
7598
+ buildSquadsDepositProposalTx(params) {
7599
+ return __async$e(this, null, function* () {
7600
+ var _a, _b, _c, _d;
7601
+ const { connection, multisigPda, amountLamports, wallet } = params;
7602
+ const vaultIndex = (_a = params.vaultIndex) != null ? _a : 0;
7603
+ if (!(wallet == null ? void 0 : wallet.publicKey)) throw new Error("wallet.publicKey missing");
7604
+ if (!amountLamports || amountLamports <= BigInt(0)) throw new Error("amountLamports must be > 0");
7605
+ const [vaultPda] = multisig__namespace.getVaultPda({ multisigPda, index: vaultIndex });
7606
+ const depositBuilt = yield this.buildDepositIxForUser(amountLamports, vaultPda);
7607
+ const ms = yield multisig__namespace.accounts.Multisig.fromAccountAddress(connection, multisigPda);
7608
+ const current = BigInt((_d = (_c = (_b = ms.transactionIndex) == null ? void 0 : _b.toString) == null ? void 0 : _c.call(_b)) != null ? _d : 0);
7609
+ const transactionIndex = current + BigInt(1);
7610
+ const { blockhash } = yield connection.getLatestBlockhash("confirmed");
7611
+ const message = new web3_js.TransactionMessage({
7612
+ payerKey: vaultPda,
7613
+ recentBlockhash: blockhash,
7614
+ instructions: [depositBuilt.ix]
7615
+ });
7616
+ const createVaultTxIx = yield multisig__namespace.instructions.vaultTransactionCreate({
7617
+ multisigPda,
7618
+ transactionIndex,
7619
+ creator: wallet.publicKey,
7620
+ vaultIndex,
7621
+ ephemeralSigners: 0,
7622
+ transactionMessage: message
7623
+ });
7624
+ console.log("createVaultTxIx", createVaultTxIx);
7625
+ const tx = new web3_js.Transaction().add(createVaultTxIx);
7626
+ return { tx, transactionIndex, vaultPda };
7627
+ });
7628
+ }
7629
+ buildSquadsDepositProposalTx2(params) {
7630
+ return __async$e(this, null, function* () {
7631
+ var _a, _b, _c, _d;
7632
+ const { connection, multisigPda, amountLamports, wallet } = params;
7633
+ const vaultIndex = (_a = params.vaultIndex) != null ? _a : 0;
7634
+ if (!(wallet == null ? void 0 : wallet.publicKey)) throw new Error("wallet.publicKey missing");
7635
+ if (!amountLamports || amountLamports <= BigInt(0)) throw new Error("amountLamports must be > 0");
7636
+ const [vaultPda] = multisig__namespace.getVaultPda({ multisigPda, index: vaultIndex });
7637
+ const depositBuilt = yield this.buildDepositIxForUser(amountLamports, vaultPda);
7638
+ const ms = yield multisig__namespace.accounts.Multisig.fromAccountAddress(connection, multisigPda);
7639
+ const current = BigInt((_d = (_c = (_b = ms.transactionIndex) == null ? void 0 : _b.toString) == null ? void 0 : _c.call(_b)) != null ? _d : 0);
7640
+ const transactionIndex = current + BigInt(1);
7641
+ const { blockhash } = yield connection.getLatestBlockhash("confirmed");
7642
+ new web3_js.TransactionMessage({
7643
+ payerKey: vaultPda,
7644
+ recentBlockhash: blockhash,
7645
+ instructions: [depositBuilt.ix]
7646
+ });
7647
+ const createProposalIx = yield multisig__namespace.instructions.proposalCreate({
7648
+ multisigPda,
7649
+ transactionIndex,
7650
+ creator: wallet.publicKey
7651
+ });
7652
+ const tx = new web3_js.Transaction().add(createProposalIx);
7653
+ return { tx, transactionIndex, vaultPda };
7574
7654
  });
7575
7655
  }
7576
7656
  buildWithdrawTx(_0) {
@@ -7589,7 +7669,7 @@ class DepositClient {
7589
7669
  const userAta = splToken.getAssociatedTokenAddressSync(
7590
7670
  liqsolMint,
7591
7671
  user,
7592
- false,
7672
+ true,
7593
7673
  splToken.TOKEN_2022_PROGRAM_ID
7594
7674
  );
7595
7675
  const userRecord = deriveUserRecordPda(userAta);
@@ -7622,7 +7702,7 @@ class DepositClient {
7622
7702
  const nftAta = splToken.getAssociatedTokenAddressSync(
7623
7703
  nftMint,
7624
7704
  owner,
7625
- false,
7705
+ true,
7626
7706
  splToken.TOKEN_2022_PROGRAM_ID
7627
7707
  );
7628
7708
  const bucketAuthority = deriveBucketAuthorityPda();
@@ -7661,6 +7741,70 @@ class DepositClient {
7661
7741
  return new web3_js.Transaction().add(ix);
7662
7742
  });
7663
7743
  }
7744
+ buildDepositIxForUser(amount, user) {
7745
+ return __async$e(this, null, function* () {
7746
+ if (!user) {
7747
+ throw new Error("buildDepositIxForUser: user is required");
7748
+ }
7749
+ if (!amount || amount <= BigInt(0)) {
7750
+ throw new Error("buildDepositIxForUser: amount must be > 0");
7751
+ }
7752
+ const depositAuthority = deriveDepositAuthorityPda();
7753
+ const liqsolMint = deriveLiqsolMintPda();
7754
+ const liqsolMintAuthority = deriveLiqsolMintAuthorityPda();
7755
+ const reservePool = deriveReservePoolPda();
7756
+ const vault = deriveVaultPda();
7757
+ const controllerState = deriveStakeControllerStatePda();
7758
+ const payoutState = derivePayoutStatePda();
7759
+ const bucketAuthority = deriveBucketAuthorityPda();
7760
+ const payRateHistory = derivePayRateHistoryPda();
7761
+ const globalConfig = deriveGlobalConfigPda();
7762
+ const userAta = splToken.getAssociatedTokenAddressSync(
7763
+ liqsolMint,
7764
+ user,
7765
+ true,
7766
+ splToken.TOKEN_2022_PROGRAM_ID
7767
+ );
7768
+ const distributionState = deriveDistributionStatePda();
7769
+ const userRecord = deriveUserRecordPda(userAta);
7770
+ const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
7771
+ liqsolMint,
7772
+ bucketAuthority,
7773
+ true,
7774
+ splToken.TOKEN_2022_PROGRAM_ID
7775
+ );
7776
+ const seed = Math.floor(Math.random() * __pow(2, 32));
7777
+ const ephemeralStake = yield deriveEphemeralStakeAddress(user, seed);
7778
+ const ix = yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
7779
+ user,
7780
+ depositAuthority,
7781
+ systemProgram: web3_js.SystemProgram.programId,
7782
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
7783
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
7784
+ liqsolProgram: PROGRAM_IDS.LIQSOL_TOKEN,
7785
+ stakeProgram: web3_js.StakeProgram.programId,
7786
+ liqsolMint,
7787
+ userAta,
7788
+ liqsolMintAuthority,
7789
+ reservePool,
7790
+ vault,
7791
+ ephemeralStake,
7792
+ controllerState,
7793
+ payoutState,
7794
+ bucketAuthority,
7795
+ bucketTokenAccount,
7796
+ userRecord,
7797
+ distributionState,
7798
+ payRateHistory,
7799
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
7800
+ clock: web3_js.SYSVAR_CLOCK_PUBKEY,
7801
+ stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
7802
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
7803
+ globalConfig
7804
+ }).instruction();
7805
+ return { ix, seed, userAta, ephemeralStake };
7806
+ });
7807
+ }
7664
7808
  }
7665
7809
 
7666
7810
  var __async$d = (__this, __arguments, generator) => {
@@ -8234,7 +8378,7 @@ class DistributionClient {
8234
8378
  const ata = splToken.getAssociatedTokenAddressSync(
8235
8379
  liqsolMint,
8236
8380
  ownerOrAta,
8237
- false,
8381
+ true,
8238
8382
  splToken.TOKEN_2022_PROGRAM_ID
8239
8383
  );
8240
8384
  const pdaFromWallet = deriveUserRecordPda(ata);
@@ -8577,7 +8721,7 @@ class OutpostClient {
8577
8721
  };
8578
8722
  }
8579
8723
  static tokensToShares(amount, currentIndex) {
8580
- const numerator = amount.mul(INDEX_SCALE$1);
8724
+ const numerator = amount.mul(new anchor.BN(INDEX_SCALE$1));
8581
8725
  const shares = numerator.div(currentIndex);
8582
8726
  const remainder = numerator.mod(currentIndex);
8583
8727
  return remainder.eqn(0) ? shares : shares.addn(1);
@@ -8841,6 +8985,75 @@ const _SolanaStakingClient = class _SolanaStakingClient {
8841
8985
  get network() {
8842
8986
  return this.config.network;
8843
8987
  }
8988
+ get feePayer() {
8989
+ if (this.signer) return this.signer;
8990
+ if (this.anchor.wallet.publicKey) return this.anchor.wallet.publicKey;
8991
+ throw new Error("No signing authority available");
8992
+ }
8993
+ get squadsX() {
8994
+ var _a;
8995
+ const config = (_a = this.config.extras) == null ? void 0 : _a.squadsX;
8996
+ return config != null ? config : null;
8997
+ }
8998
+ createVaultLiqsolAtaOneShot(params) {
8999
+ return __async$8(this, null, function* () {
9000
+ const { connection, payer, vaultPda } = params;
9001
+ const liqsolMint = deriveLiqsolMintPda();
9002
+ const vaultAta = splToken.getAssociatedTokenAddressSync(
9003
+ liqsolMint,
9004
+ vaultPda,
9005
+ true,
9006
+ splToken.TOKEN_2022_PROGRAM_ID,
9007
+ splToken.ASSOCIATED_TOKEN_PROGRAM_ID
9008
+ );
9009
+ const info = yield connection.getAccountInfo(vaultAta, "confirmed");
9010
+ console.log("info?", info);
9011
+ if (info) return null;
9012
+ const ix = splToken.createAssociatedTokenAccountInstruction(
9013
+ payer,
9014
+ vaultAta,
9015
+ vaultPda,
9016
+ liqsolMint,
9017
+ splToken.TOKEN_2022_PROGRAM_ID,
9018
+ splToken.ASSOCIATED_TOKEN_PROGRAM_ID
9019
+ );
9020
+ const tx = new web3_js.Transaction().add(ix);
9021
+ return { tx, vaultAta };
9022
+ });
9023
+ }
9024
+ prepSquadsIxs(ix) {
9025
+ return __async$8(this, null, function* () {
9026
+ var _a, _b, _c, _d;
9027
+ if (!this.squadsX) throw new Error("Attempting to wrap Squads instruction without SquadsX config");
9028
+ const multisigPda = this.squadsMultisigPDA;
9029
+ const vaultPda = this.squadsVaultPDA;
9030
+ const vaultIndex = (_b = (_a = this.squadsX) == null ? void 0 : _a.vaultIndex) != null ? _b : 0;
9031
+ const creator = this.solPubKey;
9032
+ const ms = yield multisig__namespace.accounts.Multisig.fromAccountAddress(this.connection, multisigPda);
9033
+ const current = BigInt((_d = (_c = ms.transactionIndex) == null ? void 0 : _c.toString()) != null ? _d : 0);
9034
+ const transactionIndex = current + BigInt(1);
9035
+ const { blockhash } = yield this.connection.getLatestBlockhash("confirmed");
9036
+ const transactionMessage = new web3_js.TransactionMessage({
9037
+ payerKey: vaultPda,
9038
+ recentBlockhash: blockhash,
9039
+ instructions: [ix]
9040
+ });
9041
+ const createVaultTxIx = yield multisig__namespace.instructions.vaultTransactionCreate({
9042
+ multisigPda,
9043
+ transactionIndex,
9044
+ creator,
9045
+ vaultIndex,
9046
+ transactionMessage,
9047
+ ephemeralSigners: 0
9048
+ });
9049
+ const createProposalIx = yield multisig__namespace.instructions.proposalCreate({
9050
+ multisigPda,
9051
+ transactionIndex,
9052
+ creator
9053
+ });
9054
+ return [createVaultTxIx, createProposalIx];
9055
+ });
9056
+ }
8844
9057
  deposit(amountLamports) {
8845
9058
  return __async$8(this, null, function* () {
8846
9059
  this.ensureUser();
@@ -8849,11 +9062,40 @@ const _SolanaStakingClient = class _SolanaStakingClient {
8849
9062
  }
8850
9063
  try {
8851
9064
  const cuIx = web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
8852
- const ix = yield this.depositClient.buildDepositTx(amountLamports);
8853
- const tx = new web3_js.Transaction().add(cuIx, ix);
8854
- const prepared = yield this.prepareTx(tx);
8855
- const signed = yield this.signTransaction(prepared.tx);
8856
- return this.sendAndConfirmHttp(signed, prepared);
9065
+ if (!!this.squadsX) {
9066
+ const createVaultTx = yield this.createVaultLiqsolAtaOneShot({
9067
+ connection: this.connection,
9068
+ payer: this.solPubKey,
9069
+ vaultPda: this.squadsVaultPDA
9070
+ });
9071
+ if (createVaultTx !== null) {
9072
+ console.log("need to create vault ata first...");
9073
+ const tx0 = new web3_js.Transaction().add(createVaultTx.tx);
9074
+ const prepared0 = yield this.prepareTx(tx0);
9075
+ const signed0 = yield this.signTransaction(prepared0.tx);
9076
+ const sent0 = yield this.sendAndConfirmHttp(signed0, prepared0);
9077
+ console.log("create Vault ATA", sent0);
9078
+ }
9079
+ const ix = yield this.depositClient.buildDepositTx(amountLamports, this.squadsVaultPDA);
9080
+ const squadIxs = yield this.prepSquadsIxs(ix);
9081
+ const tx1 = new web3_js.Transaction().add(cuIx, squadIxs[0]);
9082
+ const prepared1 = yield this.prepareTx(tx1);
9083
+ const signed1 = yield this.signTransaction(prepared1.tx);
9084
+ const sent1 = yield this.sendAndConfirmHttp(signed1, prepared1);
9085
+ console.log("SENT 1", sent1);
9086
+ const tx2 = new web3_js.Transaction().add(cuIx, squadIxs[1]);
9087
+ const prepared2 = yield this.prepareTx(tx2);
9088
+ const signed2 = yield this.signTransaction(prepared2.tx);
9089
+ const sent2 = yield this.sendAndConfirmHttp(signed2, prepared2);
9090
+ console.log("SENT 2", sent2);
9091
+ return sent2;
9092
+ } else {
9093
+ const ix = yield this.depositClient.buildDepositTx(amountLamports);
9094
+ const tx = new web3_js.Transaction().add(ix);
9095
+ const prepared = yield this.prepareTx(tx);
9096
+ const signed = yield this.signTransaction(prepared.tx);
9097
+ return this.sendAndConfirmHttp(signed, prepared);
9098
+ }
8857
9099
  } catch (err) {
8858
9100
  throw new Error(`Failed to deposit Solana: ${err}`);
8859
9101
  }
@@ -8939,14 +9181,15 @@ const _SolanaStakingClient = class _SolanaStakingClient {
8939
9181
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
8940
9182
  if (!this.pubKey) throw new Error("User pubKey is undefined");
8941
9183
  try {
8942
- const user = this.solPubKey;
9184
+ const user = !!this.squadsX ? this.squadsVaultPDA : this.solPubKey;
9185
+ console.log("get portfolio for user", user.toBase58());
8943
9186
  const reservePoolPDA = deriveReservePoolPda();
8944
9187
  const vaultPDA = deriveVaultPda();
8945
9188
  const liqsolMint = deriveLiqsolMintPda();
8946
9189
  const userLiqsolAta = splToken.getAssociatedTokenAddressSync(
8947
9190
  liqsolMint,
8948
9191
  user,
8949
- false,
9192
+ true,
8950
9193
  splToken.TOKEN_2022_PROGRAM_ID,
8951
9194
  splToken.ASSOCIATED_TOKEN_PROGRAM_ID
8952
9195
  );
@@ -9030,6 +9273,18 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9030
9273
  return this.distributionClient.getUserRecord(this.solPubKey);
9031
9274
  });
9032
9275
  }
9276
+ get squadsMultisigPDA() {
9277
+ if (!this.squadsX) return null;
9278
+ return new web3_js.PublicKey(this.squadsX.multisigPDA);
9279
+ }
9280
+ get squadsVaultPDA() {
9281
+ var _a;
9282
+ if (!this.squadsX || !this.squadsMultisigPDA) return null;
9283
+ const multisigPda = this.squadsMultisigPDA;
9284
+ const index = (_a = this.squadsX.vaultIndex) != null ? _a : 0;
9285
+ const pda = multisig__namespace.getVaultPda({ multisigPda, index });
9286
+ return pda[0];
9287
+ }
9033
9288
  getTrancheSnapshot(options) {
9034
9289
  return __async$8(this, null, function* () {
9035
9290
  try {
@@ -9149,8 +9404,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9149
9404
  return __async$8(this, null, function* () {
9150
9405
  var _a, _b, _c, _d;
9151
9406
  this.ensureUser();
9152
- const payer = this.solPubKey;
9153
- const balanceLamports = (_a = options == null ? void 0 : options.balanceOverrideLamports) != null ? _a : BigInt(yield this.connection.getBalance(payer, commitment));
9407
+ const balanceLamports = (_a = options == null ? void 0 : options.balanceOverrideLamports) != null ? _a : BigInt(yield this.connection.getBalance(this.feePayer, commitment));
9154
9408
  if (balanceLamports <= BigInt(0)) {
9155
9409
  return BigInt(0);
9156
9410
  }
@@ -9209,7 +9463,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9209
9463
  if (this.cachedTxFee && now - this.cachedTxFee.fetchedAt < _SolanaStakingClient.FEE_CACHE_TTL_MS) {
9210
9464
  return this.cachedTxFee.value;
9211
9465
  }
9212
- const payer = this.solPubKey;
9466
+ const payer = this.feePayer;
9213
9467
  const dummyIx = web3_js.SystemProgram.transfer({
9214
9468
  fromPubkey: payer,
9215
9469
  toPubkey: payer,
@@ -9272,18 +9526,18 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9272
9526
  return __async$8(this, null, function* () {
9273
9527
  const { blockhash, lastValidBlockHeight } = yield this.connection.getLatestBlockhash("confirmed");
9274
9528
  tx.recentBlockhash = blockhash;
9275
- tx.feePayer = this.solPubKey;
9529
+ tx.feePayer = this.feePayer;
9276
9530
  return { tx, blockhash, lastValidBlockHeight };
9277
9531
  });
9278
9532
  }
9279
9533
  ensureUser() {
9280
- if (!this.pubKey || !this.anchor.wallet.publicKey) {
9281
- throw new Error("User Authorization required: pubKey is undefined");
9282
- }
9283
- if (this.solPubKey.toBase58() !== this.anchor.wallet.publicKey.toBase58()) {
9284
- throw new Error(
9285
- "Write access requires connected wallet to match pubKey"
9286
- );
9534
+ var _a;
9535
+ if (!this.pubKey) throw new Error("User pubKey is undefined");
9536
+ const wallet = (_a = this.anchor) == null ? void 0 : _a.wallet;
9537
+ const pk = wallet == null ? void 0 : wallet.publicKey;
9538
+ if (!pk) throw new Error("Wallet not connected");
9539
+ if (typeof wallet.signTransaction !== "function") {
9540
+ throw new Error("Wallet does not support signTransaction");
9287
9541
  }
9288
9542
  }
9289
9543
  };
@@ -35299,6 +35553,33 @@ class ConvertClient {
35299
35553
  };
35300
35554
  });
35301
35555
  }
35556
+ claimWithdraw(tokenId) {
35557
+ return __async$5(this, null, function* () {
35558
+ var _a, _b;
35559
+ let tx, receipt;
35560
+ try {
35561
+ tx = yield this.contract.DepositManager.claim(tokenId);
35562
+ receipt = yield tx.wait(1);
35563
+ } catch (err) {
35564
+ let errorObj = formatContractErrors(err);
35565
+ throw new Error((_a = errorObj.name) != null ? _a : errorObj.raw);
35566
+ }
35567
+ let event;
35568
+ const ev = (_b = receipt.events) == null ? void 0 : _b.find((e) => e.event === "Claimed");
35569
+ if (ev && ev.args) {
35570
+ const { sender, ethAmount } = ev.args;
35571
+ event = {
35572
+ sender,
35573
+ ethAmount: ethers.BigNumber.from(ethAmount)
35574
+ };
35575
+ }
35576
+ return {
35577
+ txHash: tx.hash,
35578
+ receipt,
35579
+ event
35580
+ };
35581
+ });
35582
+ }
35302
35583
  }
35303
35584
 
35304
35585
  var __async$4 = (__this, __arguments, generator) => {
@@ -35344,12 +35625,13 @@ class StakeClient {
35344
35625
  var _a;
35345
35626
  const depositor = this.contract.Depositor.address;
35346
35627
  const liqRead = this.contract.LiqEthToken;
35347
- yield liqRead.balanceOf(signerAddress);
35628
+ const bal = yield liqRead.balanceOf(signerAddress);
35348
35629
  const allowance = yield liqRead.allowance(signerAddress, depositor);
35349
35630
  const paused = yield this.contract.Depositor.paused();
35350
35631
  if (paused) {
35351
35632
  throw new Error("Error - Depositor is in a paused state");
35352
35633
  }
35634
+ if (bal.lt(amountWei)) throw new Error("Insufficient LiqETH balance");
35353
35635
  if (allowance.lt(amountWei)) {
35354
35636
  const liqWrite = this.contractService.getWrite("LiqEthToken");
35355
35637
  console.warn(`allowance insufficient (${allowance.toString()} < ${amountWei.toString()}); sending approve(${depositor}, ${amountWei.toString()})`);
@@ -35875,7 +36157,7 @@ class ReceiptClient {
35875
36157
  fetchPreLaunchReceipts(address, type) {
35876
36158
  return __async$1(this, null, function* () {
35877
36159
  const receiptContract = this.contract.ReceiptNFT;
35878
- const tokenIds = yield this.getOwnedTokenIdsFor(address);
36160
+ const tokenIds = yield this.getOwnedReceiptNFTsFor(address);
35879
36161
  const results = [];
35880
36162
  for (const idBN of tokenIds) {
35881
36163
  try {
@@ -35909,7 +36191,7 @@ class ReceiptClient {
35909
36191
  return results;
35910
36192
  });
35911
36193
  }
35912
- getOwnedTokenIdsFor(owner, fromBlock = 0, toBlock = "latest") {
36194
+ getOwnedReceiptNFTsFor(owner, fromBlock = 0, toBlock = "latest") {
35913
36195
  return __async$1(this, null, function* () {
35914
36196
  var _a, _b;
35915
36197
  const receiptContract = this.contract.ReceiptNFT;
@@ -35937,6 +36219,61 @@ class ReceiptClient {
35937
36219
  return Array.from(owned).map((id) => ethers.BigNumber.from(id));
35938
36220
  });
35939
36221
  }
36222
+ fetchWithdrawReceipts(address) {
36223
+ return __async$1(this, null, function* () {
36224
+ const tokenIds = yield this.getOwnedWithdrawReceiptsFor(address);
36225
+ const results = [];
36226
+ for (const idBN of tokenIds) {
36227
+ try {
36228
+ const receiptData = yield this.contract.WithdrawalQueue.info(idBN);
36229
+ results.push({
36230
+ tokenId: idBN.toBigInt(),
36231
+ receipt: {
36232
+ ethAmount: receiptData.ethAmount,
36233
+ ethBalance: {
36234
+ amount: receiptData.ethAmount.toBigInt(),
36235
+ decimals: 18,
36236
+ symbol: "ETH"
36237
+ },
36238
+ readyAt: new Date(Number(receiptData.readyAt.toString()) * 1e3).valueOf()
36239
+ }
36240
+ });
36241
+ } catch (err) {
36242
+ console.warn(`Failed to load receipt for tokenId=${idBN.toString()}`, err);
36243
+ continue;
36244
+ }
36245
+ }
36246
+ return results;
36247
+ });
36248
+ }
36249
+ getOwnedWithdrawReceiptsFor(owner, fromBlock = 0, toBlock = "latest") {
36250
+ return __async$1(this, null, function* () {
36251
+ var _a, _b;
36252
+ const contract = this.contract.WithdrawalQueue;
36253
+ const toLogs = yield contract.queryFilter(
36254
+ contract.filters.Transfer(null, owner),
36255
+ fromBlock,
36256
+ toBlock
36257
+ );
36258
+ const fromLogs = yield contract.queryFilter(
36259
+ contract.filters.Transfer(owner, null),
36260
+ fromBlock,
36261
+ toBlock
36262
+ );
36263
+ const owned = new Set();
36264
+ for (const e of toLogs) {
36265
+ const tokenId = (_a = e.args) == null ? void 0 : _a.tokenId;
36266
+ if (!tokenId) continue;
36267
+ owned.add(tokenId.toString());
36268
+ }
36269
+ for (const e of fromLogs) {
36270
+ const tokenId = (_b = e.args) == null ? void 0 : _b.tokenId;
36271
+ if (!tokenId) continue;
36272
+ owned.delete(tokenId.toString());
36273
+ }
36274
+ return Array.from(owned).map((id) => ethers.BigNumber.from(id));
36275
+ });
36276
+ }
35940
36277
  }
35941
36278
 
35942
36279
  var __async = (__this, __arguments, generator) => {
@@ -36007,6 +36344,21 @@ class EthereumStakingClient {
36007
36344
  return result.txHash;
36008
36345
  });
36009
36346
  }
36347
+ loadPendingWithdraws() {
36348
+ return __async(this, null, function* () {
36349
+ this.ensureUser();
36350
+ const address = yield this.signer.getAddress();
36351
+ return yield this.receiptClient.fetchWithdrawReceipts(address);
36352
+ });
36353
+ }
36354
+ claimWithdraw(tokenId) {
36355
+ return __async(this, null, function* () {
36356
+ this.ensureUser();
36357
+ const tokenIdBigNum = ethers.BigNumber.from(tokenId);
36358
+ const result = yield this.convertClient.claimWithdraw(tokenIdBigNum);
36359
+ return result.txHash;
36360
+ });
36361
+ }
36010
36362
  stake(amount) {
36011
36363
  return __async(this, null, function* () {
36012
36364
  this.ensureUser();
@@ -36076,6 +36428,12 @@ class EthereumStakingClient {
36076
36428
  }
36077
36429
  let estimatedClaim = BigInt(0);
36078
36430
  let estimatedYield = BigInt(0);
36431
+ if (userShares > BigInt(0) && currentIndex > BigInt(0)) {
36432
+ estimatedClaim = userShares * currentIndex / indexScale;
36433
+ if (estimatedClaim > stakeBalanceBN.toBigInt()) {
36434
+ estimatedYield = estimatedClaim - stakeBalanceBN.toBigInt();
36435
+ }
36436
+ }
36079
36437
  const portfolio = {
36080
36438
  native: {
36081
36439
  amount: nativeBalance.toBigInt(),
@@ -36251,11 +36609,9 @@ class Staker {
36251
36609
  if (!Array.isArray(config)) config = [config];
36252
36610
  config.forEach((cfg) => {
36253
36611
  switch (cfg.network.chainId) {
36254
- case core.SolChainID.Mainnet:
36255
36612
  case core.SolChainID.Devnet:
36256
36613
  this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
36257
36614
  break;
36258
- case core.EvmChainID.Ethereum:
36259
36615
  case core.EvmChainID.Hoodi:
36260
36616
  this.clients.set(cfg.network.chainId, new EthereumStakingClient(cfg));
36261
36617
  break;