Skip to main content

Clearinghouse

Git Source

Inherits: Policy, RolesConsumer, CoolerCallback

Title: Olympus Clearinghouse.

Olympus Clearinghouse (Policy) Contract.

The Olympus Clearinghouse is a lending facility built on top of Cooler Loans. The Clearinghouse ensures that OHM holders can take loans against their gOHM holdings according to the parameters approved by the community in OIP-144 and its subsequent RFCs. The Clearinghouse parameters are immutable, because of that, if backing was to increase substantially, a new governance process to fork this implementation with upgraded parameters should take place. Although the Cooler contracts allow lenders to transfer ownership of their repayment rights, the Clearinghouse doesn't implement any functions to use that feature.

Constants​

reserve​

ERC20 public immutable reserve;

sReserve​

ERC4626 public immutable sReserve;

gohm​

ERC20 public immutable gohm;

ohm​

ERC20 public immutable ohm;

staking​

IStaking public immutable staking;

INTEREST_RATE​

uint256 public constant INTEREST_RATE = 5e15;

LOAN_TO_COLLATERAL​

uint256 public constant LOAN_TO_COLLATERAL = 289292e16;

DURATION​

uint256 public constant DURATION = 121 days;

FUND_CADENCE​

uint256 public constant FUND_CADENCE = 7 days;

FUND_AMOUNT​

uint256 public constant FUND_AMOUNT = 18_000_000e18;

MAX_REWARD​

uint256 public constant MAX_REWARD = 1e17;

State Variables​

CHREG​

CHREGv1 public CHREG;

MINTR​

MINTRv1 public MINTR;

TRSRY​

TRSRYv1 public TRSRY;

active​

determines whether the contract can be funded or not.

bool public active;

fundTime​

timestamp at which the next rebalance can occur.

uint256 public fundTime;

interestReceivables​

Outstanding receivables. Incremented when a loan is taken or rolled. Decremented when a loan is repaid or collateral is burned.

uint256 public interestReceivables;

principalReceivables​

uint256 public principalReceivables;

Functions​

constructor​

constructor(
address ohm_,
address gohm_,
address staking_,
address sReserve_,
address coolerFactory_,
address kernel_
) Policy(Kernel(kernel_)) CoolerCallback(coolerFactory_);

Parameters

NameTypeDescription
ohm_address
gohm_address
staking_address
sReserve_address
coolerFactory_address
kernel_address

configureDependencies​

Default framework setup. Configure dependencies for olympus-v3 modules.

This function will be called when the executor installs the Clearinghouse policy in the olympus-v3 Kernel.

function configureDependencies() external override returns (Keycode[] memory dependencies);

Returns

NameTypeDescription
dependenciesKeycode[]

requestPermissions​

Default framework setup. Request permissions for interacting with olympus-v3 modules.

This function will be called when the executor installs the Clearinghouse policy in the olympus-v3 Kernel.

function requestPermissions() external view override returns (Permissions[] memory requests);

Returns

NameTypeDescription
requestsPermissions[]

VERSION​

Returns the version of the policy.

function VERSION() external pure returns (uint8 major, uint8 minor);

Returns

NameTypeDescription
majoruint8The major version of the policy.
minoruint8The minor version of the policy.

lendToCooler​

Lend to a cooler.

To simplify the UX and easily ensure that all holders get the same terms, this function requests a new loan and clears it in the same transaction.

function lendToCooler(Cooler cooler_, uint256 amount_) external returns (uint256);

Parameters

NameTypeDescription
cooler_Coolerto lend to.
amount_uint256of reserve to lend.

Returns

NameTypeDescription
<none>uint256the id of the granted loan.

extendLoan​

Extend the loan expiry by repaying the extension interest in advance. The extension cost is paid by the caller. If a third-party executes the extension, the loan period is extended, but the borrower debt does not increase.

function extendLoan(Cooler cooler_, uint256 loanID_, uint8 times_) external;

Parameters

NameTypeDescription
cooler_Coolerholding the loan to be extended.
loanID_uint256index of loan in loans[].
times_uint8Amount of times that the fixed-term loan duration is extended.

claimDefaulted​

Batch several default claims to save gas. The elements on both arrays must be paired based on their index.

Implements an auction style reward system that linearly increases up to a max reward.

function claimDefaulted(address[] calldata coolers_, uint256[] calldata loans_) external;

Parameters

NameTypeDescription
coolers_address[]Array of contracts where the default must be claimed.
loans_uint256[]Array of defaulted loan ids.

_onRepay​

Overridden callback to decrement loan receivables.

function _onRepay(uint256, uint256 principalPaid_, uint256 interestPaid_) internal override;

Parameters

NameTypeDescription
_uint256
principalPaid_uint256in reserve.
interestPaid_uint256in reserve.

_onDefault​

Unused callback since defaults are handled by the clearinghouse.

Overriden and left empty to save gas.

function _onDefault(uint256, uint256, uint256, uint256) internal override;

Parameters

NameTypeDescription
_uint256
_uint256
_uint256
_uint256

rebalance​

Fund loan liquidity from treasury.

Exposure is always capped at FUND_AMOUNT and rebalanced at up to FUND_CADANCE. If several rebalances are available (because some were missed), calling this function several times won't impact the funds controlled by the contract. If the emergency shutdown is triggered, a rebalance will send funds back to the treasury.

function rebalance() public returns (bool);

Returns

NameTypeDescription
<none>boolFalse if too early to rebalance. Otherwise, true.

sweepIntoSavingsVault​

Sweep excess reserve into savings vault.

function sweepIntoSavingsVault() public;

_sweepIntoSavingsVault​

Sweep excess reserve into vault.

function _sweepIntoSavingsVault(uint256 amount_) internal;

Parameters

NameTypeDescription
amount_uint256

burn​

Public function to burn gOHM.

Can be used to burn any gOHM defaulted using the Cooler instead of the Clearinghouse.

function burn() public;

activate​

Activate the contract.

function activate() external onlyRole("cooler_overseer");

emergencyShutdown​

Deactivate the contract and return funds to treasury.

function emergencyShutdown() external onlyRole("emergency_shutdown");

defund​

Return funds to treasury.

function defund(ERC20 token_, uint256 amount_) external onlyRole("cooler_overseer");

Parameters

NameTypeDescription
token_ERC20to transfer.
amount_uint256to transfer.

_defund​

Internal function to return funds to treasury.

function _defund(ERC20 token_, uint256 amount_) internal;

Parameters

NameTypeDescription
token_ERC20to transfer.
amount_uint256to transfer.

getCollateralForLoan​

view function computing collateral for a loan amount.

function getCollateralForLoan(uint256 principal_) external pure returns (uint256);

Parameters

NameTypeDescription
principal_uint256

Returns

NameTypeDescription
<none>uint256

getLoanForCollateral​

view function computing loan for a collateral amount.

function getLoanForCollateral(uint256 collateral_) public pure returns (uint256, uint256);

Parameters

NameTypeDescription
collateral_uint256amount of gOHM.

Returns

NameTypeDescription
<none>uint256debt (amount to be lent + interest) for a given collateral amount.
<none>uint256

interestForLoan​

view function to compute the interest for given principal amount.

function interestForLoan(uint256 principal_, uint256 duration_) public pure returns (uint256);

Parameters

NameTypeDescription
principal_uint256amount of reserve being lent.
duration_uint256elapsed time in seconds.

Returns

NameTypeDescription
<none>uint256

getTotalReceivables​

Get total receivable reserve for the treasury. Includes both principal and interest.

function getTotalReceivables() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

Events​

Activate​

Logs whenever the Clearinghouse is initialized or reactivated.

event Activate();

Deactivate​

Logs whenever the Clearinghouse is deactivated.

event Deactivate();

Defund​

Logs whenever the treasury is defunded.

event Defund(address token, uint256 amount);

Parameters

NameTypeDescription
tokenaddress
amountuint256

Rebalance​

Logs the balance change (in reserve terms) whenever a rebalance occurs.

event Rebalance(bool defund, uint256 reserveAmount);

Parameters

NameTypeDescription
defundbool
reserveAmountuint256

Errors​

BadEscrow​

error BadEscrow();

DurationMaximum​

error DurationMaximum();

OnlyBurnable​

error OnlyBurnable();

TooEarlyToFund​

error TooEarlyToFund();

LengthDiscrepancy​

error LengthDiscrepancy();

OnlyBorrower​

error OnlyBorrower();

NotLender​

error NotLender();