@@ -2,6 +2,7 @@ package currency
22
33import (
44 "context"
5+ "math"
56 "math/big"
67 "time"
78
@@ -39,9 +40,17 @@ func validateCoreMintClientExchangeData(ctx context.Context, data code_data.Prov
3940 clientNativeAmount := big .NewFloat (proto .NativeAmount ).SetPrec (defaultPrecision )
4041 clientQuarks := big .NewFloat (float64 (proto .Quarks )).SetPrec (defaultPrecision )
4142
43+ currencyDecimals := currency_lib .GetDecimals (currency_lib .Code (proto .Currency ))
44+ one := big .NewFloat (1.0 ).SetPrec (defaultPrecision )
45+ minTransferValue := new (big.Float ).Quo (one , big .NewFloat (math .Pow10 (currencyDecimals )))
46+
4247 rateErrorThreshold := big .NewFloat (0.001 ).SetPrec (defaultPrecision )
4348 quarkErrorThreshold := big .NewFloat (1000 ).SetPrec (defaultPrecision )
4449
50+ if clientNativeAmount .Cmp (minTransferValue ) < 0 {
51+ return false , "native amount is less than minimum transfer value" , nil
52+ }
53+
4554 // Find an exchange rate that the client could have fetched from a RPC call
4655 // within a reasonable time in the past
4756 var isClientRateValid bool
@@ -73,7 +82,7 @@ func validateCoreMintClientExchangeData(ctx context.Context, data code_data.Prov
7382 unitsOfCoreMint := new (big.Float ).Quo (clientNativeAmount , clientRate )
7483 expectedQuarks := new (big.Float ).Mul (unitsOfCoreMint , quarksPerUnit )
7584 diff := new (big.Float ).Abs (new (big.Float ).Sub (expectedQuarks , clientQuarks ))
76- if diff .Cmp (quarkErrorThreshold ) > 1000 {
85+ if diff .Cmp (quarkErrorThreshold ) > 0 {
7786 return false , "payment native amount and quark value mismatch" , nil
7887 }
7988
@@ -97,8 +106,12 @@ func validateCurrencyLaunchpadClientExchangeData(ctx context.Context, data code_
97106 clientRate := big .NewFloat (proto .ExchangeRate ).SetPrec (defaultPrecision )
98107 clientNativeAmount := big .NewFloat (proto .NativeAmount ).SetPrec (defaultPrecision )
99108
109+ currencyDecimals := currency_lib .GetDecimals (currency_lib .Code (proto .Currency ))
110+ one := big .NewFloat (1.0 ).SetPrec (defaultPrecision )
111+ minTransferValue := new (big.Float ).Quo (one , big .NewFloat (math .Pow10 (currencyDecimals )))
112+
100113 rateErrorThreshold := big .NewFloat (0.001 ).SetPrec (defaultPrecision )
101- nativeAmountErrorThreshold := big .NewFloat (0.005 ). SetPrec ( defaultPrecision )
114+ nativeAmountErrorThreshold := new ( big.Float ). Quo ( minTransferValue , big . NewFloat (2.0 ) )
102115
103116 log := logrus .StandardLogger ().WithFields (logrus.Fields {
104117 "currency" : proto .Currency ,
@@ -107,8 +120,14 @@ func validateCurrencyLaunchpadClientExchangeData(ctx context.Context, data code_
107120 "client_token_units" : clientTokenUnits ,
108121 "client_quarks" : proto .Quarks ,
109122 "mint" : mintAccount .PublicKey ().ToBase58 (),
123+ "min_transfer_value" : minTransferValue ,
110124 })
111125
126+ if clientNativeAmount .Cmp (minTransferValue ) < 0 {
127+ log .Info ("native amount is less than minimum transfer value" )
128+ return false , "native amount is less than minimum transfer value" , nil
129+ }
130+
112131 latestExchangeRateTime := GetLatestExchangeRateTime ()
113132 for i := range 2 {
114133 exchangeRateTime := latestExchangeRateTime .Add (time .Duration (- i ) * timePerExchangeRateUpdate )
0 commit comments