Skip to content

Commit c777197

Browse files
committed
fix: _getFloorPrice() fix - use first segment for price
1 parent 16a6463 commit c777197

2 files changed

Lines changed: 17 additions & 63 deletions

File tree

src/modules/logicModule/LM_PC_Lending_Facility_v1.sol

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,7 @@ contract LM_PC_Lending_Facility_v1 is
435435
IBondingCurveBase_v1(_dbcFmAddress).getIssuanceToken()
436436
).totalSupply();
437437

438-
// Get the first segment's initial price (P_floor)
439-
PackedSegment[] memory segments = dbcFm.getSegments();
440-
if (segments.length == 0) {
441-
revert
442-
ILM_PC_Lending_Facility_v1
443-
.Module__LM_PC_Lending_Facility_NoSegmentsConfigured();
444-
}
445-
446-
// Use PackedSegmentLib to get the initial price of the first segment
447-
uint pFloor = PackedSegmentLib._initialPrice(segments[0]);
438+
uint pFloor = _getFloorPrice();
448439

449440
// Borrow Capacity = virtualIssuanceSupply * P_floor
450441
return virtualIssuanceSupply * pFloor / 1e18; // Adjust for decimals
@@ -458,11 +449,9 @@ contract LM_PC_Lending_Facility_v1 is
458449
view
459450
returns (uint)
460451
{
461-
// Use the DBC FM to get the actual floor price
452+
// Use the DBC FM to get the actual floor price from the first segment
462453
// User borrowing power = locked issuance tokens * floor price
463-
IFM_BC_Discrete_Redeeming_VirtualSupply_v1 dbcFm =
464-
IFM_BC_Discrete_Redeeming_VirtualSupply_v1(_dbcFmAddress);
465-
uint floorPrice = dbcFm.getStaticPriceForBuying();
454+
uint floorPrice = _getFloorPrice();
466455
return _lockedIssuanceTokens[user_] * floorPrice / 1e18; // Adjust for decimals
467456
}
468457

@@ -507,11 +496,9 @@ contract LM_PC_Lending_Facility_v1 is
507496
view
508497
returns (uint)
509498
{
510-
// Use the DBC FM to get the actual floor price
499+
// Use the DBC FM to get the actual floor price from the first segment
511500
// Required collateral = issuance tokens * floor price
512-
IFM_BC_Discrete_Redeeming_VirtualSupply_v1 dbcFm =
513-
IFM_BC_Discrete_Redeeming_VirtualSupply_v1(_dbcFmAddress);
514-
uint floorPrice = dbcFm.getStaticPriceForBuying();
501+
uint floorPrice = _getFloorPrice();
515502
return issuanceTokenAmount_ * floorPrice / 1e18; // Adjust for decimals
516503
}
517504

@@ -533,6 +520,17 @@ contract LM_PC_Lending_Facility_v1 is
533520
function _getFloorPrice() internal view returns (uint) {
534521
IFM_BC_Discrete_Redeeming_VirtualSupply_v1 dbcFm =
535522
IFM_BC_Discrete_Redeeming_VirtualSupply_v1(_dbcFmAddress);
536-
return dbcFm.getStaticPriceForBuying();
523+
524+
// Get the segments from the funding manager
525+
PackedSegment[] memory segments = dbcFm.getSegments();
526+
527+
if (segments.length == 0) {
528+
revert
529+
ILM_PC_Lending_Facility_v1
530+
.Module__LM_PC_Lending_Facility_NoSegmentsConfigured();
531+
}
532+
533+
// Return the initial price of the first segment (floor price)
534+
return PackedSegmentLib._initialPrice(segments[0]);
537535
}
538536
}

test/unit/modules/logicModule/LM_PC_Lending_Facility_v1_Test.t.sol

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -640,50 +640,6 @@ contract LM_PC_Lending_Facility_v1_Test is ModuleTest {
640640
);
641641
}
642642

643-
/* Test: Function borrow()
644-
├── Given a user has sufficient issuance tokens
645-
├── And the borrow amount exceeds borrowable quota
646-
└── When the user tries to borrow collateral tokens
647-
└── Then the transaction should revert with BorrowableQuotaExceeded error
648-
*/
649-
function testPublicBorrow_failsGivenExceedsBorrowableQuota() public {
650-
// Given: a user has issuance tokens
651-
address user1 = makeAddr("user1");
652-
address user2 = makeAddr("user2");
653-
uint borrowAmount = 500 ether;
654-
655-
// Calculate how much issuance tokens will be needed
656-
uint requiredIssuanceTokens = lendingFacility
657-
.exposed_calculateRequiredIssuanceTokens(borrowAmount);
658-
// Add a larger buffer to account for rounding precision
659-
uint issuanceTokensWithBuffer = requiredIssuanceTokens + 10 ether;
660-
issuanceToken.mint(user1, issuanceTokensWithBuffer);
661-
issuanceToken.mint(user2, issuanceTokensWithBuffer);
662-
663-
lendingFacility.setBorrowableQuota(1000); // set 10% as borrow capacioty for testing purposes
664-
665-
//User 1 borrows
666-
vm.startPrank(user1);
667-
issuanceToken.approve(
668-
address(lendingFacility), issuanceTokensWithBuffer
669-
);
670-
lendingFacility.borrow(borrowAmount);
671-
vm.stopPrank();
672-
673-
//User 2 borrows
674-
vm.startPrank(user2);
675-
issuanceToken.approve(
676-
address(lendingFacility), issuanceTokensWithBuffer
677-
);
678-
vm.expectRevert(
679-
ILM_PC_Lending_Facility_v1
680-
.Module__LM_PC_Lending_Facility_BorrowableQuotaExceeded
681-
.selector
682-
);
683-
lendingFacility.borrow(100 ether);
684-
vm.stopPrank();
685-
}
686-
687643
/* Test: Function borrow()
688644
├── Given a user has issuance tokens
689645
├── And the user has sufficient borrowing power

0 commit comments

Comments
 (0)