@openzeppelin/upgrades-core 1.45.0-alpha.1 → 1.46.0

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.
Files changed (48) hide show
  1. package/artifacts/@openzeppelin/contracts-v5/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json +2 -2
  2. package/artifacts/@openzeppelin/contracts-v5/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +2 -2
  3. package/artifacts/@openzeppelin/contracts-v5/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +2 -2
  4. package/artifacts/build-info-v5.json +22 -22
  5. package/dist/cli/validate/build-info-file.js +4 -1
  6. package/dist/cli/validate/build-info-file.js.map +1 -1
  7. package/dist/cli/validate/build-info-file.test.js +115 -1
  8. package/dist/cli/validate/build-info-file.test.js.map +1 -1
  9. package/dist/provider.d.ts.map +1 -1
  10. package/dist/provider.js +1 -0
  11. package/dist/provider.js.map +1 -1
  12. package/dist/storage/extract.d.ts.map +1 -1
  13. package/dist/storage/extract.js +21 -7
  14. package/dist/storage/extract.js.map +1 -1
  15. package/dist/storage/namespace.d.ts.map +1 -1
  16. package/dist/storage/namespace.js +18 -11
  17. package/dist/storage/namespace.js.map +1 -1
  18. package/dist/storage-erc7201-builtin.test.d.ts +2 -0
  19. package/dist/storage-erc7201-builtin.test.d.ts.map +1 -0
  20. package/dist/storage-erc7201-builtin.test.js +105 -0
  21. package/dist/storage-erc7201-builtin.test.js.map +1 -0
  22. package/dist/utils/erc7201-builtin.d.ts +24 -0
  23. package/dist/utils/erc7201-builtin.d.ts.map +1 -0
  24. package/dist/utils/erc7201-builtin.js +83 -0
  25. package/dist/utils/erc7201-builtin.js.map +1 -0
  26. package/dist/utils/erc7201.d.ts.map +1 -1
  27. package/dist/utils/erc7201.js +5 -3
  28. package/dist/utils/erc7201.js.map +1 -1
  29. package/dist/utils/erc7201.test.js +10 -0
  30. package/dist/utils/erc7201.test.js.map +1 -1
  31. package/dist/utils/integer-literals.d.ts +19 -6
  32. package/dist/utils/integer-literals.d.ts.map +1 -1
  33. package/dist/utils/integer-literals.js +28 -10
  34. package/dist/utils/integer-literals.js.map +1 -1
  35. package/dist/utils/integer-literals.test.js +12 -0
  36. package/dist/utils/integer-literals.test.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/cli/validate/build-info-file.test.ts +156 -1
  39. package/src/cli/validate/build-info-file.ts +6 -1
  40. package/src/provider.ts +1 -0
  41. package/src/storage/extract.ts +28 -12
  42. package/src/storage/namespace.ts +21 -11
  43. package/src/storage-erc7201-builtin.test.ts +127 -0
  44. package/src/utils/erc7201-builtin.ts +91 -0
  45. package/src/utils/erc7201.test.ts +12 -0
  46. package/src/utils/erc7201.ts +6 -4
  47. package/src/utils/integer-literals.test.ts +15 -1
  48. package/src/utils/integer-literals.ts +29 -10
@@ -1,21 +1,42 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
 
3
+ const MAX_UINT256 = (1n << 256n) - 1n;
4
+
5
+ /**
6
+ * Encodes a bigint as a 0x-prefixed, 64-char lowercase hex string — the canonical text encoding of
7
+ * a `bytes32` value, used throughout this package for storage slots and similar 256-bit identifiers.
8
+ * Throws if the value is outside the 0..2^256-1 range, since that almost certainly indicates a bug
9
+ * upstream (overflow, wrong hash, etc.) and would silently produce a string longer than 64 chars.
10
+ *
11
+ * @param value bigint value to encode
12
+ * @returns 0x-prefixed, 64-char lowercase hex string
13
+ */
14
+ export function toBytes32Hex(value: bigint): string {
15
+ if (value < 0n || value > MAX_UINT256) {
16
+ throw new Error(`Value out of uint256 range: ${value}`);
17
+ }
18
+ return `0x${value.toString(16).padStart(64, '0')}`;
19
+ }
20
+
3
21
  /**
4
- * Converts a Solidity unsigned integer literal according to https://docs.soliditylang.org/en/latest/types.html#rational-literals
5
- * to a 64-byte padded hex string.
22
+ * Parses a Solidity unsigned integer literal source string (per
23
+ * https://docs.soliditylang.org/en/latest/types.html#rational-literals) and returns it in the
24
+ * canonical hex form produced by {@link toBytes32Hex}.
6
25
  *
7
- * Accepts decimal, hexadecimal, and scientific notation formats.
26
+ * Parsing is delegated to {@link BigNumber}, which accepts decimal (`1000`), hex (`0x1f`), and
27
+ * scientific notation (`1e18`). Underscore separators and uppercase digits, which BigNumber rejects
28
+ * but Solidity allows, are stripped/lowercased first. Non-integer results (e.g. `1.5e3`) are rejected.
8
29
  *
9
- * If the input is null or undefined, returns '0x0000000000000000000000000000000000000000000000000000000000000000'.
30
+ * If the input is null or undefined, returns the canonical hex form of zero.
10
31
  *
11
32
  * Assumes the input is a valid uint256-compatible literal for Solidity, and only performs minimal validation.
12
33
  *
13
- * @param literal Integer literal to convert
14
- * @returns Hex string with 0x prefix, padded to 64 bytes with leading zeroes
34
+ * @param literal Integer literal source string to parse
35
+ * @returns 0x-prefixed, 64-char lowercase hex string
15
36
  */
16
37
  export function normalizeUint256Literal(literal: string | null | undefined): string {
17
38
  if (!literal) {
18
- return '0x0000000000000000000000000000000000000000000000000000000000000000';
39
+ return toBytes32Hex(0n);
19
40
  }
20
41
  const lowercaseNoUnderscores = literal.replace(/_/g, '').toLowerCase();
21
42
 
@@ -23,7 +44,5 @@ export function normalizeUint256Literal(literal: string | null | undefined): str
23
44
  if (!parsed.isInteger()) {
24
45
  throw new Error(`Invalid integer literal: ${literal}`);
25
46
  }
26
- const calculatedValueAsHex = parsed.toString(16);
27
- const padded = calculatedValueAsHex.padStart(64, '0');
28
- return `0x${padded}`;
47
+ return toBytes32Hex(BigInt(parsed.toFixed()));
29
48
  }