InverterTransparentUpgradeableProxy_v1.sol

Git Source

Inherits: ERC1967Proxy

Author: Inverter Network

An alternative variant of the {TransparentUpgradeableProxy} of OpenZeppelin that allows for upgrading the linked implementation of the proxy to the implementation provided by a linked beacon.

*This contract is a fork of the {TransparentUpgradeableProxy} from openzeppelin. We adapted the callable functions of the admin account to only be able to upgrade the implementation to the newest implementation of the linked {InverterBeacon_v1}. !!! IMPORTANT !!!

  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 {IInverterTransparentUpgradeableProxy_v1-upgradeToNewestVersion} function exposed by the proxy itself.

  2. If the admin calls the proxy, it can call the upgradeToNewestVersion 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.*

State Variables

_admin

The address of the admin that can update the implementation address of this proxy.

address internal immutable _admin;

_beacon

The address of the beacon that is used to fetch the implementation address.

IInverterBeacon_v1 internal immutable _beacon;

majorVersion

The major version of the implementation.

uint internal majorVersion;

minorVersion

The minor version of the implementation.

uint internal minorVersion;

patchVersion

The patch version of the implementation.

uint internal patchVersion;

Functions

constructor

constructor(IInverterBeacon_v1 beacon, address initialOwner, bytes memory _data)
    ERC1967Proxy(beacon.getImplementationAddress(), _data);

version

Returns the version of the linked implementation.

This overrides the possible use of a "version" function in the modules that are called via the Proxy Beacon structure.

function version() external view returns (uint, uint, uint);

Returns

Name
Type
Description

<none>

uint256

The major version.

<none>

uint256

The minor version.

<none>

uint256

The patch version.

receive

Fallback function to delegate calls to the implementation contract even if the call data is empty but msg.value > 0.

receive() external payable virtual;

upgradeToNewestVersion

Upgrades the implementation to the newest version listed in the beacon.

function upgradeToNewestVersion() internal virtual;

_fallback

If caller is the admin process the call internally, otherwise transparently fallback to the proxy behavior.

function _fallback() internal virtual override;

Errors

InverterTransparentUpgradeableProxy__InvalidBeacon

The provided beacon address doesn't support the interface {IInverterBeacon_v1}.

error InverterTransparentUpgradeableProxy__InvalidBeacon();

InverterTransparentUpgradeableProxy__ProxyDeniedAdminAccess

If the proxy caller is the current admin then it can only call the admin functions.

error InverterTransparentUpgradeableProxy__ProxyDeniedAdminAccess();

Last updated