-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new package hyperverse-evm-mintpass #84
base: feat/builderkit
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
distribution | ||
|
||
#Hardhat files | ||
cache | ||
artifacts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# @decentology/hyperverse-ethereum-erc721 | ||
|
||
## 1.0.2 | ||
|
||
### Patch Changes | ||
|
||
- Milestone. Version bump | ||
- Updated dependencies | ||
- @decentology/[email protected] | ||
- @decentology/[email protected] | ||
- @decentology/[email protected] | ||
- @decentology/[email protected] | ||
|
||
## 1.0.1 | ||
|
||
### Patch Changes | ||
|
||
- Milestone update. Added token and er721 modules | ||
- Updated dependencies | ||
- @decentology/[email protected] | ||
- @decentology/[email protected] | ||
- @decentology/[email protected] | ||
- @decentology/[email protected] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Basic Sample Hardhat Project | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. | ||
|
||
Try running some of the following tasks: | ||
|
||
```shell | ||
npx hardhat accounts | ||
npx hardhat compile | ||
npx hardhat clean | ||
npx hardhat test | ||
npx hardhat node | ||
node scripts/sample-script.js | ||
npx hardhat help | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"metis": { | ||
"testnet": { | ||
"contractAddress": "0xACec20ad889Ba58Ec9d65AB0aA7C0e0D151222e0", | ||
"factoryAddress": "0xb38d8C98646C7F07fdc0512e1DB9ee25BfE77F30" | ||
}, | ||
"mainnet": {} | ||
}, | ||
"avalanche": { | ||
"testnet": { | ||
"contractAddress": "0x995d701c0CaAeDA88DBF21727202F3a61AF01177", | ||
"factoryAddress": "0xACec20ad889Ba58Ec9d65AB0aA7C0e0D151222e0" | ||
}, | ||
"mainnet": {} | ||
}, | ||
"ethereum": { | ||
"testnet": { | ||
"contractAddress": "0xe1a3efDbC4Cb1d69013b016cab589D323153E812", | ||
"factoryAddress": "0x9ECA54f6b69B571798DC11FD57a989d437A286B3" | ||
}, | ||
"mainnet": {} | ||
}, | ||
"polygon": { | ||
"testnet": { | ||
"contractAddress": "0x1f6c0449EA114c4A5A542d20801650066Ef8767D", | ||
"factoryAddress": "0x17f32a93376C24b4EFdAaeA72a1173606e7A2d1C" | ||
}, | ||
"mainnet": {} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,90 @@ | ||||||
// SPDX-License-Identifier: MIT | ||||||
|
||||||
pragma solidity ^0.8.0; | ||||||
|
||||||
import './hyperverse/IHyperverseModule.sol'; | ||||||
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | ||||||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||||||
|
||||||
contract MintPass is ERC1155, Ownable, IHyperverseModule { | ||||||
string public _name; | ||||||
string public _symbol; | ||||||
|
||||||
uint256 public tokenCounter; | ||||||
bool public initialized; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can get rid of this initialized variable if we just use a modifier to check reference:
|
||||||
|
||||||
mapping(uint => string) public tokenURI; | ||||||
|
||||||
// Account used to deploy contract | ||||||
address public immutable contractOwner; | ||||||
|
||||||
//stores the tenant owner | ||||||
address private tenantOwner; | ||||||
|
||||||
constructor() ERC1155("ipfs://ipfs/") { | ||||||
contractOwner = msg.sender; | ||||||
|
||||||
metadata = ModuleMetadata( | ||||||
'Token', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs to be changed to MintPass
Suggested change
|
||||||
Author(msg.sender, 'https://externallink.net'), | ||||||
'0.0.1', | ||||||
3479831479814, | ||||||
'https://externalLink.net' | ||||||
); | ||||||
} | ||||||
|
||||||
function init( | ||||||
string memory name_, | ||||||
string memory symbol_, | ||||||
address _tenant | ||||||
) external { | ||||||
require(!initialized, 'Already initialized the state.'); | ||||||
_name = name_; | ||||||
_symbol = symbol_; | ||||||
initialized = true; | ||||||
tenantOwner = _tenant; | ||||||
tokenCounter = 0; | ||||||
} | ||||||
|
||||||
function mint(address _to, uint _id, uint _amount) external { | ||||||
require(msg.sender == tenantOwner, 'Only the Tenant owner can mint an NFT'); | ||||||
_mint(_to, _id, _amount, ""); | ||||||
} | ||||||
|
||||||
function mintBatch(address _to, uint[] memory _ids, uint[] memory _amounts) external { | ||||||
require(msg.sender == tenantOwner, 'Only the Tenant owner can mint an NFT'); | ||||||
_mintBatch(_to, _ids, _amounts, ""); | ||||||
} | ||||||
|
||||||
function burn(uint _id, uint _amount) external { | ||||||
_burn(msg.sender, _id, _amount); | ||||||
} | ||||||
|
||||||
function burnBatch(uint[] memory _ids, uint[] memory _amounts) external { | ||||||
_burnBatch(msg.sender, _ids, _amounts); | ||||||
} | ||||||
|
||||||
function burnForMint(address _from, uint[] memory _burnIds, uint[] memory _burnAmounts, uint[] memory _mintIds, uint[] memory _mintAmounts) external onlyOwner { | ||||||
_burnBatch(_from, _burnIds, _burnAmounts); | ||||||
_mintBatch(_from, _mintIds, _mintAmounts, ""); | ||||||
} | ||||||
|
||||||
function setURI(uint _id, string memory _uri) external { | ||||||
require(msg.sender == tenantOwner, 'Only the Tenant owner can mint an NFT'); | ||||||
tokenURI[_id] = _uri; | ||||||
emit URI(_uri, _id); | ||||||
} | ||||||
|
||||||
function uri(uint _id) public override view returns (string memory) { | ||||||
return tokenURI[_id]; | ||||||
} | ||||||
|
||||||
function name() public view returns (string memory) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can get rid of the name and symbol getters again since name and symbol are public state vars since Solidity creates those getter for us |
||||||
return _name; | ||||||
} | ||||||
|
||||||
function symbol() public view returns (string memory) { | ||||||
return _symbol; | ||||||
} | ||||||
|
||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
// SPDX-License-Identifier: MIT | ||||||
pragma solidity ^0.8.0; | ||||||
pragma experimental ABIEncoderV2; | ||||||
|
||||||
import './hyperverse/CloneFactory.sol'; | ||||||
import './hyperverse/IHyperverseModule.sol'; | ||||||
import './MintPass.sol'; | ||||||
|
||||||
/** | ||||||
* @dev Clone Factory Implementation for ERC20 Token | ||||||
*/ | ||||||
|
||||||
contract MintPassFactory is CloneFactory { | ||||||
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ S T A T E @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets add a tenant counter to keep track of how many tenants we have
|
||||||
struct Tenant { | ||||||
MintPass mintpass; | ||||||
address owner; | ||||||
} | ||||||
|
||||||
mapping(address => Tenant) public tenants; | ||||||
|
||||||
address public immutable masterContract; | ||||||
address private hyperverseAdmin = 0xD847C7408c48b6b6720CCa75eB30a93acbF5163D; | ||||||
|
||||||
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ M O D I F I E R S @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ | ||||||
modifier isOwner(address _tenant) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need this modifier here, but let's add a hasAnInstance modifier and use it in createInstance
|
||||||
require( | ||||||
tenants[_tenant].owner == msg.sender, | ||||||
'The calling address is not an owner of a tenant' | ||||||
); | ||||||
_; | ||||||
} | ||||||
|
||||||
modifier isAllowedToCreateInstance(address _tenant) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's rename this to isAuthorized
Suggested change
|
||||||
require( | ||||||
msg.sender == _tenant || msg.sender == hyperverseAdmin, | ||||||
'Please use a valid address to create an instance' | ||||||
); | ||||||
_; | ||||||
} | ||||||
|
||||||
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ E V E N T S @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets add a TenantCreated Event
Suggested change
and emit it on createInstance |
||||||
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ C O N S T R U C T O R @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ | ||||||
constructor(address _masterContract) { | ||||||
masterContract = _masterContract; | ||||||
} | ||||||
|
||||||
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ F U N C T I O N S @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ | ||||||
|
||||||
function createInstance(string memory name, string memory symbol) external { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
lets keep the convention of using _ for function params |
||||||
address tenant = msg.sender; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we shouldn't set tenant as the msg.sender since we are allowing a hyperverseAdmin to createInstance for others |
||||||
MintPass mintpass = MintPass(createClone(masterContract)); | ||||||
|
||||||
//initializing tenant state of clone | ||||||
mintpass.init(name, symbol, tenant); | ||||||
|
||||||
//set Tenant data | ||||||
Tenant storage newTenant = tenants[tenant]; | ||||||
newTenant.mintpass = mintpass; | ||||||
newTenant.owner = tenant; | ||||||
} | ||||||
|
||||||
function getProxy(address _tenant) public view returns (MintPass) { | ||||||
return tenants[_tenant].mintpass; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/* | ||
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 { | ||
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)))) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
## The Decentology Smart Module standard on Ethereum | ||
## `IHyperverseModule` interface | ||
*/ | ||
|
||
// SPDX-License-Identifier: UNLICENSED | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
abstract contract IHyperverseModule { | ||
ModuleMetadata public metadata; | ||
address private owner; | ||
|
||
struct ModuleMetadata { | ||
bytes title; | ||
Author author; | ||
bytes version; | ||
uint64 publishedAt; | ||
bytes externalLink; | ||
} | ||
|
||
struct Author { | ||
address authorAddress; | ||
string externalLink; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require('dotenv').config(); | ||
require('@nomiclabs/hardhat-waffle'); | ||
|
||
// This is a sample Hardhat task. To learn how to create your own go to | ||
// https://hardhat.org/guides/create-task.html | ||
task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
for (const account of accounts) { | ||
console.log(account.address); | ||
} | ||
}); | ||
|
||
// You need to export an object to set up your config | ||
// Go to https://hardhat.org/config/ to learn more | ||
|
||
/** | ||
* @type import('hardhat/config').HardhatUserConfig | ||
*/ | ||
|
||
const accounts = process.env.NEXT_PRIVATE_KEY !== undefined ? [process.env.NEXT_PRIVATE_KEY] : []; | ||
|
||
module.exports = { | ||
solidity: '0.8.4', | ||
defaultNetwork: 'hardhat', | ||
networks: { | ||
hardhat: {}, | ||
ethereum: { | ||
url: `https://rinkeby.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_API_KEY}`, | ||
accounts, | ||
}, | ||
metis: { | ||
url: 'https://stardust.metis.io/?owner=588', | ||
accounts, | ||
}, | ||
avalanche: { | ||
url: 'https://api.avax-test.network/ext/bc/C/rpc', | ||
accounts, | ||
}, | ||
polygon: { | ||
url: 'https://rpc-mumbai.maticvigil.com', | ||
accounts, | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./source"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since _name and _symbol are public state variables let's remove the _