Enable deploy with proxy url params

pull/2699/head
David Disu 2 years ago committed by Aniket
parent ee3c9ade96
commit 95a78dce0d
  1. 1
      libs/remix-core-plugin/src/lib/constants/uups.ts
  2. 52
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts
  3. 22
      libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx

@ -103,3 +103,4 @@ export const UUPSupgradeAbi = {
"stateMutability": "nonpayable",
"type": "function"
}
export const EnableProxyURLParam = 'deployProxy'

@ -1,6 +1,6 @@
import { Plugin } from '@remixproject/engine'
import { ContractAST, ContractSources, DeployOptions } from '../types/contract'
import { UUPS, UUPSABI, UUPSBytecode, UUPSfunAbi, UUPSupgradeAbi } from './constants/uups'
import { EnableProxyURLParam, UUPS, UUPSABI, UUPSBytecode, UUPSfunAbi, UUPSupgradeAbi } from './constants/uups'
const proxyProfile = {
name: 'openzeppelin-proxy',
@ -33,31 +33,39 @@ export class OpenZeppelinProxy extends Plugin {
async getProxyOptions (data: ContractSources, file: string): Promise<{ [name: string]: DeployOptions }> {
const contracts = data.contracts[file]
const ast = data.sources[file].ast
const inputs = {}
if (this.kind === 'UUPS') {
Object.keys(contracts).map(name => {
if (ast) {
const UUPSSymbol = ast.exportedSymbols[UUPS] ? ast.exportedSymbols[UUPS][0] : null
ast.absolutePath === file && ast.nodes.map((node) => {
if (node.name === name && node.linearizedBaseContracts.includes(UUPSSymbol)) {
const abi = contracts[name].abi
const initializeInput = abi.find(node => node.name === 'initialize')
inputs[name] = {
options: [{ title: 'Deploy with Proxy', active: false }, { title: 'Upgrade with Proxy', active: false }],
initializeOptions: {
inputs: initializeInput,
initializeInputs: initializeInput ? this.blockchain.getInputs(initializeInput) : null
}
const options = await (this.getUUPSContractOptions(contracts, ast, file))
return options
}
}
async getUUPSContractOptions (contracts, ast, file) {
const options = {}
await Promise.all(Object.keys(contracts).map(async (name) => {
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)) {
const abi = contracts[name].abi
const initializeInput = abi.find(node => node.name === 'initialize')
const isDeployWithProxyEnabled: boolean = await this.call('config', 'getAppParameter', EnableProxyURLParam) || false
options[name] = {
options: [{ title: 'Deploy with Proxy', active: isDeployWithProxyEnabled }, { title: 'Upgrade with Proxy', active: false }],
initializeOptions: {
inputs: initializeInput,
initializeInputs: initializeInput ? this.blockchain.getInputs(initializeInput) : null
}
}
})
}
})
}
return inputs
}
}))
}
}))
return options
}
async executeUUPSProxy(implAddress: string, args: string | string [] = '', initializeABI, implementationContractObject): Promise<void> {

@ -24,6 +24,16 @@ export function ContractGUI (props: ContractGUIProps) {
const initializeFields = useRef<Array<HTMLInputElement | null>>([])
const basicInputRef = useRef<HTMLInputElement>()
useEffect(() => {
if (props.deployOption && Array.isArray(props.deployOption)) {
if (props.deployOption[0] && props.deployOption[0].title === 'Deploy with Proxy') {
handleDeployProxySelect(props.deployOption[0].active)
} else if (props.deployOption[1] && props.deployOption[1].title === 'Deploy with Proxy') {
handleUpgradeImpSelect(props.deployOption[1].active)
}
}
}, [props.deployOption])
useEffect(() => {
if (props.title) {
setTitle(props.title)
@ -179,9 +189,7 @@ export function ContractGUI (props: ContractGUIProps) {
setToggleDeployProxy(!toggleDeployProxy)
}
const handleDeployProxySelect = (e) => {
const value = e.target.checked
const handleDeployProxySelect = (value: boolean) => {
if (value) setToggleUpgradeImp(false)
setToggleDeployProxy(value)
setDeployState({ upgrade: false, deploy: value })
@ -191,9 +199,7 @@ export function ContractGUI (props: ContractGUIProps) {
setToggleUpgradeImp(!toggleUpgradeImp)
}
const handleUpgradeImpSelect = (e) => {
const value = e.target.checked
const handleUpgradeImpSelect = (value: boolean) => {
setToggleUpgradeImp(value)
if (value) {
setToggleDeployProxy(false)
@ -264,7 +270,7 @@ export function ContractGUI (props: ContractGUIProps) {
data-id="contractGUIDeployWithProxy"
className="form-check-input custom-control-input"
type="checkbox"
onChange={handleDeployProxySelect}
onChange={(e) => handleDeployProxySelect(e.target.checked)}
checked={deployState.deploy}
/>
<label
@ -307,7 +313,7 @@ export function ContractGUI (props: ContractGUIProps) {
data-id="contractGUIUpgradeImplementation"
className="form-check-input custom-control-input"
type="checkbox"
onChange={handleUpgradeImpSelect}
onChange={(e) => handleUpgradeImpSelect(e.target.checked)}
checked={deployState.upgrade}
/>
<label

Loading…
Cancel
Save