2021-08-02 20:33:24 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
|
|
|
|
import "@openzeppelin/contracts/contracts/proxy/TransparentUpgradeableProxy.sol";
|
|
|
|
|
2021-09-29 21:39:30 +02:00
|
|
|
// https://docs.tokenbridge.net/amb-bridge/development-of-a-cross-chain-application/how-to-develop-xchain-apps-by-amb#call-a-method-in-another-chain-using-the-amb-bridge
|
|
|
|
|
|
|
|
interface IAMB {
|
|
|
|
function messageSender() external view returns (address);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IOmniBridge {
|
|
|
|
function bridgeContract() external view returns (IAMB);
|
2021-08-02 20:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev TransparentUpgradeableProxy where admin acts from a different chain.
|
|
|
|
*/
|
|
|
|
contract CrossChainUpgradeableProxy is TransparentUpgradeableProxy {
|
2021-09-29 21:39:30 +02:00
|
|
|
IOmniBridge public immutable omniBridge;
|
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-09-29 21:39:30 +02:00
|
|
|
IOmniBridge _omniBridge
|
2021-08-05 09:29:49 +02:00
|
|
|
) TransparentUpgradeableProxy(_logic, _admin, _data) {
|
2021-09-29 21:39:30 +02:00
|
|
|
omniBridge = _omniBridge;
|
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-09-29 21:39:30 +02:00
|
|
|
if (msg.sender == address(omniBridge) && omniBridge.bridgeContract().messageSender() == _admin()) {
|
2021-08-02 20:33:24 +02:00
|
|
|
_;
|
|
|
|
} else {
|
|
|
|
_fallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|