@ensuro/core 2.0.0-beta12 → 2.0.0-beta13

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/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@ensuro/core",
3
3
  "description": "Ensuro - Decentralized insurance protocol",
4
- "version": "2.0.0-beta12",
4
+ "version": "2.0.0-beta13",
5
5
  "files": [
6
6
  "**/*.sol",
7
7
  "/build/contracts/*.json",
8
8
  "/build/interfaces/*.json",
9
- "/js/*.js"
9
+ "/js/*.js",
10
+ "/scripts/*.sh",
11
+ "/scripts/*.js"
10
12
  ],
11
13
  "repository": {
12
14
  "type": "git",
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+
3
+ if [ $# -ne 2 ]; then
4
+ echo "Usage $0 <contracts-dir> <new-pragma>"
5
+ exit 1
6
+ fi
7
+
8
+ CONTRACTS_DIR=$1
9
+ NEW_PRAGMA=$2
10
+
11
+ MD5S=`mktemp`
12
+
13
+ md5sum `find $CONTRACTS_DIR -name "*.sol"` > $MD5S
14
+
15
+ for SOLFILE in `find $CONTRACTS_DIR -name "*.sol"`; do
16
+ sed -i -r "s/^pragma solidity [0-9^~.]+;/pragma solidity $NEW_PRAGMA;/g" $SOLFILE
17
+ done
18
+
19
+ md5sum --check $MD5S | sed 's/: OK/: UNCHANGED/g' | sed 's/: FAILED/: MODIFIED/g' | grep -v "md5sum: "
@@ -0,0 +1,53 @@
1
+ #!/bin/bash
2
+
3
+ source `dirname $0`/utils.sh
4
+
5
+ export DEPLOY_AMOUNT_DECIMALS=6
6
+
7
+ resetAddresses
8
+
9
+ if [ -z $ALCHEMY_URL ]; then
10
+ echo "Must set environment variable $ALCHEMY_URL"
11
+ exit 1
12
+ fi
13
+
14
+ startHHNode --fork $ALCHEMY_URL
15
+
16
+ USDC=0x2791bca1f2de4661ed88a30c99a7a9449aa84174
17
+ AAVE_ADDR_PROV=0xd05e3E715d945B59290df0ae8eF85c1BdB684744 # Polygon Aave
18
+ SWAP_ROUTER=0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506 # Polygon SushiSwap
19
+ PRICE_ORACLE=0x0229f777b0fab107f9591a41d5f02e4e98db6f2d # Polygon Price Oracle of AAVE
20
+ ENSURO_TREASURY=0xFDa400f51aD6490542Bc6336Ea14b2D8bf7b0c34
21
+
22
+ npx hardhat --network $NETWORK deploy $VERIFY --currency-address $USDC \
23
+ --treasury-address $ENSURO_TREASURY || die "Error deploying pool"
24
+
25
+ POOL=`readAddress POOL`
26
+ ACCESSMANAGER=`readAddress ACCESSMANAGER`
27
+ echo "PolicyPool = $POOL / AccessManager = $ACCESSMANAGER"
28
+
29
+ for ROLE in LEVEL1 LEVEL2 LEVEL3; do
30
+ npx hardhat --network $NETWORK ens:grantRole --contract-address $ACCESSMANAGER \
31
+ --role ${ROLE}_ROLE || die "Error granting ${ROLE}_ROLE"
32
+ done
33
+
34
+ npx hardhat --network $NETWORK deploy:eToken \
35
+ --etk-name "Junior ETK" --etk-symbol "eUSDJr" --save-addr JRETK \
36
+ --pool-address $POOL $VERIFY || die "Error deploying eToken"
37
+
38
+ npx hardhat --network $NETWORK deploy:eToken \
39
+ --etk-name "Senior ETK" --etk-symbol "eUSDSr" --save-addr SRETK \
40
+ --pool-address $POOL $VERIFY || die "Error deploying eToken"
41
+
42
+ JRETK=`readAddress JRETK`
43
+ SRETK=`readAddress SRETK`
44
+
45
+ npx hardhat --network $NETWORK deploy:premiumsAccount $VERIFY \
46
+ --junior-etk $JRETK --senior-etk $SRETK \
47
+ --pool-address $POOL || die "Error deploying PremiumsAccount"
48
+
49
+ PREMIUMS_ACCOUNT=`readAddress PA`
50
+
51
+ echo "PremiumsAccount = $PREMIUMS_ACCOUNT"
52
+
53
+ killPID $HHNODE_PID
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+
3
+ source `dirname $0`/utils.sh
4
+
5
+ export DEPLOY_AMOUNT_DECIMALS=6
6
+
7
+ resetAddresses
8
+
9
+ startHHNode
10
+
11
+ ENSURO_TREASURY=0xFDa400f51aD6490542Bc6336Ea14b2D8bf7b0c34
12
+
13
+ npx hardhat --network $NETWORK deploy $VERIFY \
14
+ --treasury-address $ENSURO_TREASURY || die "Error deploying pool"
15
+
16
+ POOL=`readAddress POOL`
17
+ ACCESSMANAGER=`readAddress ACCESSMANAGER`
18
+ echo "PolicyPool = $POOL / AccessManager = $ACCESSMANAGER"
19
+
20
+ for ROLE in LEVEL1 LEVEL2 LEVEL3; do
21
+ npx hardhat --network $NETWORK ens:grantRole --contract-address $ACCESSMANAGER \
22
+ --role ${ROLE}_ROLE || die "Error granting ${ROLE}_ROLE"
23
+ done
24
+
25
+ npx hardhat --network $NETWORK deploy:eToken \
26
+ --etk-name "Junior ETK" --etk-symbol "eUSDJr" --save-addr JRETK \
27
+ --pool-address $POOL $VERIFY || die "Error deploying eToken"
28
+
29
+ npx hardhat --network $NETWORK deploy:eToken \
30
+ --etk-name "Senior ETK" --etk-symbol "eUSDSr" --save-addr SRETK \
31
+ --pool-address $POOL $VERIFY || die "Error deploying eToken"
32
+
33
+ JRETK=`readAddress JRETK`
34
+ SRETK=`readAddress SRETK`
35
+
36
+ npx hardhat --network $NETWORK deploy:premiumsAccount $VERIFY --pool-address $POOL \
37
+ --junior-etk $JRETK --senior-etk $SRETK || die "Error deploying Premiums Account"
38
+
39
+ PREMIUMS_ACCOUNT=`readAddress PA`
40
+
41
+ echo "PremiumsAccount = $PREMIUMS_ACCOUNT"
42
+
43
+ npx hardhat --network $NETWORK deploy:riskModule $VERIFY --pool-address $POOL \
44
+ --pa-address $PREMIUMS_ACCOUNT \
45
+ --wallet 0x951B9B8a7b0e3701E757c015F43df9F2F867B824 || die "Error deploying riskModule"
46
+
47
+ # Whitelist
48
+ npx hardhat --network $NETWORK deploy:whitelist $VERIFY \
49
+ --pool-address $POOL --e-token $SRETK || die "Error deploying Whitelist"
50
+
51
+ killPID $HHNODE_PID
@@ -0,0 +1,33 @@
1
+ const hre = require("hardhat");
2
+ const { artifacts } = require("hardhat");
3
+ const { findAll } = require("solidity-ast/utils");
4
+ const { getStorageLayout } = require("../test/test-utils");
5
+
6
+ /**
7
+ * Script to print a contracts storage layout as a table.
8
+ *
9
+ * Example usage: node scripts/storageLayout.js EToken
10
+ */
11
+
12
+ //
13
+
14
+ async function main(contractSrc, contractName) {
15
+ await hre.run("compile");
16
+ const layout = await getStorageLayout(contractSrc, contractName);
17
+
18
+ const summary = layout.storage.map((item) => ({
19
+ slot: parseInt(item.slot),
20
+ label: item.label,
21
+ type: item.type,
22
+ numberOfBytes: parseInt(layout.types[item.type].numberOfBytes),
23
+ endSlot: parseInt(item.slot) + Math.floor(parseInt(layout.types[item.type].numberOfBytes) / 32),
24
+ }));
25
+ console.table(summary);
26
+ }
27
+
28
+ const [contractSrc, contractName] = [`contracts/${process.argv[2]}.sol`, process.argv[2]];
29
+
30
+ console.log(`Storage layout for ${contractSrc}:${contractName}`);
31
+ main(contractSrc, contractName).then(() => {
32
+ process.exit(0);
33
+ });
@@ -0,0 +1,48 @@
1
+ die() {
2
+ printf "ERROR: %s\n" "$*"
3
+ exit 1
4
+ }
5
+
6
+ dieOnError() {
7
+ if [ $? -ne 0 ]; then
8
+ die $1
9
+ fi
10
+ }
11
+
12
+ export DEPLOY_AMOUNT_DECIMALS=6
13
+
14
+ NETWORK=${NETWORK:-localhost}
15
+
16
+ startHHNode() {
17
+ if [ $NETWORK == "localhost" ]; then
18
+ HHNODE_RUNNING=`ps aux | grep "/.bin/hardhat node" | grep -v grep | cut -c10-15`
19
+ if [ -z $HHNODE_RUNNING ]; then
20
+ START_HHNODE=1
21
+ fi
22
+ fi
23
+
24
+ if [ ! -z $START_HHNODE ]; then
25
+ echo "Starting hardhat node"
26
+ # npx hardhat node $* >/dev/null &
27
+ node_modules/.bin/hardhat node $* >/dev/null &
28
+
29
+ HHNODE_PID=$!
30
+ sleep 5
31
+ kill -0 $HHNODE_PID || die "Error launching hardhat node localhost"
32
+ fi
33
+ }
34
+
35
+ readAddress() {
36
+ python -c "import json; print(json.load(open('.addresses.json'))['$1'])"
37
+ exit $?
38
+ }
39
+
40
+ resetAddresses() {
41
+ python -c "open('.addresses.json', 'wt').write('{}')"
42
+ }
43
+
44
+ killPID() {
45
+ if [ ! -z $1 ]; then
46
+ kill $1
47
+ fi
48
+ }