DutchAuction

Category: Auctions | Difficulty: Intermediate | Chapters: Auctions | Concept: Dutch auction with descending price and encrypted reserve

Dutch auction with descending price and encrypted reserve.

Why this example

This example focuses on Dutch auction with descending price and encrypted reserve. It is designed to be self-contained and easy to run locally.

Quick start

npm install
npm run test:mocked -- test/auctions/DutchAuction.test.ts

Dependencies

  • AuctionPaymentToken

  • PrizeItem

Deployment plan

Step
Contract
Args
Saves As

1

PrizeItem

-

prizeItem

2

AuctionPaymentToken

$deployer, "Auction USD", "AUSD", ""

paymentToken

3

DutchAuction

@prizeItem, @paymentToken, 0, #Math.floor(Date.now()/1000), #Math.floor(Date.now()/1000)+3600, 1000000, 100000, 10000

auction

Contract and test

Pitfalls to avoid

No pitfalls are highlighted in the tests for this example.

API Reference

Overview

Dutch auction with descending price and encrypted reserve.

Developer Notes

Example for fhEVM Examples - Auctions Category

In a Dutch auction, the price starts high and decreases over time. The first bidder to accept the current price wins. The reserve price is encrypted so bidders cannot know the seller's minimum.

seller

The seller receiving payment

paymentToken

Confidential payment token

nftContract

NFT contract for the prize

tokenId

Token ID of the prize

prizeDeposited

Whether the prize has been deposited

auctionStartTime

Auction timing

auctionEndTime

Auction end timestamp

startingPrice

Price parameters (cleartext for price calculation)

priceDecrement

Price decrement per interval

decrementInterval

Seconds between price decrements

winner

Winner address (set when auction completes)

finalPrice

Final sale price

TooEarlyError

TooLateError

InvalidAuctionTime

PrizeNotDeposited

PrizeAlreadyDeposited

OnlySeller

AuctionAlreadyEnded

BidTooLow

ReservePriceNotSet

onlyDuringAuction

getCurrentPrice

Calculate the current price based on elapsed time.

Return Values

Name
Type
Description

[0]

uint256

The current asking price

constructor

Create a Dutch auction.

Parameters

Name
Type
Description

nftContractAddress

address

ERC721 prize contract

paymentTokenAddress

address

ERC7984 payment token

prizeTokenId

uint256

Token ID of the prize

startTime

uint256

Auction start timestamp

endTime

uint256

Auction end timestamp

startPrice

uint256

Starting price (highest)

decrement

uint256

Price decrease per interval

interval

uint256

Seconds between price decreases

depositPrize

Deposit the NFT prize into the auction.

setReservePrice

Set the encrypted reserve price (seller only).

Parameters

Name
Type
Description

encReserve

externalEuint64

Encrypted reserve price handle

inputProof

bytes

Proof for the encrypted input

buy

Accept the current price and buy the item.

Uses FHE.select to handle reserve price check without revealing it. The bid succeeds only if current price >= reserve price.

withdrawUnsoldItem

Withdraw the NFT if auction ends with no buyer.

Last updated