mirror of
https://github.com/luxfi/precompile.git
synced 2026-09-24 00:26:21 +00:00
chore: use Lux-native naming for the DEX core/EVM-adapter model
Rename the mock external perps venue in the integration test to a neutral name and reword NatSpec/docs to Lux's own terms (native HFT surface, single-entrypoint execute() dispatch, robust index methodology). Behavior-preserving: integration test passes; no ABI changes.
This commit is contained in:
+16
-16
@@ -16,7 +16,7 @@ import (
|
||||
//
|
||||
// Demonstrates how the ATS backend connects to the DEX precompile:
|
||||
// - LXRouter routes swaps through V4 pools (on-chain matching)
|
||||
// - External venues (Alpaca, Hyperliquid) provide indicative quotes
|
||||
// - External venues (Alpaca, a perps DEX) provide indicative quotes
|
||||
// - Actual external execution settles via FillAttestation (LP-9090)
|
||||
// - Pause/Freeze controls enforce regulatory compliance
|
||||
// =========================================================================
|
||||
@@ -53,18 +53,18 @@ func (v *mockAlpacaVenue) Quote(stateDB StateDB, tokenIn, tokenOut common.Addres
|
||||
return new(big.Int).Div(new(big.Int).Mul(amountIn, big.NewInt(95)), big.NewInt(100)), nil
|
||||
}
|
||||
|
||||
// mockHyperliquidVenue simulates the Hyperliquid perps DEX.
|
||||
// mockPerpsVenue simulates an external perps DEX.
|
||||
// Provides indicative quotes at ~3% spread (0.97x).
|
||||
type mockHyperliquidVenue struct{}
|
||||
type mockPerpsVenue struct{}
|
||||
|
||||
func (v *mockHyperliquidVenue) VenueID() [32]byte {
|
||||
func (v *mockPerpsVenue) VenueID() [32]byte {
|
||||
var id [32]byte
|
||||
copy(id[:], []byte("hyperliquid"))
|
||||
copy(id[:], []byte("perps"))
|
||||
return id
|
||||
}
|
||||
|
||||
func (v *mockHyperliquidVenue) Quote(stateDB StateDB, tokenIn, tokenOut common.Address, amountIn *big.Int) (*big.Int, error) {
|
||||
// Hyperliquid gives 0.97x the input (simulating ~3% spread for perps)
|
||||
func (v *mockPerpsVenue) Quote(stateDB StateDB, tokenIn, tokenOut common.Address, amountIn *big.Int) (*big.Int, error) {
|
||||
// The perps venue gives 0.97x the input (simulating ~3% spread for perps)
|
||||
return new(big.Int).Div(new(big.Int).Mul(amountIn, big.NewInt(97)), big.NewInt(100)), nil
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ func testSetup(t *testing.T) {
|
||||
t.Log("Registering external venue: Alpaca (equities, ~5% spread)")
|
||||
router.RegisterVenue(&mockAlpacaVenue{})
|
||||
|
||||
t.Log("Registering external venue: Hyperliquid (perps, ~3% spread)")
|
||||
router.RegisterVenue(&mockHyperliquidVenue{})
|
||||
t.Log("Registering external venue: Perps DEX (perps, ~3% spread)")
|
||||
router.RegisterVenue(&mockPerpsVenue{})
|
||||
|
||||
t.Logf("Setup complete: 3 pools initialized, 2 external venues registered")
|
||||
|
||||
@@ -210,7 +210,7 @@ func testMultiHopSwap(t *testing.T) {
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Step 4: Multi-venue quote — V4 pool + Alpaca + Hyperliquid
|
||||
// Step 4: Multi-venue quote — V4 pool + Alpaca + Perps DEX
|
||||
// =========================================================================
|
||||
|
||||
func testMultiVenueQuote(t *testing.T) {
|
||||
@@ -222,7 +222,7 @@ func testMultiVenueQuote(t *testing.T) {
|
||||
|
||||
setupV4Pool(t, pm, stateDB, tUSDL, tETH)
|
||||
router.RegisterVenue(&mockAlpacaVenue{})
|
||||
router.RegisterVenue(&mockHyperliquidVenue{})
|
||||
router.RegisterVenue(&mockPerpsVenue{})
|
||||
|
||||
amountIn := big.NewInt(10_000)
|
||||
quotes, err := router.QuoteExactInputSingle(stateDB, tUSDL, tETH, amountIn, 0)
|
||||
@@ -230,7 +230,7 @@ func testMultiVenueQuote(t *testing.T) {
|
||||
t.Fatalf("QuoteExactInputSingle failed: %v", err)
|
||||
}
|
||||
|
||||
// Expect 3 quotes: V4 + Alpaca + Hyperliquid
|
||||
// Expect 3 quotes: V4 + Alpaca + Perps DEX
|
||||
if len(quotes) < 3 {
|
||||
t.Fatalf("expected at least 3 quotes, got %d", len(quotes))
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func testMultiVenueQuote(t *testing.T) {
|
||||
}
|
||||
|
||||
// V4 mock engine gives 50% of input (5000), Alpaca gives 95% (9500),
|
||||
// Hyperliquid gives 97% (9700). Hyperliquid wins in this mock.
|
||||
// the perps venue gives 97% (9700). The perps venue wins in this mock.
|
||||
t.Logf("Best price: %s from %s", bestQuote.AmountOut, venueLabel(bestQuote.Venue, bestQuote.PoolID))
|
||||
|
||||
// Verify V4 is among the results
|
||||
@@ -276,7 +276,7 @@ func testExternalVenueQuoteOnly(t *testing.T) {
|
||||
|
||||
// No AAPL/USDL pool exists on-chain. Only Alpaca can quote it.
|
||||
router.RegisterVenue(&mockAlpacaVenue{})
|
||||
router.RegisterVenue(&mockHyperliquidVenue{})
|
||||
router.RegisterVenue(&mockPerpsVenue{})
|
||||
|
||||
amountIn := big.NewInt(10_000)
|
||||
|
||||
@@ -412,7 +412,7 @@ func testATSOrderFlow(t *testing.T) {
|
||||
|
||||
setupV4Pool(t, pm, stateDB, tUSDL, tETH)
|
||||
router.RegisterVenue(&mockAlpacaVenue{})
|
||||
router.RegisterVenue(&mockHyperliquidVenue{})
|
||||
router.RegisterVenue(&mockPerpsVenue{})
|
||||
|
||||
fillMgr := NewFillAttestationManager()
|
||||
|
||||
@@ -472,7 +472,7 @@ func testATSOrderFlow(t *testing.T) {
|
||||
|
||||
// --- Phase 3: External venue fill via FillAttestation ---
|
||||
// In production, if V4 has insufficient liquidity the ATS splits the order:
|
||||
// part on-chain, remainder off-chain via Broker -> Alpaca/Hyperliquid.
|
||||
// part on-chain, remainder off-chain via Broker -> Alpaca/perps venue.
|
||||
// Here we simulate the off-chain fill being recorded on-chain.
|
||||
t.Log("Phase 3: Recording external venue fill via FillAttestation (LP-9090)...")
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
# LX Architecture
|
||||
|
||||
LX is a native EVM DEX combining Uniswap v4-style AMM with Hyperliquid-class CLOB in a unified, permissionless protocol.
|
||||
LX is a native EVM DEX combining Uniswap v4-style AMM with a high-performance native CLOB in a unified, permissionless protocol.
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -302,7 +302,7 @@ Funding Payment = Position Size × Funding Rate
|
||||
|
||||
### Robust Index Construction
|
||||
|
||||
Following Hyperliquid methodology:
|
||||
Robust index methodology:
|
||||
1. Collect prices from multiple CEX/DEX sources
|
||||
2. Remove outliers (>1% deviation from median)
|
||||
3. Compute TWAP over 15-minute window
|
||||
|
||||
+2
-2
@@ -202,7 +202,7 @@ event Donate(bytes32 indexed poolId, address indexed sender, uint256 amount0, ui
|
||||
|
||||
## ILXBook (LP-9020) — CLOB Matching Engine
|
||||
|
||||
Hyperliquid-style CLOB with execute() endpoint.
|
||||
Native CLOB with single-entrypoint execute() endpoint.
|
||||
|
||||
### Custom Types
|
||||
|
||||
@@ -377,7 +377,7 @@ function cancelAllOrders(MarketId marketId) external returns (uint32 cancelled);
|
||||
function amendOrder(AmendRequest calldata req) external returns (OrderId newOrderId);
|
||||
```
|
||||
|
||||
#### Hyperliquid-Style Execute
|
||||
#### Single-Entrypoint Execute
|
||||
|
||||
```solidity
|
||||
function execute(string calldata action, bytes calldata data) external returns (bytes memory result);
|
||||
|
||||
@@ -7,7 +7,7 @@ import {ILXVault} from "./ILXVault.sol";
|
||||
/// @notice Central Limit Order Book (CLOB) matching engine for LX
|
||||
/// @dev Precompile address: LP-9020 (0x0000000000000000000000000000000000009020)
|
||||
/// @dev Matches orders and atomically settles via LXVault.applyFills()
|
||||
/// @dev Hyperliquid-style execute() endpoint for HFT
|
||||
/// @dev Native HFT surface: single-entrypoint execute() dispatch
|
||||
interface ILXBook {
|
||||
// =========================================================================
|
||||
// Custom Types
|
||||
@@ -205,11 +205,11 @@ interface ILXBook {
|
||||
function amendOrder(AmendRequest calldata req) external returns (OrderId newOrderId);
|
||||
|
||||
// =========================================================================
|
||||
// Hyperliquid-Style Execute Endpoint
|
||||
// Native HFT Execute Endpoint
|
||||
// =========================================================================
|
||||
|
||||
/// @notice Single entry point for all trading operations
|
||||
/// @dev Hyperliquid-compatible execute() pattern
|
||||
/// @dev Single-entrypoint execute() dispatch pattern
|
||||
/// @dev Action types: "order", "cancel", "cancelByClOrdId", "cancelAll", "amend"
|
||||
/// @param action Action type string
|
||||
/// @param data ABI-encoded action data
|
||||
|
||||
@@ -62,7 +62,7 @@ interface ILXOracle {
|
||||
}
|
||||
|
||||
/// @notice Robust index construction parameters
|
||||
/// @dev Based on Hyperliquid's robust index methodology
|
||||
/// @dev TWAP-windowed, outlier-trimmed robust index methodology
|
||||
struct RobustIndexParams {
|
||||
uint32 windowSeconds; // TWAP window (e.g., 900 = 15 min)
|
||||
uint32 minSamples; // Minimum samples in window
|
||||
|
||||
Reference in New Issue
Block a user