From 2cb52154bfa637766318e4b09f64f3338010f08f Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 7 Feb 2024 18:50:56 +0100 Subject: [PATCH] fix: cover the minimal boltz template with the gas estimation --- contracts/import.sol | 2 + package-lock.json | 317 +++++++++++++++++++++++++-------------- scripts/GasEstimation.ts | 212 +++++++++++++++----------- test/utils/TestUtils.ts | 112 +++++++++----- 4 files changed, 410 insertions(+), 233 deletions(-) diff --git a/contracts/import.sol b/contracts/import.sol index 20d06624..00d8ee96 100644 --- a/contracts/import.sol +++ b/contracts/import.sol @@ -5,9 +5,11 @@ import '@rsksmart/rif-relay-contracts/contracts/RelayHub.sol'; import '@rsksmart/rif-relay-contracts/contracts/smartwallet/SmartWallet.sol'; import '@rsksmart/rif-relay-contracts/contracts/smartwallet/CustomSmartWallet.sol'; import '@rsksmart/rif-relay-contracts/contracts/smartwallet/BoltzSmartWallet.sol'; +import '@rsksmart/rif-relay-contracts/contracts/smartwallet/MinimalBoltzSmartWallet.sol'; import '@rsksmart/rif-relay-contracts/contracts/factory/SmartWalletFactory.sol'; import '@rsksmart/rif-relay-contracts/contracts/factory/CustomSmartWalletFactory.sol'; import '@rsksmart/rif-relay-contracts/contracts/factory/BoltzSmartWalletFactory.sol'; +import '@rsksmart/rif-relay-contracts/contracts/factory/MinimalBoltzSmartWalletFactory.sol'; import '@rsksmart/rif-relay-contracts/contracts/verifier/CustomSmartWalletDeployVerifier.sol'; import '@rsksmart/rif-relay-contracts/contracts/verifier/DeployVerifier.sol'; import '@rsksmart/rif-relay-contracts/contracts/verifier/RelayVerifier.sol'; diff --git a/package-lock.json b/package-lock.json index b2ed1f95..e721e8aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2432,7 +2432,7 @@ }, "node_modules/@rsksmart/rif-relay-client": { "version": "2.1.0", - "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#159000d6f23349d749aaa0c5294270fe9cad63a7", + "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#70adad7b92b72b7aa6363c6042fff4541174760b", "license": "MIT", "dependencies": { "bignumber.js": "^9.1.1", @@ -2447,7 +2447,7 @@ }, "node_modules/@rsksmart/rif-relay-contracts": { "version": "2.0.0-beta.1", - "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#9d6dc34974bb74bd2137dfdc4196fb31fda0ffb2", + "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#60184e7a95f02b05d251cfdd778eaa90f4d322e3", "license": "MIT", "dependencies": { "@metamask/eth-sig-util": "^4.0.1", @@ -2584,7 +2584,7 @@ }, "node_modules/@rsksmart/rif-relay-server": { "version": "2.2.2", - "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#b1caf3c4e4c7f7e78475f8874480063df1e44b04", + "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#403423f79bcca76064ea3592a04cf05d91e63daf", "license": "MIT", "dependencies": { "@rsksmart/rif-relay-client": "github:rsksmart/rif-relay-client#PP-885/explore-solution-b2", @@ -3054,9 +3054,9 @@ } }, "node_modules/@types/express-serve-static-core": { - "version": "4.17.42", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.42.tgz", - "integrity": "sha512-ckM3jm2bf/MfB3+spLPWYPUH573plBFwpOhqQ2WottxYV85j1HQFlxmnTq57X1yHY9awZPig06hL/cLMgNWHIQ==", + "version": "4.17.43", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.43.tgz", + "integrity": "sha512-oaYtiBirUOPQGSWNGPWnzyAFJ0BP3cwvN4oWZQY+zUBwpVIGsKUkpBpSztp74drYcjavs7SKFZ4DX1V2QeN8rg==", "dev": true, "dependencies": { "@types/node": "*", @@ -4272,13 +4272,17 @@ } }, "node_modules/call-bind": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", - "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.6.tgz", + "integrity": "sha512-Mj50FLHtlsoVfRfnHaZvyrooHcrlceNZdL/QBvJJVd9Ta55qCQK0gs4ss2oZDeV9zFCs6ewzYgVE5yfVmfFpVg==", "dependencies": { + "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.1", - "set-function-length": "^1.1.1" + "get-intrinsic": "^1.2.3", + "set-function-length": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -4342,9 +4346,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001582", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001582.tgz", - "integrity": "sha512-vsJG3V5vgfduaQGVxL53uSX/HUzxyr2eA8xCo36OLal7sRcSZbibJtLeh0qja4sFOr/QQGt4opB4tOy+eOgAxg==", + "version": "1.0.30001585", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001585.tgz", + "integrity": "sha512-yr2BWR1yLXQ8fMpdS/4ZZXpseBgE7o4g41x3a6AJOqZuOi+iE/WdJYAuZ6Y95i4Ohd2Y+9MzIWRR+uGABH4s3Q==", "funding": [ { "type": "opencollective", @@ -4459,15 +4463,9 @@ } }, "node_modules/chokidar": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", - "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ], + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -4480,6 +4478,9 @@ "engines": { "node": ">= 8.10.0" }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, "optionalDependencies": { "fsevents": "~2.3.2" } @@ -5243,13 +5244,14 @@ "peer": true }, "node_modules/define-data-property": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", - "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.2.tgz", + "integrity": "sha512-SRtsSqsDbgpJBbW3pABMCOt6rQyeM8s8RiyeSN8jYG8sYmt/kGJejbydttUsnDs1tadr19tvhT4ShwMyoqAm4g==", "dependencies": { - "get-intrinsic": "^1.2.1", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.2", "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.0" + "has-property-descriptors": "^1.0.1" }, "engines": { "node": ">= 0.4" @@ -5435,9 +5437,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.655", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.655.tgz", - "integrity": "sha512-2yszojF7vIZ68adIOvzV4bku8OZad9w5H9xF3ZAMZjPuOjBarlflUkjN6DggdV+L71WZuKUfKUhov/34+G5QHg==" + "version": "1.4.659", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.659.tgz", + "integrity": "sha512-sRJ3nV3HowrYpBtPF9bASQV7OW49IgZC01Xiq43WfSE3RTCkK0/JidoCmR73Hyc1mN+l/H4Yqx0eNiomvExFZg==" }, "node_modules/elliptic": { "version": "6.5.4", @@ -5527,15 +5529,23 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-module-lexer": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.4.1.tgz", "integrity": "sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w==" }, "node_modules/escalade": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", - "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", + "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", "engines": { "node": ">=6" } @@ -6596,9 +6606,9 @@ "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==" }, "node_modules/fastq": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz", - "integrity": "sha512-zGygtijUMT7jnk3h26kUms3BkSDp4IfIKjmnqI2tvx6nuBfiF1UqOxbnLfzdv+apBy+53oaImsKtMw/xYbW+1w==", + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", + "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", "dependencies": { "reusify": "^1.0.4" } @@ -6844,15 +6854,19 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", - "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "dependencies": { + "es-errors": "^1.3.0", "function-bind": "^1.1.2", "has-proto": "^1.0.1", "has-symbols": "^1.0.3", "hasown": "^2.0.0" }, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -9271,6 +9285,32 @@ "balanced-match": "^1.0.0" } }, + "node_modules/mocha/node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/mocha/node_modules/cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", @@ -9281,6 +9321,17 @@ "wrap-ansi": "^7.0.0" } }, + "node_modules/mocha/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/mocha/node_modules/minimatch": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", @@ -9916,9 +9967,9 @@ } }, "node_modules/postcss": { - "version": "8.4.33", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.33.tgz", - "integrity": "sha512-Kkpbhhdjw2qQs2O2DGX+8m5OVqEcbB9HRBvuYM9pgrjEFUg30A9LmXNlTAUj4S9kgtGyrMbTzVjH7E+s5Re2yg==", + "version": "8.4.34", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.34.tgz", + "integrity": "sha512-4eLTO36woPSocqZ1zIrFD2K1v6wH7pY1uBh0JIM2KKfrVtGvPFiAku6aNOP0W1Wr9qwnaCsF0Z+CrVnryB2A8Q==", "funding": [ { "type": "opencollective", @@ -10921,13 +10972,14 @@ } }, "node_modules/set-function-length": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.0.tgz", - "integrity": "sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.1.tgz", + "integrity": "sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==", "dependencies": { - "define-data-property": "^1.1.1", + "define-data-property": "^1.1.2", + "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.2", + "get-intrinsic": "^1.2.3", "gopd": "^1.0.1", "has-property-descriptors": "^1.0.1" }, @@ -11007,13 +11059,17 @@ } }, "node_modules/side-channel": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", - "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.5.tgz", + "integrity": "sha512-QcgiIWV4WV7qWExbN5llt6frQB/lBven9pqliLXfGPB+K9ZYXxDozp0wLkHS24kWCm+6YXH/f0HhnObZnZOBnQ==", "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" + "call-bind": "^1.0.6", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -12193,9 +12249,9 @@ "integrity": "sha512-ZqGrAgaqqZM7LGRzNjLnw5elevWb5M8LEoDMadxIW3OWbcv72wMMgKdwOKpd5Fqxe8choLD8HN3iSj3TUh/giQ==" }, "node_modules/undici": { - "version": "5.28.2", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.2.tgz", - "integrity": "sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==", + "version": "5.28.3", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz", + "integrity": "sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==", "dependencies": { "@fastify/busboy": "^2.0.0" }, @@ -12406,9 +12462,9 @@ } }, "node_modules/web3-utils": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.10.3.tgz", - "integrity": "sha512-OqcUrEE16fDBbGoQtZXWdavsPzbGIDc5v3VrRTZ0XrIpefC/viZ1ZU9bGEemazyS0catk/3rkOOxpzTfY+XsyQ==", + "version": "1.10.4", + "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.10.4.tgz", + "integrity": "sha512-tsu8FiKJLk2PzhDl9fXbGUWTkkVXYhtTA+SmEFkKft+9BgwLxfCRpU96sWv7ICC8zixBNd3JURVoiR3dUXgP8A==", "peer": true, "dependencies": { "@ethereumjs/util": "^8.1.0", @@ -14411,7 +14467,7 @@ "integrity": "sha512-z0zMCjyhhp4y7XKAcDAi3Vgms4T2PstwBdahiO0+9NaGICQKjynK3wduSRplTgk4LXmoO1yfDGO5RbjKYxtuxA==" }, "@rsksmart/rif-relay-client": { - "version": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#159000d6f23349d749aaa0c5294270fe9cad63a7", + "version": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#70adad7b92b72b7aa6363c6042fff4541174760b", "from": "@rsksmart/rif-relay-client@github:rsksmart/rif-relay-client#PP-885/explore-solution-b2", "requires": { "bignumber.js": "^9.1.1", @@ -14421,7 +14477,7 @@ } }, "@rsksmart/rif-relay-contracts": { - "version": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#9d6dc34974bb74bd2137dfdc4196fb31fda0ffb2", + "version": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#60184e7a95f02b05d251cfdd778eaa90f4d322e3", "from": "@rsksmart/rif-relay-contracts@github:rsksmart/rif-relay-contracts#PP-885/explore-solution-b2", "requires": { "@metamask/eth-sig-util": "^4.0.1", @@ -14549,7 +14605,7 @@ } }, "@rsksmart/rif-relay-server": { - "version": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#b1caf3c4e4c7f7e78475f8874480063df1e44b04", + "version": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#403423f79bcca76064ea3592a04cf05d91e63daf", "from": "@rsksmart/rif-relay-server@github:rsksmart/rif-relay-server#PP-885/explore-solution-b2", "requires": { "@rsksmart/rif-relay-client": "github:rsksmart/rif-relay-client#PP-885/explore-solution-b2", @@ -14975,9 +15031,9 @@ } }, "@types/express-serve-static-core": { - "version": "4.17.42", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.42.tgz", - "integrity": "sha512-ckM3jm2bf/MfB3+spLPWYPUH573plBFwpOhqQ2WottxYV85j1HQFlxmnTq57X1yHY9awZPig06hL/cLMgNWHIQ==", + "version": "4.17.43", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.43.tgz", + "integrity": "sha512-oaYtiBirUOPQGSWNGPWnzyAFJ0BP3cwvN4oWZQY+zUBwpVIGsKUkpBpSztp74drYcjavs7SKFZ4DX1V2QeN8rg==", "dev": true, "requires": { "@types/node": "*", @@ -15939,13 +15995,14 @@ "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" }, "call-bind": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", - "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.6.tgz", + "integrity": "sha512-Mj50FLHtlsoVfRfnHaZvyrooHcrlceNZdL/QBvJJVd9Ta55qCQK0gs4ss2oZDeV9zFCs6ewzYgVE5yfVmfFpVg==", "requires": { + "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.1", - "set-function-length": "^1.1.1" + "get-intrinsic": "^1.2.3", + "set-function-length": "^1.2.0" } }, "call-me-maybe": { @@ -15990,9 +16047,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001582", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001582.tgz", - "integrity": "sha512-vsJG3V5vgfduaQGVxL53uSX/HUzxyr2eA8xCo36OLal7sRcSZbibJtLeh0qja4sFOr/QQGt4opB4tOy+eOgAxg==" + "version": "1.0.30001585", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001585.tgz", + "integrity": "sha512-yr2BWR1yLXQ8fMpdS/4ZZXpseBgE7o4g41x3a6AJOqZuOi+iE/WdJYAuZ6Y95i4Ohd2Y+9MzIWRR+uGABH4s3Q==" }, "case": { "version": "1.6.3", @@ -16066,9 +16123,9 @@ } }, "chokidar": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", - "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", "requires": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -16638,13 +16695,14 @@ "peer": true }, "define-data-property": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", - "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.2.tgz", + "integrity": "sha512-SRtsSqsDbgpJBbW3pABMCOt6rQyeM8s8RiyeSN8jYG8sYmt/kGJejbydttUsnDs1tadr19tvhT4ShwMyoqAm4g==", "requires": { - "get-intrinsic": "^1.2.1", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.2", "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.0" + "has-property-descriptors": "^1.0.1" } }, "delayed-stream": { @@ -16780,9 +16838,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "electron-to-chromium": { - "version": "1.4.655", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.655.tgz", - "integrity": "sha512-2yszojF7vIZ68adIOvzV4bku8OZad9w5H9xF3ZAMZjPuOjBarlflUkjN6DggdV+L71WZuKUfKUhov/34+G5QHg==" + "version": "1.4.659", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.659.tgz", + "integrity": "sha512-sRJ3nV3HowrYpBtPF9bASQV7OW49IgZC01Xiq43WfSE3RTCkK0/JidoCmR73Hyc1mN+l/H4Yqx0eNiomvExFZg==" }, "elliptic": { "version": "6.5.4", @@ -16856,15 +16914,20 @@ "is-arrayish": "^0.2.1" } }, + "es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==" + }, "es-module-lexer": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.4.1.tgz", "integrity": "sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w==" }, "escalade": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", - "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==" + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", + "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==" }, "escape-html": { "version": "1.0.3", @@ -17684,9 +17747,9 @@ "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==" }, "fastq": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz", - "integrity": "sha512-zGygtijUMT7jnk3h26kUms3BkSDp4IfIKjmnqI2tvx6nuBfiF1UqOxbnLfzdv+apBy+53oaImsKtMw/xYbW+1w==", + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", + "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", "requires": { "reusify": "^1.0.4" } @@ -17865,10 +17928,11 @@ "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==" }, "get-intrinsic": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", - "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "requires": { + "es-errors": "^1.3.0", "function-bind": "^1.1.2", "has-proto": "^1.0.1", "has-symbols": "^1.0.3", @@ -19619,6 +19683,21 @@ "balanced-match": "^1.0.0" } }, + "chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + } + }, "cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", @@ -19629,6 +19708,14 @@ "wrap-ansi": "^7.0.0" } }, + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "requires": { + "is-glob": "^4.0.1" + } + }, "minimatch": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", @@ -20107,9 +20194,9 @@ "peer": true }, "postcss": { - "version": "8.4.33", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.33.tgz", - "integrity": "sha512-Kkpbhhdjw2qQs2O2DGX+8m5OVqEcbB9HRBvuYM9pgrjEFUg30A9LmXNlTAUj4S9kgtGyrMbTzVjH7E+s5Re2yg==", + "version": "8.4.34", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.34.tgz", + "integrity": "sha512-4eLTO36woPSocqZ1zIrFD2K1v6wH7pY1uBh0JIM2KKfrVtGvPFiAku6aNOP0W1Wr9qwnaCsF0Z+CrVnryB2A8Q==", "requires": { "nanoid": "^3.3.7", "picocolors": "^1.0.0", @@ -20822,13 +20909,14 @@ } }, "set-function-length": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.0.tgz", - "integrity": "sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.1.tgz", + "integrity": "sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==", "requires": { - "define-data-property": "^1.1.1", + "define-data-property": "^1.1.2", + "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.2", + "get-intrinsic": "^1.2.3", "gopd": "^1.0.1", "has-property-descriptors": "^1.0.1" } @@ -20887,13 +20975,14 @@ } }, "side-channel": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", - "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.5.tgz", + "integrity": "sha512-QcgiIWV4WV7qWExbN5llt6frQB/lBven9pqliLXfGPB+K9ZYXxDozp0wLkHS24kWCm+6YXH/f0HhnObZnZOBnQ==", "requires": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" + "call-bind": "^1.0.6", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" } }, "signal-exit": { @@ -21787,9 +21876,9 @@ "integrity": "sha512-ZqGrAgaqqZM7LGRzNjLnw5elevWb5M8LEoDMadxIW3OWbcv72wMMgKdwOKpd5Fqxe8choLD8HN3iSj3TUh/giQ==" }, "undici": { - "version": "5.28.2", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.2.tgz", - "integrity": "sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==", + "version": "5.28.3", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz", + "integrity": "sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==", "requires": { "@fastify/busboy": "^2.0.0" } @@ -21940,9 +22029,9 @@ } }, "web3-utils": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.10.3.tgz", - "integrity": "sha512-OqcUrEE16fDBbGoQtZXWdavsPzbGIDc5v3VrRTZ0XrIpefC/viZ1ZU9bGEemazyS0catk/3rkOOxpzTfY+XsyQ==", + "version": "1.10.4", + "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.10.4.tgz", + "integrity": "sha512-tsu8FiKJLk2PzhDl9fXbGUWTkkVXYhtTA+SmEFkKft+9BgwLxfCRpU96sWv7ICC8zixBNd3JURVoiR3dUXgP8A==", "peer": true, "requires": { "@ethereumjs/util": "^8.1.0", diff --git a/scripts/GasEstimation.ts b/scripts/GasEstimation.ts index a92574f1..22bb24fc 100644 --- a/scripts/GasEstimation.ts +++ b/scripts/GasEstimation.ts @@ -8,10 +8,7 @@ import { RelayRequestBody, DeployRequest, } from '@rsksmart/rif-relay-client'; -import { - BoltzSmartWalletFactory, - UtilToken, -} from '@rsksmart/rif-relay-contracts'; +import { UtilToken } from '@rsksmart/rif-relay-contracts'; import { BigNumber, BigNumberish, @@ -26,10 +23,14 @@ import { deployRelayHub, getSuffixDataAndSignature, deployContract, + SupportedType, + SupportedSmartWallet, + SupportedSmartWalletName, + SupportedSmartWalletFactory, + getSmartWalletAddress, } from '../test/utils/TestUtils'; import { TestSwap, TestVerifierEverythingAccepted } from 'typechain-types'; import { - SmartWalletFactory, Penalizer, RelayHub, SmartWallet, @@ -82,7 +83,7 @@ async function setupRelayHub(relayHub: RelayHub) { await relayHub.connect(relayManager).registerRelayServer(RELAY_URL); } -async function deployAndSetup() { +async function deployAndSetup(payment: Payment = 'erc20') { const owner = Wallet.createRandom().connect(ethers.provider); const swap = await deployContract('TestSwap'); const penalizer = await deployContract('Penalizer'); @@ -91,10 +92,16 @@ async function deployAndSetup() { ); const token = await deployContract('UtilToken'); - const smartWalletTemplate = await deployContract('SmartWallet'); - const boltzSmartWalletTemplate = await deployContract( - 'BoltzSmartWallet' + + const templateNames: Record = { + native: 'BoltzSmartWallet', + minimalNative: 'MinimalBoltzSmartWallet', + erc20: 'SmartWallet', + }; + const template = await deployContract( + templateNames[payment] ); + const relayHub = await deployRelayHub(penalizer.address); await setupRelayHub(relayHub); @@ -110,27 +117,33 @@ async function deployAndSetup() { value: oneEther, }); - const smartWalletFactory = (await createSmartWalletFactory( - smartWalletTemplate, - 'Default', - owner - )) as SmartWalletFactory; + const supportedTypes: Record = { + native: 'Boltz', + minimalNative: 'MinimalBoltz', + erc20: 'Default', + }; - const boltzSmartWalletFactory = (await createSmartWalletFactory( - boltzSmartWalletTemplate, - 'Boltz', + const factory = (await createSmartWalletFactory( + template, + supportedTypes[payment], owner - )) as BoltzSmartWalletFactory; + )) as SupportedSmartWalletFactory; + + const tokenContracts: Record = { + native: constants.AddressZero, + minimalNative: constants.AddressZero, + erc20: token.address, + }; return { relayHub, owner, - smartWalletFactory, token, verifier, swap, - boltzSmartWalletTemplate, - boltzSmartWalletFactory, + factory, + tokenContractAddress: tokenContracts[payment], + type: supportedTypes[payment], }; } @@ -304,27 +317,30 @@ interface DestinationContractCallParams { data: BytesLike; } -async function estimateRelayCost(fees = NO_FEES, native = false) { +async function estimateRelayCost(fees = NO_FEES, payment: Payment = 'erc20') { const { relayHub, - smartWalletFactory, owner, token, verifier, swap, - boltzSmartWalletFactory, - } = await deployAndSetup(); + factory, + tokenContractAddress, + type, + } = await deployAndSetup(payment); + + const isNative = ['native', 'minimalNative'].includes(payment); const smartWallet = (await createSupportedSmartWallet({ relayHub: relayHubSigner.address, - factory: native ? boltzSmartWalletFactory : smartWalletFactory, + factory, owner, sender: relayHubSigner, - type: native ? 'Boltz' : 'Default', + type, })) as SmartWallet; // FIXME: apparently we need a high value for this - // const tokenGas = await getTokenGas(token, fees, smartWallet.address, native); + // const tokenGas = await getTokenGas(token, fees, smartWallet.address, isNative); const tokenGas = '50000'; const baseRelayRequest: RelayRequest = { request: { @@ -335,7 +351,7 @@ async function estimateRelayCost(fees = NO_FEES, native = false) { nonce: (await smartWallet.nonce()).toString(), value: '0', gas: '0', - tokenContract: native ? constants.AddressZero : token.address, + tokenContract: tokenContractAddress, tokenAmount: fees, tokenGas: tokenGas.toString(), validUntilTime: '0', @@ -366,7 +382,7 @@ async function estimateRelayCost(fees = NO_FEES, native = false) { TOKEN_AMOUNT_TO_TRANSFER, token, smartWallet, - native, + isNative, swap ); const completeReq = combineTwoRelayRequests(baseRelayRequest, { @@ -398,7 +414,7 @@ async function estimateRelayCost(fees = NO_FEES, native = false) { const feesBigNumber = BigNumber.from(fees); - if (!native) { + if (!isNative) { assertRelayedTransaction( smartWalletInitialBalance, relayWorkerInitialBalance, @@ -428,21 +444,43 @@ async function estimateRelayCost(fees = NO_FEES, native = false) { printRelayGasAnalysis(txReceiptWithRelay, txReceiptWithoutRelay); } -async function prepareDeployRequest(fees = NO_FEES, native: boolean) { - const SMART_WALLET_INDEX = '1'; - - const { relayHub, owner, smartWalletFactory, token, verifier, swap } = - await deployAndSetup(); +async function prepareDeployRequest( + fees = NO_FEES, + payment: Payment = 'erc20' +) { + const SMART_WALLET_INDEX = 1; - const swAddress = await smartWalletFactory.getSmartWalletAddress( - owner.address, - constants.AddressZero, - SMART_WALLET_INDEX - ); + const { + relayHub, + owner, + factory, + token, + verifier, + swap, + tokenContractAddress, + type, + } = await deployAndSetup(payment); + + const isNative = ['native', 'minimalNative'].includes(payment); + const swAddress = await getSmartWalletAddress({ + type, + factory, + owner: owner, + recoverer: constants.AddressZero, + index: SMART_WALLET_INDEX, + }); - await token.mint(fees, swAddress); + if (payment === 'erc20') { + await token.mint(fees, swAddress); + } else { + const sendTx = await owner.sendTransaction({ + value: BigNumber.from(fees), + to: swAddress, + }); + await sendTx.wait(); + } - const tokenGas = await getTokenGas(token, fees, swAddress, native); + const tokenGas = await getTokenGas(token, fees, swAddress, isNative); const deployRequest: DeployRequest = { request: { @@ -452,7 +490,7 @@ async function prepareDeployRequest(fees = NO_FEES, native: boolean) { relayHub: relayHub.address, to: constants.AddressZero, tokenAmount: fees, - tokenContract: native ? constants.AddressZero : token.address, + tokenContract: tokenContractAddress, tokenGas: tokenGas.toString(), value: '0', gas: '0', @@ -461,7 +499,7 @@ async function prepareDeployRequest(fees = NO_FEES, native: boolean) { recoverer: constants.AddressZero, }, relayData: { - callForwarder: smartWalletFactory.address, + callForwarder: factory.address, callVerifier: verifier.address, feesReceiver: relayWorker.address, gasPrice: GAS_PRICE, @@ -470,7 +508,7 @@ async function prepareDeployRequest(fees = NO_FEES, native: boolean) { return { deployRequest, - smartWalletFactory, + factory, owner, relayHub, swap, @@ -478,34 +516,37 @@ async function prepareDeployRequest(fees = NO_FEES, native: boolean) { }; } -async function estimateDeployCost(fees = NO_FEES, native = false) { - const { deployRequest, smartWalletFactory, owner, relayHub } = - await prepareDeployRequest(fees, native); +async function estimateDeployCost(fees = NO_FEES, payment: Payment = 'erc20') { + const { deployRequest, factory, owner, relayHub } = + await prepareDeployRequest(fees, payment); + deployRequest.request.tokenGas = 50_000; const { signature } = await getSuffixDataAndSignature( - smartWalletFactory, + factory, deployRequest, owner ); const txResponse = await relayHub .connect(relayWorker) - .deployCall(deployRequest, signature, { gasPrice: GAS_PRICE }); + .deployCall(deployRequest, signature, { + gasPrice: GAS_PRICE, + gasLimit: 1_000_000, + }); const txReceipt = await txResponse.wait(); + // FIXME: Check the deployment is correct, see relay call + console.log('\tTotal gas used on deploy: ', txReceipt.gasUsed.toString()); } -async function estimateDeployCostWithExecution(fees = NO_FEES, native = false) { - const { - deployRequest, - smartWalletFactory, - owner, - relayHub, - swap, - swAddress, - } = await prepareDeployRequest(fees, native); +async function estimateDeployCostWithExecution( + fees = NO_FEES, + payment: Payment = 'erc20' +) { + const { deployRequest, factory, owner, relayHub, swap, swAddress } = + await prepareDeployRequest(fees, payment); const { to, data, gas } = await getExecutionParameters(swap, swAddress); @@ -522,7 +563,7 @@ async function estimateDeployCostWithExecution(fees = NO_FEES, native = false) { }; const { signature } = await getSuffixDataAndSignature( - smartWalletFactory, + factory, updatedDeployRequest, owner ); @@ -592,9 +633,22 @@ async function getTokenGas( dataForTransfer ); } +async function runEstimation({ operation, payment, fees }: EstimationRun) { + logTitle( + `Operation: ${operation} estimation ${ + fees === NO_FEES ? 'without' : 'with' + } ${payment} payment` + ); + const operations: Record Promise> = { + relay: () => estimateRelayCost(fees, payment), + deploy: () => estimateDeployCost(fees, payment), + deployWithExecution: () => estimateDeployCostWithExecution(fees, payment), + }; + await operations[operation](); +} type Operation = 'relay' | 'deploy' | 'deployWithExecution'; -type Payment = 'erc20' | 'native'; +type Payment = 'erc20' | 'native' | 'minimalNative'; interface EstimationRun { operation: Operation; @@ -614,7 +668,7 @@ async function estimateGas() { SignerWithAddress ]; const runs: EstimationRun[] = [ - { + /* { operation: 'relay', payment: 'erc20', fees: NO_FEES, @@ -654,11 +708,22 @@ async function estimateGas() { payment: 'native', fees: RELAY_FEES, }, + { + operation: 'deploy', + payment: 'minimalNative', + fees: RELAY_FEES, + }, */ { operation: 'deployWithExecution', payment: 'native', fees: RELAY_FEES, }, + + { + operation: 'deployWithExecution', + payment: 'minimalNative', + fees: RELAY_FEES, + }, ]; for (const runConfig of runs) { await runEstimation(runConfig); @@ -669,24 +734,3 @@ estimateGas().catch((error) => { console.error(error); process.exitCode = 1; }); - -async function runEstimation({ operation, payment, fees }: EstimationRun) { - logTitle( - `Operation: ${operation} estimation ${ - fees === NO_FEES ? 'without' : 'with' - } ${payment} payment` - ); - switch (operation) { - case 'relay': - await estimateRelayCost(fees, payment === 'native'); - break; - case 'deploy': - await estimateDeployCost(fees, payment === 'native'); - break; - case 'deployWithExecution': - await estimateDeployCostWithExecution(fees, payment === 'native'); - break; - default: - break; - } -} diff --git a/test/utils/TestUtils.ts b/test/utils/TestUtils.ts index 81d250c8..2f583e2f 100644 --- a/test/utils/TestUtils.ts +++ b/test/utils/TestUtils.ts @@ -1,4 +1,11 @@ -import { BigNumberish, constants, Contract, utils, Wallet } from 'ethers'; +import { + BigNumberish, + constants, + Contract, + ContractInterface, + utils, + Wallet, +} from 'ethers'; import chaiAsPromised from 'chai-as-promised'; import { expect, use } from 'chai'; import { @@ -13,6 +20,8 @@ import { BoltzDeployVerifier, RelayVerifier, BoltzRelayVerifier, + MinimalBoltzSmartWallet, + MinimalBoltzSmartWalletFactory, } from '@rsksmart/rif-relay-contracts'; import { defaultEnvironment, @@ -49,6 +58,7 @@ import nodeConfig from 'config'; import SmartWalletJson from '../../artifacts/@rsksmart/rif-relay-contracts/contracts/smartwallet/SmartWallet.sol/SmartWallet.json'; import CustomSmartWalletJson from '../../artifacts/@rsksmart/rif-relay-contracts/contracts/smartwallet/CustomSmartWallet.sol/CustomSmartWallet.json'; import BoltzSmartWalletJson from '../../artifacts/@rsksmart/rif-relay-contracts/contracts/smartwallet/BoltzSmartWallet.sol/BoltzSmartWallet.json'; +import MinimalBoltzSmartWalletJson from '../../artifacts/@rsksmart/rif-relay-contracts/contracts/smartwallet/MinimalBoltzSmartWallet.sol/MinimalBoltzSmartWallet.json'; use(chaiAsPromised); @@ -56,12 +66,22 @@ const ONE_FIELD_IN_BYTES = 32; const CHARS_PER_FIELD = 64; const PREFIX_HEX = '0x'; -type SupportedSmartWallet = CustomSmartWallet | SmartWallet | BoltzSmartWallet; +type SupportedSmartWalletName = + | 'CustomSmartWallet' + | 'SmartWallet' + | 'BoltzSmartWallet' + | 'MinimalBoltzSmartWallet'; +type SupportedSmartWallet = + | CustomSmartWallet + | SmartWallet + | BoltzSmartWallet + | MinimalBoltzSmartWallet; type SupportedSmartWalletFactory = | CustomSmartWalletFactory | SmartWalletFactory - | BoltzSmartWalletFactory; -type SupportedType = 'Custom' | 'Boltz' | 'Default'; + | BoltzSmartWalletFactory + | MinimalBoltzSmartWalletFactory; +type SupportedType = 'Custom' | 'Boltz' | 'MinimalBoltz' | 'Default'; type CreateSmartWalletParams = { relayHub: string; @@ -276,39 +296,25 @@ const createSupportedSmartWallet = async ({ ); } - const swAddress = - type === 'Custom' - ? await (factory as CustomSmartWalletFactory).getSmartWalletAddress( - owner.address, - recoverer, - logicAddr, - keccak256(initParams), - index - ) - : await (factory as SmartWalletFactory).getSmartWalletAddress( - owner.address, - recoverer, - index - ); + const swAddress = await getSmartWalletAddress({ + type, + factory, + owner, + recoverer, + logicAddr, + initParams, + index, + }); // We couldn't use ethers.at(...) because we couldn't retrieve the revert reason. + const abis: Record = { + Default: SmartWalletJson.abi, + Custom: CustomSmartWalletJson.abi, + Boltz: BoltzSmartWalletJson.abi, + MinimalBoltz: MinimalBoltzSmartWalletJson.abi, + }; - switch (type) { - case 'Default': - return new Contract(swAddress, SmartWalletJson.abi, owner) as SmartWallet; - case 'Custom': - return new Contract( - swAddress, - CustomSmartWalletJson.abi, - owner - ) as CustomSmartWallet; - case 'Boltz': - return new Contract( - swAddress, - BoltzSmartWalletJson.abi, - owner - ) as BoltzSmartWallet; - } + return new Contract(swAddress, abis[type], owner) as SupportedSmartWallet; }; const prepareRelayTransaction = async ({ @@ -389,7 +395,7 @@ export const signEnvelopingRequest = async ( }; const getSuffixDataAndSignature = async ( - forwarder: SupportedSmartWallet | SmartWalletFactory, + forwarder: SupportedSmartWallet | SupportedSmartWalletFactory, relayRequest: EnvelopingRequest, owner: Wallet ) => { @@ -549,6 +555,39 @@ const createUserDefinedRequest = ( }, }; }; +type GetSmartWalletAddressParams = { + type: SupportedType; + factory: SupportedSmartWalletFactory; + owner: Wallet; + recoverer: string; + index: number; + logicAddr?: string; + initParams?: string; +}; + +async function getSmartWalletAddress({ + type, + factory, + owner, + recoverer, + index, + logicAddr = constants.AddressZero, + initParams = '0x', +}: GetSmartWalletAddressParams) { + return type === 'Custom' + ? await (factory as CustomSmartWalletFactory).getSmartWalletAddress( + owner.address, + recoverer, + logicAddr, + keccak256(initParams), + index + ) + : await (factory as SmartWalletFactory).getSmartWalletAddress( + owner.address, + recoverer, + index + ); +} async function deployContract(contract: string) { const contractFactory = await ethers.getContractFactory(contract); @@ -576,11 +615,14 @@ export { createSupportedSmartWallet, RSK_URL, deployContract, + getSmartWalletAddress, }; export type { CreateSmartWalletParams, PrepareRelayTransactionParams, + SupportedSmartWalletName, SupportedSmartWallet, SupportedSmartWalletFactory, + SupportedType, };