@@ -91,10 +91,11 @@ access(all) contract FlowALPMath {
9191 }
9292
9393 /// Checks that the DEX price does not deviate from the oracle price by more than the given threshold.
94- /// The deviation is computed as the absolute difference divided by the smaller price, expressed in basis points .
94+ /// We use the dexPrice as the denominator because that is the price we are actually swapping at .
9595 access (all ) view fun dexOraclePriceDeviationInRange (dexPrice : UFix64 , oraclePrice : UFix64 , maxDeviationBps : UInt16 ): Bool {
9696 let diff : UFix64 = dexPrice < oraclePrice ? oraclePrice - dexPrice : dexPrice - oraclePrice
97- let diffPct : UFix64 = dexPrice < oraclePrice ? diff / dexPrice : diff / oraclePrice
97+ // We care about deviation relative to the price we are actually using to swap
98+ let diffPct : UFix64 = diff / dexPrice
9899 let diffBps = UInt16 (diffPct * 10_000.0 )
99100 return diffBps < = maxDeviationBps
100101 }
@@ -146,7 +147,7 @@ access(all) contract FlowALPMath {
146147 /// Effective Collateral is defined:
147148 /// Ce = (Nc)(Pc)(Fc)
148149 /// Where:
149- /// Ce = Effective Collateral
150+ /// Ce = Effective Collateral
150151 /// Nc = Number of Collateral Tokens
151152 /// Pc = Collateral Token Price
152153 /// Fc = Collateral Factor
@@ -162,7 +163,7 @@ access(all) contract FlowALPMath {
162163 /// Effective Debt is defined:
163164 /// De = (Nd)(Pd)(Fd)
164165 /// Where:
165- /// De = Effective Debt
166+ /// De = Effective Debt
166167 /// Nd = Number of Debt Tokens
167168 /// Pd = Debt Token Price
168169 /// Fd = Borrow Factor
0 commit comments