Skip to content

Commit

Permalink
refactor: rename OwnableDocumentStore to TransferableDocumentStore
Browse files Browse the repository at this point in the history
(cherry picked from commit 893541d5fbfe85afa57d740867f79fd92a6d0318)
  • Loading branch information
superical committed Mar 25, 2024
1 parent 54717b4 commit 3945a3c
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 146 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion script/DeployBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract contract DocumentStoreDeployScript is DeployBaseScript {
}
}

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");
Expand Down
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
Expand Up @@ -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
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/libraries/DeployUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 3945a3c

Please sign in to comment.