# TermRepoServicer.sol

## TermRepoServicer

This contract maintains records, collects and disburse repurchase payments

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

### YEAR\_SECONDS

```solidity
uint256 YEAR_SECONDS
```

### ADMIN\_ROLE

```solidity
bytes32 ADMIN_ROLE
```

### AUCTION\_LOCKER

```solidity
bytes32 AUCTION_LOCKER
```

### AUCTIONEER

```solidity
bytes32 AUCTIONEER
```

### COLLATERAL\_MANAGER

```solidity
bytes32 COLLATERAL_MANAGER
```

### DEVOPS\_ROLE

```solidity
bytes32 DEVOPS_ROLE
```

### SPECIALIST\_ROLE

```solidity
bytes32 SPECIALIST_ROLE
```

### ROLLOVER\_MANAGER

```solidity
bytes32 ROLLOVER_MANAGER
```

### ROLLOVER\_TARGET\_AUCTIONEER\_ROLE

```solidity
bytes32 ROLLOVER_TARGET_AUCTIONEER_ROLE
```

### INITIALIZER\_ROLE

```solidity
bytes32 INITIALIZER_ROLE
```

### termRepoId

```solidity
bytes32 termRepoId
```

### totalOutstandingRepurchaseExposure

```solidity
uint256 totalOutstandingRepurchaseExposure
```

### totalRepurchaseCollected

```solidity
uint256 totalRepurchaseCollected
```

### maturityTimestamp

```solidity
uint256 maturityTimestamp
```

### endOfRepurchaseWindow

```solidity
uint256 endOfRepurchaseWindow
```

### redemptionTimestamp

```solidity
uint256 redemptionTimestamp
```

block timestamp at which term repo tokens can be redeemed

### servicingFee

```solidity
uint256 servicingFee
```

percentage share of bid amounts charged to bidder

### shortfallHaircutMantissa

```solidity
uint256 shortfallHaircutMantissa
```

proportion of redemption value for redemption

### purchaseToken

```solidity
address purchaseToken
```

### termRepoCollateralManager

```solidity
contract ITermRepoCollateralManager termRepoCollateralManager
```

### termRepoRolloverManager

```solidity
contract ITermRepoRolloverManager termRepoRolloverManager
```

### termRepoLocker

```solidity
contract ITermRepoLocker termRepoLocker
```

### termRepoToken

```solidity
contract ITermRepoToken termRepoToken
```

### termController

```solidity
contract ITermController termController
```

### emitter

```solidity
contract ITermEventEmitter emitter
```

### repurchaseExposureLedger

```solidity
mapping(address => uint256) repurchaseExposureLedger
```

### termContractPaired

```solidity
bool termContractPaired
```

### notTermContractPaired

```solidity
modifier notTermContractPaired()
```

### constructor

```solidity
constructor() public
```

### initialize

```solidity
function initialize(string termRepoId_, uint256 maturityTimestamp_, uint256 repurchaseWindow_, uint256 redemptionBuffer_, uint256 servicingFee_, address purchaseToken_, contract ITermController termController_, contract ITermEventEmitter emitter_, address termInitializer_) external
```

### pairTermContracts

```solidity
function pairTermContracts(address termRepoLocker_, address termRepoCollateralManager_, address termRepoToken_, address termAuctionOfferLocker_, address termAuction_, address rolloverManager_, address devopsMultisig_, address adminWallet_, string version_) external
```

### submitRepurchasePayment

```solidity
function submitRepurchasePayment(uint256 amount) external
```

The max repurchase amount is the repurchase balance less any amounts earmarked for rollover

#### Parameters

| Name   | Type    | Description                                           |
| ------ | ------- | ----------------------------------------------------- |
| amount | uint256 | The amount of purchase token to submit for repurchase |

### burnCollapseExposure

```solidity
function burnCollapseExposure(uint256 amountToBurn) external
```

#### Parameters

| Name         | Type    | Description                          |
| ------------ | ------- | ------------------------------------ |
| amountToBurn | uint256 | The amount of TermRepoTokens to burn |

### getBorrowerRepurchaseObligation

```solidity
function getBorrowerRepurchaseObligation(address borrower) external view returns (uint256)
```

#### Parameters

| Name     | Type    | Description                          |
| -------- | ------- | ------------------------------------ |
| borrower | address | The address of the borrower to query |

#### Return Values

| Name | Type    | Description                                                     |
| ---- | ------- | --------------------------------------------------------------- |
| \[0] | uint256 | The total repurchase price due at maturity for a given borrower |

### mintOpenExposure

```solidity
function mintOpenExposure(uint256 amount, uint256[] collateralAmounts) external
```

*This method allows SPECIALIST\_ROLE to open repurchase price exposure against a TermRepoToken mint of corresponding value outside of a Term Auction to create new supply*

#### Parameters

| Name              | Type       | Description                                                                           |
| ----------------- | ---------- | ------------------------------------------------------------------------------------- |
| amount            | uint256    | The amount of Term Repo Tokens to mint                                                |
| collateralAmounts | uint256\[] | An array containing an amount of collateral token for each token in collateral basket |

### redeemTermRepoTokens

```solidity
function redeemTermRepoTokens(address redeemer, uint256 amountToRedeem) external
```

#### Parameters

| Name           | Type    | Description                            |
| -------------- | ------- | -------------------------------------- |
| redeemer       | address | The address of redeemer                |
| amountToRedeem | uint256 | The amount of TermRepoTokens to redeem |

### isTermRepoBalanced

```solidity
function isTermRepoBalanced() external view returns (bool)
```

#### Return Values

| Name | Type | Description                                                        |
| ---- | ---- | ------------------------------------------------------------------ |
| \[0] | bool | A boolean that represents whether the term repo locker is balanced |

### lockOfferAmount

```solidity
function lockOfferAmount(address offeror, uint256 amount) external
```

#### Parameters

| Name    | Type    | Description                           |
| ------- | ------- | ------------------------------------- |
| offeror | address | The address of the offeror            |
| amount  | uint256 | The amount of purchase tokens to lock |

### unlockOfferAmount

```solidity
function unlockOfferAmount(address offeror, uint256 amount) external
```

#### Parameters

| Name    | Type    | Description                               |
| ------- | ------- | ----------------------------------------- |
| offeror | address | The address of the offeror                |
| amount  | uint256 | The amount of purchase tokens to unlocked |

### fulfillOffer

```solidity
function fulfillOffer(address offeror, uint256 purchasePrice, uint256 repurchasePrice, bytes32 offerId) external
```

#### Parameters

| Name            | Type    | Description                                     |
| --------------- | ------- | ----------------------------------------------- |
| offeror         | address | The address of the offeror                      |
| purchasePrice   | uint256 | The offer amount to fulfill                     |
| repurchasePrice | uint256 | The repurchase price due to offeror at maturity |
| offerId         | bytes32 | Unique identifier for this offer                |

### fulfillBid

```solidity
function fulfillBid(address bidder, uint256 purchasePrice, uint256 repurchasePrice, address[] collateralTokens, uint256[] collateralAmounts, uint256 dayCountFractionMantissa) external
```

#### Parameters

| Name                     | Type       | Description                                                     |
| ------------------------ | ---------- | --------------------------------------------------------------- |
| bidder                   | address    | The address of the bidder                                       |
| purchasePrice            | uint256    | The bid amount to fulfill                                       |
| repurchasePrice          | uint256    | The repurchase price due at maturity                            |
| collateralTokens         | address\[] | Collateral token addresses                                      |
| collateralAmounts        | uint256\[] | Collateral token amounts                                        |
| dayCountFractionMantissa | uint256    | Actual/360 day count fraction parameter from Term Auction Group |

### approveRolloverAuction

```solidity
function approveRolloverAuction(address termAuction) external
```

#### Parameters

| Name        | Type    | Description                                                     |
| ----------- | ------- | --------------------------------------------------------------- |
| termAuction | address | The address of a TermAuction contract to receive autioneer role |

### openExposureOnRolloverNew

```solidity
function openExposureOnRolloverNew(address borrower, uint256 purchasePrice, uint256 repurchasePrice, address previousTermRepoLocker, uint256 dayCountFractionMantissa) external returns (uint256)
```

#### Parameters

| Name                     | Type    | Description                                                     |
| ------------------------ | ------- | --------------------------------------------------------------- |
| borrower                 | address | The address of the borrower rolling into new Term Repo          |
| purchasePrice            | uint256 | The purchase price received from new TermRepo                   |
| repurchasePrice          | uint256 | The new repurchase price due at maturity of new TermRepo        |
| previousTermRepoLocker   | address | The address of the old TermRepoLocker contract                  |
| dayCountFractionMantissa | uint256 | Actual/360 day count fraction parameter from Term Auction Group |

#### Return Values

| Name | Type    | Description                                                               |
| ---- | ------- | ------------------------------------------------------------------------- |
| \[0] | uint256 | The net purchase price received in after deducing protocol servicing fees |

### closeExposureOnRolloverExisting

```solidity
function closeExposureOnRolloverExisting(address borrower, uint256 rolloverSettlementAmount) external returns (uint256)
```

#### Parameters

| Name                     | Type    | Description                                                                                                           |
| ------------------------ | ------- | --------------------------------------------------------------------------------------------------------------------- |
| borrower                 | address | The address of the borrower                                                                                           |
| rolloverSettlementAmount | uint256 | The amount of net proceeds received from new TermRepo to pay down existing repurchase obligation due to old Term Repo |

#### Return Values

| Name | Type    | Description                                                                                                                        |
| ---- | ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| \[0] | uint256 | A uint256 representing the proportion of total repurchase due to old Term Repo from borrower settled by proceeds from new TermRepo |

### liquidatorCoverExposure

```solidity
function liquidatorCoverExposure(address borrower, address liquidator, uint256 amountToCover) external
```

#### Parameters

| Name          | Type    | Description                                               |
| ------------- | ------- | --------------------------------------------------------- |
| borrower      | address | The address of the borrower                               |
| liquidator    | address | The address of the liquidator                             |
| amountToCover | uint256 | The amount of repurchase exposure to cover in liquidation |

### liquidatorCoverExposureWithRepoToken

```solidity
function liquidatorCoverExposureWithRepoToken(address borrower, address liquidator, uint256 amountOfRepoToken) external returns (uint256)
```

#### Parameters

| Name              | Type    | Description                                            |
| ----------------- | ------- | ------------------------------------------------------ |
| borrower          | address | The address of the borrower                            |
| liquidator        | address | The address of the liquidator                          |
| amountOfRepoToken | uint256 | The amount of term tokens used to cover in liquidation |

#### Return Values

| Name | Type    | Description                                                 |
| ---- | ------- | ----------------------------------------------------------- |
| \[0] | uint256 | A uint256 representing purchase value of repo tokens burned |

### reopenToNewAuction

```solidity
function reopenToNewAuction(struct TermAuctionGroup termAuctionGroup) external
```

#### Parameters

| Name             | Type                    | Description                                                                                               |
| ---------------- | ----------------------- | --------------------------------------------------------------------------------------------------------- |
| termAuctionGroup | struct TermAuctionGroup | A struct containing contract addresses of a Term Auction deployment to pair for a reopening of a TermRepo |

### \_isTermRepoBalanced

```solidity
function _isTermRepoBalanced() internal view returns (bool)
```

Truncation is by 4 decimal places due to the assumption that number of participants < 10000

### \_getMaxRepaymentAroundRollover

```solidity
function _getMaxRepaymentAroundRollover(address borrower) internal view returns (uint256)
```

### \_repay

```solidity
function _repay(address _borrower, address repayer_, uint256 amount_) internal
```

### \_parRedemption

```solidity
function _parRedemption(address redeemer_, uint256 amount_) internal
```

### \_proRataRedemption

```solidity
function _proRataRedemption(address redeemer_, uint256 amount_) internal
```

### \_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 |
