Use new solc build file structure

pull/5370/head
ioedeveloper 2 years ago committed by Aniket
parent 8091ba5717
commit cb84111637
  1. 15
      apps/remix-ide/src/blockchain/blockchain.js
  2. 18
      libs/remix-core-plugin/src/types/contract.ts
  3. 22
      libs/remix-ui/run-tab/src/lib/actions/deploy.ts

@ -242,7 +242,10 @@ export class Blockchain extends Plugin {
if (hasPreviousDeploys) { if (hasPreviousDeploys) {
const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`) const deployments = await this.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`)
const parsedDeployments = JSON.parse(deployments) const parsedDeployments = JSON.parse(deployments)
const oldImplementationAddress = parsedDeployments.deployments[proxyAddress].implementationAddress
const hasPreviousBuild = await this.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${networkName}/solc-${oldImplementationAddress}.json`)
if (hasPreviousBuild) await this.call('fileManager', 'remove', `.deploys/upgradeable-contracts/${networkName}/solc-${oldImplementationAddress}.json`)
parsedDeployments.deployments[proxyAddress] = { parsedDeployments.deployments[proxyAddress] = {
date: new Date().toISOString(), date: new Date().toISOString(),
contractName: contractName, contractName: contractName,
@ -251,8 +254,16 @@ export class Blockchain extends Plugin {
solcOutput: contractObject.compiler.data, solcOutput: contractObject.compiler.data,
solcInput: contractObject.compiler.source solcInput: contractObject.compiler.source
} }
await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkName}/solc-${implementationAddress}.json`, JSON.stringify({
solcInput: contractObject.compiler.source,
solcOutput: contractObject.compiler.data
}, null, 2))
await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2)) await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`, JSON.stringify(parsedDeployments, null, 2))
} else { } else {
await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkName}/solc-${implementationAddress}.json`, JSON.stringify({
solcInput: contractObject.compiler.source,
solcOutput: contractObject.compiler.data
}, null, 2))
await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`, JSON.stringify({ await this.call('fileManager', 'writeFile', `.deploys/upgradeable-contracts/${networkName}/UUPS.json`, JSON.stringify({
id: networkInfo.id, id: networkInfo.id,
network: networkInfo.name, network: networkInfo.name,
@ -261,9 +272,7 @@ export class Blockchain extends Plugin {
date: new Date().toISOString(), date: new Date().toISOString(),
contractName: contractName, contractName: contractName,
fork: networkInfo.currentFork, fork: networkInfo.currentFork,
implementationAddress: implementationAddress, implementationAddress: implementationAddress
solcInput: contractObject.compiler.source,
solcOutput: contractObject.compiler.data
} }
} }
}, null, 2)) }, null, 2))

@ -1,3 +1,4 @@
import { SolcInput, SolcOutput } from "@openzeppelin/upgrades-core"
export interface FuncABI { export interface FuncABI {
name: string, name: string,
type: string, type: string,
@ -185,14 +186,6 @@ export interface ContractSources {
} }
} }
export interface ContractSourcesContent {
sources: {
[source in string]: {
content?: string
}
}
}
export interface NetworkDeploymentFile { export interface NetworkDeploymentFile {
id: string, id: string,
network: string, network: string,
@ -201,9 +194,12 @@ export interface ContractSources {
date: Date, date: Date,
contractName: string, contractName: string,
fork: string, fork: string,
implementationAddress: string, implementationAddress: string
solcInput: ContractSourcesContent,
solcOutput: ContractSources
} }
}[] }[]
} }
export interface SolcBuildFile {
solcInput: SolcInput,
solcOutput: SolcOutput
}

@ -1,4 +1,4 @@
import { ContractData, FuncABI, NetworkDeploymentFile } from "@remix-project/core-plugin" import { ContractData, FuncABI, NetworkDeploymentFile, SolcBuildFile } from "@remix-project/core-plugin"
import { RunTab } from "../types/run-tab" import { RunTab } from "../types/run-tab"
import { CompilerAbstract as CompilerAbstractType } from '@remix-project/remix-solidity' import { CompilerAbstract as CompilerAbstractType } from '@remix-project/remix-solidity'
import * as remixLib from '@remix-project/remix-lib' import * as remixLib from '@remix-project/remix-lib'
@ -351,7 +351,9 @@ export const getNetworkProxyAddresses = async (plugin: RunTab, dispatch: React.D
const deployments = [] const deployments = []
for (const proxyAddress in Object.keys(parsedNetworkFile.deployments)) { for (const proxyAddress in Object.keys(parsedNetworkFile.deployments)) {
if (parsedNetworkFile.deployments[proxyAddress].solcInput && parsedNetworkFile.deployments[proxyAddress].solcOutput) deployments.push({ address: proxyAddress, date: parsedNetworkFile.deployments[proxyAddress].date }) const solcBuildExists = await plugin.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${identifier}/solc-${parsedNetworkFile.deployments[proxyAddress].implementationAddress}.json`)
if (solcBuildExists) deployments.push({ address: proxyAddress, date: parsedNetworkFile.deployments[proxyAddress].date })
} }
dispatch(fetchProxyDeploymentsSuccess(deployments)) dispatch(fetchProxyDeploymentsSuccess(deployments))
} else { } else {
@ -369,19 +371,21 @@ export const isValidContractUpgrade = async (plugin: RunTab, dispatch: React.Dis
const networkFile: string = await plugin.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${identifier}/UUPS.json`) const networkFile: string = await plugin.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${identifier}/UUPS.json`)
const parsedNetworkFile: NetworkDeploymentFile = JSON.parse(networkFile) const parsedNetworkFile: NetworkDeploymentFile = JSON.parse(networkFile)
if (parsedNetworkFile.deployments[proxyAddress] && parsedNetworkFile.deployments[proxyAddress].solcInput) { if (parsedNetworkFile.deployments[proxyAddress]) {
try { const solcBuildExists = await plugin.call('fileManager', 'exists', `.deploys/upgradeable-contracts/${identifier}/solc-${parsedNetworkFile.deployments[proxyAddress].implementationAddress}.json`)
const oldImpl = new UpgradeableContract(parsedNetworkFile.deployments[proxyAddress].contractName, parsedNetworkFile.deployments[proxyAddress].solcInput, parsedNetworkFile.deployments[proxyAddress].solcOutput, { kind: 'uups' })
if (solcBuildExists) {
const solcFile: string = await plugin.call('fileManager', 'readFile', `.deploys/upgradeable-contracts/${identifier}/solc-${parsedNetworkFile.deployments[proxyAddress].implementationAddress}.json`)
const parsedSolcFile: SolcBuildFile = JSON.parse(solcFile)
const oldImpl = new UpgradeableContract(parsedNetworkFile.deployments[proxyAddress].contractName, parsedSolcFile.solcInput, parsedSolcFile.solcOutput, { kind: 'uups' })
const newImpl = new UpgradeableContract(newContractName, solcInput, solcOutput, { kind: 'uups' }) const newImpl = new UpgradeableContract(newContractName, solcInput, solcOutput, { kind: 'uups' })
const report = oldImpl.getStorageUpgradeReport(newImpl, { kind: 'uups' }) const report = oldImpl.getStorageUpgradeReport(newImpl, { kind: 'uups' })
console.log('report: ', report) console.log('report: ', report)
} catch (e) { return report
console.log('e: ', e) } else {
return { success: false, error: 'Previous contract implementation not available for upgrade comparison.' } return { success: false, error: 'Previous contract implementation not available for upgrade comparison.' }
} }
} else { } else {
return { success: false, error: 'Previous contract implementation not available for upgrade comparison.' } return { success: false, error: 'Previous contract implementation not available for upgrade comparison.' }
} }

Loading…
Cancel
Save