Skip to content

Commit f000ed5

Browse files
feat: upgrade to solc 0.6.10 and added GsnCapableDocumentStore (#76)
* feat: upgrade solidity 0.6.10 * feat: added upgradeSafe contracts * feat: added gsn capable document store * fix: using wrong compiler and removed proxy factory test * chore: upgrade solhint and fix lint * chore: updated tsc to not compile node_modules/@types/*.d.ts files * feat: added gsn capable class * feat: added test for new contracts * fix: added addition test from comments * fix: patch bytecode (#77) * fix: bytecode * fix: refactored data * fix: lint Co-authored-by: Raymond Yeh <ray@geek.sg> Co-authored-by: yehjxraymond <yehjxraymond@gmail.com> Co-authored-by: Raymond Yeh <ray@geek.sg>
1 parent eea7846 commit f000ed5

25 files changed

+8489
-1778
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ yarn-error.log
44
.env
55
*.iml
66
.idea
7+
/.vscode
78
/src/contracts
89
/dist
910
/build

.solhint.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"extends": ["solhint:recommended"],
33
"plugins": ["prettier"],
44
"rules": {
5-
"indent": ["error", 2]
5+
"compiler-version": ["error", "^0.6.10"],
6+
"func-name-mixedcase": "off",
7+
"no-empty-blocks": "off",
8+
"reason-string": ["warn", {"maxLength": 256}]
69
}
710
}

contracts/Context.sol

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.6.10;
4+
5+
/*
6+
* @dev Provides information about the current execution context, including the
7+
* sender of the transaction and its data. While these are generally available
8+
* via msg.sender and msg.data, they should not be accessed in such a direct
9+
* manner, since when dealing with GSN meta-transactions the account sending and
10+
* paying for execution may not be the actual sender (as far as an application
11+
* is concerned).
12+
*
13+
* This contract is only required for intermediate, library-like contracts.
14+
*/
15+
contract Context {
16+
function _msgSender() internal view virtual returns (address payable) {
17+
return msg.sender;
18+
}
19+
20+
function _msgData() internal view virtual returns (bytes memory) {
21+
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
22+
return msg.data;
23+
}
24+
}

contracts/ContextUpgradeSafe.sol

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.6.10;
4+
5+
import "./Initializable.sol";
6+
7+
/*
8+
* @dev Provides information about the current execution context, including the
9+
* sender of the transaction and its data. While these are generally available
10+
* via msg.sender and msg.data, they should not be accessed in such a direct
11+
* manner, since when dealing with GSN meta-transactions the account sending and
12+
* paying for execution may not be the actual sender (as far as an application
13+
* is concerned).
14+
*
15+
* This contract is only required for intermediate, library-like contracts.
16+
*/
17+
contract ContextUpgradeSafe is Initializable {
18+
// Empty internal constructor, to prevent people from mistakenly deploying
19+
// an instance of this contract, which should be used via inheritance.
20+
21+
function __Context_init() internal initializer {
22+
__Context_init_unchained();
23+
}
24+
25+
function __Context_init_unchained() internal initializer {}
26+
27+
function _msgSender() internal view virtual returns (address payable) {
28+
return msg.sender;
29+
}
30+
31+
function _msgData() internal view virtual returns (bytes memory) {
32+
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
33+
return msg.data;
34+
}
35+
36+
uint256[50] private __gap;
37+
}

contracts/DocumentStore.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
pragma solidity ^0.5.16;
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
pragma solidity ^0.6.10;
24

35
import "./Ownable.sol";
46

contracts/DocumentStoreCreator.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
pragma solidity 0.5.16;
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
pragma solidity ^0.6.10;
24

35
import "./UpgradableDocumentStore.sol";
46

contracts/DocumentStoreWithRevokeReasons.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
pragma solidity 0.5.16;
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
pragma solidity ^0.6.10;
24

35
import "./UpgradableDocumentStore.sol";
46

contracts/GsnCapable.sol

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
pragma solidity ^0.6.10;
4+
5+
import "./Ownable.sol";
6+
7+
// File: contracts/introspection/IERC165.sol
8+
9+
/*
10+
* @dev Interface of the ERC165 standard, as defined in the
11+
* https://eips.ethereum.org/EIPS/eip-165[EIP].
12+
*
13+
* Implementers can declare support of contract interfaces, which can then be
14+
* queried by others ({ERC165Checker}).
15+
*
16+
* For an implementation, see {ERC165}.
17+
*/
18+
interface IERC165 {
19+
/**
20+
* @dev Returns true if this contract implements the interface defined by
21+
* `interfaceId`. See the corresponding
22+
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
23+
* to learn more about how these ids are created.
24+
*
25+
* This function call must use less than 30 000 gas.
26+
*/
27+
function supportsInterface(bytes4 interfaceId) external view returns (bool);
28+
}
29+
30+
// File: contracts/introspection/ERC165.sol
31+
32+
/**
33+
* @dev Implementation of the {IERC165} interface.
34+
*
35+
* Contracts may inherit from this and call {_registerInterface} to declare
36+
* their support of an interface.
37+
*/
38+
contract ERC165 is IERC165 {
39+
/*
40+
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
41+
*/
42+
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
43+
44+
/**
45+
* @dev Mapping of interface ids to whether or not it's supported.
46+
*/
47+
mapping(bytes4 => bool) private _supportedInterfaces;
48+
49+
constructor() internal {
50+
// Derived contracts need only register support for their own interfaces,
51+
// we register support for ERC165 itself here
52+
_registerInterface(_INTERFACE_ID_ERC165);
53+
}
54+
55+
/**
56+
* @dev See {IERC165-supportsInterface}.
57+
*
58+
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
59+
*/
60+
function supportsInterface(bytes4 interfaceId) external override view returns (bool) {
61+
return _supportedInterfaces[interfaceId];
62+
}
63+
64+
/**
65+
* @dev Registers the contract as an implementer of the interface defined by
66+
* `interfaceId`. Support of the actual ERC165 interface is automatic and
67+
* registering its interface id is not required.
68+
*
69+
* See {IERC165-supportsInterface}.
70+
*
71+
* Requirements:
72+
*
73+
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
74+
*/
75+
function _registerInterface(bytes4 interfaceId) internal {
76+
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
77+
_supportedInterfaces[interfaceId] = true;
78+
}
79+
}
80+
81+
contract GsnCapable is ERC165, Ownable {
82+
address public paymaster;
83+
bytes4 private constant _INTERFACE_ID_GSN_CAPABLE = 0xa5a23640;
84+
85+
event PaymasterSet(address indexed target);
86+
87+
constructor() public {
88+
// register the supported interface to conform to TradeTrustERC721 via ERC165
89+
_registerInterface(_INTERFACE_ID_GSN_CAPABLE);
90+
}
91+
92+
function setPaymaster(address target) external onlyOwner {
93+
paymaster = target;
94+
emit PaymasterSet(target);
95+
}
96+
97+
function getPaymaster() external view returns (address) {
98+
return paymaster;
99+
}
100+
}
101+
102+
contract calculateGsnCapableSelector {
103+
function calculateSelector() public pure returns (bytes4) {
104+
GsnCapable i;
105+
return i.setPaymaster.selector ^ i.getPaymaster.selector;
106+
}
107+
}

contracts/GsnCapableDocumentStore.sol

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
pragma solidity ^0.6.10;
4+
5+
import "./Ownable.sol";
6+
import "./DocumentStore.sol";
7+
import "./GsnCapable.sol";
8+
import "@opengsn/gsn/contracts/BaseRelayRecipient.sol";
9+
import "@opengsn/gsn/contracts/interfaces/IKnowForwarderAddress.sol";
10+
11+
contract GsnCapableDocumentStore is DocumentStore, BaseRelayRecipient, IKnowForwarderAddress, GsnCapable {
12+
constructor(string memory _name, address _forwarder) public DocumentStore(_name) {
13+
trustedForwarder = _forwarder;
14+
}
15+
16+
function _msgSender() internal override(Context, BaseRelayRecipient) view returns (address payable) {
17+
return BaseRelayRecipient._msgSender();
18+
}
19+
20+
function _msgData() internal override(Context, BaseRelayRecipient) view returns (bytes memory) {
21+
return BaseRelayRecipient._msgData();
22+
}
23+
24+
function getTrustedForwarder() public override view returns (address) {
25+
return trustedForwarder;
26+
}
27+
28+
function setTrustedForwarder(address _forwarder) public onlyOwner {
29+
trustedForwarder = _forwarder;
30+
}
31+
32+
function versionRecipient() external virtual override view returns (string memory) {
33+
return version;
34+
}
35+
}

contracts/Initializable.sol

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.6.10;
4+
5+
/**
6+
* @title Initializable
7+
*
8+
* @dev Helper contract to support initializer functions. To use it, replace
9+
* the constructor with a function that has the `initializer` modifier.
10+
* WARNING: Unlike constructors, initializer functions must be manually
11+
* invoked. This applies both to deploying an Initializable contract, as well
12+
* as extending an Initializable contract via inheritance.
13+
* WARNING: When used with inheritance, manual care must be taken to not invoke
14+
* a parent initializer twice, or ensure that all initializers are idempotent,
15+
* because this is not dealt with automatically as with constructors.
16+
*/
17+
contract Initializable {
18+
/**
19+
* @dev Indicates that the contract has been initialized.
20+
*/
21+
bool private initialized;
22+
23+
/**
24+
* @dev Indicates that the contract is in the process of being initialized.
25+
*/
26+
bool private initializing;
27+
28+
/**
29+
* @dev Modifier to use in the initializer function of a contract.
30+
*/
31+
modifier initializer() {
32+
require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized");
33+
34+
bool isTopLevelCall = !initializing;
35+
if (isTopLevelCall) {
36+
initializing = true;
37+
initialized = true;
38+
}
39+
40+
_;
41+
42+
if (isTopLevelCall) {
43+
initializing = false;
44+
}
45+
}
46+
47+
/// @dev Returns true if and only if the function is running in the constructor
48+
function isConstructor() private view returns (bool) {
49+
// extcodesize checks the size of the code stored in an address, and
50+
// address returns the current address. Since the code is still not
51+
// deployed when running a constructor, any checks on its code size will
52+
// yield zero, making it an effective way to detect if a contract is
53+
// under construction or not.
54+
address self = address(this);
55+
uint256 cs;
56+
assembly {
57+
cs := extcodesize(self)
58+
}
59+
return cs == 0;
60+
}
61+
62+
// Reserved storage space to allow for layout changes in the future.
63+
uint256[50] private ______gap;
64+
}

0 commit comments

Comments
 (0)