Skip to content

Commit

Permalink
refactor licensing term libs
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Nov 13, 2023
1 parent 661711f commit 7aafd29
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
8 changes: 4 additions & 4 deletions contracts/hooks/licensing/TermsHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 *;
Expand All @@ -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();
}
Expand All @@ -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 "";
}
Expand Down
11 changes: 0 additions & 11 deletions contracts/lib/hooks/licensing/TermsHooks.sol

This file was deleted.

12 changes: 1 addition & 11 deletions contracts/lib/modules/Licensing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
21 changes: 21 additions & 0 deletions contracts/lib/modules/LicensingTerms.sol
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 7aafd29

Please sign in to comment.