Skip to main content

MortgageQueue

Git Source

Inherits: Context, ERC165, AccessControl, IMortgageQueue

Title: MortgageQueue

Author: SocksNFlops

The MortgageQueue contract is responsible for managing the queue of mortgage positions by sorting them by a specified trigger price

State Variables

mortgageHead

Storage Variables

uint256 public override mortgageHead

mortgageTail

The tokenId of the MortgagePosition at the tail of the queue.

uint256 public override mortgageTail

mortgageSize

The number of nodes in the queue.

uint256 public override mortgageSize

mortgageGasFee

The gas fee for enqueueing a mortgage into the queue.

uint256 public override mortgageGasFee

_mortgageNodes

The mapping of tokenIds to mortgage nodes

mapping(uint256 tokenId => MortgageNode) internal _mortgageNodes

Functions

constructor

Constructor

constructor() ;

supportsInterface

Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControl, ERC165) returns (bool);

mortgageNodes

The node for the corresponding tokenId (if it exists).

function mortgageNodes(uint256 tokenId) external view override returns (MortgageNode memory mortgageNode);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the MortgagePosition to get the node for.

Returns

NameTypeDescription
mortgageNodeMortgageNodeThe node for the corresponding tokenId.

setMortgageGasFee

Sets the gas fee for enqueueing a mortgage into the queue.

function setMortgageGasFee(uint256 mortgageGasFee_) external override onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
mortgageGasFee_uint256The gas fee for enqueueing a mortgage into the queue.

_insertMortgage

Inserts a mortgage position into the queue

function _insertMortgage(uint256 tokenId, uint256 triggerPrice, uint256 hintPrevId) internal;

Parameters

NameTypeDescription
tokenIduint256The tokenId of the MortgagePosition to insert.
triggerPriceuint256The trigger price of the MortgagePosition to insert.
hintPrevIduint256The tokenId of the "hint" previous node that is close and before the new node. If 0 is provided, it will start from the head.

_removeMortgage

Removes a mortgage position from the queue

function _removeMortgage(uint256 tokenId) internal returns (uint256 gasFee);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the MortgagePosition to remove.

Returns

NameTypeDescription
gasFeeuint256The gas fee collected from the removed mortgageNode

_popMortgage

Pops the current node from the queue and returns the next node

function _popMortgage(uint256 tokenId) internal returns (uint256 nextId, uint256 gasFee);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the node to pop.

Returns

NameTypeDescription
nextIduint256The tokenId of the next node in the queue.
gasFeeuint256The gas fee collected from the removed mortgageNode

_findFirstTriggered

Finds the first mortgage position in the queue that has a trigger price less than or equal to the input trigger price

function _findFirstTriggered(uint256 triggerPrice) internal view returns (uint256 tokenId);

Parameters

NameTypeDescription
triggerPriceuint256The trigger price to find the first MortgagePosition for.

Returns

NameTypeDescription
tokenIduint256The tokenId of the first MortgagePosition in the Conversion Queue that has a trigger price less than or equal to the input trigger price.