# TermAuctionBidLocker.sol

## TermAuctionBidLocker

This contract handles and proceesses Term Auction bid submissions

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

### MAX\_BID\_PRICE

```solidity
uint256 MAX_BID_PRICE
```

### MAX\_BID\_COUNT

```solidity
uint256 MAX_BID_COUNT
```

### THREESIXTY\_DAYCOUNT\_SECONDS

```solidity
uint256 THREESIXTY_DAYCOUNT_SECONDS
```

### ADMIN\_ROLE

```solidity
bytes32 ADMIN_ROLE
```

### AUCTIONEER\_ROLE

```solidity
bytes32 AUCTIONEER_ROLE
```

### DEVOPS\_ROLE

```solidity
bytes32 DEVOPS_ROLE
```

### INITIALIZER\_ROLE

```solidity
bytes32 INITIALIZER_ROLE
```

### ROLLOVER\_MANAGER

```solidity
bytes32 ROLLOVER_MANAGER
```

### termRepoId

```solidity
bytes32 termRepoId
```

### termAuctionId

```solidity
bytes32 termAuctionId
```

### auctionStartTime

```solidity
uint256 auctionStartTime
```

### revealTime

```solidity
uint256 revealTime
```

### auctionEndTime

```solidity
uint256 auctionEndTime
```

### minimumTenderAmount

```solidity
uint256 minimumTenderAmount
```

### dayCountFractionMantissa

```solidity
uint256 dayCountFractionMantissa
```

### purchaseToken

```solidity
address purchaseToken
```

### collateralTokens

```solidity
mapping(contract IERC20Upgradeable => bool) collateralTokens
```

### termRepoCollateralManager

```solidity
contract ITermRepoCollateralManager termRepoCollateralManager
```

### termRepoServicer

```solidity
contract ITermRepoServicer termRepoServicer
```

### termPriceOracle

```solidity
contract ITermPriceOracle termPriceOracle
```

### emitter

```solidity
contract ITermEventEmitter emitter
```

### termAuction

```solidity
contract ITermAuction termAuction
```

### bids

```solidity
mapping(bytes32 => struct TermAuctionBid) bids
```

### bidCount

```solidity
uint256 bidCount
```

### termContractPaired

```solidity
bool termContractPaired
```

### lockingPaused

```solidity
bool lockingPaused
```

### unlockingPaused

```solidity
bool unlockingPaused
```

### onlyWhileAuctionOpen

```solidity
modifier onlyWhileAuctionOpen()
```

### onlyWhileAuctionRevealing

```solidity
modifier onlyWhileAuctionRevealing()
```

### onlyBidder

```solidity
modifier onlyBidder(address bidder, address authedUser)
```

### whenLockingNotPaused

```solidity
modifier whenLockingNotPaused()
```

### whenUnlockingNotPaused

```solidity
modifier whenUnlockingNotPaused()
```

### notTermContractPaired

```solidity
modifier notTermContractPaired()
```

### constructor

```solidity
constructor() public
```

### initialize

```solidity
function initialize(string termRepoId_, string auctionId_, uint256 auctionStartTime_, uint256 revealTime_, uint256 auctionEndTime_, uint256 redemptionTimestamp_, uint256 minimumTenderAmount_, address purchaseToken_, contract IERC20Upgradeable[] collateralTokens_, address termInitializer_) external
```

### pairTermContracts

```solidity
function pairTermContracts(address termAuction_, contract ITermRepoServicer termRepoServicer_, contract ITermEventEmitter emitter_, contract ITermRepoCollateralManager termRepoCollateralManager_, contract ITermPriceOracle termPriceOracle_, address devopsMultisig_, address adminWallet_) external
```

### pairRolloverManager

```solidity
function pairRolloverManager(address rolloverManager) external
```

#### Parameters

| Name            | Type    | Description                                         |
| --------------- | ------- | --------------------------------------------------- |
| rolloverManager | address | The address of the TermRepoRolloverManager contract |

### lockBidsWithReferral

```solidity
function lockBidsWithReferral(struct TermAuctionBidSubmission[] bidSubmissions, address referralAddress) external returns (bytes32[])
```

#### Parameters

| Name            | Type                               | Description                                                                                                        |
| --------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| bidSubmissions  | struct TermAuctionBidSubmission\[] | An array of Term Auction bid submissions to borrow an amount of money at rate up to but not exceeding the bid rate |
| referralAddress | address                            | A user address that referred the submitter of this bid                                                             |

#### Return Values

| Name | Type       | Description                                 |
| ---- | ---------- | ------------------------------------------- |
| \[0] | bytes32\[] | A bytes32 array of unique on chain bid ids. |

### lockRolloverBid

```solidity
function lockRolloverBid(struct TermAuctionBid bid) external
```

#### Parameters

| Name | Type                  | Description                            |
| ---- | --------------------- | -------------------------------------- |
| bid  | struct TermAuctionBid | A struct containing details of the bid |

### lockBids

```solidity
function lockBids(struct TermAuctionBidSubmission[] bidSubmissions) external returns (bytes32[])
```

#### Parameters

| Name           | Type                               | Description                 |
| -------------- | ---------------------------------- | --------------------------- |
| bidSubmissions | struct TermAuctionBidSubmission\[] | An array of bid submissions |

#### Return Values

| Name | Type       | Description                                 |
| ---- | ---------- | ------------------------------------------- |
| \[0] | bytes32\[] | A bytes32 array of unique on chain bid ids. |

### lockedBid

```solidity
function lockedBid(bytes32 id) external view returns (struct TermAuctionBid)
```

#### Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | bytes32 | A bid Id    |

#### Return Values

| Name | Type                  | Description                                   |
| ---- | --------------------- | --------------------------------------------- |
| \[0] | struct TermAuctionBid | A struct containing details of the locked bid |

### revealBids

```solidity
function revealBids(bytes32[] ids, uint256[] prices, uint256[] nonces) external
```

#### Parameters

| Name   | Type       | Description                                           |
| ------ | ---------- | ----------------------------------------------------- |
| ids    | bytes32\[] | An array of bid ids of the bids to reveal             |
| prices | uint256\[] | An array of the bid prices to reveal                  |
| nonces | uint256\[] | An array of nonce values to generate bid price hashes |

### unlockBids

```solidity
function unlockBids(bytes32[] ids) external
```

unlockBids unlocks multiple bids and returns funds to the bidder

#### Parameters

| Name | Type       | Description               |
| ---- | ---------- | ------------------------- |
| ids  | bytes32\[] | An array of ids to unlock |

### getAllBids

```solidity
function getAllBids(bytes32[] revealedBids, bytes32[] expiredRolloverBids, bytes32[] unrevealedBids) external returns (struct TermAuctionRevealedBid[], struct TermAuctionBid[])
```

#### Parameters

| Name                | Type       | Description                              |
| ------------------- | ---------- | ---------------------------------------- |
| revealedBids        | bytes32\[] | An array of the revealed offer ids       |
| expiredRolloverBids | bytes32\[] | An array of the expired rollover bid ids |
| unrevealedBids      | bytes32\[] | An array of the unrevealed offer ids     |

#### Return Values

| Name | Type                             | Description                                                                        |
| ---- | -------------------------------- | ---------------------------------------------------------------------------------- |
| \[0] | struct TermAuctionRevealedBid\[] | An array of TermAuctionRevealedBid structs containing details of the revealed bids |
| \[1] | struct TermAuctionBid\[]         | An array of TermAuctionBid structs containing details of the unrevealed bids       |

### auctionUnlockBid

```solidity
function auctionUnlockBid(bytes32 id, address bidder, address[] bidCollateralTokens, uint256[] amounts) external
```

#### Parameters

| Name                | Type       | Description                                   |
| ------------------- | ---------- | --------------------------------------------- |
| id                  | bytes32    | A bytes32 bid id                              |
| bidder              | address    | The address of the bidder                     |
| bidCollateralTokens | address\[] | The addresses of the token used as collateral |
| amounts             | uint256\[] | The amounts of collateral tokens to unlock    |

### \_lock

```solidity
function _lock(struct TermAuctionBidSubmission bidSubmission, address authedUser) internal returns (struct TermAuctionBid)
```

### \_lockRolloverBid

```solidity
function _lockRolloverBid(struct TermAuctionBid bid) internal
```

### \_unlock

```solidity
function _unlock(bytes32 id, address bidder, address[] bidCollateralTokens, uint256[] amounts) internal
```

### \_revealBid

```solidity
function _revealBid(bytes32 id, uint256 price, uint256 nonce) internal
```

### \_getAllBids

```solidity
function _getAllBids(bytes32[] revealedBids, bytes32[] expiredRolloverBids, bytes32[] unrevealedBids) internal returns (struct TermAuctionRevealedBid[], struct TermAuctionBid[])
```

#### Parameters

| Name                | Type       | Description                              |
| ------------------- | ---------- | ---------------------------------------- |
| revealedBids        | bytes32\[] | An array of the revealed offer ids       |
| expiredRolloverBids | bytes32\[] | An array of the expired rollover bid ids |
| unrevealedBids      | bytes32\[] | An array of the unrevealed offer ids     |

#### Return Values

| Name | Type                             | Description                                                                        |
| ---- | -------------------------------- | ---------------------------------------------------------------------------------- |
| \[0] | struct TermAuctionRevealedBid\[] | An array of TermAuctionRevealedBid structs containing details of the revealed bids |
| \[1] | struct TermAuctionBid\[]         | An array of TermAuctionBid structs containing details of the unrevealed bids       |

### \_truncateBidStruct

```solidity
function _truncateBidStruct(struct TermAuctionBid bid) internal pure returns (struct TermAuctionRevealedBid revealed)
```

*This does not check the hash of the revealed bid price*

#### Parameters

| Name | Type                  | Description                                             |
| ---- | --------------------- | ------------------------------------------------------- |
| bid  | struct TermAuctionBid | The TermAuctionBid to convert to TermAuctionRevealedBid |

### \_processRevealedBidsForValidity

```solidity
function _processRevealedBidsForValidity(bytes32[] revealedBids, uint256 unrevealedBidCount) internal returns (struct TermAuctionBid[], uint256, uint256, uint256)
```

### \_isRolloverStillValid

```solidity
function _isRolloverStillValid(struct TermAuctionBid revealedBid, contract ITermRepoServicer pairOffServicer) internal returns (bool)
```

### \_isInInitialCollateralShortFall

```solidity
function _isInInitialCollateralShortFall(uint256 bidAmount, address[] collateralTokens_, uint256[] collateralAmounts) internal view returns (bool)
```

### \_isInMaintenanceCollateralShortFall

```solidity
function _isInMaintenanceCollateralShortFall(uint256 bidAmount, uint256 bidPrice, address[] collateralTokens_, uint256[] collateralAmounts) internal view returns (bool)
```

### \_fillRevealedBidsForAuctionClearing

```solidity
function _fillRevealedBidsForAuctionClearing(bytes32[] revealedBids, uint256 auctionBidCount) internal returns (struct TermAuctionRevealedBid[])
```

### \_generateBidId

```solidity
function _generateBidId(bytes32 id, address user) internal view returns (bytes32)
```

### \_processBidForAuction

```solidity
function _processBidForAuction(bytes32 id) internal
```

### pauseLocking

```solidity
function pauseLocking() external
```

### unpauseLocking

```solidity
function unpauseLocking() external
```

### pauseUnlocking

```solidity
function pauseUnlocking() external
```

### unpauseUnlocking

```solidity
function unpauseUnlocking() external
```

### \_authorizeUpgrade

```solidity
function _authorizeUpgrade(address impl) internal
```

*required override by the OpenZeppelin UUPS module*

#### Parameters

| Name | Type    | Description                        |
| ---- | ------- | ---------------------------------- |
| impl | address | new impl address for proxy upgrade |
