Mini-Mart is a gas-efficient, signature-based (EIP-712) ERC721 marketplace contract built with the Foundry framework. It allows users to list NFTs for sale with off-chain signatures, minimizing gas costs for sellers. The marketplace logic is executed on-chain only during the fulfillment of an order.
- On-Chain Order Fulfillment: A buyer fills the seller's signed order to the contract, and the
fulfillOrder
function atomically handles payment, fee collection, and NFT transfer. - Buyer Protection: If an order cannot be fulfilled (e.g., the NFT was transferred, approval was revoked, or the listing expired), the buyer's payment is automatically refunded within the same transaction.
- Fixed Platform Fee: A 3% fee is collected on every successful sale.
- Admin Controls:
- Pausable: The owner can pause and unpause all trading activity (
addOrder
,fulfillOrder
) in case of an emergency. - Fee Withdrawal: The owner can withdraw all accumulated fees from the contract.
- Pausable: The owner can pause and unpause all trading activity (
- Comprehensive Testing: The project includes an extensive test suite using Foundry, covering unit tests, negative paths, and fuzz testing.
- Foundry: You will need
forge
andanvil
installed. - Slither: For static analysis.
- Mythril: For symbolic execution analysis.
-
Clone the repository:
git clone https://github.com/your-username/mini-mart.git cd mini-mart
-
Install dependencies:
forge install
-
Set up environment variables: Create a
.env
file in the root of the project. This file is required for deploying to live networks and verifying contracts on Etherscan.# .env # For live network deployments (e.g., 'make deploy') RPC_URL=https://your_rpc_provider_url WALLET_ID=your_keystore_wallet_alias # e.g., my_wallet.json KEYSTORE_PASSWORD=your_keystore_password # For Etherscan verification ETHERSCAN_API_KEY=your_etherscan_api_key
The deployment commands require a script file from the script/
directory to be passed as an argument.
-
Deploy to a Local Network (Anvil): This command uses the
DeployLocal.s.sol
script, which not only deploys the contracts but also seeds the local environment by whitelisting the test NFT, minting tokens, and creating/removing sample orders.- Start a local Anvil node in a separate terminal:
anvil
- Run the local deployment script:
make deploy-local DeployLocal.s.sol
- Start a local Anvil node in a separate terminal:
-
Deploy to a Live Network: This requires
RPC_URL
,WALLET_ID
, andKEYSTORE_PASSWORD
to be set in your.env
file. TheDeploy.s.sol
script is a template and must be filled out before use.# Example: Dry-run a deployment without broadcasting the transaction make dry-run Deploy.s.sol # Example: Execute the deployment and broadcast the transaction make deploy Deploy.s.sol
This is the core contract. It implements the EIP-712 standard to create verifiable off-chain order data.
Order Flow:
- Seller: Creates an
Order
struct with sale details (price, tokenId, etc.) and signs its EIP-712 hash. - Buyer: Submits the
Order
struct and the seller'ssignature
to theaddOrder()
function. The contract verifies the signature and lists the order. - Buyer: Calls
fulfillOrder()
with the correctmsg.value
to purchase the NFT. The contract verifies all conditions (e.g., ownership, approval), transfers the NFT to the buyer, and pays the seller (minus fees).