@@ -34,10 +34,10 @@ func (curve *ExponentialCurve) CostToBuyTokens(currentSupply, tokensToBuy *big.F
3434 newSupply := new (big.Float ).Add (currentSupply , tokensToBuy )
3535 cs := new (big.Float ).Mul (curve .c , currentSupply )
3636 ns := new (big.Float ).Mul (curve .c , newSupply )
37- expCS := expBig (cs )
38- expNS := expBig (ns )
37+ expCs := expBig (cs )
38+ expNs := expBig (ns )
3939 abOverC := new (big.Float ).Quo (new (big.Float ).Mul (curve .a , curve .b ), curve .c )
40- diff := new (big.Float ).Sub (expNS , expCS )
40+ diff := new (big.Float ).Sub (expNs , expCs )
4141 return new (big.Float ).Mul (abOverC , diff )
4242}
4343
@@ -54,32 +54,21 @@ func (curve *ExponentialCurve) ValueFromSellingTokens(currentValue, tokensToSell
5454// How many tokens will be bought for a value given the currentSupply?
5555func (curve * ExponentialCurve ) TokensBoughtForValue (currentSupply , value * big.Float ) * big.Float {
5656 abOverC := new (big.Float ).Quo (new (big.Float ).Mul (curve .a , curve .b ), curve .c )
57- expCS := expBig (new (big.Float ).Mul (curve .c , currentSupply ))
58- term := new (big.Float ).Add (new (big.Float ).Quo (value , abOverC ), expCS )
57+ expCs := expBig (new (big.Float ).Mul (curve .c , currentSupply ))
58+ term := new (big.Float ).Add (new (big.Float ).Quo (value , abOverC ), expCs )
5959 lnTerm := logBig (term )
6060 result := new (big.Float ).Quo (lnTerm , curve .c )
6161 return new (big.Float ).Sub (result , currentSupply )
6262}
6363
6464// How many tokens should be exchanged for a value given the currentSupply?
65- //
66- // Note: This function assumes the default curve, and is not present in the currency creator program.
6765func (curve * ExponentialCurve ) TokensForValueExchange (currentSupply , value * big.Float ) * big.Float {
68- hundred := big .NewFloat (100 )
69- oneOverHundred := new (big.Float ).Quo (big .NewFloat (1 ), hundred )
70-
71- hundredTimesA := new (big.Float ).Mul (hundred , curve .a )
72- negativeHundredTimesA := new (big.Float ).Mul (big .NewFloat (- 1 ), hundredTimesA )
73-
74- valueTimesB := new (big.Float ).Mul (value , curve .b )
75-
76- expCsTimesB := expBig (new (big.Float ).Mul (currentSupply , curve .b ))
77- oneOverHundredTimesExpCsTimesB := new (big.Float ).Mul (oneOverHundred , expCsTimesB )
78-
79- lnInput := new (big.Float ).Quo (valueTimesB , oneOverHundredTimesExpCsTimesB )
80- lnInput = new (big.Float ).Sub (big .NewFloat (1 ), lnInput )
81-
82- return new (big.Float ).Mul (negativeHundredTimesA , logBig (lnInput ))
66+ abOverC := new (big.Float ).Quo (new (big.Float ).Mul (curve .a , curve .b ), curve .c )
67+ expCs := expBig (new (big.Float ).Mul (curve .c , currentSupply ))
68+ abOverCTimesExpCs := new (big.Float ).Mul (abOverC , expCs )
69+ oneMinusFrac := new (big.Float ).Sub (big .NewFloat (1 ), new (big.Float ).Quo (value , abOverCTimesExpCs ))
70+ ln := logBig (oneMinusFrac )
71+ return new (big.Float ).Quo (new (big.Float ).Neg (ln ), curve .c )
8372}
8473
8574func DefaultExponentialCurve () * ExponentialCurve {
0 commit comments