Skip to main content

OrderPool

Git Source

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

NameTypeDescription
nativeWrapper_addressThe address of the native wrapper contract
generalManager_addressThe address of the GeneralManager
admin_addressThe 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

NameTypeDescription
gasFee_uint256The 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

NameTypeDescription
maximumOrderDuration_uint256The 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

NameTypeDescription
indexuint256The index of the purchase order

Returns

NameTypeDescription
<none>PurchaseOrderThe 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

NameTypeDescription
conversionQueuesaddress[]The list of conversion queues to calculate the mortgage gas fee for

Returns

NameTypeDescription
mortgageGasFeeuint256The 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

NameTypeDescription
originationPoolsaddress[]The addresses of the origination pools to deploy funds from
borrowAmountsuint256[]The amounts being borrowed from each origination pool
conversionQueuesaddress[]The addresses of the conversion queues to use
orderAmountsOrderAmountsThe amounts being collected from the borrower
mortgageParamsMortgageParamsThe parameters for the mortgage being created
expirationuint256The expiration timestamp of the order
expansionboolWhether the mortgage is a balance sheet expansion of an existing position

Returns

NameTypeDescription
indexuint256The 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

NameTypeDescription
receiveraddressThe address to send the assets to
orderPurchaseOrderThe order being processed

_processOrder

Processes an order at a given internal index

function _processOrder(uint256 index, uint256[] memory hintPrevIds) internal returns (uint256 collectedGasFee);

Parameters

NameTypeDescription
indexuint256The index of the order
hintPrevIdsuint256[]List of hints for identifying the previous mortgage position in the respective conversion queue.

Returns

NameTypeDescription
collectedGasFeeuint256The 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

NameTypeDescription
indicesuint256[]The indices of the purchase orders to process
hintPrevIdsListuint256[][]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.