Skip to content

Commit

Permalink
Separated IncentivesPool deployment function to be in the separate Fa…
Browse files Browse the repository at this point in the history
…ctory contract, updated w2 parameter in the LinearSum for Chiado Testnet
  • Loading branch information
u-hubar committed Jun 14, 2024
1 parent 36088fb commit 447114f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 123 deletions.
65 changes: 0 additions & 65 deletions abi/Paranet.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,6 @@
"name": "ParanetHasAlreadyBeenRegistered",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "knowledgeAssetStorageAddress",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "string",
"name": "poolType",
"type": "string"
},
{
"internalType": "address",
"name": "poolAddress",
"type": "address"
}
],
"name": "ParanetIncentivesPoolAlreadyExists",
"type": "error"
},
{
"inputs": [
{
Expand Down Expand Up @@ -433,45 +407,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "paranetKAStorageContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "paranetKATokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "tracToNeuroEmissionMultiplier",
"type": "uint256"
},
{
"internalType": "uint16",
"name": "paranetOperatorRewardPercentage",
"type": "uint16"
},
{
"internalType": "uint16",
"name": "paranetIncentivizationProposalVotersRewardPercentage",
"type": "uint16"
}
],
"name": "deployNeuroIncentivesPool",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "hashingProxy",
Expand Down
53 changes: 0 additions & 53 deletions contracts/v2/paranets/Paranet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {ParanetKnowledgeAssetsRegistry} from "../storage/paranets/ParanetKnowled
import {ParanetKnowledgeMinersRegistry} from "../storage/paranets/ParanetKnowledgeMinersRegistry.sol";
import {ParanetsRegistry} from "../storage/paranets/ParanetsRegistry.sol";
import {ParanetServicesRegistry} from "../storage/paranets/ParanetServicesRegistry.sol";
import {ParanetNeuroIncentivesPool} from "./ParanetNeuroIncentivesPool.sol";
import {ServiceAgreementStorageProxy} from "../../v1/storage/ServiceAgreementStorageProxy.sol";
import {HashingProxy} from "../../v1/HashingProxy.sol";
import {ContractStatusV2} from "../abstract/ContractStatus.sol";
Expand Down Expand Up @@ -129,58 +128,6 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable {
return pr.registerParanet(paranetKAStorageContract, paranetKATokenId, paranetName, paranetDescription);
}

function deployNeuroIncentivesPool(
address paranetKAStorageContract,
uint256 paranetKATokenId,
uint256 tracToNeuroEmissionMultiplier,
uint16 paranetOperatorRewardPercentage,
uint16 paranetIncentivizationProposalVotersRewardPercentage
) external onlyKnowledgeAssetOwner(paranetKAStorageContract, paranetKATokenId) returns (address) {
HubV2 h = hub;
ParanetsRegistry pr = paranetsRegistry;

if (
pr.hasIncentivesPoolByType(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
"Neuroweb"
)
) {
revert ParanetErrors.ParanetIncentivesPoolAlreadyExists(
paranetKAStorageContract,
paranetKATokenId,
"Neuroweb",
pr.getIncentivesPoolAddress(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
"Neuroweb"
)
);
}

ParanetNeuroIncentivesPool incentivesPool = new ParanetNeuroIncentivesPool(
address(h),
h.getContractAddress("ParanetsRegistry"),
h.getContractAddress("ParanetKnowledgeMinersRegistry"),
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
tracToNeuroEmissionMultiplier,
paranetOperatorRewardPercentage,
paranetIncentivizationProposalVotersRewardPercentage
);

pr.setIncentivesPoolAddress(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
"Neuroweb",
address(incentivesPool)
);

emit ParanetIncetivesPoolDeployed(
paranetKAStorageContract,
paranetKATokenId,
ParanetStructs.IncentivesPool({poolType: "Neuroweb", addr: address(incentivesPool)})
);

return address(incentivesPool);
}

function updateParanetMetadata(
address paranetKAStorageContract,
uint256 paranetKATokenId,
Expand Down
16 changes: 16 additions & 0 deletions deploy/046_deploy_paranet_incentives_pool_factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
if (!hre.network.name.startsWith('otp') && !hre.network.name.startsWith('hardhat')) {
return;
}

await hre.helpers.deploy({
newContractName: 'ParanetIncentivesPoolFactory',
});
};

export default func;
func.tags = ['ParanetIncentivesPoolFactory', 'v2'];
func.dependencies = ['HubV2', 'ParanetsRegistry'];
3 changes: 3 additions & 0 deletions deployments/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@
"setterArgs": [5, false]
}
]
},
"LinearSum": {
"w2": "50"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Named from './abi/Named.json';
import NodeOperatorFeesStorage from './abi/NodeOperatorFeesStorage.json';
import ParametersStorage from './abi/ParametersStorage.json';
import Paranet from './abi/Paranet.json';
import ParanetIncentivesPoolFactory from './abi/ParanetIncentivesPoolFactory.json';
import ParanetKnowledgeAssetsRegistry from './abi/ParanetKnowledgeAssetsRegistry.json';
import ParanetKnowledgeMinersRegistry from './abi/ParanetKnowledgeMinersRegistry.json';
import ParanetNeuroIncentivesPool from './abi/ParanetNeuroIncentivesPool.json';
Expand Down Expand Up @@ -113,6 +114,7 @@ const ABIV2 = {
LinearSum,
NodeOperatorFeesStorage,
Paranet,
ParanetIncentivesPoolFactory,
ParanetKnowledgeAssetsRegistry,
ParanetKnowledgeMinersRegistry,
ParanetServicesRegistry,
Expand Down Expand Up @@ -151,6 +153,7 @@ export {
Log2PLDSF as Log2PLDSFABI,
NodeOperatorFeesStorage as NodeOperatorFeesStorageABI,
Paranet as ParanetABI,
ParanetIncentivesPoolFactory as ParanetIncentivesPoolFactoryABI,
ParanetKnowledgeAssetsRegistry as ParanetKnowledgeAssetsRegistryABI,
ParanetKnowledgeMinersRegistry as ParanetKnowledgeMinersRegistryABI,
ParanetServicesRegistry as ParanetServicesRegistryABI,
Expand Down
11 changes: 10 additions & 1 deletion test/v2/integration/Paranet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ServiceAgreementV1,
ContentAssetStorageV2,
Token,
ParanetIncentivesPoolFactory,
} from '../../../typechain';
import { ContentAssetStructs } from '../../../typechain/contracts/v2/assets/ContentAsset.sol/ContentAssetV2';

Expand All @@ -28,6 +29,7 @@ type ParanetNeuroIncentivesPoolFixture = {
ParanetKnowledgeMinersRegistry: ParanetKnowledgeMinersRegistry;
ParanetsRegistry: ParanetsRegistry;
Paranet: Paranet;
ParanetIncentivesPoolFactory: ParanetIncentivesPoolFactory;
};

describe('@v2 @integration Paranet', function () {
Expand All @@ -42,6 +44,7 @@ describe('@v2 @integration Paranet', function () {
let ParanetKnowledgeMinersRegistry: ParanetKnowledgeMinersRegistry;
let ParanetsRegistry: ParanetsRegistry;
let Paranet: Paranet;
let ParanetIncentivesPoolFactory: ParanetIncentivesPoolFactory;

async function deployParanetNeuroIncentivesPoolFixture(): Promise<ParanetNeuroIncentivesPoolFixture> {
await hre.deployments.fixture([
Expand All @@ -50,6 +53,7 @@ describe('@v2 @integration Paranet', function () {
'ContentAssetStorageV2',
'ContentAssetV2',
'Paranet',
'ParanetIncentivesPoolFactory',
]);

ContentAssetStorage = await hre.ethers.getContract<ContentAssetStorageV2>('ContentAssetStorage');
Expand All @@ -62,6 +66,9 @@ describe('@v2 @integration Paranet', function () {
);
ParanetsRegistry = await hre.ethers.getContract<ParanetsRegistry>('ParanetsRegistry');
Paranet = await hre.ethers.getContract<Paranet>('Paranet');
ParanetIncentivesPoolFactory = await hre.ethers.getContract<ParanetIncentivesPoolFactory>(
'ParanetIncentivesPoolFactory',
);

accounts = await hre.ethers.getSigners();

Expand All @@ -77,6 +84,7 @@ describe('@v2 @integration Paranet', function () {
ParanetKnowledgeMinersRegistry,
ParanetsRegistry,
Paranet,
ParanetIncentivesPoolFactory,
};
}

Expand Down Expand Up @@ -114,7 +122,7 @@ describe('@v2 @integration Paranet', function () {
);
await tx1.wait();

const tx2 = await Paranet.connect(operator).deployNeuroIncentivesPool(
const tx2 = await ParanetIncentivesPoolFactory.connect(operator).deployNeuroIncentivesPool(
ContentAssetStorage.address,
paranetKATokenId,
tracToNeuroEmissionMultiplier,
Expand Down Expand Up @@ -145,6 +153,7 @@ describe('@v2 @integration Paranet', function () {
ParanetKnowledgeMinersRegistry,
ParanetsRegistry,
Paranet,
ParanetIncentivesPoolFactory,
} = await loadFixture(deployParanetNeuroIncentivesPoolFixture));

operator = accounts[1];
Expand Down
16 changes: 12 additions & 4 deletions test/v2/unit/Paranet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ParanetNeuroIncentivesPool,
Token,
ServiceAgreementV1,
ParanetIncentivesPoolFactory,
} from '../../../typechain';
import { ParanetStructs } from '../../../typechain/contracts/v2/paranets/Paranet';

Expand All @@ -30,6 +31,7 @@ type deployParanetFixture = {
ParanetServicesRegistry: ParanetServicesRegistry;
ParanetKnowledgeMinersRegistry: ParanetKnowledgeMinersRegistry;
ParanetKnowledgeAssetsRegistry: ParanetKnowledgeAssetsRegistry;
ParanetIncentivesPoolFactory: ParanetIncentivesPoolFactory;
HashingProxy: HashingProxy;
ServiceAgreementStorageProxy: ServiceAgreementStorageProxy;
Token: Token;
Expand All @@ -46,6 +48,7 @@ describe('@v2 @unit ParanetKnowledgeMinersRegistry contract', function () {
let ParanetServicesRegistry: ParanetServicesRegistry;
let ParanetKnowledgeMinersRegistry: ParanetKnowledgeMinersRegistry;
let ParanetKnowledgeAssetsRegistry: ParanetKnowledgeAssetsRegistry;
let ParanetIncentivesPoolFactory: ParanetIncentivesPoolFactory;
let HashingProxy: HashingProxy;
let ServiceAgreementStorageProxy: ServiceAgreementStorageProxy;
let Token: Token;
Expand All @@ -63,6 +66,7 @@ describe('@v2 @unit ParanetKnowledgeMinersRegistry contract', function () {
'ParanetServicesRegistry',
'ParanetKnowledgeMinersRegistry',
'ParanetKnowledgeAssetsRegistry',
'ParanetIncentivesPoolFactory',
'HashingProxy',
'ServiceAgreementStorageProxy',
'Token',
Expand All @@ -83,6 +87,9 @@ describe('@v2 @unit ParanetKnowledgeMinersRegistry contract', function () {
ParanetKnowledgeAssetsRegistry = await hre.ethers.getContract<ParanetKnowledgeAssetsRegistry>(
'ParanetKnowledgeAssetsRegistry',
);
ParanetIncentivesPoolFactory = await hre.ethers.getContract<ParanetIncentivesPoolFactory>(
'ParanetIncentivesPoolFactory',
);
ServiceAgreementStorageProxy = await hre.ethers.getContract<ServiceAgreementStorageProxy>(
'ServiceAgreementStorageProxy',
);
Expand All @@ -103,6 +110,7 @@ describe('@v2 @unit ParanetKnowledgeMinersRegistry contract', function () {
ParanetServicesRegistry,
ParanetKnowledgeMinersRegistry,
ParanetKnowledgeAssetsRegistry,
ParanetIncentivesPoolFactory,
HashingProxy,
ServiceAgreementStorageProxy,
Token,
Expand All @@ -112,15 +120,15 @@ describe('@v2 @unit ParanetKnowledgeMinersRegistry contract', function () {

beforeEach(async () => {
hre.helpers.resetDeploymentsJson();
({ accounts, Paranet } = await loadFixture(deployParanetFixture));
({ accounts, Paranet, ParanetIncentivesPoolFactory } = await loadFixture(deployParanetFixture));
});

it('The contract is named "Paranet"', async () => {
expect(await Paranet.name()).to.equal('Paranet');
});

it('The contract is version "2.1.2"', async () => {
expect(await Paranet.version()).to.equal('2.1.2');
it('The contract is version "2.1.3"', async () => {
expect(await Paranet.version()).to.equal('2.1.3');
});

it('should register paranet', async () => {
Expand Down Expand Up @@ -951,7 +959,7 @@ describe('@v2 @unit ParanetKnowledgeMinersRegistry contract', function () {
paranetName,
paranetDescription,
);
await Paranet.connect(accounts[100 + number]).deployNeuroIncentivesPool(
await ParanetIncentivesPoolFactory.connect(accounts[100 + number]).deployNeuroIncentivesPool(
paranetKAStorageContract,
paranetKATokenId,
tracToNeuroEmissionMultiplier,
Expand Down

0 comments on commit 447114f

Please sign in to comment.