diff --git a/abi/KnowledgeCollection.json b/abi/KnowledgeCollection.json index 118ccd20..8b27268a 100644 --- a/abi/KnowledgeCollection.json +++ b/abi/KnowledgeCollection.json @@ -397,6 +397,45 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "paranetKnowledgeAssetsRegistry", + "outputs": [ + { + "internalType": "contract ParanetKnowledgeAssetsRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "paranetKnowledgeMinersRegistry", + "outputs": [ + { + "internalType": "contract ParanetKnowledgeMinersRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "paranetsRegistry", + "outputs": [ + { + "internalType": "contract ParanetsRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "shardingTableStorage", diff --git a/abi/Paranet.json b/abi/Paranet.json index a36ed8e3..4559f8c2 100644 --- a/abi/Paranet.json +++ b/abi/Paranet.json @@ -994,6 +994,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "knowledgeCollectionStorage", + "outputs": [ + { + "internalType": "contract KnowledgeCollectionStorage", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { diff --git a/contracts/v1/KnowledgeCollection.sol b/contracts/v1/KnowledgeCollection.sol index 28bd1ca9..5ed24a24 100644 --- a/contracts/v1/KnowledgeCollection.sol +++ b/contracts/v1/KnowledgeCollection.sol @@ -7,6 +7,9 @@ import {KnowledgeCollectionStorage} from "./storage/KnowledgeCollectionStorage.s import {ShardingTableStorage} from "./storage/ShardingTableStorage.sol"; import {IdentityStorage} from "./storage/IdentityStorage.sol"; import {ParametersStorage} from "./storage/ParametersStorage.sol"; +import {ParanetKnowledgeAssetsRegistry} from "../v2/storage/paranets/ParanetKnowledgeAssetsRegistry.sol"; +import {ParanetKnowledgeMinersRegistry} from "../v2/storage/paranets/ParanetKnowledgeMinersRegistry.sol"; +import {ParanetsRegistry} from "../v2/storage/paranets/ParanetsRegistry.sol"; import {KnowledgeCollectionLib} from "./libraries/KnowledgeCollectionLib.sol"; import {TokenLib} from "./libraries/TokenLib.sol"; import {IdentityLib} from "./libraries/IdentityLib.sol"; @@ -26,6 +29,9 @@ contract KnowledgeCollection is Named, Versioned, HubDependent { IERC20 public tokenContract; ParametersStorage public parametersStorage; IdentityStorage public identityStorage; + ParanetKnowledgeAssetsRegistry public paranetKnowledgeAssetsRegistry; + ParanetKnowledgeMinersRegistry public paranetKnowledgeMinersRegistry; + ParanetsRegistry public paranetsRegistry; constructor(address hubAddress) HubDependent(hubAddress) {} @@ -38,6 +44,13 @@ contract KnowledgeCollection is Named, Versioned, HubDependent { tokenContract = IERC20(hub.getContractAddress("Token")); parametersStorage = ParametersStorage(hub.getContractAddress("ParametersStorage")); identityStorage = IdentityStorage(hub.getContractAddress("IdentityStorage")); + paranetKnowledgeAssetsRegistry = ParanetKnowledgeAssetsRegistry( + hub.getContractAddress("ParanetKnowledgeAssetsRegistry") + ); + paranetKnowledgeMinersRegistry = ParanetKnowledgeMinersRegistry( + hub.getContractAddress("ParanetKnowledgeMinersRegistry") + ); + paranetsRegistry = ParanetsRegistry(hub.getContractAddress("ParanetsRegistry")); } function name() public pure virtual returns (string memory) { @@ -95,6 +108,7 @@ contract KnowledgeCollection is Named, Versioned, HubDependent { _addTokens(tokenAmount, paymaster); } + //TODO: If KC part of paranet update function updateKnowledgeCollection( uint256 id, string calldata updateOperationId, @@ -179,6 +193,22 @@ contract KnowledgeCollection is Named, Versioned, HubDependent { _validateTokenAmount(byteSize, epochs, tokenAmount, false); _addTokens(tokenAmount, paymaster); + + ParanetKnowledgeAssetsRegistry pkar = paranetKnowledgeAssetsRegistry; + address knowledgeCollectionStorageAddress = address(kcs); + if (pkar.isParanetKnowledgeAsset(keccak256(abi.encodePacked(knowledgeCollectionStorageAddress, id)))) { + ParanetKnowledgeMinersRegistry pkmr = paranetKnowledgeMinersRegistry; + + bytes32 paranetId = pkar.getParanetId(keccak256(abi.encodePacked(knowledgeCollectionStorageAddress, id))); + + // Add Knowledge Asset Token Amount Metadata to the ParanetsRegistry + paranetsRegistry.addCumulativeKnowledgeValue(paranetId, tokenAmount); + + // Add Knowledge Asset Token Amount Metadata to the KnowledgeMinersRegistry + pkmr.addCumulativeTracSpent(msg.sender, paranetId, tokenAmount); + pkmr.addUnrewardedTracSpent(msg.sender, paranetId, tokenAmount); + pkmr.addTotalTracSpent(msg.sender, tokenAmount); + } } function increaseKnowledgeCollectionTokenAmount(uint256 id, uint96 tokenAmount, address paymaster) external { @@ -197,6 +227,23 @@ contract KnowledgeCollection is Named, Versioned, HubDependent { kcs.setTokenAmount(id, oldTokenAmount + tokenAmount); _addTokens(tokenAmount, paymaster); + + ParanetKnowledgeAssetsRegistry pkar = paranetKnowledgeAssetsRegistry; + address knowledgeCollectionStorageAddress = address(kcs); + if (pkar.isParanetKnowledgeAsset(keccak256(abi.encodePacked(knowledgeCollectionStorageAddress, id)))) { + ParanetKnowledgeMinersRegistry pkmr = paranetKnowledgeMinersRegistry; + + bytes32 paranetId = pkar.getParanetId(keccak256(abi.encodePacked(knowledgeCollectionStorageAddress, id))); + + // Add Knowledge Asset Token Amount Metadata to the ParanetsRegistry + paranetsRegistry.addCumulativeKnowledgeValue(paranetId, tokenAmount); + + // Add Knowledge Asset Token Amount Metadata to the KnowledgeMinersRegistry + // Question is there some problem when paymaster is used ??? + pkmr.addCumulativeTracSpent(msg.sender, paranetId, tokenAmount); + pkmr.addUnrewardedTracSpent(msg.sender, paranetId, tokenAmount); + pkmr.addTotalTracSpent(msg.sender, tokenAmount); + } } function _verifySignatures( diff --git a/contracts/v2/paranets/Paranet.sol b/contracts/v2/paranets/Paranet.sol index 13f56723..b1ba2577 100644 --- a/contracts/v2/paranets/Paranet.sol +++ b/contracts/v2/paranets/Paranet.sol @@ -11,6 +11,7 @@ import {ParanetsRegistry} from "../storage/paranets/ParanetsRegistry.sol"; import {ParanetServicesRegistry} from "../storage/paranets/ParanetServicesRegistry.sol"; import {ProfileStorage} from "../../v1/storage/ProfileStorage.sol"; import {ServiceAgreementStorageProxy} from "../../v1/storage/ServiceAgreementStorageProxy.sol"; +import {KnowledgeCollectionStorage} from "../../v1/storage/KnowledgeCollectionStorage.sol"; import {IdentityStorage} from "../storage/IdentityStorage.sol"; import {HashingProxy} from "../../v1/HashingProxy.sol"; import {ContractStatusV2} from "../abstract/ContractStatus.sol"; @@ -22,6 +23,7 @@ import {ParanetStructs} from "../structs/paranets/ParanetStructs.sol"; import {ParanetErrors} from "../errors/paranets/ParanetErrors.sol"; import {ProfileErrors} from "../../v1/errors/ProfileErrors.sol"; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; +import {ERC1155Delta} from "../../v1/tokens/ERC1155Delta.sol"; import {HASH_FUNCTION_ID} from "../../v1/constants/assets/ContentAssetConstants.sol"; contract Paranet is Named, Versioned, ContractStatusV2, Initializable { @@ -123,7 +125,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { ); string private constant _NAME = "Paranet"; - string private constant _VERSION = "2.2.1"; + string private constant _VERSION = "2.3.0"; ParanetsRegistry public paranetsRegistry; ParanetServicesRegistry public paranetServicesRegistry; @@ -135,6 +137,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { ContentAssetV2 public contentAsset; HashingProxy public hashingProxy; ServiceAgreementStorageProxy public serviceAgreementStorageProxy; + KnowledgeCollectionStorage public knowledgeCollectionStorage; // solhint-disable-next-line no-empty-blocks constructor(address hubAddress) ContractStatusV2(hubAddress) {} @@ -161,6 +164,9 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { serviceAgreementStorageProxy = ServiceAgreementStorageProxy( hub.getContractAddress("ServiceAgreementStorageProxy") ); + knowledgeCollectionStorage = KnowledgeCollectionStorage( + hub.getAssetStorageAddress("KnowledgeCollectionStorage") + ); } function name() external pure virtual override returns (string memory) { @@ -927,20 +933,28 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { ) ); } - - uint96 remainingTokenAmount = serviceAgreementStorageProxy.getAgreementTokenAmount( - hashingProxy.callHashFunction( - HASH_FUNCTION_ID, - abi.encodePacked( - address(contentAssetStorage), - knowledgeAssetTokenId, + // This needs to have separet logiic for new and old assets + uint96 remainingTokenAmount = 0; + try ERC1155Delta(knowledgeAssetStorageContract).isOwnerOf(msg.sender, knowledgeAssetTokenId) returns ( + bool isOwner + ) { + KnowledgeCollectionStorage kcs = KnowledgeCollectionStorage(knowledgeAssetStorageContract); + remainingTokenAmount = kcs.getTokenAmount(knowledgeAssetTokenId); + } catch { + remainingTokenAmount = serviceAgreementStorageProxy.getAgreementTokenAmount( + hashingProxy.callHashFunction( + HASH_FUNCTION_ID, abi.encodePacked( address(contentAssetStorage), - contentAssetStorage.getAssertionIdByIndex(knowledgeAssetTokenId, 0) + knowledgeAssetTokenId, + abi.encodePacked( + address(contentAssetStorage), + contentAssetStorage.getAssertionIdByIndex(knowledgeAssetTokenId, 0) + ) ) ) - ) - ); + ); + } _updateSubmittedKnowledgeAssetMetadata( paranetKAStorageContract, @@ -1107,9 +1121,17 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { uint256 knowledgeAssetTokenId ) internal view virtual { require(hub.isAssetStorage(knowledgeAssetStorageContract), "Given address isn't KA Storage"); - require( - IERC721(knowledgeAssetStorageContract).ownerOf(knowledgeAssetTokenId) == msg.sender, - "Caller isn't the owner of the KA" - ); + try ERC1155Delta(knowledgeAssetStorageContract).isOwnerOf(msg.sender, knowledgeAssetTokenId) returns ( + bool isOwner + ) { + require(isOwner, "Caller isn't the owner of the KA"); + // TODO: Check for each KA in KC + } catch { + try IERC721(knowledgeAssetStorageContract).ownerOf(knowledgeAssetTokenId) returns (address owner) { + require(owner == msg.sender, "Caller isn't the owner of the KA"); + } catch { + revert("Caller isn't the owner of the KA"); + } + } } -} +} \ No newline at end of file diff --git a/deploy/048_deploy_chronos.ts b/deploy/033_deploy_chronos.ts similarity index 100% rename from deploy/048_deploy_chronos.ts rename to deploy/033_deploy_chronos.ts diff --git a/deploy/049_deploy_knowledge_collection_storage.ts b/deploy/034_deploy_knowledge_collection_storage.ts similarity index 100% rename from deploy/049_deploy_knowledge_collection_storage.ts rename to deploy/034_deploy_knowledge_collection_storage.ts diff --git a/deploy/033_deploy_staking_v2.ts b/deploy/035_deploy_staking_v2.ts similarity index 100% rename from deploy/033_deploy_staking_v2.ts rename to deploy/035_deploy_staking_v2.ts diff --git a/deploy/034_deploy_staking.ts b/deploy/036_deploy_staking.ts similarity index 100% rename from deploy/034_deploy_staking.ts rename to deploy/036_deploy_staking.ts diff --git a/deploy/035_deploy_profile_v2.ts b/deploy/037_deploy_profile_v2.ts similarity index 100% rename from deploy/035_deploy_profile_v2.ts rename to deploy/037_deploy_profile_v2.ts diff --git a/deploy/036_deploy_profile.ts b/deploy/038_deploy_profile.ts similarity index 100% rename from deploy/036_deploy_profile.ts rename to deploy/038_deploy_profile.ts diff --git a/deploy/037_deploy_commit_manager_v2.ts b/deploy/039_deploy_commit_manager_v2.ts similarity index 100% rename from deploy/037_deploy_commit_manager_v2.ts rename to deploy/039_deploy_commit_manager_v2.ts diff --git a/deploy/038_deploy_commit_manager_v1.ts b/deploy/040_deploy_commit_manager_v1.ts similarity index 100% rename from deploy/038_deploy_commit_manager_v1.ts rename to deploy/040_deploy_commit_manager_v1.ts diff --git a/deploy/039_deploy_commit_manager_v2_u1.ts b/deploy/041_deploy_commit_manager_v2_u1.ts similarity index 100% rename from deploy/039_deploy_commit_manager_v2_u1.ts rename to deploy/041_deploy_commit_manager_v2_u1.ts diff --git a/deploy/040_deploy_commit_manager_v1_u1.ts b/deploy/042_deploy_commit_manager_v1_u1.ts similarity index 100% rename from deploy/040_deploy_commit_manager_v1_u1.ts rename to deploy/042_deploy_commit_manager_v1_u1.ts diff --git a/deploy/041_deploy_proof_manager_v1.ts b/deploy/043_deploy_proof_manager_v1.ts similarity index 100% rename from deploy/041_deploy_proof_manager_v1.ts rename to deploy/043_deploy_proof_manager_v1.ts diff --git a/deploy/042_deploy_proof_manager_v1_u1.ts b/deploy/044_deploy_proof_manager_v1_u1.ts similarity index 100% rename from deploy/042_deploy_proof_manager_v1_u1.ts rename to deploy/044_deploy_proof_manager_v1_u1.ts diff --git a/deploy/043_deploy_service_agreement_v1.ts b/deploy/045_deploy_service_agreement_v1.ts similarity index 100% rename from deploy/043_deploy_service_agreement_v1.ts rename to deploy/045_deploy_service_agreement_v1.ts diff --git a/deploy/044_deploy_content_asset_v2.ts b/deploy/046_deploy_content_asset_v2.ts similarity index 100% rename from deploy/044_deploy_content_asset_v2.ts rename to deploy/046_deploy_content_asset_v2.ts diff --git a/deploy/045_deploy_content_asset.ts b/deploy/047_deploy_content_asset.ts similarity index 100% rename from deploy/045_deploy_content_asset.ts rename to deploy/047_deploy_content_asset.ts diff --git a/deploy/046_deploy_paranet.ts b/deploy/048_deploy_paranet.ts similarity index 95% rename from deploy/046_deploy_paranet.ts rename to deploy/048_deploy_paranet.ts index e4f7a633..ea7798d0 100644 --- a/deploy/046_deploy_paranet.ts +++ b/deploy/048_deploy_paranet.ts @@ -21,4 +21,5 @@ func.dependencies = [ 'ProfileStorage', 'ServiceAgreementStorageProxy', 'IdentityStorage', + 'KnowledgeCollectionStorage', ]; diff --git a/deploy/047_deploy_paranet_incentives_pool_factory.ts b/deploy/049_deploy_paranet_incentives_pool_factory.ts similarity index 100% rename from deploy/047_deploy_paranet_incentives_pool_factory.ts rename to deploy/049_deploy_paranet_incentives_pool_factory.ts diff --git a/deploy/050_deploy_knowledge_collection.ts b/deploy/050_deploy_knowledge_collection.ts index 8eb8270d..a0c35df8 100644 --- a/deploy/050_deploy_knowledge_collection.ts +++ b/deploy/050_deploy_knowledge_collection.ts @@ -9,4 +9,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { export default func; func.tags = ['KnowledgeCollection', 'v1', 'v2']; -func.dependencies = []; +func.dependencies = [ + 'Hub', + 'KnowledgeCollectionStorage', + 'Chronos', + 'ShardingTableStorage', + 'Token', + 'ParametersStorage', + 'IdentityStorage', + 'ParanetKnowledgeAssetsRegistry', + 'ParanetKnowledgeMinersRegistry', + 'ParanetsRegistry', +];