@_koii/task-node 1.12.37
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 +49 -0
- package/dist/bincode_js.d.ts +225 -0
- package/dist/bincode_js.js +1211 -0
- package/dist/bincode_js_bg.wasm +0 -0
- package/dist/bincode_js_bg.wasm.d.ts +44 -0
- package/dist/taskNodeLib.d.ts +712 -0
- package/dist/taskNodeLib.js +5980 -0
- package/dist/taskNodeLib.mjs +5948 -0
- package/dist/zstd.wasm +0 -0
- package/package.json +116 -0
@@ -0,0 +1,712 @@
|
|
1
|
+
import { PublicKey, Keypair, AccountInfo, Connection } from '@_koii/web3.js';
|
2
|
+
import { Application, RequestHandler } from 'express';
|
3
|
+
import { ChildProcess } from 'child_process';
|
4
|
+
import { WriteStream } from 'fs';
|
5
|
+
import * as BufferLayout from '@solana/buffer-layout';
|
6
|
+
import * as jsonwebtoken from 'jsonwebtoken';
|
7
|
+
import * as fsPromises from 'fs/promises';
|
8
|
+
|
9
|
+
interface IDatabase {
|
10
|
+
get(key: string, callback?: () => void): Promise<any>;
|
11
|
+
put(key: string, value: string, callback?: () => void): Promise<void>;
|
12
|
+
}
|
13
|
+
|
14
|
+
interface TaskData {
|
15
|
+
task_id?: string;
|
16
|
+
task_name?: string;
|
17
|
+
task_manager?: PublicKey;
|
18
|
+
task_audit_program?: string;
|
19
|
+
stake_pot_account?: PublicKey;
|
20
|
+
bounty_amount_per_round?: number;
|
21
|
+
}
|
22
|
+
declare enum LogLevel {
|
23
|
+
Log = "log",
|
24
|
+
Warn = "warn",
|
25
|
+
Error = "error"
|
26
|
+
}
|
27
|
+
interface INode {
|
28
|
+
data: {
|
29
|
+
url: string | undefined;
|
30
|
+
timestamp: number;
|
31
|
+
};
|
32
|
+
signature: string;
|
33
|
+
owner: string;
|
34
|
+
submitterPubkey: string;
|
35
|
+
}
|
36
|
+
/**
|
37
|
+
* @dev We need this additional interface because the constructor only sits on the
|
38
|
+
* static side of the class, not on the instance side.
|
39
|
+
*/
|
40
|
+
interface IRunningTasks<T extends ITaskNodeBase> {
|
41
|
+
[key: string]: {
|
42
|
+
namespace: T;
|
43
|
+
child: ChildProcess;
|
44
|
+
expressAppPort: number;
|
45
|
+
secret: string;
|
46
|
+
};
|
47
|
+
}
|
48
|
+
interface ISelectedTasks {
|
49
|
+
task_name: string;
|
50
|
+
task_id: string;
|
51
|
+
task_audit_program: string;
|
52
|
+
task_manager?: PublicKey;
|
53
|
+
stake_pot_account?: PublicKey;
|
54
|
+
bounty_amount_per_round?: number;
|
55
|
+
round_time: number;
|
56
|
+
starting_slot: number;
|
57
|
+
audit_window: number;
|
58
|
+
submission_window: number;
|
59
|
+
task_executable_network: string;
|
60
|
+
task_metadata: string;
|
61
|
+
task_type: string;
|
62
|
+
}
|
63
|
+
declare type ExpressMethodType = 'get' | 'post' | 'put' | 'delete';
|
64
|
+
interface TaskNodeConfig {
|
65
|
+
taskTxId: string;
|
66
|
+
mainSystemAccount: Keypair | null | undefined;
|
67
|
+
taskData: TaskData;
|
68
|
+
serverApp: Application | null;
|
69
|
+
db: IDatabase;
|
70
|
+
rpcUrl: string;
|
71
|
+
taskType: string;
|
72
|
+
}
|
73
|
+
interface ITaskNodeBaseWithConstructor extends ITaskNodeBase {
|
74
|
+
new (config: TaskNodeConfig): ITaskNodeBase;
|
75
|
+
}
|
76
|
+
interface ITaskNodeBase {
|
77
|
+
/**
|
78
|
+
* @param {string} taskTxId - Tasks transaction ID to be used as the namespace name
|
79
|
+
*/
|
80
|
+
taskTxId: string;
|
81
|
+
/**
|
82
|
+
* @param {Application} app - Express app instance
|
83
|
+
*/
|
84
|
+
serverApp: Application | null;
|
85
|
+
/**
|
86
|
+
* @param {IDatabase} db - Database adapter
|
87
|
+
*/
|
88
|
+
db: IDatabase;
|
89
|
+
rpcUrl: string;
|
90
|
+
taskType: string;
|
91
|
+
mainSystemAccount: Keypair | null | undefined;
|
92
|
+
mainSystemAccountPubKey: PublicKey;
|
93
|
+
taskAccountInfo: AccountInfo<Buffer> | null;
|
94
|
+
taskData: TaskData;
|
95
|
+
appDataPath: string;
|
96
|
+
submitterAccountKeyPair: Keypair;
|
97
|
+
distributionAccountKeyPair: Keypair;
|
98
|
+
submitterPubkey: string;
|
99
|
+
distributionPubKey: string;
|
100
|
+
connection: Connection;
|
101
|
+
taskStateInfoPublicKey: PublicKey;
|
102
|
+
stakePotAccount: PublicKey;
|
103
|
+
getMainSystemAccountPubKey(): Promise<Keypair>;
|
104
|
+
storeGet(key: string): Promise<any>;
|
105
|
+
storeGetRaw(key: string): Promise<string | null>;
|
106
|
+
storeSet(key: string, value: string): Promise<void>;
|
107
|
+
jwtSign(accessToken: string, secret: string): Promise<string>;
|
108
|
+
jwtVerify(accessToken: string, secret: string): Promise<any>;
|
109
|
+
fs(method: any, path: any, ...args: any): Promise<any>;
|
110
|
+
fsStaking(method: any, path: any, ...args: any[]): Promise<any>;
|
111
|
+
fsWriteStream(imagepath: string): Promise<WriteStream>;
|
112
|
+
fsReadStream(imagepath: string): Promise<Buffer>;
|
113
|
+
express(method: ExpressMethodType, path: string, callback: () => void): Application;
|
114
|
+
submissionOnChain(submitterKeypair: Keypair, submission: string, round: number): Promise<string>;
|
115
|
+
stakeOnChain(taskStateInfoPublicKey: PublicKey, stakingAccKeypair: Keypair, stakePotAccount: PublicKey, stakeAmount: number): Promise<string>;
|
116
|
+
claimReward(stakePotAccount: PublicKey, beneficiaryAccount: PublicKey, claimerKeypair: Keypair): Promise<string>;
|
117
|
+
sendTransaction(serviceNodeAccount: PublicKey, beneficiaryAccount: PublicKey, amount: number): Promise<string>;
|
118
|
+
bs58Encode(data: Uint8Array): Promise<string>;
|
119
|
+
bs58Decode(data: any): Promise<Uint8Array>;
|
120
|
+
signData(data: any): Promise<string>;
|
121
|
+
verifySignedData(signedData: any, publicKey: string): Promise<{
|
122
|
+
error: string;
|
123
|
+
data?: undefined;
|
124
|
+
} | {
|
125
|
+
data: string;
|
126
|
+
error?: undefined;
|
127
|
+
}>;
|
128
|
+
sendAndConfirmTransactionWrapper(transaction: any, signers: any[]): Promise<string>;
|
129
|
+
establishConnection(): Promise<void>;
|
130
|
+
getTaskState(options: TaskStateOptions): Promise<any>;
|
131
|
+
getSubmitterAccount(): Promise<Keypair | null>;
|
132
|
+
checkSubmissionAndUpdateRound(submissionValue: string, round: number): Promise<void>;
|
133
|
+
getProgramAccounts(): Promise<{
|
134
|
+
pubkey: PublicKey;
|
135
|
+
account: AccountInfo<Buffer>;
|
136
|
+
}[]>;
|
137
|
+
defaultTaskSetup(): Promise<void>;
|
138
|
+
getRpcUrl(): string;
|
139
|
+
getNodes(url: string): Promise<Array<INode>>;
|
140
|
+
payloadTrigger(round: number): Promise<string>;
|
141
|
+
payloadTriggerOnBehalf(round: any, distribution_account_key: any): Promise<string>;
|
142
|
+
}
|
143
|
+
interface AuditTriggerState {
|
144
|
+
trigger_by: PublicKey;
|
145
|
+
slot: number;
|
146
|
+
votes: Array<{
|
147
|
+
is_valid: boolean;
|
148
|
+
voter: PublicKey;
|
149
|
+
slot: number;
|
150
|
+
}>;
|
151
|
+
}
|
152
|
+
declare type SubmissionsPerRound = Record<Round, Record<PublicKeyString, Submission>>;
|
153
|
+
declare type Round = string;
|
154
|
+
declare type PublicKeyString = string;
|
155
|
+
declare type Submission = {
|
156
|
+
submission_value: string;
|
157
|
+
slot: number;
|
158
|
+
};
|
159
|
+
declare type ROE = number;
|
160
|
+
interface TaskState {
|
161
|
+
task_id: string;
|
162
|
+
task_name: string;
|
163
|
+
task_manager: PublicKey;
|
164
|
+
is_allowlisted: boolean;
|
165
|
+
is_active: boolean;
|
166
|
+
task_audit_program: string;
|
167
|
+
stake_pot_account: PublicKey;
|
168
|
+
total_bounty_amount: number;
|
169
|
+
bounty_amount_per_round: number;
|
170
|
+
current_round: number;
|
171
|
+
available_balances: Record<string, ROE>;
|
172
|
+
stake_list: Record<string, ROE>;
|
173
|
+
task_metadata: string;
|
174
|
+
task_description: string;
|
175
|
+
submissions: SubmissionsPerRound;
|
176
|
+
submissions_audit_trigger: Record<string, Record<string, AuditTriggerState>>;
|
177
|
+
total_stake_amount: number;
|
178
|
+
minimum_stake_amount: number;
|
179
|
+
ip_address_list: Record<string, string>;
|
180
|
+
round_time: number;
|
181
|
+
starting_slot: number;
|
182
|
+
audit_window: number;
|
183
|
+
submission_window: number;
|
184
|
+
task_executable_network: 'IPFS' | 'ARWEAVE';
|
185
|
+
distribution_rewards_submission: SubmissionsPerRound;
|
186
|
+
distributions_audit_trigger: Record<string, Record<string, AuditTriggerState>>;
|
187
|
+
distributions_audit_record: Record<string, 'Uninitialized' | 'PayoutSuccessful' | 'PayoutFailed'>;
|
188
|
+
task_vars: string;
|
189
|
+
koii_vars: string;
|
190
|
+
is_migrated: boolean;
|
191
|
+
migrated_to: string;
|
192
|
+
allowed_failed_distributions: number;
|
193
|
+
}
|
194
|
+
interface TaskStateKPL {
|
195
|
+
task_id: string;
|
196
|
+
task_name: string;
|
197
|
+
task_manager: PublicKey;
|
198
|
+
is_allowlisted: boolean;
|
199
|
+
is_active: boolean;
|
200
|
+
task_audit_program: string;
|
201
|
+
stake_pot_account: PublicKey;
|
202
|
+
stake_pot_seed: PublicKey;
|
203
|
+
stake_pot_bump: number;
|
204
|
+
total_bounty_amount: number;
|
205
|
+
bounty_amount_per_round: number;
|
206
|
+
token_type: PublicKey;
|
207
|
+
current_round: number;
|
208
|
+
available_balances: Record<string, ROE>;
|
209
|
+
stake_list: Record<string, ROE>;
|
210
|
+
task_metadata: string;
|
211
|
+
task_description: string;
|
212
|
+
submissions: SubmissionsPerRound;
|
213
|
+
submissions_audit_trigger: Record<string, Record<string, AuditTriggerState>>;
|
214
|
+
total_stake_amount: number;
|
215
|
+
minimum_stake_amount: number;
|
216
|
+
ip_address_list: Record<string, string>;
|
217
|
+
round_time: number;
|
218
|
+
starting_slot: number;
|
219
|
+
audit_window: number;
|
220
|
+
submission_window: number;
|
221
|
+
task_executable_network: 'IPFS' | 'ARWEAVE';
|
222
|
+
distribution_rewards_submission: SubmissionsPerRound;
|
223
|
+
distributions_audit_trigger: Record<string, Record<string, AuditTriggerState>>;
|
224
|
+
distributions_audit_record: Record<string, 'Uninitialized' | 'PayoutSuccessful' | 'PayoutFailed'>;
|
225
|
+
task_vars: string;
|
226
|
+
koii_vars: string;
|
227
|
+
is_migrated: boolean;
|
228
|
+
migrated_to: string;
|
229
|
+
allowed_failed_distributions: number;
|
230
|
+
}
|
231
|
+
interface TaskStateOptions {
|
232
|
+
is_submission_required?: boolean;
|
233
|
+
is_distribution_required?: boolean;
|
234
|
+
is_available_balances_required?: boolean;
|
235
|
+
is_stake_list_required?: boolean;
|
236
|
+
}
|
237
|
+
|
238
|
+
declare class DbAdapter implements IDatabase {
|
239
|
+
private static instance;
|
240
|
+
private db;
|
241
|
+
constructor(databasePath: string);
|
242
|
+
static getInstance(databasePath: string): DbAdapter;
|
243
|
+
compactDatafile(): void;
|
244
|
+
get(key: string): Promise<unknown>;
|
245
|
+
put(key: string, value: string): Promise<void>;
|
246
|
+
}
|
247
|
+
|
248
|
+
interface ExecuteTasksPayload {
|
249
|
+
selectedTasks: ISelectedTasks[];
|
250
|
+
expressApp: Application;
|
251
|
+
operationMode: string;
|
252
|
+
Namespace: ITaskNodeBaseWithConstructor;
|
253
|
+
mainSystemAccount: Keypair;
|
254
|
+
secrets: Record<string, string>;
|
255
|
+
attentionStake: unknown;
|
256
|
+
taskStakes?: string;
|
257
|
+
k2NodeUrl?: string;
|
258
|
+
serviceUrl?: string;
|
259
|
+
db: IDatabase;
|
260
|
+
}
|
261
|
+
declare function executeTasks({ selectedTasks, expressApp, operationMode, Namespace, mainSystemAccount, secrets, attentionStake, taskStakes, k2NodeUrl, serviceUrl, db, }: ExecuteTasksPayload): Promise<void>;
|
262
|
+
|
263
|
+
declare enum FilesystemNetwork {
|
264
|
+
ARWEAVE = "ARWEAVE",
|
265
|
+
IPFS = "IPFS"
|
266
|
+
}
|
267
|
+
/**
|
268
|
+
* Load tasks and generate task executables
|
269
|
+
* @param {any[]} selectedTasks Array of selected tasks
|
270
|
+
* @param {any} expressApp
|
271
|
+
* @returns {any[]} Array of executable tasks
|
272
|
+
*/
|
273
|
+
declare function loadTasks(selectedTasks: ISelectedTasks[], environment: string): Promise<void>;
|
274
|
+
|
275
|
+
declare function encodeData(type: any, fields: any): Buffer;
|
276
|
+
|
277
|
+
declare function getAlloc(type: any, fields: any): number;
|
278
|
+
|
279
|
+
/**
|
280
|
+
* @description Get URL from K2_NODE_URL environment variable
|
281
|
+
* @todo: probably should not be exported to the package
|
282
|
+
*/
|
283
|
+
declare function getRpcUrlWrapper(): string;
|
284
|
+
|
285
|
+
declare function padStringWithSpaces(input: string, length: number): string;
|
286
|
+
|
287
|
+
declare function makeChunks(data: Buffer, size: number): any[];
|
288
|
+
|
289
|
+
declare function sleep(ms: any): Promise<unknown>;
|
290
|
+
|
291
|
+
/** CORE TIMER LOGIC - BEGIN */
|
292
|
+
|
293
|
+
interface IGlobalTimersConfig {
|
294
|
+
KPL_tasks: string[];
|
295
|
+
selectedTasks: ISelectedTasks[];
|
296
|
+
runningTasks: IRunningTasks<ITaskNodeBase>;
|
297
|
+
setTimerForRewards?: (value: number) => void;
|
298
|
+
networkURL?: string;
|
299
|
+
}
|
300
|
+
declare function runTimers({ KPL_tasks, selectedTasks, runningTasks, setTimerForRewards, networkURL, }: IGlobalTimersConfig): Promise<NodeJS.Timer | undefined>;
|
301
|
+
declare function updateRewardsQueue(KPL_tasks: string[], setTimerForRewards: any, connection: Connection): Promise<void>;
|
302
|
+
|
303
|
+
declare function getAverageSlotTime(connection: Connection, prevAvgSlotTime?: number, samplesNumber?: number): Promise<number>;
|
304
|
+
|
305
|
+
declare function getCurrentSlot(connection: Connection): Promise<number>;
|
306
|
+
|
307
|
+
declare function getTaskState(connection: Connection, taskId: string, options: TaskStateOptions, context?: string): Promise<TaskState>;
|
308
|
+
declare function getTaskStateKPL(connection: {
|
309
|
+
getAccountInfo: (arg0: PublicKey) => any;
|
310
|
+
}, taskId: string, options: TaskStateOptions, context?: string): Promise<TaskStateKPL>;
|
311
|
+
|
312
|
+
interface TaskSubmissionState {
|
313
|
+
submissions: SubmissionsPerRound;
|
314
|
+
submissions_audit_trigger: Record<string, Record<string, AuditTriggerState>>;
|
315
|
+
}
|
316
|
+
declare function getTaskSubmissionInfo(connection: Connection, taskId: string, round?: number, task_type?: string, forceRefetch?: boolean): Promise<TaskSubmissionState>;
|
317
|
+
|
318
|
+
interface TaskDistributionInfo {
|
319
|
+
distribution_rewards_submission: SubmissionsPerRound;
|
320
|
+
distributions_audit_trigger: Record<string, Record<string, AuditTriggerState>>;
|
321
|
+
distributions_audit_record: Record<string, 'Uninitialized' | 'PayoutSuccessful' | 'PayoutFailed'>;
|
322
|
+
}
|
323
|
+
declare function getTaskDistributionInfo(connection: Connection, taskId: string, round?: number, task_type?: string): Promise<TaskDistributionInfo>;
|
324
|
+
|
325
|
+
interface MyTaskSubmission {
|
326
|
+
submission_value: string;
|
327
|
+
slot: number;
|
328
|
+
}
|
329
|
+
declare function getMyTaskSubmissionRoundInfo(connection: Connection, taskId: string, staking_wallet_address: string, round: number): Promise<MyTaskSubmission>;
|
330
|
+
|
331
|
+
declare function getMyTaskStakeInfo(connection: Connection, taskId: string, staking_wallet_address: string): Promise<number>;
|
332
|
+
|
333
|
+
declare function decodeZstd(base64ZstdData: string): Promise<Buffer>;
|
334
|
+
|
335
|
+
declare const TASK_INSTRUCTION_LAYOUTS: Readonly<{
|
336
|
+
CreateTask: {
|
337
|
+
index: number;
|
338
|
+
layout: BufferLayout.Structure<{
|
339
|
+
instruction: number;
|
340
|
+
task_name: Uint8Array;
|
341
|
+
task_description: Uint8Array;
|
342
|
+
task_audit_program: Buffer;
|
343
|
+
task_executable_network: Buffer;
|
344
|
+
total_bounty_amount: bigint;
|
345
|
+
bounty_amount_per_round: bigint;
|
346
|
+
round_time: bigint;
|
347
|
+
audit_window: bigint;
|
348
|
+
submission_window: bigint;
|
349
|
+
minimum_stake_amount: bigint;
|
350
|
+
task_metadata: Buffer;
|
351
|
+
local_vars: Buffer;
|
352
|
+
}>;
|
353
|
+
};
|
354
|
+
SubmitTask: {
|
355
|
+
index: number;
|
356
|
+
layout: BufferLayout.Structure<{
|
357
|
+
instruction: number;
|
358
|
+
submission: Uint8Array;
|
359
|
+
round: bigint;
|
360
|
+
}>;
|
361
|
+
};
|
362
|
+
AuditSubmissions: {
|
363
|
+
index: number;
|
364
|
+
layout: BufferLayout.Structure<{
|
365
|
+
instruction: number;
|
366
|
+
is_valid: bigint;
|
367
|
+
round: bigint;
|
368
|
+
}>;
|
369
|
+
};
|
370
|
+
AuditDistribution: {
|
371
|
+
index: number;
|
372
|
+
layout: BufferLayout.Structure<{
|
373
|
+
instruction: number;
|
374
|
+
is_valid: bigint;
|
375
|
+
round: bigint;
|
376
|
+
}>;
|
377
|
+
};
|
378
|
+
Payout: {
|
379
|
+
index: number;
|
380
|
+
layout: BufferLayout.Structure<{
|
381
|
+
instruction: number;
|
382
|
+
round: number;
|
383
|
+
}>;
|
384
|
+
};
|
385
|
+
Whitelist: {
|
386
|
+
index: number;
|
387
|
+
layout: BufferLayout.Structure<{
|
388
|
+
instruction: number;
|
389
|
+
isWhitelisted: bigint;
|
390
|
+
}>;
|
391
|
+
};
|
392
|
+
SetActive: {
|
393
|
+
index: number;
|
394
|
+
layout: BufferLayout.Structure<{
|
395
|
+
instruction: number;
|
396
|
+
isActive: bigint;
|
397
|
+
}>;
|
398
|
+
};
|
399
|
+
ClaimReward: {
|
400
|
+
index: number;
|
401
|
+
layout: BufferLayout.Structure<{
|
402
|
+
instruction: number;
|
403
|
+
}>;
|
404
|
+
};
|
405
|
+
FundTask: {
|
406
|
+
index: number;
|
407
|
+
layout: BufferLayout.Structure<{
|
408
|
+
instruction: number;
|
409
|
+
amount: bigint;
|
410
|
+
}>;
|
411
|
+
};
|
412
|
+
Stake: {
|
413
|
+
index: number;
|
414
|
+
layout: BufferLayout.Structure<{
|
415
|
+
instruction: number;
|
416
|
+
stakeAmount: bigint;
|
417
|
+
ipAddress: Uint8Array;
|
418
|
+
}>;
|
419
|
+
};
|
420
|
+
Withdraw: {
|
421
|
+
index: number;
|
422
|
+
layout: BufferLayout.Structure<{
|
423
|
+
instruction: number;
|
424
|
+
}>;
|
425
|
+
};
|
426
|
+
UploadDistributionList: {
|
427
|
+
index: number;
|
428
|
+
layout: BufferLayout.Structure<{
|
429
|
+
instruction: number;
|
430
|
+
instruction_data: ArrayBuffer;
|
431
|
+
}>;
|
432
|
+
};
|
433
|
+
SubmitDistributionList: {
|
434
|
+
index: number;
|
435
|
+
layout: BufferLayout.Structure<{
|
436
|
+
instruction: number;
|
437
|
+
round: bigint;
|
438
|
+
}>;
|
439
|
+
};
|
440
|
+
}>;
|
441
|
+
declare type TaskInstructionLayouts = typeof TASK_INSTRUCTION_LAYOUTS;
|
442
|
+
|
443
|
+
declare const TASK_INSTRUCTION_LAYOUTS_KPL: Readonly<{
|
444
|
+
CreateTask: {
|
445
|
+
index: number;
|
446
|
+
layout: BufferLayout.Structure<{
|
447
|
+
instruction: number;
|
448
|
+
task_name: Uint8Array;
|
449
|
+
task_description: Uint8Array;
|
450
|
+
task_audit_program: Buffer;
|
451
|
+
task_executable_network: Buffer;
|
452
|
+
total_bounty_amount: bigint;
|
453
|
+
bounty_amount_per_round: bigint;
|
454
|
+
round_time: bigint;
|
455
|
+
audit_window: bigint;
|
456
|
+
submission_window: bigint;
|
457
|
+
minimum_stake_amount: bigint;
|
458
|
+
task_metadata: Buffer;
|
459
|
+
local_vars: Buffer;
|
460
|
+
}>;
|
461
|
+
};
|
462
|
+
SubmitTask: {
|
463
|
+
index: number;
|
464
|
+
layout: BufferLayout.Structure<{
|
465
|
+
instruction: number;
|
466
|
+
submission: Uint8Array;
|
467
|
+
round: bigint;
|
468
|
+
}>;
|
469
|
+
};
|
470
|
+
AuditSubmissions: {
|
471
|
+
index: number;
|
472
|
+
layout: BufferLayout.Structure<{
|
473
|
+
instruction: number;
|
474
|
+
is_valid: bigint;
|
475
|
+
round: bigint;
|
476
|
+
}>;
|
477
|
+
};
|
478
|
+
AuditDistribution: {
|
479
|
+
index: number;
|
480
|
+
layout: BufferLayout.Structure<{
|
481
|
+
instruction: number;
|
482
|
+
is_valid: bigint;
|
483
|
+
round: bigint;
|
484
|
+
}>;
|
485
|
+
};
|
486
|
+
Payout: {
|
487
|
+
index: number;
|
488
|
+
layout: BufferLayout.Structure<{
|
489
|
+
instruction: number;
|
490
|
+
round: number;
|
491
|
+
}>;
|
492
|
+
};
|
493
|
+
Whitelist: {
|
494
|
+
index: number;
|
495
|
+
layout: BufferLayout.Structure<{
|
496
|
+
instruction: number;
|
497
|
+
isWhitelisted: bigint;
|
498
|
+
}>;
|
499
|
+
};
|
500
|
+
SetActive: {
|
501
|
+
index: number;
|
502
|
+
layout: BufferLayout.Structure<{
|
503
|
+
instruction: number;
|
504
|
+
isActive: bigint;
|
505
|
+
}>;
|
506
|
+
};
|
507
|
+
ClaimReward: {
|
508
|
+
index: number;
|
509
|
+
layout: BufferLayout.Structure<{
|
510
|
+
instruction: number;
|
511
|
+
}>;
|
512
|
+
};
|
513
|
+
FundTask: {
|
514
|
+
index: number;
|
515
|
+
layout: BufferLayout.Structure<{
|
516
|
+
instruction: number;
|
517
|
+
amount: bigint;
|
518
|
+
}>;
|
519
|
+
};
|
520
|
+
Stake: {
|
521
|
+
index: number;
|
522
|
+
layout: BufferLayout.Structure<{
|
523
|
+
instruction: number;
|
524
|
+
stakeAmount: bigint;
|
525
|
+
ipAddress: Uint8Array;
|
526
|
+
}>;
|
527
|
+
};
|
528
|
+
Withdraw: {
|
529
|
+
index: number;
|
530
|
+
layout: BufferLayout.Structure<{
|
531
|
+
instruction: number;
|
532
|
+
}>;
|
533
|
+
};
|
534
|
+
UploadDistributionList: {
|
535
|
+
index: number;
|
536
|
+
layout: BufferLayout.Structure<{
|
537
|
+
instruction: number;
|
538
|
+
instruction_data: ArrayBuffer;
|
539
|
+
}>;
|
540
|
+
};
|
541
|
+
SubmitDistributionList: {
|
542
|
+
index: number;
|
543
|
+
layout: BufferLayout.Structure<{
|
544
|
+
instruction: number;
|
545
|
+
round: bigint;
|
546
|
+
}>;
|
547
|
+
};
|
548
|
+
}>;
|
549
|
+
declare type KPLTaskInstructionLayouts = typeof TASK_INSTRUCTION_LAYOUTS_KPL;
|
550
|
+
|
551
|
+
declare const DEFAULT_PROGRAM_ID = "Koiitask22222222222222222222222222222222222";
|
552
|
+
declare const TASK_CONTRACT_ID: PublicKey;
|
553
|
+
declare const CLOCK_PUBLIC_KEY: PublicKey;
|
554
|
+
declare const BUNDLER_NODES = "/nodes";
|
555
|
+
declare const ARWEAVE_GATEWAY_URL = "https://arweave.net/";
|
556
|
+
declare const IPFS_GATEWAY_URL = "https://ipfs.io/ipfs/";
|
557
|
+
declare const KPL_PROGRAM_ID = "KPLTRVs6jA7QTthuJH2cEmyCEskFbSV2xpZw46cganN";
|
558
|
+
declare const KPL_CONTRACT_ID: PublicKey;
|
559
|
+
|
560
|
+
declare abstract class TaskNodeBase implements ITaskNodeBase {
|
561
|
+
abstract getSubmitterAccount(): Promise<Keypair | null>;
|
562
|
+
abstract getMainSystemAccountPubKey(db?: IDatabase): Promise<Keypair>;
|
563
|
+
abstract getDistributionAccount(): Promise<Keypair | null>;
|
564
|
+
db: IDatabase;
|
565
|
+
mainSystemAccount: Keypair | null | undefined;
|
566
|
+
taskData: TaskData;
|
567
|
+
mainSystemAccountPubKey: PublicKey;
|
568
|
+
taskAccountInfo: AccountInfo<Buffer> | null;
|
569
|
+
submitterAccountKeyPair: Keypair;
|
570
|
+
distributionAccountKeyPair: Keypair;
|
571
|
+
submitterPubkey: string;
|
572
|
+
distributionPubKey: string;
|
573
|
+
connection: Connection;
|
574
|
+
taskStateInfoPublicKey: PublicKey;
|
575
|
+
stakePotAccount: PublicKey;
|
576
|
+
taskTxId: string;
|
577
|
+
serverApp: Application | null;
|
578
|
+
rpcUrl: string;
|
579
|
+
taskType: string;
|
580
|
+
loggerCallback: null | ((level: LogLevel, message: string, action: string) => void);
|
581
|
+
constructor({ mainSystemAccount, taskTxId, taskData, serverApp, db, rpcUrl, taskType, }: TaskNodeConfig);
|
582
|
+
appDataPath: string;
|
583
|
+
storeGet(key: string): Promise<any>;
|
584
|
+
/**
|
585
|
+
* Namespace wrapper over storeSetAsync
|
586
|
+
* @param {string} key Path to set
|
587
|
+
* @param {*} value Data to set
|
588
|
+
* @returns {Promise<void>}
|
589
|
+
*/
|
590
|
+
storeSet(key: string, value: string): Promise<void>;
|
591
|
+
jwtSign(accessToken: string, secret: string): Promise<string>;
|
592
|
+
jwtVerify(accessToken: string, secret: string): Promise<string | jsonwebtoken.JwtPayload>;
|
593
|
+
/**
|
594
|
+
* Namespace wrapper over fsPromises methods
|
595
|
+
* @param {*} method The fsPromise method to call
|
596
|
+
* @param {*} path Path for the express call
|
597
|
+
* @param {...any} args Remaining parameters for the FS call
|
598
|
+
* @returns {Promise<any>}
|
599
|
+
*/
|
600
|
+
fs(method: keyof typeof fsPromises, path: string, ...args: unknown[]): Promise<unknown>;
|
601
|
+
fsStaking(method: keyof typeof fsPromises, path: any, ...args: any[]): Promise<unknown>;
|
602
|
+
fsWriteStream(imagepath: string): Promise<WriteStream>;
|
603
|
+
fsReadStream(imagepath: string): Promise<Buffer>;
|
604
|
+
/**
|
605
|
+
* Namespace wrapper over express app methods
|
606
|
+
* @param {string} method // Receive method ["get", "post", "put", "delete"]
|
607
|
+
* @param {string} path // Endpoint path appended to namespace
|
608
|
+
* @param {Function} callback // Callback function on traffic receive
|
609
|
+
*/
|
610
|
+
express(method: ExpressMethodType, path: string, callback: RequestHandler): Application;
|
611
|
+
/**
|
612
|
+
* Wrapper function for the OnChain submission for Task contract
|
613
|
+
* @param {Connection} connection // The k2 connection object
|
614
|
+
* @param {PublicKey} taskStateInfoKeypairPubKey // Task Id
|
615
|
+
* @param {Keypair} submitterPubkey //The keypair of the submitter node
|
616
|
+
* @param {string} submission // The actual submission to onchain (cannot pe greater than 512 bytes)
|
617
|
+
*/
|
618
|
+
submissionOnChain(submitterKeypair: Keypair, submission: string, round: number): Promise<string>;
|
619
|
+
distributionListSubmissionOnChain(round: number): Promise<string>;
|
620
|
+
stakeOnChain(taskStateInfoPublicKey: PublicKey, stakingAccKeypair: Keypair, stakePotAccount: PublicKey, stakeAmount: number): Promise<string>;
|
621
|
+
claimReward(stakePotAccount: PublicKey, beneficiaryAccount: PublicKey, claimerKeypair: Keypair, taskStateInfoPublicKey?: PublicKey): Promise<string>;
|
622
|
+
sendTransaction(serviceNodeAccount: PublicKey, beneficiaryAccount: PublicKey, amount: number): Promise<string>;
|
623
|
+
bs58Encode(data: Uint8Array): Promise<string>;
|
624
|
+
bs58Decode(data: any): Promise<Uint8Array>;
|
625
|
+
signData(data: any): Promise<string>;
|
626
|
+
verifySignedData(signedData: any, publicKey: string): Promise<{
|
627
|
+
error: string;
|
628
|
+
data?: undefined;
|
629
|
+
} | {
|
630
|
+
data: string;
|
631
|
+
error?: undefined;
|
632
|
+
}>;
|
633
|
+
decodePayload(payload: Uint8Array): string;
|
634
|
+
setLoggerCallback(callback: (level: LogLevel, message: string, action: string) => void): void;
|
635
|
+
logger(level: LogLevel, message: string, action: string): Promise<boolean>;
|
636
|
+
/**
|
637
|
+
* @consider to remove it from here and add it just to the Task Node, it is not used in the Desktop Node
|
638
|
+
*/
|
639
|
+
sendAndConfirmTransactionWrapper(transaction: any, signers: any[]): Promise<string>;
|
640
|
+
/**
|
641
|
+
* @todo: fix types
|
642
|
+
*/
|
643
|
+
mapSignersToKeypairs(signers: any[]): Keypair[];
|
644
|
+
establishConnection(): Promise<void>;
|
645
|
+
/**
|
646
|
+
* @description Get the latest Task State
|
647
|
+
* @returns task data in JSON format
|
648
|
+
*/
|
649
|
+
getTaskState(options: TaskStateOptions, context?: string): Promise<TaskState>;
|
650
|
+
/**
|
651
|
+
* @description Refers the value of round to know if submission is allowed or not
|
652
|
+
*/
|
653
|
+
checkSubmissionAndUpdateRound(submissionValue: string, round: number): Promise<void>;
|
654
|
+
/**
|
655
|
+
* @description Get the latest Task State
|
656
|
+
* @returns task data in JSON format
|
657
|
+
*/
|
658
|
+
getProgramAccounts(): Promise<{
|
659
|
+
pubkey: PublicKey;
|
660
|
+
account: AccountInfo<Buffer>;
|
661
|
+
}[]>;
|
662
|
+
getRpcUrl(): string;
|
663
|
+
storeGetRaw(key: string): Promise<string | null>;
|
664
|
+
defaultTaskSetup(): Promise<void>;
|
665
|
+
/**
|
666
|
+
* Gets an array of service nodes
|
667
|
+
* @param url URL of the service node to retrieve the array from a known service node
|
668
|
+
* @returns Array of service nodes
|
669
|
+
*/
|
670
|
+
getNodes(url: string): Promise<Array<INode>>;
|
671
|
+
getTaskStateById(taskId: string, options: TaskStateOptions, task_type: string, context?: string): Promise<TaskState>;
|
672
|
+
getCurrentSlot(): Promise<number>;
|
673
|
+
payloadTriggerOnBehalf(round: any, distribution_account_key: any): Promise<string>;
|
674
|
+
getCacheNodes(taskId: string): Promise<INode[]>;
|
675
|
+
/**
|
676
|
+
* @todo: ask Syed if we can get taskId from the class
|
677
|
+
*/
|
678
|
+
registerNodes(newNodes: any, taskId: string): Promise<boolean>;
|
679
|
+
payloadTrigger(round: any): Promise<string>;
|
680
|
+
getRound(): Promise<number>;
|
681
|
+
uploadDistributionList(distributionListDataBlob: object, round: number): Promise<boolean | null>;
|
682
|
+
distributionListAuditSubmission(candidatePubkey: PublicKey, isValid: boolean, round: number): Promise<string>;
|
683
|
+
/**
|
684
|
+
* Wrapper function for the OnChain Voting for Task contract
|
685
|
+
* @param {Connection} connection // The k2 connection object
|
686
|
+
* @param {PublicKey} candidatePubkey // Candidate public key who submitted the task and you are approving whose task is correct
|
687
|
+
* @param {Keypair} voterKeypair // Voter keypair optional, by default will use the your task account keypair
|
688
|
+
* @param {boolean} isValid // Boolean indicating submission is valid or Invalid
|
689
|
+
|
690
|
+
*/
|
691
|
+
auditSubmission(candidatePubkey: PublicKey, isValid: boolean, round: number): Promise<string>;
|
692
|
+
getDistributionList(publicKey: string, round: string, taskId?: string): Promise<string | null>;
|
693
|
+
getTaskSubmissionInfo(round: number): Promise<TaskSubmissionState | null>;
|
694
|
+
getTaskDistributionInfo(round: number): Promise<TaskDistributionInfo | null>;
|
695
|
+
getAverageSlotTime(): Promise<number>;
|
696
|
+
validateUploadedDistributionList(publicKey: PublicKey, round: string, originalDistributionList: object): Promise<boolean>;
|
697
|
+
shallowEqual(parsed: any, generateDistributionList: any): Promise<boolean>;
|
698
|
+
getBincodeDeserializedDistributionList(raw_data: any, round: string, taskId: string): string | null;
|
699
|
+
retryFailedTransactions(dataByteCount: number, chunks: Array<Uint8Array>, ourAccount: Keypair, uploadAccount: Keypair, round: string, orginalDistributionList: any, totalChunks: number): Promise<boolean>;
|
700
|
+
private insertStringAt;
|
701
|
+
getTaskLevelDBPath(): Promise<string>;
|
702
|
+
getBasePath(): Promise<string>;
|
703
|
+
getTaskNodeVersion(): Promise<string>;
|
704
|
+
}
|
705
|
+
|
706
|
+
/**
|
707
|
+
* Run loop that executes every 5 minutes
|
708
|
+
*/
|
709
|
+
declare function runPeriodic(selectedTasks: any, namespace: any, mainSystemWalletAccount: Keypair, serviceUrl: string, haveStaticIP: boolean): Promise<void>;
|
710
|
+
declare function initialPropagation(selectedTasks: any, attentionTaskId: string, namespace: any, mainSystemWalletAccount: Keypair, serviceUrl: string, haveStaticIP: boolean): Promise<any>;
|
711
|
+
|
712
|
+
export { ARWEAVE_GATEWAY_URL, AuditTriggerState, BUNDLER_NODES, CLOCK_PUBLIC_KEY, DEFAULT_PROGRAM_ID, DbAdapter, ExpressMethodType, FilesystemNetwork, IDatabase, IGlobalTimersConfig, INode, IPFS_GATEWAY_URL, IRunningTasks, ISelectedTasks, ITaskNodeBase, ITaskNodeBaseWithConstructor, KPLTaskInstructionLayouts, KPL_CONTRACT_ID, KPL_PROGRAM_ID, LogLevel, PublicKeyString, Round, Submission, SubmissionsPerRound, TASK_CONTRACT_ID, TASK_INSTRUCTION_LAYOUTS, TASK_INSTRUCTION_LAYOUTS_KPL, TaskData, TaskDistributionInfo, TaskInstructionLayouts, TaskNodeBase, TaskNodeConfig, TaskState, TaskStateKPL, TaskStateOptions, TaskSubmissionState, decodeZstd, encodeData, executeTasks, getAlloc, getAverageSlotTime, getCurrentSlot, getMyTaskStakeInfo, getMyTaskSubmissionRoundInfo, getRpcUrlWrapper, getTaskDistributionInfo, getTaskState, getTaskStateKPL, getTaskSubmissionInfo, initialPropagation, loadTasks, makeChunks, padStringWithSpaces, runPeriodic, runTimers, sleep, updateRewardsQueue };
|