Skip to content

Commit 56378b8

Browse files
cursoragentpaullinator
authored andcommitted
Guard v3 rate calculations against zero rates
1 parent 742b02d commit 56378b8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/ratesEngine.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,22 @@ async function updateTxValuesV3(transaction: DbTx): Promise<void> {
229229
`No rate found for payout ${payoutCurrency} ${payoutChainPluginId} ${payoutTokenId}`
230230
)
231231
}
232-
if (depositRate != null && payoutRate != null) {
232+
if (
233+
depositRate != null &&
234+
depositRate > 0 &&
235+
payoutRate != null &&
236+
payoutRate > 0
237+
) {
233238
transaction.payoutAmount = (depositAmount * depositRate) / payoutRate
234239
}
235240
}
236241

237242
// Calculate the usdValue first trying to use the deposit amount. If that's not available
238243
// then try to use the payout amount.
239244
if (transaction.usdValue == null || transaction.usdValue <= 0) {
240-
if (depositRate != null) {
245+
if (depositRate != null && depositRate > 0) {
241246
transaction.usdValue = depositAmount * depositRate
242-
} else if (payoutRate != null) {
247+
} else if (payoutRate != null && payoutRate > 0) {
243248
transaction.usdValue = transaction.payoutAmount * payoutRate
244249
}
245250
}

0 commit comments

Comments
 (0)