From 6378c4083db66eb0a1ac38227feaeeb5461a4bee Mon Sep 17 00:00:00 2001 From: Daksh Miglani Date: Wed, 21 Apr 2021 13:08:24 +0530 Subject: [PATCH 1/3] change rollup builds and add new tests for common.js as well as es6 dists --- package-lock.json | 204 ++++++--- package.json | 4 +- rollup.config.js | 7 +- test-dist/dsa.node-cjs.spec.js | 36 ++ test-dist/dsa.node.spec.ts | 62 +++ test/dsa.node.spec.ts | 810 --------------------------------- tsconfig.json | 2 +- 7 files changed, 259 insertions(+), 866 deletions(-) create mode 100644 test-dist/dsa.node-cjs.spec.js create mode 100644 test-dist/dsa.node.spec.ts delete mode 100644 test/dsa.node.spec.ts diff --git a/package-lock.json b/package-lock.json index 27371b56..2c5c098f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "dsa-connect", - "version": "0.2.2", + "version": "0.2.0-beta.12", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.2.2", + "version": "0.2.0-beta.12", "license": "MIT", "devDependencies": { "@babel/cli": "^7.10.1", @@ -16,6 +16,7 @@ "@babel/preset-env": "^7.10.2", "@nomiclabs/hardhat-ethers": "^2.0.1", "@nomiclabs/hardhat-web3": "^2.0.0", + "@rollup/plugin-commonjs": "^18.0.0", "@types/jest": "^26.0.14", "babel-loader": "^8.1.0", "babel-preset-minify": "^0.5.0", @@ -751,8 +752,7 @@ "version": "3.6.5", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.5.tgz", "integrity": "sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==", - "dev": true, - "hasInstallScript": true + "dev": true }, "node_modules/@babel/parser": { "version": "7.10.2", @@ -4646,6 +4646,33 @@ "@types/bignumber.js": "^5.0.0" } }, + "node_modules/@rollup/plugin-commonjs": { + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.0.0.tgz", + "integrity": "sha512-fj92shhg8luw7XbA0HowAqz90oo7qtLGwqTKbyZ8pmOyH8ui5e+u0wPEgeHLH3djcVma6gUCUrjY6w5R2o1u6g==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^3.1.0", + "commondir": "^1.0.1", + "estree-walker": "^2.0.1", + "glob": "^7.1.6", + "is-reference": "^1.2.1", + "magic-string": "^0.25.7", + "resolve": "^1.17.0" + }, + "engines": { + "node": ">= 8.0.0" + }, + "peerDependencies": { + "rollup": "^2.30.0" + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "node_modules/@rollup/pluginutils": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", @@ -8342,8 +8369,7 @@ "version": "2.6.11", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", - "dev": true, - "hasInstallScript": true + "dev": true }, "node_modules/core-js-compat": { "version": "3.6.5", @@ -8368,8 +8394,7 @@ "version": "3.9.0", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.9.0.tgz", "integrity": "sha512-3pEcmMZC9Cq0D4ZBh3pe2HLtqxpGNJBLXF/kZ2YzK17RbKp94w0HFbdbSx8H8kAlZG5k76hvLrkPm57Uyef+kg==", - "dev": true, - "hasInstallScript": true + "dev": true }, "node_modules/core-util-is": { "version": "1.0.2", @@ -9705,7 +9730,6 @@ "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz", "integrity": "sha512-epq90L9jlFWCW7+pQa6JOnKn2Xgl2mtI664seYR6MHskvI9agt7AnDqmAlp9TqU4/caMYbA08Hi5DMZAl5zdkA==", "dev": true, - "hasInstallScript": true, "dependencies": { "node-addon-api": "^2.0.0", "node-gyp-build": "^4.2.0" @@ -9719,7 +9743,6 @@ "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz", "integrity": "sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg==", "dev": true, - "hasInstallScript": true, "dependencies": { "elliptic": "^6.5.2", "node-addon-api": "^2.0.0", @@ -10860,7 +10883,6 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.12.tgz", "integrity": "sha512-Ggd/Ktt7E7I8pxZRbGIs7vwqAPscSESMrCSkx2FtWeqmheJgCo2R74fTsZFCifr0VTPwqRpPv17+6b8Zp7th0Q==", "dev": true, - "hasInstallScript": true, "optional": true, "os": [ "darwin" @@ -14050,6 +14072,18 @@ "is-ci": "bin.js" } }, + "node_modules/is-core-module": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz", + "integrity": "sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==", + "dev": true, + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-data-descriptor": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz", @@ -14282,6 +14316,15 @@ "integrity": "sha1-DFLlS8yjkbssSUsh6GJtczbG45c=", "dev": true }, + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/is-regex": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.5.tgz", @@ -16561,15 +16604,6 @@ "node": ">=8" } }, - "node_modules/jest-resolve/node_modules/resolve": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", - "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", - "dev": true, - "dependencies": { - "path-parse": "^1.0.6" - } - }, "node_modules/jest-resolve/node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -18215,7 +18249,6 @@ "resolved": "https://registry.npmjs.org/keccak/-/keccak-2.1.0.tgz", "integrity": "sha512-m1wbJRTo+gWbctZWay9i26v5fFnYkOn7D5PCxJ3fZUGUEb49dE1Pm4BREUYCt/aoO6di7jeoGmhvqN9Nzylm3Q==", "dev": true, - "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", "inherits": "^2.0.4", @@ -18767,6 +18800,15 @@ "integrity": "sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=", "dev": true }, + "node_modules/magic-string": { + "version": "0.25.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", + "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "dev": true, + "dependencies": { + "sourcemap-codec": "^1.4.4" + } + }, "node_modules/make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -21519,12 +21561,16 @@ "dev": true }, "node_modules/resolve": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz", - "integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", + "integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==", "dev": true, "dependencies": { + "is-core-module": "^2.2.0", "path-parse": "^1.0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/resolve-cwd": { @@ -21643,9 +21689,9 @@ } }, "node_modules/rollup": { - "version": "2.28.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.28.2.tgz", - "integrity": "sha512-8txbsFBFLmm9Xdt4ByTOGa9Muonmc8MfNjnGAR8U8scJlF1ZW7AgNZa7aqBXaKtlvnYP/ab++fQIq9dB9NWUbg==", + "version": "2.45.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.45.2.tgz", + "integrity": "sha512-kRRU7wXzFHUzBIv0GfoFFIN3m9oteY4uAsKllIpQDId5cfnkWF2J130l+27dzDju0E6MScKiV0ZM5Bw8m4blYQ==", "dev": true, "bin": { "rollup": "dist/bin/rollup" @@ -21654,7 +21700,7 @@ "node": ">=10.0.0" }, "optionalDependencies": { - "fsevents": "~2.1.2" + "fsevents": "~2.3.1" } }, "node_modules/rollup-plugin-terser": { @@ -21876,10 +21922,11 @@ } }, "node_modules/rollup/node_modules/fsevents": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", - "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, + "hasInstallScript": true, "optional": true, "os": [ "darwin" @@ -22010,7 +22057,6 @@ "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.8.0.tgz", "integrity": "sha512-k5ke5avRZbtl9Tqx/SA7CbY3NF6Ro+Sj9cZxezFzuBlLDmyqPiL8hJJ+EmzD8Ig4LUDByHJ3/iPOVoRixs/hmw==", "dev": true, - "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", "bip66": "^1.1.5", @@ -22602,6 +22648,12 @@ "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=", "dev": true }, + "node_modules/sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "dev": true + }, "node_modules/spawn-command": { "version": "0.0.2-1", "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2-1.tgz", @@ -24325,7 +24377,6 @@ "resolved": "https://registry.npmjs.org/web3/-/web3-1.2.9.tgz", "integrity": "sha512-Mo5aBRm0JrcNpN/g4VOrDzudymfOnHRC3s2VarhYxRA8aWgF5rnhQ0ziySaugpic1gksbXPe105pUWyRqw8HUA==", "dev": true, - "hasInstallScript": true, "dependencies": { "web3-bzz": "1.2.9", "web3-core": "1.2.9", @@ -25076,7 +25127,6 @@ "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.31.tgz", "integrity": "sha512-VAouplvGKPiKFDTeCCO65vYHsyay8DqoBSlzIO3fayrfOgU94lQN5a1uWVnFrMLceTJw/+fQXR5PGbUVRaHshQ==", "dev": true, - "hasInstallScript": true, "dependencies": { "debug": "^2.2.0", "es5-ext": "^0.10.50", @@ -29778,6 +29828,29 @@ "@types/bignumber.js": "^5.0.0" } }, + "@rollup/plugin-commonjs": { + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.0.0.tgz", + "integrity": "sha512-fj92shhg8luw7XbA0HowAqz90oo7qtLGwqTKbyZ8pmOyH8ui5e+u0wPEgeHLH3djcVma6gUCUrjY6w5R2o1u6g==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.1.0", + "commondir": "^1.0.1", + "estree-walker": "^2.0.1", + "glob": "^7.1.6", + "is-reference": "^1.2.1", + "magic-string": "^0.25.7", + "resolve": "^1.17.0" + }, + "dependencies": { + "estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + } + } + }, "@rollup/pluginutils": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", @@ -37907,6 +37980,15 @@ "ci-info": "^2.0.0" } }, + "is-core-module": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz", + "integrity": "sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, "is-data-descriptor": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz", @@ -38081,6 +38163,15 @@ "integrity": "sha1-DFLlS8yjkbssSUsh6GJtczbG45c=", "dev": true }, + "is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "requires": { + "@types/estree": "*" + } + }, "is-regex": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.5.tgz", @@ -40066,15 +40157,6 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, - "resolve": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", - "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", - "dev": true, - "requires": { - "path-parse": "^1.0.6" - } - }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -41715,6 +41797,15 @@ "integrity": "sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=", "dev": true }, + "magic-string": { + "version": "0.25.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", + "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + }, "make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -44011,11 +44102,12 @@ "dev": true }, "resolve": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz", - "integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", + "integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==", "dev": true, "requires": { + "is-core-module": "^2.2.0", "path-parse": "^1.0.6" } }, @@ -44113,18 +44205,18 @@ } }, "rollup": { - "version": "2.28.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.28.2.tgz", - "integrity": "sha512-8txbsFBFLmm9Xdt4ByTOGa9Muonmc8MfNjnGAR8U8scJlF1ZW7AgNZa7aqBXaKtlvnYP/ab++fQIq9dB9NWUbg==", + "version": "2.45.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.45.2.tgz", + "integrity": "sha512-kRRU7wXzFHUzBIv0GfoFFIN3m9oteY4uAsKllIpQDId5cfnkWF2J130l+27dzDju0E6MScKiV0ZM5Bw8m4blYQ==", "dev": true, "requires": { - "fsevents": "~2.1.2" + "fsevents": "~2.3.1" }, "dependencies": { "fsevents": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", - "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "optional": true } @@ -44940,6 +45032,12 @@ "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=", "dev": true }, + "sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "dev": true + }, "spawn-command": { "version": "0.0.2-1", "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2-1.tgz", diff --git a/package.json b/package.json index e32db155..6689ebcd 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "dev": "concurrently -c yellow,blue -n RLP,SRV \"npm:build:watch\" \"npm:serve\"", "build": "rollup -c", "build:watch": "rollup -cw", - "test": "jest --coverage", + "test": "jest --coverage ./test/", + "test:dist": "npm run build && jest --coverage ./test-dist/", "test:watch": "jest --coverage --watch", "serve": "npx light-server --serve . -w \"index.html\" -w \"app.js\" -w \"dist/index.es.js\" -w \"dist/index.bundle.js\"", "trypublish": "npm publish || true", @@ -49,6 +50,7 @@ "@babel/preset-env": "^7.10.2", "@nomiclabs/hardhat-ethers": "^2.0.1", "@nomiclabs/hardhat-web3": "^2.0.0", + "@rollup/plugin-commonjs": "^18.0.0", "@types/jest": "^26.0.14", "babel-loader": "^8.1.0", "babel-preset-minify": "^0.5.0", diff --git a/rollup.config.js b/rollup.config.js index 9b9d7f13..1d246176 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,6 @@ import {terser} from 'rollup-plugin-terser' import typescript from 'rollup-plugin-typescript2' +import pluginCommonjs from "@rollup/plugin-commonjs"; import pkg from './package.json' const banner = ` @@ -21,6 +22,9 @@ const plugins = [ typescript({ typescript: require('typescript'), }), + pluginCommonjs({ + extensions: [".js", ".ts"] + }) ] if(!process.env.ROLLUP_WATCH) @@ -43,8 +47,9 @@ export default [ output: [ { file: pkg.main, - format: 'es', + format: 'cjs', banner, + exports: "default" }, { file: pkg.module, diff --git a/test-dist/dsa.node-cjs.spec.js b/test-dist/dsa.node-cjs.spec.js new file mode 100644 index 00000000..b2baec09 --- /dev/null +++ b/test-dist/dsa.node-cjs.spec.js @@ -0,0 +1,36 @@ + +require("dotenv").config(); +const Web3 = require("web3"); +// import hre from 'hardhat' +// import "@nomiclabs/hardhat-ethers" +// import '@nomiclabs/hardhat-web3' +const DSA = require("../dist"); + + +let web3 +let dsa +let account + +const accountPrivateKey = "0xdc68bafd6461c12ab15e8ac77dad9a74960bf308a7522a2bda798396500c028e" + + +beforeAll(() => { + web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) + dsa = new DSA({web3, mode: "node", privateKey: accountPrivateKey}) +}) + +describe('Basic', function () { + test('initalization of DSA', () => { + expect(dsa).toBeDefined() + }) + + test('get web3 accounts', async () => { + const [accountOne, accountTwo] = await web3.eth.getAccounts() + + expect(accountOne).toBeDefined() + expect(accountTwo).toBeDefined() + const dsa_account = await dsa.internal.getAddress() + console.log(dsa_account, accountOne, accountTwo) + account = accountTwo + }) +}) diff --git a/test-dist/dsa.node.spec.ts b/test-dist/dsa.node.spec.ts new file mode 100644 index 00000000..c4399105 --- /dev/null +++ b/test-dist/dsa.node.spec.ts @@ -0,0 +1,62 @@ +import { config } from 'dotenv' +import Web3 from 'web3' +// import hre from 'hardhat' +// import "@nomiclabs/hardhat-ethers" +// import '@nomiclabs/hardhat-web3' +import DSA from '../dist'; + +config() + +let web3: Web3 +let dsa: DSA +let account: string +let gasPrice: string = "20000000000" + +const accountPrivateKey: string = "0xdc68bafd6461c12ab15e8ac77dad9a74960bf308a7522a2bda798396500c028e" + +const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" +const usdcAddr = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' +const daiAddr = '0x6B175474E89094C44Da98b954EedeAC495271d0F' + +beforeAll(() => { + web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) + dsa = new DSA({web3, mode: "node", privateKey: accountPrivateKey}) + +}) + +describe('Basic', function () { + test('initalization of DSA', () => { + expect(dsa).toBeDefined() + }) + + test('get web3 accounts', async () => { + const [accountOne, accountTwo] = await web3.eth.getAccounts() + + expect(accountOne).toBeDefined() + expect(accountTwo).toBeDefined() + const dsa_account = await dsa.internal.getAddress() + console.log(dsa_account, accountOne, accountTwo) + account = accountTwo + }) +}) + +describe('DSA v1', function () { + + test('create new dsa v1', async () => { + let dsaAccounts = await dsa.accounts.getAccounts(account) + const accountCount = dsaAccounts.length + + console.log(dsaAccounts) + + await dsa.build({gasPrice}) + + dsaAccounts = await dsa.accounts.getAccounts(account) + expect(dsaAccounts.length).toEqual(accountCount + 1) + + const createdDSA = dsaAccounts[dsaAccounts.length - 1] + + await dsa.setAccount(createdDSA.id) + expect(dsa.instance.id).toEqual(createdDSA.id) + expect(dsa.instance.version).toEqual(1) + }) +}); \ No newline at end of file diff --git a/test/dsa.node.spec.ts b/test/dsa.node.spec.ts deleted file mode 100644 index 0ec1454f..00000000 --- a/test/dsa.node.spec.ts +++ /dev/null @@ -1,810 +0,0 @@ -import { config } from 'dotenv' -import Web3 from 'web3' -// import hre from 'hardhat' -// import "@nomiclabs/hardhat-ethers" -// import '@nomiclabs/hardhat-web3' -import DSA from '../src' - -config() - -let web3: Web3 -let dsa: DSA -let account: string -let gasPrice: string = "20000000000" - -const accountPrivateKey: string = "0xdc68bafd6461c12ab15e8ac77dad9a74960bf308a7522a2bda798396500c028e" - -const ethAddr = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" -const usdcAddr = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' -const daiAddr = '0x6B175474E89094C44Da98b954EedeAC495271d0F' - -beforeAll(() => { - web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) - dsa = new DSA({web3, mode: "node", privateKey: accountPrivateKey}) - -}) - -describe('Basic', function () { - test('initalization of DSA', () => { - expect(dsa).toBeDefined() - }) - - test('get web3 accounts', async () => { - const [accountOne, accountTwo] = await web3.eth.getAccounts() - - expect(accountOne).toBeDefined() - expect(accountTwo).toBeDefined() - const dsa_account = await dsa.internal.getAddress() - console.log(dsa_account, accountOne, accountTwo) - account = accountTwo - }) -}) - -describe('DSA v1', function () { - - test('create new dsa v1', async () => { - let dsaAccounts = await dsa.accounts.getAccounts(account) - const accountCount = dsaAccounts.length - - console.log(dsaAccounts) - - await dsa.build({gasPrice}) - - dsaAccounts = await dsa.accounts.getAccounts(account) - expect(dsaAccounts.length).toEqual(accountCount + 1) - - const createdDSA = dsaAccounts[dsaAccounts.length - 1] - - await dsa.setAccount(createdDSA.id) - expect(dsa.instance.id).toEqual(createdDSA.id) - expect(dsa.instance.version).toEqual(1) - }) - - test('Cast with flashloan', async () => { - const usdc_address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' - - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'withdraw', - args: [usdc_address, 0, account, 0, 0], - }) - - spells.add({ - connector: 'instapool_v2', - method: 'flashBorrow', - args: [usdc_address, "10000000", 0], - }) - - spells.add({ - connector: "instapool_v2", - method: "flashPayback", - args: [usdc_address, "10000000", 0, 0] - }) - - const calldata = await dsa.encodeCastABI(spells) - expect(calldata).toBeDefined() - - const txHash = await dsa.cast({ spells: spells, from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Cast with flashloan with multiple', async () => { - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'withdraw', - args: [usdcAddr, 0, account, 0, 0], - }) - - spells.add({ - connector: 'instapool_v2', - method: 'flashBorrow', - args: [usdcAddr, "10000000", 0], - }) - - - spells.add({ - connector: 'compound', - method: 'withdraw', - args: [ethAddr, "100000000000", 0, 0], - }) - - spells.add({ - connector: 'instapool_v2', - method: 'flashBorrow', - args: [daiAddr, "1000000000000000", 0], - }) - - spells.add({ - connector: 'aave', - method: 'borrow', - args: [daiAddr, "1000000000000000", 0, 0], - }) - - spells.add({ - connector: "instapool_v2", - method: "flashPayback", - args: [daiAddr, "1000000000000000", 0, 0] - }) - - spells.add({ - connector: "instapool_v2", - method: "flashPayback", - args: [usdcAddr, "10000000", 0, 0] - }) - - const calldata = await dsa.encodeCastABI(spells) - expect(calldata).toBeDefined() - - // const txHash = await dsa.cast({ spells: spells, from: process.env.PUBLIC_ADDRESS }) // Throws error due to connector - - }) - - test('Deposit 10 ETH to DSA', async () => { - const amt = web3.utils.toWei("10", "ether") - const data = { - token: ethAddr, - amount: amt, - to: dsa.instance.address, - from: account, - gasPrice - } - await dsa.erc20.transfer(data) - - const balance = await web3.eth.getBalance(dsa.instance.address) - expect(balance).toEqual(amt.toString()) - }) - - test('Swap 1 ETH to USDC', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Withdraw USDC from DSA', async () => { - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'withdraw', - args: [usdcAddr, dsa.maxValue, account, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Give USDC allowance', async () => { - var data = { - token: usdcAddr, - amount: "1000000000000", - to: dsa.instance.address, - gasPrice - } - await dsa.erc20.approve(data) - - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'deposit', - args: [usdcAddr, dsa.maxValue, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Swap 1 ETH to USDC #2', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Deposit ETH to Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'compound', - method: 'deposit', - args: ['ETH-A', amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Borrow DAI from Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("10", "ether") - spells.add({ - connector: 'compound', - method: 'borrow', - args: ["DAI-A", amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Payback DAI to Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("10", "ether") - spells.add({ - connector: 'compound', - method: 'payback', - args: ["DAI-A", amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Withdraw ETH from Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("0.9", "ether") - spells.add({ - connector: 'compound', - method: 'withdraw', - args: ["ETH-A", amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Swap 1 ETH to DAI', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [daiAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Deposit ETH, Borrow DAI, Payback DAI, Withdraw ETH', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - const amt2 = web3.utils.toWei("100", "ether") - spells.add({ - connector: 'compound', - method: 'deposit', - args: ["ETH-A", amt, 0, 0], - }) - spells.add({ - connector: 'compound', - method: 'borrow', - args: ["DAI-A", amt2, 0, 0], - }) - spells.add({ - connector: 'compound', - method: 'payback', - args: ["DAI-A", dsa.maxValue, 0, 0], - }) - spells.add({ - connector: 'compound', - method: 'withdraw', - args: ["ETH-A", dsa.maxValue, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Object-oriented Spells', async () => { - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'withdraw', - args: [daiAddr, dsa.maxValue, account, 0, 0], - }) - - const calldata = await dsa.encodeCastABI(spells) - expect(calldata).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - }) - - test('Swap 1 ETH to USDC #3', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Cast with fluid api', async () => { - const txHash = await dsa - .Spell() - .add({ - connector: 'basic', - method: 'withdraw', - args: [usdcAddr, dsa.maxVal(), account, 0, 0], - }) - .cast({ from: account, gasPrice }) - - expect(txHash).toBeDefined() - }) - - test('get transaction count', async () => { - const nonce = await dsa.transaction.getTransactionCount(account as string) - - expect(nonce).toBeDefined() - }) - - test('Swap 1 ETH to USDC #4', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Transfer -1 USDC from DSA', async () => { - var data = { - token: usdcAddr, - amount: dsa.maxValue, - to: account, - gasPrice - } - await dsa.erc20.transfer(data) - }) - - test('Transfer -1 USDC to DSA', async () => { - var data = { - token: usdcAddr, - amount: dsa.maxValue, - to: dsa.instance.address, - gasPrice - } - await dsa.erc20.transfer(data) - }) - - test('Give -1 DAI allowance', async () => { - var data = { - token: daiAddr, - amount: dsa.maxValue, - to: dsa.instance.address, - gasPrice - } - await dsa.erc20.approve(data) - }) -}) - -describe('DSA v2', function () { - test('create new dsa v2', async () => { - let dsaAccounts = await dsa.accounts.getAccounts(account) - const accountCount = dsaAccounts.length - - console.log(dsaAccounts) - - await dsa.build({version: 2, gasPrice}) - - dsaAccounts = await dsa.accounts.getAccounts(account) - expect(dsaAccounts.length).toEqual(accountCount + 1) - - const createdDSA = dsaAccounts[dsaAccounts.length - 1] - - await dsa.setAccount(createdDSA.id) - expect(dsa.instance.id).toEqual(createdDSA.id) - expect(dsa.instance.version).toEqual(2) - }) - - test('Deposit 10 ETH to DSA', async () => { - const amt = web3.utils.toWei("10", "ether") - const data = { - token: ethAddr, - amount: amt, - to: dsa.instance.address, - from: account, - gasPrice - } - await dsa.erc20.transfer(data) - - const balance = await web3.eth.getBalance(dsa.instance.address) - expect(balance).toEqual(amt.toString()) - }) - - test('Swap 1 ETH to USDC', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Swap 1 ETH to USDC (Spell: "1INCH-A")', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: '1INCH-A', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, "0x90411a32000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f04000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f04000000000000000000000000a8abe411d1a3f524a2ab9c54f8427066a1f9f2660000000000000000000000000000000000000000000000000d7c73f8d3422bde000000000000000000000000000000000000000000000000000000007809e3510000000000000000000000000000000000000000000000000000000079404a770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b1dc62ec38e6e3857a887210c38418e4a17da5b200000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000006e0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d7c73f8d3422bde00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000004d0e30db000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dc0000000000000000000000000000000000000000000000000d7c73f8d3422bde00000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a4c9f12e9d000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dc000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000003b3c9669a5706477a2b237d98edb9b57678926f04000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002647f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f0400000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000b1dc62ec38e6e3857a887210c38418e4a17da5b20000000000000000000000000000000000000000000000000000000000000001000000000000000002c43fc1fd44678100000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000004c1f1500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000079404a77000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000184b3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000024000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000100000000000000000000000000000001000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000a8abe411d1a3f524a2ab9c54f8427066a1f9f26600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 0], - }) - - - try { - await spells.estimateCastGas({ from: account }) - } catch (e) { - expect(e.message).toBe("Returned error: VM Exception while processing transaction: revert 1Inch-swap-failed"); - } - - try { - const txHash = await spells.cast({ from: account, gasPrice }) - } catch (e) { - expect(e.message).toBe("Returned error: VM Exception while processing transaction: revert 1Inch-swap-failed"); - } - }) - - test('Swap 1 ETH to USDC (Spell: "1INCH-A")', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'oneInch', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, "0x90411a32000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f04000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f04000000000000000000000000a8abe411d1a3f524a2ab9c54f8427066a1f9f2660000000000000000000000000000000000000000000000000d7c73f8d3422bde000000000000000000000000000000000000000000000000000000007809e3510000000000000000000000000000000000000000000000000000000079404a770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b1dc62ec38e6e3857a887210c38418e4a17da5b200000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000006e0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d7c73f8d3422bde00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000004d0e30db000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dc0000000000000000000000000000000000000000000000000d7c73f8d3422bde00000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a4c9f12e9d000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dc000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000003b3c9669a5706477a2b237d98edb9b57678926f04000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002647f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f0400000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000b1dc62ec38e6e3857a887210c38418e4a17da5b20000000000000000000000000000000000000000000000000000000000000001000000000000000002c43fc1fd44678100000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000004c1f1500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000079404a77000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000184b3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000024000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000100000000000000000000000000000001000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000a8abe411d1a3f524a2ab9c54f8427066a1f9f26600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 0], - }) - - try { - await spells.estimateCastGas({ from: account }) - } catch (e) { - expect(e.message).toBe("Returned error: VM Exception while processing transaction: revert 1Inch-swap-failed"); - } - - try { - const txHash = await spells.cast({ from: account, gasPrice }) - } catch (e) { - console.log("EADD", e.message) - expect(e.message).toBe("Returned error: VM Exception while processing transaction: revert 1Inch-swap-failed"); - } - }) - - test('Withdraw USDC from DSA', async () => { - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'withdraw', - args: [usdcAddr, dsa.maxValue, account, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Give USDC allowance', async () => { - var data = { - token: usdcAddr, - amount: "1000000000000", - to: dsa.instance.address, - gasPrice - } - await dsa.erc20.approve(data) - - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'deposit', - args: [usdcAddr, dsa.maxValue, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Swap 1 ETH to USDC #2', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Deposit ETH to Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'COMPOUND-A', - method: 'deposit', - args: ['ETH-A', amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Borrow DAI from Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("10", "ether") - spells.add({ - connector: 'compound', - method: 'borrow', - args: ["DAI-A", amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Payback DAI to Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("10", "ether") - spells.add({ - connector: 'compound', - method: 'payback', - args: ["DAI-A", amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Withdraw ETH from Compound', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("0.9", "ether") - spells.add({ - connector: 'compound', - method: 'withdraw', - args: ["ETH-A", amt, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Swap 1 ETH to DAI', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [daiAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Deposit ETH, Borrow DAI, Payback DAI, Withdraw ETH', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - const amt2 = web3.utils.toWei("100", "ether") - spells.add({ - connector: 'compound', - method: 'deposit', - args: ["ETH-A", amt, 0, 0], - }) - spells.add({ - connector: 'COMPOUND-A', - method: 'borrow', - args: ["DAI-A", amt2, 0, 0], - }) - spells.add({ - connector: 'COMPOUND-A', - method: 'payback', - args: ["DAI-A", dsa.maxValue, 0, 0], - }) - spells.add({ - connector: 'compound', - method: 'withdraw', - args: ["ETH-A", dsa.maxValue, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Object-oriented Spells', async () => { - const spells = dsa.Spell() - - spells.add({ - connector: 'basic', - method: 'withdraw', - args: [daiAddr, dsa.maxValue, account, 0, 0], - }) - - const calldata = await dsa.encodeCastABI(spells) - expect(calldata).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - }) - - test('Swap 1 ETH to USDC #3', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Cast with fluid api', async () => { - const txHash = await dsa - .Spell() - .add({ - connector: 'basic', - method: 'withdraw', - args: [usdcAddr, dsa.maxVal(), account, 0, 0], - }) - .cast({ from: account, gasPrice }) - - expect(txHash).toBeDefined() - }) - - test('get transaction count', async () => { - const nonce = await dsa.transaction.getTransactionCount(account as string) - - expect(nonce).toBeDefined() - }) - - test('Swap 1 ETH to USDC #4', async () => { - const spells = dsa.Spell() - const amt = web3.utils.toWei("1", "ether") - spells.add({ - connector: 'uniswap', - method: 'sell', - args: [usdcAddr, ethAddr, amt, 0, 0, 0], - }) - - const gas = await spells.estimateCastGas({ from: account }) - expect(gas).toBeDefined() - - const txHash = await spells.cast({ from: account, gasPrice }) - expect(txHash).toBeDefined() - }) - - test('Transfer -1 USDC from DSA', async () => { - var data = { - token: usdcAddr, - amount: dsa.maxValue, - to: account, - gasPrice - } - await dsa.erc20.transfer(data) - }) - - test('Transfer -1 USDC to DSA', async () => { - var data = { - token: usdcAddr, - amount: dsa.maxValue, - to: dsa.instance.address, - gasPrice - } - await dsa.erc20.transfer(data) - }) - - test('Give -1 DAI allowance', async () => { - var data = { - token: daiAddr, - amount: dsa.maxValue, - to: dsa.instance.address, - gasPrice - } - await dsa.erc20.approve(data) - }) -}) - diff --git a/tsconfig.json b/tsconfig.json index dc784f62..d89b793f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "ES5", - "module": "ES6", + "module": "ES2015", "moduleResolution": "Node", "sourceMap": true, "lib": [], From b2ead1c4d0a4fcf2da95dafe410e58b0e72cf3a1 Mon Sep 17 00:00:00 2001 From: Daksh Miglani Date: Wed, 21 Apr 2021 13:20:32 +0530 Subject: [PATCH 2/3] add package.json in dist --- dist/package.json | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 dist/package.json diff --git a/dist/package.json b/dist/package.json new file mode 100644 index 00000000..62701040 --- /dev/null +++ b/dist/package.json @@ -0,0 +1,72 @@ +{ + "name": "dsa-connect", + "version": "0.0.5", + "description": "Build DeFi apps instantly", + "main": "index.js", + "files": [ + "index.js", + "README.md" + ], + "types": "./index.d.ts", + "private": false, + "scripts": { + "dev": "concurrently -c yellow,blue -n RLP,SRV \"npm:build:watch\" \"npm:serve\"", + "build": "rollup -c", + "build:watch": "rollup -cw", + "test": "jest --coverage", + "test:watch": "jest --coverage --watch", + "serve": "npx light-server --serve . -w \"index.html\" -w \"app.js\" -w \"index.es.js\" -w \"index.bundle.js\"", + "trypublish": "npm publish || true", + "postversion": "git push && git push --tags && npm publish && npm run open-releases", + "open-releases": "open \"$(node -e 'console.log(`${require(\"./package.json\").repository}/releases`)')\"", + "ganache:fork": "dotenv -- cross-var npx ganache-cli --fork %ETH_NODE_URL% --unlock %PUBLIC_ADDRESS%" + }, + "bugs": "https://github.com/instadapp/dsa-connect/issues", + "repository": { + "type": "git", + "url": "https://github.com/instadapp/dsa-connect" + }, + "author": { + "name": "INSTADAPP LABS LLC", + "email": "info@instadapp.io" + }, + "license": "MIT", + "keywords": [ + "ethereum", + "defi", + "dapps" + ], + "dependencies": {}, + "devDependencies": { + "@babel/cli": "^7.10.1", + "@babel/core": "^7.9.0", + "@babel/node": "^7.8.7", + "@babel/plugin-proposal-class-properties": "^7.10.1", + "@babel/polyfill": "^7.10.1", + "@babel/preset-env": "^7.10.2", + "@types/jest": "^26.0.14", + "babel-loader": "^8.1.0", + "babel-preset-minify": "^0.5.0", + "concurrently": "^5.3.0", + "dotenv": "^8.2.0", + "cross-var": "^1.1.0", + "dotenv-cli": "^3.2.0", + "ganache-cli": "^6.11.0", + "html-webpack-plugin": "^4.2.0", + "jest": "^26.5.2", + "light-server": "^2.8.0", + "prettier": "^2.0.5", + "prettier-webpack-plugin": "^1.2.0", + "rollup": "^2.28.2", + "rollup-plugin-terser": "^7.0.2", + "rollup-plugin-typescript2": "^0.27.3", + "@rollup/plugin-commonjs": "^18.0.0", + "ts-jest": "^26.4.1", + "tslib": "^2.0.1", + "typescript": "^4.0.3", + "web3": "^1.2.8", + "webpack": "^4.42.1", + "webpack-cli": "^3.3.11", + "webpack-dev-server": "^3.11.0" + } + } \ No newline at end of file From 4fdd330d9999b3560d8fbb3733012ba11419338f Mon Sep 17 00:00:00 2001 From: Daksh Miglani Date: Sun, 25 Apr 2021 15:18:21 +0530 Subject: [PATCH 3/3] rebase on master --- package-lock.json | 10 ++++++++-- run-test.sh | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2c5c098f..af4e872f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "dsa-connect", - "version": "0.2.0-beta.12", + "version": "0.2.3", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.2.0-beta.12", + "version": "0.2.3", "license": "MIT", "devDependencies": { "@babel/cli": "^7.10.1", @@ -9730,6 +9730,7 @@ "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz", "integrity": "sha512-epq90L9jlFWCW7+pQa6JOnKn2Xgl2mtI664seYR6MHskvI9agt7AnDqmAlp9TqU4/caMYbA08Hi5DMZAl5zdkA==", "dev": true, + "hasInstallScript": true, "dependencies": { "node-addon-api": "^2.0.0", "node-gyp-build": "^4.2.0" @@ -9743,6 +9744,7 @@ "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz", "integrity": "sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg==", "dev": true, + "hasInstallScript": true, "dependencies": { "elliptic": "^6.5.2", "node-addon-api": "^2.0.0", @@ -10883,6 +10885,7 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.12.tgz", "integrity": "sha512-Ggd/Ktt7E7I8pxZRbGIs7vwqAPscSESMrCSkx2FtWeqmheJgCo2R74fTsZFCifr0VTPwqRpPv17+6b8Zp7th0Q==", "dev": true, + "hasInstallScript": true, "optional": true, "os": [ "darwin" @@ -18249,6 +18252,7 @@ "resolved": "https://registry.npmjs.org/keccak/-/keccak-2.1.0.tgz", "integrity": "sha512-m1wbJRTo+gWbctZWay9i26v5fFnYkOn7D5PCxJ3fZUGUEb49dE1Pm4BREUYCt/aoO6di7jeoGmhvqN9Nzylm3Q==", "dev": true, + "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", "inherits": "^2.0.4", @@ -22057,6 +22061,7 @@ "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.8.0.tgz", "integrity": "sha512-k5ke5avRZbtl9Tqx/SA7CbY3NF6Ro+Sj9cZxezFzuBlLDmyqPiL8hJJ+EmzD8Ig4LUDByHJ3/iPOVoRixs/hmw==", "dev": true, + "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", "bip66": "^1.1.5", @@ -25127,6 +25132,7 @@ "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.31.tgz", "integrity": "sha512-VAouplvGKPiKFDTeCCO65vYHsyay8DqoBSlzIO3fayrfOgU94lQN5a1uWVnFrMLceTJw/+fQXR5PGbUVRaHshQ==", "dev": true, + "hasInstallScript": true, "dependencies": { "debug": "^2.2.0", "es5-ext": "^0.10.50", diff --git a/run-test.sh b/run-test.sh index c04b884b..ae26bc9e 100755 --- a/run-test.sh +++ b/run-test.sh @@ -9,3 +9,4 @@ sleep 5 echo "Running tests" npm run test +npm run test:dist \ No newline at end of file