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 , 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:
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
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
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
policyId
uint256
The policy id
triggerPolicy
Triggers the policy if the triggerPrice
has been reached, provided that the policy is active and minDuration
has elapsed.
pricePolicy
Returns the premium and lossProb of the policy
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
premium
uint256
Premium that needs to be paid
lossProb
uint256
Probability of paying the maximum payout
setCDF
Sets the probability distribution for a given duration
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
Sets the minimum duration before a policy can be triggered.
Receives the new minimum duration in seconds.
getCDF
Returns the probability distribution for a given duration
referenceOracle
Returns the address for the reference oracle.
assetOracle
Returns the address for the asset oracle.
minDuration
Returns the minimal duration for policies.
oracleTolerance
Returns the oracle tolerance.
Last updated