mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Code to compute how much you need to pay to get a particular output from an offer.
This commit is contained in:
@@ -234,6 +234,8 @@ STAmount operator*(const STAmount &v1, const STAmount &v2)
|
|||||||
|
|
||||||
STAmount getRate(const STAmount& offerOut, const STAmount& offerIn)
|
STAmount getRate(const STAmount& offerOut, const STAmount& offerIn)
|
||||||
{
|
{
|
||||||
|
// offerOut = how much comes out of the offer, from the offeror to the taker
|
||||||
|
// offerIn = how much goes into the offer, from the taker to the offeror
|
||||||
return offerOut / offerIn;
|
return offerOut / offerIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,3 +273,11 @@ STAmount getClaimed(STAmount& offerOut, STAmount& offerIn, STAmount& paid)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STAmount getNeeded(const STAmount& offerOut, const STAmount& offerIn, const STAmount& needed)
|
||||||
|
{ // Someone wants to get (needed) out of the offer, how much should they pay in?
|
||||||
|
if(offerOut.isZero()) return STAmount();
|
||||||
|
if(needed >= offerOut) return needed;
|
||||||
|
STAmount ret = needed * (offerIn / offerOut);
|
||||||
|
return (ret > offerIn) ? offerIn : ret;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user