Skip to content

Commit

Permalink
chore: Add HeyPro contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Mar 2, 2025
1 parent 9705c14 commit 067a18d
Show file tree
Hide file tree
Showing 10 changed files with 6,197 additions and 116 deletions.
1 change: 1 addition & 0 deletions packages/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRIVATE_KEY=""
3 changes: 3 additions & 0 deletions packages/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cache-zk/
artifacts-zk/
typechain-types/
65 changes: 65 additions & 0 deletions packages/contracts/contracts/HeyPro.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract HeyPro is ERC721Enumerable, Ownable {
struct NFTData {
uint256 expiry;
string name;
}

mapping(uint256 => NFTData) public nftDetails;

constructor() ERC721("HeyPro", "PRO") Ownable(msg.sender) {}

function mint() external {
uint256 tokenId = totalSupply() + 1;
uint256 currentTime = block.timestamp;
uint256 expiry = currentTime + 30 days;

// NFT name derived from epoch timestamp (10 chars)
string memory nftName = _uintToString(currentTime);

_safeMint(msg.sender, tokenId);
nftDetails[tokenId] = NFTData(expiry, nftName);
}

function extendSubscription() external {
uint256 lastTokenId = balanceOf(msg.sender);
require(lastTokenId > 0, "You don't own any NFTs");

uint256 tokenId = tokenOfOwnerByIndex(msg.sender, lastTokenId - 1);
require(
nftDetails[tokenId].expiry > block.timestamp,
"Subscription expired"
);

// Extend by 30 days
nftDetails[tokenId].expiry += 30 days;
}

function getNFTDetails(
uint256 tokenId
) external view returns (string memory, uint256) {
require(_isValidToken(tokenId), "Token does not exist");
return (nftDetails[tokenId].name, nftDetails[tokenId].expiry);
}

function _uintToString(
uint256 value
) internal pure returns (string memory) {
bytes memory buffer = new bytes(10);
for (uint256 i = 9; i >= 0; i--) {
buffer[i] = bytes1(uint8(48 + (value % 10)));
value /= 10;
if (value == 0) break;
}
return string(buffer);
}

function _isValidToken(uint256 tokenId) internal view returns (bool) {
return tokenId > 0 && tokenId <= totalSupply();
}
}
19 changes: 19 additions & 0 deletions packages/contracts/deploy/heypro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Deployer } from "@matterlabs/hardhat-zksync";
import type { HardhatRuntimeEnvironment } from "hardhat/types";
import { Wallet } from "zksync-ethers";

export default async function (hre: HardhatRuntimeEnvironment) {
try {
// Initialize the wallet.
const wallet = new Wallet(process.env.PRIVATE_KEY as string);
const deployer = new Deployer(hre, wallet as any);
const artifact = await deployer.loadArtifact("HeyPro");
const heyProContract = await deployer.deploy(artifact);
console.log(
`${artifact.contractName} was deployed to ${await heyProContract.getAddress()}`
);
} catch (error) {
console.error("Error in deployment:", error);
process.exit(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x90f7
Loading

0 comments on commit 067a18d

Please sign in to comment.