@autonomys/auto-consensus 1.5.1 → 1.5.3
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/dist/account.d.ts +26 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/account.js +26 -0
- package/dist/balances.d.ts +50 -0
- package/dist/balances.d.ts.map +1 -1
- package/dist/balances.js +50 -0
- package/dist/batch.d.ts +29 -0
- package/dist/batch.d.ts.map +1 -1
- package/dist/batch.js +29 -0
- package/dist/domain.d.ts +58 -1
- package/dist/domain.d.ts.map +1 -1
- package/dist/domain.js +116 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/info.d.ts +406 -0
- package/dist/info.d.ts.map +1 -1
- package/dist/info.js +406 -0
- package/dist/position/index.d.ts +42 -0
- package/dist/position/index.d.ts.map +1 -0
- package/dist/position/index.js +170 -0
- package/dist/position/price.d.ts +69 -0
- package/dist/position/price.d.ts.map +1 -0
- package/dist/position/price.js +137 -0
- package/dist/position/utils.d.ts +62 -0
- package/dist/position/utils.d.ts.map +1 -0
- package/dist/position/utils.js +73 -0
- package/dist/position.d.ts +4 -0
- package/dist/position.d.ts.map +1 -0
- package/dist/position.js +20 -0
- package/dist/remark.d.ts +29 -0
- package/dist/remark.d.ts.map +1 -1
- package/dist/remark.js +29 -0
- package/dist/staking.d.ts +305 -0
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +327 -4
- package/dist/transfer.d.ts +59 -0
- package/dist/transfer.d.ts.map +1 -1
- package/dist/transfer.js +59 -0
- package/dist/types/domain.d.ts +1 -0
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/position.d.ts +13 -0
- package/dist/types/position.d.ts.map +1 -0
- package/dist/types/position.js +2 -0
- package/dist/types/staking.d.ts +2 -2
- package/dist/types/staking.d.ts.map +1 -1
- package/dist/utils/format.d.ts +86 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +86 -0
- package/dist/utils/parse.d.ts +1 -1
- package/dist/utils/parse.d.ts.map +1 -1
- package/dist/utils/parse.js +5 -3
- package/dist/utils/query.d.ts +31 -0
- package/dist/utils/query.d.ts.map +1 -1
- package/dist/utils/query.js +31 -0
- package/dist/utils/sudo.d.ts +36 -0
- package/dist/utils/sudo.d.ts.map +1 -1
- package/dist/utils/sudo.js +36 -0
- package/package.json +3 -3
package/dist/info.js
CHANGED
|
@@ -16,32 +16,280 @@ exports.solutionRangeToPieces = solutionRangeToPieces;
|
|
|
16
16
|
const parse_1 = require("./utils/parse");
|
|
17
17
|
const query_1 = require("./utils/query");
|
|
18
18
|
const PIECE_SIZE = BigInt(1048576);
|
|
19
|
+
/**
|
|
20
|
+
* Executes an RPC call on the blockchain API.
|
|
21
|
+
*
|
|
22
|
+
* This is a generic function that allows calling any RPC method available on the blockchain API.
|
|
23
|
+
* RPC calls are remote procedure calls that interact with the blockchain node.
|
|
24
|
+
*
|
|
25
|
+
* @param api - The connected API instance
|
|
26
|
+
* @param methodPath - The RPC method path (e.g., 'chain.getHeader', 'system.health')
|
|
27
|
+
* @param params - Array of parameters to pass to the RPC method
|
|
28
|
+
* @returns Promise that resolves to the RPC call result
|
|
29
|
+
* @throws Error if the RPC call fails or method path is invalid
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { rpc } from '@autonomys/auto-consensus'
|
|
34
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
35
|
+
*
|
|
36
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
37
|
+
* const header = await rpc(api, 'chain.getHeader', [])
|
|
38
|
+
* const health = await rpc(api, 'system.health', [])
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
19
41
|
const rpc = (api_1, methodPath_1, ...args_1) => __awaiter(void 0, [api_1, methodPath_1, ...args_1], void 0, function* (api, methodPath, params = []) { return yield (0, query_1.queryMethodPath)(api, `rpc.${methodPath}`, params); });
|
|
20
42
|
exports.rpc = rpc;
|
|
43
|
+
/**
|
|
44
|
+
* Executes a storage query on the blockchain API.
|
|
45
|
+
*
|
|
46
|
+
* This is a generic function that allows querying any storage item available on the blockchain.
|
|
47
|
+
* Storage queries retrieve data that is stored on-chain in the blockchain's state.
|
|
48
|
+
*
|
|
49
|
+
* @param api - The connected API instance
|
|
50
|
+
* @param methodPath - The storage query path (e.g., 'system.account', 'balances.totalIssuance')
|
|
51
|
+
* @param params - Array of parameters to pass to the storage query
|
|
52
|
+
* @returns Promise that resolves to the storage query result
|
|
53
|
+
* @throws Error if the storage query fails or method path is invalid
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { query } from '@autonomys/auto-consensus'
|
|
58
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
59
|
+
*
|
|
60
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
61
|
+
* const totalIssuance = await query(api, 'balances.totalIssuance', [])
|
|
62
|
+
* const accountData = await query(api, 'system.account', ['5GrwvaEF5z...'])
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
21
65
|
const query = (api_1, methodPath_1, ...args_1) => __awaiter(void 0, [api_1, methodPath_1, ...args_1], void 0, function* (api, methodPath, params = []) { return yield (0, query_1.queryMethodPath)(api, `query.${methodPath}`, params); });
|
|
22
66
|
exports.query = query;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves the header information of the latest block.
|
|
69
|
+
*
|
|
70
|
+
* The block header contains metadata about a block including its number, parent hash,
|
|
71
|
+
* state root, and extrinsics root. This function gets the header of the current latest block.
|
|
72
|
+
*
|
|
73
|
+
* @param api - The connected API instance
|
|
74
|
+
* @returns Promise that resolves to the block Header
|
|
75
|
+
* @throws Error if the header query fails
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { header } from '@autonomys/auto-consensus'
|
|
80
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
81
|
+
*
|
|
82
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
83
|
+
* const blockHeader = await header(api)
|
|
84
|
+
* console.log(`Block number: ${blockHeader.number}`)
|
|
85
|
+
* console.log(`Parent hash: ${blockHeader.parentHash}`)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
23
88
|
const header = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.rpc)(api, 'chain.getHeader', []); });
|
|
24
89
|
exports.header = header;
|
|
90
|
+
/**
|
|
91
|
+
* Retrieves a complete block including its extrinsics.
|
|
92
|
+
*
|
|
93
|
+
* This function fetches a full block with all its transaction data (extrinsics).
|
|
94
|
+
* If no block hash is provided, it returns the latest block.
|
|
95
|
+
*
|
|
96
|
+
* @param api - The connected API instance
|
|
97
|
+
* @param blockHash - Optional block hash to fetch a specific block
|
|
98
|
+
* @returns Promise that resolves to a SignedBlock containing all block data
|
|
99
|
+
* @throws Error if the block query fails
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { block } from '@autonomys/auto-consensus'
|
|
104
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
105
|
+
*
|
|
106
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
107
|
+
*
|
|
108
|
+
* // Get latest block
|
|
109
|
+
* const latestBlock = await block(api)
|
|
110
|
+
*
|
|
111
|
+
* // Get specific block by hash
|
|
112
|
+
* const specificBlock = await block(api, '0x1234...')
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
25
115
|
const block = (api, blockHash) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.rpc)(api, 'chain.getBlock', [blockHash]); });
|
|
26
116
|
exports.block = block;
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves and parses all extrinsics from a block.
|
|
119
|
+
*
|
|
120
|
+
* Extrinsics are transactions or operations that modify the blockchain state.
|
|
121
|
+
* This function fetches a block and extracts all extrinsics in a parsed format
|
|
122
|
+
* for easier consumption.
|
|
123
|
+
*
|
|
124
|
+
* @param api - The connected API instance
|
|
125
|
+
* @param blockHash - Optional block hash to fetch extrinsics from a specific block
|
|
126
|
+
* @returns Promise that resolves to an array of parsed Extrinsic objects
|
|
127
|
+
* @throws Error if the block query or parsing fails
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* import { blockExtrinsics } from '@autonomys/auto-consensus'
|
|
132
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
133
|
+
*
|
|
134
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
135
|
+
* const extrinsics = await blockExtrinsics(api)
|
|
136
|
+
*
|
|
137
|
+
* extrinsics.forEach(ext => {
|
|
138
|
+
* console.log(`${ext.section}.${ext.method} by ${ext.signer}`)
|
|
139
|
+
* })
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
27
142
|
const blockExtrinsics = (api, blockHash) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.block)(api, blockHash).then((block) => (0, parse_1.parseBlockExtrinsics)(block)); });
|
|
28
143
|
exports.blockExtrinsics = blockExtrinsics;
|
|
144
|
+
/**
|
|
145
|
+
* Retrieves and parses all transfer-related extrinsics from a block.
|
|
146
|
+
*
|
|
147
|
+
* This function filters extrinsics to only include those related to token transfers,
|
|
148
|
+
* such as balance transfers and cross-chain transfers. It's useful for tracking
|
|
149
|
+
* token movement within a specific block.
|
|
150
|
+
*
|
|
151
|
+
* @param api - The connected API instance
|
|
152
|
+
* @param blockHash - Optional block hash to fetch transfers from a specific block
|
|
153
|
+
* @returns Promise that resolves to an array of transfer Extrinsic objects
|
|
154
|
+
* @throws Error if the block query or parsing fails
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* import { blockTransfers } from '@autonomys/auto-consensus'
|
|
159
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
160
|
+
*
|
|
161
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
162
|
+
* const transfers = await blockTransfers(api)
|
|
163
|
+
*
|
|
164
|
+
* console.log(`Found ${transfers.length} transfers in latest block`)
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
29
167
|
const blockTransfers = (api, blockHash) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.block)(api, blockHash).then((block) => (0, parse_1.parseBlockTransfers)(block)); });
|
|
30
168
|
exports.blockTransfers = blockTransfers;
|
|
169
|
+
/**
|
|
170
|
+
* Retrieves the current block number.
|
|
171
|
+
*
|
|
172
|
+
* This function gets the block number of the latest block on the blockchain.
|
|
173
|
+
* Block numbers increment sequentially as new blocks are produced.
|
|
174
|
+
*
|
|
175
|
+
* @param api - The connected API instance
|
|
176
|
+
* @returns Promise that resolves to the current block number as a number
|
|
177
|
+
* @throws Error if the block query fails
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* import { blockNumber } from '@autonomys/auto-consensus'
|
|
182
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
183
|
+
*
|
|
184
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
185
|
+
* const currentBlock = await blockNumber(api)
|
|
186
|
+
* console.log(`Current block: ${currentBlock}`)
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
31
189
|
const blockNumber = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
190
|
const _block = yield (0, exports.block)(api);
|
|
33
191
|
return parseInt(_block.block.header.number.toString());
|
|
34
192
|
});
|
|
35
193
|
exports.blockNumber = blockNumber;
|
|
194
|
+
/**
|
|
195
|
+
* Retrieves the hash of a block.
|
|
196
|
+
*
|
|
197
|
+
* This function gets the hash of a specific block by its number, or the latest
|
|
198
|
+
* block hash if no block number is provided. Block hashes are unique identifiers
|
|
199
|
+
* for each block.
|
|
200
|
+
*
|
|
201
|
+
* @param api - The connected API instance
|
|
202
|
+
* @param blockNumber - Optional block number to get hash for specific block
|
|
203
|
+
* @returns Promise that resolves to the block hash as a hex string
|
|
204
|
+
* @throws Error if the block hash query fails
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* import { blockHash } from '@autonomys/auto-consensus'
|
|
209
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
210
|
+
*
|
|
211
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
212
|
+
*
|
|
213
|
+
* // Get latest block hash
|
|
214
|
+
* const latestHash = await blockHash(api)
|
|
215
|
+
*
|
|
216
|
+
* // Get hash of specific block
|
|
217
|
+
* const specificHash = await blockHash(api, 1000)
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
36
220
|
const blockHash = (api, blockNumber) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
221
|
const _blockHash = yield (0, exports.rpc)(api, 'chain.getBlockHash', [blockNumber]);
|
|
38
222
|
return _blockHash.toString();
|
|
39
223
|
});
|
|
40
224
|
exports.blockHash = blockHash;
|
|
225
|
+
/**
|
|
226
|
+
* Retrieves the hash of the finalized head block.
|
|
227
|
+
*
|
|
228
|
+
* The finalized head is the latest block that has been finalized by the consensus
|
|
229
|
+
* mechanism and is considered irreversible. This provides the hash of that block.
|
|
230
|
+
*
|
|
231
|
+
* @param api - The connected API instance
|
|
232
|
+
* @returns Promise that resolves to the finalized head block hash
|
|
233
|
+
* @throws Error if the finalized head query fails
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* import { finalizedHead } from '@autonomys/auto-consensus'
|
|
238
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
239
|
+
*
|
|
240
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
241
|
+
* const finalizedHash = await finalizedHead(api)
|
|
242
|
+
* console.log(`Finalized block hash: ${finalizedHash}`)
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
41
245
|
const finalizedHead = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.rpc)(api, 'chain.getFinalizedHead', []); });
|
|
42
246
|
exports.finalizedHead = finalizedHead;
|
|
247
|
+
/**
|
|
248
|
+
* Retrieves the current network timestamp.
|
|
249
|
+
*
|
|
250
|
+
* This function gets the timestamp of the current block, which represents
|
|
251
|
+
* the time when the block was produced. The timestamp is set by block producers
|
|
252
|
+
* and represents network time.
|
|
253
|
+
*
|
|
254
|
+
* @param api - The connected API instance
|
|
255
|
+
* @returns Promise that resolves to the network timestamp as a Codec
|
|
256
|
+
* @throws Error if the timestamp query fails
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* import { networkTimestamp } from '@autonomys/auto-consensus'
|
|
261
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
262
|
+
*
|
|
263
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
264
|
+
* const timestamp = await networkTimestamp(api)
|
|
265
|
+
* const networkTime = new Date(Number(timestamp.toString()))
|
|
266
|
+
* console.log(`Network time: ${networkTime}`)
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
43
269
|
const networkTimestamp = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)(api, 'timestamp.now', []); });
|
|
44
270
|
exports.networkTimestamp = networkTimestamp;
|
|
271
|
+
/**
|
|
272
|
+
* Retrieves the current solution ranges for the consensus mechanism.
|
|
273
|
+
*
|
|
274
|
+
* Solution ranges are used in the Proof of Archival Storage consensus to determine
|
|
275
|
+
* the difficulty of finding valid solutions. This includes current and next solution
|
|
276
|
+
* ranges for both regular consensus and voting.
|
|
277
|
+
*
|
|
278
|
+
* @param api - The connected API instance
|
|
279
|
+
* @returns Promise that resolves to solution ranges object with current/next values
|
|
280
|
+
* @throws Error if the solution ranges query fails
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* import { solutionRanges } from '@autonomys/auto-consensus'
|
|
285
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
286
|
+
*
|
|
287
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
288
|
+
* const ranges = await solutionRanges(api)
|
|
289
|
+
* console.log(`Current solution range: ${ranges.current}`)
|
|
290
|
+
* console.log(`Next solution range: ${ranges.next}`)
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
45
293
|
const solutionRanges = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
294
|
const _solutionRanges = yield (0, exports.query)(api, 'subspace.solutionRanges', []);
|
|
47
295
|
const solution = _solutionRanges.toPrimitive();
|
|
@@ -53,8 +301,49 @@ const solutionRanges = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
53
301
|
};
|
|
54
302
|
});
|
|
55
303
|
exports.solutionRanges = solutionRanges;
|
|
304
|
+
/**
|
|
305
|
+
* Checks if the solution range should be adjusted.
|
|
306
|
+
*
|
|
307
|
+
* This function queries whether the consensus mechanism has determined that
|
|
308
|
+
* the solution range needs to be adjusted based on network conditions.
|
|
309
|
+
*
|
|
310
|
+
* @param api - The connected API instance
|
|
311
|
+
* @returns Promise that resolves to boolean indicating if adjustment is needed
|
|
312
|
+
* @throws Error if the query fails
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* import { shouldAdjustSolutionRange } from '@autonomys/auto-consensus'
|
|
317
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
318
|
+
*
|
|
319
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
320
|
+
* const shouldAdjust = await shouldAdjustSolutionRange(api)
|
|
321
|
+
* console.log(`Solution range adjustment needed: ${shouldAdjust}`)
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
56
324
|
const shouldAdjustSolutionRange = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)(api, 'subspace.shouldAdjustSolutionRange', []); });
|
|
57
325
|
exports.shouldAdjustSolutionRange = shouldAdjustSolutionRange;
|
|
326
|
+
/**
|
|
327
|
+
* Retrieves segment commitment information.
|
|
328
|
+
*
|
|
329
|
+
* Segment commitments are cryptographic commitments to data segments in the
|
|
330
|
+
* Autonomys network's decentralized storage system. This function retrieves
|
|
331
|
+
* all current segment commitments.
|
|
332
|
+
*
|
|
333
|
+
* @param api - The connected API instance
|
|
334
|
+
* @returns Promise that resolves to array of segment commitment entries
|
|
335
|
+
* @throws Error if the segment commitment query fails
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* import { segmentCommitment } from '@autonomys/auto-consensus'
|
|
340
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
341
|
+
*
|
|
342
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
343
|
+
* const commitments = await segmentCommitment(api)
|
|
344
|
+
* console.log(`Found ${commitments.length} segment commitments`)
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
58
347
|
const segmentCommitment = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
348
|
if (api.at) {
|
|
60
349
|
const { parentHash } = yield (0, exports.header)(api);
|
|
@@ -63,10 +352,75 @@ const segmentCommitment = (api) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
63
352
|
return yield (0, exports.query)(api, 'subspace.segmentCommitment.entries', []);
|
|
64
353
|
});
|
|
65
354
|
exports.segmentCommitment = segmentCommitment;
|
|
355
|
+
/**
|
|
356
|
+
* Retrieves the slot probability configuration.
|
|
357
|
+
*
|
|
358
|
+
* Slot probability defines the likelihood that a farmer will be able to produce
|
|
359
|
+
* a block in any given slot. It's returned as a fraction [numerator, denominator].
|
|
360
|
+
*
|
|
361
|
+
* @param api - The connected API instance
|
|
362
|
+
* @returns Tuple representing slot probability as [numerator, denominator]
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* import { slotProbability } from '@autonomys/auto-consensus'
|
|
367
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
368
|
+
*
|
|
369
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
370
|
+
* const [num, den] = slotProbability(api)
|
|
371
|
+
* console.log(`Slot probability: ${num}/${den} = ${num/den}`)
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
66
374
|
const slotProbability = (api) => api.consts.subspace.slotProbability.toPrimitive();
|
|
67
375
|
exports.slotProbability = slotProbability;
|
|
376
|
+
/**
|
|
377
|
+
* Retrieves the maximum number of pieces that can fit in a sector.
|
|
378
|
+
*
|
|
379
|
+
* In the Autonomys storage system, data is organized into pieces and sectors.
|
|
380
|
+
* This function returns the maximum number of pieces that can be stored in
|
|
381
|
+
* a single sector.
|
|
382
|
+
*
|
|
383
|
+
* @param api - The connected API instance
|
|
384
|
+
* @returns Maximum pieces per sector as a bigint
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```typescript
|
|
388
|
+
* import { maxPiecesInSector } from '@autonomys/auto-consensus'
|
|
389
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
390
|
+
*
|
|
391
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
392
|
+
* const maxPieces = maxPiecesInSector(api)
|
|
393
|
+
* console.log(`Max pieces per sector: ${maxPieces}`)
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
68
396
|
const maxPiecesInSector = (api) => BigInt(api.consts.subspace.maxPiecesInSector.toPrimitive());
|
|
69
397
|
exports.maxPiecesInSector = maxPiecesInSector;
|
|
398
|
+
/**
|
|
399
|
+
* Converts solution range to the equivalent number of pieces.
|
|
400
|
+
*
|
|
401
|
+
* This utility function converts a solution range value to the equivalent
|
|
402
|
+
* number of pieces that would need to be stored to achieve that solution range,
|
|
403
|
+
* taking into account the slot probability.
|
|
404
|
+
*
|
|
405
|
+
* @param solutionRange - The solution range value to convert
|
|
406
|
+
* @param slotProbability - Slot probability as [numerator, denominator] tuple
|
|
407
|
+
* @returns Number of pieces equivalent to the solution range
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```typescript
|
|
411
|
+
* import { solutionRangeToPieces, solutionRanges, slotProbability } from '@autonomys/auto-consensus'
|
|
412
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
413
|
+
*
|
|
414
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
415
|
+
* const ranges = await solutionRanges(api)
|
|
416
|
+
* const slotProb = slotProbability(api)
|
|
417
|
+
*
|
|
418
|
+
* if (ranges.current) {
|
|
419
|
+
* const pieces = solutionRangeToPieces(ranges.current, [BigInt(slotProb[0]), BigInt(slotProb[1])])
|
|
420
|
+
* console.log(`Current solution range equals ${pieces} pieces`)
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
70
424
|
function solutionRangeToPieces(solutionRange, slotProbability) {
|
|
71
425
|
const MAX_U64 = BigInt(Math.pow(2, 64) - 1);
|
|
72
426
|
const RECORD_NUM_CHUNKS = BigInt(32768);
|
|
@@ -75,6 +429,28 @@ function solutionRangeToPieces(solutionRange, slotProbability) {
|
|
|
75
429
|
RECORD_NUM_S_BUCKETS;
|
|
76
430
|
return pieces / solutionRange;
|
|
77
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Calculates the total space pledged to the network.
|
|
434
|
+
*
|
|
435
|
+
* This function calculates the total amount of storage space that has been
|
|
436
|
+
* pledged to the Autonomys network by farmers, based on the current solution
|
|
437
|
+
* range and slot probability.
|
|
438
|
+
*
|
|
439
|
+
* @param api - The connected API instance
|
|
440
|
+
* @returns Promise that resolves to total pledged space in bytes as bigint
|
|
441
|
+
* @throws Error if unable to retrieve solution ranges or calculate space
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```typescript
|
|
445
|
+
* import { spacePledged } from '@autonomys/auto-consensus'
|
|
446
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
447
|
+
*
|
|
448
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
449
|
+
* const pledgedSpace = await spacePledged(api)
|
|
450
|
+
* const pledgedGB = Number(pledgedSpace) / (1024 ** 3)
|
|
451
|
+
* console.log(`Total pledged space: ${pledgedGB.toFixed(2)} GB`)
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
78
454
|
const spacePledged = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
455
|
const _solutionRanges = yield (0, exports.solutionRanges)(api);
|
|
80
456
|
const _slotProbability = (0, exports.slotProbability)(api);
|
|
@@ -88,12 +464,42 @@ const spacePledged = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
88
464
|
return totalSpacePledged;
|
|
89
465
|
});
|
|
90
466
|
exports.spacePledged = spacePledged;
|
|
467
|
+
/**
|
|
468
|
+
* @deprecated Use spacePledged instead. This function will be removed in a future major release.
|
|
469
|
+
*
|
|
470
|
+
* Calculates the total space pledged to the network.
|
|
471
|
+
*
|
|
472
|
+
* @param api - The connected API instance
|
|
473
|
+
* @returns Promise that resolves to total pledged space in bytes as bigint
|
|
474
|
+
*/
|
|
91
475
|
// This function is deprecated (use spacePledged instead) and will be removed in a future major release
|
|
92
476
|
const spacePledge = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
477
|
console.warn('spacePledge is deprecated (use spacePledged instead) and will be removed in a future major release');
|
|
94
478
|
return (0, exports.spacePledged)(api);
|
|
95
479
|
});
|
|
96
480
|
exports.spacePledge = spacePledge;
|
|
481
|
+
/**
|
|
482
|
+
* Calculates the total blockchain size.
|
|
483
|
+
*
|
|
484
|
+
* This function calculates the total size of the blockchain by counting
|
|
485
|
+
* the number of segment commitments and multiplying by the size per segment.
|
|
486
|
+
* This represents the total amount of data stored in the blockchain.
|
|
487
|
+
*
|
|
488
|
+
* @param api - The connected API instance
|
|
489
|
+
* @returns Promise that resolves to total blockchain size in bytes as bigint
|
|
490
|
+
* @throws Error if unable to retrieve segment commitments
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* import { blockchainSize } from '@autonomys/auto-consensus'
|
|
495
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
496
|
+
*
|
|
497
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
498
|
+
* const totalSize = await blockchainSize(api)
|
|
499
|
+
* const sizeGB = Number(totalSize) / (1024 ** 3)
|
|
500
|
+
* console.log(`Blockchain size: ${sizeGB.toFixed(2)} GB`)
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
97
503
|
const blockchainSize = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
504
|
const _segmentCommitment = yield (0, exports.segmentCommitment)(api);
|
|
99
505
|
const segmentsCount = BigInt(_segmentCommitment.length);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Api } from '@autonomys/auto-utils';
|
|
2
|
+
import type { NominatorPosition } from '../types/position';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the complete staking position of a nominator for a specific operator.
|
|
5
|
+
*
|
|
6
|
+
* This function calculates the comprehensive staking position of a nominator including
|
|
7
|
+
* current value, pending deposits, pending withdrawals, and storage fee deposits.
|
|
8
|
+
* It handles complex calculations involving share prices across different epochs
|
|
9
|
+
* and provides a complete view of the nominator's stake position.
|
|
10
|
+
*
|
|
11
|
+
* @param api - The connected API instance
|
|
12
|
+
* @param operatorId - The ID of the operator to query position for
|
|
13
|
+
* @param nominatorAccountId - The account ID of the nominator
|
|
14
|
+
* @returns Promise that resolves to NominatorPosition with complete position details
|
|
15
|
+
* @throws Error if operator not found, domain staking summary unavailable, or calculation fails
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { nominatorPosition } from '@autonomys/auto-consensus'
|
|
20
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
21
|
+
*
|
|
22
|
+
* const api = await activate({ networkId: 'gemini-3h' })
|
|
23
|
+
* const position = await nominatorPosition(api, '1', 'nominator_account_address')
|
|
24
|
+
*
|
|
25
|
+
* console.log(`Current Value: ${position.knownValue}`)
|
|
26
|
+
* console.log(`Storage Fee Deposit: ${position.storageFeeDeposit}`)
|
|
27
|
+
* console.log(`Pending Deposits: ${position.pendingDeposits.length}`)
|
|
28
|
+
* console.log(`Pending Withdrawals: ${position.pendingWithdrawals.length}`)
|
|
29
|
+
*
|
|
30
|
+
* // Check pending deposits
|
|
31
|
+
* position.pendingDeposits.forEach(deposit => {
|
|
32
|
+
* console.log(`Pending: ${deposit.amount} at epoch ${deposit.effectiveEpoch}`)
|
|
33
|
+
* })
|
|
34
|
+
*
|
|
35
|
+
* // Check pending withdrawals
|
|
36
|
+
* position.pendingWithdrawals.forEach(withdrawal => {
|
|
37
|
+
* console.log(`Withdrawal: ${withdrawal.amount} unlocks at block ${withdrawal.unlockAtBlock}`)
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const nominatorPosition: (api: Api, operatorId: string | number | bigint, nominatorAccountId: string) => Promise<NominatorPosition>;
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/position/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAGhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAkH1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,GAAG,EACR,YAAY,MAAM,GAAG,MAAM,GAAG,MAAM,EACpC,oBAAoB,MAAM,KACzB,OAAO,CAAC,iBAAiB,CAkE3B,CAAA"}
|