mirror of
https://github.com/Instadapp/infinite-proxy.git
synced 2024-07-29 21:47:49 +00:00
initial commit 🚀
This commit is contained in:
parent
8fc7bb3b1e
commit
ba18bc271e
36
proxy.sol
36
proxy.sol
|
|
@ -31,10 +31,7 @@ contract Internals is Events {
|
||||||
*/
|
*/
|
||||||
bytes32 internal constant _DUMMY_IMPLEMENTATION_SLOT =
|
bytes32 internal constant _DUMMY_IMPLEMENTATION_SLOT =
|
||||||
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
|
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Returns the storage slot which stores the sigs array set for the implementation.
|
|
||||||
*/
|
|
||||||
function _getSlotImplSigsSlot(address implementation_)
|
function _getSlotImplSigsSlot(address implementation_)
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
|
|
@ -46,9 +43,6 @@ contract Internals is Events {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Returns the storage slot which stores the implementation address for the function sig.
|
|
||||||
*/
|
|
||||||
function _getSlotSigsImplSlot(bytes4 sig_) internal pure returns (bytes32) {
|
function _getSlotSigsImplSlot(bytes4 sig_) internal pure returns (bytes32) {
|
||||||
return keccak256(abi.encode("eip1967.proxy.implementation", sig_));
|
return keccak256(abi.encode("eip1967.proxy.implementation", sig_));
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +97,7 @@ contract Internals is Events {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Removes implementation and the mappings corresponding to it.
|
* @dev removes implementation and the mappings corresponding to it.
|
||||||
*/
|
*/
|
||||||
function _removeImplementationSigs(address implementation_) internal {
|
function _removeImplementationSigs(address implementation_) internal {
|
||||||
bytes32 slot_ = _getSlotImplSigsSlot(implementation_);
|
bytes32 slot_ = _getSlotImplSigsSlot(implementation_);
|
||||||
|
|
@ -117,9 +111,6 @@ contract Internals is Events {
|
||||||
emit removeImplementationLog(implementation_);
|
emit removeImplementationLog(implementation_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Returns bytes4[] sigs from implementation address. If implemenatation is not registered then returns empty array.
|
|
||||||
*/
|
|
||||||
function _getImplementationSigs(address implementation_)
|
function _getImplementationSigs(address implementation_)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
|
|
@ -129,9 +120,6 @@ contract Internals is Events {
|
||||||
return getSigsSlot(slot_).value;
|
return getSigsSlot(slot_).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Returns implementation address from bytes4 sig. If sig is not registered then returns address(0).
|
|
||||||
*/
|
|
||||||
function _getSigImplementation(bytes4 sig_)
|
function _getSigImplementation(bytes4 sig_)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
|
|
@ -235,24 +223,20 @@ contract Internals is Events {
|
||||||
}
|
}
|
||||||
|
|
||||||
contract AdminStuff is Internals {
|
contract AdminStuff is Internals {
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Only admin gaurd.
|
|
||||||
*/
|
|
||||||
modifier onlyAdmin() {
|
modifier onlyAdmin() {
|
||||||
require(msg.sender == _getAdmin(), "not-the-admin");
|
require(msg.sender == _getAdmin(), "not-the-admin");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sets new admin.
|
* @dev sets new admin.
|
||||||
*/
|
*/
|
||||||
function setAdmin(address newAdmin_) external onlyAdmin {
|
function setAdmin(address newAdmin_) external onlyAdmin {
|
||||||
_setAdmin(newAdmin_);
|
_setAdmin(newAdmin_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sets new dummy-implementation.
|
* @dev sets new dummy-implementation.
|
||||||
*/
|
*/
|
||||||
function setDummyImplementation(address newDummyImplementation_)
|
function setDummyImplementation(address newDummyImplementation_)
|
||||||
external
|
external
|
||||||
|
|
@ -262,7 +246,7 @@ contract AdminStuff is Internals {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Adds new implementation address.
|
* @dev adds new implementation address.
|
||||||
*/
|
*/
|
||||||
function addImplementation(address implementation_, bytes4[] calldata sigs_)
|
function addImplementation(address implementation_, bytes4[] calldata sigs_)
|
||||||
external
|
external
|
||||||
|
|
@ -272,7 +256,7 @@ contract AdminStuff is Internals {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Removes an existing implementation address.
|
* @dev removes an existing implementation address.
|
||||||
*/
|
*/
|
||||||
function removeImplementation(address implementation_) external onlyAdmin {
|
function removeImplementation(address implementation_) external onlyAdmin {
|
||||||
_removeImplementationSigs(implementation_);
|
_removeImplementationSigs(implementation_);
|
||||||
|
|
@ -290,21 +274,21 @@ abstract contract Proxy is AdminStuff {
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Returns admin's address.
|
* @dev returns admin's address.
|
||||||
*/
|
*/
|
||||||
function getAdmin() external view returns (address) {
|
function getAdmin() external view returns (address) {
|
||||||
return _getAdmin();
|
return _getAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Returns dummy-implementations's address.
|
* @dev returns dummy-implementations's address.
|
||||||
*/
|
*/
|
||||||
function getDummyImplementation() external view returns (address) {
|
function getDummyImplementation() external view returns (address) {
|
||||||
return _getDummyImplementation();
|
return _getDummyImplementation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Returns bytes4[] sigs from implementation address If not registered then returns empty array.
|
* @dev returns bytes4[] sigs from implementation address If not registered then returns empty array.
|
||||||
*/
|
*/
|
||||||
function getImplementationSigs(address impl_)
|
function getImplementationSigs(address impl_)
|
||||||
external
|
external
|
||||||
|
|
@ -315,7 +299,7 @@ abstract contract Proxy is AdminStuff {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Returns implementation address from bytes4 sig. If sig is not registered then returns address(0).
|
* @dev returns implementation address from bytes4 sig. If sig is not registered then returns address(0).
|
||||||
*/
|
*/
|
||||||
function getSigsImplementation(bytes4 sig_)
|
function getSigsImplementation(bytes4 sig_)
|
||||||
external
|
external
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user