-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add release-package.yml * patch package scope * patch repository url * patch homepage * Unstructured storage (#4) * bump version * UnstructuredStorageLib * rename to keystore, add initializablekeystore * rename InitializableKeyStored * patch doc * CloneFactory.sol * Add ArrayLib helper functions * change org name * fix npm ignore files (#5) * v0.1.1 + docs
- Loading branch information
Showing
19 changed files
with
684 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
//from https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol | ||
//explainer at https://blog.openzeppelin.com/deep-dive-into-the-minimal-proxy-contract/ | ||
//also see https://eips.ethereum.org/EIPS/eip-1167 | ||
|
||
//WARNING: READ BELOW to understand differences with original contract | ||
/** | ||
* Modified from @optionality.io/clone-factory/contracts/CloneFactory.sol | ||
* - Added support for CREATE2-deployed minimal proxy. | ||
*/ | ||
|
||
/** | ||
* @dev EIP1167 Minimal Proxy | ||
*/ | ||
|
||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2018 Murray Software, LLC. | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
//solhint-disable max-line-length | ||
//solhint-disable no-inline-assembly | ||
|
||
contract CloneFactory { | ||
//CHANGE from REFERENCE implementation by Leo VIGNA | ||
//Added create2 support | ||
function create2Clone(address target, bytes32 salt) internal returns (address result) { | ||
bytes20 targetBytes = bytes20(target); | ||
assembly { | ||
let clone := mload(0x40) | ||
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) | ||
mstore(add(clone, 0x14), targetBytes) | ||
mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) | ||
result := create2(0, clone, 0x37, salt) | ||
} | ||
} | ||
|
||
function createClone(address target) internal returns (address result) { | ||
bytes20 targetBytes = bytes20(target); | ||
assembly { | ||
let clone := mload(0x40) | ||
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) | ||
mstore(add(clone, 0x14), targetBytes) | ||
mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) | ||
result := create(0, clone, 0x37) | ||
} | ||
} | ||
|
||
function isClone(address target, address query) internal view returns (bool result) { | ||
bytes20 targetBytes = bytes20(target); | ||
assembly { | ||
let clone := mload(0x40) | ||
mstore(clone, 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000) | ||
mstore(add(clone, 0xa), targetBytes) | ||
mstore(add(clone, 0x1e), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) | ||
|
||
let other := add(clone, 0x40) | ||
extcodecopy(query, other, 0, 0x2d) | ||
result := and(eq(mload(clone), mload(other)), eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
// solhint-disable-next-line compiler-version | ||
pragma solidity >=0.4.24 <0.8.0; | ||
|
||
import '../Storage/KeyStoreLib.sol'; | ||
|
||
//WARNING: READ BELOW to understand differences with original contract | ||
/** Modified from @openzeppelin/contracts/proxy/Initializable.sol | ||
* Contracts that inherit from a parent class often can't also | ||
* be made Initializable because of conflicts with parent contract's | ||
* storage layer. The solution until now was to make the parent contract | ||
* Initializable but this cannot always be done (eg. using a library such as OpenGSN). | ||
* | ||
* This version of the Initializable contract uses KeyStoreLib to store the | ||
* variables at InitializableKeyStored._initialized and | ||
* InitializableKeyStored._initializing. | ||
*/ | ||
|
||
/** | ||
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed | ||
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an | ||
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer | ||
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. | ||
* | ||
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as | ||
* possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. | ||
* | ||
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure | ||
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. | ||
*/ | ||
abstract contract InitializableKeyStored { | ||
using KeyStoreLib for bytes32; | ||
|
||
/** | ||
* @dev Indicates that the contract has been initialized. | ||
*/ | ||
bytes32 private constant _initializedSlot = keccak256('InitializableKeyStored._initialized'); | ||
|
||
/** | ||
* @dev Indicates that the contract is in the process of being initialized. | ||
*/ | ||
bytes32 private constant _initializingSlot = keccak256('InitializableKeyStored._initializing'); | ||
|
||
/** | ||
* @dev Modifier to protect an initializer function from being invoked twice. | ||
*/ | ||
modifier initializer() { | ||
bool _initialized = _initializedSlot.getBool(); | ||
bool _initializing = _initializingSlot.getBool(); | ||
|
||
require(_initializing || _isConstructor() || !_initialized, 'Initializable: contract is already initialized'); | ||
|
||
bool isTopLevelCall = !_initializing; | ||
if (isTopLevelCall) { | ||
_initializing = true; | ||
_initialized = true; | ||
} | ||
|
||
_; | ||
|
||
if (isTopLevelCall) { | ||
_initializing = false; | ||
} | ||
} | ||
|
||
/// @dev Returns true if and only if the function is running in the constructor | ||
function _isConstructor() private view returns (bool) { | ||
// extcodesize checks the size of the code stored in an address, and | ||
// address returns the current address. Since the code is still not | ||
// deployed when running a constructor, any checks on its code size will | ||
// yield zero, making it an effective way to detect if a contract is | ||
// under construction or not. | ||
address self = address(this); | ||
uint256 cs; | ||
// solhint-disable-next-line no-inline-assembly | ||
assembly { | ||
cs := extcodesize(self) | ||
} | ||
return cs == 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity >=0.6.0; | ||
|
||
import './KeyStoreLib.sol'; | ||
|
||
/** | ||
* @dev An example external facing contract using KeyStoreLib | ||
* | ||
* WARNING: Contracts should use KeyStoreLib directly (recommended) or override KeyStore setter methods. | ||
* | ||
*/ | ||
contract KeyStore { | ||
using KeyStoreLib for bytes32; | ||
|
||
/** | ||
* @dev Get uint256 | ||
* @param slot storage slot | ||
* @return v | ||
* | ||
*/ | ||
function getUInt256(bytes32 slot) public view returns (uint256 v) { | ||
return slot.getUInt256(); | ||
} | ||
|
||
/** | ||
* @dev Set uint256 | ||
* @param slot storage slot | ||
* @param v value | ||
* | ||
*/ | ||
function setUInt256(bytes32 slot, uint256 v) public { | ||
slot.setUInt256(v); | ||
} | ||
|
||
/** | ||
* @dev Get address | ||
* @param slot storage slot | ||
* @return v | ||
* | ||
*/ | ||
function getAddress(bytes32 slot) public view returns (address v) { | ||
return slot.getAddress(); | ||
} | ||
|
||
/** | ||
* @dev Set address | ||
* @param slot storage slot | ||
* @param v value | ||
* | ||
*/ | ||
function setAddress(bytes32 slot, address v) public { | ||
slot.setAddress(v); | ||
} | ||
|
||
/** | ||
* @dev Get uint256[] storage | ||
* @param slot storage slot | ||
* @param k index | ||
* @return v | ||
* | ||
*/ | ||
function getUInt256Array(bytes32 slot, uint256 k) public view returns (uint256) { | ||
uint256[] storage m = slot.getUInt256Array(); | ||
return m[k]; | ||
} | ||
|
||
/** | ||
* @dev Push uint256[] storage | ||
* @param slot storage slot | ||
* @param v value | ||
* | ||
*/ | ||
function pushUInt256Array(bytes32 slot, uint256 v) public { | ||
uint256[] storage m = slot.getUInt256Array(); | ||
m.push(v); | ||
} | ||
|
||
/** | ||
* @dev Get mapping(uint256 => uint256) storage | ||
* @param slot storage slot | ||
* @param k key | ||
* @return v | ||
* | ||
*/ | ||
function getUInt256Mapping(bytes32 slot, uint256 k) public view returns (uint256) { | ||
mapping(uint256 => uint256) storage m = slot.getUInt256Mapping(); | ||
return m[k]; | ||
} | ||
|
||
/** | ||
* @dev Set mapping(uint256 => uint256) storage | ||
* @param slot storage slot | ||
* @param k key | ||
* @param v value | ||
* | ||
*/ | ||
function setUInt256Mapping( | ||
bytes32 slot, | ||
uint256 k, | ||
uint256 v | ||
) public { | ||
mapping(uint256 => uint256) storage m = slot.getUInt256Mapping(); | ||
m[k] = v; | ||
} | ||
} |
Oops, something went wrong.