@ensuro/core 1.2.6 → 2.0.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -17
- package/build/contracts/EToken.sol/EToken.json +163 -173
- package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +112 -315
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +34 -2
- package/build/contracts/Policy.sol/Policy.json +2 -2
- package/build/contracts/PolicyNFT.sol/PolicyNFT.json +16 -3
- package/build/contracts/PolicyPool.sol/PolicyPool.json +105 -351
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +32 -0
- package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +77 -98
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +761 -0
- package/build/contracts/{BaseAssetManager.sol/BaseAssetManager.json → Reserve.sol/Reserve.json} +23 -191
- package/build/contracts/RiskModule.sol/RiskModule.json +94 -302
- package/build/contracts/TimeScaled.sol/TimeScaled.json +24 -0
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +142 -325
- package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +15 -2
- package/build/contracts/dependencies/ERC1967Proxy.sol/ERC1967Proxy.json +64 -0
- package/build/{interfaces/IExchange.sol/IExchange.json → contracts/dependencies/IERC20Metadata.sol/IERC20Metadata.json} +83 -79
- package/build/{interfaces → contracts/interfaces}/IEToken.sol/IEToken.json +32 -97
- package/build/{interfaces → contracts/interfaces}/ILPWhitelist.sol/ILPWhitelist.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyHolder.sol/IPolicyHolder.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyNFT.sol/IPolicyNFT.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyPool.sol/IPolicyPool.json +121 -108
- package/build/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyPoolConfig.sol/IPolicyPoolConfig.json +20 -49
- package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +302 -0
- package/build/{interfaces → contracts/interfaces}/IRiskModule.sol/IRiskModule.json +58 -34
- package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +43 -0
- package/build/{interfaces/IInsolvencyHook.sol/IInsolvencyHook.json → contracts/mocks/IMintableERC20.sol/IMintableERC20.json} +13 -8
- package/build/contracts/mocks/LinkTokenMock.sol/LinkTokenMock.json +370 -0
- package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +202 -0
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +35 -0
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +603 -0
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +92 -0
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +343 -0
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +388 -0
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +16 -3
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +16 -3
- package/contracts/EToken.sol +210 -267
- package/contracts/FlightDelayRiskModule.sol +30 -21
- package/contracts/LPManualWhitelist.sol +4 -4
- package/contracts/Policy.sol +48 -44
- package/contracts/PolicyNFT.sol +2 -2
- package/contracts/PolicyPool.sol +114 -467
- package/contracts/PolicyPoolComponent.sol +14 -3
- package/contracts/PolicyPoolConfig.sol +29 -91
- package/contracts/PremiumsAccount.sol +274 -0
- package/contracts/Reserve.sol +34 -0
- package/contracts/RiskModule.sol +216 -164
- package/contracts/TimeScaled.sol +134 -0
- package/contracts/TrustfulRiskModule.sol +23 -21
- package/contracts/dependencies/ERC1967Proxy.sol +19 -0
- package/contracts/dependencies/IERC20Metadata.sol +19 -0
- package/contracts/interfaces/IEToken.sol +172 -0
- package/{interfaces → contracts/interfaces}/ILPWhitelist.sol +0 -0
- package/{interfaces → contracts/interfaces}/IPolicyHolder.sol +0 -0
- package/{interfaces → contracts/interfaces}/IPolicyNFT.sol +0 -0
- package/contracts/interfaces/IPolicyPool.sol +138 -0
- package/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol +0 -0
- package/{interfaces → contracts/interfaces}/IPolicyPoolConfig.sol +31 -22
- package/contracts/interfaces/IPremiumsAccount.sol +71 -0
- package/contracts/interfaces/IRiskModule.sol +60 -0
- package/contracts/mocks/ForwardProxy.sol +66 -0
- package/contracts/mocks/IMintableERC20.sol +13 -0
- package/contracts/mocks/LinkTokenMock.sol +30 -0
- package/contracts/mocks/PolicyHolderMock.sol +68 -0
- package/contracts/mocks/PolicyPoolComponentMock.sol +17 -0
- package/contracts/mocks/PolicyPoolMock.sol +122 -0
- package/contracts/mocks/TestCurrency.sol +35 -0
- package/contracts/mocks/TestNFT.sol +23 -0
- package/contracts/upgraded/PolicyNFTv1.sol +1 -1
- package/js/test-utils.js +278 -0
- package/package.json +2 -2
- package/build/contracts/AaveAssetManager.sol/AaveAssetManager.json +0 -723
- package/build/contracts/DataTypes.sol/DataTypes.json +0 -10
- package/build/contracts/Exchange.sol/Exchange.json +0 -546
- package/build/contracts/extras/IPriceRiskModule.sol/IPriceRiskModule.json +0 -253
- package/build/contracts/extras/PriceRiskModule.sol/PriceRiskModule.json +0 -1036
- package/build/interfaces/IAssetManager.sol/IAssetManager.json +0 -31
- package/build/interfaces/IExchange.sol/IPriceOracle.json +0 -30
- package/contracts/AaveAssetManager.sol +0 -298
- package/contracts/BaseAssetManager.sol +0 -301
- package/contracts/DataTypes.sol +0 -287
- package/contracts/Exchange.sol +0 -173
- package/contracts/extras/IPriceRiskModule.sol +0 -41
- package/contracts/extras/PriceRiskModule.sol +0 -243
- package/interfaces/IAssetManager.sol +0 -23
- package/interfaces/IEToken.sol +0 -48
- package/interfaces/IExchange.sol +0 -59
- package/interfaces/IInsolvencyHook.sol +0 -27
- package/interfaces/IPolicyPool.sol +0 -44
- package/interfaces/IRiskModule.sol +0 -29
package/README.md
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
[](https://github.com/ensuro/ensuro/actions/workflows/tests.yaml)
|
|
2
|
+
[](https://github.com/ensuro/ensuro/actions/workflows/tests.yaml)
|
|
3
|
+
[](https://github.com/ensuro/ensuro/actions/workflows/build-base-image.yaml)
|
|
4
|
+
[](https://github.com/ensuro/ensuro/releases)
|
|
5
|
+
|
|
1
6
|
# Ensuro - Decentralized capital for insurance
|
|
2
7
|
|
|
3
|
-
Ensuro is a decentralized protocol that manages the capital to support insurance products.
|
|
8
|
+
Ensuro is a decentralized protocol that manages the capital to support insurance products.
|
|
4
9
|
|
|
5
|
-
It allows liquidity providers (LPs) to deposit capital (using stable coins) that will fulfill solvency capital requirements of underwritten policies. This capital will be deposited in different pools (
|
|
10
|
+
It allows liquidity providers (LPs) to deposit capital (using stable coins) that will fulfill solvency capital requirements of underwritten policies. This capital will be deposited in different pools (_eTokens_) that are linked to different risks. The capital will be locked for the duration of policies and will report profits to the LPs in the form of continous interest.
|
|
6
11
|
|
|
7
|
-
On the policy side, the policies are injected into the protocol by
|
|
12
|
+
On the policy side, the policies are injected into the protocol by _Risk Modules_. Each risk module represent an Ensuro partner and a specific insurance product and is implemented with a smart contract (inherited from `RiskModule`). Each risk module has two responsabilities: pricing and policy resolution. Also, the RiskModule smart contract stores several parameters of the risk module such as Ensuro and Risk Module fees, capital allocation limits, etc.
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
Each policy sold and active it's a _risk_ or potential loss, a random variable that goes from 0 (no losses) to the maximum payout defined in the policy. The solvency capital to cover these risks comes from two sources:
|
|
10
15
|
|
|
16
|
+
- **pure premiums**: the part of the premium that's equal to the estimated mean of the risk random variable (expected losses), paid by the policy holder.
|
|
17
|
+
- **scr**: the rest of the solvency capital (unexpected losses), required to be able to cover the risks with a given _confidence level_, is locked from the _eTokens_.
|
|
18
|
+
|
|
19
|
+

|
|
11
20
|
|
|
12
21
|
## Contracts
|
|
22
|
+
|
|
13
23
|
<dl>
|
|
14
24
|
<dt>PolicyPool</dt>
|
|
15
25
|
<dd>This is the main contract that keeps track of active policies and manages the assets. It has the methods for LP to deposit/withdraw. The PolicyPool is connected to a set of eTokens and RiskModules.</dd>
|
|
@@ -22,7 +32,7 @@ On the policy side, the policies are injected into the protocol by *Risk Modules
|
|
|
22
32
|
|
|
23
33
|
<dl>
|
|
24
34
|
<dt>PolicyPoolConfig</dt>
|
|
25
|
-
<dd>This contract holds some configurable components of the protocol such as treasury address
|
|
35
|
+
<dd>This contract holds some configurable components of the protocol such as treasury address and the installed risk modules. Also this module holds the access control permissions for the governance actions.</dd>
|
|
26
36
|
</dl>
|
|
27
37
|
|
|
28
38
|
<dl>
|
|
@@ -33,11 +43,11 @@ On the policy side, the policies are injected into the protocol by *Risk Modules
|
|
|
33
43
|
<dl>
|
|
34
44
|
<dt>RiskModule</dt>
|
|
35
45
|
<dd>This is a base contract that needs to be reimplemented with the specific logic related with custom policy parameters, validation of the received price and with different strategies for policy resolution (e.g. using oracles). This is the contract that must be called by a customer for creating a new policy that, after doing validations and storing parameters needed for resolution, will submit the new policy to the PolicyPool.</dd>
|
|
36
|
-
|
|
46
|
+
</dl>
|
|
37
47
|
|
|
38
48
|
<dl>
|
|
39
|
-
<dt>
|
|
40
|
-
<dd>
|
|
49
|
+
<dt>PremiumsAccount</dt>
|
|
50
|
+
<dd>The risk modules are grouped in *premiums accounts* that keep track of the pure premiums (active and earned) their policies. The responsability of these contracts is keeping track of the premiums and releasing the payouts. When premiums are exhausted (losses more than expected), they borrow money from the *eTokens* to cover the payouts. This money will be repaid when/if later the premiums account has surplus (losses less than expected).</dd>
|
|
41
51
|
</dl>
|
|
42
52
|
|
|
43
53
|
<dl>
|
|
@@ -45,17 +55,11 @@ On the policy side, the policies are injected into the protocol by *Risk Modules
|
|
|
45
55
|
<dd>This is an optional component. If present it controls which Liquidity Providers can deposit or transfer their <i>eTokens</i>.</dd>
|
|
46
56
|
</dl>
|
|
47
57
|
|
|
48
|
-
<dl>
|
|
49
|
-
<dt>InsolvencyHook</dt>
|
|
50
|
-
<dd>This component of the protocol is the one responsible for handling situations where there is not enough money in the protocol to cover losses (something unlikely but possible, since we aren't fully collaterized). Possible implementations of this are trigger of reinsurance (excess loss) policy from another company, sell governance tokens or take a loan.</dd>
|
|
51
|
-
</dl>
|
|
52
|
-
|
|
53
58
|
<dl>
|
|
54
59
|
<dt>Policy</dt>
|
|
55
60
|
<dd>This is a library with the struct and the calculation of relevant attributes of a policy. It includes the logic around the distribution of the premium, calculation of SCR, shared coverage and other behaviour of the protocol.</dd>
|
|
56
61
|
</dl>
|
|
57
62
|
|
|
58
|
-
|
|
59
63
|
## Governance
|
|
60
64
|
|
|
61
65
|
The protocol uses three levels of access control, plus a guardian role. The roles are managed by the PolicyPoolConfig smart contract.
|
|
@@ -66,9 +70,37 @@ More info about governance in https://docs.google.com/spreadsheets/d/1LqlogRn8Al
|
|
|
66
70
|
|
|
67
71
|
For coding the smart contracts the approach we took was prototyping initially in Python (see folder `prototype`), and later we coded in Solidity. The tests run the same test case both on the Python prototype code and the Solidity code. To adapt the Solidity code that is called using [brownie](https://eth-brownie.readthedocs.io/en/stable/), we have some glue code implemented in `tests/wrappers.py`.
|
|
68
72
|
|
|
73
|
+
### Without docker
|
|
74
|
+
|
|
75
|
+
You can also run the development environment without using docker, just Python (>=3.9) and Node v16 are required as pre-requisits.
|
|
76
|
+
|
|
77
|
+
Initial setup:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Setup a virtualenv
|
|
81
|
+
python3 -m venv venv
|
|
82
|
+
source venv/bin/activate
|
|
83
|
+
# Install python dependencies
|
|
84
|
+
pip install -r requirements.txt
|
|
85
|
+
pip install -r requirements-dev.txt
|
|
86
|
+
# Install javascript dependencies
|
|
87
|
+
nvm use # To change to node v16
|
|
88
|
+
npm install
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Then, you can run the tests with:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
brownie test -v
|
|
95
|
+
npx hardhat test
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Using docker
|
|
99
|
+
|
|
69
100
|
The development environment is prepared for running inside a docker container defined in the Dockerfile. Also you can launch the docker environment using [invoke tasks](http://www.pyinvoke.org/), but before you need to run `pip install inv-py-docker-k8s-tasks` to install a package with common tasks for coding inside docker. Then with `inv start-dev` you should be able to launch the docker environment. Then you can run specific tasks:
|
|
70
|
-
|
|
71
|
-
- `inv
|
|
101
|
+
|
|
102
|
+
- `inv test`: runs the test suite
|
|
103
|
+
- `inv shell`: opens a shell inside the docker container
|
|
72
104
|
|
|
73
105
|
Also the docker container is prepared to run [hardhat](https://hardhat.org/). This will be used probably for deployment scripts and perhaps some aditional tests.
|
|
74
106
|
|
|
@@ -85,7 +117,7 @@ Please note we have a [Code of Conduct](CODE_OF_CONDUCT.md), please follow it in
|
|
|
85
117
|
|
|
86
118
|
## Authors
|
|
87
119
|
|
|
88
|
-
|
|
120
|
+
- _Guillermo M. Narvaja_
|
|
89
121
|
|
|
90
122
|
## License
|
|
91
123
|
|