// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.6;
import "../utils/IERC721Enhanced.sol";
/**
* @title IPolicyManager
* @author solace.fi
* @notice The **PolicyManager** manages the creation of new policies and modification of existing policies.
*
* Most users will not interact with **PolicyManager** directly. To buy, modify, or cancel policies, users should use the respective [**product**](../products/BaseProduct) for the position they would like to cover. Use **PolicyManager** to view policies.
*
* Policies are [**ERC721s**](https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#ERC721).
*/
interface IPolicyManager is IERC721Enhanced {
/***************************************
EVENTS
***************************************/
/// @notice Emitted when a policy is created.
event PolicyCreated(uint256 policyID);
/// @notice Emitted when a policy is updated.
event PolicyUpdated(uint256 indexed policyID);
/// @notice Emitted when a policy is burned.
event PolicyBurned(uint256 policyID);
/// @notice Emitted when the policy descriptor is set.
event PolicyDescriptorSet(address policyDescriptor);
/// @notice Emitted when a new product is added.
event ProductAdded(address product);
/// @notice Emitted when a new product is removed.
event ProductRemoved(address product);
/// @notice Emitted when registry is set.
event RegistrySet(address registry);
/***************************************
POLICY VIEW FUNCTIONS
***************************************/
/// @notice PolicyInfo struct.
struct PolicyInfo {
uint256 coverLimit;
address product;
uint40 expirationBlock;
uint24 price;
bytes positionDescription;
address riskStrategy;
}
/**
* @notice Information about a policy.
* @param policyID The policy ID to return info.
* @return info info in a struct.
*/
function policyInfo(uint256 policyID) external view returns (PolicyInfo memory info);
/**
* @notice Information about a policy.
* @param policyID The policy ID to return info.
* @return policyholder The address of the policy holder.
* @return product The product of the policy.
* @return coverLimit The amount covered for the policy.
* @return expirationBlock The expiration block of the policy.
* @return price The price of the policy.
* @return positionDescription The description of the covered position(s).
* @return riskStrategy The risk strategy of the covered product.
*/
function getPolicyInfo(uint256 policyID) external view returns (address policyholder, address product, uint256 coverLimit, uint40 expirationBlock, uint24 price, bytes calldata positionDescription, address riskStrategy);
/**
* @notice The holder of the policy.
* @param policyID The policy ID.
* @return policyholder The address of the policy holder.
*/
function getPolicyholder(uint256 policyID) external view returns (address policyholder);
/**
* @notice The product used to purchase the policy.
* @param policyID The policy ID.
* @return product The product of the policy.
*/
function getPolicyProduct(uint256 policyID) external view returns (address product);
/**
* @notice The expiration block of the policy.
* @param policyID The policy ID.
* @return expirationBlock The expiration block of the policy.
*/
function getPolicyExpirationBlock(uint256 policyID) external view returns (uint40 expirationBlock);
/**
* @notice The cover limit of the policy.
* @param policyID The policy ID.
* @return coverLimit The cover limit of the policy.
*/
function getPolicyCoverLimit(uint256 policyID) external view returns (uint256 coverLimit);
/**
* @notice The cover price in wei per block per wei multiplied by 1e12.
* @param policyID The policy ID.
* @return price The price of the policy.
*/
function getPolicyPrice(uint256 policyID) external view returns (uint24 price);
/**
* @notice The byte encoded description of the covered position(s).
* Only makes sense in context of the product.
* @param policyID The policy ID.
* @return positionDescription The description of the covered position(s).
*/
function getPositionDescription(uint256 policyID) external view returns (bytes calldata positionDescription);
/**
* @notice Returns the risk strategy of the product in policy.
* @param policyID The policy ID.
* @return strategy The risk strategy address.
*/
function getPolicyRiskStrategy(uint256 policyID) external view returns (address strategy);
/*
* @notice These functions can be used to check a policys stage in the lifecycle.
* There are three major lifecycle events:
* 1 - policy is bought (aka minted)
* 2 - policy expires
* 3 - policy is burnt (aka deleted)
* There are four stages:
* A - pre-mint
* B - pre-expiration
* C - post-expiration
* D - post-burn
* Truth table:
* A B C D
* exists 0 1 1 0
* isActive 0 1 0 0
* hasExpired 0 0 1 0
/**
* @notice Checks if a policy is active.
* @param policyID The policy ID.
* @return status True if the policy is active.
*/
function policyIsActive(uint256 policyID) external view returns (bool);
/**
* @notice Checks whether a given policy is expired.
* @param policyID The policy ID.
* @return status True if the policy is expired.
*/
function policyHasExpired(uint256 policyID) external view returns (bool);
/// @notice The total number of policies ever created.
function totalPolicyCount() external view returns (uint256 count);
/// @notice The address of the [`PolicyDescriptor`](./PolicyDescriptor) contract.
function policyDescriptor() external view returns (address);
/**
* @notice Returns [`Registry`](./Registry) contract address.
* @return registry_ The `Registry` address.
*/
function registry() external view returns (address registry_);
/***************************************
POLICY MUTATIVE FUNCTIONS
***************************************/
/**
* @notice Creates a new policy.
* Can only be called by **products**.
* @param policyholder The receiver of new policy token.
* @param coverLimit The policy coverage amount (in wei).
* @param expirationBlock The policy expiration block number.
* @param price The coverage price.
* @param positionDescription The description of the covered position(s).
* @param riskStrategy The risk strategy of the covered product.
* @return policyID The policy ID.
*/
function createPolicy(
address policyholder,
uint256 coverLimit,
uint40 expirationBlock,
uint24 price,
bytes calldata positionDescription,
address riskStrategy
) external returns (uint256 policyID);
/**
* @notice Modifies a policy.
* Can only be called by **products**.
* @param policyID The policy ID.
* @param coverLimit The policy coverage amount (in wei).
* @param expirationBlock The policy expiration block number.
* @param price The coverage price.
* @param positionDescription The description of the covered position(s).
* @param riskStrategy The risk strategy of the covered positions(s).
*/
function setPolicyInfo(uint256 policyID, uint256 coverLimit, uint40 expirationBlock, uint24 price, bytes calldata positionDescription, address riskStrategy) external;
/**
* @notice Modifies a policy without position description value.
* Can only be called by **products**.
* @param policyID The policy ID.
* @param coverLimit The policy coverage amount (in wei).
* @param expirationBlock The policy expiration block number.
* @param price The coverage price.
*/
function updatePolicyInfo(uint256 policyID, uint256 coverLimit, uint40 expirationBlock, uint24 price) external;
/**
* @notice Burns expired or cancelled policies.
* Can only be called by **products**.
* @param policyID The ID of the policy to burn.
*/
function burn(uint256 policyID) external;
/**
* @notice Burns expired policies.
* @param policyIDs The list of expired policies.
*/
function updateActivePolicies(uint256[] calldata policyIDs) external;
/***************************************
PRODUCT VIEW FUNCTIONS
***************************************/
/**
* @notice Checks is an address is an active product.
* @param product The product to check.
* @return status True if the product is active.
*/
function productIsActive(address product) external view returns (bool status);
/**
* @notice Returns the number of products.
* @return count The number of products.
*/
function numProducts() external view returns (uint256 count);
/**
* @notice Returns the product at the given index.
* @param productNum The index to query.
* @return product The address of the product.
*/
function getProduct(uint256 productNum) external view returns (address product);
/***************************************
GOVERNANCE FUNCTIONS
***************************************/
/**
* @notice Adds a new product.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @param product the new product
*/
function addProduct(address product) external;
/**
* @notice Removes a product.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @param product the product to remove
*/
function removeProduct(address product) external;
/**
* @notice Set the token descriptor.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @param policyDescriptor The new token descriptor address.
*/
function setPolicyDescriptor(address policyDescriptor) external;
/**
* @notice Sets the [`Registry`](./Registry) contract address.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @param registry_ The address of `Registry` contract.
*/
function setRegistry(address registry_) external;
} |