Add contract name and ensure upgrade point to new implementation

pull/3187/head
Praise Disu 2 years ago
parent 03a84e1d3e
commit 914ea4dfe9
  1. 65
      apps/remix-ide/src/blockchain/blockchain.js
  2. 5
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts

@ -177,32 +177,37 @@ export class Blockchain extends Plugin {
_paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error]) _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error])
return this.call('terminal', 'logHtml', log) return this.call('terminal', 'logHtml', log)
} }
const { contractName, implementationAddress } = implementationContractObject
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`)
// make deploys folder read only. // TODO: make deploys folder read only.
if (hasPreviousDeploys) { if (hasPreviousDeploys) {
const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`) const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`)
const parsedDeployments = JSON.parse(deployments) const parsedDeployments = JSON.parse(deployments)
parsedDeployments.deployments.push({ parsedDeployments.deployments[address] = {
date: new Date().toISOString(),
contractName: contractName,
fork: networkInfo.currentFork, fork: networkInfo.currentFork,
proxyAddress: address, proxyAddress: address,
implementationAddress: implementationContractObject.implementationAddress, implementationAddress: implementationAddress,
layout: implementationContractObject.contract.object.storageLayout, layout: implementationContractObject.contract.object.storageLayout
date: new Date().toISOString() }
})
await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2))
} else { } else {
await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({ await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkInfo.name}/UUPS.json`, JSON.stringify({
id: networkInfo.id, id: networkInfo.id,
network: networkInfo.name, network: networkInfo.name,
deployments: [{ deployments: {
fork: networkInfo.currentFork, [address]: {
proxyAddress: address, date: new Date().toISOString(),
implementationAddress: implementationContractObject.implementationAddress, contractName: contractName,
layout: implementationContractObject.contract.object.storageLayout, fork: networkInfo.currentFork,
date: new Date().toISOString() proxyAddress: address,
}] implementationAddress: implementationAddress,
layout: implementationContractObject.contract.object.storageLayout
}
}
}, null, 2)) }, null, 2))
} }
_paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful']) _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful'])
@ -235,19 +240,51 @@ export class Blockchain extends Plugin {
async runUpgradeTx (proxyAddress, data, newImplementationContractObject) { async runUpgradeTx (proxyAddress, data, newImplementationContractObject) {
const args = { useCall: false, data, to: proxyAddress } const args = { useCall: false, data, to: proxyAddress }
let networkInfo
const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => {
// continue using original authorization given by user // continue using original authorization given by user
networkInfo = network
continueTxExecution(null) continueTxExecution(null)
} }
const continueCb = (error, continueTxExecution, cancelCb) => { continueTxExecution() } const continueCb = (error, continueTxExecution, cancelCb) => { continueTxExecution() }
const promptCb = (okCb, cancelCb) => { okCb() } const promptCb = (okCb, cancelCb) => { okCb() }
const finalCb = (error, txResult, address, returnValue) => { const finalCb = async (error, txResult, address, returnValue) => {
if (error) { if (error) {
const log = logBuilder(error) const log = logBuilder(error)
_paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade failed']) _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade failed'])
return this.call('terminal', 'logHtml', log) 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']) _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade Successful'])
this.call('udapp', 'addInstance', addressToString(proxyAddress), newImplementationContractObject.abi, newImplementationContractObject.name) this.call('udapp', 'addInstance', addressToString(proxyAddress), newImplementationContractObject.abi, newImplementationContractObject.name)
} }

@ -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. // 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.implementationAddress = implAddress
implementationContractObject.name = proxyName
this.blockchain.deployProxy(data, implementationContractObject) this.blockchain.deployProxy(data, implementationContractObject)
} }
@ -117,6 +118,8 @@ export class OpenZeppelinProxy extends Plugin {
dataHex: fnData.replace('0x', '') dataHex: fnData.replace('0x', '')
} }
// re-use implementation contract's ABI for UI display in udapp and change name to proxy name. // 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 newImplementationContractObject.name = proxyName
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject) this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject)
} }

Loading…
Cancel
Save