@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.
@@ -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 // Change 7 to 39 for lower case output
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) // 32 bytes for length + 2 bytes for '0x'
56
- mstore(0x40, add(toPtr, resultLength)) // move free memory pointer
57
- mstore(add(result, 2), 0x3078) // 0x3078 is right aligned so we write to `result + 2`
58
- // to store the last 2 bytes in the beginning of the string
59
- mstore(result, add(resultLength, 2)) // extra 2 bytes for '0x'
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 note that this function does nothing in case of zero amount
39
- function uniTransfer(IERC20 token, address payable to, uint256 amount) internal {
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 note that this function does nothing in case of zero amount
53
- function uniTransferFrom(IERC20 token, address payable from, address to, uint256 amount) internal {
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
- function uniSymbol(IERC20 token) internal view returns(string memory) {
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
- function uniName(IERC20 token) internal view returns(string memory) {
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
- function uniApprove(IERC20 token, address to, uint256 amount) internal {
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(IERC20 token, bytes4 lowerCaseSelector, bytes4 upperCaseSelector) private view returns(string memory result) {
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{ gas: 20000 }(
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{ gas: 20000 }(
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
- if (offset == 0x20 && len > 0 && data.length == 0x40 + len) {
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, 0x20)
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(string memory name, string memory symbol, uint256 amount, uint8 decimals_) ERC20(name, symbol) ERC20Permit(name) {
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) {}
@@ -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;
1
+ export declare function assertRoughlyEqualValues(expected: string | number | bigint, actual: string | number | bigint, relativeDiff: number): void;
@@ -1,32 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertRoughlyEqualValues = exports.toBNExtended = void 0;
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 = 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();
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 = (0, prelude_1.toBN)('1');
14
+ let multiplerDenominator = 1n;
22
15
  while (!Number.isInteger(multiplerNumerator)) {
23
- multiplerDenominator = multiplerDenominator.mul((0, prelude_1.toBN)('10'));
16
+ multiplerDenominator = multiplerDenominator * 10n;
24
17
  multiplerNumerator *= 10;
25
18
  }
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`);
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;
@@ -1 +1 @@
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,G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,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"}
@@ -1,8 +1,8 @@
1
- /// <reference types="node" />
2
- import { MessageTypes, SignTypedDataVersion, TypedMessage } from '@metamask/eth-sig-util';
3
- import { Token } from './utils';
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: string;
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: BN | string): string;
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 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;
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;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
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' + eth_sig_util_1.TypedDataUtils.hashStruct('EIP712Domain', { name, version, chainId, verifyingContract }, { EIP712Domain: exports.EIP712Domain }, exports.TypedDataVersion).toString('hex');
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
- primaryType: 'Permit',
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
- primaryType: 'Permit',
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, ownerPrivateKey, permitContract, tokenVersion, chainId, spender, value, deadline = exports.defaultDeadline) {
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 = 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();
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, holderPrivateKey, permitContract, tokenVersion, chainId, spender, allowed, expiry = exports.defaultDeadline) {
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 = 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();
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;
@@ -1 +1 @@
1
- {"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/permit.ts"],"names":[],"mappings":";;;AAAA,yDAAyH;AACzH,qDAA6C;AAE7C,uCAAsC;AAGzB,QAAA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assertion, AssertionError, assert, expect, config, should } from 'chai';
2
- import 'chai-bn';
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: string;
10
- readonly MAX_INT256: string;
11
- readonly MIN_INT256: string;
7
+ readonly MAX_UINT256: bigint;
8
+ readonly MAX_INT256: bigint;
9
+ readonly MIN_INT256: bigint;
10
+ readonly MAX_UINT128: bigint;
12
11
  };
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, };
12
+ export { time };
13
+ export declare function ether(n: string): bigint;
14
+ export { Assertion, AssertionError, assert, expect, config, should };
@@ -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.BN = exports.constants = exports.toBN = void 0;
4
- const tslib_1 = require("tslib");
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("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;
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: 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(),
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 toBN((0, web3_utils_1.toWei)(n, 'ether'));
24
+ return (0, utils_1.parseUnits)(n).toBigInt();
38
25
  }
39
26
  exports.ether = ether;
40
27
  //# sourceMappingURL=prelude.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/prelude.ts"],"names":[],"mappings":";;;;AAAA,qDAAuF;AA4CnF,0FA5CW,gBAAS,OA4CX;AACT,+FA7CsB,qBAAc,OA6CtB;AACd,uFA9CsC,aAAM,OA8CtC;AACN,uFA/C8C,aAAM,OA+C9C;AACN,uFAhDsD,aAAM,OAgDtD;AACN,uFAjD8D,aAAM,OAiD9D;AAhDV,mBAAiB;AACjB,gFAA8C;AAC9C,2CAAmC;AACnC,0DAAuB;AAuBnB,aAvBG,eAAE,CAuBH;AAtBN,cAAI,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACzB,8DAA8D;AAC9D,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAEjE,SAAgB,IAAI,CAAE,GAAoB,EAAE,IAAqB;IAC7D,IAAI,OAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAClD,OAAO,IAAI,eAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;KACvC;IACD,OAAO,IAAI,eAAE,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC;AALD,oBAKC;AAEY,QAAA,SAAS,GAAG;IACrB,YAAY,EAAE,4CAA4C;IAC1D,WAAW,EAAE,4CAA4C;IACzD,YAAY,EAAE,oEAAoE;IAClF,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;IACjE,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,C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+1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ import '@nomiclabs/hardhat-ethers';
3
4
  import { PathLike, promises as fs } from 'fs';
4
5
  export declare const gasspectOptionsDefault: {
5
6
  minOpGasCost: number;