1
1
package org .tron .core .capsule ;
2
2
3
3
import lombok .extern .slf4j .Slf4j ;
4
+ import org .tron .common .math .Maths ;
4
5
5
6
@ Slf4j (topic = "capsule" )
6
7
public class ExchangeProcessor {
7
8
8
9
private long supply ;
10
+ private final boolean useStrictMath ;
9
11
10
- public ExchangeProcessor (long supply ) {
12
+ public ExchangeProcessor (long supply , boolean useStrictMath ) {
11
13
this .supply = supply ;
14
+ this .useStrictMath = useStrictMath ;
12
15
}
13
16
14
17
private long exchangeToSupply (long balance , long quant ) {
15
18
logger .debug ("balance: " + balance );
16
19
long newBalance = balance + quant ;
17
20
logger .debug ("balance + quant: " + newBalance );
18
21
19
- double issuedSupply = -supply * (1.0 - Math .pow (1.0 + (double ) quant / newBalance , 0.0005 ));
22
+ double issuedSupply = -supply * (1.0
23
+ - Maths .pow (1.0 + (double ) quant / newBalance , 0.0005 , this .useStrictMath ));
20
24
logger .debug ("issuedSupply: " + issuedSupply );
21
25
long out = (long ) issuedSupply ;
22
26
supply += out ;
@@ -27,8 +31,8 @@ private long exchangeToSupply(long balance, long quant) {
27
31
private long exchangeFromSupply (long balance , long supplyQuant ) {
28
32
supply -= supplyQuant ;
29
33
30
- double exchangeBalance =
31
- balance * (Math .pow (1.0 + (double ) supplyQuant / supply , 2000.0 ) - 1.0 );
34
+ double exchangeBalance = balance
35
+ * (Maths .pow (1.0 + (double ) supplyQuant / supply , 2000.0 , this . useStrictMath ) - 1.0 );
32
36
logger .debug ("exchangeBalance: " + exchangeBalance );
33
37
34
38
return (long ) exchangeBalance ;
0 commit comments