From 7aafd296c41cac0f25856ef81fa58d6fa37df9de Mon Sep 17 00:00:00 2001 From: Raul Date: Mon, 13 Nov 2023 15:28:57 -0300 Subject: [PATCH] refactor licensing term libs --- contracts/hooks/licensing/TermsHook.sol | 8 +++---- contracts/lib/hooks/licensing/TermsHooks.sol | 11 ---------- contracts/lib/modules/Licensing.sol | 12 +---------- contracts/lib/modules/LicensingTerms.sol | 21 +++++++++++++++++++ .../licensing/LicenseCreatorModule.Terms.sol | 3 ++- .../LicensingCreatorModule.Config.t.sol | 3 ++- .../LicensingCreatorModule.Licensing.sol | 3 ++- 7 files changed, 32 insertions(+), 29 deletions(-) delete mode 100644 contracts/lib/hooks/licensing/TermsHooks.sol create mode 100644 contracts/lib/modules/LicensingTerms.sol diff --git a/contracts/hooks/licensing/TermsHook.sol b/contracts/hooks/licensing/TermsHook.sol index e485e86b..fb5adfee 100644 --- a/contracts/hooks/licensing/TermsHook.sol +++ b/contracts/hooks/licensing/TermsHook.sol @@ -4,10 +4,10 @@ pragma solidity ^0.8.19; import { HookResult } from "contracts/interfaces/hooks/base/IHook.sol"; import { SyncBaseHook } from "contracts/hooks/base/SyncBaseHook.sol"; import { Errors } from "contracts/lib/Errors.sol"; -import { TermsHooks } from "contracts/lib/hooks/licensing/TermsHooks.sol"; import { ShortStrings, ShortString } from "@openzeppelin/contracts/utils/ShortStrings.sol"; import { ShortStringOps } from "contracts/utils/ShortStringOps.sol"; -import { TermIds, Licensing } from "contracts/lib/modules/Licensing.sol"; +import { Licensing } from "contracts/lib/modules/Licensing.sol"; +import { TermIds, TermData } from "contracts/lib/modules/LicensingTerms.sol"; contract TermsHook is SyncBaseHook { using ShortStrings for *; @@ -20,7 +20,7 @@ contract TermsHook is SyncBaseHook { // If config is correct, this will not revert // See https://github.com/ethereum/solidity/issues/13869 if (ShortStringOps._equal(TermIds.SHARE_ALIKE, termId)) { - abi.decode(data, (TermsHooks.ShareAlike)); + abi.decode(data, (TermData.ShareAlike)); } revert Errors.TermsHook_UnsupportedTermsId(); } @@ -31,7 +31,7 @@ contract TermsHook is SyncBaseHook { ) internal virtual override returns (bytes memory) { (ShortString termId, bytes memory data) = abi.decode(hookConfig_, (ShortString, bytes)); if (ShortStringOps._equal(TermIds.SHARE_ALIKE, termId)) { - abi.decode(data, (TermsHooks.ShareAlike)); + abi.decode(data, (TermData.ShareAlike)); } return ""; } diff --git a/contracts/lib/hooks/licensing/TermsHooks.sol b/contracts/lib/hooks/licensing/TermsHooks.sol deleted file mode 100644 index 5d369127..00000000 --- a/contracts/lib/hooks/licensing/TermsHooks.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -pragma solidity ^0.8.19; - -library TermsHooks { - // ShareAlike is so universal it could be enshrined in - // the protocol itself - struct ShareAlike { - bool enabled; - } - -} diff --git a/contracts/lib/modules/Licensing.sol b/contracts/lib/modules/Licensing.sol index fff51505..aad56fa9 100644 --- a/contracts/lib/modules/Licensing.sol +++ b/contracts/lib/modules/Licensing.sol @@ -59,14 +59,4 @@ library Licensing { } bytes32 constant LICENSING_FRAMEWORK_CONFIG = keccak256("LICENSING_FRAMEWORK_CONFIG"); -} - -library TermCategories { - string constant FORMAT_CATEGORIES = "FORMAT_CATEGORIES"; -} - -/// @dev must be < 32 bytes long, or they will blow up at some point -/// see https://docs.openzeppelin.com/contracts/4.x/api/utils#ShortStrings -library TermIds { - string constant SHARE_ALIKE = "SHARE_ALIKE"; -} +} \ No newline at end of file diff --git a/contracts/lib/modules/LicensingTerms.sol b/contracts/lib/modules/LicensingTerms.sol new file mode 100644 index 00000000..e168b867 --- /dev/null +++ b/contracts/lib/modules/LicensingTerms.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.19; + +library TermCategories { + string constant FORMAT_CATEGORIES = "FORMAT_CATEGORIES"; +} + +/// @dev must be < 32 bytes long, or they will blow up at some point +/// see https://docs.openzeppelin.com/contracts/4.x/api/utils#ShortStrings +library TermIds { + string constant SHARE_ALIKE = "SHARE_ALIKE"; +} + +library TermData { + // ShareAlike is so universal it could be enshrined in + // the protocol itself + struct ShareAlike { + bool enabled; + } + +} \ No newline at end of file diff --git a/test/foundry/modules/licensing/LicenseCreatorModule.Terms.sol b/test/foundry/modules/licensing/LicenseCreatorModule.Terms.sol index 610a42aa..2b6ecd0f 100644 --- a/test/foundry/modules/licensing/LicenseCreatorModule.Terms.sol +++ b/test/foundry/modules/licensing/LicenseCreatorModule.Terms.sol @@ -6,7 +6,8 @@ import 'test/foundry/utils/BaseTest.sol'; import 'contracts/modules/relationships/RelationshipModule.sol'; import 'contracts/lib/modules/LibRelationship.sol'; import { AccessControl } from "contracts/lib/AccessControl.sol"; -import { Licensing, TermCategories, TermIds } from "contracts/lib/modules/Licensing.sol"; +import { Licensing } from "contracts/lib/modules/Licensing.sol"; +import { TermIds, TermCategories } from "contracts/lib/modules/LicensingTerms.sol"; import { OffChain } from "contracts/lib/OffChain.sol"; import { IHook } from "contracts/interfaces/hooks/base/IHook.sol"; import { IPAsset } from "contracts/lib/IPAsset.sol"; diff --git a/test/foundry/modules/licensing/LicensingCreatorModule.Config.t.sol b/test/foundry/modules/licensing/LicensingCreatorModule.Config.t.sol index b7ed3194..f60b099a 100644 --- a/test/foundry/modules/licensing/LicensingCreatorModule.Config.t.sol +++ b/test/foundry/modules/licensing/LicensingCreatorModule.Config.t.sol @@ -5,7 +5,8 @@ import "forge-std/Test.sol"; import "contracts/modules/relationships/RelationshipModule.sol"; import "contracts/lib/modules/LibRelationship.sol"; import { AccessControl } from "contracts/lib/AccessControl.sol"; -import { Licensing, TermCategories, TermIds } from "contracts/lib/modules/Licensing.sol"; +import { Licensing } from "contracts/lib/modules/Licensing.sol"; +import { TermCategories, TermIds } from "contracts/lib/modules/LicensingTerms.sol"; import { OffChain } from "contracts/lib/OffChain.sol"; import { IHook } from "contracts/interfaces/hooks/base/IHook.sol"; import { BaseLicensingTest } from "./BaseLicensingTest.sol"; diff --git a/test/foundry/modules/licensing/LicensingCreatorModule.Licensing.sol b/test/foundry/modules/licensing/LicensingCreatorModule.Licensing.sol index 2e6ff04f..91260213 100644 --- a/test/foundry/modules/licensing/LicensingCreatorModule.Licensing.sol +++ b/test/foundry/modules/licensing/LicensingCreatorModule.Licensing.sol @@ -6,7 +6,8 @@ import "test/foundry/utils/BaseTest.sol"; import "contracts/modules/relationships/RelationshipModule.sol"; import "contracts/lib/modules/LibRelationship.sol"; import { AccessControl } from "contracts/lib/AccessControl.sol"; -import { Licensing, TermCategories, TermIds } from "contracts/lib/modules/Licensing.sol"; +import { Licensing } from "contracts/lib/modules/Licensing.sol"; +import { TermCategories, TermIds } from "contracts/lib/modules/LicensingTerms.sol"; import { OffChain } from "contracts/lib/OffChain.sol"; import { IHook } from "contracts/interfaces/hooks/base/IHook.sol"; import { IPAsset } from "contracts/lib/IPAsset.sol";