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

allow whitelist for specific projectType #298

Merged
merged 3 commits into from
Dec 12, 2023
Merged
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
13 changes: 7 additions & 6 deletions contracts/ProjectRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract ProjectRegistry is Initializable, OwnableUpgradeable, ERC721Upgradeable
uint256 public nextProjectId;

/// @notice is the contract run in creator restrict mode. If in creator restrict mode, only permissioned account allowed to create and update project
bool public creatorRestricted;
mapping(ProjectType => bool) public creatorRestricted;

/// @notice account address -> is creator
mapping(address => bool) public creatorWhitelist;
Expand Down Expand Up @@ -85,7 +85,8 @@ contract ProjectRegistry is Initializable, OwnableUpgradeable, ERC721Upgradeable
__ERC721Enumerable_init();

settings = _settings;
creatorRestricted = true;
creatorRestricted[ProjectType.SUBQUERY] = true;
creatorRestricted[ProjectType.RPC] = true;
creatorWhitelist[msg.sender] = true;
nextProjectId = 1;
}
Expand All @@ -98,8 +99,8 @@ contract ProjectRegistry is Initializable, OwnableUpgradeable, ERC721Upgradeable
* @notice set the mode to restrict or not
* restrict mode -- only permissioned accounts allowed to create project
*/
function setCreatorRestricted(bool _creatorRestricted) external onlyOwner {
creatorRestricted = _creatorRestricted;
function setCreatorRestricted(ProjectType _type, bool _creatorRestricted) external onlyOwner {
creatorRestricted[_type] = _creatorRestricted;
}

/**
Expand Down Expand Up @@ -140,7 +141,7 @@ contract ProjectRegistry is Initializable, OwnableUpgradeable, ERC721Upgradeable
* @notice create a project, if in the restrict mode, only creator allowed to call this function
*/
function createProject(string memory projectMetadataUri, bytes32 deploymentMetdata, bytes32 deploymentId, ProjectType projectType) external {
if (creatorRestricted) {
if (creatorRestricted[projectType]) {
require(creatorWhitelist[msg.sender], 'PR001');
}

Expand Down Expand Up @@ -191,7 +192,7 @@ contract ProjectRegistry is Initializable, OwnableUpgradeable, ERC721Upgradeable
}

emit ProjectDeploymentUpdated(msg.sender, projectId, deploymentId, metadata);

if (updateLatest && projectInfos[projectId].latestDeploymentId != deploymentId) {
_updateProjectLatestDeployment(projectId, deploymentId);
}
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,13 @@ export enum SQContracts {
PriceOracle,
RootChainManager,
}

export enum ServiceStatus {
TERMINATED,
READY,
}

export enum ProjectType {
SUBQUERY,
RPC
}
11 changes: 6 additions & 5 deletions test/ProjectRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ describe('Project Registry Contract', () => {
expect(await projectRegistry.symbol()).to.equal('SP');
expect(await projectRegistry.totalSupply()).to.equal(0);

expect(await projectRegistry.creatorRestricted()).to.equal(true);
expect(await projectRegistry.creatorRestricted(ProjectType.SUBQUERY)).to.equal(true);
expect(await projectRegistry.creatorRestricted(ProjectType.RPC)).to.equal(true);
expect(await projectRegistry.creatorWhitelist(wallet_0.address)).to.equal(true);
expect(await projectRegistry.creatorWhitelist(wallet_1.address)).to.equal(false);
expect(await projectRegistry.settings()).to.equal(setting.address);
Expand All @@ -87,9 +88,9 @@ describe('Project Registry Contract', () => {

describe('Managing Creator', () => {
it('change creator restricted mode should work', async () => {
expect(await projectRegistry.creatorRestricted()).to.equal(true);
await projectRegistry.setCreatorRestricted(false);
expect(await projectRegistry.creatorRestricted()).to.equal(false);
expect(await projectRegistry.creatorRestricted(ProjectType.SUBQUERY)).to.equal(true);
await projectRegistry.setCreatorRestricted(ProjectType.SUBQUERY, false);
expect(await projectRegistry.creatorRestricted(ProjectType.SUBQUERY)).to.equal(false);
});

it('add creator should work', async () => {
Expand Down Expand Up @@ -140,7 +141,7 @@ describe('Project Registry Contract', () => {
});

it('any account can create a project when creatorRestricted mode disabled', async () => {
await projectRegistry.setCreatorRestricted(false);
await projectRegistry.setCreatorRestricted(ProjectType.SUBQUERY, false);
await createProject(wallet_1);
expect(await projectRegistry.ownerOf(1)).to.equal(wallet_1.address);
});
Expand Down
4 changes: 2 additions & 2 deletions test/serviceAgreementRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ERC20,
ServiceAgreementExtra,
ServiceAgreementRegistry,
Staking,
Staking, ProjectType,
} from '../src';
import { DEPLOYMENT_ID, METADATA_HASH, VERSION, deploymentIds, poi } from './constants';
import { createPurchaseOffer, etherParse, eventFrom, futureTimestamp, time, timeTravel } from './helper';
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Service Agreement Registry Contract', () => {
rewardsStaking = deployment.rewardsStaking;
rewardsHelper = deployment.rewardsHelper;

await projectRegistry.setCreatorRestricted(false);
await projectRegistry.setCreatorRestricted(ProjectType.SUBQUERY, false);

// period 1000 s
// planTemplateId: 0
Expand Down
Loading