Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8/paranet to test kc #312

Open
wants to merge 7 commits into
base: test/knowledge-collections
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions abi/KnowledgeCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions abi/Paranet.json
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "knowledgeCollectionStorage",
"outputs": [
{
"internalType": "contract KnowledgeCollectionStorage",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
47 changes: 47 additions & 0 deletions contracts/v1/KnowledgeCollection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {}

Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand Down
54 changes: 38 additions & 16 deletions contracts/v2/paranets/Paranet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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) {}
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ func.dependencies = [
'ProfileStorage',
'ServiceAgreementStorageProxy',
'IdentityStorage',
'KnowledgeCollectionStorage',
];
13 changes: 12 additions & 1 deletion deploy/050_deploy_knowledge_collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];