@rev-net/core-v6 0.0.63 → 0.0.65

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,18 +1,16 @@
1
1
  {
2
2
  "name": "@rev-net/core-v6",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/rev-net/revnet-core-v6"
8
8
  },
9
9
  "files": [
10
- "CHANGELOG.md",
11
10
  "foundry.toml",
12
11
  "references/",
13
12
  "remappings.txt",
14
- "script/Deploy.s.sol",
15
- "script/helpers/",
13
+ "script/",
16
14
  "src/"
17
15
  ],
18
16
  "engines": {
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;
package/CHANGELOG.md DELETED
@@ -1,112 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.0.62 — Omit unset router terminal registry
4
-
5
- - `REVDeployer` now omits `ROUTER_TERMINAL_REGISTRY` from the canonical terminal configuration when it was
6
- constructed with `address(0)`.
7
- - This supports chains where the router terminal stack is unavailable while still launching revnets with the canonical
8
- multi terminal.
9
-
10
- ## 0.0.56 — Bump v6 deps to nana-core-v6 0.0.53 cohort
11
-
12
- - `@bananapus/core-v6`: `^0.0.48 → ^0.0.53` ([PR #145](https://github.com/Bananapus/nana-core-v6/pull/145)).
13
- - `@bananapus/721-hook-v6`: `^0.0.47 → ^0.0.50`.
14
- - `@bananapus/buyback-hook-v6`: `^0.0.39 → ^0.0.46`.
15
- - `@bananapus/router-terminal-v6`: `^0.0.37 → ^0.0.43`.
16
- - `@bananapus/suckers-v6`: `^0.0.37 → ^0.0.46`.
17
- - `@bananapus/permission-ids-v6`: `^0.0.24 → ^0.0.25`.
18
- - Test updates:
19
- - `jbMultiTerminal().FEE()` → `JBConstants.FEE` (FEE moved to a compile-time constant in core 0.0.52+).
20
- - `JBBuybackHook` constructor signature changed in 0.0.45 (V4 PoolManager + Hooks moved to a one-shot setter). Updated `ForkTestBase` and `TestSplitWeightFork` to construct then call `setChainSpecificConstants`.
21
- - All `JBRulesetMetadata` test literals patched to include `pauseCrossProjectFeeFreeInflows: false`. `REVConfig` and `JBBeforeCashOutRecordedContext` literals are unchanged (no new fields).
22
-
23
- ## Scope
24
-
25
- This file describes the verified change from `revnet-core-v5` to the current `revnet-core-v6` repo.
26
-
27
- ## Current v6 surface
28
-
29
- - `REVDeployer`
30
- - `REVOwner`
31
- - `REVLoans`
32
- - `IREVDeployer`
33
- - `IREVOwner`
34
- - `IREVLoans`
35
-
36
- ## Summary
37
-
38
- - The current repo assumes 721 hooks are part of the normal revnet deployment path rather than a separate special case.
39
- - Buyback and loans configuration are more centralized than in v5. The repo is oriented around shared infrastructure instead of repeating per-revnet setup.
40
- - `REVOwner` is now a real part of the repo's runtime surface. That split matters because the hook behavior no longer lives only on `REVDeployer`.
41
- - The v6 test tree is substantially broader than the v5 tree, with dedicated regression, fork, attack, and invariant coverage for loans, cash-outs, split weights, and lifecycle edges.
42
- - The repo moved from the v5 `0.8.23` baseline to `0.8.28`.
43
-
44
- ## In-v6 changes
45
-
46
- ### `0.0.52` — Cap reported surplus on `REVOwner.beforeCashOutRecordedWith` to fit local liquidity
47
-
48
- PR #149 scaled the fee + reclaim proportionally when the gross global outflow exceeded local terminal liquidity, preserving a nonzero fee. But the data hook still returned the **unscaled** `effectiveSurplusValue` to `JBTerminalStore._cashOutWithDataHook`, which recomputes the beneficiary reclaim as `cashOutFrom(effSurplus, cashOutCount, totalSupply, taxRate)` and caps it at local surplus before adding the fee spec — so `balanceDiff = localSurplus + feeAmount > localSurplus` reverted with `InadequateTerminalStoreBalance`. Omnichain holders could not cash out locally when global surplus dominated.
49
-
50
- `cashOutFrom` is linear in `surplus`. After the existing PR #149 scaling, `REVOwner` now lowers the reported `effectiveSurplusValue` proportionally so the store's recomputed reclaim is at most `localSurplus - feeAmount`, leaving exact room for the (preserved) fee spec. The buyback hook still receives the full pre-cap global surplus for its routing decision — only the store-facing return is capped.
51
-
52
- The fee is **never** trimmed or zeroed: that was the regression PR #149 fixed.
53
-
54
- Integrator impact: omnichain cash-outs that previously reverted with `InadequateTerminalStoreBalance` when local liquidity was the binding cap now settle. The beneficiary receives `localSurplus - feeAmount` and the fee revnet receives `feeAmount`. The user still burns the full `context.cashOutCount` tokens — semantics are the same as the pre-existing local-cap protocol behavior, just now reachable end-to-end.
55
-
56
- ## Operator delegation
57
-
58
- - Added new `JBPermissionIds` for operator delegation in `@bananapus/permission-ids-v6`:
59
- - `OPEN_LOAN` — open a loan on behalf of a token holder via `REVLoans.borrowFrom`
60
- - `REALLOCATE_LOAN` — reallocate loan collateral on behalf of a loan owner via `REVLoans.reallocateCollateralFromLoan`
61
- - `REPAY_LOAN` — repay a loan on behalf of a loan owner via `REVLoans.repayLoan`
62
- - `REVLoans.borrowFrom` now accepts a `holder` parameter. The loan NFT is minted to `holder`, and collateral is burned from `holder`. An operator with `OPEN_LOAN` permission can borrow on behalf of a holder.
63
- - `REVLoans.repayLoan` now allows permissioned operators with `REPAY_LOAN` to repay on behalf of the loan NFT owner. Replacement loans are minted to the original loan owner.
64
- - `REVLoans.reallocateCollateralFromLoan` now allows permissioned operators with `REALLOCATE_LOAN` to reallocate on behalf of the loan NFT owner. Returned collateral and replacement loans go to the original loan owner.
65
- - `REVLoans` stores a `PERMISSIONS` immutable for inline permission checks (cannot inherit `JBPermissioned` due to existing `ERC721 + ERC2771Context + Ownable` inheritance).
66
-
67
- ### Breaking ABI changes from delegation
68
-
69
- - `IREVLoans.borrowFrom` signature changed: added `address holder` as last parameter
70
-
71
- ## Verified deltas
72
-
73
- - `IREVDeployer.deployWith721sFor(...)` is gone.
74
- - `IREVDeployer.deployFor(...)` now has overloads that return `(uint256, IJB721TiersHook)`.
75
- - `IREVDeployer.BUYBACK_HOOK()`, `LOANS()`, and `OWNER()` are explicit v6 surface area.
76
- - `IREVOwner` is a new interface and runtime counterpart to the deployer.
77
- - The old caller-supplied `REVBuybackHookConfig` path is no longer part of the deployer interface.
78
-
79
- ## Breaking ABI changes
80
-
81
- - `deployWith721sFor(...)` was removed.
82
- - `deployFor(...)` overloads changed shape and return the deployed 721 hook.
83
- - `REVConfig` no longer carries `loanSources` or `loans`.
84
- - `REVDeploy721TiersHookConfig` now uses `REVBaseline721HookConfig` and inverted `preventOperator*` booleans.
85
- - `IREVOwner` is a new interface that some integrations must track separately from `IREVDeployer`.
86
-
87
- ## Indexer impact
88
-
89
- - Runtime hook activity may now come from `REVOwner`, not only `REVDeployer`.
90
- - Deployment indexing should assume a 721 hook is returned and present by default.
91
- - Any schema built around caller-supplied buyback-hook config in deploy events needs to be revisited.
92
-
93
- ## Migration notes
94
-
95
- - Re-check any integration that assumed `REVDeployer` was the only important runtime address. `REVOwner` now matters.
96
- - Update deployment and indexing code for the default-721-hook assumption.
97
- - Rebuild ABI expectations from the current interfaces and structs. The revnet surface is not a light-touch v5 upgrade.
98
-
99
- ## ABI appendix
100
-
101
- - Removed functions
102
- - `deployWith721sFor(...)`
103
- - Changed functions
104
- - `deployFor(...)` overloads now return the 721 hook
105
- - Added interfaces / runtime addresses
106
- - `IREVOwner`
107
- - `OWNER()`
108
- - Changed structs
109
- - `REVConfig`
110
- - `REVDeploy721TiersHookConfig`
111
- - Removed config path
112
- - caller-supplied `REVBuybackHookConfig`