PriceRiskModule

PriceRiskModule is a Risk Module that triggers the payout if the price of an asset is lower or higher than a set trigger price. It's not part of the core Ensuro repository but an extension with its own repository.

The loss probability is determined by a cumulative distribution function f(currentPrice,targetPrice,duration)f(currentPrice, targetPrice, duration), which is the probability that the price will reach the target within that duration.

The function is pre-computed offchain and loaded into the contract as an array of histograms, one for each duration in hours.

Roles

The specific roles and functions of the contract are as follows:

RoleGlobal*DescriptionMethds Accessible

PRICER_ROLE

Sets the pricing.

  • setCDF: Sets the probability distribution for a given policy duration.

ORACLE_ADMIN_ROLE

Sets the pricing oracle.

  • setMinDuration: Sets the minimum duration before a policy can be activated.

  • setOracle: Changes the pricing oracle used by the risk module.

( * ) Global means that the role can be delegated to a user at the protocol level (for all components) or only for a specific component. Non-global roles can only be granted for a specific component.

Parameters

FieldTypeDescription

assetOracle

address (AggregatorV3Interface)

Address of the Chainlink price feed oracle for the asset. Immutable

referenceOracle (optional)

address (AggregatorV3Interface)

Address of the Chainlink price feed oracle for the reference asset. If address(0), the price will be computed in the oracle denomination. If non zero, it has to be in the same denomination as the assetOracle param. Immutable

slotSize

uint256 (wad)

There's a fixed number of slots for the histograms (40) but the slot size can be set at contract initialization to accommodate different requirements.

oracleTolerance

uint40 (seconds)

This is the maximum accepted age of the price data provided by the oracles.

minDuration

uint40 (seconds)

The minimum time that must elapse before a policy can be triggered, since the policy creation.

Important Notice: the contract has no way of verifying that both oracles have the same denomination, users will have to make sure of that when deploying. A deployment audit by a reputable third party is highly recommended.

External Methods

newPolicy

function newPolicy(uint256 triggerPrice, bool lower, uint256 payout, uint40 expiration) external returns (uint256)
NameTypeDescription

triggerPrice

uint256

Price of the asset that will trigger the policy (expressed in the reference currency)

lower

bool

If true -> triggers if the price is lower

If false -> triggers if the price is higher

payout

uint256

Expressed in policyPool.currency()

expiration

uint40

The policy expiration timestamp

onBehalfOf

address

The address that will own the new policy

NameTypeDescription

policyId

uint256

The policy id

triggerPolicy

function triggerPolicy(uint256 policyId) external

Triggers the policy if the triggerPrice has been reached, provided that the policy is active and minDuration has elapsed.

pricePolicy

function pricePolicy(uint256 triggerPrice, bool lower, uint256 payout, uint40 expiration) external view returns (uint256 premium, uint256 lossProb)

Returns the premium and lossProb of the policy

NameTypeDescription

triggerPrice

uint256

Price of the asset that will trigger the policy (expressed in the reference currency)

lower

bool

If true -> triggers if the price is lower, If false -> triggers if the price is higher

payout

uint256

Expressed in policyPool.currency()

expiration

uint40

Expiration of the policy

NameTypeDescription

premium

uint256

Premium that needs to be paid

lossProb

uint256

Probability of paying the maximum payout

setCDF

function setCDF(int40 duration, uint256[30] cdf) external

Sets the probability distribution for a given duration

NameTypeDescription

duration

int40

Duration of the policy in hours (simetric rounding) positive if probability of lower price negative if probability of higher price

cdf

uint256[30]

Array where cdf[i] = prob of price lower/higher than i% of current price

setMinDuration

function setMinDuration(uint40 minDuration)

Sets the minimum duration before a policy can be triggered.

Receives the new minimum duration in seconds.

getCDF

function getCDF(int40 duration) external view returns (uint256[30])

Returns the probability distribution for a given duration

referenceOracle

function referenceOracle() external view override returns (AggregatorV3Interface)

Returns the address for the reference oracle.

assetOracle

function assetOracle() external view override returns (AggregatorV3Interface)

Returns the address for the asset oracle.

minDuration

function minDuration() external view override returns (uint40)

Returns the minimal duration for policies.

oracleTolerance

function oracleTolerance() external view override returns (uint40)

Returns the oracle tolerance.

Last updated