@ensuro/core 1.2.7 → 2.0.0-beta1

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.
Files changed (92) hide show
  1. package/README.md +44 -17
  2. package/build/contracts/EToken.sol/EToken.json +122 -177
  3. package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +101 -323
  4. package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +15 -2
  5. package/build/contracts/Policy.sol/Policy.json +2 -2
  6. package/build/contracts/PolicyNFT.sol/PolicyNFT.json +16 -3
  7. package/build/contracts/PolicyPool.sol/PolicyPool.json +105 -351
  8. package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +13 -0
  9. package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +77 -72
  10. package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +761 -0
  11. package/build/contracts/{BaseAssetManager.sol/BaseAssetManager.json → Reserve.sol/Reserve.json} +15 -202
  12. package/build/contracts/RiskModule.sol/RiskModule.json +83 -310
  13. package/build/contracts/TimeScaled.sol/TimeScaled.json +24 -0
  14. package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +131 -333
  15. package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +15 -2
  16. package/build/contracts/dependencies/ERC1967Proxy.sol/ERC1967Proxy.json +64 -0
  17. package/build/{interfaces/IExchange.sol/IExchange.json → contracts/dependencies/IERC20Metadata.sol/IERC20Metadata.json} +83 -79
  18. package/build/{interfaces → contracts/interfaces}/IEToken.sol/IEToken.json +32 -97
  19. package/build/{interfaces → contracts/interfaces}/ILPWhitelist.sol/ILPWhitelist.json +1 -1
  20. package/build/{interfaces → contracts/interfaces}/IPolicyHolder.sol/IPolicyHolder.json +1 -1
  21. package/build/{interfaces → contracts/interfaces}/IPolicyNFT.sol/IPolicyNFT.json +1 -1
  22. package/build/{interfaces → contracts/interfaces}/IPolicyPool.sol/IPolicyPool.json +121 -108
  23. package/build/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +1 -1
  24. package/build/{interfaces → contracts/interfaces}/IPolicyPoolConfig.sol/IPolicyPoolConfig.json +20 -36
  25. package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +302 -0
  26. package/build/{interfaces → contracts/interfaces}/IRiskModule.sol/IRiskModule.json +58 -34
  27. package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +43 -0
  28. package/build/{interfaces/IInsolvencyHook.sol/IInsolvencyHook.json → contracts/mocks/IMintableERC20.sol/IMintableERC20.json} +13 -8
  29. package/build/contracts/mocks/LinkTokenMock.sol/LinkTokenMock.json +370 -0
  30. package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +202 -0
  31. package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +35 -0
  32. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +603 -0
  33. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +92 -0
  34. package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +343 -0
  35. package/build/contracts/mocks/TestCurrencyUUPS.sol/TestCurrencyUUPS.json +353 -0
  36. package/build/contracts/mocks/TestNFT.sol/TestNFT.json +388 -0
  37. package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +16 -3
  38. package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +16 -3
  39. package/contracts/EToken.sol +188 -269
  40. package/contracts/FlightDelayRiskModule.sol +30 -21
  41. package/contracts/LPManualWhitelist.sol +3 -3
  42. package/contracts/Policy.sol +48 -44
  43. package/contracts/PolicyNFT.sol +2 -2
  44. package/contracts/PolicyPool.sol +114 -467
  45. package/contracts/PolicyPoolComponent.sol +8 -3
  46. package/contracts/PolicyPoolConfig.sol +30 -73
  47. package/contracts/PremiumsAccount.sol +274 -0
  48. package/contracts/Reserve.sol +34 -0
  49. package/contracts/RiskModule.sol +216 -164
  50. package/contracts/TimeScaled.sol +134 -0
  51. package/contracts/TrustfulRiskModule.sol +23 -21
  52. package/contracts/dependencies/ERC1967Proxy.sol +19 -0
  53. package/contracts/dependencies/IERC20Metadata.sol +19 -0
  54. package/contracts/interfaces/IEToken.sol +172 -0
  55. package/{interfaces → contracts/interfaces}/ILPWhitelist.sol +0 -0
  56. package/{interfaces → contracts/interfaces}/IPolicyHolder.sol +0 -0
  57. package/{interfaces → contracts/interfaces}/IPolicyNFT.sol +0 -0
  58. package/contracts/interfaces/IPolicyPool.sol +138 -0
  59. package/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol +0 -0
  60. package/{interfaces → contracts/interfaces}/IPolicyPoolConfig.sol +29 -20
  61. package/contracts/interfaces/IPremiumsAccount.sol +71 -0
  62. package/contracts/interfaces/IRiskModule.sol +60 -0
  63. package/contracts/mocks/ForwardProxy.sol +66 -0
  64. package/contracts/mocks/IMintableERC20.sol +13 -0
  65. package/contracts/mocks/LinkTokenMock.sol +30 -0
  66. package/contracts/mocks/PolicyHolderMock.sol +68 -0
  67. package/contracts/mocks/PolicyPoolComponentMock.sol +17 -0
  68. package/contracts/mocks/PolicyPoolMock.sol +122 -0
  69. package/contracts/mocks/TestCurrency.sol +35 -0
  70. package/contracts/mocks/TestNFT.sol +23 -0
  71. package/contracts/upgraded/PolicyNFTv1.sol +1 -1
  72. package/js/test-utils.js +278 -0
  73. package/package.json +2 -2
  74. package/build/contracts/AaveAssetManager.sol/AaveAssetManager.json +0 -742
  75. package/build/contracts/DataTypes.sol/DataTypes.json +0 -10
  76. package/build/contracts/Exchange.sol/Exchange.json +0 -591
  77. package/build/contracts/extras/IPriceRiskModule.sol/IPriceRiskModule.json +0 -253
  78. package/build/contracts/extras/PriceRiskModule.sol/PriceRiskModule.json +0 -1055
  79. package/build/interfaces/IAssetManager.sol/IAssetManager.json +0 -31
  80. package/build/interfaces/IExchange.sol/IPriceOracle.json +0 -30
  81. package/contracts/AaveAssetManager.sol +0 -298
  82. package/contracts/BaseAssetManager.sol +0 -301
  83. package/contracts/DataTypes.sol +0 -287
  84. package/contracts/Exchange.sol +0 -189
  85. package/contracts/extras/IPriceRiskModule.sol +0 -41
  86. package/contracts/extras/PriceRiskModule.sol +0 -243
  87. package/interfaces/IAssetManager.sol +0 -23
  88. package/interfaces/IEToken.sol +0 -48
  89. package/interfaces/IExchange.sol +0 -59
  90. package/interfaces/IInsolvencyHook.sol +0 -27
  91. package/interfaces/IPolicyPool.sol +0 -44
  92. package/interfaces/IRiskModule.sol +0 -29
package/README.md CHANGED
@@ -1,15 +1,20 @@
1
1
  # Ensuro - Decentralized capital for insurance
2
2
 
3
- Ensuro is a decentralized protocol that manages the capital to support insurance products.
3
+ Ensuro is a decentralized protocol that manages the capital to support insurance products.
4
4
 
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 (*eTokens*) according to provider's cashback period preferences. The capital will be locked for the duration of policies and will report profits to the LPs in the form of continous interest.
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 (_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
6
 
7
- 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.
7
+ 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
8
 
9
- ![Architecture Diagram](Architecture.png "Architecture Diagram")
9
+ 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
+
11
+ - **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.
12
+ - **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_.
10
13
 
14
+ ![Architecture Diagram](Architecture.png "Architecture Diagram")
11
15
 
12
16
  ## Contracts
17
+
13
18
  <dl>
14
19
  <dt>PolicyPool</dt>
15
20
  <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 +27,7 @@ On the policy side, the policies are injected into the protocol by *Risk Modules
22
27
 
23
28
  <dl>
24
29
  <dt>PolicyPoolConfig</dt>
25
- <dd>This contract holds some configurable components of the protocol such as treasury address, InsolvencyHook, AssetManager and the installed risk modules. Also this module holds the access control permissions for the governance actions.</dd>
30
+ <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
31
  </dl>
27
32
 
28
33
  <dl>
@@ -33,11 +38,11 @@ On the policy side, the policies are injected into the protocol by *Risk Modules
33
38
  <dl>
34
39
  <dt>RiskModule</dt>
35
40
  <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
- </dl>
41
+ </dl>
37
42
 
38
43
  <dl>
39
- <dt>AssetManager</dt>
40
- <dd>This component of the protocol is the one responsible for managing the assets and getting additional interest reinvesting the assets. Different implementations of the asset management can be done, depeding on the strategy to be applied. In the base class, has different liquidity parameters that affect how much liquidity to keep in the PolicyPool to avoid continous invest/deinvest operations.</dd>
44
+ <dt>PremiumsAccount</dt>
45
+ <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
46
  </dl>
42
47
 
43
48
  <dl>
@@ -45,17 +50,11 @@ On the policy side, the policies are injected into the protocol by *Risk Modules
45
50
  <dd>This is an optional component. If present it controls which Liquidity Providers can deposit or transfer their <i>eTokens</i>.</dd>
46
51
  </dl>
47
52
 
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
53
  <dl>
54
54
  <dt>Policy</dt>
55
55
  <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
56
  </dl>
57
57
 
58
-
59
58
  ## Governance
60
59
 
61
60
  The protocol uses three levels of access control, plus a guardian role. The roles are managed by the PolicyPoolConfig smart contract.
@@ -66,9 +65,37 @@ More info about governance in https://docs.google.com/spreadsheets/d/1LqlogRn8Al
66
65
 
67
66
  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
67
 
68
+ ### Without docker
69
+
70
+ You can also run the development environment without using docker, just Python (>=3.9) and Node v16 are required as pre-requisits.
71
+
72
+ Initial setup:
73
+
74
+ ```bash
75
+ # Setup a virtualenv
76
+ python3 -m venv venv
77
+ source venv/bin/activate
78
+ # Install python dependencies
79
+ pip install -r requirements.txt
80
+ pip install -r requirements-dev.txt
81
+ # Install javascript dependencies
82
+ nvm use # To change to node v16
83
+ npm install
84
+ ```
85
+
86
+ Then, you can run the tests with:
87
+
88
+ ```bash
89
+ brownie test -v
90
+ npx hardhat test
91
+ ```
92
+
93
+ ### Using docker
94
+
69
95
  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
- - `inv tests`: runs the test suite
71
- - `inv shell`: opens a shell inside the docker container
96
+
97
+ - `inv test`: runs the test suite
98
+ - `inv shell`: opens a shell inside the docker container
72
99
 
73
100
  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
101
 
@@ -85,7 +112,7 @@ Please note we have a [Code of Conduct](CODE_OF_CONDUCT.md), please follow it in
85
112
 
86
113
  ## Authors
87
114
 
88
- * *Guillermo M. Narvaja*
115
+ - _Guillermo M. Narvaja_
89
116
 
90
117
  ## License
91
118