lens-modules 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +94 -0
  2. package/dist/index.js +17 -0
  3. package/package.json +8 -3
package/README.md CHANGED
@@ -12,6 +12,8 @@ npm i lens-modules
12
12
 
13
13
  ## Usage
14
14
 
15
+ Boilerplate for an Open Action module:
16
+
15
17
  ```solidity
16
18
  pragma solidity ^0.8.21;
17
19
 
@@ -36,6 +38,14 @@ contract OpenActionModule is
36
38
  // ...
37
39
  }
38
40
 
41
+ function supportsInterface(
42
+ bytes4 interfaceID
43
+ ) public pure virtual override returns (bool) {
44
+ return
45
+ interfaceID == type(IPublicationActionModule).interfaceId ||
46
+ super.supportsInterface(interfaceID);
47
+ }
48
+
39
49
  function initializePublicationAction(
40
50
  uint256 profileId,
41
51
  uint256 pubId,
@@ -51,4 +61,88 @@ contract OpenActionModule is
51
61
  // ...
52
62
  }
53
63
  }
64
+ ```
65
+
66
+ The library also has the contracts needed to create a Follow or Collect Module. Here's a basic example of a `CollectModule` that can be registered with the platform `CollectPublicationAction` contract.
67
+
68
+ ```solidity
69
+ // SPDX-License-Identifier: MIT
70
+ pragma solidity 0.8.23;
71
+
72
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
73
+ import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
74
+ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
75
+ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
76
+
77
+ import {Types} from "lens-modules/contracts/libraries/constants/Types.sol";
78
+ import {IPublicationActionModule} from "lens-modules/contracts/interfaces/IPublicationActionModule.sol";
79
+ import {HubRestricted} from "lens-modules/contracts/base/HubRestricted.sol";
80
+ import {IModuleRegistry} from "lens-modules/contracts/interfaces/IModuleRegistry.sol";
81
+ import {LensModuleMetadata} from "lens-modules/contracts/modules/LensModuleMetadata.sol";
82
+ import {LensModuleRegistrant} from "lens-modules/contracts/modules/base/LensModuleRegistrant.sol";
83
+ import {ICollectModule} from "lens-modules/contracts/modules/interfaces/ICollectModule.sol";
84
+ import {BaseFeeCollectModule} from "lens-modules/contracts/modules/act/collect/base/BaseFeeCollectModule.sol";
85
+ import {IBaseFeeCollectModule, BaseFeeCollectModuleInitData} from "lens-modules/contracts/modules/interfaces/IBaseFeeCollectModule.sol";
86
+ import {ModuleTypes} from "lens-modules/contracts/modules/libraries/constants/ModuleTypes.sol";
87
+ import {LensModule} from "lens-modules/contracts/modules/LensModule.sol";
88
+
89
+ contract YourCollectModule is BaseFeeCollectModule, LensModuleMetadata {
90
+ using SafeERC20 for IERC20;
91
+
92
+ constructor(
93
+ address hub,
94
+ address actionModule,
95
+ address moduleRegistry,
96
+ address moduleOwner
97
+ )
98
+ BaseFeeCollectModule(hub, actionModule, moduleRegistry)
99
+ LensModuleMetadata()
100
+ {}
101
+
102
+ function supportsInterface(
103
+ bytes4 interfaceID
104
+ ) public pure override(BaseFeeCollectModule, LensModule) returns (bool) {
105
+ return
106
+ BaseFeeCollectModule.supportsInterface(interfaceID) ||
107
+ LensModule.supportsInterface(interfaceID);
108
+ }
109
+
110
+ function initializePublicationCollectModule(
111
+ uint256 profileId,
112
+ uint256 pubId,
113
+ address /* transactionExecutor */,
114
+ bytes calldata data
115
+ ) external override onlyActionModule returns (bytes memory) {
116
+ BaseFeeCollectModuleInitData memory baseInitData = abi.decode(
117
+ data,
118
+ (BaseFeeCollectModuleInitData)
119
+ );
120
+ _validateBaseInitData(baseInitData);
121
+ _storeBasePublicationCollectParameters(profileId, pubId, baseInitData);
122
+ return data;
123
+ }
124
+
125
+ function calculateFee(
126
+ ModuleTypes.ProcessCollectParams calldata processCollectParams
127
+ ) public view virtual override returns (uint160) {
128
+ // Override calculateFee to add custom logic to calculate the fee
129
+ return
130
+ _dataByPublicationByProfile[processCollectParams.profileId][
131
+ processCollectParams.pubId
132
+ ].amount;
133
+ }
134
+
135
+ function processCollect(
136
+ ModuleTypes.ProcessCollectParams calldata processCollectParams
137
+ ) external override returns (bytes memory) {
138
+ _validateAndStoreCollect(processCollectParams);
139
+ // Override processCollect to add custom logic to process the collect
140
+ if (processCollectParams.referrerProfileIds.length == 0) {
141
+ _processCollect(processCollectParams);
142
+ } else {
143
+ _processCollectWithReferral(processCollectParams);
144
+ }
145
+ return processCollectParams.data;
146
+ }
147
+ }
54
148
  ```
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lens-contracts"), exports);
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "lens-modules",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "All interfaces and base classes from Lens core used for creating follow, collect, and open action modules",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
5
7
  "files": [
6
8
  "/contracts/**/*.sol"
7
9
  ],
8
10
  "scripts": {
9
11
  "compile": "hardhat compile",
10
- "clean": "hardhat clean"
12
+ "clean": "hardhat clean",
13
+ "build": "tsc",
14
+ "prepublish": "tsc"
11
15
  },
12
16
  "repository": {
13
17
  "type": "git",
@@ -27,6 +31,7 @@
27
31
  "license": "MIT",
28
32
  "devDependencies": {
29
33
  "@openzeppelin/contracts": "4.8.0",
30
- "hardhat": "^2.19.4"
34
+ "hardhat": "^2.19.4",
35
+ "typescript": "^5.4.2"
31
36
  }
32
37
  }