@1inch/solidity-utils 2.2.6 → 2.2.8
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/permit.d.ts +3 -2
- package/dist/src/permit.js +22 -2
- package/dist/src/permit.js.map +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +15 -10
- package/dist/src/utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -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/permit.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SignTypedDataVersion } from '@metamask/eth-sig-util';
|
|
2
2
|
import { Contract } from 'ethers';
|
|
3
3
|
import { Wallet } from 'ethers';
|
|
4
|
+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
|
|
4
5
|
export declare const TypedDataVersion = SignTypedDataVersion.V4;
|
|
5
6
|
export declare const defaultDeadline: bigint;
|
|
6
7
|
export declare const EIP712Domain: {
|
|
@@ -60,6 +61,6 @@ export declare function buildDataLikeDai(name: string, version: string, chainId:
|
|
|
60
61
|
readonly allowed: boolean;
|
|
61
62
|
};
|
|
62
63
|
};
|
|
63
|
-
export declare function getPermit(owner: Wallet, permitContract: Contract, tokenVersion: string, chainId: number, spender: string, value: string, deadline?: string): Promise<string>;
|
|
64
|
-
export declare function getPermitLikeDai(holder: Wallet, permitContract: Contract, tokenVersion: string, chainId: number, spender: string, allowed: boolean, expiry?: string): Promise<string>;
|
|
64
|
+
export declare function getPermit(owner: Wallet | SignerWithAddress, permitContract: Contract, tokenVersion: string, chainId: number, spender: string, value: string, deadline?: string, compact?: boolean): Promise<string>;
|
|
65
|
+
export declare function getPermitLikeDai(holder: Wallet | SignerWithAddress, permitContract: Contract, tokenVersion: string, chainId: number, spender: string, allowed: boolean, expiry?: string, compact?: boolean): Promise<string>;
|
|
65
66
|
export declare function withTarget(target: bigint | string, data: bigint | string): string;
|
package/dist/src/permit.js
CHANGED
|
@@ -63,12 +63,22 @@ exports.buildDataLikeDai = buildDataLikeDai;
|
|
|
63
63
|
/*
|
|
64
64
|
* @param permitContract The contract object with ERC20Permit type and token address for which the permit creating.
|
|
65
65
|
*/
|
|
66
|
-
async function getPermit(owner, permitContract, tokenVersion, chainId, spender, value, deadline = exports.defaultDeadline.toString()) {
|
|
66
|
+
async function getPermit(owner, permitContract, tokenVersion, chainId, spender, value, deadline = exports.defaultDeadline.toString(), compact = false) {
|
|
67
67
|
const nonce = await permitContract.nonces(owner.address);
|
|
68
68
|
const name = await permitContract.name();
|
|
69
69
|
const data = buildData(name, tokenVersion, chainId, permitContract.address, owner.address, spender, value, nonce.toString(), deadline);
|
|
70
70
|
const signature = await owner._signTypedData(data.domain, data.types, data.message);
|
|
71
71
|
const { v, r, s } = (0, utils_1.splitSignature)(signature);
|
|
72
|
+
if (compact) {
|
|
73
|
+
if (BigInt(deadline) !== prelude_1.constants.MAX_UINT256 && BigInt(deadline) >= (1n << 32n)) {
|
|
74
|
+
throw new Error('Deadline is too big for the compact mode');
|
|
75
|
+
}
|
|
76
|
+
return '0x' +
|
|
77
|
+
BigInt(value).toString(16).padStart(64, '0') +
|
|
78
|
+
(deadline === prelude_1.constants.MAX_UINT256.toString() ? '00000000' : (BigInt(deadline) + 1n).toString(16).padStart(8, '0')) +
|
|
79
|
+
BigInt(r).toString(16).padStart(64, '0') +
|
|
80
|
+
(BigInt(s) | (BigInt(v - 27) << 255n)).toString(16).padStart(64, '0');
|
|
81
|
+
}
|
|
72
82
|
const permitCall = permitContract.interface.encodeFunctionData('permit', [
|
|
73
83
|
owner.address,
|
|
74
84
|
spender,
|
|
@@ -84,12 +94,22 @@ exports.getPermit = getPermit;
|
|
|
84
94
|
/*
|
|
85
95
|
* @param permitContract The contract object with ERC20PermitLikeDai type and token address for which the permit creating.
|
|
86
96
|
*/
|
|
87
|
-
async function getPermitLikeDai(holder, permitContract, tokenVersion, chainId, spender, allowed, expiry = exports.defaultDeadline.toString()) {
|
|
97
|
+
async function getPermitLikeDai(holder, permitContract, tokenVersion, chainId, spender, allowed, expiry = exports.defaultDeadline.toString(), compact = false) {
|
|
88
98
|
const nonce = await permitContract.nonces(holder.address);
|
|
89
99
|
const name = await permitContract.name();
|
|
90
100
|
const data = buildDataLikeDai(name, tokenVersion, chainId, permitContract.address, holder.address, spender, nonce.toString(), allowed, expiry);
|
|
91
101
|
const signature = await holder._signTypedData(data.domain, data.types, data.message);
|
|
92
102
|
const { v, r, s } = (0, utils_1.splitSignature)(signature);
|
|
103
|
+
if (compact) {
|
|
104
|
+
if (BigInt(expiry) !== prelude_1.constants.MAX_UINT256 && BigInt(expiry) >= (1n << 32n)) {
|
|
105
|
+
throw new Error('Expiry is too big for the compact mode');
|
|
106
|
+
}
|
|
107
|
+
return '0x' +
|
|
108
|
+
BigInt(nonce).toString(16).padStart(8, '0') +
|
|
109
|
+
(expiry === prelude_1.constants.MAX_UINT256.toString() ? '00000000' : (BigInt(expiry) + 1n).toString(16).padStart(8, '0')) +
|
|
110
|
+
BigInt(r).toString(16).padStart(64, '0') +
|
|
111
|
+
(BigInt(s) | (BigInt(v - 27) << 255n)).toString(16).padStart(64, '0');
|
|
112
|
+
}
|
|
93
113
|
const permitCall = permitContract.interface.encodeFunctionData('permit(address,address,uint256,uint256,bool,uint8,bytes32,bytes32)', [holder.address, spender, nonce, expiry, allowed, v, r, s]);
|
|
94
114
|
return cutSelector(permitCall);
|
|
95
115
|
}
|
package/dist/src/permit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/permit.ts"],"names":[],"mappings":";;;AAAA,yDAA8E;AAC9E,uCAAsC;AAGtC,4CAAkD;
|
|
1
|
+
{"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/permit.ts"],"names":[],"mappings":";;;AAAA,yDAA8E;AAC9E,uCAAsC;AAGtC,4CAAkD;AAGrC,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,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;CACxC,CAAC;AAEW,QAAA,aAAa,GAAG;IACzB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;IACnC,EAAE,IAAI,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AAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAChH,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;YACxC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;KAC7E;IAED,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;AA1CD,4CA0CC;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/utils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function trackReceivedTokenAndTx<T extends unknown[]>(provider: p
|
|
|
5
5
|
address: typeof constants.ZERO_ADDRESS;
|
|
6
6
|
} | {
|
|
7
7
|
address: typeof constants.EEE_ADDRESS;
|
|
8
|
-
}, wallet: string, txPromise: (...args: T) => Promise<ContractTransaction>, ...args: T): Promise<
|
|
8
|
+
}, wallet: string, txPromise: (...args: T) => Promise<ContractTransaction>, ...args: T): Promise<any[]>;
|
|
9
9
|
export declare function fixSignature(signature: string): string;
|
|
10
10
|
export declare function signMessage(signer: Wallet, messageHex?: string | Bytes): Promise<string>;
|
|
11
11
|
export declare function countInstructions(provider: providers.JsonRpcProvider, txHash: string, instructions: string[]): Promise<number[]>;
|
package/dist/src/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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 prelude_1 = require("./prelude");
|
|
4
5
|
const hardhat_network_helpers_1 = require("@nomicfoundation/hardhat-network-helpers");
|
|
5
6
|
async function timeIncreaseTo(seconds) {
|
|
6
7
|
const delay = 1000 - new Date().getMilliseconds();
|
|
@@ -9,17 +10,21 @@ async function timeIncreaseTo(seconds) {
|
|
|
9
10
|
}
|
|
10
11
|
exports.timeIncreaseTo = timeIncreaseTo;
|
|
11
12
|
async function trackReceivedTokenAndTx(provider, token, wallet, txPromise, ...args) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const preBalance = await balanceFunc();
|
|
13
|
+
const isETH = token.address === prelude_1.constants.ZERO_ADDRESS || token.address === prelude_1.constants.EEE_ADDRESS;
|
|
14
|
+
const getBalance = 'balanceOf' in token ? token.balanceOf : provider.getBalance;
|
|
15
|
+
const preBalance = await getBalance(wallet);
|
|
16
16
|
const txResult = await txPromise(...args);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const postBalance = await getBalance(wallet);
|
|
18
|
+
if ('wait' in txResult) {
|
|
19
|
+
const txReceipt = await txResult.wait();
|
|
20
|
+
const txFees = wallet.toLowerCase() === txResult.from.toLowerCase() && isETH
|
|
21
|
+
? txReceipt.gasUsed.toBigInt() * txReceipt.effectiveGasPrice.toBigInt()
|
|
22
|
+
: 0n;
|
|
23
|
+
return [postBalance.sub(preBalance).add(txFees), txResult];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return [postBalance.sub(preBalance), txResult];
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
29
|
exports.trackReceivedTokenAndTx = trackReceivedTokenAndTx;
|
|
25
30
|
function fixSignature(signature) {
|
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","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AACtC,sFAAgE;AAGzD,KAAK,UAAU,cAAc,CAAC,OAAwB;IACzD,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,eAAe,EAAE,CAAC;IAClD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,MAAM,8BAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAJD,wCAIC;AAEM,KAAK,UAAU,uBAAuB,CACzC,QAAmC,EACnC,KAAwG,EACxG,MAAc,EACd,SAAuD,EACvD,GAAG,IAAO;IAEV,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,KAAK,mBAAS,CAAC,YAAY,IAAI,KAAK,CAAC,OAAO,KAAK,mBAAS,CAAC,WAAW,CAAC;IAClG,MAAM,UAAU,GAAG,WAAW,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;IAEhF,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;IAE7C,IAAI,MAAM,IAAI,QAAQ,EAAE;QACpB,MAAM,SAAS,GAAG,MAAM,Q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,CAAC,CAAC,CAAC;IAEtE,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAElC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC9B,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;AAZD,8CAYC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1inch/solidity-utils",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.9",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"prebuild": "rimraf ./dist && cti src -b",
|
|
13
13
|
"build": "tsc -p tsconfig.publish.json",
|
|
14
14
|
"postbuild": "echo done",
|
|
15
|
-
"
|
|
15
|
+
"prepublish": "yarn build",
|
|
16
16
|
"coverage": "hardhat coverage",
|
|
17
17
|
"format": "yarn format-ts && yarn format-sol",
|
|
18
18
|
"format-ts": "prettier '**/*.ts' --write",
|
|
@@ -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",
|