Skip to content

Commit 5494432

Browse files
committed
Propagate field logging in validateCurrencyLaunchpadClientExchangeData
1 parent 61abc63 commit 5494432

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

pkg/code/currency/validation.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func validateCoreMintClientExchangeData(ctx context.Context, data code_data.Prov
3939
clientNativeAmount := big.NewFloat(proto.NativeAmount).SetPrec(defaultPrecision)
4040
clientQuarks := big.NewFloat(float64(proto.Quarks)).SetPrec(defaultPrecision)
4141

42-
rateErrorThreshold := big.NewFloat(0.01).SetPrec(defaultPrecision)
42+
rateErrorThreshold := big.NewFloat(0.001).SetPrec(defaultPrecision)
4343
quarkErrorThreshold := big.NewFloat(1000).SetPrec(defaultPrecision)
4444

4545
// Find an exchange rate that the client could have fetched from a RPC call
@@ -97,7 +97,7 @@ func validateCurrencyLaunchpadClientExchangeData(ctx context.Context, data code_
9797
clientRate := big.NewFloat(proto.ExchangeRate).SetPrec(defaultPrecision)
9898
clientNativeAmount := big.NewFloat(proto.NativeAmount).SetPrec(defaultPrecision)
9999

100-
rateErrorThreshold := big.NewFloat(0.01).SetPrec(defaultPrecision)
100+
rateErrorThreshold := big.NewFloat(0.001).SetPrec(defaultPrecision)
101101
nativeAmountErrorThreshold := big.NewFloat(0.005).SetPrec(defaultPrecision)
102102

103103
log := logrus.StandardLogger().WithFields(logrus.Fields{
@@ -161,23 +161,29 @@ func validateCurrencyLaunchpadClientExchangeData(ctx context.Context, data code_
161161
big.NewFloat(float64(coreMintQuarksPerUnit)).SetPrec(defaultPrecision),
162162
)
163163
potentialNativeAmount := new(big.Float).Mul(new(big.Float).Quo(otherRate, usdRate), coreMintSellValueInUnits)
164+
165+
log := log.WithFields(logrus.Fields{
166+
"core_mint_sell_value": coreMintSellValueInUnits,
167+
"native_amount_lower_bound": nativeAmountLowerBound,
168+
"native_amount_upper_bound": nativeAmountUpperBound,
169+
"potential_native_amount": potentialNativeAmount,
170+
"usd_rate": usdRate,
171+
"other_rate": otherRate,
172+
})
173+
164174
if potentialNativeAmount.Cmp(nativeAmountLowerBound) < 0 || potentialNativeAmount.Cmp(nativeAmountUpperBound) > 0 {
165-
log.WithFields(logrus.Fields{
166-
"core_mint_sell_value": coreMintSellValueInUnits,
167-
"native_amount_lower_bound": nativeAmountLowerBound,
168-
"native_amount_upper_bound": nativeAmountUpperBound,
169-
"potential_native_amount": potentialNativeAmount,
170-
"usd_rate": usdRate,
171-
"other_rate": otherRate,
172-
}).Info("native amount is outside error threshold")
175+
log.Info("native amount is outside error threshold")
173176
continue
174177
}
175178

176179
// For the valid native amount, is the exchange rate calculated correctly?
177180
expectedRate := new(big.Float).Quo(clientNativeAmount, clientTokenUnits)
178181
percentDiff := new(big.Float).Quo(new(big.Float).Abs(new(big.Float).Sub(clientRate, expectedRate)), expectedRate)
182+
183+
log = log.WithField("potential_exchange_rate", expectedRate)
184+
179185
if percentDiff.Cmp(rateErrorThreshold) > 0 {
180-
log.WithField("potential_exchange_rate", expectedRate).Info("exchange rate is outside error threshold")
186+
log.Info("exchange rate is outside error threshold")
181187
continue
182188
}
183189

0 commit comments

Comments
 (0)