Skip to main content

DualAuction

Inherits: ERC1155SupplyUpgradeable, Clone, ReentrancyGuardUpgradeable, AuctionImmutableArgs, AuctionConversions, IDualAuction

DualAuction contract

State Variables

MAXIMUM_ALLOWED_PRICE

the maximum allowed price is 2^255 because we save the top bit for differentiating between bids and asks in the token id

uint256 internal constant MAXIMUM_ALLOWED_PRICE = 2 ** 255 - 1;

NUM_TICKS

The number of ticks allowed between the minimum and maximum price (inclusive)

uint256 internal constant NUM_TICKS = 100;

maxBid

The highest bid received so far

uint256 public maxBid;

minAsk

The lowest ask received so far

uint256 public minAsk;

clearingBidPrice

The clearing bid price of the auction, set after settlement

uint256 public clearingBidPrice;

clearingAskPrice

The clearing ask price of the auction, set after settlement

uint256 public clearingAskPrice;

bidTokensClearedAtClearing

The number of bid tokens cleared at the tick closest to clearing price

uint256 public bidTokensClearedAtClearing;

askTokensClearedAtClearing

The number of ask tokens cleared at the tick closest to clearing price

uint256 public askTokensClearedAtClearing;

settled

True if the auction has been settled, else false

bool public settled;

Functions

onlyValidPrice

Ensures that the given price is valid validity is defined as in range (minPrice, maxPrice) and on a valid tick

modifier onlyValidPrice(uint256 price);

onlyAuctionActive

Ensures that the auction is active

modifier onlyAuctionActive();

onlyAuctionEnded

Ensures that the auction is finalized

modifier onlyAuctionEnded();

onlyAuctionSettled

Ensures that the auction has been settled

modifier onlyAuctionSettled();

initialize

Initializes the auction, should be called by DualAuctionFactory

function initialize() external initializer;

bid

Places a bid using amountIn bidAsset tokens, for askAsset tokens at the given price

function bid(uint256 amountIn, uint256 price)
external
onlyValidPrice(price)
onlyAuctionActive
nonReentrant
returns (uint256);

Parameters

NameTypeDescription
amountInuint256The amount to bid, in bidAsset
priceuint256the price at which to bid, denominated in terms of bidAsset per askAsset

Returns

NameTypeDescription
<none>uint256The number of shares output

ask

Places an ask using amountIn askAsset tokens, for bidAsset tokens at the given price

function ask(uint256 amountIn, uint256 price)
external
onlyValidPrice(price)
onlyAuctionActive
nonReentrant
returns (uint256);

Parameters

NameTypeDescription
amountInuint256The amount to sell, in askAsset
priceuint256the price at which to ask, denominated in terms of bidAsset per askAsset

Returns

NameTypeDescription
<none>uint256The number of shares output

settle

Settles the auction after the end date

iterates through the bids and asks to determine The clearing price, setting the clearingPrice variable afterwards

function settle() external onlyAuctionEnded nonReentrant returns (uint256);

Returns

NameTypeDescription
<none>uint256The settled clearing price, or 0 if none

redeem

Redeems bid/ask slips after the auction has concluded

function redeem(uint256 tokenId, uint256 amount)
external
onlyAuctionSettled
nonReentrant
returns (uint256 bidTokens, uint256 askTokens);

Parameters

NameTypeDescription
tokenIduint256The id of the bid/ask slip to redeem
amountuint256The amount of slips to redeem

Returns

NameTypeDescription
bidTokensuint256The number of tokens received
askTokensuint256

clearingPrice

The clearing price of the auction, set after settlement

function clearingPrice() public view override returns (uint256);

shareValue

returns the value of the shares after settlement

function shareValue(uint256 shareAmount, uint256 tokenId)
internal
view
returns (uint256 bidTokens, uint256 askTokens);

Parameters

NameTypeDescription
shareAmountuint256The number of bid/ask slips to check
tokenIduint256The token id of the share

Returns

NameTypeDescription
bidTokensuint256The number of bid tokens the share tokens are worth
askTokensuint256The number of ask tokens the share tokens are worth