From adbcc4f3dcc194510d4005a1f1b0889421126520 Mon Sep 17 00:00:00 2001 From: akorchyn Date: Mon, 18 Mar 2024 16:26:51 +0200 Subject: [PATCH] fixed stake --- package-lock.json | 416 +++++++++++++++++++++++++++++++++---------- package.json | 2 +- snapshotter/stake.js | 53 +++--- 3 files changed, 356 insertions(+), 115 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35e12da..b83ea7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,11 +13,180 @@ "big.js": "^6.1.1", "commander": "^12.0.0", "fs": "^0.0.1security", - "near-api-js": "^0.44.2", + "near-api-js": "3.0.4", "p-retry": "^6.2.0", "pg": "^8.11.3" } }, + "node_modules/@near-js/accounts": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@near-js/accounts/-/accounts-1.0.4.tgz", + "integrity": "sha512-6zgSwq/rQ9ggPOIkGUx9RoEurbJiojqA/axeh6o1G+46GqUBI7SUcDooyVvZjeiOvUPObnTQptDYpbV+XZji8g==", + "dependencies": { + "@near-js/crypto": "1.2.1", + "@near-js/providers": "0.1.1", + "@near-js/signers": "0.1.1", + "@near-js/transactions": "1.1.2", + "@near-js/types": "0.0.4", + "@near-js/utils": "0.1.0", + "ajv": "8.11.2", + "ajv-formats": "2.1.1", + "bn.js": "5.2.1", + "borsh": "1.0.0", + "depd": "2.0.0", + "lru_map": "0.4.1", + "near-abi": "0.1.1" + } + }, + "node_modules/@near-js/crypto": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@near-js/crypto/-/crypto-1.2.1.tgz", + "integrity": "sha512-iJOHaGKvdudYfR8nEtRhGlgcTEHeVmxMoT0JVXmuP3peG96v/sSnA03CE6MZBeCC8txKAQOffagxE7oU6hJp9g==", + "dependencies": { + "@near-js/types": "0.0.4", + "@near-js/utils": "0.1.0", + "@noble/curves": "1.2.0", + "bn.js": "5.2.1", + "borsh": "1.0.0", + "randombytes": "2.1.0" + } + }, + "node_modules/@near-js/keystores": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/@near-js/keystores/-/keystores-0.0.9.tgz", + "integrity": "sha512-j8ySgVEcm2Gg6zxkSdadNtPlIqhJZdPGfWWM3tPtEoowNS9snhwZn5NRFPrgmX0+MzpF7E091CRcY90MvRVhsg==", + "dependencies": { + "@near-js/crypto": "1.2.1", + "@near-js/types": "0.0.4" + } + }, + "node_modules/@near-js/keystores-browser": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/@near-js/keystores-browser/-/keystores-browser-0.0.9.tgz", + "integrity": "sha512-JzPj+RHJN2G3CEm/LyfbtZDQy/wxgOlqfh52voqPGijUHg93b27KBqtZShazAgJNkhzRbWcoluWQnd2jL8vF7A==", + "dependencies": { + "@near-js/crypto": "1.2.1", + "@near-js/keystores": "0.0.9" + } + }, + "node_modules/@near-js/keystores-node": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/@near-js/keystores-node/-/keystores-node-0.0.9.tgz", + "integrity": "sha512-2B9MYz6uIhysG1fhQSjvaPYCM7gM+UAeDchX0J8QRauXIeN8TGzpcdgkdkMUnWNTIdt3Iblh0ZuCs+FY02dTXg==", + "dependencies": { + "@near-js/crypto": "1.2.1", + "@near-js/keystores": "0.0.9" + } + }, + "node_modules/@near-js/providers": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@near-js/providers/-/providers-0.1.1.tgz", + "integrity": "sha512-0M/Vz2Ac34ShKVoe2ftVJ5Qg4eSbEqNXDbCDOdVj/2qbLWZa7Wpe+me5ei4TMY2ZhGdawhgJUPrYwdJzOCyf8w==", + "dependencies": { + "@near-js/transactions": "1.1.2", + "@near-js/types": "0.0.4", + "@near-js/utils": "0.1.0", + "bn.js": "5.2.1", + "borsh": "1.0.0", + "http-errors": "1.7.2" + }, + "optionalDependencies": { + "node-fetch": "2.6.7" + } + }, + "node_modules/@near-js/signers": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@near-js/signers/-/signers-0.1.1.tgz", + "integrity": "sha512-focJgs04dBUfawMnyGg3yIjaMawuVz2OeLRKC4t5IQDmO4PLfdIraEuwgS7tckMq3GdrJ7nqkwkpSNYpdt7I5Q==", + "dependencies": { + "@near-js/crypto": "1.2.1", + "@near-js/keystores": "0.0.9", + "@noble/hashes": "1.3.3" + } + }, + "node_modules/@near-js/transactions": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@near-js/transactions/-/transactions-1.1.2.tgz", + "integrity": "sha512-AqYA56ncwgrWjIu+bNaWjTPRZb0O+SfpWIP7U+1FKNKxNYMCtkt6zp7SlQeZn743shKVq9qMzA9+ous/KCb0QQ==", + "dependencies": { + "@near-js/crypto": "1.2.1", + "@near-js/signers": "0.1.1", + "@near-js/types": "0.0.4", + "@near-js/utils": "0.1.0", + "@noble/hashes": "1.3.3", + "bn.js": "5.2.1", + "borsh": "1.0.0" + } + }, + "node_modules/@near-js/types": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@near-js/types/-/types-0.0.4.tgz", + "integrity": "sha512-8TTMbLMnmyG06R5YKWuS/qFG1tOA3/9lX4NgBqQPsvaWmDsa+D+QwOkrEHDegped0ZHQwcjAXjKML1S1TyGYKg==", + "dependencies": { + "bn.js": "5.2.1" + } + }, + "node_modules/@near-js/utils": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@near-js/utils/-/utils-0.1.0.tgz", + "integrity": "sha512-kOVAXmJzaC8ElJD3RLEoBuqOK+d5s7jc0JkvhyEtbuEmXYHHAy9Q17/YkDcX9tyr01L85iOt66z0cODqzgtQwA==", + "dependencies": { + "@near-js/types": "0.0.4", + "bn.js": "5.2.1", + "bs58": "4.0.0", + "depd": "2.0.0", + "mustache": "4.0.0" + } + }, + "node_modules/@near-js/wallet-account": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@near-js/wallet-account/-/wallet-account-1.1.1.tgz", + "integrity": "sha512-NnoJKtogBQ7Qz+AP+LdF70BP8Az6UXQori7OjPqJLMo73bn6lh5Ywvegwd1EB7ZEVe4BRt9+f9QkbU5M8ANfAw==", + "dependencies": { + "@near-js/accounts": "1.0.4", + "@near-js/crypto": "1.2.1", + "@near-js/keystores": "0.0.9", + "@near-js/signers": "0.1.1", + "@near-js/transactions": "1.1.2", + "@near-js/types": "0.0.4", + "@near-js/utils": "0.1.0", + "bn.js": "5.2.1", + "borsh": "1.0.0" + } + }, + "node_modules/@noble/curves": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", + "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", + "dependencies": { + "@noble/hashes": "1.3.2" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/curves/node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@supercharge/promise-pool": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@supercharge/promise-pool/-/promise-pool-2.4.0.tgz", @@ -26,17 +195,57 @@ "node": ">=8" } }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==" + }, "node_modules/@types/retry": { "version": "0.12.2", "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.2.tgz", "integrity": "sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow==" }, + "node_modules/ajv": { + "version": "8.11.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.2.tgz", + "integrity": "sha512-E4bfmKAhGiSTvMfL1Myyycaub+cUEU2/IvpylXkUu7CHBkBj1f/ikdzbD7YQ6FKUbixDxeYvB/xY4fvyroDlQg==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/base-x": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.9.tgz", - "integrity": "sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-2.0.6.tgz", + "integrity": "sha512-UAmjxz9KbK+YIi66xej+pZVo/vxUOh49ubEvZW5egCbxhur05pBb+hwuireQwKO4nDpsNm64/jEei17LEpsr5g==", + "deprecated": "use 3.0.0 instead, safe-buffer has been merged and release for compatability", "dependencies": { "safe-buffer": "^5.0.1" + }, + "engines": { + "node": ">=4.5.0" } }, "node_modules/big.js": { @@ -52,26 +261,21 @@ } }, "node_modules/bn.js": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.0.tgz", - "integrity": "sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw==" + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", + "integrity": "sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==" }, "node_modules/borsh": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/borsh/-/borsh-0.6.0.tgz", - "integrity": "sha512-sl5k89ViqsThXQpYa9XDtz1sBl3l1lI313cFUY1HKr+wvMILnb+58xpkqTNrYbelh99dY7K8usxoCusQmqix9Q==", - "dependencies": { - "bn.js": "^5.2.0", - "bs58": "^4.0.0", - "text-encoding-utf-8": "^1.0.2" - } + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/borsh/-/borsh-1.0.0.tgz", + "integrity": "sha512-fSVWzzemnyfF89EPwlUNsrS5swF5CrtiN4e+h0/lLf4dz2he4L3ndM20PS9wj7ICSkXJe/TQUHdaPTq15b1mNQ==" }, "node_modules/bs58": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", - "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.0.tgz", + "integrity": "sha512-/jcGuUuSebyxwLLfKrbKnCJttxRf9PM51EnHTwmFKBxl4z1SGkoAhrfd6uZKE0dcjQTfm6XzTP8DPr1tzE4KIw==", "dependencies": { - "base-x": "^3.0.2" + "base-x": "^2.0.1" } }, "node_modules/buffer-writer": { @@ -82,11 +286,6 @@ "node": ">=4" } }, - "node_modules/capability": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/capability/-/capability-0.2.5.tgz", - "integrity": "sha512-rsJZYVCgXd08sPqwmaIqjAd5SUTfonV0z/gDJ8D6cN8wQphky1kkAYEqQ+hmDxTw7UihvBfjUVUSY+DBEe44jg==" - }, "node_modules/commander": { "version": "12.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", @@ -103,15 +302,10 @@ "node": ">= 0.8" } }, - "node_modules/error-polyfill": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/error-polyfill/-/error-polyfill-0.1.3.tgz", - "integrity": "sha512-XHJk60ufE+TG/ydwp4lilOog549iiQF2OAPhkk9DdiYWMrltz5yhDz/xnKuenNwP7gy3dsibssO5QpVhkrSzzg==", - "dependencies": { - "capability": "^0.2.5", - "o3": "^1.0.3", - "u3": "^0.1.1" - } + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "node_modules/fs": { "version": "0.0.1-security", @@ -119,15 +313,15 @@ "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" }, "node_modules/http-errors": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", - "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", + "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", "dependencies": { "depd": "~1.1.2", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", + "inherits": "2.0.3", + "setprototypeof": "1.1.1", "statuses": ">= 1.5.0 < 2", - "toidentifier": "1.0.1" + "toidentifier": "1.0.0" }, "engines": { "node": ">= 0.6" @@ -142,9 +336,9 @@ } }, "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" }, "node_modules/is-network-error": { "version": "1.0.1", @@ -157,41 +351,66 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/js-sha256": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", - "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, + "node_modules/lru_map": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.4.1.tgz", + "integrity": "sha512-I+lBvqMMFfqaV8CJCISjI3wbjmwVu/VyOoU7+qtu9d7ioW5klMgsTTiUOUp+DJvfTTzKXoPbyC6YfgkNcyPSOg==" }, "node_modules/mustache": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", - "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.0.0.tgz", + "integrity": "sha512-FJgjyX/IVkbXBXYUwH+OYwQKqWpFPLaLVESd70yHjSDunwzV2hZOoTBvPf4KLoxesUzzyfTH6F784Uqd7Wm5yA==", "bin": { "mustache": "bin/mustache" + }, + "engines": { + "npm": ">=1.4.0" + } + }, + "node_modules/near-abi": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/near-abi/-/near-abi-0.1.1.tgz", + "integrity": "sha512-RVDI8O+KVxRpC3KycJ1bpfVj9Zv+xvq9PlW1yIFl46GhrnLw83/72HqHGjGDjQ8DtltkcpSjY9X3YIGZ+1QyzQ==", + "dependencies": { + "@types/json-schema": "^7.0.11" } }, "node_modules/near-api-js": { - "version": "0.44.2", - "resolved": "https://registry.npmjs.org/near-api-js/-/near-api-js-0.44.2.tgz", - "integrity": "sha512-eMnc4V+geggapEUa3nU2p8HSHn/njtloI4P2mceHQWO8vDE1NGpnAw8FuTBrLmXSgIv9m6oocgFc9t3VNf5zwg==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/near-api-js/-/near-api-js-3.0.4.tgz", + "integrity": "sha512-qKWjnugoB7kSFhzZ5GXyH/eABspCQYWBmWnM4hpV5ctnQBt89LqgEu9yD1z4sa89MvUu8BuCxwb1m00BE8iofg==", "dependencies": { - "bn.js": "5.2.0", - "borsh": "^0.6.0", - "bs58": "^4.0.0", - "depd": "^2.0.0", - "error-polyfill": "^0.1.3", - "http-errors": "^1.7.2", - "js-sha256": "^0.9.0", - "mustache": "^4.0.0", - "node-fetch": "^2.6.1", - "text-encoding-utf-8": "^1.0.2", - "tweetnacl": "^1.0.1" + "@near-js/accounts": "1.0.4", + "@near-js/crypto": "1.2.1", + "@near-js/keystores": "0.0.9", + "@near-js/keystores-browser": "0.0.9", + "@near-js/keystores-node": "0.0.9", + "@near-js/providers": "0.1.1", + "@near-js/signers": "0.1.1", + "@near-js/transactions": "1.1.2", + "@near-js/types": "0.0.4", + "@near-js/utils": "0.1.0", + "@near-js/wallet-account": "1.1.1", + "@noble/curves": "1.2.0", + "ajv": "8.11.2", + "ajv-formats": "2.1.1", + "bn.js": "5.2.1", + "borsh": "1.0.0", + "depd": "2.0.0", + "http-errors": "1.7.2", + "near-abi": "0.1.1", + "node-fetch": "2.6.7" } }, "node_modules/node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -207,14 +426,6 @@ } } }, - "node_modules/o3": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/o3/-/o3-1.0.3.tgz", - "integrity": "sha512-f+4n+vC6s4ysy7YO7O2gslWZBUu8Qj2i2OUJOvjRxQva7jVjYjB29jrr9NCjmxZQR0gzrOcv1RnqoYOeMs5VRQ==", - "dependencies": { - "capability": "^0.2.5" - } - }, "node_modules/p-retry": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-6.2.0.tgz", @@ -354,6 +565,30 @@ "node": ">=0.10.0" } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "engines": { + "node": ">=6" + } + }, + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dependencies": { + "safe-buffer": "^5.1.0" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/retry": { "version": "0.13.1", "resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz", @@ -382,9 +617,9 @@ ] }, "node_modules/setprototypeof": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", + "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, "node_modules/split2": { "version": "4.2.0", @@ -402,15 +637,10 @@ "node": ">= 0.6" } }, - "node_modules/text-encoding-utf-8": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/text-encoding-utf-8/-/text-encoding-utf-8-1.0.2.tgz", - "integrity": "sha512-8bw4MY9WjdsD2aMtO0OzOCY3pXGYNx2d2FfHRVUKkiCPDWjKuOlhLVASS+pD7VkLTVjW268LYJHwsnPFlBpbAg==" - }, "node_modules/toidentifier": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", - "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", + "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==", "engines": { "node": ">=0.6" } @@ -420,15 +650,13 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, - "node_modules/tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" - }, - "node_modules/u3": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/u3/-/u3-0.1.1.tgz", - "integrity": "sha512-+J5D5ir763y+Am/QY6hXNRlwljIeRMZMGs0cT6qqZVVzzT3X3nFPXVyPOFRMOR4kupB0T8JnCdpWdp6Q/iXn3w==" + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dependencies": { + "punycode": "^2.1.0" + } }, "node_modules/webidl-conversions": { "version": "3.0.1", diff --git a/package.json b/package.json index 2078ea7..7fb0709 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "big.js": "^6.1.1", "commander": "^12.0.0", "fs": "^0.0.1security", - "near-api-js": "^0.44.2", + "near-api-js": "3.0.4", "p-retry": "^6.2.0", "pg": "^8.11.3" } diff --git a/snapshotter/stake.js b/snapshotter/stake.js index 3e76bd8..9c37f89 100644 --- a/snapshotter/stake.js +++ b/snapshotter/stake.js @@ -87,8 +87,7 @@ const processLockup = async (lockup) => { .then(owner => { console.log(`Lockup ${lockup} owned by ${owner} at block ${blockId}`); return owner - }) - .catch((e) => console.error(e)); + }); }; const processLockups = async (delegators) => { @@ -98,8 +97,9 @@ const processLockups = async (delegators) => { .withConcurrency(24) .for(lockupDelegators) .process(async (lockupAccount) => { - let account_id = await pRetry(() => processLockup(lockupAccount), { retries: 100 }); - return { lockupAccount, account_id }; + return pRetry(() => processLockup(lockupAccount).then((account_id) => { + return { lockupAccount, account_id }; + }), { retries: 500, onFailedAttempt }); }); if (lockupErrors.length > 0) { @@ -127,14 +127,18 @@ async function checkRecordsExist(client, accountIds) { } +let recursePrevent = {}; + async function loadDelegatorsFromValidators(validators) { console.log(`Loading delegators from ${validators.length} validators...`); const { results: allValidatorsDetails, errors: poolsError } = await PromisePool .withConcurrency(8) - .for(validators) - .process(async (accountId) => - pRetry(() => _near.viewCall(accountId, "get_number_of_accounts", {}, blockId), { shouldRetry: (err) => !err.message.includes("MethodResolveError(MethodNotFound)"), retries: 100 }) - .then(number_of_accounts => ({ account_id: accountId, number_of_accounts })) + .for(validators.filter(accountId => recursePrevent[accountId] !== 1)) + .process(async (accountId) => { + recursePrevent[accountId] = 1; + return pRetry(() => _near.viewCall(accountId, "get_number_of_accounts", {}, blockId), { shouldRetry: (err) => !err.message.includes("Contract method is not found"), onFailedAttempt, retries: 100 }) + .then(number_of_accounts => ({ account_id: accountId, number_of_accounts })); + } ); @@ -161,7 +165,7 @@ async function loadDelegatorsFromValidators(validators) { }, blockId).then((accounts) => { console.log(`Loading ${validatorRequest.account_id} delegators: batch #${1 + validatorRequest.from_index / 100}, added ${accounts.length} accounts`) return accounts; - }), { retries: 100, shouldRetry: (err) => !err.message.includes("MethodResolveError(MethodNotFound)") }); + }), { retries: 100, factor: 1, shouldRetry: (err) => !err.message.includes("Contract method is not found"), onFailedAttempt }); return data; }); if (delegatorsError.length > 0) { @@ -190,13 +194,19 @@ async function addToDatabase(client, accounts) { if (accounts === undefined || accounts.length === 0) { return {}; } - const accountString = accounts.map((value) => `'${value}'`).join(', '); - const query = `INSERT INTO ${tableName} (${columnName}) VALUES (${accountString})`; + const accountString = accounts.map((value) => `('${value}')`).join(', '); + const query = `INSERT INTO ${tableName} (${columnName}) VALUES ${accountString}`; const res = await client.query(query); return res; } +const onFailedAttempt = (error) => { + if (error.attemptNumber > 5) { + console.log(`Failed attempt for ${error.attemptNumber}: ${error.message}$`) + } +}; + async function processGaps(accountsOrPools, client) { if (accountsOrPools === undefined || accountsOrPools.length === 0) { return {}; @@ -205,16 +215,19 @@ async function processGaps(accountsOrPools, client) { // Check if user has a contract console.log(`Checking ${accountsOrPools.length} accounts...`) let { results: accounts, errors } = await PromisePool - .withConcurrency(8) + .withConcurrency(24) .for(accountsOrPools) .process(async (account) => pRetry(() => _near.viewAccount(account.account_id, blockId) .then((data) => { return { ...account, data } }), { - retries: 20, - // Account deleted :( - shouldRetry: (err) => !err.message.includes("does not exist while viewing") + retries: 100, factor: 1, + // Account deleted :( or invalid params it means it's some internal account or something like that (see ..NSLP..) + // https://github.com/Narwallets/meta-pool/blob/04b6ed9f53be93b94b17fb8135163be7b25bf710/metapool/src/types.rs#L14 + shouldRetry: (err) => !err.message.includes(`doesn't exist`) && !err.message.includes("Invalid params:"), + onFailedAttempt, + } ) ); @@ -234,11 +247,11 @@ async function processGaps(accountsOrPools, client) { } let added = []; - for (let i in failedAccoutns) { - let contract = pools[i]; - console.log('Unsupported staking mechanism: Adding to the database:', contract.account_id); - newDelegators[contract.account_id] = (newDelegators[contract.account_id] ?? 0) + contract.stake; - added.push(contract.account_id); + for (let account_id of failedAccoutns) { + let stake = pools.find(pool => pool.account_id === account_id).stake; + console.log('Unsupported staking mechanism: Adding to the database:', account_id); + newDelegators[account_id] = (newDelegators[account_id] ?? 0) + stake; + added.push(account_id); } for (let account of users) { console.log('Missed account: Adding to the database:', account.account_id);