Skip to main content

EmissionManager

Git Source

Inherits: IEmissionManager, IPeriodicTask, Policy, PolicyEnabler

forge-lint: disable-start(mixed-case-function, mixed-case-variable, screaming-snake-case-immutable)

State Variables

ONE_HUNDRED_PERCENT

uint256 internal constant ONE_HUNDRED_PERCENT = 1e18

MAX_BOND_MARKET_CAPACITY_SCALAR

uint256 internal constant MAX_BOND_MARKET_CAPACITY_SCALAR = 2e18

ROLE_HEART

The role assigned to the Heart contract. This enables the Heart contract to call specific functions on this contract.

bytes32 public constant ROLE_HEART = "heart"

ROLE_EM_MANAGER

The role defined for the manager of this contract

bytes32 public constant ROLE_EM_MANAGER = "em_manager"

ENABLE_PARAMS_LENGTH

The length of the EnableParams struct in bytes

uint256 internal constant ENABLE_PARAMS_LENGTH = 224

rateChange

active base emissions rate change information

active until daysLeft is 0

BaseRateChange public rateChange

TRSRY

TRSRYv1 public TRSRY

PRICE

PRICEv1 public PRICE

MINTR

MINTRv1 public MINTR

CHREG

CHREGv1 public CHREG

ohm

ERC20 public immutable ohm

gohm

IgOHM public immutable gohm

reserve

ERC20 public immutable reserve

sReserve

ERC4626 public immutable sReserve

bondAuctioneer

IBondSDA public bondAuctioneer

teller

address public teller

cdAuctioneer

IConvertibleDepositAuctioneer public cdAuctioneer

baseEmissionRate

The base emission rate, in OHM scale.

e.g. 2e5 = 0.02%

uint256 public baseEmissionRate

minimumPremium

The minimum premium for bond markets created by the manager, in terms of ONE_HUNDRED_PERCENT.

A minimum premium of 1e18 would require the market price to be 100% above the backing price (i.e. double).

uint256 public minimumPremium

vestingPeriod

The vesting period for bond markets created by the manager, in seconds.

Initialized at 0, which means no vesting.

uint48 public vestingPeriod

backing

The backed price of OHM, in reserve scale.

uint256 public backing

beatCounter

Used to track the number of beats that have occurred.

uint8 public beatCounter

activeMarketId

The ID of the active bond market (or 0)

uint256 public activeMarketId

tickSize

The fixed tick size for CD auctions, in OHM scale (9 decimals)

uint256 public tickSize

minPriceScalar

The multiplier applied to the price, in terms of ONE_HUNDRED_PERCENT

The value must be greater than or equal to ONE_HUNDRED_PERCENT (100%)

uint256 public minPriceScalar

bondMarketCapacityScalar

The multiplier applied to bond market capacity from auction remainders, in terms of ONE_HUNDRED_PERCENT

The value must be between 0 and MAX_BOND_MARKET_CAPACITY_SCALAR (0-200%)

uint256 public bondMarketCapacityScalar

_oracleDecimals

uint8 internal _oracleDecimals

_ohmDecimals

uint8 internal immutable _ohmDecimals

_gohmDecimals

uint8 internal immutable _gohmDecimals

_reserveDecimals

uint8 internal immutable _reserveDecimals

shutdownTimestamp

timestamp of last shutdown

uint48 public shutdownTimestamp

restartTimeframe

time in seconds that the manager needs to be restarted after a shutdown, otherwise it must be re-initialized

uint48 public restartTimeframe

bondMarketPendingCapacity

In situations where a bond market cannot be created, this variable is used to record the OHM capacity for the bond market that needs to be created

uint256 public bondMarketPendingCapacity

Functions

constructor

constructor(
Kernel kernel_,
address ohm_,
address gohm_,
address reserve_,
address sReserve_,
address bondAuctioneer_,
address cdAuctioneer_,
address teller_
) Policy(kernel_);

configureDependencies

Define module dependencies for this policy.

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

Returns

NameTypeDescription
dependenciesKeycode[]- Keycode array of module dependencies.

requestPermissions

Function called by kernel to set module function permissions.

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

Returns

NameTypeDescription
permissionsPermissions[]requests - Array of keycodes and function selectors for requested permissions.

VERSION

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

execute

Executes the periodic task

This function performs the following:

  • Adjusts the beat counter
  • Exits if the beat counter is not 0
  • Sets the parameters for the auction
  • If the auction tracking period has finished and there is a deficit of OHM sold, attempts to create a bond market
  • If market creation fails (external dependency), emits BondMarketCreationFailed and continues execution Notes:
  • If the CD auction is not running (e.g. the auctioneer contract is disabled), this function will consider OHM to have been under-sold across the auction tracking period. This will result in a bond market being created at the end of the auction tracking period in an attempt to sell the remaining OHM.
  • If there are delays in the heartbeat (which calls this function), auction result tracking will be affected.
function execute() external onlyRole(ROLE_HEART);

_enable

Implementation-specific enable function

This function expects the parameters to be an abi-encoded EnableParams struct

function _enable(bytes calldata params_) internal override;

Parameters

NameTypeDescription
params_bytes

callback

callback function for bond market, only callable by the teller

function callback(uint256 id_, uint256 inputAmount_, uint256 outputAmount_) external;

_createMarket

create bond protocol market with given budget

function _createMarket(uint256 saleAmount) internal;

Parameters

NameTypeDescription
saleAmountuint256amount of DAI to fund bond market with

_updateBacking

allow emission manager to update backing price based on new supply and reserves added

function _updateBacking(uint256 supplyAdded, uint256 reservesAdded) internal;

Parameters

NameTypeDescription
supplyAddeduint256number of new OHM minted
reservesAddeduint256number of new DAI added

_getPriceDecimals

Helper function to calculate number of price decimals based on the value returned from the price feed.

function _getPriceDecimals(uint256 price_) internal view returns (int8);

Parameters

NameTypeDescription
price_uint256The price to calculate the number of decimals for

Returns

NameTypeDescription
<none>int8The number of decimals

_onlyAdminOrEmManagerRole

Reverts if the caller does not have the admin or em_manager role

function _onlyAdminOrEmManagerRole() internal view;

onlyAdminOrEmManagerRole

modifier onlyAdminOrEmManagerRole() ;

_disable

Implementation-specific disable function

This function performs the following:

  • Sets the shutdown timestamp
  • Closes the active bond market (if it is active)
  • Disables the convertible deposit auction
function _disable(bytes calldata) internal override;

Parameters

NameTypeDescription
<none>bytes

restart

Restart the emission manager

This function reverts if:

  • The caller does not have the admin role
  • The restart timeframe has passed since shutdown
function restart() external onlyAdminRole;

rescue

Rescue any ERC20 token sent to this contract and send it to the TRSRY

This function is restricted to the ADMIN role

function rescue(address token_) external onlyAdminRole;

Parameters

NameTypeDescription
token_addressThe address of the ERC20 token to rescue

changeBaseRate

Set the base emissions rate

This function reverts if:

  • The caller does not have the admin or em_manager role
  • There is an underflow or overflow on adjustments
function changeBaseRate(uint256 changeBy_, uint48 forNumBeats_, bool add) external onlyAdminOrEmManagerRole;

Parameters

NameTypeDescription
changeBy_uint256uint256 added or subtracted from baseEmissionRate
forNumBeats_uint48uint256 number of times to change baseEmissionRate by changeBy_
addboolbool determining addition or subtraction to baseEmissionRate

setMinimumPremium

Set the minimum premium for emissions

This function reverts if:

  • The caller does not have the admin or em_manager role
  • newMinimumPremium_ is 0
function setMinimumPremium(uint256 newMinimumPremium_) external onlyAdminOrEmManagerRole;

Parameters

NameTypeDescription
newMinimumPremium_uint256The new minimum premium, in terms of ONE_HUNDRED_PERCENT

setVestingPeriod

Set the new bond vesting period in seconds

This function reverts if:

  • The caller does not have the admin role
  • newVestingPeriod_ is more than 31536000 (1 year in seconds)
function setVestingPeriod(uint48 newVestingPeriod_) external onlyAdminRole;

Parameters

NameTypeDescription
newVestingPeriod_uint48uint48

setBacking

Allow governance to adjust backing price if deviated from reality

This function reverts if:

  • The caller does not have the admin role
  • newBacking is 0
  • newBacking is less than 90% of current backing (to prevent large sudden drops) Note: if adjustment is more than 33% down, contract should be redeployed
function setBacking(uint256 newBacking) external onlyAdminRole;

Parameters

NameTypeDescription
newBackinguint256to adjust to TODO maybe put in a timespan arg so it can be smoothed over time if desirable

setRestartTimeframe

Allow governance to adjust the timeframe for restart after shutdown

This function reverts if:

  • The caller does not have the admin role
  • newTimeframe is 0
function setRestartTimeframe(uint48 newTimeframe) external onlyAdminRole;

Parameters

NameTypeDescription
newTimeframeuint48to adjust it to

setBondContracts

allow governance to set the bond contracts used by the emission manager

This function reverts if:

  • The caller does not have the admin role
  • bondAuctioneer_ is the zero address
  • teller_ is the zero address
function setBondContracts(address bondAuctioneer_, address teller_) external onlyAdminRole;

Parameters

NameTypeDescription
bondAuctioneer_addressaddress of the bond auctioneer contract
teller_addressaddress of the bond teller contract

setCDAuctionContract

Allow governance to set the CD contract used by the emission manager

This function reverts if:

  • The caller does not have the admin role
  • cdAuctioneer_ is the zero address
  • The deposit asset of the CDAuctioneer is not the same as the reserve asset in this contract
function setCDAuctionContract(address cdAuctioneer_) external onlyAdminRole;

Parameters

NameTypeDescription
cdAuctioneer_addressaddress of the cd auctioneer contract

setTickSize

Allow governance to set the CD tick size

This function reverts if:

  • The caller does not have the admin or em_manager role
  • newTickSize_ is 0
function setTickSize(uint256 newTickSize_) external onlyAdminOrEmManagerRole;

Parameters

NameTypeDescription
newTickSize_uint256as a fixed amount in OHM decimals (9)

setMinPriceScalar

Allow governance to set the CD minimum price scalar

This function reverts if:

  • The caller does not have the admin or em_manager role
  • newScalar is less than ONE_HUNDRED_PERCENT (100% in 18 decimals)
function setMinPriceScalar(uint256 newScalar) external onlyAdminOrEmManagerRole;

Parameters

NameTypeDescription
newScalaruint256as a percentage in 18 decimals

setBondMarketCapacityScalar

Allow governance to set the bond market capacity scalar, which acts as a multiplier for the bond market capacity

This function reverts if:

  • The caller does not have the admin or em_manager role
  • newScalar is greater than MAX_BOND_MARKET_CAPACITY_SCALAR (200%)
function setBondMarketCapacityScalar(uint256 newScalar) external onlyAdminOrEmManagerRole;

Parameters

NameTypeDescription
newScalaruint256as a percentage in 18 decimals

getReserves

return reserves, measured as clearinghouse receivables and sReserve balances, in reserve denomination

function getReserves() public view returns (uint256 reserves);

getSupply

return supply, measured as supply of gOHM in OHM denomination

function getSupply() public view returns (uint256 supply);

getPremium

return the current premium as a percentage where 1e18 is 100%

function getPremium() public view returns (uint256);

getNextEmission

return the next sale amount, premium, emission rate, and emissions based on the current premium

function getNextEmission() public view returns (uint256 premium, uint256 emissionRate, uint256 emission);

getSizeFor

Get the auction tick size for a given target

Returns the standard tick size if the target emission is at least the standard tick size. Otherwise, 0 is returned to indicate that the auction should be disabled.

function getSizeFor(uint256 target) public view returns (uint256 size);

Parameters

NameTypeDescription
targetuint256size of day's CD auction

Returns

NameTypeDescription
sizeuint256of tick

getMinPriceFor

Get CD auction minimum price for a given price input

Expects price to already be expressed in the reserve asset's decimal scale. This function does not adjust/convert decimal scales.

function getMinPriceFor(uint256 price) public view returns (uint256);

Parameters

NameTypeDescription
priceuint256Price of OHM in reserve token terms, scaled to the reserve asset's decimals

_getCurrentPrice

Returns the current price from the PRICE module

function _getCurrentPrice() internal view returns (uint256);

Returns

NameTypeDescription
<none>uint256currentPrice with decimal scale of the reserve asset

createPendingBondMarket

Creates a bond market

Notes:

  • If there is no pending capacity, no bond market will be created This function will revert if:
  • The caller is not this contract, or an address with the admin/manager role
  • The contract is disabled
  • The bond market cannot be created
function createPendingBondMarket() external onlyEnabled;

supportsInterface

function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(PolicyEnabler, IPeriodicTask)
returns (bool);