@@ -21,24 +21,35 @@ contract CrestManager is Auth, ReentrancyGuard {
2121 // ========================================= CONSTANTS =========================================
2222
2323 /**
24- * @notice USDT0 token ID on Hyperliquid Core (bridgeable )
24+ * @notice USDC token ID on Hyperliquid Core (for trading )
2525 */
26- uint64 public constant USDT0_TOKEN_ID = 268 ;
26+ uint64 public constant USDC_TOKEN_ID = 0 ;
27+
28+ uint256 public constant TESTNET_CHAINID = 998 ;
2729
2830 /**
29- * @notice USDT0 ERC20 address on Hyperliquid EVM
31+ * @notice USDT0 token ID on Hyperliquid Core (bridgeable)
3032 */
31- address public constant USDT0_ADDRESS = 0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb ;
33+ function usdt0TokenId () internal view returns (uint64 ) {
34+ return block .chainid == TESTNET_CHAINID ? 1204 : 268 ;
35+ }
3236
3337 /**
34- * @notice USDC token ID on Hyperliquid Core (for trading)
38+ * @notice USDT0 ERC20 address on Hyperliquid EVM
3539 */
36- uint64 public constant USDC_TOKEN_ID = 0 ;
40+ function usdt0Address () internal view returns (address ) {
41+ return
42+ block .chainid == TESTNET_CHAINID
43+ ? 0x779Ded0c9e1022225f8E0630b35a9b54bE713736
44+ : 0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb ;
45+ }
3746
3847 /**
3948 * @notice USDT0/USDC spot index for swapping
4049 */
41- uint32 public constant USDT0_USDC_SPOT_INDEX = 166 ;
50+ function usdt0SpotIndex () internal view returns (uint32 ) {
51+ return block .chainid == TESTNET_CHAINID ? 1115 : 166 ;
52+ }
4253
4354 /**
4455 * @notice Allocation percentages (basis points)
@@ -191,21 +202,21 @@ contract CrestManager is Auth, ReentrancyGuard {
191202
192203 // Bridge USDT0 to Hyperliquid core
193204 CoreWriterLib.bridgeToCore (
194- USDT0_ADDRESS ,
205+ usdt0Address () ,
195206 marginAmount + spotAmount + perpAmount
196207 );
197208
198209 // Swap USDT0 to USDC on Hyperliquid
199210 uint64 usdt0CoreAmount = HLConversions.evmToWei (
200- USDT0_TOKEN_ID ,
211+ usdt0TokenId () ,
201212 marginAmount + spotAmount + perpAmount
202213 );
203214
204215 // Place market order to sell USDT0 for USDC
205216 CoreWriterLib.placeLimitOrder (
206- USDT0_USDC_SPOT_INDEX ,
217+ usdt0SpotIndex () ,
207218 false , // sell USDT0
208- PrecompileLib.spotPx (USDT0_USDC_SPOT_INDEX ) - 10 , // slight slippage for immediate fill
219+ PrecompileLib.spotPx (usdt0SpotIndex () ) - 10 , // slight slippage for immediate fill
209220 usdt0CoreAmount,
210221 false , // not reduce only
211222 3 , // IOC
@@ -231,7 +242,7 @@ contract CrestManager is Auth, ReentrancyGuard {
231242 CoreWriterLib.placeLimitOrder (
232243 spotIndex,
233244 true , // isBuy
234- spotPrice + (spotPrice * 50 / 10000 ), // 0.5% slippage
245+ spotPrice + (( spotPrice * 50 ) / 10000 ), // 0.5% slippage
235246 spotSizeInAsset,
236247 false , // reduceOnly
237248 3 , // IOC (Immediate or Cancel)
@@ -257,7 +268,7 @@ contract CrestManager is Auth, ReentrancyGuard {
257268 CoreWriterLib.placeLimitOrder (
258269 perpIndex,
259270 false , // isBuy (short)
260- perpPrice - (perpPrice * 50 / 10000 ), // 0.5% slippage
271+ perpPrice - (( perpPrice * 50 ) / 10000 ), // 0.5% slippage
261272 perpSizeInAsset,
262273 false , // reduceOnly
263274 3 , // IOC (Immediate or Cancel)
@@ -345,7 +356,7 @@ contract CrestManager is Auth, ReentrancyGuard {
345356 CoreWriterLib.placeLimitOrder (
346357 currentSpotPosition.index,
347358 false , // isBuy (sell to close)
348- currentSpotPrice - (currentSpotPrice * 50 / 10000 ), // 0.5% below market for immediate fill
359+ currentSpotPrice - (( currentSpotPrice * 50 ) / 10000 ), // 0.5% below market for immediate fill
349360 currentSpotPosition.size,
350361 true , // reduceOnly
351362 3 , // IOC
@@ -390,7 +401,7 @@ contract CrestManager is Auth, ReentrancyGuard {
390401 CoreWriterLib.placeLimitOrder (
391402 currentPerpPosition.index,
392403 true , // isBuy (buy to close short)
393- currentPerpPrice + (currentPerpPrice * 50 / 10000 ), // 0.5% above market for immediate fill
404+ currentPerpPrice + (( currentPerpPrice * 50 ) / 10000 ), // 0.5% above market for immediate fill
394405 currentPerpPosition.size,
395406 true , // reduceOnly
396407 3 , // IOC
@@ -441,9 +452,9 @@ contract CrestManager is Auth, ReentrancyGuard {
441452 if (spotBalance.total > 0 ) {
442453 // Buy USDT0 with USDC
443454 CoreWriterLib.placeLimitOrder (
444- USDT0_USDC_SPOT_INDEX ,
455+ usdt0SpotIndex () ,
445456 true , // buy USDT0
446- PrecompileLib.spotPx (USDT0_USDC_SPOT_INDEX ) + 10 , // slight slippage
457+ PrecompileLib.spotPx (usdt0SpotIndex () ) + 10 , // slight slippage
447458 spotBalance.total,
448459 false ,
449460 3 , // IOC
@@ -452,9 +463,13 @@ contract CrestManager is Auth, ReentrancyGuard {
452463
453464 // Get USDT0 balance and bridge back
454465 PrecompileLib.SpotBalance memory usdt0Balance = PrecompileLib
455- .spotBalance (address (this ), USDT0_TOKEN_ID );
466+ .spotBalance (address (this ), usdt0TokenId () );
456467 if (usdt0Balance.total > 0 ) {
457- CoreWriterLib.bridgeToEvm (USDT0_TOKEN_ID, usdt0Balance.total, false );
468+ CoreWriterLib.bridgeToEvm (
469+ usdt0TokenId (),
470+ usdt0Balance.total,
471+ false
472+ );
458473 }
459474 }
460475
0 commit comments