Skip to content

Commit

Permalink
Added Phygital Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
soumalya340 committed Jan 24, 2024
1 parent c07c8ea commit 4f404a0
Show file tree
Hide file tree
Showing 13 changed files with 1,263 additions and 326 deletions.
48 changes: 24 additions & 24 deletions contracts/phygital/Phygital.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;

mapping(uint256 => bytes16) public nfcId;
mapping(uint256 => bytes16) public phygitalID;

mapping(bytes16 => bool) public nfcCheck;
mapping(bytes16 => bool) public assetStatus;

IACCESSMASTER flowRoles;

Expand Down Expand Up @@ -111,14 +111,12 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
constructor(
string memory name,
string memory symbol,
uint256 _nftPrice,
address tradeHubAddress,
address flowContract
) ERC721(name, symbol) {
flowRoles = IACCESSMASTER(flowContract);
tradeHub = tradeHubAddress;
accessMasterAddress = flowContract;
nftPrice = _nftPrice;
}

/// @notice transferring funds
Expand Down Expand Up @@ -152,16 +150,16 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
function createAsset(
string memory metadataURI,
uint96 royaltyPercentBasisPoint,
bytes16 _nfcId
bytes16 _phygitalID
) public onlyCreator returns (uint256) {
// We cannot just use balanceOf to create the new tokenId because tokens
// can be burned (destroyed), so we need a separate counter.
require(!nfcCheck[_nfcId], "Phygital: NFC Tag is already stored!");
require(!assetStatus[_phygitalID], "Phygital: NFC Tag is already stored!");
Counter++;
uint256 currentTokenID = Counter;

nfcId[currentTokenID] = _nfcId;
nfcCheck[_nfcId] = true;
phygitalID[currentTokenID] = _phygitalID;
assetStatus[_phygitalID] = true;

_safeMint(_msgSender(), currentTokenID);
_setTokenURI(currentTokenID, metadataURI);
Expand Down Expand Up @@ -197,16 +195,16 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {
address creator,
string memory metadataURI,
uint96 royaltyPercentBasisPoint,
bytes16 _nfcId
bytes16 _phygitalID
) public onlyOperator returns (uint256) {
// We cannot just use balanceOf to create the new tokenId because tokens
// can be burned (destroyed), so we need a separate counter.
require(!nfcCheck[_nfcId], "Phygital: NFC Tag is already stored!");
require(!assetStatus[_phygitalID], "Phygital: NFC Tag is already stored!");
Counter++;
uint256 currentTokenID = Counter;

nfcId[currentTokenID] = _nfcId;
nfcCheck[_nfcId] = true;
phygitalID[currentTokenID] = _phygitalID;
assetStatus[_phygitalID] = true;

_safeMint(creator, currentTokenID);
_setTokenURI(currentTokenID, metadataURI);
Expand Down Expand Up @@ -333,18 +331,6 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {

/** Getter Functions **/

/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
require(_exists(tokenId), "Phygital: Non-Existent Asset");
string memory _tokenURI = _tokenURIs[tokenId];

return _tokenURI;
}

/************* Rental(ERC4907) ***************** */
/// @dev IERC4907 implementation
function userOf(uint256 tokenId) public view returns (address) {
Expand All @@ -371,6 +357,20 @@ contract Phygital is Context, ERC721Enumerable, ERC2981, IERC4907 {

/////////////////////////////////////////////////

/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
require(_exists(tokenId), "SignatureSeries: Non-Existent Asset");
string memory _tokenURI = _tokenURIs[tokenId];

return _tokenURI;
}



function _beforeTokenTransfer(
address from,
address to,
Expand Down
13 changes: 6 additions & 7 deletions contracts/phygital/PhygitalA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ contract PhygitalA is

mapping(uint256 => string) private _tokenURIs;

mapping(uint256 => bytes16) public nfcId;
mapping(uint256 => bytes16) public phygitalID;

mapping(bytes16 => bool) public nfcCheck;
mapping(bytes16 => bool) public assetStatus;

// INTERFACES
IACCESSMASTER flowRoles;
Expand Down Expand Up @@ -164,15 +164,14 @@ contract PhygitalA is
return (prevQuantity, quantity);
}


/// @dev to register Asset NFC ID TO the tokenID
function registerAssetId(
uint256 tokenId,
bytes16 _nfcId
bytes16 _phygitalID
) external onlyOperator {
require(!nfcCheck[_nfcId],"PhygitalA: It's already registerd");
nfcId[tokenId] = _nfcId;
nfcCheck[_nfcId] = true;
require(!assetStatus[_phygitalID],"PhygitalA: It's already registerd");
phygitalID[tokenId] = _phygitalID;
assetStatus[_phygitalID] = true;
}

/**
Expand Down
34 changes: 8 additions & 26 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,18 @@ module.exports = {
maticmum: {
networkId: 80001,
url: MATICMUM_RPC_URL,
// accounts: [PRIVATE_KEY],
accounts: {
mnemonic: MNEMONIC,
},
accounts: [PRIVATE_KEY],
// accounts: {
// mnemonic: MNEMONIC,
// },
},
sepolia: {
networkId: 11155111,
url: SEPOLIA_RPC_URL,
// accounts : [PRIVATE_KEY],
accounts: {
mnemonic: MNEMONIC,
},
},

bnbTest :{
networkId: 97,
url: BNB_TESTNET_RPC_URL,
// accounts : [PRIVATE_KEY],
accounts: {
mnemonic: MNEMONIC,
}
accounts : [PRIVATE_KEY],
// accounts: {
// mnemonic: MNEMONIC,
// },
},
arbiGoerli :{
networkId: 421613,
Expand Down Expand Up @@ -164,14 +155,6 @@ module.exports = {
mnemonic: MNEMONIC,
},
},
bnb:{
networkId: 56,
url: BNB_RPC_URL,
// accounts : [PRIVATE_KEY],
accounts: {
mnemonic: MNEMONIC,
}
},
arbitrum :{
networkId: 42161,
url: ARBITRUM_RPC_URL,
Expand Down Expand Up @@ -221,7 +204,6 @@ module.exports = {
apiKey: {
polygonMumbai : POLYGONSCAN_API_KEY,
sepolia : ETHERSCAN_API_KEY,
bscTestnet : BSCSCAN_API_KEY,
optimisticGoerli: OPTISCAN_API_KEY,
arbitrumGoerli: ARBISCAN_API_KEY,
baseGoerli: BASESCAN_API_KEY,
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
"coverage": "hardhat coverage",
"deploy": "hardhat run scripts/deploy.ts --network $NETWORK",
"compile": "hardhat compile",
"launch":"hardhat run scripts/launch/launch.js",
"launchMumbai" : "hardhat run scripts/launch/launch.js --network maticmum",
"launchSepolia" : "hardhat run scripts/launch/launch.js --network sepolia",
"launchBNBTest" : "hardhat run scripts/launch/launch.js --network bnbTest",
"launchFilCalibration" : "hardhat run scripts/launch/launch.js --network filecoinCalibaration",
"launchLineaGoerli" : "hardhat run scripts/launch/launch.js --network lineaGoerli",
"contractAddress" : "hardhat run scripts/contractAddress.js",
"revokeRole" : "hardhat run scripts/revokeRole.js"

"launch": "hardhat run scripts/launch/launch.js",
"launchMumbai": "hardhat run scripts/launch/launch.js --network maticmum",
"launchSepolia": "hardhat run scripts/launch/launch.js --network sepolia",
"launchBNBTest": "hardhat run scripts/launch/launch.js --network bnbTest",
"launchFilCalibration": "hardhat run scripts/launch/launch.js --network filecoinCalibaration",
"launchLineaGoerli": "hardhat run scripts/launch/launch.js --network lineaGoerli",
"contractAddress": "hardhat run scripts/contractAddress.js",
"revokeRole": "hardhat run scripts/revokeRole.js"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.4",
Expand Down
31 changes: 31 additions & 0 deletions scripts/launch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,37 @@ The JSON file should have the following format:
}
```

`Phygital`

```shell
{
"contractName" : "Phygital",
"constructorParams":{
"param1": "Alice Clothing",
"param2" : "AC",
"param3" : "0x3A29EA5Ee6AB0326D72b55837dD9fD45b7a867Dd", - TradeHub
"param4" : "0xc3fE1c3bCCE02d7A115Df2d4737137A15ff830F9" - AccessMaster
}
}
```
`PhygitalA`

```shell
{
"contractName" : "PhygitalA",
"constructorParams":{
"param1": "Alice Clothing",
"param2" : "AC",
"param3" : "0x3A29EA5Ee6AB0326D72b55837dD9fD45b7a867Dd" , //tradehub
"param4" : "0xc3fE1c3bCCE02d7A115Df2d4737137A15ff830F9", // accessmaster
"param5" : 200, // maxsupply
"param6" : 300, // royalty
"param7" : "www.xyz.com"
}
}
```


`FlowSubscription Contract`

```shell
Expand Down
65 changes: 64 additions & 1 deletion scripts/launch/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,62 @@ async function eternalSoulDeploy() {
}
}

async function phygitalDeploy() {
const constructorParam = jsonContent.constructorParams
const Phygital = await hre.ethers.getContractFactory("Phygital")
const phygital = await Phygital.deploy(
constructorParam.param1,
constructorParam.param2,
constructorParam.param3,
constructorParam.param4
)
await phygital.deployed()
console.log("Phygital Deployed to:", phygital.address)
contractAddress = phygital.address
blockNumber = phygital.provider._maxInternalBlockNumber
/// VERIFY
if (hre.network.name != "hardhat") {
await phygital.deployTransaction.wait(6)
await verify(phygital.address, [
constructorParam.param1,
constructorParam.param2,
constructorParam.param3,
constructorParam.param4,
])
}
}

async function phygitalADeploy() {
const constructorParam = jsonContent.constructorParams
const PhygitalA = await hre.ethers.getContractFactory("PhygitalA")
const phygitala = await PhygitalA.deploy(
constructorParam.param1,
constructorParam.param2,
constructorParam.param3,
constructorParam.param4,
constructorParam.param5,
constructorParam.param6,
constructorParam.param7
)
await phygitala.deployed()
console.log("PhygitalA Deployed to:", phygitala.address)
contractAddress = phygitala.address
blockNumber = phygitala.provider._maxInternalBlockNumber
/// VERIFY
if (hre.network.name != "hardhat") {
await phygitala.deployTransaction.wait(6)
await verify(phygitala.address, [
constructorParam.param1,
constructorParam.param2,
constructorParam.param3,
constructorParam.param4,
constructorParam.param5,
constructorParam.param6,
constructorParam.param7,
])
}
}

async function flowSubscriptionDeploy() {
const constructorParam = jsonContent.constructorParams
const FlowSubscription = await hre.ethers.getContractFactory(
Expand Down Expand Up @@ -321,7 +377,14 @@ async function main() {
if (jsonContent.contractName == "EternalSoul") {
await eternalSoulDeploy()
}

//PHGITAL CONTRACT
if (jsonContent.contractName == "Phygital") {
await phygitalDeploy()
}
//PHYGITALA CONTRACT
if (jsonContent.contractName == "PhygitalA") {
await phygitalADeploy()
}
// FLOWSUBSCRIPTION
if (jsonContent.contractName == "FlowSubscription") {
await flowSubscriptionDeploy()
Expand Down
10 changes: 8 additions & 2 deletions scripts/launch/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"contractName" : "AccessMaster",
"contractName" : "PhygitalA",
"constructorParams":{
"param1" : "0x83AD8ddAdb013fbA80DE0d802FD4fB1a949AD79f"
"param1": "Alice Clothing",
"param2" : "AC",
"param3" : "0x3A29EA5Ee6AB0326D72b55837dD9fD45b7a867Dd" ,
"param4" : "0xc3fE1c3bCCE02d7A115Df2d4737137A15ff830F9",
"param5" : 200,
"param6" : 300,
"param7" : "www.xyz.com"
}
}
Loading

0 comments on commit 4f404a0

Please sign in to comment.