dkg 0.1.0b6__py3-none-any.whl → 1.1.0__py3-none-any.whl

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.
Files changed (44) hide show
  1. dkg/asset.py +106 -28
  2. dkg/constants.py +18 -10
  3. dkg/data/interfaces/ContentAsset.json +133 -3
  4. dkg/data/interfaces/Paranet.json +821 -0
  5. dkg/data/interfaces/{Identity.json → ParanetIncentivesPoolFactory.json} +67 -86
  6. dkg/data/interfaces/ParanetKnowledgeMinersRegistry.json +919 -0
  7. dkg/data/interfaces/ParanetNeurowebIncentivesPool.json +1102 -0
  8. dkg/data/interfaces/{ServiceAgreementStorageV1.json → ParanetsRegistry.json} +331 -360
  9. dkg/dataclasses.py +28 -8
  10. dkg/exceptions.py +1 -1
  11. dkg/main.py +6 -3
  12. dkg/method.py +55 -39
  13. dkg/module.py +1 -0
  14. dkg/network.py +20 -10
  15. dkg/paranet.py +476 -0
  16. dkg/providers/blockchain.py +57 -26
  17. dkg/types/__init__.py +1 -0
  18. dkg/types/general.py +44 -0
  19. dkg/utils/blockchain_request.py +149 -4
  20. dkg/utils/node_request.py +77 -80
  21. {dkg-0.1.0b6.dist-info → dkg-1.1.0.dist-info}/METADATA +3 -141
  22. dkg-1.1.0.dist-info/NOTICE +9 -0
  23. dkg-1.1.0.dist-info/RECORD +52 -0
  24. {dkg-0.1.0b6.dist-info → dkg-1.1.0.dist-info}/WHEEL +1 -1
  25. dkg/data/interfaces/Assertion.json +0 -157
  26. dkg/data/interfaces/CommitManagerV1.json +0 -549
  27. dkg/data/interfaces/CommitManagerV1U1.json +0 -735
  28. dkg/data/interfaces/HashingProxy.json +0 -253
  29. dkg/data/interfaces/IdentityStorage.json +0 -342
  30. dkg/data/interfaces/ParametersStorage.json +0 -487
  31. dkg/data/interfaces/Profile.json +0 -318
  32. dkg/data/interfaces/ProfileStorage.json +0 -596
  33. dkg/data/interfaces/ProofManagerV1.json +0 -540
  34. dkg/data/interfaces/ProofManagerV1U1.json +0 -561
  35. dkg/data/interfaces/ScoringProxy.json +0 -268
  36. dkg/data/interfaces/ServiceAgreementStorageV1U1.json +0 -1097
  37. dkg/data/interfaces/ServiceAgreementV1.json +0 -745
  38. dkg/data/interfaces/ShardingTable.json +0 -294
  39. dkg/data/interfaces/ShardingTableStorage.json +0 -317
  40. dkg/data/interfaces/Staking.json +0 -482
  41. dkg/data/interfaces/StakingStorage.json +0 -407
  42. dkg/data/interfaces/WhitelistStorage.json +0 -124
  43. dkg-0.1.0b6.dist-info/RECORD +0 -64
  44. {dkg-0.1.0b6.dist-info → dkg-1.1.0.dist-info}/LICENSE +0 -0
dkg/asset.py CHANGED
@@ -34,6 +34,7 @@ from dkg.constants import (
34
34
  PRIVATE_HISTORICAL_REPOSITORY,
35
35
  )
36
36
  from dkg.dataclasses import (
37
+ BidSuggestionRange,
37
38
  KnowledgeAssetContentVisibility,
38
39
  KnowledgeAssetEnumStates,
39
40
  NodeResponseDict,
@@ -68,7 +69,7 @@ from dkg.utils.rdf import format_content, normalize_dataset
68
69
  from dkg.utils.ual import format_ual, parse_ual
69
70
 
70
71
 
71
- class ContentAsset(Module):
72
+ class KnowledgeAsset(Module):
72
73
  def __init__(self, manager: DefaultRequestManager):
73
74
  self.manager = manager
74
75
 
@@ -195,6 +196,7 @@ class ContentAsset(Module):
195
196
 
196
197
  _get_asset_storage_address = Method(BlockchainRequest.get_asset_storage_address)
197
198
  _create = Method(BlockchainRequest.create_asset)
199
+ _mint_paranet_knowledge_asset = Method(BlockchainRequest.mint_knowledge_asset)
198
200
 
199
201
  _get_bid_suggestion = Method(NodeRequest.bid_suggestion)
200
202
  _local_store = Method(NodeRequest.local_store)
@@ -207,6 +209,7 @@ class ContentAsset(Module):
207
209
  token_amount: Wei | None = None,
208
210
  immutable: bool = False,
209
211
  content_type: Literal["JSON-LD", "N-Quads"] = "JSON-LD",
212
+ paranet_ual: UAL | None = None,
210
213
  ) -> dict[str, UAL | HexStr | dict[str, dict[str, str] | TxReceipt]]:
211
214
  blockchain_id = self.manager.blockchain_provider.blockchain_id
212
215
  assertions = format_content(content, content_type)
@@ -230,6 +233,7 @@ class ContentAsset(Module):
230
233
  content_asset_storage_address,
231
234
  public_assertion_id,
232
235
  DEFAULT_HASH_FUNCTION_ID,
236
+ token_amount or BidSuggestionRange.LOW,
233
237
  )["bidSuggestion"]
234
238
  )
235
239
 
@@ -240,20 +244,54 @@ class ContentAsset(Module):
240
244
  result = {"publicAssertionId": public_assertion_id, "operation": {}}
241
245
 
242
246
  try:
243
- receipt: TxReceipt = self._create(
244
- {
245
- "assertionId": Web3.to_bytes(hexstr=public_assertion_id),
246
- "size": public_assertion_metadata["size"],
247
- "triplesNumber": public_assertion_metadata["triples_number"],
248
- "chunksNumber": public_assertion_metadata["chunks_number"],
249
- "tokenAmount": token_amount,
250
- "epochsNumber": epochs_number,
251
- "scoreFunctionId": DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[
252
- self.manager.blockchain_provider.environment
253
- ][blockchain_id],
254
- "immutable_": immutable,
255
- }
256
- )
247
+ if paranet_ual is None:
248
+ receipt: TxReceipt = self._create(
249
+ {
250
+ "assertionId": Web3.to_bytes(hexstr=public_assertion_id),
251
+ "size": public_assertion_metadata["size"],
252
+ "triplesNumber": public_assertion_metadata["triples_number"],
253
+ "chunksNumber": public_assertion_metadata["chunks_number"],
254
+ "tokenAmount": token_amount,
255
+ "epochsNumber": epochs_number,
256
+ "scoreFunctionId": DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[
257
+ self.manager.blockchain_provider.environment
258
+ ][blockchain_id],
259
+ "immutable_": immutable,
260
+ }
261
+ )
262
+ else:
263
+ parsed_paranet_ual = parse_ual(paranet_ual)
264
+ paranet_knowledge_asset_storage, paranet_knowledge_asset_token_id = (
265
+ parsed_paranet_ual["contract_address"],
266
+ parsed_paranet_ual["token_id"],
267
+ )
268
+
269
+ receipt: TxReceipt = self._mint_paranet_knowledge_asset(
270
+ paranet_knowledge_asset_storage,
271
+ paranet_knowledge_asset_token_id,
272
+ {
273
+ "assertionId": Web3.to_bytes(hexstr=public_assertion_id),
274
+ "size": public_assertion_metadata["size"],
275
+ "triplesNumber": public_assertion_metadata["triples_number"],
276
+ "chunksNumber": public_assertion_metadata["chunks_number"],
277
+ "tokenAmount": token_amount,
278
+ "epochsNumber": epochs_number,
279
+ "scoreFunctionId": DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[
280
+ self.manager.blockchain_provider.environment
281
+ ][blockchain_id],
282
+ "immutable_": immutable,
283
+ },
284
+ )
285
+
286
+ result["paranetId"] = Web3.to_hex(
287
+ Web3.solidity_keccak(
288
+ ["address", "uint256"],
289
+ [
290
+ paranet_knowledge_asset_storage,
291
+ paranet_knowledge_asset_token_id,
292
+ ],
293
+ )
294
+ )
257
295
  except ContractLogicError as err:
258
296
  if is_allowance_increased:
259
297
  self.decrease_allowance(token_amount)
@@ -278,7 +316,7 @@ class ContentAsset(Module):
278
316
  "tokenId": token_id,
279
317
  "assertionId": public_assertion_id,
280
318
  "assertion": assertions["public"],
281
- "storeType": StoreTypes.TRIPLE.value,
319
+ "storeType": StoreTypes.TRIPLE,
282
320
  }
283
321
  ]
284
322
 
@@ -293,7 +331,7 @@ class ContentAsset(Module):
293
331
  sort_pairs=True,
294
332
  ).root,
295
333
  "assertion": assertions["private"],
296
- "storeType": StoreTypes.TRIPLE.value,
334
+ "storeType": StoreTypes.TRIPLE,
297
335
  }
298
336
  )
299
337
 
@@ -323,6 +361,42 @@ class ContentAsset(Module):
323
361
 
324
362
  return result
325
363
 
364
+ _submit_knowledge_asset = Method(BlockchainRequest.submit_knowledge_asset)
365
+
366
+ def submit_to_paranet(
367
+ self, ual: UAL, paranet_ual: UAL
368
+ ) -> dict[str, UAL | Address | TxReceipt]:
369
+ parsed_ual = parse_ual(ual)
370
+ knowledge_asset_storage, knowledge_asset_token_id = (
371
+ parsed_ual["contract_address"],
372
+ parsed_ual["token_id"],
373
+ )
374
+
375
+ parsed_paranet_ual = parse_ual(paranet_ual)
376
+ paranet_knowledge_asset_storage, paranet_knowledge_asset_token_id = (
377
+ parsed_paranet_ual["contract_address"],
378
+ parsed_paranet_ual["token_id"],
379
+ )
380
+
381
+ receipt: TxReceipt = self._submit_knowledge_asset(
382
+ paranet_knowledge_asset_storage,
383
+ paranet_knowledge_asset_token_id,
384
+ knowledge_asset_storage,
385
+ knowledge_asset_token_id,
386
+ )
387
+
388
+ return {
389
+ "UAL": ual,
390
+ "paranetUAL": paranet_ual,
391
+ "paranetId": Web3.to_hex(
392
+ Web3.solidity_keccak(
393
+ ["address", "uint256"],
394
+ [knowledge_asset_storage, knowledge_asset_token_id],
395
+ )
396
+ ),
397
+ "operation": json.loads(Web3.to_json(receipt)),
398
+ }
399
+
326
400
  _transfer = Method(BlockchainRequest.transfer_asset)
327
401
 
328
402
  def transfer(
@@ -396,6 +470,7 @@ class ContentAsset(Module):
396
470
  content_asset_storage_address,
397
471
  public_assertion_id,
398
472
  DEFAULT_HASH_FUNCTION_ID,
473
+ token_amount or BidSuggestionRange.LOW,
399
474
  )["bidSuggestion"]
400
475
  )
401
476
 
@@ -427,7 +502,7 @@ class ContentAsset(Module):
427
502
  "tokenId": token_id,
428
503
  "assertionId": public_assertion_id,
429
504
  "assertion": assertions["public"],
430
- "storeType": StoreTypes.PENDING.value,
505
+ "storeType": StoreTypes.PENDING,
431
506
  }
432
507
  ]
433
508
 
@@ -442,7 +517,7 @@ class ContentAsset(Module):
442
517
  sort_pairs=True,
443
518
  ).root,
444
519
  "assertion": assertions["private"],
445
- "storeType": StoreTypes.PENDING.value,
520
+ "storeType": StoreTypes.PENDING,
446
521
  }
447
522
  )
448
523
 
@@ -460,7 +535,7 @@ class ContentAsset(Module):
460
535
  operation_result = self.get_operation_result(operation_id, "update")
461
536
 
462
537
  return {
463
- "UAL": format_ual(blockchain_id, content_asset_storage_address, token_id),
538
+ "UAL": ual,
464
539
  "publicAssertionId": public_assertion_id,
465
540
  "operation": {
466
541
  "operationId": operation_id,
@@ -499,8 +574,8 @@ class ContentAsset(Module):
499
574
  def get(
500
575
  self,
501
576
  ual: UAL,
502
- state: str | HexStr | int = KnowledgeAssetEnumStates.LATEST.value,
503
- content_visibility: str = KnowledgeAssetContentVisibility.ALL.value,
577
+ state: str | HexStr | int = KnowledgeAssetEnumStates.LATEST,
578
+ content_visibility: str = KnowledgeAssetContentVisibility.ALL,
504
579
  output_format: Literal["JSON-LD", "N-Quads"] = "JSON-LD",
505
580
  validate: bool = True,
506
581
  ) -> dict[str, UAL | HexStr | list[JSONLD] | dict[str, str]]:
@@ -528,10 +603,10 @@ class ContentAsset(Module):
528
603
  is_state_finalized = False
529
604
 
530
605
  match state:
531
- case KnowledgeAssetEnumStates.LATEST.value:
606
+ case KnowledgeAssetEnumStates.LATEST:
532
607
  public_assertion_id, is_state_finalized = handle_latest_state(token_id)
533
608
 
534
- case KnowledgeAssetEnumStates.LATEST_FINALIZED.value:
609
+ case KnowledgeAssetEnumStates.LATEST_FINALIZED:
535
610
  public_assertion_id, is_state_finalized = handle_latest_finalized_state(
536
611
  token_id
537
612
  )
@@ -592,7 +667,7 @@ class ContentAsset(Module):
592
667
  )
593
668
 
594
669
  result = {"operation": {}}
595
- if content_visibility != KnowledgeAssetContentVisibility.PRIVATE.value:
670
+ if content_visibility != KnowledgeAssetContentVisibility.PRIVATE:
596
671
  formatted_public_assertion = public_assertion
597
672
 
598
673
  match output_format:
@@ -609,7 +684,7 @@ class ContentAsset(Module):
609
684
  f"{output_format} isn't supported!"
610
685
  )
611
686
 
612
- if content_visibility == KnowledgeAssetContentVisibility.PUBLIC.value:
687
+ if content_visibility == KnowledgeAssetContentVisibility.PUBLIC:
613
688
  result = {
614
689
  **result,
615
690
  "asertion": formatted_public_assertion,
@@ -626,7 +701,7 @@ class ContentAsset(Module):
626
701
  "status": get_public_operation_result["status"],
627
702
  }
628
703
 
629
- if content_visibility != KnowledgeAssetContentVisibility.PUBLIC.value:
704
+ if content_visibility != KnowledgeAssetContentVisibility.PUBLIC:
630
705
  private_assertion_link_triples = list(
631
706
  filter(
632
707
  lambda element: PRIVATE_ASSERTION_PREDICATE in element,
@@ -702,7 +777,7 @@ class ContentAsset(Module):
702
777
  f"{output_format} isn't supported!"
703
778
  )
704
779
 
705
- if content_visibility == KnowledgeAssetContentVisibility.PRIVATE:
780
+ if content_visibility == KnowledgeAssetContentVisibility:
706
781
  result = {
707
782
  **result,
708
783
  "assertion": formatted_private_assertion,
@@ -751,6 +826,7 @@ class ContentAsset(Module):
751
826
  content_asset_storage_address,
752
827
  latest_finalized_state,
753
828
  DEFAULT_HASH_FUNCTION_ID,
829
+ token_amount or BidSuggestionRange.LOW,
754
830
  )["bidSuggestion"]
755
831
  )
756
832
 
@@ -806,6 +882,7 @@ class ContentAsset(Module):
806
882
  content_asset_storage_address,
807
883
  latest_finalized_state,
808
884
  DEFAULT_HASH_FUNCTION_ID,
885
+ token_amount or BidSuggestionRange.LOW,
809
886
  )["bidSuggestion"]
810
887
  ) - sum(agreement_data.tokensInfo)
811
888
 
@@ -863,6 +940,7 @@ class ContentAsset(Module):
863
940
  content_asset_storage_address,
864
941
  unfinalized_state,
865
942
  DEFAULT_HASH_FUNCTION_ID,
943
+ token_amount or BidSuggestionRange.LOW,
866
944
  )["bidSuggestion"]
867
945
  ) - sum(agreement_data.tokensInfo)
868
946
 
dkg/constants.py CHANGED
@@ -29,10 +29,6 @@ BLOCKCHAINS = {
29
29
  "hub": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
30
30
  "rpc": "http://localhost:9545",
31
31
  },
32
- "otp:2043": {
33
- "hub": "0x7585a99C5C150a08f5CDeFD16465C6De8D41EbbD",
34
- "rpc": "http://parachain-alphanet-02.origin-trail.network:9933",
35
- },
36
32
  },
37
33
  "devnet": {
38
34
  "otp:2160": {
@@ -44,6 +40,10 @@ BLOCKCHAINS = {
44
40
  "rpc": "https://rpc.chiadochain.net",
45
41
  "gas_price_oracle": "https://blockscout.chiadochain.net/api/v1/gas-price-oracle",
46
42
  },
43
+ "base:84532": {
44
+ "hub": "0x6C861Cb69300C34DfeF674F7C00E734e840C29C0",
45
+ "rpc": "https://sepolia.base.org",
46
+ }
47
47
  },
48
48
  "testnet": {
49
49
  "otp:20430": {
@@ -55,6 +55,10 @@ BLOCKCHAINS = {
55
55
  "rpc": "https://rpc.chiadochain.net",
56
56
  "gas_price_oracle": "https://blockscout.chiadochain.net/api/v1/gas-price-oracle",
57
57
  },
58
+ "base:84532": {
59
+ "hub": "0x144eDa5cbf8926327cb2cceef168A121F0E4A299",
60
+ "rpc": "https://sepolia.base.org",
61
+ }
58
62
  },
59
63
  "mainnet": {
60
64
  "otp:2043": {
@@ -68,7 +72,11 @@ BLOCKCHAINS = {
68
72
  "https://api.gnosisscan.io/api?module=proxy&action=eth_gasPrice",
69
73
  "https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle",
70
74
  ],
71
- }
75
+ },
76
+ "base:8453": {
77
+ "hub": "0xaBfcf2ad1718828E7D3ec20435b0d0b5EAfbDf2c",
78
+ "rpc": "https://mainnet.base.org",
79
+ },
72
80
  },
73
81
  }
74
82
 
@@ -80,20 +88,20 @@ DEFAULT_GAS_PRICE_GWEI = {
80
88
  DEFAULT_HASH_FUNCTION_ID = 1
81
89
  DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS = {
82
90
  "development": {
83
- "hardhat1:31337": 1,
91
+ "hardhat1:31337": 2,
84
92
  "hardhat2:31337": 2,
85
- "otp:2043": 1
93
+ "otp:2043": 2
86
94
  },
87
95
  "devnet": {
88
- "otp:2160": 1,
96
+ "otp:2160": 2,
89
97
  "gnosis:10200": 2,
90
98
  },
91
99
  "testnet": {
92
- "otp:20430": 1,
100
+ "otp:20430": 2,
93
101
  "gnosis:10200": 2,
94
102
  },
95
103
  "mainnet": {
96
- "otp:2043": 1,
104
+ "otp:2043": 2,
97
105
  "gnosis:100": 2,
98
106
  },
99
107
  }
@@ -344,6 +344,19 @@
344
344
  "stateMutability": "nonpayable",
345
345
  "type": "function"
346
346
  },
347
+ {
348
+ "inputs": [
349
+ {
350
+ "internalType": "uint256",
351
+ "name": "tokenId",
352
+ "type": "uint256"
353
+ }
354
+ ],
355
+ "name": "cancelAssetStateUpdateFromContract",
356
+ "outputs": [],
357
+ "stateMutability": "nonpayable",
358
+ "type": "function"
359
+ },
347
360
  {
348
361
  "inputs": [],
349
362
  "name": "contentAssetStorage",
@@ -408,7 +421,79 @@
408
421
  }
409
422
  ],
410
423
  "name": "createAsset",
411
- "outputs": [],
424
+ "outputs": [
425
+ {
426
+ "internalType": "uint256",
427
+ "name": "",
428
+ "type": "uint256"
429
+ }
430
+ ],
431
+ "stateMutability": "nonpayable",
432
+ "type": "function"
433
+ },
434
+ {
435
+ "inputs": [
436
+ {
437
+ "internalType": "address",
438
+ "name": "originalSender",
439
+ "type": "address"
440
+ },
441
+ {
442
+ "components": [
443
+ {
444
+ "internalType": "bytes32",
445
+ "name": "assertionId",
446
+ "type": "bytes32"
447
+ },
448
+ {
449
+ "internalType": "uint128",
450
+ "name": "size",
451
+ "type": "uint128"
452
+ },
453
+ {
454
+ "internalType": "uint32",
455
+ "name": "triplesNumber",
456
+ "type": "uint32"
457
+ },
458
+ {
459
+ "internalType": "uint96",
460
+ "name": "chunksNumber",
461
+ "type": "uint96"
462
+ },
463
+ {
464
+ "internalType": "uint16",
465
+ "name": "epochsNumber",
466
+ "type": "uint16"
467
+ },
468
+ {
469
+ "internalType": "uint96",
470
+ "name": "tokenAmount",
471
+ "type": "uint96"
472
+ },
473
+ {
474
+ "internalType": "uint8",
475
+ "name": "scoreFunctionId",
476
+ "type": "uint8"
477
+ },
478
+ {
479
+ "internalType": "bool",
480
+ "name": "immutable_",
481
+ "type": "bool"
482
+ }
483
+ ],
484
+ "internalType": "struct ContentAssetStructs.AssetInputArgs",
485
+ "name": "args",
486
+ "type": "tuple"
487
+ }
488
+ ],
489
+ "name": "createAssetFromContract",
490
+ "outputs": [
491
+ {
492
+ "internalType": "uint256",
493
+ "name": "",
494
+ "type": "uint256"
495
+ }
496
+ ],
412
497
  "stateMutability": "nonpayable",
413
498
  "type": "function"
414
499
  },
@@ -456,7 +541,13 @@
456
541
  }
457
542
  ],
458
543
  "name": "createAssetWithVariables",
459
- "outputs": [],
544
+ "outputs": [
545
+ {
546
+ "internalType": "uint256",
547
+ "name": "",
548
+ "type": "uint256"
549
+ }
550
+ ],
460
551
  "stateMutability": "nonpayable",
461
552
  "type": "function"
462
553
  },
@@ -501,7 +592,7 @@
501
592
  "name": "hub",
502
593
  "outputs": [
503
594
  {
504
- "internalType": "contract Hub",
595
+ "internalType": "contract HubV2",
505
596
  "name": "",
506
597
  "type": "address"
507
598
  }
@@ -578,6 +669,45 @@
578
669
  "stateMutability": "view",
579
670
  "type": "function"
580
671
  },
672
+ {
673
+ "inputs": [],
674
+ "name": "paranetKnowledgeAssetsRegistry",
675
+ "outputs": [
676
+ {
677
+ "internalType": "contract ParanetKnowledgeAssetsRegistry",
678
+ "name": "",
679
+ "type": "address"
680
+ }
681
+ ],
682
+ "stateMutability": "view",
683
+ "type": "function"
684
+ },
685
+ {
686
+ "inputs": [],
687
+ "name": "paranetKnowledgeMinersRegistry",
688
+ "outputs": [
689
+ {
690
+ "internalType": "contract ParanetKnowledgeMinersRegistry",
691
+ "name": "",
692
+ "type": "address"
693
+ }
694
+ ],
695
+ "stateMutability": "view",
696
+ "type": "function"
697
+ },
698
+ {
699
+ "inputs": [],
700
+ "name": "paranetsRegistry",
701
+ "outputs": [
702
+ {
703
+ "internalType": "contract ParanetsRegistry",
704
+ "name": "",
705
+ "type": "address"
706
+ }
707
+ ],
708
+ "stateMutability": "view",
709
+ "type": "function"
710
+ },
581
711
  {
582
712
  "inputs": [],
583
713
  "name": "serviceAgreementStorageProxy",