2021-08-02 20:33:24 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
|
2021-10-05 11:08:04 +02:00
|
|
|
import { IAMB } from "./interfaces/Bridge.sol";
|
2021-08-02 20:33:24 +02:00
|
|
|
import "@openzeppelin/contracts/contracts/proxy/TransparentUpgradeableProxy.sol";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev TransparentUpgradeableProxy where admin acts from a different chain.
|
|
|
|
*/
|
|
|
|
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
2021-10-05 11:08:04 +02:00
|
|
|
IAMB public immutable ambBridge;
|
2021-10-04 12:06:58 +02:00
|
|
|
bytes32 public immutable adminChainId;
|
2021-08-02 20:33:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Initializes an upgradeable proxy backed by the implementation at `_logic`.
|
|
|
|
*/
|
|
|
|
constructor(
|
|
|
|
address _logic,
|
|
|
|
address _admin,
|
2021-08-05 09:29:49 +02:00
|
|
|
bytes memory _data,
|
2021-10-05 11:08:04 +02:00
|
|
|
IAMB _ambBridge,
|
2021-10-04 12:06:58 +02:00
|
|
|
uint256 _adminChainId
|
2021-08-05 09:29:49 +02:00
|
|
|
) TransparentUpgradeableProxy(_logic, _admin, _data) {
|
2021-10-05 11:08:04 +02:00
|
|
|
ambBridge = _ambBridge;
|
2021-10-04 12:06:58 +02:00
|
|
|
adminChainId = bytes32(uint256(_adminChainId));
|
2021-08-05 09:29:49 +02:00
|
|
|
}
|
2021-08-02 20:33:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the cross chain admin.
|
|
|
|
*/
|
|
|
|
modifier ifAdmin() override {
|
2021-10-04 12:06:58 +02:00
|
|
|
if (
|
2021-10-05 11:08:04 +02:00
|
|
|
msg.sender == address(ambBridge) &&
|
|
|
|
ambBridge.messageSourceChainId() == adminChainId &&
|
|
|
|
ambBridge.messageSender() == _admin()
|
2021-10-04 12:06:58 +02:00
|
|
|
) {
|
2021-08-02 20:33:24 +02:00
|
|
|
_;
|
|
|
|
} else {
|
|
|
|
_fallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|