caelum0x 94c26e9496 feat: QIE Forge โ€” clean-room AMM + lending vault, SDK, and CLI for QIE
Initial build for QIE Mainnet Hackathon 3.0 (DeFi & Financial
Infrastructure track). Includes:

- packages/contracts: constant-product AMM (factory/pair/router),
  over-collateralized lending vault, and an oracle adapter wrapping
  QIE's real deployed price-feed contracts. 25/25 Foundry tests pass
  locally. Clean-room: no existing DEX/lending protocol source was
  read or copied.
- packages/core: TypeScript SDK (viem-based) for QIE's chain, the
  real (corrected) oracle ABI, a fail-closed QUSDC helper, a
  Blockscout explorer client, and QIE Wallet connection constants.
  Live-verified against real testnet (chain 1983) and mainnet
  (chain 1990) RPCs and the real oracle contracts.
- packages/cli: a small CLI built on @qie-forge/core.

Real findings from building this, documented in README.md and
docs/STATUS.md: the previously-documented testnet RPC URL is dead
(replacement found and verified live); QIE's own oracle docs describe
a getPrice(string) function that reverts on the real deployed
contracts, which actually implement a Chainlink AggregatorV3-style
interface (verified live via raw eth_call); the oracle is deployed on
Mainnet only, not Testnet.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-26 23:34:51 +03:00

500 lines
21 KiB
Diff

diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
deleted file mode 100644
index 35ad097ff..000000000
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ /dev/null
@@ -1,21 +0,0 @@
----
-name: Bug report
-about: Report a bug in OpenZeppelin Contracts
-
----
-
-<!-- Briefly describe the issue you're experiencing. Tell us what you were trying to do and what happened instead. -->
-
-<!-- Remember, this is not a place to ask for help debugging code. For that, we welcome you in the OpenZeppelin Community Forum: https://forum.openzeppelin.com/. -->
-
-**๐Ÿ’ป Environment**
-
-<!-- Tell us what version of OpenZeppelin Contracts you're using, and how you're using it: Hardhat, Remix, etc. -->
-
-**๐Ÿ“ Details**
-
-<!-- Describe the problem you have been experiencing in more detail. Include as much information as you think is relevant. Keep in mind that transactions can fail for many reasons; context is key here. -->
-
-**๐Ÿ”ข Code to reproduce bug**
-
-<!-- We will be able to better help if you provide a minimal example that triggers the bug. -->
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index 4018cef29..d343a53d8 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -1,4 +1,8 @@
+blank_issues_enabled: false
contact_links:
+ - name: Bug Reports & Feature Requests
+ url: https://github.com/OpenZeppelin/openzeppelin-contracts/issues/new/choose
+ about: Visit the OpenZeppelin Contracts repository
- name: Questions & Support Requests
url: https://forum.openzeppelin.com/c/support/contracts/18
about: Ask in the OpenZeppelin Forum
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
deleted file mode 100644
index ff596b0c3..000000000
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ /dev/null
@@ -1,14 +0,0 @@
----
-name: Feature request
-about: Suggest an idea for OpenZeppelin Contracts
-
----
-
-**๐Ÿง Motivation**
-<!-- Is your feature request related to a specific problem? Is it just a crazy idea? Tell us about it! -->
-
-**๐Ÿ“ Details**
-<!-- Please describe your feature request in detail. -->
-
-<!-- Make sure that you have reviewed the OpenZeppelin Contracts Contributor Guidelines. -->
-<!-- https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CONTRIBUTING.md -->
diff --git a/README.md b/README.md
index 0408a9fda..7bf53e3a3 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,9 @@
> [!IMPORTANT]
> OpenZeppelin Contracts uses semantic versioning to communicate backwards compatibility of its API and storage layout. For upgradeable contracts, the storage layout of different major versions should be assumed incompatible, for example, it is unsafe to upgrade from 4.9.3 to 5.0.0. Learn more at [Backwards Compatibility](https://docs.openzeppelin.com/contracts/backwards-compatibility).
+> [!NOTE]
+> You are looking at the upgradeable variant of OpenZeppelin Contracts. Be sure to review the documentation on [Using OpenZeppelin Contracts with Upgrades](https://docs.openzeppelin.com/contracts/upgradeable).
+
## Overview
### Release tags
@@ -34,12 +37,12 @@ We use NPM tags to clearly distinguish between audited and non-audited versions
#### Hardhat (npm)
```
-$ npm install @openzeppelin/contracts
+$ npm install @openzeppelin/contracts-upgradeable
```
โ†’ Installs the latest audited release (`latest`).
```
-$ npm install @openzeppelin/contracts@dev
+$ npm install @openzeppelin/contracts-upgradeable@dev
```
โ†’ Installs the latest unaudited release (`dev`).
@@ -52,10 +55,10 @@ $ npm install @openzeppelin/contracts@dev
> Foundry installs the latest version initially, but subsequent `forge update` commands will use the `master` branch.
```
-$ forge install OpenZeppelin/openzeppelin-contracts
+$ forge install OpenZeppelin/openzeppelin-contracts-upgradeable
```
-Add `@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/` in `remappings.txt`.
+Add `@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/` in `remappings.txt`.
### Usage
@@ -64,10 +67,11 @@ Once installed, you can use the contracts in the library by importing them:
```solidity
pragma solidity ^0.8.20;
-import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
+import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
-contract MyCollectible is ERC721 {
- constructor() ERC721("MyCollectible", "MCO") {
+contract MyCollectible is ERC721Upgradeable {
+ function initialize() initializer public {
+ __ERC721_init("MyCollectible", "MCO");
}
}
```
diff --git a/contracts/package.json b/contracts/package.json
index 0f0252dd7..a8785361c 100644
--- a/contracts/package.json
+++ b/contracts/package.json
@@ -1,5 +1,5 @@
{
- "name": "@openzeppelin/contracts",
+ "name": "@openzeppelin/contracts-upgradeable",
"description": "Secure Smart Contract library for Solidity",
"version": "5.7.0",
"files": [
@@ -13,7 +13,7 @@
},
"repository": {
"type": "git",
- "url": "https://github.com/OpenZeppelin/openzeppelin-contracts.git"
+ "url": "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable.git"
},
"keywords": [
"solidity",
@@ -28,5 +28,8 @@
"bugs": {
"url": "https://github.com/OpenZeppelin/openzeppelin-contracts/issues"
},
- "homepage": "https://openzeppelin.com/contracts/"
+ "homepage": "https://openzeppelin.com/contracts/",
+ "peerDependencies": {
+ "@openzeppelin/contracts": "<package-version>"
+ }
}
diff --git a/contracts/token/ERC20/extensions/ERC20TransferAuthorization.sol b/contracts/token/ERC20/extensions/ERC20TransferAuthorization.sol
index b818d327b..8cdff61fa 100644
--- a/contracts/token/ERC20/extensions/ERC20TransferAuthorization.sol
+++ b/contracts/token/ERC20/extensions/ERC20TransferAuthorization.sol
@@ -15,6 +15,14 @@ import {ERC3009} from "./draft-ERC3009.sol";
* different keys are independent and can be submitted in parallel without ordering constraints, while nonces
* sharing the same key must be used sequentially. This is unlike {ERC20Permit} which uses a single global
* sequential nonce.
+ *
+ * WARNING: Upgrading a proxy between {ERC3009} and {ERC20TransferAuthorization} implementations (in either direction)
+ * can re-enable replay of previously-consumed authorizations. The two contracts use different nonce-consumption
+ * schemes and do not share storage: {ERC3009} records used nonces in a
+ * `mapping(address => mapping(bytes32 => bool))`, while this contract uses {NoncesKeyed}'s keyed sequential counters.
+ * Historical usage recorded under one scheme is not observed by the other, so a previously-used nonce can become valid
+ * again after the upgrade. If such an upgrade is unavoidable, consider bumping the EIP-712 domain `version` (or `name`)
+ * to invalidate pre-upgrade signatures.
*/
abstract contract ERC20TransferAuthorization is ERC3009, NoncesKeyed {
/**
diff --git a/contracts/token/ERC721/extensions/ERC721Enumerable.sol b/contracts/token/ERC721/extensions/ERC721Enumerable.sol
index 4cc6d9751..96af07f9c 100644
--- a/contracts/token/ERC721/extensions/ERC721Enumerable.sol
+++ b/contracts/token/ERC721/extensions/ERC721Enumerable.sol
@@ -13,6 +13,10 @@ import {IERC721Enumerable} from "./IERC721Enumerable.sol";
*
* CAUTION: {ERC721} extensions that implement custom `balanceOf` logic, such as {ERC721Consecutive},
* interfere with enumerability and should not be used together with {ERC721Enumerable}.
+ *
+ * CAUTION: This extension should not be added in an upgrade after tokens have already been minted.
+ * Enumeration is tracked in {_update}, so preexisting tokens would be missing from {totalSupply},
+ * {tokenByIndex}, and {tokenOfOwnerByIndex}.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
mapping(address owner => mapping(uint256 index => uint256)) private _ownedTokens;
diff --git a/contracts/utils/ReentrancyGuard.sol b/contracts/utils/ReentrancyGuard.sol
index c156fa1cc..895e39342 100644
--- a/contracts/utils/ReentrancyGuard.sol
+++ b/contracts/utils/ReentrancyGuard.sol
@@ -36,6 +36,11 @@ abstract contract ReentrancyGuard {
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
+ /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
+ struct ReentrancyGuardStorage {
+ uint256 _status;
+ }
+
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
@@ -55,10 +60,6 @@ abstract contract ReentrancyGuard {
*/
error ReentrancyGuardReentrantCall();
- constructor() {
- _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
- }
-
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol
index 66a165221..9a223cadf 100644
--- a/contracts/utils/cryptography/EIP712.sol
+++ b/contracts/utils/cryptography/EIP712.sol
@@ -4,7 +4,6 @@
pragma solidity ^0.8.24;
import {IERC5267} from "../../interfaces/IERC5267.sol";
-import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {MessageHashUtils} from "./MessageHashUtils.sol";
/**
@@ -25,43 +24,18 @@ import {MessageHashUtils} from "./MessageHashUtils.sol";
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
- * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
- * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
- * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
- *
- * IMPORTANT: The `name` and `version` must each fit in a `ShortString` (at most 31 bytes). Longer values cause the
- * constructor to revert with a `ShortStrings.StringTooLong` error. Because the values are stored exclusively in
- * immutables, the domain is preserved when the contract is used behind a proxy or clone without an initializer.
- *
- * @custom:oz-upgrades-unsafe-allow state-variable-immutable
+ * NOTE: The upgradeable version of this contract does not use an immutable cache and recomputes the domain separator
+ * each time {_domainSeparatorV4} is called. This is cheaper than accessing a cached version in cold storage.
*/
abstract contract EIP712 is IERC5267 {
- using ShortStrings for *;
-
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
- // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
- // invalidate the cached domain separator if the chain id changes.
- bytes32 private immutable _cachedDomainSeparator;
- uint256 private immutable _cachedChainId;
- address private immutable _cachedThis;
-
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
- ShortString private immutable _name;
- ShortString private immutable _version;
-
- // IMPORTANT: Deprecated. Kept to preserve the storage layout of inheriting contracts used as an
- // implementation behind a proxy.
- // slither-disable-next-line constable-states
- string private _nameFallback;
-
- // IMPORTANT: Deprecated. Kept to preserve the storage layout of inheriting contracts used as an
- // implementation behind a proxy.
- // slither-disable-next-line constable-states
- string private _versionFallback;
+ string private _name;
+ string private _version;
/**
* @dev Initializes the domain separator and parameter caches.
@@ -76,29 +50,19 @@ abstract contract EIP712 is IERC5267 {
* contract upgrade].
*/
constructor(string memory name, string memory version) {
- _name = name.toShortString();
- _version = version.toShortString();
- _hashedName = keccak256(bytes(name));
- _hashedVersion = keccak256(bytes(version));
-
- _cachedChainId = block.chainid;
- _cachedDomainSeparator = _buildDomainSeparator();
- _cachedThis = address(this);
+ _name = name;
+ _version = version;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
- if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
- return _cachedDomainSeparator;
- } else {
- return _buildDomainSeparator();
- }
+ return _buildDomainSeparator();
}
function _buildDomainSeparator() private view returns (bytes32) {
- return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
+ return keccak256(abi.encode(TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), block.chainid, address(this)));
}
/**
@@ -149,20 +113,38 @@ abstract contract EIP712 is IERC5267 {
/**
* @dev The name parameter for the EIP712 domain.
*
- * NOTE: This function reads `_name`, which is an immutable value.
+ * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
+ * are a concern.
*/
- // solhint-disable-next-line func-name-mixedcase
- function _EIP712Name() internal view returns (string memory) {
- return _name.toString();
+ function _EIP712Name() internal view virtual returns (string memory) {
+ return _name;
}
/**
* @dev The version parameter for the EIP712 domain.
*
- * NOTE: This function reads `_version`, which is an immutable value.
+ * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
+ * are a concern.
+ */
+ function _EIP712Version() internal view virtual returns (string memory) {
+ return _version;
+ }
+
+ /**
+ * @dev The hash of the name parameter for the EIP712 domain.
+ *
+ * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Name` instead.
+ */
+ function _EIP712NameHash() internal view returns (bytes32) {
+ return keccak256(bytes(_EIP712Name()));
+ }
+
+ /**
+ * @dev The hash of the version parameter for the EIP712 domain.
+ *
+ * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Version` instead.
*/
- // solhint-disable-next-line func-name-mixedcase
- function _EIP712Version() internal view returns (string memory) {
- return _version.toString();
+ function _EIP712VersionHash() internal view returns (bytes32) {
+ return keccak256(bytes(_EIP712Version()));
}
}
diff --git a/hardhat.config.ts b/hardhat.config.ts
index e66fae29c..490d991e8 100644
--- a/hardhat.config.ts
+++ b/hardhat.config.ts
@@ -43,7 +43,7 @@ export default defineConfig({
hardhatOzContractsHelpers,
],
paths: {
- sources: argv.src,
+ sources: [ argv.src, 'lib/openzeppelin-contracts/contracts' ],
},
solidity: {
version: argv.compiler,
@@ -96,7 +96,7 @@ export default defineConfig({
},
exposed: {
initializers: true,
- include: ['contracts/**/*.sol'],
+ include: ['{,lib/openzeppelin-contracts/}contracts/**/*.sol'],
exclude: ['**/*WithInit.sol'],
},
docgen: await import('./docs/config.mjs').then(m => m.default),
diff --git a/package.json b/package.json
index 8c6a287a2..ef7b67d75 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
},
"repository": {
"type": "git",
- "url": "https://github.com/OpenZeppelin/openzeppelin-contracts.git"
+ "url": "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable.git"
},
"keywords": [
"solidity",
diff --git a/remappings.txt b/remappings.txt
index ec2d5de0a..4f77a0ea5 100644
--- a/remappings.txt
+++ b/remappings.txt
@@ -1,4 +1,5 @@
-@openzeppelin/contracts/=contracts/
+@openzeppelin/contracts-upgradeable/=contracts/
+@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
forge-std=lib/forge-std/src
halmos-cheatcodes=lib/halmos-cheatcodes/src
erc4626-tests=lib/erc4626-tests
diff --git a/test/account/AccountEIP7702.test.js b/test/account/AccountEIP7702.test.js
index 98aae7492..9e2785021 100644
--- a/test/account/AccountEIP7702.test.js
+++ b/test/account/AccountEIP7702.test.js
@@ -28,8 +28,8 @@ async function fixture() {
const entrypointDomain = await getDomain(ethers.predeploy.entrypoint.v09);
// domain cannot be fetched using getDomain(mock) before the mock is deployed
const domain = {
- name: 'AccountEIP7702Mock',
- version: '1',
+ name: '', // Not initialized in the context of signer
+ version: '', // Not initialized in the context of signer
chainId: entrypointDomain.chainId,
verifyingContract: mock.address,
};
diff --git a/test/account/examples/AccountEIP7702WithModulesMock.test.js b/test/account/examples/AccountEIP7702WithModulesMock.test.js
index bd30d77e0..3b7e243e8 100644
--- a/test/account/examples/AccountEIP7702WithModulesMock.test.js
+++ b/test/account/examples/AccountEIP7702WithModulesMock.test.js
@@ -38,8 +38,8 @@ async function fixture() {
// domain cannot be fetched using getDomain(mock) before the mock is deployed
const domain = {
- name: 'AccountEIP7702WithModulesMock',
- version: '1',
+ name: '', // Not initialized in the context of signer
+ version: '', // Not initialized in the context of signer
chainId: entrypointDomain.chainId,
verifyingContract: mock.address,
};
diff --git a/test/utils/cryptography/EIP712.test.js b/test/utils/cryptography/EIP712.test.js
index 6e050f772..e929f5392 100644
--- a/test/utils/cryptography/EIP712.test.js
+++ b/test/utils/cryptography/EIP712.test.js
@@ -35,7 +35,6 @@ describe('EIP712', function () {
describe('domain separator', function () {
it('is internally available', async function () {
const expected = await domainSeparator(this.domain);
-
await expect(this.eip712.$_domainSeparatorV4()).to.eventually.equal(expected);
});
@@ -43,22 +42,6 @@ describe('EIP712', function () {
const rebuildDomain = await getDomain(this.eip712);
expect(rebuildDomain).to.be.deep.equal(this.domain);
});
-
- it('adjusts when behind proxy', async function () {
- const factory = await ethers.deployContract('$Clones');
-
- const clone = await factory
- .$clone(this.eip712)
- .then(tx => tx.wait())
- .then(receipt => receipt.logs.find(ev => ev.fragment.name == 'return$clone_address').args.instance)
- .then(address => ethers.getContractAt('$EIP712Verifier', address));
-
- const expectedDomain = { ...this.domain, verifyingContract: clone.target };
- await expect(getDomain(clone)).to.eventually.deep.equal(expectedDomain);
-
- const expectedSeparator = await domainSeparator(expectedDomain);
- await expect(clone.$_domainSeparatorV4()).to.eventually.equal(expectedSeparator);
- });
});
it('hash digest', async function () {
@@ -98,18 +81,30 @@ describe('EIP712', function () {
});
describe('with long name and version', function () {
- it('deployment fails with long name', async function () {
+ it('upgradeable version supports long name', async function () {
const longName = 'A'.repeat(32);
- await expect(ethers.deployContract('$EIP712Verifier', [longName, version]))
- .to.be.revertedWithCustomError(this.eip712, 'StringTooLong')
- .withArgs(longName);
+ const instance = await ethers.deployContract('$EIP712Verifier', [longName, version]);
+
+ await expect(instance.$_EIP712Name()).to.eventually.equal(longName);
+ await expect(instance.$_EIP712Version()).to.eventually.equal(version);
+ await expect(getDomain(instance)).to.eventually.be.deep.equal({
+ ...this.domain,
+ name: longName,
+ verifyingContract: instance.target,
+ });
});
- it('deployment fails with long version', async function () {
+ it('upgradeable version supports long version', async function () {
const longVersion = 'B'.repeat(32);
- await expect(ethers.deployContract('$EIP712Verifier', [name, longVersion]))
- .to.be.revertedWithCustomError(this.eip712, 'StringTooLong')
- .withArgs(longVersion);
+ const instance = await ethers.deployContract('$EIP712Verifier', [name, longVersion]);
+
+ await expect(instance.$_EIP712Name()).to.eventually.equal(name);
+ await expect(instance.$_EIP712Version()).to.eventually.equal(longVersion);
+ await expect(getDomain(instance)).to.eventually.be.deep.equal({
+ ...this.domain,
+ version: longVersion,
+ verifyingContract: instance.target,
+ });
});
});
});