# InverterTransparentUpgradeableProxy\_v1.sol

[Git Source](https://github.com/InverterNetwork/inverter-contracts/blob/2a8a4c80ff4f24a59546d4e6126b81bc51228c94/src/proxies/InverterTransparentUpgradeableProxy_v1.sol)

**Inherits:** [ERC1967Proxy](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/proxy/ERC1967/ERC1967Proxy.sol)

**Author:** Inverter Network

An alternative variant of the [{TransparentUpgradeableProxy}](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/proxy/transparent/TransparentUpgradeableProxy.sol) 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}](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/proxy/transparent/TransparentUpgradeableProxy.sol) 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}](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol). !!! 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.*

```solidity
address internal immutable _admin;
```

#### \_beacon

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

```solidity
IInverterBeacon_v1 internal immutable _beacon;
```

#### majorVersion

*The major version of the implementation.*

```solidity
uint internal majorVersion;
```

#### minorVersion

*The minor version of the implementation.*

```solidity
uint internal minorVersion;
```

#### patchVersion

*The patch version of the implementation.*

```solidity
uint internal patchVersion;
```

### Functions

#### constructor

```solidity
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.*

```solidity
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.*

```solidity
receive() external payable virtual;
```

#### upgradeToNewestVersion

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

```solidity
function upgradeToNewestVersion() internal virtual;
```

#### \_fallback

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

```solidity
function _fallback() internal virtual override;
```

### Errors

#### InverterTransparentUpgradeableProxy\_\_InvalidBeacon

The provided beacon address doesn't support the interface [{IInverterBeacon\_v1}](https://docs.inverter.network/contracts/technical-reference/proxies/interfaces/iinverterbeacon_v1.sol).

```solidity
error InverterTransparentUpgradeableProxy__InvalidBeacon();
```

#### InverterTransparentUpgradeableProxy\_\_ProxyDeniedAdminAccess

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

```solidity
error InverterTransparentUpgradeableProxy__ProxyDeniedAdminAccess();
```
