Skip to content

Commit

Permalink
Merge pull request #8 from citydaoproject/mnorman-issue1
Browse files Browse the repository at this point in the history
Added etherscan verification
  • Loading branch information
Slyracoon23 authored May 7, 2022
2 parents 8aed707 + ec19fc9 commit 646dc8f
Show file tree
Hide file tree
Showing 21 changed files with 428 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
uses: actions/checkout@v3
- name: Install dependencies
run: npm ci
- name: Prepare CI
run: npm run ci-prepare
- name: Build
run: npm run build
- name: Test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/types
/artifacts
/cache
.secrets.json


################################################################################
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,37 @@ npm test
```
npm run build
```
## Verification
Set up a `.secrets.json` file that looks similar to `example.secrets.json`:
After deploying your contract, you can verify it by running the following.
### Rinkeby
```
npx hardhat verify --network rinkeby CONTRACT_ADDRESS
```
For a proxy contract, you'll need to pass the arguments to the proxy contract, and pass the contract as well:
```
npx hardhat verify --network rinkeby \
--contract contracts/common/UpgradeableProxy.sol:UpgradeableProxy \
--constructor-args examples/parcelNFTConstructorParams.js \
CONTRACT_ADDRESS
```
### Mainnet
```
npx hardhat verify --network rinkeby CONTRACT_ADDRESS
```
```
npx hardhat verify --network mainnet \
--contract contracts/common/UpgradeableProxy.sol:UpgradeableProxy \
--constructor-args examples/parcelNFTConstructorParams.js \
CONTRACT_ADDRESS
```
See [hardhat-etherscan](https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html) for more examples
44 changes: 36 additions & 8 deletions contracts/ParcelNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ pragma solidity ^0.8.9;
import '@gnus.ai/contracts-upgradeable-diamond/access/AccessControlUpgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/proxy/utils/UUPSUpgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/security/PausableUpgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/token/ERC721/extensions/ERC721RoyaltyUpgradeable.sol';
import './ParcelNFTStorage.sol';
import '@gnus.ai/contracts-upgradeable-diamond/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol';
import './common/RoyaltyEventSupport.sol';
import './common/TokenUriStorage.sol';
import './Roles.sol';

contract ParcelNFT is
UUPSUpgradeable,
ERC721EnumerableUpgradeable,
ERC721URIStorageUpgradeable,
RoyaltyEventSupport,
ERC721RoyaltyUpgradeable,
Expand All @@ -27,6 +29,7 @@ contract ParcelNFT is

function initialize(InitParams memory initParams) public initializer {
__ERC721_init(initParams.name, initParams.symbol);
__ERC721Enumerable_init_unchained();
__ERC721URIStorage_init_unchained();
__ERC2981_init_unchained();
__ERC721Royalty_init_unchained();
Expand All @@ -48,21 +51,34 @@ contract ParcelNFT is
public
view
virtual
override(AccessControlUpgradeable, ERC721RoyaltyUpgradeable, ERC721Upgradeable, ERC2981Upgradeable)
override(
AccessControlUpgradeable,
ERC721EnumerableUpgradeable,
ERC721RoyaltyUpgradeable,
ERC721Upgradeable,
ERC2981Upgradeable
)
returns (bool)
{
return super.supportsInterface(interfaceId);
}

/**
* @notice Sets `baseURI` as the base URI for all tokens. Used when explicit tokenURI not set.
* @notice Gets base URI for all tokens, if set.
*/
function setBaseURI(string calldata baseURI) external onlyRole(Roles.PARCEL_MANAGER) {
ParcelNFTStorage.setBaseURI(baseURI);
function baseURI() public view returns (string memory) {
return _baseURI();
}

function _baseURI() internal view virtual override returns (string memory) {
return ParcelNFTStorage.baseURI();
return TokenUriStorage.baseURI();
}

/**
* @notice Sets `baseURI` as the base URI for all tokens. Used when explicit tokenURI not set.
*/
function setBaseURI(string calldata __baseURI) external onlyRole(Roles.PARCEL_MANAGER) {
TokenUriStorage.setBaseURI(__baseURI);
}

/**
Expand Down Expand Up @@ -190,10 +206,22 @@ contract ParcelNFT is
_unpause();
}

function _burn(uint256 tokenId) internal virtual override(ERC721URIStorageUpgradeable, ERC721RoyaltyUpgradeable) {
function _burn(uint256 tokenId)
internal
virtual
override(ERC721URIStorageUpgradeable, ERC721RoyaltyUpgradeable, ERC721Upgradeable)
{
super._burn(tokenId);
}

function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override(ERC721EnumerableUpgradeable, ERC721Upgradeable) {
super._beforeTokenTransfer(from, to, tokenId);
}

// solhint-disable-next-line no-empty-blocks
function _authorizeUpgrade(address newImplementation) internal virtual override onlyRole(Roles.UPGRADER) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

pragma solidity ^0.8.9;

library ParcelNFTStorage {
library TokenUriStorage {
struct Layout {
// storage for base URI
string baseURI;
}

bytes32 internal constant STORAGE_SLOT = keccak256('citydao.contracts.storage.ParcelNFT');
bytes32 internal constant STORAGE_SLOT = keccak256('citydao.contracts.storage.TokenUri');

//noinspection NoReturn
function layout() internal pure returns (Layout storage _layout) {
Expand Down
11 changes: 11 additions & 0 deletions contracts/common/UpgradeableProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.9;

import '@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol';

// needed to be able to use the proxy for verification
contract UpgradeableProxy is ERC1967Proxy {
// solhint-disable-next-line no-empty-blocks
constructor(address _logic, bytes memory _data) payable ERC1967Proxy(_logic, _data) {}
}
5 changes: 5 additions & 0 deletions contracts/test/ERC165IdCalc.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.9;
import '@gnus.ai/contracts-upgradeable-diamond/access/IAccessControlUpgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/interfaces/IERC2981Upgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/token/ERC721/IERC721Upgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/token/ERC721/extensions/IERC721EnumerableUpgradeable.sol';
import '@gnus.ai/contracts-upgradeable-diamond/token/ERC721/extensions/IERC721MetadataUpgradeable.sol';

library ERC165IdCalc {
Expand All @@ -20,6 +21,10 @@ library ERC165IdCalc {
return type(IERC721Upgradeable).interfaceId;
}

function calcERC721EnumerableInterfaceId() external pure returns (bytes4) {
return type(IERC721EnumerableUpgradeable).interfaceId;
}

function calcERC721MetadataInterfaceId() external pure returns (bytes4) {
return type(IERC721MetadataUpgradeable).interfaceId;
}
Expand Down
8 changes: 8 additions & 0 deletions example.secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"networks": {
"rinkeby": {
"url": "https://rinkeby.infura.io/v3/YOUR_PROJECT_ID"
}
},
"etherscanApiKey": "YOUR_API_KEY"
}
8 changes: 8 additions & 0 deletions examples/parcelNFTConstructorParams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { buildParcelNFTInitFunction } = require('../dist/src/contracts/parcelNFT');
module.exports = [
'0xc0cA359c8ce6De21B98fC6c7921a08703f453Fe9',
buildParcelNFTInitFunction({
name: 'ParcelNFT Test 2022-05-07-02',
symbol: 'PT050702',
}),
];
8 changes: 8 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-etherscan';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat';
import { HardhatUserConfig } from 'hardhat/config';
import { etherscanApiKey, networks } from './.secrets.json';

const hardhatConfig: HardhatUserConfig = {
solidity: {
Expand All @@ -19,6 +21,12 @@ const hardhatConfig: HardhatUserConfig = {
outDir: 'types/contracts',
target: 'ethers-v5',
},

networks,

etherscan: {
apiKey: etherscanApiKey,
},
};

export default hardhatConfig;
Loading

0 comments on commit 646dc8f

Please sign in to comment.