diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index f461081ebf..0824c97063 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -3656,7 +3656,7 @@ std::vector CPoolSwap::CalculateSwaps(CCustomCSView& view, bool testOnly std::vector> poolPaths = CalculatePoolPaths(view); // Record best pair - std::pair, CAmount> bestPair{{}, 0}; + std::pair, CAmount> bestPair{{}, -1}; // Loop through all common pairs for (const auto& path : poolPaths) { @@ -3768,6 +3768,10 @@ Res CPoolSwap::ExecuteSwap(CCustomCSView& view, std::vector poolIDs, boo poolIDs.clear(); } + if (obj.amountFrom <= 0) { + return Res::Err("Input amount should be positive"); + } + // Single swap if no pool IDs provided auto poolPrice = POOLPRICE_MAX; boost::optional > poolPair; diff --git a/src/masternodes/poolpairs.cpp b/src/masternodes/poolpairs.cpp index da6f4a5947..a11c17c155 100644 --- a/src/masternodes/poolpairs.cpp +++ b/src/masternodes/poolpairs.cpp @@ -391,8 +391,11 @@ Res CPoolPair::Swap(CTokenAmount in, CAmount dexfeeInPct, PoolPrice const & maxP if (in.nTokenId != idTokenA && in.nTokenId != idTokenB) return Res::Err("Error, input token ID (" + in.nTokenId.ToString() + ") doesn't match pool tokens (" + idTokenA.ToString() + "," + idTokenB.ToString() + ")"); - if (in.nValue <= 0) - return Res::Err("Input amount should be positive!"); + // TODO: The whole block of the fork condition can be removed safely after FCH. + if (height < Params().GetConsensus().FortCanningHillHeight) { + if (in.nValue <= 0) + return Res::Err("Input amount should be positive!"); + } if (!status) return Res::Err("Pool trading is turned off!"); diff --git a/src/masternodes/rpc_poolpair.cpp b/src/masternodes/rpc_poolpair.cpp index f7300dbe64..13201d912f 100644 --- a/src/masternodes/rpc_poolpair.cpp +++ b/src/masternodes/rpc_poolpair.cpp @@ -1056,6 +1056,9 @@ UniValue testpoolswap(const JSONRPCRequest& request) { if (!poolPair) throw JSONRPCError(RPC_INVALID_REQUEST, std::string{"Direct pool pair not found. Use 'auto' mode to use composite swap."}); + if (poolSwapMsg.amountFrom <= 0) + throw JSONRPCError(RPC_INVALID_REQUEST, "Input amount should be positive"); + CPoolPair pp = poolPair->second; auto dexfeeInPct = mnview_dummy.GetDexFeePct(poolPair->first, poolSwapMsg.idTokenFrom);