diff --git a/package.json b/package.json index f0f0da7b..7cec9d6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@1inch/solidity-utils", - "version": "3.1.0", + "version": "3.2.0", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", "repository": { diff --git a/src/utils.ts b/src/utils.ts index 9040c7da..59d2b576 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import '@nomicfoundation/hardhat-ethers'; // required to populate the HardhatRuntimeEnvironment with ethers import hre, { ethers } from 'hardhat'; import { time } from '@nomicfoundation/hardhat-network-helpers'; -import { BaseContract, BigNumberish, Contract, ContractTransactionReceipt, ContractTransactionResponse, JsonRpcProvider, Wallet } from 'ethers'; +import { BaseContract, BigNumberish, BytesLike, Contract, ContractTransactionReceipt, ContractTransactionResponse, JsonRpcProvider, Signer, Wallet } from 'ethers'; import { DeployOptions, DeployResult } from 'hardhat-deploy/types'; import { constants } from './prelude'; @@ -81,6 +81,14 @@ export async function deployContract(name: string, parameters: Array = [], signer?: Signer) : Promise { + const ContractFactory = await ethers.getContractFactory(abi, bytecode, signer); + const instance = await ContractFactory.deploy(...parameters); + await instance.waitForDeployment(); + return instance; +} + type Token = { balanceOf: (address: string) => Promise; getAddress: () => Promise; diff --git a/test/utils.test.ts b/test/utils.test.ts index ad752e99..0e56dad9 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -1,5 +1,5 @@ import { expect, ether, time, constants } from '../src/prelude'; -import { timeIncreaseTo, fixSignature, signMessage, trackReceivedTokenAndTx, countInstructions, deployContract, deployAndGetContract } from '../src/utils'; +import { timeIncreaseTo, fixSignature, signMessage, trackReceivedTokenAndTx, countInstructions, deployContract, deployAndGetContract, deployContractFromBytecode } from '../src/utils'; import hre, { deployments, ethers } from 'hardhat'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; @@ -182,6 +182,22 @@ describe('utils', function () { }); }); + describe('deployContractFromBytecode', function () { + it('should deploy new contract instance', async function () { + const contractArtifact = await hre.artifacts.readArtifact('TokenMock'); + const token = await deployContractFromBytecode(contractArtifact.abi, contractArtifact.bytecode, ['SomeToken', 'STM']); + expect(await token.getAddress()).to.be.not.eq(constants.ZERO_ADDRESS); + expect(await token.name()).to.be.eq('SomeToken'); + }); + + it('can be used without arguments', async function () { + const contractArtifact = await hre.artifacts.readArtifact('WETH'); + const weth = await deployContractFromBytecode(contractArtifact.abi, contractArtifact.bytecode); + expect(await weth.getAddress()).to.be.not.eq(constants.ZERO_ADDRESS); + expect(await weth.name()).to.be.eq('Wrapped Ether'); + }); + }); + describe('deployAndGetContract', function () { it('should deploy new contract instance', async function () { const tokenName = 'SomeToken';