@bananapus/router-terminal-v6 0.0.61 → 0.0.63
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananapus/router-terminal-v6",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.63",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,10 +24,10 @@
|
|
|
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.
|
|
28
|
-
"@bananapus/core-v6": "^0.0.
|
|
27
|
+
"@bananapus/buyback-hook-v6": "^0.0.68",
|
|
28
|
+
"@bananapus/core-v6": "^0.0.81",
|
|
29
29
|
"@bananapus/permission-ids-v6": "^0.0.28",
|
|
30
|
-
"@bananapus/univ4-router-v6": "^0.0.
|
|
30
|
+
"@bananapus/univ4-router-v6": "^0.0.51",
|
|
31
31
|
"@openzeppelin/contracts": "5.6.1",
|
|
32
32
|
"@uniswap/permit2": "github:Uniswap/permit2#cc56ad0f3439c502c246fc5cfcc3db92bb8b7219",
|
|
33
33
|
"@uniswap/v3-core": "github:Uniswap/v3-core#6562c52e8f75f0c10f9deaf44861847585fc8129",
|
package/src/JBRouterTerminal.sol
CHANGED
|
@@ -1161,6 +1161,8 @@ contract JBRouterTerminal is
|
|
|
1161
1161
|
/// @param token The current token to process.
|
|
1162
1162
|
/// @param amount The amount of the current token.
|
|
1163
1163
|
/// @param metadata Bytes in `JBMetadataResolver`'s format (may contain a `cashOut` reclaim floor).
|
|
1164
|
+
/// @param refundTo The address that should receive any unsold source project tokens returned by a partial
|
|
1165
|
+
/// buyback-hook cash-out fill (otherwise they would strand in this router).
|
|
1164
1166
|
/// @return destTerminal The terminal that accepts the final token (address(0) if no direct acceptance found).
|
|
1165
1167
|
/// @return finalToken The token after all cashouts.
|
|
1166
1168
|
/// @return finalAmount The amount of the final token.
|
|
@@ -1169,7 +1171,8 @@ contract JBRouterTerminal is
|
|
|
1169
1171
|
address token,
|
|
1170
1172
|
uint256 amount,
|
|
1171
1173
|
bytes calldata metadata,
|
|
1172
|
-
address preferredToken
|
|
1174
|
+
address preferredToken,
|
|
1175
|
+
address payable refundTo
|
|
1173
1176
|
)
|
|
1174
1177
|
internal
|
|
1175
1178
|
returns (IJBTerminal destTerminal, address finalToken, uint256 finalAmount)
|
|
@@ -1209,6 +1212,10 @@ contract JBRouterTerminal is
|
|
|
1209
1212
|
uint256 cashOutCount = amount;
|
|
1210
1213
|
uint256 balanceBefore = _balanceOf({token: tokenToReclaim, account: address(this)});
|
|
1211
1214
|
|
|
1215
|
+
// Snapshot the source project-token balance so the unsold residue a partial buyback fill returns to this
|
|
1216
|
+
// router can be measured precisely below (only this hop's residue, never pre-existing balances).
|
|
1217
|
+
uint256 sourceBalanceBefore = _balanceOf({token: token, account: address(this)});
|
|
1218
|
+
|
|
1212
1219
|
// Cash out the source project's tokens.
|
|
1213
1220
|
// Don't rely on the terminal return value here. Buyback-hook sell-side execution returns 0 reclaimAmount
|
|
1214
1221
|
// from nana-core, then transfers the real proceeds during the hook callback.
|
|
@@ -1225,8 +1232,7 @@ contract JBRouterTerminal is
|
|
|
1225
1232
|
tokenToReclaim: tokenToReclaim,
|
|
1226
1233
|
minTokensReclaimed: 0,
|
|
1227
1234
|
beneficiary: payable(address(this)),
|
|
1228
|
-
metadata: hopMetadata
|
|
1229
|
-
referralProjectId: 0
|
|
1235
|
+
metadata: hopMetadata
|
|
1230
1236
|
});
|
|
1231
1237
|
|
|
1232
1238
|
// Measure the reclaimed-token balance delta so fee-on-transfer behavior cannot fake delivery.
|
|
@@ -1244,6 +1250,16 @@ contract JBRouterTerminal is
|
|
|
1244
1250
|
revert JBRouterTerminal_SlippageExceeded({amountOut: amount, minAmountOut: minTokensReclaimed});
|
|
1245
1251
|
}
|
|
1246
1252
|
|
|
1253
|
+
// Refund any unsold source project tokens the buyback hook returned on a partial fill. The terminal burned
|
|
1254
|
+
// `cashOutCount` source tokens before the hook ran, so the post-cash-out source balance is
|
|
1255
|
+
// `sourceBalanceBefore - cashOutCount + unsold`; recovering `unsold` refunds exactly this hop's residue to
|
|
1256
|
+
// the route's refund recipient instead of stranding it, without sweeping any pre-existing balance.
|
|
1257
|
+
uint256 sourceResidue =
|
|
1258
|
+
_balanceOf({token: token, account: address(this)}) + cashOutCount - sourceBalanceBefore;
|
|
1259
|
+
if (sourceResidue != 0) {
|
|
1260
|
+
_transferFrom({from: address(this), to: refundTo, token: token, amount: sourceResidue});
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1247
1263
|
// Clear the reclaim minimum after the first hop.
|
|
1248
1264
|
// Multi-hop routes can change token units between hops, so there is no sound generic way to rescale a
|
|
1249
1265
|
// single metadata amount across the remaining path.
|
|
@@ -1545,7 +1561,8 @@ contract JBRouterTerminal is
|
|
|
1545
1561
|
tokenIn: tokenIn,
|
|
1546
1562
|
amount: amount,
|
|
1547
1563
|
metadata: metadata,
|
|
1548
|
-
preferredToken: address(0)
|
|
1564
|
+
preferredToken: address(0),
|
|
1565
|
+
refundTo: refundTo
|
|
1549
1566
|
});
|
|
1550
1567
|
|
|
1551
1568
|
// If the cashout loop found a destination terminal, the route is already complete.
|
|
@@ -1605,7 +1622,12 @@ contract JBRouterTerminal is
|
|
|
1605
1622
|
|
|
1606
1623
|
// First route through any source-project cashout path so project-token inputs are converted before swap logic.
|
|
1607
1624
|
(cashOutResolvedTerminal, tokenIn, amount) = _routeInputFromSource({
|
|
1608
|
-
destProjectId: destProjectId,
|
|
1625
|
+
destProjectId: destProjectId,
|
|
1626
|
+
tokenIn: tokenIn,
|
|
1627
|
+
amount: amount,
|
|
1628
|
+
metadata: metadata,
|
|
1629
|
+
preferredToken: tokenOut,
|
|
1630
|
+
refundTo: refundTo
|
|
1609
1631
|
});
|
|
1610
1632
|
|
|
1611
1633
|
// Return early when the source cashout path already reached the final destination terminal.
|
|
@@ -1629,6 +1651,7 @@ contract JBRouterTerminal is
|
|
|
1629
1651
|
/// @param amount The current route input amount.
|
|
1630
1652
|
/// @param metadata Metadata that may include a `cashOut` reclaim floor.
|
|
1631
1653
|
/// @param preferredToken The preferred token to target during any cashout loop.
|
|
1654
|
+
/// @param refundTo The address that should receive any unsold source project tokens from a partial buyback fill.
|
|
1632
1655
|
/// @return resolvedTerminal The terminal found by the cashout loop, or address(0) if conversion should continue.
|
|
1633
1656
|
/// @return routedTokenIn The token that remains to be routed after the cashout step.
|
|
1634
1657
|
/// @return routedAmountIn The amount of `routedTokenIn` that remains to be routed.
|
|
@@ -1637,7 +1660,8 @@ contract JBRouterTerminal is
|
|
|
1637
1660
|
address tokenIn,
|
|
1638
1661
|
uint256 amount,
|
|
1639
1662
|
bytes calldata metadata,
|
|
1640
|
-
address preferredToken
|
|
1663
|
+
address preferredToken,
|
|
1664
|
+
address payable refundTo
|
|
1641
1665
|
)
|
|
1642
1666
|
internal
|
|
1643
1667
|
returns (IJBTerminal resolvedTerminal, address routedTokenIn, uint256 routedAmountIn)
|
|
@@ -1651,7 +1675,8 @@ contract JBRouterTerminal is
|
|
|
1651
1675
|
token: tokenIn,
|
|
1652
1676
|
amount: amount,
|
|
1653
1677
|
metadata: metadata,
|
|
1654
|
-
preferredToken: preferredToken
|
|
1678
|
+
preferredToken: preferredToken,
|
|
1679
|
+
refundTo: refundTo
|
|
1655
1680
|
});
|
|
1656
1681
|
}
|
|
1657
1682
|
|
|
@@ -153,8 +153,15 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
153
153
|
override
|
|
154
154
|
returns (JBAccountingContext memory context)
|
|
155
155
|
{
|
|
156
|
-
//
|
|
157
|
-
|
|
156
|
+
// Discovery view, fail-open: resolve the project's effective terminal WITHOUT reverting. When no terminal can
|
|
157
|
+
// be resolved (e.g. no default terminal has been set on this chain yet), return an empty context
|
|
158
|
+
// (`token == address(0)`) rather than reverting. Callers such as `JBDirectory.primaryTerminalOf` read this to
|
|
159
|
+
// decide whether the registry accepts the token; an empty context means "not accepted", letting them fall
|
|
160
|
+
// through to `address(0)` instead of propagating a revert that would brick the originating operation (e.g. a
|
|
161
|
+
// protocol-fee cash out/payout routed to project #1). Transactional paths keep `_requireResolvedTerminalOf`
|
|
162
|
+
// and still revert before accepting funds or forwarding into `address(0)`.
|
|
163
|
+
IJBTerminal terminal = _resolvedTerminalOf(projectId);
|
|
164
|
+
if (terminal == IJBTerminal(address(0))) return context;
|
|
158
165
|
|
|
159
166
|
// Get the accounting context for the token.
|
|
160
167
|
return terminal.accountingContextForTokenOf({projectId: projectId, token: token});
|
|
@@ -169,8 +176,11 @@ contract JBRouterTerminalRegistry is IJBRouterTerminalRegistry, JBPermissioned,
|
|
|
169
176
|
override
|
|
170
177
|
returns (JBAccountingContext[] memory contexts)
|
|
171
178
|
{
|
|
172
|
-
//
|
|
173
|
-
|
|
179
|
+
// Discovery view, fail-open: resolve WITHOUT reverting and return an empty array when no terminal can be
|
|
180
|
+
// resolved on this chain (see `accountingContextForTokenOf`). Transactional paths keep
|
|
181
|
+
// `_requireResolvedTerminalOf` and still revert.
|
|
182
|
+
IJBTerminal terminal = _resolvedTerminalOf(projectId);
|
|
183
|
+
if (terminal == IJBTerminal(address(0))) return contexts;
|
|
174
184
|
|
|
175
185
|
// Get the accounting contexts.
|
|
176
186
|
return terminal.accountingContextsOf(projectId);
|