n8n-nodes-bittensor 1.0.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/LICENSE +46 -0
- package/README.md +329 -0
- package/dist/credentials/BittensorApi.credentials.d.ts +8 -0
- package/dist/credentials/BittensorApi.credentials.js +75 -0
- package/dist/credentials/BittensorApi.credentials.js.map +1 -0
- package/dist/credentials/BittensorNetwork.credentials.d.ts +8 -0
- package/dist/credentials/BittensorNetwork.credentials.js +117 -0
- package/dist/credentials/BittensorNetwork.credentials.js.map +1 -0
- package/dist/credentials/SubnetCredentials.credentials.d.ts +8 -0
- package/dist/credentials/SubnetCredentials.credentials.js +81 -0
- package/dist/credentials/SubnetCredentials.credentials.js.map +1 -0
- package/dist/nodes/Bittensor/Bittensor.node.d.ts +5 -0
- package/dist/nodes/Bittensor/Bittensor.node.js +938 -0
- package/dist/nodes/Bittensor/Bittensor.node.js.map +1 -0
- package/dist/nodes/Bittensor/bittensor.svg +4 -0
- package/dist/nodes/Bittensor/constants/hyperparameters.d.ts +23 -0
- package/dist/nodes/Bittensor/constants/hyperparameters.js +127 -0
- package/dist/nodes/Bittensor/constants/hyperparameters.js.map +1 -0
- package/dist/nodes/Bittensor/constants/networks.d.ts +31 -0
- package/dist/nodes/Bittensor/constants/networks.js +54 -0
- package/dist/nodes/Bittensor/constants/networks.js.map +1 -0
- package/dist/nodes/Bittensor/constants/pallets.d.ts +73 -0
- package/dist/nodes/Bittensor/constants/pallets.js +99 -0
- package/dist/nodes/Bittensor/constants/pallets.js.map +1 -0
- package/dist/nodes/Bittensor/constants/subnets.d.ts +25 -0
- package/dist/nodes/Bittensor/constants/subnets.js +55 -0
- package/dist/nodes/Bittensor/constants/subnets.js.map +1 -0
- package/dist/nodes/Bittensor/transport/metagraphSync.d.ts +63 -0
- package/dist/nodes/Bittensor/transport/metagraphSync.js +153 -0
- package/dist/nodes/Bittensor/transport/metagraphSync.js.map +1 -0
- package/dist/nodes/Bittensor/transport/queryClient.d.ts +93 -0
- package/dist/nodes/Bittensor/transport/queryClient.js +144 -0
- package/dist/nodes/Bittensor/transport/queryClient.js.map +1 -0
- package/dist/nodes/Bittensor/transport/subtensorClient.d.ts +138 -0
- package/dist/nodes/Bittensor/transport/subtensorClient.js +414 -0
- package/dist/nodes/Bittensor/transport/subtensorClient.js.map +1 -0
- package/dist/nodes/Bittensor/transport/taostatsApi.d.ts +133 -0
- package/dist/nodes/Bittensor/transport/taostatsApi.js +139 -0
- package/dist/nodes/Bittensor/transport/taostatsApi.js.map +1 -0
- package/dist/nodes/Bittensor/utils/addressUtils.d.ts +25 -0
- package/dist/nodes/Bittensor/utils/addressUtils.js +70 -0
- package/dist/nodes/Bittensor/utils/addressUtils.js.map +1 -0
- package/dist/nodes/Bittensor/utils/metagraphUtils.d.ts +103 -0
- package/dist/nodes/Bittensor/utils/metagraphUtils.js +113 -0
- package/dist/nodes/Bittensor/utils/metagraphUtils.js.map +1 -0
- package/dist/nodes/Bittensor/utils/unitConverter.d.ts +48 -0
- package/dist/nodes/Bittensor/utils/unitConverter.js +109 -0
- package/dist/nodes/Bittensor/utils/unitConverter.js.map +1 -0
- package/dist/nodes/Bittensor/utils/weightUtils.d.ts +49 -0
- package/dist/nodes/Bittensor/utils/weightUtils.js +90 -0
- package/dist/nodes/Bittensor/utils/weightUtils.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Velocity BPA, LLC
|
|
4
|
+
* Licensed under the Business Source License 1.1
|
|
5
|
+
* Commercial use requires a separate commercial license.
|
|
6
|
+
* See LICENSE file for details.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SubtensorClient = void 0;
|
|
10
|
+
exports.createSubtensorClient = createSubtensorClient;
|
|
11
|
+
/**
|
|
12
|
+
* Subtensor Client
|
|
13
|
+
*
|
|
14
|
+
* Main client for interacting with the Bittensor Subtensor chain.
|
|
15
|
+
*/
|
|
16
|
+
const api_1 = require("@polkadot/api");
|
|
17
|
+
const keyring_1 = require("@polkadot/keyring");
|
|
18
|
+
const networks_1 = require("../constants/networks");
|
|
19
|
+
const pallets_1 = require("../constants/pallets");
|
|
20
|
+
const unitConverter_1 = require("../utils/unitConverter");
|
|
21
|
+
/**
|
|
22
|
+
* Subtensor Client Class
|
|
23
|
+
*/
|
|
24
|
+
class SubtensorClient {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.api = null;
|
|
27
|
+
this.provider = null;
|
|
28
|
+
this.coldkey = null;
|
|
29
|
+
this.hotkey = null;
|
|
30
|
+
this.connected = false;
|
|
31
|
+
this._network = options.network;
|
|
32
|
+
const config = (0, networks_1.getNetworkConfig)(options.network, options.wsEndpoint);
|
|
33
|
+
this.wsEndpoint = options.wsEndpoint || config.wsEndpoint;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the connected network
|
|
37
|
+
*/
|
|
38
|
+
get network() {
|
|
39
|
+
return this._network;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Connect to Subtensor
|
|
43
|
+
*/
|
|
44
|
+
async connect() {
|
|
45
|
+
if (this.connected && this.api) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
this.provider = new api_1.WsProvider(this.wsEndpoint);
|
|
50
|
+
this.api = await api_1.ApiPromise.create({ provider: this.provider });
|
|
51
|
+
await this.api.isReady;
|
|
52
|
+
this.connected = true;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw new Error(`Failed to connect to Subtensor: ${error.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Disconnect from Subtensor
|
|
60
|
+
*/
|
|
61
|
+
async disconnect() {
|
|
62
|
+
if (this.api) {
|
|
63
|
+
await this.api.disconnect();
|
|
64
|
+
}
|
|
65
|
+
if (this.provider) {
|
|
66
|
+
await this.provider.disconnect();
|
|
67
|
+
}
|
|
68
|
+
this.connected = false;
|
|
69
|
+
this.api = null;
|
|
70
|
+
this.provider = null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Initialize coldkey from mnemonic
|
|
74
|
+
*/
|
|
75
|
+
initColdkey(mnemonic) {
|
|
76
|
+
const keyring = new keyring_1.Keyring({ type: 'sr25519', ss58Format: networks_1.SS58_PREFIX });
|
|
77
|
+
this.coldkey = keyring.addFromMnemonic(mnemonic);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Initialize hotkey from mnemonic
|
|
81
|
+
*/
|
|
82
|
+
initHotkey(mnemonic) {
|
|
83
|
+
const keyring = new keyring_1.Keyring({ type: 'sr25519', ss58Format: networks_1.SS58_PREFIX });
|
|
84
|
+
this.hotkey = keyring.addFromMnemonic(mnemonic);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Ensure connected
|
|
88
|
+
*/
|
|
89
|
+
ensureConnected() {
|
|
90
|
+
if (!this.api || !this.connected) {
|
|
91
|
+
throw new Error('Not connected to Subtensor');
|
|
92
|
+
}
|
|
93
|
+
return this.api;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get balance for an address
|
|
97
|
+
*/
|
|
98
|
+
async getBalance(address) {
|
|
99
|
+
const api = this.ensureConnected();
|
|
100
|
+
const account = await api.query.system.account(address);
|
|
101
|
+
const data = account.data;
|
|
102
|
+
return data.free.toBigInt();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get stake for coldkey-hotkey pair
|
|
106
|
+
*/
|
|
107
|
+
async getStake(coldkey, hotkey) {
|
|
108
|
+
const api = this.ensureConnected();
|
|
109
|
+
const stake = await api.query[pallets_1.PALLETS.SUBTENSOR_MODULE].Stake(hotkey, coldkey);
|
|
110
|
+
return stake.toBigInt();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get total stake for a coldkey
|
|
114
|
+
*/
|
|
115
|
+
async getTotalColdkeyStake(coldkey) {
|
|
116
|
+
const api = this.ensureConnected();
|
|
117
|
+
const stake = await api.query[pallets_1.PALLETS.SUBTENSOR_MODULE].TotalColdkeyStake(coldkey);
|
|
118
|
+
return stake.toBigInt();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get total stake for a hotkey
|
|
122
|
+
*/
|
|
123
|
+
async getTotalHotkeyStake(hotkey) {
|
|
124
|
+
const api = this.ensureConnected();
|
|
125
|
+
const stake = await api.query[pallets_1.PALLETS.SUBTENSOR_MODULE].TotalHotkeyStake(hotkey);
|
|
126
|
+
return stake.toBigInt();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get current block number
|
|
130
|
+
*/
|
|
131
|
+
async getBlockNumber() {
|
|
132
|
+
const api = this.ensureConnected();
|
|
133
|
+
const header = await api.rpc.chain.getHeader();
|
|
134
|
+
return header.number.toNumber();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get block hash by number
|
|
138
|
+
*/
|
|
139
|
+
async getBlockHash(blockNumber) {
|
|
140
|
+
const api = this.ensureConnected();
|
|
141
|
+
const hash = await api.rpc.chain.getBlockHash(blockNumber);
|
|
142
|
+
return hash.toString();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get total networks count
|
|
146
|
+
*/
|
|
147
|
+
async getTotalNetworks() {
|
|
148
|
+
const api = this.ensureConnected();
|
|
149
|
+
const count = await api.query[pallets_1.PALLETS.SUBTENSOR_MODULE].TotalNetworks();
|
|
150
|
+
return count.toNumber();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get subnet info
|
|
154
|
+
*/
|
|
155
|
+
async getSubnetInfo(netuid) {
|
|
156
|
+
const api = this.ensureConnected();
|
|
157
|
+
const pallet = api.query[pallets_1.PALLETS.SUBTENSOR_MODULE];
|
|
158
|
+
const [n, tempo, difficulty, immunityPeriod, maxValidators, minWeights, maxWeightLimit] = await Promise.all([
|
|
159
|
+
pallet.SubnetworkN(netuid),
|
|
160
|
+
pallet.Tempo(netuid),
|
|
161
|
+
pallet.Difficulty(netuid),
|
|
162
|
+
pallet.ImmunityPeriod(netuid),
|
|
163
|
+
pallet.MaxAllowedValidators(netuid),
|
|
164
|
+
pallet.MinAllowedWeights(netuid),
|
|
165
|
+
pallet.MaxWeightLimit(netuid),
|
|
166
|
+
]);
|
|
167
|
+
return {
|
|
168
|
+
netuid,
|
|
169
|
+
n: n.toNumber(),
|
|
170
|
+
tempo: tempo.toNumber(),
|
|
171
|
+
difficulty: difficulty.toBigInt().toString(),
|
|
172
|
+
immunityPeriod: immunityPeriod.toNumber(),
|
|
173
|
+
maxValidators: maxValidators.toNumber(),
|
|
174
|
+
minAllowedWeights: minWeights.toNumber(),
|
|
175
|
+
maxWeightLimit: maxWeightLimit.toNumber(),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get neuron info
|
|
180
|
+
*/
|
|
181
|
+
async getNeuronInfo(netuid, uid) {
|
|
182
|
+
const api = this.ensureConnected();
|
|
183
|
+
const pallet = api.query[pallets_1.PALLETS.SUBTENSOR_MODULE];
|
|
184
|
+
const [hotkey, active, rank, trust, consensus, incentive, dividends, emission, validatorTrust, validatorPermit] = await Promise.all([
|
|
185
|
+
pallet.Keys(netuid, uid),
|
|
186
|
+
pallet.Active(netuid, uid),
|
|
187
|
+
pallet.Rank(netuid, uid),
|
|
188
|
+
pallet.Trust(netuid, uid),
|
|
189
|
+
pallet.Consensus(netuid, uid),
|
|
190
|
+
pallet.Incentive(netuid, uid),
|
|
191
|
+
pallet.Dividends(netuid, uid),
|
|
192
|
+
pallet.Emission(netuid, uid),
|
|
193
|
+
pallet.ValidatorTrust(netuid, uid),
|
|
194
|
+
pallet.ValidatorPermit(netuid, uid),
|
|
195
|
+
]);
|
|
196
|
+
const hotkeyStr = hotkey.toString();
|
|
197
|
+
const stake = await this.getTotalHotkeyStake(hotkeyStr);
|
|
198
|
+
return {
|
|
199
|
+
uid,
|
|
200
|
+
netuid,
|
|
201
|
+
hotkey: hotkeyStr,
|
|
202
|
+
active: active.isTrue ?? false,
|
|
203
|
+
rank: rank.toNumber(),
|
|
204
|
+
trust: trust.toNumber(),
|
|
205
|
+
consensus: consensus.toNumber(),
|
|
206
|
+
incentive: incentive.toNumber(),
|
|
207
|
+
dividends: dividends.toNumber(),
|
|
208
|
+
emission: emission.toBigInt().toString(),
|
|
209
|
+
validatorTrust: validatorTrust.toNumber(),
|
|
210
|
+
validatorPermit: validatorPermit.isTrue ?? false,
|
|
211
|
+
stake: stake.toString(),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get all delegates
|
|
216
|
+
*/
|
|
217
|
+
async getDelegates() {
|
|
218
|
+
const api = this.ensureConnected();
|
|
219
|
+
const delegates = await api.query[pallets_1.PALLETS.SUBTENSOR_MODULE].Delegates.entries();
|
|
220
|
+
return delegates.map(([key]) => {
|
|
221
|
+
const hotkey = key.args[0];
|
|
222
|
+
return hotkey.toString();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get delegate take rate
|
|
227
|
+
*/
|
|
228
|
+
async getDelegateTake(hotkey) {
|
|
229
|
+
const api = this.ensureConnected();
|
|
230
|
+
const take = await api.query[pallets_1.PALLETS.SUBTENSOR_MODULE].Delegates(hotkey);
|
|
231
|
+
return take.toNumber();
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Get registration cost (burn amount)
|
|
235
|
+
*/
|
|
236
|
+
async getRegistrationCost(netuid) {
|
|
237
|
+
const api = this.ensureConnected();
|
|
238
|
+
const burn = await api.query[pallets_1.PALLETS.SUBTENSOR_MODULE].Burn(netuid);
|
|
239
|
+
return burn.toBigInt();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Transfer TAO
|
|
243
|
+
*/
|
|
244
|
+
async transfer(to, amount) {
|
|
245
|
+
const api = this.ensureConnected();
|
|
246
|
+
if (!this.coldkey) {
|
|
247
|
+
throw new Error('Coldkey not initialized');
|
|
248
|
+
}
|
|
249
|
+
const amountRao = (0, unitConverter_1.taoToRao)(amount);
|
|
250
|
+
return new Promise((resolve, reject) => {
|
|
251
|
+
api.tx.balances
|
|
252
|
+
.transferKeepAlive(to, amountRao)
|
|
253
|
+
.signAndSend(this.coldkey, ({ status, events, dispatchError }) => {
|
|
254
|
+
if (status.isInBlock || status.isFinalized) {
|
|
255
|
+
if (dispatchError) {
|
|
256
|
+
resolve({ success: false, error: dispatchError.toString() });
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
resolve({
|
|
260
|
+
success: true,
|
|
261
|
+
blockHash: status.asInBlock?.toString() || status.asFinalized?.toString(),
|
|
262
|
+
events: events.map(e => e.toHuman()),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
.catch(reject);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Add stake
|
|
272
|
+
*/
|
|
273
|
+
async addStake(hotkey, amount) {
|
|
274
|
+
const api = this.ensureConnected();
|
|
275
|
+
if (!this.coldkey) {
|
|
276
|
+
throw new Error('Coldkey not initialized');
|
|
277
|
+
}
|
|
278
|
+
const amountRao = (0, unitConverter_1.taoToRao)(amount);
|
|
279
|
+
return new Promise((resolve, reject) => {
|
|
280
|
+
api.tx[pallets_1.PALLETS.SUBTENSOR_MODULE]
|
|
281
|
+
.addStake(hotkey, amountRao)
|
|
282
|
+
.signAndSend(this.coldkey, ({ status, events, dispatchError }) => {
|
|
283
|
+
if (status.isInBlock || status.isFinalized) {
|
|
284
|
+
if (dispatchError) {
|
|
285
|
+
resolve({ success: false, error: dispatchError.toString() });
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
resolve({
|
|
289
|
+
success: true,
|
|
290
|
+
blockHash: status.asInBlock?.toString() || status.asFinalized?.toString(),
|
|
291
|
+
events: events.map(e => e.toHuman()),
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
.catch(reject);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Remove stake
|
|
301
|
+
*/
|
|
302
|
+
async removeStake(hotkey, amount) {
|
|
303
|
+
const api = this.ensureConnected();
|
|
304
|
+
if (!this.coldkey) {
|
|
305
|
+
throw new Error('Coldkey not initialized');
|
|
306
|
+
}
|
|
307
|
+
const amountRao = (0, unitConverter_1.taoToRao)(amount);
|
|
308
|
+
return new Promise((resolve, reject) => {
|
|
309
|
+
api.tx[pallets_1.PALLETS.SUBTENSOR_MODULE]
|
|
310
|
+
.removeStake(hotkey, amountRao)
|
|
311
|
+
.signAndSend(this.coldkey, ({ status, events, dispatchError }) => {
|
|
312
|
+
if (status.isInBlock || status.isFinalized) {
|
|
313
|
+
if (dispatchError) {
|
|
314
|
+
resolve({ success: false, error: dispatchError.toString() });
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
resolve({
|
|
318
|
+
success: true,
|
|
319
|
+
blockHash: status.asInBlock?.toString() || status.asFinalized?.toString(),
|
|
320
|
+
events: events.map(e => e.toHuman()),
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
})
|
|
325
|
+
.catch(reject);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Set weights (validator only)
|
|
330
|
+
*/
|
|
331
|
+
async setWeights(netuid, uids, weights, versionKey) {
|
|
332
|
+
const api = this.ensureConnected();
|
|
333
|
+
if (!this.hotkey) {
|
|
334
|
+
throw new Error('Hotkey not initialized');
|
|
335
|
+
}
|
|
336
|
+
return new Promise((resolve, reject) => {
|
|
337
|
+
api.tx[pallets_1.PALLETS.SUBTENSOR_MODULE]
|
|
338
|
+
.setWeights(netuid, uids, weights, versionKey)
|
|
339
|
+
.signAndSend(this.hotkey, ({ status, events, dispatchError }) => {
|
|
340
|
+
if (status.isInBlock || status.isFinalized) {
|
|
341
|
+
if (dispatchError) {
|
|
342
|
+
resolve({ success: false, error: dispatchError.toString() });
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
resolve({
|
|
346
|
+
success: true,
|
|
347
|
+
blockHash: status.asInBlock?.toString() || status.asFinalized?.toString(),
|
|
348
|
+
events: events.map(e => e.toHuman()),
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
.catch(reject);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Burned register on subnet
|
|
358
|
+
*/
|
|
359
|
+
async burnedRegister(netuid) {
|
|
360
|
+
const api = this.ensureConnected();
|
|
361
|
+
if (!this.coldkey || !this.hotkey) {
|
|
362
|
+
throw new Error('Both coldkey and hotkey required for registration');
|
|
363
|
+
}
|
|
364
|
+
return new Promise((resolve, reject) => {
|
|
365
|
+
api.tx[pallets_1.PALLETS.SUBTENSOR_MODULE]
|
|
366
|
+
.burnedRegister(netuid, this.hotkey.address)
|
|
367
|
+
.signAndSend(this.coldkey, ({ status, events, dispatchError }) => {
|
|
368
|
+
if (status.isInBlock || status.isFinalized) {
|
|
369
|
+
if (dispatchError) {
|
|
370
|
+
resolve({ success: false, error: dispatchError.toString() });
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
resolve({
|
|
374
|
+
success: true,
|
|
375
|
+
blockHash: status.asInBlock?.toString() || status.asFinalized?.toString(),
|
|
376
|
+
events: events.map(e => e.toHuman()),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
.catch(reject);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Subscribe to new blocks
|
|
386
|
+
*/
|
|
387
|
+
async subscribeToBlocks(callback) {
|
|
388
|
+
const api = this.ensureConnected();
|
|
389
|
+
const unsubscribe = await api.rpc.chain.subscribeNewHeads((header) => {
|
|
390
|
+
callback(header.number.toNumber());
|
|
391
|
+
});
|
|
392
|
+
return unsubscribe;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Subscribe to events
|
|
396
|
+
*/
|
|
397
|
+
async subscribeToEvents(callback) {
|
|
398
|
+
const api = this.ensureConnected();
|
|
399
|
+
const unsubscribe = await api.query.system.events((events) => {
|
|
400
|
+
callback(events.toHuman());
|
|
401
|
+
});
|
|
402
|
+
return unsubscribe;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
exports.SubtensorClient = SubtensorClient;
|
|
406
|
+
/**
|
|
407
|
+
* Create and connect a new client
|
|
408
|
+
*/
|
|
409
|
+
async function createSubtensorClient(options) {
|
|
410
|
+
const client = new SubtensorClient(options);
|
|
411
|
+
await client.connect();
|
|
412
|
+
return client;
|
|
413
|
+
}
|
|
414
|
+
//# sourceMappingURL=subtensorClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtensorClient.js","sourceRoot":"","sources":["../../../../nodes/Bittensor/transport/subtensorClient.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA6cH,sDAIC;AA/cD;;;;GAIG;AAEH,uCAAuD;AACvD,+CAA4C;AAE5C,oDAAmF;AACnF,kDAA+C;AAC/C,0DAAkD;AAwBlD;;GAEG;AACH,MAAa,eAAe;IAS3B,YAAY,OAAmC;QARvC,QAAG,GAAsB,IAAI,CAAC;QAC9B,aAAQ,GAAsB,IAAI,CAAC;QACnC,YAAO,GAAuB,IAAI,CAAC;QACnC,WAAM,GAAuB,IAAI,CAAC;QAGlC,cAAS,GAAG,KAAK,CAAC;QAGzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QAChC,MAAM,MAAM,GAAG,IAAA,2BAAgB,EAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,U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AAC,QAAqC;QAC5D,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAkC,EAAE,EAAE;YACxF,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAe,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QACH,OAAO,WAAoC,CAAC;IAC7C,CAAC;CACD;AAhaD,0CAgaC;AAED;;GAEG;AACI,KAAK,UAAU,qBAAqB,CAAC,OAAmC;IAC9E,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Price data response
|
|
3
|
+
*/
|
|
4
|
+
export interface TaostatsPriceData {
|
|
5
|
+
price: number;
|
|
6
|
+
price24hChange: number;
|
|
7
|
+
marketCap: number;
|
|
8
|
+
volume24h: number;
|
|
9
|
+
circulatingSupply: number;
|
|
10
|
+
totalSupply: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Validator info from Taostats
|
|
14
|
+
*/
|
|
15
|
+
export interface TaostatsValidator {
|
|
16
|
+
hotkey: string;
|
|
17
|
+
coldkey: string;
|
|
18
|
+
stake: string;
|
|
19
|
+
delegatedStake: string;
|
|
20
|
+
take: number;
|
|
21
|
+
nominators: number;
|
|
22
|
+
apr: number;
|
|
23
|
+
rank: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Subnet info from Taostats
|
|
27
|
+
*/
|
|
28
|
+
export interface TaostatsSubnet {
|
|
29
|
+
netuid: number;
|
|
30
|
+
name: string;
|
|
31
|
+
emission: number;
|
|
32
|
+
neurons: number;
|
|
33
|
+
tempo: number;
|
|
34
|
+
difficulty: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Historical price point
|
|
38
|
+
*/
|
|
39
|
+
export interface PricePoint {
|
|
40
|
+
timestamp: number;
|
|
41
|
+
price: number;
|
|
42
|
+
volume: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Taostats API client
|
|
46
|
+
*/
|
|
47
|
+
export declare class TaostatsApiClient {
|
|
48
|
+
private client;
|
|
49
|
+
private _apiKey?;
|
|
50
|
+
constructor(apiKey?: string);
|
|
51
|
+
/**
|
|
52
|
+
* Check if API key is configured
|
|
53
|
+
*/
|
|
54
|
+
get hasApiKey(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Get TAO price data
|
|
57
|
+
*/
|
|
58
|
+
getPriceData(): Promise<TaostatsPriceData>;
|
|
59
|
+
/**
|
|
60
|
+
* Get validators list
|
|
61
|
+
*/
|
|
62
|
+
getValidators(limit?: number, offset?: number): Promise<TaostatsValidator[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Get subnet list
|
|
65
|
+
*/
|
|
66
|
+
getSubnets(): Promise<TaostatsSubnet[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Get account info
|
|
69
|
+
*/
|
|
70
|
+
getAccount(address: string): Promise<Record<string, unknown>>;
|
|
71
|
+
/**
|
|
72
|
+
* Get historical price data
|
|
73
|
+
*/
|
|
74
|
+
getHistoricalPrice(days?: number): Promise<PricePoint[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Get historical emission data
|
|
77
|
+
*/
|
|
78
|
+
getHistoricalEmission(days?: number): Promise<{
|
|
79
|
+
timestamp: number;
|
|
80
|
+
emission: number;
|
|
81
|
+
}[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Get network statistics
|
|
84
|
+
*/
|
|
85
|
+
getNetworkStats(): Promise<{
|
|
86
|
+
totalStake: string;
|
|
87
|
+
totalSupply: string;
|
|
88
|
+
circulatingSupply: string;
|
|
89
|
+
blockHeight: number;
|
|
90
|
+
validators: number;
|
|
91
|
+
subnets: number;
|
|
92
|
+
}>;
|
|
93
|
+
/**
|
|
94
|
+
* Get transfer history for an address
|
|
95
|
+
*/
|
|
96
|
+
getTransferHistory(address: string, limit?: number, offset?: number): Promise<{
|
|
97
|
+
hash: string;
|
|
98
|
+
from: string;
|
|
99
|
+
to: string;
|
|
100
|
+
amount: string;
|
|
101
|
+
block: number;
|
|
102
|
+
timestamp: number;
|
|
103
|
+
}[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Get staking history for an address
|
|
106
|
+
*/
|
|
107
|
+
getStakingHistory(address: string, limit?: number, offset?: number): Promise<{
|
|
108
|
+
type: 'stake' | 'unstake';
|
|
109
|
+
hotkey: string;
|
|
110
|
+
amount: string;
|
|
111
|
+
block: number;
|
|
112
|
+
timestamp: number;
|
|
113
|
+
}[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Get validator delegations
|
|
116
|
+
*/
|
|
117
|
+
getValidatorDelegations(hotkey: string): Promise<{
|
|
118
|
+
coldkey: string;
|
|
119
|
+
stake: string;
|
|
120
|
+
percentage: number;
|
|
121
|
+
}[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Search for addresses or transactions
|
|
124
|
+
*/
|
|
125
|
+
search(query: string): Promise<{
|
|
126
|
+
type: 'address' | 'transaction' | 'block';
|
|
127
|
+
result: unknown;
|
|
128
|
+
}[]>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create Taostats client
|
|
132
|
+
*/
|
|
133
|
+
export declare function createTaostatsClient(apiKey?: string): TaostatsApiClient;
|