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

uint256 THREESIXTY_DAYCOUNT_SECONDS

ADMIN_ROLE

bytes32 ADMIN_ROLE

DEVOPS_ROLE

bytes32 DEVOPS_ROLE

INITIALIZER_ROLE

bytes32 INITIALIZER_ROLE

termRepoId

bytes32 termRepoId

termAuctionId

bytes32 termAuctionId

auctionEndTime

uint256 auctionEndTime

dayCountFractionMantissa

uint256 dayCountFractionMantissa

termRepoServicer

contract ITermRepoServicer termRepoServicer

termAuctionBidLocker

contract ITermAuctionBidLocker termAuctionBidLocker

termAuctionOfferLocker

contract ITermAuctionOfferLocker termAuctionOfferLocker

purchaseToken

contract IERC20MetadataUpgradeable purchaseToken

emitter

contract ITermEventEmitter emitter

controller

contract ITermController controller

clearingPrice

uint256 clearingPrice

clearingPricePostProcessingOffset

uint256 clearingPricePostProcessingOffset

auctionCompleted

bool auctionCompleted

auctionCancelledForWithdrawal

bool auctionCancelledForWithdrawal

completeAuctionPaused

bool completeAuctionPaused

termContractPaired

bool termContractPaired

onlyWhileAuctionClosed

modifier 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

modifier whenCompleteAuctionNotPaused()

notTermContractPaired

modifier notTermContractPaired()

constructor

constructor() public

initialize

function initialize(string termRepoId_, string auctionId_, uint256 auctionEndTime_, uint256 termStart_, uint256 redemptionTimestamp_, contract IERC20MetadataUpgradeable purchaseToken_, address termAuctionInitializer_, uint256 clearingPricePostProcessingOffset_) external

Initializes the contract

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

pairTermContracts

function pairTermContracts(contract ITermEventEmitter emitter_, contract ITermController controller_, contract ITermRepoServicer termRepoServicer_, contract ITermAuctionBidLocker termAuctionBidLocker_, contract ITermAuctionOfferLocker termAuctionOfferLocker_, address devopsMultisigAddress_, address adminWallet_, string version_) external

completeAuction

function completeAuction(struct CompleteAuctionInput completeAuctionInput) external

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

Parameters

cancelAuction

function cancelAuction(struct CompleteAuctionInput completeAuctionInput) public

Cancels an auction and returns all funds to bidders and fulfillBiders

Parameters

cancelAuctionForWithdrawal

function cancelAuctionForWithdrawal(address[] rolloverBorrowers, address[] rolloverPairOffTermRepoServicer) public

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

_increaseCumSumBids

function _increaseCumSumBids(struct TermAuctionRevealedBid[] sortedBids, uint256 startIndex, uint256 previousCumSumBids, uint256 currentPrice) internal pure returns (uint256, uint256)

_decreaseCumSumBids

function _decreaseCumSumBids(struct TermAuctionRevealedBid[] sortedBids, uint256 startIndex, uint256 previousCumSumBids, uint256 currentPrice) internal pure returns (uint256, uint256)

_minUint256

function _minUint256(uint256 a, uint256 b) internal pure returns (uint256)

Returns the min of two uint256 values

Parameters

Return Values

_calculateClearingPrice

function _calculateClearingPrice(struct TermAuctionRevealedBid[] sortedBids, struct TermAuctionRevealedOffer[] sortedOffers, uint256 clearingOffset) internal pure returns (uint256, uint256)

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

Return Values

_findFirstIndexForPrice

function _findFirstIndexForPrice(uint256 price, struct TermAuctionRevealedBid[] sortedBids, uint256 startIndex) internal pure returns (uint256 i, uint256 totalAmount)

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

Return Values

_findLastIndexForPrice

function _findLastIndexForPrice(uint256 price, struct TermAuctionRevealedOffer[] sortedOffers, uint256 startIndex) internal pure returns (uint256 i, uint256 totalAmount)

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

Return Values

_fullyAssignBid

function _fullyAssignBid(struct TermAuctionRevealedBid bid) internal returns (uint256)

Fully assigns a bid

Parameters

Return Values

_fullyAssignOffer

function _fullyAssignOffer(struct TermAuctionRevealedOffer offer) internal returns (uint256)

Fully assigns an offer

Parameters

Return Values

_partiallyAssignBid

function _partiallyAssignBid(struct TermAuctionRevealedBid bid, uint256 assignedAmount) internal returns (uint256)

Partially assigns a bid

Parameters

Return Values

_partiallyAssignOffer

function _partiallyAssignOffer(struct TermAuctionRevealedOffer offer, uint256 assignedAmount) internal returns (uint256)

Partially assigns an offer

Parameters

Return Values

_assignRolloverBid

function _assignRolloverBid(address borrower, uint256 purchasePrice, uint256 repurchasePrice, address rolloverPairOffTermRepoServicer) internal

_markRolloverAsProcessed

function _markRolloverAsProcessed(address rolloverPairOffTermRepoServicer, address borrower) internal

_assignBids

function _assignBids(struct TermAuctionRevealedBid[] sortedBids, uint256 maxAssignable, uint256 purchaseTokenDecimals) internal returns (uint256)

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

Return Values

_assignOffers

function _assignOffers(struct TermAuctionRevealedOffer[] sortedOffers, uint256 maxAssignable, uint256 purchaseTokenDecimals) internal returns (uint256)

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

Return Values

_calculateRepurchasePrice

function _calculateRepurchasePrice(uint256 purchasePrice) internal view returns (uint256)

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

Parameters

Return Values

_calculateAndStoreClearingPrice

function _calculateAndStoreClearingPrice(struct TermAuctionRevealedBid[] sortedBids, struct TermAuctionRevealedOffer[] sortedOffers) internal returns (uint256, uint256)

pauseCompleteAuction

function pauseCompleteAuction() external

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

unpauseCompleteAuction

function unpauseCompleteAuction() external

Unpuses the TermAuction contract allowing public state changes

_See {Pausable-unpause}.

_authorizeUpgrade

function _authorizeUpgrade(address impl) internal

required override by the OpenZeppelin UUPS module

Parameters

Last updated