forked from 0xPolygonHermez/zkevm-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00d6ea8
commit d8eff2b
Showing
7 changed files
with
709 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"printWidth": 80, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"explicitTypes": "always" | ||
} | ||
"printWidth": 120, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"quoteProps": "as-needed", | ||
"trailingComma": "es5", | ||
"bracketSpacing": false, | ||
"arrowParens": "always", | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"printWidth": 80, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"explicitTypes": "always" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/transparent/TransparentUpgradeableProxy.sol) | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {ERC1967Utils} from "@openzeppelin/contracts5/proxy/ERC1967/ERC1967Utils.sol"; | ||
import {ERC1967Proxy} from "@openzeppelin/contracts5/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import {IERC1967} from "@openzeppelin/contracts5/interfaces/IERC1967.sol"; | ||
import {ProxyAdmin} from "@openzeppelin/contracts5/proxy/transparent/ProxyAdmin.sol"; | ||
import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts5/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
/** | ||
* @dev Contrac TransparentUpgradeableProxy from Openzeppelin v5 with the following modifications: | ||
* - Admin is a parameter in the constructor ( like previous versions) isntead of being deployed | ||
* - Let the admin get access to the proxy | ||
* - Add custom errors | ||
* - Replace _msgSender() with msg.sender | ||
*/ | ||
contract PolygonTransparentProxy 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 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 admin, | ||
bytes memory _data | ||
) payable ERC1967Proxy(_logic, _data) { | ||
_admin = admin; | ||
// 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 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 | ||
) { | ||
super._fallback(); | ||
} 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); | ||
} | ||
} |
Oops, something went wrong.