@bananapus/router-terminal-v6 0.0.2 → 0.0.4
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/foundry.toml +1 -1
- package/package.json +2 -2
- package/src/JBRouterTerminal.sol +44 -55
package/foundry.toml
CHANGED
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.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"artifacts": "source ./.env && npx sphinx artifacts --org-id 'ea165b21-7cdc-4d7b-be59-ecdd4c26bee4' --project-name 'nana-router-terminal-v6'"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@bananapus/core-v6": "^0.0.
|
|
20
|
+
"@bananapus/core-v6": "^0.0.5",
|
|
21
21
|
"@openzeppelin/contracts": "^5.2.0",
|
|
22
22
|
"@uniswap/permit2": "github:Uniswap/permit2",
|
|
23
23
|
"@uniswap/v3-core": "github:Uniswap/v3-core#0.8",
|
package/src/JBRouterTerminal.sol
CHANGED
|
@@ -71,16 +71,20 @@ contract JBRouterTerminal is
|
|
|
71
71
|
/// @notice The default TWAP window used for auto-discovered pools.
|
|
72
72
|
uint256 public constant DEFAULT_TWAP_WINDOW = 10 minutes;
|
|
73
73
|
|
|
74
|
+
/// @notice The denominator used for slippage tolerance basis points.
|
|
75
|
+
uint256 public constant SLIPPAGE_DENOMINATOR = 10_000;
|
|
76
|
+
|
|
77
|
+
//*********************************************************************//
|
|
78
|
+
// ---------------------- internal stored properties ----------------- //
|
|
79
|
+
//*********************************************************************//
|
|
80
|
+
|
|
74
81
|
/// @notice The fee tiers to search when auto-discovering V3 pools, ordered by commonality.
|
|
75
82
|
/// 3000 = 0.3%, 500 = 0.05%, 10000 = 1%, 100 = 0.01%.
|
|
76
|
-
uint24[4]
|
|
83
|
+
uint24[4] internal _FEE_TIERS = [uint24(3000), uint24(500), uint24(10_000), uint24(100)];
|
|
77
84
|
|
|
78
85
|
/// @notice The fee/tickSpacing pairings to search for V4 vanilla pools.
|
|
79
|
-
uint24[4]
|
|
80
|
-
int24[4]
|
|
81
|
-
|
|
82
|
-
/// @notice The denominator used for slippage tolerance basis points.
|
|
83
|
-
uint256 public constant SLIPPAGE_DENOMINATOR = 10_000;
|
|
86
|
+
uint24[4] internal _V4_FEES = [uint24(3000), uint24(500), uint24(10_000), uint24(100)];
|
|
87
|
+
int24[4] internal _V4_TICK_SPACINGS = [int24(60), int24(10), int24(200), int24(1)];
|
|
84
88
|
|
|
85
89
|
//*********************************************************************//
|
|
86
90
|
// ---------------- public immutable stored properties --------------- //
|
|
@@ -607,46 +611,32 @@ contract JBRouterTerminal is
|
|
|
607
611
|
function _bestPoolLiquidity(address tokenA, address tokenB) internal view returns (uint128 bestLiquidity) {
|
|
608
612
|
// Search V3.
|
|
609
613
|
for (uint256 i; i < 4; i++) {
|
|
610
|
-
address poolAddr = FACTORY.getPool(tokenA, tokenB,
|
|
614
|
+
address poolAddr = FACTORY.getPool(tokenA, tokenB, _FEE_TIERS[i]);
|
|
611
615
|
if (poolAddr == address(0)) continue;
|
|
612
616
|
|
|
613
617
|
uint128 liquidity = IUniswapV3Pool(poolAddr).liquidity();
|
|
614
618
|
if (liquidity > bestLiquidity) bestLiquidity = liquidity;
|
|
615
619
|
}
|
|
616
620
|
|
|
617
|
-
// Search V4.
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
for (uint256 i; i < 4; i++) {
|
|
637
|
-
PoolKey memory key = PoolKey({
|
|
638
|
-
currency0: Currency.wrap(sorted0),
|
|
639
|
-
currency1: Currency.wrap(sorted1),
|
|
640
|
-
fee: V4_FEES[i],
|
|
641
|
-
tickSpacing: V4_TICK_SPACINGS[i],
|
|
642
|
-
hooks: IHooks(address(0))
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
(uint160 sqrtPriceX96,,,) = POOL_MANAGER.getSlot0(key.toId());
|
|
646
|
-
if (sqrtPriceX96 == 0) continue;
|
|
647
|
-
|
|
648
|
-
uint128 liquidity = POOL_MANAGER.getLiquidity(key.toId());
|
|
649
|
-
if (liquidity > bestLiquidity) bestLiquidity = liquidity;
|
|
621
|
+
// Search V4 — reuse _discoverV4Pool with current best.
|
|
622
|
+
PoolInfo memory v4Result = _discoverV4Pool(
|
|
623
|
+
tokenA,
|
|
624
|
+
tokenB,
|
|
625
|
+
bestLiquidity,
|
|
626
|
+
PoolInfo({
|
|
627
|
+
isV4: false,
|
|
628
|
+
v3Pool: IUniswapV3Pool(address(0)),
|
|
629
|
+
v4Key: PoolKey({
|
|
630
|
+
currency0: Currency.wrap(address(0)),
|
|
631
|
+
currency1: Currency.wrap(address(0)),
|
|
632
|
+
fee: 0,
|
|
633
|
+
tickSpacing: 0,
|
|
634
|
+
hooks: IHooks(address(0))
|
|
635
|
+
})
|
|
636
|
+
})
|
|
637
|
+
);
|
|
638
|
+
if (v4Result.isV4) {
|
|
639
|
+
bestLiquidity = POOL_MANAGER.getLiquidity(v4Result.v4Key.toId());
|
|
650
640
|
}
|
|
651
641
|
}
|
|
652
642
|
|
|
@@ -986,7 +976,7 @@ contract JBRouterTerminal is
|
|
|
986
976
|
|
|
987
977
|
// Search V3.
|
|
988
978
|
for (uint256 i; i < 4; i++) {
|
|
989
|
-
address poolAddr = FACTORY.getPool(normalizedTokenIn, normalizedTokenOut,
|
|
979
|
+
address poolAddr = FACTORY.getPool(normalizedTokenIn, normalizedTokenOut, _FEE_TIERS[i]);
|
|
990
980
|
|
|
991
981
|
if (poolAddr == address(0)) continue;
|
|
992
982
|
|
|
@@ -994,7 +984,17 @@ contract JBRouterTerminal is
|
|
|
994
984
|
|
|
995
985
|
if (poolLiquidity > bestLiquidity) {
|
|
996
986
|
bestLiquidity = poolLiquidity;
|
|
997
|
-
bestPool = PoolInfo({
|
|
987
|
+
bestPool = PoolInfo({
|
|
988
|
+
isV4: false,
|
|
989
|
+
v3Pool: IUniswapV3Pool(poolAddr),
|
|
990
|
+
v4Key: PoolKey({
|
|
991
|
+
currency0: Currency.wrap(address(0)),
|
|
992
|
+
currency1: Currency.wrap(address(0)),
|
|
993
|
+
fee: 0,
|
|
994
|
+
tickSpacing: 0,
|
|
995
|
+
hooks: IHooks(address(0))
|
|
996
|
+
})
|
|
997
|
+
});
|
|
998
998
|
}
|
|
999
999
|
}
|
|
1000
1000
|
|
|
@@ -1030,8 +1030,8 @@ contract JBRouterTerminal is
|
|
|
1030
1030
|
PoolKey memory key = PoolKey({
|
|
1031
1031
|
currency0: Currency.wrap(sorted0),
|
|
1032
1032
|
currency1: Currency.wrap(sorted1),
|
|
1033
|
-
fee:
|
|
1034
|
-
tickSpacing:
|
|
1033
|
+
fee: _V4_FEES[i],
|
|
1034
|
+
tickSpacing: _V4_TICK_SPACINGS[i],
|
|
1035
1035
|
hooks: IHooks(address(0))
|
|
1036
1036
|
});
|
|
1037
1037
|
|
|
@@ -1309,17 +1309,6 @@ contract JBRouterTerminal is
|
|
|
1309
1309
|
PERMIT2.transferFrom(from, to, uint160(amount), token);
|
|
1310
1310
|
}
|
|
1311
1311
|
|
|
1312
|
-
/// @notice Returns an empty PoolKey for use in V3-only PoolInfo structs.
|
|
1313
|
-
function _emptyPoolKey() internal pure returns (PoolKey memory) {
|
|
1314
|
-
return PoolKey({
|
|
1315
|
-
currency0: Currency.wrap(address(0)),
|
|
1316
|
-
currency1: Currency.wrap(address(0)),
|
|
1317
|
-
fee: 0,
|
|
1318
|
-
tickSpacing: 0,
|
|
1319
|
-
hooks: IHooks(address(0))
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
1312
|
//*********************************************************************//
|
|
1324
1313
|
// ---------------------------- receive ----------------------------- //
|
|
1325
1314
|
//*********************************************************************//
|