pull/4109/merge
filip mertens 1 year ago committed by Aniket
parent 3682c51c10
commit 2b192457bc
  1. 32
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts

@ -32,7 +32,7 @@ export class OpenZeppelinProxy extends Plugin {
return false
}
async getProxyOptions (data: ContractSources, file: string): Promise<{ [name: string]: DeployOptions }> {
async getProxyOptions(data: ContractSources, file: string): Promise<{ [name: string]: DeployOptions }> {
const contracts = data.contracts[file]
const ast = data.sources[file].ast
@ -43,7 +43,7 @@ export class OpenZeppelinProxy extends Plugin {
}
}
async getUUPSContractOptions (contracts, ast, file) {
async getUUPSContractOptions(contracts, ast, file) {
const options = {}
await Promise.all(Object.keys(contracts).map(async (name) => {
@ -71,7 +71,7 @@ export class OpenZeppelinProxy extends Plugin {
return options
}
async executeUUPSProxy(implAddress: string, args: string | string [] = '', initializeABI, implementationContractObject): Promise<void> {
async executeUUPSProxy(implAddress: string, args: string | string[] = '', initializeABI, implementationContractObject): Promise<void> {
// deploy the proxy, or use an existing one
if (!initializeABI) throw new Error('Cannot deploy proxy: Missing initialize ABI')
args = args === '' ? [] : args
@ -80,14 +80,14 @@ export class OpenZeppelinProxy extends Plugin {
if (this.kind === 'UUPS') this.deployUUPSProxy(implAddress, _data, implementationContractObject)
}
async executeUUPSContractUpgrade (proxyAddress: string, newImplAddress: string, newImplementationContractObject): Promise<void> {
async executeUUPSContractUpgrade(proxyAddress: string, newImplAddress: string, newImplementationContractObject): Promise<void> {
if (!newImplAddress) throw new Error('Cannot upgrade: Missing implementation address')
if (!proxyAddress) throw new Error('Cannot upgrade: Missing proxy address')
if (this.kind === 'UUPS') this.upgradeUUPSProxy(proxyAddress, newImplAddress, newImplementationContractObject)
}
async deployUUPSProxy (implAddress: string, _data: string, implementationContractObject): Promise<void> {
async deployUUPSProxy(implAddress: string, _data: string, implementationContractObject): Promise<void> {
const args = [implAddress, _data]
const constructorData = await this.blockchain.getEncodedParams(args, UUPSfunAbi)
const proxyName = 'ERC1967Proxy'
@ -108,7 +108,7 @@ export class OpenZeppelinProxy extends Plugin {
this.blockchain.deployProxy(data, implementationContractObject)
}
async upgradeUUPSProxy (proxyAddress: string, newImplAddress: string, newImplementationContractObject): Promise<void> {
async upgradeUUPSProxy(proxyAddress: string, newImplAddress: string, newImplementationContractObject): Promise<void> {
const proxyName = 'ERC1967Proxy'
const dataHex = await this.blockchain.getEncodedFunctionHex([], GETUUPSProxyVersionAbi)
const args = {
@ -120,17 +120,20 @@ export class OpenZeppelinProxy extends Plugin {
contractName: proxyName,
funArgs: []
},
useCall : true
useCall: true
}
await this.blockchain.runTx(args, () => {}, () => {}, () => {}, async (error, txResult, _address, returnValue) => {
// 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
await this.blockchain.runTx(args, () => { }, () => { }, () => { }, async (error, txResult, _address, returnValue) => {
if (error) {
throw new Error(`error: ${error.message ? error.message : error}`)
}
const response = txFormat.decodeResponse(returnValue, GETUUPSProxyVersionAbi)
const version = response[0].split('string: ')[1]
// check if version is >= 5.0.0
if(semver.gte(version, '5.0.0')){
if (semver.gte(version, '5.0.0')) {
const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress, "0x"], UUPSupgradeToAndCallAbi)
const data = {
@ -142,10 +145,6 @@ 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)
} else {
const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress], UUPSupgradeAbi)
@ -158,10 +157,7 @@ export class OpenZeppelinProxy extends Plugin {
linkReferences: {},
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)
}
})

Loading…
Cancel
Save