@rev-net/core-v6 0.0.63 → 0.0.64

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.64 — Owner-settable referral target on `REVLoans`
4
+
5
+ - New `referralProjectId()` view returning the packed `(chainId << 48) | projectId` reference credited as the referrer on every `useAllowanceOf` call this contract makes.
6
+ - New `setReferralProjectId(uint256 projectId, uint256 chainId)` (`onlyOwner`): takes the two fields unpacked, packs and stores them. Bounded so the pack is lossless — `projectId <= type(uint48).max`, `chainId <= type(uint208).max`. Reverts with `REVLoans_ReferralProjectIdTooLarge` / `REVLoans_ReferralChainIdTooLarge` otherwise. Emits `SetReferralProjectId(referralChainId, referralProjectId, caller)`.
7
+ - Default at construction: `(chainId = 1, projectId = REV_ID)` — fee-volume credit still lands on the REV revnet on Ethereum mainnet regardless of which chain a loan originates from. Owner can repoint this if REV ever migrates chains, or pass `(0, 0)` to disable referral credit entirely.
8
+ - The inline `(uint256(1) << 48) | REV_ID` pack inside `_borrowAmountFrom` is replaced by a read of the new storage slot. No external behavior change for default deployments.
9
+ - Storage layout: `referralProjectId` was inserted at slot 8 in alphabetical order between `isLoanSourceOf` and `tokenUriResolver` (per `STYLE_GUIDE.md`), shifting all subsequent public slots by 1. `LoanIdOverflowGuard.t.sol`'s `TOTAL_LOANS_BORROWED_FOR_SLOT` was bumped 11 → 12 and `StorageLayoutStable.t.sol` was updated in lockstep. **External slot-based tooling reading `totalLoansBorrowedFor`/`totalCollateralOf`/`totalBorrowedFrom`/`tokenUriResolver` directly via raw storage must be re-pointed.**
10
+
3
11
  ## 0.0.62 — Omit unset router terminal registry
4
12
 
5
13
  - `REVDeployer` now omits `ROUTER_TERMINAL_REGISTRY` from the canonical terminal configuration when it was
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rev-net/core-v6",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/src/REVLoans.sol CHANGED
@@ -72,6 +72,8 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
72
72
  error REVLoans_PermitAllowanceNotEnough(uint256 allowanceAmount, uint256 requiredAmount);
73
73
  error REVLoans_ReallocatingMoreCollateralThanBorrowedAmountAllows(uint256 newBorrowAmount, uint256 loanAmount);
74
74
  error REVLoans_ReentrantLoanAction();
75
+ error REVLoans_ReferralChainIdTooLarge(uint256 referralChainId);
76
+ error REVLoans_ReferralProjectIdTooLarge(uint256 referralProjectId);
75
77
  error REVLoans_SourceMismatch(address expectedToken, address actualToken);
76
78
  error REVLoans_UnderMinBorrowAmount(uint256 minBorrowAmount, uint256 borrowAmount);
77
79
  error REVLoans_ZeroBorrowAmount(uint256 revnetId, uint256 collateralCount);
@@ -138,6 +140,12 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
138
140
  /// @custom:param token The token source to check.
139
141
  mapping(uint256 revnetId => mapping(address token => bool)) public override isLoanSourceOf;
140
142
 
143
+ /// @notice The packed `(referralChainId << 48) | referralProjectId` reference credited as the referrer on every
144
+ /// `useAllowanceOf` call this contract makes against `TERMINAL`. Defaults to `(1, REV_ID)` so fee-volume credit
145
+ /// accrues to the REV revnet on Ethereum mainnet regardless of which chain the loan originates from. Settable
146
+ /// by the contract owner via `setReferralProjectId` to retarget governance (e.g. if REV migrates chains).
147
+ uint256 public override referralProjectId;
148
+
141
149
  /// @notice The contract resolving each project ID to its ERC721 URI.
142
150
  IJBTokenUriResolver public override tokenUriResolver;
143
151
 
@@ -212,6 +220,10 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
212
220
  REV_ID = revId;
213
221
  PERMIT2 = permit2;
214
222
  SUCKER_REGISTRY = suckerRegistry;
223
+
224
+ // Default referrer reference: REV revnet on Ethereum mainnet. Encoded `(chainId << 48) | projectId` per
225
+ // `JBMultiTerminal.currentReferralProjectId`. Owner can retarget via `setReferralProjectId`.
226
+ referralProjectId = (uint256(1) << 48) | revId;
215
227
  }
216
228
 
217
229
  //*********************************************************************//
@@ -945,6 +957,36 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
945
957
  }
946
958
  }
947
959
 
960
+ /// @notice Update the referrer reference credited on every `useAllowanceOf` call this contract makes.
961
+ /// @dev Stores the packed `(newReferralChainId << 48) | newReferralProjectId` value used by
962
+ /// `JBMultiTerminal.currentReferralProjectId`. Either field may be zero — passing `(0, 0)` disables the
963
+ /// referral credit entirely (the terminal treats `referralProjectId == 0` as "no credit"). Bounded so the
964
+ /// pack is lossless: `newReferralProjectId` must fit in `uint48`, `newReferralChainId` must fit in
965
+ /// `uint208` (so the left-shift by 48 doesn't drop high bits).
966
+ /// @param newReferralProjectId The referring project's bare ID on `newReferralChainId`.
967
+ /// @param newReferralChainId The EIP-155 chain ID of the referrer's home chain.
968
+ function setReferralProjectId(
969
+ uint256 newReferralProjectId,
970
+ uint256 newReferralChainId
971
+ )
972
+ external
973
+ override
974
+ onlyOwner
975
+ {
976
+ // Bound the inputs to the on-chain encoding so the pack is lossless. The same shape JBMultiTerminal uses:
977
+ // projectId in bits [47:0], chainId in bits [255:48].
978
+ if (newReferralProjectId > type(uint48).max) {
979
+ revert REVLoans_ReferralProjectIdTooLarge(newReferralProjectId);
980
+ }
981
+ if (newReferralChainId >> 208 != 0) revert REVLoans_ReferralChainIdTooLarge(newReferralChainId);
982
+
983
+ referralProjectId = (newReferralChainId << 48) | newReferralProjectId;
984
+
985
+ emit SetReferralProjectId({
986
+ referralChainId: newReferralChainId, referralProjectId: newReferralProjectId, caller: _msgSender()
987
+ });
988
+ }
989
+
948
990
  /// @notice Set the address of the resolver used to retrieve the tokenURI of loans.
949
991
  /// @param resolver The address of the new resolver.
950
992
  function setTokenUriResolver(IJBTokenUriResolver resolver) external override onlyOwner {
@@ -1055,16 +1097,12 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1055
1097
  JBAccountingContext memory context =
1056
1098
  TERMINAL.accountingContextForTokenOf({projectId: revnetId, token: sourceToken});
1057
1099
 
1058
- // Pull the amount to be loaned out of the revnet. This will incure the protocol fee. Crediting `REV_ID`
1059
- // as the referrer attributes the protocol fee volume from every Revnet loan back to the REV revnet
1060
- // itself REV is the project that facilitated the activity, regardless of which revnet is borrowing.
1061
- //
1062
- // The referrer reference is encoded as `(referralChainId << 48) | referralProjectId` per
1063
- // `JBMultiTerminal`'s `currentReferralProjectId` packing. REV lives on Ethereum mainnet, so we hard-code
1064
- // `referralChainId = 1`
1065
- // here: this ensures the protocol fee volume credit accrues to REV on mainnet regardless of which chain
1066
- // the loan originates from. (Auto-resolving to `block.chainid` would scatter credit across L2s where REV
1067
- // has no canonical project ID, so we pin mainnet explicitly.)
1100
+ // Pull the amount to be loaned out of the revnet. This will incure the protocol fee. The configured
1101
+ // `referralProjectId` (default `(1, REV_ID)`, owner-settable via `setReferralProjectId`) attributes the
1102
+ // protocol fee volume from every Revnet loan back to the REV revnet REV is the project that
1103
+ // facilitated the activity, regardless of which revnet is borrowing. The packing is
1104
+ // `(chainId << 48) | projectId` per `JBMultiTerminal.currentReferralProjectId`; pinning mainnet by
1105
+ // default avoids scattering credit across L2s where REV has no canonical project ID.
1068
1106
  netAmountPaidOut = TERMINAL.useAllowanceOf({
1069
1107
  projectId: revnetId,
1070
1108
  token: sourceToken,
@@ -1074,7 +1112,7 @@ contract REVLoans is ERC721, ERC2771Context, JBPermissioned, Ownable, IREVLoans
1074
1112
  beneficiary: payable(address(this)),
1075
1113
  feeBeneficiary: beneficiary,
1076
1114
  memo: "",
1077
- referralProjectId: (uint256(1) << 48) | REV_ID
1115
+ referralProjectId: referralProjectId
1078
1116
  });
1079
1117
  }
1080
1118
 
@@ -82,6 +82,12 @@ interface IREVLoans {
82
82
  address caller
83
83
  );
84
84
 
85
+ /// @notice Emitted when the referrer reference for fee-volume credit is updated.
86
+ /// @param referralChainId The EIP-155 chain ID of the new referrer's home chain.
87
+ /// @param referralProjectId The new referring project's bare project ID on `referralChainId`.
88
+ /// @param caller The address that set the new referrer.
89
+ event SetReferralProjectId(uint256 indexed referralChainId, uint256 indexed referralProjectId, address caller);
90
+
85
91
  /// @notice Emitted when the token URI resolver is changed.
86
92
  /// @param resolver The new token URI resolver.
87
93
  /// @param caller The address that set the resolver.
@@ -162,6 +168,12 @@ interface IREVLoans {
162
168
  /// @return The prices contract.
163
169
  function PRICES() external view returns (IJBPrices);
164
170
 
171
+ /// @notice The packed `(referralChainId << 48) | referralProjectId` reference credited as the referrer on
172
+ /// every `useAllowanceOf` call this contract makes. Defaults to `(1, REV_ID)` so credit accrues to REV on
173
+ /// Ethereum mainnet; owner-settable via `setReferralProjectId`.
174
+ /// @return The packed referrer reference.
175
+ function referralProjectId() external view returns (uint256);
176
+
165
177
  /// @notice The ID of the REV revnet that receives protocol fees from loans.
166
178
  /// @return The REV revnet ID.
167
179
  function REV_ID() external view returns (uint256);
@@ -277,6 +289,15 @@ interface IREVLoans {
277
289
  payable
278
290
  returns (uint256 paidOffLoanId, REVLoan memory paidOffloan);
279
291
 
292
+ /// @notice Update the referrer reference credited on every `useAllowanceOf` call this contract makes.
293
+ /// @dev Stores the packed `(newReferralChainId << 48) | newReferralProjectId` value used by
294
+ /// `JBMultiTerminal.currentReferralProjectId`. Either field may be zero (passing `(0, 0)` disables the
295
+ /// referral credit). Bounded so the pack is lossless: `newReferralProjectId <= type(uint48).max`,
296
+ /// `newReferralChainId <= type(uint208).max`.
297
+ /// @param newReferralProjectId The referring project's bare ID on `newReferralChainId`.
298
+ /// @param newReferralChainId The EIP-155 chain ID of the referrer's home chain.
299
+ function setReferralProjectId(uint256 newReferralProjectId, uint256 newReferralChainId) external;
300
+
280
301
  /// @notice Set the address of the resolver used to retrieve the token URI of loans.
281
302
  /// @param resolver The new token URI resolver.
282
303
  function setTokenUriResolver(IJBTokenUriResolver resolver) external;