@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
package/README.md CHANGED
@@ -1,28 +1,275 @@
1
- # LIQ Staking Module
1
+ # @wireio/stake โ€” LIQ Staking SDK
2
2
 
3
- Library for interacting with the Liquidity Staking System on Wire Network
3
+ TypeScript SDK for interacting with the **Liquidity Staking System (LIQ)** on **Wire Network**.
4
4
 
5
- For networks: ETH, SOL, SUI, etc.
5
+ - **Today:** Solana (Wire testnet) implementation
6
+ - **Next:** Ethereum (shared interface, coming soon)
7
+ - **Later:** Sui and additional chains (all conforming to the same `IStakingClient` interface)
6
8
 
7
- Features:
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - ๐Ÿ”‘ Unified **Staker** facade across multiple chains
14
+ - ๐Ÿ’ธ **Deposit** (stake) funds on supported networks
15
+ - ๐Ÿงพ **Register** untracked liquid stake tokens (correct & register flow on Solana)
16
+ - ๐Ÿ“Š **Portfolio** helper (native / actual / tracked balances)
17
+ - ๐Ÿงฑ Low-level Solana clients:
18
+ - `DepositClient` โ€“ builds & submits deposit transactions
19
+ - `DistributionClient` โ€“ balance reconciliation & registration (updateUser)
20
+ - `ValidatorLeaderboardClient` โ€“ Interact with the validator leaderboard program
21
+ - ๐Ÿงฉ Clean, typed program access via `SolanaProgramService`
22
+
23
+ ---
8
24
 
9
25
  ## Installation
10
26
 
11
- The `@wireio/stake` package is distributed as a module on [npm](https://www.npmjs.com/package/@wireio/stake).
27
+ The package is published on npm.
12
28
 
13
- ```sh
29
+ ```bash
14
30
  npm install @wireio/stake
15
- # or
16
- yarn add @wireio/stake
31
+ ```
32
+
33
+ ---
34
+
35
+ ## Getting Started
36
+
37
+ ### 1) Construct a `Staker`
38
+
39
+ Create the staker with one or more chain configs (only Solana client is active today):
40
+
41
+ ```ts
42
+ import { Staker, StakerConfig } from '@wireio/stake';
43
+ import { PublicKey as WirePubKey, KeyType } from '@wireio/core';
44
+ import { BaseSignerWalletAdapter } from '@solana/wallet-adapter-base';
45
+
46
+ // Example: Solana (Wire testnet)
47
+ const adapter: BaseSignerWalletAdapter = /* your connected wallet adapter */;
48
+ const network = {
49
+ chainId: 13371337, // your Wire testnet chain ID
50
+ name: 'Wire Testnet',
51
+ rpcUrls: ['https://...http', 'wss://...ws'],
52
+ nativeCurrency: { symbol: 'SOL', decimals: 9 }
53
+ };
54
+
55
+ const cfg: StakerConfig = {
56
+ provider: adapter,
57
+ network,
58
+ pubKey: new WirePubKey(KeyType.ED, adapter.publicKey!.toBytes()),
59
+ };
60
+
61
+ const staker = new Staker(cfg /* or [cfg1, cfg2, ...] */, network.chainId);
62
+ ```
63
+
64
+ > **Note:** If you pass multiple networks, `Staker` can switch between them via `staker.setChain(chainId)`.
65
+
66
+ ### 2) Get the active client & portfolio
67
+
68
+ ```ts
69
+ const client = staker.client; // current chainโ€™s client (or undefined if not configured)
70
+ if (!client) throw new Error('Chain not configured');
71
+
72
+ const portfolio = await client.getPortfolio();
73
+ /**
74
+ * portfolio.native.amount // wallet SOL in lamports
75
+ * portfolio.actual.amount // liqSOL in ATA
76
+ * portfolio.tracked.amount // tracked on distribution program
77
+ */
78
+ ```
79
+
80
+ ### 3) Deposit
81
+
82
+ Amounts must be passed in the chainโ€™s **smallest unit** (lamports on Solana, wei on EVM).
83
+
84
+ ```ts
85
+ // Human โ†’ smallest unit (e.g., 0.5 SOL โ†’ 0.5 * 10^9)
86
+ const human = 0.5;
87
+ const smallest = Math.round(human * Math.pow(10, client.network.nativeCurrency.decimals));
88
+
89
+ const sig = await client.deposit(smallest);
90
+ console.log('Deposit tx:', sig);
91
+ ```
92
+
93
+ ### 4) Register (Correct & Register on Solana)
94
+
95
+ Registers any **untracked** liqSOL (if your actual token balance > tracked) and, if necessary,
96
+ first corrects other users with positive tracked deltas to free available balance.
97
+
98
+ ```ts
99
+ const sig = await client.register();
100
+ console.log('Register tx:', sig);
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Solana-specific Clients (low-level)
106
+
107
+ You typically donโ€™t need these directly if you use `Staker`, but theyโ€™re available.
108
+
109
+ ### `DepositClient`
110
+
111
+ - `buildDepositTx(user: PublicKey, amount: number)` โ†’ `{ transaction, ephemeralStakePubkey }`
112
+ - `deposit(user: PublicKey, amount: number)` โ†’ confirmed signature
113
+
114
+ ### `DistributionClient`
115
+
116
+ - `getDistributionState()`, `getUserRecord(user)`
117
+ - `getActualBalance(user)`, `getTrackedBalance(user)`
118
+ - `updateUser(targetUser)` โ€“ register/correct a user
119
+ - `buildCorrectRegisterTx({ amount?, preloadCandidates? })` โ€“ build a tx that:
120
+ - if your mismatch < 0 โ†’ just **correct self**
121
+ - else โ†’ **free available** by updating top candidates, then **register self**
122
+
123
+ ---
124
+
125
+ ## Core Types
126
+
127
+ ```ts
128
+ import { BaseSignerWalletAdapter } from '@solana/wallet-adapter-base';
129
+ import { PublicKey as SolPubKey } from '@solana/web3.js';
130
+ import { ExternalNetwork, PublicKey } from '@wireio/core';
131
+ import { ethers } from 'ethers';
132
+
133
+ export interface IStakingClient {
134
+ pubKey: PublicKey;
135
+ network: ExternalNetwork;
136
+
137
+ /** Amount is in the chain's smallest unit (lamports/wei, etc.) */
138
+ deposit(amount: number): Promise<string>;
139
+
140
+ /** Register any untracked LIQ staked tokens */
141
+ register(): Promise<string>;
142
+
143
+ /** Fetch the portfolio for the LIQ stake user */
144
+ getPortfolio(): Promise<Portfolio>;
145
+ }
146
+
147
+ export type StakerConfig = {
148
+ network: ExternalNetwork;
149
+ provider: BaseSignerWalletAdapter | ethers.providers.Web3Provider;
150
+ pubKey: PublicKey;
151
+ }
152
+
153
+ export interface Portfolio {
154
+ /** Native SOL balance on chain */
155
+ native: BalanceView;
156
+ /** Actual liquid SOL balance from ATA */
157
+ actual: BalanceView;
158
+ /** Tracked liquid SOL balance from distribution program */
159
+ tracked: BalanceView;
160
+ /** Extra PDAs and account addresses */
161
+ extras?: Record&lt;string, any&gt;;
162
+ }
163
+
164
+ export type BalanceView = {
165
+ amount: bigint; // raw on-chain integer value
166
+ decimals: number; // number of decimal places
167
+ symbol?: string; // optional token symbol identifier
168
+ ata?: SolPubKey; // associated token account address
169
+ };
170
+ ```
171
+
172
+ ---
173
+
174
+ ## Multi-chain Notes &amp; Roadmap
175
+
176
+ - **Ethereum** client is planned (will implement `IStakingClient` with the same methods).
177
+ - **Sui** (and other chains) to follow the same interface for a unified developer experience.
178
+ - Your app can rely on the `Staker` facade today and gain new chains later without API changes.
179
+
180
+ ---
181
+
182
+ ## Error Handling
183
+
184
+ - All public methods throw on failure. Wrap calls with `try/catch` and surface errors to your users.
185
+ - For Solana, failed transactions carry logs; some SDK methods surface logs in thrown errors.
186
+
187
+ ---
188
+
189
+ ## Development
190
+
191
+ Requires:
192
+
193
+ - **Node.js** (LTS recommended)
194
+ - **npm**
195
+ - **Make** (optional, for convenience targets)
196
+
197
+ Common tasks:
198
+
199
+ ```bash
200
+ # Install deps
201
+ npm ci
202
+
203
+ # Build
204
+ npm run prepare
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Testnet Deployment 11/19/25
210
+ ```
211
+ RPC URL: https://sol.gitgo.app/
212
+ Deploying cluster: http://solana-genesis:8899
213
+ Upgrade authority: ./wallets/deploymentWallet/universalDeploymentWallet.json
214
+ Deploying program "liq_sol_token"...
215
+ Program path: /app/program/target/deploy/liq_sol_token.so...
216
+ Program Id: FsRiJLqerifBSpZjzdWxSyJ3sQmJ3ScFwHv4VRi9ghVT
217
+
218
+ Signature: 26JPXjiNXBzPk7p8PQx8y1bQog1baWCjyRqWYyQKNxEpK9reAHpeNwcw9Sh7dAyaAhyuosQueE4XrnTZibXdwx99
219
+
220
+ Deploying program "validator_leaderboard"...
221
+ Program path: /app/program/target/deploy/validator_leaderboard.so...
222
+ Program Id: 9SW7GqRTzEc5KjSnXXTqvojcyCvzHjn8J4xdBeS91Gbq
223
+
224
+ Signature: 5nobXLXnnMD9MmPjcJ5xbmawV4wDXxCYEBR2CwoBkvEQ4iLAVQCpzZWw7Pgb7eGwk6bu88VvpC2occCJh2EYajfJ
225
+
226
+ Deploying program "liqsol_core"...
227
+ Program path: /app/program/target/deploy/liqsol_core.so...
228
+ Program Id: 8zBGapo9WvnGskgXyKmgNgLACimELqJzAPEHyShWg5Dj
229
+
230
+ Signature: 2wakzKzaxkRLC4nMw3t8pCSL4PfG32EoSKZXo6og8mAgVq54twWUhqG5JLAQejvsqGgEBaZ7zwWj9tvsijt8vwbi
231
+
232
+ Deploy success
233
+ ๐Ÿช™ Initializing token mint...
234
+ ๐Ÿš€ Initializing Liquid SOL Token...
235
+
236
+ ๐Ÿ“ Mint Authority PDA: 3XwUD4Sy6Aua1ceC8yEHTWk16vMmmWAdFMfJpzwvwveD
237
+ ๐Ÿช™ Deterministic Mint Address: Empuao5KEK7zq3rFz8Q8fVSmNwhbkrqkNctdfZKdY9b2
238
+ ๐Ÿ”— Network: http://solana-genesis:8899
239
+ ๐Ÿ‘ค Payer: Ebar1nLiEpHEFH4DmYasqJHMm3fn6g1jJY3WBfwc6GsD
240
+ ๐Ÿ“ Token Name: Liquid Staked SOL
241
+ ๐Ÿท๏ธ Token Symbol: liqSOL
242
+
243
+ ๐Ÿฆ Receiver ATA: 3B9dtsRGYvB1aVQYR8yHfzbbECgohHkH7U67v6gPJ1HQ
244
+ ๐Ÿ”„ Sending mint creation transaction...
245
+ โœ… Liquid SOL Token mint created! Transaction: 5fgNuuNorhBcvjp28AQhHK1jkSG6fRCPBbxsHbEnB3CyuRYPRTGybH2gjLhGdb7kD8CUohibUzd1wnPLUDUauret
246
+
247
+ ๐Ÿ“Š Created Mint Information:
248
+ Mint Address: Empuao5KEK7zq3rFz8Q8fVSmNwhbkrqkNctdfZKdY9b2
249
+ Mint Authority: 3XwUD4Sy6Aua1ceC8yEHTWk16vMmmWAdFMfJpzwvwveD
250
+ Token Name: Liquid Staked SOL
251
+ Token Symbol: liqSOL
252
+ Decimals: 9
253
+ Receiver ATA: 3B9dtsRGYvB1aVQYR8yHfzbbECgohHkH7U67v6gPJ1HQ
254
+
255
+ ๐ŸŽ‰ Liquid SOL Token is ready to use!
256
+ Mint Address: Empuao5KEK7zq3rFz8Q8fVSmNwhbkrqkNctdfZKdY9b2
257
+ Program ID: FsRiJLqerifBSpZjzdWxSyJ3sQmJ3ScFwHv4VRi9ghVT
258
+ Mint Authority PDA: 3XwUD4Sy6Aua1ceC8yEHTWk16vMmmWAdFMfJpzwvwveD
259
+ โ–ถ Initializing Distribution Program...
260
+ Distribution Program: 8zBGapo9WvnGskgXyKmgNgLACimELqJzAPEHyShWg5Dj
261
+ Wallet: Ebar1nLiEpHEFH4DmYasqJHMm3fn6g1jJY3WBfwc6GsD
262
+ LiqSOL Mint: Empuao5KEK7zq3rFz8Q8fVSmNwhbkrqkNctdfZKdY9b2
263
+ Distribution State PDA: BHMC9S1J8jy7nitVt4CHGeRHVK8kh9jpm4xKhf4cJWgn
17
264
  ```
18
265
 
19
266
  ## Autodocs
20
267
 
21
- - [API Documentation](https://Wire-Network.github.io/sdk-stake/)
22
- - Code Coverage Report - Coming soon
268
+ - **API Docs:** <https://Wire-Network.github.io/sdk-stake/>
269
+ - **Coverage:** coming soon
23
270
 
24
- ## Developing
271
+ ---
25
272
 
26
- You need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.
273
+ ## License
27
274
 
28
- Clone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.
275
+ MIT โ€“ see [LICENSE](./LICENSE).