diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index 8dd45f147..c3d2c7a57 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -1057,7 +1057,7 @@ bool STAmount::applyOffer( // Offer has limited funding, limit offer gets and pays by funds available. saOfferPaysAvailable = saOfferFundsAvailable; - saOfferGetsAvailable = std::min(saOfferGets, multiply(saOfferPaysAvailable, saOfferRate, saOfferGets)); + saOfferGetsAvailable = std::min(saOfferGets, mulRound(saOfferPaysAvailable, saOfferRate, saOfferGets, true)); } cLog(lsINFO) << "applyOffer: saOfferPaysAvailable=" << saOfferFundsAvailable.getFullText(); @@ -1069,14 +1069,14 @@ bool STAmount::applyOffer( cLog(lsINFO) << "applyOffer: saTakerPaysMax=" << saTakerPaysMax.getFullText(); STAmount saTakerGetsMax = saTakerPaysMax >= saOfferGetsAvailable ? saOfferPaysAvailable // Potentially take entire offer. Avoid math shenanigans. - : std::min(saOfferPaysAvailable, divide(saTakerPaysMax, saOfferRate, saTakerGets)); // Taker a portion of offer. + : std::min(saOfferPaysAvailable, divRound(saTakerPaysMax, saOfferRate, saTakerGets, !saTakerGets.isNative())); // Taker a portion of offer. cLog(lsINFO) << "applyOffer: saOfferRate=" << saOfferRate.getFullText(); cLog(lsINFO) << "applyOffer: saTakerGetsMax=" << saTakerGetsMax.getFullText(); saTakerGot = std::min(saTakerGets, saTakerGetsMax); // Limit by wanted. saTakerPaid = saTakerGot == saOfferPaysAvailable ? saOfferGetsAvailable - : std::min(saOfferGetsAvailable, multiply(saTakerGot, saOfferRate, saTakerFunds)); + : std::min(saOfferGetsAvailable, mulRound(saTakerGot, saOfferRate, saTakerFunds, true)); cLog(lsINFO) << "applyOffer: saTakerGot=" << saTakerGot.getFullText(); cLog(lsINFO) << "applyOffer: saTakerPaid=" << saTakerPaid.getFullText(); @@ -1093,7 +1093,7 @@ bool STAmount::applyOffer( cLog(lsINFO) << "applyOffer: saTransferRate=" << saTransferRate.getFullText(); // TakerCost includes transfer fees. - STAmount saTakerCost = STAmount::multiply(saTakerPaid, saTransferRate); + STAmount saTakerCost = STAmount::mulRound(saTakerPaid, saTransferRate, true); cLog(lsINFO) << "applyOffer: saTakerCost=" << saTakerCost.getFullText(); cLog(lsINFO) << "applyOffer: saTakerFunds=" << saTakerFunds.getFullText(); @@ -1111,7 +1111,7 @@ bool STAmount::applyOffer( else { // Compute fees in a rounding safe way. - STAmount saOfferCost = STAmount::multiply(saTakerGot, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uOfferPaysRate, -9)); + STAmount saOfferCost = STAmount::mulRound(saTakerGot, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uOfferPaysRate, -9), true); saOfferIssuerFee = saOfferCost > saOfferFunds ? saOfferFunds-saTakerGot // Not enough funds to cover fee, stiff issuer the rounding error. diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 15d0f0446..cd7d8e9f0 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -1306,7 +1306,7 @@ TER RippleCalc::calcNodeDeliverRev( { // Adjust output to conform to limited input. // XXX Verify it is impossible for these to be larger than available funds. - saOutPass = STAmount::divRound(saInPassAct, saOfrRate, saTakerGets, true); + saOutPass = STAmount::divRound(saInPassAct, saOfrRate, saTakerGets, !saTakerGets.isNative()); saOutPlusFees = STAmount::mulRound(saOutPass, saOutFeeRate, true); cLog(lsINFO) << boost::str(boost::format("calcNodeDeliverRev: adjusted: saOutPass=%s saOutPlusFees=%s") @@ -1447,7 +1447,7 @@ TER RippleCalc::calcNodeDeliverFwd( STAmount saInTotal = STAmount::mulRound(saInFunded, saInFeeRate, true); // Offer maximum in with fees. STAmount saInSum = std::min(saInTotal, saInReq-saInAct-saInFees); // In limited by remaining. STAmount saInPassAct = STAmount::divRound(saInSum, saInFeeRate, true); // In without fees. - STAmount saOutPassMax = STAmount::divRound(saInPassAct, saOfrRate, saTakerGets, true); // Out limited by in remaining. + STAmount saOutPassMax = STAmount::divRound(saInPassAct, saOfrRate, saTakerGets, !saTakerGets.isNative()); // Out limited by in remaining. STAmount saInPassFeesMax = saInSum-saInPassAct; @@ -2280,7 +2280,7 @@ TER RippleCalc::calcNodeAccountFwd( STAmount saIssueCrd = uQualityIn >= QUALITY_ONE ? saPrvIssueReq // No fee. - : STAmount::mulRound(saPrvIssueReq, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uQualityIn, -9), false); // Amount to credit. + : STAmount::mulRound(saPrvIssueReq, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uQualityIn, -9), true); // Amount to credit. // Amount to credit. Credit for less than received as a surcharge. saCurReceive = saPrvRedeemReq+saIssueCrd;