@wireio/stake 0.1.2 → 0.2.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.
@@ -5,7 +5,7 @@
5
5
  * IDL can be found at `target/idl/liqsol_token.json`.
6
6
  */
7
7
  export type LiqsolToken = {
8
- "address": "AY6sWK1dt23rkAiqiETwaEcbjhJCwb5cNC6hVWadZLFf",
8
+ "address": "HEAKvfg2X7K4zbGDiAbfuu5abxQyk1HbKVgskZZFXrUx",
9
9
  "metadata": {
10
10
  "name": "liqsolToken",
11
11
  "version": "0.1.0",
@@ -5,7 +5,7 @@
5
5
  * IDL can be found at `target/idl/validator_leaderboard.json`.
6
6
  */
7
7
  export type ValidatorLeaderboard = {
8
- "address": "5Nf6jL5B2qkMbnLoN3RTT1sKcBKrrsRnovTBDZXcQnfo",
8
+ "address": "BcMW7wN54FexYaB7Xujvag5uUQ1WoDoGbzVg1VEXPBhV",
9
9
  "metadata": {
10
10
  "name": "validatorLeaderboard",
11
11
  "version": "0.1.0",
package/src/index.ts CHANGED
@@ -16,3 +16,4 @@ export * from './networks/solana/utils';
16
16
  export * from './networks/solana/clients/deposit.client';
17
17
  export * from './networks/solana/clients/distribution.client';
18
18
  export * from './networks/solana/clients/leaderboard.client';
19
+ export * from './networks/solana/clients/outpost.client';
@@ -1,12 +1,9 @@
1
- // src/networks/ethereum/ethereum.ts
2
-
3
1
  import { BigNumber, BigNumberish, ethers } from 'ethers';
4
2
  import { IStakingClient, Portfolio, StakerConfig } from '../../staker/types';
5
3
  import { PublicKey as WirePubKey } from '@wireio/core';
6
4
  import { ERC20Abi, EthereumContractService } from './contract'; // TODO replace with staking contract ABI
7
5
  import { DepositEvent, DepositResult } from './types';
8
6
 
9
- // TODO extend to implement ISTAKINGCLIENT
10
7
  export class EthereumStakingClient implements IStakingClient {
11
8
  public readonly pubKey: WirePubKey;
12
9
  private readonly provider: ethers.providers.Web3Provider;
@@ -34,7 +31,7 @@ export class EthereumStakingClient implements IStakingClient {
34
31
  }
35
32
 
36
33
  // ---------------------------------------------------------------------
37
- // Public IStakingClient.deposit
34
+ // Public IStakingClient Interface Methods
38
35
  // ---------------------------------------------------------------------
39
36
 
40
37
  /**
@@ -49,10 +46,81 @@ export class EthereumStakingClient implements IStakingClient {
49
46
  : BigNumber.from(amount);
50
47
 
51
48
  const result = await this.performDeposit(amountWei);
52
- // For now, IStakingClient contract is: just return tx hash.
53
- // If/when you extend the interface, you can surface more here.
54
49
  return result.txHash;
55
50
  }
51
+
52
+ // TODO
53
+ async withdraw(): Promise<string> {
54
+ throw new Error("Method not yet implemented.");
55
+ }
56
+
57
+ // TODO
58
+ async stake(): Promise<string> {
59
+ throw new Error("Method not yet implemented.");
60
+ }
61
+
62
+ // TODO
63
+ async unstake(): Promise<string> {
64
+ throw new Error("Method not yet implemented.");
65
+ }
66
+
67
+ /**
68
+ * Resolve the user's ETH + liqETH balances.
69
+ *
70
+ * native = ETH in wallet
71
+ * actual = liqETH token balance (ERC-20)
72
+ * tracked = liqETH tracked balance (protocol/accounting view)
73
+ */
74
+ async getPortfolio(): Promise<Portfolio> {
75
+ const walletAddress = await this.signer.getAddress();
76
+ // console.log('getPortfolio() wallet address', walletAddress)
77
+ // 1) Native ETH balance
78
+ const nativeBalance = await this.provider.getBalance(walletAddress);
79
+ // console.log('nativeBalance', nativeBalance);
80
+ const nativeDecimals = this.network?.nativeCurrency?.decimals ?? 18;
81
+ const nativeSymbol = this.network?.nativeCurrency?.symbol ?? 'ETH';
82
+
83
+
84
+
85
+ // 2) liqETH ERC-20 balance (actual)
86
+ const liqBalance: ethers.BigNumber = await this.contract.LiqEth.balanceOf(walletAddress);
87
+ // console.log('liqBalance', liqBalance);
88
+
89
+ const liqDecimals = this.network?.nativeCurrency?.decimals ?? 18;
90
+ const liqSymbol = 'Liq' + (this.network?.nativeCurrency?.symbol ?? 'ETH');
91
+
92
+ const portfolio: Portfolio = {
93
+ native: {
94
+ amount: nativeBalance.toBigInt(),
95
+ decimals: nativeDecimals,
96
+ symbol: nativeSymbol,
97
+ },
98
+ liq: {
99
+ amount: liqBalance.toBigInt(),
100
+ decimals: liqDecimals,
101
+ symbol: liqSymbol,
102
+ },
103
+ tracked: {
104
+ amount: liqBalance.toBigInt(),
105
+ decimals: liqDecimals,
106
+ symbol: liqSymbol,
107
+ },
108
+ staked: { // TODO fetch staked balance from outpost
109
+ amount: BigNumber.from(0).toBigInt(),
110
+ decimals: liqDecimals,
111
+ symbol: liqSymbol,
112
+ },
113
+ chainID: this.network.chainId
114
+ }
115
+ // console.log('ETH PORTFOLIO', portfolio);
116
+ return portfolio;
117
+ }
118
+
119
+
120
+ // ---------------------------------------------------------------------
121
+ // Internal ETH Staking client helper functions
122
+ // ---------------------------------------------------------------------
123
+
56
124
  /**
57
125
  * Simulate a deposit via callStatic.
58
126
  *
@@ -111,50 +179,5 @@ export class EthereumStakingClient implements IStakingClient {
111
179
  };
112
180
  }
113
181
 
114
- /**
115
- * Resolve the user's ETH + liqETH balances.
116
- *
117
- * native = ETH in wallet
118
- * actual = liqETH token balance (ERC-20)
119
- * tracked = liqETH tracked balance (protocol/accounting view)
120
- */
121
- async getPortfolio(): Promise<Portfolio> {
122
- const walletAddress = await this.signer.getAddress();
123
-
124
- // 1) Native ETH balance
125
- const nativeBalance = await this.provider.getBalance(walletAddress);
126
- // console.log('nativeBalance', nativeBalance);
127
- const nativeDecimals = this.network?.nativeCurrency?.decimals ?? 18;
128
- const nativeSymbol = this.network?.nativeCurrency?.symbol ?? 'ETH';
129
-
130
- // 2) liqETH ERC-20 balance (actual)
131
- const liqBalance: ethers.BigNumber = await this.contract.LiqEth.balanceOf(walletAddress);
132
- // console.log('liqBalance', liqBalance);
133
-
134
- const liqDecimals = this.network?.nativeCurrency?.decimals ?? 18;
135
- const liqSymbol = 'Liq' + (this.network?.nativeCurrency?.symbol ?? 'ETH');
136
-
137
- const portfolio: Portfolio = {
138
- native: {
139
- amount: nativeBalance,
140
- decimals: nativeDecimals,
141
- symbol: nativeSymbol,
142
- },
143
- liq: {
144
- amount: liqBalance,
145
- decimals: liqDecimals,
146
- symbol: liqSymbol,
147
- },
148
- staked: { // TODO fetch staked balance from outpost
149
- amount: BigNumber.from(0),
150
- decimals: liqDecimals,
151
- symbol: liqSymbol,
152
- },
153
- chainID: this.network.chainId
154
- }
155
- // console.log('ETH PORTFOLIO', portfolio);
156
- return portfolio;
157
- }
158
-
159
182
  // TODO: implement withdraw, claimRewards, etc.
160
183
  }
@@ -34,22 +34,19 @@ import {
34
34
  derivePayoutStatePda,
35
35
  deriveEphemeralStakeAddress,
36
36
  } from '../constants';
37
+ import { WalletLike } from '../types';
37
38
 
38
39
  export class DepositClient {
39
40
  private program: Program<LiqsolCore>;
40
41
 
42
+ get wallet(): WalletLike { return this.provider.wallet; }
43
+
41
44
  constructor(private provider: AnchorProvider) {
42
45
  const svc = new SolanaProgramService(provider);
43
46
  this.program = svc.getProgram('liqsolCore');
44
47
  }
45
48
 
46
- async buildDepositTx(
47
- user: PublicKey,
48
- lamports: number
49
- ): Promise<{ transaction: Transaction; ephemeralStake: PublicKey }> {
50
-
51
- const program = this.program;
52
-
49
+ async buildDepositTx(amount: bigint, user = this.wallet.publicKey): Promise<Transaction> {
53
50
  // -------------------------------------------------------------
54
51
  // PDAs
55
52
  // -------------------------------------------------------------
@@ -91,8 +88,8 @@ export class DepositClient {
91
88
  // -------------------------------------------------------------
92
89
  // BUILD IX (MUST MATCH IDL)
93
90
  // -------------------------------------------------------------
94
- const ix: TransactionInstruction = await program.methods
95
- .deposit(new BN(lamports), seed)
91
+ const ix: TransactionInstruction = await this.program.methods
92
+ .deposit(new BN(amount.toString()), seed)
96
93
  .accounts({
97
94
  user,
98
95
  depositAuthority,
@@ -125,7 +122,6 @@ export class DepositClient {
125
122
  })
126
123
  .instruction();
127
124
 
128
- const tx = new Transaction().add(ix);
129
- return { transaction: tx, ephemeralStake };
125
+ return new Transaction().add(ix);
130
126
  }
131
127
  }
@@ -42,9 +42,7 @@ export class DistributionClient {
42
42
  this.program = svc.getProgram('liqsolCore');
43
43
  }
44
44
 
45
- get connection() {
46
- return this.provider.connection;
47
- }
45
+ get connection() { return this.provider.connection; }
48
46
 
49
47
  /**
50
48
  * Fetch the global distribution state account.