OrderPool
Inherits: Context, ERC165, AccessControl, IOrderPool, ReentrancyGuard
Title: PurchasePool
Author: SocksNFlops
PurchasePool is a contract that stores a collection of PurchaseOrders for fulfilling collateral purchases for mortgages.
State Variables
nativeWrapper
Get the native token wrapper contract (whype/weth/etc).
address public immutable override nativeWrapper
generalManager
Returns the affiliated general manager address that is allowed to submit purchase orders.
address public immutable override generalManager
usdx
Returns the USDX token address
address public immutable override usdx
consol
Returns the Consol token address
address public immutable override consol
gasFee
Returns the gas fee for adding a PurchaseOrder to the OrderPool
uint256 public override gasFee
maximumOrderDuration
Returns the maximum duration for a PurchaseOrder
uint256 public override maximumOrderDuration
_orders
Internal mapping of purchase orders
mapping(uint256 => PurchaseOrder) private _orders
orderCount
Returns the total number of PurchaseOrder (current and past) placed in the order pool. Used to index the orders mapping.
uint256 public override orderCount
Functions
onlyGeneralManager
Modifier to check if the caller is the general manager
modifier onlyGeneralManager() ;
constructor
Constructor for the OrderPool
constructor(address nativeWrapper_, address generalManager_, address admin_) ;
Parameters
| Name | Type | Description |
|---|---|---|
nativeWrapper_ | address | The address of the native wrapper contract |
generalManager_ | address | The address of the GeneralManager |
admin_ | address | The address of the admin |
supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControl, ERC165) returns (bool);
setGasFee
Sets the gas fee for adding a PurchaseOrder to the OrderPool. Only callable by the admin role.
function setGasFee(uint256 gasFee_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
gasFee_ | uint256 | The new value of the gas fee |
setMaximumOrderDuration
Sets the maximum duration for a PurchaseOrder. Only callable by the admin role.
function setMaximumOrderDuration(uint256 maximumOrderDuration_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
maximumOrderDuration_ | uint256 | The new value of the maximum duration |
orders
Returns the purchase order at the given index
function orders(uint256 index) external view returns (PurchaseOrder memory);
Parameters
| Name | Type | Description |
|---|---|---|
index | uint256 | The index of the purchase order |
Returns
| Name | Type | Description |
|---|---|---|
<none> | PurchaseOrder | The purchase order |
_calculateMortgageGasFee
Calculates the mortgage gas fee for a list of conversion queues
function _calculateMortgageGasFee(address[] memory conversionQueues) internal view returns (uint256 mortgageGasFee);
Parameters
| Name | Type | Description |
|---|---|---|
conversionQueues | address[] | The list of conversion queues to calculate the mortgage gas fee for |
Returns
| Name | Type | Description |
|---|---|---|
mortgageGasFee | uint256 | The total mortgage gas fee |
sendOrder
Adds a PurchaseOrder to the OrderPool. Only callable by the general manager.
function sendOrder(
address[] memory originationPools,
uint256[] memory borrowAmounts,
address[] memory conversionQueues,
OrderAmounts memory orderAmounts,
MortgageParams memory mortgageParams,
uint256 expiration,
bool expansion
) external payable onlyGeneralManager nonReentrant returns (uint256 index);
Parameters
| Name | Type | Description |
|---|---|---|
originationPools | address[] | The addresses of the origination pools to deploy funds from |
borrowAmounts | uint256[] | The amounts being borrowed from each origination pool |
conversionQueues | address[] | The addresses of the conversion queues to use |
orderAmounts | OrderAmounts | The amounts being collected from the borrower |
mortgageParams | MortgageParams | The parameters for the mortgage being created |
expiration | uint256 | The expiration timestamp of the order |
expansion | bool | Whether the mortgage is a balance sheet expansion of an existing position |
Returns
| Name | Type | Description |
|---|---|---|
index | uint256 | The index of the PurchaseOrder |
_sendCollectedAssets
Helper function for sending collected assets to the general manager or refunding to the borrower
function _sendCollectedAssets(address receiver, PurchaseOrder memory order) internal;
Parameters
| Name | Type | Description |
|---|---|---|
receiver | address | The address to send the assets to |
order | PurchaseOrder | The order being processed |
_processOrder
Processes an order at a given internal index
function _processOrder(uint256 index, uint256[] memory hintPrevIds) internal returns (uint256 collectedGasFee);
Parameters
| Name | Type | Description |
|---|---|---|
index | uint256 | The index of the order |
hintPrevIds | uint256[] | List of hints for identifying the previous mortgage position in the respective conversion queue. |
Returns
| Name | Type | Description |
|---|---|---|
collectedGasFee | uint256 | The amount of gas fee collected |
processOrders
Processes the purchase orders at the given indices by fulfilling them or removing expired orders. Only callable by the FULFILLMENT_ROLE.
function processOrders(uint256[] memory indices, uint256[][] memory hintPrevIdsList)
external
onlyRole(Roles.FULFILLMENT_ROLE)
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
indices | uint256[] | The indices of the purchase orders to process |
hintPrevIdsList | uint256[][] | The list of hintPrevIds for each purchase order. Each hintPrevIds is a list of hint of the previous mortgage position in the respective conversion queue. |