upgradability init

This commit is contained in:
Alexey 2021-08-02 21:33:24 +03:00
parent 4d2244297b
commit 93bc29580b
3 changed files with 41 additions and 5 deletions

View File

@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "@openzeppelin/contracts/contracts/proxy/TransparentUpgradeableProxy.sol";
// https://github.com/ethereum-optimism/optimism/blob/c7bc85deee999b8edfbe187b302d0ea262638ca9/packages/contracts/contracts/optimistic-ethereum/iOVM/bridge/messaging/iOVM_CrossDomainMessenger.sol
interface iOVM_CrossDomainMessenger {
function xDomainMessageSender() external view returns (address);
}
/**
* @dev TransparentUpgradeableProxy where admin acts from a different chain.
*/
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
// https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts/deployments/README.md
iOVM_CrossDomainMessenger public constant messenger = iOVM_CrossDomainMessenger(0x4200000000000000000000000000000000000007);
/**
* @dev Initializes an upgradeable proxy backed by the implementation at `_logic`.
*/
constructor(
address _logic,
address _admin,
bytes memory _data
) TransparentUpgradeableProxy(_logic, _admin, _data) {}
/**
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the cross chain admin.
*/
modifier ifAdmin() override {
if (msg.sender == address(messenger) && messenger.xDomainMessageSender() == _admin()) {
_;
} else {
_fallback();
}
}
}

View File

@ -24,7 +24,7 @@
"dependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "^3.4.0",
"@openzeppelin/contracts": "git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f",
"bignumber.js": "^9.0.0",
"chai": "^4.3.4",
"circom": "^0.5.45",

View File

@ -683,10 +683,9 @@
"@types/sinon-chai" "^3.2.3"
"@types/web3" "1.0.19"
"@openzeppelin/contracts@^3.4.0":
version "3.4.1"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-3.4.1.tgz#03c891fec7f93be0ae44ed74e57a122a38732ce7"
integrity sha512-cUriqMauq1ylzP2TxePNdPqkwI7Le3Annh4K9rrpvKfSBB/bdW+Iu1ihBaTIABTAAJ85LmKL5SSPPL9ry8d1gQ==
"@openzeppelin/contracts@git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f":
version "3.4.1-solc-0.7-2"
resolved "git+https://github.com/tornadocash/openzeppelin-contracts.git#6e46aa6946a7f215e7604169ddf46e1aebea850f"
"@resolver-engine/core@^0.3.3":
version "0.3.3"