@@ -46,10 +46,6 @@ import (
4646 "github.com/tyler-smith/go-bip39"
4747)
4848
49- func init () {
50- dexeth .MaybeReadSimnetAddrs ()
51- }
52-
5349func registerToken (tokenID uint32 , desc string ) {
5450 token , found := dexeth .Tokens [tokenID ]
5551 if ! found {
@@ -67,6 +63,7 @@ func registerToken(tokenID uint32, desc string) {
6763}
6864
6965func init () {
66+ dexeth .MaybeReadSimnetAddrs ()
7067 asset .Register (BipID , & Driver {})
7168 registerToken (usdcTokenID , "The USDC Ethereum ERC20 token." )
7269 registerToken (usdtTokenID , "The USDT Ethereum ERC20 token." )
@@ -882,7 +879,8 @@ func (w *ETHWallet) Connect(ctx context.Context) (_ *sync.WaitGroup, err error)
882879 for ver , constructor := range contractorConstructors {
883880 contractAddr , exists := w .versionedContracts [ver ]
884881 if ! exists || contractAddr == (common.Address {}) {
885- 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
886884 }
887885 c , err := constructor (w .net , contractAddr , w .addr , w .node .contractBackend ())
888886 if err != nil {
@@ -5629,9 +5627,26 @@ func (getGas) ReadCredentials(chain, credentialsPath string, net dex.Network) (a
56295627 return
56305628}
56315629
5632- func getGetGasClientWithEstimatesAndBalances (ctx context.Context , net dex.Network , contractVer uint32 , maxSwaps int ,
5633- walletDir string , providers []string , seed []byte , wParams * GetGasWalletParams , log dex.Logger ) (cl * multiRPCClient , c contractor ,
5634- ethReq , swapReq , feeRate uint64 , ethBal , tokenBal * big.Int , err error ) {
5630+ func getGetGasClientWithEstimatesAndBalances (
5631+ ctx context.Context ,
5632+ net dex.Network ,
5633+ contractVer uint32 ,
5634+ maxSwaps int ,
5635+ walletDir string ,
5636+ providers []string ,
5637+ seed []byte ,
5638+ wParams * GetGasWalletParams ,
5639+ log dex.Logger ,
5640+ ) (
5641+ cl * multiRPCClient ,
5642+ c contractor ,
5643+ ethReq ,
5644+ swapReq ,
5645+ feeRate uint64 ,
5646+ ethBal ,
5647+ tokenBal * big.Int ,
5648+ err error ,
5649+ ) {
56355650
56365651 cl , c , err = quickNode (ctx , walletDir , contractVer , seed , providers , wParams , net , log )
56375652 if err != nil {
@@ -5882,6 +5897,7 @@ func (getGas) returnFunds(
58825897 }
58835898
58845899 remainder := ethBal - fees
5900+
58855901 txOpts , err := cl .txOpts (ctx , remainder , defaultSendGasLimit , maxFeeRate , tipRate , nil )
58865902 if err != nil {
58875903 return fmt .Errorf ("error generating tx opts: %w" , err )
@@ -5906,6 +5922,10 @@ func (getGas) returnFunds(
59065922func (getGas ) Estimate (ctx context.Context , net dex.Network , assetID , contractVer uint32 , maxSwaps int ,
59075923 credentialsPath string , wParams * GetGasWalletParams , log dex.Logger ) error {
59085924
5925+ if * wParams .Gas == (dexeth.Gases {}) {
5926+ return fmt .Errorf ("empty gas table. put some estimates in VersionedGases or Tokens for this contract" )
5927+ }
5928+
59095929 symbol := dex .BipIDSymbol (assetID )
59105930 log .Infof ("Getting gas estimates for up to %d swaps of asset %s, contract version %d on %s" , maxSwaps , symbol , contractVer , symbol )
59115931
@@ -6047,6 +6067,8 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
60476067 return fmt .Errorf ("error getting network fees: %v" , err )
60486068 }
60496069
6070+ maxFeeRate := new (big.Int ).Add (tipRate , new (big.Int ).Mul (baseRate , big .NewInt (2 )))
6071+
60506072 defer func () {
60516073 if len (stats .swaps ) == 0 {
60526074 return
@@ -6087,17 +6109,23 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
60876109 fmt .Printf (" %+v \n " , stats .transfers )
60886110 }()
60896111
6112+ logTx := func (tag string , n int , tx * types.Transaction ) {
6113+ log .Infof ("%s %d tx, hash = %s, nonce = %d, maxFeeRate = %s, tip cap = %s" ,
6114+ tag , n , tx .Hash (), tx .Nonce (), tx .GasFeeCap (), tx .GasTipCap ())
6115+ }
6116+
60906117 // Estimate approve for tokens.
60916118 if isToken {
60926119 sendApprove := func (cl ethFetcher , c tokenContractor ) error {
6093- txOpts , err := cl .txOpts (ctx , 0 , g .Approve * 2 , baseRate , tipRate , nil )
6120+ txOpts , err := cl .txOpts (ctx , 0 , g .Approve * 2 , maxFeeRate , tipRate , nil )
60946121 if err != nil {
60956122 return fmt .Errorf ("error constructing signed tx opts for approve: %w" , err )
60966123 }
60976124 tx , err := c .approve (txOpts , unlimitedAllowance )
60986125 if err != nil {
60996126 return fmt .Errorf ("error estimating approve gas: %w" , err )
61006127 }
6128+ logTx ("Approve" , 1 , tx )
61016129 if err = waitForConfirmation (ctx , cl , tx .Hash ()); err != nil {
61026130 return fmt .Errorf ("error waiting for approve transaction: %w" , err )
61036131 }
@@ -6124,7 +6152,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61246152 return fmt .Errorf ("error sending approve transaction for the initiator: %w" , err )
61256153 }
61266154
6127- txOpts , err := cl .txOpts (ctx , 0 , g .Transfer * 2 , baseRate , tipRate , nil )
6155+ txOpts , err := cl .txOpts (ctx , 0 , g .Transfer * 2 , maxFeeRate , tipRate , nil )
61286156 if err != nil {
61296157 return fmt .Errorf ("error constructing signed tx opts for transfer: %w" , err )
61306158 }
@@ -6137,6 +6165,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61376165 if err != nil {
61386166 return fmt .Errorf ("transfer error: %w" , err )
61396167 }
6168+ logTx ("Transfer" , 1 , transferTx )
61406169 if err = waitForConfirmation (ctx , cl , transferTx .Hash ()); err != nil {
61416170 return fmt .Errorf ("error waiting for transfer tx: %w" , err )
61426171 }
@@ -6176,7 +6205,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61766205 }
61776206
61786207 // Send the inits
6179- txOpts , err := cl .txOpts (ctx , optsVal , g .SwapN (n )* 2 , baseRate , tipRate , nil )
6208+ txOpts , err := cl .txOpts (ctx , optsVal , g .SwapN (n )* 2 , maxFeeRate , tipRate , nil )
61806209 if err != nil {
61816210 return fmt .Errorf ("error constructing signed tx opts for %d swaps: %v" , n , err )
61826211 }
@@ -6185,6 +6214,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
61856214 if err != nil {
61866215 return fmt .Errorf ("initiate error for %d swaps: %v" , n , err )
61876216 }
6217+ logTx ("Initiate" , n , tx )
61886218 if err = waitForConfirmation (ctx , cl , tx .Hash ()); err != nil {
61896219 return fmt .Errorf ("error waiting for init tx to be mined: %w" , err )
61906220 }
@@ -6219,7 +6249,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
62196249 })
62206250 }
62216251
6222- txOpts , err = cl .txOpts (ctx , 0 , g .RedeemN (n )* 2 , baseRate , tipRate , nil )
6252+ txOpts , err = cl .txOpts (ctx , 0 , g .RedeemN (n )* 2 , maxFeeRate , tipRate , nil )
62236253 if err != nil {
62246254 return fmt .Errorf ("error constructing signed tx opts for %d redeems: %v" , n , err )
62256255 }
@@ -6228,6 +6258,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
62286258 if err != nil {
62296259 return fmt .Errorf ("redeem error for %d swaps: %v" , n , err )
62306260 }
6261+ logTx ("Redeem" , n , tx )
62316262 if err = waitForConfirmation (ctx , cl , tx .Hash ()); err != nil {
62326263 return fmt .Errorf ("error waiting for redeem tx to be mined: %w" , err )
62336264 }
0 commit comments