refactor: move brother_node development artifact to dev/test-nodes subdirectory
Development Artifact Cleanup: ✅ BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location - dev/test-nodes/brother_node/: Moved from root directory for better organization - Contains development configuration, test logs, and test chain data - No impact on production systems - purely development/testing artifact ✅ DEVELOPMENT ARTIFACTS IDENTIFIED: - Chain ID: aitbc-brother-chain (test/development chain) - Ports: 8010 (P2P) and 8011 (RPC) - different from production - Environment: .env file with test configuration - Logs: rpc.log and node.log from development testing session (March 15, 2026) ✅ ROOT DIRECTORY CLEANUP: Removed development clutter from production directory - brother_node/ moved to dev/test-nodes/brother_node/ - Root directory now contains only production-ready components - Development artifacts properly organized in dev/ subdirectory DIRECTORY STRUCTURE IMPROVEMENT: 📁 dev/test-nodes/: Development and testing node configurations 🏗️ Root Directory: Clean production structure with only essential components 🧪 Development Isolation: Test environments separated from production BENEFITS: ✅ Clean Production Directory: No development artifacts in root ✅ Better Organization: Development nodes grouped in dev/ subdirectory ✅ Clear Separation: Production vs development environments clearly distinguished ✅ Maintainability: Easier to identify and manage development components RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
This commit is contained in:
294
dev/env/node_modules/@openzeppelin/contracts/proxy/Clones.sol
generated
vendored
Executable file
294
dev/env/node_modules/@openzeppelin/contracts/proxy/Clones.sol
generated
vendored
Executable file
@@ -0,0 +1,294 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/Clones.sol)
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import {Create2} from "../utils/Create2.sol";
|
||||
import {Errors} from "../utils/Errors.sol";
|
||||
|
||||
/**
|
||||
* @dev https://eips.ethereum.org/EIPS/eip-1167[ERC-1167] is a standard for
|
||||
* deploying minimal proxy contracts, also known as "clones".
|
||||
*
|
||||
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
|
||||
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
|
||||
*
|
||||
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
|
||||
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
|
||||
* deterministic method.
|
||||
*/
|
||||
library Clones {
|
||||
error CloneArgumentsTooLong();
|
||||
|
||||
/**
|
||||
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation`.
|
||||
*
|
||||
* This function uses the create opcode, which should never revert.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*/
|
||||
function clone(address implementation) internal returns (address instance) {
|
||||
return clone(implementation, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Clones-clone-address-}[clone], but with a `value` parameter to send native currency
|
||||
* to the new contract.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*
|
||||
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
|
||||
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
|
||||
*/
|
||||
function clone(address implementation, uint256 value) internal returns (address instance) {
|
||||
if (address(this).balance < value) {
|
||||
revert Errors.InsufficientBalance(address(this).balance, value);
|
||||
}
|
||||
assembly ("memory-safe") {
|
||||
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
|
||||
// of the `implementation` address with the bytecode before the address.
|
||||
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
|
||||
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
|
||||
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
|
||||
instance := create(value, 0x09, 0x37)
|
||||
}
|
||||
if (instance == address(0)) {
|
||||
revert Errors.FailedDeployment();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation`.
|
||||
*
|
||||
* This function uses the create2 opcode and a `salt` to deterministically deploy
|
||||
* the clone. Using the same `implementation` and `salt` multiple times will revert, since
|
||||
* the clones cannot be deployed twice at the same address.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*/
|
||||
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
|
||||
return cloneDeterministic(implementation, salt, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Clones-cloneDeterministic-address-bytes32-}[cloneDeterministic], but with
|
||||
* a `value` parameter to send native currency to the new contract.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*
|
||||
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
|
||||
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
|
||||
*/
|
||||
function cloneDeterministic(
|
||||
address implementation,
|
||||
bytes32 salt,
|
||||
uint256 value
|
||||
) internal returns (address instance) {
|
||||
if (address(this).balance < value) {
|
||||
revert Errors.InsufficientBalance(address(this).balance, value);
|
||||
}
|
||||
assembly ("memory-safe") {
|
||||
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
|
||||
// of the `implementation` address with the bytecode before the address.
|
||||
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
|
||||
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
|
||||
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
|
||||
instance := create2(value, 0x09, 0x37, salt)
|
||||
}
|
||||
if (instance == address(0)) {
|
||||
revert Errors.FailedDeployment();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
|
||||
*/
|
||||
function predictDeterministicAddress(
|
||||
address implementation,
|
||||
bytes32 salt,
|
||||
address deployer
|
||||
) internal pure returns (address predicted) {
|
||||
assembly ("memory-safe") {
|
||||
let ptr := mload(0x40)
|
||||
mstore(add(ptr, 0x38), deployer)
|
||||
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
|
||||
mstore(add(ptr, 0x14), implementation)
|
||||
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
|
||||
mstore(add(ptr, 0x58), salt)
|
||||
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
|
||||
predicted := and(keccak256(add(ptr, 0x43), 0x55), 0xffffffffffffffffffffffffffffffffffffffff)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
|
||||
*/
|
||||
function predictDeterministicAddress(
|
||||
address implementation,
|
||||
bytes32 salt
|
||||
) internal view returns (address predicted) {
|
||||
return predictDeterministicAddress(implementation, salt, address(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation` with custom
|
||||
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
|
||||
* access the arguments within the implementation, use {fetchCloneArgs}.
|
||||
*
|
||||
* This function uses the create opcode, which should never revert.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*/
|
||||
function cloneWithImmutableArgs(address implementation, bytes memory args) internal returns (address instance) {
|
||||
return cloneWithImmutableArgs(implementation, args, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Clones-cloneWithImmutableArgs-address-bytes-}[cloneWithImmutableArgs], but with a `value`
|
||||
* parameter to send native currency to the new contract.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*
|
||||
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
|
||||
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
|
||||
*/
|
||||
function cloneWithImmutableArgs(
|
||||
address implementation,
|
||||
bytes memory args,
|
||||
uint256 value
|
||||
) internal returns (address instance) {
|
||||
if (address(this).balance < value) {
|
||||
revert Errors.InsufficientBalance(address(this).balance, value);
|
||||
}
|
||||
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
|
||||
assembly ("memory-safe") {
|
||||
instance := create(value, add(bytecode, 0x20), mload(bytecode))
|
||||
}
|
||||
if (instance == address(0)) {
|
||||
revert Errors.FailedDeployment();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation` with custom
|
||||
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
|
||||
* access the arguments within the implementation, use {fetchCloneArgs}.
|
||||
*
|
||||
* This function uses the create2 opcode and a `salt` to deterministically deploy the clone. Using the same
|
||||
* `implementation`, `args` and `salt` multiple times will revert, since the clones cannot be deployed twice
|
||||
* at the same address.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*/
|
||||
function cloneDeterministicWithImmutableArgs(
|
||||
address implementation,
|
||||
bytes memory args,
|
||||
bytes32 salt
|
||||
) internal returns (address instance) {
|
||||
return cloneDeterministicWithImmutableArgs(implementation, args, salt, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Clones-cloneDeterministicWithImmutableArgs-address-bytes-bytes32-}[cloneDeterministicWithImmutableArgs],
|
||||
* but with a `value` parameter to send native currency to the new contract.
|
||||
*
|
||||
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
|
||||
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
|
||||
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
|
||||
*
|
||||
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
|
||||
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
|
||||
*/
|
||||
function cloneDeterministicWithImmutableArgs(
|
||||
address implementation,
|
||||
bytes memory args,
|
||||
bytes32 salt,
|
||||
uint256 value
|
||||
) internal returns (address instance) {
|
||||
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
|
||||
return Create2.deploy(value, salt, bytecode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
|
||||
*/
|
||||
function predictDeterministicAddressWithImmutableArgs(
|
||||
address implementation,
|
||||
bytes memory args,
|
||||
bytes32 salt,
|
||||
address deployer
|
||||
) internal pure returns (address predicted) {
|
||||
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
|
||||
return Create2.computeAddress(salt, keccak256(bytecode), deployer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
|
||||
*/
|
||||
function predictDeterministicAddressWithImmutableArgs(
|
||||
address implementation,
|
||||
bytes memory args,
|
||||
bytes32 salt
|
||||
) internal view returns (address predicted) {
|
||||
return predictDeterministicAddressWithImmutableArgs(implementation, args, salt, address(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get the immutable args attached to a clone.
|
||||
*
|
||||
* - If `instance` is a clone that was deployed using `clone` or `cloneDeterministic`, this
|
||||
* function will return an empty array.
|
||||
* - If `instance` is a clone that was deployed using `cloneWithImmutableArgs` or
|
||||
* `cloneDeterministicWithImmutableArgs`, this function will return the args array used at
|
||||
* creation.
|
||||
* - If `instance` is NOT a clone deployed using this library, the behavior is undefined. This
|
||||
* function should only be used to check addresses that are known to be clones.
|
||||
*/
|
||||
function fetchCloneArgs(address instance) internal view returns (bytes memory) {
|
||||
bytes memory result = new bytes(instance.code.length - 45); // revert if length is too short
|
||||
assembly ("memory-safe") {
|
||||
extcodecopy(instance, add(result, 32), 45, mload(result))
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Helper that prepares the initcode of the proxy with immutable args.
|
||||
*
|
||||
* An assembly variant of this function requires copying the `args` array, which can be efficiently done using
|
||||
* `mcopy`. Unfortunately, that opcode is not available before cancun. A pure solidity implementation using
|
||||
* abi.encodePacked is more expensive but also more portable and easier to review.
|
||||
*
|
||||
* NOTE: https://eips.ethereum.org/EIPS/eip-170[EIP-170] limits the length of the contract code to 24576 bytes.
|
||||
* With the proxy code taking 45 bytes, that limits the length of the immutable args to 24531 bytes.
|
||||
*/
|
||||
function _cloneCodeWithImmutableArgs(
|
||||
address implementation,
|
||||
bytes memory args
|
||||
) private pure returns (bytes memory) {
|
||||
if (args.length > 24531) revert CloneArgumentsTooLong();
|
||||
return
|
||||
abi.encodePacked(
|
||||
hex"61",
|
||||
uint16(args.length + 45),
|
||||
hex"3d81600a3d39f3363d3d373d3d3d363d73",
|
||||
implementation,
|
||||
hex"5af43d82803e903d91602b57fd5bf3",
|
||||
args
|
||||
);
|
||||
}
|
||||
}
|
||||
40
dev/env/node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol
generated
vendored
Executable file
40
dev/env/node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol
generated
vendored
Executable file
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/ERC1967/ERC1967Proxy.sol)
|
||||
|
||||
pragma solidity ^0.8.22;
|
||||
|
||||
import {Proxy} from "../Proxy.sol";
|
||||
import {ERC1967Utils} from "./ERC1967Utils.sol";
|
||||
|
||||
/**
|
||||
* @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
|
||||
* implementation address that can be changed. This address is stored in storage in the location specified by
|
||||
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967], so that it doesn't conflict with the storage layout of the
|
||||
* implementation behind the proxy.
|
||||
*/
|
||||
contract ERC1967Proxy is Proxy {
|
||||
/**
|
||||
* @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation`.
|
||||
*
|
||||
* If `_data` is nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
|
||||
* encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - If `data` is empty, `msg.value` must be zero.
|
||||
*/
|
||||
constructor(address implementation, bytes memory _data) payable {
|
||||
ERC1967Utils.upgradeToAndCall(implementation, _data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current implementation address.
|
||||
*
|
||||
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
|
||||
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
|
||||
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
|
||||
*/
|
||||
function _implementation() internal view virtual override returns (address) {
|
||||
return ERC1967Utils.getImplementation();
|
||||
}
|
||||
}
|
||||
177
dev/env/node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol
generated
vendored
Executable file
177
dev/env/node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol
generated
vendored
Executable file
@@ -0,0 +1,177 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/ERC1967/ERC1967Utils.sol)
|
||||
|
||||
pragma solidity ^0.8.21;
|
||||
|
||||
import {IBeacon} from "../beacon/IBeacon.sol";
|
||||
import {IERC1967} from "../../interfaces/IERC1967.sol";
|
||||
import {Address} from "../../utils/Address.sol";
|
||||
import {StorageSlot} from "../../utils/StorageSlot.sol";
|
||||
|
||||
/**
|
||||
* @dev This library provides getters and event emitting update functions for
|
||||
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
|
||||
*/
|
||||
library ERC1967Utils {
|
||||
/**
|
||||
* @dev Storage slot with the address of the current implementation.
|
||||
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
|
||||
*/
|
||||
// solhint-disable-next-line private-vars-leading-underscore
|
||||
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
|
||||
|
||||
/**
|
||||
* @dev The `implementation` of the proxy is invalid.
|
||||
*/
|
||||
error ERC1967InvalidImplementation(address implementation);
|
||||
|
||||
/**
|
||||
* @dev The `admin` of the proxy is invalid.
|
||||
*/
|
||||
error ERC1967InvalidAdmin(address admin);
|
||||
|
||||
/**
|
||||
* @dev The `beacon` of the proxy is invalid.
|
||||
*/
|
||||
error ERC1967InvalidBeacon(address beacon);
|
||||
|
||||
/**
|
||||
* @dev An upgrade function sees `msg.value > 0` that may be lost.
|
||||
*/
|
||||
error ERC1967NonPayable();
|
||||
|
||||
/**
|
||||
* @dev Returns the current implementation address.
|
||||
*/
|
||||
function getImplementation() internal view returns (address) {
|
||||
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Stores a new address in the ERC-1967 implementation slot.
|
||||
*/
|
||||
function _setImplementation(address newImplementation) private {
|
||||
if (newImplementation.code.length == 0) {
|
||||
revert ERC1967InvalidImplementation(newImplementation);
|
||||
}
|
||||
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
|
||||
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
|
||||
* to avoid stuck value in the contract.
|
||||
*
|
||||
* Emits an {IERC1967-Upgraded} event.
|
||||
*/
|
||||
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
|
||||
_setImplementation(newImplementation);
|
||||
emit IERC1967.Upgraded(newImplementation);
|
||||
|
||||
if (data.length > 0) {
|
||||
Address.functionDelegateCall(newImplementation, data);
|
||||
} else {
|
||||
_checkNonPayable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Storage slot with the admin of the contract.
|
||||
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
|
||||
*/
|
||||
// solhint-disable-next-line private-vars-leading-underscore
|
||||
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
|
||||
|
||||
/**
|
||||
* @dev Returns the current admin.
|
||||
*
|
||||
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
|
||||
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
|
||||
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
|
||||
*/
|
||||
function getAdmin() internal view returns (address) {
|
||||
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Stores a new address in the ERC-1967 admin slot.
|
||||
*/
|
||||
function _setAdmin(address newAdmin) private {
|
||||
if (newAdmin == address(0)) {
|
||||
revert ERC1967InvalidAdmin(address(0));
|
||||
}
|
||||
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the admin of the proxy.
|
||||
*
|
||||
* Emits an {IERC1967-AdminChanged} event.
|
||||
*/
|
||||
function changeAdmin(address newAdmin) internal {
|
||||
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
|
||||
_setAdmin(newAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
|
||||
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
|
||||
*/
|
||||
// solhint-disable-next-line private-vars-leading-underscore
|
||||
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
|
||||
|
||||
/**
|
||||
* @dev Returns the current beacon.
|
||||
*/
|
||||
function getBeacon() internal view returns (address) {
|
||||
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Stores a new beacon in the ERC-1967 beacon slot.
|
||||
*/
|
||||
function _setBeacon(address newBeacon) private {
|
||||
if (newBeacon.code.length == 0) {
|
||||
revert ERC1967InvalidBeacon(newBeacon);
|
||||
}
|
||||
|
||||
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
|
||||
|
||||
address beaconImplementation = IBeacon(newBeacon).implementation();
|
||||
if (beaconImplementation.code.length == 0) {
|
||||
revert ERC1967InvalidImplementation(beaconImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Change the beacon and trigger a setup call if data is nonempty.
|
||||
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
|
||||
* to avoid stuck value in the contract.
|
||||
*
|
||||
* Emits an {IERC1967-BeaconUpgraded} event.
|
||||
*
|
||||
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
|
||||
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
|
||||
* efficiency.
|
||||
*/
|
||||
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
|
||||
_setBeacon(newBeacon);
|
||||
emit IERC1967.BeaconUpgraded(newBeacon);
|
||||
|
||||
if (data.length > 0) {
|
||||
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
|
||||
} else {
|
||||
_checkNonPayable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
|
||||
* if an upgrade doesn't perform an initialization call.
|
||||
*/
|
||||
function _checkNonPayable() private {
|
||||
if (msg.value > 0) {
|
||||
revert ERC1967NonPayable();
|
||||
}
|
||||
}
|
||||
}
|
||||
69
dev/env/node_modules/@openzeppelin/contracts/proxy/Proxy.sol
generated
vendored
Executable file
69
dev/env/node_modules/@openzeppelin/contracts/proxy/Proxy.sol
generated
vendored
Executable file
@@ -0,0 +1,69 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Proxy.sol)
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
/**
|
||||
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
|
||||
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
|
||||
* be specified by overriding the virtual {_implementation} function.
|
||||
*
|
||||
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
|
||||
* different contract through the {_delegate} function.
|
||||
*
|
||||
* The success and return data of the delegated call will be returned back to the caller of the proxy.
|
||||
*/
|
||||
abstract contract Proxy {
|
||||
/**
|
||||
* @dev Delegates the current call to `implementation`.
|
||||
*
|
||||
* This function does not return to its internal call site, it will return directly to the external caller.
|
||||
*/
|
||||
function _delegate(address implementation) internal virtual {
|
||||
assembly {
|
||||
// Copy msg.data. We take full control of memory in this inline assembly
|
||||
// block because it will not return to Solidity code. We overwrite the
|
||||
// Solidity scratch pad at memory position 0.
|
||||
calldatacopy(0, 0, calldatasize())
|
||||
|
||||
// Call the implementation.
|
||||
// out and outsize are 0 because we don't know the size yet.
|
||||
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
|
||||
|
||||
// Copy the returned data.
|
||||
returndatacopy(0, 0, returndatasize())
|
||||
|
||||
switch result
|
||||
// delegatecall returns 0 on error.
|
||||
case 0 {
|
||||
revert(0, returndatasize())
|
||||
}
|
||||
default {
|
||||
return(0, returndatasize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback
|
||||
* function and {_fallback} should delegate.
|
||||
*/
|
||||
function _implementation() internal view virtual returns (address);
|
||||
|
||||
/**
|
||||
* @dev Delegates the current call to the address returned by `_implementation()`.
|
||||
*
|
||||
* This function does not return to its internal call site, it will return directly to the external caller.
|
||||
*/
|
||||
function _fallback() internal virtual {
|
||||
_delegate(_implementation());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
|
||||
* function in the contract matches the call data.
|
||||
*/
|
||||
fallback() external payable virtual {
|
||||
_fallback();
|
||||
}
|
||||
}
|
||||
57
dev/env/node_modules/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol
generated
vendored
Executable file
57
dev/env/node_modules/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol
generated
vendored
Executable file
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/beacon/BeaconProxy.sol)
|
||||
|
||||
pragma solidity ^0.8.22;
|
||||
|
||||
import {IBeacon} from "./IBeacon.sol";
|
||||
import {Proxy} from "../Proxy.sol";
|
||||
import {ERC1967Utils} from "../ERC1967/ERC1967Utils.sol";
|
||||
|
||||
/**
|
||||
* @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
|
||||
*
|
||||
* The beacon address can only be set once during construction, and cannot be changed afterwards. It is stored in an
|
||||
* immutable variable to avoid unnecessary storage reads, and also in the beacon storage slot specified by
|
||||
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] so that it can be accessed externally.
|
||||
*
|
||||
* CAUTION: Since the beacon address can never be changed, you must ensure that you either control the beacon, or trust
|
||||
* the beacon to not upgrade the implementation maliciously.
|
||||
*
|
||||
* IMPORTANT: Do not use the implementation logic to modify the beacon storage slot. Doing so would leave the proxy in
|
||||
* an inconsistent state where the beacon storage slot does not match the beacon address.
|
||||
*/
|
||||
contract BeaconProxy is Proxy {
|
||||
// An immutable address for the beacon to avoid unnecessary SLOADs before each delegate call.
|
||||
address private immutable _beacon;
|
||||
|
||||
/**
|
||||
* @dev Initializes the proxy with `beacon`.
|
||||
*
|
||||
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
|
||||
* will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity
|
||||
* constructor.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `beacon` must be a contract with the interface {IBeacon}.
|
||||
* - If `data` is empty, `msg.value` must be zero.
|
||||
*/
|
||||
constructor(address beacon, bytes memory data) payable {
|
||||
ERC1967Utils.upgradeBeaconToAndCall(beacon, data);
|
||||
_beacon = beacon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current implementation address of the associated beacon.
|
||||
*/
|
||||
function _implementation() internal view virtual override returns (address) {
|
||||
return IBeacon(_getBeacon()).implementation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the beacon.
|
||||
*/
|
||||
function _getBeacon() internal view virtual returns (address) {
|
||||
return _beacon;
|
||||
}
|
||||
}
|
||||
16
dev/env/node_modules/@openzeppelin/contracts/proxy/beacon/IBeacon.sol
generated
vendored
Executable file
16
dev/env/node_modules/@openzeppelin/contracts/proxy/beacon/IBeacon.sol
generated
vendored
Executable file
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/beacon/IBeacon.sol)
|
||||
|
||||
pragma solidity >=0.4.16;
|
||||
|
||||
/**
|
||||
* @dev This is the interface that {BeaconProxy} expects of its beacon.
|
||||
*/
|
||||
interface IBeacon {
|
||||
/**
|
||||
* @dev Must return an address that can be used as a delegate call target.
|
||||
*
|
||||
* {UpgradeableBeacon} will check that this address is a contract.
|
||||
*/
|
||||
function implementation() external view returns (address);
|
||||
}
|
||||
70
dev/env/node_modules/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol
generated
vendored
Executable file
70
dev/env/node_modules/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol
generated
vendored
Executable file
@@ -0,0 +1,70 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/UpgradeableBeacon.sol)
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import {IBeacon} from "./IBeacon.sol";
|
||||
import {Ownable} from "../../access/Ownable.sol";
|
||||
|
||||
/**
|
||||
* @dev This contract is used in conjunction with one or more instances of {BeaconProxy} to determine their
|
||||
* implementation contract, which is where they will delegate all function calls.
|
||||
*
|
||||
* An owner is able to change the implementation the beacon points to, thus upgrading the proxies that use this beacon.
|
||||
*/
|
||||
contract UpgradeableBeacon is IBeacon, Ownable {
|
||||
address private _implementation;
|
||||
|
||||
/**
|
||||
* @dev The `implementation` of the beacon is invalid.
|
||||
*/
|
||||
error BeaconInvalidImplementation(address implementation);
|
||||
|
||||
/**
|
||||
* @dev Emitted when the implementation returned by the beacon is changed.
|
||||
*/
|
||||
event Upgraded(address indexed implementation);
|
||||
|
||||
/**
|
||||
* @dev Sets the address of the initial implementation, and the initial owner who can upgrade the beacon.
|
||||
*/
|
||||
constructor(address implementation_, address initialOwner) Ownable(initialOwner) {
|
||||
_setImplementation(implementation_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current implementation address.
|
||||
*/
|
||||
function implementation() public view virtual returns (address) {
|
||||
return _implementation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Upgrades the beacon to a new implementation.
|
||||
*
|
||||
* Emits an {Upgraded} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - msg.sender must be the owner of the contract.
|
||||
* - `newImplementation` must be a contract.
|
||||
*/
|
||||
function upgradeTo(address newImplementation) public virtual onlyOwner {
|
||||
_setImplementation(newImplementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets the implementation contract address for this beacon
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `newImplementation` must be a contract.
|
||||
*/
|
||||
function _setImplementation(address newImplementation) private {
|
||||
if (newImplementation.code.length == 0) {
|
||||
revert BeaconInvalidImplementation(newImplementation);
|
||||
}
|
||||
_implementation = newImplementation;
|
||||
emit Upgraded(newImplementation);
|
||||
}
|
||||
}
|
||||
45
dev/env/node_modules/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol
generated
vendored
Executable file
45
dev/env/node_modules/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol
generated
vendored
Executable file
@@ -0,0 +1,45 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/transparent/ProxyAdmin.sol)
|
||||
|
||||
pragma solidity ^0.8.22;
|
||||
|
||||
import {ITransparentUpgradeableProxy} from "./TransparentUpgradeableProxy.sol";
|
||||
import {Ownable} from "../../access/Ownable.sol";
|
||||
|
||||
/**
|
||||
* @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
|
||||
* explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
|
||||
*/
|
||||
contract ProxyAdmin is Ownable {
|
||||
/**
|
||||
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgrade(address,address)`
|
||||
* and `upgradeAndCall(address,address,bytes)` are present, and `upgrade` must be used if no function should be called,
|
||||
* while `upgradeAndCall` will invoke the `receive` function if the third argument is the empty byte string.
|
||||
* If the getter returns `"5.0.0"`, only `upgradeAndCall(address,address,bytes)` is present, and the third argument must
|
||||
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
|
||||
* during an upgrade.
|
||||
*/
|
||||
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
|
||||
|
||||
/**
|
||||
* @dev Sets the initial owner who can perform upgrades.
|
||||
*/
|
||||
constructor(address initialOwner) Ownable(initialOwner) {}
|
||||
|
||||
/**
|
||||
* @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation.
|
||||
* See {TransparentUpgradeableProxy-_dispatchUpgradeToAndCall}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - This contract must be the admin of `proxy`.
|
||||
* - If `data` is empty, `msg.value` must be zero.
|
||||
*/
|
||||
function upgradeAndCall(
|
||||
ITransparentUpgradeableProxy proxy,
|
||||
address implementation,
|
||||
bytes memory data
|
||||
) public payable virtual onlyOwner {
|
||||
proxy.upgradeToAndCall{value: msg.value}(implementation, data);
|
||||
}
|
||||
}
|
||||
118
dev/env/node_modules/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol
generated
vendored
Executable file
118
dev/env/node_modules/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol
generated
vendored
Executable file
@@ -0,0 +1,118 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/transparent/TransparentUpgradeableProxy.sol)
|
||||
|
||||
pragma solidity ^0.8.22;
|
||||
|
||||
import {ERC1967Utils} from "../ERC1967/ERC1967Utils.sol";
|
||||
import {ERC1967Proxy} from "../ERC1967/ERC1967Proxy.sol";
|
||||
import {IERC1967} from "../../interfaces/IERC1967.sol";
|
||||
import {ProxyAdmin} from "./ProxyAdmin.sol";
|
||||
|
||||
/**
|
||||
* @dev Interface for {TransparentUpgradeableProxy}. In order to implement transparency, {TransparentUpgradeableProxy}
|
||||
* does not implement this interface directly, and its upgradeability mechanism is implemented by an internal dispatch
|
||||
* mechanism. The compiler is unaware that these functions are implemented by {TransparentUpgradeableProxy} and will not
|
||||
* include them in the ABI so this interface must be used to interact with it.
|
||||
*/
|
||||
interface ITransparentUpgradeableProxy is IERC1967 {
|
||||
/// @dev See {UUPSUpgradeable-upgradeToAndCall}
|
||||
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev This contract implements a proxy that is upgradeable through an associated {ProxyAdmin} instance.
|
||||
*
|
||||
* To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
|
||||
* clashing], which can potentially be used in an attack, this contract uses the
|
||||
* https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
|
||||
* things that go hand in hand:
|
||||
*
|
||||
* 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
|
||||
* that call matches the {ITransparentUpgradeableProxy-upgradeToAndCall} function exposed by the proxy itself.
|
||||
* 2. If the admin calls the proxy, it can call the `upgradeToAndCall` function but any other call won't be forwarded to
|
||||
* the implementation. If the admin tries to call a function on the implementation it will fail with an error indicating
|
||||
* the proxy admin cannot fallback to the target implementation.
|
||||
*
|
||||
* These properties mean that the admin account can only be used for upgrading the proxy, so it's best if it's a
|
||||
* dedicated account that is not used for anything else. This will avoid headaches due to sudden errors when trying to
|
||||
* call a function from the proxy implementation. For this reason, the proxy deploys an instance of {ProxyAdmin} and
|
||||
* allows upgrades only if they come through it. You should think of the `ProxyAdmin` instance as the administrative
|
||||
* interface of the proxy, including the ability to change who can trigger upgrades by transferring ownership.
|
||||
*
|
||||
* NOTE: The real interface of this proxy is that defined in `ITransparentUpgradeableProxy`. This contract does not
|
||||
* inherit from that interface, and instead `upgradeToAndCall` is implicitly implemented using a custom dispatch
|
||||
* mechanism in `_fallback`. Consequently, the compiler will not produce an ABI for this contract. This is necessary to
|
||||
* fully implement transparency without decoding reverts caused by selector clashes between the proxy and the
|
||||
* implementation.
|
||||
*
|
||||
* NOTE: This proxy does not inherit from {Context} deliberately. The {ProxyAdmin} of this contract won't send a
|
||||
* meta-transaction in any way, and any other meta-transaction setup should be made in the implementation contract.
|
||||
*
|
||||
* IMPORTANT: This contract avoids unnecessary storage reads by setting the admin only during construction as an
|
||||
* immutable variable, preventing any changes thereafter. However, the admin slot defined in ERC-1967 can still be
|
||||
* overwritten by the implementation logic pointed to by this proxy. In such cases, the contract may end up in an
|
||||
* undesirable state where the admin slot is different from the actual admin. Relying on the value of the admin slot
|
||||
* is generally fine if the implementation is trusted.
|
||||
*
|
||||
* WARNING: It is not recommended to extend this contract to add additional external functions. If you do so, the
|
||||
* compiler will not check that there are no selector conflicts, due to the note above. A selector clash between any new
|
||||
* function and the functions declared in {ITransparentUpgradeableProxy} will be resolved in favor of the new one. This
|
||||
* could render the `upgradeToAndCall` function inaccessible, preventing upgradeability and compromising transparency.
|
||||
*/
|
||||
contract TransparentUpgradeableProxy is ERC1967Proxy {
|
||||
// An immutable address for the admin to avoid unnecessary SLOADs before each call
|
||||
// at the expense of removing the ability to change the admin once it's set.
|
||||
// This is acceptable if the admin is always a ProxyAdmin instance or similar contract
|
||||
// with its own ability to transfer the permissions to another account.
|
||||
address private immutable _admin;
|
||||
|
||||
/**
|
||||
* @dev The proxy caller is the current admin, and can't fallback to the proxy target.
|
||||
*/
|
||||
error ProxyDeniedAdminAccess();
|
||||
|
||||
/**
|
||||
* @dev Initializes an upgradeable proxy managed by an instance of a {ProxyAdmin} with an `initialOwner`,
|
||||
* backed by the implementation at `_logic`, and optionally initialized with `_data` as explained in
|
||||
* {ERC1967Proxy-constructor}.
|
||||
*/
|
||||
constructor(address _logic, address initialOwner, bytes memory _data) payable ERC1967Proxy(_logic, _data) {
|
||||
_admin = address(new ProxyAdmin(initialOwner));
|
||||
// Set the storage value and emit an event for ERC-1967 compatibility
|
||||
ERC1967Utils.changeAdmin(_proxyAdmin());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the admin of this proxy.
|
||||
*/
|
||||
function _proxyAdmin() internal view virtual returns (address) {
|
||||
return _admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev If caller is the admin process the call internally, otherwise transparently fallback to the proxy behavior.
|
||||
*/
|
||||
function _fallback() internal virtual override {
|
||||
if (msg.sender == _proxyAdmin()) {
|
||||
if (msg.sig != ITransparentUpgradeableProxy.upgradeToAndCall.selector) {
|
||||
revert ProxyDeniedAdminAccess();
|
||||
} else {
|
||||
_dispatchUpgradeToAndCall();
|
||||
}
|
||||
} else {
|
||||
super._fallback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Upgrade the implementation of the proxy. See {ERC1967Utils-upgradeToAndCall}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - If `data` is empty, `msg.value` must be zero.
|
||||
*/
|
||||
function _dispatchUpgradeToAndCall() private {
|
||||
(address newImplementation, bytes memory data) = abi.decode(msg.data[4:], (address, bytes));
|
||||
ERC1967Utils.upgradeToAndCall(newImplementation, data);
|
||||
}
|
||||
}
|
||||
238
dev/env/node_modules/@openzeppelin/contracts/proxy/utils/Initializable.sol
generated
vendored
Executable file
238
dev/env/node_modules/@openzeppelin/contracts/proxy/utils/Initializable.sol
generated
vendored
Executable file
@@ -0,0 +1,238 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
/**
|
||||
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
|
||||
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
|
||||
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
|
||||
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
|
||||
*
|
||||
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
|
||||
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
|
||||
* case an upgrade adds a module that needs to be initialized.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* [.hljs-theme-light.nopadding]
|
||||
* ```solidity
|
||||
* contract MyToken is ERC20Upgradeable {
|
||||
* function initialize() initializer public {
|
||||
* __ERC20_init("MyToken", "MTK");
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
|
||||
* function initializeV2() reinitializer(2) public {
|
||||
* __ERC20Permit_init("MyToken");
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
|
||||
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
|
||||
*
|
||||
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
|
||||
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
|
||||
*
|
||||
* [CAUTION]
|
||||
* ====
|
||||
* Avoid leaving a contract uninitialized.
|
||||
*
|
||||
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
|
||||
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
|
||||
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
|
||||
*
|
||||
* [.hljs-theme-light.nopadding]
|
||||
* ```
|
||||
* /// @custom:oz-upgrades-unsafe-allow constructor
|
||||
* constructor() {
|
||||
* _disableInitializers();
|
||||
* }
|
||||
* ```
|
||||
* ====
|
||||
*/
|
||||
abstract contract Initializable {
|
||||
/**
|
||||
* @dev Storage of the initializable contract.
|
||||
*
|
||||
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
|
||||
* when using with upgradeable contracts.
|
||||
*
|
||||
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
|
||||
*/
|
||||
struct InitializableStorage {
|
||||
/**
|
||||
* @dev Indicates that the contract has been initialized.
|
||||
*/
|
||||
uint64 _initialized;
|
||||
/**
|
||||
* @dev Indicates that the contract is in the process of being initialized.
|
||||
*/
|
||||
bool _initializing;
|
||||
}
|
||||
|
||||
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
|
||||
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
|
||||
|
||||
/**
|
||||
* @dev The contract is already initialized.
|
||||
*/
|
||||
error InvalidInitialization();
|
||||
|
||||
/**
|
||||
* @dev The contract is not initializing.
|
||||
*/
|
||||
error NotInitializing();
|
||||
|
||||
/**
|
||||
* @dev Triggered when the contract has been initialized or reinitialized.
|
||||
*/
|
||||
event Initialized(uint64 version);
|
||||
|
||||
/**
|
||||
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
|
||||
* `onlyInitializing` functions can be used to initialize parent contracts.
|
||||
*
|
||||
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
|
||||
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
|
||||
* production.
|
||||
*
|
||||
* Emits an {Initialized} event.
|
||||
*/
|
||||
modifier initializer() {
|
||||
// solhint-disable-next-line var-name-mixedcase
|
||||
InitializableStorage storage $ = _getInitializableStorage();
|
||||
|
||||
// Cache values to avoid duplicated sloads
|
||||
bool isTopLevelCall = !$._initializing;
|
||||
uint64 initialized = $._initialized;
|
||||
|
||||
// Allowed calls:
|
||||
// - initialSetup: the contract is not in the initializing state and no previous version was
|
||||
// initialized
|
||||
// - construction: the contract is initialized at version 1 (no reinitialization) and the
|
||||
// current contract is just being deployed
|
||||
bool initialSetup = initialized == 0 && isTopLevelCall;
|
||||
bool construction = initialized == 1 && address(this).code.length == 0;
|
||||
|
||||
if (!initialSetup && !construction) {
|
||||
revert InvalidInitialization();
|
||||
}
|
||||
$._initialized = 1;
|
||||
if (isTopLevelCall) {
|
||||
$._initializing = true;
|
||||
}
|
||||
_;
|
||||
if (isTopLevelCall) {
|
||||
$._initializing = false;
|
||||
emit Initialized(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
|
||||
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
|
||||
* used to initialize parent contracts.
|
||||
*
|
||||
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
|
||||
* are added through upgrades and that require initialization.
|
||||
*
|
||||
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
|
||||
* cannot be nested. If one is invoked in the context of another, execution will revert.
|
||||
*
|
||||
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
|
||||
* a contract, executing them in the right order is up to the developer or operator.
|
||||
*
|
||||
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
|
||||
*
|
||||
* Emits an {Initialized} event.
|
||||
*/
|
||||
modifier reinitializer(uint64 version) {
|
||||
// solhint-disable-next-line var-name-mixedcase
|
||||
InitializableStorage storage $ = _getInitializableStorage();
|
||||
|
||||
if ($._initializing || $._initialized >= version) {
|
||||
revert InvalidInitialization();
|
||||
}
|
||||
$._initialized = version;
|
||||
$._initializing = true;
|
||||
_;
|
||||
$._initializing = false;
|
||||
emit Initialized(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
|
||||
* {initializer} and {reinitializer} modifiers, directly or indirectly.
|
||||
*/
|
||||
modifier onlyInitializing() {
|
||||
_checkInitializing();
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
|
||||
*/
|
||||
function _checkInitializing() internal view virtual {
|
||||
if (!_isInitializing()) {
|
||||
revert NotInitializing();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
|
||||
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
|
||||
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
|
||||
* through proxies.
|
||||
*
|
||||
* Emits an {Initialized} event the first time it is successfully executed.
|
||||
*/
|
||||
function _disableInitializers() internal virtual {
|
||||
// solhint-disable-next-line var-name-mixedcase
|
||||
InitializableStorage storage $ = _getInitializableStorage();
|
||||
|
||||
if ($._initializing) {
|
||||
revert InvalidInitialization();
|
||||
}
|
||||
if ($._initialized != type(uint64).max) {
|
||||
$._initialized = type(uint64).max;
|
||||
emit Initialized(type(uint64).max);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the highest version that has been initialized. See {reinitializer}.
|
||||
*/
|
||||
function _getInitializedVersion() internal view returns (uint64) {
|
||||
return _getInitializableStorage()._initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
|
||||
*/
|
||||
function _isInitializing() internal view returns (bool) {
|
||||
return _getInitializableStorage()._initializing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
|
||||
*
|
||||
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
|
||||
*/
|
||||
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
|
||||
return INITIALIZABLE_STORAGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns a pointer to the storage namespace.
|
||||
*/
|
||||
// solhint-disable-next-line var-name-mixedcase
|
||||
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
|
||||
bytes32 slot = _initializableStorageSlot();
|
||||
assembly {
|
||||
$.slot := slot
|
||||
}
|
||||
}
|
||||
}
|
||||
146
dev/env/node_modules/@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol
generated
vendored
Executable file
146
dev/env/node_modules/@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol
generated
vendored
Executable file
@@ -0,0 +1,146 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)
|
||||
|
||||
pragma solidity ^0.8.22;
|
||||
|
||||
import {IERC1822Proxiable} from "../../interfaces/draft-IERC1822.sol";
|
||||
import {ERC1967Utils} from "../ERC1967/ERC1967Utils.sol";
|
||||
|
||||
/**
|
||||
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
|
||||
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
|
||||
*
|
||||
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
|
||||
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
|
||||
* `UUPSUpgradeable` with a custom implementation of upgrades.
|
||||
*
|
||||
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
|
||||
*/
|
||||
abstract contract UUPSUpgradeable is IERC1822Proxiable {
|
||||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
||||
address private immutable __self = address(this);
|
||||
|
||||
/**
|
||||
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
|
||||
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
|
||||
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
|
||||
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
|
||||
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
|
||||
* during an upgrade.
|
||||
*/
|
||||
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
|
||||
|
||||
/**
|
||||
* @dev The call is from an unauthorized context.
|
||||
*/
|
||||
error UUPSUnauthorizedCallContext();
|
||||
|
||||
/**
|
||||
* @dev The storage `slot` is unsupported as a UUID.
|
||||
*/
|
||||
error UUPSUnsupportedProxiableUUID(bytes32 slot);
|
||||
|
||||
/**
|
||||
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
|
||||
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
|
||||
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
|
||||
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
|
||||
* fail.
|
||||
*/
|
||||
modifier onlyProxy() {
|
||||
_checkProxy();
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
|
||||
* callable on the implementing contract but not through proxies.
|
||||
*/
|
||||
modifier notDelegated() {
|
||||
_checkNotDelegated();
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
|
||||
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
|
||||
*
|
||||
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
|
||||
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
|
||||
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
|
||||
*/
|
||||
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
|
||||
return ERC1967Utils.IMPLEMENTATION_SLOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
|
||||
* encoded in `data`.
|
||||
*
|
||||
* Calls {_authorizeUpgrade}.
|
||||
*
|
||||
* Emits an {Upgraded} event.
|
||||
*
|
||||
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
|
||||
*/
|
||||
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
|
||||
_authorizeUpgrade(newImplementation);
|
||||
_upgradeToAndCallUUPS(newImplementation, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Reverts if the execution is not performed via delegatecall or the execution
|
||||
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
|
||||
*/
|
||||
function _checkProxy() internal view virtual {
|
||||
if (
|
||||
address(this) == __self || // Must be called through delegatecall
|
||||
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
|
||||
) {
|
||||
revert UUPSUnauthorizedCallContext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Reverts if the execution is performed via delegatecall.
|
||||
* See {notDelegated}.
|
||||
*/
|
||||
function _checkNotDelegated() internal view virtual {
|
||||
if (address(this) != __self) {
|
||||
// Must not be called through delegatecall
|
||||
revert UUPSUnauthorizedCallContext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
|
||||
* {upgradeToAndCall}.
|
||||
*
|
||||
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
|
||||
*
|
||||
* ```solidity
|
||||
* function _authorizeUpgrade(address) internal onlyOwner {}
|
||||
* ```
|
||||
*/
|
||||
function _authorizeUpgrade(address newImplementation) internal virtual;
|
||||
|
||||
/**
|
||||
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
|
||||
*
|
||||
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
|
||||
* is expected to be the implementation slot in ERC-1967.
|
||||
*
|
||||
* Emits an {IERC1967-Upgraded} event.
|
||||
*/
|
||||
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
|
||||
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
|
||||
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
|
||||
revert UUPSUnsupportedProxiableUUID(slot);
|
||||
}
|
||||
ERC1967Utils.upgradeToAndCall(newImplementation, data);
|
||||
} catch {
|
||||
// The implementation is not UUPS
|
||||
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user