Skip to content

Commit 0778480

Browse files
Remove package-lock.json, update dependencies in package.json, and add new EAS contracts and related configurations. Refactor marketplace components and enhance review functionalities in the Next.js app. Clean up unused block explorer components and improve IPFS handling.
1 parent 9c182f3 commit 0778480

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+7935
-31650
lines changed

package-lock.json

Lines changed: 0 additions & 30058 deletions
This file was deleted.

packages/hardhat/contracts/IListingType.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface IListingType {
1212
function onSale(uint256 listingId, address buyer, bytes calldata data) external payable returns (bool);
1313
function afterSale(uint256 listingId, address buyer, bytes calldata data) external returns (bool);
1414

15-
// Pre-buy lifecycle (e.g., escrow setup)
15+
// Pre-buy lifecycle (e.g., escrow setup, pre-payment, auction mechanism etc.)
1616
function beforePreBuy(uint256 listingId, address buyer, bytes calldata data) external returns (bool);
1717
function onPreBuy(uint256 listingId, address buyer, bytes calldata data) external payable returns (bool);
1818
function afterPreBuy(uint256 listingId, address buyer, bytes calldata data) external returns (bool);

packages/hardhat/contracts/SimpleListings.sol

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
pragma solidity >=0.8.0 <0.9.0;
33

44
import { IListingType } from "./IListingType.sol";
5-
6-
interface IERC20 {
7-
function transfer(address to, uint256 value) external returns (bool);
8-
function transferFrom(address from, address to, uint256 value) external returns (bool);
9-
}
5+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
106

117
contract SimpleListings is IListingType {
128
// Custom errors
@@ -192,12 +188,4 @@ contract SimpleListings is IListingType {
192188
emit SimpleListingClosed(listingId, caller);
193189
return true;
194190
}
195-
196-
// Backward compatibility
197-
function closeListing(uint256 listingId, address caller) external onlyMarketplace returns (bool) {
198-
if (!this.beforeClose(listingId, caller, "")) revert BeforeCloseFailed();
199-
if (!this.onClose(listingId, caller, "")) revert OnCloseFailed();
200-
if (!this.afterClose(listingId, caller, "")) revert AfterCloseFailed();
201-
return true;
202-
}
203191
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5+
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
6+
7+
/**
8+
* @title TestERC20
9+
* @notice Simple ERC20 with configurable name, symbol and decimals at deploy time.
10+
* Ownership is set to the provided `initialOwner` so minting can be controlled in tests/local.
11+
*/
12+
contract TestERC20 is ERC20, Ownable {
13+
uint8 private immutable _customDecimals;
14+
15+
constructor(
16+
string memory name_,
17+
string memory symbol_,
18+
uint8 decimals_,
19+
address initialOwner
20+
) ERC20(name_, symbol_) Ownable(initialOwner) {
21+
_customDecimals = decimals_;
22+
}
23+
24+
function decimals() public view override returns (uint8) {
25+
return _customDecimals;
26+
}
27+
28+
function mint(address to, uint256 amount) external onlyOwner {
29+
_mint(to, amount);
30+
}
31+
}
32+
33+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
5+
// Only deploy on localhost/hardhat for development convenience
6+
const networkName = hre.network.name;
7+
if (networkName !== "localhost" && networkName !== "hardhat") {
8+
console.log("Skipping TestERC20 deploy on network:", networkName);
9+
return;
10+
}
11+
12+
const OWNER = "0xe1CE8616c669Cd3F1EC4598cef01B89331e7D849";
13+
const { deployer } = await hre.getNamedAccounts();
14+
const { deploy, get, log } = hre.deployments;
15+
16+
// Token A: 2 decimals
17+
const name2 = process.env.TEST_ERC20_2_NAME ?? "Test Token 2d";
18+
const symbol2 = process.env.TEST_ERC20_2_SYMBOL ?? "TT2";
19+
const decimals2 = 2;
20+
21+
await deploy("TestERC20_2dec", {
22+
contract: "TestERC20",
23+
from: deployer,
24+
args: [name2, symbol2, decimals2, OWNER],
25+
log: true,
26+
autoMine: true,
27+
});
28+
29+
const token2 = await get("TestERC20_2dec");
30+
log(`TestERC20_2dec deployed at ${token2.address} (name=${name2}, symbol=${symbol2}, decimals=${decimals2})`);
31+
32+
// Token B: 6 decimals
33+
const name6 = process.env.TEST_ERC20_6_NAME ?? "Test Token 6d";
34+
const symbol6 = process.env.TEST_ERC20_6_SYMBOL ?? "TT6";
35+
const decimals6 = 6;
36+
37+
await deploy("TestERC20_6dec", {
38+
contract: "TestERC20",
39+
from: deployer,
40+
args: [name6, symbol6, decimals6, OWNER],
41+
log: true,
42+
autoMine: true,
43+
});
44+
45+
const token6 = await get("TestERC20_6dec");
46+
log(`TestERC20_6dec deployed at ${token6.address} (name=${name6}, symbol=${symbol6}, decimals=${decimals6})`);
47+
};
48+
49+
export default func;
50+
func.tags = ["TestERC20"];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import schemaRegistryArtifact from "@ethereum-attestation-service/eas-contracts/artifacts/contracts/SchemaRegistry.sol/SchemaRegistry.json";
4+
import easArtifact from "@ethereum-attestation-service/eas-contracts/artifacts/contracts/EAS.sol/EAS.json";
5+
6+
// Deploy EAS core contracts locally (SchemaRegistry and EAS) using artifacts from the npm package
7+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
8+
const { deployer } = await hre.getNamedAccounts();
9+
const { deploy } = hre.deployments;
10+
11+
// Load artifacts from installed package (json imports)
12+
if (hre.network.name != "localhost") {
13+
return;
14+
}
15+
16+
const schemaRegistry = await deploy("SchemaRegistry", {
17+
from: deployer,
18+
log: true,
19+
autoMine: true,
20+
args: [],
21+
contract: {
22+
abi: schemaRegistryArtifact.abi,
23+
bytecode: schemaRegistryArtifact.bytecode,
24+
},
25+
});
26+
27+
await deploy("EAS", {
28+
from: deployer,
29+
log: true,
30+
autoMine: true,
31+
args: [schemaRegistry.address],
32+
contract: {
33+
abi: easArtifact.abi,
34+
bytecode: easArtifact.bytecode,
35+
},
36+
});
37+
};
38+
39+
export default func;
40+
func.tags = ["EASLocal", "ReviewSchema"];
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import * as fs from "fs";
4+
import * as path from "path";
5+
import schemaRegArtifact from "@ethereum-attestation-service/eas-contracts/artifacts/contracts/SchemaRegistry.sol/SchemaRegistry.json";
6+
7+
// Registers a local review schema on the deployed SchemaRegistry and logs the schema UID
8+
// Schema: uint8 rating,string comment
9+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
10+
const { deployer } = await hre.getNamedAccounts();
11+
12+
const chainId = await hre.getChainId();
13+
const KNOWN_SCHEMA_REGISTRY: Record<string, string> = {
14+
// Mainnets
15+
"1": "0xA7b39296258348C78294F95B872b282326A97BDF", // Ethereum mainnet
16+
"10": "0x4200000000000000000000000000000000000020", // Optimism
17+
"8453": "0x4200000000000000000000000000000000000020", // Base
18+
"42161": "0xA310da9c5B885E7fb3fbA9D66E9Ba6Df512b78eB", // Arbitrum One
19+
// Testnets
20+
"11155111": "0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0", // Sepolia
21+
"11155420": "0x4200000000000000000000000000000000000020", // Optimism Sepolia
22+
"84532": "0x4200000000000000000000000000000000000020", // Base Sepolia
23+
"420": "0x4200000000000000000000000000000000000020", // Optimism Goerli
24+
};
25+
26+
const KNOWN_EAS: Record<string, string> = {
27+
// Mainnets
28+
"1": "0xA1207F3BBa224E2c9c3c6D5aF63D0eb1582Ce587", // Ethereum mainnet
29+
"10": "0x4200000000000000000000000000000000000021", // Optimism
30+
"8453": "0x4200000000000000000000000000000000000021", // Base
31+
"42161": "0xbD75f629A22Dc1ceD33dDA0b68c546A1c035c458", // Arbitrum One
32+
// Testnets
33+
"11155111": "0xC2679fBD37d54388Ce493F1DB75320D236e1815e", // Sepolia
34+
"11155420": "0x4200000000000000000000000000000000000021", // Optimism Sepolia
35+
"84532": "0x4200000000000000000000000000000000000021", // Base Sepolia
36+
"420": "0x4200000000000000000000000000000000000021", // Optimism Goerli
37+
};
38+
39+
let schemaRegistryAddress: string;
40+
if (hre.network.name === "localhost") {
41+
schemaRegistryAddress = (await hre.deployments.get("SchemaRegistry")).address;
42+
} else if (KNOWN_SCHEMA_REGISTRY[chainId]) {
43+
schemaRegistryAddress = KNOWN_SCHEMA_REGISTRY[chainId];
44+
} else {
45+
throw new Error(`SchemaRegistry address unknown for chainId ${chainId}. Add it to KNOWN_SCHEMA_REGISTRY.`);
46+
}
47+
48+
const signer = await hre.ethers.getSigner(deployer);
49+
const schemaRegistry = new hre.ethers.Contract(schemaRegistryAddress, schemaRegArtifact.abi, signer);
50+
51+
// New schema links reviews to a specific sale via listingId and counterparty
52+
// Recipient of the attestation is the reviewee address
53+
const schema = "uint256 listingId,uint8 rating,string commentIPFSHash";
54+
const revocable = true;
55+
const resolver = hre.ethers.ZeroAddress;
56+
57+
let uid: string | undefined;
58+
try {
59+
const tx = await (schemaRegistry as any).register(schema, resolver, revocable);
60+
const receipt = await tx.wait();
61+
console.log("🧾 Review schema registered. TX:", receipt?.hash);
62+
// Parse Registered event to get UID
63+
const iface = new hre.ethers.Interface(schemaRegArtifact.abi);
64+
for (const log of receipt?.logs || []) {
65+
try {
66+
const parsed = iface.parseLog(log);
67+
if (parsed?.name === "Registered") {
68+
uid = parsed.args?.uid as string;
69+
break;
70+
}
71+
} catch {}
72+
}
73+
} catch {
74+
console.log("ℹ️ Schema likely already registered; computing UID.");
75+
}
76+
if (!uid) {
77+
// Compute with encodePacked to mirror contract logic
78+
const packed = hre.ethers.solidityPacked(["string", "address", "bool"], [schema, resolver, revocable]);
79+
uid = hre.ethers.keccak256(packed);
80+
}
81+
console.log("🆔 Review schema UID:", uid);
82+
83+
// Determine EAS address for output helper file
84+
let easAddressOut = "";
85+
if (hre.network.name === "localhost") {
86+
easAddressOut = (await hre.deployments.get("EAS")).address;
87+
} else if (KNOWN_EAS[chainId]) {
88+
easAddressOut = KNOWN_EAS[chainId];
89+
}
90+
91+
// Always write a generic helper json for frontend/backends regardless of network
92+
const nextjsOutPath = path.resolve(hre.config.paths.root, "../nextjs/contracts/easConfig.json");
93+
const nextjsOut = {
94+
chainId: await hre.getChainId(),
95+
schemaRegistry: schemaRegistryAddress,
96+
eas: easAddressOut,
97+
reviewSchemaUid: uid,
98+
};
99+
fs.writeFileSync(nextjsOutPath, JSON.stringify(nextjsOut, null, 2), { encoding: "utf-8" });
100+
101+
const indexerOutPath = path.resolve(hre.config.paths.root, "../indexer/src/easConfig.json");
102+
const indexerOut = {
103+
chainId: await hre.getChainId(),
104+
schemaRegistry: schemaRegistryAddress,
105+
eas: easAddressOut,
106+
reviewSchemaUid: uid,
107+
};
108+
fs.writeFileSync(indexerOutPath, JSON.stringify(indexerOut, null, 2), { encoding: "utf-8" });
109+
console.log("📝 Wrote EAS generic config:", nextjsOutPath, indexerOutPath);
110+
};
111+
112+
export default func;
113+
func.tags = ["EASLocal", "ReviewSchema"];

packages/hardhat/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"verify": "hardhat etherscan-verify"
2323
},
2424
"dependencies": {
25+
"@ethereum-attestation-service/eas-contracts": "^1.8.0",
2526
"@inquirer/password": "^4.0.2",
2627
"@openzeppelin/contracts": "~5.0.2",
2728
"@typechain/ethers-v6": "~0.5.1",

0 commit comments

Comments
 (0)