Skip to content

Commit

Permalink
add mint script
Browse files Browse the repository at this point in the history
  • Loading branch information
koybasimuhittin committed Nov 19, 2023
1 parent 2c08a97 commit 8cf3c06
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 38 deletions.
7 changes: 6 additions & 1 deletion packages/hardhat/contracts/HarbergerNft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/contracts/PublicResolver.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
11 changes: 0 additions & 11 deletions packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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"];
38 changes: 38 additions & 0 deletions packages/hardhat/deploy/04_mint_zero_nft.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion packages/nextjs/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function Navbar({
<button
onClick={openChainModal}
type="button"
className="bg-[#3DB9CF] rounded-md text-white text-md"
className="w-32 h-12 bg-[#3DB9CF] rounded-md text-white text-md"
>
Wrong network
</button>
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const deployedContracts = {
31337: {
HarbergerNft: {
address: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
address: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
abi: [
{
inputs: [
Expand Down Expand Up @@ -1206,7 +1206,7 @@ export const deployedContracts = {
},
},
PublicResolver: {
address: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
address: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
abi: [
{
inputs: [
Expand Down
66 changes: 44 additions & 22 deletions packages/nextjs/pages/me/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import { useState } from "react"
import { useEffect, useState } from "react"
import {
Command,
CommandInput,
CommandItem,
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"

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 (
<>
<div className="w-full h-screen flex flex-col justify-center items-center gap-3">
<div className="w-full h-[800px] flex flex-col justify-center items-center gap-3">
<h1 className="text-4xl">SEARCH FOR A NAME!</h1>
<Command className="md:w-1/2 w-full h-20">
<CommandInput
Expand All @@ -28,40 +35,55 @@ export default function Search() {
value={domain}
onValueChange={(val) => {
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) && (
<CommandList className="">
<CommandList className="h-fit overflow-hidden">
<CommandItem
value={domain}
onSelect={(value) => {
router.push(`cards/${value}`)
router.push(`/me/cards/${value}`)
setDomain("")
}}
className="text-xl -mt-1"
>
<div className="flex justify-between">
<div className="flex justify-between w-full">
{generateFullMeName(domain)}
<></>
<div className="flex items-center justify-center">
{isLoading ? (
<svg
aria-hidden="true"
// eslint-disable-next-line tailwindcss/no-custom-classname
className={`mr-2 inline animate-spin text-gray-600 w-4 h-4`}
viewBox="0 0 100 101"
fill="black"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
) : (
<p
className={cn(
isError ? "text-green-400" : "text-red-400",
"text-md"
)}
>
{isError ? "available" : "unavailable"}
</p>
)}
</div>
</div>
</CommandItem>
</CommandList>
)}
</Command>
{isAvailable ? null : (
<button className="text-[20px] w-[354px] h-[78px] bg-[#3DB9CF] rounded-[10px] text-white">
Marketplace
</button>
)}
</div>
</>
)
Expand Down

0 comments on commit 8cf3c06

Please sign in to comment.