@@ -879,7 +879,8 @@ func (w *ETHWallet) Connect(ctx context.Context) (_ *sync.WaitGroup, err error)
879879 for ver , constructor := range contractorConstructors {
880880 contractAddr , exists := w .versionedContracts [ver ]
881881 if ! exists || contractAddr == (common.Address {}) {
882- return nil , fmt .Errorf ("no contract address for version %d, net %s" , ver , w .net )
882+ w .log .Debugf ("no eth swap contract address for version %d, net %s" , ver , w .net )
883+ continue
883884 }
884885 c , err := constructor (w .net , contractAddr , w .addr , w .node .contractBackend ())
885886 if err != nil {
@@ -5580,9 +5581,26 @@ func (getGas) ReadCredentials(chain, credentialsPath string, net dex.Network) (a
55805581 return
55815582}
55825583
5583- func getGetGasClientWithEstimatesAndBalances (ctx context.Context , net dex.Network , assetID , contractVer uint32 , maxSwaps int ,
5584- walletDir string , providers []string , seed []byte , wParams * GetGasWalletParams , log dex.Logger ) (cl * multiRPCClient , c contractor ,
5585- ethReq , swapReq , feeRate uint64 , ethBal , tokenBal * big.Int , err error ) {
5584+ func getGetGasClientWithEstimatesAndBalances (
5585+ ctx context.Context ,
5586+ net dex.Network ,
5587+ contractVer uint32 ,
5588+ maxSwaps int ,
5589+ walletDir string ,
5590+ providers []string ,
5591+ seed []byte ,
5592+ wParams * GetGasWalletParams ,
5593+ log dex.Logger ,
5594+ ) (
5595+ cl * multiRPCClient ,
5596+ c contractor ,
5597+ ethReq ,
5598+ swapReq ,
5599+ feeRate uint64 ,
5600+ ethBal ,
5601+ tokenBal * big.Int ,
5602+ err error ,
5603+ ) {
55865604
55875605 cl , c , err = quickNode (ctx , walletDir , contractVer , seed , providers , wParams , net , log )
55885606 if err != nil {
@@ -5666,7 +5684,7 @@ func (getGas) EstimateFunding(ctx context.Context, net dex.Network, assetID, con
56665684 }
56675685 defer os .RemoveAll (walletDir )
56685686
5669- cl , _ , ethReq , swapReq , _ , ethBalBig , tokenBalBig , err := getGetGasClientWithEstimatesAndBalances (ctx , net , assetID , contractVer , maxSwaps , walletDir , providers , seed , wParams , log )
5687+ cl , _ , ethReq , swapReq , _ , ethBalBig , tokenBalBig , err := getGetGasClientWithEstimatesAndBalances (ctx , net , contractVer , maxSwaps , walletDir , providers , seed , wParams , log )
56705688 if err != nil {
56715689 return err
56725690 }
@@ -5833,6 +5851,7 @@ func (getGas) returnFunds(
58335851 }
58345852
58355853 remainder := ethBal - fees
5854+
58365855 txOpts , err := cl .txOpts (ctx , remainder , defaultSendGasLimit , maxFeeRate , tipRate , nil )
58375856 if err != nil {
58385857 return fmt .Errorf ("error generating tx opts: %w" , err )
@@ -5857,6 +5876,10 @@ func (getGas) returnFunds(
58575876func (getGas ) Estimate (ctx context.Context , net dex.Network , assetID , contractVer uint32 , maxSwaps int ,
58585877 credentialsPath string , wParams * GetGasWalletParams , log dex.Logger ) error {
58595878
5879+ if * wParams .Gas == (dexeth.Gases {}) {
5880+ return fmt .Errorf ("empty gas table. put some estimates in VersionedGases or Tokens for this contract" )
5881+ }
5882+
58605883 symbol := dex .BipIDSymbol (assetID )
58615884 log .Infof ("Getting gas estimates for up to %d swaps of asset %s, contract version %d on %s" , maxSwaps , symbol , contractVer , symbol )
58625885
@@ -5873,7 +5896,7 @@ func (getGas) Estimate(ctx context.Context, net dex.Network, assetID, contractVe
58735896 }
58745897 defer os .RemoveAll (walletDir )
58755898
5876- cl , c , ethReq , swapReq , feeRate , ethBal , tokenBal , err := getGetGasClientWithEstimatesAndBalances (ctx , net , assetID , contractVer , maxSwaps , walletDir , providers , seed , wParams , log )
5899+ cl , c , ethReq , swapReq , feeRate , ethBal , tokenBal , err := getGetGasClientWithEstimatesAndBalances (ctx , net , contractVer , maxSwaps , walletDir , providers , seed , wParams , log )
58775900 if err != nil {
58785901 return err
58795902 }
@@ -5998,6 +6021,8 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
59986021 return fmt .Errorf ("error getting network fees: %v" , err )
59996022 }
60006023
6024+ maxFeeRate := new (big.Int ).Add (tipRate , new (big.Int ).Mul (baseRate , big .NewInt (2 )))
6025+
60016026 defer func () {
60026027 if len (stats .swaps ) == 0 {
60036028 return
@@ -6038,17 +6063,23 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
60386063 fmt .Printf (" %+v \n " , stats .transfers )
60396064 }()
60406065
6066+ logTx := func (tag string , n int , tx * types.Transaction ) {
6067+ log .Infof ("%s %d tx, hash = %s, nonce = %d, maxFeeRate = %s, tip cap = %s" ,
6068+ tag , n , tx .Hash (), tx .Nonce (), tx .GasFeeCap (), tx .GasTipCap ())
6069+ }
6070+
60416071 // Estimate approve for tokens.
60426072 if isToken {
60436073 sendApprove := func (cl ethFetcher , c tokenContractor ) error {
6044- txOpts , err := cl .txOpts (ctx , 0 , g .Approve * 2 , baseRate , tipRate , nil )
6074+ txOpts , err := cl .txOpts (ctx , 0 , g .Approve * 2 , maxFeeRate , tipRate , nil )
60456075 if err != nil {
60466076 return fmt .Errorf ("error constructing signed tx opts for approve: %w" , err )
60476077 }
60486078 tx , err := c .approve (txOpts , unlimitedAllowance )
60496079 if err != nil {
60506080 return fmt .Errorf ("error estimating approve gas: %w" , err )
60516081 }
6082+ logTx ("Approve" , 1 , tx )
60526083 if err = waitForConfirmation (ctx , cl , tx .Hash ()); err != nil {
60536084 return fmt .Errorf ("error waiting for approve transaction: %w" , err )
60546085 }
@@ -6075,7 +6106,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
60756106 return fmt .Errorf ("error sending approve transaction for the initiator: %w" , err )
60766107 }
60776108
6078- txOpts , err := cl .txOpts (ctx , 0 , g .Transfer * 2 , baseRate , tipRate , nil )
6109+ txOpts , err := cl .txOpts (ctx , 0 , g .Transfer * 2 , maxFeeRate , tipRate , nil )
60796110 if err != nil {
60806111 return fmt .Errorf ("error constructing signed tx opts for transfer: %w" , err )
60816112 }
@@ -6088,6 +6119,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
60886119 if err != nil {
60896120 return fmt .Errorf ("transfer error: %w" , err )
60906121 }
6122+ logTx ("Transfer" , 1 , transferTx )
60916123 if err = waitForConfirmation (ctx , cl , transferTx .Hash ()); err != nil {
60926124 return fmt .Errorf ("error waiting for transfer tx: %w" , err )
60936125 }
@@ -6127,7 +6159,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61276159 }
61286160
61296161 // Send the inits
6130- txOpts , err := cl .txOpts (ctx , optsVal , g .SwapN (n )* 2 , baseRate , tipRate , nil )
6162+ txOpts , err := cl .txOpts (ctx , optsVal , g .SwapN (n )* 2 , maxFeeRate , tipRate , nil )
61316163 if err != nil {
61326164 return fmt .Errorf ("error constructing signed tx opts for %d swaps: %v" , n , err )
61336165 }
@@ -6136,6 +6168,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61366168 if err != nil {
61376169 return fmt .Errorf ("initiate error for %d swaps: %v" , n , err )
61386170 }
6171+ logTx ("Initiate" , n , tx )
61396172 if err = waitForConfirmation (ctx , cl , tx .Hash ()); err != nil {
61406173 return fmt .Errorf ("error waiting for init tx to be mined: %w" , err )
61416174 }
@@ -6170,7 +6203,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61706203 })
61716204 }
61726205
6173- txOpts , err = cl .txOpts (ctx , 0 , g .RedeemN (n )* 2 , baseRate , tipRate , nil )
6206+ txOpts , err = cl .txOpts (ctx , 0 , g .RedeemN (n )* 2 , maxFeeRate , tipRate , nil )
61746207 if err != nil {
61756208 return fmt .Errorf ("error constructing signed tx opts for %d redeems: %v" , n , err )
61766209 }
@@ -6179,6 +6212,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61796212 if err != nil {
61806213 return fmt .Errorf ("redeem error for %d swaps: %v" , n , err )
61816214 }
6215+ logTx ("Redeem" , n , tx )
61826216 if err = waitForConfirmation (ctx , cl , tx .Hash ()); err != nil {
61836217 return fmt .Errorf ("error waiting for redeem tx to be mined: %w" , err )
61846218 }
0 commit comments