Skip to content

Commit 1f96663

Browse files
committed
implemented payables
1 parent 5b8e22f commit 1f96663

20 files changed

+95736
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: MIT
2+
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
3+
4+
pragma solidity ^0.8.20;
5+
6+
/**
7+
* @dev Helper library for emitting standardized panic codes.
8+
*
9+
* ```solidity
10+
* contract Example {
11+
* using Panic for uint256;
12+
*
13+
* // Use any of the declared internal constants
14+
* function foo() { Panic.GENERIC.panic(); }
15+
*
16+
* // Alternatively
17+
* function foo() { Panic.panic(Panic.GENERIC); }
18+
* }
19+
* ```
20+
*
21+
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
22+
*
23+
* _Available since v5.1._
24+
*/
25+
// slither-disable-next-line unused-state
26+
library Panic {
27+
/// @dev generic / unspecified error
28+
uint256 internal constant GENERIC = 0x00;
29+
/// @dev used by the assert() builtin
30+
uint256 internal constant ASSERT = 0x01;
31+
/// @dev arithmetic underflow or overflow
32+
uint256 internal constant UNDER_OVERFLOW = 0x11;
33+
/// @dev division or modulo by zero
34+
uint256 internal constant DIVISION_BY_ZERO = 0x12;
35+
/// @dev enum conversion error
36+
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
37+
/// @dev invalid encoding in storage
38+
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
39+
/// @dev empty array pop
40+
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
41+
/// @dev array out of bounds access
42+
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
43+
/// @dev resource error (too large allocation or too large array)
44+
uint256 internal constant RESOURCE_ERROR = 0x41;
45+
/// @dev calling invalid internal function
46+
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
47+
48+
/// @dev Reverts with a panic code. Recommended to use with
49+
/// the internal constants with predefined codes.
50+
function panic(uint256 code) internal pure {
51+
assembly ("memory-safe") {
52+
mstore(0x00, 0x4e487b71)
53+
mstore(0x20, code)
54+
revert(0x1c, 0x24)
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// SPDX-License-Identifier: MIT
2+
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Strings.sol)
3+
4+
pragma solidity ^0.8.20;
5+
6+
import {Math} from "./math/Math.sol";
7+
import {SignedMath} from "./math/SignedMath.sol";
8+
9+
/**
10+
* @dev String operations.
11+
*/
12+
library Strings {
13+
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
14+
uint8 private constant ADDRESS_LENGTH = 20;
15+
16+
/**
17+
* @dev The `value` string doesn't fit in the specified `length`.
18+
*/
19+
error StringsInsufficientHexLength(uint256 value, uint256 length);
20+
21+
/**
22+
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
23+
*/
24+
function toString(uint256 value) internal pure returns (string memory) {
25+
unchecked {
26+
uint256 length = Math.log10(value) + 1;
27+
string memory buffer = new string(length);
28+
uint256 ptr;
29+
assembly ("memory-safe") {
30+
ptr := add(buffer, add(32, length))
31+
}
32+
while (true) {
33+
ptr--;
34+
assembly ("memory-safe") {
35+
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
36+
}
37+
value /= 10;
38+
if (value == 0) break;
39+
}
40+
return buffer;
41+
}
42+
}
43+
44+
/**
45+
* @dev Converts a `int256` to its ASCII `string` decimal representation.
46+
*/
47+
function toStringSigned(int256 value) internal pure returns (string memory) {
48+
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
49+
}
50+
51+
/**
52+
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
53+
*/
54+
function toHexString(uint256 value) internal pure returns (string memory) {
55+
unchecked {
56+
return toHexString(value, Math.log256(value) + 1);
57+
}
58+
}
59+
60+
/**
61+
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
62+
*/
63+
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
64+
uint256 localValue = value;
65+
bytes memory buffer = new bytes(2 * length + 2);
66+
buffer[0] = "0";
67+
buffer[1] = "x";
68+
for (uint256 i = 2 * length + 1; i > 1; --i) {
69+
buffer[i] = HEX_DIGITS[localValue & 0xf];
70+
localValue >>= 4;
71+
}
72+
if (localValue != 0) {
73+
revert StringsInsufficientHexLength(value, length);
74+
}
75+
return string(buffer);
76+
}
77+
78+
/**
79+
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
80+
* representation.
81+
*/
82+
function toHexString(address addr) internal pure returns (string memory) {
83+
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
84+
}
85+
86+
/**
87+
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
88+
* representation, according to EIP-55.
89+
*/
90+
function toChecksumHexString(address addr) internal pure returns (string memory) {
91+
bytes memory buffer = bytes(toHexString(addr));
92+
93+
// hash the hex part of buffer (skip length + 2 bytes, length 40)
94+
uint256 hashValue;
95+
assembly ("memory-safe") {
96+
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
97+
}
98+
99+
for (uint256 i = 41; i > 1; --i) {
100+
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
101+
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
102+
// case shift by xoring with 0x20
103+
buffer[i] ^= 0x20;
104+
}
105+
hashValue >>= 4;
106+
}
107+
return string(buffer);
108+
}
109+
110+
/**
111+
* @dev Returns true if the two strings are equal.
112+
*/
113+
function equal(string memory a, string memory b) internal pure returns (bool) {
114+
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
115+
}
116+
}

0 commit comments

Comments
 (0)