-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathcontract-manifest-schema.json
More file actions
867 lines (867 loc) · 25.7 KB
/
Copy pathcontract-manifest-schema.json
File metadata and controls
867 lines (867 loc) · 25.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://grainlify.dev/schemas/contract-manifest.json",
"title": "Smart Contract Metadata Manifest",
"description": "Machine-readable metadata manifest for Grainlify smart contracts",
"type": "object",
"required": ["contract_name", "contract_purpose", "version", "entrypoints", "configuration", "behaviors"],
"properties": {
"error_registry": {
"type": "object",
"description": "Error code registry for this contract. Enables cross-manifest uniqueness validation and SDK generation.",
"properties": {
"codes": {
"type": "array",
"description": "All error codes defined in this contract's error enum, in ascending order.",
"items": {
"$ref": "#/$defs/error_registry_entry"
},
"minItems": 1,
"uniqueItems": true
},
"ranges": {
"type": "array",
"description": "Reserved numeric ranges for this contract's error codes. Must follow established conventions: 1-99 (common), 100-199 (governance), 200-299 (escrow), 300-399 (identity), 400-499 (program_escrow), 1000+ (system).",
"items": {
"$ref": "#/$defs/error_code_range"
},
"minItems": 1
},
"cross_contract_validation": {
"type": "object",
"description": "Cross-contract validation configuration",
"properties": {
"allow_conflicts": {
"type": "boolean",
"description": "Whether conflicts with other contracts are allowed (default: false)",
"default": false
},
"conflict_resolution": {
"type": "string",
"enum": ["error", "warning", "ignore"],
"description": "How to handle cross-contract conflicts",
"default": "warning"
},
"excluded_contracts": {
"type": "array",
"description": "List of contract names to exclude from conflict checking",
"items": {
"type": "string"
}
}
}
}
},
"required": ["codes", "ranges"]
},
"contract_name": {
"type": "string",
"description": "Human-readable name of the smart contract",
"examples": ["BountyEscrowContract", "GrainlifyContract", "ProgramEscrowContract"]
},
"contract_purpose": {
"type": "string",
"description": "Clear description of what the contract does",
"examples": [
"Manages bounty escrow with multi-token support and capability-based authorization",
"Provides secure contract upgrade mechanism with version tracking and migration support",
"Handles hackathon program prize pools with batch payouts and dependency management"
]
},
"version": {
"type": "object",
"description": "Version information for the contract",
"required": ["current", "schema"],
"properties": {
"current": {
"type": "string",
"description": "Current contract version (semantic versioning)",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"schema": {
"type": "string",
"description": "Version of this manifest schema",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"history": {
"type": "array",
"description": "Version history with changelog",
"items": {
"type": "object",
"required": ["version", "release_date", "changes"],
"properties": {
"version": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"release_date": {
"type": "string",
"format": "date"
},
"changes": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
},
"entrypoints": {
"type": "object",
"description": "Contract entrypoints and their specifications",
"required": ["public", "view"],
"properties": {
"public": {
"type": "array",
"description": "State-changing functions that require authentication",
"items": {
"$ref": "#/$defs/entrypoint"
}
},
"view": {
"type": "array",
"description": "Read-only functions that don't require authentication. Includes liveness/health views such as liveness_watchdog() which returns a LivenessStatus snapshot combining pause state, read-only mode, version, and admin presence.",
"items": {
"$ref": "#/$defs/entrypoint"
}
},
"admin": {
"type": "array",
"description": "Admin-only functions",
"items": {
"$ref": "#/$defs/entrypoint"
}
}
}
},
"configuration": {
"type": "object",
"description": "Configuration parameters and their defaults",
"required": ["parameters"],
"properties": {
"parameters": {
"type": "array",
"description": "Configurable parameters",
"items": {
"$ref": "#/$defs/config_parameter"
}
},
"storage_keys": {
"type": "array",
"description": "Important storage keys used by the contract",
"items": {
"$ref": "#/$defs/storage_key"
}
}
}
},
"behaviors": {
"type": "object",
"description": "Critical behaviors and important notes",
"required": ["security_features", "access_control"],
"properties": {
"security_features": {
"type": "array",
"description": "Security mechanisms implemented",
"items": {
"type": "string"
}
},
"access_control": {
"type": "array",
"description": "Access control mechanisms",
"items": {
"$ref": "#/$defs/access_control"
}
},
"critical_behaviors": {
"type": "array",
"description": "Critical behaviors that developers should be aware of",
"items": {
"$ref": "#/$defs/critical_behavior"
}
},
"error_handling": {
"type": "array",
"description": "Common error scenarios and their meanings",
"items": {
"$ref": "#/$defs/error_scenario"
}
},
"gas_considerations": {
"type": "array",
"description": "Gas cost considerations for different operations",
"items": {
"type": "object",
"required": ["operation", "cost_level", "notes"],
"properties": {
"operation": {
"type": "string"
},
"cost_level": {
"type": "string",
"enum": ["low", "medium", "high", "very_high"]
},
"notes": {
"type": "string"
}
}
}
},
"events": {
"type": "array",
"description": "Events emitted by the contract",
"items": {
"$ref": "#/$defs/event"
}
},
"emergency_pause": {
"type": "object",
"description": "Configuration and policy for emergency pause functionality",
"properties": {
"enabled": {
"type": "boolean"
},
"blocks_upgrades": {
"type": "boolean"
}
}
},
"timelocked_upgrades": {
"type": "object",
"description": "Configuration and policy for timelocked upgrades",
"properties": {
"enabled": {
"type": "boolean"
},
"min_delay_seconds": {
"type": "integer"
},
"max_delay_seconds": {
"type": "integer"
}
}
},
"snapshot_rollback": {
"type": "object",
"description": "Configuration and policy for on-chain state snapshots and rollbacks",
"properties": {
"enabled": {
"type": "boolean"
},
"snapshot_limit": {
"type": "integer",
"description": "Maximum number of retained snapshots"
},
"two_step_admin_restore": {
"type": "boolean",
"description": "Whether restoring an admin change requires a two-step confirmation"
},
"blocked_in_read_only": {
"type": "boolean",
"description": "Whether snapshot mutations are blocked when the contract is in read-only mode"
}
}
}
}
},
"dependencies": {
"type": "object",
"description": "External dependencies and integrations",
"properties": {
"contracts": {
"type": "array",
"description": "Other contracts this contract interacts with",
"items": {
"$ref": "#/$defs/contract_dependency"
}
},
"tokens": {
"type": "array",
"description": "Token contracts this contract works with",
"items": {
"$ref": "#/$defs/token_dependency"
}
},
"external_apis": {
"type": "array",
"description": "External APIs or services",
"items": {
"$ref": "#/$defs/external_api"
}
}
}
},
"deployment": {
"type": "object",
"description": "Deployment information",
"properties": {
"networks": {
"type": "array",
"description": "Networks where this contract is deployed",
"items": {
"$ref": "#/$defs/network_deployment"
}
},
"initialization": {
"$ref": "#/$defs/initialization_guide"
},
"upgrade_process": {
"$ref": "#/$defs/upgrade_process"
}
}
},
"testing": {
"type": "object",
"description": "Testing information",
"properties": {
"test_coverage": {
"type": "object",
"description": "Test coverage information",
"properties": {
"unit_tests": {
"type": "string",
"description": "Unit test coverage percentage"
},
"integration_tests": {
"type": "string",
"description": "Integration test coverage percentage"
},
"test_files": {
"type": "array",
"description": "List of test files",
"items": {
"type": "string"
}
}
}
},
"test_scenarios": {
"type": "array",
"description": "Important test scenarios covered",
"items": {
"type": "string"
}
}
}
},
"registry": {
"type": "object",
"description": "Deployed contract registry metadata",
"properties": {
"enabled": {
"type": "boolean",
"description": "Whether the contract maintains a registry of deployed addresses"
},
"max_entries": {
"type": "integer",
"description": "Maximum number of contracts that can be registered"
},
"entrypoint_register": {
"type": "string",
"description": "Entrypoint name for registering a contract"
},
"entrypoint_deregister": {
"type": "string",
"description": "Entrypoint name for deregistering a contract"
},
"entrypoint_list": {
"type": "string",
"description": "Entrypoint name for listing registered contracts"
},
"entrypoint_get": {
"type": "string",
"description": "Entrypoint name for getting a single registered contract"
},
"entrypoint_count": {
"type": "string",
"description": "Entrypoint name for getting the registry count"
}
}
},
"documentation": {
"type": "object",
"description": "Documentation references",
"properties": {
"readme": {
"type": "string",
"description": "Path to README file"
},
"api_docs": {
"type": "string",
"description": "Path to API documentation"
},
"examples": {
"type": "array",
"description": "Example code or tutorials",
"items": {
"type": "string"
}
}
}
}
},
"$defs": {
"entrypoint": {
"type": "object",
"required": ["name", "description", "parameters", "returns"],
"properties": {
"name": {
"type": "string",
"description": "Function name",
"examples": ["init_program", "batch_payout", "liveness_watchdog", "get_liveness_schema_version"]
},
"description": {
"type": "string",
"description": "What the function does"
},
"parameters": {
"type": "array",
"description": "Function parameters",
"items": {
"$ref": "#/$defs/parameter"
}
},
"returns": {
"type": "object",
"description": "Return value specification",
"properties": {
"type": {
"type": "string",
"description": "Return type",
"examples": ["ProgramData", "bool", "u32", "LivenessStatus", "Option<Address>"]
},
"description": {
"type": "string",
"description": "What is returned"
}
}
},
"authorization": {
"type": "string",
"description": "Authorization requirements",
"enum": ["admin", "signer", "any", "none", "capability", "multisig", "admin-or-governor"]
},
"pausable": {
"type": "boolean",
"description": "Whether this function can be paused"
},
"timelocked": {
"type": "boolean",
"description": "Whether this function requires a timelock delay before execution",
"default": false
},
"gas_estimate": {
"type": "string",
"description": "Gas cost estimate",
"enum": ["low", "medium", "high", "very_high"]
}
}
},
"parameter": {
"type": "object",
"required": ["name", "type", "description"],
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"description": {
"type": "string"
},
"optional": {
"type": "boolean",
"default": false
},
"validation": {
"type": "string",
"description": "Validation rules"
}
}
},
"config_parameter": {
"type": "object",
"required": ["name", "type", "default_value", "description"],
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"default_value": {
"description": "Default value for this parameter"
},
"description": {
"type": "string"
},
"constraints": {
"type": "string",
"description": "Constraints or limits on this parameter"
},
"admin_only": {
"type": "boolean",
"default": false
},
"timelock_seconds": {
"type": "integer",
"description": "Required timelock delay in seconds for applying this configuration parameter",
"minimum": 0
},
"requires_proposal": {
"type": "boolean",
"description": "Whether this parameter must be changed via propose/execute governance flow",
"default": false
}
}
},
"storage_key": {
"type": "object",
"required": ["name", "type", "description"],
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["instance", "persistent", "temporary"]
},
"description": {
"type": "string"
},
"data_structure": {
"type": "string",
"description": "Data structure stored at this key"
}
}
},
"access_control": {
"type": "object",
"required": ["mechanism", "description"],
"properties": {
"mechanism": {
"type": "string",
"enum": ["admin_auth", "multisig", "capability", "rbac", "whitelist"]
},
"description": {
"type": "string"
},
"configuration": {
"type": "string",
"description": "How this mechanism is configured"
}
}
},
"critical_behavior": {
"type": "object",
"required": ["behavior", "impact", "mitigation"],
"properties": {
"behavior": {
"type": "string"
},
"impact": {
"type": "string"
},
"mitigation": {
"type": "string"
}
}
},
"error_scenario": {
"type": "object",
"required": ["error_code", "scenario", "resolution"],
"properties": {
"error_code": {
"type": "string"
},
"scenario": {
"type": "string"
},
"resolution": {
"type": "string"
}
}
},
"event": {
"type": "object",
"required": ["name", "description", "data"],
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"event_version": {
"type": "integer",
"description": "Schema version of this event struct. Matches the EVENT_SCHEMA_VERSION constant in the contract source. Consumers must validate this field before deserializing event data to detect cross-version incompatibilities.",
"minimum": 1
},
"min_compatible_version": {
"type": "integer",
"description": "Minimum EVENT_SCHEMA_VERSION value that a consumer can safely deserialize. Useful when a new version adds optional fields that older consumers can ignore.",
"minimum": 1
},
"data": {
"type": "array",
"description": "Event data fields",
"items": {
"type": "object",
"required": ["name", "type"],
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"description": {
"type": "string"
}
}
}
},
"trigger": {
"type": "string",
"description": "When this event is emitted"
},
"topic": {
"type": "array",
"description": "Event topic path as emitted on-chain (e.g. [\"init\", \"build\"])",
"items": {
"type": "string"
}
},
"auth_context": {
"type": "string",
"description": "Authorization context required for the event to be emitted"
},
"security_notes": {
"type": "string",
"description": "Security and audit notes for the event"
}
}
},
"contract_dependency": {
"type": "object",
"required": ["contract_name", "interface"],
"properties": {
"contract_name": {
"type": "string"
},
"interface": {
"type": "string",
"description": "Interface or functions used"
},
"purpose": {
"type": "string",
"description": "Why this dependency is needed"
}
}
},
"token_dependency": {
"type": "object",
"required": ["token_standard", "purpose"],
"properties": {
"token_standard": {
"type": "string",
"enum": ["SAC", "Native", "Custom"]
},
"purpose": {
"type": "string"
},
"requirements": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"external_api": {
"type": "object",
"required": ["name", "purpose"],
"properties": {
"name": {
"type": "string"
},
"purpose": {
"type": "string"
},
"authentication": {
"type": "string"
}
}
},
"network_deployment": {
"type": "object",
"required": ["network", "contract_id"],
"properties": {
"network": {
"type": "string",
"enum": ["mainnet", "testnet", "futurenet", "standalone"]
},
"contract_id": {
"type": "string",
"description": "Contract address on this network"
},
"deployed_at": {
"type": "string",
"format": "date-time"
},
"version": {
"type": "string"
}
}
},
"initialization_guide": {
"type": "object",
"required": ["steps"],
"properties": {
"steps": {
"type": "array",
"items": {
"type": "object",
"required": ["step", "description"],
"properties": {
"step": {
"type": "integer"
},
"description": {
"type": "string"
},
"command": {
"type": "string"
},
"notes": {
"type": "string"
}
}
}
},
"prerequisites": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"upgrade_process": {
"type": "object",
"required": ["steps"],
"properties": {
"steps": {
"type": "array",
"items": {
"type": "object",
"required": ["step", "description"],
"properties": {
"step": {
"type": "integer"
},
"description": {
"type": "string"
},
"command": {
"type": "string"
},
"notes": {
"type": "string"
}
}
}
},
"rollback_procedure": {
"type": "string"
},
"testing_requirements": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"error_registry_entry": {
"type": "object",
"description": "A single error code entry in the registry.",
"required": ["code", "name", "range"],
"properties": {
"code": {
"type": "integer",
"description": "Numeric discriminant used in the #[contracterror] enum. Must be within designated ranges: 1-99 (common), 100-199 (governance), 200-299 (escrow), 300-399 (identity), 400-499 (program_escrow), 1000+ (system).",
"minimum": 1,
"maximum": 9999
},
"name": {
"type": "string",
"description": "Rust variant name (e.g. 'AlreadyInitialized'). Must match the enum variant name exactly.",
"minLength": 1,
"pattern": "^[A-Z][a-zA-Z0-9]*$"
},
"description": {
"type": "string",
"description": "Human-readable explanation of when this error is raised. Should be clear and actionable.",
"minLength": 10
},
"range": {
"type": "string",
"description": "Logical range this code belongs to. Must be one of: common, governance, escrow, identity, program_escrow, system.",
"enum": ["common", "governance", "escrow", "identity", "program_escrow", "system"]
},
"added_in": {
"type": "string",
"description": "Contract version when this code was introduced.",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"deprecated_in": {
"type": "string",
"description": "Contract version when this code was deprecated (if applicable).",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"security_critical": {
"type": "boolean",
"description": "Whether this error indicates a security-critical condition that should be monitored.",
"default": false
}
}
},
"error_code_range": {
"type": "object",
"description": "A reserved numeric range for error codes in this contract. Must follow established range conventions.",
"required": ["name", "min", "max"],
"properties": {
"name": {
"type": "string",
"description": "Logical name of the range. Must be one of: common, governance, escrow, identity, program_escrow, system.",
"enum": ["common", "governance", "escrow", "identity", "program_escrow", "system"]
},
"min": {
"type": "integer",
"description": "Inclusive lower bound. Must align with standard range conventions.",
"minimum": 1
},
"max": {
"type": "integer",
"description": "Inclusive upper bound. Must be greater than or equal to min."
},
"description": {
"type": "string",
"description": "What kinds of errors live in this range.",
"minLength": 10
},
"reserved": {
"type": "boolean",
"description": "Whether this range is reserved for future use (default: false).",
"default": false
}
}
}
}
}