- Lending Protocol
- DEX
Adding a Lending Protocol to LiquidationMonitor
The LiquidationMonitor contract maintains a registry of lending protocols it can scan for at-risk accounts. Each protocol entry has an address, a type constant, and an active flag.Supported Protocol Types
1
Define the protocol interface
If the new protocol uses a different interface than Aave V3, add a
sol_interface! declaration in contracts/liquidation-monitor/src/lib.rs:2
Add a type constant
Define a new constant for the protocol type:The contract dispatches health factor queries based on this type
constant, so each protocol needs a unique value.
3
Add dispatch logic in the health scanner
In the
get_health_factor method, add a branch for the new type:4
Register the protocol on-chain
Call This emits a
add_lending_protocol with the pool address and type constant:LendingProtocolAdded event and returns the registry
index.5
Write tests
Add tests using the
TestVM and mock_static_call patterns:mock_static_call in stylus-test 0.10.0 always returns the LAST
registered mock’s data. Register losing mocks first, then the
winning mock last.Soft-Delete Removal Pattern
Both contracts use soft-delete rather than array compaction. When you remove a protocol or DEX, theactive flag is set to false but the entry remains
in the mapping. The scanning functions skip inactive entries.
LendingProtocolRemoved or DexRemoved event.
Attempting to remove an already-inactive entry reverts.