@wireio/stake 0.0.6 → 0.1.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.
- package/README.md +203 -13
- package/lib/stake.browser.js +2800 -3329
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +376 -6261
- package/lib/stake.js +2937 -3476
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +2800 -3329
- package/lib/stake.m.js.map +1 -1
- package/package.json +2 -2
- package/src/assets/solana/idl/deposit.json +46 -10
- package/src/assets/solana/idl/distribution.json +40 -8
- package/src/assets/solana/idl/liq_sol_token.json +25 -2
- package/src/assets/solana/idl/mint_helper.json +110 -0
- package/src/assets/solana/idl/read_tracked_balance.json +140 -0
- package/src/assets/solana/idl/stake_controller.json +1141 -780
- package/src/assets/solana/idl/treasury.json +1 -227
- package/src/assets/solana/idl/validator_leaderboard.json +88 -47
- package/src/assets/solana/idl/validator_registry.json +115 -46
- package/src/assets/solana/idl/yield_oracle.json +1 -1
- package/src/assets/solana/types/deposit.ts +46 -10
- package/src/assets/solana/types/distribution.ts +40 -8
- package/src/assets/solana/types/liq_sol_token.ts +25 -2
- package/src/assets/solana/types/mint_helper.ts +116 -0
- package/src/assets/solana/types/read_tracked_balance.ts +146 -0
- package/src/assets/solana/types/stake_controller.ts +1141 -780
- package/src/assets/solana/types/treasury.ts +1 -227
- package/src/assets/solana/types/validator_leaderboard.ts +88 -47
- package/src/assets/solana/types/validator_registry.ts +115 -46
- package/src/assets/solana/types/yield_oracle.ts +1 -1
- package/src/index.ts +3 -4
- package/src/networks/ethereum/ethereum.ts +2 -2
- package/src/networks/solana/clients/deposit.client.ts +71 -80
- package/src/networks/solana/clients/distribution.client.ts +392 -141
- package/src/networks/solana/clients/leaderboard.client.ts +82 -107
- package/src/networks/solana/constants.ts +141 -56
- package/src/networks/solana/program.ts +36 -89
- package/src/networks/solana/solana.ts +168 -34
- package/src/networks/solana/types.ts +57 -0
- package/src/scripts/fetch-artifacts.sh +24 -0
- package/src/staker/staker.ts +32 -28
- package/src/staker/types.ts +24 -21
- package/src/assets/solana/idl/stake_registry.json +0 -435
- package/src/networks/solana/utils.ts +0 -122
- /package/src/{utils.ts → common/utils.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,28 +1,218 @@
|
|
|
1
|
-
# LIQ Staking
|
|
1
|
+
# @wireio/stake — LIQ Staking SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for interacting with the **Liquidity Staking System (LIQ)** on **Wire Network**.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
|
27
|
+
The package is published on npm.
|
|
12
28
|
|
|
13
|
-
```
|
|
29
|
+
```bash
|
|
14
30
|
npm install @wireio/stake
|
|
15
|
-
# or
|
|
16
|
-
yarn add @wireio/stake
|
|
17
31
|
```
|
|
18
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<string, any>;
|
|
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 & 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
|
+
|
|
19
209
|
## Autodocs
|
|
20
210
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
211
|
+
- **API Docs:** <https://Wire-Network.github.io/sdk-stake/>
|
|
212
|
+
- **Coverage:** coming soon
|
|
23
213
|
|
|
24
|
-
|
|
214
|
+
---
|
|
25
215
|
|
|
26
|
-
|
|
216
|
+
## License
|
|
27
217
|
|
|
28
|
-
|
|
218
|
+
MIT – see [LICENSE](./LICENSE).
|