mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 19:26:33 +00:00
Fix .gitignore: stop tracking ignored files
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/beacon/BeaconProxy.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./IBeacon.sol";
|
||||
import "../Proxy.sol";
|
||||
import "../ERC1967/ERC1967Upgrade.sol";
|
||||
|
||||
/**
|
||||
* @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
|
||||
*
|
||||
* The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't
|
||||
* conflict with the storage layout of the implementation behind the proxy.
|
||||
*
|
||||
* _Available since v3.4._
|
||||
*/
|
||||
contract BeaconProxy is Proxy, ERC1967Upgrade {
|
||||
/**
|
||||
* @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}.
|
||||
*/
|
||||
constructor(address beacon, bytes memory data) payable {
|
||||
_upgradeBeaconToAndCall(beacon, data, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current beacon address.
|
||||
*/
|
||||
function _beacon() internal view virtual returns (address) {
|
||||
return _getBeacon();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current implementation address of the associated beacon.
|
||||
*/
|
||||
function _implementation() internal view virtual override returns (address) {
|
||||
return IBeacon(_getBeacon()).implementation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}.
|
||||
*
|
||||
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `beacon` must be a contract.
|
||||
* - The implementation returned by `beacon` must be a contract.
|
||||
*/
|
||||
function _setBeacon(address beacon, bytes memory data) internal virtual {
|
||||
_upgradeBeaconToAndCall(beacon, data, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* {BeaconProxy} will check that this address is a contract.
|
||||
*/
|
||||
function implementation() external view returns (address);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/UpgradeableBeacon.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./IBeacon.sol";
|
||||
import "../../access/Ownable.sol";
|
||||
import "../../utils/Address.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 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 deployer account as the owner who can upgrade the
|
||||
* beacon.
|
||||
*/
|
||||
constructor(address implementation_) {
|
||||
_setImplementation(implementation_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current implementation address.
|
||||
*/
|
||||
function implementation() public view virtual override 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);
|
||||
emit Upgraded(newImplementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets the implementation contract address for this beacon
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `newImplementation` must be a contract.
|
||||
*/
|
||||
function _setImplementation(address newImplementation) private {
|
||||
require(Address.isContract(newImplementation), "UpgradeableBeacon: implementation is not a contract");
|
||||
_implementation = newImplementation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user