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

Added possibility to mine Paranet KnowledgeAsset for someone #284

Closed
wants to merge 2 commits into from
Closed
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
41 changes: 40 additions & 1 deletion abi/ContentAssetV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@
"name": "PendingUpdateFinalization",
"type": "error"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "paranetId",
"type": "bytes32"
},
{
"internalType": "address",
"name": "claimer",
"type": "address"
}
],
"name": "RewardHasBeenAlreadyClaimed",
"type": "error"
},
{
"inputs": [
{
Expand Down Expand Up @@ -435,7 +451,12 @@
"inputs": [
{
"internalType": "address",
"name": "originalSender",
"name": "minter",
"type": "address"
},
{
"internalType": "address",
"name": "payer",
"type": "address"
},
{
Expand Down Expand Up @@ -734,6 +755,24 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferWithMinerRights",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "unfinalizedStateStorage",
Expand Down
76 changes: 76 additions & 0 deletions abi/Paranet.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,82 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "paranetKAStorageContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "paranetKATokenId",
"type": "uint256"
},
{
"components": [
{
"internalType": "bytes32",
"name": "assertionId",
"type": "bytes32"
},
{
"internalType": "uint128",
"name": "size",
"type": "uint128"
},
{
"internalType": "uint32",
"name": "triplesNumber",
"type": "uint32"
},
{
"internalType": "uint96",
"name": "chunksNumber",
"type": "uint96"
},
{
"internalType": "uint16",
"name": "epochsNumber",
"type": "uint16"
},
{
"internalType": "uint96",
"name": "tokenAmount",
"type": "uint96"
},
{
"internalType": "uint8",
"name": "scoreFunctionId",
"type": "uint8"
},
{
"internalType": "bool",
"name": "immutable_",
"type": "bool"
}
],
"internalType": "struct ContentAssetStructs.AssetInputArgs",
"name": "knowledgeAssetArgs",
"type": "tuple"
},
{
"internalType": "address",
"name": "miner",
"type": "address"
}
],
"name": "mintKnowledgeAssetFor",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
Expand Down
99 changes: 92 additions & 7 deletions contracts/v2/assets/ContentAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Versioned} from "../../v1/interface/Versioned.sol";
import {ContentAssetStructs} from "../../v1/structs/assets/ContentAssetStructs.sol";
import {ServiceAgreementStructsV1} from "../../v1/structs/ServiceAgreementStructsV1.sol";
import {ContentAssetErrors} from "../errors/assets/ContentAssetErrors.sol";
import {ParanetErrors} from "../errors/paranets/ParanetErrors.sol";
import {HASH_FUNCTION_ID} from "../../v1/constants/assets/ContentAssetConstants.sol";
import {LOG2PLDSF_ID, LINEAR_SUM_ID} from "../../v1/constants/ScoringConstants.sol";

Expand Down Expand Up @@ -47,7 +48,7 @@ contract ContentAssetV2 is Named, Versioned, HubDependentV2, Initializable {
event AssetUpdatePaymentIncreased(address indexed assetContract, uint256 indexed tokenId, uint96 tokenAmount);

string private constant _NAME = "ContentAsset";
string private constant _VERSION = "2.1.0";
string private constant _VERSION = "2.2.0";

Assertion public assertionContract;
HashingProxy public hashingProxy;
Expand Down Expand Up @@ -103,6 +104,7 @@ contract ContentAssetV2 is Named, Versioned, HubDependentV2, Initializable {
function createAsset(ContentAssetStructs.AssetInputArgs calldata args) external returns (uint256) {
return
_createAsset(
msg.sender,
msg.sender,
args.assertionId,
args.size,
Expand All @@ -116,12 +118,14 @@ contract ContentAssetV2 is Named, Versioned, HubDependentV2, Initializable {
}

function createAssetFromContract(
address originalSender,
address minter,
address payer,
ContentAssetStructs.AssetInputArgs calldata args
) external onlyContracts returns (uint256) {
return
_createAsset(
originalSender,
minter,
payer,
args.assertionId,
args.size,
args.triplesNumber,
Expand All @@ -145,6 +149,7 @@ contract ContentAssetV2 is Named, Versioned, HubDependentV2, Initializable {
) external returns (uint256) {
return
_createAsset(
msg.sender,
msg.sender,
assertionId,
size,
Expand All @@ -157,6 +162,71 @@ contract ContentAssetV2 is Named, Versioned, HubDependentV2, Initializable {
);
}

function transferWithMinerRights(uint256 tokenId, address newOwner) external onlyAssetOwner(tokenId) {
ContentAssetStorage cas = contentAssetStorage;
ParanetKnowledgeAssetsRegistry pkar = paranetKnowledgeAssetsRegistry;

if (pkar.isParanetKnowledgeAsset(keccak256(abi.encodePacked(cas, tokenId)))) {
ParanetKnowledgeMinersRegistry pkmr = paranetKnowledgeMinersRegistry;

// Check if new owner is has Knowledge Miner profile
// If not: Create a profile
if (!pkmr.knowledgeMinerExists(newOwner)) {
pkmr.registerKnowledgeMiner(newOwner);
}

bytes32 paranetId = pkar.getParanetId(keccak256(abi.encodePacked(address(cas), tokenId)));

// Check if new owner is registered as a Knowledge Miner in the paranet
// If not: Register it
if (!paranetsRegistry.isKnowledgeMinerRegistered(paranetId, newOwner)) {
paranetsRegistry.addKnowledgeMiner(paranetId, newOwner);
}

// Change miner address in the ParanetKnowledgeAssetsRegistry
paranetKnowledgeAssetsRegistry.setMinerAddress(
keccak256(abi.encodePacked(address(cas), tokenId)),
msg.sender
);

// Update Knowledge Asset Metadata in the KnowledgeMinersRegistry
pkmr.removeSubmittedKnowledgeAsset(
msg.sender,
paranetId,
keccak256(abi.encodePacked(address(cas), tokenId))
);
pkmr.addSubmittedKnowledgeAsset(newOwner, paranetId, keccak256(abi.encodePacked(address(cas), tokenId)));

uint96 remainingTokenAmount = serviceAgreementStorageProxy.getAgreementTokenAmount(
hashingProxy.callHashFunction(
HASH_FUNCTION_ID,
abi.encodePacked(
address(cas),
tokenId,
abi.encodePacked(address(cas), cas.getAssertionIdByIndex(tokenId, 0))
)
)
);

if (pkmr.getUnrewardedTracSpent(msg.sender, paranetId) < remainingTokenAmount) {
revert ParanetErrors.RewardHasBeenAlreadyClaimed(paranetId, msg.sender);
}

pkmr.subCumulativeTracSpent(msg.sender, paranetId, remainingTokenAmount);
pkmr.addCumulativeTracSpent(newOwner, paranetId, remainingTokenAmount);
pkmr.subUnrewardedTracSpent(msg.sender, paranetId, remainingTokenAmount);
pkmr.addUnrewardedTracSpent(newOwner, paranetId, remainingTokenAmount);

pkmr.decrementTotalSubmittedKnowledgeAssetsCount(msg.sender);
pkmr.incrementTotalSubmittedKnowledgeAssetsCount(newOwner);

pkmr.subTotalTracSpent(msg.sender, remainingTokenAmount);
pkmr.addTotalTracSpent(newOwner, remainingTokenAmount);
}

cas.safeTransferFrom(msg.sender, newOwner, tokenId);
}

function burnAsset(uint256 tokenId) external onlyAssetOwner(tokenId) {
ContentAssetStorage cas = contentAssetStorage;

Expand Down Expand Up @@ -455,13 +525,28 @@ contract ContentAssetV2 is Named, Versioned, HubDependentV2, Initializable {
revert ContentAssetErrors.AssetExpired(tokenId);
}

ParanetKnowledgeAssetsRegistry pkar = paranetKnowledgeAssetsRegistry;

if (pkar.isParanetKnowledgeAsset(keccak256(abi.encodePacked(contentAssetStorageAddress, tokenId)))) {
bytes32 paranetId = pkar.getParanetId(keccak256(abi.encodePacked(contentAssetStorageAddress, tokenId)));

// Add additional tokenAmount to the UpdatingKnowledgeAssets in the KnowledgeMinersRegistry
paranetKnowledgeMinersRegistry.addUpdatingKnowledgeAssetUpdateTokenAmount(
msg.sender,
paranetId,
keccak256(abi.encodePacked(contentAssetStorageAddress, tokenId, unfinalizedState)),
tokenAmount
);
}

sasV1.addUpdateTokens(msg.sender, agreementId, tokenAmount);

emit AssetUpdatePaymentIncreased(contentAssetStorageAddress, tokenId, tokenAmount);
}

function _createAsset(
address originalSender,
address minter,
address payer,
bytes32 assertionId,
uint128 size,
uint32 triplesNumber,
Expand All @@ -474,18 +559,18 @@ contract ContentAssetV2 is Named, Versioned, HubDependentV2, Initializable {
ContentAssetStorage cas = contentAssetStorage;

uint256 tokenId = cas.generateTokenId();
cas.mint(originalSender, tokenId);
cas.mint(minter, tokenId);

assertionContract.createAssertion(assertionId, size, triplesNumber, chunksNumber);
cas.setAssertionIssuer(tokenId, assertionId, originalSender);
cas.setAssertionIssuer(tokenId, assertionId, minter);
cas.setMutability(tokenId, immutable_);
cas.pushAssertionId(tokenId, assertionId);

address contentAssetStorageAddress = address(cas);

serviceAgreementV1.createServiceAgreement(
ServiceAgreementStructsV1.ServiceAgreementInputArgs({
assetCreator: originalSender,
assetCreator: payer,
assetContract: contentAssetStorageAddress,
tokenId: tokenId,
keyword: abi.encodePacked(contentAssetStorageAddress, assertionId),
Expand Down
1 change: 1 addition & 0 deletions contracts/v2/errors/paranets/ParanetErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ library ParanetErrors {
uint96 currentCumulativeWeight,
uint96 targetCumulativeWeight
);
error RewardHasBeenAlreadyClaimed(bytes32 paranetId, address claimer);
}
Loading
Loading