@ssv-labs/ssv-sdk 0.1.3 → 1.0.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.
Files changed (61) hide show
  1. package/README.html +4 -7
  2. package/README.md +56 -29
  3. package/dist/{KeyShares-B_4l2THg.js → KeyShares-Bk9uzOlK.js} +194 -51
  4. package/dist/{KeyShares-ClzHwMUy.mjs → KeyShares-Dlp4Pa3b.mjs} +198 -55
  5. package/dist/abi/mainnet/v4/getter.d.ts +699 -74
  6. package/dist/abi/mainnet/v4/setter.d.ts +939 -59
  7. package/dist/api/subgraph/index.d.ts +50 -48
  8. package/dist/config/create.d.ts +2 -2
  9. package/dist/config/globals.d.ts +3 -0
  10. package/dist/{globals-CDOcDUnk.mjs → config-BdEJjnYA.mjs} +107 -79
  11. package/dist/{globals-DsaKgq3v.js → config-ClGS9Tic.js} +73 -45
  12. package/dist/contract-interactions/create.d.ts +1 -1
  13. package/dist/contract-interactions/types.d.ts +9 -3
  14. package/dist/graphql/graphql.d.ts +4799 -921
  15. package/dist/keys.js +1 -1
  16. package/dist/keys.mjs +5 -5
  17. package/dist/libs/api/index.d.ts +1 -0
  18. package/dist/libs/cluster/index.d.ts +3 -1
  19. package/dist/libs/cluster/methods/deposit.d.ts +150 -4
  20. package/dist/libs/cluster/methods/exit-validators.d.ts +149 -0
  21. package/dist/libs/cluster/methods/index.d.ts +3 -1
  22. package/dist/libs/cluster/methods/liquidate-cluster.d.ts +149 -0
  23. package/dist/libs/cluster/methods/liquidate-ssv.d.ts +430 -0
  24. package/dist/libs/cluster/methods/migrate-cluster-to-eth.d.ts +431 -0
  25. package/dist/libs/cluster/methods/reactivate-cluster.d.ts +149 -0
  26. package/dist/libs/cluster/methods/register-validators.d.ts +2222 -309
  27. package/dist/libs/cluster/methods/remove-validators.d.ts +149 -0
  28. package/dist/libs/cluster/methods/set-fee-recipient.d.ts +149 -0
  29. package/dist/libs/cluster/methods/withdraw.d.ts +149 -0
  30. package/dist/libs/dao/index.d.ts +8 -0
  31. package/dist/libs/dao/methods/commit-root.d.ts +432 -0
  32. package/dist/libs/dao/methods/index.d.ts +3 -0
  33. package/dist/libs/dao/methods/update-network-fee-ssv.d.ts +430 -0
  34. package/dist/libs/dao/methods/withdraw-network-ssv-earnings.d.ts +430 -0
  35. package/dist/libs/operator/index.d.ts +1525 -32
  36. package/dist/libs/operator/methods.d.ts +1732 -3
  37. package/dist/libs/ssv-keys/Encryption/__test__/RsaKeys.d.ts +1 -1
  38. package/dist/libs/ssv-keys/KeyShares/KeySharesItem.d.ts +1 -1
  39. package/dist/libs/ssv-keys/SSVKeys.d.ts +1 -1
  40. package/dist/libs/ssv-keys/exceptions/index.d.ts +1 -1
  41. package/dist/libs/ssv-keys/index.d.ts +1 -1
  42. package/dist/libs/ssv-keys/interfaces/index.d.ts +2 -2
  43. package/dist/libs/utils/index.d.ts +8 -4
  44. package/dist/libs/utils/methods/calc-deposit-from-runway.d.ts +11 -0
  45. package/dist/libs/utils/methods/get-cluster-balance.d.ts +4 -1
  46. package/dist/libs/utils/methods/index.d.ts +1 -0
  47. package/dist/libs/utils/methods/keyshares.d.ts +4 -2
  48. package/dist/libs/utils/methods/keystores.d.ts +4 -4
  49. package/dist/libs/utils/methods/write-keyshares-file.d.ts +16 -0
  50. package/dist/main.d.ts +1 -0
  51. package/dist/main.js +2970 -733
  52. package/dist/main.mjs +2961 -746
  53. package/dist/sdk.d.ts +8 -4
  54. package/dist/types/contract-interactions.d.ts +11 -0
  55. package/dist/types/methods.d.ts +4 -3
  56. package/dist/utils/cluster.d.ts +3 -3
  57. package/dist/utils/funding.d.ts +29 -0
  58. package/dist/utils/zod/config.d.ts +1 -1
  59. package/dist/utils.js +38 -38
  60. package/dist/utils.mjs +34 -34
  61. package/package.json +18 -6
package/README.html CHANGED
@@ -51,7 +51,7 @@
51
51
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
52
52
  </code></pre><h3 id="cluster-management">Cluster management </h3>
53
53
  <pre data-role="codeBlock" data-info="typescript" class="language-typescript typescript"><code><span class="token comment">// Get cluster balance</span>
54
- <span class="token keyword keyword-import">import</span> <span class="token punctuation">{</span> getClusterSnapshot <span class="token punctuation">}</span> <span class="token keyword keyword-from">from</span> <span class="token string">'@/utils/cluster'</span>
54
+ <span class="token keyword keyword-import">import</span> <span class="token punctuation">{</span> toSolidityCluster <span class="token punctuation">}</span> <span class="token keyword keyword-from">from</span> <span class="token string">'@/utils/cluster'</span>
55
55
  <span class="token keyword keyword-import">import</span> <span class="token punctuation">{</span> <span class="token constant">SSVSDK</span> <span class="token punctuation">}</span> <span class="token keyword keyword-from">from</span> <span class="token string">'ssv-sdk'</span>
56
56
 
57
57
  <span class="token comment">// Initialize with basic configuration</span>
@@ -66,7 +66,7 @@
66
66
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
67
67
 
68
68
  <span class="token keyword keyword-const">const</span> balance <span class="token operator">=</span> <span class="token keyword keyword-await">await</span> sdk<span class="token punctuation">.</span>contract<span class="token punctuation">.</span>write<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
69
- cluster<span class="token operator">:</span> <span class="token function">getClusterSnapshot</span><span class="token punctuation">(</span>cluster<span class="token punctuation">)</span><span class="token punctuation">,</span>
69
+ cluster<span class="token operator">:</span> <span class="token function">toSolidityCluster</span><span class="token punctuation">(</span>cluster<span class="token punctuation">)</span><span class="token punctuation">,</span>
70
70
  clusterOwner<span class="token operator">:</span> <span class="token string">'0x'</span><span class="token punctuation">,</span>
71
71
  operatorIds<span class="token operator">:</span> operators<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span>o<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token function">BigInt</span><span class="token punctuation">(</span>o<span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
72
72
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
@@ -76,11 +76,8 @@
76
76
  <span class="token keyword keyword-await">await</span> sdk<span class="token punctuation">.</span>clusters<span class="token punctuation">.</span><span class="token function">deposit</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
77
77
  id<span class="token operator">:</span> <span class="token string">'...'</span><span class="token punctuation">,</span>
78
78
  amount<span class="token operator">:</span> <span class="token function">parseEther</span><span class="token punctuation">(</span><span class="token string">'1.5'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
79
- options<span class="token operator">:</span> <span class="token punctuation">{</span>
80
- approve<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// Automatically triggers token approval transaction if the allowance is lower than the deposit amount</span>
81
- <span class="token punctuation">}</span><span class="token punctuation">,</span>
82
79
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
83
- </code></pre><h3 id="environment-setup-for-testing">Environment Setup for Testing </h3>
80
+ </code></pre><p><strong>Note:</strong> The current <code>sdk.clusters.deposit</code> path is payable and does not perform ERC-20 allowance checks or <code>approve</code> calls.</p><h3 id="environment-setup-for-testing">Environment Setup for Testing </h3>
84
81
  <p>To run tests, you'll need to set up your environment variables. Create a <code>.env</code> file in the root directory of your project using the provided <code>.env.example</code> as a template:</p>
85
82
  <pre data-role="codeBlock" data-info="bash" class="language-bash bash"><code><span class="token comment"># Copy the example env file</span>
86
83
  <span class="token function">cp</span> .env.example .env
@@ -99,4 +96,4 @@
99
96
 
100
97
 
101
98
 
102
- </body></html>
99
+ </body></html>
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://ssv.network/wp-content/uploads/2024/06/full_logo_white.svg" alt="SSV Network" width="300"/>
2
+ <img src="https://framerusercontent.com/assets/SxrtOSpELBgEtirWSlWPnBE0cd4.png" alt="SSV Network" width="300"/>
3
3
  </p>
4
4
 
5
5
  <h1 align="center">SSV SDK</h1>
@@ -18,9 +18,10 @@ The SSV SDK is a TypeScript library for interacting with the SSV network, enabli
18
18
 
19
19
  ## Core Modules
20
20
 
21
- The SDK consists of four main modules:
21
+ The SDK consists of five main modules:
22
22
 
23
23
  - **Clusters**: Manage validator clusters, handle deposits, and register validators
24
+ - **DAO**: Manage DAO-related actions and values
24
25
  - **Operators**: Interact with network operators and manage operator relationships
25
26
  - **API**: Access network data, query states, and retrieve operational information
26
27
  - **Utils**: Helper functions for keyshare validation, share generation, and other utilities
@@ -43,79 +44,105 @@ pnpm install @ssv-labs/ssv-sdk
43
44
  ### Initialize the SDK
44
45
 
45
46
  ```typescript
46
- import { SSVSDK, chains } from '@ssv-labs/ssv-sdk'
47
- import { createPublicClient, createWalletClient, http } from 'viem'
48
- import { privateKeyToAccount } from 'viem/accounts'
47
+ import { SSVSDK, chains } from '@ssv-labs/ssv-sdk';
48
+ import { createPublicClient, createWalletClient, http } from 'viem';
49
+ import { privateKeyToAccount } from 'viem/accounts';
49
50
 
50
- const chain = chains.mainnet // or chains.holesky
51
- const transport = http()
51
+ const chain = chains.mainnet; // or chains.hoodi
52
+ const transport = http();
52
53
 
53
54
  const publicClient = createPublicClient({
54
55
  chain,
55
56
  transport,
56
- })
57
+ });
57
58
 
58
- const account = privateKeyToAccount('0x...')
59
+ const account = privateKeyToAccount('0x...');
59
60
  const walletClient = createWalletClient({
60
61
  account,
61
62
  chain,
62
63
  transport,
63
- })
64
+ });
64
65
 
65
66
  const sdk = new SSVSDK({
66
67
  publicClient,
67
68
  walletClient,
68
- })
69
+ });
69
70
  ```
70
71
 
71
72
  ### API Examples
72
73
 
73
74
  ```typescript
74
75
  // Query operators
75
- const operators = await sdk.api.getOperators({
76
+ const { operators } = await sdk.api.getOperators({
76
77
  operatorIds: ['220', '221', '223', '224'],
77
- })
78
+ });
78
79
 
79
80
  // Get owner nonce
80
- const nonce = await sdk.api.getOwnerNonce({
81
+ const { nonce } = await sdk.api.getOwnerNonce({
81
82
  owner: 'your_wallet_address',
82
- })
83
+ });
84
+
85
+ // Export SDK-generated payloads into a webapp-ready keyshares JSON file (Node.js only)
86
+ await sdk.utils.writeKeysharesFile({
87
+ path: './keyshares-webapp.json',
88
+ shares,
89
+ ownerAddress: 'your_wallet_address',
90
+ nonce,
91
+ });
83
92
  ```
84
93
 
94
+ ### API Compatibility Notes
95
+
96
+ `getClusterSnapshot` is the canonical cluster snapshot API.
97
+
98
+ Snapshot-aware SDK read methods return the queried data together with the subgraph snapshot block number, for example:
99
+
100
+ - `sdk.api.getOwnerNonce(...) -> { blockNumber, nonce }`
101
+ - `sdk.api.getOperators(...) -> { blockNumber, operators }`
102
+ - `sdk.api.getClusterSnapshot(...) -> { blockNumber, cluster }`
103
+
104
+ | SDK version | Method name |
105
+ | ----------- | ------------------------------------ |
106
+ | `0.1.x` | `sdk.api.getClusterSnapshot({ id })` |
107
+ | `1.x` | `sdk.api.getClusterSnapshot({ id })` |
108
+
109
+ `sdk.api.toSolidityCluster` is no longer part of the public subgraph API. The internal utility `toSolidityCluster(...)` in `utils/cluster` still exists for converting cluster data into the Solidity struct shape used by contract calls.
110
+
111
+ `sdk.utils.writeKeysharesFile(...)` is a Node.js utility and relies on filesystem access.
112
+
85
113
  ### Cluster Management
86
114
 
87
115
  ```typescript
88
- import { parseEther } from 'viem'
116
+ import { parseEther } from 'viem';
89
117
 
90
118
  // Deposit to cluster
91
- await sdk.clusters.deposit(
92
- {
93
- id: 'your_cluster_id',
94
- amount: parseEther('30'),
95
- },
96
- {
97
- approve: true, // Auto-approve token if needed
98
- },
99
- )
119
+ await sdk.clusters.deposit({
120
+ id: 'your_cluster_id',
121
+ amount: parseEther('30'),
122
+ });
100
123
  ```
101
124
 
125
+ > Note: The current `sdk.clusters.deposit` path is payable and does not perform ERC-20 allowance checks or `approve` calls.
126
+
102
127
  ### Register Validators
128
+
103
129
  To register validators, you'll need to:
104
130
 
105
131
  1. Create shares from your keyshares JSON file
106
132
  2. Register the validator using the created shares
133
+
107
134
  ```typescript
108
- import { parseEther } from 'viem'
135
+ import { parseEther } from 'viem';
109
136
 
110
137
  // Your keyshares JSON file containing the validator's data
111
- import keyshares from 'path/to/keyshares.json'
138
+ import keyshares from 'path/to/keyshares.json';
112
139
 
113
140
  // First, validate and create shares from your keyshares
114
141
  try {
115
142
  const result = await sdk.utils.validateSharesPreRegistration({
116
143
  operatorIds: ['220', '221', '223', '224'],
117
144
  keyshares,
118
- })
145
+ });
119
146
 
120
147
  // Register validators using the clusters API
121
148
  const receipt = await sdk.clusters
@@ -125,7 +152,7 @@ try {
125
152
  depositAmount: parseEther('2'),
126
153
  },
127
154
  })
128
- .then((tx) => tx.wait())
155
+ .then((tx) => tx.wait());
129
156
  } catch (e) {
130
157
  // something went wrong
131
158
  }