Skip to content

Commit

Permalink
Added check if KA is already part of other Paranet during submission
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar committed May 10, 2024
1 parent 1b6c070 commit 172cacb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
21 changes: 21 additions & 0 deletions abi/Paranet.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "address",
"name": "paranetKnowledgeAssetStorageContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "paranetTokenId",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "paranetId",
"type": "bytes32"
}
],
"name": "KnowledgeAssetIsAPartOfOtherParanet",
"type": "error"
},
{
"inputs": [
{
Expand Down
5 changes: 5 additions & 0 deletions contracts/v2/errors/paranets/ParanetErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ library ParanetErrors {
address knowledgeAssetStorageContract,
uint256 knowledgeAssetTokenId
);
error KnowledgeAssetIsAPartOfOtherParanet(
address paranetKnowledgeAssetStorageContract,
uint256 paranetTokenId,
bytes32 paranetId
);
error NoOperatorRewardAvailable(bytes32 paranetId);
error NoEarnedReward(bytes32 paranetId, address miner);
error TracTargetExceeded(bytes32 paranetId, uint96 tracTarget, uint96 tracRewarded, uint96 tracSpent);
Expand Down
24 changes: 18 additions & 6 deletions contracts/v2/paranets/Paranet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
ParanetKnowledgeMinersRegistry pkmr = paranetKnowledgeMinersRegistry;
ParanetKnowledgeAssetsRegistry pkar = paranetKnowledgeAssetsRegistry;

if (!pr.paranetExists(keccak256(abi.encodePacked(knowledgeAssetStorageContract, paranetKATokenId)))) {
revert ParanetErrors.ParanetDoesntExist(knowledgeAssetStorageContract, paranetKATokenId);
if (!pr.paranetExists(keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)))) {
revert ParanetErrors.ParanetDoesntExist(paranetKAStorageContract, paranetKATokenId);
}

if (IERC721(knowledgeAssetStorageContract).ownerOf(knowledgeAssetTokenId) != msg.sender) {
Expand All @@ -572,6 +572,18 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
);
}

if (
pkar.isParanetKnowledgeAsset(
keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId))
)
) {
revert ParanetErrors.KnowledgeAssetIsAPartOfOtherParanet(
knowledgeAssetStorageContract,
knowledgeAssetTokenId,
pkar.getParanetId(keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId)))
);
}

uint96 remainingTokenAmount = serviceAgreementStorageProxy.getAgreementTokenAmount(
hashingProxy.callHashFunction(
HASH_FUNCTION_ID,
Expand All @@ -596,7 +608,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
// Add Knowledge Asset to the KnowledgeAssetsRegistry
pkar.addKnowledgeAsset(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
address(contentAssetStorage),
knowledgeAssetStorageContract,
knowledgeAssetTokenId,
msg.sender,
bytes("")
Expand All @@ -605,7 +617,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
// Add Knowledge Asset Metadata to the ParanetsRegistry
pr.addKnowledgeAsset(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
keccak256(abi.encodePacked(address(contentAssetStorage), knowledgeAssetTokenId))
keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId))
);
pr.addCumulativeKnowledgeValue(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
Expand All @@ -616,7 +628,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
pkmr.addSubmittedKnowledgeAsset(
msg.sender,
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
keccak256(abi.encodePacked(address(contentAssetStorage), knowledgeAssetTokenId))
keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId))
);
pkmr.addCumulativeTracSpent(
msg.sender,
Expand All @@ -629,7 +641,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
emit KnowledgeAssetSubmittedToParanet(
paranetKAStorageContract,
paranetKATokenId,
address(contentAssetStorage),
knowledgeAssetStorageContract,
knowledgeAssetTokenId
);
}
Expand Down

0 comments on commit 172cacb

Please sign in to comment.