TermAuction.sol

This contract belongs to the Term Auction group of contracts and is specific to a Term Repo deployment. This contract calculates a clearing price in a blind double auction and manages auction clearing

TermAuction

This contract calculates a clearing price in a blind double auction and manages auction clearing and settlement

This contract belongs to the Term Auction group of contracts and is specific to a Term Repo deployment

ClearingPriceState

struct ClearingPriceState {
  uint256 offerPrice;
  uint256 offerIndex;
  uint256 bidIndex;
  uint256 cumSumOffers;
  uint256 cumSumBids;
  uint256 maxClearingVolume;
  uint256 nextOfferIndex;
  uint256 nextBidIndex;
  uint256 nextCumSumOffers;
  uint256 nextCumSumBids;
  uint256 nextOfferPrice;
  uint256 nextMaxClearingVolume;
  bool minCumSumCorrection;
  uint256 nextBidPrice;
  uint256 clearingPrice;
}

THREESIXTY_DAYCOUNT_SECONDS

ADMIN_ROLE

DEVOPS_ROLE

INITIALIZER_ROLE

termRepoId

termAuctionId

auctionEndTime

dayCountFractionMantissa

termRepoServicer

termAuctionBidLocker

termAuctionOfferLocker

purchaseToken

emitter

clearingPrice

clearingPricePostProcessingOffset

auctionCompleted

auctionCancelledForWithdrawal

completeAuctionPaused

termContractPaired

onlyWhileAuctionClosed

This only runs if the auction is closed (after auction end time)

This uses the block timestamp to determine if the auction is closed

whenCompleteAuctionNotPaused

notTermContractPaired

constructor

initialize

Initializes the contract

See: https://docs.openzeppelin.com/contracts/4.x/upgradeable

pairTermContracts

completeAuction

Calculates an auction's clearing price, assigns bids/offers, and returns unassigned funds

Parameters

Name
Type
Description

completeAuctionInput

struct CompleteAuctionInput

A struct containing all revealed and unrevealed bids and offers and expired rollover bids

cancelAuction

Cancels an auction and returns all funds to bidders and fulfillBiders

Parameters

Name
Type
Description

completeAuctionInput

struct CompleteAuctionInput

A struct containing all revealed and unrevealed bids and offers and expired rollover bids

cancelAuctionForWithdrawal

Cancels an auction and sets auctionCancelledForWithdrawal to true to open unlocking tenders

_increaseCumSumBids

_decreaseCumSumBids

_minUint256

Returns the min of two uint256 values

Parameters

Name
Type
Description

a

uint256

The first value to compare

b

uint256

The second value to compare

Return Values

Name
Type
Description

[0]

uint256

The min of the two values

_calculateClearingPrice

Calculates the intersection between bid/offer schedules to arrive at a clearing price

Imagine a graph with price along the X-axis and cumsum(bid/offerAmount*price) along the Y-axis. This function finds the point where the supply line crosses the demand line using binary search

Parameters

Name
Type
Description

sortedBids

struct TermAuctionRevealedBid[]

A sorted array of bids used to arrive at a demand schedule

sortedOffers

struct TermAuctionRevealedOffer[]

A sorted array of offers used to arrive at a supply schedule

clearingOffset

uint256

The offset to apply to the marginal bid and offer indexes when calculating the final clearing price

Return Values

Name
Type
Description

[0]

uint256

clearingPrice The price at which Term Auction will be cleared

[1]

uint256

_findFirstIndexForPrice

Finds the index of the first bid with a bidPrice of price and calculate the cumsum of the bid amounts up to that index

Parameters

Name
Type
Description

price

uint256

The price to search for

sortedBids

struct TermAuctionRevealedBid[]

An array of sorted bids to search

startIndex

uint256

The index to start searching from

Return Values

Name
Type
Description

i

uint256

The index of the first bid with a bidPrice of price

totalAmount

uint256

The cumsum of the bid amounts up to return index i

_findLastIndexForPrice

Finds the index of the last offer with a offerPrice of price and calculate the cumsum of the offer amounts up to that index

Parameters

Name
Type
Description

price

uint256

The price to search for

sortedOffers

struct TermAuctionRevealedOffer[]

An array of offers to search

startIndex

uint256

The index to start searching from

Return Values

Name
Type
Description

i

uint256

The index of the last offer with a offerPrice of price

totalAmount

uint256

The cumsum of the offer amounts up to return index i

_fullyAssignBid

Fully assigns a bid

Parameters

Name
Type
Description

bid

struct TermAuctionRevealedBid

The bid to assign

Return Values

Name
Type
Description

[0]

uint256

The amount that was assigned

_fullyAssignOffer

Fully assigns an offer

Parameters

Name
Type
Description

offer

struct TermAuctionRevealedOffer

The offer to assign

Return Values

Name
Type
Description

[0]

uint256

The amount that was assigned

_partiallyAssignBid

Partially assigns a bid

Parameters

Name
Type
Description

bid

struct TermAuctionRevealedBid

The bid to assign

assignedAmount

uint256

The amount to assign

Return Values

Name
Type
Description

[0]

uint256

The amount that was assigned

_partiallyAssignOffer

Partially assigns an offer

Parameters

Name
Type
Description

offer

struct TermAuctionRevealedOffer

The offer to assign

assignedAmount

uint256

The amount to assign

Return Values

Name
Type
Description

[0]

uint256

The amount that was assigned

_assignRolloverBid

_markRolloverAsProcessed

_assignBids

Assigns bids up to maxAssignable

This method allocates pro-rata across an the marginal price group (pro-rata on the margin) and attempts to prevent residuals from accumulating to a single bid

Parameters

Name
Type
Description

sortedBids

struct TermAuctionRevealedBid[]

An array of sorted bids to process

maxAssignable

uint256

The maximum bid amount that can be assigned across all bidders

purchaseTokenDecimals

uint256

The number of decimals of the purchase token

Return Values

Name
Type
Description

[0]

uint256

The total amount assigned

_assignOffers

Assigns offers up to maxAssignable

This method allocates pro-rata across an the marginal price group (pro-rata on the margin) and attempts to prevent residuals from accumulating to a single offer

Parameters

Name
Type
Description

sortedOffers

struct TermAuctionRevealedOffer[]

An array of sorted offers to process

maxAssignable

uint256

The maximum offer amount that can be assigned across all offers

purchaseTokenDecimals

uint256

The number of decimals of the purchase token

Return Values

Name
Type
Description

[0]

uint256

The total amount assigned

_calculateRepurchasePrice

Calculates repurchase price given a purchase price (equivalent to principal plus interest)

Parameters

Name
Type
Description

purchasePrice

uint256

The purchase price

Return Values

Name
Type
Description

[0]

uint256

The repurchase price obtained by applying the clearing rate on an Actual/360 day-count convention

_calculateAndStoreClearingPrice

pauseCompleteAuction

_This function pauses the TermAuction contract preventing public state changes See {Pausable-pause}.

unpauseCompleteAuction

Unpuses the TermAuction contract allowing public state changes

_See {Pausable-unpause}.

_authorizeUpgrade

required override by the OpenZeppelin UUPS module

Parameters

Name
Type
Description

impl

address

new impl address for proxy upgrade

Last updated