1
1
'use strict'
2
2
import { EventManager } from '../eventManager'
3
3
import type { Transaction as InternalTransaction } from './txRunner'
4
- import { Web3 } from 'web3'
5
- import { BrowserProvider , getAddress } from 'ethers'
4
+ import { BrowserProvider , getAddress , parseUnits } from 'ethers'
6
5
import { normalizeHexAddress } from '../helpers/uiHelper'
7
6
import { aaSupportedNetworks , aaLocalStorageKey , getPimlicoBundlerURL , aaDeterminiticProxyAddress } from '../helpers/aaConstants'
8
7
import { randomBytes } from 'crypto'
@@ -17,7 +16,7 @@ const { createPimlicoClient } = require("permissionless/clients/pimlico")
17
16
export class TxRunnerWeb3 {
18
17
event
19
18
_api
20
- getWeb3 : ( ) => Web3
19
+ getWeb3 : ( ) => BrowserProvider
21
20
currentblockGasLimit : ( ) => number
22
21
23
22
constructor ( api , getWeb3 , currentblockGasLimit ) {
@@ -37,11 +36,11 @@ export class TxRunnerWeb3 {
37
36
}
38
37
if ( txFee ) {
39
38
if ( txFee . baseFeePerGas ) {
40
- tx . maxPriorityFeePerGas = toHex ( BigInt ( this . getWeb3 ( ) . utils . toWei ( txFee . maxPriorityFee , 'gwei' ) ) )
41
- tx . maxFeePerGas = toHex ( BigInt ( this . getWeb3 ( ) . utils . toWei ( txFee . maxFee , 'gwei' ) ) )
39
+ tx . maxPriorityFeePerGas = toHex ( BigInt ( parseUnits ( txFee . maxPriorityFee , 'gwei' ) ) )
40
+ tx . maxFeePerGas = toHex ( BigInt ( parseUnits ( txFee . maxFee , 'gwei' ) ) )
42
41
tx . type = '0x2'
43
42
} else {
44
- tx . gasPrice = toHex ( BigInt ( this . getWeb3 ( ) . utils . toWei ( txFee . gasPrice , 'gwei' ) ) )
43
+ tx . gasPrice = toHex ( BigInt ( parseUnits ( txFee . gasPrice , 'gwei' ) ) )
45
44
// tx.type = '0x1'
46
45
}
47
46
if ( tx . authorizationList ) {
@@ -97,8 +96,8 @@ export class TxRunnerWeb3 {
97
96
promptCb (
98
97
async ( value ) => {
99
98
try {
100
- const res = await ( this . getWeb3 ( ) as any ) . eth . personal . sendTransaction ( { ...tx , value } , { checkRevertBeforeSending : false , ignoreGasPricing : true } )
101
- cb ( null , res . transactionHash , isCreation , false , null )
99
+ const res = await ( await this . getWeb3 ( ) . getSigner ( ) ) . sendTransaction ( { ...tx , value } )
100
+ cb ( null , res . hash , isCreation , false , null )
102
101
103
102
} catch ( e ) {
104
103
console . log ( `Send transaction failed: ${ e . message || e . error } . if you use an injected provider, please check it is properly unlocked. ` )
@@ -118,8 +117,8 @@ export class TxRunnerWeb3 {
118
117
const { txHash, contractAddress } = await this . sendUserOp ( tx , network . id )
119
118
cb ( null , txHash , isCreation , true , contractAddress )
120
119
} else {
121
- const res = await this . getWeb3 ( ) . eth . sendTransaction ( tx , null , { checkRevertBeforeSending : false , ignoreGasPricing : true } )
122
- cb ( null , res . transactionHash , isCreation , false , null )
120
+ const res = await ( await this . getWeb3 ( ) . getSigner ( ) ) . sendTransaction ( tx )
121
+ cb ( null , res . hash , isCreation , false , null )
123
122
}
124
123
} catch ( e ) {
125
124
if ( ! e . message ) e . message = ''
@@ -146,7 +145,7 @@ export class TxRunnerWeb3 {
146
145
if ( this . _api && this . _api . isVM ( ) ) {
147
146
( this . getWeb3 ( ) as any ) . remix . registerCallId ( timestamp )
148
147
}
149
- this . getWeb3 ( ) . eth . call ( tx )
148
+ this . getWeb3 ( ) . call ( tx )
150
149
. then ( ( result : any ) => callback ( null , {
151
150
result : result
152
151
} ) )
@@ -170,7 +169,7 @@ export class TxRunnerWeb3 {
170
169
txCopy . gasPrice = undefined
171
170
}
172
171
}
173
- const ethersProvider = new BrowserProvider ( this . getWeb3 ( ) . currentProvider as any )
172
+ const ethersProvider = this . getWeb3 ( )
174
173
ethersProvider . estimateGas ( txCopy )
175
174
. then ( gasEstimationBigInt => {
176
175
gasEstimationForceSend ( null , ( ) => {
@@ -322,9 +321,9 @@ export class TxRunnerWeb3 {
322
321
}
323
322
}
324
323
325
- async function tryTillReceiptAvailable ( txhash : string , web3 : Web3 ) {
324
+ async function tryTillReceiptAvailable ( txhash : string , provider : BrowserProvider ) {
326
325
try {
327
- const receipt = await web3 . eth . getTransactionReceipt ( txhash )
326
+ const receipt = await provider . getTransactionReceipt ( txhash )
328
327
if ( receipt ) {
329
328
if ( ! receipt . to && ! receipt . contractAddress ) {
330
329
// this is a contract creation and the receipt doesn't contain a contract address. we have to keep polling...
@@ -334,15 +333,15 @@ async function tryTillReceiptAvailable (txhash: string, web3: Web3) {
334
333
}
335
334
} catch ( e ) { }
336
335
await pause ( )
337
- return await tryTillReceiptAvailable ( txhash , web3 )
336
+ return await tryTillReceiptAvailable ( txhash , provider )
338
337
}
339
338
340
- async function tryTillTxAvailable ( txhash : string , web3 : Web3 ) {
339
+ async function tryTillTxAvailable ( txhash : string , provider : BrowserProvider ) {
341
340
try {
342
- const tx = await web3 . eth . getTransaction ( txhash )
341
+ const tx = await provider . getTransaction ( txhash )
343
342
if ( tx && tx . blockHash ) return tx
344
343
} catch ( e ) { }
345
- return await tryTillTxAvailable ( txhash , web3 )
344
+ return await tryTillTxAvailable ( txhash , provider )
346
345
}
347
346
348
347
async function pause ( ) { return new Promise ( ( resolve , reject ) => { setTimeout ( resolve , 500 ) } ) }
0 commit comments