From 79aa5af1881b3c88fca451f7c4dd9ddf1126376b Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Tue, 22 Nov 2022 11:04:27 +0100 Subject: [PATCH 01/11] Improve saved deployments --- apps/remix-ide/src/blockchain/blockchain.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 1a1c591833..4a42057941 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -177,8 +177,12 @@ export class Blockchain extends Plugin { _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error]) return this.call('terminal', 'logHtml', log) } - if (networkInfo.name === 'VM') this.config.set('vm/proxy', address) - else this.config.set(`${networkInfo.name}/${networkInfo.currentFork}/${networkInfo.id}/proxy`, address) + if (networkInfo.name === 'VM') { + this.call('fileManager', 'exists', '.deploys', (error, exists) => { + this.config.set('vm/proxy', address) + } else { + this.config.set(`${networkInfo.name}/${networkInfo.currentFork}/${networkInfo.id}/proxy`, address) + } _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful']) this.call('udapp', 'addInstance', addressToString(address), implementationContractObject.abi, implementationContractObject.name) } From 5d86c569a91cb9d637a4eb1226b7a11c3967e923 Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Mon, 5 Dec 2022 14:08:34 +0100 Subject: [PATCH 02/11] Save proxy layout data --- apps/remix-ide/src/blockchain/blockchain.js | 33 ++++++++++++++++--- .../src/lib/openzeppelin-proxy.ts | 1 + 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 4a42057941..5c8e238060 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -161,6 +161,7 @@ export class Blockchain extends Plugin { } async runProxyTx (proxyData, implementationContractObject) { + const args = { useCall: false, data: proxyData } let networkInfo const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { @@ -170,18 +171,40 @@ export class Blockchain extends Plugin { } const continueCb = (error, continueTxExecution, cancelCb) => { continueTxExecution() } const promptCb = (okCb, cancelCb) => { okCb() } - const finalCb = (error, txResult, address, returnValue) => { + const finalCb = async (error, txResult, address, returnValue) => { if (error) { const log = logBuilder(error) _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error]) return this.call('terminal', 'logHtml', log) } - if (networkInfo.name === 'VM') { - this.call('fileManager', 'exists', '.deploys', (error, exists) => { - this.config.set('vm/proxy', address) + const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}.json`) + + // make deploys folder read only. + if (hasPreviousDeploys) { + const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}.json`) + const parsedDeployments = JSON.parse(deployments) + + parsedDeployments.deployments.push({ + fork: networkInfo.currentFork, + proxyAddress: address, + implementationAddress: implementationContractObject.implementationAddress, + layout: implementationContractObject.contract.object.storageLayout, + date: new Date().toISOString() + }) + await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}.json`, JSON.stringify(parsedDeployments, null, 2)) } else { - this.config.set(`${networkInfo.name}/${networkInfo.currentFork}/${networkInfo.id}/proxy`, address) + await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}.json`, JSON.stringify({ + id: networkInfo.id, + network: networkInfo.name, + deployments: [{ + fork: networkInfo.currentFork, + proxyAddress: address, + implementationAddress: implementationContractObject.implementationAddress, + layout: implementationContractObject.contract.object.storageLayout, + date: new Date().toISOString() + }] + }, null, 2)) } _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful']) this.call('udapp', 'addInstance', addressToString(address), implementationContractObject.abi, implementationContractObject.name) diff --git a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts index 9caa46e441..b3f01c8267 100644 --- a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts +++ b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts @@ -101,6 +101,7 @@ export class OpenZeppelinProxy extends Plugin { // re-use implementation contract's ABI for UI display in udapp and change name to proxy name. implementationContractObject.name = proxyName + implementationContractObject.implementationAddress = implAddress this.blockchain.deployProxy(data, implementationContractObject) } From f5d7109d9d8858adfb37855b424dc6893656a271 Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Mon, 5 Dec 2022 15:20:17 +0100 Subject: [PATCH 03/11] Remove un-needed code --- apps/remix-ide/src/blockchain/blockchain.js | 2 -- libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts | 1 - libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx | 1 - 3 files changed, 4 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 5c8e238060..0b14c881ce 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -188,7 +188,6 @@ export class Blockchain extends Plugin { parsedDeployments.deployments.push({ fork: networkInfo.currentFork, proxyAddress: address, - implementationAddress: implementationContractObject.implementationAddress, layout: implementationContractObject.contract.object.storageLayout, date: new Date().toISOString() }) @@ -200,7 +199,6 @@ export class Blockchain extends Plugin { deployments: [{ fork: networkInfo.currentFork, proxyAddress: address, - implementationAddress: implementationContractObject.implementationAddress, layout: implementationContractObject.contract.object.storageLayout, date: new Date().toISOString() }] diff --git a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts index b3f01c8267..9caa46e441 100644 --- a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts +++ b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts @@ -101,7 +101,6 @@ export class OpenZeppelinProxy extends Plugin { // re-use implementation contract's ABI for UI display in udapp and change name to proxy name. implementationContractObject.name = proxyName - implementationContractObject.implementationAddress = implAddress this.blockchain.deployProxy(data, implementationContractObject) } diff --git a/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx b/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx index f0617adf6a..40c86aaec6 100644 --- a/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx @@ -1,7 +1,6 @@ // eslint-disable-next-line no-use-before-define import React, { useEffect, useRef, useState } from 'react' import * as remixLib from '@remix-project/remix-lib' -import Web3 from 'web3' import { ContractGUIProps } from '../types' import { CopyToClipboard } from '@remix-ui/clipboard' import { CustomTooltip } from '@remix-ui/helper' From 541120392d290ccb51824f40154ea8e8b2d7a24d Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Mon, 5 Dec 2022 15:37:02 +0100 Subject: [PATCH 04/11] Remove empty new line --- apps/remix-ide/src/blockchain/blockchain.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 0b14c881ce..644c6b7035 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -161,7 +161,6 @@ export class Blockchain extends Plugin { } async runProxyTx (proxyData, implementationContractObject) { - const args = { useCall: false, data: proxyData } let networkInfo const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { From cf353d64b853e756c7f0957235dd75129db6998c Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Mon, 5 Dec 2022 16:11:01 +0100 Subject: [PATCH 05/11] Make network name sub-folder --- apps/remix-ide/src/blockchain/blockchain.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 644c6b7035..8e038e29e6 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -177,11 +177,11 @@ export class Blockchain extends Plugin { _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error]) return this.call('terminal', 'logHtml', log) } - const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}.json`) + const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) // make deploys folder read only. if (hasPreviousDeploys) { - const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}.json`) + const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) const parsedDeployments = JSON.parse(deployments) parsedDeployments.deployments.push({ @@ -190,9 +190,9 @@ export class Blockchain extends Plugin { layout: implementationContractObject.contract.object.storageLayout, date: new Date().toISOString() }) - await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}.json`, JSON.stringify(parsedDeployments, null, 2)) + await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) } else { - await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}.json`, JSON.stringify({ + await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ id: networkInfo.id, network: networkInfo.name, deployments: [{ From 03a84e1d3e0e8ce09dd596ab0de3ca4668e2de9f Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Mon, 5 Dec 2022 16:28:35 +0100 Subject: [PATCH 06/11] Include implementation address in deploys config. --- apps/remix-ide/src/blockchain/blockchain.js | 2 ++ libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 8e038e29e6..c15485f98f 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -187,6 +187,7 @@ export class Blockchain extends Plugin { parsedDeployments.deployments.push({ fork: networkInfo.currentFork, proxyAddress: address, + implementationAddress: implementationContractObject.implementationAddress, layout: implementationContractObject.contract.object.storageLayout, date: new Date().toISOString() }) @@ -198,6 +199,7 @@ export class Blockchain extends Plugin { deployments: [{ fork: networkInfo.currentFork, proxyAddress: address, + implementationAddress: implementationContractObject.implementationAddress, layout: implementationContractObject.contract.object.storageLayout, date: new Date().toISOString() }] diff --git a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts index 9caa46e441..b3f01c8267 100644 --- a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts +++ b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts @@ -101,6 +101,7 @@ export class OpenZeppelinProxy extends Plugin { // re-use implementation contract's ABI for UI display in udapp and change name to proxy name. implementationContractObject.name = proxyName + implementationContractObject.implementationAddress = implAddress this.blockchain.deployProxy(data, implementationContractObject) } From 914ea4dfe96fd06cdd5b3f135081ff4aea7c7e98 Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Mon, 5 Dec 2022 18:33:44 +0100 Subject: [PATCH 07/11] Add contract name and ensure upgrade point to new implementation --- apps/remix-ide/src/blockchain/blockchain.js | 65 +++++++++++++++---- .../src/lib/openzeppelin-proxy.ts | 5 +- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index c15485f98f..1918686a1b 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -177,32 +177,37 @@ export class Blockchain extends Plugin { _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error]) return this.call('terminal', 'logHtml', log) } + const { contractName, implementationAddress } = implementationContractObject const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) - // make deploys folder read only. + // TODO: make deploys folder read only. if (hasPreviousDeploys) { const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) const parsedDeployments = JSON.parse(deployments) - parsedDeployments.deployments.push({ + parsedDeployments.deployments[address] = { + date: new Date().toISOString(), + contractName: contractName, fork: networkInfo.currentFork, proxyAddress: address, - implementationAddress: implementationContractObject.implementationAddress, - layout: implementationContractObject.contract.object.storageLayout, - date: new Date().toISOString() - }) + implementationAddress: implementationAddress, + layout: implementationContractObject.contract.object.storageLayout + } await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) } else { await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ id: networkInfo.id, network: networkInfo.name, - deployments: [{ - fork: networkInfo.currentFork, - proxyAddress: address, - implementationAddress: implementationContractObject.implementationAddress, - layout: implementationContractObject.contract.object.storageLayout, - date: new Date().toISOString() - }] + deployments: { + [address]: { + date: new Date().toISOString(), + contractName: contractName, + fork: networkInfo.currentFork, + proxyAddress: address, + implementationAddress: implementationAddress, + layout: implementationContractObject.contract.object.storageLayout + } + } }, null, 2)) } _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful']) @@ -235,19 +240,51 @@ export class Blockchain extends Plugin { async runUpgradeTx (proxyAddress, data, newImplementationContractObject) { const args = { useCall: false, data, to: proxyAddress } + let networkInfo const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { // continue using original authorization given by user + networkInfo = network continueTxExecution(null) } const continueCb = (error, continueTxExecution, cancelCb) => { continueTxExecution() } const promptCb = (okCb, cancelCb) => { okCb() } - const finalCb = (error, txResult, address, returnValue) => { + const finalCb = async (error, txResult, address, returnValue) => { if (error) { const log = logBuilder(error) _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade failed']) return this.call('terminal', 'logHtml', log) } + const { contractName, implementationAddress } = newImplementationContractObject + const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}/$UUPS.json`) + + if (hasPreviousDeploys) { + const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) + const parsedDeployments = JSON.parse(deployments) + + parsedDeployments.deployments[proxyAddress] = { + lastUpdated: new Date().toISOString(), + ...parsedDeployments.deployments[proxyAddress], + implementationAddress: implementationAddress, + layout: newImplementationContractObject.contract.object.storageLayout + } + await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) + } else { + await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ + id: networkInfo.id, + network: networkInfo.name, + deployments: { + [proxyAddress]: { + date: new Date().toISOString(), + contractName: contractName, + fork: networkInfo.currentFork, + proxyAddress, + implementationAddress: implementationAddress, + layout: newImplementationContractObject.contract.object.storageLayout + } + } + }, null, 2)) + } _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade Successful']) this.call('udapp', 'addInstance', addressToString(proxyAddress), newImplementationContractObject.abi, newImplementationContractObject.name) } diff --git a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts index b3f01c8267..47db52425f 100644 --- a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts +++ b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts @@ -100,8 +100,9 @@ export class OpenZeppelinProxy extends Plugin { } // re-use implementation contract's ABI for UI display in udapp and change name to proxy name. - implementationContractObject.name = proxyName + implementationContractObject.contractName = implementationContractObject.name implementationContractObject.implementationAddress = implAddress + implementationContractObject.name = proxyName this.blockchain.deployProxy(data, implementationContractObject) } @@ -117,6 +118,8 @@ export class OpenZeppelinProxy extends Plugin { dataHex: fnData.replace('0x', '') } // re-use implementation contract's ABI for UI display in udapp and change name to proxy name. + newImplementationContractObject.contractName = newImplementationContractObject.name + newImplementationContractObject.implementationAddress = newImplAddress newImplementationContractObject.name = proxyName this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject) } From 27147092cdee70abb0decdb09e1829c83c52a0c0 Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Mon, 5 Dec 2022 19:00:25 +0100 Subject: [PATCH 08/11] Fix typo --- apps/remix-ide/src/blockchain/blockchain.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 1918686a1b..713845b0c6 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -256,7 +256,7 @@ export class Blockchain extends Plugin { return this.call('terminal', 'logHtml', log) } const { contractName, implementationAddress } = newImplementationContractObject - const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}/$UUPS.json`) + const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) if (hasPreviousDeploys) { const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) From 75bc23514ee5fd54ebf03e92f58b7273d3d58472 Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Tue, 6 Dec 2022 12:15:14 +0100 Subject: [PATCH 09/11] Made all requested changes --- apps/remix-ide/src/blockchain/blockchain.js | 25 ++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 713845b0c6..8107f73a78 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -185,28 +185,26 @@ export class Blockchain extends Plugin { const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) const parsedDeployments = JSON.parse(deployments) - parsedDeployments.deployments[address] = { + parsedDeployments.deployments[address] = [{ date: new Date().toISOString(), contractName: contractName, fork: networkInfo.currentFork, - proxyAddress: address, implementationAddress: implementationAddress, layout: implementationContractObject.contract.object.storageLayout - } + }] await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) } else { await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ id: networkInfo.id, network: networkInfo.name, deployments: { - [address]: { + [address]: [{ date: new Date().toISOString(), contractName: contractName, fork: networkInfo.currentFork, - proxyAddress: address, implementationAddress: implementationAddress, layout: implementationContractObject.contract.object.storageLayout - } + }] } }, null, 2)) } @@ -262,26 +260,27 @@ export class Blockchain extends Plugin { const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) const parsedDeployments = JSON.parse(deployments) - parsedDeployments.deployments[proxyAddress] = { - lastUpdated: new Date().toISOString(), - ...parsedDeployments.deployments[proxyAddress], + if (!parsedDeployments.deployments[proxyAddress]) parsedDeployments.deployments[proxyAddress] = [] + parsedDeployments.deployments[proxyAddress].push({ + date: new Date().toISOString(), + contractName: contractName, + fork: networkInfo.currentFork, implementationAddress: implementationAddress, layout: newImplementationContractObject.contract.object.storageLayout - } + }) await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) } else { await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ id: networkInfo.id, network: networkInfo.name, deployments: { - [proxyAddress]: { + [address]: [{ date: new Date().toISOString(), contractName: contractName, fork: networkInfo.currentFork, - proxyAddress, implementationAddress: implementationAddress, layout: newImplementationContractObject.contract.object.storageLayout - } + }] } }, null, 2)) } From 9b889164ea4dd69bf46627387f9bea008ae1592b Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Thu, 8 Dec 2022 15:27:24 +0100 Subject: [PATCH 10/11] Save only last deployment --- apps/remix-ide/src/blockchain/blockchain.js | 61 ++++++--------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 8107f73a78..aee7a9bd3b 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -177,37 +177,7 @@ export class Blockchain extends Plugin { _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error]) return this.call('terminal', 'logHtml', log) } - const { contractName, implementationAddress } = implementationContractObject - const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) - - // TODO: make deploys folder read only. - if (hasPreviousDeploys) { - const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) - const parsedDeployments = JSON.parse(deployments) - - parsedDeployments.deployments[address] = [{ - date: new Date().toISOString(), - contractName: contractName, - fork: networkInfo.currentFork, - implementationAddress: implementationAddress, - layout: implementationContractObject.contract.object.storageLayout - }] - await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) - } else { - await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ - id: networkInfo.id, - network: networkInfo.name, - deployments: { - [address]: [{ - date: new Date().toISOString(), - contractName: contractName, - fork: networkInfo.currentFork, - implementationAddress: implementationAddress, - layout: implementationContractObject.contract.object.storageLayout - }] - } - }, null, 2)) - } + await this.saveDeployedContractStorageLayout(implementationContractObject, address, networkInfo) _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful']) this.call('udapp', 'addInstance', addressToString(address), implementationContractObject.abi, implementationContractObject.name) } @@ -253,41 +223,44 @@ export class Blockchain extends Plugin { _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade failed']) return this.call('terminal', 'logHtml', log) } - const { contractName, implementationAddress } = newImplementationContractObject + await this.saveDeployedContractStorageLayout(newImplementationContractObject, proxyAddress, networkInfo) + _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade Successful']) + this.call('udapp', 'addInstance', addressToString(proxyAddress), newImplementationContractObject.abi, newImplementationContractObject.name) + } + this.runTx(args, confirmationCb, continueCb, promptCb, finalCb) + } + + async saveDeployedContractStorageLayout (contractObject, proxyAddress, networkInfo) { + const { contractName, implementationAddress, contract } = contractObject const hasPreviousDeploys = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) - + // TODO: make deploys folder read only. if (hasPreviousDeploys) { const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) const parsedDeployments = JSON.parse(deployments) - if (!parsedDeployments.deployments[proxyAddress]) parsedDeployments.deployments[proxyAddress] = [] - parsedDeployments.deployments[proxyAddress].push({ + parsedDeployments.deployments[proxyAddress] = { date: new Date().toISOString(), contractName: contractName, fork: networkInfo.currentFork, implementationAddress: implementationAddress, - layout: newImplementationContractObject.contract.object.storageLayout - }) + layout: contract.object.storageLayout + } await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) } else { await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ id: networkInfo.id, network: networkInfo.name, deployments: { - [address]: [{ + [proxyAddress]: { date: new Date().toISOString(), contractName: contractName, fork: networkInfo.currentFork, implementationAddress: implementationAddress, - layout: newImplementationContractObject.contract.object.storageLayout - }] + layout: contract.object.storageLayout + } } }, null, 2)) } - _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade Successful']) - this.call('udapp', 'addInstance', addressToString(proxyAddress), newImplementationContractObject.abi, newImplementationContractObject.name) - } - this.runTx(args, confirmationCb, continueCb, promptCb, finalCb) } async getEncodedFunctionHex (args, funABI) { From 85be272e04c10000bd8ee1ddc8d37ba402ba57a4 Mon Sep 17 00:00:00 2001 From: Praise Disu Date: Thu, 8 Dec 2022 15:42:17 +0100 Subject: [PATCH 11/11] Restore saving proxy address in localstorage --- apps/remix-ide/src/blockchain/blockchain.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index aee7a9bd3b..c345231ce9 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -177,6 +177,8 @@ export class Blockchain extends Plugin { _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error]) return this.call('terminal', 'logHtml', log) } + if (networkInfo.name === 'VM') this.config.set('vm/proxy', address) + else this.config.set(`${networkInfo.name}/${networkInfo.currentFork}/${networkInfo.id}/proxy`, address) await this.saveDeployedContractStorageLayout(implementationContractObject, address, networkInfo) _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful']) this.call('udapp', 'addInstance', addressToString(address), implementationContractObject.abi, implementationContractObject.name)