@@ -23,10 +23,9 @@ import {
23
23
* with the deployedCode property generated by truffle builds
24
24
*/
25
25
export async function getCodeDigestWithoutAddress (
26
- rpcUrl : string ,
26
+ web3 : Web3 ,
27
27
address : string
28
28
) : Promise < string > {
29
- const web3 = new Web3 ( rpcUrl ) ;
30
29
const code = await web3 . eth . getCode ( address ) ;
31
30
const strippedCode = code . replaceAll (
32
31
address . toLowerCase ( ) . replace ( "0x" , "" ) ,
@@ -70,7 +69,7 @@ export class EvmWormholeContract extends WormholeContract {
70
69
super ( ) ;
71
70
}
72
71
getContract ( ) : Contract {
73
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
72
+ const web3 = this . chain . getWeb3 ( ) ;
74
73
return new web3 . eth . Contract ( WORMHOLE_ABI , this . address ) ;
75
74
}
76
75
@@ -99,7 +98,7 @@ export class EvmWormholeContract extends WormholeContract {
99
98
}
100
99
101
100
async upgradeGuardianSets ( senderPrivateKey : PrivateKey , vaa : Buffer ) {
102
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
101
+ const web3 = this . chain . getWeb3 ( ) ;
103
102
const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
104
103
const wormholeContract = new web3 . eth . Contract ( WORMHOLE_ABI , this . address ) ;
105
104
const transactionObject = wormholeContract . methods . submitNewGuardianSet (
@@ -222,7 +221,7 @@ export class EvmEntropyContract extends Storable {
222
221
) : Promise < Buffer > {
223
222
// Executor contract is the owner of entropy contract
224
223
const executorAddr = await this . getOwner ( ) ;
225
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
224
+ const web3 = this . chain . getWeb3 ( ) ;
226
225
const executor = new web3 . eth . Contract ( EXECUTOR_ABI , executorAddr ) ;
227
226
const data = executor . methods . upgradeTo ( newImplementation ) . encodeABI ( ) ;
228
227
return this . chain . generateExecutorPayload ( executorAddr , executorAddr , data ) ;
@@ -252,7 +251,7 @@ export class EvmEntropyContract extends Storable {
252
251
}
253
252
254
253
getContract ( ) {
255
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
254
+ const web3 = this . chain . getWeb3 ( ) ;
256
255
return new web3 . eth . Contract ( EXTENDED_ENTROPY_ABI , this . address ) ;
257
256
}
258
257
@@ -327,7 +326,7 @@ export class EvmEntropyContract extends Storable {
327
326
sequenceNumber : number ,
328
327
senderPrivateKey : PrivateKey
329
328
) {
330
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
329
+ const web3 = this . chain . getWeb3 ( ) ;
331
330
// can not use `this.getContract()` because it uses another web3 instance without the wallet
332
331
const contract = new web3 . eth . Contract ( EXTENDED_ENTROPY_ABI , this . address ) ;
333
332
const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
@@ -343,7 +342,7 @@ export class EvmEntropyContract extends Storable {
343
342
}
344
343
345
344
generateUserRandomNumber ( ) {
346
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
345
+ const web3 = this . chain . getWeb3 ( ) ;
347
346
return web3 . utils . randomHex ( 32 ) ;
348
347
}
349
348
@@ -358,7 +357,7 @@ export class EvmEntropyContract extends Storable {
358
357
senderPrivateKey : PrivateKey ,
359
358
withCallback ?: boolean
360
359
) {
361
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
360
+ const web3 = this . chain . getWeb3 ( ) ;
362
361
const userCommitment = web3 . utils . keccak256 ( userRandomNumber ) ;
363
362
const contract = new web3 . eth . Contract ( EXTENDED_ENTROPY_ABI , this . address ) ;
364
363
const fee = await contract . methods . getFee ( provider ) . call ( ) ;
@@ -392,7 +391,7 @@ export class EvmEntropyContract extends Storable {
392
391
sequenceNumber : string ,
393
392
senderPrivateKey : PrivateKey
394
393
) {
395
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
394
+ const web3 = this . chain . getWeb3 ( ) ;
396
395
const contract = new web3 . eth . Contract ( EXTENDED_ENTROPY_ABI , this . address ) ;
397
396
const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
398
397
const transactionObject = contract . methods . reveal (
@@ -486,7 +485,7 @@ export class EvmExpressRelayContract extends Storable {
486
485
}
487
486
488
487
getContract ( ) {
489
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
488
+ const web3 = this . chain . getWeb3 ( ) ;
490
489
return new web3 . eth . Contract ( EXPRESS_RELAY_ABI , this . address ) ;
491
490
}
492
491
}
@@ -499,7 +498,7 @@ export class EvmExecutorContract {
499
498
}
500
499
501
500
async getWormholeContract ( ) : Promise < EvmWormholeContract > {
502
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
501
+ const web3 = this . chain . getWeb3 ( ) ;
503
502
//Unfortunately, there is no public method to get the wormhole address
504
503
//Found 251 by using `forge build --extra-output storageLayout` and finding the slot for the wormhole variable.
505
504
let address = await web3 . eth . getStorageAt ( this . address , 251 ) ;
@@ -508,7 +507,7 @@ export class EvmExecutorContract {
508
507
}
509
508
510
509
getContract ( ) {
511
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
510
+ const web3 = this . chain . getWeb3 ( ) ;
512
511
return new web3 . eth . Contract ( EXECUTOR_ABI , this . address ) ;
513
512
}
514
513
@@ -542,7 +541,7 @@ export class EvmExecutorContract {
542
541
senderPrivateKey : PrivateKey ,
543
542
vaa : Buffer
544
543
) {
545
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
544
+ const web3 = this . chain . getWeb3 ( ) ;
546
545
const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
547
546
const executorContract = new web3 . eth . Contract ( EXECUTOR_ABI , this . address ) ;
548
547
const transactionObject = executorContract . methods . execute (
@@ -589,7 +588,7 @@ export class EvmPriceFeedContract extends PriceFeedContract {
589
588
}
590
589
591
590
getContract ( ) {
592
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
591
+ const web3 = this . chain . getWeb3 ( ) ;
593
592
const pythContract = new web3 . eth . Contract ( EXTENDED_PYTH_ABI , this . address ) ;
594
593
return pythContract ;
595
594
}
@@ -599,12 +598,12 @@ export class EvmPriceFeedContract extends PriceFeedContract {
599
598
*/
600
599
async getCode ( ) : Promise < string > {
601
600
// TODO: handle proxy contracts
602
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
601
+ const web3 = this . chain . getWeb3 ( ) ;
603
602
return web3 . eth . getCode ( this . address ) ;
604
603
}
605
604
606
605
async getImplementationAddress ( ) : Promise < string > {
607
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
606
+ const web3 = this . chain . getWeb3 ( ) ;
608
607
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1) according to EIP-1967
609
608
const storagePosition =
610
609
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" ;
@@ -617,11 +616,11 @@ export class EvmPriceFeedContract extends PriceFeedContract {
617
616
* Returns the keccak256 digest of the contract bytecode
618
617
*/
619
618
async getCodeDigestWithoutAddress ( ) : Promise < string > {
620
- return getCodeDigestWithoutAddress ( this . chain . getRpcUrl ( ) , this . address ) ;
619
+ return getCodeDigestWithoutAddress ( this . chain . getWeb3 ( ) , this . address ) ;
621
620
}
622
621
623
622
async getTotalFee ( ) : Promise < TokenQty > {
624
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
623
+ const web3 = this . chain . getWeb3 ( ) ;
625
624
const amount = BigInt ( await web3 . eth . getBalance ( this . address ) ) ;
626
625
return {
627
626
amount,
@@ -712,7 +711,7 @@ export class EvmPriceFeedContract extends PriceFeedContract {
712
711
}
713
712
714
713
async executeUpdatePriceFeed ( senderPrivateKey : PrivateKey , vaas : Buffer [ ] ) {
715
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
714
+ const web3 = this . chain . getWeb3 ( ) ;
716
715
const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
717
716
const pythContract = new web3 . eth . Contract ( EXTENDED_PYTH_ABI , this . address ) ;
718
717
const priceFeedUpdateData = vaas . map ( ( vaa ) => "0x" + vaa . toString ( "hex" ) ) ;
@@ -732,7 +731,7 @@ export class EvmPriceFeedContract extends PriceFeedContract {
732
731
senderPrivateKey : PrivateKey ,
733
732
vaa : Buffer
734
733
) {
735
- const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
734
+ const web3 = this . chain . getWeb3 ( ) ;
736
735
const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
737
736
const pythContract = new web3 . eth . Contract ( EXTENDED_PYTH_ABI , this . address ) ;
738
737
const transactionObject = pythContract . methods . executeGovernanceInstruction (
0 commit comments