{"id":334721,"date":"2022-06-19T21:00:25","date_gmt":"2022-06-19T21:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334721"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334721","title":{"rendered":"<span>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441 BeaconProxy \u043e\u0442 OpenZeppelin<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u043d\u043e\u0433\u0438\u043c \u0438\u0437 \u0432\u0430\u0441, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0442\u0435\u043e\u0440\u0438\u0438, \u0441\u043c\u0430\u0440\u0442-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b \u0432 EVM-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 (immutable), \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043d\u0435 \u0442\u0430\u043a. \u0418 \u0440\u0435\u0447\u044c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u043a\u0430\u043a Pausable, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u0430 \u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u0435\u043c\u044b \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043d\u0438\u0445, \u043d\u0430 BeaconProxy.<\/p>\n<p>\u041a\u043b\u044e\u0447\u043e\u043c \u043a \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0412 \u0432\u0430\u0448\u0435\u043c Solidity-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0435 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043e\u0434\u043d\u0430 \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430. \u0414\u0430-\u0434\u0430! \u0412\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435 \u043c\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438 \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043e\u043d\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u0438 \u043e\u043d\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0442 \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u043e\u0434\u043d\u0430 \u0438 \u0432 \u043d\u0435\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u043e\u0443\u0442\u0435\u0440, \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0445\u044d\u0448 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0434\u0435\u043b\u0430\u044e\u0449\u0438\u0439 JUMPI \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0432 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435. (<a href=\"https:\/\/www.paradigm.xyz\/2021\/01\/how-does-optimisms-rollup-really-work#fn3\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430 <\/a>\u043d\u0430 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0445\u044d\u0448 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0440\u043e\u0443\u0442\u0435\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/docs.soliditylang.org\/en\/v0.5.15\/contracts.html#fallback-function\" rel=\"noopener noreferrer nofollow\">fallback<\/a> (\u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c).<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/eip2535diamonds.substack.com\/p\/understanding-delegatecall-and-how#:~:text=Addresses%20in%20Solidity%20have%20a%20%60delegatecall%60%20method%20that,is%20any%20return%20value%20from%20the%20function%20call.\" rel=\"noopener noreferrer nofollow\">delegatecall<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043b\u043e\u0442\u044b \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u0430\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b EVM \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a: \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/655717\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043b\u043e\u0442<\/a> 3, \u0437\u0430\u043f\u0438\u0448\u0438 \u0432 \u0441\u043b\u043e\u0442 8 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0447\u0438\u0441\u043b\u043e 12, \u0438\u0442\u043f. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043f\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441 \u0441\u0430\u043c\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u043c. \u0421\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0435, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e key\/value \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0433\u0434\u0435 key &#8212; \u044d\u0442\u043e \u043d\u043e\u043c\u0435\u0440 \u0441\u043b\u043e\u0442\u0430. \u0412\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0438\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432. \u0414\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 Proxy-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442. \u041e\u043d \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u043b\u043e\u0442\u043e\u0432 (\u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u043d\u043e\u043c\u0435\u0440\u043e\u043c) \u0430\u0434\u0440\u0435\u0441 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043f\u0440\u043e\u043a\u0441\u0438, \u0441\u0440\u0430\u0431\u0430\u0440\u044b\u0432\u0430\u0435\u0442 fallback, \u0430 \u043e\u0442\u0442\u0443\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f delegatecall. \u041f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0432 \u043d\u043e\u0432\u044b\u0439 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u0430 \u0437\u0430\u0442\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432\u043d\u0443\u0442\u0440\u0438 Proxy-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 (<a href=\"https:\/\/docs.openzeppelin.com\/upgrades-plugins\/1.x\/\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a>).<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0442\u0435\u043e\u0440\u0438\u044f \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438! \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code># \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0440\u0430\u0431\u043e\u0442\u0435 $ curl -s https:\/\/deb.nodesource.com\/setup_16.x | sudo bash $ sudo apt-get install -y nodejs $ mkdir habr-proxy &amp;&amp; cd habr-proxy $ npm init -y $ npm install --save-dev @openzeppelin\/contracts-upgradable \\                          @openzeppelin\/hardhat-upgrades \\                          @nomiclabs\/hardhat-ethers ethers $ npx hardhat  # \u0442\u0443\u0442 \u044f \u0432\u044b\u0431\u0438\u0440\u0430\u044e basic project $ nano hardhat.config.js  # \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c require('@openzeppelin\/hardhat-upgrades');<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b7\/3b7\/663\/9b73b76630f82885c54c08dc97662e4d.png\" width=\"516\" height=\"519\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b7\/3b7\/663\/9b73b76630f82885c54c08dc97662e4d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b:<\/p>\n<pre><code>\/\/ \/\/ contracts\/Version1.sol \/\/ pragma solidity ^0.8.0;  import \"hardhat\/console.sol\"; import \"@openzeppelin\/contracts-upgradeable\/proxy\/utils\/Initializable.sol\";  contract Version1 is Initializable {     uint32 public counter;     function __Version1_init() internal onlyInitializing {         __Version1_init_unchained();     }     function __Version1_init_unchained() internal onlyInitializing {         counter = 100;     }     function initialize() initializer public {         __Version1_init();     }      function setCounter(uint32 counter_) public {         counter = counter_;     }     function getCounter() view public returns(uint32) {         return counter;     }      \/**      * @dev This empty reserved space is put in place to allow future versions to add new      * variables without shifting down storage in the inheritance chain.      * See https:\/\/docs.openzeppelin.com\/contracts\/4.x\/upgradeable#storage_gaps      *\/     uint256[45] private __gap; }  \/\/ \/\/ contracts\/Version2.sol \/\/ pragma solidity ^0.8.0;  import \"hardhat\/console.sol\"; import \"@openzeppelin\/contracts-upgradeable\/proxy\/utils\/Initializable.sol\";  contract Version2 is Initializable {     uint32 public counter;      function __Version2_init() internal onlyInitializing {         __Version2_init_unchained();     }     function __Version2_init_unchained() internal onlyInitializing {         counter = 1000;     }     function initialize() initializer public {         __Version2_init();     }      function setCounter(uint32 counter_) public {         counter = counter_+500;     }     function getCounter() view public returns(uint32) {         return counter+5;     }      \/**      * @dev This empty reserved space is put in place to allow future versions to add new      * variables without shifting down storage in the inheritance chain.      * See https:\/\/docs.openzeppelin.com\/contracts\/4.x\/upgradeable#storage_gaps      *\/     uint256[45] private __gap; }<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 + \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c OpenZeppelin \u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 Upgradable \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code>\/\/ test\/main-test.js const { expect } = require(\"chai\"); const { ethers } = require(\"hardhat\");  describe(\"BeaconProxy\", function () {   it(\"Should do what we need when deployed from Hardhat\", async function () {     const Version1 = await ethers.getContractFactory(\"Version1\");     const Version2 = await ethers.getContractFactory(\"Version2\");      \/\/ \u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e     \/\/ \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, (Implementation Pointer \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435)     const beacon = await upgrades.deployBeacon(Version1);     await beacon.deployed();     console.log(\"Beacon deployed to:\", beacon.address);      \/\/ \u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u043a\u0441\u0435\u0439 (\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0442\u043e\u0440\u0430\u0434\u0436\u0435\u0439)     const proxy1 = await upgrades.deployBeaconProxy(beacon, Version1, []);     await proxy1.deployed();     console.log(\"Proxy1 deployed to:\", proxy1.address);      const proxy2 = await upgrades.deployBeaconProxy(beacon, Version1, []);     await proxy2.deployed();     console.log(\"Proxy2 deployed to:\", proxy2.address);      \/\/ \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0441 \u043f\u0440\u043e\u043a\u0441\u0438.     const proxy1_accessor = Version1.attach(proxy1.address)     const proxy2_accessor = Version1.attach(proxy2.address)      \/\/ \u0418 \u0432\u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b.     {         const setValueTx = await proxy1_accessor.setCounter(105)         await setValueTx.wait()     }     {         const value = await proxy1_accessor.getCounter()         expect(value.toString()).to.equal('105')     }     {         const value = await proxy2_accessor.getCounter()         expect(value.toString()).to.equal('100')     }     \/\/ \u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0438 \u043f\u0440\u0430\u0432\u0434\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u043e\u043a\u0441\u0438-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432,     \/\/ \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0432\u043d\u0430 105, \u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c 100.      \/\/ \u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430.     await upgrades.upgradeBeacon(beacon, Version2);     {         const setValueTx = await proxy1_accessor.setCounter(105)         await setValueTx.wait()     }     {         const value = await proxy1_accessor.getCounter()         expect(value.toString()).to.equal('610')  \/\/ 105 + 500 + 5     }     {         const value = await proxy2_accessor.getCounter()         expect(value.toString()).to.equal('105')     }     \/\/ \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043d\u0430 \u043e\u0431\u043e\u0438\u0445 \u043f\u0440\u043e\u043a\u0441\u044f\u0445 \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.   }); });<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0435, \u0430 \u0443\u0436\u0435 \u0441\u043a\u043e\u0440\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/672204\/\"> https:\/\/habr.com\/ru\/post\/672204\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u043d\u043e\u0433\u0438\u043c \u0438\u0437 \u0432\u0430\u0441, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0442\u0435\u043e\u0440\u0438\u0438, \u0441\u043c\u0430\u0440\u0442-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b \u0432 EVM-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 (immutable), \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043d\u0435 \u0442\u0430\u043a. \u0418 \u0440\u0435\u0447\u044c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u043a\u0430\u043a Pausable, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u0430 \u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u0435\u043c\u044b \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043d\u0438\u0445, \u043d\u0430 BeaconProxy.<\/p>\n<p>\u041a\u043b\u044e\u0447\u043e\u043c \u043a \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0412 \u0432\u0430\u0448\u0435\u043c Solidity-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0435 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043e\u0434\u043d\u0430 \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430. \u0414\u0430-\u0434\u0430! \u0412\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435 \u043c\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438 \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043e\u043d\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u0438 \u043e\u043d\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0442 \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u043e\u0434\u043d\u0430 \u0438 \u0432 \u043d\u0435\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u043e\u0443\u0442\u0435\u0440, \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0445\u044d\u0448 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0434\u0435\u043b\u0430\u044e\u0449\u0438\u0439 JUMPI \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0432 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435. (<a href=\"https:\/\/www.paradigm.xyz\/2021\/01\/how-does-optimisms-rollup-really-work#fn3\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430 <\/a>\u043d\u0430 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0445\u044d\u0448 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0440\u043e\u0443\u0442\u0435\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/docs.soliditylang.org\/en\/v0.5.15\/contracts.html#fallback-function\" rel=\"noopener noreferrer nofollow\">fallback<\/a> (\u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c).<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <a href=\"https:\/\/eip2535diamonds.substack.com\/p\/understanding-delegatecall-and-how#:~:text=Addresses%20in%20Solidity%20have%20a%20%60delegatecall%60%20method%20that,is%20any%20return%20value%20from%20the%20function%20call.\" rel=\"noopener noreferrer nofollow\">delegatecall<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043b\u043e\u0442\u044b \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u0430\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b EVM \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a: \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/655717\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043b\u043e\u0442<\/a> 3, \u0437\u0430\u043f\u0438\u0448\u0438 \u0432 \u0441\u043b\u043e\u0442 8 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0447\u0438\u0441\u043b\u043e 12, \u0438\u0442\u043f. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043f\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441 \u0441\u0430\u043c\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u043c. \u0421\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0435, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e key\/value \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0433\u0434\u0435 key &#8212; \u044d\u0442\u043e \u043d\u043e\u043c\u0435\u0440 \u0441\u043b\u043e\u0442\u0430. \u0412\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0438\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432. \u0414\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 Proxy-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442. \u041e\u043d \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u043b\u043e\u0442\u043e\u0432 (\u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u043d\u043e\u043c\u0435\u0440\u043e\u043c) \u0430\u0434\u0440\u0435\u0441 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043f\u0440\u043e\u043a\u0441\u0438, \u0441\u0440\u0430\u0431\u0430\u0440\u044b\u0432\u0430\u0435\u0442 fallback, \u0430 \u043e\u0442\u0442\u0443\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f delegatecall. \u041f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0432 \u043d\u043e\u0432\u044b\u0439 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u0430 \u0437\u0430\u0442\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432\u043d\u0443\u0442\u0440\u0438 Proxy-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 (<a href=\"https:\/\/docs.openzeppelin.com\/upgrades-plugins\/1.x\/\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a>).<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0442\u0435\u043e\u0440\u0438\u044f \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438! \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code># \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0440\u0430\u0431\u043e\u0442\u0435 $ curl -s https:\/\/deb.nodesource.com\/setup_16.x | sudo bash $ sudo apt-get install -y nodejs $ mkdir habr-proxy &amp;&amp; cd habr-proxy $ npm init -y $ npm install --save-dev @openzeppelin\/contracts-upgradable \\                          @openzeppelin\/hardhat-upgrades \\                          @nomiclabs\/hardhat-ethers ethers $ npx hardhat  # \u0442\u0443\u0442 \u044f \u0432\u044b\u0431\u0438\u0440\u0430\u044e basic project $ nano hardhat.config.js  # \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c require('@openzeppelin\/hardhat-upgrades');<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u042f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b:<\/p>\n<pre><code>\/\/ \/\/ contracts\/Version1.sol \/\/ pragma solidity ^0.8.0;  import \"hardhat\/console.sol\"; import \"@openzeppelin\/contracts-upgradeable\/proxy\/utils\/Initializable.sol\";  contract Version1 is Initializable {     uint32 public counter;     function __Version1_init() internal onlyInitializing {         __Version1_init_unchained();     }     function __Version1_init_unchained() internal onlyInitializing {         counter = 100;     }     function initialize() initializer public {         __Version1_init();     }      function setCounter(uint32 counter_) public {         counter = counter_;     }     function getCounter() view public returns(uint32) {         return counter;     }      \/**      * @dev This empty reserved space is put in place to allow future versions to add new      * variables without shifting down storage in the inheritance chain.      * See https:\/\/docs.openzeppelin.com\/contracts\/4.x\/upgradeable#storage_gaps      *\/     uint256[45] private __gap; }  \/\/ \/\/ contracts\/Version2.sol \/\/ pragma solidity ^0.8.0;  import \"hardhat\/console.sol\"; import \"@openzeppelin\/contracts-upgradeable\/proxy\/utils\/Initializable.sol\";  contract Version2 is Initializable {     uint32 public counter;      function __Version2_init() internal onlyInitializing {         __Version2_init_unchained();     }     function __Version2_init_unchained() internal onlyInitializing {         counter = 1000;     }     function initialize() initializer public {         __Version2_init();     }      function setCounter(uint32 counter_) public {         counter = counter_+500;     }     function getCounter() view public returns(uint32) {         return counter+5;     }      \/**      * @dev This empty reserved space is put in place to allow future versions to add new      * variables without shifting down storage in the inheritance chain.      * See https:\/\/docs.openzeppelin.com\/contracts\/4.x\/upgradeable#storage_gaps      *\/     uint256[45] private __gap; }<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 + \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c OpenZeppelin \u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 Upgradable \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code>\/\/ test\/main-test.js const { expect } = require(\"chai\"); const { ethers } = require(\"hardhat\");  describe(\"BeaconProxy\", function () {   it(\"Should do what we need when deployed from Hardhat\", async function () {     const Version1 = await ethers.getContractFactory(\"Version1\");     const Version2 = await ethers.getContractFactory(\"Version2\");      \/\/ \u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e     \/\/ \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430, (Implementation Pointer \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435)     const beacon = await upgrades.deployBeacon(Version1);     await beacon.deployed();     console.log(\"Beacon deployed to:\", beacon.address);      \/\/ \u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u043a\u0441\u0435\u0439 (\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0442\u043e\u0440\u0430\u0434\u0436\u0435\u0439)     const proxy1 = await upgrades.deployBeaconProxy(beacon, Version1, []);     await proxy1.deployed();     console.log(\"Proxy1 deployed to:\", proxy1.address);      const proxy2 = await upgrades.deployBeaconProxy(beacon, Version1, []);     await proxy2.deployed();     console.log(\"Proxy2 deployed to:\", proxy2.address);      \/\/ \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0441 \u043f\u0440\u043e\u043a\u0441\u0438.     const proxy1_accessor = Version1.attach(proxy1.address)     const proxy2_accessor = Version1.attach(proxy2.address)      \/\/ \u0418 \u0432\u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b.     {         const setValueTx = await proxy1_accessor.setCounter(105)         await setValueTx.wait()     }     {         const value = await proxy1_accessor.getCounter()         expect(value.toString()).to.equal('105')     }     {         const value = await proxy2_accessor.getCounter()         expect(value.toString()).to.equal('100')     }     \/\/ \u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0438 \u043f\u0440\u0430\u0432\u0434\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u043e\u043a\u0441\u0438-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432,     \/\/ \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0432\u043d\u0430 105, \u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c 100.      \/\/ \u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430.     await upgrades.upgradeBeacon(beacon, Version2);     {         const setValueTx = await proxy1_accessor.setCounter(105)         await setValueTx.wait()     }     {         const value = await proxy1_accessor.getCounter()         expect(value.toString()).to.equal('610')  \/\/ 105 + 500 + 5     }     {         const value = await proxy2_accessor.getCounter()         expect(value.toString()).to.equal('105')     }     \/\/ \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043d\u0430 \u043e\u0431\u043e\u0438\u0445 \u043f\u0440\u043e\u043a\u0441\u044f\u0445 \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.   }); });<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0435, \u0430 \u0443\u0436\u0435 \u0441\u043a\u043e\u0440\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/672204\/\"> https:\/\/habr.com\/ru\/post\/672204\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-334721","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=334721"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334721\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}