@rev-net/core-v6 0.0.40 → 0.0.42

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/src/REVLoans.sol CHANGED
@@ -79,20 +79,18 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
79
79
  // ------------------------- public constants ------------------------ //
80
80
  //*********************************************************************//
81
81
 
82
- /// @dev After the prepaid duration, the loan will cost more to pay off. After 10 years, the loan
83
- /// collateral cannot be recouped. This means paying 50% of the loan amount upfront will pay for having access to
84
- /// the remaining 50% for 10 years,
85
- /// whereas paying 0% of the loan upfront will cost 100% of the loan amount to be paid off after 10 years. After 10
86
- /// years with repayment, both loans cost 100% and are liquidated.
82
+ /// @notice The duration after which an unrepaid loan expires and its collateral is permanently lost (10 years).
83
+ /// @dev After the prepaid duration, the loan will cost more to pay off. Paying 50% upfront covers access to the
84
+ /// remaining 50% for 10 years. Paying 0% upfront costs 100% after 10 years. Both loans liquidate at 10 years.
87
85
  uint256 public constant override LOAN_LIQUIDATION_DURATION = 3650 days;
88
86
 
89
- /// @dev The maximum amount of a loan that can be prepaid at the time of borrowing, in terms of JBConstants.MAX_FEE.
87
+ /// @notice The maximum fee percent that can be prepaid when borrowing (50%), in terms of JBConstants.MAX_FEE.
90
88
  uint256 public constant override MAX_PREPAID_FEE_PERCENT = 500;
91
89
 
92
- /// @dev A fee of 1% is charged by the $REV revnet.
90
+ /// @notice The fee percent charged by the $REV revnet on each loan (1%), in terms of JBConstants.MAX_FEE.
93
91
  uint256 public constant override REV_PREPAID_FEE_PERCENT = 10; // 1%
94
92
 
95
- /// @dev A fee of 2.5% is charged by the loan's source upfront.
93
+ /// @notice The minimum fee percent that must be prepaid when borrowing (2.5%), in terms of JBConstants.MAX_FEE.
96
94
  uint256 public constant override MIN_PREPAID_FEE_PERCENT = 25; // 2.5%
97
95
 
98
96
  //*********************************************************************//
@@ -107,7 +105,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
107
105
  // --------------- public immutable stored properties ---------------- //
108
106
  //*********************************************************************//
109
107
 
110
- /// @notice The permit2 utility.
108
+ /// @notice The Permit2 contract used for token approvals and transfers.
111
109
  IPermit2 public immutable override PERMIT2;
112
110
 
113
111
  /// @notice The controller of revnets that use this loans contract.
@@ -131,9 +129,9 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
131
129
 
132
130
  /// @notice An indication if a revnet currently has outstanding loans from the specified terminal in the specified
133
131
  /// token.
134
- /// @custom:param revnetId The ID of the revnet issuing the loan.
135
- /// @custom:param terminal The terminal that the loan is issued from.
136
- /// @custom:param token The token being loaned.
132
+ /// @custom:param revnetId The ID of the revnet to check.
133
+ /// @custom:param terminal The terminal to check.
134
+ /// @custom:param token The token to check.
137
135
  mapping(uint256 revnetId => mapping(IJBPayoutTerminal terminal => mapping(address token => bool)))
138
136
  public
139
137
  override isLoanSourceOf;
@@ -142,22 +140,22 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
142
140
  /// @dev This counter only increments (on borrow, repay-with-new-loan, and reallocation) and never decrements.
143
141
  /// It does NOT represent the number of currently active loans. Repaid and liquidated loans leave permanent gaps
144
142
  /// in the ID sequence. Integrators should not use this to count active loans.
145
- /// @custom:param revnetId The ID of the revnet to get the cumulative loan count from.
143
+ /// @custom:param revnetId The ID of the revnet to check.
146
144
  mapping(uint256 revnetId => uint256) public override totalLoansBorrowedFor;
147
145
 
148
146
  /// @notice The contract resolving each project ID to its ERC721 URI.
149
147
  IJBTokenUriResolver public override tokenUriResolver;
150
148
 
151
149
  /// @notice The total amount loaned out by a revnet from a specified terminal in a specified token.
152
- /// @custom:param revnetId The ID of the revnet issuing the loan.
153
- /// @custom:param terminal The terminal that the loan is issued from.
154
- /// @custom:param token The token being loaned.
150
+ /// @custom:param revnetId The ID of the revnet to check.
151
+ /// @custom:param terminal The terminal to check.
152
+ /// @custom:param token The token to check.
155
153
  mapping(uint256 revnetId => mapping(IJBPayoutTerminal terminal => mapping(address token => uint256)))
156
154
  public
157
155
  override totalBorrowedFrom;
158
156
 
159
157
  /// @notice The total amount of collateral supporting a revnet's loans.
160
- /// @custom:param revnetId The ID of the revnet issuing the loan.
158
+ /// @custom:param revnetId The ID of the revnet to check.
161
159
  mapping(uint256 revnetId => uint256) public override totalCollateralOf;
162
160
 
163
161
  //*********************************************************************//
@@ -169,7 +167,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
169
167
  /// borrowing, but are never removed. The `isLoanSourceOf` mapping tracks whether a source has been registered.
170
168
  /// Since the number of distinct (terminal, token) pairs per revnet is practically bounded (typically < 10),
171
169
  /// the gas cost of iterating this array in `loanSourcesOf` remains manageable.
172
- /// @custom:member revnetId The ID of the revnet issuing the loan.
170
+ /// @custom:member revnetId The ID of the revnet to look up.
173
171
  mapping(uint256 revnetId => REVLoanSource[]) internal _loanSourcesOf;
174
172
 
175
173
  /// @notice The loans.
@@ -212,10 +210,10 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
212
210
  //*********************************************************************//
213
211
 
214
212
  /// @notice The amount that can be borrowed from a revnet.
215
- /// @param revnetId The ID of the revnet to check for borrowable assets from.
216
- /// @param collateralCount The amount of collateral used to secure the loan.
217
- /// @param decimals The decimals the resulting fixed point value will include.
218
- /// @param currency The currency that the resulting amount should be in terms of.
213
+ /// @param revnetId The ID of the revnet to borrow from.
214
+ /// @param collateralCount The amount of collateral to secure the loan with.
215
+ /// @param decimals The decimals to use for the resulting fixed point value.
216
+ /// @param currency The currency to denominate the resulting amount in.
219
217
  /// @return borrowableAmount The amount that can be borrowed from the revnet.
220
218
  function borrowableAmountFrom(
221
219
  uint256 revnetId,
@@ -243,8 +241,8 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
243
241
  });
244
242
  }
245
243
 
246
- /// @notice Get a loan.
247
- /// @custom:member The ID of the loan.
244
+ /// @notice Get a loan's full details -- amount, collateral, creation time, prepaid fee, and source.
245
+ /// @param loanId The ID of the loan to look up.
248
246
  function loanOf(uint256 loanId) external view override returns (REVLoan memory) {
249
247
  return _loanOf[loanId];
250
248
  }
@@ -252,7 +250,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
252
250
  /// @notice The sources of each revnet's loan.
253
251
  /// @dev This array only grows -- sources are never removed. The number of distinct sources is practically bounded
254
252
  /// by the number of unique (terminal, token) pairs used for borrowing, which is typically small.
255
- /// @custom:member revnetId The ID of the revnet issuing the loan.
253
+ /// @param revnetId The ID of the revnet to look up.
256
254
  function loanSourcesOf(uint256 revnetId) external view override returns (REVLoanSource[] memory) {
257
255
  return _loanSourcesOf[revnetId];
258
256
  }
@@ -261,24 +259,24 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
261
259
  // -------------------------- public views --------------------------- //
262
260
  //*********************************************************************//
263
261
 
264
- /// @notice Determines the source fee amount for a loan being paid off a certain amount.
265
- /// @param loan The loan having its source fee amount determined.
266
- /// @param amount The amount being paid off.
262
+ /// @notice Determines the source fee amount for a loan when paying off a certain amount.
263
+ /// @param loan The loan to determine the source fee for.
264
+ /// @param amount The amount to pay off.
267
265
  /// @return sourceFeeAmount The source fee amount for the loan.
268
266
  function determineSourceFeeAmount(REVLoan memory loan, uint256 amount) public view returns (uint256) {
269
267
  return _determineSourceFeeAmount({loan: loan, amount: amount});
270
268
  }
271
269
 
272
- /// @notice The revnet ID for the loan with the provided loan ID.
273
- /// @param loanId The loan ID of the loan to get the revnet ID of.
270
+ /// @notice The revnet ID for a given loan ID.
271
+ /// @param loanId The loan ID to look up.
274
272
  /// @return The ID of the revnet.
275
273
  function revnetIdOfLoanWith(uint256 loanId) public pure override returns (uint256) {
276
274
  return loanId / _ONE_TRILLION;
277
275
  }
278
276
 
279
277
  /// @notice Returns the URI where the ERC-721 standard JSON of a loan is hosted.
280
- /// @param loanId The ID of the loan to get a URI of.
281
- /// @return The token URI to use for the provided `loanId`.
278
+ /// @param loanId The ID of the loan to get the URI for.
279
+ /// @return The token URI for the provided `loanId`.
282
280
  function tokenURI(uint256 loanId) public view override returns (string memory) {
283
281
  // Keep a reference to the resolver.
284
282
  IJBTokenUriResolver resolver = tokenUriResolver;
@@ -295,7 +293,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
295
293
  //*********************************************************************//
296
294
 
297
295
  /// @notice Checks this contract's balance of a specific token.
298
- /// @param token The address of the token to get this contract's balance of.
296
+ /// @param token The address of the token to check.
299
297
  /// @return This contract's balance.
300
298
  function _balanceOf(address token) internal view returns (uint256) {
301
299
  // If the `token` is native, get the native token balance.
@@ -325,11 +323,11 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
325
323
  /// effective collateralization margin. For example, a 20% `cashOutTaxRate` means borrowers can only extract ~80%
326
324
  /// of their pro-rata surplus, providing a ~20% buffer against collateral depreciation before liquidation.
327
325
  /// A `cashOutTaxRate` of 0 means the full pro-rata amount is borrowable (true 100% LTV with no margin).
328
- /// @param revnetId The ID of the revnet to check for borrowable assets from.
329
- /// @param collateralCount The amount of collateral that the loan will be collateralized with.
330
- /// @param decimals The decimals the resulting fixed point value will include.
331
- /// @param currency The currency that the resulting amount should be in terms of.
332
- /// @param terminals The terminals that the funds are being borrowed from.
326
+ /// @param revnetId The ID of the revnet to borrow from.
327
+ /// @param collateralCount The amount of collateral to secure the loan with.
328
+ /// @param decimals The decimals to use for the resulting fixed point value.
329
+ /// @param currency The currency to denominate the resulting amount in.
330
+ /// @param terminals The terminals to borrow from.
333
331
  /// @param currentStage The pre-fetched current ruleset.
334
332
  /// @return borrowableAmount The amount that can be borrowed from the revnet.
335
333
  function _borrowableAmountFrom(
@@ -386,11 +384,11 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
386
384
  }
387
385
 
388
386
  /// @notice The amount of the loan that should be borrowed for the given collateral amount.
389
- /// @param loan The loan having its borrow amount determined.
390
- /// @param revnetId The ID of the revnet to check for borrowable assets from.
391
- /// @param collateralCount The amount of collateral that the loan will be collateralized with.
387
+ /// @param loan The loan to determine the borrow amount for.
388
+ /// @param revnetId The ID of the revnet to borrow from.
389
+ /// @param collateralCount The amount of collateral to secure the loan with.
392
390
  /// @param currentRuleset The pre-fetched current ruleset.
393
- /// @return borrowAmount The amount of the loan that should be borrowed.
391
+ /// @return borrowAmount The amount that should be borrowed.
394
392
  function _borrowAmountFrom(
395
393
  REVLoan storage loan,
396
394
  uint256 revnetId,
@@ -449,9 +447,9 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
449
447
  (currentRuleset,) = CONTROLLER.currentRulesetOf(revnetId);
450
448
  }
451
449
 
452
- /// @notice Determines the source fee amount for a loan being paid off a certain amount.
453
- /// @param loan The loan having its source fee amount determined.
454
- /// @param amount The amount being paid off.
450
+ /// @notice Determines the source fee amount for a loan when paying off a certain amount.
451
+ /// @param loan The loan to determine the source fee for.
452
+ /// @param amount The amount to pay off.
455
453
  /// @return The source fee amount for the loan.
456
454
  function _determineSourceFeeAmount(REVLoan memory loan, uint256 amount) internal view returns (uint256) {
457
455
  // Keep a reference to the time since the loan was created.
@@ -486,12 +484,12 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
486
484
  return mulDiv({x: fullSourceFeeAmount, y: amount, denominator: loan.amount});
487
485
  }
488
486
 
489
- /// @notice Generate a ID for a loan given a revnet ID and a loan number within that revnet.
487
+ /// @notice Generate an ID for a loan given a revnet ID and a loan number within that revnet.
490
488
  /// @dev The multiplication and addition can theoretically overflow a uint256 if revnetId or loanNumber are
491
489
  /// astronomically large. In practice this is infeasible — it would require 2^256 loans or project IDs, far
492
490
  /// beyond any realistic usage. No overflow check is needed.
493
491
  /// @param revnetId The ID of the revnet to generate a loan ID for.
494
- /// @param loanNumber The loan number of the loan within the revnet.
492
+ /// @param loanNumber The loan number within the revnet.
495
493
  /// @return The token ID of the 721.
496
494
  function _generateLoanId(uint256 revnetId, uint256 loanNumber) internal pure returns (uint256) {
497
495
  return (revnetId * _ONE_TRILLION) + loanNumber;
@@ -522,9 +520,9 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
522
520
  /// arithmetic errors. For cross-currency sources, the normalized amount is then converted via the price feed.
523
521
  /// @dev Inverse price feeds may truncate to zero at low decimal counts (e.g. a feed returning 1e21 at 6 decimals
524
522
  /// inverts to mulDiv(1e6, 1e6, 1e21) = 0). Sources with a zero price are skipped to prevent division-by-zero.
525
- /// @param revnetId The ID of the revnet to check for borrowed assets from.
526
- /// @param decimals The decimals the resulting fixed point value will include.
527
- /// @param currency The currency the resulting value will be in terms of.
523
+ /// @param revnetId The ID of the revnet to check.
524
+ /// @param decimals The decimals to use for the resulting fixed point value.
525
+ /// @param currency The currency to denominate the resulting value in.
528
526
  /// @return borrowedAmount The total amount borrowed.
529
527
  function _totalBorrowedFrom(
530
528
  uint256 revnetId,
@@ -601,16 +599,15 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
601
599
  /// lost and cannot be recovered.
602
600
  /// @dev A delegated operator (with OPEN_LOAN permission) can set `beneficiary` to any address, directing borrowed
603
601
  /// funds away from the holder. Holders should only grant OPEN_LOAN to fully trusted operators.
604
- /// @param revnetId The ID of the revnet being borrowed from.
605
- /// @param source The source of the loan being borrowed.
606
- /// @param minBorrowAmount The minimum amount being borrowed, denominated in the token of the source's accounting
602
+ /// @param revnetId The ID of the revnet to borrow from.
603
+ /// @param source The source of the loan (terminal and token).
604
+ /// @param minBorrowAmount The minimum amount to borrow, denominated in the token of the source's accounting
607
605
  /// context.
608
606
  /// @param collateralCount The amount of tokens to use as collateral for the loan.
609
- /// @param beneficiary The address that'll receive the borrowed funds and the tokens resulting from fee payments.
610
- /// @param prepaidFeePercent The fee percent that will be charged upfront from the revnet being borrowed from.
611
- /// Prepaying a fee is cheaper than paying later.
612
- /// @return loanId The ID of the loan created from borrowing.
613
- /// @return loan The loan created from borrowing.
607
+ /// @param beneficiary The address that will receive the borrowed funds and the tokens resulting from fee payments.
608
+ /// @param prepaidFeePercent The fee percent to charge upfront. Prepaying a fee is cheaper than paying later.
609
+ /// @return loanId The ID of the loan created.
610
+ /// @return loan The loan created.
614
611
  function borrowFrom(
615
612
  uint256 revnetId,
616
613
  REVLoanSource calldata source,
@@ -639,7 +636,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
639
636
  });
640
637
  }
641
638
 
642
- /// @notice Liquidates loans that have exceeded the 10-year liquidation duration.
639
+ /// @notice Liquidate loans that have exceeded the 10-year liquidation duration.
643
640
  /// @dev Liquidation permanently destroys the collateral backing expired loans. Since collateral tokens were burned
644
641
  /// at deposit time (not held in escrow), there is nothing to return upon liquidation -- the collateral count is
645
642
  /// simply removed from tracking. The borrower retains whatever funds they received from the loan, but the
@@ -650,8 +647,8 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
650
647
  /// @dev Since some loans may be reallocated or paid off, loans within startingLoanId and startingLoanId + count
651
648
  /// may be skipped, so choose these parameters carefully to avoid extra gas usage.
652
649
  /// @param revnetId The ID of the revnet to liquidate loans from.
653
- /// @param startingLoanId The ID of the loan to start iterating from.
654
- /// @param count The amount of loans iterate over since the last liquidated loan.
650
+ /// @param startingLoanId The loan number to start iterating from.
651
+ /// @param count The number of loans to iterate over.
655
652
  function liquidateExpiredLoansFrom(uint256 revnetId, uint256 startingLoanId, uint256 count) external override {
656
653
  // Prevent cross-revnet accounting corruption: loan numbers must stay within the revnet's ID namespace.
657
654
  if (startingLoanId + count > _ONE_TRILLION) revert REVLoans_LoanIdOverflow();
@@ -699,7 +696,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
699
696
  }
700
697
  }
701
698
 
702
- /// @notice Refinances a loan by transferring extra collateral from an existing loan to a new loan.
699
+ /// @notice Refinance a loan by transferring extra collateral from an existing loan to a new loan.
703
700
  /// @dev Useful if a loan's collateral has gone up in value since the loan was created.
704
701
  /// @dev Refinancing a loan will burn the original and create two new loans.
705
702
  /// @dev This function is intentionally not payable — it only moves existing collateral between loans and does
@@ -708,15 +705,15 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
708
705
  /// borrowed funds from the new loan away from the loan owner. Grant this permission only to trusted operators.
709
706
  /// @param loanId The ID of the loan to reallocate collateral from.
710
707
  /// @param collateralCountToTransfer The amount of collateral to transfer from the original loan.
711
- /// @param source The source of the loan to create.
712
- /// @param minBorrowAmount The minimum amount being borrowed, denominated in the token of the source's accounting
708
+ /// @param source The source of the new loan (terminal and token). Must match the existing loan's source.
709
+ /// @param minBorrowAmount The minimum amount to borrow, denominated in the token of the source's accounting
713
710
  /// context.
714
- /// @param collateralCountToAdd The amount of collateral to add to the loan.
715
- /// @param beneficiary The address that'll receive the borrowed funds and the tokens resulting from fee payments.
716
- /// @param prepaidFeePercent The fee percent that will be charged upfront from the revnet being borrowed from.
717
- /// @return reallocatedLoanId The ID of the loan being reallocated.
711
+ /// @param collateralCountToAdd The amount of collateral to add to the new loan from your balance.
712
+ /// @param beneficiary The address that will receive the borrowed funds and the tokens resulting from fee payments.
713
+ /// @param prepaidFeePercent The fee percent to charge upfront for the new loan.
714
+ /// @return reallocatedLoanId The ID of the reallocated (reduced) loan.
718
715
  /// @return newLoanId The ID of the new loan.
719
- /// @return reallocatedLoan The loan being reallocated.
716
+ /// @return reallocatedLoan The reallocated loan data.
720
717
  /// @return newLoan The new loan created from reallocating collateral.
721
718
  function reallocateCollateralFromLoan(
722
719
  uint256 loanId,
@@ -774,18 +771,17 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
774
771
  });
775
772
  }
776
773
 
777
- /// @notice Allows the owner of a loan to pay it back or receive returned collateral no longer necessary to support
778
- /// the loan.
774
+ /// @notice Repay a loan or return excess collateral no longer needed to support the loan.
779
775
  /// @dev A delegated operator (with REPAY_LOAN permission) can set `beneficiary` to any address, directing returned
780
776
  /// collateral tokens away from the loan owner. Grant this permission only to trusted operators.
781
- /// @param loanId The ID of the loan being adjusted.
782
- /// @param maxRepayBorrowAmount The maximum amount being paid off, denominated in the token of the source's
777
+ /// @param loanId The ID of the loan to repay.
778
+ /// @param maxRepayBorrowAmount The maximum amount to repay, denominated in the token of the source's
783
779
  /// accounting context.
784
- /// @param collateralCountToReturn The amount of collateral being returned from the loan.
785
- /// @param beneficiary The address receiving the returned collateral and any tokens resulting from paying fees.
786
- /// @param allowance An allowance to faciliate permit2 interactions.
787
- /// @return paidOffLoanId The ID of the loan after it's been paid off.
788
- /// @return paidOffloan The loan after it's been paid off.
780
+ /// @param collateralCountToReturn The amount of collateral to return from the loan.
781
+ /// @param beneficiary The address to receive the returned collateral and any tokens resulting from paying fees.
782
+ /// @param allowance An allowance to facilitate permit2 interactions.
783
+ /// @return paidOffLoanId The ID of the loan after repayment.
784
+ /// @return paidOffloan The loan after repayment.
789
785
  function repayLoan(
790
786
  uint256 loanId,
791
787
  uint256 maxRepayBorrowAmount,
@@ -891,7 +887,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
891
887
  }
892
888
  }
893
889
 
894
- /// @notice Sets the address of the resolver used to retrieve the tokenURI of loans.
890
+ /// @notice Set the address of the resolver used to retrieve the tokenURI of loans.
895
891
  /// @param resolver The address of the new resolver.
896
892
  function setTokenUriResolver(IJBTokenUriResolver resolver) external override onlyOwner {
897
893
  // Store the new resolver.
@@ -904,11 +900,11 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
904
900
  // --------------------- internal transactions ----------------------- //
905
901
  //*********************************************************************//
906
902
 
907
- /// @notice Accepts an incoming token.
908
- /// @param token The token being accepted.
909
- /// @param amount The number of tokens being accepted.
903
+ /// @notice Accept an incoming token.
904
+ /// @param token The token to accept.
905
+ /// @param amount The number of tokens to accept.
910
906
  /// @param allowance The permit2 context.
911
- /// @return amount The number of tokens which have been accepted.
907
+ /// @return amount The number of tokens accepted.
912
908
  function _acceptFundsFor(
913
909
  address token,
914
910
  uint256 amount,
@@ -954,11 +950,11 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
954
950
  return _balanceOf(token) - balanceBefore;
955
951
  }
956
952
 
957
- /// @notice Adds collateral to a loan by burning the collateral tokens permanently.
953
+ /// @notice Add collateral to a loan by burning the collateral tokens permanently.
958
954
  /// @dev The collateral tokens are burned via the controller, not held in escrow. They are only re-minted if the
959
955
  /// loan is repaid. If the loan expires and is liquidated, the burned collateral is permanently lost.
960
- /// @param revnetId The ID of the revnet the loan is being added in.
961
- /// @param amount The new amount of collateral being added to the loan.
956
+ /// @param revnetId The ID of the revnet to add collateral in.
957
+ /// @param amount The amount of collateral to add to the loan.
962
958
  function _addCollateralTo(uint256 revnetId, uint256 amount, address holder) internal {
963
959
  // Increment the total amount of collateral tokens.
964
960
  totalCollateralOf[revnetId] += amount;
@@ -968,12 +964,12 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
968
964
  }
969
965
 
970
966
  /// @notice Add a new amount to the loan that is greater than the previous amount.
971
- /// @param loan The loan being added to.
972
- /// @param revnetId The ID of the revnet the loan is being added in.
973
- /// @param addedBorrowAmount The amount being added to the loan, denominated in the token of the source's
967
+ /// @param loan The loan to add to.
968
+ /// @param revnetId The ID of the revnet the loan is in.
969
+ /// @param addedBorrowAmount The amount to add to the loan, denominated in the token of the source's
974
970
  /// accounting context.
975
- /// @param sourceFeeAmount The amount of the fee being taken from the revnet acting as the source of the loan.
976
- /// @param beneficiary The address receiving the returned collateral and any tokens resulting from paying fees.
971
+ /// @param sourceFeeAmount The fee amount taken from the revnet acting as the source of the loan.
972
+ /// @param beneficiary The address to receive the borrowed funds and any tokens resulting from paying fees.
977
973
  function _addTo(
978
974
  REVLoan memory loan,
979
975
  uint256 revnetId,
@@ -1050,21 +1046,20 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1050
1046
  });
1051
1047
  }
1052
1048
 
1053
- /// @notice Allows the owner of a loan to pay it back, add more, or receive returned collateral no longer necessary
1054
- /// to support the loan.
1049
+ /// @notice Adjust a loan -- pay it back, add more, or return excess collateral.
1055
1050
  /// @dev CEI ordering note: `totalCollateralOf` is not incremented until `_addCollateralTo` executes,
1056
1051
  /// which happens after the external calls in `_addTo` (useAllowanceOf, fee payment, transfer). A reentrant
1057
1052
  /// `borrowFrom` during those calls would see a lower `totalCollateralOf`, potentially passing collateral
1058
1053
  /// checks that should fail. Practically infeasible — requires an adversarial pay hook on the revnet's own
1059
1054
  /// terminal that calls back into `borrowFrom`, which is not a realistic deployment configuration.
1060
- /// @param loan The loan being adjusted.
1061
- /// @param revnetId The ID of the revnet the loan is being adjusted in.
1055
+ /// @param loan The loan to adjust.
1056
+ /// @param revnetId The ID of the revnet the loan is in.
1062
1057
  /// @param newBorrowAmount The new amount of the loan, denominated in the token of the source's accounting
1063
1058
  /// context.
1064
- /// @param newCollateralCount The new amount of collateral backing the loan.
1065
- /// @param sourceFeeAmount The amount of the fee being taken from the revnet acting as the source of the loan.
1066
- /// @param beneficiary The address receiving the returned collateral and any tokens resulting from paying fees.
1067
- /// @param holder The address whose tokens are used as collateral (burned).
1059
+ /// @param newCollateralCount The new amount of collateral to back the loan with.
1060
+ /// @param sourceFeeAmount The fee amount taken from the revnet acting as the source of the loan.
1061
+ /// @param beneficiary The address to receive the returned collateral and any tokens resulting from paying fees.
1062
+ /// @param holder The address whose tokens to use as collateral (burned).
1068
1063
  function _adjust(
1069
1064
  REVLoan storage loan,
1070
1065
  uint256 revnetId,
@@ -1139,12 +1134,12 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1139
1134
  }
1140
1135
  }
1141
1136
 
1142
- /// @notice Logic to be triggered before transferring tokens from this contract.
1143
- /// @param to The address the transfer is going to.
1144
- /// @param token The token being transferred.
1145
- /// @param amount The number of tokens being transferred, as a fixed point number with the same number of decimals
1137
+ /// @notice Logic to trigger before transferring tokens from this contract.
1138
+ /// @param to The address to transfer to.
1139
+ /// @param token The token to transfer.
1140
+ /// @param amount The number of tokens to transfer, as a fixed point number with the same number of decimals
1146
1141
  /// as the token specifies.
1147
- /// @return payValue The value to attach to the transaction being sent.
1142
+ /// @return payValue The value to attach to the transaction.
1148
1143
  function _beforeTransferTo(address to, address token, uint256 amount) internal returns (uint256) {
1149
1144
  // If the token is the native token, no allowance needed.
1150
1145
  if (token == JBConstants.NATIVE_TOKEN) return amount;
@@ -1152,9 +1147,9 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1152
1147
  return 0;
1153
1148
  }
1154
1149
 
1155
- /// @notice Clears any token allowance granted by `_beforeTransferTo`.
1150
+ /// @notice Clear any token allowance granted by `_beforeTransferTo`.
1156
1151
  /// @param to The address that was granted the allowance.
1157
- /// @param token The token whose allowance should be cleared.
1152
+ /// @param token The token whose allowance to clear.
1158
1153
  function _afterTransferTo(address to, address token) internal {
1159
1154
  if (token == JBConstants.NATIVE_TOKEN) return;
1160
1155
  IERC20(token).forceApprove({spender: to, value: 0});
@@ -1163,15 +1158,15 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1163
1158
  /// @notice Internal implementation of loan creation, without the OPEN_LOAN permission check.
1164
1159
  /// @dev Called by `borrowFrom` (after its own permission check) and by `reallocateCollateralFromLoan`
1165
1160
  /// (which only requires REALLOCATE_LOAN permission).
1166
- /// @param revnetId The ID of the revnet being borrowed from.
1167
- /// @param source The source of the loan being borrowed.
1168
- /// @param minBorrowAmount The minimum amount being borrowed.
1161
+ /// @param revnetId The ID of the revnet to borrow from.
1162
+ /// @param source The source of the loan (terminal and token).
1163
+ /// @param minBorrowAmount The minimum amount to borrow.
1169
1164
  /// @param collateralCount The amount of tokens to use as collateral for the loan.
1170
- /// @param beneficiary The address that'll receive the borrowed funds and the tokens resulting from fee payments.
1171
- /// @param prepaidFeePercent The fee percent that will be charged upfront.
1172
- /// @param holder The address whose tokens are used as collateral and who receives the loan NFT.
1173
- /// @return loanId The ID of the loan created from borrowing.
1174
- /// @return loan The loan created from borrowing.
1165
+ /// @param beneficiary The address that will receive the borrowed funds and fee payment tokens.
1166
+ /// @param prepaidFeePercent The fee percent to charge upfront.
1167
+ /// @param holder The address whose tokens to use as collateral and who receives the loan NFT.
1168
+ /// @return loanId The ID of the loan created.
1169
+ /// @return loan The loan created.
1175
1170
  function _borrowFrom(
1176
1171
  uint256 revnetId,
1177
1172
  REVLoanSource calldata source,
@@ -1275,11 +1270,11 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1275
1270
  return (loanId, loan);
1276
1271
  }
1277
1272
 
1278
- /// @notice Reallocates collateral from a loan by making a new loan based on the original, with reduced collateral.
1273
+ /// @notice Reallocate collateral from a loan by making a new loan based on the original, with reduced collateral.
1279
1274
  /// @param loanId The ID of the loan to reallocate collateral from.
1280
1275
  /// @param revnetId The ID of the revnet the loan is from.
1281
1276
  /// @param collateralCountToRemove The amount of collateral to remove from the loan.
1282
- /// @return reallocatedLoanId The ID of the loan.
1277
+ /// @return reallocatedLoanId The ID of the reallocated loan.
1283
1278
  /// @return reallocatedLoan The reallocated loan.
1284
1279
  function _reallocateCollateralFromLoan(
1285
1280
  uint256 loanId,
@@ -1360,10 +1355,10 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1360
1355
  });
1361
1356
  }
1362
1357
 
1363
- /// @notice Pays off a loan.
1364
- /// @param loan The loan being paid off.
1365
- /// @param revnetId The ID of the revnet the loan is being paid off in.
1366
- /// @param repaidBorrowAmount The amount being paid off, denominated in the token of the source's accounting
1358
+ /// @notice Pay off a loan.
1359
+ /// @param loan The loan to pay off.
1360
+ /// @param revnetId The ID of the revnet the loan is in.
1361
+ /// @param repaidBorrowAmount The amount to pay off, denominated in the token of the source's accounting
1367
1362
  /// context.
1368
1363
  function _removeFrom(REVLoan memory loan, uint256 revnetId, uint256 repaidBorrowAmount) internal {
1369
1364
  // Decrement the total amount of a token being loaned out by the revnet from its terminal.
@@ -1388,14 +1383,13 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1388
1383
  _afterTransferTo({to: address(loan.source.terminal), token: loan.source.token});
1389
1384
  }
1390
1385
 
1391
- /// @notice Pays down a loan.
1392
- /// @param loanId The ID of the loan being paid down.
1393
- /// @param loan The loan being paid down.
1394
- /// @param repayBorrowAmount The amount being paid down from the loan, denominated in the token of the source's
1395
- /// accounting context.
1396
- /// @param sourceFeeAmount The amount of the fee being taken from the revnet acting as the source of the loan.
1397
- /// @param collateralCountToReturn The amount of collateral being returned that the loan no longer requires.
1398
- /// @param beneficiary The address receiving the returned collateral and any tokens resulting from paying fees.
1386
+ /// @notice Pay down a loan.
1387
+ /// @param loanId The ID of the loan to pay down.
1388
+ /// @param loan The loan to pay down.
1389
+ /// @param repayBorrowAmount The amount to pay down, denominated in the token of the source's accounting context.
1390
+ /// @param sourceFeeAmount The fee amount taken from the revnet acting as the source of the loan.
1391
+ /// @param collateralCountToReturn The amount of collateral to return that the loan no longer requires.
1392
+ /// @param beneficiary The address to receive the returned collateral and any tokens resulting from paying fees.
1399
1393
  /// @param loanOwner The owner of the loan NFT (receives replacement loan if partial repay).
1400
1394
  // slither-disable-next-line reentrancy-eth,reentrancy-events
1401
1395
  function _repayLoan(
@@ -1505,10 +1499,10 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1505
1499
  }
1506
1500
  }
1507
1501
 
1508
- /// @notice Returns collateral from a loan.
1509
- /// @param revnetId The ID of the revnet the loan is being returned in.
1510
- /// @param collateralCount The amount of collateral being returned from the loan.
1511
- /// @param beneficiary The address receiving the returned collateral.
1502
+ /// @notice Return collateral from a loan.
1503
+ /// @param revnetId The ID of the revnet the loan is in.
1504
+ /// @param collateralCount The amount of collateral to return from the loan.
1505
+ /// @param beneficiary The address to receive the returned collateral.
1512
1506
  function _returnCollateralFrom(uint256 revnetId, uint256 collateralCount, address payable beneficiary) internal {
1513
1507
  // Decrement the total amount of collateral tokens.
1514
1508
  totalCollateralOf[revnetId] -= collateralCount;
@@ -1524,10 +1518,10 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1524
1518
  });
1525
1519
  }
1526
1520
 
1527
- /// @notice Transfers tokens.
1521
+ /// @notice Transfer tokens.
1528
1522
  /// @param from The address to transfer tokens from.
1529
1523
  /// @param to The address to transfer tokens to.
1530
- /// @param token The address of the token being transfered.
1524
+ /// @param token The address of the token to transfer.
1531
1525
  /// @param amount The amount of tokens to transfer, as a fixed point number with the same number of decimals as the
1532
1526
  /// token.
1533
1527
  function _transferFrom(address from, address payable to, address token, uint256 amount) internal virtual {
@@ -1552,13 +1546,13 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1552
1546
  PERMIT2.transferFrom({from: from, to: to, amount: uint160(amount), token: token});
1553
1547
  }
1554
1548
 
1555
- /// @notice Attempts to pay a fee to a terminal. On failure, cleans up the ERC-20 allowance and returns false.
1549
+ /// @notice Attempt to pay a fee to a terminal. On failure, cleans up the ERC-20 allowance and returns false.
1556
1550
  /// @param terminal The terminal to pay the fee to.
1557
- /// @param projectId The project receiving the fee.
1558
- /// @param token The token being used to pay the fee.
1551
+ /// @param projectId The project to pay the fee to.
1552
+ /// @param token The token to pay the fee with.
1559
1553
  /// @param amount The fee amount.
1560
1554
  /// @param beneficiary The address to credit for the fee payment.
1561
- /// @param metadataProjectId The project ID encoded in the payment metadata.
1555
+ /// @param metadataProjectId The project ID to encode in the payment metadata.
1562
1556
  /// @return success Whether the fee was successfully paid.
1563
1557
  function _tryPayFee(
1564
1558
  IJBTerminal terminal,