Skip to content

Commit 9a685af

Browse files
committed
Update launchpad currency exchange data validaiton
1 parent 30b846c commit 9a685af

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pkg/code/currency/validation.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,22 @@ func validateCurrencyLaunchpadClientExchangeData(ctx context.Context, data code_
115115
SellFeeBps: 0,
116116
})
117117

118-
// Given the sell value, does it align with the native amount in the target currency?
118+
// Given the sell value, does it align with the native amount in the target currency
119+
// within half a penny?
120+
errorThreshold := 0.005
121+
nativeAmountLowerBound := math.Max(proto.NativeAmount-errorThreshold, errorThreshold)
122+
nativeAmountUpperBound := proto.NativeAmount + errorThreshold
119123
coreMintSellValueInUnits := float64(coreMintSellValueInQuarks) / float64(coreMintQuarksPerUnit)
120124
potentialNativeAmount := otherExchangeRateRecord.Rate * coreMintSellValueInUnits / usdExchangeRateRecord.Rate
121-
percentDiff := math.Abs(proto.NativeAmount-potentialNativeAmount) / potentialNativeAmount
122-
if percentDiff > 0.001 {
125+
if potentialNativeAmount < nativeAmountLowerBound || potentialNativeAmount > nativeAmountUpperBound {
123126
continue
124127
}
125128

126129
// For the valid native amount, is the exchange rate calculated correctly?
127130
otherMintUnits := float64(proto.Quarks) / float64(otherMintQuarksPerUnit)
128131
expectedRate := potentialNativeAmount / otherMintUnits
129-
percentDiff = math.Abs(proto.ExchangeRate-expectedRate) / expectedRate
130-
if percentDiff > 0.001 {
132+
percentDiff := math.Abs(proto.ExchangeRate-expectedRate) / expectedRate
133+
if percentDiff > 0.0001 {
131134
continue
132135
}
133136

0 commit comments

Comments
 (0)