Skip to main content

GeneralManager

Git Source

Inherits: Initializable, ERC165Upgradeable, AccessControlUpgradeable, UUPSUpgradeable, IGeneralManager, ReentrancyGuard

Title: GeneralManager

Author: SocksNFlops

The GeneralManager contract manages the origination of mortgage positions using origination pools

State Variables

GeneralManagerStorageLocation

The storage location of the GeneralManager contract

keccak256(abi.encode(uint256(keccak256("buttonwood.storage.GeneralManager")) - 1)) & ~bytes32(uint256(0xff))

bytes32 private constant GeneralManagerStorageLocation =
0xa0fde9a47799f0a64e9adfc0ccfed9fa7d54162399ca936d199d08c2d005ad00

Functions

_getGeneralManagerStorage

Gets the storage location of the GeneralManager contract

function _getGeneralManagerStorage() private pure returns (GeneralManagerStorage storage $);

Returns

NameTypeDescription
$GeneralManagerStorageThe storage location of the GeneralManager contract

__GeneralManager_init

Initializes the GeneralManager contract and calls parent initializers

function __GeneralManager_init(
address usdx_,
address consol_,
uint16 penaltyRate_,
uint16 refinanceRate_,
uint16 conversionPremiumRate_,
uint16 priceSpread_,
address insuranceFund_,
address interestRateOracle_
) internal onlyInitializing;

Parameters

NameTypeDescription
usdx_addressThe address of the USDX token
consol_addressThe address of the Consol token
penaltyRate_uint16The penalty rate
refinanceRate_uint16The refinancing rate
conversionPremiumRate_uint16The conversion premium rate
priceSpread_uint16The price spread
insuranceFund_addressThe address of the insurance fund
interestRateOracle_addressThe address of the interest rate oracle

__GeneralManager_init_unchained

Initializes only the GeneralManager contract

function __GeneralManager_init_unchained(
address usdx_,
address consol_,
uint16 penaltyRate_,
uint16 refinanceRate_,
uint16 conversionPremiumRate_,
uint16 priceSpread_,
address insuranceFund_,
address interestRateOracle_
) internal onlyInitializing;

Parameters

NameTypeDescription
usdx_addressThe address of the USDX token
consol_addressThe address of the Consol token
penaltyRate_uint16The penalty rate
refinanceRate_uint16The refinancing rate
conversionPremiumRate_uint16The conversion premium rate
priceSpread_uint16The price spread
insuranceFund_addressThe address of the insurance fund
interestRateOracle_addressThe address of the interest rate oracle

initialize

Initializes the GeneralManager contract

function initialize(
address usdx_,
address consol_,
uint16 penaltyRate_,
uint16 refinanceRate_,
uint16 conversionPremiumRate_,
uint16 priceSpread_,
address insuranceFund_,
address interestRateOracle_
) external initializer;

Parameters

NameTypeDescription
usdx_addressThe address of the USDX token
consol_addressThe address of the Consol token
penaltyRate_uint16The penalty rate
refinanceRate_uint16The refinancing rate
conversionPremiumRate_uint16The conversion premium rate
priceSpread_uint16The price spread
insuranceFund_addressThe address of the insurance fund
interestRateOracle_addressThe address of the interest rate oracle

constructor

Note: oz-upgrades-unsafe-allow: constructor

constructor() ;

_authorizeUpgrade

Function that should revert when msg.sender is not authorized to upgrade the contract. Called by {upgradeToAndCall}. Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.

function _authorizeUpgrade(address) internal onlyOwner {}
function _authorizeUpgrade(address newImplementation) internal virtual override onlyRole(Roles.DEFAULT_ADMIN_ROLE);

whenNotPaused

Modifier to check if the contract is paused

modifier whenNotPaused() ;

onlyOrderPool

Modifier to check if the caller is the order pool

modifier onlyOrderPool() ;

onlyRegisteredOriginationPool

Modifier to check if the caller is an origination pool

modifier onlyRegisteredOriginationPool() ;

_addConversionQueues

Appends the conversionQueueList to the recorded conversion queues for a mortgage position

function _addConversionQueues(uint256 tokenId, address[] memory conversionQueueList) internal;

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
conversionQueueListaddress[]The list of conversion queues to update

_calculateRequiredGasFee

Calculates the required gas fee for the caller

function _calculateRequiredGasFee(bool usingOrderPool, address[] memory conversionQueueList)
internal
view
returns (uint256 requiredGasFee);

Parameters

NameTypeDescription
usingOrderPoolboolWhether the caller is using the order pool
conversionQueueListaddress[]The list of conversion queues to calculate the required gas fee for

Returns

NameTypeDescription
requiredGasFeeuint256The required gas fee

_checkSufficientGas

Checks if the caller sent enough value to cover the required gas fee

function _checkSufficientGas(uint256 requiredGasFee) internal view;

Parameters

NameTypeDescription
requiredGasFeeuint256The required gas fee

_refundSurplusGas

Refunds the surplus gas to the caller

function _refundSurplusGas(uint256 requiredGasFee) internal;

Parameters

NameTypeDescription
requiredGasFeeuint256The required gas fee

_validateMortgageOwner

Validates that the caller is the owner of the mortgage

function _validateMortgageOwner(uint256 tokenId) internal view;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

_validateTotalPeriods

Validates that the total periods is supported for the collateral

function _validateTotalPeriods(address collateral, uint8 totalPeriods) internal view;

Parameters

NameTypeDescription
collateraladdressThe collateral address
totalPeriodsuint8The total periods

onlyMortgageOwner

Modifier to check if the caller is the owner of the mortgage

modifier onlyMortgageOwner(uint256 tokenId) ;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

_validateBorrowCaps

Validates that the amount being borrowed exceeds the minimum cap and does not exceed the maximum cap

function _validateBorrowCaps(MortgageParams memory mortgageParams) internal view;

Parameters

NameTypeDescription
mortgageParamsMortgageParamsThe mortgage parameters

_validateOriginationPools

Validates that the origination pools are supported

function _validateOriginationPools(address[] memory originationPools) internal view;

Parameters

NameTypeDescription
originationPoolsaddress[]The origination pools

_validateConversionQueues

Validates that the conversion queues have the CONVERSION_ROLE role

function _validateConversionQueues(address[] memory conversionQueueList) internal view;

Parameters

NameTypeDescription
conversionQueueListaddress[]The list of conversion queues to validate

_replaceNFTRole

Revokes the NFT role of an address and grants it to a new address

function _replaceNFTRole(address oldRoleHolder, address newRoleHolder) internal;

Parameters

NameTypeDescription
oldRoleHolderaddressThe address to remove the NFT role from
newRoleHolderaddressThe address to grant the NFT role to

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
override(AccessControlUpgradeable, ERC165Upgradeable)
returns (bool);

usdx

Returns the USDX token address

function usdx() external view returns (address);

Returns

NameTypeDescription
<none>addressThe USDX token address

consol

Returns the Consol token address

function consol() external view returns (address);

Returns

NameTypeDescription
<none>addressThe Consol token address

setPenaltyRate

Sets the penalty rate for a mortgage (in basis points)

function setPenaltyRate(uint16 penaltyRate_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
penaltyRate_uint16The penalty rate

penaltyRate

Returns the penalty rate for a mortgage (in basis points)

Takes in a mortgage position to allow upgraded implementations to take into account the position's details.

function penaltyRate(MortgagePosition memory) external view returns (uint16);

Parameters

NameTypeDescription
<none>MortgagePosition

Returns

NameTypeDescription
<none>uint16The penalty rate

setRefinanceRate

Sets the refinance rate for a mortgage (in basis points)

function setRefinanceRate(uint16 refinanceRate_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
refinanceRate_uint16The refinance rate

refinanceRate

Returns the refinance rate (in basis points).

Takes in a mortgage position to allow upgraded implementations to take into account the position's details.

function refinanceRate(MortgagePosition memory) external view returns (uint16);

Parameters

NameTypeDescription
<none>MortgagePosition

Returns

NameTypeDescription
<none>uint16The refinance rate

setInsuranceFund

Sets the insurance fund address

function setInsuranceFund(address insuranceFund_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
insuranceFund_addressThe insurance fund address

insuranceFund

Returns the insurance fund address

function insuranceFund() external view returns (address);

Returns

NameTypeDescription
<none>addressThe insurance fund address

setInterestRateOracle

Sets the interest rate oracle address

function setInterestRateOracle(address interestRateOracle_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
interestRateOracle_addressThe interest rate oracle address

interestRateOracle

Returns the interest rate oracle address

function interestRateOracle() external view returns (address);

Returns

NameTypeDescription
<none>addressThe interest rate oracle address

interestRate

Returns the interest rate (in basis points)

function interestRate(address collateral, uint8 totalPeriods, bool hasPaymentPlan) public view returns (uint16);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral
totalPeriodsuint8The total number of periods for the mortgage
hasPaymentPlanboolWhether the mortgage has a payment plan

Returns

NameTypeDescription
<none>uint16The interest rate

conversionPremiumRate

Returns the conversion premium rate (in basis points)

function conversionPremiumRate(address, uint8, bool) public view returns (uint16);

Parameters

NameTypeDescription
<none>address
<none>uint8
<none>bool

Returns

NameTypeDescription
<none>uint16The conversion premium rate

setConversionPremiumRate

Sets the conversion premium rate (in basis points)

function setConversionPremiumRate(uint16 conversionPremiumRate_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
conversionPremiumRate_uint16The conversion premium rate

setOriginationPoolScheduler

Sets the origination pool scheduler address

function setOriginationPoolScheduler(address originationPoolScheduler_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
originationPoolScheduler_addressThe origination pool scheduler address

originationPoolScheduler

Returns the origination pool scheduler address

function originationPoolScheduler() public view returns (address);

Returns

NameTypeDescription
<none>addressThe origination pool scheduler address

setLoanManager

Sets the loan manager address

function setLoanManager(address loanManager_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
loanManager_addressThe loan manager address

loanManager

Returns the loan manager address

function loanManager() public view returns (address);

Returns

NameTypeDescription
<none>addressThe loan manager address

mortgageNFT

Returns the mortgage NFT address

function mortgageNFT() public view returns (address);

Returns

NameTypeDescription
<none>addressThe mortgage NFT address

setOrderPool

Sets the order pool address

function setOrderPool(address orderPool_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
orderPool_addressThe order pool address

orderPool

Returns the order pool address

function orderPool() public view returns (address);

Returns

NameTypeDescription
<none>addressThe order pool address

updateSupportedMortgagePeriodTerms

Updates the supported mortgage period terms for a collateral.

function updateSupportedMortgagePeriodTerms(address collateral, uint8 mortgagePeriods, bool isSupported)
external
onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral
mortgagePeriodsuint8
isSupportedboolWhether the mortgage period term is supported

isSupportedMortgagePeriodTerms

Returns whether a mortgage period term is supported

function isSupportedMortgagePeriodTerms(address collateral, uint8 mortgagePeriods) external view returns (bool);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral
mortgagePeriodsuint8The mortgage period

Returns

NameTypeDescription
<none>boolWhether the mortgage period term is supported

setPriceOracle

Sets the address of the price oracle

function setPriceOracle(address collateral, address priceOracle) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral
priceOracleaddressThe address of the price oracle

priceOracles

The address of the price oracle for the collateral

function priceOracles(address collateral) external view returns (address);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral

Returns

NameTypeDescription
<none>addressThe address of the price oracle

setMinimumCap

Sets the minimum request size of a mortgage for a given collateral. Requests cannot borrow less than this amount.

function setMinimumCap(address collateral, uint256 minimumCap_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral
minimumCap_uint256The minimum cap

minimumCap

Returns the minimum request size of a mortgage for a given collateral. Requests cannot borrow less than this amount.

function minimumCap(address collateral) external view returns (uint256);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral

Returns

NameTypeDescription
<none>uint256The minimum cap

setMaximumCap

Sets the maximum request size of a mortgage for a given collateral. Requests cannot borrow more than this amount.

function setMaximumCap(address collateral, uint256 maximumCap_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral
maximumCap_uint256The maximum cap

maximumCap

Returns the maximum request size of a mortgage for a given collateral. Requests cannot borrow more than this amount.

function maximumCap(address collateral) external view returns (uint256);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral

Returns

NameTypeDescription
<none>uint256The maximum cap

setPriceSpread

Sets the price spread to incentivize the fulfiller to fill orders

function setPriceSpread(uint16 priceSpread_) external onlyRole(Roles.DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
priceSpread_uint16The price spread

priceSpread

The price spread to incentivize the fulfiller to fill orders

function priceSpread() external view returns (uint16);

Returns

NameTypeDescription
<none>uint16priceSpread The price spread

conversionQueues

Returns the conversion queues a given mortgage position is registered with

function conversionQueues(uint256 tokenId) public view returns (address[] memory);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position

Returns

NameTypeDescription
<none>address[]The conversion queues

_calculateCost

Calculates the cost of the collateral

function _calculateCost(address collateral, uint256 collateralAmount)
internal
view
returns (uint256 cost, uint8 collateralDecimals);

Parameters

NameTypeDescription
collateraladdressThe address of the collateral token
collateralAmountuint256The amount of collateral to calculate the cost for

Returns

NameTypeDescription
costuint256The cost of the collateral
collateralDecimalsuint8The decimals of the collateral token

_prepareOrder

Prepares the mortgageParams and orderAmounts for an order

function _prepareOrder(
uint256 tokenId,
BaseRequest calldata baseRequest,
address collateral,
address subConsol,
bool hasPaymentPlan
)
internal
view
returns (MortgageParams memory mortgageParams, OrderAmounts memory orderAmounts, uint256[] memory borrowAmounts);

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage NFT
baseRequestBaseRequestThe base request for the mortgage
collateraladdressThe address of the collateral token
subConsoladdressThe address of the subConsol contract
hasPaymentPlanboolWhether the mortgage has a payment plan

Returns

NameTypeDescription
mortgageParamsMortgageParamsThe mortgage parameters
orderAmountsOrderAmountsThe order amounts
borrowAmountsuint256[]The amounts being borrowed from each origination pool

_sendOrder

Sends completed order to the order pool

function _sendOrder(
uint256[] memory borrowAmounts,
MortgageParams memory mortgageParams,
OrderAmounts memory orderAmounts,
BaseRequest calldata baseRequest,
address[] memory conversionQueueList,
uint256 requiredGasFee,
bool expansion
) internal;

Parameters

NameTypeDescription
borrowAmountsuint256[]The amounts being borrowed from each origination pool
mortgageParamsMortgageParamsThe mortgage parameters
orderAmountsOrderAmountsThe order amounts
baseRequestBaseRequestThe base request for the mortgage
conversionQueueListaddress[]The addresses of the conversion queues to use
requiredGasFeeuint256The required gas fee
expansionboolWhether the request is a new mortgage creation or a balance sheet expansion

_sendRequest

Sends a request to the order pool

function _sendRequest(
BaseRequest calldata baseRequest,
uint256 tokenId,
address collateral,
address subConsol,
address[] memory conversionQueueList,
uint256 requiredGasFee,
bool hasPaymentPlan,
bool expansion
) internal;

Parameters

NameTypeDescription
baseRequestBaseRequestThe base request for the mortgage
tokenIduint256The ID of the mortgage NFT
collateraladdressThe address of the collateral token
subConsoladdressThe address of the subConsol contract
conversionQueueListaddress[]The addresses of the conversion queues to use
requiredGasFeeuint256The required gas fee
hasPaymentPlanboolWhether the mortgage has a payment plan
expansionboolWhether the request is a new mortgage creation or a balance sheet expansion

requestMortgageCreation

Requests a new mortgage creation

function requestMortgageCreation(CreationRequest calldata creationRequest)
external
payable
whenNotPaused
nonReentrant
returns (uint256 tokenId);

Parameters

NameTypeDescription
creationRequestCreationRequestThe parameters of the mortgage creation being requested

Returns

NameTypeDescription
tokenIduint256The tokenId of the mortgage NFT that was created

requestBalanceSheetExpansion

Requests to expand the balance sheet of a mortgage position by adding additional principal and collateral to the mortgage position. Only callable by whitelisted addresses.

function requestBalanceSheetExpansion(ExpansionRequest calldata expansionRequest)
external
payable
onlyRole(Roles.EXPANSION_ROLE)
whenNotPaused
nonReentrant
onlyMortgageOwner(expansionRequest.tokenId);

Parameters

NameTypeDescription
expansionRequestExpansionRequestThe parameters of the balance sheet expansion being requested

burnMortgageNFT

Burns a mortgage NFT

function burnMortgageNFT(uint256 tokenId) external onlyRole(Roles.NFT_ROLE);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage NFT to burn

originate

Originates a mortgage position. Only callable by the OrderPool.

function originate(OriginationParameters calldata originationParameters)
external
payable
onlyOrderPool
whenNotPaused
nonReentrant;

Parameters

NameTypeDescription
originationParametersOriginationParametersThe parameters for originating a mortgage creation or balance sheet expansion

originationPoolDeployCallback

Called to msg.sender after transferring to the recipient from IOriginationPool#deploy.

amount = amountBorrowed

returnAmount = amountBorrowed + originationFee

function originationPoolDeployCallback(uint256, uint256 returnAmount, bytes calldata data)
external
onlyRegisteredOriginationPool;

Parameters

NameTypeDescription
<none>uint256
returnAmountuint256The amount of consol to return to the origination pool
databytesAny data passed through by the caller via the IOriginationPool#deploy call

_enqueueMortgage

Enqueues a mortgage position into a conversion queue

function _enqueueMortgage(uint256 tokenId, address[] memory conversionQueueList, uint256[] memory hintPrevIds)
internal;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage NFT
conversionQueueListaddress[]The list of conversion queues
hintPrevIdsuint256[]The IDs of the previous mortgage position in the respective conversion queue

enqueueMortgage

Enqueues a mortgage position into a conversion queue

function enqueueMortgage(uint256 tokenId, address[] memory conversionQueueList, uint256[] memory hintPrevIds)
external
payable
whenNotPaused
nonReentrant
onlyMortgageOwner(tokenId);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
conversionQueueListaddress[]The list of conversion queues to use
hintPrevIdsuint256[]The hint for the previous mortgage position in the conversion queue

convert

Converts a mortgage position

function convert(uint256 tokenId, uint256 amount, uint256 collateralAmount, address receiver)
external
onlyRole(Roles.CONVERSION_ROLE)
whenNotPaused
nonReentrant;

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
amountuint256The amount of the principal being coverted
collateralAmountuint256The amount of the collateral being withdrawn during the conversion
receiveraddressThe address receiving the converted collateral

setPaused

Pause or unpause the contract

function setPaused(bool pause) external override onlyRole(Roles.PAUSE_ROLE);

Parameters

NameTypeDescription
pauseboolThe new paused state

paused

Get the paused state of the contract

function paused() public view override returns (bool);

Returns

NameTypeDescription
<none>boolThe paused state of the contract

Structs

GeneralManagerStorage

Storage structure for GeneralManager contract

Uses ERC-7201 namespaced storage pattern

Note: storage-location: erc7201:buttonwood.storage.GeneralManager

struct GeneralManagerStorage {
address _usdx;
address _consol;
uint16 _penaltyRate;
uint16 _refinanceRate;
uint16 _conversionPremiumRate;
uint16 _priceSpread;
address _insuranceFund;
address _interestRateOracle;
address _originationPoolScheduler;
address _loanManager;
address _orderPool;
mapping(address => mapping(uint8 => bool)) _supportedMortgagePeriodTerms;
mapping(address => address) _priceOracles;
mapping(address => uint256) _minimumCaps;
mapping(address => uint256) _maximumCaps;
mapping(uint256 => address[]) _conversionQueues;
mapping(uint256 => mapping(address => bool)) _mortgageEnqueued;
bool _paused;
}

Properties

NameTypeDescription
_usdxaddressAddress of the USDX token contract
_consoladdressAddress of the Consol token contract
_penaltyRateuint16Late payment penalty rate in basis points (BPS)
_refinanceRateuint16Refinancing fee rate in basis points (BPS)
_conversionPremiumRateuint16Conversion premium rate in basis points (BPS)
_priceSpreaduint16Price spread in basis points (BPS)
_insuranceFundaddressAddress of the insurance fund
_interestRateOracleaddressAddress of the interest rate oracle contract
_originationPoolScheduleraddressAddress of the origination pool scheduler contract
_loanManageraddressAddress of the loan manager contract
_orderPooladdressAddress of the order pool contract
_supportedMortgagePeriodTermsmapping(address => mapping(uint8 => bool))Mapping of collateral address to period term to supported status
_priceOraclesmapping(address => address)Mapping of collateral address to price oracle address
_minimumCapsmapping(address => uint256)Mapping of collateral address to minimum cap
_maximumCapsmapping(address => uint256)Mapping of collateral address to maximum cap
_conversionQueuesmapping(uint256 => address[])Mapping of collateral address to conversion queues
_mortgageEnqueuedmapping(uint256 => mapping(address => bool))Mapping of tokenId to conversion queue to enqueued status
_pausedboolWhether the contract is paused