Cant find Math
library in openzeppelin/contracts-upgradeable/contracts/utils/math (original) (raw)
December 6, 2023, 3:48pm 1
I wanted to use the math library for upgradeable contracts but I cant seem to find it in the repo, interestingly the readme talks about the library in utils but the math folder itself is not visible.
I cant find the math library in oz upgradeable in the github either, I'm using v4.9.2
Can someone help me figure out what is happening?
barakman December 6, 2023, 3:55pm 2
Math is an internally linked library, so it's agnostic to upgradability.
In short, just get rid of the -upgradable
part in your search path.
This is for v5, but you can probably see the same directory structure in your version:
Abelaby December 6, 2023, 4:00pm 3
Ty mate, the problem is that its in a deployed contract and I wanted to run forked tests against it,
import { MathUpgradeable as Math } from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
Update the remappings in my setup?
barakman December 6, 2023, 4:05pm 4
I think that this is (was, by now) just an attempt by OZ dev team to keep their naming-convention consistent across the repository. It is virtually identical to Math
as far as I know, so you may as well just use:
import { Math } from "@openzeppelin-contracts-upgradeable/contracts/utils/math/Math.sol";
BTW, compared with the title of your question, you are missing /contracts
in your current code:
"@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
Abelaby December 6, 2023, 4:07pm 5
The current code is a deployed one, so I actually cant edit
it.
The missing contracts is okay, updated by the remappings
@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts
But I cant seem to get the math lib
barakman December 6, 2023, 4:09pm 6
You can just navigate to the node_modules
directory in your local project and search for that file.
Shadow September 9, 2024, 8:22am 7
Did you manage to solve this? I am at the same bug, unfortunately. I cant seem to find the MathUpgradeable sol file despite the team claiming it is here [import {MathUpgradeable} from '@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol';], there is no math folder as a matter of fact.
Hi @Shadow,
Since OpenZeppelin 5.0, we removed the library
files (and other stateless contracts) from the upgradeable repository. The reasoning is that the upgradeable repository is an adapted version of the vanilla version with changes that ensure compatibility of the storage layout. In the case of Math
or any library in our package, they don't require an upgradeable version and therefore, it's safe to import from the non-upgradeable version of OpenZeppelin Contracts.
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";