PolicyPool
Last updated
Last updated
The PolicyPool is the main contract that keeps track of active policies and receives the spending allowances. It's a single PolicyPool for each instance of the protocol. One of its attributes is currency()
, which points to the coin (ERC20) used throughout the protocol. So far we support only USDC as currency.
It has methods for LP to deposit/withdraw, acting as a gateway for the eTokens. The PolicyPool is connected to a set of eTokens, premiums accounts, and risk modules.
This contract also follows the ERC721 standard, minting an NFT for each policy created. The owner of the NFT is who will receive the payout in case there's any.
The roles and functions of the contract are as follows:
Role | Description | Methods Accessible |
---|---|---|
One of the responsibilities of the PolicyPool contract is to keep track of active policies with all the (immutable) data.
Given the Policy struct has many fields and storage is expensive on-chain, the struct isn't stored as a storage variable of the contracts.
Instead, when the policy is created, only a hash of the struct is stored and an event with all the fields is emitted. Then, for any operation with the Policy (like resolution or expiration), all the policy needs to be sent as a parameter. The PolicyPool contract computes the hash of the parameter and compares it with the stored one.
The mapping from policyId to hash is stored in the _policies
attribute.
Event emitted every time a new policy is added to the pool. Contains all the data about the policy that is later required for doing operations with the policy like resolution or expiration.
Event emitted every time a policy is removed from the pool. If the policy expired, the payout
is 0, otherwise is the amount transferred to the policyholder.
Event emitted when the treasury changes.
Event emitted when a new component added/removed to the pool or the status changes.
Creates a new Policy. Must be called from an active RiskModule
Requirements:
msg.sender
must be an active RiskModule
caller
approved the spending of currency()
for at least policy.premium
internalId
must be unique within policy.riskModule
and not used before
Events:
{PolicyPool-NewPolicy}: with all the details about the policy
{ERC20-Transfer}: does several transfers from caller address to the different receivers of the premium (see Premium Split in the docs)
Resolves a policy with a payout. Must be called from an active RiskModule
Requirements:
policy
: must be a Policy previously created with newPolicy
(checked with policy.hash()
) and not resolved before and not expired (if payout > 0
).
payout
: must be less than equal to policy.payout
.
Events:
{PolicyPool-PolicyResolved}: with the payout
{ERC20-Transfer}: to the policyholder with the payout
Resolves a policy with a payout that can be either 0 or the maximum payout of the policy
Requirements:
policy
: must be a Policy previously created with newPolicy
(checked with policy.hash()
) and not resolved before and not expired (if customerWon).
Events:
{PolicyPool-PolicyResolved}: with the payout
{ERC20-Transfer}: to the policyholder with the payout
Resolves a policy with a payout 0, unlocking the solvency. Can be called by anyone, but only after Policy.expiration
.
Requirements:
policy
: must be a Policy previously created with newPolicy
(checked with policy.hash()
) and not resolved before
Policy expired: Policy.expiration
<= block.timestamp
Events:
{PolicyPool-PolicyResolved}: with payout == 0
Deposits liquidity into an eToken. Forwards the call to {EToken-deposit}, after transferring the funds. The user will receive etokens for the same amount deposited.
Requirements:
msg.sender
approved the spending of currency()
for at least amount
eToken
is an active eToken installed in the pool.
Events:
{EToken-Transfer}: from 0x0 to msg.sender
, reflects the eTokens minted.
{ERC20-Transfer}: from msg.sender
to address(eToken)
Withdraws an amount from an eToken. Forwards the call to {EToken-withdraw}. amount
of eTokens will be burned and the user will receive the same amount in currency()
.
Requirements:
eToken
is an active (or deprecated) eToken installed in the pool.
Events:
{EToken-Transfer}: from msg.sender
to 0x0
, reflects the eTokens burned.
{ERC20-Transfer}: from address(eToken) to msg.sender
Reference to the {AccessManager} contract, this contract manages the access controls.
Reference to the main currency (ERC20) used in the protocol
Returns the address of the treasury, the one that receives the protocol fees.
Adds a new component (either an {EToken}, {RiskModule} or {PremiumsAccount}) to the protocol. The component status will be active
.
Requirements:
Must be called by a user with the {LEVEL1_ROLE}
The component wasn't added before.
Events:
Emits {ComponentStatusChanged} with status active.
Removes a component from the protocol. The component needs to be in deprecated
status before doing this operation.
Requirements:
Must be called by a user with the {LEVEL1_ROLE}
The component status is deprecated
.
Events:
Emits {ComponentStatusChanged} with status inactive.
Changes the status of a component.
Requirements:
Must be called by a user with the {LEVEL1_ROLE} if the new status is active
or deprecated
.
Must be called by a user with the {GUARDIAN_ROLE} if the new status is suspended
.
Events:
Emits {ComponentStatusChanged} with the new status.
Field | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|