From ed1dfd302bdfc8d2c324e6dff27680c40f55d9a3 Mon Sep 17 00:00:00 2001 From: JustAnotherDevv Date: Sun, 14 Jul 2024 04:16:27 +0200 Subject: [PATCH] contracts interaction --- packages/hardhat/contracts/BoxManager.sol | 2 +- packages/hardhat/contracts/BoxToken.sol | 4 +- .../hardhat/deploy/00_deploy_your_contract.ts | 11 +- packages/hardhat/hardhat.config.ts | 4 +- packages/nextjs/app/page.tsx | 28 +- packages/nextjs/components/Footer.tsx | 2 + .../nextjs/contracts/deployedContracts.ts | 930 ++++++++++++++++++ packages/nextjs/scaffold.config.ts | 3 +- 8 files changed, 972 insertions(+), 12 deletions(-) diff --git a/packages/hardhat/contracts/BoxManager.sol b/packages/hardhat/contracts/BoxManager.sol index 4728c4c..d04d053 100644 --- a/packages/hardhat/contracts/BoxManager.sol +++ b/packages/hardhat/contracts/BoxManager.sol @@ -42,7 +42,7 @@ contract BoxManager is Ownable { BoxStatus status; } - constructor(address initialOwner, IERC20 _token) Ownable(initialOwner) { + constructor(IERC20 _token) Ownable() { token = _token; } diff --git a/packages/hardhat/contracts/BoxToken.sol b/packages/hardhat/contracts/BoxToken.sol index 436d113..7c97bb9 100644 --- a/packages/hardhat/contracts/BoxToken.sol +++ b/packages/hardhat/contracts/BoxToken.sol @@ -6,9 +6,9 @@ import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; contract BoxToken is ERC20, Ownable, ERC20Permit { - constructor(address initialOwner) + constructor() ERC20("BoxToken", "BOX") - Ownable(initialOwner) + Ownable() ERC20Permit("BoxToken") {} diff --git a/packages/hardhat/deploy/00_deploy_your_contract.ts b/packages/hardhat/deploy/00_deploy_your_contract.ts index 20b06c1..aae521e 100644 --- a/packages/hardhat/deploy/00_deploy_your_contract.ts +++ b/packages/hardhat/deploy/00_deploy_your_contract.ts @@ -34,21 +34,24 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn await deploy("BoxToken", { from: deployer, - args: [deployer], + args: [], log: true, autoMine: true, }); + const boxToken = await hre.ethers.getContract("BoxToken", deployer); + console.log(boxToken.target); + await deploy("BoxManager", { from: deployer, - args: [deployer], + args: [boxToken.target], log: true, autoMine: true, }); // Get the deployed contract to interact with it after deploying. - const yourContract = await hre.ethers.getContract("YourContract", deployer); - console.log("👋 Initial greeting:", await yourContract.greeting()); + // const boxToken = await hre.ethers.getContract("BoxToken", deployer); + // console.log("👋 Initial greeting:", await boxToken.greeting()); }; export default deployYourContract; diff --git a/packages/hardhat/hardhat.config.ts b/packages/hardhat/hardhat.config.ts index 45e74db..50833a6 100644 --- a/packages/hardhat/hardhat.config.ts +++ b/packages/hardhat/hardhat.config.ts @@ -21,7 +21,7 @@ const etherscanApiKey = process.env.ETHERSCAN_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z const config: HardhatUserConfig = { solidity: { - version: "0.8.17", + version: "0.8.20", settings: { optimizer: { enabled: true, @@ -30,7 +30,7 @@ const config: HardhatUserConfig = { }, }, }, - defaultNetwork: "sepolia", + defaultNetwork: "localhost", namedAccounts: { deployer: { // By default, it will take the first Hardhat account as the deployer diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index 5963dbc..87ec70e 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -8,18 +8,42 @@ import { Address } from "~~/components/scaffold-eth"; import { Alert, AlertDescription, AlertTitle } from "~~/components/ui/alert"; import { Button } from "~~/components/ui/button"; import { Card, CardContent } from "~~/components/ui/card"; +import { Badge } from "~~/components/ui/badge"; +import { useReadContract } from "wagmi"; +import {deployedContracts} from "~~/contracts/deployedContracts"; +import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; const Home: NextPage = () => { const { address: connectedAddress } = useAccount(); + const { data: isRegistered } = useScaffoldReadContract({ + contractName: "BoxManager", + functionName: "isBoxRegistered", + args: [BigInt(0)], + }); + + const { data: boxInfo } = useScaffoldReadContract({ + contractName: "BoxManager", + functionName: "boxes", + args: [BigInt(0)], + }); + return ( <>

- Welcome to - The Box + {/* Welcome to + The Box */} + Box.eth + {isRegistered ? ( +
+ {boxInfo?.status} +
+ ) : ""} + {/* EMPTY */} + {/* Available */}

The peer-to-peer delivery service.

diff --git a/packages/nextjs/components/Footer.tsx b/packages/nextjs/components/Footer.tsx index a40f95a..c84f7dd 100644 --- a/packages/nextjs/components/Footer.tsx +++ b/packages/nextjs/components/Footer.tsx @@ -8,6 +8,7 @@ import { BuidlGuidlLogo } from "~~/components/assets/BuidlGuidlLogo"; import { Faucet } from "~~/components/scaffold-eth"; import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; import { useGlobalState } from "~~/services/store/store"; +// import { getTargetNetworks } from "~~/utils/scaffold-eth"; /** * Site footer @@ -20,6 +21,7 @@ export const Footer = () => { return (
+
    diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 9160ed9..dd2e210 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -6,6 +6,936 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; const deployedContracts = { 31337: { + BoxManager: { + address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + abi: [ + { + inputs: [ + { + internalType: "contract IERC20", + name: "_token", + type: "address", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + inputs: [], + name: "DELIVERY_REPORT_DEADLINE", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + name: "boxConfig", + outputs: [ + { + internalType: "uint256", + name: "stakeMin", + type: "uint256", + }, + { + internalType: "uint256", + name: "stakeMax", + type: "uint256", + }, + { + internalType: "uint256", + name: "bountyMin", + type: "uint256", + }, + { + internalType: "uint256", + name: "bountyMax", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + name: "boxes", + outputs: [ + { + internalType: "address", + name: "operator", + type: "address", + }, + { + internalType: "address", + name: "sender", + type: "address", + }, + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "address", + name: "courier", + type: "address", + }, + { + internalType: "uint256", + name: "bounty", + type: "uint256", + }, + { + internalType: "uint256", + name: "stake", + type: "uint256", + }, + { + internalType: "uint256", + name: "pickupTime", + type: "uint256", + }, + { + internalType: "string", + name: "location", + type: "string", + }, + { + internalType: "enum BoxManager.BoxStatus", + name: "status", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "boxId", + type: "uint256", + }, + ], + name: "confirmDelivery", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "courierBlacklist", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "courierRewards", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "courierStakes", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "boxId", + type: "uint256", + }, + ], + name: "isBoxRegistered", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "nextBoxId", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "stakeMin", + type: "uint256", + }, + { + internalType: "uint256", + name: "stakeMax", + type: "uint256", + }, + { + internalType: "uint256", + name: "bountyMin", + type: "uint256", + }, + { + internalType: "uint256", + name: "bountyMax", + type: "uint256", + }, + ], + name: "registerBox", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "boxId", + type: "uint256", + }, + ], + name: "reportDelivery", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "boxId", + type: "uint256", + }, + { + internalType: "string", + name: "location", + type: "string", + }, + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "uint256", + name: "requiredStake", + type: "uint256", + }, + { + internalType: "uint256", + name: "bountyAmount", + type: "uint256", + }, + ], + name: "sendPackage", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "boxId", + type: "uint256", + }, + ], + name: "stake", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "token", + outputs: [ + { + internalType: "contract IERC20", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "boxId", + type: "uint256", + }, + ], + name: "unstake", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "withdrawRewards", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + ], + inheritedFunctions: { + owner: "@openzeppelin/contracts/access/Ownable.sol", + renounceOwnership: "@openzeppelin/contracts/access/Ownable.sol", + transferOwnership: "@openzeppelin/contracts/access/Ownable.sol", + }, + }, + BoxToken: { + address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + abi: [ + { + inputs: [], + stateMutability: "nonpayable", + type: "constructor", + }, + { + inputs: [], + name: "InvalidShortString", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "str", + type: "string", + }, + ], + name: "StringTooLong", + type: "error", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "owner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "spender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Approval", + type: "event", + }, + { + anonymous: false, + inputs: [], + name: "EIP712DomainChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Transfer", + type: "event", + }, + { + inputs: [], + name: "DOMAIN_SEPARATOR", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + ], + name: "allowance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "approve", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "balanceOf", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "decimals", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "subtractedValue", + type: "uint256", + }, + ], + name: "decreaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "eip712Domain", + outputs: [ + { + internalType: "bytes1", + name: "fields", + type: "bytes1", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "version", + type: "string", + }, + { + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + internalType: "address", + name: "verifyingContract", + type: "address", + }, + { + internalType: "bytes32", + name: "salt", + type: "bytes32", + }, + { + internalType: "uint256[]", + name: "extensions", + type: "uint256[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "addedValue", + type: "uint256", + }, + ], + name: "increaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "mint", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "name", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + ], + name: "nonces", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + { + internalType: "uint8", + name: "v", + type: "uint8", + }, + { + internalType: "bytes32", + name: "r", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "s", + type: "bytes32", + }, + ], + name: "permit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "symbol", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "totalSupply", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "from", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "transferFrom", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + ], + inheritedFunctions: { + allowance: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + approve: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + balanceOf: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + decimals: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + decreaseAllowance: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + increaseAllowance: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + name: "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + symbol: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + totalSupply: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + transfer: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + transferFrom: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + owner: "@openzeppelin/contracts/access/Ownable.sol", + renounceOwnership: "@openzeppelin/contracts/access/Ownable.sol", + transferOwnership: "@openzeppelin/contracts/access/Ownable.sol", + DOMAIN_SEPARATOR: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + eip712Domain: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + nonces: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + permit: + "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol", + }, + }, YourContract: { address: "0x5FbDB2315678afecb367f032d93F642f64180aa3", abi: [ diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index b00a22e..d919a4f 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -10,7 +10,8 @@ export type ScaffoldConfig = { const scaffoldConfig = { // The networks on which your DApp is live - targetNetworks: [chains.sepolia], + // targetNetworks: [chains.sepolia], + targetNetworks: [chains.hardhat], // The interval at which your front-end polls the RPC servers for new data // it has no effect if you only target the local network (default is 4000)