diff --git a/services/wallet/router/pathprocessor/common.go b/services/wallet/router/pathprocessor/common.go index 3194b28e2..e1d7f213f 100644 --- a/services/wallet/router/pathprocessor/common.go +++ b/services/wallet/router/pathprocessor/common.go @@ -20,11 +20,15 @@ func getSigner(chainID uint64, from types.Address, verifiedAccount *account.Sele } } -func makeKey(fromChain, toChain uint64, fromTokenSymbol, toTokenSymbol string) string { +func makeKey(fromChain, toChain uint64, fromTokenSymbol, toTokenSymbol string, amount *big.Int) string { + key := fmt.Sprintf("%d-%d", fromChain, toChain) if fromTokenSymbol != "" || toTokenSymbol != "" { - return fmt.Sprintf("%d-%d-%s-%s", fromChain, toChain, fromTokenSymbol, toTokenSymbol) + key = fmt.Sprintf("%s-%s-%s", key, fromTokenSymbol, toTokenSymbol) } - return fmt.Sprintf("%d-%d", fromChain, toChain) + if amount != nil { + key = fmt.Sprintf("%s-%s", key, amount.String()) + } + return key } func getNameFromEnsUsername(ensUsername string) string { diff --git a/services/wallet/router/pathprocessor/constants.go b/services/wallet/router/pathprocessor/constants.go index 7b128e515..eea7a4d0d 100644 --- a/services/wallet/router/pathprocessor/constants.go +++ b/services/wallet/router/pathprocessor/constants.go @@ -1,7 +1,7 @@ package pathprocessor const ( - IncreaseEstimatedGasFactor = 1.1 + IncreaseEstimatedGasFactor = 1.2 SevenDaysInSeconds = 60 * 60 * 24 * 7 StatusDomain = ".stateofus.eth" diff --git a/services/wallet/router/pathprocessor/processor_bridge_hop.go b/services/wallet/router/pathprocessor/processor_bridge_hop.go index 22e1eab78..760ff92e2 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_hop.go +++ b/services/wallet/router/pathprocessor/processor_bridge_hop.go @@ -201,7 +201,7 @@ func (h *HopBridgeProcessor) packTxInputDataInternally(params ProcessorInputPara return []byte{}, createBridgeHopErrorResponse(err) } - bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "") + bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn) bonderFeeIns, ok := h.bonderFee.Load(bonderKey) if !ok { return nil, ErrNoBonderFeeFound @@ -319,7 +319,7 @@ func (h *HopBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, sig return tx, createBridgeHopErrorResponse(err) } - bonderKey := makeKey(sendArgs.HopTx.ChainID, sendArgs.HopTx.ChainIDTo, "", "") + bonderKey := makeKey(sendArgs.HopTx.ChainID, sendArgs.HopTx.ChainIDTo, "", "", (*big.Int)(sendArgs.HopTx.Amount)) bonderFeeIns, ok := h.bonderFee.Load(bonderKey) if !ok { return nil, ErrNoBonderFeeFound @@ -386,7 +386,7 @@ func (h *HopBridgeProcessor) sendOrBuildV2(sendArgs *transactions.SendTxArgs, si return tx, createBridgeHopErrorResponse(err) } - bonderKey := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, "", "") + bonderKey := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, "", "", (*big.Int)(sendArgs.Value)) bonderFeeIns, ok := h.bonderFee.Load(bonderKey) if !ok { return nil, ErrNoBonderFeeFound @@ -427,6 +427,9 @@ func (h *HopBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, lastUsedNo func (h *HopBridgeProcessor) BuildTransaction(sendArgs *MultipathProcessorTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { tx, err := h.sendOrBuild(sendArgs, nil, lastUsedNonce) + if err != nil { + return nil, 0, createBridgeHopErrorResponse(err) + } return tx, tx.Nonce(), createBridgeHopErrorResponse(err) } @@ -439,7 +442,7 @@ func (h *HopBridgeProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArg } func (h *HopBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "") + bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn) if params.TestsMode { if val, ok := params.TestBonderFeeMap[params.FromToken.Symbol]; ok { res := new(big.Int).Sub(params.AmountIn, val) @@ -504,7 +507,7 @@ func (h *HopBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big.In } func (h *HopBridgeProcessor) CalculateAmountOut(params ProcessorInputParams) (*big.Int, error) { - bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "") + bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn) bonderFeeIns, ok := h.bonderFee.Load(bonderKey) if !ok { return nil, ErrNoBonderFeeFound diff --git a/services/wallet/router/pathprocessor/processor_swap_paraswap.go b/services/wallet/router/pathprocessor/processor_swap_paraswap.go index 21d6050de..c52627eb0 100644 --- a/services/wallet/router/pathprocessor/processor_swap_paraswap.go +++ b/services/wallet/router/pathprocessor/processor_swap_paraswap.go @@ -190,14 +190,14 @@ func (s *SwapParaswapProcessor) EstimateGas(params ProcessorInputParams) (uint64 return 0, createSwapParaswapErrorResponse(err) } - key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol) + key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn) s.priceRoute.Store(key, &priceRoute) return priceRoute.GasCost.Uint64(), nil } func (s *SwapParaswapProcessor) GetContractAddress(params ProcessorInputParams) (address common.Address, err error) { - key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol) + key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn) priceRouteIns, ok := s.priceRoute.Load(key) if !ok { err = ErrPriceRouteNotFound @@ -212,7 +212,7 @@ func (s *SwapParaswapProcessor) GetContractAddress(params ProcessorInputParams) func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorTxArgs) error { slippageBP := uint(sendArgs.SwapTx.SlippagePercentage * 100) // convert to basis points - key := makeKey(sendArgs.SwapTx.ChainID, sendArgs.SwapTx.ChainIDTo, sendArgs.SwapTx.TokenIDFrom, sendArgs.SwapTx.TokenIDTo) + key := makeKey(sendArgs.SwapTx.ChainID, sendArgs.SwapTx.ChainIDTo, sendArgs.SwapTx.TokenIDFrom, sendArgs.SwapTx.TokenIDTo, sendArgs.SwapTx.Value.ToInt()) priceRouteIns, ok := s.priceRoute.Load(key) if !ok { return ErrPriceRouteNotFound @@ -258,7 +258,7 @@ func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorT func (s *SwapParaswapProcessor) prepareTransactionV2(sendArgs *transactions.SendTxArgs) error { slippageBP := uint(sendArgs.SlippagePercentage * 100) // convert to basis points - key := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, sendArgs.FromTokenID, sendArgs.ToTokenID) + key := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, sendArgs.FromTokenID, sendArgs.ToTokenID, sendArgs.Value.ToInt()) priceRouteIns, ok := s.priceRoute.Load(key) if !ok { return ErrPriceRouteNotFound @@ -326,7 +326,7 @@ func (s *SwapParaswapProcessor) Send(sendArgs *MultipathProcessorTxArgs, lastUse } func (s *SwapParaswapProcessor) CalculateAmountOut(params ProcessorInputParams) (*big.Int, error) { - key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol) + key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn) priceRouteIns, ok := s.priceRoute.Load(key) if !ok { return nil, ErrPriceRouteNotFound diff --git a/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go b/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go index 07a2ec2f1..56f38bcff 100644 --- a/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go +++ b/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go @@ -44,7 +44,7 @@ func TestParaswapWithPartnerFee(t *testing.T) { chainIDs := []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.OptimismMainnet, walletCommon.UnknownChainID} for _, chainID := range chainIDs { - key := makeKey(chainID, chainID, fromToken.Symbol, toToken.Symbol) + key := makeKey(chainID, chainID, fromToken.Symbol, toToken.Symbol, testPriceRoute.SrcAmount.Int) processor.priceRoute.Store(key, testPriceRoute) testInputParams := ProcessorInputParams{ @@ -52,6 +52,7 @@ func TestParaswapWithPartnerFee(t *testing.T) { ToChain: ¶ms.Network{ChainID: chainID}, FromToken: &fromToken, ToToken: &toToken, + AmountIn: testPriceRoute.SrcAmount.Int, } partnerAddress, partnerFeePcnt := getPartnerAddressAndFeePcnt(chainID)