|
|
@ -32,7 +32,7 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
return false |
|
|
|
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 contracts = data.contracts[file] |
|
|
|
const ast = data.sources[file].ast |
|
|
|
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 = {} |
|
|
|
const options = {} |
|
|
|
|
|
|
|
|
|
|
|
await Promise.all(Object.keys(contracts).map(async (name) => { |
|
|
|
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 initializeInput = abi.find(node => node.name === 'initialize') |
|
|
|
const isDeployWithProxyEnabled: boolean = await this.call('config', 'getAppParameter', EnableProxyURLParam) || false |
|
|
|
const isDeployWithProxyEnabled: boolean = await this.call('config', 'getAppParameter', EnableProxyURLParam) || false |
|
|
|
const isDeployWithUpgradeEnabled: boolean = await this.call('config', 'getAppParameter', EnableUpgradeURLParam) || false |
|
|
|
const isDeployWithUpgradeEnabled: boolean = await this.call('config', 'getAppParameter', EnableUpgradeURLParam) || false |
|
|
|
|
|
|
|
|
|
|
|
options[name] = { |
|
|
|
options[name] = { |
|
|
|
options: [{ title: 'Deploy with Proxy', active: isDeployWithProxyEnabled }, { title: 'Upgrade with Proxy', active: isDeployWithUpgradeEnabled }], |
|
|
|
options: [{ title: 'Deploy with Proxy', active: isDeployWithProxyEnabled }, { title: 'Upgrade with Proxy', active: isDeployWithUpgradeEnabled }], |
|
|
|
initializeOptions: { |
|
|
|
initializeOptions: { |
|
|
@ -71,7 +71,7 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
return options |
|
|
|
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
|
|
|
|
// deploy the proxy, or use an existing one
|
|
|
|
if (!initializeABI) throw new Error('Cannot deploy proxy: Missing initialize ABI') |
|
|
|
if (!initializeABI) throw new Error('Cannot deploy proxy: Missing initialize ABI') |
|
|
|
args = args === '' ? [] : args |
|
|
|
args = args === '' ? [] : args |
|
|
@ -80,14 +80,14 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
if (this.kind === 'UUPS') this.deployUUPSProxy(implAddress, _data, implementationContractObject) |
|
|
|
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 (!newImplAddress) throw new Error('Cannot upgrade: Missing implementation address') |
|
|
|
if (!proxyAddress) throw new Error('Cannot upgrade: Missing proxy address') |
|
|
|
if (!proxyAddress) throw new Error('Cannot upgrade: Missing proxy address') |
|
|
|
|
|
|
|
|
|
|
|
if (this.kind === 'UUPS') this.upgradeUUPSProxy(proxyAddress, newImplAddress, newImplementationContractObject) |
|
|
|
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 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' |
|
|
@ -108,7 +108,7 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
this.blockchain.deployProxy(data, implementationContractObject) |
|
|
|
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 proxyName = 'ERC1967Proxy' |
|
|
|
const dataHex = await this.blockchain.getEncodedFunctionHex([], GETUUPSProxyVersionAbi) |
|
|
|
const dataHex = await this.blockchain.getEncodedFunctionHex([], GETUUPSProxyVersionAbi) |
|
|
|
const args = { |
|
|
|
const args = { |
|
|
@ -120,17 +120,20 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
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.
|
|
|
|
await this.blockchain.runTx(args, () => {}, () => {}, () => {}, async (error, txResult, _address, returnValue) => { |
|
|
|
newImplementationContractObject.contractName = newImplementationContractObject.name |
|
|
|
|
|
|
|
newImplementationContractObject.implementationAddress = newImplAddress |
|
|
|
|
|
|
|
newImplementationContractObject.name = proxyName |
|
|
|
|
|
|
|
await this.blockchain.runTx(args, () => { }, () => { }, () => { }, async (error, txResult, _address, returnValue) => { |
|
|
|
if (error) { |
|
|
|
if (error) { |
|
|
|
throw new Error(`error: ${error.message ? error.message : error}`) |
|
|
|
throw new Error(`error: ${error.message ? error.message : error}`) |
|
|
|
} |
|
|
|
} |
|
|
|
const response = txFormat.decodeResponse(returnValue, GETUUPSProxyVersionAbi) |
|
|
|
const response = txFormat.decodeResponse(returnValue, GETUUPSProxyVersionAbi) |
|
|
|
const version = response[0].split('string: ')[1] |
|
|
|
const version = response[0].split('string: ')[1] |
|
|
|
// check if version is >= 5.0.0
|
|
|
|
// 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 fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress, "0x"], UUPSupgradeToAndCallAbi) |
|
|
|
|
|
|
|
|
|
|
|
const data = { |
|
|
|
const data = { |
|
|
@ -141,11 +144,7 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
linkReferences: {}, |
|
|
|
linkReferences: {}, |
|
|
|
dataHex: fnData.replace('0x', '') |
|
|
|
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) |
|
|
|
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress], UUPSupgradeAbi) |
|
|
|
const fnData = await this.blockchain.getEncodedFunctionHex([newImplAddress], UUPSupgradeAbi) |
|
|
@ -158,10 +157,7 @@ export class OpenZeppelinProxy extends Plugin { |
|
|
|
linkReferences: {}, |
|
|
|
linkReferences: {}, |
|
|
|
dataHex: fnData.replace('0x', '') |
|
|
|
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) |
|
|
|
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|