uups update

pull/4143/head
filip mertens 1 year ago committed by bunsenstraat
parent 67030c9f8a
commit a62bbe68d1
  1. 34
      libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts
  2. 2
      libs/remix-core-plugin/src/lib/constants/uups.ts

@ -4,7 +4,7 @@ import { util } from '@remix-project/remix-lib'
import { toChecksumAddress } from '@ethereumjs/util' import { toChecksumAddress } from '@ethereumjs/util'
import { fetchContractFromEtherscan } from './helpers/fetch-etherscan' import { fetchContractFromEtherscan } from './helpers/fetch-etherscan'
import { fetchContractFromSourcify } from './helpers/fetch-sourcify' import { fetchContractFromSourcify } from './helpers/fetch-sourcify'
import { UUPSDeployedByteCode, UUPSCompilerVersion, UUPSOptimize, UUPSRuns, UUPSEvmVersion, UUPSLanguage } from './constants/uups' import { UUPSDeployedByteCode, UUPSCompilerVersion, UUPSOptimize, UUPSRuns, UUPSEvmVersion, UUPSLanguage, UUPSDeployedByteCodeV5, UUPSCompilerVersionV5 } from './constants/uups'
const profile = { const profile = {
name: 'fetchAndCompile', name: 'fetchAndCompile',
@ -41,6 +41,7 @@ export class FetchAndCompile extends Plugin {
* @return {CompilerAbstract} - compilation data targeting the given @arg contractAddress * @return {CompilerAbstract} - compilation data targeting the given @arg contractAddress
*/ */
async resolve (contractAddress, codeAtAddress, targetPath) { async resolve (contractAddress, codeAtAddress, targetPath) {
console.log('resolve', contractAddress, codeAtAddress, targetPath)
contractAddress = toChecksumAddress(contractAddress) contractAddress = toChecksumAddress(contractAddress)
const localCompilation = async () => { const localCompilation = async () => {
@ -57,6 +58,7 @@ export class FetchAndCompile extends Plugin {
if (this.unresolvedAddresses.includes(contractAddress)) return localCompilation() if (this.unresolvedAddresses.includes(contractAddress)) return localCompilation()
if (codeAtAddress === '0x' + UUPSDeployedByteCode) { // proxy if (codeAtAddress === '0x' + UUPSDeployedByteCode) { // proxy
console.log('proxy')
const settings = { const settings = {
version: UUPSCompilerVersion, version: UUPSCompilerVersion,
language: UUPSLanguage, language: UUPSLanguage,
@ -84,6 +86,36 @@ export class FetchAndCompile extends Plugin {
return compData return compData
} }
if (codeAtAddress === '0x' + UUPSDeployedByteCodeV5) { // proxy
console.log('UUPSDeployedByteCodeV5')
const settings = {
version: UUPSCompilerVersionV5,
language: UUPSLanguage,
evmVersion: UUPSEvmVersion,
optimize: UUPSOptimize,
runs: UUPSRuns
}
const proxyUrl = 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0/contracts/proxy/ERC1967/ERC1967Proxy.sol'
const compilationTargets = {
'proxy.sol': { content: `import "${proxyUrl}";` }
}
const compData = await compile(
compilationTargets,
settings,
async (url, cb) => {
// we first try to resolve the content from the compilation target using a more appropiate path
const path = `${targetPath}/${url}`
if (compilationTargets[path] && compilationTargets[path].content) {
return cb(null, compilationTargets[path].content)
} else {
await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))
}
})
console.log('compData', compData)
await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compData)
return compData
}
// sometimes when doing an internal call, the only available artifact is the Solidity interface. // sometimes when doing an internal call, the only available artifact is the Solidity interface.
// resolving addresses of internal call would allow to step over the source code, even if the declaration was made using an Interface. // resolving addresses of internal call would allow to step over the source code, even if the declaration was made using an Interface.

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save