@@ -7,7 +7,6 @@ import { DataSource, EvmExecute } from "xc_admin_common";
7
7
import { WormholeContract } from "./wormhole" ;
8
8
9
9
// Just to make sure tx gas limit is enough
10
- const GAS_ESTIMATE_MULTIPLIER = 2 ;
11
10
const EXTENDED_ENTROPY_ABI = [
12
11
{
13
12
inputs : [ ] ,
@@ -394,18 +393,10 @@ export class WormholeEvmContract extends WormholeContract {
394
393
const transactionObject = wormholeContract . methods . submitNewGuardianSet (
395
394
"0x" + vaa . toString ( "hex" )
396
395
) ;
397
- const gasEstiamte = await transactionObject . estimateGas ( {
398
- from : address ,
399
- gas : 15000000 ,
400
- } ) ;
401
- // Some networks like Filecoin do not support the normal transaction type and need a type 2 transaction.
402
- // To send a type 2 transaction, remove the ``gasPrice`` field and add the `type` field with the value
403
- // `0x2` to the transaction configuration parameters.
404
- const result = await transactionObject . send ( {
405
- from : address ,
406
- gas : gasEstiamte * GAS_ESTIMATE_MULTIPLIER ,
407
- gasPrice : await this . chain . getGasPrice ( ) ,
408
- } ) ;
396
+ const result = await this . chain . estiamteAndSendTransaction (
397
+ transactionObject ,
398
+ { from : address }
399
+ ) ;
409
400
return { id : result . transactionHash , info : result } ;
410
401
}
411
402
}
@@ -543,6 +534,54 @@ export class EvmEntropyContract extends Storable {
543
534
uri : Web3 . utils . toAscii ( info . uri ) ,
544
535
} ;
545
536
}
537
+
538
+ generateUserRandomNumber ( ) {
539
+ const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
540
+ return web3 . utils . randomHex ( 32 ) ;
541
+ }
542
+
543
+ async requestRandomness (
544
+ userRandomNumber : string ,
545
+ provider : string ,
546
+ senderPrivateKey : PrivateKey
547
+ ) {
548
+ const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
549
+ const userCommitment = web3 . utils . keccak256 ( userRandomNumber ) ;
550
+ const contract = new web3 . eth . Contract ( EXTENDED_ENTROPY_ABI , this . address ) ;
551
+ const fee = await contract . methods . getFee ( provider ) . call ( ) ;
552
+ const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
553
+ const useBlockHash = false ;
554
+ const transactionObject = contract . methods . request (
555
+ provider ,
556
+ userCommitment ,
557
+ useBlockHash
558
+ ) ;
559
+ return this . chain . estiamteAndSendTransaction ( transactionObject , {
560
+ from : address ,
561
+ value : fee ,
562
+ } ) ;
563
+ }
564
+
565
+ async revealRandomness (
566
+ userRevelation : string ,
567
+ providerRevelation : string ,
568
+ provider : string ,
569
+ sequenceNumber : string ,
570
+ senderPrivateKey : PrivateKey
571
+ ) {
572
+ const web3 = new Web3 ( this . chain . getRpcUrl ( ) ) ;
573
+ const contract = new web3 . eth . Contract ( EXTENDED_ENTROPY_ABI , this . address ) ;
574
+ const { address } = web3 . eth . accounts . wallet . add ( senderPrivateKey ) ;
575
+ const transactionObject = contract . methods . reveal (
576
+ provider ,
577
+ sequenceNumber ,
578
+ userRevelation ,
579
+ providerRevelation
580
+ ) ;
581
+ return this . chain . estiamteAndSendTransaction ( transactionObject , {
582
+ from : address ,
583
+ } ) ;
584
+ }
546
585
}
547
586
548
587
export class EvmExecutorContract {
@@ -602,15 +641,10 @@ export class EvmExecutorContract {
602
641
const transactionObject = executorContract . methods . execute (
603
642
"0x" + vaa . toString ( "hex" )
604
643
) ;
605
- const gasEstimate = await transactionObject . estimateGas ( {
606
- from : address ,
607
- gas : 100000000 ,
608
- } ) ;
609
- const result = await transactionObject . send ( {
610
- from : address ,
611
- gas : gasEstimate * GAS_ESTIMATE_MULTIPLIER ,
612
- gasPrice : await this . chain . getGasPrice ( ) ,
613
- } ) ;
644
+ const result = await this . chain . estiamteAndSendTransaction (
645
+ transactionObject ,
646
+ { from : address }
647
+ ) ;
614
648
return { id : result . transactionHash , info : result } ;
615
649
}
616
650
}
@@ -787,17 +821,10 @@ export class EvmPriceFeedContract extends PriceFeedContract {
787
821
. call ( ) ;
788
822
const transactionObject =
789
823
pythContract . methods . updatePriceFeeds ( priceFeedUpdateData ) ;
790
- const gasEstimate = await transactionObject . estimateGas ( {
791
- from : address ,
792
- gas : 15000000 ,
793
- value : updateFee ,
794
- } ) ;
795
- const result = await transactionObject . send ( {
796
- from : address ,
797
- value : updateFee ,
798
- gas : gasEstimate * GAS_ESTIMATE_MULTIPLIER ,
799
- gasPrice : await this . chain . getGasPrice ( ) ,
800
- } ) ;
824
+ const result = await this . chain . estiamteAndSendTransaction (
825
+ transactionObject ,
826
+ { from : address , value : updateFee }
827
+ ) ;
801
828
return { id : result . transactionHash , info : result } ;
802
829
}
803
830
@@ -811,15 +838,10 @@ export class EvmPriceFeedContract extends PriceFeedContract {
811
838
const transactionObject = pythContract . methods . executeGovernanceInstruction (
812
839
"0x" + vaa . toString ( "hex" )
813
840
) ;
814
- const gasEstiamte = await transactionObject . estimateGas ( {
815
- from : address ,
816
- gas : 15000000 ,
817
- } ) ;
818
- const result = await transactionObject . send ( {
819
- from : address ,
820
- gas : gasEstiamte * GAS_ESTIMATE_MULTIPLIER ,
821
- gasPrice : await this . chain . getGasPrice ( ) ,
822
- } ) ;
841
+ const result = await this . chain . estiamteAndSendTransaction (
842
+ transactionObject ,
843
+ { from : address }
844
+ ) ;
823
845
return { id : result . transactionHash , info : result } ;
824
846
}
825
847
0 commit comments