contract-defs.ts 820 Bytes
Newer Older
1 2 3 4
import * as path from 'path'
import { ethers, ContractFactory, Signer } from 'ethers'
import { Interface } from 'ethers/lib/utils'

5 6 7 8 9 10
export const getContractDefinition = (name: string, ovm?: boolean): any => {
  return require(path.join(
    __dirname,
    `../artifacts${ovm ? '/ovm' : ''}`,
    `${name}.json`
  ))
11 12
}

13 14 15 16 17
export const getContractInterface = (
  name: string,
  ovm?: boolean
): Interface => {
  const definition = getContractDefinition(name, ovm)
18 19 20 21 22
  return new ethers.utils.Interface(definition.abi)
}

export const getContractFactory = (
  name: string,
23 24
  signer?: Signer,
  ovm?: boolean
25
): ContractFactory => {
26 27
  const definition = getContractDefinition(name, ovm)
  const contractInterface = getContractInterface(name, ovm)
28 29
  return new ContractFactory(contractInterface, definition.bytecode, signer)
}