Rosario Borgesi pfp
Rosario Borgesi

@rosarioborgesi

I’ve been building an over-collateralized lending protocol in the @buidlguidl SpeedrunEthereum challenge (ETH collateral, CORN debt). Here’s the reasoning behind my `borrowCorn()` function 👇 The key idea: • You can only borrow if your position stays above the minimum collateral ratio (120% in my case). So: • collateralValue / debt >= 1.20 Implementation choices in the function: 1) Reject borrowAmount == 0 No pointless state writes. 2) Update debt FIRST: s_userBorrowed[msg.sender] += borrowAmount; 3) Validate AFTER increasing debt: _validatePosition(msg.sender); 4) Only if it’s safe, transfer CORN to the user.
0 reply
0 recast
0 reaction