Skip to content

Commit

Permalink
adding config for provenance
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed Jun 14, 2022
1 parent b3838f3 commit 5424afa
Show file tree
Hide file tree
Showing 34 changed files with 114 additions and 246 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Compile the solidity contracts:
yarn compile
```

In a new terminal, launch an Ethereum RPC client, e.g. [ganache-cli](https://github.com/trufflesuite/ganache-cli):
In a new terminal, launch an Ethereum RPC client, e.g. hardhat:

```bash
npx hardhat node --port 18545
Expand Down
17 changes: 7 additions & 10 deletions contracts/governance/INVMConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ abstract contract INVMConfig {
bytes32 indexed _parameter
);

/**
* @notice Used to initialize the contract during delegator constructor
* @param _owner The owner of the contract
* @param _governor The address to be granted with the `GOVERNOR_ROLE`
*/
function initialize(
address _owner,
address _governor
) virtual external;

/**
* @notice The governor can update the Nevermined Marketplace fees
* @param _marketplaceFee new marketplace fee
Expand Down Expand Up @@ -59,4 +49,11 @@ abstract contract INVMConfig {
*/
function getFeeReceiver()
external view virtual returns (address);

/**
* @notice Returns true if provenance should be stored in storage
* @return true if provenance should be stored in storage
*/
function getProvenanceStorage()
external view virtual returns (bool);
}
24 changes: 21 additions & 3 deletions contracts/governance/NeverminedConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,25 @@ INVMConfig
// See `marketplaceFee`
address public feeReceiver;

// @notice Switch to turn off provenance in storage. By default the storage is on
bool public provenanceOff;

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////


/**
* @notice Used to initialize the contract during delegator constructor
* @param _owner The owner of the contract
* @param _governor The address to be granted with the `GOVERNOR_ROLE`
*/
function initialize(
address _owner,
address _governor
address _governor,
bool _provenanceOff
)
public
override
initializer
{
__Ownable_init();
Expand All @@ -44,8 +52,9 @@ INVMConfig
AccessControlUpgradeable.__AccessControl_init();
AccessControlUpgradeable._setupRole(DEFAULT_ADMIN_ROLE, _owner);
AccessControlUpgradeable._setupRole(GOVERNOR_ROLE, _governor);
provenanceOff = _provenanceOff;
}

function setMarketplaceFees(
uint256 _marketplaceFee,
address _feeReceiver
Expand Down Expand Up @@ -106,6 +115,15 @@ INVMConfig
return feeReceiver;
}

function getProvenanceStorage()
external
view
override
returns (bool)
{
return !provenanceOff;
}

modifier onlyGovernor(address _address)
{
require(
Expand Down
18 changes: 0 additions & 18 deletions contracts/registry/DIDFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,6 @@ contract DIDFactory is OwnableUpgradeable, ProvenanceRegistry {
address _delegate
);

/**
* @dev DIDRegistry Initializer
* Initialize Ownable. Only on contract creation.
* @param _owner refers to the owner of the contract.
*/
/*
function initialize(
address _owner
)
public
virtual
initializer
{
OwnableUpgradeable.__Ownable_init();
transferOwnership(_owner);
manager = _owner;
}*/

/**
* Sets the manager role. Should be the TransferCondition contract address
*/
Expand Down
4 changes: 3 additions & 1 deletion contracts/registry/DIDRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ contract DIDRegistry is DIDFactory {
function initialize(
address _owner,
address _erc1155,
address _erc721
address _erc721,
address _config
)
public
initializer
Expand All @@ -45,6 +46,7 @@ contract DIDRegistry is DIDFactory {
erc721 = NFT721Upgradeable(_erc721);
transferOwnership(_owner);
manager = _owner;
nvmConfig = INVMConfig(_config);
}

function registerRoyaltiesChecker(address _addr) public onlyOwner {
Expand Down
12 changes: 8 additions & 4 deletions contracts/registry/ProvenanceRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
// Code is Apache-2.0 and docs are CC-BY-4.0

import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '../governance/INVMConfig.sol';

/**
* @title Provenance Registry Library
Expand All @@ -13,8 +14,9 @@ import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
*/
/* solium-disable-next-line */
abstract contract ProvenanceRegistry is OwnableUpgradeable {
//library ProvenanceRegistry {


INVMConfig public nvmConfig;

// solhint-disable-next-line
function __ProvenanceRegistry_init() internal initializer {
__Context_init_unchained();
Expand Down Expand Up @@ -162,9 +164,12 @@ abstract contract ProvenanceRegistry is OwnableUpgradeable {
string memory _attributes
)
internal
returns (bool)
{

if (address(nvmConfig) != address(0) && !nvmConfig.getProvenanceStorage()) {
return;
}

require(
provenanceRegistry.list[_provId].createdBy == address(0x0),
'Already existing provId'
Expand Down Expand Up @@ -195,7 +200,6 @@ abstract contract ProvenanceRegistry is OwnableUpgradeable {
block.number
);

return true;
}


Expand Down
4 changes: 2 additions & 2 deletions test/external/kovan/Aave_NFT_Credit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ contract('End to End NFT Collateral Scenario [@skip-on-coverage]', (accounts) =>
await token.initialize(owner, owner)

const nvmConfig = await NeverminedConfig.new()
await nvmConfig.initialize(owner, governor)
await nvmConfig.initialize(owner, governor, false)

const didRegistryLibrary = await DIDRegistryLibrary.new()
await DIDRegistry.link(didRegistryLibrary)
didRegistry = await DIDRegistry.new({ gas: 19000000 })
await didRegistry.initialize(owner, constants.address.zero, constants.address.zero)
await didRegistry.initialize(owner, constants.address.zero, constants.address.zero, constants.address.zero)

const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
Expand Down
4 changes: 2 additions & 2 deletions test/external/kovan/Aave_NFT_Timeout_Credit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ contract('End to End NFT Collateral Scenario (timeout) [@skip-on-coverage]', (ac
await token.initialize(owner, owner)

const nvmConfig = await NeverminedConfig.new()
await nvmConfig.initialize(owner, governor)
await nvmConfig.initialize(owner, governor, false)

const didRegistryLibrary = await DIDRegistryLibrary.new()
await DIDRegistry.link(didRegistryLibrary)
didRegistry = await DIDRegistry.new()
await didRegistry.initialize(owner, constants.address.zero, constants.address.zero)
await didRegistry.initialize(owner, constants.address.zero, constants.address.zero, constants.address.zero)

const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/deployManagers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const deployManagers = async function(deployer, owner, governor = owner) {
const epochLibrary = await EpochLibrary.new({ from: deployer })

const token = await testUtils.deploy('NeverminedToken', [owner, owner], deployer)
const nvmConfig = await testUtils.deploy('NeverminedConfig', [owner, governor], deployer)
const nvmConfig = await testUtils.deploy('NeverminedConfig', [owner, governor, false], deployer)
const nft = await testUtils.deploy('NFTUpgradeable', [''], deployer)
const nft721 = await testUtils.deploy('NFT721Upgradeable', [], deployer)

const didRegistry = await testUtils.deploy('DIDRegistry', [owner, nft.address, nft721.address], deployer, [didRegistryLibrary])
const didRegistry = await testUtils.deploy('DIDRegistry', [owner, nft.address, nft721.address, nvmConfig.address], deployer, [didRegistryLibrary])
const royaltyManager = await testUtils.deploy('StandardRoyalties', [didRegistry.address], deployer)

const templateStoreManager = await testUtils.deploy('TemplateStoreManager', [owner], deployer)
Expand Down
30 changes: 30 additions & 0 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const { hardhatArguments } = require('hardhat')
const network = hardhatArguments.network || 'hardhat'
const deploying = network === 'hardhat' || network === 'coverage'
const constants = require('./constants')

const utils = {
deploying,
Expand Down Expand Up @@ -75,6 +76,35 @@ const utils = {
const addr = require(`../../artifacts/${name}.external.json`).address
return afact.at(addr)
}
},

deployManagers: async (owner, createRole) => {
const DIDRegistry = artifacts.require('DIDRegistry')
const NeverminedConfig = artifacts.require('NeverminedConfig')
const ConditionStoreManager = artifacts.require('ConditionStoreManager')
const EpochLibrary = artifacts.require('EpochLibrary')
const DIDRegistryLibrary = artifacts.require('DIDRegistryLibrary')
const NFT = artifacts.require('NFTUpgradeable')

const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
const didRegistryLibrary = await DIDRegistryLibrary.new()
await DIDRegistry.link(didRegistryLibrary)
const nvmConfig = await NeverminedConfig.new()
await nvmConfig.initialize(owner, owner, false)
const nft = await NFT.new()
await nft.initialize('')
const didRegistry = await DIDRegistry.new()
await didRegistry.initialize(owner, nft.address, constants.address.zero, nvmConfig.address)
const conditionStoreManager = await ConditionStoreManager.new()
await conditionStoreManager.initialize(createRole, owner, nvmConfig.address, { from: owner })
await nft.addMinter(didRegistry.address)
return {
didRegistry,
nvmConfig,
conditionStoreManager,
nft
}
}

}
Expand Down
6 changes: 2 additions & 4 deletions test/unit/agreements/AgreementStoreManager.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ contract('AgreementStoreManager', (accounts) => {
await token.initialize(owner, owner)

const nvmConfig = await NeverminedConfig.new()
await nvmConfig.initialize(owner, owner)
await nvmConfig.initialize(owner, owner, false)

const didRegistryLibrary = await DIDRegistryLibrary.new()
await DIDRegistry.link(didRegistryLibrary)
didRegistry = await DIDRegistry.new()
await didRegistry.initialize(owner, constants.address.zero, constants.address.zero)
await didRegistry.initialize(owner, constants.address.zero, constants.address.zero, constants.address.zero)

conditionStoreManager = await ConditionStoreManager.new({ from: deployer })

Expand All @@ -67,8 +67,6 @@ contract('AgreementStoreManager', (accounts) => {
{ from: deployer }
)

// const agreementStoreLibrary = await AgreementStoreLibrary.new({ from: deployer })
// await AgreementStoreManager.link(agreementStoreLibrary)
agreementStoreManager = await AgreementStoreManager.new({ from: deployer })
await agreementStoreManager.methods['initialize(address,address,address,address)'](
owner,
Expand Down
4 changes: 1 addition & 3 deletions test/unit/conditions/ComputeExecutionCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ contract('ComputeExecutionCondition constructor', (accounts) => {
const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
const conditionStoreManager = await ConditionStoreManager.new()
// const agreementStoreLibrary = await AgreementStoreLibrary.new()
// await AgreementStoreManager.link(agreementStoreLibrary)
const agreementStoreManager = await AgreementStoreManager.new()
const didRegistryLibrary = await DIDRegistryLibrary.new()
await DIDRegistry.link(didRegistryLibrary)
const didRegistry = await DIDRegistry.new()
await didRegistry.initialize(accounts[0], constants.address.zero, constants.address.zero)
await didRegistry.initialize(accounts[0], constants.address.zero, constants.address.zero, constants.address.zero)
const computeExecutionCondition = await ComputeExecutionCondition.new()

await computeExecutionCondition.methods['initialize(address,address,address)'](
Expand Down
2 changes: 1 addition & 1 deletion test/unit/conditions/ConditionStoreManager.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract('ConditionStoreManager', (accounts) => {

before(async () => {
nvmConfig = await NeverminedConfig.new()
await nvmConfig.initialize(owner, governor)
await nvmConfig.initialize(owner, governor, false)
const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
})
Expand Down
2 changes: 1 addition & 1 deletion test/unit/conditions/HashLockCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract('HashLockCondition constructor', (accounts) => {
const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
nvmConfig = await NeverminedConfig.new()
await nvmConfig.initialize(owner, owner)
await nvmConfig.initialize(owner, owner, false)
})

beforeEach(async () => {
Expand Down

0 comments on commit 5424afa

Please sign in to comment.