Skip to content

Commit 9099b7b

Browse files
Merge pull request #178 from onflow/UlianaAndrukhiv/149-oracle-failure-and-manipulation-testing
Oracle Failure & Manipulation Testing
2 parents a2e8f2b + 24aa633 commit 9099b7b

File tree

6 files changed

+559
-4
lines changed

6 files changed

+559
-4
lines changed

cadence/contracts/mocks/MockOracle.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ access(all) contract MockOracle {
6565
}
6666
}
6767

68-
access(all) fun setPrice(forToken: Type, price: UFix64) {
68+
access(all) fun setPrice(forToken: Type, price: UFix64?) {
6969
self.mockedPrices[forToken] = price
7070
}
7171

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import "FlowALPv0"
2+
3+
/// Returns whether a position is eligible for liquidation
4+
///
5+
/// A position is liquidatable when its health factor is below 1.0,
6+
/// indicating it has crossed the global liquidation threshold.
7+
///
8+
/// @param pid: The unique identifier of the position.
9+
/// @return `true` if the position can be liquidated, otherwise `false`.
10+
access(all) fun main(pid: UInt64): Bool {
11+
let protocolAddress = Type<@FlowALPv0.Pool>().address!
12+
let pool = getAccount(protocolAddress).capabilities.borrow<&FlowALPv0.Pool>(FlowALPv0.PoolPublicPath)
13+
?? panic("Could not find Pool at path \(FlowALPv0.PoolPublicPath)")
14+
15+
return pool.isLiquidatable(pid: pid)
16+
}

0 commit comments

Comments
 (0)