@rev-net/core-v6 0.0.1

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.
Files changed (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/REVNET_SECURITY_CHECKLIST.md +164 -0
  4. package/SECURITY.md +68 -0
  5. package/SKILLS.md +166 -0
  6. package/deployments/revnet-core-v5/arbitrum/REVDeployer.json +2821 -0
  7. package/deployments/revnet-core-v5/arbitrum/REVLoans.json +2260 -0
  8. package/deployments/revnet-core-v5/arbitrum_sepolia/REVDeployer.json +2821 -0
  9. package/deployments/revnet-core-v5/arbitrum_sepolia/REVLoans.json +2260 -0
  10. package/deployments/revnet-core-v5/base/REVDeployer.json +2825 -0
  11. package/deployments/revnet-core-v5/base/REVLoans.json +2264 -0
  12. package/deployments/revnet-core-v5/base_sepolia/REVDeployer.json +2825 -0
  13. package/deployments/revnet-core-v5/base_sepolia/REVLoans.json +2264 -0
  14. package/deployments/revnet-core-v5/ethereum/REVDeployer.json +2825 -0
  15. package/deployments/revnet-core-v5/ethereum/REVLoans.json +2264 -0
  16. package/deployments/revnet-core-v5/optimism/REVDeployer.json +2821 -0
  17. package/deployments/revnet-core-v5/optimism/REVLoans.json +2260 -0
  18. package/deployments/revnet-core-v5/optimism_sepolia/REVDeployer.json +2825 -0
  19. package/deployments/revnet-core-v5/optimism_sepolia/REVLoans.json +2264 -0
  20. package/deployments/revnet-core-v5/sepolia/REVDeployer.json +2825 -0
  21. package/deployments/revnet-core-v5/sepolia/REVLoans.json +2264 -0
  22. package/docs/book.css +13 -0
  23. package/docs/book.toml +13 -0
  24. package/docs/solidity.min.js +74 -0
  25. package/docs/src/README.md +88 -0
  26. package/docs/src/SUMMARY.md +20 -0
  27. package/docs/src/src/README.md +7 -0
  28. package/docs/src/src/REVDeployer.sol/contract.REVDeployer.md +968 -0
  29. package/docs/src/src/REVLoans.sol/contract.REVLoans.md +1047 -0
  30. package/docs/src/src/interfaces/IREVDeployer.sol/interface.IREVDeployer.md +243 -0
  31. package/docs/src/src/interfaces/IREVLoans.sol/interface.IREVLoans.md +296 -0
  32. package/docs/src/src/interfaces/README.md +5 -0
  33. package/docs/src/src/structs/README.md +14 -0
  34. package/docs/src/src/structs/REVAutoIssuance.sol/struct.REVAutoIssuance.md +19 -0
  35. package/docs/src/src/structs/REVBuybackHookConfig.sol/struct.REVBuybackHookConfig.md +19 -0
  36. package/docs/src/src/structs/REVBuybackPoolConfig.sol/struct.REVBuybackPoolConfig.md +21 -0
  37. package/docs/src/src/structs/REVConfig.sol/struct.REVConfig.md +35 -0
  38. package/docs/src/src/structs/REVCroptopAllowedPost.sol/struct.REVCroptopAllowedPost.md +28 -0
  39. package/docs/src/src/structs/REVDeploy721TiersHookConfig.sol/struct.REVDeploy721TiersHookConfig.md +34 -0
  40. package/docs/src/src/structs/REVDescription.sol/struct.REVDescription.md +23 -0
  41. package/docs/src/src/structs/REVLoan.sol/struct.REVLoan.md +28 -0
  42. package/docs/src/src/structs/REVLoanSource.sol/struct.REVLoanSource.md +16 -0
  43. package/docs/src/src/structs/REVStageConfig.sol/struct.REVStageConfig.md +44 -0
  44. package/docs/src/src/structs/REVSuckerDeploymentConfig.sol/struct.REVSuckerDeploymentConfig.md +16 -0
  45. package/foundry.lock +11 -0
  46. package/foundry.toml +23 -0
  47. package/package.json +31 -0
  48. package/remappings.txt +1 -0
  49. package/script/Deploy.s.sol +350 -0
  50. package/script/helpers/RevnetCoreDeploymentLib.sol +72 -0
  51. package/slither-ci.config.json +10 -0
  52. package/sphinx.lock +507 -0
  53. package/src/REVDeployer.sol +1257 -0
  54. package/src/REVLoans.sol +1333 -0
  55. package/src/interfaces/IREVDeployer.sol +198 -0
  56. package/src/interfaces/IREVLoans.sol +241 -0
  57. package/src/structs/REVAutoIssuance.sol +11 -0
  58. package/src/structs/REVConfig.sol +17 -0
  59. package/src/structs/REVCroptopAllowedPost.sol +20 -0
  60. package/src/structs/REVDeploy721TiersHookConfig.sol +25 -0
  61. package/src/structs/REVDescription.sol +14 -0
  62. package/src/structs/REVLoan.sol +19 -0
  63. package/src/structs/REVLoanSource.sol +11 -0
  64. package/src/structs/REVStageConfig.sol +34 -0
  65. package/src/structs/REVSuckerDeploymentConfig.sol +11 -0
  66. package/test/REV.integrations.t.sol +420 -0
  67. package/test/REVAutoIssuanceFuzz.t.sol +276 -0
  68. package/test/REVDeployerAuditRegressions.t.sol +328 -0
  69. package/test/REVInvincibility.t.sol +1275 -0
  70. package/test/REVInvincibilityHandler.sol +357 -0
  71. package/test/REVLifecycle.t.sol +364 -0
  72. package/test/REVLoans.invariants.t.sol +642 -0
  73. package/test/REVLoansAttacks.t.sol +739 -0
  74. package/test/REVLoansAuditRegressions.t.sol +314 -0
  75. package/test/REVLoansFeeRecovery.t.sol +704 -0
  76. package/test/REVLoansSourced.t.sol +1732 -0
  77. package/test/REVLoansUnSourced.t.sol +331 -0
  78. package/test/TestPR09_ConversionDocumentation.t.sol +304 -0
  79. package/test/TestPR10_LiquidationBehavior.t.sol +340 -0
  80. package/test/TestPR11_LowFindings.t.sol +571 -0
  81. package/test/TestPR12_FlashLoanSurplus.t.sol +305 -0
  82. package/test/TestPR13_CrossSourceReallocation.t.sol +302 -0
  83. package/test/TestPR15_CashOutCallerValidation.t.sol +320 -0
  84. package/test/TestPR16_ZeroRepayment.t.sol +297 -0
  85. package/test/TestPR21_Uint112Overflow.t.sol +251 -0
  86. package/test/TestPR22_HookArrayOOB.t.sol +221 -0
  87. package/test/TestPR26_BurnHeldTokens.t.sol +331 -0
  88. package/test/TestPR27_CEIPattern.t.sol +448 -0
  89. package/test/TestPR29_SwapTerminalPermission.t.sol +206 -0
  90. package/test/TestPR32_MixedFixes.t.sol +529 -0
  91. package/test/helpers/MaliciousContracts.sol +233 -0
  92. package/test/mock/MockBuybackDataHook.sol +61 -0
@@ -0,0 +1,1047 @@
1
+ # REVLoans
2
+ [Git Source](https://github.com/rev-net/revnet-core-v5/blob/364afaae78a8f60af2b98252dc96af1c2e4760d3/src/REVLoans.sol)
3
+
4
+ **Inherits:**
5
+ ERC721, ERC2771Context, Ownable, [IREVLoans](/src/interfaces/IREVLoans.sol/interface.IREVLoans.md)
6
+
7
+ A contract for borrowing from revnets.
8
+
9
+ *Tokens used as collateral are burned, and reminted when the loan is paid off. This keeps the revnet's token
10
+ structure orderly.*
11
+
12
+ *The borrowable amount is the same as the cash out amount.*
13
+
14
+ *An upfront fee is taken when a loan is created. 2.5% is charged by the underlying protocol, 2.5% is charged
15
+ by the
16
+ revnet issuing the loan, and a variable amount charged by the revnet that receives the fees. This variable amount is
17
+ chosen by the borrower, the more paid upfront, the longer the prepaid duration. The loan can be repaid anytime
18
+ within the prepaid duration without additional fees.
19
+ After the prepaid duration, the loan will increasingly cost more to pay off. After 10 years, the loan collateral
20
+ cannot be
21
+ recouped.*
22
+
23
+ *The loaned amounts include the fees taken, meaning the amount paid back is the amount borrowed plus the fees.*
24
+
25
+
26
+ ## State Variables
27
+ ### LOAN_LIQUIDATION_DURATION
28
+ *After the prepaid duration, the loan will cost more to pay off. After 10 years, the loan
29
+ collateral cannot be recouped. This means paying 50% of the loan amount upfront will pay for having access to
30
+ the remaining 50% for 10 years,
31
+ whereas paying 0% of the loan upfront will cost 100% of the loan amount to be paid off after 10 years. After 10
32
+ years with repayment, both loans cost 100% and are liquidated.*
33
+
34
+
35
+ ```solidity
36
+ uint256 public constant override LOAN_LIQUIDATION_DURATION = 3650 days;
37
+ ```
38
+
39
+
40
+ ### MAX_PREPAID_FEE_PERCENT
41
+ *The maximum amount of a loan that can be prepaid at the time of borrowing, in terms of JBConstants.MAX_FEE.*
42
+
43
+
44
+ ```solidity
45
+ uint256 public constant override MAX_PREPAID_FEE_PERCENT = 500;
46
+ ```
47
+
48
+
49
+ ### REV_PREPAID_FEE_PERCENT
50
+ *A fee of 1% is charged by the $REV revnet.*
51
+
52
+
53
+ ```solidity
54
+ uint256 public constant override REV_PREPAID_FEE_PERCENT = 10;
55
+ ```
56
+
57
+
58
+ ### MIN_PREPAID_FEE_PERCENT
59
+ *A fee of 2.5% is charged by the loan's source upfront.*
60
+
61
+
62
+ ```solidity
63
+ uint256 public constant override MIN_PREPAID_FEE_PERCENT = 25;
64
+ ```
65
+
66
+
67
+ ### _ONE_TRILLION
68
+ Just a kind reminder to our readers.
69
+
70
+ *Used in loan token ID generation.*
71
+
72
+
73
+ ```solidity
74
+ uint256 private constant _ONE_TRILLION = 1_000_000_000_000;
75
+ ```
76
+
77
+
78
+ ### PERMIT2
79
+ The permit2 utility.
80
+
81
+
82
+ ```solidity
83
+ IPermit2 public immutable override PERMIT2;
84
+ ```
85
+
86
+
87
+ ### CONTROLLER
88
+ The controller of revnets that use this loans contract.
89
+
90
+
91
+ ```solidity
92
+ IJBController public immutable override CONTROLLER;
93
+ ```
94
+
95
+
96
+ ### REVNETS
97
+ Mints ERC-721s that represent project ownership and transfers.
98
+
99
+
100
+ ```solidity
101
+ IREVDeployer public immutable override REVNETS;
102
+ ```
103
+
104
+
105
+ ### DIRECTORY
106
+ The directory of terminals and controllers for revnets.
107
+
108
+
109
+ ```solidity
110
+ IJBDirectory public immutable override DIRECTORY;
111
+ ```
112
+
113
+
114
+ ### PRICES
115
+ A contract that stores prices for each revnet.
116
+
117
+
118
+ ```solidity
119
+ IJBPrices public immutable override PRICES;
120
+ ```
121
+
122
+
123
+ ### PROJECTS
124
+ Mints ERC-721s that represent revnet ownership and transfers.
125
+
126
+
127
+ ```solidity
128
+ IJBProjects public immutable override PROJECTS;
129
+ ```
130
+
131
+
132
+ ### REV_ID
133
+ The ID of the REV revnet that will receive the fees.
134
+
135
+
136
+ ```solidity
137
+ uint256 public immutable override REV_ID;
138
+ ```
139
+
140
+
141
+ ### isLoanSourceOf
142
+ An indication if a revnet currently has outstanding loans from the specified terminal in the specified
143
+ token.
144
+
145
+
146
+ ```solidity
147
+ mapping(uint256 revnetId => mapping(IJBPayoutTerminal terminal => mapping(address token => bool))) public override
148
+ isLoanSourceOf;
149
+ ```
150
+
151
+
152
+ ### numberOfLoansFor
153
+ The amount of loans that have been created.
154
+
155
+
156
+ ```solidity
157
+ mapping(uint256 revnetId => uint256) public override numberOfLoansFor;
158
+ ```
159
+
160
+
161
+ ### tokenUriResolver
162
+ The contract resolving each project ID to its ERC721 URI.
163
+
164
+
165
+ ```solidity
166
+ IJBTokenUriResolver public override tokenUriResolver;
167
+ ```
168
+
169
+
170
+ ### totalBorrowedFrom
171
+ The total amount loaned out by a revnet from a specified terminal in a specified token.
172
+
173
+
174
+ ```solidity
175
+ mapping(uint256 revnetId => mapping(IJBPayoutTerminal terminal => mapping(address token => uint256))) public override
176
+ totalBorrowedFrom;
177
+ ```
178
+
179
+
180
+ ### totalCollateralOf
181
+ The total amount of collateral supporting a revnet's loans.
182
+
183
+
184
+ ```solidity
185
+ mapping(uint256 revnetId => uint256) public override totalCollateralOf;
186
+ ```
187
+
188
+
189
+ ### _loanSourcesOf
190
+ The sources of each revnet's loan.
191
+
192
+ **Note:**
193
+ member: revnetId The ID of the revnet issuing the loan.
194
+
195
+
196
+ ```solidity
197
+ mapping(uint256 revnetId => REVLoanSource[]) internal _loanSourcesOf;
198
+ ```
199
+
200
+
201
+ ### _loanOf
202
+ The loans.
203
+
204
+ **Note:**
205
+ member: The ID of the loan.
206
+
207
+
208
+ ```solidity
209
+ mapping(uint256 loanId => REVLoan) internal _loanOf;
210
+ ```
211
+
212
+
213
+ ## Functions
214
+ ### constructor
215
+
216
+
217
+ ```solidity
218
+ constructor(
219
+ IREVDeployer revnets,
220
+ uint256 revId,
221
+ address owner,
222
+ IPermit2 permit2,
223
+ address trustedForwarder
224
+ )
225
+ ERC721("REV Loans", "$REVLOAN")
226
+ ERC2771Context(trustedForwarder)
227
+ Ownable(owner);
228
+ ```
229
+ **Parameters**
230
+
231
+ |Name|Type|Description|
232
+ |----|----|-----------|
233
+ |`revnets`|`IREVDeployer`|A contract from which revnets using this loans contract are deployed.|
234
+ |`revId`|`uint256`|The ID of the REV revnet that will receive the fees.|
235
+ |`owner`|`address`|The owner of the contract that can set the URI resolver.|
236
+ |`permit2`|`IPermit2`|A permit2 utility.|
237
+ |`trustedForwarder`|`address`|A trusted forwarder of transactions to this contract.|
238
+
239
+
240
+ ### borrowableAmountFrom
241
+
242
+ The amount that can be borrowed from a revnet.
243
+
244
+
245
+ ```solidity
246
+ function borrowableAmountFrom(
247
+ uint256 revnetId,
248
+ uint256 collateralCount,
249
+ uint256 decimals,
250
+ uint256 currency
251
+ )
252
+ external
253
+ view
254
+ returns (uint256);
255
+ ```
256
+ **Parameters**
257
+
258
+ |Name|Type|Description|
259
+ |----|----|-----------|
260
+ |`revnetId`|`uint256`|The ID of the revnet to check for borrowable assets from.|
261
+ |`collateralCount`|`uint256`|The amount of collateral used to secure the loan.|
262
+ |`decimals`|`uint256`|The decimals the resulting fixed point value will include.|
263
+ |`currency`|`uint256`|The currency that the resulting amount should be in terms of.|
264
+
265
+ **Returns**
266
+
267
+ |Name|Type|Description|
268
+ |----|----|-----------|
269
+ |`<none>`|`uint256`|borrowableAmount The amount that can be borrowed from the revnet.|
270
+
271
+
272
+ ### loanOf
273
+
274
+ Get a loan.
275
+
276
+ **Note:**
277
+ member: The ID of the loan.
278
+
279
+
280
+ ```solidity
281
+ function loanOf(uint256 loanId) external view override returns (REVLoan memory);
282
+ ```
283
+
284
+ ### loanSourcesOf
285
+
286
+ The sources of each revnet's loan.
287
+
288
+ **Note:**
289
+ member: revnetId The ID of the revnet issuing the loan.
290
+
291
+
292
+ ```solidity
293
+ function loanSourcesOf(uint256 revnetId) external view override returns (REVLoanSource[] memory);
294
+ ```
295
+
296
+ ### determineSourceFeeAmount
297
+
298
+ Determines the source fee amount for a loan being paid off a certain amount.
299
+
300
+
301
+ ```solidity
302
+ function determineSourceFeeAmount(REVLoan memory loan, uint256 amount) public view returns (uint256);
303
+ ```
304
+ **Parameters**
305
+
306
+ |Name|Type|Description|
307
+ |----|----|-----------|
308
+ |`loan`|`REVLoan`|The loan having its source fee amount determined.|
309
+ |`amount`|`uint256`|The amount being paid off.|
310
+
311
+ **Returns**
312
+
313
+ |Name|Type|Description|
314
+ |----|----|-----------|
315
+ |`<none>`|`uint256`|sourceFeeAmount The source fee amount for the loan.|
316
+
317
+
318
+ ### tokenURI
319
+
320
+ Returns the URI where the ERC-721 standard JSON of a loan is hosted.
321
+
322
+
323
+ ```solidity
324
+ function tokenURI(uint256 loanId) public view override returns (string memory);
325
+ ```
326
+ **Parameters**
327
+
328
+ |Name|Type|Description|
329
+ |----|----|-----------|
330
+ |`loanId`|`uint256`|The ID of the loan to get a URI of.|
331
+
332
+ **Returns**
333
+
334
+ |Name|Type|Description|
335
+ |----|----|-----------|
336
+ |`<none>`|`string`|The token URI to use for the provided `loanId`.|
337
+
338
+
339
+ ### revnetIdOfLoanWith
340
+
341
+ The revnet ID for the loan with the provided loan ID.
342
+
343
+
344
+ ```solidity
345
+ function revnetIdOfLoanWith(uint256 loanId) public pure override returns (uint256);
346
+ ```
347
+ **Parameters**
348
+
349
+ |Name|Type|Description|
350
+ |----|----|-----------|
351
+ |`loanId`|`uint256`|The loan ID of the loan to get the revent ID of.|
352
+
353
+ **Returns**
354
+
355
+ |Name|Type|Description|
356
+ |----|----|-----------|
357
+ |`<none>`|`uint256`|The ID of the revnet.|
358
+
359
+
360
+ ### _balanceOf
361
+
362
+ Checks this contract's balance of a specific token.
363
+
364
+
365
+ ```solidity
366
+ function _balanceOf(address token) internal view returns (uint256);
367
+ ```
368
+ **Parameters**
369
+
370
+ |Name|Type|Description|
371
+ |----|----|-----------|
372
+ |`token`|`address`|The address of the token to get this contract's balance of.|
373
+
374
+ **Returns**
375
+
376
+ |Name|Type|Description|
377
+ |----|----|-----------|
378
+ |`<none>`|`uint256`|This contract's balance.|
379
+
380
+
381
+ ### _borrowableAmountFrom
382
+
383
+ *The amount that can be borrowed from a revnet given a certain amount of collateral.*
384
+
385
+
386
+ ```solidity
387
+ function _borrowableAmountFrom(
388
+ uint256 revnetId,
389
+ uint256 collateralCount,
390
+ uint256 decimals,
391
+ uint256 currency,
392
+ IJBTerminal[] memory terminals
393
+ )
394
+ internal
395
+ view
396
+ returns (uint256);
397
+ ```
398
+ **Parameters**
399
+
400
+ |Name|Type|Description|
401
+ |----|----|-----------|
402
+ |`revnetId`|`uint256`|The ID of the revnet to check for borrowable assets from.|
403
+ |`collateralCount`|`uint256`|The amount of collateral that the loan will be collateralized with.|
404
+ |`decimals`|`uint256`|The decimals the resulting fixed point value will include.|
405
+ |`currency`|`uint256`|The currency that the resulting amount should be in terms of.|
406
+ |`terminals`|`IJBTerminal[]`|The terminals that the funds are being borrowed from.|
407
+
408
+ **Returns**
409
+
410
+ |Name|Type|Description|
411
+ |----|----|-----------|
412
+ |`<none>`|`uint256`|borrowableAmount The amount that can be borrowed from the revnet.|
413
+
414
+
415
+ ### _borrowAmountFrom
416
+
417
+ The amount of the loan that should be borrowed for the given collateral amount.
418
+
419
+
420
+ ```solidity
421
+ function _borrowAmountFrom(
422
+ REVLoan storage loan,
423
+ uint256 revnetId,
424
+ uint256 collateralCount
425
+ )
426
+ internal
427
+ view
428
+ returns (uint256);
429
+ ```
430
+ **Parameters**
431
+
432
+ |Name|Type|Description|
433
+ |----|----|-----------|
434
+ |`loan`|`REVLoan`|The loan having its borrow amount determined.|
435
+ |`revnetId`|`uint256`|The ID of the revnet to check for borrowable assets from.|
436
+ |`collateralCount`|`uint256`|The amount of collateral that the loan will be collateralized with.|
437
+
438
+ **Returns**
439
+
440
+ |Name|Type|Description|
441
+ |----|----|-----------|
442
+ |`<none>`|`uint256`|borrowAmount The amount of the loan that should be borrowed.|
443
+
444
+
445
+ ### _contextSuffixLength
446
+
447
+ *`ERC-2771` specifies the context as being a single address (20 bytes).*
448
+
449
+
450
+ ```solidity
451
+ function _contextSuffixLength() internal view override(ERC2771Context, Context) returns (uint256);
452
+ ```
453
+
454
+ ### _determineSourceFeeAmount
455
+
456
+ Determines the source fee amount for a loan being paid off a certain amount.
457
+
458
+
459
+ ```solidity
460
+ function _determineSourceFeeAmount(REVLoan memory loan, uint256 amount) internal view returns (uint256);
461
+ ```
462
+ **Parameters**
463
+
464
+ |Name|Type|Description|
465
+ |----|----|-----------|
466
+ |`loan`|`REVLoan`|The loan having its source fee amount determined.|
467
+ |`amount`|`uint256`|The amount being paid off.|
468
+
469
+ **Returns**
470
+
471
+ |Name|Type|Description|
472
+ |----|----|-----------|
473
+ |`<none>`|`uint256`|The source fee amount for the loan.|
474
+
475
+
476
+ ### _generateLoanId
477
+
478
+ Generate a ID for a loan given a revnet ID and a loan number within that revnet.
479
+
480
+
481
+ ```solidity
482
+ function _generateLoanId(uint256 revnetId, uint256 loanNumber) internal pure returns (uint256);
483
+ ```
484
+ **Parameters**
485
+
486
+ |Name|Type|Description|
487
+ |----|----|-----------|
488
+ |`revnetId`|`uint256`|The ID of the revnet to generate a loan ID for.|
489
+ |`loanNumber`|`uint256`|The loan number of the loan within the revnet.|
490
+
491
+ **Returns**
492
+
493
+ |Name|Type|Description|
494
+ |----|----|-----------|
495
+ |`<none>`|`uint256`|The token ID of the 721.|
496
+
497
+
498
+ ### _msgData
499
+
500
+ The calldata. Preferred to use over `msg.data`.
501
+
502
+
503
+ ```solidity
504
+ function _msgData() internal view override(ERC2771Context, Context) returns (bytes calldata);
505
+ ```
506
+ **Returns**
507
+
508
+ |Name|Type|Description|
509
+ |----|----|-----------|
510
+ |`<none>`|`bytes`|calldata The `msg.data` of this call.|
511
+
512
+
513
+ ### _msgSender
514
+
515
+ The message's sender. Preferred to use over `msg.sender`.
516
+
517
+
518
+ ```solidity
519
+ function _msgSender() internal view override(ERC2771Context, Context) returns (address sender);
520
+ ```
521
+ **Returns**
522
+
523
+ |Name|Type|Description|
524
+ |----|----|-----------|
525
+ |`sender`|`address`|The address which sent this call.|
526
+
527
+
528
+ ### _totalBorrowedFrom
529
+
530
+ The total borrowed amount from a revnet.
531
+
532
+
533
+ ```solidity
534
+ function _totalBorrowedFrom(
535
+ uint256 revnetId,
536
+ uint256 decimals,
537
+ uint256 currency
538
+ )
539
+ internal
540
+ view
541
+ returns (uint256 borrowedAmount);
542
+ ```
543
+ **Parameters**
544
+
545
+ |Name|Type|Description|
546
+ |----|----|-----------|
547
+ |`revnetId`|`uint256`|The ID of the revnet to check for borrowed assets from.|
548
+ |`decimals`|`uint256`|The decimals the resulting fixed point value will include.|
549
+ |`currency`|`uint256`|The currency the resulting value will be in terms of.|
550
+
551
+ **Returns**
552
+
553
+ |Name|Type|Description|
554
+ |----|----|-----------|
555
+ |`borrowedAmount`|`uint256`|The total amount borrowed.|
556
+
557
+
558
+ ### borrowFrom
559
+
560
+ Open a loan by borrowing from a revnet.
561
+
562
+
563
+ ```solidity
564
+ function borrowFrom(
565
+ uint256 revnetId,
566
+ REVLoanSource calldata source,
567
+ uint256 minBorrowAmount,
568
+ uint256 collateralCount,
569
+ address payable beneficiary,
570
+ uint256 prepaidFeePercent
571
+ )
572
+ public
573
+ override
574
+ returns (uint256 loanId, REVLoan memory);
575
+ ```
576
+ **Parameters**
577
+
578
+ |Name|Type|Description|
579
+ |----|----|-----------|
580
+ |`revnetId`|`uint256`|The ID of the revnet being borrowed from.|
581
+ |`source`|`REVLoanSource`|The source of the loan being borrowed.|
582
+ |`minBorrowAmount`|`uint256`|The minimum amount being borrowed, denominated in the token of the source's accounting context.|
583
+ |`collateralCount`|`uint256`|The amount of tokens to use as collateral for the loan.|
584
+ |`beneficiary`|`address payable`|The address that'll receive the borrowed funds and the tokens resulting from fee payments.|
585
+ |`prepaidFeePercent`|`uint256`|The fee percent that will be charged upfront from the revnet being borrowed from. Prepaying a fee is cheaper than paying later.|
586
+
587
+ **Returns**
588
+
589
+ |Name|Type|Description|
590
+ |----|----|-----------|
591
+ |`loanId`|`uint256`|The ID of the loan created from borrowing.|
592
+ |`<none>`|`REVLoan`|loan The loan created from borrowing.|
593
+
594
+
595
+ ### liquidateExpiredLoansFrom
596
+
597
+ Cleans up any liquiditated loans.
598
+
599
+ *Since some loans may be reallocated or paid off, loans within startingLoanId and startingLoanId + count may
600
+ be skipped, so choose these parameters carefully to avoid extra gas usage.*
601
+
602
+
603
+ ```solidity
604
+ function liquidateExpiredLoansFrom(uint256 revnetId, uint256 startingLoanId, uint256 count) external override;
605
+ ```
606
+ **Parameters**
607
+
608
+ |Name|Type|Description|
609
+ |----|----|-----------|
610
+ |`revnetId`|`uint256`|The ID of the revnet to liquidate loans from.|
611
+ |`startingLoanId`|`uint256`|The ID of the loan to start iterating from.|
612
+ |`count`|`uint256`|The amount of loans iterate over since the last liquidated loan.|
613
+
614
+
615
+ ### reallocateCollateralFromLoan
616
+
617
+ Refinances a loan by transferring extra collateral from an existing loan to a new loan.
618
+
619
+ *Useful if a loan's collateral has gone up in value since the loan was created.*
620
+
621
+ *Refinancing a loan will burn the original and create two new loans.*
622
+
623
+
624
+ ```solidity
625
+ function reallocateCollateralFromLoan(
626
+ uint256 loanId,
627
+ uint256 collateralCountToTransfer,
628
+ REVLoanSource calldata source,
629
+ uint256 minBorrowAmount,
630
+ uint256 collateralCountToAdd,
631
+ address payable beneficiary,
632
+ uint256 prepaidFeePercent
633
+ )
634
+ external
635
+ payable
636
+ override
637
+ returns (uint256 reallocatedLoanId, uint256 newLoanId, REVLoan memory reallocatedLoan, REVLoan memory newLoan);
638
+ ```
639
+ **Parameters**
640
+
641
+ |Name|Type|Description|
642
+ |----|----|-----------|
643
+ |`loanId`|`uint256`|The ID of the loan to reallocate collateral from.|
644
+ |`collateralCountToTransfer`|`uint256`|The amount of collateral to transfer from the original loan.|
645
+ |`source`|`REVLoanSource`|The source of the loan to create.|
646
+ |`minBorrowAmount`|`uint256`|The minimum amount being borrowed, denominated in the token of the source's accounting context.|
647
+ |`collateralCountToAdd`|`uint256`|The amount of collateral to add to the loan.|
648
+ |`beneficiary`|`address payable`|The address that'll receive the borrowed funds and the tokens resulting from fee payments.|
649
+ |`prepaidFeePercent`|`uint256`|The fee percent that will be charged upfront from the revnet being borrowed from.|
650
+
651
+ **Returns**
652
+
653
+ |Name|Type|Description|
654
+ |----|----|-----------|
655
+ |`reallocatedLoanId`|`uint256`|The ID of the loan being reallocated.|
656
+ |`newLoanId`|`uint256`|The ID of the new loan.|
657
+ |`reallocatedLoan`|`REVLoan`|The loan being reallocated.|
658
+ |`newLoan`|`REVLoan`|The new loan created from reallocating collateral.|
659
+
660
+
661
+ ### repayLoan
662
+
663
+ Allows the owner of a loan to pay it back or receive returned collateral no longer necessary to support
664
+ the loan.
665
+
666
+
667
+ ```solidity
668
+ function repayLoan(
669
+ uint256 loanId,
670
+ uint256 maxRepayBorrowAmount,
671
+ uint256 collateralCountToReturn,
672
+ address payable beneficiary,
673
+ JBSingleAllowance calldata allowance
674
+ )
675
+ external
676
+ payable
677
+ override
678
+ returns (uint256 paidOffLoanId, REVLoan memory paidOffloan);
679
+ ```
680
+ **Parameters**
681
+
682
+ |Name|Type|Description|
683
+ |----|----|-----------|
684
+ |`loanId`|`uint256`|The ID of the loan being adjusted.|
685
+ |`maxRepayBorrowAmount`|`uint256`|The maximum amount being paid off, denominated in the token of the source's accounting context.|
686
+ |`collateralCountToReturn`|`uint256`|The amount of collateral being returned from the loan.|
687
+ |`beneficiary`|`address payable`|The address receiving the returned collateral and any tokens resulting from paying fees.|
688
+ |`allowance`|`JBSingleAllowance`|An allowance to faciliate permit2 interactions.|
689
+
690
+ **Returns**
691
+
692
+ |Name|Type|Description|
693
+ |----|----|-----------|
694
+ |`paidOffLoanId`|`uint256`|The ID of the loan after it's been paid off.|
695
+ |`paidOffloan`|`REVLoan`|The loan after it's been paid off.|
696
+
697
+
698
+ ### setTokenUriResolver
699
+
700
+ Sets the address of the resolver used to retrieve the tokenURI of loans.
701
+
702
+
703
+ ```solidity
704
+ function setTokenUriResolver(IJBTokenUriResolver resolver) external override onlyOwner;
705
+ ```
706
+ **Parameters**
707
+
708
+ |Name|Type|Description|
709
+ |----|----|-----------|
710
+ |`resolver`|`IJBTokenUriResolver`|The address of the new resolver.|
711
+
712
+
713
+ ### _addCollateralTo
714
+
715
+ Adds collateral to a loan.
716
+
717
+
718
+ ```solidity
719
+ function _addCollateralTo(uint256 revnetId, uint256 amount) internal;
720
+ ```
721
+ **Parameters**
722
+
723
+ |Name|Type|Description|
724
+ |----|----|-----------|
725
+ |`revnetId`|`uint256`|The ID of the revnet the loan is being added in.|
726
+ |`amount`|`uint256`|The new amount of collateral being added to the loan.|
727
+
728
+
729
+ ### _addTo
730
+
731
+ Add a new amount to the loan that is greater than the previous amount.
732
+
733
+
734
+ ```solidity
735
+ function _addTo(
736
+ REVLoan memory loan,
737
+ uint256 revnetId,
738
+ uint256 addedBorrowAmount,
739
+ uint256 sourceFeeAmount,
740
+ address payable beneficiary
741
+ )
742
+ internal;
743
+ ```
744
+ **Parameters**
745
+
746
+ |Name|Type|Description|
747
+ |----|----|-----------|
748
+ |`loan`|`REVLoan`|The loan being added to.|
749
+ |`revnetId`|`uint256`|The ID of the revnet the loan is being added in.|
750
+ |`addedBorrowAmount`|`uint256`|The amount being added to the loan, denominated in the token of the source's accounting context.|
751
+ |`sourceFeeAmount`|`uint256`|The amount of the fee being taken from the revnet acting as the source of the loan.|
752
+ |`beneficiary`|`address payable`|The address receiving the returned collateral and any tokens resulting from paying fees.|
753
+
754
+
755
+ ### _adjust
756
+
757
+ Allows the owner of a loan to pay it back, add more, or receive returned collateral no longer necessary
758
+ to support the loan.
759
+
760
+
761
+ ```solidity
762
+ function _adjust(
763
+ REVLoan storage loan,
764
+ uint256 revnetId,
765
+ uint256 newBorrowAmount,
766
+ uint256 newCollateralCount,
767
+ uint256 sourceFeeAmount,
768
+ address payable beneficiary
769
+ )
770
+ internal;
771
+ ```
772
+ **Parameters**
773
+
774
+ |Name|Type|Description|
775
+ |----|----|-----------|
776
+ |`loan`|`REVLoan`|The loan being adjusted.|
777
+ |`revnetId`|`uint256`|The ID of the revnet the loan is being adjusted in.|
778
+ |`newBorrowAmount`|`uint256`|The new amount of the loan, denominated in the token of the source's accounting context.|
779
+ |`newCollateralCount`|`uint256`|The new amount of collateral backing the loan.|
780
+ |`sourceFeeAmount`|`uint256`|The amount of the fee being taken from the revnet acting as the source of the loan.|
781
+ |`beneficiary`|`address payable`|The address receiving the returned collateral and any tokens resulting from paying fees.|
782
+
783
+
784
+ ### _acceptFundsFor
785
+
786
+ Accepts an incoming token.
787
+
788
+
789
+ ```solidity
790
+ function _acceptFundsFor(
791
+ address token,
792
+ uint256 amount,
793
+ JBSingleAllowance memory allowance
794
+ )
795
+ internal
796
+ returns (uint256);
797
+ ```
798
+ **Parameters**
799
+
800
+ |Name|Type|Description|
801
+ |----|----|-----------|
802
+ |`token`|`address`|The token being accepted.|
803
+ |`amount`|`uint256`|The number of tokens being accepted.|
804
+ |`allowance`|`JBSingleAllowance`|The permit2 context.|
805
+
806
+ **Returns**
807
+
808
+ |Name|Type|Description|
809
+ |----|----|-----------|
810
+ |`<none>`|`uint256`|amount The number of tokens which have been accepted.|
811
+
812
+
813
+ ### _beforeTransferTo
814
+
815
+ Logic to be triggered before transferring tokens from this contract.
816
+
817
+
818
+ ```solidity
819
+ function _beforeTransferTo(address to, address token, uint256 amount) internal returns (uint256);
820
+ ```
821
+ **Parameters**
822
+
823
+ |Name|Type|Description|
824
+ |----|----|-----------|
825
+ |`to`|`address`|The address the transfer is going to.|
826
+ |`token`|`address`|The token being transferred.|
827
+ |`amount`|`uint256`|The number of tokens being transferred, as a fixed point number with the same number of decimals as the token specifies.|
828
+
829
+ **Returns**
830
+
831
+ |Name|Type|Description|
832
+ |----|----|-----------|
833
+ |`<none>`|`uint256`|payValue The value to attach to the transaction being sent.|
834
+
835
+
836
+ ### _repayLoan
837
+
838
+ Pays down a loan.
839
+
840
+
841
+ ```solidity
842
+ function _repayLoan(
843
+ uint256 loanId,
844
+ REVLoan storage loan,
845
+ uint256 revnetId,
846
+ uint256 repayBorrowAmount,
847
+ uint256 sourceFeeAmount,
848
+ uint256 collateralCountToReturn,
849
+ address payable beneficiary
850
+ )
851
+ internal
852
+ returns (uint256, REVLoan memory);
853
+ ```
854
+ **Parameters**
855
+
856
+ |Name|Type|Description|
857
+ |----|----|-----------|
858
+ |`loanId`|`uint256`|The ID of the loan being paid down.|
859
+ |`loan`|`REVLoan`|The loan being paid down.|
860
+ |`revnetId`|`uint256`||
861
+ |`repayBorrowAmount`|`uint256`|The amount being paid down from the loan, denominated in the token of the source's accounting context.|
862
+ |`sourceFeeAmount`|`uint256`|The amount of the fee being taken from the revnet acting as the source of the loan.|
863
+ |`collateralCountToReturn`|`uint256`|The amount of collateral being returned that the loan no longer requires.|
864
+ |`beneficiary`|`address payable`|The address receiving the returned collateral and any tokens resulting from paying fees.|
865
+
866
+
867
+ ### _reallocateCollateralFromLoan
868
+
869
+ Reallocates collateral from a loan by making a new loan based on the original, with reduced collateral.
870
+
871
+
872
+ ```solidity
873
+ function _reallocateCollateralFromLoan(
874
+ uint256 loanId,
875
+ uint256 revnetId,
876
+ uint256 collateralCountToRemove
877
+ )
878
+ internal
879
+ returns (uint256 reallocatedLoanId, REVLoan storage reallocatedLoan);
880
+ ```
881
+ **Parameters**
882
+
883
+ |Name|Type|Description|
884
+ |----|----|-----------|
885
+ |`loanId`|`uint256`|The ID of the loan to reallocate collateral from.|
886
+ |`revnetId`|`uint256`|The ID of the revnet the loan is from.|
887
+ |`collateralCountToRemove`|`uint256`|The amount of collateral to remove from the loan.|
888
+
889
+ **Returns**
890
+
891
+ |Name|Type|Description|
892
+ |----|----|-----------|
893
+ |`reallocatedLoanId`|`uint256`|The ID of the loan.|
894
+ |`reallocatedLoan`|`REVLoan`|The reallocated loan.|
895
+
896
+
897
+ ### _removeFrom
898
+
899
+ Pays off a loan.
900
+
901
+
902
+ ```solidity
903
+ function _removeFrom(REVLoan memory loan, uint256 revnetId, uint256 repaidBorrowAmount) internal;
904
+ ```
905
+ **Parameters**
906
+
907
+ |Name|Type|Description|
908
+ |----|----|-----------|
909
+ |`loan`|`REVLoan`|The loan being paid off.|
910
+ |`revnetId`|`uint256`|The ID of the revnet the loan is being paid off in.|
911
+ |`repaidBorrowAmount`|`uint256`|The amount being paid off, denominated in the token of the source's accounting context.|
912
+
913
+
914
+ ### _returnCollateralFrom
915
+
916
+ Returns collateral from a loan.
917
+
918
+
919
+ ```solidity
920
+ function _returnCollateralFrom(uint256 revnetId, uint256 collateralCount, address payable beneficiary) internal;
921
+ ```
922
+ **Parameters**
923
+
924
+ |Name|Type|Description|
925
+ |----|----|-----------|
926
+ |`revnetId`|`uint256`|The ID of the revnet the loan is being returned in.|
927
+ |`collateralCount`|`uint256`|The amount of collateral being returned from the loan.|
928
+ |`beneficiary`|`address payable`|The address receiving the returned collateral.|
929
+
930
+
931
+ ### _transferFrom
932
+
933
+ Transfers tokens.
934
+
935
+
936
+ ```solidity
937
+ function _transferFrom(address from, address payable to, address token, uint256 amount) internal virtual;
938
+ ```
939
+ **Parameters**
940
+
941
+ |Name|Type|Description|
942
+ |----|----|-----------|
943
+ |`from`|`address`|The address to transfer tokens from.|
944
+ |`to`|`address payable`|The address to transfer tokens to.|
945
+ |`token`|`address`|The address of the token being transfered.|
946
+ |`amount`|`uint256`|The amount of tokens to transfer, as a fixed point number with the same number of decimals as the token.|
947
+
948
+
949
+ ### fallback
950
+
951
+
952
+ ```solidity
953
+ fallback() external payable;
954
+ ```
955
+
956
+ ### receive
957
+
958
+
959
+ ```solidity
960
+ receive() external payable;
961
+ ```
962
+
963
+ ## Errors
964
+ ### REVLoans_CollateralExceedsLoan
965
+
966
+ ```solidity
967
+ error REVLoans_CollateralExceedsLoan(uint256 collateralToReturn, uint256 loanCollateral);
968
+ ```
969
+
970
+ ### REVLoans_InvalidPrepaidFeePercent
971
+
972
+ ```solidity
973
+ error REVLoans_InvalidPrepaidFeePercent(uint256 prepaidFeePercent, uint256 min, uint256 max);
974
+ ```
975
+
976
+ ### REVLoans_NotEnoughCollateral
977
+
978
+ ```solidity
979
+ error REVLoans_NotEnoughCollateral();
980
+ ```
981
+
982
+ ### REVLoans_OverflowAlert
983
+
984
+ ```solidity
985
+ error REVLoans_OverflowAlert(uint256 value, uint256 limit);
986
+ ```
987
+
988
+ ### REVLoans_OverMaxRepayBorrowAmount
989
+
990
+ ```solidity
991
+ error REVLoans_OverMaxRepayBorrowAmount(uint256 maxRepayBorrowAmount, uint256 repayBorrowAmount);
992
+ ```
993
+
994
+ ### REVLoans_PermitAllowanceNotEnough
995
+
996
+ ```solidity
997
+ error REVLoans_PermitAllowanceNotEnough(uint256 allowanceAmount, uint256 requiredAmount);
998
+ ```
999
+
1000
+ ### REVLoans_NewBorrowAmountGreaterThanLoanAmount
1001
+
1002
+ ```solidity
1003
+ error REVLoans_NewBorrowAmountGreaterThanLoanAmount(uint256 newBorrowAmount, uint256 loanAmount);
1004
+ ```
1005
+
1006
+ ### REVLoans_NoMsgValueAllowed
1007
+
1008
+ ```solidity
1009
+ error REVLoans_NoMsgValueAllowed();
1010
+ ```
1011
+
1012
+ ### REVLoans_LoanExpired
1013
+
1014
+ ```solidity
1015
+ error REVLoans_LoanExpired(uint256 timeSinceLoanCreated, uint256 loanLiquidationDuration);
1016
+ ```
1017
+
1018
+ ### REVLoans_ReallocatingMoreCollateralThanBorrowedAmountAllows
1019
+
1020
+ ```solidity
1021
+ error REVLoans_ReallocatingMoreCollateralThanBorrowedAmountAllows(uint256 newBorrowAmount, uint256 loanAmount);
1022
+ ```
1023
+
1024
+ ### REVLoans_RevnetsMismatch
1025
+
1026
+ ```solidity
1027
+ error REVLoans_RevnetsMismatch(address revnetOwner, address revnets);
1028
+ ```
1029
+
1030
+ ### REVLoans_Unauthorized
1031
+
1032
+ ```solidity
1033
+ error REVLoans_Unauthorized(address caller, address owner);
1034
+ ```
1035
+
1036
+ ### REVLoans_UnderMinBorrowAmount
1037
+
1038
+ ```solidity
1039
+ error REVLoans_UnderMinBorrowAmount(uint256 minBorrowAmount, uint256 borrowAmount);
1040
+ ```
1041
+
1042
+ ### REVLoans_ZeroCollateralLoanIsInvalid
1043
+
1044
+ ```solidity
1045
+ error REVLoans_ZeroCollateralLoanIsInvalid();
1046
+ ```
1047
+