proxy-manager.ts 945 Bytes
Newer Older
Kelvin Fichter's avatar
Kelvin Fichter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract } from 'ethers'

export const makeProxies = async (
  Proxy_Manager: Contract,
  names: string[]
): Promise<void> => {
  for (const name of names) {
    if (await Proxy_Manager['hasProxy(string)'](name)) {
      continue
    }

    const Factory__Proxy_Forwarder = await ethers.getContractFactory(
      'Proxy_Forwarder'
    )

    const Proxy_Forwarder = await Factory__Proxy_Forwarder.deploy(
      Proxy_Manager.address
    )

Kelvin Fichter's avatar
Kelvin Fichter committed
22
    await Proxy_Manager.setProxy(name, Proxy_Forwarder.address)
Kelvin Fichter's avatar
Kelvin Fichter committed
23 24 25 26 27 28 29 30 31
  }
}

export const setProxyTarget = async (
  Proxy_Manager: Contract,
  name: string,
  target: Contract
): Promise<void> => {
  await makeProxies(Proxy_Manager, [name])
Kelvin Fichter's avatar
Kelvin Fichter committed
32 33

  await Proxy_Manager.setTarget(name, target.address)
Kelvin Fichter's avatar
Kelvin Fichter committed
34 35 36
}

export const getProxyManager = async (): Promise<Contract> => {
Kelvin Fichter's avatar
Kelvin Fichter committed
37
  return (await ethers.getContractFactory('Proxy_Manager')).deploy()
Kelvin Fichter's avatar
Kelvin Fichter committed
38
}