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

feat: rename OwnableDocumentStore to TransferableDocumentStore #157

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
refactor: rename OwnableDocumentStore to TransferableDocumentStore
(cherry picked from commit 893541d5fbfe85afa57d740867f79fd92a6d0318)
superical committed Mar 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 3945a3cdce4859751e91a6d86d813b2475070697
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -38,7 +38,14 @@
"prettier:write": "npx prettier --write \"**/*.{json,md,yml,sol}\" \"!broadcast/**/*\" --ignore-path=.prettierignore",
"test": "forge test",
"test:coverage": "rimraf coverage && mkdir coverage && forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage",
"test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage"
"test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage",
"deploy": "./deploy.sh $npm_config_network $npm_config_sender $npm_config_verify",
"deploy:ds": "npm run -s deploy script/DocumentStore.s.sol:DocumentStoreScript \"run(string,address)\" \"$npm_config_name\" \"$npm_config_admin\"",
"deploy:ds:impl": "npm run -s deploy script/DocumentStoreInitializable.s.sol:DocumentStoreInitializableScript",
"deploy:ds:upgradeable": "npm run -s deploy script/DocumentStoreUpgradeable.s.sol:DocumentStoreUpgradeableScript \"run(string,address)\" \"$npm_config_name\" \"$npm_config_admin\"",
"deploy:tds": "npm run -s deploy script/TransferableDocumentStore.s.sol:TransferableDocumentStoreScript \"run(string,string,address)\" \"$npm_config_name\" \"$npm_config_symbol\" \"$npm_config_admin\"",
"deploy:tds:impl": "npm run -s deploy script/TransferableDocumentStoreInitializable.s.sol:TransferableDocumentStoreInitializableScript",
"deploy:tds:upgradeable": "npm run -s deploy script/TransferableDocumentStoreUpgradeable.s.sol:TransferableDocumentStoreUpgradeableScript \"run(string,string,address)\" \"$npm_config_name\" \"$npm_config_symbol\" \"$npm_config_admin\""
},
"jest": {
"globalSetup": "./jest/setup.ts",
2 changes: 1 addition & 1 deletion script/DeployBase.s.sol
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
pragma solidity >=0.8.23 <0.9.0;

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

Check warning on line 5 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

imported name console2 is not used

abstract contract DeployBaseScript is Script {
address internal constant FACTORY = 0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed;
@@ -10,21 +10,21 @@
address internal constant TDS_IMPL = 0x8E9Eb7f019068f42E075f0a985D8A29596C82ED4;

constructor() {
require(getDocumentStoreSalt() != getTransferableDocumentStoreSalt(), "Salts must be different");

Check warning on line 13 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Use Custom Errors instead of require statements
}

function getSaltEntropy(string memory entropyName) internal view returns (bytes11) {
bytes11 entropy = bytes11(vm.envOr({ name: entropyName, defaultValue: bytes("") }));
require(entropy != bytes11(0), "Salt entropy not set");

Check warning on line 18 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Use Custom Errors instead of require statements

return entropy;
}

function getSalt(bytes11 entropy) internal view returns (bytes32 salt) {
require(entropy != bytes11(0), "Salt entropy not be zero");

Check warning on line 24 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Use Custom Errors instead of require statements

address deployer = vm.envOr({ name: "DEPLOYER_ADDRESS", defaultValue: address(0) });
require(deployer != address(0), "Deployer address not set");

Check warning on line 27 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Use Custom Errors instead of require statements

bytes20 deployerBytes = bytes20(deployer);

@@ -54,24 +54,24 @@
(bool ok, bytes memory data) = FACTORY.staticcall(
abi.encodeWithSignature("computeCreate3Address(bytes32)", guardedSalt)
);
require(ok, "Error compute DocumentStoreInitializable address");

Check warning on line 57 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Use Custom Errors instead of require statements
return abi.decode(data, (address));
}

function deploy(bytes32 salt, bytes memory initCode) internal returns (address) {
(bool ok, bytes memory data) = FACTORY.call(

Check warning on line 62 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Avoid to use low level calls
abi.encodeWithSignature("deployCreate3(bytes32,bytes)", salt, initCode)
);
require(ok, "Deployment failed");

Check warning on line 65 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Use Custom Errors instead of require statements

return abi.decode(data, (address));
}

function clone(address impl, bytes memory initData) internal returns (address) {
(bool ok, bytes memory data) = FACTORY.call(

Check warning on line 71 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Avoid to use low level calls
abi.encodeWithSignature("deployCreate2Clone(address,bytes)", impl, initData)
);
require(ok, "Clone deployment failed");

Check warning on line 74 in script/DeployBase.s.sol

GitHub Actions / Linters / Code Lint

Use Custom Errors instead of require statements

return abi.decode(data, (address));
}
@@ -100,7 +100,7 @@
}
}

abstract contract OwnableDocumentStoreDeployScript is DeployBaseScript {
abstract contract TransferableDocumentStoreDeployScript is DeployBaseScript {
function _requireParams(string memory name, string memory symbol, address admin) internal pure {
require(bytes(name).length > 0, "Name is required");
require(bytes(symbol).length > 0, "Symbol is required");
29 changes: 0 additions & 29 deletions script/OwnableDocumentStore.s.sol

This file was deleted.

23 changes: 0 additions & 23 deletions script/OwnableDocumentStoreInitializable.s.sol

This file was deleted.

26 changes: 0 additions & 26 deletions script/OwnableDocumentStoreUpgradeable.s.sol

This file was deleted.

29 changes: 29 additions & 0 deletions script/TransferableDocumentStore.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

import { console2 } from "forge-std/console2.sol";

import { TransferableDocumentStoreDeployScript } from "./DeployBase.s.sol";
import "../src/TransferableDocumentStore.sol";

contract TransferableDocumentStoreScript is TransferableDocumentStoreDeployScript {
function run(string memory name, string memory symbol, address admin) public returns (TransferableDocumentStore ds) {
_requireParams(name, symbol, admin);

console2.log("TransferableDocumentStore Name: ", name);
console2.log("TransferableDocumentStore Symbol: ", symbol);
console2.log("TransferableDocumentStore Admin: ", admin);

if (tdsImplExists()) {
bytes memory initData = abi.encodeWithSignature("initialize(string,string,address)", name, symbol, admin);

vm.broadcast();
address dsAddr = clone(TDS_IMPL, initData);

ds = TransferableDocumentStore(dsAddr);
} else {
vm.broadcast();
ds = new TransferableDocumentStore(name, symbol, admin);
}
}
}
23 changes: 23 additions & 0 deletions script/TransferableDocumentStoreInitializable.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

import { TransferableDocumentStoreDeployScript } from "./DeployBase.s.sol";
import "../src/initializables/TransferableDocumentStoreInitializable.sol";

contract TransferableDocumentStoreInitializableScript is TransferableDocumentStoreDeployScript {
function run() public returns (TransferableDocumentStoreInitializable documentStore) {
require(!dsImplExists(), "TransferableDocumentStoreInitializable already exists");

bytes memory initCode = abi.encodePacked(type(TransferableDocumentStoreInitializable).creationCode);

bytes32 dsSalt = getTransferableDocumentStoreSalt();

address computedAddr = computeAddr(dsSalt);
require(computedAddr == TDS_IMPL, "Bad deployment address");

vm.broadcast();
address dsAddr = deploy(dsSalt, initCode);

documentStore = TransferableDocumentStoreInitializable(dsAddr);
}
}
26 changes: 26 additions & 0 deletions script/TransferableDocumentStoreUpgradeable.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

import { console2 } from "forge-std/console2.sol";

import { TransferableDocumentStoreDeployScript } from "./DeployBase.s.sol";
import { DeployUtils } from "../src/libraries/DeployUtils.sol";
import "../src/upgradeables/TransferableDocumentStoreUpgradeable.sol";

contract TransferableDocumentStoreUpgradeableScript is TransferableDocumentStoreDeployScript {
function run(
string memory name,
string memory symbol,
address admin
) public returns (TransferableDocumentStoreUpgradeable ds) {
_requireParams(name, symbol, admin);

console2.log("TransferableDocumentStore Name: ", name);
console2.log("TransferableDocumentStore Symbol: ", symbol);
console2.log("TransferableDocumentStore Admin: ", admin);

vm.broadcast();
(address pAddr, ) = DeployUtils.deployTransferableDocumentStoreUpgradeable(name, symbol, admin);
ds = TransferableDocumentStoreUpgradeable(pAddr);
}
}
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@

pragma solidity >=0.8.23 <0.9.0;

import "./base/BaseOwnableDocumentStore.sol";
import "./base/BaseTransferableDocumentStore.sol";

contract OwnableDocumentStore is BaseOwnableDocumentStore {
contract TransferableDocumentStore is BaseTransferableDocumentStore {
constructor(string memory name_, string memory symbol_, address initAdmin) {
initialize(name_, symbol_, initAdmin);
}

function initialize(string memory name_, string memory symbol_, address initAdmin) internal initializer {
__OwnableDocumentStore_init(name_, symbol_, initAdmin);
__TransferableDocumentStore_init(name_, symbol_, initAdmin);
}
}
Original file line number Diff line number Diff line change
@@ -6,31 +6,32 @@ import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

import "../base/DocumentStoreAccessControl.sol";
import "../interfaces/IOwnableDocumentStore.sol";
import "../interfaces/IOwnableDocumentStoreErrors.sol";
import "../interfaces/ITransferableDocumentStore.sol";
import "../interfaces/ITransferableDocumentStoreErrors.sol";
import "../interfaces/IERC5192.sol";

abstract contract BaseOwnableDocumentStore is
abstract contract BaseTransferableDocumentStore is
DocumentStoreAccessControl,
ERC721Upgradeable,
IERC5192,
IOwnableDocumentStoreErrors,
IOwnableDocumentStore
ITransferableDocumentStoreErrors,
ITransferableDocumentStore
{
using Strings for uint256;

/// @custom:storage-location erc7201:openattestation.storage.OwnableDocumentStore
/// @custom:storage-location erc7201:openattestation.storage.TransferableDocumentStore
struct DocumentStoreStorage {
string baseURI;
mapping(uint256 => bool) revoked;
mapping(uint256 => bool) locked;
}

// keccak256(abi.encode(uint256(keccak256("openattestation.storage.OwnableDocumentStore")) - 1)) & ~bytes32(uint256(0xff))
// keccak256(abi.encode(uint256(keccak256("openattestation.storage.TransferableDocumentStore")) - 1)) &
// ~bytes32(uint256(0xff))
bytes32 private constant _DocumentStoreStorageSlot =
0x5b868bb5de5c3e5f8f786d02cbc568987b1921539a10331babbe7311c24de500;
0xe00db8ee8fc09b2a809fe10830715c77ed23b7661f93309e127fb70c1f33ef00;

function __OwnableDocumentStore_init(
function __TransferableDocumentStore_init(
string memory name_,
string memory symbol_,
address initAdmin
@@ -111,7 +112,7 @@ abstract contract BaseOwnableDocumentStore is
) public view virtual override(ERC721Upgradeable, AccessControlUpgradeable) returns (bool) {
return
interfaceId == type(IDocumentStore).interfaceId ||
interfaceId == type(IOwnableDocumentStore).interfaceId ||
interfaceId == type(ITransferableDocumentStore).interfaceId ||
interfaceId == type(IERC5192).interfaceId ||
super.supportsInterface(interfaceId);
}
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@

pragma solidity >=0.8.23 <0.9.0;

import "../base/BaseOwnableDocumentStore.sol";
import "../base/BaseTransferableDocumentStore.sol";

contract OwnableDocumentStoreInitializable is BaseOwnableDocumentStore {
contract TransferableDocumentStoreInitializable is BaseTransferableDocumentStore {
constructor() initializer {}

function initialize(string memory name_, string memory symbol_, address initAdmin) external initializer {
__OwnableDocumentStore_init(name_, symbol_, initAdmin);
__TransferableDocumentStore_init(name_, symbol_, initAdmin);
}
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@ pragma solidity >=0.8.23 <0.9.0;

import "./IDocumentStore.sol";

interface IOwnableDocumentStore is IDocumentStore {
interface ITransferableDocumentStore is IDocumentStore {
function issue(address to, bytes32 documentRoot, bool locked) external;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

interface IOwnableDocumentStoreErrors {
interface ITransferableDocumentStoreErrors {
error InactiveDocument(bytes32 document);

error DocumentExists(bytes32 document);
11 changes: 7 additions & 4 deletions src/libraries/DeployUtils.sol
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ pragma solidity >=0.8.23 <0.9.0;
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

import "../upgradeables/DocumentStoreUpgradeable.sol";
import "../upgradeables/OwnableDocumentStoreUpgradeable.sol";
import "../upgradeables/TransferableDocumentStoreUpgradeable.sol";

library DeployUtils {
function deployDocumentStoreUpgradeable(string memory name, address initAdmin) internal returns (address, address) {
@@ -18,14 +18,17 @@ library DeployUtils {
return (address(proxy), dsAddr);
}

function deployOwnableDocumentStoreUpgradeable(
function deployTransferableDocumentStoreUpgradeable(
string memory name,
string memory symbol,
address initAdmin
) internal returns (address, address) {
bytes memory initData = abi.encodeCall(OwnableDocumentStoreInitializable.initialize, (name, symbol, initAdmin));
bytes memory initData = abi.encodeCall(
TransferableDocumentStoreInitializable.initialize,
(name, symbol, initAdmin)
);

OwnableDocumentStoreUpgradeable documentStore = new OwnableDocumentStoreUpgradeable();
TransferableDocumentStoreUpgradeable documentStore = new TransferableDocumentStoreUpgradeable();
address dsAddr = address(documentStore);

ERC1967Proxy proxy = new ERC1967Proxy(dsAddr, initData);
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ pragma solidity >=0.8.23 <0.9.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

import "../initializables/OwnableDocumentStoreInitializable.sol";
import "../initializables/TransferableDocumentStoreInitializable.sol";

contract OwnableDocumentStoreUpgradeable is UUPSUpgradeable, OwnableDocumentStoreInitializable {
contract TransferableDocumentStoreUpgradeable is UUPSUpgradeable, TransferableDocumentStoreInitializable {
function _authorizeUpgrade(address) internal view virtual override onlyRole(DEFAULT_ADMIN_ROLE) {}
}
18 changes: 9 additions & 9 deletions test/CommonTest.t.sol
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import "forge-std/Test.sol";

import "../src/DocumentStore.sol";
import "./fixtures/DocumentStoreFixture.sol";
import "../src/OwnableDocumentStore.sol";
import "./fixtures/OwnableDocumentStoreFixture.sol";
import "../src/TransferableDocumentStore.sol";
import "./fixtures/TransferableDocumentStoreFixture.sol";

abstract contract CommonTest is Test {
address public owner = vm.addr(1);
@@ -236,31 +236,31 @@ abstract contract DocumentStore_multicall_revoke_Initializer is DocumentStore_mu
}
}

abstract contract OwnableDocumentStoreCommonTest is CommonTest {
OwnableDocumentStore public documentStore;
abstract contract TranferableDocumentStoreCommonTest is CommonTest {
TransferableDocumentStore public documentStore;

string public storeName = "OwnableDocumentStore Test";
string public storeName = "TransferableDocumentStore Test";
string public storeSymbol = "XYZ";

function setUp() public virtual override {
super.setUp();

vm.startPrank(owner);
documentStore = new OwnableDocumentStore(storeName, storeSymbol, owner);
documentStore = new TransferableDocumentStore(storeName, storeSymbol, owner);
documentStore.grantRole(documentStore.ISSUER_ROLE(), issuer);
documentStore.grantRole(documentStore.REVOKER_ROLE(), revoker);
vm.stopPrank();
}
}

abstract contract OwnableDocumentStore_Initializer is OwnableDocumentStoreCommonTest {
OwnableDocumentStoreFixture private _fixture;
abstract contract TransferableDocumentStore_Initializer is TranferableDocumentStoreCommonTest {
TransferableDocumentStoreFixture private _fixture;
address[] public recipients;

function setUp() public virtual override {
super.setUp();

_fixture = new OwnableDocumentStoreFixture();
_fixture = new TransferableDocumentStoreFixture();

recipients = new address[](2);
recipients[0] = vm.addr(4);
Loading