@bananapus/router-terminal-v6 0.0.56 → 0.0.58
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/README.md +12 -7
- package/package.json +2 -2
- package/src/JBRouterTerminal.sol +19 -19
package/README.md
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
`@bananapus/router-terminal-v6` is a routing terminal for Juicebox V6. It accepts value in many input tokens, discovers what token the destination project actually accepts, and forwards the payment through the best route it can resolve from the configured candidates.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
|
|
6
|
+
## Documentation
|
|
7
|
+
|
|
8
|
+
- [INVARIANTS.md](./INVARIANTS.md) — runtime invariants enforced by the router, registry, and pay-route resolver.
|
|
9
|
+
- [ARCHITECTURE.md](./ARCHITECTURE.md) — system overview, modules, trust boundaries, and critical flows.
|
|
10
|
+
- [ADMINISTRATION.md](./ADMINISTRATION.md) — registry-owner and project-owner control surfaces, locking, and recovery.
|
|
11
|
+
- [RISKS.md](./RISKS.md) — accepted security risks (oracle, slippage, registry forwarding, token compatibility).
|
|
12
|
+
- [USER_JOURNEYS.md](./USER_JOURNEYS.md) — primary actor flows: paying, previewing, locking, and migrating.
|
|
13
|
+
- [AUDIT_INSTRUCTIONS.md](./AUDIT_INSTRUCTIONS.md) — scope, attack surfaces, and verification steps for auditors.
|
|
14
|
+
- [SKILLS.md](./SKILLS.md) — agent-oriented index pointing at the right file or contract for a given task.
|
|
15
|
+
- [STYLE_GUIDE.md](./STYLE_GUIDE.md) — Solidity and repo-layout conventions used across the V6 ecosystem.
|
|
16
|
+
- [CHANGELOG.md](./CHANGELOG.md) — v5 → v6 migration notes and in-v6 behavior changes for integrators.
|
|
12
17
|
|
|
13
18
|
## Overview
|
|
14
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananapus/router-terminal-v6",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.58",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"artifacts": "source ./.env && npx sphinx artifacts --org-id 'ea165b21-7cdc-4d7b-be59-ecdd4c26bee4' --project-name 'nana-router-terminal-v6'"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@bananapus/buyback-hook-v6": "^0.0.
|
|
27
|
+
"@bananapus/buyback-hook-v6": "^0.0.64",
|
|
28
28
|
"@bananapus/core-v6": "^0.0.72",
|
|
29
29
|
"@bananapus/permission-ids-v6": "^0.0.27",
|
|
30
30
|
"@bananapus/univ4-router-v6": "^0.0.46",
|
package/src/JBRouterTerminal.sol
CHANGED
|
@@ -154,11 +154,11 @@ contract JBRouterTerminal is
|
|
|
154
154
|
/// @notice Pre-computed metadata ID for "permit2".
|
|
155
155
|
bytes4 internal immutable _PERMIT2_ID;
|
|
156
156
|
|
|
157
|
-
/// @notice Pre-computed metadata ID for "
|
|
158
|
-
bytes4 internal immutable
|
|
157
|
+
/// @notice Pre-computed metadata ID for "cashOut" (the cash-out reclaim floor).
|
|
158
|
+
bytes4 internal immutable _CASH_OUT_ID;
|
|
159
159
|
|
|
160
|
-
/// @notice Pre-computed metadata ID for "
|
|
161
|
-
bytes4 internal immutable
|
|
160
|
+
/// @notice Pre-computed metadata ID for "pay" (the pay-phase swap quote).
|
|
161
|
+
bytes4 internal immutable _PAY_ID;
|
|
162
162
|
|
|
163
163
|
//*********************************************************************//
|
|
164
164
|
// --------------------- public stored properties -------------------- //
|
|
@@ -220,8 +220,8 @@ contract JBRouterTerminal is
|
|
|
220
220
|
|
|
221
221
|
// Pre-compute metadata IDs to avoid hashing string literals on every call.
|
|
222
222
|
_PERMIT2_ID = JBMetadataResolver.getId("permit2");
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
_CASH_OUT_ID = JBMetadataResolver.getId("cashOut");
|
|
224
|
+
_PAY_ID = JBMetadataResolver.getId("pay");
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
//*********************************************************************//
|
|
@@ -1136,7 +1136,7 @@ contract JBRouterTerminal is
|
|
|
1136
1136
|
/// @param destProjectId The ID of the destination project.
|
|
1137
1137
|
/// @param token The current token to process.
|
|
1138
1138
|
/// @param amount The amount of the current token.
|
|
1139
|
-
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain
|
|
1139
|
+
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain a `cashOut` reclaim floor).
|
|
1140
1140
|
/// @return destTerminal The terminal that accepts the final token (address(0) if no direct acceptance found).
|
|
1141
1141
|
/// @return finalToken The token after all cashouts.
|
|
1142
1142
|
/// @return finalAmount The amount of the final token.
|
|
@@ -1240,7 +1240,7 @@ contract JBRouterTerminal is
|
|
|
1240
1240
|
/// @param tokenOut The token to convert into.
|
|
1241
1241
|
/// @param amount The amount to convert.
|
|
1242
1242
|
/// @param projectId The project ID (passed through to swap callback data).
|
|
1243
|
-
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain
|
|
1243
|
+
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain a `pay` swap quote).
|
|
1244
1244
|
/// @param refundTo The address to receive leftover input tokens from partial fills.
|
|
1245
1245
|
/// @return The amount of tokenOut produced.
|
|
1246
1246
|
function _convert(
|
|
@@ -1422,7 +1422,7 @@ contract JBRouterTerminal is
|
|
|
1422
1422
|
/// @param tokenIn The token to swap from.
|
|
1423
1423
|
/// @param tokenOut The token to swap into.
|
|
1424
1424
|
/// @param amount The amount of tokenIn to swap.
|
|
1425
|
-
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain
|
|
1425
|
+
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain a `pay` swap quote).
|
|
1426
1426
|
/// @param refundTo The address to receive leftover input tokens from partial fills.
|
|
1427
1427
|
/// @return amountOut The amount of tokenOut received.
|
|
1428
1428
|
function _handleSwap(
|
|
@@ -1587,7 +1587,7 @@ contract JBRouterTerminal is
|
|
|
1587
1587
|
/// @param destProjectId The destination project to reach.
|
|
1588
1588
|
/// @param tokenIn The current route input token.
|
|
1589
1589
|
/// @param amount The current route input amount.
|
|
1590
|
-
/// @param metadata Metadata that may include a
|
|
1590
|
+
/// @param metadata Metadata that may include a `cashOut` reclaim floor.
|
|
1591
1591
|
/// @param preferredToken The preferred token to target during any cashout loop.
|
|
1592
1592
|
/// @return resolvedTerminal The terminal found by the cashout loop, or address(0) if conversion should continue.
|
|
1593
1593
|
/// @return routedTokenIn The token that remains to be routed after the cashout step.
|
|
@@ -2263,7 +2263,7 @@ contract JBRouterTerminal is
|
|
|
2263
2263
|
/// 3. Thin pools, newly initialized pools, and unusually large swaps should not rely on this fallback.
|
|
2264
2264
|
///
|
|
2265
2265
|
/// Mitigations in place:
|
|
2266
|
-
/// 1. Users SHOULD provide a `
|
|
2266
|
+
/// 1. Users SHOULD provide a `pay` swap quote in the payment metadata (obtained from an off-chain
|
|
2267
2267
|
/// quoter or RPC simulation). The quote must encode the output token and minimum output amount. When present,
|
|
2268
2268
|
/// this function is bypassed entirely — see `_pickPoolAndQuote`.
|
|
2269
2269
|
/// 2. When a hook implements `IGeomeanOracle.observe(...)`, this function uses that oracle-derived tick instead
|
|
@@ -2276,7 +2276,7 @@ contract JBRouterTerminal is
|
|
|
2276
2276
|
/// this V4 spot-price path altogether.
|
|
2277
2277
|
///
|
|
2278
2278
|
/// Despite these mitigations, the spot-based fallback does NOT provide full MEV protection. Integrators and
|
|
2279
|
-
/// front-ends should supply `
|
|
2279
|
+
/// front-ends should supply `pay` swap-quote metadata for V4 swaps whenever possible so the user's slippage
|
|
2280
2280
|
/// tolerance reflects a recent, off-chain-verified price. When no external quote can be provided, this fallback
|
|
2281
2281
|
/// is still available as an accepted-risk convenience path.
|
|
2282
2282
|
/// @param key The V4 pool key describing the pool to quote against.
|
|
@@ -2376,11 +2376,11 @@ contract JBRouterTerminal is
|
|
|
2376
2376
|
}
|
|
2377
2377
|
}
|
|
2378
2378
|
|
|
2379
|
-
/// @notice Parse the optional `
|
|
2379
|
+
/// @notice Parse the optional `cashOut` metadata (the minimum-reclaim floor).
|
|
2380
2380
|
/// @param metadata The metadata to inspect for minimum reclaim amounts.
|
|
2381
2381
|
/// @return minTokensReclaimed The minimum reclaim amount, or 0 if none is specified.
|
|
2382
2382
|
function _minReclaimedFrom(bytes calldata metadata) internal view returns (uint256 minTokensReclaimed) {
|
|
2383
|
-
(bool exists, bytes memory minData) = _getDataFor({metadata: metadata, id:
|
|
2383
|
+
(bool exists, bytes memory minData) = _getDataFor({metadata: metadata, id: _CASH_OUT_ID});
|
|
2384
2384
|
if (exists) minTokensReclaimed = abi.decode(minData, (uint256));
|
|
2385
2385
|
}
|
|
2386
2386
|
|
|
@@ -2418,10 +2418,10 @@ contract JBRouterTerminal is
|
|
|
2418
2418
|
/// @dev For V4 pools without TWAP-capable hooks, `minAmountOut` is derived from the same-block spot tick, which is
|
|
2419
2419
|
/// manipulable via sandwich attacks. This is an accepted risk for integrations that cannot source external quotes,
|
|
2420
2420
|
/// especially when routing through deep pools and routine swap sizes, but it should not be treated as full MEV
|
|
2421
|
-
/// protection. Integrators should still supply `
|
|
2421
|
+
/// protection. Integrators should still supply `pay` swap-quote metadata whenever they can.
|
|
2422
2422
|
///
|
|
2423
2423
|
/// Priority for `minAmountOut`:
|
|
2424
|
-
/// 1. **User-provided quote** — If `
|
|
2424
|
+
/// 1. **User-provided quote** — If a `pay` swap quote is present in `metadata`, it is used after confirming the
|
|
2425
2425
|
/// quote's output token matches the selected route. This is the recommended path for MEV protection,
|
|
2426
2426
|
/// especially for V4 pools.
|
|
2427
2427
|
/// 2. **V3 TWAP** — If the best pool is V3, uses a manipulation-resistant time-weighted average price.
|
|
@@ -2430,7 +2430,7 @@ contract JBRouterTerminal is
|
|
|
2430
2430
|
/// same block (see `_getV4SpotQuote` security note). The sigmoid slippage formula provides a floor but not
|
|
2431
2431
|
/// full MEV protection.
|
|
2432
2432
|
///
|
|
2433
|
-
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain
|
|
2433
|
+
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain a `pay` swap quote).
|
|
2434
2434
|
/// @param normalizedTokenIn The normalized input token address.
|
|
2435
2435
|
/// @param amount The amount of tokens to swap.
|
|
2436
2436
|
/// @param normalizedTokenOut The normalized output token address.
|
|
@@ -2452,9 +2452,9 @@ contract JBRouterTerminal is
|
|
|
2452
2452
|
revert JBRouterTerminal_NoPoolFound({tokenIn: normalizedTokenIn, tokenOut: normalizedTokenOut});
|
|
2453
2453
|
}
|
|
2454
2454
|
|
|
2455
|
-
// `
|
|
2455
|
+
// `pay` is encoded as `(tokenOut, minAmountOut)`. Binding the quote to its output token prevents
|
|
2456
2456
|
// metadata quoted for one route from being replayed against another route with a weaker floor.
|
|
2457
|
-
(bool exists, bytes memory quote) = _getDataFor({metadata: metadata, id:
|
|
2457
|
+
(bool exists, bytes memory quote) = _getDataFor({metadata: metadata, id: _PAY_ID});
|
|
2458
2458
|
|
|
2459
2459
|
if (exists) {
|
|
2460
2460
|
(address quotedTokenOut, uint256 quotedMinAmountOut) = abi.decode(quote, (address, uint256));
|