@wireio/stake 0.0.6 → 0.1.1

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.
Files changed (48) hide show
  1. package/README.md +260 -13
  2. package/lib/stake.browser.js +4861 -4218
  3. package/lib/stake.browser.js.map +1 -1
  4. package/lib/stake.d.ts +434 -6484
  5. package/lib/stake.js +5059 -4371
  6. package/lib/stake.js.map +1 -1
  7. package/lib/stake.m.js +4861 -4218
  8. package/lib/stake.m.js.map +1 -1
  9. package/package.json +2 -2
  10. package/src/assets/solana/idl/liqsol_core.json +4239 -0
  11. package/src/assets/solana/idl/liqsol_token.json +183 -0
  12. package/src/assets/solana/idl/validator_leaderboard.json +296 -250
  13. package/src/assets/solana/types/liqsol_core.ts +4245 -0
  14. package/src/assets/solana/types/liqsol_token.ts +189 -0
  15. package/src/assets/solana/types/validator_leaderboard.ts +296 -250
  16. package/src/index.ts +2 -5
  17. package/src/networks/ethereum/contract.ts +138 -36
  18. package/src/networks/ethereum/ethereum.ts +167 -38
  19. package/src/networks/ethereum/types.ts +32 -1
  20. package/src/networks/solana/clients/deposit.client.ts +92 -139
  21. package/src/networks/solana/clients/distribution.client.ts +302 -178
  22. package/src/networks/solana/clients/leaderboard.client.ts +40 -160
  23. package/src/networks/solana/constants.ts +238 -69
  24. package/src/networks/solana/program.ts +27 -93
  25. package/src/networks/solana/solana.ts +181 -36
  26. package/src/networks/solana/types.ts +47 -0
  27. package/src/networks/solana/utils.ts +522 -93
  28. package/src/scripts/fetch-artifacts.sh +24 -0
  29. package/src/scripts/tsconfig.json +17 -0
  30. package/src/staker/staker.ts +35 -30
  31. package/src/staker/types.ts +25 -22
  32. package/src/assets/solana/idl/deposit.json +0 -260
  33. package/src/assets/solana/idl/distribution.json +0 -736
  34. package/src/assets/solana/idl/liq_sol_token.json +0 -275
  35. package/src/assets/solana/idl/stake_controller.json +0 -1788
  36. package/src/assets/solana/idl/stake_registry.json +0 -435
  37. package/src/assets/solana/idl/treasury.json +0 -336
  38. package/src/assets/solana/idl/validator_registry.json +0 -418
  39. package/src/assets/solana/idl/yield_oracle.json +0 -32
  40. package/src/assets/solana/types/deposit.ts +0 -266
  41. package/src/assets/solana/types/distribution.ts +0 -742
  42. package/src/assets/solana/types/liq_sol_token.ts +0 -281
  43. package/src/assets/solana/types/stake_controller.ts +0 -1794
  44. package/src/assets/solana/types/stake_registry.ts +0 -441
  45. package/src/assets/solana/types/treasury.ts +0 -342
  46. package/src/assets/solana/types/validator_registry.ts +0 -424
  47. package/src/assets/solana/types/yield_oracle.ts +0 -38
  48. package/src/utils.ts +0 -9
@@ -1,14 +1,35 @@
1
1
  // src/staker/staker.ts
2
2
 
3
- import { ChainID, Curve, EvmChainID, SolChainID } from '@wireio/core';
4
- import { IStakingClient, StakeBalance, StakerConfig } from './types';
3
+ import { ChainID, EvmChainID, SolChainID } from '@wireio/core';
4
+ import { IStakingClient, StakerConfig } from './types';
5
5
  import { SolanaStakingClient } from '../networks/solana/solana';
6
6
  import { EthereumStakingClient } from '../networks/ethereum/ethereum';
7
7
 
8
8
  export class Staker {
9
+ public selectedChainID?: ChainID;
9
10
  private clients: Map<ChainID, IStakingClient> = new Map();
10
11
 
11
- constructor(config: StakerConfig | StakerConfig[]) {
12
+ /**
13
+ * Get the staking client for the currently selected chain.
14
+ * @returns The staking client instance.
15
+ */
16
+ get client(): IStakingClient | undefined {
17
+ return this.selectedChainID && this.isConfigured(this.selectedChainID)
18
+ ? this.clients.get(this.selectedChainID) : undefined;
19
+ }
20
+
21
+ /** Is there a client configured for this chain? */
22
+ isConfigured(chainId: ChainID): boolean {
23
+ return this.clients.has(chainId);
24
+ }
25
+
26
+ /** List of configured chains */
27
+ listConfigured(): ChainID[] {
28
+ return [...this.clients.keys()];
29
+ }
30
+
31
+ constructor(config: StakerConfig | StakerConfig[], selectedChainID?: ChainID) {
32
+ if (!config) throw new Error('StakerConfig is required');
12
33
  if (!Array.isArray(config)) config = [config];
13
34
 
14
35
  config.forEach((cfg) => {
@@ -17,40 +38,24 @@ export class Staker {
17
38
  this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
18
39
  break;
19
40
 
20
- // case EvmChainID.Sepolia:
21
- // this.clients.set(EvmChainID.Sepolia, new EthereumStakingClient(cfg));
22
- // break;
41
+ case EvmChainID.Hoodi:
42
+ this.clients.set(EvmChainID.Hoodi, new EthereumStakingClient(cfg));
43
+ break;
23
44
  default:
24
- throw new Error(`Unsupported network curve: ${cfg.network.name}`);
45
+ // console.log(`No staking client available for chain ${cfg.network.chainId}`);
46
+ // throw new Error(`Unsupported network curve: ${cfg.network.name}`);
25
47
  }
26
48
  });
27
- }
28
-
29
- /** Return the raw client (if any) for a chain */
30
- getClient(chainId: ChainID): IStakingClient | undefined {
31
- return this.clients.get(chainId);
32
- }
33
49
 
34
- /** Convenience: ensure a client exists or throw a friendly error */
35
- private ensureClient(chainId: ChainID): IStakingClient {
36
- const c = this.clients.get(chainId);
37
- if (!c) throw new Error(`Staker not initialized for chain ${chainId}`);
38
- return c;
50
+ this.selectedChainID = selectedChainID;
39
51
  }
40
52
 
41
53
  /**
42
- * Deposit funds into the staking pool.
43
- * @param chainId The chain ID to deposit into.
44
- * @param amount The amount to deposit (in smallest unit i.e. Lamport or Wei).
45
- * @returns The transaction signature.
54
+ * Select a chain. Returns true if a client exists for it, false otherwise.
55
+ * (We still record the selectedChainID so the UI can reflect the chosen chain.)
46
56
  */
47
- deposit(chainId: ChainID, amount: number): Promise<string> {
48
- return this.ensureClient(chainId).deposit(amount);
57
+ setChain(chainID: ChainID): boolean {
58
+ this.selectedChainID = chainID;
59
+ return this.clients.has(chainID);
49
60
  }
50
-
51
- getBalance(chainId: ChainID): Promise<StakeBalance> {
52
- return this.ensureClient(chainId).setBalances();
53
- }
54
-
55
- // …withdraw, claimRewards, etc…
56
61
  }
@@ -1,41 +1,44 @@
1
1
  // types.ts
2
2
 
3
3
  import { BaseSignerWalletAdapter } from '@solana/wallet-adapter-base';
4
- import { Transaction, VersionedTransaction } from '@solana/web3.js';
5
- import { ChainID, Curve, ExternalNetwork, ProviderType, PublicKey } from '@wireio/core';
6
- import { ethers } from 'ethers';
4
+ import { PublicKey as SolPubKey } from '@solana/web3.js';
5
+ import { ExternalNetwork, PublicKey } from '@wireio/core';
6
+ import { BigNumberish, ethers } from 'ethers';
7
7
 
8
- export type SolanaTransaction = Transaction | VersionedTransaction
9
- export interface IStakingClient{
8
+ export interface IStakingClient {
10
9
  pubKey: PublicKey;
11
10
  network: ExternalNetwork;
12
11
 
13
- balanceNative: number;
14
- balanceLiquid: number;
15
-
16
12
  /** Amount is in the chain's smallest unit (lamports/wei, etc.) */
17
13
  deposit(amount: number): Promise<string>;
18
14
 
19
- /** Update the native and liquid balances. */
20
- setBalances(): Promise<StakeBalance>;
21
-
22
- // /** Return native balance in the chain’s smallest unit (lamports for Sol) */
23
- // getBalanceNative(): Promise<number>;
15
+ /** Register any untracked LIQ staked tokens */
16
+ register(): Promise<string>;
24
17
 
25
- // /** Return liquid balance in the chain’s smallest unit (lamports for Sol) */
26
- // getBalanceLiquid(): Promise<number>;
18
+ /** Fetch the portfolio for the LIQ stake user */
19
+ getPortfolio(): Promise<Portfolio>;
27
20
  }
28
21
 
29
- /**
30
- * Union config for our unified Staker
31
- */
32
22
  export type StakerConfig = {
33
23
  network: ExternalNetwork;
34
24
  provider: BaseSignerWalletAdapter | ethers.providers.Web3Provider;
35
25
  pubKey: PublicKey;
36
26
  }
37
27
 
38
- export interface StakeBalance {
39
- native: number;
40
- liquid: number;
41
- }
28
+ export interface Portfolio {
29
+ /** Native SOL balance on chain */
30
+ native: BalanceView;
31
+ /** Actual liquid SOL balance from ATA */
32
+ actual: BalanceView;
33
+ /** Tracked liquid SOL balance from distribution program */
34
+ tracked: BalanceView;
35
+ /** Extra PDAs and account addresses */
36
+ extras?: Record<string, any>;
37
+ }
38
+
39
+ export type BalanceView = {
40
+ amount: BigNumberish; // raw on-chain integer value
41
+ decimals: number; // number of decimal places
42
+ symbol?: string; // optional token symbol identifier
43
+ ata?: SolPubKey; // associated token account address
44
+ };
@@ -1,260 +0,0 @@
1
- {
2
- "address": "8dtZVExD471mgT5hx8PWMZQT1YJ6aBbTdYw8BbydCdFJ",
3
- "metadata": {
4
- "name": "deposit",
5
- "version": "0.1.0",
6
- "spec": "0.1.0",
7
- "description": "Created with Anchor"
8
- },
9
- "instructions": [
10
- {
11
- "name": "deposit",
12
- "discriminator": [
13
- 242,
14
- 35,
15
- 198,
16
- 137,
17
- 82,
18
- 225,
19
- 242,
20
- 182
21
- ],
22
- "accounts": [
23
- {
24
- "name": "user",
25
- "writable": true,
26
- "signer": true
27
- },
28
- {
29
- "name": "program_authority",
30
- "writable": true,
31
- "pda": {
32
- "seeds": [
33
- {
34
- "kind": "const",
35
- "value": [
36
- 112,
37
- 114,
38
- 111,
39
- 103,
40
- 114,
41
- 97,
42
- 109,
43
- 95,
44
- 97,
45
- 117,
46
- 116,
47
- 104,
48
- 111,
49
- 114,
50
- 105,
51
- 116,
52
- 121
53
- ]
54
- }
55
- ]
56
- }
57
- },
58
- {
59
- "name": "treasury_wallet",
60
- "writable": true
61
- },
62
- {
63
- "name": "system_program",
64
- "address": "11111111111111111111111111111111"
65
- },
66
- {
67
- "name": "token_program"
68
- },
69
- {
70
- "name": "associated_token_program",
71
- "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
72
- },
73
- {
74
- "name": "stake_controller_program",
75
- "address": "2BLSWVneoJAFXTDW2siQuEaZ7RUPTb9df482VChToK7K"
76
- },
77
- {
78
- "name": "liqsol_program"
79
- },
80
- {
81
- "name": "yield_oracle_program",
82
- "address": "ABMUzgJCoJ17WPYvxZg4Biuo5oCaEbuD4svUVGFBTWCz"
83
- },
84
- {
85
- "name": "stake_program",
86
- "address": "Stake11111111111111111111111111111111111111"
87
- },
88
- {
89
- "name": "distribution_program",
90
- "address": "4MAXmFPeLotiGBt1BRWQwUYrWcsvGKrWWKxMwiMgKfci"
91
- },
92
- {
93
- "name": "liqsol_mint",
94
- "writable": true
95
- },
96
- {
97
- "name": "user_ata",
98
- "writable": true,
99
- "pda": {
100
- "seeds": [
101
- {
102
- "kind": "account",
103
- "path": "user"
104
- },
105
- {
106
- "kind": "account",
107
- "path": "token_program"
108
- },
109
- {
110
- "kind": "account",
111
- "path": "liqsol_mint"
112
- }
113
- ],
114
- "program": {
115
- "kind": "const",
116
- "value": [
117
- 140,
118
- 151,
119
- 37,
120
- 143,
121
- 78,
122
- 36,
123
- 137,
124
- 241,
125
- 187,
126
- 61,
127
- 16,
128
- 41,
129
- 20,
130
- 142,
131
- 13,
132
- 131,
133
- 11,
134
- 90,
135
- 19,
136
- 153,
137
- 218,
138
- 255,
139
- 16,
140
- 132,
141
- 4,
142
- 142,
143
- 123,
144
- 216,
145
- 219,
146
- 233,
147
- 248,
148
- 89
149
- ]
150
- }
151
- }
152
- },
153
- {
154
- "name": "liqsol_mint_authority"
155
- },
156
- {
157
- "name": "reserve_pool",
158
- "writable": true
159
- },
160
- {
161
- "name": "vault",
162
- "writable": true
163
- },
164
- {
165
- "name": "ephemeral_stake",
166
- "writable": true
167
- },
168
- {
169
- "name": "controller_state"
170
- },
171
- {
172
- "name": "user_record",
173
- "writable": true
174
- },
175
- {
176
- "name": "distribution_state",
177
- "writable": true
178
- },
179
- {
180
- "name": "instructions_sysvar",
181
- "address": "Sysvar1nstructions1111111111111111111111111"
182
- },
183
- {
184
- "name": "clock",
185
- "address": "SysvarC1ock11111111111111111111111111111111"
186
- },
187
- {
188
- "name": "stake_history",
189
- "address": "SysvarStakeHistory1111111111111111111111111"
190
- },
191
- {
192
- "name": "rent",
193
- "address": "SysvarRent111111111111111111111111111111111"
194
- }
195
- ],
196
- "args": [
197
- {
198
- "name": "amount",
199
- "type": "u64"
200
- },
201
- {
202
- "name": "seed",
203
- "type": "u32"
204
- }
205
- ]
206
- }
207
- ],
208
- "errors": [
209
- {
210
- "code": 6000,
211
- "name": "DepositTooSmall",
212
- "msg": "Deposit amount is below minimum required"
213
- },
214
- {
215
- "code": 6001,
216
- "name": "NotInitialized",
217
- "msg": "Deposit Router not initialized"
218
- },
219
- {
220
- "code": 6002,
221
- "name": "InvalidAuthority",
222
- "msg": "Invalid authority"
223
- },
224
- {
225
- "code": 6003,
226
- "name": "InsufficientFunds",
227
- "msg": "Insufficient funds"
228
- },
229
- {
230
- "code": 6004,
231
- "name": "Overflow",
232
- "msg": "Arithmetic overflow"
233
- },
234
- {
235
- "code": 6005,
236
- "name": "CalculationFailure",
237
- "msg": "Calculation failure"
238
- },
239
- {
240
- "code": 6006,
241
- "name": "NothingToMint",
242
- "msg": "Cannot mint zero tokens"
243
- },
244
- {
245
- "code": 6007,
246
- "name": "InvalidAccount",
247
- "msg": "Invalid account provided"
248
- },
249
- {
250
- "code": 6008,
251
- "name": "InsufficientFundsForStake",
252
- "msg": "Insufficient funds remaining after reserving fees to proceed with staking"
253
- },
254
- {
255
- "code": 6009,
256
- "name": "UnauthorizedProgram",
257
- "msg": "Unauthorized program attempting to call this instruction"
258
- }
259
- ]
260
- }