@1inch/solidity-utils 2.0.6 → 2.0.9
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.
- package/README.md +22 -3
- package/package.json +7 -5
- package/utils/contract.hbs +69 -0
- package/utils/docify.utils.js +130 -0
- package/utils/solidity-docgen-helpers.js +31 -0
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://github.com/1inch/farming/blob/master/.github/1inch_github_w.svg#gh-light-mode-only">
|
|
3
|
+
<img src="https://github.com/1inch/farming/blob/master/.github/1inch_github_b.svg#gh-dark-mode-only">
|
|
4
|
+
</div>
|
|
4
5
|
|
|
5
6
|
# Utils library for contracts and tests
|
|
6
7
|
|
|
@@ -44,4 +45,22 @@ This repository contains frequently used smart contracts, libraries and interfac
|
|
|
44
45
|
|
|
45
46
|
### UTILS
|
|
46
47
|
|
|
48
|
+
#### Docify
|
|
49
|
+
|
|
50
|
+
Generates documentation in markdown format from natspec docs
|
|
51
|
+
|
|
52
|
+
##### Usage
|
|
53
|
+
Add to `package.json` file solidity compiler version and shortcut to run command
|
|
54
|
+
|
|
55
|
+
`devDependencies` section
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
"solc": "0.8.12",
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`scripts` section
|
|
62
|
+
```
|
|
63
|
+
"docify": "npx solidity-utils-docify"
|
|
64
|
+
```
|
|
65
|
+
|
|
47
66
|
...
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1inch/solidity-utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -25,13 +25,14 @@
|
|
|
25
25
|
"typechain": "hardhat typechain"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@metamask/eth-sig-util": "
|
|
28
|
+
"@metamask/eth-sig-util": "4.0.0",
|
|
29
29
|
"@openzeppelin/contracts": "4.5.0",
|
|
30
30
|
"@openzeppelin/test-helpers": "0.5.15",
|
|
31
|
+
"bn.js": "5.2.0",
|
|
31
32
|
"chai": "4.3.6",
|
|
32
33
|
"chai-as-promised": "7.1.1",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
34
|
+
"chai-bn": "0.3.1",
|
|
35
|
+
"ethereumjs-util": "7.1.4",
|
|
35
36
|
"web3-utils": "1.7.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
@@ -46,7 +47,6 @@
|
|
|
46
47
|
"@types/node": "17.0.18",
|
|
47
48
|
"@typescript-eslint/eslint-plugin": "5.12.0",
|
|
48
49
|
"@typescript-eslint/parser": "5.12.0",
|
|
49
|
-
"chai-bn": "0.3.1",
|
|
50
50
|
"create-ts-index": "^1.14.0",
|
|
51
51
|
"cross-spawn": "7.0.3",
|
|
52
52
|
"dotenv": "16.0.0",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"eslint-plugin-promise": "6.0.0",
|
|
58
58
|
"eslint-plugin-standard": "5.0.0",
|
|
59
59
|
"eslint-plugin-typescript": "0.14.0",
|
|
60
|
+
"hardhat": "2.8.4",
|
|
60
61
|
"hardhat-deploy": "0.10.5",
|
|
61
62
|
"hardhat-gas-reporter": "1.0.8",
|
|
62
63
|
"rimraf": "3.0.2",
|
|
@@ -80,6 +81,7 @@
|
|
|
80
81
|
"files": [
|
|
81
82
|
"./dist",
|
|
82
83
|
"./*.MD",
|
|
84
|
+
"./utils",
|
|
83
85
|
"contracts/*.sol",
|
|
84
86
|
"contracts/interfaces",
|
|
85
87
|
"contracts/libraries"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# {{{name}}}
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
{{{natspec.title}}}
|
|
5
|
+
{{{natspec.userdoc}}}
|
|
6
|
+
{{{natspec.devdoc}}}
|
|
7
|
+
|
|
8
|
+
{{#if (withoutFirstElement inheritance)}}
|
|
9
|
+
## Derives
|
|
10
|
+
{{/if}}
|
|
11
|
+
{{#each (withoutFirstElement inheritance)}}
|
|
12
|
+
{{#if (getRelativeDocPath name source.contractsDir source.solcOutput.sources)}}
|
|
13
|
+
- [{{name}}]({{getRelativeDocPath name source.contractsDir source.solcOutput.sources}})
|
|
14
|
+
{{else}}
|
|
15
|
+
- {{name}}
|
|
16
|
+
{{/if}}
|
|
17
|
+
{{/each}}
|
|
18
|
+
|
|
19
|
+
{{#if ownFunctions}}
|
|
20
|
+
## Functions
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#ownFunctions}}
|
|
23
|
+
### {{name}}
|
|
24
|
+
```solidity
|
|
25
|
+
function {{name}}(
|
|
26
|
+
{{#args}}
|
|
27
|
+
{{type}} {{name}}{{#if @last}}{{else}},{{/if}}
|
|
28
|
+
{{/args}}
|
|
29
|
+
) {{visibility}}{{#if outputs}} returns ({{outputs}}){{/if}}
|
|
30
|
+
```
|
|
31
|
+
{{#if natspec.userdoc}}{{natspec.userdoc}}{{/if}}
|
|
32
|
+
{{#if natspec.devdoc}}{{natspec.devdoc}}{{/if}}
|
|
33
|
+
{{#if args}}
|
|
34
|
+
#### Parameters:
|
|
35
|
+
| Name | Type | Description |
|
|
36
|
+
| :--- | :--- | :------------------------------------------------------------------- |
|
|
37
|
+
{{#args}}
|
|
38
|
+
|`{{name}}` | {{type}} | {{#with (lookup ../natspec.params @index)~}} {{ removeNewlines description }} {{/with}}
|
|
39
|
+
{{/args}}{{/if}}
|
|
40
|
+
{{#if natspec.returns}}
|
|
41
|
+
#### Return Values:
|
|
42
|
+
| Name | Type | Description |
|
|
43
|
+
| :----------------------------- | :------------ | :--------------------------------------------------------------------------- |
|
|
44
|
+
{{#natspec.returns}}
|
|
45
|
+
|`{{param}}`| {{#lookup ../outputs.types @index}}{{/lookup}} | {{{removeNewlines description}}}
|
|
46
|
+
{{/natspec.returns}}{{/if}}
|
|
47
|
+
{{/ownFunctions}}
|
|
48
|
+
{{#if ownEvents}}
|
|
49
|
+
## Events
|
|
50
|
+
{{/if}}
|
|
51
|
+
{{#ownEvents}}
|
|
52
|
+
### {{name}}
|
|
53
|
+
```solidity
|
|
54
|
+
event {{name}}(
|
|
55
|
+
{{#args}}
|
|
56
|
+
{{type}} {{name}}{{#if @last}}{{else}},{{/if}}
|
|
57
|
+
{{/args}}
|
|
58
|
+
)
|
|
59
|
+
```
|
|
60
|
+
{{#if natspec.userdoc}}{{natspec.userdoc}}{{/if}}
|
|
61
|
+
{{#if natspec.devdoc}}{{natspec.devdoc}}{{/if}}
|
|
62
|
+
{{#if args}}
|
|
63
|
+
#### Parameters:
|
|
64
|
+
| Name | Type | Description |
|
|
65
|
+
| :--- | :--- | :------------------------------------------------------------------- |
|
|
66
|
+
{{#args}}
|
|
67
|
+
|`{{name}}` | {{type}} | {{#with (lookup ../natspec.params @index)~}} {{ removeNewlines description }} {{/with}}
|
|
68
|
+
{{/args}}{{/if}}
|
|
69
|
+
{{/ownEvents}}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const SOLC_NPM_NAME = 'solc';
|
|
3
|
+
const BASE_DIR = 'docgen';
|
|
4
|
+
const SCRIPT_DIR = __dirname;
|
|
5
|
+
const INPUT_DIR = 'contracts';
|
|
6
|
+
const OUTPUT_DIR = `${BASE_DIR}/docs`;
|
|
7
|
+
const HELPERS_PATH = `${SCRIPT_DIR}/solidity-docgen-helpers.js`;
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const spawn = require('cross-spawn');
|
|
12
|
+
|
|
13
|
+
function getFileNameWithoutExtension (fileName) {
|
|
14
|
+
return fileName.substr(0, fileName.lastIndexOf('.'));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function runProcess (name, args) {
|
|
18
|
+
console.log(`running ${name} with args ${JSON.stringify(args)}`);
|
|
19
|
+
const result = spawn.sync(name, args, { stdio: ['inherit', 'inherit', 'pipe'] });
|
|
20
|
+
if (result.stderr.length > 0) {
|
|
21
|
+
throw new Error(result.stderr);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getReadmes (targetPath) {
|
|
26
|
+
let result = [];
|
|
27
|
+
const readmePath = path.join(targetPath, 'README.md');
|
|
28
|
+
if (!fs.existsSync(readmePath)) {
|
|
29
|
+
const content = `# ${path.basename(targetPath)}\n`;
|
|
30
|
+
result.push({ path: readmePath, content });
|
|
31
|
+
}
|
|
32
|
+
const childDirs = fs.readdirSync(targetPath, { withFileTypes: true }).filter(item => item.isDirectory());
|
|
33
|
+
for (const dir of childDirs) {
|
|
34
|
+
result = result.concat(getReadmes(path.join(targetPath, dir.name)));
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function generateReadmes (readmes) {
|
|
40
|
+
for (const readme of readmes) {
|
|
41
|
+
fs.writeFileSync(readme.path, readme.content);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getSummary (targetPath) {
|
|
46
|
+
function getSummaryRoot (summaryTargetPath, indentation) {
|
|
47
|
+
function specialCaseRoot (item) {
|
|
48
|
+
if (item.indentation >= 0) {
|
|
49
|
+
return item;
|
|
50
|
+
}
|
|
51
|
+
return ({
|
|
52
|
+
name: 'Main Readme',
|
|
53
|
+
path: item.path,
|
|
54
|
+
indentation: 0,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const items = fs.readdirSync(summaryTargetPath, { withFileTypes: true });
|
|
59
|
+
let result = [specialCaseRoot({
|
|
60
|
+
name: path.basename(summaryTargetPath),
|
|
61
|
+
path: path.relative(targetPath, path.join(summaryTargetPath, 'README.md')).replaceAll('\\', '/'),
|
|
62
|
+
indentation: indentation - 1,
|
|
63
|
+
})];
|
|
64
|
+
for (const dir of items.filter(item => item.isDirectory())) {
|
|
65
|
+
result = result.concat(getSummaryRoot(path.join(summaryTargetPath, dir.name), indentation + 1));
|
|
66
|
+
}
|
|
67
|
+
result = result
|
|
68
|
+
.concat(items
|
|
69
|
+
.filter(item => !item.isDirectory() &&
|
|
70
|
+
!item.name.endsWith('README.md') &&
|
|
71
|
+
!item.name.endsWith('SUMMARY.md'))
|
|
72
|
+
.map(file => ({
|
|
73
|
+
name: getFileNameWithoutExtension(file.name),
|
|
74
|
+
path: path.relative(targetPath, path.join(summaryTargetPath, file.name)).replaceAll('\\', '/'),
|
|
75
|
+
indentation,
|
|
76
|
+
})));
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function generateContent (summaryTree) {
|
|
81
|
+
const lines = summaryTree.map(x => `${'\t'.repeat(x.indentation)}* [${x.name}](${x.path})`).join('\n');
|
|
82
|
+
return `# Table of contents\n\n${lines}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return generateContent(getSummaryRoot(targetPath, 0));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function generateSummary (targetPath, summary) {
|
|
89
|
+
fs.writeFileSync(path.join(targetPath, 'SUMMARY.md'), summary);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function generateGitbookFiles () {
|
|
93
|
+
if (fs.existsSync(path.join(BASE_DIR, 'README.md'))){
|
|
94
|
+
fs.copyFileSync(path.join(BASE_DIR, 'README.md'), path.join(OUTPUT_DIR, 'README.md'));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const readmesToGenerate = getReadmes(OUTPUT_DIR);
|
|
98
|
+
const summary = getSummary(OUTPUT_DIR);
|
|
99
|
+
|
|
100
|
+
generateReadmes(readmesToGenerate);
|
|
101
|
+
generateSummary(OUTPUT_DIR, summary);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function removeUnwantedDocs () {
|
|
105
|
+
const unwantedDirs = ['mocks', 'tests'];
|
|
106
|
+
for (const unwantedDir of unwantedDirs) {
|
|
107
|
+
fs.rmSync(path.join(OUTPUT_DIR, unwantedDir), { force: true, recursive: true });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const solidityDocgenArgs = [
|
|
112
|
+
'solidity-docgen',
|
|
113
|
+
'-i',
|
|
114
|
+
INPUT_DIR,
|
|
115
|
+
'-o',
|
|
116
|
+
OUTPUT_DIR,
|
|
117
|
+
'--solc-module',
|
|
118
|
+
SOLC_NPM_NAME,
|
|
119
|
+
'--solc-settings',
|
|
120
|
+
JSON.stringify({ optimizer: { enabled: false } }),
|
|
121
|
+
'--templates',
|
|
122
|
+
SCRIPT_DIR,
|
|
123
|
+
'--helpers',
|
|
124
|
+
HELPERS_PATH,
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
fs.rmSync(OUTPUT_DIR, { force: true, recursive: true });
|
|
128
|
+
runProcess('npx', solidityDocgenArgs);
|
|
129
|
+
generateGitbookFiles();
|
|
130
|
+
removeUnwantedDocs();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
removeNewlines (str) {
|
|
3
|
+
return str.replace(/\r?\n/g, ' ');
|
|
4
|
+
},
|
|
5
|
+
withoutFirstElement (arr) {
|
|
6
|
+
return arr.splice(1);
|
|
7
|
+
},
|
|
8
|
+
getRelativeDocPath (contractName, contractsDir, sources) {
|
|
9
|
+
function getRelativePath (contractPath) {
|
|
10
|
+
if (contractPath){
|
|
11
|
+
if (contractPath.startsWith(contractsDir)) {
|
|
12
|
+
return contractPath.substr(contractsDir.length + 1).replace('.sol', '.md');
|
|
13
|
+
}
|
|
14
|
+
if (contractPath.startsWith('@openzeppelin')) {
|
|
15
|
+
const regexMatch = contractPath.match(/@openzeppelin\/contracts\/(.+)\/([^/]+)\.sol/);
|
|
16
|
+
return `https://docs.openzeppelin.com/contracts/3.x/api/${regexMatch[1]}#${regexMatch[2]}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const sourcesKeys = Object.keys(sources);
|
|
23
|
+
const contractPath = sourcesKeys.find(x => x.includes(contractName));
|
|
24
|
+
|
|
25
|
+
if (!contractPath){
|
|
26
|
+
console.log('WARNING: file ' + contractName + '.sol not found in source files.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return getRelativePath(contractPath);
|
|
30
|
+
},
|
|
31
|
+
};
|