@1inch/solidity-utils 2.0.24 → 2.0.25
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.
|
@@ -133,9 +133,8 @@ library ECDSA {
|
|
|
133
133
|
mstore(add(ptr, 0x24), 0x40)
|
|
134
134
|
mstore(add(ptr, 0x44), signature.length)
|
|
135
135
|
calldatacopy(add(ptr, 0x64), signature.offset, signature.length)
|
|
136
|
-
mstore(0, 0)
|
|
137
136
|
if staticcall(gas(), signer, ptr, add(0x64, signature.length), 0, 0x20) {
|
|
138
|
-
success := eq(selector, mload(0))
|
|
137
|
+
success := and(eq(selector, mload(0)), eq(returndatasize(), 0x20))
|
|
139
138
|
}
|
|
140
139
|
}
|
|
141
140
|
}
|
|
@@ -153,9 +152,8 @@ library ECDSA {
|
|
|
153
152
|
mstore(add(ptr, 0x64), r)
|
|
154
153
|
mstore(add(ptr, 0x84), s)
|
|
155
154
|
mstore8(add(ptr, 0xa4), v)
|
|
156
|
-
mstore(0, 0)
|
|
157
155
|
if staticcall(gas(), signer, ptr, 0xa5, 0, 0x20) {
|
|
158
|
-
success := eq(selector, mload(0))
|
|
156
|
+
success := and(eq(selector, mload(0)), eq(returndatasize(), 0x20))
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
159
|
}
|
|
@@ -174,9 +172,8 @@ library ECDSA {
|
|
|
174
172
|
mstore(add(ptr, 0x44), 64)
|
|
175
173
|
mstore(add(ptr, 0x64), r)
|
|
176
174
|
mstore(add(ptr, 0x84), vs)
|
|
177
|
-
mstore(0, 0)
|
|
178
175
|
if staticcall(gas(), signer, ptr, 0xa5, 0, 0x20) {
|
|
179
|
-
success := eq(selector, mload(0))
|
|
176
|
+
success := and(eq(selector, mload(0)), eq(returndatasize(), 0x20))
|
|
180
177
|
}
|
|
181
178
|
}
|
|
182
179
|
}
|
|
@@ -196,9 +193,8 @@ library ECDSA {
|
|
|
196
193
|
mstore(add(ptr, 0x64), r)
|
|
197
194
|
mstore(add(ptr, 0x84), shr(1, shl(1, vs)))
|
|
198
195
|
mstore8(add(ptr, 0xa4), add(27, shr(255, vs)))
|
|
199
|
-
mstore(0, 0)
|
|
200
196
|
if staticcall(gas(), signer, ptr, 0xa5, 0, 0x20) {
|
|
201
|
-
success := eq(selector, mload(0))
|
|
197
|
+
success := and(eq(selector, mload(0)), eq(returndatasize(), 0x20))
|
|
202
198
|
}
|
|
203
199
|
}
|
|
204
200
|
}
|
|
@@ -51,12 +51,12 @@ library StringUtil {
|
|
|
51
51
|
|
|
52
52
|
result := mload(0x40)
|
|
53
53
|
let length := mload(data)
|
|
54
|
-
let resultLength :=
|
|
55
|
-
let toPtr := add(result,
|
|
54
|
+
let resultLength := shl(1, length)
|
|
55
|
+
let toPtr := add(result, 0x22) // 32 bytes for length + 2 bytes for '0x'
|
|
56
56
|
mstore(0x40, add(toPtr, resultLength)) // move free memory pointer
|
|
57
|
-
mstore(result,
|
|
58
|
-
|
|
59
|
-
|
|
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'
|
|
60
60
|
|
|
61
61
|
for {
|
|
62
62
|
let fromPtr := add(data, 0x20)
|
|
@@ -17,7 +17,6 @@ library UniERC20 {
|
|
|
17
17
|
using SafeERC20 for IERC20;
|
|
18
18
|
|
|
19
19
|
error InsufficientBalance();
|
|
20
|
-
error ETHSendFailed();
|
|
21
20
|
error ApproveCalledOnETH();
|
|
22
21
|
error NotEnoughValue();
|
|
23
22
|
error FromIsNotSender();
|
|
@@ -42,8 +41,8 @@ library UniERC20 {
|
|
|
42
41
|
if (amount > 0) {
|
|
43
42
|
if (isETH(token)) {
|
|
44
43
|
if (address(this).balance < amount) revert InsufficientBalance();
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
// we do not use low-level calls to protect from possible reentrancy
|
|
45
|
+
to.transfer(amount);
|
|
47
46
|
} else {
|
|
48
47
|
token.safeTransfer(to, amount);
|
|
49
48
|
}
|
|
@@ -58,10 +57,8 @@ library UniERC20 {
|
|
|
58
57
|
if (to != address(this)) revert ToIsNotThis();
|
|
59
58
|
if (msg.value > amount) {
|
|
60
59
|
// Return remainder if exist
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!success) revert ETHSendFailed();
|
|
64
|
-
}
|
|
60
|
+
// we do not use low-level calls to protect from possible reentrancy
|
|
61
|
+
unchecked { from.transfer(msg.value - amount); }
|
|
65
62
|
}
|
|
66
63
|
} else {
|
|
67
64
|
token.safeTransferFrom(from, to, amount);
|
|
@@ -83,7 +80,7 @@ library UniERC20 {
|
|
|
83
80
|
token.forceApprove(to, amount);
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
function _uniDecode(IERC20 token, bytes4 lowerCaseSelector, bytes4 upperCaseSelector) private view returns(string memory) {
|
|
83
|
+
function _uniDecode(IERC20 token, bytes4 lowerCaseSelector, bytes4 upperCaseSelector) private view returns(string memory result) {
|
|
87
84
|
if (isETH(token)) {
|
|
88
85
|
return "ETH";
|
|
89
86
|
}
|
|
@@ -97,10 +94,14 @@ library UniERC20 {
|
|
|
97
94
|
);
|
|
98
95
|
}
|
|
99
96
|
|
|
100
|
-
if (success && data.length >=
|
|
97
|
+
if (success && data.length >= 0x40) {
|
|
101
98
|
(uint256 offset, uint256 len) = abi.decode(data, (uint256, uint256));
|
|
102
|
-
if (offset == 0x20 && len > 0 &&
|
|
103
|
-
|
|
99
|
+
if (offset == 0x20 && len > 0 && data.length == 0x40 + len) {
|
|
100
|
+
/// @solidity memory-safe-assembly
|
|
101
|
+
assembly { // solhint-disable-line no-inline-assembly
|
|
102
|
+
result := add(data, 0x20)
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
@@ -113,6 +114,7 @@ library UniERC20 {
|
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
if (len > 0) {
|
|
117
|
+
/// @solidity memory-safe-assembly
|
|
116
118
|
assembly { // solhint-disable-line no-inline-assembly
|
|
117
119
|
mstore(data, len)
|
|
118
120
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
|
|
5
|
+
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
|
|
6
|
+
|
|
7
|
+
contract ERC20PermitMock is ERC20Permit {
|
|
8
|
+
constructor(
|
|
9
|
+
string memory name,
|
|
10
|
+
string memory symbol,
|
|
11
|
+
address initialAccount,
|
|
12
|
+
uint256 initialBalance
|
|
13
|
+
) payable ERC20(name, symbol) ERC20Permit(name) {
|
|
14
|
+
_mint(initialAccount, initialBalance);
|
|
15
|
+
}
|
|
16
|
+
}
|