@1inch/solidity-utils 2.0.9 → 2.0.10
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/Permitable.sol
CHANGED
|
@@ -4,11 +4,13 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
pragma abicoder v1;
|
|
5
5
|
|
|
6
6
|
import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
|
|
7
|
-
import "./libraries/RevertReasonParser.sol";
|
|
8
7
|
import "./interfaces/IDaiLikePermit.sol";
|
|
9
8
|
|
|
10
9
|
contract Permitable {
|
|
11
|
-
|
|
10
|
+
error BadPermitLength();
|
|
11
|
+
error PermitFailed();
|
|
12
|
+
|
|
13
|
+
function _permit(address token, bytes calldata permit) internal virtual {
|
|
12
14
|
if (permit.length > 0) {
|
|
13
15
|
bool success;
|
|
14
16
|
bytes memory result;
|
|
@@ -19,11 +21,9 @@ contract Permitable {
|
|
|
19
21
|
// solhint-disable-next-line avoid-low-level-calls
|
|
20
22
|
(success, result) = token.call(abi.encodePacked(IDaiLikePermit.permit.selector, permit));
|
|
21
23
|
} else {
|
|
22
|
-
revert(
|
|
23
|
-
}
|
|
24
|
-
if (!success) {
|
|
25
|
-
revert(RevertReasonParser.parse(result, "Permit failed: "));
|
|
24
|
+
revert BadPermitLength();
|
|
26
25
|
}
|
|
26
|
+
if (!success) revert PermitFailed();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -4,6 +4,10 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
library AddressArray {
|
|
7
|
+
error IndexOutOfBounds();
|
|
8
|
+
error PopFromEmptyArray();
|
|
9
|
+
error OutputArrayTooSmall();
|
|
10
|
+
|
|
7
11
|
struct Data {
|
|
8
12
|
mapping(uint256 => uint256) _raw;
|
|
9
13
|
}
|
|
@@ -28,7 +32,7 @@ library AddressArray {
|
|
|
28
32
|
|
|
29
33
|
function _get(Data storage self, address[] memory output, uint256 lengthAndFirst) private view returns(address[] memory) {
|
|
30
34
|
uint256 len = lengthAndFirst >> 160;
|
|
31
|
-
|
|
35
|
+
if (len > output.length) revert OutputArrayTooSmall();
|
|
32
36
|
if (len > 0) {
|
|
33
37
|
output[0] = address(uint160(lengthAndFirst));
|
|
34
38
|
for (uint i = 1; i < len; i++) {
|
|
@@ -54,7 +58,7 @@ library AddressArray {
|
|
|
54
58
|
function pop(Data storage self) internal {
|
|
55
59
|
uint256 lengthAndFirst = self._raw[0];
|
|
56
60
|
uint256 len = lengthAndFirst >> 160;
|
|
57
|
-
|
|
61
|
+
if (len == 0) revert PopFromEmptyArray();
|
|
58
62
|
self._raw[len - 1] = 0;
|
|
59
63
|
if (len > 1) {
|
|
60
64
|
self._raw[0] = lengthAndFirst - (1 << 160);
|
|
@@ -63,7 +67,7 @@ library AddressArray {
|
|
|
63
67
|
|
|
64
68
|
function set(Data storage self, uint256 index, address account) internal {
|
|
65
69
|
uint256 len = length(self);
|
|
66
|
-
|
|
70
|
+
if (index >= len) revert IndexOutOfBounds();
|
|
67
71
|
|
|
68
72
|
if (index == 0) {
|
|
69
73
|
self._raw[0] = (len << 160) | uint160(account);
|