@bananapus/router-terminal-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/package.json +1 -1
- package/src/JBPayRouteResolver.sol +24 -24
- package/src/JBRouterTerminal.sol +91 -92
- package/src/JBRouterTerminalRegistry.sol +28 -28
- package/src/interfaces/IJBPayRoutePreviewer.sol +5 -5
- package/src/interfaces/IJBPayRouteResolver.sol +14 -14
- package/src/interfaces/IJBRouterTerminalRegistry.sol +6 -6
- package/src/libraries/JBForwardingCheck.sol +1 -1
- package/src/libraries/JBSwapLib.sol +2 -2
- package/src/structs/CashOutPathCandidates.sol +5 -5
package/package.json
CHANGED
|
@@ -384,8 +384,8 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
384
384
|
/// @notice Whether previewing through a terminal would cycle back into the router.
|
|
385
385
|
/// @dev Delegates to `JBForwardingCheck.isCircularTerminal` — shared with `JBRouterTerminal` so that
|
|
386
386
|
/// preview and execution use identical cycle-detection logic.
|
|
387
|
-
/// @param router The router whose preview path
|
|
388
|
-
/// @param projectId The project
|
|
387
|
+
/// @param router The router whose preview path to evaluate.
|
|
388
|
+
/// @param projectId The project to resolve forwarding terminal for.
|
|
389
389
|
/// @param terminal The terminal that would receive the previewed route.
|
|
390
390
|
/// @return isCircular A flag indicating whether `terminal` is the router itself or forwards back into it.
|
|
391
391
|
function _isCircularTerminal(
|
|
@@ -408,10 +408,10 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
/// @notice Preview the amount that would be routed into a specific destination token.
|
|
411
|
-
/// @param router The router terminal whose preview helpers
|
|
411
|
+
/// @param router The router terminal whose preview helpers to use.
|
|
412
412
|
/// @param destProjectId The destination project the router is trying to pay.
|
|
413
413
|
/// @param tokenIn The token currently available to route.
|
|
414
|
-
/// @param amount The amount of `tokenIn`
|
|
414
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
415
415
|
/// @param metadata Metadata that may encode cashout-source and route-token overrides.
|
|
416
416
|
/// @param tokenOut The preferred destination token to preview.
|
|
417
417
|
/// @return routedTokenIn The token that would actually be provided to the destination terminal.
|
|
@@ -454,11 +454,11 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
454
454
|
}
|
|
455
455
|
|
|
456
456
|
/// @notice Preview a pay route for a specific destination token.
|
|
457
|
-
/// @param router The router terminal whose preview helpers
|
|
457
|
+
/// @param router The router terminal whose preview helpers to use.
|
|
458
458
|
/// @param projectId The destination project that would receive the payment.
|
|
459
459
|
/// @param tokenIn The token currently available to route.
|
|
460
|
-
/// @param amount The amount of `tokenIn`
|
|
461
|
-
/// @param beneficiary The address
|
|
460
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
461
|
+
/// @param beneficiary The address to measure beneficiary token count for.
|
|
462
462
|
/// @param metadata Metadata forwarded into both the routing preview and terminal preview.
|
|
463
463
|
/// @param tokenOut The candidate destination token to preview.
|
|
464
464
|
/// @param destTerminal The terminal that accepts `tokenOut` for the destination project.
|
|
@@ -526,10 +526,10 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
526
526
|
}
|
|
527
527
|
|
|
528
528
|
/// @notice Preview the fallback route that would be used when no candidate token can be scored directly.
|
|
529
|
-
/// @param router The router terminal whose preview helpers
|
|
530
|
-
/// @param destProjectId The destination project
|
|
529
|
+
/// @param router The router terminal whose preview helpers to use.
|
|
530
|
+
/// @param destProjectId The destination project to pay.
|
|
531
531
|
/// @param tokenIn The token currently available to route.
|
|
532
|
-
/// @param amount The amount of `tokenIn`
|
|
532
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
533
533
|
/// @param metadata Metadata forwarded into preview helpers.
|
|
534
534
|
/// @return destTerminal The terminal the router would use.
|
|
535
535
|
/// @return tokenOut The token `destTerminal` would receive.
|
|
@@ -573,7 +573,7 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
573
573
|
}
|
|
574
574
|
|
|
575
575
|
/// @notice Preview how the current route input would change after cashing out a project-token source if needed.
|
|
576
|
-
/// @param router The router terminal whose preview helpers
|
|
576
|
+
/// @param router The router terminal whose preview helpers to use.
|
|
577
577
|
/// @param destProjectId The destination project the route is trying to reach.
|
|
578
578
|
/// @param tokenIn The current route input token.
|
|
579
579
|
/// @param amount The current route input amount.
|
|
@@ -614,9 +614,9 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
614
614
|
}
|
|
615
615
|
|
|
616
616
|
/// @notice Resolve what output token a project accepts for a given input token.
|
|
617
|
-
/// @param router The router whose view helpers
|
|
618
|
-
/// @param projectId The destination project
|
|
619
|
-
/// @param tokenIn The input token
|
|
617
|
+
/// @param router The router whose view helpers to use.
|
|
618
|
+
/// @param projectId The destination project to pay.
|
|
619
|
+
/// @param tokenIn The input token to route.
|
|
620
620
|
/// @param metadata Metadata forwarded into route-token resolution.
|
|
621
621
|
/// @return tokenOut The token the project accepts.
|
|
622
622
|
/// @return destTerminal The terminal that accepts `tokenOut`.
|
|
@@ -688,7 +688,7 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
688
688
|
|
|
689
689
|
/// @notice Best-effort terminal lookup that degrades to an empty list if the directory call reverts.
|
|
690
690
|
/// @param directory The directory storing project terminal relationships.
|
|
691
|
-
/// @param projectId The project
|
|
691
|
+
/// @param projectId The project to look up terminals for.
|
|
692
692
|
/// @return terminals The terminal list, or an empty list if the directory call failed.
|
|
693
693
|
function _safeTerminalsOf(
|
|
694
694
|
IJBDirectory directory,
|
|
@@ -710,7 +710,7 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
710
710
|
}
|
|
711
711
|
|
|
712
712
|
/// @notice Scale a known beneficiary/reserved token split to a different total token count.
|
|
713
|
-
/// @param tokenCount The total token count
|
|
713
|
+
/// @param tokenCount The total token count to score.
|
|
714
714
|
/// @param referenceTokenCount The total token count the reference split was computed from.
|
|
715
715
|
/// @param referenceBeneficiaryTokenCount The beneficiary share of the reference split.
|
|
716
716
|
/// @param referenceReservedTokenCount The reserved share of the reference split.
|
|
@@ -812,9 +812,9 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
812
812
|
}
|
|
813
813
|
|
|
814
814
|
/// @notice Resolve the usable primary terminal for a discovered candidate token.
|
|
815
|
-
/// @param router The router whose circular-terminal rule
|
|
815
|
+
/// @param router The router whose circular-terminal rule to apply.
|
|
816
816
|
/// @param directory The directory used to resolve primary terminals.
|
|
817
|
-
/// @param projectId The destination project
|
|
817
|
+
/// @param projectId The destination project to inspect.
|
|
818
818
|
/// @param candidateToken The discovered accepted token candidate.
|
|
819
819
|
/// @return candidateTerminal The candidate token's primary terminal, or address(0) if unusable.
|
|
820
820
|
function _usablePrimaryTerminalForCandidate(
|
|
@@ -997,10 +997,10 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
997
997
|
/// `self.previewFallbackRoute(...)` so that a revert in the fallback path (e.g. a broken terminal or
|
|
998
998
|
/// price feed) is caught instead of bricking the entire best-route preview.
|
|
999
999
|
/// @dev This function should only be called by this contract itself — external callers have no reason to use it.
|
|
1000
|
-
/// @param routePreviewer The router terminal whose preview helpers
|
|
1001
|
-
/// @param destProjectId The project
|
|
1000
|
+
/// @param routePreviewer The router terminal whose preview helpers to use for simulating the route.
|
|
1001
|
+
/// @param destProjectId The project to pay through the fallback route.
|
|
1002
1002
|
/// @param tokenIn The token the payer is sending.
|
|
1003
|
-
/// @param amountIn The amount of `tokenIn`
|
|
1003
|
+
/// @param amountIn The amount of `tokenIn` to route.
|
|
1004
1004
|
/// @param beneficiary The address that would receive minted project tokens.
|
|
1005
1005
|
/// @param metadata Arbitrary bytes forwarded into route and terminal pay previews.
|
|
1006
1006
|
/// @return destTerminal The terminal the fallback route would deliver funds to.
|
|
@@ -1055,11 +1055,11 @@ contract JBPayRouteResolver is IJBPayRouteResolver {
|
|
|
1055
1055
|
}
|
|
1056
1056
|
|
|
1057
1057
|
/// @notice External wrapper so candidate previews can be isolated with `try/catch`.
|
|
1058
|
-
/// @param router The router terminal whose preview helpers
|
|
1058
|
+
/// @param router The router terminal whose preview helpers to use.
|
|
1059
1059
|
/// @param projectId The destination project that would receive the payment.
|
|
1060
1060
|
/// @param tokenIn The token currently available to route.
|
|
1061
|
-
/// @param amount The amount of `tokenIn`
|
|
1062
|
-
/// @param beneficiary The address
|
|
1061
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
1062
|
+
/// @param beneficiary The address to measure beneficiary token count for.
|
|
1063
1063
|
/// @param metadata Metadata forwarded into both the routing preview and terminal preview.
|
|
1064
1064
|
/// @param tokenOut The candidate destination token to preview.
|
|
1065
1065
|
/// @param destTerminal The terminal that accepts `tokenOut` for the destination project.
|
package/src/JBRouterTerminal.sol
CHANGED
|
@@ -130,7 +130,7 @@ contract JBRouterTerminal is
|
|
|
130
130
|
/// @notice The Uniswap V3 factory used for pool discovery and verification.
|
|
131
131
|
IUniswapV3Factory public immutable FACTORY;
|
|
132
132
|
|
|
133
|
-
/// @notice The
|
|
133
|
+
/// @notice The Permit2 contract used for token approvals and transfers.
|
|
134
134
|
IPermit2 public immutable override PERMIT2;
|
|
135
135
|
|
|
136
136
|
/// @notice The Uniswap V4 PoolManager. Can be address(0) if V4 is not deployed on this chain.
|
|
@@ -234,8 +234,8 @@ contract JBRouterTerminal is
|
|
|
234
234
|
|
|
235
235
|
/// @notice Add funds to a project's balance by routing the incoming token to whatever token the project accepts.
|
|
236
236
|
/// @param projectId The ID of the destination project.
|
|
237
|
-
/// @param token The address of the token
|
|
238
|
-
/// @param amount The amount of tokens
|
|
237
|
+
/// @param token The address of the token to pay in.
|
|
238
|
+
/// @param amount The amount of tokens to send.
|
|
239
239
|
/// @param shouldReturnHeldFees Whether held fees should be returned based on the amount added.
|
|
240
240
|
/// @param memo A memo to pass along to the emitted event.
|
|
241
241
|
/// @param metadata Bytes in `JBMetadataResolver`'s format.
|
|
@@ -317,9 +317,9 @@ contract JBRouterTerminal is
|
|
|
317
317
|
|
|
318
318
|
/// @notice Pay a project by routing the incoming token to whatever token the project accepts.
|
|
319
319
|
/// @dev Automatically handles direct forwarding, Uniswap swaps, JB token cashouts, or combinations.
|
|
320
|
-
/// @param projectId The ID of the destination project
|
|
321
|
-
/// @param token The address of the token
|
|
322
|
-
/// @param amount The amount of tokens
|
|
320
|
+
/// @param projectId The ID of the destination project to pay.
|
|
321
|
+
/// @param token The address of the token to pay with.
|
|
322
|
+
/// @param amount The amount of tokens to send.
|
|
323
323
|
/// @param beneficiary The address to receive any tokens minted by the destination project.
|
|
324
324
|
/// @param minReturnedTokens The minimum number of destination project tokens expected in return.
|
|
325
325
|
/// @param memo A memo to pass along to the emitted event.
|
|
@@ -381,8 +381,8 @@ contract JBRouterTerminal is
|
|
|
381
381
|
|
|
382
382
|
/// @notice The Uniswap v3 pool callback where the token transfer is expected to happen.
|
|
383
383
|
/// @dev Verifies the caller is a legitimate pool via the factory using the encoded tokenIn/tokenOut pair.
|
|
384
|
-
/// @param amount0Delta The amount of token 0
|
|
385
|
-
/// @param amount1Delta The amount of token 1
|
|
384
|
+
/// @param amount0Delta The amount of token 0 used for the swap.
|
|
385
|
+
/// @param amount1Delta The amount of token 1 used for the swap.
|
|
386
386
|
/// @param data Data passed in by the swap operation: abi.encode(projectId, tokenIn, tokenOut).
|
|
387
387
|
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external override {
|
|
388
388
|
// Unpack the data from the original swap config.
|
|
@@ -473,7 +473,7 @@ contract JBRouterTerminal is
|
|
|
473
473
|
/// @notice Returns a best-effort accounting context for any token the router can route.
|
|
474
474
|
/// @dev This surface is still synthetic for routing discovery, but it probes ERC-20 decimals when available and
|
|
475
475
|
/// falls back to 18 if a token omits or breaks `decimals()`.
|
|
476
|
-
/// @param token The address of the token to get
|
|
476
|
+
/// @param token The address of the token to get accounting context for.
|
|
477
477
|
function accountingContextForTokenOf(
|
|
478
478
|
uint256,
|
|
479
479
|
address token
|
|
@@ -579,9 +579,9 @@ contract JBRouterTerminal is
|
|
|
579
579
|
|
|
580
580
|
/// @notice Preview a payment by simulating the router's routing logic in view context.
|
|
581
581
|
/// @dev Returns the router's best estimate using current routing and quote data, including swap quotes when needed.
|
|
582
|
-
/// @param projectId The ID of the destination project
|
|
583
|
-
/// @param token The token
|
|
584
|
-
/// @param amount The amount of the input token
|
|
582
|
+
/// @param projectId The ID of the destination project to pay.
|
|
583
|
+
/// @param token The token to provide to the router.
|
|
584
|
+
/// @param amount The amount of the input token to provide.
|
|
585
585
|
/// @param beneficiary The address that would receive any minted project tokens.
|
|
586
586
|
/// @param metadata Extra data used to preview fund acceptance, routing, and the destination terminal call.
|
|
587
587
|
/// @return ruleset The current ruleset the destination terminal would use.
|
|
@@ -613,8 +613,8 @@ contract JBRouterTerminal is
|
|
|
613
613
|
|
|
614
614
|
/// @notice Preview the recursive cashout loop the router would use for a project-token input.
|
|
615
615
|
/// @param destProjectId The destination project the router is trying to pay.
|
|
616
|
-
/// @param token The current token
|
|
617
|
-
/// @param amount The amount of `token`
|
|
616
|
+
/// @param token The current token to route.
|
|
617
|
+
/// @param amount The amount of `token` to preview.
|
|
618
618
|
/// @param sourceProjectIdOverride The one-shot source project override encoded in metadata, if any.
|
|
619
619
|
/// @param metadata Metadata forwarded into preview helpers.
|
|
620
620
|
/// @param preferredToken The token the cashout loop should prefer to land on, or `address(0)` for no preference.
|
|
@@ -646,7 +646,7 @@ contract JBRouterTerminal is
|
|
|
646
646
|
/// @notice Preview the amount a direct token-to-token swap would return.
|
|
647
647
|
/// @param tokenIn The input token.
|
|
648
648
|
/// @param tokenOut The output token.
|
|
649
|
-
/// @param amount The amount of `tokenIn`
|
|
649
|
+
/// @param amount The amount of `tokenIn` to swap.
|
|
650
650
|
/// @param metadata Metadata forwarded into quote selection.
|
|
651
651
|
/// @return amountOut The quoted amount of `tokenOut`.
|
|
652
652
|
function previewSwapAmountOutOf(
|
|
@@ -663,11 +663,11 @@ contract JBRouterTerminal is
|
|
|
663
663
|
}
|
|
664
664
|
|
|
665
665
|
/// @notice Preview a destination terminal payment from the router's caller context.
|
|
666
|
-
/// @param destTerminal The terminal whose pay preview
|
|
666
|
+
/// @param destTerminal The terminal whose pay preview to query.
|
|
667
667
|
/// @param projectId The destination project that would receive the payment.
|
|
668
668
|
/// @param token The token the destination terminal would receive.
|
|
669
669
|
/// @param amount The amount of `token` the destination terminal would receive.
|
|
670
|
-
/// @param beneficiary The address
|
|
670
|
+
/// @param beneficiary The address to measure beneficiary token count for.
|
|
671
671
|
/// @param metadata Metadata forwarded unchanged into the destination terminal preview.
|
|
672
672
|
/// @return ruleset The ruleset returned by the destination terminal preview.
|
|
673
673
|
/// @return beneficiaryTokenCount The beneficiary token count returned by the destination terminal preview.
|
|
@@ -706,7 +706,7 @@ contract JBRouterTerminal is
|
|
|
706
706
|
/// @notice Indicates if this contract adheres to the specified interface.
|
|
707
707
|
/// @dev See {IERC165-supportsInterface}.
|
|
708
708
|
/// @param interfaceId The ID of the interface to check for adherence to.
|
|
709
|
-
/// @return A flag indicating
|
|
709
|
+
/// @return A flag indicating whether the provided interface ID is supported.
|
|
710
710
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
711
711
|
return interfaceId == type(IJBTerminal).interfaceId || interfaceId == type(IJBPermitTerminal).interfaceId
|
|
712
712
|
|| interfaceId == type(IJBRouterTerminal).interfaceId || interfaceId == type(IERC165).interfaceId;
|
|
@@ -732,12 +732,12 @@ contract JBRouterTerminal is
|
|
|
732
732
|
}
|
|
733
733
|
|
|
734
734
|
/// @notice Route a payment using the destination token that yields the highest previewed beneficiary output.
|
|
735
|
-
/// @param destProjectId The project
|
|
735
|
+
/// @param destProjectId The project to route the payment to.
|
|
736
736
|
/// @param tokenIn The token currently held by the router for this payment.
|
|
737
737
|
/// @param amount The amount of `tokenIn` available to route.
|
|
738
|
-
/// @param beneficiary The address whose beneficiary token count
|
|
738
|
+
/// @param beneficiary The address whose beneficiary token count to maximize.
|
|
739
739
|
/// @param metadata Metadata forwarded into route discovery and the final destination payment.
|
|
740
|
-
/// @param refundTo The address
|
|
740
|
+
/// @param refundTo The address to receive any leftover input tokens from partial fills.
|
|
741
741
|
/// @return destTerminal The terminal selected for the winning route.
|
|
742
742
|
/// @return tokenOut The token `destTerminal` should receive for the winning route.
|
|
743
743
|
/// @return amountOut The amount of `tokenOut` that will be delivered to `destTerminal`.
|
|
@@ -824,10 +824,10 @@ contract JBRouterTerminal is
|
|
|
824
824
|
}
|
|
825
825
|
|
|
826
826
|
/// @notice Preview the best pay route using the resolver helper.
|
|
827
|
-
/// @param projectId The destination project
|
|
827
|
+
/// @param projectId The destination project to pay.
|
|
828
828
|
/// @param tokenIn The token currently available to route.
|
|
829
|
-
/// @param amount The amount of `tokenIn`
|
|
830
|
-
/// @param beneficiary The address whose minted token count
|
|
829
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
830
|
+
/// @param beneficiary The address whose minted token count to optimize.
|
|
831
831
|
/// @param metadata Metadata forwarded into route and pay previews.
|
|
832
832
|
/// @return destTerminal The terminal chosen for the best previewed route.
|
|
833
833
|
/// @return tokenOut The token `destTerminal` would receive.
|
|
@@ -870,7 +870,7 @@ contract JBRouterTerminal is
|
|
|
870
870
|
/// @notice Preview the output amount for a direct token-to-token swap route.
|
|
871
871
|
/// @param tokenIn The token currently available to swap.
|
|
872
872
|
/// @param tokenOut The token the swap should deliver.
|
|
873
|
-
/// @param amount The amount of `tokenIn`
|
|
873
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
874
874
|
/// @param metadata Metadata that can provide an explicit quote override for the swap.
|
|
875
875
|
/// @return amountOut The predicted amount of `tokenOut` the router would receive.
|
|
876
876
|
function _previewSwapAmountOut(
|
|
@@ -911,7 +911,7 @@ contract JBRouterTerminal is
|
|
|
911
911
|
/// `_isForwardingTerminal` calls in the pay/addToBalance flows.
|
|
912
912
|
/// @param terminal The destination terminal that will receive the final forwarded funds.
|
|
913
913
|
/// @param token The token the terminal is expected to receive.
|
|
914
|
-
/// @param projectId The project
|
|
914
|
+
/// @param projectId The project to check forwarding status for.
|
|
915
915
|
/// @return receiptBaseline The terminal's balance in `token` before the final forwarded call.
|
|
916
916
|
/// @return isForwarding Whether the terminal forwards calls onward.
|
|
917
917
|
function _terminalReceiptBaselineOf(
|
|
@@ -965,8 +965,8 @@ contract JBRouterTerminal is
|
|
|
965
965
|
}
|
|
966
966
|
|
|
967
967
|
/// @notice Whether a terminal forwards terminal-facing calls onward instead of acting as the final receiver.
|
|
968
|
-
/// @param terminal The terminal
|
|
969
|
-
/// @param projectId The project
|
|
968
|
+
/// @param terminal The terminal to check for forwarding behavior.
|
|
969
|
+
/// @param projectId The project to resolve forwarding target for.
|
|
970
970
|
/// @return isForwarding A flag indicating whether receipt enforcement should be delegated to `terminal`.
|
|
971
971
|
function _isForwardingTerminal(IJBTerminal terminal, uint256 projectId) internal view returns (bool isForwarding) {
|
|
972
972
|
// Probe via staticcall so non-forwarding terminals degrade cleanly.
|
|
@@ -981,7 +981,7 @@ contract JBRouterTerminal is
|
|
|
981
981
|
|
|
982
982
|
/// @notice Return a project's primary terminal only if the router can safely forward into it.
|
|
983
983
|
/// @dev Inlined from the resolver to avoid a cross-contract roundtrip (saves 3 external calls per lookup).
|
|
984
|
-
/// @param projectId The project
|
|
984
|
+
/// @param projectId The project to check the primary terminal for.
|
|
985
985
|
/// @param token The token that terminal should accept.
|
|
986
986
|
/// @return terminal The usable primary terminal, or address(0) if none is usable.
|
|
987
987
|
function _usablePrimaryTerminalOf(uint256 projectId, address token) internal view returns (IJBTerminal terminal) {
|
|
@@ -1009,7 +1009,7 @@ contract JBRouterTerminal is
|
|
|
1009
1009
|
|
|
1010
1010
|
/// @notice Resolve which source project a routed token should cash out from.
|
|
1011
1011
|
/// @param sourceProjectIdOverride A one-shot source-project override decoded from routing metadata.
|
|
1012
|
-
/// @param token The current route token that may
|
|
1012
|
+
/// @param token The current route token that may be a JB project token.
|
|
1013
1013
|
/// @return sourceProjectId The project to cash out from, or 0 if the token is not a JB project token.
|
|
1014
1014
|
function _sourceProjectIdOf(
|
|
1015
1015
|
uint256 sourceProjectIdOverride,
|
|
@@ -1029,11 +1029,11 @@ contract JBRouterTerminal is
|
|
|
1029
1029
|
}
|
|
1030
1030
|
}
|
|
1031
1031
|
|
|
1032
|
-
/// @notice
|
|
1033
|
-
/// @param token The address of the token
|
|
1034
|
-
/// @param amount The amount of tokens
|
|
1032
|
+
/// @notice Accept a token paid in by the caller.
|
|
1033
|
+
/// @param token The address of the token to accept.
|
|
1034
|
+
/// @param amount The amount of tokens to accept.
|
|
1035
1035
|
/// @param metadata The metadata in which `permit2` and credit context is provided.
|
|
1036
|
-
/// @return The amount of tokens
|
|
1036
|
+
/// @return The amount of tokens accepted.
|
|
1037
1037
|
function _acceptFundsFor(address token, uint256 amount, bytes calldata metadata) internal returns (uint256) {
|
|
1038
1038
|
// Cache _msgSender() once to avoid repeated ERC-2771 context resolution.
|
|
1039
1039
|
address sender = _msgSender();
|
|
@@ -1115,9 +1115,9 @@ contract JBRouterTerminal is
|
|
|
1115
1115
|
if (token != JBConstants.NATIVE_TOKEN) IERC20(token).forceApprove({spender: address(destTerminal), value: 0});
|
|
1116
1116
|
}
|
|
1117
1117
|
|
|
1118
|
-
/// @notice Logic to
|
|
1118
|
+
/// @notice Logic to trigger before transferring tokens from this terminal.
|
|
1119
1119
|
/// @param to The address to transfer tokens to.
|
|
1120
|
-
/// @param token The token
|
|
1120
|
+
/// @param token The token to transfer.
|
|
1121
1121
|
/// @param amount The amount of tokens to transfer.
|
|
1122
1122
|
/// @return payValue The amount that will be paid as a `msg.value`.
|
|
1123
1123
|
function _beforeTransferFor(address to, address token, uint256 amount) internal returns (uint256) {
|
|
@@ -1131,7 +1131,7 @@ contract JBRouterTerminal is
|
|
|
1131
1131
|
}
|
|
1132
1132
|
|
|
1133
1133
|
/// @notice Snapshot the normalized input-token balance used to measure refundable leftovers for one route.
|
|
1134
|
-
/// @param tokenIn The token
|
|
1134
|
+
/// @param tokenIn The token to route.
|
|
1135
1135
|
/// @param amount The fresh route input amount currently held by the router.
|
|
1136
1136
|
/// @return baseline The normalized input-token balance attributable only to pre-existing funds.
|
|
1137
1137
|
function _refundBalanceBaselineOf(address tokenIn, uint256 amount) internal view returns (uint256 baseline) {
|
|
@@ -1144,7 +1144,7 @@ contract JBRouterTerminal is
|
|
|
1144
1144
|
|
|
1145
1145
|
/// @notice Recursively cash out JB project tokens until reaching a token the destination accepts or a base token.
|
|
1146
1146
|
/// @param destProjectId The ID of the destination project.
|
|
1147
|
-
/// @param token The current token
|
|
1147
|
+
/// @param token The current token to process.
|
|
1148
1148
|
/// @param amount The amount of the current token.
|
|
1149
1149
|
/// @param sourceProjectIdOverride When non-zero, use this as the source project ID instead of looking up via
|
|
1150
1150
|
/// `TOKENS.projectIdOf()`. Reset to 0 after first use.
|
|
@@ -1254,7 +1254,7 @@ contract JBRouterTerminal is
|
|
|
1254
1254
|
|
|
1255
1255
|
/// @notice Convert tokenIn to tokenOut. No-op if same, wrap/unwrap for NATIVE/WETH, or swap via Uniswap.
|
|
1256
1256
|
/// @param tokenIn The token to convert from.
|
|
1257
|
-
/// @param tokenOut The token to convert
|
|
1257
|
+
/// @param tokenOut The token to convert into.
|
|
1258
1258
|
/// @param amount The amount to convert.
|
|
1259
1259
|
/// @param projectId The project ID (passed through to swap callback data).
|
|
1260
1260
|
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain quoteForSwap).
|
|
@@ -1299,8 +1299,8 @@ contract JBRouterTerminal is
|
|
|
1299
1299
|
|
|
1300
1300
|
/// @notice Discover a pool, get a quote, and execute the swap (dispatches to V3 or V4).
|
|
1301
1301
|
/// @dev Separated from _handleSwap to manage stack depth.
|
|
1302
|
-
/// @param normalizedTokenIn The normalized token
|
|
1303
|
-
/// @param normalizedTokenOut The normalized token
|
|
1302
|
+
/// @param normalizedTokenIn The normalized token to swap in.
|
|
1303
|
+
/// @param normalizedTokenOut The normalized token to swap out.
|
|
1304
1304
|
/// @param amount The amount of `normalizedTokenIn` to swap.
|
|
1305
1305
|
/// @param metadata Bytes in `JBMetadataResolver`'s format, used for quote overrides.
|
|
1306
1306
|
/// @param callbackData ABI-encoded callback data for the V3 swap path.
|
|
@@ -1348,8 +1348,8 @@ contract JBRouterTerminal is
|
|
|
1348
1348
|
|
|
1349
1349
|
/// @notice Execute a swap through a V3 pool.
|
|
1350
1350
|
/// @param pool The V3 pool to swap through.
|
|
1351
|
-
/// @param normalizedTokenIn The normalized token
|
|
1352
|
-
/// @param normalizedTokenOut The normalized token
|
|
1351
|
+
/// @param normalizedTokenIn The normalized token to sell.
|
|
1352
|
+
/// @param normalizedTokenOut The normalized token to buy.
|
|
1353
1353
|
/// @param amount The exact input amount to swap.
|
|
1354
1354
|
/// @param minAmountOut The minimum acceptable output after slippage protection.
|
|
1355
1355
|
/// @param callbackData ABI-encoded data that the V3 callback will use to settle the input side.
|
|
@@ -1396,7 +1396,7 @@ contract JBRouterTerminal is
|
|
|
1396
1396
|
|
|
1397
1397
|
/// @notice Execute a swap through a V4 pool via PoolManager.unlock().
|
|
1398
1398
|
/// @param key The V4 pool key describing the pool to swap through.
|
|
1399
|
-
/// @param normalizedTokenIn The normalized token
|
|
1399
|
+
/// @param normalizedTokenIn The normalized token to swap in.
|
|
1400
1400
|
/// @param canUseExistingNativeBalance Whether raw ETH already held by the router can fund the input side.
|
|
1401
1401
|
/// @param amount The amount of `normalizedTokenIn` to swap.
|
|
1402
1402
|
/// @param minAmountOut The minimum acceptable amount out for the swap.
|
|
@@ -1436,8 +1436,8 @@ contract JBRouterTerminal is
|
|
|
1436
1436
|
|
|
1437
1437
|
/// @notice Execute a Uniswap swap from tokenIn to tokenOut (V3 or V4).
|
|
1438
1438
|
/// @param projectId The project ID (included in callback data).
|
|
1439
|
-
/// @param tokenIn The
|
|
1440
|
-
/// @param tokenOut The
|
|
1439
|
+
/// @param tokenIn The token to swap from.
|
|
1440
|
+
/// @param tokenOut The token to swap into.
|
|
1441
1441
|
/// @param amount The amount of tokenIn to swap.
|
|
1442
1442
|
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain quoteForSwap).
|
|
1443
1443
|
/// @param refundTo The address to receive leftover input tokens from partial fills.
|
|
@@ -1490,8 +1490,8 @@ contract JBRouterTerminal is
|
|
|
1490
1490
|
/// @notice Core routing logic shared by pay() and addToBalanceOf().
|
|
1491
1491
|
/// @dev Determines whether to forward directly, cashout JB tokens, swap via Uniswap, or a combination.
|
|
1492
1492
|
/// @param destProjectId The ID of the destination project.
|
|
1493
|
-
/// @param tokenIn The address of the token
|
|
1494
|
-
/// @param amount The amount of tokens
|
|
1493
|
+
/// @param tokenIn The address of the token to route.
|
|
1494
|
+
/// @param amount The amount of tokens to route.
|
|
1495
1495
|
/// @param metadata Bytes in `JBMetadataResolver`'s format.
|
|
1496
1496
|
/// @param refundTo The address to receive leftover input tokens from partial fills.
|
|
1497
1497
|
/// @return destTerminal The terminal to forward funds to.
|
|
@@ -1537,12 +1537,12 @@ contract JBRouterTerminal is
|
|
|
1537
1537
|
}
|
|
1538
1538
|
|
|
1539
1539
|
/// @notice Route funds to a specific destination token.
|
|
1540
|
-
/// @param destProjectId The project
|
|
1540
|
+
/// @param destProjectId The project to route the payment to.
|
|
1541
1541
|
/// @param tokenIn The token currently held by the router for this route.
|
|
1542
1542
|
/// @param amount The amount of `tokenIn` available to route.
|
|
1543
|
-
/// @param tokenOut The destination token
|
|
1543
|
+
/// @param tokenOut The destination token for the project to receive.
|
|
1544
1544
|
/// @param metadata Metadata forwarded into any source cashout and swap logic.
|
|
1545
|
-
/// @param refundTo The address
|
|
1545
|
+
/// @param refundTo The address to receive any leftover input tokens from partial fills.
|
|
1546
1546
|
/// @return destTerminal The terminal that accepts the resolved destination token.
|
|
1547
1547
|
/// @return resolvedTokenOut The concrete destination token the router routed into.
|
|
1548
1548
|
/// @return amountOut The amount of `resolvedTokenOut` that will be delivered to `destTerminal`.
|
|
@@ -1588,7 +1588,7 @@ contract JBRouterTerminal is
|
|
|
1588
1588
|
}
|
|
1589
1589
|
|
|
1590
1590
|
/// @notice Route the current input through a project-token cashout first when the route starts from a JB token.
|
|
1591
|
-
/// @param destProjectId The destination project
|
|
1591
|
+
/// @param destProjectId The destination project to reach.
|
|
1592
1592
|
/// @param tokenIn The current route input token.
|
|
1593
1593
|
/// @param amount The current route input amount.
|
|
1594
1594
|
/// @param metadata Metadata that may include a cashout-source override.
|
|
@@ -1659,8 +1659,8 @@ contract JBRouterTerminal is
|
|
|
1659
1659
|
}
|
|
1660
1660
|
|
|
1661
1661
|
/// @notice Settle the input side of a V4 swap by transferring the owed input asset into the PoolManager.
|
|
1662
|
-
/// @param currency The V4 currency
|
|
1663
|
-
/// @param amount The amount of `currency`
|
|
1662
|
+
/// @param currency The V4 currency to settle with the PoolManager.
|
|
1663
|
+
/// @param amount The amount of `currency` to settle.
|
|
1664
1664
|
/// @param canUseExistingNativeBalance Whether already-held raw ETH can be used before unwrapping WETH.
|
|
1665
1665
|
function _settleV4(Currency currency, uint256 amount, bool canUseExistingNativeBalance) internal {
|
|
1666
1666
|
if (_unwrapCurrency(currency) == address(0)) {
|
|
@@ -1687,8 +1687,8 @@ contract JBRouterTerminal is
|
|
|
1687
1687
|
}
|
|
1688
1688
|
}
|
|
1689
1689
|
|
|
1690
|
-
/// @notice Take the output side of a V4 swap by pulling the owed asset
|
|
1691
|
-
/// @param currency The V4 currency
|
|
1690
|
+
/// @notice Take the output side of a V4 swap by pulling the owed asset from the PoolManager.
|
|
1691
|
+
/// @param currency The V4 currency to take from the PoolManager.
|
|
1692
1692
|
/// @param amount The amount of `currency` to take.
|
|
1693
1693
|
function _takeV4(Currency currency, uint256 amount) internal {
|
|
1694
1694
|
// Pull the owed output asset into the router before any later wrapping/unwrapping or forwarding logic runs.
|
|
@@ -1702,7 +1702,7 @@ contract JBRouterTerminal is
|
|
|
1702
1702
|
/// fallback.
|
|
1703
1703
|
/// @param from The address to transfer tokens from.
|
|
1704
1704
|
/// @param to The address to transfer tokens to.
|
|
1705
|
-
/// @param token The address of the token
|
|
1705
|
+
/// @param token The address of the token to transfer.
|
|
1706
1706
|
/// @param amount The amount of tokens to transfer.
|
|
1707
1707
|
function _transferFrom(address from, address payable to, address token, uint256 amount) internal {
|
|
1708
1708
|
if (from == address(this)) {
|
|
@@ -1757,14 +1757,14 @@ contract JBRouterTerminal is
|
|
|
1757
1757
|
return (token, amount);
|
|
1758
1758
|
}
|
|
1759
1759
|
|
|
1760
|
-
/// @notice
|
|
1760
|
+
/// @notice Wrap native tokens into WETH.
|
|
1761
1761
|
/// @param amount The amount of native tokens to wrap.
|
|
1762
1762
|
// slither-disable-next-line calls-loop
|
|
1763
1763
|
function _wethDeposit(uint256 amount) internal {
|
|
1764
1764
|
WETH.deposit{value: amount}();
|
|
1765
1765
|
}
|
|
1766
1766
|
|
|
1767
|
-
/// @notice
|
|
1767
|
+
/// @notice Unwrap WETH into native tokens.
|
|
1768
1768
|
/// @param amount The amount of WETH to unwrap.
|
|
1769
1769
|
// slither-disable-next-line calls-loop
|
|
1770
1770
|
function _wethWithdraw(uint256 amount) internal {
|
|
@@ -1775,7 +1775,7 @@ contract JBRouterTerminal is
|
|
|
1775
1775
|
// ------------------------- internal views -------------------------- //
|
|
1776
1776
|
//*********************************************************************//
|
|
1777
1777
|
|
|
1778
|
-
/// @notice Look up
|
|
1778
|
+
/// @notice Look up a pool address from the V3 factory.
|
|
1779
1779
|
/// @param tokenA One token in the pair.
|
|
1780
1780
|
/// @param tokenB The other token in the pair.
|
|
1781
1781
|
/// @param fee The fee tier to query.
|
|
@@ -1785,15 +1785,15 @@ contract JBRouterTerminal is
|
|
|
1785
1785
|
return FACTORY.getPool({tokenA: tokenA, tokenB: tokenB, fee: fee});
|
|
1786
1786
|
}
|
|
1787
1787
|
|
|
1788
|
-
/// @notice Look up the in-range liquidity
|
|
1789
|
-
/// @param id The pool ID.
|
|
1788
|
+
/// @notice Look up the in-range liquidity of a V4 pool.
|
|
1789
|
+
/// @param id The pool ID to query.
|
|
1790
1790
|
/// @return The pool's current in-range liquidity.
|
|
1791
1791
|
function _getLiquidity(PoolId id) internal view returns (uint128) {
|
|
1792
1792
|
return POOL_MANAGER.getLiquidity(id);
|
|
1793
1793
|
}
|
|
1794
1794
|
|
|
1795
1795
|
/// @notice Read slot0 from a V4 pool.
|
|
1796
|
-
/// @param id The pool ID.
|
|
1796
|
+
/// @param id The pool ID to query.
|
|
1797
1797
|
/// @return sqrtPriceX96 The current sqrt price.
|
|
1798
1798
|
/// @return tick The current tick.
|
|
1799
1799
|
/// @return protocolFee The protocol fee.
|
|
@@ -1808,7 +1808,7 @@ contract JBRouterTerminal is
|
|
|
1808
1808
|
}
|
|
1809
1809
|
|
|
1810
1810
|
/// @notice Look up the primary terminal for a project and token.
|
|
1811
|
-
/// @param projectId The ID of the project.
|
|
1811
|
+
/// @param projectId The ID of the project to look up.
|
|
1812
1812
|
/// @param token The token to look up.
|
|
1813
1813
|
/// @return The primary terminal, or IJBTerminal(address(0)) if none.
|
|
1814
1814
|
// slither-disable-next-line calls-loop
|
|
@@ -1825,7 +1825,7 @@ contract JBRouterTerminal is
|
|
|
1825
1825
|
}
|
|
1826
1826
|
|
|
1827
1827
|
/// @notice Read a project's terminal list from the directory.
|
|
1828
|
-
/// @param projectId The project
|
|
1828
|
+
/// @param projectId The project to read terminals for.
|
|
1829
1829
|
/// @param shouldIgnoreFailure Whether a reverting directory call should degrade into an empty list.
|
|
1830
1830
|
/// @return terminals The project's terminal list, or an empty list if `shouldIgnoreFailure` is true and the call
|
|
1831
1831
|
/// failed.
|
|
@@ -1864,7 +1864,7 @@ contract JBRouterTerminal is
|
|
|
1864
1864
|
}
|
|
1865
1865
|
|
|
1866
1866
|
/// @notice Parse the optional `cashOutSource` metadata.
|
|
1867
|
-
/// @param metadata The metadata to inspect for
|
|
1867
|
+
/// @param metadata The metadata to inspect for credit cashout overrides.
|
|
1868
1868
|
/// @return sourceProjectId The source project override, or 0 if none is specified.
|
|
1869
1869
|
/// @return amount The credit amount, or 0 if none is specified.
|
|
1870
1870
|
function _cashOutSourceFrom(bytes calldata metadata)
|
|
@@ -1888,7 +1888,7 @@ contract JBRouterTerminal is
|
|
|
1888
1888
|
|
|
1889
1889
|
/// @notice Check whether a cashout route can complete at the current destination.
|
|
1890
1890
|
/// @dev Shared by _cashOutLoop and _previewCashOutLoop to keep destination logic in sync.
|
|
1891
|
-
/// @param destProjectId The destination project.
|
|
1891
|
+
/// @param destProjectId The destination project to check.
|
|
1892
1892
|
/// @param token The current token in the route.
|
|
1893
1893
|
/// @param preferredToken The caller's preferred output token (or address(0) for none).
|
|
1894
1894
|
/// @return terminal The usable terminal if a route was found, or IJBTerminal(address(0)).
|
|
@@ -1958,8 +1958,8 @@ contract JBRouterTerminal is
|
|
|
1958
1958
|
}
|
|
1959
1959
|
|
|
1960
1960
|
/// @notice Search supported V4 pools and update the best pool candidate if a deeper V4 pool exists.
|
|
1961
|
-
/// @param normalizedTokenIn The normalized input token
|
|
1962
|
-
/// @param normalizedTokenOut The normalized output token
|
|
1961
|
+
/// @param normalizedTokenIn The normalized input token to search pools for.
|
|
1962
|
+
/// @param normalizedTokenOut The normalized output token to search pools for.
|
|
1963
1963
|
/// @param currentBestLiquidity The highest liquidity found so far from prior discovery passes.
|
|
1964
1964
|
/// @param bestPool The current best pool candidate to preserve unless a better V4 pool is found.
|
|
1965
1965
|
/// @return updatedBestPool The winning pool after evaluating all supported V4 fee, tick-spacing, and hook
|
|
@@ -2051,7 +2051,7 @@ contract JBRouterTerminal is
|
|
|
2051
2051
|
/// @notice Find which terminal to cash out from and which token to reclaim.
|
|
2052
2052
|
/// @dev Prioritizes: 1) tokens the destination directly accepts, 2) base tokens that can exit the recursion
|
|
2053
2053
|
/// immediately, 3) JB project tokens (recursable) only when no direct or base-token exit exists.
|
|
2054
|
-
/// @param sourceProjectId The ID of the project
|
|
2054
|
+
/// @param sourceProjectId The ID of the project to cash out tokens from.
|
|
2055
2055
|
/// @param destProjectId The ID of the destination project.
|
|
2056
2056
|
/// @return tokenToReclaim The token to reclaim from the cash out.
|
|
2057
2057
|
/// @return cashOutTerminal The terminal to cash out from.
|
|
@@ -2186,7 +2186,7 @@ contract JBRouterTerminal is
|
|
|
2186
2186
|
}
|
|
2187
2187
|
|
|
2188
2188
|
/// @notice Get the slippage tolerance for a given swap using the continuous sigmoid formula.
|
|
2189
|
-
/// @param amountIn The amount of tokens
|
|
2189
|
+
/// @param amountIn The amount of tokens to swap.
|
|
2190
2190
|
/// @param liquidity The pool's in-range liquidity.
|
|
2191
2191
|
/// @param tokenOut The output token.
|
|
2192
2192
|
/// @param tokenIn The input token.
|
|
@@ -2226,10 +2226,10 @@ contract JBRouterTerminal is
|
|
|
2226
2226
|
}
|
|
2227
2227
|
|
|
2228
2228
|
/// @notice Get a TWAP-based quote with dynamic slippage for a V3 pool.
|
|
2229
|
-
/// @param pool The V3 pool
|
|
2230
|
-
/// @param normalizedTokenIn The normalized token
|
|
2231
|
-
/// @param normalizedTokenOut The normalized token
|
|
2232
|
-
/// @param amount The amount of `normalizedTokenIn`
|
|
2229
|
+
/// @param pool The V3 pool to quote.
|
|
2230
|
+
/// @param normalizedTokenIn The normalized token to swap in.
|
|
2231
|
+
/// @param normalizedTokenOut The normalized token to swap out.
|
|
2232
|
+
/// @param amount The amount of `normalizedTokenIn` to quote.
|
|
2233
2233
|
/// @return minAmountOut The minimum amount out implied by the TWAP quote and dynamic slippage model.
|
|
2234
2234
|
function _getV3TwapQuote(
|
|
2235
2235
|
IUniswapV3Pool pool,
|
|
@@ -2313,9 +2313,9 @@ contract JBRouterTerminal is
|
|
|
2313
2313
|
/// tolerance reflects a recent, off-chain-verified price. When no external quote can be provided, this fallback
|
|
2314
2314
|
/// is still available as an accepted-risk convenience path.
|
|
2315
2315
|
/// @param key The V4 pool key describing the pool to quote against.
|
|
2316
|
-
/// @param normalizedTokenIn The normalized token
|
|
2317
|
-
/// @param normalizedTokenOut The normalized token
|
|
2318
|
-
/// @param amount The exact input amount
|
|
2316
|
+
/// @param normalizedTokenIn The normalized token to sell into the pool.
|
|
2317
|
+
/// @param normalizedTokenOut The normalized token to buy from the pool.
|
|
2318
|
+
/// @param amount The exact input amount to quote.
|
|
2319
2319
|
/// @return minAmountOut The quoted minimum output after the router's slippage model is applied.
|
|
2320
2320
|
function _getV4SpotQuote(
|
|
2321
2321
|
PoolKey memory key,
|
|
@@ -2411,7 +2411,7 @@ contract JBRouterTerminal is
|
|
|
2411
2411
|
}
|
|
2412
2412
|
|
|
2413
2413
|
/// @notice Parse the optional `cashOutMinReclaimed` metadata.
|
|
2414
|
-
/// @param metadata The metadata to inspect for
|
|
2414
|
+
/// @param metadata The metadata to inspect for minimum reclaim amounts.
|
|
2415
2415
|
/// @return minTokensReclaimed The minimum reclaim amount, or 0 if none is specified.
|
|
2416
2416
|
function _minReclaimedFrom(bytes calldata metadata) internal view returns (uint256 minTokensReclaimed) {
|
|
2417
2417
|
(bool exists, bytes memory minData) = _getDataFor({metadata: metadata, id: _CASH_OUT_MIN_RECLAIMED_ID});
|
|
@@ -2431,8 +2431,8 @@ contract JBRouterTerminal is
|
|
|
2431
2431
|
}
|
|
2432
2432
|
|
|
2433
2433
|
/// @notice Return the balance of an account for a token, using ETH balance for the native token sentinel.
|
|
2434
|
-
/// @param token The token
|
|
2435
|
-
/// @param account The account
|
|
2434
|
+
/// @param token The token to read the balance of.
|
|
2435
|
+
/// @param account The account to read the balance of.
|
|
2436
2436
|
/// @return balance The account's balance in `token`.
|
|
2437
2437
|
// slither-disable-next-line calls-loop
|
|
2438
2438
|
function _balanceOf(address token, address account) internal view returns (uint256) {
|
|
@@ -2441,16 +2441,15 @@ contract JBRouterTerminal is
|
|
|
2441
2441
|
}
|
|
2442
2442
|
|
|
2443
2443
|
/// @notice Normalize a token address by replacing the native token sentinel with WETH.
|
|
2444
|
-
/// @param token The token to normalize
|
|
2444
|
+
/// @param token The token to normalize.
|
|
2445
2445
|
/// @return normalizedToken The normalized token address.
|
|
2446
2446
|
function _normalize(address token) internal view returns (address) {
|
|
2447
2447
|
// Replace the native-token sentinel with WETH so ETH and WETH share one routing representation.
|
|
2448
2448
|
return token == JBConstants.NATIVE_TOKEN ? address(WETH) : token;
|
|
2449
2449
|
}
|
|
2450
2450
|
|
|
2451
|
-
/// @notice Discover a pool and compute the minimum acceptable output for a swap.
|
|
2452
|
-
///
|
|
2453
|
-
/// with dynamic slippage.
|
|
2451
|
+
/// @notice Discover a pool and compute the minimum acceptable output for a swap. Uses a user-provided quote if
|
|
2452
|
+
/// available, otherwise falls back to TWAP (V3) or automatic V4 quoting with dynamic slippage.
|
|
2454
2453
|
/// @dev For V4 pools without TWAP-capable hooks, `minAmountOut` is derived from the same-block spot tick, which is
|
|
2455
2454
|
/// manipulable via sandwich attacks. This is an accepted risk for integrations that cannot source external quotes,
|
|
2456
2455
|
/// especially when routing through deep pools and routine swap sizes, but it should not be treated as full MEV
|
|
@@ -2518,7 +2517,7 @@ contract JBRouterTerminal is
|
|
|
2518
2517
|
/// @notice A view-only mirror of `_acceptFundsFor` used for previews.
|
|
2519
2518
|
/// @dev Preview semantics use the caller-supplied `amount` as the intended input amount.
|
|
2520
2519
|
/// @param amount The caller-supplied payment amount.
|
|
2521
|
-
/// @param metadata The metadata to inspect for
|
|
2520
|
+
/// @param metadata The metadata to inspect for credit cashout overrides.
|
|
2522
2521
|
/// @return The effective amount that routing should use.
|
|
2523
2522
|
function _previewAcceptFundsFor(uint256 amount, bytes calldata metadata) internal view returns (uint256) {
|
|
2524
2523
|
// Credit cashouts use the credit amount encoded in metadata rather than the raw token amount.
|
|
@@ -2534,7 +2533,7 @@ contract JBRouterTerminal is
|
|
|
2534
2533
|
|
|
2535
2534
|
/// @notice A view-only mirror of `_cashOutLoop`.
|
|
2536
2535
|
/// @param destProjectId The ID of the destination project.
|
|
2537
|
-
/// @param token The current token
|
|
2536
|
+
/// @param token The current token to process.
|
|
2538
2537
|
/// @param amount The amount of the current token.
|
|
2539
2538
|
/// @param sourceProjectIdOverride An optional source project override from metadata.
|
|
2540
2539
|
/// @param metadata Bytes in `JBMetadataResolver`'s format.
|
|
@@ -2610,8 +2609,8 @@ contract JBRouterTerminal is
|
|
|
2610
2609
|
}
|
|
2611
2610
|
|
|
2612
2611
|
/// @notice Preview a single cashout hop in the recursive cashout path.
|
|
2613
|
-
/// @param sourceProjectId The project
|
|
2614
|
-
/// @param destProjectId The final destination project
|
|
2612
|
+
/// @param sourceProjectId The project to cash out tokens from.
|
|
2613
|
+
/// @param destProjectId The final destination project to pay.
|
|
2615
2614
|
/// @param amount The amount of source-project tokens to cash out.
|
|
2616
2615
|
/// @return tokenToReclaim The token that would be reclaimed from the source terminal.
|
|
2617
2616
|
/// @return reclaimAmount The amount of that token that would be reclaimed.
|
|
@@ -2653,8 +2652,8 @@ contract JBRouterTerminal is
|
|
|
2653
2652
|
/// @notice Get a minimum-amount-out quote at the given tick, applying dynamic slippage.
|
|
2654
2653
|
/// @param amount The input amount.
|
|
2655
2654
|
/// @param liquidity The pool's in-range liquidity.
|
|
2656
|
-
/// @param tokenIn The input token address
|
|
2657
|
-
/// @param tokenOut The output token address
|
|
2655
|
+
/// @param tokenIn The input token address for sorting and quoting.
|
|
2656
|
+
/// @param tokenOut The output token address for sorting and quoting.
|
|
2658
2657
|
/// @param tick The tick to quote at (TWAP mean tick or spot tick).
|
|
2659
2658
|
/// @param poolFeeBps The pool fee in basis points.
|
|
2660
2659
|
/// @return minAmountOut The quoted output amount after slippage.
|
|
@@ -2702,7 +2701,7 @@ contract JBRouterTerminal is
|
|
|
2702
2701
|
/// @notice Read a metadata entry from the router's metadata namespace.
|
|
2703
2702
|
/// @param metadata The metadata blob to query.
|
|
2704
2703
|
/// @param id The pre-computed metadata ID to look up.
|
|
2705
|
-
/// @return exists
|
|
2704
|
+
/// @return exists Whether the metadata entry was present.
|
|
2706
2705
|
/// @return data The raw metadata payload for `id`.
|
|
2707
2706
|
function _getDataFor(bytes calldata metadata, bytes4 id) internal pure returns (bool exists, bytes memory data) {
|
|
2708
2707
|
// slither-disable-next-line unused-return
|
|
@@ -52,25 +52,25 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
52
52
|
// -------------------- public immutable properties ------------------ //
|
|
53
53
|
//*********************************************************************//
|
|
54
54
|
|
|
55
|
-
/// @notice The project registry.
|
|
55
|
+
/// @notice The Juicebox project registry used to verify project existence and ownership.
|
|
56
56
|
IJBProjects public immutable override PROJECTS;
|
|
57
57
|
|
|
58
|
-
/// @notice The
|
|
58
|
+
/// @notice The Permit2 contract used for token approvals and transfers.
|
|
59
59
|
IPermit2 public immutable override PERMIT2;
|
|
60
60
|
|
|
61
61
|
//*********************************************************************//
|
|
62
62
|
// --------------------- public stored properties -------------------- //
|
|
63
63
|
//*********************************************************************//
|
|
64
64
|
|
|
65
|
-
/// @notice The default terminal
|
|
65
|
+
/// @notice The default terminal used for payments when a project hasn't registered a specific one.
|
|
66
66
|
IJBTerminal public override defaultTerminal;
|
|
67
67
|
|
|
68
68
|
/// @notice Whether the terminal for a given project has been locked against future updates.
|
|
69
|
-
/// @custom:param projectId The ID of the project
|
|
69
|
+
/// @custom:param projectId The ID of the project to check lock state for.
|
|
70
70
|
mapping(uint256 projectId => bool) public override hasLockedTerminal;
|
|
71
71
|
|
|
72
72
|
/// @notice Whether a terminal is allowlisted for project-level selection.
|
|
73
|
-
/// @custom:param terminal The terminal
|
|
73
|
+
/// @custom:param terminal The terminal to check allowlist status for.
|
|
74
74
|
mapping(IJBTerminal terminal => bool) public override isTerminalAllowed;
|
|
75
75
|
|
|
76
76
|
//*********************************************************************//
|
|
@@ -78,7 +78,7 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
78
78
|
//*********************************************************************//
|
|
79
79
|
|
|
80
80
|
/// @notice The terminal explicitly configured for a project before default-terminal fallback is applied.
|
|
81
|
-
/// @custom:param projectId The ID of the project
|
|
81
|
+
/// @custom:param projectId The ID of the project to look up the explicit terminal for.
|
|
82
82
|
mapping(uint256 projectId => IJBTerminal) internal _terminalOf;
|
|
83
83
|
|
|
84
84
|
//*********************************************************************//
|
|
@@ -181,8 +181,8 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
181
181
|
|
|
182
182
|
/// @notice Preview a payment by forwarding the call to the terminal currently resolved for the project.
|
|
183
183
|
/// @dev Uses the project-specific terminal when set, otherwise falls back to `defaultTerminal`.
|
|
184
|
-
/// @param projectId The ID of the project
|
|
185
|
-
/// @param token The token
|
|
184
|
+
/// @param projectId The ID of the project to pay.
|
|
185
|
+
/// @param token The token to pay into the resolved terminal.
|
|
186
186
|
/// @param amount The amount of the input token to preview.
|
|
187
187
|
/// @param beneficiary The address that would receive any minted project tokens.
|
|
188
188
|
/// @param metadata Extra data to forward unchanged to the resolved terminal preview.
|
|
@@ -229,9 +229,9 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
229
229
|
// -------------------------- public views --------------------------- //
|
|
230
230
|
//*********************************************************************//
|
|
231
231
|
|
|
232
|
-
/// @notice
|
|
232
|
+
/// @notice Check whether the registry supports a given interface ID.
|
|
233
233
|
/// @param interfaceId The interface ID to check.
|
|
234
|
-
/// @return supported
|
|
234
|
+
/// @return supported Whether `interfaceId` is implemented.
|
|
235
235
|
function supportsInterface(bytes4 interfaceId) public pure override returns (bool supported) {
|
|
236
236
|
supported = interfaceId == type(IJBRouterTerminalRegistry).interfaceId
|
|
237
237
|
|| interfaceId == type(IJBForwardingTerminal).interfaceId || interfaceId == type(IJBTerminal).interfaceId
|
|
@@ -248,7 +248,7 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/// @notice Prevent the registry from forwarding straight back into its immediate caller.
|
|
251
|
-
/// @param terminal The terminal
|
|
251
|
+
/// @param terminal The terminal to check for circular forwarding.
|
|
252
252
|
function _enforceNoCircularForward(IJBTerminal terminal) internal view {
|
|
253
253
|
// Reject immediate caller cycles so router -> registry -> same router cannot recurse indefinitely.
|
|
254
254
|
if (msg.sender == address(terminal)) revert JBRouterTerminalRegistry_CircularForward(terminal);
|
|
@@ -267,8 +267,8 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
/// @notice Reject terminal choices that would forward the project back into this registry.
|
|
270
|
-
/// @param projectId The project
|
|
271
|
-
/// @param terminal The terminal
|
|
270
|
+
/// @param projectId The project to validate forwarding for.
|
|
271
|
+
/// @param terminal The terminal to validate.
|
|
272
272
|
function _requireNonCircularTerminalFor(uint256 projectId, IJBTerminal terminal) internal view {
|
|
273
273
|
// Reject direct self-selection so the registry cannot forward a project to itself.
|
|
274
274
|
if (address(terminal) == address(this)) revert JBRouterTerminalRegistry_CircularForward(terminal);
|
|
@@ -290,7 +290,7 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
/// @notice Resolve the effective terminal for a project, falling back to the default terminal when unset.
|
|
293
|
-
/// @param projectId The project
|
|
293
|
+
/// @param projectId The project to resolve the terminal for.
|
|
294
294
|
/// @return terminal The project-specific terminal, or the default terminal if no override exists.
|
|
295
295
|
function _resolvedTerminalOf(uint256 projectId) internal view returns (IJBTerminal terminal) {
|
|
296
296
|
// Start from the project-specific override, if one was configured.
|
|
@@ -317,9 +317,9 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
317
317
|
|
|
318
318
|
/// @notice Add funds to a project's balance by forwarding them through the project's resolved router terminal.
|
|
319
319
|
/// @dev Uses the project-specific terminal when set, otherwise falls back to `defaultTerminal`.
|
|
320
|
-
/// @param projectId The ID of the project
|
|
321
|
-
/// @param token The address of the token
|
|
322
|
-
/// @param amount The amount of tokens
|
|
320
|
+
/// @param projectId The ID of the project to add balance to.
|
|
321
|
+
/// @param token The address of the token to pay in.
|
|
322
|
+
/// @param amount The amount of tokens to send.
|
|
323
323
|
/// @param shouldReturnHeldFees Whether held fees should be returned based on the amount added.
|
|
324
324
|
/// @param memo A memo to pass along to the emitted event.
|
|
325
325
|
/// @param metadata Bytes in `JBMetadataResolver`'s format (may include `permit2` allowance data).
|
|
@@ -459,9 +459,9 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
459
459
|
/// @notice Pay a project by accepting the caller's tokens and forwarding them to the project's resolved router
|
|
460
460
|
/// terminal.
|
|
461
461
|
/// @dev Uses the project-specific terminal when set, otherwise falls back to `defaultTerminal`.
|
|
462
|
-
/// @param projectId The ID of the project
|
|
463
|
-
/// @param token The address of the token
|
|
464
|
-
/// @param amount The amount of tokens
|
|
462
|
+
/// @param projectId The ID of the project to pay.
|
|
463
|
+
/// @param token The address of the token to pay with.
|
|
464
|
+
/// @param amount The amount of tokens to send.
|
|
465
465
|
/// @param beneficiary The address that will receive any project tokens minted by the destination.
|
|
466
466
|
/// @param minReturnedTokens The minimum number of project tokens expected in return.
|
|
467
467
|
/// @param memo A memo to pass along to the emitted event.
|
|
@@ -564,12 +564,12 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
564
564
|
// ---------------------- internal transactions ---------------------- //
|
|
565
565
|
//*********************************************************************//
|
|
566
566
|
|
|
567
|
-
/// @notice
|
|
567
|
+
/// @notice Accept a token paid in by the caller.
|
|
568
568
|
/// @dev Measures the actual received balance so forwarded amounts stay in sync with lossy ERC-20 transfers.
|
|
569
|
-
/// @param token The address of the token
|
|
570
|
-
/// @param amount The amount of tokens
|
|
569
|
+
/// @param token The address of the token to accept.
|
|
570
|
+
/// @param amount The amount of tokens to accept.
|
|
571
571
|
/// @param metadata The metadata in which `permit2` context is provided.
|
|
572
|
-
/// @return amount The amount of tokens
|
|
572
|
+
/// @return amount The amount of tokens accepted.
|
|
573
573
|
// slither-disable-next-line reentrancy-events
|
|
574
574
|
function _acceptFundsFor(address token, uint256 amount, bytes calldata metadata) internal returns (uint256) {
|
|
575
575
|
// If native tokens are being paid in, return the `msg.value`.
|
|
@@ -618,11 +618,11 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
618
618
|
return IERC20(token).balanceOf(address(this)) - balanceBefore;
|
|
619
619
|
}
|
|
620
620
|
|
|
621
|
-
/// @notice Logic to
|
|
621
|
+
/// @notice Logic to trigger before transferring tokens from this terminal.
|
|
622
622
|
/// @param to The address to transfer tokens to.
|
|
623
|
-
/// @param token The token
|
|
623
|
+
/// @param token The token to transfer.
|
|
624
624
|
/// @param amount The amount of tokens to transfer.
|
|
625
|
-
/// @return payValue The amount that
|
|
625
|
+
/// @return payValue The amount that will be paid as a `msg.value`.
|
|
626
626
|
function _beforeTransferFor(address to, address token, uint256 amount) internal virtual returns (uint256) {
|
|
627
627
|
// If the token is the native token, return early.
|
|
628
628
|
if (token == JBConstants.NATIVE_TOKEN) return amount;
|
|
@@ -637,7 +637,7 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
637
637
|
/// fallback.
|
|
638
638
|
/// @param from The address to transfer tokens from.
|
|
639
639
|
/// @param to The address to transfer tokens to.
|
|
640
|
-
/// @param token The address of the token
|
|
640
|
+
/// @param token The address of the token to transfer.
|
|
641
641
|
/// @param amount The amount of tokens to transfer.
|
|
642
642
|
function _transferFrom(address from, address payable to, address token, uint256 amount) internal virtual {
|
|
643
643
|
if (from == address(this)) {
|
|
@@ -28,8 +28,8 @@ interface IJBPayRoutePreviewer {
|
|
|
28
28
|
|
|
29
29
|
/// @notice Preview the recursive cashout loop the router would use for a project-token input.
|
|
30
30
|
/// @param destProjectId The destination project the router is trying to pay.
|
|
31
|
-
/// @param token The current token
|
|
32
|
-
/// @param amount The amount of `token`
|
|
31
|
+
/// @param token The current token to route.
|
|
32
|
+
/// @param amount The amount of `token` to preview.
|
|
33
33
|
/// @param sourceProjectIdOverride The one-shot source project override encoded in metadata, if any.
|
|
34
34
|
/// @param metadata Metadata forwarded into preview helpers.
|
|
35
35
|
/// @param preferredToken The token the cashout loop should prefer to land on, or `address(0)` for no preference.
|
|
@@ -51,7 +51,7 @@ interface IJBPayRoutePreviewer {
|
|
|
51
51
|
/// @notice Preview the amount a direct token-to-token swap would return.
|
|
52
52
|
/// @param tokenIn The input token.
|
|
53
53
|
/// @param tokenOut The output token.
|
|
54
|
-
/// @param amount The amount of `tokenIn`
|
|
54
|
+
/// @param amount The amount of `tokenIn` to swap.
|
|
55
55
|
/// @param metadata Metadata forwarded into quote selection.
|
|
56
56
|
/// @return amountOut The quoted amount of `tokenOut`.
|
|
57
57
|
function previewSwapAmountOutOf(
|
|
@@ -71,11 +71,11 @@ interface IJBPayRoutePreviewer {
|
|
|
71
71
|
function bestPoolLiquidityOf(address tokenA, address tokenB) external view returns (uint128 bestLiquidity);
|
|
72
72
|
|
|
73
73
|
/// @notice Preview a destination terminal payment from the router's caller context.
|
|
74
|
-
/// @param destTerminal The terminal whose pay preview
|
|
74
|
+
/// @param destTerminal The terminal whose pay preview to query.
|
|
75
75
|
/// @param projectId The destination project that would receive the payment.
|
|
76
76
|
/// @param token The token the destination terminal would receive.
|
|
77
77
|
/// @param amount The amount of `token` the destination terminal would receive.
|
|
78
|
-
/// @param beneficiary The address
|
|
78
|
+
/// @param beneficiary The address to measure beneficiary token count for.
|
|
79
79
|
/// @param metadata Metadata forwarded unchanged into the destination terminal preview.
|
|
80
80
|
/// @return ruleset The ruleset returned by the destination terminal preview.
|
|
81
81
|
/// @return beneficiaryTokenCount The beneficiary token count returned by the destination terminal preview.
|
|
@@ -10,11 +10,11 @@ import {IJBPayRoutePreviewer} from "./IJBPayRoutePreviewer.sol";
|
|
|
10
10
|
/// @notice Resolves the best pay route preview for a router terminal.
|
|
11
11
|
interface IJBPayRouteResolver {
|
|
12
12
|
/// @notice Preview the best pay route for a router terminal.
|
|
13
|
-
/// @param router The router terminal whose preview helpers
|
|
13
|
+
/// @param router The router terminal whose preview helpers to use.
|
|
14
14
|
/// @param projectId The destination project that would receive the payment.
|
|
15
15
|
/// @param tokenIn The token currently available to route.
|
|
16
|
-
/// @param amount The amount of `tokenIn`
|
|
17
|
-
/// @param beneficiary The address whose minted token count
|
|
16
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
17
|
+
/// @param beneficiary The address whose minted token count to optimize.
|
|
18
18
|
/// @param metadata Metadata forwarded into route and pay previews.
|
|
19
19
|
/// @return destTerminal The terminal chosen for the best previewed route.
|
|
20
20
|
/// @return tokenOut The token `destTerminal` would receive.
|
|
@@ -44,11 +44,11 @@ interface IJBPayRouteResolver {
|
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
/// @notice Preview a specific candidate pay route so callers can isolate revert-prone candidates with `try/catch`.
|
|
47
|
-
/// @param router The router terminal whose preview helpers
|
|
47
|
+
/// @param router The router terminal whose preview helpers to use.
|
|
48
48
|
/// @param projectId The destination project that would receive the payment.
|
|
49
49
|
/// @param tokenIn The token currently available to route.
|
|
50
|
-
/// @param amount The amount of `tokenIn`
|
|
51
|
-
/// @param beneficiary The address
|
|
50
|
+
/// @param amount The amount of `tokenIn` to preview.
|
|
51
|
+
/// @param beneficiary The address to measure minted token count for.
|
|
52
52
|
/// @param metadata Metadata forwarded into route and pay previews.
|
|
53
53
|
/// @param tokenOut The candidate destination token to preview.
|
|
54
54
|
/// @param destTerminal The terminal that accepts `tokenOut` for the destination project.
|
|
@@ -82,9 +82,9 @@ interface IJBPayRouteResolver {
|
|
|
82
82
|
);
|
|
83
83
|
|
|
84
84
|
/// @notice Determine what output token a project accepts for a given input token.
|
|
85
|
-
/// @param router The router whose view helpers
|
|
86
|
-
/// @param projectId The destination project
|
|
87
|
-
/// @param tokenIn The input token
|
|
85
|
+
/// @param router The router whose view helpers to use.
|
|
86
|
+
/// @param projectId The destination project to pay.
|
|
87
|
+
/// @param tokenIn The input token to route.
|
|
88
88
|
/// @param metadata Metadata forwarded into route-token resolution.
|
|
89
89
|
/// @return tokenOut The token the project accepts.
|
|
90
90
|
/// @return destTerminal The terminal that accepts `tokenOut`.
|
|
@@ -101,10 +101,10 @@ interface IJBPayRouteResolver {
|
|
|
101
101
|
/// @notice External self-call wrapper that previews the fallback route in an isolated context.
|
|
102
102
|
/// @dev Called via `self.previewFallbackRoute(...)` so `try/catch` can absorb reverts from broken
|
|
103
103
|
/// terminals or price feeds without bricking the entire best-route preview.
|
|
104
|
-
/// @param routePreviewer The router terminal whose preview helpers
|
|
105
|
-
/// @param destProjectId The project
|
|
104
|
+
/// @param routePreviewer The router terminal whose preview helpers to use for simulating the route.
|
|
105
|
+
/// @param destProjectId The project to pay through the fallback route.
|
|
106
106
|
/// @param tokenIn The token the payer is sending.
|
|
107
|
-
/// @param amountIn The amount of `tokenIn`
|
|
107
|
+
/// @param amountIn The amount of `tokenIn` to route.
|
|
108
108
|
/// @param beneficiary The address that would receive minted project tokens.
|
|
109
109
|
/// @param metadata Arbitrary bytes forwarded into route and terminal pay previews.
|
|
110
110
|
/// @return destTerminal The terminal the fallback route would deliver funds to.
|
|
@@ -135,8 +135,8 @@ interface IJBPayRouteResolver {
|
|
|
135
135
|
);
|
|
136
136
|
|
|
137
137
|
/// @notice Resolve a project's primary terminal only when the router can safely forward into it.
|
|
138
|
-
/// @param router The router whose forwarding-terminal rules
|
|
139
|
-
/// @param projectId The project
|
|
138
|
+
/// @param router The router whose forwarding-terminal rules to apply.
|
|
139
|
+
/// @param projectId The project to check the primary terminal for.
|
|
140
140
|
/// @param token The token that terminal should accept.
|
|
141
141
|
/// @return terminal The usable primary terminal, or address(0) if none is usable.
|
|
142
142
|
function usablePrimaryTerminalOf(
|
|
@@ -11,17 +11,17 @@ import {IJBPayerTracker} from "./IJBPayerTracker.sol";
|
|
|
11
11
|
/// @notice A registry that maps projects to their preferred router terminal.
|
|
12
12
|
interface IJBRouterTerminalRegistry is IJBTerminal, IJBForwardingTerminal, IJBPayerTracker {
|
|
13
13
|
/// @notice Emitted when a terminal is allowed for use by projects.
|
|
14
|
-
/// @param terminal The terminal
|
|
14
|
+
/// @param terminal The terminal allowed.
|
|
15
15
|
/// @param caller The address that called the function.
|
|
16
16
|
event JBRouterTerminalRegistry_AllowTerminal(IJBTerminal terminal, address caller);
|
|
17
17
|
|
|
18
18
|
/// @notice Emitted when a terminal is disallowed from use by projects.
|
|
19
|
-
/// @param terminal The terminal
|
|
19
|
+
/// @param terminal The terminal disallowed.
|
|
20
20
|
/// @param caller The address that called the function.
|
|
21
21
|
event JBRouterTerminalRegistry_DisallowTerminal(IJBTerminal terminal, address caller);
|
|
22
22
|
|
|
23
23
|
/// @notice Emitted when a project's terminal is locked and can no longer be changed.
|
|
24
|
-
/// @param projectId The ID of the project
|
|
24
|
+
/// @param projectId The ID of the project locked.
|
|
25
25
|
/// @param caller The address that called the function.
|
|
26
26
|
event JBRouterTerminalRegistry_LockTerminal(uint256 indexed projectId, address caller);
|
|
27
27
|
|
|
@@ -31,8 +31,8 @@ interface IJBRouterTerminalRegistry is IJBTerminal, IJBForwardingTerminal, IJBPa
|
|
|
31
31
|
event JBRouterTerminalRegistry_SetDefaultTerminal(IJBTerminal terminal, address caller);
|
|
32
32
|
|
|
33
33
|
/// @notice Emitted when a project's terminal is set.
|
|
34
|
-
/// @param projectId The ID of the project
|
|
35
|
-
/// @param terminal The terminal
|
|
34
|
+
/// @param projectId The ID of the project updated.
|
|
35
|
+
/// @param terminal The terminal set for the project.
|
|
36
36
|
/// @param caller The address that called the function.
|
|
37
37
|
event JBRouterTerminalRegistry_SetTerminal(uint256 indexed projectId, IJBTerminal terminal, address caller);
|
|
38
38
|
|
|
@@ -62,7 +62,7 @@ interface IJBRouterTerminalRegistry is IJBTerminal, IJBForwardingTerminal, IJBPa
|
|
|
62
62
|
/// @param terminal The terminal to allow.
|
|
63
63
|
function allowTerminal(IJBTerminal terminal) external;
|
|
64
64
|
|
|
65
|
-
/// @notice Disallow a terminal from
|
|
65
|
+
/// @notice Disallow a terminal from use by projects.
|
|
66
66
|
/// @param terminal The terminal to disallow.
|
|
67
67
|
function disallowTerminal(IJBTerminal terminal) external;
|
|
68
68
|
|
|
@@ -9,7 +9,7 @@ import {IJBForwardingTerminal} from "../interfaces/IJBForwardingTerminal.sol";
|
|
|
9
9
|
library JBForwardingCheck {
|
|
10
10
|
/// @notice Whether routing through `terminal` would cycle back to `target` within 5 hops.
|
|
11
11
|
/// @param target The address to detect cycles against (typically the router).
|
|
12
|
-
/// @param projectId The project
|
|
12
|
+
/// @param projectId The project to follow the forwarding chain for.
|
|
13
13
|
/// @param terminal The starting terminal to check.
|
|
14
14
|
/// @return isCircular True if the terminal forwards (directly or transitively) back to `target`.
|
|
15
15
|
function isCircularTerminal(
|
|
@@ -67,7 +67,7 @@ library JBSwapLib {
|
|
|
67
67
|
|
|
68
68
|
/// @notice Estimate the price impact of a swap, scaled by IMPACT_PRECISION.
|
|
69
69
|
/// @dev Uses 1e18 precision to capture sub-basis-point impacts for small swaps in deep pools.
|
|
70
|
-
/// @param amountIn The amount of tokens
|
|
70
|
+
/// @param amountIn The amount of tokens to swap in.
|
|
71
71
|
/// @param liquidity The pool's in-range liquidity.
|
|
72
72
|
/// @param sqrtP The sqrt price in Q96 format.
|
|
73
73
|
/// @param zeroForOne Whether the swap is token0 → token1.
|
|
@@ -101,7 +101,7 @@ library JBSwapLib {
|
|
|
101
101
|
/// @notice Compute a sqrtPriceLimitX96 from input/output amounts so the swap stops
|
|
102
102
|
/// if the execution price would be worse than the minimum acceptable rate.
|
|
103
103
|
/// @dev When `minimumAmountOut == 0`, returns extreme values (no limit).
|
|
104
|
-
/// @param amountIn The amount of tokens
|
|
104
|
+
/// @param amountIn The amount of tokens to swap in.
|
|
105
105
|
/// @param minimumAmountOut The minimum acceptable output.
|
|
106
106
|
/// @param zeroForOne True when selling token0 for token1 (price decreases).
|
|
107
107
|
/// @return sqrtPriceLimit The V3-compatible sqrtPriceLimitX96.
|
|
@@ -3,12 +3,12 @@ pragma solidity ^0.8.0;
|
|
|
3
3
|
|
|
4
4
|
import {IJBCashOutTerminal} from "@bananapus/core-v6/src/interfaces/IJBCashOutTerminal.sol";
|
|
5
5
|
|
|
6
|
-
/// @custom:member fallbackToken The first reclaimable JB project token
|
|
7
|
-
/// @custom:member fallbackTerminal The cashout terminal
|
|
8
|
-
/// @custom:member baseFallbackToken The first reclaimable base token
|
|
9
|
-
/// @custom:member baseFallbackTerminal The cashout terminal
|
|
6
|
+
/// @custom:member fallbackToken The first reclaimable JB project token found for recursive cashout routing.
|
|
7
|
+
/// @custom:member fallbackTerminal The cashout terminal to reclaim `fallbackToken` from.
|
|
8
|
+
/// @custom:member baseFallbackToken The first reclaimable base token found for swap-based fallback routing.
|
|
9
|
+
/// @custom:member baseFallbackTerminal The cashout terminal to reclaim `baseFallbackToken` from.
|
|
10
10
|
/// @custom:member directFallbackToken The first reclaimable token the destination project directly accepts.
|
|
11
|
-
/// @custom:member directFallbackTerminal The cashout terminal
|
|
11
|
+
/// @custom:member directFallbackTerminal The cashout terminal to reclaim `directFallbackToken` from.
|
|
12
12
|
struct CashOutPathCandidates {
|
|
13
13
|
address fallbackToken;
|
|
14
14
|
IJBCashOutTerminal fallbackTerminal;
|