Skip to content

Commit

Permalink
fix: init issue (#112)
Browse files Browse the repository at this point in the history
* fix: init issue

* fix: missing hardhat waffle

* chore: fix linter

* chore: update solhint compiler version
  • Loading branch information
superical authored Aug 8, 2022
1 parent 85635c6 commit 3edf13c
Show file tree
Hide file tree
Showing 17 changed files with 1,122 additions and 4,874 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"env": {
"jest": true
Expand Down
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": ["solhint:recommended"],
"plugins": ["prettier"],
"rules": {
"compiler-version": ["error", "^0.6.10"],
"compiler-version": ["error", "^0.8.0"],
"func-name-mixedcase": "off",
"no-empty-blocks": "off",
"reason-string": ["warn", { "maxLength": 256 }]
Expand Down
2 changes: 2 additions & 0 deletions benchmark/GasCostBenchmark.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */

const { ethers } = require("hardhat");
const { groupBy, mapValues } = require("lodash");
const { generateHashes } = require("../scripts/generateHashes");
Expand Down
6 changes: 3 additions & 3 deletions contracts/BaseDocumentStore.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract BaseDocumentStore is Initializable {
string public name;
Expand All @@ -17,7 +17,7 @@ contract BaseDocumentStore is Initializable {
event DocumentIssued(bytes32 indexed document);
event DocumentRevoked(bytes32 indexed document);

function initialize(string memory _name) public initializer {
function initialize(string memory _name) internal onlyInitializing {
version = "2.3.0";
name = _name;
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/DocumentStore.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

Expand All @@ -19,7 +19,7 @@ contract DocumentStore is Ownable {
event DocumentIssued(bytes32 indexed document);
event DocumentRevoked(bytes32 indexed document);

constructor(string memory _name) public {
constructor(string memory _name) {
name = _name;
}

Expand Down
5 changes: 2 additions & 3 deletions contracts/DocumentStoreCreator.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "./UpgradableDocumentStore.sol";

Expand All @@ -12,8 +12,7 @@ contract DocumentStoreCreator {

function deploy(string memory name) public returns (address) {
// solhint-disable-next-line mark-callable-contracts
UpgradableDocumentStore instance = new UpgradableDocumentStore();
instance.initialize(name, msg.sender);
UpgradableDocumentStore instance = new UpgradableDocumentStore(name, msg.sender);
emit DocumentStoreDeployed(address(instance), msg.sender);
return address(instance);
}
Expand Down
4 changes: 3 additions & 1 deletion contracts/DocumentStoreWithRevokeReasons.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "./UpgradableDocumentStore.sol";

Expand All @@ -10,6 +10,8 @@ contract DocumentStoreWithRevokeReasons is UpgradableDocumentStore {

event DocumentRevokedWithReason(bytes32 indexed document, uint256 reason);

constructor(string memory _name, address owner) UpgradableDocumentStore(_name, owner) {}

function revoke(bytes32 document, uint256 reason) public onlyOwner onlyNotRevoked(document) returns (bool) {
revoke(document);
revokeReason[document] = reason;
Expand Down
8 changes: 4 additions & 4 deletions contracts/GsnCapable.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";

contract GsnCapable is ERC165, Ownable {
contract GsnCapable is ERC165Storage, Ownable {
address public paymaster;
bytes4 private constant _INTERFACE_ID_GSN_CAPABLE = 0xa5a23640;

event PaymasterSet(address indexed target);

constructor() public {
constructor() {
// register the supported interface to conform to TradeTrustERC721 via ERC165
_registerInterface(_INTERFACE_ID_GSN_CAPABLE);
}
Expand Down
16 changes: 8 additions & 8 deletions contracts/GsnCapableDocumentStore.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "@opengsn/gsn/contracts/BaseRelayRecipient.sol";
import "@opengsn/gsn/contracts/interfaces/IKnowForwarderAddress.sol";
import "@opengsn/contracts/src/BaseRelayRecipient.sol";

import "./OwnableDocumentStore.sol";
import "./GsnCapable.sol";
import "../interfaces/IKnowForwarderAddress.sol";

contract GsnCapableDocumentStore is OwnableDocumentStore, BaseRelayRecipient, IKnowForwarderAddress, GsnCapable {
string public override versionRecipient = "2.0.0";

constructor(string memory _name, address _forwarder) public OwnableDocumentStore(_name) {
trustedForwarder = _forwarder;
constructor(string memory _name, address _forwarder) OwnableDocumentStore(_name) {
_setTrustedForwarder(_forwarder);
}

function _msgSender() internal view override(Context, BaseRelayRecipient) returns (address payable) {
function _msgSender() internal view override(Context, BaseRelayRecipient) returns (address) {
return BaseRelayRecipient._msgSender();
}

Expand All @@ -24,10 +24,10 @@ contract GsnCapableDocumentStore is OwnableDocumentStore, BaseRelayRecipient, IK
}

function getTrustedForwarder() public view override returns (address) {
return trustedForwarder;
return trustedForwarder();
}

function setTrustedForwarder(address _forwarder) public onlyOwner {
trustedForwarder = _forwarder;
_setTrustedForwarder(_forwarder);
}
}
12 changes: 6 additions & 6 deletions contracts/NaivePaymaster.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;

import "@opengsn/gsn/contracts/forwarder/IForwarder.sol";
import "@opengsn/gsn/contracts/BasePaymaster.sol";
import "@opengsn/contracts/src/forwarder/IForwarder.sol";
import "@opengsn/contracts/src/BasePaymaster.sol";

/**
* @dev Implementation of the {BasePaymaster} interface.
Expand All @@ -23,7 +23,7 @@ contract NaivePaymaster is BasePaymaster {
*/
mapping(address => bool) private targetAddresses;

constructor(string memory _name) public {
constructor(string memory _name) {
name = _name;
}

Expand Down Expand Up @@ -68,8 +68,8 @@ contract NaivePaymaster is BasePaymaster {

// check if relayed request is to a accepted address
require(targetAddresses[relayRequest.request.to]);
emit PreRelayed(now);
return (abi.encode(now), false);
emit PreRelayed(block.timestamp);
return (abi.encode(block.timestamp), false);
}

function postRelayedCall(
Expand Down
5 changes: 2 additions & 3 deletions contracts/OwnableDocumentStore.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

import "./BaseDocumentStore.sol";

contract OwnableDocumentStore is BaseDocumentStore, Ownable {
constructor(string memory _name) public {
constructor(string memory _name) initializer {
BaseDocumentStore.initialize(_name);
}

Expand Down
10 changes: 7 additions & 3 deletions contracts/UpgradableDocumentStore.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import "./BaseDocumentStore.sol";

contract UpgradableDocumentStore is BaseDocumentStore, OwnableUpgradeable {
function initialize(string memory _name, address owner) public initializer {
constructor(string memory _name, address owner) {
initialize(_name, owner);
}

function initialize(string memory _name, address owner) internal initializer {
super.__Ownable_init();
super.transferOwnership(owner);
BaseDocumentStore.initialize(_name);
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ConfigurableTrustForwarder.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.6.10;
pragma solidity ^0.8.0;

contract ConfigurableTrustForwarder {
function execute(
Expand Down
5 changes: 3 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable import/no-extraneous-dependencies */

require("@nomiclabs/hardhat-waffle");
require("hardhat-typechain");
require("@openzeppelin/hardhat-upgrades");

/**
* @type import('hardhat/config').HardhatUserConfig
*/

module.exports = {
solidity: {
version: "0.6.10",
version: "0.8.2",
settings: {
optimizer: {
enabled: true,
Expand Down
16 changes: 16 additions & 0 deletions interfaces/IKnowForwarderAddress.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;

/**
* Interface carried over from OpenGSN v2.1.0
* https://github.com/opengsn/gsn/blob/v2.1.0/contracts/interfaces/IKnowForwarderAddress.sol[Original Source]
*/
interface IKnowForwarderAddress {

/**
* return the forwarder we trust to forward relayed transactions to us.
* the forwarder is required to verify the sender's signature, and verify
* the call is not a replay.
*/
function getTrustedForwarder() external view returns(address);
}
Loading

0 comments on commit 3edf13c

Please sign in to comment.