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

Schema Stuff #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct User {
}
```

Once users have registered accounts, they can register a `ProvenanceClaim`, an attestation that a certain Royal Protocol account is the creator of a certain work (identified by hash).
Once users have registered accounts, they can register a `ProvenanceClaim`, an record that a certain Royal Protocol account is the creator of a certain work (identified by hash).
Users can register works while specifying themselves as the author.
They can also register works on behalf of a different author; this enables digital creative tools to register works on behalf of its users (provided both user and registrar have a Royal Protocol account).

Expand Down
10 changes: 5 additions & 5 deletions script/CalculateInitialSalts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";

import {IdRegistry} from "../../src/IdRegistry.sol";
import {IdGateway} from "../../src/IdGateway.sol";
import {ProvenanceRegistry} from "../../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../../src/delegation/DelegateRegistry.sol";
import {IdRegistry} from "../src/IdRegistry.sol";
import {IdGateway} from "../src/IdGateway.sol";
import {ProvenanceRegistry} from "../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../src/delegation/DelegateRegistry.sol";

import {LibClone} from "solady/utils/LibClone.sol";

Expand Down
10 changes: 5 additions & 5 deletions script/CalculateUpgradeSalts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";

import {IdRegistry} from "../../src/IdRegistry.sol";
import {IdGateway} from "../../src/IdGateway.sol";
import {ProvenanceRegistry} from "../../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../../src/delegation/DelegateRegistry.sol";
import {IdRegistry} from "../src/IdRegistry.sol";
import {IdGateway} from "../src/IdGateway.sol";
import {ProvenanceRegistry} from "../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../src/delegation/DelegateRegistry.sol";

import {LibClone} from "solady/utils/LibClone.sol";

Expand Down
10 changes: 5 additions & 5 deletions script/DeployProtocolContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";

import {IdRegistry} from "../../src/IdRegistry.sol";
import {IdGateway} from "../../src/IdGateway.sol";
import {ProvenanceRegistry} from "../../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../../src/delegation/DelegateRegistry.sol";
import {IdRegistry} from "../src/IdRegistry.sol";
import {IdGateway} from "../src/IdGateway.sol";
import {ProvenanceRegistry} from "../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../src/delegation/DelegateRegistry.sol";

import {LibClone} from "solady/utils/LibClone.sol";

Expand Down
114 changes: 114 additions & 0 deletions script/DeploySchemaContracts.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";

import {SchemaRegistry} from "../src/SchemaRegistry.sol";
import {RecordRegistry} from "../src/RecordRegistry.sol";

import {FieldDefinition, FieldType, ISchemaResolver} from "../src/interfaces/ISchemaRegistry.sol";
import {RecordRequest, RecordRequestData} from "../src/interfaces/IRecordRegistry.sol";
import {IIdRegistry} from "../src/interfaces/IIdRegistry.sol";

import {LibClone} from "solady/utils/LibClone.sol";

/**
* NOTE: This script won't work unless you go back in Git history to get the contract code at time of initial deploy.
*
* If this ends up being an annoying problem - right solve is probably to use CREATE3 moving forward.
*/
contract DeployProtocolContracts is Script {
// =============================================================
// INPUTS
// =============================================================

// NOTE: Get initcode hashes from CalculateSalts script, and then salts from maldon (or create2crunch/cast).
bytes32 schemaRegistrySalt = bytes32(uint256(2));
bytes32 recordRegistrySalt = bytes32(uint256(2));

bytes32 schemaRegistryProxySalt = bytes32(uint256(2));
bytes32 recordRegistryProxySalt = bytes32(uint256(2));

// NOTE: Double-check addresses?
IIdRegistry public constant ID_REGISTRY = IIdRegistry(0x0000002c243D1231dEfA58915324630AB5dBd4f4);

address public constant OWNER = 0x62Bd6bD77403268E387a8c7e09aF5D3127186be8;

// =============================================================
// SCRIPT
// =============================================================

function run() external {
if (msg.sender != OWNER) {
console.log("Must run as OWNER");
return;
}

// Deploy SchemaRegistry
vm.startBroadcast();
address schemaRegistryImplementation = address(new SchemaRegistry{salt: schemaRegistrySalt}());
SchemaRegistry schemaRegistry =
SchemaRegistry(LibClone.deployDeterministicERC1967(schemaRegistryImplementation, schemaRegistryProxySalt));
schemaRegistry.initialize(ID_REGISTRY, OWNER);
console.log("SchemaRegistry address: %s", address(schemaRegistry));
vm.stopBroadcast();

// Register canonical schemas for schema metadata
FieldDefinition[] memory fields = new FieldDefinition[](2);
fields[0] = FieldDefinition({
fieldName: "schemaId",
fieldType: FieldType.SCHEMA_ID,
isArray: false,
allowedSchemaIds: new bytes32[](0),
enumValues: new string[](0)
});

fields[1] = FieldDefinition({
fieldName: "description",
fieldType: FieldType.STRING,
isArray: false,
allowedSchemaIds: new bytes32[](0),
enumValues: new string[](0)
});

// Register Schema#1 - Description
vm.startBroadcast();
bytes32 descriptionSchemaUID = schemaRegistry.register({
name: "Schema Description",
fields: fields,
revocable: false,
updatable: true,
resolver: ISchemaResolver(address(0)),
salt: bytes32(0)
});
vm.stopBroadcast();

// Deploy RecordRegistry
vm.startBroadcast();
address recordRegistryImplementation = address(new RecordRegistry{salt: recordRegistrySalt}());
RecordRegistry recordRegistry =
RecordRegistry(LibClone.deployDeterministicERC1967(recordRegistryImplementation, recordRegistryProxySalt));
recordRegistry.initialize(schemaRegistry, ID_REGISTRY, OWNER);
console.log("RecordRegistry address: %s", address(recordRegistry));
vm.stopBroadcast();

// Setup Record for a Description for Schema#1
RecordRequest memory descriptionDescriptionRecordRequest = RecordRequest({
schema: descriptionSchemaUID,
data: RecordRequestData({
revocable: false,
updatable: true,
data: abi.encode(descriptionSchemaUID, "A descriptive description of the schema."),
salt: bytes32(0),
value: 0
})
});

// Attest to the description of the canonical "Schema Description"
uint256 accountId = ID_REGISTRY.idOf(OWNER);

vm.startBroadcast();
recordRegistry.register(accountId, descriptionDescriptionRecordRequest);
vm.stopBroadcast();
}
}
10 changes: 5 additions & 5 deletions script/UpgradeProtocolContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";

import {IdRegistry} from "../../src/IdRegistry.sol";
import {IdGateway} from "../../src/IdGateway.sol";
import {ProvenanceRegistry} from "../../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../../src/delegation/DelegateRegistry.sol";
import {IdRegistry} from "../src/IdRegistry.sol";
import {IdGateway} from "../src/IdGateway.sol";
import {ProvenanceRegistry} from "../src/ProvenanceRegistry.sol";
import {ProvenanceGateway} from "../src/ProvenanceGateway.sol";
import {DelegateRegistry} from "../src/delegation/DelegateRegistry.sol";

import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol";

Expand Down
32 changes: 32 additions & 0 deletions src/Common.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// TODO: Rename this file.

// A representation of an empty/uninitialized UID.
bytes32 constant EMPTY_UID = 0;

// TODO: Review error messages
error AccessDenied();
error InvalidLength();
error NotFound();

/// @notice A struct representing ECDSA signature data.
struct Signature {
uint8 v; // The recovery ID.
bytes32 r; // The x-coordinate of the nonce R.
bytes32 s; // The signature data.
}

/// @notice A struct representing a single record.
struct Record {
bytes32 uid; // A unique identifier of the record.
bytes32 schema; // The unique identifier of the schema.
uint256 originator; // The attester/sender of the record.
uint256 registrar; // The registrar of the record.
uint64 time; // The time when the record was created (Unix timestamp).
uint64 revocationTime; // The time when the record was revoked (Unix timestamp).
bool revocable; // Whether the record is revocable.
bool updatable; // Whether the record data is updatable.
bytes data; // Custom record data.
}
Loading
Loading