@wireio/stake 2.2.1 → 2.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wireio/stake",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "LIQ Staking Module for Wire Network",
5
5
  "homepage": "https://gitea.gitgo.app/Wire/sdk-stake",
6
6
  "license": "FSL-1.1-Apache-2.0",
@@ -0,0 +1,61 @@
1
+ import { BigNumber, ethers } from "ethers";
2
+ import { ClaimedEvent, DepositEvent, DepositResult, SharesBurnedEvent, ValidatorDepositedEvent } from "../types";
3
+ import { EthereumContractService } from "../contract";
4
+ import { formatContractErrors } from "../utils";
5
+
6
+ export class ValidatorClient {
7
+
8
+ private readonly contractService: EthereumContractService;
9
+
10
+ get contract() { return this.contractService.contract; }
11
+
12
+ constructor(contract: EthereumContractService) {
13
+ this.contractService = contract;
14
+ }
15
+
16
+
17
+ /**
18
+ *
19
+ * @param amountWei an amount of liqETH (in WEI) to stake to the Outpost
20
+ * @returns txHash (hash of the transaction), receipt, Staked event
21
+ */
22
+ async validatorDepositAndLockBond(): Promise<any> {
23
+ const amountWei: BigNumber = ethers.utils.parseEther("32");
24
+
25
+ // simulate call first
26
+ try {
27
+ await this.contract.DepositManager.callStatic.validatorDepositAndLockBond({ value: amountWei });
28
+ } catch (err: any) {
29
+ let errorObj = formatContractErrors(err);
30
+ throw new Error(errorObj.name ?? errorObj.raw)
31
+ }
32
+
33
+
34
+ // send the tx to stake liqeth
35
+ const tx = await this.contract.DepositManager.validatorDepositAndLockBond({ value: amountWei });
36
+
37
+ // Wait for 1 confirmation
38
+ const receipt = await tx.wait(1);
39
+
40
+ // Parse ValidatorDeposited event if present
41
+ let staked: ValidatorDepositedEvent | undefined;
42
+ const ev = receipt.events?.find((e) => e.event === 'Staked');
43
+
44
+ if (ev && ev.args) {
45
+ const { sender, amount, shares } = ev.args;
46
+ staked = {
47
+ sender,
48
+ amount: BigNumber.from(amount),
49
+ shares: BigNumber.from(shares),
50
+ };
51
+ }
52
+
53
+ return {
54
+ txHash: tx.hash,
55
+ receipt,
56
+ staked,
57
+ };
58
+ }
59
+
60
+
61
+ }
@@ -15,6 +15,7 @@ import { StakeClient } from './clients/stake.client';
15
15
  import { PretokenClient } from './clients/pretoken.client';
16
16
  import { OPPClient } from './clients/opp.client';
17
17
  import { ReceiptClient } from './clients/receipt.client';
18
+ import { ValidatorClient } from './clients/validator.client';
18
19
 
19
20
  export const INITIAL_TRANCHE_SUPPLY = 35000;
20
21
 
@@ -29,6 +30,7 @@ export class EthereumStakingClient implements IStakingClient {
29
30
  private stakeClient: StakeClient;
30
31
  private oppClient: OPPClient;
31
32
  private receiptClient: ReceiptClient;
33
+ private validatorClient: ValidatorClient;
32
34
 
33
35
 
34
36
  get contract() { return this.contractService.contract; }
@@ -56,6 +58,7 @@ export class EthereumStakingClient implements IStakingClient {
56
58
  this.stakeClient = new StakeClient(this.contractService);
57
59
  this.oppClient = new OPPClient(this.contractService);
58
60
  this.receiptClient = new ReceiptClient(this.contractService);
61
+ this.validatorClient = new ValidatorClient(this.contractService)
59
62
  }
60
63
  catch (error) {
61
64
  // console.error('Error initializing EthereumStakingClient:', error);
@@ -178,6 +181,21 @@ export class EthereumStakingClient implements IStakingClient {
178
181
  }
179
182
 
180
183
 
184
+ /**
185
+ * Validator functions
186
+ */
187
+ async validatorDeposit(): Promise<string> {
188
+ this.ensureUser();
189
+
190
+ let result = await this.validatorClient.validatorDepositAndLockBond();
191
+ return result && result.txHash ? result.txHash : "Error - no resulting txHash";
192
+ }
193
+
194
+
195
+
196
+
197
+
198
+
181
199
  /**
182
200
  * Resolve the user's ETH + liqETH balances.
183
201
  *
@@ -310,6 +328,8 @@ export class EthereumStakingClient implements IStakingClient {
310
328
  return await this.oppClient.getMessages(address);
311
329
  }
312
330
 
331
+
332
+
313
333
  // Ensure that signer wallet is available for write operations
314
334
  private ensureUser() {
315
335
  if (!this.signer) {
@@ -117,7 +117,6 @@ export interface ClaimedEvent {
117
117
  amount: BigNumber;
118
118
  }
119
119
 
120
-
121
120
  export interface WithdrawReceipt {
122
121
  tokenId: bigint;
123
122
  receipt: {
@@ -125,4 +124,12 @@ export interface WithdrawReceipt {
125
124
  ethBalance: BalanceView;
126
125
  readyAt: number;
127
126
  }
128
- }
127
+ }
128
+
129
+
130
+
131
+ export interface ValidatorDepositedEvent {
132
+ sender: string;
133
+ amount: BigNumber;
134
+ shares: BigNumber
135
+ }
package/src/types.ts CHANGED
@@ -70,6 +70,8 @@ export interface IStakingClient {
70
70
  minBufferLamports?: bigint; // minimum gas buffer (default ~0.01 SOL)
71
71
  balanceOverrideLamports?: bigint; // for tests/custom callers
72
72
  }): Promise<bigint>
73
+
74
+ validatorDeposit(): Promise<string>
73
75
  }
74
76
 
75
77
  /**