From 088e351f289e818c806a664663d8e7904db980a8 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Thu, 13 Feb 2025 14:04:22 +0100 Subject: [PATCH] fix(wallet)_: applied custom tx changes to the path Before this change, custom parameters were applied only after the next fee update, now they will be updated appropriately and immediately. --- services/wallet/router/router.go | 20 ++++++++++++++++++ services/wallet/router/routes/router_path.go | 22 ++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/services/wallet/router/router.go b/services/wallet/router/router.go index 18705b15a6..6973be9452 100644 --- a/services/wallet/router/router.go +++ b/services/wallet/router/router.go @@ -169,6 +169,26 @@ func (r *Router) setCustomTxDetails(pathTxIdentity *requests.PathTxIdentity, pat continue } + if pathTxIdentity.IsApprovalTx { + path.ApprovalGasFeeMode = pathTxCustomParams.GasFeeMode + if pathTxCustomParams.GasFeeMode == fees.GasFeeCustom { + path.ApprovalTxNonce = (*hexutil.Uint64)(&pathTxCustomParams.Nonce) + path.ApprovalGasAmount = pathTxCustomParams.GasAmount + path.ApprovalMaxFeesPerGas = pathTxCustomParams.MaxFeesPerGas + path.ApprovalBaseFee = (*hexutil.Big)(new(big.Int).Sub(pathTxCustomParams.MaxFeesPerGas.ToInt(), pathTxCustomParams.PriorityFee.ToInt())) + path.ApprovalPriorityFee = pathTxCustomParams.PriorityFee + } + } else { + path.TxGasFeeMode = pathTxCustomParams.GasFeeMode + if pathTxCustomParams.GasFeeMode == fees.GasFeeCustom { + path.TxNonce = (*hexutil.Uint64)(&pathTxCustomParams.Nonce) + path.TxGasAmount = pathTxCustomParams.GasAmount + path.TxMaxFeesPerGas = pathTxCustomParams.MaxFeesPerGas + path.TxBaseFee = (*hexutil.Big)(new(big.Int).Sub(pathTxCustomParams.MaxFeesPerGas.ToInt(), pathTxCustomParams.PriorityFee.ToInt())) + path.TxPriorityFee = pathTxCustomParams.PriorityFee + } + } + r.lastInputParamsMutex.Lock() if r.lastInputParams.PathTxCustomParams == nil { r.lastInputParams.PathTxCustomParams = make(map[string]*requests.PathTxCustomParams) diff --git a/services/wallet/router/routes/router_path.go b/services/wallet/router/routes/router_path.go index aaef92c032..622a985663 100644 --- a/services/wallet/router/routes/router_path.go +++ b/services/wallet/router/routes/router_path.go @@ -142,10 +142,24 @@ func (p *Path) Copy() *Path { } if p.SuggestedLevelsForMaxFeesPerGas != nil { - newPath.SuggestedLevelsForMaxFeesPerGas = &fees.MaxFeesLevels{ - Low: (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.Low.ToInt())), - Medium: (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.Medium.ToInt())), - High: (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.High.ToInt())), + newPath.SuggestedLevelsForMaxFeesPerGas = &fees.MaxFeesLevels{} + if p.SuggestedLevelsForMaxFeesPerGas.Low != nil { + newPath.SuggestedLevelsForMaxFeesPerGas.Low = (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.Low.ToInt())) + } + if p.SuggestedLevelsForMaxFeesPerGas.LowPriority != nil { + newPath.SuggestedLevelsForMaxFeesPerGas.LowPriority = (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.LowPriority.ToInt())) + } + if p.SuggestedLevelsForMaxFeesPerGas.Medium != nil { + newPath.SuggestedLevelsForMaxFeesPerGas.Medium = (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.Medium.ToInt())) + } + if p.SuggestedLevelsForMaxFeesPerGas.MediumPriority != nil { + newPath.SuggestedLevelsForMaxFeesPerGas.MediumPriority = (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.MediumPriority.ToInt())) + } + if p.SuggestedLevelsForMaxFeesPerGas.High != nil { + newPath.SuggestedLevelsForMaxFeesPerGas.High = (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.High.ToInt())) + } + if p.SuggestedLevelsForMaxFeesPerGas.HighPriority != nil { + newPath.SuggestedLevelsForMaxFeesPerGas.HighPriority = (*hexutil.Big)(big.NewInt(0).Set(p.SuggestedLevelsForMaxFeesPerGas.HighPriority.ToInt())) } }