diff --git a/services/wallet/common/const.go b/services/wallet/common/const.go index a3021dc83..3f60d44fa 100644 --- a/services/wallet/common/const.go +++ b/services/wallet/common/const.go @@ -1,6 +1,7 @@ package common import ( + "math/big" "strconv" "time" @@ -32,8 +33,6 @@ const ( ) var ( - ZeroAddress = ethCommon.HexToAddress("0x0000000000000000000000000000000000000000") - SupportedNetworks = map[uint64]bool{ EthereumMainnet: true, OptimismMainnet: true, @@ -56,6 +55,14 @@ const ( ContractTypeERC1155 ) +func ZeroAddress() ethCommon.Address { + return ethCommon.Address{} +} + +func ZeroBigIntValue() *big.Int { + return big.NewInt(0) +} + func (c ChainID) String() string { return strconv.FormatUint(uint64(c), 10) } diff --git a/services/wallet/onramp/provider_mercuryo.go b/services/wallet/onramp/provider_mercuryo.go index 36fb00cbf..8e7a01e46 100644 --- a/services/wallet/onramp/provider_mercuryo.go +++ b/services/wallet/onramp/provider_mercuryo.go @@ -122,7 +122,7 @@ func (p *MercuryoProvider) GetURL(ctx context.Context, parameters Parameters) (s widgetSecret = "AZ5fmxmrgyrXH3zre6yHU2Vw9fPqEw82" // #nosec G101 ) - if parameters.DestAddress == nil || *parameters.DestAddress == walletCommon.ZeroAddress { + if parameters.DestAddress == nil || *parameters.DestAddress == walletCommon.ZeroAddress() { return "", errors.New("destination address is required") } diff --git a/services/wallet/requests/router_input_params.go b/services/wallet/requests/router_input_params.go index b701f3ec8..1ada0b5a5 100644 --- a/services/wallet/requests/router_input_params.go +++ b/services/wallet/requests/router_input_params.go @@ -123,8 +123,8 @@ func (i *RouteInputParams) Validate() error { if i.AmountIn != nil && i.AmountOut != nil && - i.AmountIn.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 && - i.AmountOut.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { + i.AmountIn.ToInt().Cmp(walletCommon.ZeroBigIntValue()) > 0 && + i.AmountOut.ToInt().Cmp(walletCommon.ZeroBigIntValue()) > 0 { return ErrSwapAmountInAmountOutMustBeExclusive } diff --git a/services/wallet/router/filter.go b/services/wallet/router/filter.go index 21bc79fa6..bdd45b5e0 100644 --- a/services/wallet/router/filter.go +++ b/services/wallet/router/filter.go @@ -5,7 +5,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/status-im/status-go/services/wallet/common" - "github.com/status-im/status-go/services/wallet/router/pathprocessor" + walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/router/routes" "go.uber.org/zap" @@ -108,7 +108,7 @@ func setupRouteValidationMaps(fromLockedAmount map[uint64]*hexutil.Big) (map[uin fromExcluded := make(map[uint64]bool) for chainID, amount := range fromLockedAmount { - if amount.ToInt().Cmp(pathprocessor.ZeroBigIntValue) <= 0 { + if amount.ToInt().Cmp(walletCommon.ZeroBigIntValue()) <= 0 { fromExcluded[chainID] = false } else { fromIncluded[chainID] = false diff --git a/services/wallet/router/filter_test.go b/services/wallet/router/filter_test.go index ae0a974e7..e7f1a4b3a 100644 --- a/services/wallet/router/filter_test.go +++ b/services/wallet/router/filter_test.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/status-im/status-go/params" - "github.com/status-im/status-go/services/wallet/router/pathprocessor" + walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/router/routes" "github.com/stretchr/testify/assert" @@ -94,9 +94,9 @@ func TestSetupRouteValidationMaps(t *testing.T) { { name: "Mixed zero and non-zero amounts", fromLockedAmount: map[uint64]*hexutil.Big{ - 1: (*hexutil.Big)(pathprocessor.ZeroBigIntValue), + 1: (*hexutil.Big)(walletCommon.ZeroBigIntValue()), 2: (*hexutil.Big)(big.NewInt(200)), - 3: (*hexutil.Big)(pathprocessor.ZeroBigIntValue), + 3: (*hexutil.Big)(walletCommon.ZeroBigIntValue()), 4: (*hexutil.Big)(big.NewInt(400)), }, expectedIncluded: map[uint64]bool{ @@ -123,8 +123,8 @@ func TestSetupRouteValidationMaps(t *testing.T) { { name: "All zero amounts", fromLockedAmount: map[uint64]*hexutil.Big{ - 1: (*hexutil.Big)(pathprocessor.ZeroBigIntValue), - 2: (*hexutil.Big)(pathprocessor.ZeroBigIntValue), + 1: (*hexutil.Big)(walletCommon.ZeroBigIntValue()), + 2: (*hexutil.Big)(walletCommon.ZeroBigIntValue()), }, expectedIncluded: map[uint64]bool{}, expectedExcluded: map[uint64]bool{ @@ -145,7 +145,7 @@ func TestSetupRouteValidationMaps(t *testing.T) { { name: "Single zero amount", fromLockedAmount: map[uint64]*hexutil.Big{ - 1: (*hexutil.Big)(pathprocessor.ZeroBigIntValue), + 1: (*hexutil.Big)(walletCommon.ZeroBigIntValue()), }, expectedIncluded: map[uint64]bool{}, expectedExcluded: map[uint64]bool{ diff --git a/services/wallet/router/pathprocessor/constants.go b/services/wallet/router/pathprocessor/constants.go index 984ac6ac4..0d4ad4a9a 100644 --- a/services/wallet/router/pathprocessor/constants.go +++ b/services/wallet/router/pathprocessor/constants.go @@ -1,16 +1,5 @@ package pathprocessor -import ( - "math/big" - - "github.com/ethereum/go-ethereum/common" -) - -var ( - ZeroAddress = common.Address{} - ZeroBigIntValue = big.NewInt(0) -) - const ( IncreaseEstimatedGasFactor = 1.1 SevenDaysInSeconds = 60 * 60 * 24 * 7 diff --git a/services/wallet/router/pathprocessor/multipath_processor.go b/services/wallet/router/pathprocessor/multipath_processor.go index f34475d42..a80f8d91c 100644 --- a/services/wallet/router/pathprocessor/multipath_processor.go +++ b/services/wallet/router/pathprocessor/multipath_processor.go @@ -4,6 +4,7 @@ import ( "math/big" "github.com/status-im/status-go/eth-node/types" + walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/transactions" ) @@ -31,7 +32,7 @@ func (t *MultipathProcessorTxArgs) Value() *big.Int { return t.ERC1155TransferTx.Amount.ToInt() } - return ZeroBigIntValue + return walletCommon.ZeroBigIntValue() } func (t *MultipathProcessorTxArgs) From() types.Address { diff --git a/services/wallet/router/pathprocessor/processor_bridge_celar.go b/services/wallet/router/pathprocessor/processor_bridge_celar.go index c1dc85201..3e187f07f 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_celar.go +++ b/services/wallet/router/pathprocessor/processor_bridge_celar.go @@ -23,6 +23,7 @@ import ( "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/params" + walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/router/pathprocessor/cbridge" "github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/token" @@ -203,7 +204,7 @@ func (s *CelerBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big. return nil, nil, ErrFailedToParsePercentageFee } - return ZeroBigIntValue, new(big.Int).Add(baseFee, percFee), nil + return walletCommon.ZeroBigIntValue(), new(big.Int).Add(baseFee, percFee), nil } func (c *CelerBridgeProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { diff --git a/services/wallet/router/pathprocessor/processor_bridge_hop.go b/services/wallet/router/pathprocessor/processor_bridge_hop.go index 7fe327b06..6753d450a 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_hop.go +++ b/services/wallet/router/pathprocessor/processor_bridge_hop.go @@ -377,7 +377,7 @@ func (h *HopBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big.In Deadline: time.Now().Add(SevenDaysInSeconds).Unix(), } h.bonderFee.Store(bonderKey, bonderFee) - return val, ZeroBigIntValue, nil + return val, walletCommon.ZeroBigIntValue(), nil } return nil, nil, ErrNoBonderFeeFound } @@ -471,7 +471,7 @@ func (h *HopBridgeProcessor) packL1BridgeTx(abi abi.ABI, toChainID uint64, to co bonderFee.AmountOutMin.Int, big.NewInt(bonderFee.Deadline), common.Address{}, - ZeroBigIntValue) + walletCommon.ZeroBigIntValue) } func (h *HopBridgeProcessor) sendL1BridgeTx(contractAddress common.Address, ethClient chain.ClientInterface, toChainID uint64, @@ -493,7 +493,7 @@ func (h *HopBridgeProcessor) sendL1BridgeTx(contractAddress common.Address, ethC bonderFee.AmountOutMin.Int, big.NewInt(bonderFee.Deadline), common.Address{}, - ZeroBigIntValue) + walletCommon.ZeroBigIntValue()) } if token.Symbol == HopSymbol { @@ -513,7 +513,7 @@ func (h *HopBridgeProcessor) sendL1BridgeTx(contractAddress common.Address, ethC bonderFee.AmountOutMin.Int, big.NewInt(bonderFee.Deadline), common.Address{}, - ZeroBigIntValue) + walletCommon.ZeroBigIntValue()) } contractInstance, err := hopL1Erc20Bridge.NewHopL1Erc20Bridge( @@ -532,7 +532,7 @@ func (h *HopBridgeProcessor) sendL1BridgeTx(contractAddress common.Address, ethC bonderFee.AmountOutMin.Int, big.NewInt(bonderFee.Deadline), common.Address{}, - ZeroBigIntValue) + walletCommon.ZeroBigIntValue()) } diff --git a/services/wallet/router/pathprocessor/processor_ens_public_key.go b/services/wallet/router/pathprocessor/processor_ens_public_key.go index 781727835..b0134439c 100644 --- a/services/wallet/router/pathprocessor/processor_ens_public_key.go +++ b/services/wallet/router/pathprocessor/processor_ens_public_key.go @@ -48,7 +48,7 @@ func (s *ENSPublicKeyProcessor) AvailableFor(params ProcessorInputParams) (bool, } func (s *ENSPublicKeyProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *ENSPublicKeyProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { @@ -89,7 +89,7 @@ func (s *ENSPublicKeyProcessor) EstimateGas(params ProcessorInputParams) (uint64 msg := ethereum.CallMsg{ From: params.FromAddr, To: &contractAddress, - Value: ZeroBigIntValue, + Value: walletCommon.ZeroBigIntValue(), Data: input, } @@ -120,7 +120,7 @@ func (s *ENSPublicKeyProcessor) GetContractAddress(params ProcessorInputParams) if err != nil { return common.Address{}, createENSPublicKeyErrorResponse(err) } - if *addr == ZeroAddress { + if *addr == walletCommon.ZeroAddress() { return common.Address{}, ErrENSResolverNotFound } return *addr, nil diff --git a/services/wallet/router/pathprocessor/processor_ens_register.go b/services/wallet/router/pathprocessor/processor_ens_register.go index 29ec6bfca..fef94839d 100644 --- a/services/wallet/router/pathprocessor/processor_ens_register.go +++ b/services/wallet/router/pathprocessor/processor_ens_register.go @@ -64,7 +64,7 @@ func (s *ENSRegisterProcessor) AvailableFor(params ProcessorInputParams) (bool, } func (s *ENSRegisterProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *ENSRegisterProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { @@ -125,7 +125,7 @@ func (s *ENSRegisterProcessor) EstimateGas(params ProcessorInputParams) (uint64, msg := ethereum.CallMsg{ From: params.FromAddr, To: &contractAddress, - Value: ZeroBigIntValue, + Value: walletCommon.ZeroBigIntValue(), Data: input, } diff --git a/services/wallet/router/pathprocessor/processor_ens_release.go b/services/wallet/router/pathprocessor/processor_ens_release.go index 3e9f5943b..6f0d56aa2 100644 --- a/services/wallet/router/pathprocessor/processor_ens_release.go +++ b/services/wallet/router/pathprocessor/processor_ens_release.go @@ -48,7 +48,7 @@ func (s *ENSReleaseProcessor) AvailableFor(params ProcessorInputParams) (bool, e } func (s *ENSReleaseProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *ENSReleaseProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { @@ -88,7 +88,7 @@ func (s *ENSReleaseProcessor) EstimateGas(params ProcessorInputParams) (uint64, msg := ethereum.CallMsg{ From: params.FromAddr, To: &contractAddress, - Value: ZeroBigIntValue, + Value: walletCommon.ZeroBigIntValue(), Data: input, } @@ -119,7 +119,7 @@ func (s *ENSReleaseProcessor) GetContractAddress(params ProcessorInputParams) (c if err != nil { return common.Address{}, err } - if addr == ZeroAddress { + if addr == walletCommon.ZeroAddress() { return common.Address{}, ErrENSRegistrarNotFound } return addr, nil diff --git a/services/wallet/router/pathprocessor/processor_erc1155.go b/services/wallet/router/pathprocessor/processor_erc1155.go index 02d50a688..1f8b7d43c 100644 --- a/services/wallet/router/pathprocessor/processor_erc1155.go +++ b/services/wallet/router/pathprocessor/processor_erc1155.go @@ -16,6 +16,7 @@ import ( "github.com/status-im/status-go/contracts/ierc1155" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/rpc" + walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/transactions" ) @@ -48,7 +49,7 @@ func (s *ERC1155Processor) AvailableFor(params ProcessorInputParams) (bool, erro } func (s *ERC1155Processor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *ERC1155Processor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { diff --git a/services/wallet/router/pathprocessor/processor_erc721.go b/services/wallet/router/pathprocessor/processor_erc721.go index 35f5814a4..5591596bb 100644 --- a/services/wallet/router/pathprocessor/processor_erc721.go +++ b/services/wallet/router/pathprocessor/processor_erc721.go @@ -18,6 +18,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/params" "github.com/status-im/status-go/rpc" + walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/token" "github.com/status-im/status-go/transactions" ) @@ -55,7 +56,7 @@ func (s *ERC721Processor) AvailableFor(params ProcessorInputParams) (bool, error } func (s *ERC721Processor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *ERC721Processor) packTxInputDataInternally(params ProcessorInputParams, functionName string) ([]byte, error) { diff --git a/services/wallet/router/pathprocessor/processor_stickers_buy.go b/services/wallet/router/pathprocessor/processor_stickers_buy.go index 5db9d9628..8e83dbd1a 100644 --- a/services/wallet/router/pathprocessor/processor_stickers_buy.go +++ b/services/wallet/router/pathprocessor/processor_stickers_buy.go @@ -50,7 +50,7 @@ func (s *StickersBuyProcessor) AvailableFor(params ProcessorInputParams) (bool, } func (s *StickersBuyProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *StickersBuyProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { @@ -117,7 +117,7 @@ func (s *StickersBuyProcessor) EstimateGas(params ProcessorInputParams) (uint64, msg := ethereum.CallMsg{ From: params.FromAddr, To: &contractAddress, - Value: ZeroBigIntValue, + Value: walletCommon.ZeroBigIntValue(), Data: input, } diff --git a/services/wallet/router/pathprocessor/processor_swap_paraswap.go b/services/wallet/router/pathprocessor/processor_swap_paraswap.go index a9b92a485..991c2a591 100644 --- a/services/wallet/router/pathprocessor/processor_swap_paraswap.go +++ b/services/wallet/router/pathprocessor/processor_swap_paraswap.go @@ -109,8 +109,8 @@ func (s *SwapParaswapProcessor) AvailableFor(params ProcessorInputParams) (bool, s.paraswapClient.SetPartnerAddress(partnerAddress) s.paraswapClient.SetPartnerFeePcnt(partnerFeePcnt) - searchForToken := params.FromToken.Address == ZeroAddress - searchForToToken := params.ToToken.Address == ZeroAddress + searchForToken := params.FromToken.Address == walletCommon.ZeroAddress() + searchForToToken := params.ToToken.Address == walletCommon.ZeroAddress() if searchForToToken || searchForToken { tokensList, err := s.paraswapClient.FetchTokensList(context.Background()) if err != nil { @@ -136,7 +136,7 @@ func (s *SwapParaswapProcessor) AvailableFor(params ProcessorInputParams) (bool, } } - if params.FromToken.Address == ZeroAddress || params.ToToken.Address == ZeroAddress { + if params.FromToken.Address == walletCommon.ZeroAddress() || params.ToToken.Address == walletCommon.ZeroAddress() { return false, ErrCannotResolveTokens } @@ -161,7 +161,7 @@ func calcReceivedAmountAndFee(baseDestAmount *big.Int, feePcnt float64) (destAmo } func (s *SwapParaswapProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *SwapParaswapProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { @@ -180,7 +180,7 @@ func (s *SwapParaswapProcessor) EstimateGas(params ProcessorInputParams) (uint64 } swapSide := paraswap.SellSide - if params.AmountOut != nil && params.AmountOut.Cmp(ZeroBigIntValue) > 0 { + if params.AmountOut != nil && params.AmountOut.Cmp(walletCommon.ZeroBigIntValue()) > 0 { swapSide = paraswap.BuySide } diff --git a/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go b/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go index 578efb5ce..07a2ec2f1 100644 --- a/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go +++ b/services/wallet/router/pathprocessor/processor_swap_paraswap_test.go @@ -56,7 +56,7 @@ func TestParaswapWithPartnerFee(t *testing.T) { partnerAddress, partnerFeePcnt := getPartnerAddressAndFeePcnt(chainID) - if partnerAddress != walletCommon.ZeroAddress { + if partnerAddress != walletCommon.ZeroAddress() { require.Greater(t, partnerFeePcnt, 0.0) expectedFee := uint64(float64(testPriceRoute.DestAmount.Uint64()) * partnerFeePcnt / 100.0) diff --git a/services/wallet/router/pathprocessor/processor_transfer.go b/services/wallet/router/pathprocessor/processor_transfer.go index a6a3e3781..4fa056eb4 100644 --- a/services/wallet/router/pathprocessor/processor_transfer.go +++ b/services/wallet/router/pathprocessor/processor_transfer.go @@ -13,6 +13,7 @@ import ( "github.com/status-im/status-go/contracts/ierc20" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/rpc" + walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/transactions" ) @@ -47,7 +48,7 @@ func (s *TransferProcessor) AvailableFor(params ProcessorInputParams) (bool, err } func (s *TransferProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) { - return ZeroBigIntValue, ZeroBigIntValue, nil + return walletCommon.ZeroBigIntValue(), walletCommon.ZeroBigIntValue(), nil } func (s *TransferProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) { diff --git a/services/wallet/router/router.go b/services/wallet/router/router.go index 6a551ebb8..86dc58684 100644 --- a/services/wallet/router/router.go +++ b/services/wallet/router/router.go @@ -242,7 +242,7 @@ func (r *Router) SuggestedRoutes(ctx context.Context, input *requests.RouteInput // return only if there are no balances, otherwise try to resolve the candidates for chains we know the balances for noBalanceOnAnyChain := true r.activeBalanceMap.Range(func(key, value interface{}) bool { - if value.(*big.Int).Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if value.(*big.Int).Cmp(walletCommon.ZeroBigIntValue()) > 0 { noBalanceOnAnyChain = false return false } @@ -406,7 +406,7 @@ func (r *Router) getOptionsForAmoutToSplitAccrossChainsForProcessingChain(input continue } - if tokenBalance.Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if tokenBalance.Cmp(walletCommon.ZeroBigIntValue()) > 0 { if tokenBalance.Cmp(amountToSplit) <= 0 { crossChainAmountOptions[chain.ChainID] = append(crossChainAmountOptions[chain.ChainID], amountOption{ amount: tokenBalance, @@ -414,7 +414,7 @@ func (r *Router) getOptionsForAmoutToSplitAccrossChainsForProcessingChain(input subtractFees: true, // for chains where we're taking the full balance, we want to subtract the fees }) amountToSplit = new(big.Int).Sub(amountToSplit, tokenBalance) - } else if amountToSplit.Cmp(pathprocessor.ZeroBigIntValue) > 0 { + } else if amountToSplit.Cmp(walletCommon.ZeroBigIntValue()) > 0 { crossChainAmountOptions[chain.ChainID] = append(crossChainAmountOptions[chain.ChainID], amountOption{ amount: amountToSplit, locked: false, @@ -438,7 +438,7 @@ func (r *Router) getCrossChainsOptionsForSendingAmount(input *requests.RouteInpu amountLocked := false amountToSend := input.AmountIn.ToInt() - if amountToSend.Cmp(pathprocessor.ZeroBigIntValue) == 0 { + if amountToSend.Cmp(walletCommon.ZeroBigIntValue()) == 0 { finalCrossChainAmountOptions[selectedFromChain.ChainID] = append(finalCrossChainAmountOptions[selectedFromChain.ChainID], amountOption{ amount: amountToSend, locked: false, @@ -459,7 +459,7 @@ func (r *Router) getCrossChainsOptionsForSendingAmount(input *requests.RouteInpu } } - if amountToSend.Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if amountToSend.Cmp(walletCommon.ZeroBigIntValue()) > 0 { // add full amount always, cause we want to check for balance errors at the end of the routing algorithm // TODO: once we introduce bettwer error handling and start checking for the balance at the beginning of the routing algorithm // we can remove this line and optimize the routing algorithm more @@ -796,7 +796,7 @@ func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute rou for _, path := range bestRoute { tokenKey := makeBalanceKey(path.FromChain.ChainID, path.FromToken.Symbol) if tokenBalance, ok := balanceMapCopy[tokenKey]; ok { - if tokenBalance.Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if tokenBalance.Cmp(walletCommon.ZeroBigIntValue()) > 0 { hasPositiveBalance = true } } @@ -807,7 +807,7 @@ func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute rou } } - if path.RequiredTokenBalance != nil && path.RequiredTokenBalance.Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if path.RequiredTokenBalance != nil && path.RequiredTokenBalance.Cmp(walletCommon.ZeroBigIntValue()) > 0 { if tokenBalance, ok := balanceMapCopy[tokenKey]; ok { if tokenBalance.Cmp(path.RequiredTokenBalance) == -1 { err := &errors.ErrorResponse{ @@ -911,12 +911,12 @@ func (r *Router) resolveRoutes(ctx context.Context, input *requests.RouteInputPa for _, path := range bestRoute { if path.SubtractFees && path.FromToken.IsNative() { path.AmountIn.ToInt().Sub(path.AmountIn.ToInt(), path.TxFee.ToInt()) - if path.TxL1Fee.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if path.TxL1Fee.ToInt().Cmp(walletCommon.ZeroBigIntValue()) > 0 { path.AmountIn.ToInt().Sub(path.AmountIn.ToInt(), path.TxL1Fee.ToInt()) } if path.ApprovalRequired { path.AmountIn.ToInt().Sub(path.AmountIn.ToInt(), path.ApprovalFee.ToInt()) - if path.ApprovalL1Fee.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if path.ApprovalL1Fee.ToInt().Cmp(walletCommon.ZeroBigIntValue()) > 0 { path.AmountIn.ToInt().Sub(path.AmountIn.ToInt(), path.ApprovalL1Fee.ToInt()) } } diff --git a/services/wallet/router/router_helper.go b/services/wallet/router/router_helper.go index b373ccff1..ee1ae4556 100644 --- a/services/wallet/router/router_helper.go +++ b/services/wallet/router/router_helper.go @@ -44,7 +44,7 @@ func (r *Router) requireApproval(ctx context.Context, sendType sendtype.SendType return false, nil, err } - if approvalContractAddress == nil || *approvalContractAddress == pathprocessor.ZeroAddress { + if approvalContractAddress == nil || *approvalContractAddress == walletCommon.ZeroAddress() { return false, nil, nil } @@ -68,7 +68,7 @@ func (r *Router) requireApproval(ctx context.Context, sendType sendtype.SendType } func (r *Router) packApprovalInputData(amountIn *big.Int, approvalContractAddress *common.Address) ([]byte, error) { - if approvalContractAddress == nil || *approvalContractAddress == pathprocessor.ZeroAddress { + if approvalContractAddress == nil || *approvalContractAddress == walletCommon.ZeroAddress { return []byte{}, nil } @@ -94,7 +94,7 @@ func (r *Router) estimateGasForApproval(params pathprocessor.ProcessorInputParam return ethClient.EstimateGas(context.Background(), ethereum.CallMsg{ From: params.FromAddr, To: ¶ms.FromToken.Address, - Value: pathprocessor.ZeroBigIntValue, + Value: walletCommon.ZeroBigIntValue(), Data: data, }) } diff --git a/services/wallet/router/routes/route.go b/services/wallet/router/routes/route.go index eee24b007..aa00ae002 100644 --- a/services/wallet/router/routes/route.go +++ b/services/wallet/router/routes/route.go @@ -5,7 +5,6 @@ import ( "math/big" "github.com/status-im/status-go/services/wallet/common" - "github.com/status-im/status-go/services/wallet/router/pathprocessor" ) type Route []*Path @@ -25,19 +24,19 @@ func FindBestRoute(routes []Route, tokenPrice float64, nativeTokenPrice float64) txFeeInEth := common.GweiToEth(common.WeiToGwei(path.TxFee.ToInt())) pathCost := new(big.Float).Mul(txFeeInEth, nativeTokenPrice) - if path.TxL1Fee.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if path.TxL1Fee.ToInt().Cmp(common.ZeroBigIntValue()) > 0 { txL1FeeInEth := common.GweiToEth(common.WeiToGwei(path.TxL1Fee.ToInt())) pathCost.Add(pathCost, new(big.Float).Mul(txL1FeeInEth, nativeTokenPrice)) } - if path.TxBonderFees != nil && path.TxBonderFees.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if path.TxBonderFees != nil && path.TxBonderFees.ToInt().Cmp(common.ZeroBigIntValue()) > 0 { pathCost.Add(pathCost, new(big.Float).Mul( new(big.Float).Quo(new(big.Float).SetInt(path.TxBonderFees.ToInt()), tokenDenominator), new(big.Float).SetFloat64(tokenPrice))) } - if path.TxTokenFees != nil && path.TxTokenFees.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 && path.FromToken != nil { + if path.TxTokenFees != nil && path.TxTokenFees.ToInt().Cmp(common.ZeroBigIntValue()) > 0 && path.FromToken != nil { pathCost.Add(pathCost, new(big.Float).Mul( new(big.Float).Quo(new(big.Float).SetInt(path.TxTokenFees.ToInt()), tokenDenominator), new(big.Float).SetFloat64(tokenPrice))) @@ -48,7 +47,7 @@ func FindBestRoute(routes []Route, tokenPrice float64, nativeTokenPrice float64) approvalFeeInEth := common.GweiToEth(common.WeiToGwei(path.ApprovalFee.ToInt())) pathCost.Add(pathCost, new(big.Float).Mul(approvalFeeInEth, nativeTokenPrice)) - if path.ApprovalL1Fee.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { + if path.ApprovalL1Fee.ToInt().Cmp(common.ZeroBigIntValue()) > 0 { approvalL1FeeInEth := common.GweiToEth(common.WeiToGwei(path.ApprovalL1Fee.ToInt())) pathCost.Add(pathCost, new(big.Float).Mul(approvalL1FeeInEth, nativeTokenPrice)) } diff --git a/services/wallet/router/sendtype/send_type.go b/services/wallet/router/sendtype/send_type.go index 6018db658..c6f8381a9 100644 --- a/services/wallet/router/sendtype/send_type.go +++ b/services/wallet/router/sendtype/send_type.go @@ -119,13 +119,13 @@ func (s SendType) CanUseProcessor(p pathprocessor.PathProcessor) bool { } func (s SendType) ProcessZeroAmountInProcessor(amountIn *big.Int, amountOut *big.Int, processorName string) bool { - if amountIn.Cmp(pathprocessor.ZeroBigIntValue) == 0 { + if amountIn.Cmp(walletCommon.ZeroBigIntValue()) == 0 { if s == Transfer { if processorName != pathprocessor.ProcessorTransferName { return false } } else if s == Swap { - if amountOut.Cmp(pathprocessor.ZeroBigIntValue) == 0 { + if amountOut.Cmp(walletCommon.ZeroBigIntValue()) == 0 { return false } } else { diff --git a/services/wallet/thirdparty/paraswap/request_build_transaction.go b/services/wallet/thirdparty/paraswap/request_build_transaction.go index b1f80e47b..1ea433cb2 100644 --- a/services/wallet/thirdparty/paraswap/request_build_transaction.go +++ b/services/wallet/thirdparty/paraswap/request_build_transaction.go @@ -50,7 +50,7 @@ func (c *ClientV5) BuildTransaction(ctx context.Context, srcTokenAddress common. params["destAmount"] = destAmountWei.String() } params["partner"] = c.partnerID - if c.partnerAddress != walletCommon.ZeroAddress && c.partnerFeePcnt > 0 { + if c.partnerAddress != walletCommon.ZeroAddress() && c.partnerFeePcnt > 0 { params["partnerAddress"] = c.partnerAddress.Hex() params["partnerFeeBps"] = uint(c.partnerFeePcnt * 100) }