Skip to main content
The Stylus contracts use dynamic registries — indexed mappings with soft-delete removal — so new protocols and DEXes can be added on-chain without redeployment. This guide covers both workflows.

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 add_lending_protocol with the pool address and type constant:
This emits a 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, the active flag is set to false but the entry remains in the mapping. The scanning functions skip inactive entries.
Removing a protocol emits a LendingProtocolRemoved or DexRemoved event. Attempting to remove an already-inactive entry reverts.
Use get_lending_protocol(index) or get_dex(index) to check the current state of a registry entry before removal.