@rev-net/core-v6 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RISKS.md +19 -1
- package/package.json +9 -9
- package/src/REVDeployer.sol +19 -10
- package/src/REVLoans.sol +138 -89
- package/src/REVOwner.sol +6 -4
- package/test/REV.integrations.t.sol +14 -14
- package/test/REVInvincibility.t.sol +16 -16
- package/test/REVLifecycle.t.sol +32 -32
- package/test/REVLoansSourced.t.sol +15 -15
- package/test/TestCashOutCallerValidation.t.sol +8 -8
- package/test/TestConversionDocumentation.t.sol +2 -5
- package/test/TestCrossCurrencyReclaim.t.sol +72 -72
- package/test/TestLongTailEconomics.t.sol +56 -56
- package/test/TestSwapTerminalPermission.t.sol +21 -21
- package/test/audit/HiddenSupplyCashout.t.sol +61 -0
- package/test/audit/NemesisVerification.t.sol +97 -0
- package/test/audit/REVOwnerCurrencyMismatch.t.sol +188 -0
- package/test/audit/REVOwnerRemoteSurplusCurrencyMismatch.t.sol +140 -0
- package/test/audit/ReallocatePermission.t.sol +363 -0
- package/test/audit/RemoteLoanAccountingGap.t.sol +74 -0
- package/test/audit/SupportsInterfaceTest.t.sol +51 -0
- package/test/audit/TestFeeAllowanceLeak.t.sol +197 -0
- package/test/audit/TestLoansAndDeployerFixes.t.sol +576 -0
- package/test/fork/TestCashOutFork.t.sol +48 -48
- package/test/fork/TestLoanAdversarialFork.t.sol +744 -0
- package/test/fork/TestLoanERC20Fork.t.sol +2 -8
- package/test/fork/TestPermit2PaymentFork.t.sol +32 -32
- package/test/regression/TestBurnPermissionRequired.t.sol +5 -5
- package/test/regression/TestCashOutBuybackFeeLeak.t.sol +8 -8
- /package/test/audit/{CodexCrossChainBuybackRouteMismatch.t.sol → CrossChainBuybackRouteMismatch.t.sol} +0 -0
- /package/test/audit/{NemesisOperatorDelegation.t.sol → OperatorDelegation.t.sol} +0 -0
- /package/test/audit/{CodexPhantomSurplusTerminal.t.sol → PhantomSurplusTerminal.t.sol} +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
|
+
|
|
6
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
7
|
+
import {JBCashOuts} from "@bananapus/core-v6/src/libraries/JBCashOuts.sol";
|
|
8
|
+
|
|
9
|
+
contract CodexNemesisVerificationTest is Test {
|
|
10
|
+
function testConfigurationHashDoesNotCommitSplitOperatorSplitsOrExtraMetadata() public pure {
|
|
11
|
+
bytes32 hashA = _revDeployerEncodedConfigurationHash();
|
|
12
|
+
bytes32 hashB = _revDeployerEncodedConfigurationHash();
|
|
13
|
+
|
|
14
|
+
assertEq(hashA, hashB, "actual REVDeployer hash collides");
|
|
15
|
+
|
|
16
|
+
bytes32 fullCommitmentA = keccak256(
|
|
17
|
+
abi.encode(hashA, address(0x1111), uint32(7000), address(0xAAAA), uint48(30 days), uint16(0x0004))
|
|
18
|
+
);
|
|
19
|
+
bytes32 fullCommitmentB = keccak256(
|
|
20
|
+
abi.encode(hashB, address(0x2222), uint32(7000), address(0xBBBB), uint48(90 days), uint16(0x0000))
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
assertNotEq(fullCommitmentA, fullCommitmentB, "omitted fields are economically distinct");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function testRemoteLoanStateOmissionOverstatesCrossChainCashOutValue() public pure {
|
|
27
|
+
uint256 localSupply = 100 ether;
|
|
28
|
+
uint256 localSurplus = 100 ether;
|
|
29
|
+
uint256 remoteVisibleSupply = 1 ether;
|
|
30
|
+
uint256 remoteVisibleSurplus = 1 ether;
|
|
31
|
+
uint256 omittedRemoteLoanCollateral = 99 ether;
|
|
32
|
+
uint256 omittedRemoteLoanDebt = 99 ether;
|
|
33
|
+
uint256 cashOutCount = 100 ether;
|
|
34
|
+
uint256 cashOutTaxRate = 1000;
|
|
35
|
+
|
|
36
|
+
uint256 current = JBCashOuts.cashOutFrom({
|
|
37
|
+
surplus: localSurplus + remoteVisibleSurplus,
|
|
38
|
+
cashOutCount: cashOutCount,
|
|
39
|
+
totalSupply: localSupply + remoteVisibleSupply,
|
|
40
|
+
cashOutTaxRate: cashOutTaxRate
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
uint256 withRemoteLoans = JBCashOuts.cashOutFrom({
|
|
44
|
+
surplus: localSurplus + remoteVisibleSurplus + omittedRemoteLoanDebt,
|
|
45
|
+
cashOutCount: cashOutCount,
|
|
46
|
+
totalSupply: localSupply + remoteVisibleSupply + omittedRemoteLoanCollateral,
|
|
47
|
+
cashOutTaxRate: cashOutTaxRate
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
assertGt(current, withRemoteLoans, "omitting remote loan state should not increase cash-out value");
|
|
51
|
+
assertGt(current - withRemoteLoans, 4 ether, "drift is material");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function testRemoteLoanStateOmissionCanHitFullSupplyBranch() public pure {
|
|
55
|
+
uint256 localSupply = 100 ether;
|
|
56
|
+
uint256 localSurplus = 100 ether;
|
|
57
|
+
uint256 omittedRemoteLoanCollateral = 100 ether;
|
|
58
|
+
uint256 omittedRemoteLoanDebt = 100 ether;
|
|
59
|
+
uint256 cashOutCount = 100 ether;
|
|
60
|
+
uint256 cashOutTaxRate = 1000;
|
|
61
|
+
|
|
62
|
+
uint256 current = JBCashOuts.cashOutFrom({
|
|
63
|
+
surplus: localSurplus, cashOutCount: cashOutCount, totalSupply: localSupply, cashOutTaxRate: cashOutTaxRate
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
uint256 withRemoteLoans = JBCashOuts.cashOutFrom({
|
|
67
|
+
surplus: localSurplus + omittedRemoteLoanDebt,
|
|
68
|
+
cashOutCount: cashOutCount,
|
|
69
|
+
totalSupply: localSupply + omittedRemoteLoanCollateral,
|
|
70
|
+
cashOutTaxRate: cashOutTaxRate
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
assertEq(current, localSurplus, "current path enters full-supply branch");
|
|
74
|
+
assertEq(withRemoteLoans, 95 ether, "true omnichain curve should remain partial");
|
|
75
|
+
assertGt(current, withRemoteLoans, "full-supply branch overstates cash-out value");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _revDeployerEncodedConfigurationHash() internal pure returns (bytes32) {
|
|
79
|
+
bytes memory encodedConfiguration = abi.encode(uint32(1), "REV", "REV", bytes32("codex-nemesis"));
|
|
80
|
+
|
|
81
|
+
encodedConfiguration = abi.encode(encodedConfiguration, address(0x1234));
|
|
82
|
+
|
|
83
|
+
encodedConfiguration = abi.encode(
|
|
84
|
+
encodedConfiguration,
|
|
85
|
+
uint48(1_740_089_444),
|
|
86
|
+
uint16(7000),
|
|
87
|
+
uint112(1_000_000 ether),
|
|
88
|
+
uint32(30 days),
|
|
89
|
+
uint32(0),
|
|
90
|
+
uint16(JBConstants.MAX_CASH_OUT_TAX_RATE / 2)
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
encodedConfiguration = abi.encode(encodedConfiguration, uint32(1), address(0xBEEF), uint104(100_000 ether));
|
|
94
|
+
|
|
95
|
+
return keccak256(encodedConfiguration);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
6
|
+
import {IJBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
|
|
7
|
+
import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
|
|
8
|
+
import {JBBeforeCashOutRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforeCashOutRecordedContext.sol";
|
|
9
|
+
import {JBBeforePayRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforePayRecordedContext.sol";
|
|
10
|
+
import {JBCashOutHookSpecification} from "@bananapus/core-v6/src/structs/JBCashOutHookSpecification.sol";
|
|
11
|
+
import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
12
|
+
import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.sol";
|
|
13
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
14
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
15
|
+
import {IJBSuckerRegistry} from "@bananapus/suckers-v6/src/interfaces/IJBSuckerRegistry.sol";
|
|
16
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
17
|
+
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
18
|
+
|
|
19
|
+
import {REVOwner} from "../../src/REVOwner.sol";
|
|
20
|
+
|
|
21
|
+
/// @notice Mock sucker registry that returns configurable remote values.
|
|
22
|
+
/// @dev All functions are view/pure to avoid StateChangeDuringStaticCall when called from
|
|
23
|
+
/// REVOwner.beforeCashOutRecordedWith (which is a view function).
|
|
24
|
+
contract MockSuckerRegistry {
|
|
25
|
+
uint256 public remoteSurplusToReturn;
|
|
26
|
+
uint256 public remoteSupplyToReturn;
|
|
27
|
+
|
|
28
|
+
function setRemoteValues(uint256 supply, uint256 surplus) external {
|
|
29
|
+
remoteSupplyToReturn = supply;
|
|
30
|
+
remoteSurplusToReturn = surplus;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isSuckerOf(uint256, address) external pure returns (bool) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function remoteTotalSupplyOf(uint256) external view returns (uint256) {
|
|
38
|
+
return remoteSupplyToReturn;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function remoteSurplusOf(uint256, uint256, uint256) external view returns (uint256) {
|
|
42
|
+
return remoteSurplusToReturn;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// @notice Minimal echo buyback registry that passes through cash out context unchanged.
|
|
47
|
+
contract EchoBuybackRegistry is IJBRulesetDataHook {
|
|
48
|
+
function beforeCashOutRecordedWith(JBBeforeCashOutRecordedContext calldata context)
|
|
49
|
+
external
|
|
50
|
+
pure
|
|
51
|
+
returns (
|
|
52
|
+
uint256 cashOutTaxRate,
|
|
53
|
+
uint256 cashOutCount,
|
|
54
|
+
uint256 totalSupply,
|
|
55
|
+
uint256 effectiveSurplusValue,
|
|
56
|
+
JBCashOutHookSpecification[] memory hookSpecifications
|
|
57
|
+
)
|
|
58
|
+
{
|
|
59
|
+
cashOutTaxRate = context.cashOutTaxRate;
|
|
60
|
+
cashOutCount = context.cashOutCount;
|
|
61
|
+
totalSupply = context.totalSupply;
|
|
62
|
+
effectiveSurplusValue = context.surplus.value;
|
|
63
|
+
hookSpecifications = new JBCashOutHookSpecification[](0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
|
|
67
|
+
external
|
|
68
|
+
pure
|
|
69
|
+
returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
|
|
70
|
+
{
|
|
71
|
+
weight = context.weight;
|
|
72
|
+
hookSpecifications = new JBPayHookSpecification[](0);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function hasMintPermissionFor(uint256, JBRuleset calldata, address) external pure returns (bool) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function setPoolFor(uint256, PoolKey calldata, uint256, address) external pure {}
|
|
80
|
+
function setPoolFor(uint256, uint24, int24, uint256, address) external pure {}
|
|
81
|
+
function initializePoolFor(uint256, uint24, int24, uint256, address, uint160) external pure {}
|
|
82
|
+
|
|
83
|
+
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
|
|
84
|
+
return interfaceId == type(IJBRulesetDataHook).interfaceId || interfaceId == type(IERC165).interfaceId;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// @notice REVOwner.beforeCashOutRecordedWith should pass the surplus currency (not the token address) to
|
|
89
|
+
/// remoteSurplusOf. @dev `currency: uint256(context.surplus.currency)` passes the correct currency value,
|
|
90
|
+
/// not `uint256(uint160(context.surplus.token))` which would pass the token address (e.g. 61166 for NATIVE_TOKEN).
|
|
91
|
+
contract REVOwnerCurrencyMismatchTest is TestBaseWorkflow {
|
|
92
|
+
REVOwner internal ownerHook;
|
|
93
|
+
MockSuckerRegistry internal suckerRegistry;
|
|
94
|
+
EchoBuybackRegistry internal buybackRegistry;
|
|
95
|
+
|
|
96
|
+
function setUp() public override {
|
|
97
|
+
super.setUp();
|
|
98
|
+
|
|
99
|
+
suckerRegistry = new MockSuckerRegistry();
|
|
100
|
+
buybackRegistry = new EchoBuybackRegistry();
|
|
101
|
+
|
|
102
|
+
ownerHook = new REVOwner(
|
|
103
|
+
IJBBuybackHookRegistry(address(buybackRegistry)),
|
|
104
|
+
jbDirectory(),
|
|
105
|
+
999_999, // fee revnet ID (won't be used in this test path)
|
|
106
|
+
IJBSuckerRegistry(address(suckerRegistry)),
|
|
107
|
+
address(0), // loans
|
|
108
|
+
address(0) // hidden tokens
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// @notice Verify that remoteSurplusOf is called with the context's currency, not the token address.
|
|
113
|
+
/// @dev NATIVE_TOKEN = 0x000000000000000000000000000000000000EEEe
|
|
114
|
+
/// uint160(NATIVE_TOKEN) = 61166
|
|
115
|
+
/// The correct currency for ETH is 1 (baseCurrency).
|
|
116
|
+
/// Before the fix, 61166 was passed. After the fix, 1 is passed.
|
|
117
|
+
function test_remoteSurplusOf_receives_currency_not_token_address() public {
|
|
118
|
+
// Set up remote values so the registry returns something.
|
|
119
|
+
suckerRegistry.setRemoteValues(500 ether, 900 ether);
|
|
120
|
+
|
|
121
|
+
uint32 ethCurrency = 1; // ETH baseCurrency identifier
|
|
122
|
+
|
|
123
|
+
// Build a context where surplus.token = NATIVE_TOKEN and surplus.currency = 1 (ETH).
|
|
124
|
+
// These are intentionally different values to detect the bug.
|
|
125
|
+
JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
|
|
126
|
+
terminal: address(jbMultiTerminal()),
|
|
127
|
+
holder: address(0xCAFE),
|
|
128
|
+
projectId: 1,
|
|
129
|
+
rulesetId: 0,
|
|
130
|
+
cashOutCount: 100 ether,
|
|
131
|
+
totalSupply: 1000 ether,
|
|
132
|
+
surplus: JBTokenAmount({
|
|
133
|
+
token: JBConstants.NATIVE_TOKEN, // 0xEEEe
|
|
134
|
+
value: 100 ether,
|
|
135
|
+
decimals: 18,
|
|
136
|
+
currency: ethCurrency // 1
|
|
137
|
+
}),
|
|
138
|
+
useTotalSurplus: true,
|
|
139
|
+
cashOutTaxRate: 0, // zero tax = feeless path (simpler, avoids needing fee terminal)
|
|
140
|
+
beneficiaryIsFeeless: false,
|
|
141
|
+
metadata: ""
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Use vm.expectCall to verify the exact parameters passed to remoteSurplusOf.
|
|
145
|
+
// After fix: currency should be 1 (ethCurrency), NOT 61166 (uint160(NATIVE_TOKEN)).
|
|
146
|
+
// This assertion will fail if the buggy code passes uint256(uint160(NATIVE_TOKEN)) = 61166.
|
|
147
|
+
vm.expectCall(
|
|
148
|
+
address(suckerRegistry), abi.encodeCall(suckerRegistry.remoteSurplusOf, (1, 18, uint256(ethCurrency)))
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
ownerHook.beforeCashOutRecordedWith(context);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// @notice Verify that the remote surplus is actually included in the returned effectiveSurplusValue.
|
|
155
|
+
/// @dev This is a regression test: if the wrong currency is passed, the registry might return 0
|
|
156
|
+
/// and the remote surplus would be silently dropped.
|
|
157
|
+
function test_remoteSurplus_included_in_effectiveSurplus() public {
|
|
158
|
+
suckerRegistry.setRemoteValues(500 ether, 900 ether);
|
|
159
|
+
|
|
160
|
+
uint32 ethCurrency = 1;
|
|
161
|
+
|
|
162
|
+
JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
|
|
163
|
+
terminal: address(jbMultiTerminal()),
|
|
164
|
+
holder: address(0xCAFE),
|
|
165
|
+
projectId: 1,
|
|
166
|
+
rulesetId: 0,
|
|
167
|
+
cashOutCount: 100 ether,
|
|
168
|
+
totalSupply: 1000 ether,
|
|
169
|
+
surplus: JBTokenAmount({
|
|
170
|
+
token: JBConstants.NATIVE_TOKEN, value: 100 ether, decimals: 18, currency: ethCurrency
|
|
171
|
+
}),
|
|
172
|
+
useTotalSurplus: true,
|
|
173
|
+
cashOutTaxRate: 0,
|
|
174
|
+
beneficiaryIsFeeless: false,
|
|
175
|
+
metadata: ""
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
(,, uint256 returnedSupply, uint256 returnedSurplus,) = ownerHook.beforeCashOutRecordedWith(context);
|
|
179
|
+
|
|
180
|
+
// Remote supply should be added.
|
|
181
|
+
assertEq(returnedSupply, 1500 ether, "totalSupply should include remote supply");
|
|
182
|
+
|
|
183
|
+
// Remote surplus should be added (100 local + 900 remote = 1000).
|
|
184
|
+
assertEq(
|
|
185
|
+
returnedSurplus, 1000 ether, "effectiveSurplusValue should include remote surplus (100 local + 900 remote)"
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
6
|
+
import {IJBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
|
|
7
|
+
import {IJBCashOutHook} from "@bananapus/core-v6/src/interfaces/IJBCashOutHook.sol";
|
|
8
|
+
import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
|
|
9
|
+
import {JBBeforeCashOutRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforeCashOutRecordedContext.sol";
|
|
10
|
+
import {JBBeforePayRecordedContext} from "@bananapus/core-v6/src/structs/JBBeforePayRecordedContext.sol";
|
|
11
|
+
import {JBCashOutHookSpecification} from "@bananapus/core-v6/src/structs/JBCashOutHookSpecification.sol";
|
|
12
|
+
import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
13
|
+
import {JBTokenAmount} from "@bananapus/core-v6/src/structs/JBTokenAmount.sol";
|
|
14
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
15
|
+
import {IJBSuckerRegistry} from "@bananapus/suckers-v6/src/interfaces/IJBSuckerRegistry.sol";
|
|
16
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
17
|
+
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
18
|
+
|
|
19
|
+
import {REVOwner} from "../../src/REVOwner.sol";
|
|
20
|
+
|
|
21
|
+
contract CurrencyAwareSuckerRegistry {
|
|
22
|
+
uint256 public expectedCurrency;
|
|
23
|
+
uint256 public remoteSupply;
|
|
24
|
+
uint256 public remoteSurplus;
|
|
25
|
+
|
|
26
|
+
function setRemoteValues(uint256 currency, uint256 supply, uint256 surplus) external {
|
|
27
|
+
expectedCurrency = currency;
|
|
28
|
+
remoteSupply = supply;
|
|
29
|
+
remoteSurplus = surplus;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isSuckerOf(uint256, address) external pure returns (bool) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function remoteTotalSupplyOf(uint256) external view returns (uint256) {
|
|
37
|
+
return remoteSupply;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function remoteSurplusOf(uint256, uint256, uint256 currency) external view returns (uint256) {
|
|
41
|
+
return currency == expectedCurrency ? remoteSurplus : 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
contract EchoBuybackRegistry is IJBRulesetDataHook {
|
|
46
|
+
function beforeCashOutRecordedWith(JBBeforeCashOutRecordedContext calldata context)
|
|
47
|
+
external
|
|
48
|
+
pure
|
|
49
|
+
returns (
|
|
50
|
+
uint256 cashOutTaxRate,
|
|
51
|
+
uint256 cashOutCount,
|
|
52
|
+
uint256 totalSupply,
|
|
53
|
+
uint256 effectiveSurplusValue,
|
|
54
|
+
JBCashOutHookSpecification[] memory hookSpecifications
|
|
55
|
+
)
|
|
56
|
+
{
|
|
57
|
+
cashOutTaxRate = context.cashOutTaxRate;
|
|
58
|
+
cashOutCount = context.cashOutCount;
|
|
59
|
+
totalSupply = context.totalSupply;
|
|
60
|
+
effectiveSurplusValue = context.surplus.value;
|
|
61
|
+
hookSpecifications = new JBCashOutHookSpecification[](0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function beforePayRecordedWith(JBBeforePayRecordedContext calldata context)
|
|
65
|
+
external
|
|
66
|
+
pure
|
|
67
|
+
returns (uint256 weight, JBPayHookSpecification[] memory hookSpecifications)
|
|
68
|
+
{
|
|
69
|
+
weight = context.weight;
|
|
70
|
+
hookSpecifications = new JBPayHookSpecification[](0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function hasMintPermissionFor(uint256, JBRuleset calldata, address) external pure returns (bool) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function setPoolFor(uint256, PoolKey calldata, uint256, address) external pure {}
|
|
78
|
+
function setPoolFor(uint256, uint24, int24, uint256, address) external pure {}
|
|
79
|
+
function initializePoolFor(uint256, uint24, int24, uint256, address, uint160) external pure {}
|
|
80
|
+
|
|
81
|
+
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
|
|
82
|
+
return interfaceId == type(IJBRulesetDataHook).interfaceId || interfaceId == type(IERC165).interfaceId;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
contract REVOwnerRemoteSurplusCurrencyMismatchTest is TestBaseWorkflow {
|
|
87
|
+
REVOwner internal ownerHook;
|
|
88
|
+
CurrencyAwareSuckerRegistry internal suckerRegistry;
|
|
89
|
+
EchoBuybackRegistry internal buybackRegistry;
|
|
90
|
+
|
|
91
|
+
uint32 internal constant ETH_CURRENCY = 1;
|
|
92
|
+
|
|
93
|
+
function setUp() public override {
|
|
94
|
+
super.setUp();
|
|
95
|
+
|
|
96
|
+
suckerRegistry = new CurrencyAwareSuckerRegistry();
|
|
97
|
+
buybackRegistry = new EchoBuybackRegistry();
|
|
98
|
+
|
|
99
|
+
ownerHook = new REVOwner(
|
|
100
|
+
IJBBuybackHookRegistry(address(buybackRegistry)),
|
|
101
|
+
jbDirectory(),
|
|
102
|
+
999_999,
|
|
103
|
+
IJBSuckerRegistry(address(suckerRegistry)),
|
|
104
|
+
address(0),
|
|
105
|
+
address(0)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function test_beforeCashOutRecordedWith_usesTokenAddressInsteadOfCurrencyForRemoteSurplus() public {
|
|
110
|
+
suckerRegistry.setRemoteValues(ETH_CURRENCY, 500 ether, 900 ether);
|
|
111
|
+
|
|
112
|
+
address usdToken = address(0xBEEF);
|
|
113
|
+
|
|
114
|
+
JBBeforeCashOutRecordedContext memory context = JBBeforeCashOutRecordedContext({
|
|
115
|
+
terminal: address(jbMultiTerminal()),
|
|
116
|
+
holder: address(0xCAFE),
|
|
117
|
+
projectId: 1,
|
|
118
|
+
rulesetId: 0,
|
|
119
|
+
cashOutCount: 100 ether,
|
|
120
|
+
totalSupply: 1000 ether,
|
|
121
|
+
surplus: JBTokenAmount({token: usdToken, value: 100 ether, decimals: 18, currency: ETH_CURRENCY}),
|
|
122
|
+
useTotalSurplus: true,
|
|
123
|
+
cashOutTaxRate: 0,
|
|
124
|
+
beneficiaryIsFeeless: false,
|
|
125
|
+
metadata: ""
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
(,, uint256 returnedSupply, uint256 returnedSurplus,) = ownerHook.beforeCashOutRecordedWith(context);
|
|
129
|
+
|
|
130
|
+
assertEq(returnedSupply, 1500 ether, "remote supply should still be included");
|
|
131
|
+
// Remote surplus is correctly included (100 local + 900 remote = 1000) because the currency is passed to
|
|
132
|
+
// remoteSurplusOf.
|
|
133
|
+
assertEq(returnedSurplus, 1000 ether, "remote surplus should be included now that currency is passed correctly");
|
|
134
|
+
assertEq(
|
|
135
|
+
suckerRegistry.remoteSurplusOf(1, 18, ETH_CURRENCY),
|
|
136
|
+
900 ether,
|
|
137
|
+
"registry confirms surplus exists for the requested currency"
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|