@wireio/stake 0.4.1 → 0.4.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.d.ts CHANGED
@@ -10,7 +10,7 @@ import { BN, AnchorProvider, Program } from '@coral-xyz/anchor';
10
10
 
11
11
  type StakerConfig = {
12
12
  network: ExternalNetwork;
13
- provider: BaseSignerWalletAdapter | ethers.providers.Web3Provider;
13
+ provider?: BaseSignerWalletAdapter | ethers.providers.Web3Provider;
14
14
  pubKey?: PublicKey;
15
15
  };
16
16
  interface IStakingClient {
@@ -24,6 +24,8 @@ interface IStakingClient {
24
24
  buy(amount: bigint): Promise<string>;
25
25
  /** Fetch the complete user portfolio */
26
26
  getPortfolio(): Promise<Portfolio>;
27
+ getSystemAPY(): Promise<number>;
28
+ getDepositFee(amount: bigint): Promise<bigint>;
27
29
  /**
28
30
  * Program-level prelaunch WIRE/tranche snapshot for this chain.
29
31
  *
@@ -330,9 +332,9 @@ declare namespace types$1 {
330
332
 
331
333
  declare class EthereumStakingClient implements IStakingClient {
332
334
  private config;
333
- readonly pubKey?: PublicKey;
334
335
  private readonly provider;
335
- private readonly signer;
336
+ readonly pubKey?: PublicKey;
337
+ private readonly signer?;
336
338
  private readonly contractService;
337
339
  private convertClient;
338
340
  private pretokenClient;
@@ -388,15 +390,6 @@ declare class EthereumStakingClient implements IStakingClient {
388
390
  */
389
391
  unstakePrelaunch(tokenId: bigint, recipient: string): Promise<string>;
390
392
  buy(amount: bigint): Promise<string>;
391
- getOPPMessages(address?: string): Promise<OPPAssertion[]>;
392
- getOPPStatus(): Promise<any>;
393
- /**
394
- * ETH Prelaunch function to list the Stake ReceiptNFTs owned by a specific user
395
- * @param address address to query the receipts for
396
- * @returns array of receipts
397
- */
398
- fetchPrelaunchReceipts(address?: string): Promise<preLaunchReceipt[]>;
399
- getEthStats(): Promise<any>;
400
393
  /**
401
394
  * Resolve the user's ETH + liqETH balances.
402
395
  *
@@ -405,8 +398,22 @@ declare class EthereumStakingClient implements IStakingClient {
405
398
  * tracked = liqETH tracked balance (protocol/accounting view)
406
399
  */
407
400
  getPortfolio(): Promise<Portfolio>;
401
+ /**
402
+ * ETH Prelaunch function to list the Stake ReceiptNFTs owned by a specific user
403
+ * @param address address to query the receipts for
404
+ * @returns array of receipts
405
+ */
406
+ fetchPrelaunchReceipts(address?: string): Promise<preLaunchReceipt[]>;
407
+ getOPPMessages(address?: string): Promise<OPPAssertion[]>;
408
+ private ensureUser;
409
+ getSystemAPY(): Promise<number>;
410
+ getDepositFee(amount: bigint): Promise<bigint>;
411
+ getOPPStatus(): Promise<any>;
412
+ getEthStats(): Promise<any>;
408
413
  /**
409
414
  * Program-level prelaunch WIRE / tranche snapshot for Ethereum
415
+ *
416
+ * SUPPORTS READ-ONLY ACcESS
410
417
  */
411
418
  getTrancheSnapshot(options?: {
412
419
  chainID?: ChainID;
@@ -7432,6 +7439,13 @@ declare class SolanaStakingClient implements IStakingClient {
7432
7439
  * - extras: useful internal addresses and raw state for debugging/UX
7433
7440
  */
7434
7441
  getPortfolio(): Promise<Portfolio>;
7442
+ /**
7443
+ * Convenience helper to fetch the distribution userRecord for the current user.
7444
+ * Used by balance-correction flows and debugging.
7445
+ */
7446
+ getUserRecord(): Promise<DistributionUserRecord | null>;
7447
+ getSystemAPY(): Promise<number>;
7448
+ getDepositFee(amount: bigint): Promise<bigint>;
7435
7449
  /**
7436
7450
  * Unified, chain-agnostic tranche snapshot for Solana.
7437
7451
  *
@@ -7447,11 +7461,6 @@ declare class SolanaStakingClient implements IStakingClient {
7447
7461
  windowBefore?: number;
7448
7462
  windowAfter?: number;
7449
7463
  }): Promise<TrancheSnapshot>;
7450
- /**
7451
- * Convenience helper to fetch the distribution userRecord for the current user.
7452
- * Used by balance-correction flows and debugging.
7453
- */
7454
- getUserRecord(): Promise<DistributionUserRecord | null>;
7455
7464
  /**
7456
7465
  * Send a signed transaction over HTTP RPC and wait for confirmation.
7457
7466
  * Throws if the transaction fails.
@@ -7479,7 +7488,7 @@ declare class SolanaStakingClient implements IStakingClient {
7479
7488
  * Guard for all write operations (deposit/withdraw/stake/unstake/buy).
7480
7489
  * Ensures we have a Wire pubKey and an Anchor wallet pubKey, and that they match.
7481
7490
  */
7482
- ensureWriteAccess(): void;
7491
+ ensureUser(): void;
7483
7492
  }
7484
7493
 
7485
7494
  /**
package/lib/stake.js CHANGED
@@ -8565,7 +8565,7 @@ class SolanaStakingClient {
8565
8565
  }
8566
8566
  deposit(amountLamports) {
8567
8567
  return __async$8(this, null, function* () {
8568
- this.ensureWriteAccess();
8568
+ this.ensureUser();
8569
8569
  if (amountLamports <= BigInt(0)) {
8570
8570
  throw new Error("Deposit amount must be greater than zero.");
8571
8571
  }
@@ -8580,7 +8580,7 @@ class SolanaStakingClient {
8580
8580
  }
8581
8581
  withdraw(amountLamports) {
8582
8582
  return __async$8(this, null, function* () {
8583
- this.ensureWriteAccess();
8583
+ this.ensureUser();
8584
8584
  if (amountLamports <= BigInt(0)) {
8585
8585
  throw new Error("Withdraw amount must be greater than zero.");
8586
8586
  }
@@ -8595,7 +8595,7 @@ class SolanaStakingClient {
8595
8595
  }
8596
8596
  stake(amountLamports) {
8597
8597
  return __async$8(this, null, function* () {
8598
- this.ensureWriteAccess();
8598
+ this.ensureUser();
8599
8599
  if (!amountLamports || amountLamports <= BigInt(0)) {
8600
8600
  throw new Error("Stake amount must be greater than zero.");
8601
8601
  }
@@ -8609,7 +8609,7 @@ class SolanaStakingClient {
8609
8609
  }
8610
8610
  unstake(amountLamports) {
8611
8611
  return __async$8(this, null, function* () {
8612
- this.ensureWriteAccess();
8612
+ this.ensureUser();
8613
8613
  if (!amountLamports || amountLamports <= BigInt(0)) {
8614
8614
  throw new Error("Unstake amount must be greater than zero.");
8615
8615
  }
@@ -8623,7 +8623,7 @@ class SolanaStakingClient {
8623
8623
  }
8624
8624
  buy(amountLamports) {
8625
8625
  return __async$8(this, null, function* () {
8626
- this.ensureWriteAccess();
8626
+ this.ensureUser();
8627
8627
  if (!amountLamports || amountLamports <= BigInt(0)) {
8628
8628
  throw new Error("liqSOL pretoken purchase requires a positive amount.");
8629
8629
  }
@@ -8725,6 +8725,18 @@ class SolanaStakingClient {
8725
8725
  };
8726
8726
  });
8727
8727
  }
8728
+ getUserRecord() {
8729
+ return __async$8(this, null, function* () {
8730
+ if (!this.pubKey) throw new Error("User pubKey is undefined");
8731
+ return this.distributionClient.getUserRecord(this.solPubKey);
8732
+ });
8733
+ }
8734
+ getSystemAPY() {
8735
+ return Promise.resolve(0);
8736
+ }
8737
+ getDepositFee(amount) {
8738
+ return Promise.resolve(BigInt(0));
8739
+ }
8728
8740
  getTrancheSnapshot(options) {
8729
8741
  return __async$8(this, null, function* () {
8730
8742
  const {
@@ -8748,15 +8760,9 @@ class SolanaStakingClient {
8748
8760
  });
8749
8761
  });
8750
8762
  }
8751
- getUserRecord() {
8752
- return __async$8(this, null, function* () {
8753
- if (!this.pubKey) throw new Error("User pubKey is undefined");
8754
- return this.distributionClient.getUserRecord(this.solPubKey);
8755
- });
8756
- }
8757
8763
  sendAndConfirmHttp(signed, ctx) {
8758
8764
  return __async$8(this, null, function* () {
8759
- this.ensureWriteAccess();
8765
+ this.ensureUser();
8760
8766
  const signature = yield this.connection.sendRawTransaction(
8761
8767
  signed.serialize(),
8762
8768
  {
@@ -8783,13 +8789,13 @@ class SolanaStakingClient {
8783
8789
  }
8784
8790
  signTransaction(tx) {
8785
8791
  return __async$8(this, null, function* () {
8786
- this.ensureWriteAccess();
8792
+ this.ensureUser();
8787
8793
  return this.anchor.wallet.signTransaction(tx);
8788
8794
  });
8789
8795
  }
8790
8796
  sendTransaction(signed) {
8791
8797
  return __async$8(this, null, function* () {
8792
- this.ensureWriteAccess();
8798
+ this.ensureUser();
8793
8799
  return this.anchor.sendAndConfirm(signed);
8794
8800
  });
8795
8801
  }
@@ -8801,7 +8807,7 @@ class SolanaStakingClient {
8801
8807
  return { tx, blockhash, lastValidBlockHeight };
8802
8808
  });
8803
8809
  }
8804
- ensureWriteAccess() {
8810
+ ensureUser() {
8805
8811
  if (!this.pubKey || !this.anchor.wallet.publicKey) {
8806
8812
  throw new Error("User Authorization required: pubKey is undefined");
8807
8813
  }
@@ -29640,8 +29646,12 @@ class EthereumStakingClient {
29640
29646
  constructor(config) {
29641
29647
  this.config = config;
29642
29648
  try {
29643
- this.provider = config.provider;
29644
- this.signer = this.provider.getSigner();
29649
+ if (config.provider) {
29650
+ this.provider = config.provider;
29651
+ this.signer = this.provider.getSigner();
29652
+ } else {
29653
+ this.provider = new ethers.ethers.providers.JsonRpcProvider(config.network.rpcUrls[0]);
29654
+ }
29645
29655
  this.pubKey = config.pubKey;
29646
29656
  this.contractService = new EthereumContractService({
29647
29657
  provider: this.provider,
@@ -29664,6 +29674,7 @@ class EthereumStakingClient {
29664
29674
  }
29665
29675
  deposit(amount) {
29666
29676
  return __async(this, null, function* () {
29677
+ this.ensureUser();
29667
29678
  const amountWei = ethers.BigNumber.isBigNumber(amount) ? amount : ethers.BigNumber.from(amount);
29668
29679
  const result = yield this.convertClient.performDeposit(amountWei);
29669
29680
  return result.txHash;
@@ -29671,6 +29682,7 @@ class EthereumStakingClient {
29671
29682
  }
29672
29683
  withdraw(amount) {
29673
29684
  return __async(this, null, function* () {
29685
+ this.ensureUser();
29674
29686
  const address = yield this.signer.getAddress();
29675
29687
  const amountWei = ethers.BigNumber.from(amount);
29676
29688
  const result = yield this.convertClient.performWithdraw(address, amountWei);
@@ -29679,6 +29691,7 @@ class EthereumStakingClient {
29679
29691
  }
29680
29692
  stake(amount) {
29681
29693
  return __async(this, null, function* () {
29694
+ this.ensureUser();
29682
29695
  const walletAddress = yield this.signer.getAddress();
29683
29696
  const amountWei = ethers.BigNumber.from(amount);
29684
29697
  const result = yield this.stakeClient.performStake(amountWei, walletAddress);
@@ -29692,6 +29705,7 @@ class EthereumStakingClient {
29692
29705
  }
29693
29706
  unstakePrelaunch(tokenId, recipient) {
29694
29707
  return __async(this, null, function* () {
29708
+ this.ensureUser();
29695
29709
  const tokenIdBigNum = ethers.BigNumber.from(tokenId);
29696
29710
  const result = yield this.stakeClient.performWithdrawStake(tokenIdBigNum, recipient);
29697
29711
  return result.txHash;
@@ -29699,44 +29713,17 @@ class EthereumStakingClient {
29699
29713
  }
29700
29714
  buy(amount) {
29701
29715
  return __async(this, null, function* () {
29716
+ this.ensureUser();
29702
29717
  const buyer = yield this.signer.getAddress();
29703
29718
  yield this.updateMockAggregatorPrice();
29704
29719
  let result = yield this.pretokenClient.purchasePretokensWithLiqETH(amount, buyer);
29705
29720
  return result && result.txHash ? result.txHash : "Error - no resulting txHash";
29706
29721
  });
29707
29722
  }
29708
- getOPPMessages(address) {
29709
- return __async(this, null, function* () {
29710
- if (!address) address = yield this.signer.getAddress();
29711
- return yield this.oppClient.getMessages(address);
29712
- });
29713
- }
29714
- getOPPStatus() {
29715
- return __async(this, null, function* () {
29716
- return yield this.oppClient.getStatus();
29717
- });
29718
- }
29719
- fetchPrelaunchReceipts(address) {
29720
- return __async(this, null, function* () {
29721
- if (address === void 0) address = yield this.signer.getAddress();
29722
- return yield this.receiptClient.stakeReceipts(address);
29723
- });
29724
- }
29725
- getEthStats() {
29726
- return __async(this, null, function* () {
29727
- let withdrawDelay = yield this.contract.DepositManager.withdrawDelay();
29728
- let minDeposit = yield this.contract.DepositManager.minDeposit();
29729
- let rewardCooldown = yield this.contract.DepositManager.rewardCooldown();
29730
- return {
29731
- withdrawDelay,
29732
- minDeposit,
29733
- rewardCooldown
29734
- };
29735
- });
29736
- }
29737
29723
  getPortfolio() {
29738
29724
  return __async(this, null, function* () {
29739
29725
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
29726
+ this.ensureUser();
29740
29727
  const walletAddress = yield this.signer.getAddress();
29741
29728
  const nativeBalance = yield this.provider.getBalance(walletAddress);
29742
29729
  const nativeDecimals = (_c = (_b = (_a = this.network) == null ? void 0 : _a.nativeCurrency) == null ? void 0 : _b.decimals) != null ? _c : 18;
@@ -29775,6 +29762,50 @@ class EthereumStakingClient {
29775
29762
  return portfolio;
29776
29763
  });
29777
29764
  }
29765
+ fetchPrelaunchReceipts(address) {
29766
+ return __async(this, null, function* () {
29767
+ this.ensureUser();
29768
+ if (address === void 0) address = yield this.signer.getAddress();
29769
+ return yield this.receiptClient.stakeReceipts(address);
29770
+ });
29771
+ }
29772
+ getOPPMessages(address) {
29773
+ return __async(this, null, function* () {
29774
+ this.ensureUser();
29775
+ if (!address) address = yield this.signer.getAddress();
29776
+ return yield this.oppClient.getMessages(address);
29777
+ });
29778
+ }
29779
+ ensureUser() {
29780
+ if (!this.signer) {
29781
+ throw new Error(
29782
+ "EthereumStakingClient: write operation requires a wallet-connected Web3 provider"
29783
+ );
29784
+ }
29785
+ }
29786
+ getSystemAPY() {
29787
+ return Promise.resolve(0);
29788
+ }
29789
+ getDepositFee(amount) {
29790
+ return Promise.resolve(BigInt(0));
29791
+ }
29792
+ getOPPStatus() {
29793
+ return __async(this, null, function* () {
29794
+ return yield this.oppClient.getStatus();
29795
+ });
29796
+ }
29797
+ getEthStats() {
29798
+ return __async(this, null, function* () {
29799
+ let withdrawDelay = yield this.contract.DepositManager.withdrawDelay();
29800
+ let minDeposit = yield this.contract.DepositManager.minDeposit();
29801
+ let rewardCooldown = yield this.contract.DepositManager.rewardCooldown();
29802
+ return {
29803
+ withdrawDelay,
29804
+ minDeposit,
29805
+ rewardCooldown
29806
+ };
29807
+ });
29808
+ }
29778
29809
  getTrancheSnapshot(options) {
29779
29810
  return __async(this, null, function* () {
29780
29811
  const {