Section 7 of 15

Build
+15 Lynx

BorrowerOperations: openTrove

Key takeaway: openTrove is the user's entry point to the protocol. The flow: fetch price, check Recovery Mode, validate the max-fee parameter, accept the user's ETH, compute the composite debt (LUSD requested + 0.5% borrowing fee + 200 LUSD gas compensation), check ICR against MCR (or CCR in Recovery Mode), set the Trove storage on TroveManager, snapshot the redistribution accumulators, compute the Trove's stake, insert into SortedTroves, move ETH into ActivePool, mint LUSD to the borrower, and mint 200 LUSD to GasPool. Every step in the function is a defense — anti-MEV via max-fee, anti-undercollateralization via ICR check, anti-dilution via snapshot. Until this function runs successfully, nothing else in the protocol matters.

What You Are Building

openTrove is the first function any user calls. Until they have a Trove, they can't borrow, can't be liquidated, can't redeem against. Everything starts here.

The function does fifteen things in roughly the order listed in the Key takeaway. None of them are tricky on their own; the difficulty is keeping the ordering right. Get any step out of order and you either let invalid Troves through, charge users the wrong fee, or break the redistribution accounting permanently.

This section also extends TroveManager with two new state-mutating functions: updateTroveRewardSnapshots and updateStakeAndTotalStakes. These are TroveManager methods called by BorrowerOperations — they live on TroveManager because they modify TroveManager's storage, but we build them here so the whole openTrove pipeline appears in one place.

Your Code

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

Sign up free — keep reading + earn 15 Lynx

Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.

Sign up free to continue

Already have an account? Log in