@1inch/solidity-utils 5.2.3 → 5.3.0

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.
@@ -0,0 +1,38 @@
1
+ {{h}} {{name}}
2
+
3
+ {{#if signature}}
4
+ ```solidity
5
+ {{{signature}}}
6
+ ```
7
+ {{/if}}
8
+ {{{natspec.notice}}}
9
+
10
+ {{#if natspec.dev}}
11
+ _{{{natspec.dev}}}_
12
+ {{/if}}
13
+
14
+ {{#if params}}
15
+ {{#if (arrayHasDescriptions params)}}
16
+ {{h 2}} Parameters
17
+
18
+ | Name | Type | Description |
19
+ | ---- | ---- | ----------- |
20
+ {{#each params}}
21
+ | {{name}} | {{type}} | {{{joinLines natspec}}} |
22
+ {{/each}}
23
+ {{/if}}
24
+ {{/if}}
25
+
26
+ {{#if returns}}
27
+ {{#if (arrayHasDescriptions returns)}}
28
+
29
+ {{h 2}} Return Values
30
+
31
+ | Name | Type | Description |
32
+ | ---- | ---- | ----------- |
33
+ {{#each returns}}
34
+ {{#if name}}{{name}}{{else}}[{{@index}}]{{/if}} | {{type}} | {{{joinLines natspec}}} |
35
+ {{/each}}
36
+ {{/if}}
37
+ {{/if}}
38
+
@@ -0,0 +1,73 @@
1
+ {{>common}}
2
+
3
+ {{#if types}}
4
+ {{h 2}} Types list
5
+ {{#each types}}
6
+ - [{{name}}](#{{lower name}})
7
+ {{/each}}
8
+ {{/if}}
9
+
10
+ {{#if functions}}
11
+ {{h 2}} Functions list
12
+ {{#each functions}}
13
+ {{>signature}}
14
+ {{/each}}
15
+ {{/if}}
16
+
17
+ {{#if events}}
18
+ {{h 2}} Events list
19
+ {{#each events}}
20
+ {{>signature}}
21
+ {{/each}}
22
+ {{/if}}
23
+
24
+ {{#if errors}}
25
+ {{h 2}} Errors list
26
+ {{#each errors}}
27
+ {{>signature}}
28
+ {{/each}}
29
+ {{/if}}
30
+
31
+ {{#if types}}
32
+ {{h 2}} Types
33
+ {{#hsection}}
34
+ {{#each types}}
35
+ {{>item}}
36
+ {{/each}}
37
+ {{/hsection}}
38
+ {{/if}}
39
+
40
+ {{#if functions}}
41
+ {{h 2}} Functions
42
+ {{#hsection}}
43
+ {{#each functions}}
44
+ {{>function}}
45
+ {{/each}}
46
+ {{/hsection}}
47
+ {{/if}}
48
+
49
+ {{#if events}}
50
+ {{h 2}} Events
51
+ {{#hsection}}
52
+ {{#each events}}
53
+ {{>common}}
54
+ {{/each}}
55
+ {{/hsection}}
56
+ {{/if}}
57
+
58
+ {{#if errors}}
59
+ {{h 2}} Errors
60
+ {{#hsection}}
61
+ {{#each errors}}
62
+ {{>common}}
63
+ {{/each}}
64
+ {{/hsection}}
65
+ {{/if}}
66
+
67
+ {{!--
68
+ {{#each items}}
69
+ {{#hsection}}
70
+ {{>item}}
71
+ {{/hsection}}
72
+ {{/each}}
73
+ --}}
@@ -0,0 +1,9 @@
1
+ {{>common}}
2
+
3
+ ```solidity
4
+ enum {{name}} {
5
+ {{#each members}}
6
+ {{name}}{{#unless @last}},{{/unless}}
7
+ {{/each}}
8
+ }
9
+ ```
@@ -0,0 +1 @@
1
+ {{>common}}
@@ -0,0 +1 @@
1
+ {{>common}}
@@ -0,0 +1 @@
1
+ {{>common}}
@@ -0,0 +1,76 @@
1
+ exports.lower = lower;
2
+ exports.isContract = isContract;
3
+ exports.getFunctionsToDisplay = getFunctionsToDisplay;
4
+ exports.findContractById = findContractById;
5
+ exports.arrayHasDescriptions = arrayHasDescriptions;
6
+ // exports
7
+
8
+ function lower (text) {
9
+ if (typeof text === 'string') {
10
+ return text.toLowerCase();
11
+ }
12
+ }
13
+
14
+ function isContract(item){
15
+ return item != undefined && item.nodeType === 'ContractDefinition';
16
+ }
17
+
18
+ function arrayHasDescriptions(items){
19
+ if (items != undefined){
20
+ return items.map(item => item.natspec).filter(natspec => natspec !== undefined).length > 0;
21
+ }
22
+ return false;
23
+ }
24
+
25
+ function getFunctionsToDisplay (baseContractIds, allContracts){
26
+ const resultMap = [];
27
+ if (baseContractIds.length > 0){
28
+ primaryContractFns = getContractFunctions(baseContractIds[0], allContracts);
29
+ primaryContractFns.map(fn => resultMap.push({id: baseContractIds[0], fnId: fn.id, selector: fn.functionSelector, name: fn.name}));
30
+
31
+ for(let i=1; i < baseContractIds.length; i++) {
32
+ const baseContractId = baseContractIds[i];
33
+ const functions = getContractFunctions(baseContractId, allContracts);
34
+
35
+ const newFn = functions.filter(fn => {
36
+ //console.log(fn);
37
+ //console.log(baseContractId, fn.id, fn.name, fn.functionSelector);
38
+ const exclude = fn.kind === 'constructor' && !(fn.visibility === 'public' || fn.visibility === 'external');
39
+ const include = resultMap.find(item => item.selector === fn.functionSelector);
40
+ return !exclude && !include;
41
+ });
42
+
43
+ newFn.map(fn => resultMap.push({id: fn.scope, fnId: fn.id, selector: fn.functionSelector, name: fn.name}));
44
+ }
45
+ }
46
+
47
+ resultArray = Object.values(resultMap.reduce((acc, item) => {
48
+ if (!acc[item.id]) {
49
+ acc[item.id] = {
50
+ id: item.id,
51
+ functions: []
52
+ };
53
+ }
54
+ acc[item.id].functions.push({
55
+ fnId: item.fnId,
56
+ selector: item.selector,
57
+ name: item.name
58
+ });
59
+ return acc;
60
+ }, {}));
61
+
62
+ //console.log(resultArray);
63
+
64
+ return resultArray;
65
+ }
66
+
67
+ function findContractById (id, allContracts) {
68
+ return allContracts.find(contract => contract.id === id);
69
+ }
70
+
71
+ // helpers
72
+
73
+ getContractFunctions = (id, allContracts) => {
74
+ const contract = findContractById(id, allContracts);
75
+ return contract ? contract.functions : [];
76
+ }
@@ -0,0 +1 @@
1
+ {{>common}}
@@ -0,0 +1,7 @@
1
+ {{#each items}}
2
+
3
+ {{#hsection}}
4
+ {{>item}}
5
+ {{/hsection}}
6
+
7
+ {{/each}}
@@ -0,0 +1 @@
1
+ - [{{name}}({{#each parameters.parameters}}{{name}}{{#unless @last}}, {{/unless}}{{/each}}) {{visibility}}](#{{lower name}})
@@ -0,0 +1,9 @@
1
+ {{>common}}
2
+
3
+ ```solidity
4
+ struct {{name}} {
5
+ {{#each members}}
6
+ {{{typeName.typeDescriptions.typeString}}} {{name}};
7
+ {{/each}}
8
+ }
9
+ ```
@@ -0,0 +1 @@
1
+ {{>common}}
@@ -0,0 +1 @@
1
+ {{>common}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/solidity-utils",
3
- "version": "5.2.3",
3
+ "version": "5.3.0",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "exports": {
@@ -103,6 +103,7 @@
103
103
  "contracts/interfaces",
104
104
  "contracts/libraries",
105
105
  "contracts/mixins",
106
- "contracts/mocks"
106
+ "contracts/mocks",
107
+ "docgen/templates"
107
108
  ]
108
109
  }
package/utils/README.md CHANGED
@@ -35,7 +35,7 @@ const { oneInchTemplates } = require('@1inch/solidity-utils/docgen');
35
35
  module.exports = {
36
36
  ...
37
37
  docgen: {
38
- outputDir: "docs", // Can be omitted, docs used by default
38
+ outputDir: 'docs', // Can be omitted, docs used by default
39
39
  templates: oneInchTemplates(), // 1inch templates
40
40
  pages: 'files', // Doc output format for 1inch templates
41
41
  exclude: ['mocks', 'test'], // Directories to exclude from generation