@bananapus/distributor-v6 0.0.35 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/distributor-v6",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,12 +24,12 @@
24
24
  "deploy:testnets": "source ./.env && npx sphinx propose ./script/Deploy.s.sol --networks testnets"
25
25
  },
26
26
  "dependencies": {
27
- "@bananapus/721-hook-v6": "^0.0.63",
28
- "@bananapus/core-v6": "^0.0.72",
29
- "@bananapus/permission-ids-v6": "^0.0.27",
27
+ "@bananapus/721-hook-v6": "^0.0.65",
28
+ "@bananapus/core-v6": "^0.0.78",
29
+ "@bananapus/permission-ids-v6": "^0.0.28",
30
30
  "@openzeppelin/contracts": "5.6.1",
31
31
  "@prb/math": "4.1.1",
32
- "@rev-net/core-v6": "^0.0.75"
32
+ "@rev-net/core-v6": "^0.0.84"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@sphinx-labs/plugins": "0.33.3"
@@ -507,15 +507,18 @@ abstract contract JBDistributor is IJBDistributor {
507
507
  // Measure any returned project tokens while excluding any source-token payment effects.
508
508
  uint256 rewardBalanceBefore = vestingLoan.token.balanceOf(address(this));
509
509
 
510
- // Repay through this distributor because it owns the loan NFT and must receive the returned collateral.
511
- paidOffLoanId = _repayLoanSource({
510
+ // Repay through this distributor because it owns the loan NFT and must receive the returned collateral. Any
511
+ // native overpayment is reported back so it can be refunded only after this loan's state is fully settled.
512
+ uint256 nativeRefundAmount;
513
+ (paidOffLoanId, nativeRefundAmount) = _repayLoanSource({
512
514
  loanId: loanId,
513
515
  loan: loan,
514
516
  repayBorrowAmount: repayBorrowAmount,
515
517
  collateralCount: vestingLoan.collateralCount
516
518
  });
517
519
 
518
- // Restore the collateral to inventory while preserving the original vesting data untouched.
520
+ // Restore the collateral to inventory while preserving the original vesting data untouched. This deletes the
521
+ // loan record and decrements the loaned-vesting inventory before any value leaves the contract.
519
522
  _restoreVestingCollateral({
520
523
  loanId: loanId,
521
524
  paidOffLoanId: paidOffLoanId,
@@ -523,6 +526,15 @@ abstract contract JBDistributor is IJBDistributor {
523
526
  rewardBalanceBefore: rewardBalanceBefore,
524
527
  repayBorrowAmount: repayBorrowAmount
525
528
  });
529
+
530
+ // Return any native overpayment last, following checks-effects-interactions. The loan is already settled, so a
531
+ // re-entrant call during this transfer cannot observe a half-settled loan.
532
+ if (nativeRefundAmount != 0) {
533
+ (bool success,) = msg.sender.call{value: nativeRefundAmount}("");
534
+ if (!success) {
535
+ revert JBDistributor_NativeTransferFailed({beneficiary: msg.sender, amount: nativeRefundAmount});
536
+ }
537
+ }
526
538
  }
527
539
 
528
540
  /// @notice Write off a distributor-held Revnet loan after Revnet liquidation permanently destroys its collateral.
@@ -857,11 +869,14 @@ abstract contract JBDistributor is IJBDistributor {
857
869
  }
858
870
 
859
871
  /// @notice Repay a Revnet loan with the source token it borrowed.
872
+ /// @dev Any native overpayment is reported via `nativeRefundAmount` instead of being refunded here, so the caller
873
+ /// can settle the loan's state before returning the overpayment (checks-effects-interactions).
860
874
  /// @param loanId The Revnet loan NFT ID to repay.
861
875
  /// @param loan The Revnet loan data.
862
876
  /// @param repayBorrowAmount The amount of source token needed to repay the loan.
863
877
  /// @param collateralCount The amount of collateral to return.
864
878
  /// @return paidOffLoanId The paid-off loan ID returned by Revnet loans.
879
+ /// @return nativeRefundAmount The native overpayment the caller must refund after settling the loan.
865
880
  function _repayLoanSource(
866
881
  uint256 loanId,
867
882
  REVLoan memory loan,
@@ -869,7 +884,7 @@ abstract contract JBDistributor is IJBDistributor {
869
884
  uint256 collateralCount
870
885
  )
871
886
  internal
872
- returns (uint256 paidOffLoanId)
887
+ returns (uint256 paidOffLoanId, uint256 nativeRefundAmount)
873
888
  {
874
889
  JBSingleAllowance memory allowance;
875
890
 
@@ -888,14 +903,8 @@ abstract contract JBDistributor is IJBDistributor {
888
903
  allowance: allowance
889
904
  });
890
905
 
891
- // Return any native overpayment to the caller.
892
- uint256 refundAmount = msg.value - repayBorrowAmount;
893
- if (refundAmount != 0) {
894
- (bool success,) = msg.sender.call{value: refundAmount}("");
895
- if (!success) {
896
- revert JBDistributor_NativeTransferFailed({beneficiary: msg.sender, amount: refundAmount});
897
- }
898
- }
906
+ // Report any native overpayment so the caller can refund it only after the loan's state is settled.
907
+ nativeRefundAmount = msg.value - repayBorrowAmount;
899
908
  } else {
900
909
  // ERC-20 repayments must not carry native ETH.
901
910
  if (msg.value != 0) {