|
|
|
@ -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) => { |
|
|
|
@ -56,7 +56,7 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
|
const initializeInput = abi.find(node => node.name === 'initialize') |
|
|
|
|
const isDeployWithProxyEnabled: boolean = await this.call('config', 'getAppParameter', EnableProxyURLParam) || false |
|
|
|
|
const isDeployWithUpgradeEnabled: boolean = await this.call('config', 'getAppParameter', EnableUpgradeURLParam) || false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options[name] = { |
|
|
|
|
options: [{ title: 'Deploy with Proxy', active: isDeployWithProxyEnabled }, { title: 'Upgrade with Proxy', active: isDeployWithUpgradeEnabled }], |
|
|
|
|
initializeOptions: { |
|
|
|
@ -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 = { |
|
|
|
@ -141,11 +144,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) |
|
|
|
|
} 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) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|