1
1
import async from 'async'
2
2
import { execution } from '@remix-project/remix-lib'
3
3
import { compilationInterface } from './types'
4
- import { BrowserProvider , ContractFactory , ethers } from 'ethers'
4
+ import { BaseContract , BrowserProvider , Contract , ContractFactory , ethers , TransactionReceipt , TransactionResponse } from 'ethers'
5
5
6
6
/**
7
7
* @dev Deploy all contracts from compilation result
@@ -57,27 +57,26 @@ export function deployAll (compileResult: compilationInterface, provider: Browse
57
57
next ( null , contractsToDeploy )
58
58
} ,
59
59
function deployContracts ( contractsToDeploy : string [ ] , next ) {
60
- const deployRunner = ( deployObject , contractObject , contractName , filename , callback ) => {
61
- deployObject . estimateGas ( undefined ) . then ( ( gasValue ) => {
62
- const gasBase = Math . ceil ( gasValue * 1.2 )
63
- const gas = withDoubleGas ? gasBase * 2 : gasBase
64
- deployObject . send ( {
65
- from : accounts [ 0 ] ,
66
- gas : gas
67
- } ) . on ( 'receipt' , async function ( receipt ) {
68
- contractObject . options . address = receipt . contractAddress
69
- contractObject . options . from = accounts [ 0 ]
70
- contractObject . options . gas = 5000 * 1000
71
- compiledObject [ contractName ] . deployedAddress = receipt . contractAddress
60
+ const deployRunner = ( deployObject , { abi, signer} , contractName , filename , callback ) => {
61
+ deployObject . getDeployTransaction ( ) . then ( ( tx : TransactionResponse ) => {
62
+ provider . estimateGas ( tx ) . then ( ( gasValue ) => {
63
+ const gasBase = Math . ceil ( Number ( gasValue ) * 1.2 )
64
+ const gas = withDoubleGas ? gasBase * 2 : gasBase
65
+ deployObject . deploy ( {
66
+ from : accounts [ 0 ] ,
67
+ gasLimit : gas
68
+ } ) . then ( async function ( deployContractObj : BaseContract ) {
69
+ const deployTx = deployContractObj . deploymentTransaction ( )
70
+ const receipt : TransactionReceipt = await provider . getTransactionReceipt ( deployTx . hash )
71
+ const contractObject : Contract = new ethers . Contract ( receipt . contractAddress , abi , signer )
72
+ compiledObject [ contractName ] . deployedAddress = receipt . contractAddress
72
73
73
- contracts [ contractName ] = contractObject
74
- contracts [ contractName ] . filename = filename
74
+ contracts [ contractName ] = contractObject
75
+ contracts [ contractName ] . filename = filename
75
76
76
- if ( deployCb ) await deployCb ( filename , receipt . contractAddress )
77
- callback ( null , { receipt : { contractAddress : receipt . contractAddress } } ) // TODO this will only work with JavaScriptV VM
78
- } ) . on ( 'error' , function ( err ) {
79
- console . error ( err )
80
- callback ( err )
77
+ if ( deployCb ) await deployCb ( filename , receipt . contractAddress )
78
+ callback ( null , { receipt : { contractAddress : receipt . contractAddress } } ) // TODO this will only work with JavaScriptV VM
79
+ } )
81
80
} )
82
81
} ) . catch ( ( err ) => {
83
82
console . error ( err )
@@ -90,10 +89,8 @@ export function deployAll (compileResult: compilationInterface, provider: Browse
90
89
const encodeDataFinalCallback = ( error , contractDeployData ) => {
91
90
if ( error ) return nextEach ( error )
92
91
provider . getSigner ( ) . then ( ( signer ) => {
93
- const contractObject : ContractFactory = new ethers . ContractFactory ( contract . abi , '0x' + contractDeployData . dataHex , signer )
94
- contractObject . deploy ( ) . then ( ( deployObject ) => {
95
- deployRunner ( deployObject , contractObject , contractName , contract . filename , ( error ) => { nextEach ( error ) } )
96
- } )
92
+ const deployObject : ContractFactory = new ethers . ContractFactory ( contract . abi , '0x' + contractDeployData . dataHex , signer )
93
+ deployRunner ( deployObject , { abi : contract . abi , signer} , contractName , contract . filename , ( error ) => { nextEach ( error ) } )
97
94
} )
98
95
}
99
96
@@ -103,10 +100,8 @@ export function deployAll (compileResult: compilationInterface, provider: Browse
103
100
const abi = compiledObject [ libData . data . contractName ] . abi
104
101
const code = compiledObject [ libData . data . contractName ] . code
105
102
provider . getSigner ( ) . then ( ( signer ) => {
106
- const libraryObject = new ethers . ContractFactory ( abi , '0x' + code , signer )
107
- contract . deploy ( ) . then ( ( deployObject ) => {
108
- deployRunner ( deployObject , libraryObject , libData . data . contractName , contract . filename , callback )
109
- } )
103
+ const deployObject : ContractFactory = new ethers . ContractFactory ( abi , '0x' + code , signer )
104
+ deployRunner ( deployObject , { abi, signer} , libData . data . contractName , contract . filename , callback )
110
105
} )
111
106
}
112
107
0 commit comments