@1inch/solidity-utils 2.2.6 → 2.2.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.
- package/contracts/libraries/SafeERC20.sol +77 -32
- package/contracts/mocks/.DS_Store +0 -0
- package/dist/src/asserts.d.ts +3 -1
- package/dist/src/asserts.js +21 -14
- package/dist/src/asserts.js.map +1 -1
- package/dist/src/permit.d.ts +23 -8
- package/dist/src/permit.js +26 -28
- package/dist/src/permit.js.map +1 -1
- package/dist/src/prelude.d.ts +14 -8
- package/dist/src/prelude.js +23 -10
- package/dist/src/prelude.js.map +1 -1
- package/dist/src/profileEVM.d.ts +2 -4
- package/dist/src/profileEVM.js +40 -31
- package/dist/src/profileEVM.js.map +1 -1
- package/dist/src/utils.d.ts +9 -6
- package/dist/src/utils.js +22 -13
- package/dist/src/utils.js.map +1 -1
- package/package.json +2 -2
|
@@ -97,60 +97,105 @@ library SafeERC20 {
|
|
|
97
97
|
forceApprove(token, spender, allowance - value);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
/// @dev Calls either ERC20 or Dai `permit` for `token`, if unsuccessful forwards revert from external call.
|
|
101
100
|
function safePermit(IERC20 token, bytes calldata permit) internal {
|
|
102
|
-
if (!tryPermit(token, permit)) RevertReasonForwarder.reRevert();
|
|
101
|
+
if (!tryPermit(token, msg.sender, address(this), permit)) RevertReasonForwarder.reRevert();
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
function
|
|
106
|
-
if (
|
|
107
|
-
return _makeCalldataCall(token, IERC20Permit.permit.selector, permit);
|
|
108
|
-
}
|
|
109
|
-
if (permit.length == 32 * 8) {
|
|
110
|
-
return _makeCalldataCall(token, IDaiLikePermit.permit.selector, permit);
|
|
111
|
-
}
|
|
112
|
-
revert SafePermitBadLength();
|
|
104
|
+
function safePermit(IERC20 token, address owner, address spender, bytes calldata permit) internal {
|
|
105
|
+
if (!tryPermit(token, owner, spender, permit)) RevertReasonForwarder.reRevert();
|
|
113
106
|
}
|
|
114
107
|
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
function tryPermit(IERC20 token, bytes calldata permit) internal returns(bool success) {
|
|
109
|
+
return tryPermit(token, msg.sender, address(this), permit);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function tryPermit(IERC20 token, address owner, address spender, bytes calldata permit) internal returns(bool success) {
|
|
113
|
+
bytes4 permitSelector = IERC20Permit.permit.selector;
|
|
114
|
+
bytes4 daiPermitSelector = IDaiLikePermit.permit.selector;
|
|
115
|
+
bool lengthIsInvalid;
|
|
121
116
|
/// @solidity memory-safe-assembly
|
|
122
117
|
assembly { // solhint-disable-line no-inline-assembly
|
|
123
|
-
|
|
118
|
+
switch permit.length
|
|
119
|
+
case 100 {
|
|
120
|
+
let ptr := mload(0x40)
|
|
121
|
+
mstore(ptr, permitSelector)
|
|
122
|
+
mstore(add(ptr, 0x04), owner)
|
|
123
|
+
mstore(add(ptr, 0x24), spender)
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
// Compact IERC20Permit.permit(uint256 value, uint32 deadline, uint256 r, uint256 vs)
|
|
126
|
+
{ // stack too deep
|
|
127
|
+
let deadline := shr(224, calldataload(add(permit.offset, 0x20)))
|
|
128
|
+
let vs := calldataload(add(permit.offset, 0x44))
|
|
129
|
+
|
|
130
|
+
calldatacopy(add(ptr, 0x44), permit.offset, 0x20) // value
|
|
131
|
+
mstore(add(ptr, 0x64), sub(deadline, 1))
|
|
132
|
+
mstore(add(ptr, 0x84), add(27, shr(255, vs)))
|
|
133
|
+
calldatacopy(add(ptr, 0xa4), add(permit.offset, 0x24), 0x20) // r
|
|
134
|
+
mstore(add(ptr, 0xc4), shr(1, shl(1, vs)))
|
|
133
135
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
// IERC20Permit.permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s)
|
|
137
|
+
success := call(gas(), token, 0, ptr, 0xe4, 0, 0)
|
|
138
|
+
}
|
|
139
|
+
case 72 {
|
|
140
|
+
let ptr := mload(0x40)
|
|
141
|
+
mstore(ptr, daiPermitSelector)
|
|
142
|
+
mstore(add(ptr, 0x04), owner)
|
|
143
|
+
mstore(add(ptr, 0x24), spender)
|
|
144
|
+
|
|
145
|
+
// Compact IDaiLikePermit.permit(uint32 nonce, uint32 expiry, uint256 r, uint256 vs)
|
|
146
|
+
{ // stack too deep
|
|
147
|
+
let nonce := shr(224, calldataload(permit.offset))
|
|
148
|
+
let expiry := shr(224, calldataload(add(permit.offset, 0x04)))
|
|
149
|
+
let vs := calldataload(add(permit.offset, 0x28))
|
|
150
|
+
|
|
151
|
+
mstore(add(ptr, 0x44), nonce)
|
|
152
|
+
mstore(add(ptr, 0x64), sub(expiry, 1))
|
|
153
|
+
mstore(add(ptr, 0x84), true)
|
|
154
|
+
mstore(add(ptr, 0xa4), add(27, shr(255, vs)))
|
|
155
|
+
calldatacopy(add(ptr, 0xc4), add(permit.offset, 0x08), 0x20) // r
|
|
156
|
+
mstore(add(ptr, 0xe4), shr(1, shl(1, vs)))
|
|
136
157
|
}
|
|
158
|
+
// IDaiLikePermit.permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s)
|
|
159
|
+
success := call(gas(), token, 0, ptr, 0x104, 0, 0)
|
|
160
|
+
}
|
|
161
|
+
case 224 {
|
|
162
|
+
let ptr := mload(0x40)
|
|
163
|
+
mstore(ptr, permitSelector)
|
|
164
|
+
calldatacopy(add(ptr, 0x04), permit.offset, permit.length)
|
|
165
|
+
// IERC20Permit.permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s)
|
|
166
|
+
success := call(gas(), token, 0, ptr, add(4, permit.length), 0, 0)
|
|
167
|
+
}
|
|
168
|
+
case 256 {
|
|
169
|
+
let ptr := mload(0x40)
|
|
170
|
+
mstore(ptr, daiPermitSelector)
|
|
171
|
+
calldatacopy(add(ptr, 0x04), permit.offset, permit.length)
|
|
172
|
+
// IDaiLikePermit.permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s)
|
|
173
|
+
success := call(gas(), token, 0, ptr, add(4, permit.length), 0, 0)
|
|
137
174
|
}
|
|
175
|
+
default {
|
|
176
|
+
lengthIsInvalid := true
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (lengthIsInvalid) {
|
|
181
|
+
revert SafePermitBadLength();
|
|
138
182
|
}
|
|
139
183
|
}
|
|
140
184
|
|
|
141
|
-
function
|
|
185
|
+
function _makeCall(
|
|
142
186
|
IERC20 token,
|
|
143
187
|
bytes4 selector,
|
|
144
|
-
|
|
188
|
+
address to,
|
|
189
|
+
uint256 amount
|
|
145
190
|
) private returns (bool success) {
|
|
146
191
|
/// @solidity memory-safe-assembly
|
|
147
192
|
assembly { // solhint-disable-line no-inline-assembly
|
|
148
|
-
let len := add(4, args.length)
|
|
149
193
|
let data := mload(0x40)
|
|
150
194
|
|
|
151
195
|
mstore(data, selector)
|
|
152
|
-
|
|
153
|
-
|
|
196
|
+
mstore(add(data, 0x04), to)
|
|
197
|
+
mstore(add(data, 0x24), amount)
|
|
198
|
+
success := call(gas(), token, 0, data, 0x44, 0x0, 0x20)
|
|
154
199
|
if success {
|
|
155
200
|
switch returndatasize()
|
|
156
201
|
case 0 {
|
|
Binary file
|
package/dist/src/asserts.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import BN from 'bn.js';
|
|
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;
|
package/dist/src/asserts.js
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertRoughlyEqualValues = void 0;
|
|
3
|
+
exports.assertRoughlyEqualValues = exports.toBNExtended = 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;
|
|
5
12
|
function assertRoughlyEqualValues(expected, actual, relativeDiff) {
|
|
6
|
-
let expectedBN =
|
|
7
|
-
let actualBN =
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
let expectedBN = toBNExtended(expected);
|
|
14
|
+
let actualBN = toBNExtended(actual);
|
|
15
|
+
if (expectedBN.isNeg() !== actualBN.isNeg()) {
|
|
16
|
+
(0, prelude_1.expect)(actualBN).to.be.bignumber.equal(expectedBN, 'Values are of different sign');
|
|
17
|
+
}
|
|
18
|
+
expectedBN = expectedBN.abs();
|
|
19
|
+
actualBN = actualBN.abs();
|
|
13
20
|
let multiplerNumerator = relativeDiff;
|
|
14
|
-
let multiplerDenominator =
|
|
21
|
+
let multiplerDenominator = (0, prelude_1.toBN)('1');
|
|
15
22
|
while (!Number.isInteger(multiplerNumerator)) {
|
|
16
|
-
multiplerDenominator = multiplerDenominator
|
|
23
|
+
multiplerDenominator = multiplerDenominator.mul((0, prelude_1.toBN)('10'));
|
|
17
24
|
multiplerNumerator *= 10;
|
|
18
25
|
}
|
|
19
|
-
const diff = expectedBN
|
|
20
|
-
const treshold = (
|
|
21
|
-
if (diff
|
|
22
|
-
(0, prelude_1.expect)(actualBN).to.be.equal(expectedBN, `${actual} != ${expected} with ${relativeDiff} precision`);
|
|
26
|
+
const diff = expectedBN.sub(actualBN).abs();
|
|
27
|
+
const treshold = expectedBN.mul((0, prelude_1.toBN)(multiplerNumerator.toString())).div(multiplerDenominator);
|
|
28
|
+
if (!diff.lte(treshold)) {
|
|
29
|
+
(0, prelude_1.expect)(actualBN).to.be.bignumber.equal(expectedBN, `${actual} != ${expected} with ${relativeDiff} precision`);
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
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,uCAAyC;AAGzC,SAAgB,YAAY,CAAE,KAA2B;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACxD,OAAO,IAAA,cAAI,EAAC,KAAK,CAAC,CAAC;KACtB;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AALD,oCAKC;AAED,SAAgB,wBAAwB,CAAE,QAA8B,EAAE,MAA4B,EAAE,YAAoB;IACxH,IAAI,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,QAAQ,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,UAAU,CAAC,KAAK,EAAE,KAAK,QAAQ,CAAC,KAAK,EAAE,EAAE;QACzC,IAAA,gBAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,8BAA8B,CAAC,CAAC;KACtF;IAED,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC;IAC9B,QAAQ,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;IAE1B,IAAI,kBAAkB,GAAG,YAAY,CAAC;IACtC,IAAI,oBAAoB,GAAG,IAAA,cAAI,EAAC,GAAG,CAAC,CAAC;IACrC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE;QAC1C,oBAAoB,GAAG,oBAAoB,CAAC,GAAG,CAAC,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,kBAAkB,IAAI,EAAE,CAAC;KAC5B;IACD,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,IAAA,cAAI,EAAC,kBAAkB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC/F,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;QACrB,IAAA,gBAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,MAAM,OAAO,QAAQ,SAAS,YAAY,YAAY,CAAC,CAAC;KACjH;AACL,CAAC;AArBD,4DAqBC"}
|
package/dist/src/permit.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { MessageTypes, SignTypedDataVersion, TypedMessage } from '@metamask/eth-sig-util';
|
|
3
|
+
import { Token } from './utils';
|
|
4
4
|
export declare const TypedDataVersion = SignTypedDataVersion.V4;
|
|
5
|
-
export declare const defaultDeadline:
|
|
5
|
+
export declare const defaultDeadline: string;
|
|
6
6
|
export declare const EIP712Domain: {
|
|
7
7
|
name: string;
|
|
8
8
|
type: string;
|
|
@@ -15,11 +15,16 @@ 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: BN | 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";
|
|
22
23
|
readonly types: {
|
|
24
|
+
readonly EIP712Domain: {
|
|
25
|
+
name: string;
|
|
26
|
+
type: string;
|
|
27
|
+
}[];
|
|
23
28
|
readonly Permit: {
|
|
24
29
|
name: string;
|
|
25
30
|
type: string;
|
|
@@ -40,7 +45,12 @@ export declare function buildData(name: string, version: string, chainId: number
|
|
|
40
45
|
};
|
|
41
46
|
};
|
|
42
47
|
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";
|
|
43
49
|
readonly types: {
|
|
50
|
+
readonly EIP712Domain: {
|
|
51
|
+
name: string;
|
|
52
|
+
type: string;
|
|
53
|
+
}[];
|
|
44
54
|
readonly Permit: {
|
|
45
55
|
name: string;
|
|
46
56
|
type: string;
|
|
@@ -60,6 +70,11 @@ export declare function buildDataLikeDai(name: string, version: string, chainId:
|
|
|
60
70
|
readonly allowed: boolean;
|
|
61
71
|
};
|
|
62
72
|
};
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
export interface PermittableToken extends Token {
|
|
74
|
+
nonces(owner: string, txDetails?: Truffle.TransactionDetails): Promise<BN>;
|
|
75
|
+
name(txDetails?: Truffle.TransactionDetails): Promise<string>;
|
|
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;
|
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.buildDataLikeDai = exports.buildData = exports.domainSeparator = exports.cutSelector = exports.trim0x = exports.DaiLikePermit = exports.Permit = exports.EIP712Domain = exports.defaultDeadline = exports.TypedDataVersion = void 0;
|
|
3
|
+
exports.withTarget = exports.getPermitLikeDai = exports.getPermit = exports.signWithPk = 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");
|
|
5
6
|
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,57 +40,55 @@ function cutSelector(data) {
|
|
|
40
40
|
}
|
|
41
41
|
exports.cutSelector = cutSelector;
|
|
42
42
|
function domainSeparator(name, version, chainId, verifyingContract) {
|
|
43
|
-
return
|
|
44
|
-
eth_sig_util_1.TypedDataUtils.hashStruct('EIP712Domain', { name, version, chainId, verifyingContract }, { EIP712Domain: exports.EIP712Domain }, exports.TypedDataVersion).toString('hex'));
|
|
43
|
+
return '0x' + eth_sig_util_1.TypedDataUtils.hashStruct('EIP712Domain', { name, version, chainId, verifyingContract }, { EIP712Domain: exports.EIP712Domain }, exports.TypedDataVersion).toString('hex');
|
|
45
44
|
}
|
|
46
45
|
exports.domainSeparator = domainSeparator;
|
|
47
|
-
function buildData(name, version, chainId, verifyingContract, owner, spender, value, nonce, deadline = exports.defaultDeadline
|
|
46
|
+
function buildData(name, version, chainId, verifyingContract, owner, spender, value, nonce, deadline = exports.defaultDeadline) {
|
|
48
47
|
return {
|
|
49
|
-
|
|
48
|
+
primaryType: 'Permit',
|
|
49
|
+
types: { EIP712Domain: exports.EIP712Domain, 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) {
|
|
56
56
|
return {
|
|
57
|
-
|
|
57
|
+
primaryType: 'Permit',
|
|
58
|
+
types: { EIP712Domain: exports.EIP712Domain, Permit: exports.DaiLikePermit },
|
|
58
59
|
domain: { name, version, chainId, verifyingContract },
|
|
59
60
|
message: { holder, spender, nonce, expiry, allowed },
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
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;
|
|
63
69
|
/*
|
|
64
70
|
* @param permitContract The contract object with ERC20Permit type and token address for which the permit creating.
|
|
65
71
|
*/
|
|
66
|
-
async function getPermit(owner, permitContract, tokenVersion, chainId, spender, value, deadline = exports.defaultDeadline
|
|
67
|
-
const nonce = await permitContract.nonces(owner
|
|
72
|
+
async function getPermit(owner, ownerPrivateKey, permitContract, tokenVersion, chainId, spender, value, deadline = exports.defaultDeadline) {
|
|
73
|
+
const nonce = await permitContract.nonces(owner);
|
|
68
74
|
const name = await permitContract.name();
|
|
69
|
-
const data = buildData(name, tokenVersion, chainId, permitContract.address, owner
|
|
70
|
-
const signature =
|
|
71
|
-
const { v, r, s } = (0,
|
|
72
|
-
const permitCall = permitContract.
|
|
73
|
-
owner.address,
|
|
74
|
-
spender,
|
|
75
|
-
value,
|
|
76
|
-
deadline,
|
|
77
|
-
v,
|
|
78
|
-
r,
|
|
79
|
-
s,
|
|
80
|
-
]);
|
|
75
|
+
const data = buildData(name, tokenVersion, chainId, permitContract.address, owner, spender, value, nonce.toString(), deadline);
|
|
76
|
+
const signature = signWithPk(ownerPrivateKey, data);
|
|
77
|
+
const { v, r, s } = (0, ethereumjs_util_1.fromRpcSig)(signature);
|
|
78
|
+
const permitCall = permitContract.contract.methods.permit(owner, spender, value, deadline, v, r, s).encodeABI();
|
|
81
79
|
return cutSelector(permitCall);
|
|
82
80
|
}
|
|
83
81
|
exports.getPermit = getPermit;
|
|
84
82
|
/*
|
|
85
83
|
* @param permitContract The contract object with ERC20PermitLikeDai type and token address for which the permit creating.
|
|
86
84
|
*/
|
|
87
|
-
async function getPermitLikeDai(holder, permitContract, tokenVersion, chainId, spender, allowed, expiry = exports.defaultDeadline
|
|
88
|
-
const nonce = await permitContract.nonces(holder
|
|
85
|
+
async function getPermitLikeDai(holder, holderPrivateKey, permitContract, tokenVersion, chainId, spender, allowed, expiry = exports.defaultDeadline) {
|
|
86
|
+
const nonce = await permitContract.nonces(holder);
|
|
89
87
|
const name = await permitContract.name();
|
|
90
|
-
const data = buildDataLikeDai(name, tokenVersion, chainId, permitContract.address, holder
|
|
91
|
-
const signature =
|
|
92
|
-
const { v, r, s } = (0,
|
|
93
|
-
const permitCall = permitContract.
|
|
88
|
+
const data = buildDataLikeDai(name, tokenVersion, chainId, permitContract.address, holder, spender, nonce.toString(), allowed, expiry);
|
|
89
|
+
const signature = signWithPk(holderPrivateKey, data);
|
|
90
|
+
const { v, r, s } = (0, ethereumjs_util_1.fromRpcSig)(signature);
|
|
91
|
+
const permitCall = permitContract.contract.methods.permit(holder, spender, nonce, expiry, allowed, v, r, s).encodeABI();
|
|
94
92
|
return cutSelector(permitCall);
|
|
95
93
|
}
|
|
96
94
|
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,"file":"permit.js","sourceRoot":"","sources":["../../src/permit.ts"],"names":[],"mappings":";;;AAAA,yDAAyH;AACzH,qDAA6C;AAE7C,uCAAsC;AAGzB,QAAA,gBAAgB,GAAG,mCAAoB,CAAC,EAAE,CAAC;AAC3C,QAAA,eAAe,GAAG,mBAAS,CAAC,WAAW,CAAC;AAExC,QAAA,YAAY,GAAG;IACxB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACpC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;CACjD,CAAC;AAEW,QAAA,MAAM,GAAG;IAClB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACpC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,EAAE,IAAI,EAAE,OAAO,EA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EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACvI,MAAM,SAAS,GAAG,UAAU,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAA,4BAAU,EAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IACxH,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC;AAjBD,4CAiBC;AAED,SAAgB,UAAU,CAAE,MAAmB,EAAE,IAAiB;IAC9D,OAAO,MAAM,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAFD,gCAEC"}
|
package/dist/src/prelude.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { Assertion, AssertionError, assert, expect, config, should } from 'chai';
|
|
2
|
-
import
|
|
2
|
+
import 'chai-bn';
|
|
3
|
+
import BN from 'bn.js';
|
|
4
|
+
export declare function toBN(num: string | number, base?: number | 'hex'): BN;
|
|
3
5
|
export declare const constants: {
|
|
4
6
|
readonly ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
5
7
|
readonly EEE_ADDRESS: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
6
8
|
readonly ZERO_BYTES32: "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7
|
-
readonly MAX_UINT256:
|
|
8
|
-
readonly MAX_INT256:
|
|
9
|
-
readonly MIN_INT256:
|
|
10
|
-
readonly MAX_UINT128: bigint;
|
|
9
|
+
readonly MAX_UINT256: string;
|
|
10
|
+
readonly MAX_INT256: string;
|
|
11
|
+
readonly MIN_INT256: string;
|
|
11
12
|
};
|
|
12
|
-
export {
|
|
13
|
-
export declare
|
|
14
|
-
|
|
13
|
+
export { BN, };
|
|
14
|
+
export declare type Time = {
|
|
15
|
+
increaseTo: (target: string | number | BN) => Promise<BN>;
|
|
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, };
|
package/dist/src/prelude.js
CHANGED
|
@@ -1,27 +1,40 @@
|
|
|
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.constants = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.should = exports.config = exports.expect = exports.assert = exports.AssertionError = exports.Assertion = exports.ether = exports.time = exports.BN = exports.constants = exports.toBN = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chai_1 = tslib_1.__importStar(require("chai"));
|
|
5
6
|
Object.defineProperty(exports, "Assertion", { enumerable: true, get: function () { return chai_1.Assertion; } });
|
|
6
7
|
Object.defineProperty(exports, "AssertionError", { enumerable: true, get: function () { return chai_1.AssertionError; } });
|
|
7
8
|
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return chai_1.assert; } });
|
|
8
9
|
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return chai_1.expect; } });
|
|
9
10
|
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return chai_1.config; } });
|
|
10
11
|
Object.defineProperty(exports, "should", { enumerable: true, get: function () { return chai_1.should; } });
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
require("chai-bn");
|
|
13
|
+
const chai_as_promised_1 = tslib_1.__importDefault(require("chai-as-promised"));
|
|
14
|
+
const web3_utils_1 = require("web3-utils");
|
|
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
|
+
if (typeof (num) === 'string' && num.startsWith('0x')) {
|
|
22
|
+
return new bn_js_1.default(num.substring(2), 16);
|
|
23
|
+
}
|
|
24
|
+
return new bn_js_1.default(num, base);
|
|
25
|
+
}
|
|
26
|
+
exports.toBN = toBN;
|
|
14
27
|
exports.constants = {
|
|
15
28
|
ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
|
|
16
29
|
EEE_ADDRESS: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
|
|
17
30
|
ZERO_BYTES32: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
18
|
-
MAX_UINT256:
|
|
19
|
-
MAX_INT256:
|
|
20
|
-
MIN_INT256: -(
|
|
21
|
-
MAX_UINT128: 2n ** 128n - 1n,
|
|
31
|
+
MAX_UINT256: toBN('2').pow(toBN('256')).sub(toBN('1')).toString(),
|
|
32
|
+
MAX_INT256: toBN('2').pow(toBN('255')).sub(toBN('1')).toString(),
|
|
33
|
+
MIN_INT256: toBN('2').pow(toBN('255')).mul(toBN('-1')).toString(),
|
|
22
34
|
};
|
|
35
|
+
exports.time = timeImpl;
|
|
23
36
|
function ether(n) {
|
|
24
|
-
return (0,
|
|
37
|
+
return toBN((0, web3_utils_1.toWei)(n, 'ether'));
|
|
25
38
|
}
|
|
26
39
|
exports.ether = ether;
|
|
27
40
|
//# sourceMappingURL=prelude.js.map
|
package/dist/src/prelude.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/prelude.ts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GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;IAChE,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC3D,CAAC;AAaE,QAAA,IAAI,GAAS,QAAQ,CAAC;AAEnC,SAAgB,KAAK,CAAE,CAAS;IAC5B,OAAO,IAAI,CAAC,IAAA,kBAAK,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AACnC,CAAC;AAFD,sBAEC"}
|
package/dist/src/profileEVM.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { PathLike, promises as fs } from 'fs';
|
|
4
|
-
import { providers } from 'ethers';
|
|
5
3
|
export declare const gasspectOptionsDefault: {
|
|
6
4
|
minOpGasCost: number;
|
|
7
5
|
args: boolean;
|
|
8
6
|
res: boolean;
|
|
9
7
|
};
|
|
10
|
-
export declare function profileEVM(
|
|
11
|
-
export declare function gasspectEVM(
|
|
8
|
+
export declare function profileEVM(txHash: string, instruction: string[], optionalTraceFile?: PathLike | fs.FileHandle): Promise<number[]>;
|
|
9
|
+
export declare function gasspectEVM(txHash: string, gasspectOptions?: Record<string, unknown>, optionalTraceFile?: PathLike | fs.FileHandle): Promise<string[]>;
|
package/dist/src/profileEVM.js
CHANGED
|
@@ -1,7 +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
|
+
const util_1 = require("util");
|
|
4
5
|
const fs_1 = require("fs");
|
|
6
|
+
const prelude_1 = require("./prelude");
|
|
5
7
|
exports.gasspectOptionsDefault = {
|
|
6
8
|
minOpGasCost: 300,
|
|
7
9
|
args: false,
|
|
@@ -10,21 +12,16 @@ exports.gasspectOptionsDefault = {
|
|
|
10
12
|
function _normalizeOp(ops, i) {
|
|
11
13
|
if (ops[i].op === 'STATICCALL') {
|
|
12
14
|
ops[i].gasCost = ops[i].gasCost - ops[i + 1].gas;
|
|
13
|
-
if (ops[i].stack.length > 8 &&
|
|
14
|
-
ops[i].stack[ops[i].stack.length - 8] === '0000000000000000000000000000000000000000000000000000000000000001') {
|
|
15
|
+
if (ops[i].stack.length > 8 && ops[i].stack[ops[i].stack.length - 8] === '0000000000000000000000000000000000000000000000000000000000000001') {
|
|
15
16
|
ops[i].op = 'STATICCALL-ECRECOVER';
|
|
16
17
|
}
|
|
17
|
-
else if (ops[i].stack.length > 8 &&
|
|
18
|
-
ops[i].stack[ops[i].stack.length - 8] <= '00000000000000000000000000000000000000000000000000000000000000FF') {
|
|
18
|
+
else if (ops[i].stack.length > 8 && ops[i].stack[ops[i].stack.length - 8] <= '00000000000000000000000000000000000000000000000000000000000000FF') {
|
|
19
19
|
ops[i].op = 'STATICCALL-' + ops[i].stack[ops[i].stack.length - 8].substr(62, 2);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
ops[i].args = [
|
|
23
|
-
'0x' + ops[i].stack[ops[i].stack.length - 2].
|
|
24
|
-
'0x' +
|
|
25
|
-
(ops[i].memory || [])
|
|
26
|
-
.join('')
|
|
27
|
-
.substr(2 * Number(ops[i].stack[ops[i].stack.length - 3]), 2 * Number(ops[i].stack[ops[i].stack.length - 4])),
|
|
23
|
+
'0x' + ops[i].stack[ops[i].stack.length - 2].substr(24),
|
|
24
|
+
'0x' + (ops[i].memory || []).join('').substr(2 * (0, prelude_1.toBN)(ops[i].stack[ops[i].stack.length - 3]).toNumber(), 2 * (0, prelude_1.toBN)(ops[i].stack[ops[i].stack.length - 4]).toNumber()),
|
|
28
25
|
];
|
|
29
26
|
if (ops[i].gasCost === 100) {
|
|
30
27
|
ops[i].op += '_R';
|
|
@@ -33,11 +30,8 @@ function _normalizeOp(ops, i) {
|
|
|
33
30
|
}
|
|
34
31
|
if (['CALL', 'DELEGATECALL', 'CALLCODE'].indexOf(ops[i].op) !== -1) {
|
|
35
32
|
ops[i].args = [
|
|
36
|
-
'0x' + ops[i].stack[ops[i].stack.length - 2].
|
|
37
|
-
'0x' +
|
|
38
|
-
(ops[i].memory || [])
|
|
39
|
-
.join('')
|
|
40
|
-
.substr(2 * Number(ops[i].stack[ops[i].stack.length - 4]), 2 * Number(ops[i].stack[ops[i].stack.length - 5])),
|
|
33
|
+
'0x' + ops[i].stack[ops[i].stack.length - 2].substr(24),
|
|
34
|
+
'0x' + (ops[i].memory || []).join('').substr(2 * (0, prelude_1.toBN)(ops[i].stack[ops[i].stack.length - 4]).toNumber(), 2 * (0, prelude_1.toBN)(ops[i].stack[ops[i].stack.length - 5]).toNumber()),
|
|
41
35
|
];
|
|
42
36
|
ops[i].gasCost = ops[i].gasCost - ops[i + 1].gas;
|
|
43
37
|
ops[i].res = ops[i + 1].stack[ops[i + 1].stack.length - 1];
|
|
@@ -49,14 +43,16 @@ function _normalizeOp(ops, i) {
|
|
|
49
43
|
ops[i].gasCost = 3;
|
|
50
44
|
}
|
|
51
45
|
if (['SSTORE', 'SLOAD'].indexOf(ops[i].op) !== -1) {
|
|
52
|
-
ops[i].args = [
|
|
46
|
+
ops[i].args = [
|
|
47
|
+
'0x' + ops[i].stack[ops[i].stack.length - 1],
|
|
48
|
+
];
|
|
53
49
|
if (ops[i].op === 'SSTORE') {
|
|
54
50
|
ops[i].args.push('0x' + ops[i].stack[ops[i].stack.length - 2]);
|
|
55
51
|
}
|
|
56
52
|
if (ops[i].gasCost === 100) {
|
|
57
53
|
ops[i].op += '_R';
|
|
58
54
|
}
|
|
59
|
-
if (ops[i].gasCost
|
|
55
|
+
if (ops[i].gasCost === 20000) {
|
|
60
56
|
ops[i].op += '_I';
|
|
61
57
|
}
|
|
62
58
|
if (ops[i].op.startsWith('SLOAD')) {
|
|
@@ -64,25 +60,43 @@ function _normalizeOp(ops, i) {
|
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
62
|
if (ops[i].op === 'EXTCODESIZE') {
|
|
67
|
-
ops[i].args = [
|
|
63
|
+
ops[i].args = [
|
|
64
|
+
'0x' + ops[i].stack[ops[i].stack.length - 1].substr(24),
|
|
65
|
+
];
|
|
68
66
|
ops[i].res = ops[i + 1].stack[ops[i + 1].stack.length - 1];
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
|
-
async function profileEVM(
|
|
72
|
-
|
|
69
|
+
async function profileEVM(txHash, instruction, optionalTraceFile) {
|
|
70
|
+
if (!web3.currentProvider || typeof web3.currentProvider === 'string' || !web3.currentProvider.send) {
|
|
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
|
+
});
|
|
73
79
|
const str = JSON.stringify(trace);
|
|
74
80
|
if (optionalTraceFile) {
|
|
75
81
|
await fs_1.promises.writeFile(optionalTraceFile, str);
|
|
76
82
|
}
|
|
77
|
-
return instruction.map(
|
|
83
|
+
return instruction.map(instr => {
|
|
78
84
|
return str.split('"' + instr.toUpperCase() + '"').length - 1;
|
|
79
85
|
});
|
|
80
86
|
}
|
|
81
87
|
exports.profileEVM = profileEVM;
|
|
82
|
-
async function gasspectEVM(
|
|
88
|
+
async function gasspectEVM(txHash, gasspectOptions = {}, optionalTraceFile) {
|
|
83
89
|
const options = { ...exports.gasspectOptionsDefault, ...gasspectOptions };
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
if (!web3.currentProvider || typeof web3.currentProvider === 'string' || !web3.currentProvider.send) {
|
|
91
|
+
throw new Error('Unsupported provider');
|
|
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
100
|
const traceAddress = [0, -1];
|
|
87
101
|
for (const [i, op] of ops.entries()) {
|
|
88
102
|
op.traceAddress = traceAddress.slice(0, traceAddress.length - 1);
|
|
@@ -95,17 +109,12 @@ async function gasspectEVM(provider, txHash, gasspectOptions = {}, optionalTrace
|
|
|
95
109
|
traceAddress.pop();
|
|
96
110
|
}
|
|
97
111
|
}
|
|
98
|
-
const result = ops
|
|
99
|
-
.filter((op) => op.gasCost > options.minOpGasCost)
|
|
100
|
-
.map((op) => op.traceAddress.join('-') +
|
|
101
|
-
'-' +
|
|
102
|
-
op.op +
|
|
112
|
+
const result = ops.filter(op => op.gasCost > options.minOpGasCost).map(op => op.traceAddress.join('-') + '-' + op.op +
|
|
103
113
|
(options.args ? '(' + (op.args || []).join(',') + ')' : '') +
|
|
104
114
|
(options.res ? (op.res ? ':0x' + op.res : '') : '') +
|
|
105
|
-
' = ' +
|
|
106
|
-
op.gasCost);
|
|
115
|
+
' = ' + op.gasCost);
|
|
107
116
|
if (optionalTraceFile) {
|
|
108
|
-
await fs_1.promises.writeFile(optionalTraceFile, JSON.stringify(
|
|
117
|
+
await fs_1.promises.writeFile(optionalTraceFile, JSON.stringify(result));
|
|
109
118
|
}
|
|
110
119
|
return result;
|
|
111
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profileEVM.js","sourceRoot":"","sources":["../../src/profileEVM.ts"],"names":[],"mappings":";;;AAAA,2BAA8C;
|
|
1
|
+
{"version":3,"file":"profileEVM.js","sourceRoot":"","sources":["../../src/profileEVM.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AACjC,2BAA8C;AAC9C,uCAAiC;AA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,CAAC,EAAE,CAAC,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC,EAAE;QAChG,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,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;IAExC,IAAI,iBAAiB,EAAE;QACnB,MAAM,aAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;KACjE;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAzCD,kCAyCC"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { constants } from './prelude';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export declare function timeIncreaseTo(seconds: number | string | BN): Promise<void>;
|
|
4
|
+
export interface Token extends Truffle.ContractInstance {
|
|
5
|
+
balanceOf(account: string, txDetails?: Truffle.TransactionDetails): Promise<BN>;
|
|
6
|
+
}
|
|
7
|
+
export declare function trackReceivedTokenAndTx<T extends unknown[], U extends Truffle.AnyEvent>(token: Token | {
|
|
5
8
|
address: typeof constants.ZERO_ADDRESS;
|
|
6
9
|
} | {
|
|
7
10
|
address: typeof constants.EEE_ADDRESS;
|
|
8
|
-
}, wallet: string, txPromise: (...args: T) => Promise<
|
|
11
|
+
}, wallet: string, txPromise: (...args: T) => Promise<Truffle.TransactionResponse<U>>, ...args: T): Promise<readonly [import("bn.js"), Truffle.TransactionResponse<U>]>;
|
|
9
12
|
export declare function fixSignature(signature: string): string;
|
|
10
|
-
export declare function signMessage(signer:
|
|
11
|
-
export declare function countInstructions(
|
|
13
|
+
export declare function signMessage(signer: string, messageHex?: string): Promise<string>;
|
|
14
|
+
export declare function countInstructions(txHash: string, instructions: string[]): Promise<number[]>;
|
package/dist/src/utils.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
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
|
-
const
|
|
4
|
+
const util_1 = require("util");
|
|
5
|
+
const prelude_1 = require("./prelude");
|
|
5
6
|
async function timeIncreaseTo(seconds) {
|
|
6
7
|
const delay = 1000 - new Date().getMilliseconds();
|
|
7
|
-
await new Promise(
|
|
8
|
-
await
|
|
8
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
9
|
+
await prelude_1.time.increaseTo(seconds);
|
|
9
10
|
}
|
|
10
11
|
exports.timeIncreaseTo = timeIncreaseTo;
|
|
11
|
-
async function trackReceivedTokenAndTx(
|
|
12
|
+
async function trackReceivedTokenAndTx(token, wallet, txPromise, ...args) {
|
|
12
13
|
const [balanceFunc, isETH] = 'balanceOf' in token
|
|
13
14
|
? [() => token.balanceOf(wallet), false]
|
|
14
|
-
: [async () => await
|
|
15
|
+
: [async () => (0, prelude_1.toBN)(await web3.eth.getBalance(wallet)), true];
|
|
15
16
|
const preBalance = await balanceFunc();
|
|
16
17
|
const txResult = await txPromise(...args);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
: 0n;
|
|
18
|
+
const txFees = (wallet.toLowerCase() === txResult.receipt.from.toLowerCase() && isETH)
|
|
19
|
+
? (0, prelude_1.toBN)(txResult.receipt.gasUsed).mul((0, prelude_1.toBN)(txResult.receipt.effectiveGasPrice))
|
|
20
|
+
: (0, prelude_1.toBN)('0');
|
|
21
21
|
const postBalance = await balanceFunc();
|
|
22
22
|
return [postBalance.sub(preBalance).add(txFees), txResult];
|
|
23
23
|
}
|
|
@@ -34,14 +34,23 @@ function fixSignature(signature) {
|
|
|
34
34
|
return signature.slice(0, 130) + vHex;
|
|
35
35
|
}
|
|
36
36
|
exports.fixSignature = fixSignature;
|
|
37
|
+
// signs message in node (ganache auto-applies "Ethereum Signed Message" prefix)
|
|
37
38
|
async function signMessage(signer, messageHex = '0x') {
|
|
38
|
-
return fixSignature(await
|
|
39
|
+
return fixSignature(await web3.eth.sign(messageHex, signer));
|
|
39
40
|
}
|
|
40
41
|
exports.signMessage = signMessage;
|
|
41
|
-
async function countInstructions(
|
|
42
|
-
|
|
42
|
+
async function countInstructions(txHash, instructions) {
|
|
43
|
+
if (!web3.currentProvider || typeof web3.currentProvider === 'string' || !web3.currentProvider.send) {
|
|
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
|
+
});
|
|
43
52
|
const str = JSON.stringify(trace);
|
|
44
|
-
return instructions.map(
|
|
53
|
+
return instructions.map(instr => {
|
|
45
54
|
return str.split('"' + instr.toUpperCase() + '"').length - 1;
|
|
46
55
|
});
|
|
47
56
|
}
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js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,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;QACpB,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;KAC3B,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAElC,OAAO,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QAC5B,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACP,CAAC;AAhBD,8CAgBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1inch/solidity-utils",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@nomicfoundation/hardhat-chai-matchers": "1.0.3",
|
|
42
|
-
"@typechain/hardhat": "6.1.3",
|
|
43
42
|
"@typechain/ethers-v5": "10.1.0",
|
|
43
|
+
"@typechain/hardhat": "6.1.3",
|
|
44
44
|
"@types/chai": "4.3.3",
|
|
45
45
|
"@types/eth-sig-util": "2.1.1",
|
|
46
46
|
"@types/ethereumjs-util": "6.1.0",
|