@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
|
@@ -13,6 +13,8 @@ library StringUtil {
|
|
|
13
13
|
return toHex(abi.encodePacked(value));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/// @dev this is the assembly adaptation of highly optimized toHex16 code from Mikhail Vladimirov
|
|
17
|
+
/// https://stackoverflow.com/a/69266989
|
|
16
18
|
function toHex(bytes memory data) internal pure returns (string memory result) {
|
|
17
19
|
/// @solidity memory-safe-assembly
|
|
18
20
|
assembly { // solhint-disable-line no-inline-assembly
|
|
@@ -44,7 +46,7 @@ library StringUtil {
|
|
|
44
46
|
shr(4, add(output, 0x0606060606060606060606060606060606060606060606060606060606060606)),
|
|
45
47
|
0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F
|
|
46
48
|
),
|
|
47
|
-
7
|
|
49
|
+
7 // Change 7 to 39 for lower case output
|
|
48
50
|
)
|
|
49
51
|
)
|
|
50
52
|
}
|
|
@@ -52,11 +54,11 @@ library StringUtil {
|
|
|
52
54
|
result := mload(0x40)
|
|
53
55
|
let length := mload(data)
|
|
54
56
|
let resultLength := shl(1, length)
|
|
55
|
-
let toPtr := add(result, 0x22)
|
|
56
|
-
mstore(0x40, add(toPtr, resultLength))
|
|
57
|
-
mstore(add(result, 2), 0x3078)
|
|
58
|
-
|
|
59
|
-
mstore(result, add(resultLength, 2))
|
|
57
|
+
let toPtr := add(result, 0x22) // 32 bytes for length + 2 bytes for '0x'
|
|
58
|
+
mstore(0x40, add(toPtr, resultLength)) // move free memory pointer
|
|
59
|
+
mstore(add(result, 2), 0x3078) // 0x3078 is right aligned so we write to `result + 2`
|
|
60
|
+
// to store the last 2 bytes in the beginning of the string
|
|
61
|
+
mstore(result, add(resultLength, 2)) // extra 2 bytes for '0x'
|
|
60
62
|
|
|
61
63
|
for {
|
|
62
64
|
let fromPtr := add(data, 0x20)
|
|
@@ -9,6 +9,7 @@ import "../interfaces/IERC20MetadataUppercase.sol";
|
|
|
9
9
|
import "./SafeERC20.sol";
|
|
10
10
|
import "./StringUtil.sol";
|
|
11
11
|
|
|
12
|
+
/// @title Library, which allows usage of ETH as ERC20 and ERC20 itself. Uses SafeERC20 library for ERC20 interface.
|
|
12
13
|
library UniERC20 {
|
|
13
14
|
using SafeERC20 for IERC20;
|
|
14
15
|
|
|
@@ -23,10 +24,12 @@ library UniERC20 {
|
|
|
23
24
|
IERC20 private constant _ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
|
|
24
25
|
IERC20 private constant _ZERO_ADDRESS = IERC20(address(0));
|
|
25
26
|
|
|
27
|
+
/// @dev Returns true if `token` is ETH.
|
|
26
28
|
function isETH(IERC20 token) internal pure returns (bool) {
|
|
27
29
|
return (token == _ZERO_ADDRESS || token == _ETH_ADDRESS);
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/// @dev Returns `account` ERC20 `token` balance.
|
|
30
33
|
function uniBalanceOf(IERC20 token, address account) internal view returns (uint256) {
|
|
31
34
|
if (isETH(token)) {
|
|
32
35
|
return account.balance;
|
|
@@ -35,8 +38,13 @@ library UniERC20 {
|
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
/// @dev
|
|
39
|
-
function
|
|
41
|
+
/// @dev `token` transfer `to` `amount`.
|
|
42
|
+
/// Note that this function does nothing in case of zero amount.
|
|
43
|
+
function uniTransfer(
|
|
44
|
+
IERC20 token,
|
|
45
|
+
address payable to,
|
|
46
|
+
uint256 amount
|
|
47
|
+
) internal {
|
|
40
48
|
if (amount > 0) {
|
|
41
49
|
if (isETH(token)) {
|
|
42
50
|
if (address(this).balance < amount) revert InsufficientBalance();
|
|
@@ -49,8 +57,14 @@ library UniERC20 {
|
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
/// @dev
|
|
53
|
-
|
|
60
|
+
/// @dev `token` transfer `from` `to` `amount`.
|
|
61
|
+
/// Note that this function does nothing in case of zero amount.
|
|
62
|
+
function uniTransferFrom(
|
|
63
|
+
IERC20 token,
|
|
64
|
+
address payable from,
|
|
65
|
+
address to,
|
|
66
|
+
uint256 amount
|
|
67
|
+
) internal {
|
|
54
68
|
if (amount > 0) {
|
|
55
69
|
if (isETH(token)) {
|
|
56
70
|
if (msg.value < amount) revert NotEnoughValue();
|
|
@@ -70,47 +84,62 @@ library UniERC20 {
|
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
86
|
|
|
73
|
-
|
|
87
|
+
/// @dev Returns `token` symbol from ERC20 metadata.
|
|
88
|
+
function uniSymbol(IERC20 token) internal view returns (string memory) {
|
|
74
89
|
return _uniDecode(token, IERC20Metadata.symbol.selector, IERC20MetadataUppercase.SYMBOL.selector);
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
|
|
92
|
+
/// @dev Returns `token` name from ERC20 metadata.
|
|
93
|
+
function uniName(IERC20 token) internal view returns (string memory) {
|
|
78
94
|
return _uniDecode(token, IERC20Metadata.name.selector, IERC20MetadataUppercase.NAME.selector);
|
|
79
95
|
}
|
|
80
96
|
|
|
81
|
-
|
|
97
|
+
/// @dev Reverts if `token` is ETH, otherwise performs ERC20 forceApprove.
|
|
98
|
+
function uniApprove(
|
|
99
|
+
IERC20 token,
|
|
100
|
+
address to,
|
|
101
|
+
uint256 amount
|
|
102
|
+
) internal {
|
|
82
103
|
if (isETH(token)) revert ApproveCalledOnETH();
|
|
83
104
|
|
|
84
105
|
token.forceApprove(to, amount);
|
|
85
106
|
}
|
|
86
107
|
|
|
87
|
-
/// 20K gas is provided to account for possible implementations of name/symbol
|
|
108
|
+
/// @dev 20K gas is provided to account for possible implementations of name/symbol
|
|
88
109
|
/// (token implementation might be behind proxy or store the value in storage)
|
|
89
|
-
function _uniDecode(
|
|
110
|
+
function _uniDecode(
|
|
111
|
+
IERC20 token,
|
|
112
|
+
bytes4 lowerCaseSelector,
|
|
113
|
+
bytes4 upperCaseSelector
|
|
114
|
+
) private view returns (string memory result) {
|
|
90
115
|
if (isETH(token)) {
|
|
91
116
|
return "ETH";
|
|
92
117
|
}
|
|
93
118
|
|
|
94
|
-
(bool success, bytes memory data) = address(token).staticcall{
|
|
119
|
+
(bool success, bytes memory data) = address(token).staticcall{gas: 20000}(
|
|
95
120
|
abi.encodeWithSelector(lowerCaseSelector)
|
|
96
121
|
);
|
|
97
122
|
if (!success) {
|
|
98
|
-
(success, data) = address(token).staticcall{
|
|
99
|
-
abi.encodeWithSelector(upperCaseSelector)
|
|
100
|
-
);
|
|
123
|
+
(success, data) = address(token).staticcall{gas: 20000}(abi.encodeWithSelector(upperCaseSelector));
|
|
101
124
|
}
|
|
102
125
|
|
|
103
126
|
if (success && data.length >= 0x40) {
|
|
104
127
|
(uint256 offset, uint256 len) = abi.decode(data, (uint256, uint256));
|
|
105
|
-
|
|
128
|
+
/*
|
|
129
|
+
return data is padded up to 32 bytes with ABI encoder also sometimes
|
|
130
|
+
there is extra 32 bytes of zeros padded in the end:
|
|
131
|
+
https://github.com/ethereum/solidity/issues/10170
|
|
132
|
+
because of that we can't check for equality and instead check
|
|
133
|
+
that overall data length is greater or equal than string length + extra 64 bytes
|
|
134
|
+
*/
|
|
135
|
+
if (offset == 0x20 && data.length >= 0x40 + len) {
|
|
106
136
|
/// @solidity memory-safe-assembly
|
|
107
137
|
assembly { // solhint-disable-line no-inline-assembly
|
|
108
|
-
result := add(data,
|
|
138
|
+
result := add(data, 0x40)
|
|
109
139
|
}
|
|
110
140
|
return result;
|
|
111
141
|
}
|
|
112
142
|
}
|
|
113
|
-
|
|
114
143
|
if (success && data.length == 32) {
|
|
115
144
|
uint256 len = 0;
|
|
116
145
|
while (len < data.length && data[len] >= 0x20 && data[len] <= 0x7E) {
|
|
@@ -8,7 +8,12 @@ import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
|
|
|
8
8
|
contract TokenCustomDecimalsMock is ERC20Permit, Ownable {
|
|
9
9
|
uint8 internal immutable _decimals;
|
|
10
10
|
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(
|
|
12
|
+
string memory name,
|
|
13
|
+
string memory symbol,
|
|
14
|
+
uint256 amount,
|
|
15
|
+
uint8 decimals_
|
|
16
|
+
) ERC20(name, symbol) ERC20Permit(name) {
|
|
12
17
|
_mint(msg.sender, amount);
|
|
13
18
|
_decimals = decimals_;
|
|
14
19
|
}
|
|
@@ -25,7 +30,7 @@ contract TokenCustomDecimalsMock is ERC20Permit, Ownable {
|
|
|
25
30
|
return _decimals;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
function getChainId() external view returns(uint256) {
|
|
33
|
+
function getChainId() external view returns (uint256) {
|
|
29
34
|
return block.chainid;
|
|
30
35
|
}
|
|
31
36
|
}
|
|
@@ -6,7 +6,6 @@ pragma abicoder v1;
|
|
|
6
6
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
|
7
7
|
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
contract TokenMock is ERC20, Ownable {
|
|
11
10
|
// solhint-disable-next-line no-empty-blocks
|
|
12
11
|
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}
|
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,E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
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,"file":"permit.js","sourceRoot":"","sources":["../../src/permit.ts"],"names":[],"mappings":";;;AAAA,yDAA8E;AAC9E,uCAAsC;AAGtC,4CAAkD;AAErC,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,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CACT,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrF,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC,kBAAkB,CAC1D,oEAAoE,EACpE,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAC7D,CAAC;IACF,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC;AA7BD,4CA6BC;AAED,SAAgB,UAAU,CAAC,MAAuB,EAAE,IAAqB;IACrE,OAAO,MAAM,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAFD,gCAEC"}
|
package/dist/src/prelude.d.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { Assertion, AssertionError, 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,40 +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
|
-
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;
|
|
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; } });
|
|
27
14
|
exports.constants = {
|
|
28
15
|
ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
|
|
29
16
|
EEE_ADDRESS: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
|
|
30
17
|
ZERO_BYTES32: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
31
|
-
MAX_UINT256:
|
|
32
|
-
MAX_INT256:
|
|
33
|
-
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,
|
|
34
22
|
};
|
|
35
|
-
exports.time = timeImpl;
|
|
36
23
|
function ether(n) {
|
|
37
|
-
return
|
|
24
|
+
return (0, utils_1.parseUnits)(n).toBigInt();
|
|
38
25
|
}
|
|
39
26
|
exports.ether = ether;
|
|
40
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"}
|