Skip to content

Commit 0c1a677

Browse files
authored
Linting Enforcement on Periphery Contracts (#9)
* feat: bump & remove unused pkgs, add husky * fix: yarn lock * config: add to solhint * style: fix linting issues
1 parent 0dec3c1 commit 0c1a677

21 files changed

+473
-1792
lines changed

.husky/pre-push

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
yarn lint:sol:fix
5+
# recheck
6+
yarn solhint

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"plugins": ["prettier-plugin-solidity"],
23
"useTabs": false,
34
"printWidth": 120,
45
"trailingComma": "es5",
@@ -12,6 +13,12 @@
1213
"options": {
1314
"tabWidth": 2
1415
}
16+
},
17+
{
18+
"files": "*.sol",
19+
"options": {
20+
"singleQuote": false
21+
}
1522
}
1623
]
1724
}

.solhint.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
"plugins": ["prettier"],
44
"rules": {
55
"code-complexity": ["error", 8],
6-
"compiler-version": ["error", ">=0.8.19"],
6+
"compiler-version": ["error", ">=0.8.23"],
77
"const-name-snakecase": "off",
88
"no-empty-blocks": "off",
99
"constructor-syntax": "error",
1010
"func-visibility": ["error", { "ignoreConstructors": true }],
11-
"modifier-name-mixedcase": "error",
1211
"max-line-length": ["error", 120],
1312
"not-rely-on-time": "off",
1413
"reason-string": ["warn", { "maxLength": 64 }],
1514
"no-unused-import": "error",
16-
"no-unused-vars": "error",
15+
"no-unused-vars": "off",
1716
"no-inline-assembly": "off",
1817
"avoid-low-level-calls": "off",
1918
"no-global-import": "error",
2019
"prettier/prettier": "error",
21-
"private-vars-leading-underscore": "off"
20+
"private-vars-leading-underscore": "off",
21+
"func-name-mixedcase": "off",
22+
"var-name-mixedcase": "off",
23+
"modifier-name-mixedcase": "off"
2224
}
2325
}

contracts/StoryProtocolGateway.sol

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.23;
55
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
66
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
77
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
8+
// solhint-disable-next-line max-line-length
89
import { PILPolicy, PILPolicyFrameworkManager, RegisterPILPolicyParams } from "@storyprotocol/contracts/modules/licensing/PILPolicyFrameworkManager.sol";
910
import { BaseModule } from "@storyprotocol/contracts/modules/BaseModule.sol";
1011
import { IPAssetRegistry } from "@storyprotocol/contracts/registries/IPAssetRegistry.sol";
@@ -224,15 +225,11 @@ contract StoryProtocolGateway is BaseModule, ERC721SPNFTFactory, IStoryProtocolG
224225
_setCustomIpMetadata(ipId, ipMetadata.customMetadata);
225226
}
226227

227-
// TODO: Implement the function once `IPolicyFrameworkManager` has `registerPolicy` function exposed.
228-
// function createPolicy(address policyFrameworkManager, bytes memory policyData) external returns (uint256 policyId) {
229-
// policyId = IPolicyFrameworkManager(policyFrameworkManager).registerPolicy(policyData);
230-
// }
231-
232228
/// @notice Create a new policy to Licensing Module via the PIL Policy Framework Manager.
233229
/// @param pilPolicy The PIL policy to add to the Licensing Module.
234230
/// @param transferable Whether or not the license is transferable.
235-
/// @param royaltyPolicy Address of a royalty policy contract (e.g. RoyaltyPolicyLAP) that will handle royalty payments.
231+
/// @param royaltyPolicy Address of a royalty policy contract (e.g. RoyaltyPolicyLAP) that will handle royalty
232+
/// payments.
236233
/// @param mintingFee Fee to be paid when minting a license.
237234
/// @param mintingFeeToken Token to be used to pay the minting fee.
238235
/// @return policyId The ID of the newly registered policy.
@@ -257,7 +254,8 @@ contract StoryProtocolGateway is BaseModule, ERC721SPNFTFactory, IStoryProtocolG
257254
/// @notice Add a PIL policy to an IPAsset. Create a new PIL policy if it doesn't exist.
258255
/// @param pilPolicy The PIL policy to add to the Licensing Module.
259256
/// @param transferable Whether or not the license is transferable.
260-
/// @param royaltyPolicy Address of a royalty policy contract (e.g. RoyaltyPolicyLAP) that will handle royalty payments.
257+
/// @param royaltyPolicy Address of a royalty policy contract (e.g. RoyaltyPolicyLAP) that will handle royalty
258+
/// payments.
261259
/// @param mintingFee Fee to be paid when minting a license.
262260
/// @param mintingFeeToken Token to be used to pay the minting fee.
263261
/// @param ipId The address of the IP asset to add the policy to.
@@ -321,7 +319,8 @@ contract StoryProtocolGateway is BaseModule, ERC721SPNFTFactory, IStoryProtocolG
321319
/// @param amount The amount of licenses to mint.
322320
/// @param royaltyContext The bytes-encoded context for royalty policy to process.
323321
/// @param transferable Whether or not the license is transferable.
324-
/// @param royaltyPolicy Address of a royalty policy contract (e.g. RoyaltyPolicyLAP) that will handle royalty payments.
322+
/// @param royaltyPolicy Address of a royalty policy contract (e.g. RoyaltyPolicyLAP) that will handle royalty
323+
/// payments.
325324
/// @param mintingFee Fee to be paid when minting a license.
326325
/// @param mintingFeeToken Token to be used to pay the minting fee.
327326
/// @return licenseId The ID of the minted license NFT.

contracts/interfaces/nft/IERC721SPNFT.sol

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.23;
33

4-
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
54
import { IStoryProtocolToken } from "../IStoryProtocolToken.sol";
65

76
/// @title ERC-721 Story Protocol NFT Interface

package.json

+18-13
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,31 @@
88
"test": "test"
99
},
1010
"scripts": {
11-
"lint": "npm run lint:solidity && npm run lint:javascript",
12-
"lint:javascript": "eslint ./",
13-
"lint:solidity": "solhint \"contracts/**/*.sol\" \"test/**/*.sol\"",
14-
"test": "npx hardhat test"
11+
"lint": "npm run lint:js && npm run lint:sol",
12+
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
13+
"lint:js": "prettier --log-level warn --ignore-path .gitignore '**/*.{js,ts}' --check && eslint --ignore-path .gitignore .",
14+
"lint:js:fix": "prettier --log-level warn --ignore-path .gitignore '**/*.{js,ts}' --write && eslint --ignore-path .gitignore . --fix",
15+
"lint:sol": "prettier --log-level warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --check && solhint '{contracts,test}/**/*.sol'",
16+
"lint:sol:fix": "prettier --log-level warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --write",
17+
"solhint": "solhint '{contracts,test}/**/*.sol'",
18+
"test": "npx hardhat test",
19+
"prepare": "husky install"
1520
},
1621
"author": "StoryProtocol",
1722
"license": "BUSL-1.1",
1823
"devDependencies": {
19-
"chai": "^4.3.7",
20-
"dotenv": "^16.0.3",
21-
"eslint": "^8.38.0",
22-
"eslint-plugin-prettier": "^4.2.1",
23-
"ethereum-waffle": "^4.0.10",
24+
"chai": "^5.0.3",
25+
"dotenv": "^16.4.1",
26+
"eslint": "^8.56.0",
27+
"eslint-plugin-prettier": "^5.1.3",
2428
"ethers": "^6.10.0",
29+
"husky": "^9.0.11",
2530
"mocha": "^10.2.0",
26-
"prettier": "2.8.7",
31+
"prettier": "^3.0.0",
2732
"prettier-plugin-solidity": "^1.1.3",
28-
"solhint": "^3.4.1",
29-
"solhint-plugin-prettier": "^0.0.5",
30-
"solidity-coverage": "^0.8.2",
33+
"solhint": "^4.1.1",
34+
"solhint-plugin-prettier": "^0.1.0",
35+
"solidity-coverage": "^0.8.6",
3136
"ts-node": "^10.9.2",
3237
"typechain": "^8.3.2"
3338
},

remappings.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@ensdomains/=node_modules/@ensdomains/
2-
@ethereum-waffle/=node_modules/@ethereum-waffle/
32
@openzeppelin/=node_modules/@openzeppelin/
43
@storyprotocol/=node_modules/@story-protocol/protocol-core/
54
@storyprotocol-old/=node_modules/@storyprotocol/contracts-old/

test/StoryProtocolGateway.t.sol

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@ pragma solidity ^0.8.23;
44
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
55

66
import { IPAssetRegistry } from "@storyprotocol/contracts/registries/IPAssetRegistry.sol";
7-
import { LicensingModule } from "@storyprotocol/contracts/modules/licensing/LicensingModule.sol";
87
import { ILicensingModule } from "@storyprotocol/contracts/interfaces/modules/licensing/ILicensingModule.sol";
98
import { IRoyaltyPolicyLAP } from "@storyprotocol/contracts/interfaces/modules/royalty/policies/IRoyaltyPolicyLAP.sol";
109
import { AccessPermission } from "@storyprotocol/contracts/lib/AccessPermission.sol";
1110
import { MetaTx } from "@storyprotocol/contracts/lib/MetaTx.sol";
1211
import { ModuleRegistry } from "@storyprotocol/contracts/registries/ModuleRegistry.sol";
12+
// solhint-disable-next-line max-line-length
1313
import { PILPolicy, IPILPolicyFrameworkManager, RegisterPILPolicyParams } from "@storyprotocol/contracts/interfaces/modules/licensing/IPILPolicyFrameworkManager.sol";
14-
import { IP } from "@storyprotocol/contracts/lib/IP.sol";
1514
import { AccessController } from "@storyprotocol/contracts/AccessController.sol";
1615
import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol";
1716
import { IPResolver } from "@storyprotocol/contracts/resolvers/IPResolver.sol";
18-
import { KeyValueResolver } from "@storyprotocol/contracts/resolvers/KeyValueResolver.sol";
1917

20-
import { stdJson } from "forge-std/StdJson.sol";
2118
import { MockERC721Cloneable } from "./mocks/nft/MockERC721Cloneable.sol";
2219
import { StoryProtocolCoreAddressManager } from "script/utils/StoryProtocolCoreAddressManager.sol";
2320
import { ForkTest } from "./utils/Fork.t.sol";
@@ -29,7 +26,6 @@ import { StoryProtocolGateway } from "contracts/StoryProtocolGateway.sol";
2926

3027
/// @title Story Protocol Gateway Test Contract
3128
contract StoryProtocolGatewayTest is ForkTest, StoryProtocolCoreAddressManager {
32-
3329
MockERC721Cloneable internal externalNFT;
3430
IPAssetRegistry internal ipAssetRegistry;
3531
ILicensingModule internal licensingModule;
@@ -67,7 +63,7 @@ contract StoryProtocolGatewayTest is ForkTest, StoryProtocolCoreAddressManager {
6763
bytes internal emptyRoyaltyPolicyLAPInitParams;
6864

6965
/// @notice The Story Protocol Gateway SUT.
70-
StoryProtocolGateway public spg;
66+
StoryProtocolGateway internal spg;
7167

7268
function setUp() public virtual override(ForkTest) {
7369
_readStoryProtocolCoreAddresses();
@@ -173,6 +169,7 @@ contract StoryProtocolGatewayTest is ForkTest, StoryProtocolCoreAddressManager {
173169
assertEq(nft.name(), SPG_DEFAULT_NFT_NAME);
174170
assertEq(nft.symbol(), SPG_DEFAULT_NFT_SYMBOL);
175171

172+
/* solhint-disable */
176173
string memory uriEncoding = string(
177174
abi.encodePacked(
178175
'{"description": "Test SPG contract", ',
@@ -181,6 +178,7 @@ contract StoryProtocolGatewayTest is ForkTest, StoryProtocolCoreAddressManager {
181178
'"name": "SPG Default Collection"}'
182179
)
183180
);
181+
/* solhint-enable */
184182
string memory expectedURI = string(
185183
abi.encodePacked(
186184
"data:application/json;base64,",
@@ -219,7 +217,7 @@ contract StoryProtocolGatewayTest is ForkTest, StoryProtocolCoreAddressManager {
219217

220218
address ipId = IPAssetRegistry(ipAssetRegistryAddr).ipId(block.chainid, address(externalNFT), 0);
221219

222-
uint deadline = block.timestamp + 1000;
220+
uint256 deadline = block.timestamp + 1000;
223221
AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](2);
224222
permissionList[0] = AccessPermission.Permission({
225223
ipAccount: ipId,
@@ -270,7 +268,7 @@ contract StoryProtocolGatewayTest is ForkTest, StoryProtocolCoreAddressManager {
270268
function _registerDerivativeIpWithSig(address ipId, Metadata.IPMetadata memory ipMetadata) internal {
271269
address derivativeIpId = IPAssetRegistry(ipAssetRegistryAddr).ipId(block.chainid, address(externalNFT), 1);
272270

273-
uint deadline = block.timestamp + 1000;
271+
uint256 deadline = block.timestamp + 1000;
274272
AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](2);
275273
permissionList[0] = AccessPermission.Permission({
276274
ipAccount: derivativeIpId,

test/mocks/MockStoryProtocolDrop.sol

-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.23;
33

4-
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
5-
64
import { IStoryProtocolDrop } from "contracts/interfaces/IStoryProtocolDrop.sol";
75
import { SPG } from "contracts/lib/SPG.sol";
86
import { ERC721SPNFTFactory } from "contracts/nft/ERC721SPNFTFactory.sol";
97

108
/// @title Mock Story Protocol Drop Contract
119
contract MockStoryProtocolDrop is ERC721SPNFTFactory, IStoryProtocolDrop {
12-
1310
/// @notice Keeps track of all created mints.
1411
mapping(address => SPG.MintSettings) public publicMints;
1512

@@ -33,5 +30,4 @@ contract MockStoryProtocolDrop is ERC721SPNFTFactory, IStoryProtocolDrop {
3330
function getMintSettings(address ipCollection) public view returns (SPG.MintSettings memory) {
3431
return publicMints[ipCollection];
3532
}
36-
3733
}

test/mocks/nft/MockERC721Cloneable.sol

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import { ERC721Cloneable } from "contracts/nft/ERC721Cloneable.sol";
55

66
/// @title Mock ERC721 Cloneable
77
contract MockERC721Cloneable is ERC721Cloneable {
8-
98
/// @notice Initializes the mock ERC721 cloneable contract.
10-
function initialize(
11-
string memory tokenName,
12-
string memory tokenSymbol
13-
) public initializer {
9+
function initialize(string memory tokenName, string memory tokenSymbol) public initializer {
1410
__ERC721Cloneable_init(tokenName, tokenSymbol);
1511
}
1612

@@ -30,4 +26,3 @@ contract MockERC721Cloneable is ERC721Cloneable {
3026
return "";
3127
}
3228
}
33-

test/mocks/nft/MockERC721MetadataProvider.sol

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ pragma solidity ^0.8.23;
33

44
import { IERC721MetadataProvider } from "contracts/interfaces/nft/IERC721MetadataProvider.sol";
55
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
6-
import { Errors } from "contracts/lib/Errors.sol";
76

87
/// @title Mock ERC-721 Metadata Provider
98
contract MockERC721MetadataProvider is IERC721MetadataProvider, Initializable {
10-
119
/// @dev Sample metadata schema that the provider requires for tokens.
1210
struct TokenMetadata {
1311
string url;
@@ -23,10 +21,10 @@ contract MockERC721MetadataProvider is IERC721MetadataProvider, Initializable {
2321
mapping(uint256 => bytes) internal _metadata;
2422

2523
/// @dev Tracks the token associated with the metadata provider.
26-
address _token;
27-
24+
address internal _token;
25+
2826
/// @dev Tracks the contract URL.
29-
string _contractURL;
27+
string internal _contractURL;
3028

3129
/// @notice Initializes the metadata provider for the provided erc-721 token.
3230
/// @param tokenAddr The address of the ERC-721 metadata is being provided for.

test/mocks/nft/MockERC721Receiver.sol

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.23;
33

4-
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
4+
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
55

66
import { Errors } from "contracts/lib/Errors.sol";
77

88
/// @title Mock ERC-721 Receiver
99
/// @notice This contract is used to test ERC-721 safe transfers.
1010
contract MockERC721Receiver is IERC721Receiver {
11-
1211
/// @notice Custom event used to vet whether a receive was successful.
1312
event ERC721Received(address operator, address from, uint256 tokenId, bytes data);
1413

test/mocks/nft/MockERC721SPNFT.sol

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// SPDX-License-Identifier: BUSL-1.1
32
pragma solidity ^0.8.23;
43

@@ -10,7 +9,6 @@ import { SPG } from "contracts/lib/SPG.sol";
109

1110
/// @title Mock ERC721 Cloneable
1211
contract MockERC721SPNFT is IERC721SPNFT, ERC721Cloneable {
13-
1412
/// @dev Gets the current metadata provider used for new NFTs in the collection.
1513
IERC721MetadataProvider internal _metadataProvider;
1614

@@ -68,8 +66,5 @@ contract MockERC721SPNFT is IERC721SPNFT, ERC721Cloneable {
6866
}
6967

7068
/// @notice Configures the minting settings for an ongoing Story Protocol mint.
71-
function configureMint(
72-
address spg,
73-
SPG.MintSettings calldata mintSettings
74-
) external {}
69+
function configureMint(address spg, SPG.MintSettings calldata mintSettings) external {}
7570
}

test/nft/erc721/ERC721Base.t.sol

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ pragma solidity ^0.8.23;
44
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
55
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
66
import { MockERC721Receiver } from "test/mocks/nft/MockERC721Receiver.sol";
7-
import { BaseTest } from "test/utils/Base.t.sol";
87
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
98
import { TransferHelper } from "./TransferHelper.sol";
109
import { Errors } from "contracts/lib/Errors.sol";
1110

1211
/// @title ERC721 Base Test Contract
1312
/// @notice Base contract for testing standard ERC721 functionality.
1413
abstract contract ERC721BaseTest is TransferHelper {
15-
1614
// Expected return value by contract recipients for ERC-721 safe transfers.
17-
bytes4 constant ERC721_RECEIVER_MAGIC_VALUE = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
15+
bytes4 internal constant ERC721_RECEIVER_MAGIC_VALUE =
16+
bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
1817

1918
/// @notice The ERC721 token contract SUT.
20-
IERC721Metadata public token;
19+
IERC721Metadata internal token;
2120

2221
/// @notice Initializes the base ERC721 contract for testing.
2322
function setUp() public virtual override(TransferHelper) {
@@ -133,9 +132,8 @@ abstract contract ERC721BaseTest is TransferHelper {
133132
}
134133

135134
/// @dev Gets the expected name for the ERC721 contract.
136-
function _expectedName() internal virtual pure returns (string memory);
135+
function _expectedName() internal pure virtual returns (string memory);
137136

138137
/// @dev Gets the expected symbol for the ERC721 contract.
139-
function _expectedSymbol() internal virtual pure returns (string memory);
140-
138+
function _expectedSymbol() internal pure virtual returns (string memory);
141139
}

test/nft/erc721/ERC721Cloneable.t.sol

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Errors } from "contracts/lib/Errors.sol";
88

99
/// @title ERC721 Cloneable Test Contract
1010
contract ERC721CloneableTest is ERC721BaseTest {
11-
1211
string internal constant _NAME = "MOCK_NAME";
1312
string internal constant _SYMBOL = "MOCK_SYMBOL";
1413
MockERC721Cloneable public cloneable;
@@ -86,13 +85,12 @@ contract ERC721CloneableTest is ERC721BaseTest {
8685
}
8786

8887
/// @dev Gets the expected name for the ERC721 contract.
89-
function _expectedName() internal virtual pure override returns (string memory) {
88+
function _expectedName() internal pure virtual override returns (string memory) {
9089
return _NAME;
9190
}
9291

9392
/// @dev Gets the expected symbol for the ERC721 contract.
94-
function _expectedSymbol() internal virtual pure override returns (string memory) {
93+
function _expectedSymbol() internal pure virtual override returns (string memory) {
9594
return _SYMBOL;
9695
}
97-
9896
}

0 commit comments

Comments
 (0)