@bananapus/router-terminal-v6 0.0.21 → 0.0.23

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.
@@ -1,10 +1,18 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity 0.8.28;
3
3
 
4
- import "forge-std/Test.sol";
4
+ import {Test} from "forge-std/Test.sol";
5
5
 
6
- import "../../src/JBRouterTerminal.sol";
7
- import "../../src/interfaces/IJBPayerTracker.sol";
6
+ import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
7
+ import {IJBPermissions} from "@bananapus/core-v6/src/interfaces/IJBPermissions.sol";
8
+ import {IJBTokens} from "@bananapus/core-v6/src/interfaces/IJBTokens.sol";
9
+ import {IPermit2} from "@uniswap/permit2/src/interfaces/IPermit2.sol";
10
+ import {IUniswapV3Factory} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
11
+ import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
12
+
13
+ import {JBRouterTerminal} from "../../src/JBRouterTerminal.sol";
14
+ import {IJBPayerTracker} from "../../src/interfaces/IJBPayerTracker.sol";
15
+ import {IWETH9} from "../../src/interfaces/IWETH9.sol";
8
16
 
9
17
  // ---------------------------------------------------------------------------
10
18
  // Harness – exposes the internal `_resolveRefundTo` for direct testing.
@@ -14,7 +22,6 @@ contract PayerTrackerRefundHarness is JBRouterTerminal {
14
22
  constructor(
15
23
  IJBDirectory directory,
16
24
  IJBPermissions permissions,
17
- IJBProjects projects,
18
25
  IJBTokens tokens,
19
26
  IPermit2 permit2,
20
27
  address owner,
@@ -23,9 +30,7 @@ contract PayerTrackerRefundHarness is JBRouterTerminal {
23
30
  IPoolManager poolManager,
24
31
  address trustedForwarder
25
32
  )
26
- JBRouterTerminal(
27
- directory, permissions, projects, tokens, permit2, owner, weth, factory, poolManager, trustedForwarder
28
- )
33
+ JBRouterTerminal(directory, permissions, tokens, permit2, owner, weth, factory, poolManager, trustedForwarder)
29
34
  {}
30
35
 
31
36
  /// @notice Public wrapper so tests can call `_resolveRefundWithBackupRecipient` directly.
@@ -98,7 +103,6 @@ contract PayerTrackerRefundTest is Test {
98
103
  harness = new PayerTrackerRefundHarness(
99
104
  IJBDirectory(address(0)),
100
105
  IJBPermissions(address(0)),
101
- IJBProjects(address(0)),
102
106
  IJBTokens(address(0)),
103
107
  IPermit2(address(0)),
104
108
  address(this), // owner
@@ -9,7 +9,6 @@ import {IJBPayerTracker} from "../../src/interfaces/IJBPayerTracker.sol";
9
9
 
10
10
  import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
11
11
  import {IJBPermissions} from "@bananapus/core-v6/src/interfaces/IJBPermissions.sol";
12
- import {IJBProjects} from "@bananapus/core-v6/src/interfaces/IJBProjects.sol";
13
12
  import {IJBTokens} from "@bananapus/core-v6/src/interfaces/IJBTokens.sol";
14
13
 
15
14
  import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
@@ -57,7 +56,6 @@ contract HarnessRouterTerminal is JBRouterTerminal {
57
56
  JBRouterTerminal(
58
57
  IJBDirectory(address(0)),
59
58
  IJBPermissions(address(0)),
60
- IJBProjects(address(0)),
61
59
  IJBTokens(address(0)),
62
60
  IPermit2(address(0)),
63
61
  address(this),
@@ -14,7 +14,6 @@ import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataRes
14
14
  import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
15
15
  import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
16
16
  import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
17
- import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
18
17
  import {IPermit2} from "@uniswap/permit2/src/interfaces/IPermit2.sol";
19
18
  import {IUniswapV3Factory} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
20
19
  import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
@@ -27,7 +26,7 @@ import {IWETH9} from "../../src/interfaces/IWETH9.sol";
27
26
  contract AuditMockERC20 {
28
27
  string public name;
29
28
  string public symbol;
30
- uint8 public constant decimals = 18;
29
+ uint8 public constant DECIMALS = 18;
31
30
 
32
31
  mapping(address => uint256) public balanceOf;
33
32
  mapping(address => mapping(address => uint256)) public allowance;
@@ -62,9 +61,9 @@ contract AuditMockERC20 {
62
61
  }
63
62
 
64
63
  contract AuditMockWETH is IWETH9 {
65
- string public constant name = "Wrapped Ether";
66
- string public constant symbol = "WETH";
67
- uint8 public constant decimals = 18;
64
+ string public constant NAME = "Wrapped Ether";
65
+ string public constant SYMBOL = "WETH";
66
+ uint8 public constant DECIMALS = 18;
68
67
  uint256 public totalSupply;
69
68
 
70
69
  mapping(address => uint256) public balanceOf;
@@ -179,7 +178,22 @@ contract AuditMockDestTerminal is IJBTerminal {
179
178
  returns (JBRuleset memory, uint256, uint256, JBPayHookSpecification[] memory hookSpecifications)
180
179
  {
181
180
  hookSpecifications = new JBPayHookSpecification[](0);
182
- return (JBRuleset(0, 0, 0, 0, 0, 0, 0, IJBRulesetApprovalHook(address(0)), 0), amount, 0, hookSpecifications);
181
+ return (
182
+ JBRuleset({
183
+ cycleNumber: 0,
184
+ id: 0,
185
+ basedOnId: 0,
186
+ start: 0,
187
+ duration: 0,
188
+ weight: 0,
189
+ weightCutPercent: 0,
190
+ approvalHook: IJBRulesetApprovalHook(address(0)),
191
+ metadata: 0
192
+ }),
193
+ amount,
194
+ 0,
195
+ hookSpecifications
196
+ );
183
197
  }
184
198
 
185
199
  function supportsInterface(bytes4) external pure override returns (bool) {
@@ -188,15 +202,17 @@ contract AuditMockDestTerminal is IJBTerminal {
188
202
  }
189
203
 
190
204
  contract AuditPartialFillPool is IUniswapV3Pool {
191
- address internal immutable _token0;
192
- address internal immutable _token1;
193
- AuditMockERC20 internal immutable _zeroForOneOutputToken;
194
- AuditMockERC20 internal immutable _oneForZeroOutputToken;
205
+ address internal immutable _TOKEN0;
206
+ address internal immutable _TOKEN1;
207
+ AuditMockERC20 internal immutable _ZERO_FOR_ONE_OUTPUT_TOKEN;
208
+ AuditMockERC20 internal immutable _ONE_FOR_ZERO_OUTPUT_TOKEN;
209
+ // forge-lint: disable-next-line(screaming-snake-case-immutable)
195
210
  uint24 public immutable override fee = 3000;
211
+ // forge-lint: disable-next-line(screaming-snake-case-immutable)
196
212
  uint128 public immutable override liquidity = 1_000_000;
197
213
 
198
- uint256 public immutable amountInUsed;
199
- uint256 public immutable amountOutGiven;
214
+ uint256 public immutable AMOUNT_IN_USED;
215
+ uint256 public immutable AMOUNT_OUT_GIVEN;
200
216
 
201
217
  constructor(
202
218
  address token0_,
@@ -206,12 +222,12 @@ contract AuditPartialFillPool is IUniswapV3Pool {
206
222
  uint256 amountInUsed_,
207
223
  uint256 amountOutGiven_
208
224
  ) {
209
- _token0 = token0_;
210
- _token1 = token1_;
211
- _zeroForOneOutputToken = zeroForOneOutputToken_;
212
- _oneForZeroOutputToken = oneForZeroOutputToken_;
213
- amountInUsed = amountInUsed_;
214
- amountOutGiven = amountOutGiven_;
225
+ _TOKEN0 = token0_;
226
+ _TOKEN1 = token1_;
227
+ _ZERO_FOR_ONE_OUTPUT_TOKEN = zeroForOneOutputToken_;
228
+ _ONE_FOR_ZERO_OUTPUT_TOKEN = oneForZeroOutputToken_;
229
+ AMOUNT_IN_USED = amountInUsed_;
230
+ AMOUNT_OUT_GIVEN = amountOutGiven_;
215
231
  }
216
232
 
217
233
  function swap(
@@ -225,24 +241,28 @@ contract AuditPartialFillPool is IUniswapV3Pool {
225
241
  override
226
242
  returns (int256 amount0, int256 amount1)
227
243
  {
244
+ // forge-lint: disable-next-line(unsafe-typecast)
245
+ int256 signedIn = int256(AMOUNT_IN_USED);
246
+ // forge-lint: disable-next-line(unsafe-typecast)
247
+ int256 signedOut = int256(AMOUNT_OUT_GIVEN);
248
+
228
249
  if (zeroForOne) {
229
- JBRouterTerminal(payable(msg.sender))
230
- .uniswapV3SwapCallback(int256(amountInUsed), -int256(amountOutGiven), data);
231
- _zeroForOneOutputToken.mint(recipient, amountOutGiven);
232
- return (int256(amountInUsed), -int256(amountOutGiven));
250
+ JBRouterTerminal(payable(msg.sender)).uniswapV3SwapCallback(signedIn, -signedOut, data);
251
+ _ZERO_FOR_ONE_OUTPUT_TOKEN.mint(recipient, AMOUNT_OUT_GIVEN);
252
+ return (signedIn, -signedOut);
233
253
  }
234
254
 
235
- JBRouterTerminal(payable(msg.sender)).uniswapV3SwapCallback(-int256(amountOutGiven), int256(amountInUsed), data);
236
- _oneForZeroOutputToken.mint(recipient, amountOutGiven);
237
- return (-int256(amountOutGiven), int256(amountInUsed));
255
+ JBRouterTerminal(payable(msg.sender)).uniswapV3SwapCallback(-signedOut, signedIn, data);
256
+ _ONE_FOR_ZERO_OUTPUT_TOKEN.mint(recipient, AMOUNT_OUT_GIVEN);
257
+ return (-signedOut, signedIn);
238
258
  }
239
259
 
240
260
  function token0() external view override returns (address) {
241
- return _token0;
261
+ return _TOKEN0;
242
262
  }
243
263
 
244
264
  function token1() external view override returns (address) {
245
- return _token1;
265
+ return _TOKEN1;
246
266
  }
247
267
 
248
268
  function tickSpacing() external pure override returns (int24) {
@@ -318,16 +338,7 @@ contract RegistryAddToBalancePartialFillTest is Test {
318
338
  vm.etch(address(factory), hex"00");
319
339
 
320
340
  router = new JBRouterTerminal(
321
- directory,
322
- permissions,
323
- projects,
324
- tokens,
325
- permit2,
326
- owner,
327
- weth,
328
- factory,
329
- IPoolManager(address(0)),
330
- address(0)
341
+ directory, permissions, tokens, permit2, owner, weth, factory, IPoolManager(address(0)), address(0)
331
342
  );
332
343
  registry = new JBRouterTerminalRegistry(permissions, projects, permit2, owner, address(0));
333
344
 
@@ -243,7 +243,6 @@ contract V4QuoteAndSettlementForkTest is Test {
243
243
  routerTerminal = new JBRouterTerminal({
244
244
  directory: jbDirectory,
245
245
  permissions: jbPermissions,
246
- projects: jbProjects,
247
246
  tokens: jbTokens,
248
247
  permit2: PERMIT2,
249
248
  owner: multisig,
@@ -5,7 +5,6 @@ import {Test} from "forge-std/Test.sol";
5
5
 
6
6
  import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
7
7
  import {IJBPermissions} from "@bananapus/core-v6/src/interfaces/IJBPermissions.sol";
8
- import {IJBProjects} from "@bananapus/core-v6/src/interfaces/IJBProjects.sol";
9
8
  import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
10
9
  import {IJBToken} from "@bananapus/core-v6/src/interfaces/IJBToken.sol";
11
10
  import {IJBTokens} from "@bananapus/core-v6/src/interfaces/IJBTokens.sol";
@@ -475,7 +474,7 @@ contract RouterTerminalInvariant is Test {
475
474
  // Mocked protocol contracts.
476
475
  address public mockDirectory;
477
476
  address public mockPermissions;
478
- address public mockProjects;
477
+
479
478
  address public mockTokens;
480
479
  address public mockPermit2;
481
480
  address public mockFactory;
@@ -499,8 +498,6 @@ contract RouterTerminalInvariant is Test {
499
498
  vm.etch(mockDirectory, hex"00");
500
499
  mockPermissions = makeAddr("mockPermissions");
501
500
  vm.etch(mockPermissions, hex"00");
502
- mockProjects = makeAddr("mockProjects");
503
- vm.etch(mockProjects, hex"00");
504
501
  mockTokens = makeAddr("mockTokens");
505
502
  vm.etch(mockTokens, hex"00");
506
503
  mockPermit2 = makeAddr("mockPermit2");
@@ -514,7 +511,6 @@ contract RouterTerminalInvariant is Test {
514
511
  router = new JBRouterTerminal(
515
512
  IJBDirectory(mockDirectory),
516
513
  IJBPermissions(mockPermissions),
517
- IJBProjects(mockProjects),
518
514
  IJBTokens(mockTokens),
519
515
  IPermit2(mockPermit2),
520
516
  address(this), // owner
@@ -6,7 +6,6 @@ import {Test} from "forge-std/Test.sol";
6
6
  import {IJBCashOutTerminal} from "@bananapus/core-v6/src/interfaces/IJBCashOutTerminal.sol";
7
7
  import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
8
8
  import {IJBPermissions} from "@bananapus/core-v6/src/interfaces/IJBPermissions.sol";
9
- import {IJBProjects} from "@bananapus/core-v6/src/interfaces/IJBProjects.sol";
10
9
  import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
11
10
  import {IJBToken} from "@bananapus/core-v6/src/interfaces/IJBToken.sol";
12
11
  import {IJBTokens} from "@bananapus/core-v6/src/interfaces/IJBTokens.sol";
@@ -54,7 +53,7 @@ contract CashOutLoopLimitTest is Test {
54
53
 
55
54
  IJBDirectory directory = IJBDirectory(makeAddr("directory"));
56
55
  IJBPermissions permissions = IJBPermissions(makeAddr("permissions"));
57
- IJBProjects projects = IJBProjects(makeAddr("projects"));
56
+
58
57
  IJBTokens tokens = IJBTokens(makeAddr("tokens"));
59
58
  IPermit2 permit2 = IPermit2(makeAddr("permit2"));
60
59
  IWETH9 weth = IWETH9(makeAddr("weth"));
@@ -75,7 +74,6 @@ contract CashOutLoopLimitTest is Test {
75
74
  function setUp() public {
76
75
  vm.etch(address(directory), hex"00");
77
76
  vm.etch(address(permissions), hex"00");
78
- vm.etch(address(projects), hex"00");
79
77
  vm.etch(address(tokens), hex"00");
80
78
  vm.etch(address(permit2), hex"00");
81
79
  vm.etch(address(weth), hex"00");
@@ -85,7 +83,6 @@ contract CashOutLoopLimitTest is Test {
85
83
  routerTerminal = new JBRouterTerminal(
86
84
  directory,
87
85
  permissions,
88
- projects,
89
86
  tokens,
90
87
  permit2,
91
88
  owner,
@@ -26,7 +26,7 @@ import {IWETH9} from "../../src/interfaces/IWETH9.sol";
26
26
  contract MockERC20 {
27
27
  string public name;
28
28
  string public symbol;
29
- uint8 public immutable decimals = 18;
29
+ uint8 public immutable DECIMALS = 18;
30
30
 
31
31
  mapping(address => uint256) public balanceOf;
32
32
  mapping(address => mapping(address => uint256)) public allowance;
@@ -61,9 +61,9 @@ contract MockERC20 {
61
61
  }
62
62
 
63
63
  contract MockWETH is IWETH9 {
64
- string public constant name = "Wrapped Ether";
65
- string public constant symbol = "WETH";
66
- uint8 public constant decimals = 18;
64
+ string public constant NAME = "Wrapped Ether";
65
+ string public constant SYMBOL = "WETH";
66
+ uint8 public constant DECIMALS = 18;
67
67
  uint256 public totalSupply;
68
68
 
69
69
  mapping(address => uint256) public balanceOf;
@@ -133,6 +133,7 @@ contract MockDestTerminal is IJBTerminal {
133
133
  override
134
134
  returns (JBAccountingContext memory)
135
135
  {
136
+ // forge-lint: disable-next-line(unsafe-typecast)
136
137
  return JBAccountingContext({token: token, decimals: 18, currency: uint32(uint160(token))});
137
138
  }
138
139
 
@@ -177,7 +178,22 @@ contract MockDestTerminal is IJBTerminal {
177
178
  returns (JBRuleset memory, uint256, uint256, JBPayHookSpecification[] memory hookSpecifications)
178
179
  {
179
180
  hookSpecifications = new JBPayHookSpecification[](0);
180
- return (JBRuleset(0, 0, 0, 0, 0, 0, 0, IJBRulesetApprovalHook(address(0)), 0), amount, 0, hookSpecifications);
181
+ return (
182
+ JBRuleset({
183
+ cycleNumber: 0,
184
+ id: 0,
185
+ basedOnId: 0,
186
+ start: 0,
187
+ duration: 0,
188
+ weight: 0,
189
+ weightCutPercent: 0,
190
+ approvalHook: IJBRulesetApprovalHook(address(0)),
191
+ metadata: 0
192
+ }),
193
+ amount,
194
+ 0,
195
+ hookSpecifications
196
+ );
181
197
  }
182
198
 
183
199
  function supportsInterface(bytes4) external pure override returns (bool) {
@@ -186,15 +202,17 @@ contract MockDestTerminal is IJBTerminal {
186
202
  }
187
203
 
188
204
  contract PartialFillPool is IUniswapV3Pool {
189
- address internal immutable _token0;
190
- address internal immutable _token1;
191
- MockERC20 internal immutable _zeroForOneOutputToken;
192
- MockERC20 internal immutable _oneForZeroOutputToken;
205
+ address internal immutable _TOKEN0;
206
+ address internal immutable _TOKEN1;
207
+ MockERC20 internal immutable _ZERO_FOR_ONE_OUTPUT_TOKEN;
208
+ MockERC20 internal immutable _ONE_FOR_ZERO_OUTPUT_TOKEN;
209
+ // forge-lint: disable-next-line(screaming-snake-case-immutable)
193
210
  uint24 public immutable override fee = 3000;
211
+ // forge-lint: disable-next-line(screaming-snake-case-immutable)
194
212
  uint128 public immutable override liquidity = 1_000_000;
195
213
 
196
- uint256 public immutable amountInUsed;
197
- uint256 public immutable amountOutGiven;
214
+ uint256 public immutable AMOUNT_IN_USED;
215
+ uint256 public immutable AMOUNT_OUT_GIVEN;
198
216
 
199
217
  constructor(
200
218
  address token0_,
@@ -204,12 +222,12 @@ contract PartialFillPool is IUniswapV3Pool {
204
222
  uint256 amountInUsed_,
205
223
  uint256 amountOutGiven_
206
224
  ) {
207
- _token0 = token0_;
208
- _token1 = token1_;
209
- _zeroForOneOutputToken = zeroForOneOutputToken_;
210
- _oneForZeroOutputToken = oneForZeroOutputToken_;
211
- amountInUsed = amountInUsed_;
212
- amountOutGiven = amountOutGiven_;
225
+ _TOKEN0 = token0_;
226
+ _TOKEN1 = token1_;
227
+ _ZERO_FOR_ONE_OUTPUT_TOKEN = zeroForOneOutputToken_;
228
+ _ONE_FOR_ZERO_OUTPUT_TOKEN = oneForZeroOutputToken_;
229
+ AMOUNT_IN_USED = amountInUsed_;
230
+ AMOUNT_OUT_GIVEN = amountOutGiven_;
213
231
  }
214
232
 
215
233
  function swap(
@@ -223,24 +241,28 @@ contract PartialFillPool is IUniswapV3Pool {
223
241
  override
224
242
  returns (int256 amount0, int256 amount1)
225
243
  {
244
+ // forge-lint: disable-next-line(unsafe-typecast)
245
+ int256 signedIn = int256(AMOUNT_IN_USED);
246
+ // forge-lint: disable-next-line(unsafe-typecast)
247
+ int256 signedOut = int256(AMOUNT_OUT_GIVEN);
248
+
226
249
  if (zeroForOne) {
227
- JBRouterTerminal(payable(msg.sender))
228
- .uniswapV3SwapCallback(int256(amountInUsed), -int256(amountOutGiven), data);
229
- _zeroForOneOutputToken.mint(recipient, amountOutGiven);
230
- return (int256(amountInUsed), -int256(amountOutGiven));
250
+ JBRouterTerminal(payable(msg.sender)).uniswapV3SwapCallback(signedIn, -signedOut, data);
251
+ _ZERO_FOR_ONE_OUTPUT_TOKEN.mint(recipient, AMOUNT_OUT_GIVEN);
252
+ return (signedIn, -signedOut);
231
253
  }
232
254
 
233
- JBRouterTerminal(payable(msg.sender)).uniswapV3SwapCallback(-int256(amountOutGiven), int256(amountInUsed), data);
234
- _oneForZeroOutputToken.mint(recipient, amountOutGiven);
235
- return (-int256(amountOutGiven), int256(amountInUsed));
255
+ JBRouterTerminal(payable(msg.sender)).uniswapV3SwapCallback(-signedOut, signedIn, data);
256
+ _ONE_FOR_ZERO_OUTPUT_TOKEN.mint(recipient, AMOUNT_OUT_GIVEN);
257
+ return (-signedOut, signedIn);
236
258
  }
237
259
 
238
260
  function token0() external view override returns (address) {
239
- return address(_token0);
261
+ return address(_TOKEN0);
240
262
  }
241
263
 
242
264
  function token1() external view override returns (address) {
243
- return address(_token1);
265
+ return address(_TOKEN1);
244
266
  }
245
267
 
246
268
  function tickSpacing() external pure override returns (int24) {
@@ -318,7 +340,7 @@ contract RouterTerminalEdgeCasesTest is Test {
318
340
  vm.etch(address(factory), hex"00");
319
341
 
320
342
  router = new JBRouterTerminal(
321
- directory, permissions, projects, tokens, permit2, owner, weth, factory, poolManager, address(0)
343
+ directory, permissions, tokens, permit2, owner, weth, factory, poolManager, address(0)
322
344
  );
323
345
  registry = new JBRouterTerminalRegistry(permissions, projects, permit2, owner, address(0));
324
346
  }