@dymchenko/en-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,883 @@
1
+ {
2
+ "address": "4bFkEKEgLfWQPjR21gTWzWtq8ZgUR4EVRi6LWm8LxoEc",
3
+ "metadata": {
4
+ "name": "en_solana",
5
+ "version": "0.1.0",
6
+ "spec": "0.1.0",
7
+ "description": "Created with Anchor"
8
+ },
9
+ "instructions": [
10
+ {
11
+ "name": "accept_evaluator",
12
+ "docs": [
13
+ "Provider accepts the client's proposed evaluator as-is.",
14
+ "Locks the provider in and marks evaluator as agreed, allowing fund()."
15
+ ],
16
+ "discriminator": [
17
+ 162,
18
+ 56,
19
+ 71,
20
+ 216,
21
+ 139,
22
+ 9,
23
+ 231,
24
+ 252
25
+ ],
26
+ "accounts": [
27
+ {
28
+ "name": "job",
29
+ "writable": true
30
+ },
31
+ {
32
+ "name": "provider",
33
+ "signer": true
34
+ }
35
+ ],
36
+ "args": []
37
+ },
38
+ {
39
+ "name": "cancel_recurring",
40
+ "docs": [
41
+ "Client cancels a recurring job between cycles (Open or Complete state only)."
42
+ ],
43
+ "discriminator": [
44
+ 108,
45
+ 177,
46
+ 37,
47
+ 163,
48
+ 146,
49
+ 35,
50
+ 194,
51
+ 227
52
+ ],
53
+ "accounts": [
54
+ {
55
+ "name": "job",
56
+ "writable": true
57
+ },
58
+ {
59
+ "name": "client",
60
+ "signer": true
61
+ }
62
+ ],
63
+ "args": []
64
+ },
65
+ {
66
+ "name": "client_accept_evaluator",
67
+ "docs": [
68
+ "Client accepts the provider's counter-proposed evaluator.",
69
+ "Updates the evaluator, marks agreement, returns to Open so fund() works."
70
+ ],
71
+ "discriminator": [
72
+ 221,
73
+ 201,
74
+ 129,
75
+ 49,
76
+ 105,
77
+ 143,
78
+ 8,
79
+ 255
80
+ ],
81
+ "accounts": [
82
+ {
83
+ "name": "job",
84
+ "writable": true
85
+ },
86
+ {
87
+ "name": "client",
88
+ "signer": true
89
+ }
90
+ ],
91
+ "args": []
92
+ },
93
+ {
94
+ "name": "client_reject_evaluator",
95
+ "docs": [
96
+ "Client rejects the provider's counter-proposal.",
97
+ "Clears the counter-proposal and provider, reopening the job for negotiation."
98
+ ],
99
+ "discriminator": [
100
+ 107,
101
+ 90,
102
+ 66,
103
+ 38,
104
+ 200,
105
+ 228,
106
+ 165,
107
+ 147
108
+ ],
109
+ "accounts": [
110
+ {
111
+ "name": "job",
112
+ "writable": true
113
+ },
114
+ {
115
+ "name": "client",
116
+ "signer": true
117
+ }
118
+ ],
119
+ "args": []
120
+ },
121
+ {
122
+ "name": "complete",
123
+ "discriminator": [
124
+ 0,
125
+ 77,
126
+ 224,
127
+ 147,
128
+ 136,
129
+ 25,
130
+ 88,
131
+ 76
132
+ ],
133
+ "accounts": [
134
+ {
135
+ "name": "job",
136
+ "writable": true
137
+ },
138
+ {
139
+ "name": "evaluator",
140
+ "signer": true
141
+ },
142
+ {
143
+ "name": "provider",
144
+ "writable": true
145
+ }
146
+ ],
147
+ "args": []
148
+ },
149
+ {
150
+ "name": "create_job",
151
+ "discriminator": [
152
+ 178,
153
+ 130,
154
+ 217,
155
+ 110,
156
+ 100,
157
+ 27,
158
+ 82,
159
+ 119
160
+ ],
161
+ "accounts": [
162
+ {
163
+ "name": "global_state",
164
+ "writable": true,
165
+ "pda": {
166
+ "seeds": [
167
+ {
168
+ "kind": "const",
169
+ "value": [
170
+ 103,
171
+ 108,
172
+ 111,
173
+ 98,
174
+ 97,
175
+ 108,
176
+ 95,
177
+ 115,
178
+ 116,
179
+ 97,
180
+ 116,
181
+ 101
182
+ ]
183
+ }
184
+ ]
185
+ }
186
+ },
187
+ {
188
+ "name": "job",
189
+ "writable": true,
190
+ "pda": {
191
+ "seeds": [
192
+ {
193
+ "kind": "const",
194
+ "value": [
195
+ 106,
196
+ 111,
197
+ 98
198
+ ]
199
+ },
200
+ {
201
+ "kind": "account",
202
+ "path": "client"
203
+ },
204
+ {
205
+ "kind": "account",
206
+ "path": "global_state.job_counter",
207
+ "account": "GlobalState"
208
+ }
209
+ ]
210
+ }
211
+ },
212
+ {
213
+ "name": "client",
214
+ "writable": true,
215
+ "signer": true
216
+ },
217
+ {
218
+ "name": "system_program",
219
+ "address": "11111111111111111111111111111111"
220
+ }
221
+ ],
222
+ "args": [
223
+ {
224
+ "name": "task",
225
+ "type": "string"
226
+ },
227
+ {
228
+ "name": "amount_lamports",
229
+ "type": "u64"
230
+ },
231
+ {
232
+ "name": "evaluator",
233
+ "type": "pubkey"
234
+ },
235
+ {
236
+ "name": "expiry",
237
+ "type": "i64"
238
+ },
239
+ {
240
+ "name": "bilateral_evaluator",
241
+ "type": "bool"
242
+ },
243
+ {
244
+ "name": "recurrence_interval",
245
+ "type": "i64"
246
+ },
247
+ {
248
+ "name": "lock_provider",
249
+ "type": "bool"
250
+ },
251
+ {
252
+ "name": "lock_evaluator",
253
+ "type": "bool"
254
+ }
255
+ ]
256
+ },
257
+ {
258
+ "name": "expire",
259
+ "discriminator": [
260
+ 243,
261
+ 83,
262
+ 205,
263
+ 58,
264
+ 57,
265
+ 201,
266
+ 247,
267
+ 146
268
+ ],
269
+ "accounts": [
270
+ {
271
+ "name": "job",
272
+ "writable": true
273
+ },
274
+ {
275
+ "name": "client",
276
+ "writable": true
277
+ },
278
+ {
279
+ "name": "caller",
280
+ "signer": true
281
+ }
282
+ ],
283
+ "args": []
284
+ },
285
+ {
286
+ "name": "fund",
287
+ "discriminator": [
288
+ 218,
289
+ 188,
290
+ 111,
291
+ 221,
292
+ 152,
293
+ 113,
294
+ 174,
295
+ 7
296
+ ],
297
+ "accounts": [
298
+ {
299
+ "name": "job",
300
+ "writable": true
301
+ },
302
+ {
303
+ "name": "client",
304
+ "writable": true,
305
+ "signer": true
306
+ },
307
+ {
308
+ "name": "system_program",
309
+ "address": "11111111111111111111111111111111"
310
+ }
311
+ ],
312
+ "args": []
313
+ },
314
+ {
315
+ "name": "initialize",
316
+ "discriminator": [
317
+ 175,
318
+ 175,
319
+ 109,
320
+ 31,
321
+ 13,
322
+ 152,
323
+ 155,
324
+ 237
325
+ ],
326
+ "accounts": [
327
+ {
328
+ "name": "global_state",
329
+ "writable": true,
330
+ "pda": {
331
+ "seeds": [
332
+ {
333
+ "kind": "const",
334
+ "value": [
335
+ 103,
336
+ 108,
337
+ 111,
338
+ 98,
339
+ 97,
340
+ 108,
341
+ 95,
342
+ 115,
343
+ 116,
344
+ 97,
345
+ 116,
346
+ 101
347
+ ]
348
+ }
349
+ ]
350
+ }
351
+ },
352
+ {
353
+ "name": "authority",
354
+ "writable": true,
355
+ "signer": true
356
+ },
357
+ {
358
+ "name": "system_program",
359
+ "address": "11111111111111111111111111111111"
360
+ }
361
+ ],
362
+ "args": []
363
+ },
364
+ {
365
+ "name": "propose_evaluator",
366
+ "docs": [
367
+ "Provider counter-proposes a different evaluator address.",
368
+ "Job moves to Negotiating state; client must respond before funding."
369
+ ],
370
+ "discriminator": [
371
+ 220,
372
+ 178,
373
+ 28,
374
+ 4,
375
+ 243,
376
+ 224,
377
+ 117,
378
+ 167
379
+ ],
380
+ "accounts": [
381
+ {
382
+ "name": "job",
383
+ "writable": true
384
+ },
385
+ {
386
+ "name": "provider",
387
+ "signer": true
388
+ }
389
+ ],
390
+ "args": [
391
+ {
392
+ "name": "new_evaluator",
393
+ "type": "pubkey"
394
+ }
395
+ ]
396
+ },
397
+ {
398
+ "name": "reject",
399
+ "discriminator": [
400
+ 135,
401
+ 7,
402
+ 63,
403
+ 85,
404
+ 131,
405
+ 114,
406
+ 111,
407
+ 224
408
+ ],
409
+ "accounts": [
410
+ {
411
+ "name": "job",
412
+ "writable": true
413
+ },
414
+ {
415
+ "name": "evaluator",
416
+ "signer": true
417
+ },
418
+ {
419
+ "name": "client",
420
+ "writable": true
421
+ }
422
+ ],
423
+ "args": []
424
+ },
425
+ {
426
+ "name": "reopen_job",
427
+ "docs": [
428
+ "Keeper bot calls this after recurrence_interval seconds have elapsed since completion.",
429
+ "Permissionless: any caller may trigger the reopen once the interval has passed.",
430
+ "Creates a JobCycle account (paid by the caller) that permanently records the cycle."
431
+ ],
432
+ "discriminator": [
433
+ 185,
434
+ 23,
435
+ 177,
436
+ 47,
437
+ 144,
438
+ 75,
439
+ 33,
440
+ 36
441
+ ],
442
+ "accounts": [
443
+ {
444
+ "name": "job",
445
+ "writable": true
446
+ },
447
+ {
448
+ "name": "cycle",
449
+ "writable": true,
450
+ "pda": {
451
+ "seeds": [
452
+ {
453
+ "kind": "const",
454
+ "value": [
455
+ 99,
456
+ 121,
457
+ 99,
458
+ 108,
459
+ 101
460
+ ]
461
+ },
462
+ {
463
+ "kind": "account",
464
+ "path": "job"
465
+ },
466
+ {
467
+ "kind": "account",
468
+ "path": "job.recurrence_count",
469
+ "account": "Job"
470
+ }
471
+ ]
472
+ }
473
+ },
474
+ {
475
+ "name": "caller",
476
+ "writable": true,
477
+ "signer": true
478
+ },
479
+ {
480
+ "name": "system_program",
481
+ "address": "11111111111111111111111111111111"
482
+ }
483
+ ],
484
+ "args": []
485
+ },
486
+ {
487
+ "name": "submit",
488
+ "discriminator": [
489
+ 88,
490
+ 166,
491
+ 102,
492
+ 181,
493
+ 162,
494
+ 127,
495
+ 170,
496
+ 48
497
+ ],
498
+ "accounts": [
499
+ {
500
+ "name": "job",
501
+ "writable": true
502
+ },
503
+ {
504
+ "name": "provider",
505
+ "signer": true
506
+ }
507
+ ],
508
+ "args": [
509
+ {
510
+ "name": "result_hash",
511
+ "type": "string"
512
+ }
513
+ ]
514
+ },
515
+ {
516
+ "name": "update_evaluator",
517
+ "docs": [
518
+ "Client sets a new evaluator for the next cycle when lock_evaluator = false.",
519
+ "Must be called while the job is Open and before funding."
520
+ ],
521
+ "discriminator": [
522
+ 22,
523
+ 146,
524
+ 229,
525
+ 35,
526
+ 228,
527
+ 189,
528
+ 132,
529
+ 185
530
+ ],
531
+ "accounts": [
532
+ {
533
+ "name": "job",
534
+ "writable": true
535
+ },
536
+ {
537
+ "name": "client",
538
+ "signer": true
539
+ }
540
+ ],
541
+ "args": [
542
+ {
543
+ "name": "new_evaluator",
544
+ "type": "pubkey"
545
+ }
546
+ ]
547
+ }
548
+ ],
549
+ "accounts": [
550
+ {
551
+ "name": "GlobalState",
552
+ "discriminator": [
553
+ 163,
554
+ 46,
555
+ 74,
556
+ 168,
557
+ 216,
558
+ 123,
559
+ 133,
560
+ 98
561
+ ]
562
+ },
563
+ {
564
+ "name": "Job",
565
+ "discriminator": [
566
+ 75,
567
+ 124,
568
+ 80,
569
+ 203,
570
+ 161,
571
+ 180,
572
+ 202,
573
+ 80
574
+ ]
575
+ },
576
+ {
577
+ "name": "JobCycle",
578
+ "discriminator": [
579
+ 238,
580
+ 120,
581
+ 221,
582
+ 206,
583
+ 102,
584
+ 133,
585
+ 91,
586
+ 148
587
+ ]
588
+ }
589
+ ],
590
+ "events": [
591
+ {
592
+ "name": "JobReopened",
593
+ "discriminator": [
594
+ 183,
595
+ 233,
596
+ 104,
597
+ 185,
598
+ 241,
599
+ 223,
600
+ 175,
601
+ 203
602
+ ]
603
+ }
604
+ ],
605
+ "errors": [
606
+ {
607
+ "code": 6000,
608
+ "name": "TaskTooLong",
609
+ "msg": "Task exceeds maximum length of 200 characters"
610
+ },
611
+ {
612
+ "code": 6001,
613
+ "name": "ResultTooLong",
614
+ "msg": "Result exceeds maximum length of 100 characters"
615
+ },
616
+ {
617
+ "code": 6002,
618
+ "name": "InvalidState",
619
+ "msg": "Invalid state transition"
620
+ },
621
+ {
622
+ "code": 6003,
623
+ "name": "Unauthorized",
624
+ "msg": "Unauthorized"
625
+ },
626
+ {
627
+ "code": 6004,
628
+ "name": "ExpiryInPast",
629
+ "msg": "Expiry must be in the future"
630
+ },
631
+ {
632
+ "code": 6005,
633
+ "name": "NotYetExpired",
634
+ "msg": "Job has not yet expired"
635
+ },
636
+ {
637
+ "code": 6006,
638
+ "name": "EvaluatorNotAgreed",
639
+ "msg": "Both parties must agree on the evaluator before the job can be funded"
640
+ },
641
+ {
642
+ "code": 6007,
643
+ "name": "JobAlreadyTaken",
644
+ "msg": "Another provider has already started evaluator negotiation for this job"
645
+ },
646
+ {
647
+ "code": 6008,
648
+ "name": "NotBilateral",
649
+ "msg": "This job does not require bilateral evaluator agreement"
650
+ },
651
+ {
652
+ "code": 6009,
653
+ "name": "InvalidRecurrenceInterval",
654
+ "msg": "recurrence_interval must be >= 0"
655
+ },
656
+ {
657
+ "code": 6010,
658
+ "name": "NotRecurring",
659
+ "msg": "This job is not a recurring job"
660
+ },
661
+ {
662
+ "code": 6011,
663
+ "name": "RecurrenceNotDue",
664
+ "msg": "Recurrence interval has not elapsed since last completion"
665
+ },
666
+ {
667
+ "code": 6012,
668
+ "name": "EvaluatorLocked",
669
+ "msg": "Evaluator is locked and cannot be changed on this recurring job"
670
+ },
671
+ {
672
+ "code": 6013,
673
+ "name": "EvaluatorNotSet",
674
+ "msg": "Evaluator must be set before funding a recurring job with lock_evaluator = false"
675
+ }
676
+ ],
677
+ "types": [
678
+ {
679
+ "name": "GlobalState",
680
+ "type": {
681
+ "kind": "struct",
682
+ "fields": [
683
+ {
684
+ "name": "authority",
685
+ "type": "pubkey"
686
+ },
687
+ {
688
+ "name": "job_counter",
689
+ "type": "u64"
690
+ }
691
+ ]
692
+ }
693
+ },
694
+ {
695
+ "name": "Job",
696
+ "type": {
697
+ "kind": "struct",
698
+ "fields": [
699
+ {
700
+ "name": "job_id",
701
+ "type": "u64"
702
+ },
703
+ {
704
+ "name": "client",
705
+ "type": "pubkey"
706
+ },
707
+ {
708
+ "name": "provider",
709
+ "type": "pubkey"
710
+ },
711
+ {
712
+ "name": "evaluator",
713
+ "type": "pubkey"
714
+ },
715
+ {
716
+ "name": "task",
717
+ "type": "string"
718
+ },
719
+ {
720
+ "name": "amount_lamports",
721
+ "type": "u64"
722
+ },
723
+ {
724
+ "name": "state",
725
+ "type": {
726
+ "defined": {
727
+ "name": "JobState"
728
+ }
729
+ }
730
+ },
731
+ {
732
+ "name": "created_at",
733
+ "type": "i64"
734
+ },
735
+ {
736
+ "name": "expiry",
737
+ "type": "i64"
738
+ },
739
+ {
740
+ "name": "result_hash",
741
+ "type": "string"
742
+ },
743
+ {
744
+ "name": "bilateral_evaluator",
745
+ "type": "bool"
746
+ },
747
+ {
748
+ "name": "counter_evaluator",
749
+ "type": "pubkey"
750
+ },
751
+ {
752
+ "name": "provider_accepted_evaluator",
753
+ "type": "bool"
754
+ },
755
+ {
756
+ "name": "recurrence_interval",
757
+ "docs": [
758
+ "Seconds between cycles. 0 = non-recurring."
759
+ ],
760
+ "type": "i64"
761
+ },
762
+ {
763
+ "name": "recurrence_count",
764
+ "docs": [
765
+ "Number of times this job has been reopened and completed."
766
+ ],
767
+ "type": "u64"
768
+ },
769
+ {
770
+ "name": "lock_provider",
771
+ "docs": [
772
+ "If true, only the same provider may submit each cycle."
773
+ ],
774
+ "type": "bool"
775
+ },
776
+ {
777
+ "name": "lock_evaluator",
778
+ "docs": [
779
+ "If true, the evaluator is fixed across all cycles.",
780
+ "If false, client must call update_evaluator before funding each new cycle."
781
+ ],
782
+ "type": "bool"
783
+ },
784
+ {
785
+ "name": "completed_at",
786
+ "docs": [
787
+ "Unix timestamp of the last completion, used by the keeper to check interval."
788
+ ],
789
+ "type": "i64"
790
+ }
791
+ ]
792
+ }
793
+ },
794
+ {
795
+ "name": "JobCycle",
796
+ "docs": [
797
+ "Permanent record of a single completed cycle for a recurring job.",
798
+ "PDA seeds: [\"cycle\", job_pubkey, cycle_number_le]"
799
+ ],
800
+ "type": {
801
+ "kind": "struct",
802
+ "fields": [
803
+ {
804
+ "name": "job",
805
+ "type": "pubkey"
806
+ },
807
+ {
808
+ "name": "cycle_number",
809
+ "type": "u64"
810
+ },
811
+ {
812
+ "name": "provider",
813
+ "type": "pubkey"
814
+ },
815
+ {
816
+ "name": "evaluator",
817
+ "type": "pubkey"
818
+ },
819
+ {
820
+ "name": "result_hash",
821
+ "type": "string"
822
+ },
823
+ {
824
+ "name": "completed_at",
825
+ "type": "i64"
826
+ },
827
+ {
828
+ "name": "amount_lamports",
829
+ "type": "u64"
830
+ }
831
+ ]
832
+ }
833
+ },
834
+ {
835
+ "name": "JobReopened",
836
+ "type": {
837
+ "kind": "struct",
838
+ "fields": [
839
+ {
840
+ "name": "job_id",
841
+ "type": "u64"
842
+ },
843
+ {
844
+ "name": "recurrence_count",
845
+ "type": "u64"
846
+ }
847
+ ]
848
+ }
849
+ },
850
+ {
851
+ "name": "JobState",
852
+ "type": {
853
+ "kind": "enum",
854
+ "variants": [
855
+ {
856
+ "name": "Open"
857
+ },
858
+ {
859
+ "name": "Negotiating"
860
+ },
861
+ {
862
+ "name": "Funded"
863
+ },
864
+ {
865
+ "name": "Submitted"
866
+ },
867
+ {
868
+ "name": "Complete"
869
+ },
870
+ {
871
+ "name": "Rejected"
872
+ },
873
+ {
874
+ "name": "Expired"
875
+ },
876
+ {
877
+ "name": "Cancelled"
878
+ }
879
+ ]
880
+ }
881
+ }
882
+ ]
883
+ }
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import * as anchor from "@coral-xyz/anchor";
2
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
3
+ export declare const PROGRAM_ID: anchor.web3.PublicKey;
4
+ export declare function findGlobalStatePda(): [PublicKey, number];
5
+ export declare function findJobPda(client: PublicKey, jobId: anchor.BN): [PublicKey, number];
6
+ export declare function findCyclePda(jobPda: PublicKey, cycleNumber: anchor.BN | number): [PublicKey, number];
7
+ export declare function getProgram(connection: Connection, wallet: Keypair): any;
8
+ export declare function getAllJobs(connection: Connection, wallet: Keypair): Promise<any>;
9
+ export declare function initializeGlobalState(connection: Connection, wallet: Keypair): Promise<string>;
10
+ export declare function createJob(connection: Connection, wallet: Keypair, task: string, amountSol: number, evaluator: PublicKey, expirySeconds?: number, bilateralEvaluator?: boolean, recurrenceInterval?: anchor.BN, lockProvider?: boolean, lockEvaluator?: boolean): Promise<{
11
+ txSig: string;
12
+ jobPda: PublicKey;
13
+ jobId: anchor.BN;
14
+ }>;
15
+ export declare function fundJob(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
16
+ /** Provider accepts the client's proposed evaluator. Allows client to fund(). */
17
+ export declare function acceptEvaluator(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
18
+ /** Provider counter-proposes a different evaluator. Job moves to Negotiating. */
19
+ export declare function proposeEvaluator(connection: Connection, wallet: Keypair, jobPda: PublicKey, newEvaluator: PublicKey): Promise<string>;
20
+ /** Client accepts the provider's counter-proposed evaluator. Job returns to Open. */
21
+ export declare function clientAcceptEvaluator(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
22
+ /** Client rejects the provider's counter-proposal. Job resets to Open for re-negotiation. */
23
+ export declare function clientRejectEvaluator(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
24
+ export declare function submitResult(connection: Connection, wallet: Keypair, jobPda: PublicKey, resultHash: string): Promise<string>;
25
+ export declare function approveJob(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
26
+ export declare function rejectJob(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
27
+ export declare function expireJob(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
28
+ /** Keeper: reopen a complete recurring job once the interval has elapsed. */
29
+ export declare function reopenJob(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
30
+ /** Client cancels a recurring job (Open or Complete state only). */
31
+ export declare function cancelRecurring(connection: Connection, wallet: Keypair, jobPda: PublicKey): Promise<string>;
32
+ /** Client sets a new evaluator for the next cycle (lock_evaluator = false only). */
33
+ export declare function updateEvaluator(connection: Connection, wallet: Keypair, jobPda: PublicKey, newEvaluator: PublicKey): Promise<string>;
34
+ //# sourceMappingURL=sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAA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B,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,oEAAoE;AACpE,wBAAsB,eAAe,CACnC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,MAAM,CAAC,CAajB;AAED,oFAAoF;AACpF,wBAAsB,eAAe,CACnC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,MAAM,CAAC,CAajB"}
package/dist/sdk.js ADDED
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.PROGRAM_ID = void 0;
40
+ exports.findGlobalStatePda = findGlobalStatePda;
41
+ exports.findJobPda = findJobPda;
42
+ exports.findCyclePda = findCyclePda;
43
+ exports.getProgram = getProgram;
44
+ exports.getAllJobs = getAllJobs;
45
+ exports.initializeGlobalState = initializeGlobalState;
46
+ exports.createJob = createJob;
47
+ exports.fundJob = fundJob;
48
+ exports.acceptEvaluator = acceptEvaluator;
49
+ exports.proposeEvaluator = proposeEvaluator;
50
+ exports.clientAcceptEvaluator = clientAcceptEvaluator;
51
+ exports.clientRejectEvaluator = clientRejectEvaluator;
52
+ exports.submitResult = submitResult;
53
+ exports.approveJob = approveJob;
54
+ exports.rejectJob = rejectJob;
55
+ exports.expireJob = expireJob;
56
+ exports.reopenJob = reopenJob;
57
+ exports.cancelRecurring = cancelRecurring;
58
+ exports.updateEvaluator = updateEvaluator;
59
+ const anchor = __importStar(require("@coral-xyz/anchor"));
60
+ const web3_js_1 = require("@solana/web3.js");
61
+ const en_solana_json_1 = __importDefault(require("./idl/en_solana.json"));
62
+ exports.PROGRAM_ID = new web3_js_1.PublicKey(en_solana_json_1.default.address);
63
+ const GLOBAL_STATE_SEED = Buffer.from("global_state");
64
+ const JOB_SEED = Buffer.from("job");
65
+ const CYCLE_SEED = Buffer.from("cycle");
66
+ function findGlobalStatePda() {
67
+ return web3_js_1.PublicKey.findProgramAddressSync([GLOBAL_STATE_SEED], exports.PROGRAM_ID);
68
+ }
69
+ function findJobPda(client, jobId) {
70
+ return web3_js_1.PublicKey.findProgramAddressSync([JOB_SEED, client.toBuffer(), jobId.toArrayLike(Buffer, "le", 8)], exports.PROGRAM_ID);
71
+ }
72
+ function findCyclePda(jobPda, cycleNumber) {
73
+ const buf = Buffer.alloc(8);
74
+ buf.writeBigUInt64LE(typeof cycleNumber === "number"
75
+ ? BigInt(cycleNumber)
76
+ : BigInt(cycleNumber.toString()));
77
+ return web3_js_1.PublicKey.findProgramAddressSync([CYCLE_SEED, jobPda.toBuffer(), buf], exports.PROGRAM_ID);
78
+ }
79
+ function getProgram(connection, wallet) {
80
+ const provider = new anchor.AnchorProvider(connection, new anchor.Wallet(wallet), { commitment: "confirmed" });
81
+ return new anchor.Program(en_solana_json_1.default, provider);
82
+ }
83
+ async function getAllJobs(connection, wallet) {
84
+ const program = getProgram(connection, wallet);
85
+ return program.account.job.all();
86
+ }
87
+ async function initializeGlobalState(connection, wallet) {
88
+ const program = getProgram(connection, wallet);
89
+ const [globalStatePda] = findGlobalStatePda();
90
+ const tx = await program.methods
91
+ .initialize()
92
+ .accountsStrict({
93
+ globalState: globalStatePda,
94
+ authority: wallet.publicKey,
95
+ systemProgram: web3_js_1.SystemProgram.programId,
96
+ })
97
+ .signers([wallet])
98
+ .rpc();
99
+ return tx;
100
+ }
101
+ async function createJob(connection, wallet, task, amountSol, evaluator, expirySeconds = 300, bilateralEvaluator = false, recurrenceInterval = new anchor.BN(0), lockProvider = false, lockEvaluator = false) {
102
+ const program = getProgram(connection, wallet);
103
+ const [globalStatePda] = findGlobalStatePda();
104
+ const globalState = await program.account.globalState.fetch(globalStatePda);
105
+ const jobId = new anchor.BN(globalState.jobCounter.toString());
106
+ const [jobPda] = findJobPda(wallet.publicKey, jobId);
107
+ const amountLamports = new anchor.BN(Math.round(amountSol * web3_js_1.LAMPORTS_PER_SOL));
108
+ const now = Math.floor(Date.now() / 1000);
109
+ const expiry = new anchor.BN(now + expirySeconds);
110
+ const createIx = await program.methods
111
+ .createJob(task, amountLamports, evaluator, expiry, bilateralEvaluator, recurrenceInterval, lockProvider, lockEvaluator)
112
+ .accountsStrict({
113
+ globalState: globalStatePda,
114
+ job: jobPda,
115
+ client: wallet.publicKey,
116
+ systemProgram: web3_js_1.SystemProgram.programId,
117
+ })
118
+ .instruction();
119
+ // Only fund immediately if bilateral agreement is not required
120
+ if (!bilateralEvaluator) {
121
+ const fundIx = await program.methods
122
+ .fund()
123
+ .accountsStrict({
124
+ job: jobPda,
125
+ client: wallet.publicKey,
126
+ systemProgram: web3_js_1.SystemProgram.programId,
127
+ })
128
+ .instruction();
129
+ const latestBlockhash = await connection.getLatestBlockhash();
130
+ const tx = new anchor.web3.Transaction().add(createIx, fundIx);
131
+ tx.feePayer = wallet.publicKey;
132
+ tx.recentBlockhash = latestBlockhash.blockhash;
133
+ tx.sign(wallet);
134
+ const txSig = await connection.sendRawTransaction(tx.serialize());
135
+ await connection.confirmTransaction({ signature: txSig, ...latestBlockhash }, "confirmed");
136
+ return { txSig, jobPda, jobId };
137
+ }
138
+ // Bilateral: create only, provider must agree before client can fund
139
+ const latestBlockhash = await connection.getLatestBlockhash();
140
+ const tx = new anchor.web3.Transaction().add(createIx);
141
+ tx.feePayer = wallet.publicKey;
142
+ tx.recentBlockhash = latestBlockhash.blockhash;
143
+ tx.sign(wallet);
144
+ const txSig = await connection.sendRawTransaction(tx.serialize());
145
+ await connection.confirmTransaction({ signature: txSig, ...latestBlockhash }, "confirmed");
146
+ return { txSig, jobPda, jobId };
147
+ }
148
+ async function fundJob(connection, wallet, jobPda) {
149
+ const program = getProgram(connection, wallet);
150
+ const tx = await program.methods
151
+ .fund()
152
+ .accountsStrict({
153
+ job: jobPda,
154
+ client: wallet.publicKey,
155
+ systemProgram: web3_js_1.SystemProgram.programId,
156
+ })
157
+ .signers([wallet])
158
+ .rpc();
159
+ return tx;
160
+ }
161
+ // ── Bilateral evaluator negotiation ──────────────────────────────────────────
162
+ /** Provider accepts the client's proposed evaluator. Allows client to fund(). */
163
+ async function acceptEvaluator(connection, wallet, jobPda) {
164
+ const program = getProgram(connection, wallet);
165
+ const tx = await program.methods
166
+ .acceptEvaluator()
167
+ .accountsStrict({
168
+ job: jobPda,
169
+ provider: wallet.publicKey,
170
+ })
171
+ .signers([wallet])
172
+ .rpc();
173
+ return tx;
174
+ }
175
+ /** Provider counter-proposes a different evaluator. Job moves to Negotiating. */
176
+ async function proposeEvaluator(connection, wallet, jobPda, newEvaluator) {
177
+ const program = getProgram(connection, wallet);
178
+ const tx = await program.methods
179
+ .proposeEvaluator(newEvaluator)
180
+ .accountsStrict({
181
+ job: jobPda,
182
+ provider: wallet.publicKey,
183
+ })
184
+ .signers([wallet])
185
+ .rpc();
186
+ return tx;
187
+ }
188
+ /** Client accepts the provider's counter-proposed evaluator. Job returns to Open. */
189
+ async function clientAcceptEvaluator(connection, wallet, jobPda) {
190
+ const program = getProgram(connection, wallet);
191
+ const tx = await program.methods
192
+ .clientAcceptEvaluator()
193
+ .accountsStrict({
194
+ job: jobPda,
195
+ client: wallet.publicKey,
196
+ })
197
+ .signers([wallet])
198
+ .rpc();
199
+ return tx;
200
+ }
201
+ /** Client rejects the provider's counter-proposal. Job resets to Open for re-negotiation. */
202
+ async function clientRejectEvaluator(connection, wallet, jobPda) {
203
+ const program = getProgram(connection, wallet);
204
+ const tx = await program.methods
205
+ .clientRejectEvaluator()
206
+ .accountsStrict({
207
+ job: jobPda,
208
+ client: wallet.publicKey,
209
+ })
210
+ .signers([wallet])
211
+ .rpc();
212
+ return tx;
213
+ }
214
+ async function submitResult(connection, wallet, jobPda, resultHash) {
215
+ const program = getProgram(connection, wallet);
216
+ const tx = await program.methods
217
+ .submit(resultHash)
218
+ .accountsStrict({
219
+ job: jobPda,
220
+ provider: wallet.publicKey,
221
+ })
222
+ .signers([wallet])
223
+ .rpc();
224
+ return tx;
225
+ }
226
+ async function approveJob(connection, wallet, jobPda) {
227
+ const program = getProgram(connection, wallet);
228
+ const job = await program.account.job.fetch(jobPda);
229
+ const tx = await program.methods
230
+ .complete()
231
+ .accountsStrict({
232
+ job: jobPda,
233
+ evaluator: wallet.publicKey,
234
+ provider: job.provider,
235
+ })
236
+ .signers([wallet])
237
+ .rpc();
238
+ return tx;
239
+ }
240
+ async function rejectJob(connection, wallet, jobPda) {
241
+ const program = getProgram(connection, wallet);
242
+ const job = await program.account.job.fetch(jobPda);
243
+ const tx = await program.methods
244
+ .reject()
245
+ .accountsStrict({
246
+ job: jobPda,
247
+ evaluator: wallet.publicKey,
248
+ client: job.client,
249
+ })
250
+ .signers([wallet])
251
+ .rpc();
252
+ return tx;
253
+ }
254
+ async function expireJob(connection, wallet, jobPda) {
255
+ const program = getProgram(connection, wallet);
256
+ const job = await program.account.job.fetch(jobPda);
257
+ const tx = await program.methods
258
+ .expire()
259
+ .accountsStrict({
260
+ job: jobPda,
261
+ client: job.client,
262
+ caller: wallet.publicKey,
263
+ })
264
+ .signers([wallet])
265
+ .rpc();
266
+ return tx;
267
+ }
268
+ // ── Recurring jobs ────────────────────────────────────────────────────────────
269
+ /** Keeper: reopen a complete recurring job once the interval has elapsed. */
270
+ async function reopenJob(connection, wallet, jobPda) {
271
+ const program = getProgram(connection, wallet);
272
+ const job = await program.account.job.fetch(jobPda);
273
+ const [cyclePda] = findCyclePda(jobPda, job.recurrenceCount);
274
+ const tx = await program.methods
275
+ .reopenJob()
276
+ .accountsStrict({
277
+ job: jobPda,
278
+ cycle: cyclePda,
279
+ caller: wallet.publicKey,
280
+ systemProgram: web3_js_1.SystemProgram.programId,
281
+ })
282
+ .signers([wallet])
283
+ .rpc();
284
+ return tx;
285
+ }
286
+ /** Client cancels a recurring job (Open or Complete state only). */
287
+ async function cancelRecurring(connection, wallet, jobPda) {
288
+ const program = getProgram(connection, wallet);
289
+ const tx = await program.methods
290
+ .cancelRecurring()
291
+ .accountsStrict({
292
+ job: jobPda,
293
+ client: wallet.publicKey,
294
+ })
295
+ .signers([wallet])
296
+ .rpc();
297
+ return tx;
298
+ }
299
+ /** Client sets a new evaluator for the next cycle (lock_evaluator = false only). */
300
+ async function updateEvaluator(connection, wallet, jobPda, newEvaluator) {
301
+ const program = getProgram(connection, wallet);
302
+ const tx = await program.methods
303
+ .updateEvaluator(newEvaluator)
304
+ .accountsStrict({
305
+ job: jobPda,
306
+ client: wallet.publicKey,
307
+ })
308
+ .signers([wallet])
309
+ .rpc();
310
+ return tx;
311
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@dymchenko/en-sdk",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for the En Protocol — trustless agent commerce on Solana",
5
+ "main": "dist/sdk.js",
6
+ "types": "dist/sdk.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./dist/sdk.js",
10
+ "types": "./dist/sdk.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "prepublishOnly": "npm run build",
19
+ "sync-idl": "node -e \"require('fs').copyFileSync('../target/idl/en_solana.json','idl/en_solana.json')\""
20
+ },
21
+ "peerDependencies": {
22
+ "@coral-xyz/anchor": ">=0.30.0",
23
+ "@solana/web3.js": ">=1.90.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^20.0.0",
27
+ "typescript": "^5.3.0"
28
+ },
29
+ "license": "ISC",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/en-protocol/en-solana.git"
33
+ },
34
+ "keywords": [
35
+ "solana",
36
+ "anchor",
37
+ "ai-agent",
38
+ "sdk",
39
+ "en-protocol"
40
+ ]
41
+ }