From 8cf3c06156426099d2504ae63791e56ed421a843 Mon Sep 17 00:00:00 2001 From: koybasimuhittin Date: Sun, 19 Nov 2023 04:28:06 +0300 Subject: [PATCH] add mint script --- packages/hardhat/contracts/HarbergerNft.sol | 7 +- packages/hardhat/contracts/PublicResolver.sol | 2 +- .../hardhat/deploy/00_deploy_your_contract.ts | 11 ---- packages/hardhat/deploy/04_mint_zero_nft.ts | 38 +++++++++++ packages/nextjs/components/Navbar.tsx | 2 +- .../nextjs/contracts/deployedContracts.ts | 4 +- packages/nextjs/pages/me/index.tsx | 66 ++++++++++++------- 7 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 packages/hardhat/deploy/04_mint_zero_nft.ts diff --git a/packages/hardhat/contracts/HarbergerNft.sol b/packages/hardhat/contracts/HarbergerNft.sol index 4b1a6fe..657ce65 100644 --- a/packages/hardhat/contracts/HarbergerNft.sol +++ b/packages/hardhat/contracts/HarbergerNft.sol @@ -5,6 +5,7 @@ import "./solmate/src/auth/Owned.sol"; import "./solmate/src/tokens/ERC721.sol"; import {FixedPointMathLib} from "./solmate/src/utils/FixedPointMathLib.sol"; import {LibBase37} from "./utils/LibBase37.sol"; +import "hardhat/console.sol"; /// @title HarbergerNft /// @author oemerfurkan @@ -49,7 +50,7 @@ contract HarbergerNft is ERC721, Owned { /// @notice whether the contract is paused /// @notice pauses every state changing non-owner function except approve and setApprovalForAll /// @dev can be changed by the contract owner - bool public paused = true; + bool public paused = false; /// @notice token id to its harberger price determined by the token owner mapping(uint256 => uint256) public prices; @@ -185,7 +186,9 @@ contract HarbergerNft is ERC721, Owned { function mintHarberger(uint256 id, uint256 price) external payable notPaused { require(id > 0, "zero id can not be minted"); require(isHarberger(id)); + console.log(isHarberger(id)); uint256 expirationDate = expirationDateAfterMint(price, msg.value); + console.log("expirationDate: %s", expirationDate); require(expirationDate > block.timestamp + minimumPeriod, "Insufficient payment"); expirationDates[id] = expirationDate; @@ -329,6 +332,8 @@ contract HarbergerNft is ERC721, Owned { /// @param payment price paid for mint /// @return expirationDate expiration date after mint function expirationDateAfterMint(uint256 price, uint256 payment) public view returns (uint256 expirationDate) { + console.log("price: %s", payment); + console.log("payment: %s", calculateMintPrice()); uint256 extensionPayment = payment - calculateMintPrice(); uint256 yearlyTax = price.mulDivUp(yearlyTaxBps, MAX_BPS); expirationDate = block.timestamp + extensionPayment.mulDivDown(365 days, yearlyTax); diff --git a/packages/hardhat/contracts/PublicResolver.sol b/packages/hardhat/contracts/PublicResolver.sol index 15e4a69..9e29f4d 100644 --- a/packages/hardhat/contracts/PublicResolver.sol +++ b/packages/hardhat/contracts/PublicResolver.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.17; +pragma solidity ^0.8.17; import {HarbergerNft} from "./HarbergerNft.sol"; import {IPublicResolver} from "./interfaces/IPublicResolver.sol"; diff --git a/packages/hardhat/deploy/00_deploy_your_contract.ts b/packages/hardhat/deploy/00_deploy_your_contract.ts index 418b912..7b41e3a 100644 --- a/packages/hardhat/deploy/00_deploy_your_contract.ts +++ b/packages/hardhat/deploy/00_deploy_your_contract.ts @@ -21,16 +21,6 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn const { deployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; - await deploy("YourContract", { - from: deployer, - // Contract constructor arguments - args: [deployer], - log: true, - // autoMine: can be passed to the deploy function to make the deployment process faster on local networks by - // automatically mining the contract deployment transaction. There is no effect on live networks. - autoMine: true, - }); - // Get the deployed contract // const yourContract = await hre.ethers.getContract("YourContract", deployer); }; @@ -39,4 +29,3 @@ export default deployYourContract; // Tags are useful if you have multiple deploy files and only want to run one of them. // e.g. yarn deploy --tags YourContract -deployYourContract.tags = ["YourContract"]; diff --git a/packages/hardhat/deploy/04_mint_zero_nft.ts b/packages/hardhat/deploy/04_mint_zero_nft.ts new file mode 100644 index 0000000..078dee9 --- /dev/null +++ b/packages/hardhat/deploy/04_mint_zero_nft.ts @@ -0,0 +1,38 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { DeployFunction } from "hardhat-deploy/types"; +import { BigNumber } from "ethers"; + +/** + * Deploys a contract named "YourContract" using the deployer account and + * constructor arguments set to the deployer address + * + * @param hre HardhatRuntimeEnvironment object. + */ +const mintZeroNft: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + /* + On localhost, the deployer account is the one that comes with Hardhat, which is already funded. + + When deploying to live networks (e.g `yarn deploy --network goerli`), the deployer account + should have sufficient balance to pay for the gas fees for contract creation. + + You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY + with a random private key in the .env file (then used on hardhat.config.ts) + You can run the `yarn account` command to check your balance in every network. + */ + const deployer = (await hre.ethers.getSigners())[0]; + + const HarbergerNFT = await hre.ethers.getContract("HarbergerNft", deployer); + try { + const tx = await HarbergerNFT.connect(deployer).mintHarberger(1, 123, { + value: BigNumber.from(await HarbergerNFT.calculateMintPrice()).add(123), + }); + await tx.wait(); + } catch (e) { + console.log(e); + } + + // Get the deployed contract + // const yourContract = await hre.ethers.getContract("YourContract", deployer); +}; + +export default mintZeroNft; diff --git a/packages/nextjs/components/Navbar.tsx b/packages/nextjs/components/Navbar.tsx index db7c9b1..43342d3 100644 --- a/packages/nextjs/components/Navbar.tsx +++ b/packages/nextjs/components/Navbar.tsx @@ -111,7 +111,7 @@ export default function Navbar({ diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index fa8456c..734e531 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -1,7 +1,7 @@ export const deployedContracts = { 31337: { HarbergerNft: { - address: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853", + address: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319", abi: [ { inputs: [ @@ -1206,7 +1206,7 @@ export const deployedContracts = { }, }, PublicResolver: { - address: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6", + address: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F", abi: [ { inputs: [ diff --git a/packages/nextjs/pages/me/index.tsx b/packages/nextjs/pages/me/index.tsx index d992c16..ae0a078 100644 --- a/packages/nextjs/pages/me/index.tsx +++ b/packages/nextjs/pages/me/index.tsx @@ -1,4 +1,4 @@ -import { useState } from "react" +import { useEffect, useState } from "react" import { Command, CommandInput, @@ -6,8 +6,8 @@ import { CommandList, } from "@/components/ui/command" import { useRouter } from "next/router" -import { isBase37, generateFullMeName, base37ToId } from "@/lib/utils" -import { useContractRead, useNetwork } from "wagmi" +import { isBase37, generateFullMeName, base37ToId, cn } from "@/lib/utils" +import { useContractRead } from "wagmi" import { deployedContracts } from "../../contracts/deployedContracts" import { ethers } from "ethers" @@ -15,11 +15,18 @@ export default function Search() { const [isAvailable, setIsAvailable] = useState(false) const [domain, setDomain] = useState("") + const { data, isError, isLoading } = useContractRead({ + address: deployedContracts["31337"].HarbergerNft.address as any, + abi: deployedContracts["31337"].HarbergerNft.abi, + functionName: "ownerOf", + args: [base37ToId(domain).toString()], + }) + const router = useRouter() return ( <> -
+

SEARCH FOR A NAME!

{ setDomain(val) - if (isBase37(val)) { - const { data, isError, isLoading } = useContractRead({ - address: deployedContracts["31337"].HarbergerNft - .address as any, - abi: deployedContracts["31337"].HarbergerNft.abi, - functionName: "ownerOf", - args: [ethers.BigNumber.from(base37ToId(val))], - }) - } }} /> {domain.length > 0 && isBase37(domain) && ( - + { - router.push(`cards/${value}`) + router.push(`/me/cards/${value}`) setDomain("") }} className="text-xl -mt-1" > -
+
{generateFullMeName(domain)} - <> +
+ {isLoading ? ( + + ) : ( +

+ {isError ? "available" : "unavailable"} +

+ )} +
)} - {isAvailable ? null : ( - - )}
)