updagre proxy in blocchain.js

clone_upgrade_proxy
yann300 2 years ago
parent 3a7fb9cd87
commit 00843dffa2
  1. 19
      apps/remix-ide/src/blockchain/blockchain.js
  2. 14
      libs/remix-core-plugin/src/lib/constants/uups.ts
  3. 16
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts

@ -179,6 +179,25 @@ export class Blockchain extends Plugin {
this.runTx(args, confirmationCb, continueCb, promptCb, finalCb)
}
async upgradeProxy(proxyAddress, data, newImplementationContractObject) {
const args = { useCall: false, data, to: proxyAddress }
const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => {
// continue using original authorization given by user
continueTxExecution(null)
}
const continueCb = (error, continueTxExecution, cancelCb) => { continueTxExecution() }
const promptCb = (okCb, cancelCb) => { okCb() }
const finalCb = (error, txResult, address, returnValue) => {
if (error) {
const log = logBuilder(error)
return this.call('terminal', 'logHtml', log)
}
return this.call('udapp', 'resolveContractAndAddInstance', newImplementationContractObject, address)
}
this.runTx(args, confirmationCb, continueCb, promptCb, finalCb)
}
async getEncodedFunctionHex (args, funABI) {
return new Promise((resolve, reject) => {
txFormat.encodeFunctionCall(args, funABI, (error, data) => {

@ -88,4 +88,18 @@ export const UUPSfunAbi = {
type: "constructor",
outputs: [],
stateMutability: "payable"
}
export const UUPSupgradeAbi = {
"inputs": [
{
"internalType": "address",
"name": "newImplementation",
"type": "address"
}
],
"name": "upgradeTo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}

@ -1,6 +1,6 @@
import { Plugin } from '@remixproject/engine';
import { ContractABI, ContractAST, DeployOption } from '../types/contract';
import { UUPS, UUPSABI, UUPSBytecode, UUPSfunAbi } from './constants/uups';
import { UUPS, UUPSABI, UUPSBytecode, UUPSfunAbi, UUPSupgradeAbi } from './constants/uups';
const proxyProfile = {
name: 'openzeppelin-proxy',
@ -74,4 +74,18 @@ export class OpenZeppelinProxy extends Plugin {
implementationContractObject.name = proxyName
this.blockchain.deployProxy(data, implementationContractObject)
}
async upgradeUUPSProxy (proxyAddress: string, newImplAddress: string, newImplementationContractObject): Promise<void> {
const fnData = await this.blockchain.getEncodedParams([newImplAddress], UUPSupgradeAbi)
const proxyName = 'ERC1967Proxy'
const data = {
contractABI: UUPSABI,
contractName: proxyName,
funAbi: UUPSupgradeAbi,
funArgs: [newImplAddress],
linkReferences: {},
dataHex: fnData.replace('0x', '')
}
this.blockchain.upgradeProxy(proxyAddress, data, newImplementationContractObject)
}
}

Loading…
Cancel
Save