fixes for deploying

pull/4143/head
filip mertens 1 year ago committed by bunsenstraat
parent dfd86e3493
commit 552447b1c1
  1. 153
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts
  2. 1
      libs/remix-ui/run-tab/src/lib/actions/deploy.ts

@ -37,7 +37,7 @@ export class OpenZeppelinProxy extends Plugin {
const ast = data.sources[file].ast const ast = data.sources[file].ast
if (this.kind === 'UUPS') { if (this.kind === 'UUPS') {
const options = await (this.getUUPSContractOptions(contracts, ast, file)) const options = await this.getUUPSContractOptions(contracts, ast, file)
return options return options
} }
@ -46,28 +46,36 @@ export class OpenZeppelinProxy extends Plugin {
async getUUPSContractOptions(contracts, ast, file) { async getUUPSContractOptions(contracts, ast, file) {
const options = {} const options = {}
await Promise.all(Object.keys(contracts).map(async (name) => { await Promise.all(
if (ast) { Object.keys(contracts).map(async (name) => {
const UUPSSymbol = ast.exportedSymbols[UUPS] ? ast.exportedSymbols[UUPS][0] : null if (ast) {
const UUPSSymbol = ast.exportedSymbols[UUPS] ? ast.exportedSymbols[UUPS][0] : null
await Promise.all(ast.absolutePath === file && ast.nodes.map(async (node) => {
if (node.name === name && node.linearizedBaseContracts.includes(UUPSSymbol)) { await Promise.all(
const abi = contracts[name].abi ast.absolutePath === file &&
const initializeInput = abi.find(node => node.name === 'initialize') ast.nodes.map(async (node) => {
const isDeployWithProxyEnabled: boolean = await this.call('config', 'getAppParameter', EnableProxyURLParam) || false if (node.name === name && node.linearizedBaseContracts.includes(UUPSSymbol)) {
const isDeployWithUpgradeEnabled: boolean = await this.call('config', 'getAppParameter', EnableUpgradeURLParam) || false const abi = contracts[name].abi
const initializeInput = abi.find((node) => node.name === 'initialize')
options[name] = { const isDeployWithProxyEnabled: boolean = (await this.call('config', 'getAppParameter', EnableProxyURLParam)) || false
options: [{ title: 'Deploy with Proxy', active: isDeployWithProxyEnabled }, { title: 'Upgrade with Proxy', active: isDeployWithUpgradeEnabled }], const isDeployWithUpgradeEnabled: boolean = (await this.call('config', 'getAppParameter', EnableUpgradeURLParam)) || false
initializeOptions: {
inputs: initializeInput, options[name] = {
initializeInputs: initializeInput ? this.blockchain.getInputs(initializeInput) : null options: [
} { title: 'Deploy with Proxy', active: isDeployWithProxyEnabled },
} { title: 'Upgrade with Proxy', active: isDeployWithUpgradeEnabled },
} ],
})) initializeOptions: {
} inputs: initializeInput,
})) initializeInputs: initializeInput ? this.blockchain.getInputs(initializeInput) : null,
},
}
}
})
)
}
})
)
return options return options
} }
@ -88,6 +96,7 @@ export class OpenZeppelinProxy extends Plugin {
} }
async deployUUPSProxy(implAddress: string, _data: string, implementationContractObject): Promise<void> { async deployUUPSProxy(implAddress: string, _data: string, implementationContractObject): Promise<void> {
const args = [implAddress, _data] const args = [implAddress, _data]
const constructorData = await this.blockchain.getEncodedParams(args, UUPSfunAbi) const constructorData = await this.blockchain.getEncodedParams(args, UUPSfunAbi)
const proxyName = 'ERC1967Proxy' const proxyName = 'ERC1967Proxy'
@ -98,9 +107,18 @@ export class OpenZeppelinProxy extends Plugin {
funAbi: UUPSfunAbi, funAbi: UUPSfunAbi,
funArgs: args, funArgs: args,
linkReferences: {}, linkReferences: {},
dataHex: UUPSBytecodeV5 + constructorData.replace('0x', '') dataHex: UUPSBytecodeV5 + constructorData.replace('0x', ''),
}
// check if implementation contract has a function called UPGRADE_INTERFACE_VERSION
// if it hasn't then we use the old bytecode pre 5.0.0
const hasUpgradeVersionCall = implementationContractObject.abi.find((abi) => abi.name === 'UPGRADE_INTERFACE_VERSION')
if (!hasUpgradeVersionCall) {
data.contractByteCode = UUPSBytecode
data.dataHex = UUPSBytecode + constructorData.replace('0x', '')
this.call('terminal', 'logHtml', `Using ERC1967 < 5.0.0 for proxy deployment...`)
}else{
this.call('terminal', 'logHtml', `Using ERC1967 >= 5.0.0 for proxy deployment...`)
} }
// 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.contractName = implementationContractObject.name implementationContractObject.contractName = implementationContractObject.name
implementationContractObject.implementationAddress = implAddress implementationContractObject.implementationAddress = implAddress
@ -118,57 +136,60 @@ export class OpenZeppelinProxy extends Plugin {
dataHex: dataHex, dataHex: dataHex,
funAbi: GETUUPSProxyVersionAbi, funAbi: GETUUPSProxyVersionAbi,
contractName: proxyName, contractName: proxyName,
funArgs: [] funArgs: [],
}, },
useCall: true useCall: true,
} }
// 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.contractName = newImplementationContractObject.name
newImplementationContractObject.implementationAddress = newImplAddress newImplementationContractObject.implementationAddress = newImplAddress
newImplementationContractObject.name = proxyName newImplementationContractObject.name = proxyName
await this.blockchain.runTx(args, () => { }, () => { }, () => { }, async (error, txResult, _address, returnValue) => {
let version = '4.8.3'
if (error) {
console.log(`error: ${error.message ? error.message : error}`)
console.log(`Will use version 4.8.3 of the proxy...`)
}else{
const response = txFormat.decodeResponse(returnValue, GETUUPSProxyVersionAbi)
version = response[0].split('string: ')[1]
// check if version is >= 5.0.0
console.log('version', response)
}
if (semver.gte(version, '5.0.0')) { await this.blockchain.runTx(
args,
const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress, "0x"], UUPSupgradeToAndCallAbi) () => {},
() => {},
const data = { () => {},
contractABI: UUPSABI, async (error, txResult, _address, returnValue) => {
contractName: proxyName, let version = '4.8.3'
funAbi: UUPSupgradeToAndCallAbi, if (error) {
funArgs: [newImplAddress, "0x"], console.log(`error: ${error.message ? error.message : error}`)
linkReferences: {}, console.log(`Will use version 4.8.3 of the proxy...`)
dataHex: fnData.replace('0x', '') } else {
const response = txFormat.decodeResponse(returnValue, GETUUPSProxyVersionAbi)
version = response[0].split('string: ')[1]
// check if version is >= 5.0.0
console.log('version', response)
} }
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject) if (semver.gte(version, '5.0.0')) {
} else { const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress, '0x'], UUPSupgradeToAndCallAbi)
const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress], UUPSupgradeAbi)
const proxyName = 'ERC1967Proxy'
const data = {
contractABI: UUPSABI,
contractName: proxyName,
funAbi: UUPSupgradeAbi,
funArgs: [newImplAddress],
linkReferences: {},
dataHex: fnData.replace('0x', '')
}
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject) const data = {
contractABI: UUPSABI,
contractName: proxyName,
funAbi: UUPSupgradeToAndCallAbi,
funArgs: [newImplAddress, '0x'],
linkReferences: {},
dataHex: fnData.replace('0x', ''),
}
this.call('terminal', 'logHtml', `Using ERC1967 >= 5.0.0 for proxy upgrade...`)
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject)
} else {
const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress], UUPSupgradeAbi)
const proxyName = 'ERC1967Proxy'
const data = {
contractABI: UUPSABI,
contractName: proxyName,
funAbi: UUPSupgradeAbi,
funArgs: [newImplAddress],
linkReferences: {},
dataHex: fnData.replace('0x', ''),
}
this.call('terminal', 'logHtml', `Using ERC1967 < 5.0.0 for proxy upgrade...`)
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject)
}
} }
}) )
} }
} }

@ -172,6 +172,7 @@ export const createInstance = async (
_paq.push(['trackEvent', 'udapp', 'DeployOnly', plugin.REACT_API.networkName]) _paq.push(['trackEvent', 'udapp', 'DeployOnly', plugin.REACT_API.networkName])
} }
if (isProxyDeployment) { if (isProxyDeployment) {
console.log('isProxyDeployment', contractObject.abi)
const initABI = contractObject.abi.find(abi => abi.name === 'initialize') const initABI = contractObject.abi.find(abi => abi.name === 'initialize')
plugin.call('openzeppelin-proxy', 'executeUUPSProxy', addressToString(address), args, initABI, contractObject) plugin.call('openzeppelin-proxy', 'executeUUPSProxy', addressToString(address), args, initABI, contractObject)

Loading…
Cancel
Save