Skip to content

Commit 15901cc

Browse files
committed
add inAmount guard
1 parent be6b5d5 commit 15901cc

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

cadence/contracts/connectors/SwapConnectors.cdc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,20 @@ access(all) contract SwapConnectors {
201201
}
202202
/// The estimated amount delivered out for a provided input balance.
203203
///
204-
/// Selection policy: prefer maximum outAmount across all routes.
204+
/// Selection policy: among routes where inAmount <= forProvided, prefer the highest outAmount,
205+
/// then the lowest inAmount as a tiebreaker. Routes where inAmount > forProvided are excluded —
206+
/// they cannot be executed with the provided input and would produce misleadingly high outAmounts.
205207
access(all) fun quoteOut(forProvided: UFix64, reverse: Bool): {DeFiActions.Quote} {
206208
var bestIdx = 0
207-
var bestInAmount = forProvided
209+
var bestInAmount = 0.0
208210
var bestOutAmount = 0.0
209211

210212
for i in InclusiveRange(0, self.swappers.length - 1) {
211213
let quote = (&self.swappers[i] as &{DeFiActions.Swapper})
212214
.quoteOut(forProvided: forProvided, reverse: reverse)
213215
if quote.inAmount == 0.0 || quote.outAmount == 0.0 { continue }
216+
if quote.inAmount > forProvided { continue }
217+
214218
if quote.outAmount > bestOutAmount {
215219
bestIdx = i
216220
bestInAmount = quote.inAmount

0 commit comments

Comments
 (0)