Files
erc-3643/contracts/proxy/AbstractProxy.sol

113 lines
6.1 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0
//
// :+#####%%%%%%%%%%%%%%+
// .-*@@@%+.:+%@@@@@%%#***%@@%=
// :=*%@@@#=. :#@@% *@@@%=
// .-+*%@%*-.:+%@@@@@@+. -*+: .=#. :%@@@%-
// :=*@@@@%%@@@@@@@@@%@@@- .=#@@@%@%= =@@@@#.
// -=+#%@@%#*=:. :%@@@@%. -*@@#*@@@@@@@#=:- *@@@@+
// =@@%=:. :=: *@@@@@%#- =%*%@@@@#+-. =+ :%@@@%-
// -@@%. .+@@@ =+=-. @@#- +@@@%- =@@@@%:
// :@@@. .+@@#%: : .=*=-::.-%@@@+*@@= +@@@@#.
// %@@: +@%%* =%@@@@@@@@@@@#. .*@%- +@@@@*.
// #@@= .+@@@@%:=*@@@@@- :%@%: .*@@@@+
// *@@* +@@@#-@@%-:%@@* +@@#. :%@@@@-
// -@@% .:-=++*##%%%@@@@@@@@@@@@*. :@+.@@@%: .#@@+ =@@@@#:
// .@@@*-+*#%%%@@@@@@@@@@@@@@@@%%#**@@%@@@. *@=*@@# :#@%= .#@@@@#-
// -%@@@@@@@@@@@@@@@*+==-:-@@@= *@# .#@*-=*@@@@%= -%@@@* =@@@@@%-
// -+%@@@#. %@%%= -@@:+@: -@@* *@@*-:: -%@@%=. .*@@@@@#
// *@@@* +@* *@@##@@- #@*@@+ -@@= . :+@@@#: .-+@@@%+-
// +@@@%*@@:..=@@@@* .@@@* .#@#. .=+- .=%@@@*. :+#@@@@*=:
// =@@@@%@@@@@@@@@@@@@@@@@@@@@@%- :+#*. :*@@@%=. .=#@@@@%+:
// .%@@= ..... .=#@@+. .#@@@*: -*%@@@@%+.
// +@@#+===---:::... .=%@@*- +@@@+. -*@@@@@%+.
// -@@@@@@@@@@@@@@@@@@@@@@%@@@@= -@@@+ -#@@@@@#=.
// ..:::---===+++***###%%%@@@#- .#@@+ -*@@@@@#=.
// @@@@@@+. +@@*. .+@@@@@%=.
// -@@@@@= =@@%: -#@@@@%+.
// +@@@@@. =@@@= .+@@@@@*:
// #@@@@#:%@@#. :*@@@@#-
// @@@@@%@@@= :#@@@@+.
// :@@@@@@@#.:#@@@%-
// +@@@@@@-.*@@@*:
// #@@@@#.=@@@+.
// @@@@+-%@%=
// :@@@#%@%=
// +@@@@%-
// :#%%=
//
/**
* NOTICE
*
* The T-REX software is licensed under a proprietary license or the GPL v.3.
* If you choose to receive it under the GPL v.3 license, the following applies:
* T-REX is a suite of smart contracts implementing the ERC-3643 standard and
* developed by Tokeny to manage and transfer financial assets on EVM blockchains
*
* Copyright (C) 2023, Tokeny sàrl.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity ^0.8.17;
import "./interface/IProxy.sol";
import "./authority/ITREXImplementationAuthority.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
abstract contract AbstractProxy is IProxy, Initializable {
/**
* @dev See {IProxy-setImplementationAuthority}.
*/
function setImplementationAuthority(address _newImplementationAuthority) external override {
require(msg.sender == getImplementationAuthority(), "only current implementationAuthority can call");
require(_newImplementationAuthority != address(0), "invalid argument - zero address");
require(
(ITREXImplementationAuthority(_newImplementationAuthority)).getTokenImplementation() != address(0)
&& (ITREXImplementationAuthority(_newImplementationAuthority)).getCTRImplementation() != address(0)
&& (ITREXImplementationAuthority(_newImplementationAuthority)).getIRImplementation() != address(0)
&& (ITREXImplementationAuthority(_newImplementationAuthority)).getIRSImplementation() != address(0)
&& (ITREXImplementationAuthority(_newImplementationAuthority)).getMCImplementation() != address(0)
&& (ITREXImplementationAuthority(_newImplementationAuthority)).getTIRImplementation() != address(0)
, "invalid Implementation Authority");
_storeImplementationAuthority(_newImplementationAuthority);
emit ImplementationAuthoritySet(_newImplementationAuthority);
}
/**
* @dev See {IProxy-getImplementationAuthority}.
*/
function getImplementationAuthority() public override view returns(address) {
address implemAuth;
// solhint-disable-next-line no-inline-assembly
assembly {
implemAuth := sload(0x821f3e4d3d679f19eacc940c87acf846ea6eae24a63058ea750304437a62aafc)
}
return implemAuth;
}
/**
* @dev store the implementationAuthority contract address using the ERC-3643 implementation slot in storage
* the slot storage is the result of `keccak256("ERC-3643.proxy.beacon")`
*/
function _storeImplementationAuthority(address implementationAuthority) internal {
// solhint-disable-next-line no-inline-assembly
assembly {
sstore(0x821f3e4d3d679f19eacc940c87acf846ea6eae24a63058ea750304437a62aafc, implementationAuthority)
}
}
}