@bananapus/router-terminal-v6 0.0.34 → 0.0.36
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
|
@@ -16,7 +16,8 @@ import {IJBPayRoutePreviewer} from "./interfaces/IJBPayRoutePreviewer.sol";
|
|
|
16
16
|
import {IJBPayRouteResolver} from "./interfaces/IJBPayRouteResolver.sol";
|
|
17
17
|
import {IWETH9} from "./interfaces/IWETH9.sol";
|
|
18
18
|
|
|
19
|
-
/// @notice
|
|
19
|
+
/// @notice Evaluates every token a destination project accepts and returns the route that yields the most project
|
|
20
|
+
/// tokens for the beneficiary, deployed as a helper to keep `JBRouterTerminal` within runtime size limits.
|
|
20
21
|
contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
21
22
|
//*********************************************************************//
|
|
22
23
|
// --------------------------- custom errors ------------------------- //
|
|
@@ -578,8 +579,8 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
578
579
|
/// @param amount The current route input amount.
|
|
579
580
|
/// @param metadata Metadata that may include a cashout-source override.
|
|
580
581
|
/// @param preferredToken The preferred token to target during any previewed cashout loop.
|
|
581
|
-
/// @return resolvedTerminal The terminal found by the
|
|
582
|
-
///
|
|
582
|
+
/// @return resolvedTerminal The terminal found by the cashout loop, or address(0) if conversion continues.
|
|
583
|
+
/// @return routedTokenIn The token that remains to be routed after the previewed cashout step.
|
|
583
584
|
/// @return routedAmountIn The amount of `routedTokenIn` that remains to be routed.
|
|
584
585
|
function _previewRouteInputFromSource(
|
|
585
586
|
IJBPayRoutePreviewer router,
|
package/src/JBRouterTerminal.sol
CHANGED
|
@@ -50,9 +50,9 @@ import {JBPayRouteResolver} from "./JBPayRouteResolver.sol";
|
|
|
50
50
|
import {CashOutPathCandidates} from "./structs/CashOutPathCandidates.sol";
|
|
51
51
|
import {PoolInfo} from "./structs/PoolInfo.sol";
|
|
52
52
|
|
|
53
|
-
/// @notice
|
|
54
|
-
///
|
|
55
|
-
///
|
|
53
|
+
/// @notice A universal payment terminal that accepts any token and automatically converts it into whatever token the
|
|
54
|
+
/// destination project accepts. Routes payments via direct forwarding, Uniswap V3/V4 swaps, recursive JB token
|
|
55
|
+
/// cashouts, or a combination — always selecting the path that yields the most project tokens for the beneficiary.
|
|
56
56
|
/// @custom:benediction DEVS BENEDICAT ET PROTEGAT CONTRACTVS MEAM
|
|
57
57
|
contract JBRouterTerminal is
|
|
58
58
|
ERC2771Context,
|
|
@@ -1698,7 +1698,8 @@ contract JBRouterTerminal is
|
|
|
1698
1698
|
if (_unwrapCurrency(currency) == address(0)) _wethDeposit(amount);
|
|
1699
1699
|
}
|
|
1700
1700
|
|
|
1701
|
-
/// @notice
|
|
1701
|
+
/// @notice Transfer tokens from one address to another using direct approval, `safeTransfer`, or Permit2 as a
|
|
1702
|
+
/// fallback.
|
|
1702
1703
|
/// @param from The address to transfer tokens from.
|
|
1703
1704
|
/// @param to The address to transfer tokens to.
|
|
1704
1705
|
/// @param token The address of the token being transferred.
|
|
@@ -27,7 +27,8 @@ import {IJBForwardingTerminal} from "./interfaces/IJBForwardingTerminal.sol";
|
|
|
27
27
|
import {IJBRouterTerminalRegistry} from "./interfaces/IJBRouterTerminalRegistry.sol";
|
|
28
28
|
import {IJBPayerTracker} from "./interfaces/IJBPayerTracker.sol";
|
|
29
29
|
|
|
30
|
-
/// @notice
|
|
30
|
+
/// @notice A forwarding layer that lets each project choose which router terminal receives its payments, with an
|
|
31
|
+
/// owner-managed default for projects that have not opted in. Projects can lock their choice to guarantee permanence.
|
|
31
32
|
contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned, Ownable, ERC2771Context {
|
|
32
33
|
// A library that adds default safety checks to ERC20 functionality.
|
|
33
34
|
using SafeERC20 for IERC20;
|
|
@@ -154,9 +155,29 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
154
155
|
return terminal.accountingContextsOf(projectId);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
/// @notice
|
|
158
|
-
/// @
|
|
159
|
-
|
|
158
|
+
/// @notice Always returns 0 because the registry only forwards funds and does not hold project balances.
|
|
159
|
+
/// @param projectId Unused.
|
|
160
|
+
/// @param tokens Unused.
|
|
161
|
+
/// @param decimals Unused.
|
|
162
|
+
/// @param currency Unused.
|
|
163
|
+
/// @return currentSurplus Always 0.
|
|
164
|
+
function currentSurplusOf(
|
|
165
|
+
uint256 projectId,
|
|
166
|
+
address[] calldata tokens,
|
|
167
|
+
uint256 decimals,
|
|
168
|
+
uint256 currency
|
|
169
|
+
)
|
|
170
|
+
external
|
|
171
|
+
pure
|
|
172
|
+
override
|
|
173
|
+
returns (uint256)
|
|
174
|
+
{
|
|
175
|
+
projectId;
|
|
176
|
+
tokens;
|
|
177
|
+
decimals;
|
|
178
|
+
currency;
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
160
181
|
|
|
161
182
|
/// @notice Preview a payment by forwarding the call to the terminal currently resolved for the project.
|
|
162
183
|
/// @dev Uses the project-specific terminal when set, otherwise falls back to `defaultTerminal`.
|
|
@@ -294,13 +315,14 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
294
315
|
override
|
|
295
316
|
{}
|
|
296
317
|
|
|
297
|
-
/// @notice
|
|
298
|
-
/// @
|
|
318
|
+
/// @notice Add funds to a project's balance by forwarding them through the project's resolved router terminal.
|
|
319
|
+
/// @dev Uses the project-specific terminal when set, otherwise falls back to `defaultTerminal`.
|
|
320
|
+
/// @param projectId The ID of the project receiving the balance addition.
|
|
299
321
|
/// @param token The address of the token being paid in.
|
|
300
322
|
/// @param amount The amount of tokens being paid in.
|
|
301
|
-
/// @param shouldReturnHeldFees
|
|
323
|
+
/// @param shouldReturnHeldFees Whether held fees should be returned based on the amount added.
|
|
302
324
|
/// @param memo A memo to pass along to the emitted event.
|
|
303
|
-
/// @param metadata Bytes in `JBMetadataResolver`'s format.
|
|
325
|
+
/// @param metadata Bytes in `JBMetadataResolver`'s format (may include `permit2` allowance data).
|
|
304
326
|
// slither-disable-next-line reentrancy-benign,reentrancy-eth
|
|
305
327
|
function addToBalanceOf(
|
|
306
328
|
uint256 projectId,
|
|
@@ -350,8 +372,8 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
350
372
|
originalPayer = previousPayer;
|
|
351
373
|
}
|
|
352
374
|
|
|
353
|
-
/// @notice
|
|
354
|
-
/// @dev Only the owner can
|
|
375
|
+
/// @notice Add a terminal to the allowlist so projects can select it as their router.
|
|
376
|
+
/// @dev Only the registry owner can call this.
|
|
355
377
|
/// @param terminal The terminal to allow.
|
|
356
378
|
function allowTerminal(IJBTerminal terminal) external onlyOwner {
|
|
357
379
|
// Mark the terminal as selectable for future project-level configuration.
|
|
@@ -361,8 +383,8 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
361
383
|
emit JBRouterTerminalRegistry_AllowTerminal(terminal, _msgSender());
|
|
362
384
|
}
|
|
363
385
|
|
|
364
|
-
/// @notice
|
|
365
|
-
/// @dev Only the owner can
|
|
386
|
+
/// @notice Remove a terminal from the allowlist so no new projects can select it.
|
|
387
|
+
/// @dev Only the registry owner can call this. Cannot disallow the current default terminal — call
|
|
366
388
|
/// `setDefaultTerminal` to change the default first.
|
|
367
389
|
/// @param terminal The terminal to disallow.
|
|
368
390
|
function disallowTerminal(IJBTerminal terminal) external onlyOwner {
|
|
@@ -378,7 +400,7 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
378
400
|
emit JBRouterTerminalRegistry_DisallowTerminal(terminal, _msgSender());
|
|
379
401
|
}
|
|
380
402
|
|
|
381
|
-
/// @notice
|
|
403
|
+
/// @notice Permanently lock a project's router terminal choice so it can never be changed again.
|
|
382
404
|
/// @dev Only the project's owner or an address with the `JBPermissionIds.SET_ROUTER_TERMINAL` permission can lock.
|
|
383
405
|
/// @dev Circular or self-referential terminals are rejected before the irreversible lock is written.
|
|
384
406
|
/// @param projectId The ID of the project to lock the terminal for.
|
|
@@ -413,26 +435,38 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
413
435
|
emit JBRouterTerminalRegistry_LockTerminal(projectId, _msgSender());
|
|
414
436
|
}
|
|
415
437
|
|
|
416
|
-
/// @notice
|
|
438
|
+
/// @notice Always returns 0 because the registry holds no project balances to migrate.
|
|
439
|
+
/// @param projectId Unused.
|
|
440
|
+
/// @param token Unused.
|
|
441
|
+
/// @param to Unused.
|
|
442
|
+
/// @return balance Always 0.
|
|
417
443
|
function migrateBalanceOf(
|
|
418
444
|
uint256 projectId,
|
|
419
445
|
address token,
|
|
420
446
|
IJBTerminal to
|
|
421
447
|
)
|
|
422
448
|
external
|
|
449
|
+
pure
|
|
423
450
|
override
|
|
424
|
-
returns (uint256
|
|
425
|
-
{
|
|
451
|
+
returns (uint256)
|
|
452
|
+
{
|
|
453
|
+
projectId;
|
|
454
|
+
token;
|
|
455
|
+
to;
|
|
456
|
+
return 0;
|
|
457
|
+
}
|
|
426
458
|
|
|
427
|
-
/// @notice Pay a project by
|
|
459
|
+
/// @notice Pay a project by accepting the caller's tokens and forwarding them to the project's resolved router
|
|
460
|
+
/// terminal.
|
|
461
|
+
/// @dev Uses the project-specific terminal when set, otherwise falls back to `defaultTerminal`.
|
|
428
462
|
/// @param projectId The ID of the project being paid.
|
|
429
463
|
/// @param token The address of the token being paid in.
|
|
430
464
|
/// @param amount The amount of tokens being paid in.
|
|
431
|
-
/// @param beneficiary The
|
|
465
|
+
/// @param beneficiary The address that will receive any project tokens minted by the destination.
|
|
432
466
|
/// @param minReturnedTokens The minimum number of project tokens expected in return.
|
|
433
467
|
/// @param memo A memo to pass along to the emitted event.
|
|
434
|
-
/// @param metadata Bytes in `JBMetadataResolver`'s format.
|
|
435
|
-
/// @return result The number of tokens
|
|
468
|
+
/// @param metadata Bytes in `JBMetadataResolver`'s format (may include `permit2` allowance data).
|
|
469
|
+
/// @return result The number of project tokens minted for the beneficiary.
|
|
436
470
|
// slither-disable-next-line reentrancy-benign,reentrancy-eth
|
|
437
471
|
function pay(
|
|
438
472
|
uint256 projectId,
|
|
@@ -486,8 +520,8 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
486
520
|
originalPayer = previousPayer;
|
|
487
521
|
}
|
|
488
522
|
|
|
489
|
-
/// @notice
|
|
490
|
-
/// @dev Only the owner can
|
|
523
|
+
/// @notice Change the registry-wide default terminal that all projects without an explicit override will use.
|
|
524
|
+
/// @dev Only the registry owner can call this. Automatically allowlists the new default.
|
|
491
525
|
/// @param terminal The terminal to set as the default.
|
|
492
526
|
function setDefaultTerminal(IJBTerminal terminal) external onlyOwner {
|
|
493
527
|
if (address(terminal) == address(0)) revert JBRouterTerminalRegistry_ZeroAddress();
|
|
@@ -501,7 +535,7 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
501
535
|
emit JBRouterTerminalRegistry_SetDefaultTerminal(terminal, _msgSender());
|
|
502
536
|
}
|
|
503
537
|
|
|
504
|
-
/// @notice
|
|
538
|
+
/// @notice Choose which router terminal a project's payments are forwarded through.
|
|
505
539
|
/// @dev Only the project's owner or an address with the `JBPermissionIds.SET_ROUTER_TERMINAL` permission can set.
|
|
506
540
|
/// @param projectId The ID of the project to set the terminal for.
|
|
507
541
|
/// @param terminal The terminal to set for the project.
|
|
@@ -599,7 +633,8 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
599
633
|
return 0;
|
|
600
634
|
}
|
|
601
635
|
|
|
602
|
-
/// @notice
|
|
636
|
+
/// @notice Transfer tokens from one address to another using direct approval, `safeTransfer`, or Permit2 as a
|
|
637
|
+
/// fallback.
|
|
603
638
|
/// @param from The address to transfer tokens from.
|
|
604
639
|
/// @param to The address to transfer tokens to.
|
|
605
640
|
/// @param token The address of the token being transferred.
|
|
@@ -6,9 +6,10 @@ import {mulDiv} from "@prb/math/src/Common.sol";
|
|
|
6
6
|
import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
|
|
7
7
|
|
|
8
8
|
/// @custom:benediction DEVS BENEDICAT ET PROTEGAT CONTRACTVS MEAM
|
|
9
|
-
/// @notice
|
|
10
|
-
///
|
|
11
|
-
///
|
|
9
|
+
/// @notice Math library that computes dynamic slippage tolerances for Uniswap swaps using a continuous sigmoid curve
|
|
10
|
+
/// based on estimated price impact, and derives sqrtPriceLimitX96 values from minimum output amounts.
|
|
11
|
+
/// @dev Uses continuous sigmoid formula instead of stepped if/else brackets for smoother slippage tolerance across all
|
|
12
|
+
/// swap sizes. Floor of 2% (or pool fee + 1%), ceiling of 88%.
|
|
12
13
|
library JBSwapLib {
|
|
13
14
|
/// @notice The denominator used for slippage tolerance basis points.
|
|
14
15
|
uint256 internal constant SLIPPAGE_DENOMINATOR = 10_000;
|