diff --git a/package-lock.json b/package-lock.json index bdd0cb26..36c7f4dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -376,7 +376,8 @@ "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-toolbox": "^4.0.0", "hardhat": "^2.19.3", - "mocha": "^10.2.0" + "mocha": "^10.2.0", + "solhint": "^5.0.1" }, "optionalDependencies": { "fsevents": "^2.3.3" @@ -387,6 +388,43 @@ "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz", "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==" }, + "node_modules/@babel/code-frame": { + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", + "dev": true, + "dependencies": { + "@babel/highlight": "^7.24.7", + "picocolors": "^1.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", + "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", + "dev": true, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/highlight": { + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", + "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", + "dev": true, + "dependencies": { + "@babel/helper-validator-identifier": "^7.24.7", + "chalk": "^2.4.2", + "js-tokens": "^4.0.0", + "picocolors": "^1.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@chainsafe/as-sha256": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/@chainsafe/as-sha256/-/as-sha256-0.3.1.tgz", @@ -1736,6 +1774,47 @@ "node": ">= 10" } }, + "node_modules/@pnpm/config.env-replace": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@pnpm/config.env-replace/-/config.env-replace-1.1.0.tgz", + "integrity": "sha512-htyl8TWnKL7K/ESFa1oW2UB5lVDxuF5DpM7tBi6Hu2LNL3mWkIzNLG6N4zoCUP1lCKNxWy/3iu8mS8MvToGd6w==", + "dev": true, + "engines": { + "node": ">=12.22.0" + } + }, + "node_modules/@pnpm/network.ca-file": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@pnpm/network.ca-file/-/network.ca-file-1.0.2.tgz", + "integrity": "sha512-YcPQ8a0jwYU9bTdJDpXjMi7Brhkr1mXsXrUJvjqM2mQDgkRiz8jFaQGOdaLxgjtUfQgZhKy/O3cG/YwmgKaxLA==", + "dev": true, + "dependencies": { + "graceful-fs": "4.2.10" + }, + "engines": { + "node": ">=12.22.0" + } + }, + "node_modules/@pnpm/network.ca-file/node_modules/graceful-fs": { + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", + "dev": true + }, + "node_modules/@pnpm/npm-conf": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@pnpm/npm-conf/-/npm-conf-2.2.2.tgz", + "integrity": "sha512-UA91GwWPhFExt3IizW6bOeY/pQ0BkuNwKjk9iQW9KqxluGCrg4VenZ0/L+2Y0+ZOtme72EVvg6v0zo3AMQRCeA==", + "dev": true, + "dependencies": { + "@pnpm/config.env-replace": "^1.1.0", + "@pnpm/network.ca-file": "^1.0.1", + "config-chain": "^1.1.11" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@scure/base": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.5.tgz", @@ -1916,6 +1995,18 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" }, + "node_modules/@sindresorhus/is": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-5.6.0.tgz", + "integrity": "sha512-TV7t8GKYaJWsn00tFDqBw8+Uqmr8A0fRU1tvTQhyZzGv0sJCGRQL3JGMI3ucuKo3XIZdUP+Lx7/gh2t3lewy7g==", + "dev": true, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, "node_modules/@solidity-parser/parser": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.14.5.tgz", @@ -1924,6 +2015,18 @@ "antlr4ts": "^0.5.0-alpha.4" } }, + "node_modules/@szmarczak/http-timer": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz", + "integrity": "sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw==", + "dev": true, + "dependencies": { + "defer-to-connect": "^2.0.1" + }, + "engines": { + "node": ">=14.16" + } + }, "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -2026,6 +2129,12 @@ "@types/node": "*" } }, + "node_modules/@types/http-cache-semantics": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", + "integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==", + "dev": true + }, "node_modules/@types/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-5.1.1.tgz", @@ -2262,6 +2371,15 @@ "node": ">=4" } }, + "node_modules/antlr4": { + "version": "4.13.1-patch-1", + "resolved": "https://registry.npmjs.org/antlr4/-/antlr4-4.13.1-patch-1.tgz", + "integrity": "sha512-OjFLWWLzDMV9rdFhpvroCWR4ooktNg9/nvVYSA5z28wuVpU36QUNuioR1XLnQtcjVlf8npjyz593PxnU/f/Cow==", + "dev": true, + "engines": { + "node": ">=16" + } + }, "node_modules/antlr4ts": { "version": "0.5.0-alpha.4", "resolved": "https://registry.npmjs.org/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz", @@ -2326,6 +2444,12 @@ "node": "*" } }, + "node_modules/ast-parents": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/ast-parents/-/ast-parents-0.0.1.tgz", + "integrity": "sha512-XHusKxKz3zoYk1ic8Un640joHbFMhbqneyoZfoKnEGtf2ey9Uh/IdpcQplODdO/kENaMIWsD0nJm4+wX3UNLHA==", + "dev": true + }, "node_modules/astral-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", @@ -2552,6 +2676,33 @@ "node": ">= 0.8" } }, + "node_modules/cacheable-lookup": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-7.0.0.tgz", + "integrity": "sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w==", + "dev": true, + "engines": { + "node": ">=14.16" + } + }, + "node_modules/cacheable-request": { + "version": "10.2.14", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.14.tgz", + "integrity": "sha512-zkDT5WAF4hSSoUgyfg5tFIxz8XQK+25W/TLVojJTMKBaxevLBBtLxgqguAuVQB8PVW79FVjHcU+GJ9tVbDZ9mQ==", + "dev": true, + "dependencies": { + "@types/http-cache-semantics": "^4.0.2", + "get-stream": "^6.0.1", + "http-cache-semantics": "^4.1.1", + "keyv": "^4.5.3", + "mimic-response": "^4.0.0", + "normalize-url": "^8.0.0", + "responselike": "^3.0.0" + }, + "engines": { + "node": ">=14.16" + } + }, "node_modules/call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", @@ -2570,6 +2721,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/camelcase": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", @@ -2915,6 +3075,16 @@ "safe-buffer": "~5.1.0" } }, + "node_modules/config-chain": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz", + "integrity": "sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==", + "dev": true, + "dependencies": { + "ini": "^1.3.4", + "proto-list": "~1.2.1" + } + }, "node_modules/cookie": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", @@ -2928,6 +3098,32 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, + "node_modules/cosmiconfig": { + "version": "8.3.6", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", + "integrity": "sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==", + "dev": true, + "dependencies": { + "import-fresh": "^3.3.0", + "js-yaml": "^4.1.0", + "parse-json": "^5.2.0", + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/d-fischer" + }, + "peerDependencies": { + "typescript": ">=4.9.5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/crc-32": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz", @@ -3022,6 +3218,33 @@ "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==" }, + "node_modules/decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "dev": true, + "dependencies": { + "mimic-response": "^3.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/decompress-response/node_modules/mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/deep-eql": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", @@ -3046,6 +3269,15 @@ "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==" }, + "node_modules/defer-to-connect": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", + "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", @@ -3176,6 +3408,15 @@ "node": ">=6" } }, + "node_modules/error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "dependencies": { + "is-arrayish": "^0.2.1" + } + }, "node_modules/es-define-property": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", @@ -3551,6 +3792,12 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true + }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", @@ -3566,6 +3813,12 @@ "node": ">=8.6.0" } }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", @@ -3660,6 +3913,15 @@ "node": ">= 6" } }, + "node_modules/form-data-encoder": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-2.1.4.tgz", + "integrity": "sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==", + "dev": true, + "engines": { + "node": ">= 14.17" + } + }, "node_modules/fp-ts": { "version": "1.19.3", "resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-1.19.3.tgz", @@ -3757,6 +4019,18 @@ "node": ">=4" } }, + "node_modules/get-stream": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/ghost-testrpc": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/ghost-testrpc/-/ghost-testrpc-0.0.2.tgz", @@ -3852,6 +4126,31 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/got": { + "version": "12.6.1", + "resolved": "https://registry.npmjs.org/got/-/got-12.6.1.tgz", + "integrity": "sha512-mThBblvlAF1d4O5oqyvN+ZxLAYwIJK7bpMxgYqPD9okW0C3qm5FFn7k811QrcuEBwaogR3ngOFoCfs6mRv7teQ==", + "dev": true, + "dependencies": { + "@sindresorhus/is": "^5.2.0", + "@szmarczak/http-timer": "^5.0.1", + "cacheable-lookup": "^7.0.0", + "cacheable-request": "^10.2.8", + "decompress-response": "^6.0.0", + "form-data-encoder": "^2.1.2", + "get-stream": "^6.0.1", + "http2-wrapper": "^2.1.10", + "lowercase-keys": "^3.0.0", + "p-cancelable": "^3.0.0", + "responselike": "^3.0.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sindresorhus/got?sponsor=1" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -4195,6 +4494,12 @@ "node": ">=6.0.0" } }, + "node_modules/http-cache-semantics": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==", + "dev": true + }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -4223,6 +4528,19 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==" }, + "node_modules/http2-wrapper": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-2.2.1.tgz", + "integrity": "sha512-V5nVw1PAOgfI3Lmeaj2Exmeg7fenjhRUgz1lPSezy1CuhPYbgQtbQj4jZfEAEMlaL+vupsvhjqCyjzob0yxsmQ==", + "dev": true, + "dependencies": { + "quick-lru": "^5.1.1", + "resolve-alpn": "^1.2.0" + }, + "engines": { + "node": ">=10.19.0" + } + }, "node_modules/https-proxy-agent": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", @@ -4278,6 +4596,31 @@ "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.3.4.tgz", "integrity": "sha512-fsXeu4J4i6WNWSikpI88v/PcVflZz+6kMhUfIwc5SY+poQRPnaf5V7qds6SUyUN3cVxEzuCab7QIoLOQ+DQ1wA==" }, + "node_modules/import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/import-fresh/node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/indent-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", @@ -4336,6 +4679,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", + "dev": true + }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -4503,6 +4852,12 @@ "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -4514,6 +4869,18 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true + }, + "node_modules/json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "dev": true + }, "node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", @@ -4552,6 +4919,15 @@ "node": ">=10.0.0" } }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "dependencies": { + "json-buffer": "3.0.1" + } + }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -4568,6 +4944,21 @@ "graceful-fs": "^4.1.9" } }, + "node_modules/latest-version": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-7.0.0.tgz", + "integrity": "sha512-KvNT4XqAMzdcL6ka6Tl3i2lYeFDgXNCuIX+xNx6ZMVR1dFq+idXd9FLKNMOIx0t9mJ9/HudyX4oZWXZQ0UJHeg==", + "dev": true, + "dependencies": { + "package-json": "^8.1.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/level": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/level/-/level-8.0.0.tgz", @@ -4616,6 +5007,12 @@ "node": ">= 0.8.0" } }, + "node_modules/lines-and-columns": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", + "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", + "dev": true + }, "node_modules/locate-path": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", @@ -4740,6 +5137,18 @@ "get-func-name": "^2.0.1" } }, + "node_modules/lowercase-keys": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-3.0.0.tgz", + "integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/lru_map": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz", @@ -4846,6 +5255,18 @@ "node": ">= 0.6" } }, + "node_modules/mimic-response": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-4.0.0.tgz", + "integrity": "sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", @@ -5166,6 +5587,18 @@ "node": ">=0.10.0" } }, + "node_modules/normalize-url": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-8.0.1.tgz", + "integrity": "sha512-IO9QvjUMWxPQQhs60oOu10CRkWCiZzSUkzbXGGV9pviYl1fXYcvkzQ5jV9z8Y6un8ARoVRl4EtC6v6jNqbaJ/w==", + "dev": true, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/number-to-bn": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", @@ -5242,6 +5675,15 @@ "node": ">=0.10.0" } }, + "node_modules/p-cancelable": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-3.0.0.tgz", + "integrity": "sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==", + "dev": true, + "engines": { + "node": ">=12.20" + } + }, "node_modules/p-limit": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", @@ -5286,11 +5728,71 @@ "node": ">=4" } }, + "node_modules/package-json": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/package-json/-/package-json-8.1.1.tgz", + "integrity": "sha512-cbH9IAIJHNj9uXi196JVsRlt7cHKak6u/e6AkL/bkRelZ7rlL3X1YKxsZwa36xipOEKAsdtmaG6aAJoM1fx2zA==", + "dev": true, + "dependencies": { + "got": "^12.1.0", + "registry-auth-token": "^5.0.1", + "registry-url": "^6.0.0", + "semver": "^7.3.7" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/package-json/node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/parse-cache-control": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz", "integrity": "sha512-60zvsJReQPX5/QP0Kzfd/VrpjScIQ7SHBW6bFCYfEP+fp0Eppr1SHhIO5nd1PjZtvclzSzES9D/p5nFJurwfWg==" }, + "node_modules/parse-json": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", + "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-even-better-errors": "^2.3.0", + "lines-and-columns": "^1.1.6" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", @@ -5343,6 +5845,12 @@ "node": ">=0.12" } }, + "node_modules/picocolors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", + "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==", + "dev": true + }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -5362,6 +5870,15 @@ "node": ">=6" } }, + "node_modules/pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/possible-typed-array-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", @@ -5405,6 +5922,12 @@ "asap": "~2.0.6" } }, + "node_modules/proto-list": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", + "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==", + "dev": true + }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -5451,6 +5974,18 @@ } ] }, + "node_modules/quick-lru": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", + "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -5473,6 +6008,30 @@ "node": ">= 0.8" } }, + "node_modules/rc": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", + "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "dev": true, + "dependencies": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "bin": { + "rc": "cli.js" + } + }, + "node_modules/rc/node_modules/strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -5527,6 +6086,33 @@ "node": ">=6" } }, + "node_modules/registry-auth-token": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-5.0.2.tgz", + "integrity": "sha512-o/3ikDxtXaA59BmZuZrJZDJv8NMDGSj+6j6XaeBmHw8eY1i1qd9+6H+LjVvQXx3HN6aRCGa1cUdJ9RaJZUugnQ==", + "dev": true, + "dependencies": { + "@pnpm/npm-conf": "^2.1.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/registry-url": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/registry-url/-/registry-url-6.0.1.tgz", + "integrity": "sha512-+crtS5QjFRqFCoQmvGduwYWEBng99ZvmFvF+cUJkGYF1L1BfU8C6Zp9T7f5vPAwyLkUExpvK+ANVZmGU49qi4Q==", + "dev": true, + "dependencies": { + "rc": "1.2.8" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/req-cwd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/req-cwd/-/req-cwd-2.0.0.tgz", @@ -5576,6 +6162,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/resolve-alpn": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz", + "integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==", + "dev": true + }, "node_modules/resolve-from": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", @@ -5584,6 +6176,21 @@ "node": ">=4" } }, + "node_modules/responselike": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-3.0.0.tgz", + "integrity": "sha512-40yHxbNcl2+rzXvZuVkrYohathsSJlMTXKryG5y8uciHv1+xDLHQpgjG64JUO9nrEq2jGLH6IZ8BcZyw3wrweg==", + "dev": true, + "dependencies": { + "lowercase-keys": "^3.0.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -6018,6 +6625,198 @@ "semver": "bin/semver" } }, + "node_modules/solhint": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/solhint/-/solhint-5.0.1.tgz", + "integrity": "sha512-QeQLS9HGCnIiibt+xiOa/+MuP7BWz9N7C5+Mj9pLHshdkNhuo3AzCpWmjfWVZBUuwIUO3YyCRVIcYLR3YOKGfg==", + "dev": true, + "dependencies": { + "@solidity-parser/parser": "^0.18.0", + "ajv": "^6.12.6", + "antlr4": "^4.13.1-patch-1", + "ast-parents": "^0.0.1", + "chalk": "^4.1.2", + "commander": "^10.0.0", + "cosmiconfig": "^8.0.0", + "fast-diff": "^1.2.0", + "glob": "^8.0.3", + "ignore": "^5.2.4", + "js-yaml": "^4.1.0", + "latest-version": "^7.0.0", + "lodash": "^4.17.21", + "pluralize": "^8.0.0", + "semver": "^7.5.2", + "strip-ansi": "^6.0.1", + "table": "^6.8.1", + "text-table": "^0.2.0" + }, + "bin": { + "solhint": "solhint.js" + }, + "optionalDependencies": { + "prettier": "^2.8.3" + } + }, + "node_modules/solhint/node_modules/@solidity-parser/parser": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.18.0.tgz", + "integrity": "sha512-yfORGUIPgLck41qyN7nbwJRAx17/jAIXCTanHOJZhB6PJ1iAk/84b/xlsVKFSyNyLXIj0dhppoE0+CRws7wlzA==", + "dev": true + }, + "node_modules/solhint/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/solhint/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/solhint/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/solhint/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/solhint/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/solhint/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/solhint/node_modules/commander": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", + "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", + "dev": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/solhint/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/solhint/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/solhint/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/solhint/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/solhint/node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/solhint/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/solidity-coverage": { "version": "0.8.5", "resolved": "https://registry.npmjs.org/solidity-coverage/-/solidity-coverage-0.8.5.tgz", @@ -6354,6 +7153,12 @@ "node": ">=8" } }, + "node_modules/text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true + }, "node_modules/then-request": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/then-request/-/then-request-6.0.2.tgz", diff --git a/package.json b/package.json index 2589c133..397c182f 100644 --- a/package.json +++ b/package.json @@ -379,7 +379,8 @@ "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-toolbox": "^4.0.0", "hardhat": "^2.19.3", - "mocha": "^10.2.0" + "mocha": "^10.2.0", + "solhint": "^5.0.1" }, "scripts": { "test": "mocha" diff --git a/src/core/ClientChainGateway.sol b/src/core/ClientChainGateway.sol index cd081c27..aa6e1e51 100644 --- a/src/core/ClientChainGateway.sol +++ b/src/core/ClientChainGateway.sol @@ -63,16 +63,6 @@ contract ClientChainGateway is require(owner_ != address(0), "ClientChainGateway: contract owner should not be empty"); - _registeredResponseHooks[Action.REQUEST_DEPOSIT] = this.afterReceiveDepositResponse.selector; - _registeredResponseHooks[Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE] = - this.afterReceiveWithdrawPrincipalResponse.selector; - _registeredResponseHooks[Action.REQUEST_DELEGATE_TO] = this.afterReceiveDelegateResponse.selector; - _registeredResponseHooks[Action.REQUEST_UNDELEGATE_FROM] = this.afterReceiveUndelegateResponse.selector; - _registeredResponseHooks[Action.REQUEST_WITHDRAW_REWARD_FROM_EXOCORE] = - this.afterReceiveWithdrawRewardResponse.selector; - _registeredResponseHooks[Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO] = - this.afterReceiveDepositThenDelegateToResponse.selector; - _whiteListFunctionSelectors[Action.REQUEST_ADD_WHITELIST_TOKENS] = this.afterReceiveAddWhitelistTokensRequest.selector; @@ -108,10 +98,6 @@ contract ClientChainGateway is _unpause(); } - function addWhitelistTokens(address[] calldata) external onlyOwner whenNotPaused { - revert("this function is not supported for client chain, please register on Exocore"); - } - // implementation of ITokenWhitelister function getWhitelistedTokensCount() external view returns (uint256) { return whitelistTokens.length; diff --git a/src/core/ClientGatewayLzReceiver.sol b/src/core/ClientGatewayLzReceiver.sol index f0813615..995d3236 100644 --- a/src/core/ClientGatewayLzReceiver.sol +++ b/src/core/ClientGatewayLzReceiver.sol @@ -36,27 +36,7 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp Action act = Action(uint8(payload[0])); if (act == Action.RESPOND) { - uint64 requestId = uint64(bytes8(payload[1:9])); - - Action requestAct = _registeredRequestActions[requestId]; - bytes4 hookSelector = _registeredResponseHooks[requestAct]; - if (hookSelector == bytes4(0)) { - revert UnsupportedResponse(act); - } - - bytes memory requestPayload = _registeredRequests[requestId]; - if (requestPayload.length == 0) { - revert UnexpectedResponse(requestId); - } - - (bool success, bytes memory reason) = - address(this).call(abi.encodePacked(hookSelector, abi.encode(requestPayload, payload[9:]))); - if (!success) { - revert RequestOrResponseExecuteFailed(act, _origin.nonce, reason); - } - - delete _registeredRequestActions[requestId]; - delete _registeredRequests[requestId]; + _handleResponse(payload); } else { bytes4 selector_ = _whiteListFunctionSelectors[act]; if (selector_ == bytes4(0)) { @@ -81,121 +61,157 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp return inboundNonce[srcEid][sender] + 1; } - function afterReceiveDepositResponse(bytes memory requestPayload, bytes calldata responsePayload) - public - onlyCalledFromThis - { - (address token, address depositor, uint256 amount) = abi.decode(requestPayload, (address, address, uint256)); - - bool success = (uint8(bytes1(responsePayload[0])) == 1); - uint256 lastlyUpdatedPrincipalBalance = uint256(bytes32(responsePayload[1:])); - - if (!success) { - revert DepositShouldNotFailOnExocore(token, depositor); - } - - if (token == VIRTUAL_STAKED_ETH_ADDRESS) { - IExoCapsule capsule = _getCapsule(depositor); - capsule.updatePrincipalBalance(lastlyUpdatedPrincipalBalance); + // Though this function makes external calls to contract Vault or ExoCapsule, we just update their state variables + // and don't make + // calls to other contracts that do not belong to Exocore. + // And (success, updatedBalance) would be updated according to response message. + // slither-disable-next-line reentrancy-no-eth + function _handleResponse(bytes calldata response) internal { + (uint64 requestId, Action requestAct, bytes memory cachedRequest) = _getCachedRequestForResponse(response); + + bool success = false; + uint256 updatedBalance; + + if (_expectBasicResponse(requestAct)) { + success = _decodeBasicResponse(response); + } else if (_expectBalanceResponse(requestAct)) { + (address token, address staker,, uint256 amount) = _decodeCachedRequest(requestAct, cachedRequest); + (success, updatedBalance) = _decodeBalanceResponse(response); + + if (_isPrincipalType(requestAct)) { + // we assume deposit request must always be successful, thus we should always update balance for deposit + // request + // Notice: Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO is a special operation that is not atomic, since + // deposit should always be successful while delegate could fail for some cases + if (success || _isDeposit(requestAct)) { + _updatePrincipalAssetState(requestAct, token, staker, amount, updatedBalance); + } + } else { + // otherwise this is an operation aimed at reward since Action.REQUEST_WITHDRAW_REWARD_FROM_EXOCORE is + // the only asset operation request that deals with reward instead of principal + if (success) { + IVault vault = _getVault(token); + + vault.updateRewardBalance(staker, updatedBalance); + if (_isWithdrawal(requestAct)) { + vault.updateWithdrawableBalance(staker, 0, amount); + } + } + } } else { - IVault vault = _getVault(token); - vault.updatePrincipalBalance(depositor, lastlyUpdatedPrincipalBalance); + revert UnsupportedResponse(requestAct); } - emit DepositResult(success, token, depositor, amount); + delete _registeredRequestActions[requestId]; + delete _registeredRequests[requestId]; + + emit RequestFinished(requestAct, requestId, success); } - function afterReceiveWithdrawPrincipalResponse(bytes memory requestPayload, bytes calldata responsePayload) - public - onlyCalledFromThis - { - (address token, address withdrawer, uint256 unlockPrincipalAmount) = - abi.decode(requestPayload, (address, address, uint256)); + function _getCachedRequestForResponse(bytes calldata response) internal returns (uint64, Action, bytes memory) { + uint64 requestId = uint64(bytes8(response[1:9])); - bool success = (uint8(bytes1(responsePayload[0])) == 1); - uint256 lastlyUpdatedPrincipalBalance = uint256(bytes32(responsePayload[1:33])); + bytes memory cachedRequest = _registeredRequests[requestId]; + if (cachedRequest.length == 0) { + revert UnexpectedResponse(requestId); + } + Action requestAct = _registeredRequestActions[requestId]; - if (!success) { - emit WithdrawFailedOnExocore(token, withdrawer); - } else { - if (token == VIRTUAL_STAKED_ETH_ADDRESS) { - IExoCapsule capsule = _getCapsule(withdrawer); + return (requestId, requestAct, cachedRequest); + } - capsule.updatePrincipalBalance(lastlyUpdatedPrincipalBalance); - capsule.updateWithdrawableBalance(unlockPrincipalAmount); - } else { - IVault vault = _getVault(token); + function _isAssetOperationRequest(Action action) internal pure returns (bool) { + return action == Action.REQUEST_DEPOSIT || action == Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE + || action == Action.REQUEST_WITHDRAW_REWARD_FROM_EXOCORE; + } - vault.updatePrincipalBalance(withdrawer, lastlyUpdatedPrincipalBalance); - vault.updateWithdrawableBalance(withdrawer, unlockPrincipalAmount, 0); - } + function _isStakingOperationRequest(Action action) internal pure returns (bool) { + return action == Action.REQUEST_DELEGATE_TO || action == Action.REQUEST_UNDELEGATE_FROM + || action == Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO; + } - emit WithdrawPrincipalResult(success, token, withdrawer, unlockPrincipalAmount); - } + // Basic response only includes reqeust execution status, no other informations like balance update + // and it is typically the response of a staking only operations. + function _expectBasicResponse(Action action) internal pure returns (bool) { + return action == Action.REQUEST_DELEGATE_TO || action == Action.REQUEST_UNDELEGATE_FROM; } - function afterReceiveWithdrawRewardResponse(bytes memory requestPayload, bytes calldata responsePayload) - public - onlyCalledFromThis - { - (address token, address withdrawer, uint256 unlockRewardAmount) = - abi.decode(requestPayload, (address, address, uint256)); + // Balance response includes not only request execution status, but also the balance update informations, + // so it is typically the response of an asset operation. + function _expectBalanceResponse(Action action) internal pure returns (bool) { + return action == Action.REQUEST_DEPOSIT || action == Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE + || action == Action.REQUEST_WITHDRAW_REWARD_FROM_EXOCORE || action == Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO; + } - bool success = (uint8(bytes1(responsePayload[0])) == 1); - uint256 lastlyUpdatedRewardBalance = uint256(bytes32(responsePayload[1:33])); - if (success) { - IVault vault = _getVault(token); + function _isPrincipalType(Action action) internal pure returns (bool) { + return action == Action.REQUEST_DEPOSIT || action == Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE + || action == Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO; + } - vault.updateRewardBalance(withdrawer, lastlyUpdatedRewardBalance); - vault.updateWithdrawableBalance(withdrawer, 0, unlockRewardAmount); - } + function _isWithdrawal(Action action) internal pure returns (bool) { + return action == Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE + || action == Action.REQUEST_WITHDRAW_REWARD_FROM_EXOCORE; + } - emit WithdrawRewardResult(success, token, withdrawer, unlockRewardAmount); + function _isDeposit(Action action) internal pure returns (bool) { + return action == Action.REQUEST_DEPOSIT || action == Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO; } - function afterReceiveDelegateResponse(bytes memory requestPayload, bytes calldata responsePayload) - public - onlyCalledFromThis + function _decodeCachedRequest(Action requestAct, bytes memory cachedRequest) + internal + pure + returns (address token, address staker, string memory operator, uint256 amount) { - (address token, address delegator, string memory operator, uint256 amount) = - abi.decode(requestPayload, (address, address, string, uint256)); - - bool success = (uint8(bytes1(responsePayload[0])) == 1); + if (_isAssetOperationRequest(requestAct)) { + (token, staker, amount) = abi.decode(cachedRequest, (address, address, uint256)); + } else if (_isStakingOperationRequest(requestAct)) { + (token, staker, operator, amount) = abi.decode(cachedRequest, (address, address, string, uint256)); + } else { + revert UnsupportedRequest(requestAct); + } - emit DelegateResult(success, delegator, operator, token, amount); + return (token, staker, operator, amount); } - function afterReceiveUndelegateResponse(bytes memory requestPayload, bytes calldata responsePayload) - public - onlyCalledFromThis + function _decodeBalanceResponse(bytes calldata response) + internal + pure + returns (bool success, uint256 updatedBalance) { - (address token, address undelegator, string memory operator, uint256 amount) = - abi.decode(requestPayload, (address, address, string, uint256)); - - bool success = (uint8(bytes1(responsePayload[0])) == 1); + success = (uint8(bytes1(response[9])) == 1); + updatedBalance = uint256(bytes32(response[10:])); - emit UndelegateResult(success, undelegator, operator, token, amount); + return (success, updatedBalance); } - function afterReceiveDepositThenDelegateToResponse(bytes memory requestPayload, bytes calldata responsePayload) - public - onlyCalledFromThis - { - (address token, address delegator, string memory operator, uint256 amount) = - abi.decode(requestPayload, (address, address, string, uint256)); + function _decodeBasicResponse(bytes calldata response) internal pure returns (bool success) { + success = (uint8(bytes1(response[9])) == 1); - bool delegateSuccess = (uint8(bytes1(responsePayload[0])) == 1); - uint256 lastlyUpdatedPrincipalBalance = uint256(bytes32(responsePayload[1:])); + return success; + } + function _updatePrincipalAssetState( + Action requestAct, + address token, + address staker, + uint256 amount, + uint256 updatedBalance + ) internal { if (token == VIRTUAL_STAKED_ETH_ADDRESS) { - IExoCapsule capsule = _getCapsule(delegator); - capsule.updatePrincipalBalance(lastlyUpdatedPrincipalBalance); + IExoCapsule capsule = _getCapsule(staker); + + capsule.updatePrincipalBalance(updatedBalance); + if (_isWithdrawal(requestAct)) { + capsule.updateWithdrawableBalance(amount); + } } else { IVault vault = _getVault(token); - vault.updatePrincipalBalance(delegator, lastlyUpdatedPrincipalBalance); - } - emit DepositThenDelegateResult(delegateSuccess, delegator, operator, token, amount); + vault.updatePrincipalBalance(staker, updatedBalance); + if (_isWithdrawal(requestAct)) { + vault.updateWithdrawableBalance(staker, amount, 0); + } + } } // Though `_deployVault` would make external call to newly created `Vault` contract and initialize it, diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 27d02b9b..2bead261 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -296,6 +296,8 @@ contract ExocoreGateway is } _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, success, updatedBalance), true); + + emit DepositResult(true, bytes32(token), bytes32(depositor), amount); } function requestWithdrawPrincipal(uint32 srcChainId, uint64 lzNonce, bytes calldata payload) @@ -310,15 +312,19 @@ contract ExocoreGateway is bytes memory withdrawer = payload[32:64]; uint256 amount = uint256(bytes32(payload[64:96])); + bool result = false; try ASSETS_CONTRACT.withdrawPrincipal(srcChainId, token, withdrawer, amount) returns ( bool success, uint256 updatedBalance ) { + result = success; _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, success, updatedBalance), true); } catch { emit ExocorePrecompileError(ASSETS_PRECOMPILE_ADDRESS, lzNonce); _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, false, uint256(0)), true); } + + emit WithdrawPrincipalResult(result, bytes32(token), bytes32(withdrawer), amount); } function requestWithdrawReward(uint32 srcChainId, uint64 lzNonce, bytes calldata payload) @@ -331,15 +337,19 @@ contract ExocoreGateway is bytes memory withdrawer = payload[32:64]; uint256 amount = uint256(bytes32(payload[64:96])); + bool result = false; try CLAIM_REWARD_CONTRACT.claimReward(srcChainId, token, withdrawer, amount) returns ( bool success, uint256 updatedBalance ) { + result = success; _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, success, updatedBalance), true); } catch { emit ExocorePrecompileError(CLAIM_REWARD_PRECOMPILE_ADDRESS, lzNonce); _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, false, uint256(0)), true); } + + emit WithdrawRewardResult(result, bytes32(token), bytes32(withdrawer), amount); } function requestDelegateTo(uint32 srcChainId, uint64 lzNonce, bytes calldata payload) public onlyCalledFromThis { @@ -350,14 +360,18 @@ contract ExocoreGateway is bytes memory operator = payload[64:106]; uint256 amount = uint256(bytes32(payload[106:138])); + bool result = false; try DELEGATION_CONTRACT.delegateToThroughClientChain(srcChainId, lzNonce, token, delegator, operator, amount) returns (bool success) { + result = success; _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, success), true); } catch { emit ExocorePrecompileError(DELEGATION_PRECOMPILE_ADDRESS, lzNonce); _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, false), true); } + + emit DelegateResult(result, bytes32(token), bytes32(delegator), string(operator), amount); } function requestUndelegateFrom(uint32 srcChainId, uint64 lzNonce, bytes calldata payload) @@ -371,15 +385,19 @@ contract ExocoreGateway is bytes memory operator = payload[64:106]; uint256 amount = uint256(bytes32(payload[106:138])); + bool result = false; try DELEGATION_CONTRACT.undelegateFromThroughClientChain( srcChainId, lzNonce, token, delegator, operator, amount ) returns (bool success) { + result = success; _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, success), true); } catch { emit ExocorePrecompileError(DELEGATION_PRECOMPILE_ADDRESS, lzNonce); _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, false), true); } + + emit UndelegateResult(result, bytes32(token), bytes32(delegator), string(operator), amount); } function requestDepositThenDelegateTo(uint32 srcChainId, uint64 lzNonce, bytes calldata payload) @@ -399,12 +417,16 @@ contract ExocoreGateway is // for example, you cannot index a bytes memory result from the requestDepositTo call, // if you were to modify it to return bytes and then process them here. + bool result = false; (bool success, uint256 updatedBalance) = ASSETS_CONTRACT.depositTo(srcChainId, token, depositor, amount); if (!success) { revert DepositRequestShouldNotFail(srcChainId, lzNonce); } + emit DepositResult(true, bytes32(token), bytes32(depositor), amount); + try DELEGATION_CONTRACT.delegateToThroughClientChain(srcChainId, lzNonce, token, depositor, operator, amount) returns (bool delegateSuccess) { + result = delegateSuccess; _sendInterchainMsg( srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, delegateSuccess, updatedBalance), true ); @@ -412,6 +434,7 @@ contract ExocoreGateway is emit ExocorePrecompileError(DELEGATION_PRECOMPILE_ADDRESS, lzNonce); _sendInterchainMsg(srcChainId, Action.RESPOND, abi.encodePacked(lzNonce, false, updatedBalance), true); } + emit DelegateResult(result, bytes32(token), bytes32(depositor), string(operator), amount); } function _validatePayloadLength(bytes calldata payload, uint256 expectedLength, Action action) private pure { diff --git a/src/interfaces/IClientChainGateway.sol b/src/interfaces/IClientChainGateway.sol index 95acfab9..9b919576 100644 --- a/src/interfaces/IClientChainGateway.sol +++ b/src/interfaces/IClientChainGateway.sol @@ -1,20 +1,12 @@ pragma solidity ^0.8.19; import {INativeRestakingController} from "../interfaces/INativeRestakingController.sol"; - -import {ITokenWhitelister} from "../interfaces/ITokenWhitelister.sol"; import {ILSTRestakingController} from "./ILSTRestakingController.sol"; import {IOAppCore} from "@layerzero-v2/oapp/contracts/oapp/interfaces/IOAppCore.sol"; import {IOAppReceiver} from "@layerzero-v2/oapp/contracts/oapp/interfaces/IOAppReceiver.sol"; -interface IClientChainGateway is - ITokenWhitelister, - IOAppReceiver, - IOAppCore, - ILSTRestakingController, - INativeRestakingController -{ +interface IClientChainGateway is IOAppReceiver, IOAppCore, ILSTRestakingController, INativeRestakingController { function quote(bytes memory _message) external view returns (uint256 nativeFee); diff --git a/src/storage/BootstrapStorage.sol b/src/storage/BootstrapStorage.sol index 5570bfaf..f092ff8d 100644 --- a/src/storage/BootstrapStorage.sol +++ b/src/storage/BootstrapStorage.sol @@ -300,23 +300,6 @@ contract BootstrapStorage is GatewayStorage { bool indexed success, address indexed undelegator, string indexed undelegatee, address token, uint256 amount ); - /** - * @notice Emitted when a deposit + delegation is made. - * @dev This event is triggered whenever a delegator deposits and then delegates tokens to an operator. - * @param delegateSuccess Whether the delegation succeeded (deposits always succeed!). - * @param delegator The address of the delegator, on this chain. - * @param delegatee The Exocore address of the operator. - * @param token The address of the token being delegated, on this chain. - * @param delegatedAmount The amount of the token delegated. - */ - event DepositThenDelegateResult( - bool indexed delegateSuccess, - address indexed delegator, - string indexed delegatee, - address token, - uint256 delegatedAmount - ); - /** * @notice Emitted after the Exocore chain is bootstrapped. * @dev This event is triggered after the Exocore chain is bootstrapped, indicating that diff --git a/src/storage/ClientChainGatewayStorage.sol b/src/storage/ClientChainGatewayStorage.sol index a4b15338..4617f5e4 100644 --- a/src/storage/ClientChainGatewayStorage.sol +++ b/src/storage/ClientChainGatewayStorage.sol @@ -16,7 +16,6 @@ contract ClientChainGatewayStorage is BootstrapStorage { mapping(address => IExoCapsule) public ownerToCapsule; mapping(uint64 => bytes) internal _registeredRequests; mapping(uint64 => Action) internal _registeredRequestActions; - mapping(Action => bytes4) internal _registeredResponseHooks; // immutable state variables address public immutable BEACON_ORACLE_ADDRESS; @@ -42,7 +41,7 @@ contract ClientChainGatewayStorage is BootstrapStorage { /* ----------------------------- restaking ----------------------------- */ event ClaimSucceeded(address token, address recipient, uint256 amount); - event WithdrawRewardResult(bool indexed success, address indexed token, address indexed withdrawer, uint256 amount); + event RequestFinished(Action indexed action, uint64 indexed requestId, bool indexed success); /* -------------------------------------------------------------------------- */ /* Errors */ diff --git a/src/storage/ExocoreGatewayStorage.sol b/src/storage/ExocoreGatewayStorage.sol index 4fcb74e6..c6ca2ba3 100644 --- a/src/storage/ExocoreGatewayStorage.sol +++ b/src/storage/ExocoreGatewayStorage.sol @@ -31,6 +31,19 @@ contract ExocoreGatewayStorage is GatewayStorage { event WhitelistTokenAdded(uint32 clientChainId, bytes32 token); event WhitelistTokenUpdated(uint32 clientChainId, bytes32 token); + /* --------- asset operations results and staking operations results -------- */ + event WithdrawRewardResult(bool indexed success, bytes32 indexed token, bytes32 indexed withdrawer, uint256 amount); + event DepositResult(bool indexed success, bytes32 indexed token, bytes32 indexed depositor, uint256 amount); + event WithdrawPrincipalResult( + bool indexed success, bytes32 indexed token, bytes32 indexed withdrawer, uint256 amount + ); + event DelegateResult( + bool indexed success, bytes32 indexed token, bytes32 indexed delegator, string operator, uint256 amount + ); + event UndelegateResult( + bool indexed success, bytes32 indexed token, bytes32 indexed undelegator, string operator, uint256 amount + ); + error RequestExecuteFailed(Action act, uint64 nonce, bytes reason); error PrecompileCallFailed(bytes4 selector_, bytes reason); error InvalidRequestLength(Action act, uint256 expectedLength, uint256 actualLength); diff --git a/src/storage/GatewayStorage.sol b/src/storage/GatewayStorage.sol index 07ce10a6..b30f7902 100644 --- a/src/storage/GatewayStorage.sol +++ b/src/storage/GatewayStorage.sol @@ -17,14 +17,14 @@ contract GatewayStorage { mapping(Action => bytes4) internal _whiteListFunctionSelectors; mapping(uint32 eid => mapping(bytes32 sender => uint64 nonce)) public inboundNonce; + uint256[40] private __gap; + event MessageSent(Action indexed act, bytes32 packetId, uint64 nonce, uint256 nativeFee); error UnsupportedRequest(Action act); error UnexpectedSourceChain(uint32 unexpectedSrcEndpointId); error UnexpectedInboundNonce(uint64 expectedNonce, uint64 actualNonce); - uint256[40] private __gap; - function _verifyAndUpdateNonce(uint32 srcChainId, bytes32 srcAddress, uint64 nonce) internal { uint64 expectedNonce = inboundNonce[srcChainId][srcAddress] + 1; if (nonce != expectedNonce) { diff --git a/test/foundry/Delegation.t.sol b/test/foundry/Delegation.t.sol index e39e64d4..f1078e1d 100644 --- a/test/foundry/Delegation.t.sol +++ b/test/foundry/Delegation.t.sol @@ -26,10 +26,10 @@ contract DelegateTest is ExocoreDeployer { string operatorAddress; event DelegateResult( - bool indexed success, address indexed delegator, string indexed delegatee, address token, uint256 amount + bool indexed success, bytes32 indexed token, bytes32 indexed delegator, string operator, uint256 amount ); event UndelegateResult( - bool indexed success, address indexed undelegator, string indexed undelegatee, address token, uint256 amount + bool indexed success, bytes32 indexed token, bytes32 indexed undelegator, string operator, uint256 amount ); event DelegateRequestProcessed( uint32 clientChainLzId, @@ -151,6 +151,16 @@ contract DelegateTest is ExocoreDeployer { vm.expectEmit(true, true, true, true, address(exocoreGateway)); emit MessageSent(GatewayStorage.Action.RESPOND, responseId, delegateResponseNonce, responseNativeFee); + /// exocoreGateway contract should emit DelegateResult event + vm.expectEmit(true, true, true, true, address(exocoreGateway)); + emit DelegateResult( + true, + bytes32(bytes20(address(restakeToken))), + bytes32(bytes20(delegator.addr)), + operatorAddress, + delegateAmount + ); + /// relayer call layerzero endpoint to deliver request messages and generate response message vm.startPrank(relayer.addr); exocoreLzEndpoint.lzReceive( @@ -171,10 +181,10 @@ contract DelegateTest is ExocoreDeployer { // 3. third layerzero relayers should watch the response message packet and relay the message to source chain // endpoint - /// after relayer relay the response message back to client chain, clientGateway should emit DelegateResult + /// after relayer relay the response message back to client chain, clientGateway should emit RequestFinished /// event vm.expectEmit(true, true, true, true, address(clientGateway)); - emit DelegateResult(true, delegator.addr, operatorAddress, address(restakeToken), delegateAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_DELEGATE_TO, delegateRequestNonce, true); /// relayer should watch the response message and relay it back to client chain vm.startPrank(relayer.addr); @@ -264,6 +274,16 @@ contract DelegateTest is ExocoreDeployer { vm.expectEmit(true, true, true, true, address(exocoreGateway)); emit MessageSent(GatewayStorage.Action.RESPOND, responseId, undelegateResponseNonce, responseNativeFee); + /// exocoreGateway contract should emit UndelegateResult event + vm.expectEmit(true, true, true, true, address(exocoreGateway)); + emit UndelegateResult( + true, + bytes32(bytes20(address(restakeToken))), + bytes32(bytes20(delegator.addr)), + operatorAddress, + undelegateAmount + ); + /// relayer call layerzero endpoint to deliver request messages and generate response message vm.startPrank(relayer.addr); exocoreLzEndpoint.lzReceive( @@ -283,10 +303,10 @@ contract DelegateTest is ExocoreDeployer { // 3. third layerzero relayers should watch the response message packet and relay the message to source chain // endpoint - /// after relayer relay the response message back to client chain, clientGateway should emit UndelegateResult + /// after relayer relay the response message back to client chain, clientGateway should emit RequestFinished /// event vm.expectEmit(true, true, true, true, address(clientGateway)); - emit UndelegateResult(true, delegator.addr, operatorAddress, address(restakeToken), undelegateAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_UNDELEGATE_FROM, undelegateRequestNonce, true); /// relayer should watch the response message and relay it back to client chain vm.startPrank(relayer.addr); diff --git a/test/foundry/DepositThenDelegateTo.t.sol b/test/foundry/DepositThenDelegateTo.t.sol index 5303e9c5..a30494d4 100644 --- a/test/foundry/DepositThenDelegateTo.t.sol +++ b/test/foundry/DepositThenDelegateTo.t.sol @@ -21,13 +21,10 @@ contract DepositThenDelegateToTest is ExocoreDeployer { using AddressCast for address; - // ClientChainGateway emits this when receiving the response - event DepositThenDelegateResult( - bool indexed delegateSuccess, - address indexed delegator, - string indexed delegatee, - address token, - uint256 delegatedAmount + // ExocoreGateway emits these two events after handling the request + event DepositResult(bool indexed success, bytes32 indexed token, bytes32 indexed depositor, uint256 amount); + event DelegateResult( + bool indexed success, bytes32 indexed token, bytes32 indexed delegator, string operator, uint256 amount ); // emitted by the mock delegation contract @@ -79,6 +76,36 @@ contract DepositThenDelegateToTest is ExocoreDeployer { ); } + function test_BalanceUpdatedWhen_DepositThenDelegateToResponseNotSuccess() public { + address delegator = players[0].addr; + address relayer = players[1].addr; + string memory operatorAddress = "exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac"; + + deal(delegator, 1e22); + deal(address(exocoreGateway), 1e22); + + uint64 requestLzNonce = 1; + uint64 responseLzNonce = 2; + uint256 delegateAmount = 10_000; + + // before all operations we should add whitelist tokens + test_AddWhitelistTokens(); + + // ensure there is enough balance + vm.startPrank(exocoreValidatorSet.addr); + restakeToken.transfer(delegator, delegateAmount); + vm.stopPrank(); + + // approve it + vm.startPrank(delegator); + restakeToken.approve(address(vault), delegateAmount); + vm.stopPrank(); + + (bytes32 requestId, bytes memory requestPayload) = + _testRequest(delegator, operatorAddress, requestLzNonce, delegateAmount); + _testFailureResponse(delegator, relayer, requestLzNonce, responseLzNonce, delegateAmount); + } + function _testRequest(address delegator, string memory operatorAddress, uint64 lzNonce, uint256 delegateAmount) private returns (bytes32 requestId, bytes memory requestPayload) @@ -137,6 +164,11 @@ contract DepositThenDelegateToTest is ExocoreDeployer { uint256 responseNativeFee = exocoreGateway.quote(clientChainId, responsePayload); bytes32 responseId = generateUID(responseLzNonce, false); + // deposit request is firstly handled and its event is firstly emitted + vm.expectEmit(address(exocoreGateway)); + emit DepositResult(true, bytes32(bytes20(address(restakeToken))), bytes32(bytes20(delegator)), delegateAmount); + + // secondly delegate request is handled vm.expectEmit(DELEGATION_PRECOMPILE_ADDRESS); emit DelegateRequestProcessed( clientChainId, @@ -160,6 +192,11 @@ contract DepositThenDelegateToTest is ExocoreDeployer { vm.expectEmit(address(exocoreGateway)); emit MessageSent(GatewayStorage.Action.RESPOND, responseId, responseLzNonce, responseNativeFee); + vm.expectEmit(address(exocoreGateway)); + emit DelegateResult( + true, bytes32(bytes20(address(restakeToken))), bytes32(bytes20(delegator)), operatorAddress, delegateAmount + ); + vm.startPrank(relayer); exocoreLzEndpoint.lzReceive( Origin(clientChainId, address(clientGateway).toBytes32(), requestLzNonce), @@ -189,7 +226,36 @@ contract DepositThenDelegateToTest is ExocoreDeployer { assertEq(actualDelegateAmount, delegateAmount); vm.expectEmit(true, true, true, true, address(clientGateway)); - emit DepositThenDelegateResult(true, delegator, operatorAddress, address(restakeToken), delegateAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO, requestLzNonce, true); + + vm.startPrank(relayer); + clientChainLzEndpoint.lzReceive( + Origin(exocoreChainId, address(exocoreGateway).toBytes32(), responseLzNonce), + address(clientGateway), + responseId, + responsePayload, + bytes("") + ); + vm.stopPrank(); + } + + function _testFailureResponse( + address delegator, + address relayer, + uint64 requestLzNonce, + uint64 responseLzNonce, + uint256 delegateAmount + ) private { + // we assume delegation failed for some reason + bool delegateSuccess = false; + bytes memory responsePayload = + abi.encodePacked(GatewayStorage.Action.RESPOND, requestLzNonce, delegateSuccess, delegateAmount); + uint256 responseNativeFee = exocoreGateway.quote(clientChainId, responsePayload); + bytes32 responseId = generateUID(responseLzNonce, false); + + // request finished with successful deposit and failed delegation + vm.expectEmit(true, true, true, true, address(clientGateway)); + emit RequestFinished(GatewayStorage.Action.REQUEST_DEPOSIT_THEN_DELEGATE_TO, requestLzNonce, delegateSuccess); vm.startPrank(relayer); clientChainLzEndpoint.lzReceive( @@ -200,6 +266,9 @@ contract DepositThenDelegateToTest is ExocoreDeployer { bytes("") ); vm.stopPrank(); + + // though delegation has failed, the principal balance for delegator should be updated + assertEq(vault.principalBalances(delegator), delegateAmount); } } diff --git a/test/foundry/DepositWithdrawPrinciple.t.sol b/test/foundry/DepositWithdrawPrinciple.t.sol index 44271540..106651a9 100644 --- a/test/foundry/DepositWithdrawPrinciple.t.sol +++ b/test/foundry/DepositWithdrawPrinciple.t.sol @@ -19,9 +19,9 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { using AddressCast for address; using stdStorage for StdStorage; - event DepositResult(bool indexed success, address indexed token, address indexed depositor, uint256 amount); + event DepositResult(bool indexed success, bytes32 indexed token, bytes32 indexed depositor, uint256 amount); event WithdrawPrincipalResult( - bool indexed success, address indexed token, address indexed withdrawer, uint256 amount + bool indexed success, bytes32 indexed token, bytes32 indexed withdrawer, uint256 amount ); event Transfer(address indexed from, address indexed to, uint256 amount); event MessageProcessed(uint32 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes _payload); @@ -50,11 +50,20 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { // before deposit we should add whitelist tokens test_AddWhitelistTokens(); + uint256 principalBalanceBefore = vault.principalBalances(depositor.addr); + uint256 withdrawableBefore = vault.getWithdrawableBalance(depositor.addr); _testLSTDeposit(depositor, depositAmount, lastlyUpdatedPrincipalBalance); + assertEq(principalBalanceBefore + depositAmount, vault.principalBalances(depositor.addr)); + assertEq(withdrawableBefore, vault.getWithdrawableBalance(depositor.addr)); lastlyUpdatedPrincipalBalance += depositAmount; + principalBalanceBefore = vault.principalBalances(depositor.addr); + withdrawableBefore = vault.getWithdrawableBalance(depositor.addr); _testLSTWithdraw(depositor, withdrawAmount, lastlyUpdatedPrincipalBalance); + + assertEq(principalBalanceBefore - withdrawAmount, vault.principalBalances(depositor.addr)); + assertEq(withdrawableBefore + withdrawAmount, vault.getWithdrawableBalance(depositor.addr)); } function _testLSTDeposit(Player memory depositor, uint256 depositAmount, uint256 lastlyUpdatedPrincipalBalance) @@ -119,6 +128,10 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { emit MessageSent( GatewayStorage.Action.RESPOND, depositResponseId, depositResponseNonce, depositResponseNativeFee ); + vm.expectEmit(true, true, true, true, address(exocoreGateway)); + emit DepositResult( + true, bytes32(bytes20(address(restakeToken))), bytes32(bytes20(depositor.addr)), depositAmount + ); exocoreLzEndpoint.lzReceive( Origin(clientChainId, address(clientGateway).toBytes32(), depositRequestNonce), address(exocoreGateway), @@ -130,9 +143,9 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { // third layerzero relayers should watch the response message packet and relay the message to source chain // endpoint - // client chain gateway should execute the response hook and emit depositResult event + // client chain gateway should execute the response hook and emit RequestFinished event vm.expectEmit(true, true, true, true, address(clientGateway)); - emit DepositResult(true, address(restakeToken), depositor.addr, depositAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_DEPOSIT, depositRequestNonce, true); clientChainLzEndpoint.lzReceive( Origin(exocoreChainId, address(exocoreGateway).toBytes32(), depositResponseNonce), address(clientGateway), @@ -204,6 +217,10 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { emit MessageSent( GatewayStorage.Action.RESPOND, withdrawResponseId, withdrawResponseNonce, withdrawResponseNativeFee ); + vm.expectEmit(true, true, true, true, address(exocoreGateway)); + emit WithdrawPrincipalResult( + true, bytes32(bytes20(address(restakeToken))), bytes32(bytes20(withdrawer.addr)), withdrawAmount + ); exocoreLzEndpoint.lzReceive( Origin(clientChainId, address(clientGateway).toBytes32(), withdrawRequestNonce), address(exocoreGateway), @@ -215,9 +232,9 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { // third layerzero relayers should watch the response message packet and relay the message to source chain // endpoint - // client chain gateway should execute the response hook and emit depositResult event + // client chain gateway should execute the response hook and emit RequestFinished event vm.expectEmit(true, true, true, true, address(clientGateway)); - emit WithdrawPrincipalResult(true, address(restakeToken), withdrawer.addr, withdrawAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE, withdrawRequestNonce, true); clientChainLzEndpoint.lzReceive( Origin(exocoreChainId, address(exocoreGateway).toBytes32(), withdrawResponseNonce), address(clientGateway), @@ -233,6 +250,12 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { uint256 lastlyUpdatedPrincipalBalance; + uint256 depositAmount = uint256(_getEffectiveBalance(validatorContainer)) * GWEI_TO_WEI; + // Cap to 32 ether + if (depositAmount >= 32 ether) { + depositAmount = 32 ether; + } + // transfer some ETH to depositor for staking and paying for gas fee deal(depositor.addr, 1e22); // transfer some gas fee to relayer for paying for onboarding cross-chain message packet @@ -244,52 +267,41 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { // before deposit we should add whitelist tokens test_AddWhitelistTokens(); + _stakeAndPrepareCapsuleBeforeDeposit(depositor); + + uint256 principalBalanceBefore = capsule.principalBalance(); + uint256 withdrawableBefore = capsule.withdrawableBalance(); _testNativeDeposit(depositor, relayer, lastlyUpdatedPrincipalBalance); + assertEq(principalBalanceBefore + depositAmount, capsule.principalBalance()); + assertEq(withdrawableBefore, capsule.withdrawableBalance()); + lastlyUpdatedPrincipalBalance += 32 ether; + + // before native withdraw, we simulate proper block environment states to make proof valid + _simulateBlockEnvironmentForNativeWithdraw(); + deal(address(capsule), 1 ether); // Deposit 1 ether to handle excess amount withdraw + uint64 withdrawalAmountGwei = _getWithdrawalAmount(withdrawalContainer); + uint256 withdrawalAmount; + if (withdrawalAmountGwei > MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR) { + withdrawalAmount = MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR * GWEI_TO_WEI; + } else { + withdrawalAmount = withdrawalAmountGwei * GWEI_TO_WEI; + } + + console.log("deposit amount:", depositAmount); + console.log("withdrawal amount:", withdrawalAmount); + + principalBalanceBefore = capsule.principalBalance(); + withdrawableBefore = capsule.withdrawableBalance(); _testNativeWithdraw(depositor, relayer, lastlyUpdatedPrincipalBalance); + assertEq(principalBalanceBefore - withdrawalAmount, capsule.principalBalance()); + assertEq(withdrawableBefore + withdrawalAmount, capsule.withdrawableBalance()); } function _testNativeDeposit(Player memory depositor, Player memory relayer, uint256 lastlyUpdatedPrincipalBalance) internal { - // before native stake and deposit, we simulate proper block environment states to make proof valid - _simulateBlockEnvironmentForNativeDeposit(); - - // 1. firstly depositor should stake to beacon chain by depositing 32 ETH to ETHPOS contract - IExoCapsule expectedCapsule = IExoCapsule( - Create2.computeAddress( - bytes32(uint256(uint160(depositor.addr))), - keccak256(abi.encodePacked(BEACON_PROXY_BYTECODE, abi.encode(address(capsuleBeacon), ""))), - address(clientGateway) - ) - ); - vm.expectEmit(true, true, true, true, address(clientGateway)); - emit CapsuleCreated(depositor.addr, address(expectedCapsule)); - emit StakedWithCapsule(depositor.addr, address(expectedCapsule)); - - vm.startPrank(depositor.addr); - clientGateway.stake{value: 32 ether}(abi.encodePacked(_getPubkey(validatorContainer)), bytes(""), bytes32(0)); - vm.stopPrank(); - - // do some hack to replace expectedCapsule address with capsule address loaded from proof file - // because capsule address is expected to be compatible with validator container withdrawal credentails - address capsuleAddress = _getCapsuleFromWithdrawalCredentials(_getWithdrawalCredentials(validatorContainer)); - vm.etch(capsuleAddress, address(expectedCapsule).code); - capsule = ExoCapsule(payable(capsuleAddress)); - stdstore.target(capsuleAddress).sig("_beacon()").checked_write(address(capsuleBeacon)); - assertEq(stdstore.target(capsuleAddress).sig("_beacon()").read_address(), address(capsuleBeacon)); - - /// replace expectedCapsule with capsule - bytes32 capsuleSlotInGateway = bytes32( - stdstore.target(address(clientGatewayLogic)).sig("ownerToCapsule(address)").with_key(depositor.addr).find() - ); - vm.store(address(clientGateway), capsuleSlotInGateway, bytes32(uint256(uint160(address(capsule))))); - assertEq(address(clientGateway.ownerToCapsule(depositor.addr)), address(capsule)); - - /// initialize replaced capsule - capsule.initialize(address(clientGateway), depositor.addr, address(beaconOracle)); - - // 2. next depositor call clientGateway.depositBeaconChainValidator to deposit into Exocore from client chain + // 1. next depositor call clientGateway.depositBeaconChainValidator to deposit into Exocore from client chain // through layerzero /// client chain layerzero endpoint should emit the message packet including deposit payload. @@ -328,7 +340,7 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { clientGateway.depositBeaconChainValidator{value: depositRequestNativeFee}(validatorContainer, validatorProof); vm.stopPrank(); - // 3. thirdly layerzero relayers should watch the request message packet and relay the message to destination + // 2. thirdly layerzero relayers should watch the request message packet and relay the message to destination // endpoint /// exocore gateway should return response message to exocore network layerzero endpoint @@ -353,6 +365,13 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { emit MessageSent( GatewayStorage.Action.RESPOND, depositResponseId, depositResponseNonce, depositResponseNativeFee ); + + /// exocore gateway should emit DepositResult event + vm.expectEmit(true, true, true, true, address(exocoreGateway)); + emit DepositResult( + true, bytes32(bytes20(VIRTUAL_STAKED_ETH_ADDRESS)), bytes32(bytes20(depositor.addr)), depositAmount + ); + /// relayer catches the request message packet by listening to client chain event and feed it to Exocore network vm.startPrank(relayer.addr); exocoreLzEndpoint.lzReceive( @@ -367,9 +386,9 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { // At last layerzero relayers should watch the response message packet and relay the message back to source // chain endpoint - /// client chain gateway should execute the response hook and emit depositResult event + /// client chain gateway should execute the response hook and emit RequestFinished event vm.expectEmit(true, true, true, true, address(clientGateway)); - emit DepositResult(true, VIRTUAL_STAKED_ETH_ADDRESS, depositor.addr, depositAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_DEPOSIT, depositRequestNonce, true); /// relayer catches the response message packet by listening to Exocore event and feed it to client chain vm.startPrank(relayer.addr); @@ -383,6 +402,31 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { vm.stopPrank(); } + function _stakeAndPrepareCapsuleBeforeDeposit(Player memory depositor) internal { + // before native stake and deposit, we simulate proper block environment states to make proof valid + _simulateBlockEnvironmentForNativeDeposit(); + + // 1. firstly depositor should stake to beacon chain by depositing 32 ETH to ETHPOS contract + IExoCapsule expectedCapsule = IExoCapsule( + Create2.computeAddress( + bytes32(uint256(uint160(depositor.addr))), + keccak256(abi.encodePacked(BEACON_PROXY_BYTECODE, abi.encode(address(capsuleBeacon), ""))), + address(clientGateway) + ) + ); + vm.expectEmit(true, true, true, true, address(clientGateway)); + emit CapsuleCreated(depositor.addr, address(expectedCapsule)); + emit StakedWithCapsule(depositor.addr, address(expectedCapsule)); + + vm.startPrank(depositor.addr); + clientGateway.stake{value: 32 ether}(abi.encodePacked(_getPubkey(validatorContainer)), bytes(""), bytes32(0)); + vm.stopPrank(); + + // do some hack to replace expectedCapsule address with capsule address loaded from proof file + // because capsule address is expected to be compatible with validator container withdrawal credentails + _attachCapsuleToWithdrawalCredentials(expectedCapsule, depositor); + } + function _simulateBlockEnvironmentForNativeDeposit() internal { /// we set the timestamp of proof to be exactly the timestamp that the validator container get activated on /// beacon chain @@ -402,14 +446,28 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { ); } + function _attachCapsuleToWithdrawalCredentials(IExoCapsule createdCapsule, Player memory depositor) internal { + address capsuleAddress = _getCapsuleFromWithdrawalCredentials(_getWithdrawalCredentials(validatorContainer)); + vm.etch(capsuleAddress, address(createdCapsule).code); + capsule = ExoCapsule(payable(capsuleAddress)); + stdstore.target(capsuleAddress).sig("_beacon()").checked_write(address(capsuleBeacon)); + assertEq(stdstore.target(capsuleAddress).sig("_beacon()").read_address(), address(capsuleBeacon)); + + /// replace expectedCapsule with capsule + bytes32 capsuleSlotInGateway = bytes32( + stdstore.target(address(clientGatewayLogic)).sig("ownerToCapsule(address)").with_key(depositor.addr).find() + ); + vm.store(address(clientGateway), capsuleSlotInGateway, bytes32(uint256(uint160(address(capsule))))); + assertEq(address(clientGateway.ownerToCapsule(depositor.addr)), address(capsule)); + + /// initialize replaced capsule + capsule.initialize(address(clientGateway), depositor.addr, address(beaconOracle)); + } + function _testNativeWithdraw(Player memory withdrawer, Player memory relayer, uint256 lastlyUpdatedPrincipalBalance) internal { - // before native withdraw, we simulate proper block environment states to make proof valid - _simulateBlockEnvironmentForNativeWithdraw(); - deal(address(capsule), 1 ether); // Deposit 1 ether to handle excess amount withdraw - - // 2. withdrawer will call clientGateway.processBeaconChainWithdrawal to withdraw from Exocore thru layerzero + // 1. withdrawer will call clientGateway.processBeaconChainWithdrawal to withdraw from Exocore thru layerzero /// client chain layerzero endpoint should emit the message packet including deposit payload. uint64 withdrawRequestNonce = 2; @@ -475,6 +533,13 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { emit MessageSent( GatewayStorage.Action.RESPOND, withdrawResponseId, withdrawResponseNonce, withdrawResponseNativeFee ); + + // exocore gateway should emit WithdrawPrincipalResult event + vm.expectEmit(true, true, true, true, address(exocoreGateway)); + emit WithdrawPrincipalResult( + true, bytes32(bytes20(VIRTUAL_STAKED_ETH_ADDRESS)), bytes32(bytes20(withdrawer.addr)), withdrawalAmount + ); + exocoreLzEndpoint.lzReceive( Origin(clientChainId, address(clientGateway).toBytes32(), withdrawRequestNonce), address(exocoreGateway), @@ -483,9 +548,9 @@ contract DepositWithdrawPrincipalTest is ExocoreDeployer { bytes("") ); - // client chain gateway should execute the response hook and emit depositResult event + // client chain gateway should execute the response hook and emit RequestFinished event vm.expectEmit(true, true, true, true, address(clientGateway)); - emit WithdrawPrincipalResult(true, address(VIRTUAL_STAKED_ETH_ADDRESS), withdrawer.addr, withdrawalAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_WITHDRAW_PRINCIPAL_FROM_EXOCORE, withdrawRequestNonce, true); clientChainLzEndpoint.lzReceive( Origin(exocoreChainId, address(exocoreGateway).toBytes32(), withdrawResponseNonce), address(clientGateway), diff --git a/test/foundry/ExocoreDeployer.t.sol b/test/foundry/ExocoreDeployer.t.sol index 09fa9b9c..fa7c926a 100644 --- a/test/foundry/ExocoreDeployer.t.sol +++ b/test/foundry/ExocoreDeployer.t.sol @@ -103,6 +103,7 @@ contract ExocoreDeployer is Test { event NewPacket(uint32, address, bytes32, uint64, bytes); event WhitelistTokenAdded(address _token); event VaultCreated(address underlyingToken, address vault); + event RequestFinished(GatewayStorage.Action indexed action, uint64 indexed requestId, bool indexed success); function setUp() public virtual { players.push(Player({privateKey: uint256(0x1), addr: vm.addr(uint256(0x1))})); diff --git a/test/foundry/WithdrawReward.t.sol b/test/foundry/WithdrawReward.t.sol index a39cb973..43446489 100644 --- a/test/foundry/WithdrawReward.t.sol +++ b/test/foundry/WithdrawReward.t.sol @@ -13,8 +13,7 @@ contract WithdrawRewardTest is ExocoreDeployer { using AddressCast for address; - event DepositResult(bool indexed success, address indexed token, address indexed depositor, uint256 amount); - event WithdrawRewardResult(bool indexed success, address indexed token, address indexed withdrawer, uint256 amount); + event WithdrawRewardResult(bool indexed success, bytes32 indexed token, bytes32 indexed withdrawer, uint256 amount); event Transfer(address indexed from, address indexed to, uint256 amount); event MessageProcessed(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes _payload); @@ -90,6 +89,12 @@ contract WithdrawRewardTest is ExocoreDeployer { vm.expectEmit(true, true, true, true, address(exocoreGateway)); emit MessageSent(GatewayStorage.Action.RESPOND, responseId, withdrawResponseNonce, responseNativeFee); + // exocore gateway should emit WithdrawRewardResult event + vm.expectEmit(true, true, true, true, address(exocoreGateway)); + emit WithdrawRewardResult( + true, bytes32(bytes20(address(restakeToken))), bytes32(bytes20(withdrawer.addr)), withdrawAmount + ); + vm.startPrank(relayer.addr); exocoreLzEndpoint.lzReceive( Origin(clientChainId, address(clientGateway).toBytes32(), withdrawRequestNonce), @@ -103,9 +108,9 @@ contract WithdrawRewardTest is ExocoreDeployer { // third layerzero relayers should watch the response message packet and relay the message to source chain // endpoint - // client chain gateway should execute the response hook and emit depositResult event + // client chain gateway should execute the response hook and emit RequestFinished event vm.expectEmit(true, true, true, true, address(clientGateway)); - emit WithdrawRewardResult(true, address(restakeToken), withdrawer.addr, withdrawAmount); + emit RequestFinished(GatewayStorage.Action.REQUEST_WITHDRAW_REWARD_FROM_EXOCORE, withdrawRequestNonce, true); vm.startPrank(relayer.addr); clientChainLzEndpoint.lzReceive( diff --git a/test/foundry/unit/ClientChainGateway.t.sol b/test/foundry/unit/ClientChainGateway.t.sol index 4db65ea8..1fb0d60f 100644 --- a/test/foundry/unit/ClientChainGateway.t.sol +++ b/test/foundry/unit/ClientChainGateway.t.sol @@ -273,34 +273,3 @@ contract Initialize is SetUp { } } - -contract AddWhitelistTokens is SetUp { - - using stdStorage for StdStorage; - - function test_RevertWhen_CallerNotOwner() public { - address[] memory whitelistTokens = new address[](2); - - vm.startPrank(deployer.addr); - vm.expectRevert("Ownable: caller is not the owner"); - clientGateway.addWhitelistTokens(whitelistTokens); - } - - function test_RevertWhen_Paused() public { - vm.startPrank(exocoreValidatorSet.addr); - clientGateway.pause(); - - address[] memory whitelistTokens = new address[](2); - vm.expectRevert("Pausable: paused"); - clientGateway.addWhitelistTokens(whitelistTokens); - } - - function test_Revert_NotSupported() public { - address[] memory whitelistTokens = new address[](2); - - vm.startPrank(exocoreValidatorSet.addr); - vm.expectRevert("this function is not supported for client chain, please register on Exocore"); - clientGateway.addWhitelistTokens(whitelistTokens); - } - -}