@1inch/solidity-utils 2.2.1 → 2.2.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/contracts/mocks/ERC20PermitMock.sol +3 -2
- 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 -20
- 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 +1 -1
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
pragma solidity ^0.8.0;
|
|
4
4
|
|
|
5
5
|
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
|
|
6
|
+
import "./TokenMock.sol";
|
|
6
7
|
|
|
7
|
-
contract ERC20PermitMock is ERC20Permit {
|
|
8
|
+
contract ERC20PermitMock is ERC20Permit, TokenMock {
|
|
8
9
|
constructor(
|
|
9
10
|
string memory name,
|
|
10
11
|
string memory symbol,
|
|
11
12
|
address initialAccount,
|
|
12
13
|
uint256 initialBalance
|
|
13
|
-
) payable
|
|
14
|
+
) payable TokenMock(name, symbol) ERC20Permit(name) {
|
|
14
15
|
_mint(initialAccount, initialBalance);
|
|
15
16
|
}
|
|
16
17
|
}
|
package/dist/src/asserts.d.ts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function toBNExtended(value: string | number | BN): BN;
|
|
3
|
-
export declare function assertRoughlyEqualValues(expected: string | number | BN, actual: string | number | BN, relativeDiff: number): void;
|
|
1
|
+
export declare function assertRoughlyEqualValues(expected: string | number | bigint, actual: string | number | bigint, relativeDiff: number): void;
|
package/dist/src/asserts.js
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertRoughlyEqualValues =
|
|
3
|
+
exports.assertRoughlyEqualValues = void 0;
|
|
4
4
|
const prelude_1 = require("./prelude");
|
|
5
|
-
function toBNExtended(value) {
|
|
6
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
7
|
-
return (0, prelude_1.toBN)(value);
|
|
8
|
-
}
|
|
9
|
-
return value;
|
|
10
|
-
}
|
|
11
|
-
exports.toBNExtended = toBNExtended;
|
|
12
5
|
function assertRoughlyEqualValues(expected, actual, relativeDiff) {
|
|
13
|
-
let expectedBN =
|
|
14
|
-
let actualBN =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
let expectedBN = BigInt(expected);
|
|
7
|
+
let actualBN = BigInt(actual);
|
|
8
|
+
(0, prelude_1.expect)(expectedBN * actualBN).to.be.gte(0, 'Values are of different sign');
|
|
9
|
+
if (expectedBN < 0)
|
|
10
|
+
expectedBN = -expectedBN;
|
|
11
|
+
if (actualBN < 0)
|
|
12
|
+
actualBN = -actualBN;
|
|
20
13
|
let multiplerNumerator = relativeDiff;
|
|
21
|
-
let multiplerDenominator =
|
|
14
|
+
let multiplerDenominator = 1n;
|
|
22
15
|
while (!Number.isInteger(multiplerNumerator)) {
|
|
23
|
-
multiplerDenominator = multiplerDenominator
|
|
16
|
+
multiplerDenominator = multiplerDenominator * 10n;
|
|
24
17
|
multiplerNumerator *= 10;
|
|
25
18
|
}
|
|
26
|
-
const diff = expectedBN
|
|
27
|
-
const treshold = expectedBN
|
|
28
|
-
if (
|
|
29
|
-
(0, prelude_1.expect)(actualBN).to.be.
|
|
19
|
+
const diff = expectedBN > actualBN ? expectedBN - actualBN : actualBN - expectedBN;
|
|
20
|
+
const treshold = (expectedBN * BigInt(multiplerNumerator)) / multiplerDenominator;
|
|
21
|
+
if (diff > treshold) {
|
|
22
|
+
(0, prelude_1.expect)(actualBN).to.be.equal(expectedBN, `${actual} != ${expected} with ${relativeDiff} precision`);
|
|
30
23
|
}
|
|
31
24
|
}
|
|
32
25
|
exports.assertRoughlyEqualValues = assertRoughlyEqualValues;
|
package/dist/src/asserts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asserts.js","sourceRoot":"","sources":["../../src/asserts.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"asserts.js","sourceRoot":"","sources":["../../src/asserts.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAEnC,SAAgB,wBAAwB,CACpC,QAAkC,EAClC,MAAgC,EAChC,YAAoB;IAEpB,IAAI,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAA,gBAAM,EAAC,UAAU,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,8BAA8B,CAAC,CAAC;IAE3E,IAAI,UAAU,GAAG,CAAC;QAAE,UAAU,GAAG,CAAC,UAAU,CAAC;IAC7C,IAAI,QAAQ,GAAG,CAAC;QAAE,QAAQ,GAAG,CAAC,QAAQ,CAAC;IAEvC,IAAI,kBAAkB,GAAG,YAAY,CAAC;IACtC,IAAI,oBAAoB,GAAG,EAAE,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE;QAC1C,oBAAoB,GAAG,oBAAoB,GAAG,GAAG,CAAC;QAClD,kBAAkB,IAAI,EAAE,CAAC;KAC5B;IACD,MAAM,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC;IACnF,MAAM,QAAQ,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC,GAAG,oBAAoB,CAAC;IAClF,IAAI,IAAI,GAAG,QAAQ,EAAE;QACjB,IAAA,gBAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,MAAM,OAAO,QAAQ,SAAS,YAAY,YAAY,CAAC,CAAC;KACvG;AACL,CAAC;AAvBD,4DAuBC"}
|
package/dist/src/permit.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { SignTypedDataVersion } from '@metamask/eth-sig-util';
|
|
2
|
+
import { Contract } from 'ethers';
|
|
3
|
+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
|
|
4
4
|
export declare const TypedDataVersion = SignTypedDataVersion.V4;
|
|
5
|
-
export declare const defaultDeadline:
|
|
5
|
+
export declare const defaultDeadline: bigint;
|
|
6
6
|
export declare const EIP712Domain: {
|
|
7
7
|
name: string;
|
|
8
8
|
type: string;
|
|
@@ -15,16 +15,11 @@ export declare const DaiLikePermit: {
|
|
|
15
15
|
name: string;
|
|
16
16
|
type: string;
|
|
17
17
|
}[];
|
|
18
|
-
export declare function trim0x(bigNumber:
|
|
18
|
+
export declare function trim0x(bigNumber: bigint | string): string;
|
|
19
19
|
export declare function cutSelector(data: string): string;
|
|
20
20
|
export declare function domainSeparator(name: string, version: string, chainId: string, verifyingContract: string): string;
|
|
21
21
|
export declare function buildData(name: string, version: string, chainId: number, verifyingContract: string, owner: string, spender: string, value: string, nonce: string, deadline?: string): {
|
|
22
|
-
readonly primaryType: "Permit";
|
|
23
22
|
readonly types: {
|
|
24
|
-
readonly EIP712Domain: {
|
|
25
|
-
name: string;
|
|
26
|
-
type: string;
|
|
27
|
-
}[];
|
|
28
23
|
readonly Permit: {
|
|
29
24
|
name: string;
|
|
30
25
|
type: string;
|
|
@@ -45,12 +40,7 @@ export declare function buildData(name: string, version: string, chainId: number
|
|
|
45
40
|
};
|
|
46
41
|
};
|
|
47
42
|
export declare function buildDataLikeDai(name: string, version: string, chainId: number, verifyingContract: string, holder: string, spender: string, nonce: string, allowed: boolean, expiry?: string): {
|
|
48
|
-
readonly primaryType: "Permit";
|
|
49
43
|
readonly types: {
|
|
50
|
-
readonly EIP712Domain: {
|
|
51
|
-
name: string;
|
|
52
|
-
type: string;
|
|
53
|
-
}[];
|
|
54
44
|
readonly Permit: {
|
|
55
45
|
name: string;
|
|
56
46
|
type: string;
|
|
@@ -70,11 +60,6 @@ export declare function buildDataLikeDai(name: string, version: string, chainId:
|
|
|
70
60
|
readonly allowed: boolean;
|
|
71
61
|
};
|
|
72
62
|
};
|
|
73
|
-
export
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
export declare function signWithPk<T extends MessageTypes>(privateKey: Buffer | string, data: TypedMessage<T>): string;
|
|
78
|
-
export declare function getPermit(owner: string, ownerPrivateKey: string, permitContract: PermittableToken, tokenVersion: string, chainId: number, spender: string, value: string, deadline?: string): Promise<string>;
|
|
79
|
-
export declare function getPermitLikeDai(holder: string, holderPrivateKey: string, permitContract: PermittableToken, tokenVersion: string, chainId: number, spender: string, allowed: boolean, expiry?: string): Promise<string>;
|
|
80
|
-
export declare function withTarget(target: BN | string, data: BN | string): string;
|
|
63
|
+
export declare function getPermit(owner: SignerWithAddress, permitContract: Contract, tokenVersion: string, chainId: number, spender: string, value: string, deadline?: string): Promise<string>;
|
|
64
|
+
export declare function getPermitLikeDai(holder: SignerWithAddress, permitContract: Contract, tokenVersion: string, chainId: number, spender: string, allowed: boolean, expiry?: string): Promise<string>;
|
|
65
|
+
export declare function withTarget(target: bigint | string, data: bigint | string): string;
|
package/dist/src/permit.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withTarget = exports.getPermitLikeDai = exports.getPermit = exports.
|
|
3
|
+
exports.withTarget = exports.getPermitLikeDai = exports.getPermit = exports.buildDataLikeDai = exports.buildData = exports.domainSeparator = exports.cutSelector = exports.trim0x = exports.DaiLikePermit = exports.Permit = exports.EIP712Domain = exports.defaultDeadline = exports.TypedDataVersion = void 0;
|
|
4
4
|
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
5
|
-
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
6
5
|
const prelude_1 = require("./prelude");
|
|
6
|
+
const utils_1 = require("ethers/lib/utils");
|
|
7
7
|
exports.TypedDataVersion = eth_sig_util_1.SignTypedDataVersion.V4;
|
|
8
8
|
exports.defaultDeadline = prelude_1.constants.MAX_UINT256;
|
|
9
9
|
exports.EIP712Domain = [
|
|
@@ -40,55 +40,57 @@ function cutSelector(data) {
|
|
|
40
40
|
}
|
|
41
41
|
exports.cutSelector = cutSelector;
|
|
42
42
|
function domainSeparator(name, version, chainId, verifyingContract) {
|
|
43
|
-
return '0x' +
|
|
43
|
+
return ('0x' +
|
|
44
|
+
eth_sig_util_1.TypedDataUtils.hashStruct('EIP712Domain', { name, version, chainId, verifyingContract }, { EIP712Domain: exports.EIP712Domain }, exports.TypedDataVersion).toString('hex'));
|
|
44
45
|
}
|
|
45
46
|
exports.domainSeparator = domainSeparator;
|
|
46
|
-
function buildData(name, version, chainId, verifyingContract, owner, spender, value, nonce, deadline = exports.defaultDeadline) {
|
|
47
|
+
function buildData(name, version, chainId, verifyingContract, owner, spender, value, nonce, deadline = exports.defaultDeadline.toString()) {
|
|
47
48
|
return {
|
|
48
|
-
|
|
49
|
-
types: { EIP712Domain: exports.EIP712Domain, Permit: exports.Permit },
|
|
49
|
+
types: { Permit: exports.Permit },
|
|
50
50
|
domain: { name, version, chainId, verifyingContract },
|
|
51
51
|
message: { owner, spender, value, nonce, deadline },
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
exports.buildData = buildData;
|
|
55
|
-
function buildDataLikeDai(name, version, chainId, verifyingContract, holder, spender, nonce, allowed, expiry = exports.defaultDeadline) {
|
|
55
|
+
function buildDataLikeDai(name, version, chainId, verifyingContract, holder, spender, nonce, allowed, expiry = exports.defaultDeadline.toString()) {
|
|
56
56
|
return {
|
|
57
|
-
|
|
58
|
-
types: { EIP712Domain: exports.EIP712Domain, Permit: exports.DaiLikePermit },
|
|
57
|
+
types: { Permit: exports.DaiLikePermit },
|
|
59
58
|
domain: { name, version, chainId, verifyingContract },
|
|
60
59
|
message: { holder, spender, nonce, expiry, allowed },
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
62
|
exports.buildDataLikeDai = buildDataLikeDai;
|
|
64
|
-
function signWithPk(privateKey, data) {
|
|
65
|
-
const buffer = Buffer.isBuffer(privateKey) ? privateKey : Buffer.from(trim0x(privateKey), 'hex');
|
|
66
|
-
return (0, eth_sig_util_1.signTypedData)({ privateKey: buffer, data, version: exports.TypedDataVersion });
|
|
67
|
-
}
|
|
68
|
-
exports.signWithPk = signWithPk;
|
|
69
63
|
/*
|
|
70
64
|
* @param permitContract The contract object with ERC20Permit type and token address for which the permit creating.
|
|
71
65
|
*/
|
|
72
|
-
async function getPermit(owner,
|
|
73
|
-
const nonce = await permitContract.nonces(owner);
|
|
66
|
+
async function getPermit(owner, permitContract, tokenVersion, chainId, spender, value, deadline = exports.defaultDeadline.toString()) {
|
|
67
|
+
const nonce = await permitContract.nonces(owner.address);
|
|
74
68
|
const name = await permitContract.name();
|
|
75
|
-
const data = buildData(name, tokenVersion, chainId, permitContract.address, owner, spender, value, nonce.toString(), deadline);
|
|
76
|
-
const signature =
|
|
77
|
-
const { v, r, s } = (0,
|
|
78
|
-
const permitCall = permitContract.
|
|
69
|
+
const data = buildData(name, tokenVersion, chainId, permitContract.address, owner.address, spender, value, nonce.toString(), deadline);
|
|
70
|
+
const signature = await owner._signTypedData(data.domain, data.types, data.message);
|
|
71
|
+
const { v, r, s } = (0, utils_1.splitSignature)(signature);
|
|
72
|
+
const permitCall = permitContract.interface.encodeFunctionData('permit', [
|
|
73
|
+
owner.address,
|
|
74
|
+
spender,
|
|
75
|
+
value,
|
|
76
|
+
deadline,
|
|
77
|
+
v,
|
|
78
|
+
r,
|
|
79
|
+
s,
|
|
80
|
+
]);
|
|
79
81
|
return cutSelector(permitCall);
|
|
80
82
|
}
|
|
81
83
|
exports.getPermit = getPermit;
|
|
82
84
|
/*
|
|
83
85
|
* @param permitContract The contract object with ERC20PermitLikeDai type and token address for which the permit creating.
|
|
84
86
|
*/
|
|
85
|
-
async function getPermitLikeDai(holder,
|
|
86
|
-
const nonce = await permitContract.nonces(holder);
|
|
87
|
+
async function getPermitLikeDai(holder, permitContract, tokenVersion, chainId, spender, allowed, expiry = exports.defaultDeadline.toString()) {
|
|
88
|
+
const nonce = await permitContract.nonces(holder.address);
|
|
87
89
|
const name = await permitContract.name();
|
|
88
|
-
const data = buildDataLikeDai(name, tokenVersion, chainId, permitContract.address, holder, spender, nonce.toString(), allowed, expiry);
|
|
89
|
-
const signature =
|
|
90
|
-
const { v, r, s } = (0,
|
|
91
|
-
const permitCall = permitContract.
|
|
90
|
+
const data = buildDataLikeDai(name, tokenVersion, chainId, permitContract.address, holder.address, spender, nonce.toString(), allowed, expiry);
|
|
91
|
+
const signature = await holder._signTypedData(data.domain, data.types, data.message);
|
|
92
|
+
const { v, r, s } = (0, utils_1.splitSignature)(signature);
|
|
93
|
+
const permitCall = permitContract.interface.encodeFunctionData('permit(address,address,uint256,uint256,bool,uint8,bytes32,bytes32)', [holder.address, spender, nonce, expiry, allowed, v, r, s]);
|
|
92
94
|
return cutSelector(permitCall);
|
|
93
95
|
}
|
|
94
96
|
exports.getPermitLikeDai = getPermitLikeDai;
|
package/dist/src/permit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/permit.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"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, assert, expect, config, should } from 'chai';
|
|
2
|
-
import '
|
|
3
|
-
import BN from 'bn.js';
|
|
4
|
-
export declare function toBN(num: string | number, base?: number | 'hex'): BN;
|
|
2
|
+
import { time } from '@nomicfoundation/hardhat-network-helpers';
|
|
5
3
|
export declare const constants: {
|
|
6
4
|
readonly ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
7
5
|
readonly EEE_ADDRESS: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
8
6
|
readonly ZERO_BYTES32: "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
9
|
-
readonly MAX_UINT256:
|
|
10
|
-
readonly MAX_INT256:
|
|
11
|
-
readonly MIN_INT256:
|
|
7
|
+
readonly MAX_UINT256: bigint;
|
|
8
|
+
readonly MAX_INT256: bigint;
|
|
9
|
+
readonly MIN_INT256: bigint;
|
|
10
|
+
readonly MAX_UINT128: bigint;
|
|
12
11
|
};
|
|
13
|
-
export {
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
latest: () => Promise<BN>;
|
|
17
|
-
};
|
|
18
|
-
export declare const time: Time;
|
|
19
|
-
export declare function ether(n: string): BN;
|
|
20
|
-
export { Assertion, AssertionError, assert, expect, config, should, };
|
|
12
|
+
export { time };
|
|
13
|
+
export declare function ether(n: string): bigint;
|
|
14
|
+
export { Assertion, AssertionError, assert, expect, config, should };
|
package/dist/src/prelude.js
CHANGED
|
@@ -1,37 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.should = exports.config = exports.expect = exports.assert = exports.AssertionError = exports.Assertion = exports.ether = exports.time = exports.
|
|
4
|
-
const
|
|
5
|
-
const chai_1 = tslib_1.__importStar(require("chai"));
|
|
3
|
+
exports.should = exports.config = exports.expect = exports.assert = exports.AssertionError = exports.Assertion = exports.ether = exports.time = exports.constants = void 0;
|
|
4
|
+
const chai_1 = require("chai");
|
|
6
5
|
Object.defineProperty(exports, "Assertion", { enumerable: true, get: function () { return chai_1.Assertion; } });
|
|
7
6
|
Object.defineProperty(exports, "AssertionError", { enumerable: true, get: function () { return chai_1.AssertionError; } });
|
|
8
7
|
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return chai_1.assert; } });
|
|
9
8
|
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return chai_1.expect; } });
|
|
10
9
|
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return chai_1.config; } });
|
|
11
10
|
Object.defineProperty(exports, "should", { enumerable: true, get: function () { return chai_1.should; } });
|
|
12
|
-
require("
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
|
|
16
|
-
exports.BN = bn_js_1.default;
|
|
17
|
-
chai_1.default.use(chai_as_promised_1.default);
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19
|
-
const { time: timeImpl } = require('@openzeppelin/test-helpers');
|
|
20
|
-
function toBN(num, base) {
|
|
21
|
-
return new bn_js_1.default(num, base);
|
|
22
|
-
}
|
|
23
|
-
exports.toBN = toBN;
|
|
11
|
+
const utils_1 = require("ethers/lib/utils");
|
|
12
|
+
const hardhat_network_helpers_1 = require("@nomicfoundation/hardhat-network-helpers");
|
|
13
|
+
Object.defineProperty(exports, "time", { enumerable: true, get: function () { return hardhat_network_helpers_1.time; } });
|
|
24
14
|
exports.constants = {
|
|
25
15
|
ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
|
|
26
16
|
EEE_ADDRESS: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
|
|
27
17
|
ZERO_BYTES32: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
28
|
-
MAX_UINT256:
|
|
29
|
-
MAX_INT256:
|
|
30
|
-
MIN_INT256:
|
|
18
|
+
MAX_UINT256: 2n ** 256n - 1n,
|
|
19
|
+
MAX_INT256: 2n ** 255n - 1n,
|
|
20
|
+
MIN_INT256: -(2n ** 255n),
|
|
21
|
+
MAX_UINT128: 2n ** 128n - 1n,
|
|
31
22
|
};
|
|
32
|
-
exports.time = timeImpl;
|
|
33
23
|
function ether(n) {
|
|
34
|
-
return
|
|
24
|
+
return (0, utils_1.parseUnits)(n).toBigInt();
|
|
35
25
|
}
|
|
36
26
|
exports.ether = ether;
|
|
37
27
|
//# sourceMappingURL=prelude.js.map
|
package/dist/src/prelude.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/prelude.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/prelude.ts"],"names":[],"mappings":";;;AAAA,+BAAiF;AAsBxE,0FAtBA,gBAAS,OAsBA;AAAE,+FAtBA,qBAAc,OAsBA;AAAE,uFAtBA,aAAM,OAsBA;AAAE,uFAtBA,aAAM,OAsBA;AAAE,uFAtBA,aAAM,OAsBA;AAAE,uFAtBA,aAAM,OAsBA;AArBlE,4CAA8C;AAC9C,sFAAgE;AAavD,qFAbA,8BAAI,OAaA;AAXA,QAAA,SAAS,GAAG;IACrB,YAAY,EAAE,4CAA4C;IAC1D,WAAW,EAAE,4CAA4C;IACzD,YAAY,EAAE,oEAAoE;IAClF,WAAW,EAAE,EAAE,IAAI,IAAI,GAAG,EAAE;IAC5B,UAAU,EAAE,EAAE,IAAI,IAAI,GAAG,EAAE;IAC3B,UAAU,EAAE,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC;IACzB,WAAW,EAAE,EAAE,IAAI,IAAI,GAAG,EAAE;CACtB,CAAC;AAKX,SAAgB,KAAK,CAAC,CAAS;IAC3B,OAAO,IAAA,kBAAU,EAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AACpC,CAAC;AAFD,sBAEC"}
|
package/dist/src/profileEVM.d.ts
CHANGED
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,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C;YAC3C,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACzB;QAED,IAAI,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE;YACpC,YAAY,CAAC,GAAG,EAAE,CAAC;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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