@1inch/solidity-utils 2.1.1 → 2.1.3
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 +62 -2
- package/contracts/GasChecker.sol +3 -1
- package/contracts/OnlyWethReceiver.sol +1 -1
- package/contracts/interfaces/IDaiLikePermit.sol +10 -2
- package/contracts/interfaces/IERC20MetadataUppercase.sol +3 -3
- package/contracts/interfaces/IWETH.sol +1 -1
- package/contracts/libraries/AddressArray.sol +27 -12
- package/contracts/libraries/AddressSet.sol +20 -6
- package/contracts/libraries/ECDSA.sol +61 -12
- package/contracts/libraries/RevertReasonForwarder.sol +2 -0
- package/contracts/libraries/RevertReasonParser.sol +9 -8
- package/contracts/libraries/SafeERC20.sol +66 -19
- package/contracts/libraries/StringUtil.sol +8 -6
- package/contracts/libraries/UniERC20.sol +45 -16
- package/contracts/mocks/TokenCustomDecimalsMock.sol +7 -2
- package/contracts/mocks/TokenMock.sol +0 -1
- package/dist/src/asserts.d.ts +1 -3
- package/dist/src/asserts.js +14 -21
- package/dist/src/asserts.js.map +1 -1
- package/dist/src/permit.d.ts +8 -23
- package/dist/src/permit.js +28 -26
- package/dist/src/permit.js.map +1 -1
- package/dist/src/prelude.d.ts +8 -14
- package/dist/src/prelude.js +10 -23
- package/dist/src/prelude.js.map +1 -1
- package/dist/src/profileEVM.d.ts +1 -0
- package/dist/src/profileEVM.js +31 -38
- package/dist/src/profileEVM.js.map +1 -1
- package/dist/src/utils.d.ts +7 -8
- package/dist/src/utils.js +13 -20
- package/dist/src/utils.js.map +1 -1
- package/package.json +16 -14
- package/utils/file-dependencies.js +203 -0
package/dist/src/profileEVM.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.gasspectEVM = exports.profileEVM = exports.gasspectOptionsDefault = void 0;
|
|
4
|
-
|
|
4
|
+
require("@nomiclabs/hardhat-ethers");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
const
|
|
6
|
+
const hardhat_1 = require("hardhat");
|
|
7
7
|
exports.gasspectOptionsDefault = {
|
|
8
8
|
minOpGasCost: 300,
|
|
9
9
|
args: false,
|
|
@@ -12,16 +12,21 @@ exports.gasspectOptionsDefault = {
|
|
|
12
12
|
function _normalizeOp(ops, i) {
|
|
13
13
|
if (ops[i].op === 'STATICCALL') {
|
|
14
14
|
ops[i].gasCost = ops[i].gasCost - ops[i + 1].gas;
|
|
15
|
-
if (ops[i].stack.length > 8 &&
|
|
15
|
+
if (ops[i].stack.length > 8 &&
|
|
16
|
+
ops[i].stack[ops[i].stack.length - 8] === '0000000000000000000000000000000000000000000000000000000000000001') {
|
|
16
17
|
ops[i].op = 'STATICCALL-ECRECOVER';
|
|
17
18
|
}
|
|
18
|
-
else if (ops[i].stack.length > 8 &&
|
|
19
|
+
else if (ops[i].stack.length > 8 &&
|
|
20
|
+
ops[i].stack[ops[i].stack.length - 8] <= '00000000000000000000000000000000000000000000000000000000000000FF') {
|
|
19
21
|
ops[i].op = 'STATICCALL-' + ops[i].stack[ops[i].stack.length - 8].substr(62, 2);
|
|
20
22
|
}
|
|
21
23
|
else {
|
|
22
24
|
ops[i].args = [
|
|
23
|
-
'0x' + ops[i].stack[ops[i].stack.length - 2].
|
|
24
|
-
'0x' +
|
|
25
|
+
'0x' + ops[i].stack[ops[i].stack.length - 2].substring(24),
|
|
26
|
+
'0x' +
|
|
27
|
+
(ops[i].memory || [])
|
|
28
|
+
.join('')
|
|
29
|
+
.substr(2 * Number(ops[i].stack[ops[i].stack.length - 3]), 2 * Number(ops[i].stack[ops[i].stack.length - 4])),
|
|
25
30
|
];
|
|
26
31
|
if (ops[i].gasCost === 100) {
|
|
27
32
|
ops[i].op += '_R';
|
|
@@ -30,8 +35,11 @@ function _normalizeOp(ops, i) {
|
|
|
30
35
|
}
|
|
31
36
|
if (['CALL', 'DELEGATECALL', 'CALLCODE'].indexOf(ops[i].op) !== -1) {
|
|
32
37
|
ops[i].args = [
|
|
33
|
-
'0x' + ops[i].stack[ops[i].stack.length - 2].
|
|
34
|
-
'0x' +
|
|
38
|
+
'0x' + ops[i].stack[ops[i].stack.length - 2].substring(24),
|
|
39
|
+
'0x' +
|
|
40
|
+
(ops[i].memory || [])
|
|
41
|
+
.join('')
|
|
42
|
+
.substr(2 * Number(ops[i].stack[ops[i].stack.length - 4]), 2 * Number(ops[i].stack[ops[i].stack.length - 5])),
|
|
35
43
|
];
|
|
36
44
|
ops[i].gasCost = ops[i].gasCost - ops[i + 1].gas;
|
|
37
45
|
ops[i].res = ops[i + 1].stack[ops[i + 1].stack.length - 1];
|
|
@@ -43,16 +51,14 @@ function _normalizeOp(ops, i) {
|
|
|
43
51
|
ops[i].gasCost = 3;
|
|
44
52
|
}
|
|
45
53
|
if (['SSTORE', 'SLOAD'].indexOf(ops[i].op) !== -1) {
|
|
46
|
-
ops[i].args = [
|
|
47
|
-
'0x' + ops[i].stack[ops[i].stack.length - 1],
|
|
48
|
-
];
|
|
54
|
+
ops[i].args = ['0x' + ops[i].stack[ops[i].stack.length - 1]];
|
|
49
55
|
if (ops[i].op === 'SSTORE') {
|
|
50
56
|
ops[i].args.push('0x' + ops[i].stack[ops[i].stack.length - 2]);
|
|
51
57
|
}
|
|
52
58
|
if (ops[i].gasCost === 100) {
|
|
53
59
|
ops[i].op += '_R';
|
|
54
60
|
}
|
|
55
|
-
if (ops[i].gasCost
|
|
61
|
+
if (ops[i].gasCost >= 20000) {
|
|
56
62
|
ops[i].op += '_I';
|
|
57
63
|
}
|
|
58
64
|
if (ops[i].op.startsWith('SLOAD')) {
|
|
@@ -60,43 +66,25 @@ function _normalizeOp(ops, i) {
|
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
if (ops[i].op === 'EXTCODESIZE') {
|
|
63
|
-
ops[i].args = [
|
|
64
|
-
'0x' + ops[i].stack[ops[i].stack.length - 1].substr(24),
|
|
65
|
-
];
|
|
69
|
+
ops[i].args = ['0x' + ops[i].stack[ops[i].stack.length - 1].substring(24)];
|
|
66
70
|
ops[i].res = ops[i + 1].stack[ops[i + 1].stack.length - 1];
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
async function profileEVM(txHash, instruction, optionalTraceFile) {
|
|
70
|
-
|
|
71
|
-
throw new Error('Unsupported provider');
|
|
72
|
-
}
|
|
73
|
-
const trace = await (0, util_1.promisify)(web3.currentProvider.send.bind(web3.currentProvider))({
|
|
74
|
-
jsonrpc: '2.0',
|
|
75
|
-
method: 'debug_traceTransaction',
|
|
76
|
-
params: [txHash, {}],
|
|
77
|
-
id: new Date().getTime(),
|
|
78
|
-
});
|
|
74
|
+
const trace = await hardhat_1.ethers.provider.send('debug_traceTransaction', [txHash]);
|
|
79
75
|
const str = JSON.stringify(trace);
|
|
80
76
|
if (optionalTraceFile) {
|
|
81
77
|
await fs_1.promises.writeFile(optionalTraceFile, str);
|
|
82
78
|
}
|
|
83
|
-
return instruction.map(instr => {
|
|
79
|
+
return instruction.map((instr) => {
|
|
84
80
|
return str.split('"' + instr.toUpperCase() + '"').length - 1;
|
|
85
81
|
});
|
|
86
82
|
}
|
|
87
83
|
exports.profileEVM = profileEVM;
|
|
88
84
|
async function gasspectEVM(txHash, gasspectOptions = {}, optionalTraceFile) {
|
|
89
85
|
const options = { ...exports.gasspectOptionsDefault, ...gasspectOptions };
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
const trace = await (0, util_1.promisify)(web3.currentProvider.send.bind(web3.currentProvider))({
|
|
94
|
-
jsonrpc: '2.0',
|
|
95
|
-
method: 'debug_traceTransaction',
|
|
96
|
-
params: [txHash, {}],
|
|
97
|
-
id: new Date().getTime(),
|
|
98
|
-
});
|
|
99
|
-
const ops = trace === null || trace === void 0 ? void 0 : trace.result.structLogs;
|
|
86
|
+
const trace = await hardhat_1.ethers.provider.send('debug_traceTransaction', [txHash]);
|
|
87
|
+
const ops = trace.structLogs;
|
|
100
88
|
const traceAddress = [0, -1];
|
|
101
89
|
for (const [i, op] of ops.entries()) {
|
|
102
90
|
op.traceAddress = traceAddress.slice(0, traceAddress.length - 1);
|
|
@@ -109,12 +97,17 @@ async function gasspectEVM(txHash, gasspectOptions = {}, optionalTraceFile) {
|
|
|
109
97
|
traceAddress.pop();
|
|
110
98
|
}
|
|
111
99
|
}
|
|
112
|
-
const result = ops
|
|
100
|
+
const result = ops
|
|
101
|
+
.filter((op) => op.gasCost > options.minOpGasCost)
|
|
102
|
+
.map((op) => op.traceAddress.join('-') +
|
|
103
|
+
'-' +
|
|
104
|
+
op.op +
|
|
113
105
|
(options.args ? '(' + (op.args || []).join(',') + ')' : '') +
|
|
114
106
|
(options.res ? (op.res ? ':0x' + op.res : '') : '') +
|
|
115
|
-
' = ' +
|
|
107
|
+
' = ' +
|
|
108
|
+
op.gasCost);
|
|
116
109
|
if (optionalTraceFile) {
|
|
117
|
-
await fs_1.promises.writeFile(optionalTraceFile, JSON.stringify(
|
|
110
|
+
await fs_1.promises.writeFile(optionalTraceFile, JSON.stringify(trace));
|
|
118
111
|
}
|
|
119
112
|
return result;
|
|
120
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profileEVM.js","sourceRoot":"","sources":["../../src/profileEVM.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"profileEVM.js","sourceRoot":"","sources":["../../src/profileEVM.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AACnC,2BAA8C;AAC9C,qCAAiC;AAEpB,QAAA,sBAAsB,GAAG;IAClC,YAAY,EAAE,GAAG;IACjB,IAAI,EAAE,KAAK;IACX,GAAG,EAAE,KAAK,EAAE,4BAA4B;CAC3C,CAAC;AAcF,SAAS,YAAY,CAAC,GAAS,EAAE,CAAS;IACtC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,YAAY,EAAE;QAC5B,GAAG,CAAC,CAAC,CAAC,CAAC,OA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;SACtB;KACJ;IAED,MAAM,MAAM,GAAG,GAAG;SACb,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;SACjD,GAAG,CACA,CAAC,EAAE,EAAE,EAAE,CACH,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;QACzB,GAAG;QACH,EAAE,CAAC,EAAE;QACL,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,KAAK;QACL,EAAE,CAAC,OAAO,CACjB,CAAC;IAEN,IAAI,iBAAiB,EAAE;QACnB,MAAM,aAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;KAChE;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AA5CD,kCA4CC"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import '@nomiclabs/hardhat-ethers';
|
|
2
2
|
import { constants } from './prelude';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function trackReceivedTokenAndTx<T extends unknown[], U extends Truffle.AnyEvent>(token: Token | {
|
|
3
|
+
import { Contract, Bytes, ContractTransaction } from 'ethers';
|
|
4
|
+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
|
|
5
|
+
export declare function timeIncreaseTo(seconds: number | string): Promise<void>;
|
|
6
|
+
export declare function trackReceivedTokenAndTx<T extends unknown[]>(token: Contract | {
|
|
8
7
|
address: typeof constants.ZERO_ADDRESS;
|
|
9
8
|
} | {
|
|
10
9
|
address: typeof constants.EEE_ADDRESS;
|
|
11
|
-
}, wallet: string, txPromise: (...args: T) => Promise<
|
|
10
|
+
}, wallet: string, txPromise: (...args: T) => Promise<ContractTransaction>, ...args: T): Promise<readonly [any, ContractTransaction]>;
|
|
12
11
|
export declare function fixSignature(signature: string): string;
|
|
13
|
-
export declare function signMessage(signer:
|
|
12
|
+
export declare function signMessage(signer: SignerWithAddress, messageHex?: string | Bytes): Promise<string>;
|
|
14
13
|
export declare function countInstructions(txHash: string, instructions: string[]): Promise<number[]>;
|
package/dist/src/utils.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.countInstructions = exports.signMessage = exports.fixSignature = exports.trackReceivedTokenAndTx = exports.timeIncreaseTo = void 0;
|
|
4
|
-
|
|
5
|
-
const
|
|
4
|
+
require("@nomiclabs/hardhat-ethers");
|
|
5
|
+
const hardhat_network_helpers_1 = require("@nomicfoundation/hardhat-network-helpers");
|
|
6
|
+
const hardhat_1 = require("hardhat");
|
|
6
7
|
async function timeIncreaseTo(seconds) {
|
|
7
8
|
const delay = 1000 - new Date().getMilliseconds();
|
|
8
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
9
|
-
await
|
|
9
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
10
|
+
await hardhat_network_helpers_1.time.increaseTo(seconds);
|
|
10
11
|
}
|
|
11
12
|
exports.timeIncreaseTo = timeIncreaseTo;
|
|
12
13
|
async function trackReceivedTokenAndTx(token, wallet, txPromise, ...args) {
|
|
13
14
|
const [balanceFunc, isETH] = 'balanceOf' in token
|
|
14
15
|
? [() => token.balanceOf(wallet), false]
|
|
15
|
-
: [async () =>
|
|
16
|
+
: [async () => await hardhat_1.ethers.provider.getBalance(wallet), true];
|
|
16
17
|
const preBalance = await balanceFunc();
|
|
17
18
|
const txResult = await txPromise(...args);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const txReceipt = await txResult.wait();
|
|
20
|
+
const txFees = wallet.toLowerCase() === txResult.from.toLowerCase() && isETH
|
|
21
|
+
? txReceipt.gasUsed.toBigInt() * txReceipt.effectiveGasPrice.toBigInt()
|
|
22
|
+
: 0n;
|
|
21
23
|
const postBalance = await balanceFunc();
|
|
22
24
|
return [postBalance.sub(preBalance).add(txFees), txResult];
|
|
23
25
|
}
|
|
@@ -34,23 +36,14 @@ function fixSignature(signature) {
|
|
|
34
36
|
return signature.slice(0, 130) + vHex;
|
|
35
37
|
}
|
|
36
38
|
exports.fixSignature = fixSignature;
|
|
37
|
-
// signs message in node (ganache auto-applies "Ethereum Signed Message" prefix)
|
|
38
39
|
async function signMessage(signer, messageHex = '0x') {
|
|
39
|
-
return fixSignature(await
|
|
40
|
+
return fixSignature(await signer.signMessage(messageHex));
|
|
40
41
|
}
|
|
41
42
|
exports.signMessage = signMessage;
|
|
42
43
|
async function countInstructions(txHash, instructions) {
|
|
43
|
-
|
|
44
|
-
throw new Error('Unsupported provider');
|
|
45
|
-
}
|
|
46
|
-
const trace = await (0, util_1.promisify)(web3.currentProvider.send.bind(web3.currentProvider))({
|
|
47
|
-
jsonrpc: '2.0',
|
|
48
|
-
method: 'debug_traceTransaction',
|
|
49
|
-
params: [txHash, {}],
|
|
50
|
-
id: new Date().getTime(),
|
|
51
|
-
});
|
|
44
|
+
const trace = await hardhat_1.ethers.provider.send('debug_traceTransaction', [txHash]);
|
|
52
45
|
const str = JSON.stringify(trace);
|
|
53
|
-
return instructions.map(instr => {
|
|
46
|
+
return instructions.map((instr) => {
|
|
54
47
|
return str.split('"' + instr.toUpperCase() + '"').length - 1;
|
|
55
48
|
});
|
|
56
49
|
}
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAEnC,sFAAgE;AAChE,qCAAiC;AAI1B,KAAK,UAAU,cAAc,CAAC,OAAwB;IACzD,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,eAAe,EAAE,CAAC;IAClD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,MAAM,8BAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAJD,wCAIC;AAEM,KAAK,UAAU,uBAAuB,CACzC,KAAwG,EACxG,MAAc,EACd,SAAuD,EACvD,GAAG,IAAO;IAEV,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GACtB,WAAW,IAAI,KAAK;QAChB,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;QACxC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,gBAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,MAAM,WAAW,EAAE,CAAC;IACvC,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACxC,MAAM,MAAM,GACR,MAAM,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,KAAK;QACzD,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE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CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACP,CAAC;AARD,8CAQC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1inch/solidity-utils",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"postbuild": "echo done",
|
|
15
15
|
"publishPackage": "yarn build && yarn publish",
|
|
16
16
|
"coverage": "hardhat coverage",
|
|
17
|
+
"format": "yarn format-ts && yarn format-sol",
|
|
18
|
+
"format-ts": "prettier '**/*.ts' --write",
|
|
19
|
+
"format-sol": "prettier '**/*.sol' --write",
|
|
17
20
|
"lint": "yarn run lint:ts && yarn run lint:sol",
|
|
18
21
|
"lint:fix": "yarn run lint:ts:fix && yarn run lint:sol:fix",
|
|
19
22
|
"lint:ts": "eslint . --ext .ts",
|
|
@@ -28,28 +31,24 @@
|
|
|
28
31
|
"dependencies": {
|
|
29
32
|
"@metamask/eth-sig-util": "4.0.1",
|
|
30
33
|
"@openzeppelin/contracts": "4.7.3",
|
|
31
|
-
"@openzeppelin/test-helpers": "0.5.16",
|
|
32
|
-
"bn.js": "5.2.1",
|
|
33
|
-
"chai": "4.3.6",
|
|
34
|
-
"chai-as-promised": "7.1.1",
|
|
35
|
-
"chai-bn": "0.3.1",
|
|
36
34
|
"ethereumjs-util": "7.1.5",
|
|
37
|
-
"
|
|
35
|
+
"ethers": "5.7.1"
|
|
38
36
|
},
|
|
39
37
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
38
|
+
"@nomicfoundation/hardhat-chai-matchers": "1.0.3",
|
|
39
|
+
"@nomicfoundation/hardhat-network-helpers": "1.0.6",
|
|
40
|
+
"@nomiclabs/hardhat-ethers": "2.1.1",
|
|
42
41
|
"@typechain/hardhat": "6.1.3",
|
|
43
|
-
"@typechain/
|
|
42
|
+
"@typechain/ethers-v5": "10.1.0",
|
|
44
43
|
"@types/chai": "4.3.3",
|
|
45
|
-
"@types/chai-as-promised": "7.1.5",
|
|
46
44
|
"@types/eth-sig-util": "2.1.1",
|
|
47
45
|
"@types/ethereumjs-util": "6.1.0",
|
|
48
46
|
"@types/mocha": "9.1.1",
|
|
49
|
-
"@types/node": "18.7.
|
|
47
|
+
"@types/node": "18.7.21",
|
|
50
48
|
"@typescript-eslint/eslint-plugin": "5.38.0",
|
|
51
49
|
"@typescript-eslint/parser": "5.38.0",
|
|
52
50
|
"acquit": "1.2.1",
|
|
51
|
+
"chai": "4.3.6",
|
|
53
52
|
"commander": "9.4.0",
|
|
54
53
|
"create-ts-index": "1.14.0",
|
|
55
54
|
"cross-spawn": "7.0.3",
|
|
@@ -63,17 +62,20 @@
|
|
|
63
62
|
"ethereumjs-wallet": "1.0.2",
|
|
64
63
|
"hardhat": "2.11.2",
|
|
65
64
|
"hardhat-gas-reporter": "1.0.9",
|
|
65
|
+
"prettier": "2.7.1",
|
|
66
|
+
"prettier-plugin-solidity": "1.0.0-beta.24",
|
|
66
67
|
"rimraf": "3.0.2",
|
|
67
68
|
"shx": "0.3.4",
|
|
68
69
|
"solhint": "3.3.7",
|
|
69
70
|
"solidity-coverage": "0.8.2",
|
|
70
71
|
"ts-node": "10.9.1",
|
|
71
|
-
"typechain": "
|
|
72
|
+
"typechain": "8.1.0",
|
|
72
73
|
"typescript": "4.8.3"
|
|
73
74
|
},
|
|
74
75
|
"bin": {
|
|
75
76
|
"solidity-utils-docify": "utils/docify.utils.js",
|
|
76
|
-
"test-docgen": "utils/test-docgen.js"
|
|
77
|
+
"test-docgen": "utils/test-docgen.js",
|
|
78
|
+
"imports-list": "utils/file-dependencies.js"
|
|
77
79
|
},
|
|
78
80
|
"bugs": {
|
|
79
81
|
"url": "https://github.com/1inch/solidity-utils/issues"
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const commander = require('commander');
|
|
6
|
+
const program = new commander.Command();
|
|
7
|
+
|
|
8
|
+
program
|
|
9
|
+
.name("imports-list")
|
|
10
|
+
.usage("-i <root file> [options]")
|
|
11
|
+
.requiredOption("-i, --input <input>", "file to get dependencies for")
|
|
12
|
+
.option("-a, --alias [alias...]", "alias list")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
program.parse(process.argv);
|
|
16
|
+
|
|
17
|
+
const options = program.opts();
|
|
18
|
+
// process input parameter
|
|
19
|
+
const rootPath = options.input;
|
|
20
|
+
// process alias parameter
|
|
21
|
+
const aliases = {};
|
|
22
|
+
const alias_opt = options.alias;
|
|
23
|
+
if (alias_opt != undefined && alias_opt.length > 0){
|
|
24
|
+
if (alias_opt.length % 2 == 0){
|
|
25
|
+
for(let i=0; i<alias_opt.length; i+=2){
|
|
26
|
+
aliases[alias_opt[i]] = alias_opt[i+1];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else{
|
|
30
|
+
let warning_notice = "\nWARNING:Skipping alias parameter, there are odd number of arguments.";
|
|
31
|
+
warning_notice += "\nAliases should be set in the form of pairs seperated by space.";
|
|
32
|
+
warning_notice += "\nUsage: -a alias1 path1 alias2 path2";
|
|
33
|
+
console.warn(warning_notice);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Script body
|
|
38
|
+
const regexp = /^import ({.+} from )?"(?<source>.+)";/gm;
|
|
39
|
+
|
|
40
|
+
const rootString = path.relative(process.cwd(), rootPath);
|
|
41
|
+
|
|
42
|
+
let rootNode = new Node(null, new NodeItem('root', rootPath, path.resolve(rootPath)));
|
|
43
|
+
let rootImports = extractImports(rootNode);
|
|
44
|
+
rootImports = flattenResults(rootImports);
|
|
45
|
+
|
|
46
|
+
// Scripts
|
|
47
|
+
|
|
48
|
+
function Node(parentItem, nodeItem){
|
|
49
|
+
this.parent = parentItem;
|
|
50
|
+
this.import = nodeItem;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function NodeItem(name, source, path){
|
|
54
|
+
this.name = name; // @1inch/solidity-utils/contracts/EthReceiver.sol
|
|
55
|
+
this.source = source; // ./contracts/EthReceiver.sol
|
|
56
|
+
this.path = path; // /usrs/james/Desktop/1inch/solidity-utils/contracts/EthReceiver.sol
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function extractFileImports(file){
|
|
60
|
+
let imports = [];
|
|
61
|
+
|
|
62
|
+
if (file == null)
|
|
63
|
+
return imports;
|
|
64
|
+
|
|
65
|
+
let content = fs.readFileSync(file);
|
|
66
|
+
let result = content.toString().matchAll(regexp);
|
|
67
|
+
|
|
68
|
+
for (const match of result) {
|
|
69
|
+
let source = match.groups['source'];
|
|
70
|
+
if (source != null){
|
|
71
|
+
imports.push(source);
|
|
72
|
+
}
|
|
73
|
+
else{
|
|
74
|
+
console.log('No source found for import: ', match);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return imports;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getAliasNameIfExists(source){
|
|
82
|
+
for(let alias in aliases){
|
|
83
|
+
if(source.startsWith(alias)){
|
|
84
|
+
return alias;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getAliasIfExists(source){
|
|
92
|
+
for(let alias in aliases){
|
|
93
|
+
if(source.startsWith(alias)){
|
|
94
|
+
source = source.replace(alias, aliases[alias]);
|
|
95
|
+
return source;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function isAlias(dependencyLink){
|
|
103
|
+
return dependencyLink.startsWith('@');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function resolveProject(parentProject, dependencyLink){
|
|
107
|
+
if (isAlias(dependencyLink)) {
|
|
108
|
+
let alias = getAliasNameIfExists(dependencyLink);
|
|
109
|
+
if (alias){
|
|
110
|
+
return alias;
|
|
111
|
+
}
|
|
112
|
+
else{
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else{
|
|
117
|
+
return parentProject;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function resolvePath(parentNode, dependencyLink){
|
|
122
|
+
if (isAlias(dependencyLink)) {
|
|
123
|
+
let alias = getAliasIfExists(dependencyLink)
|
|
124
|
+
if( alias ){
|
|
125
|
+
return path.join(process.cwd(), alias);
|
|
126
|
+
}
|
|
127
|
+
else{
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let source_dir = path.dirname(parentNode.path);
|
|
132
|
+
return path.join(source_dir, dependencyLink);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function resolveLinks(parentNode, dependencyLinks, nodes = []){
|
|
136
|
+
for (let dependencyLink of dependencyLinks){
|
|
137
|
+
let project = resolveProject(parentNode.name, dependencyLink);
|
|
138
|
+
let dependencyPath = resolvePath(parentNode, dependencyLink);
|
|
139
|
+
let node = new Node(parentNode, new NodeItem(project, dependencyLink, dependencyPath));
|
|
140
|
+
nodes.push(node);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return nodes;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function extractImports(node, dependencies = []){
|
|
147
|
+
let dependencyLinks = extractFileImports(node.import.path);
|
|
148
|
+
let nodesToImport = resolveLinks(node.import, dependencyLinks);
|
|
149
|
+
for (let nodeToImport of nodesToImport){
|
|
150
|
+
let found = dependencies.find(item => item.import.path == nodeToImport.import.path);
|
|
151
|
+
|
|
152
|
+
if (!found){
|
|
153
|
+
dependencies.push(nodeToImport);
|
|
154
|
+
extractImports(nodeToImport, dependencies);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return dependencies;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function aliasCompare( a, b ) {
|
|
161
|
+
if ( a.import.name < b.import.name ){
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
if ( a.import.name > b.import.name ){
|
|
165
|
+
return -1;
|
|
166
|
+
}
|
|
167
|
+
if( a.import.path < b.import.path ){
|
|
168
|
+
return -1;
|
|
169
|
+
}
|
|
170
|
+
if (a.import.path > b.import.path ){
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
if ( a.import.source < b.import.source ){
|
|
174
|
+
return -1;
|
|
175
|
+
}
|
|
176
|
+
if ( a.import.source > b.import.source ){
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function flattenResults(dependencyNodes){
|
|
183
|
+
dependencyNodes.sort(aliasCompare);
|
|
184
|
+
|
|
185
|
+
let prevProject = null;
|
|
186
|
+
for(let dependencyNode of dependencyNodes){
|
|
187
|
+
if (dependencyNode.import.name != prevProject){
|
|
188
|
+
console.log('\nProject =>', dependencyNode.import.name);
|
|
189
|
+
prevProject = dependencyNode.import.name;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
let relativePath = 'not set';
|
|
193
|
+
if (dependencyNode.import.path != null){
|
|
194
|
+
relativePath = path.relative(process.cwd(), dependencyNode.import.path);
|
|
195
|
+
}
|
|
196
|
+
else{
|
|
197
|
+
relativePath = dependencyNode.import.source;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
console.log(relativePath);
|
|
202
|
+
}
|
|
203
|
+
}
|