Files
graph/engine/v4.go
T
zeekay de2e43e606 Initial commit: Lux Graph Engine
Single-binary GraphQL query layer replacing The Graph's Graph Node.
SQLite WAL + hanzoai/replicate S3 streaming + luxfi/age PQ encryption.

- 18 schemas: AMM V2/V3/V4, DEX, FHE, Platform, XChain, Bridge,
  Privacy, Quantum, Key, AI, Identity, Oracle, Relay, ServiceNode,
  Precompile, ERC20, ERC721
- WASM subgraph loader (uni-v2/v3/v4 build/ dirs)
- EVM indexer: eth_blockNumber + eth_getLogs + V2/V3/V4 event decoding
- Production hardened: rate limiter, query depth/field caps,
  MaxBytesReader, structured logging, /ready, /metrics
- 32 e2e tests, 13 benchmarks, 775 qps @ 100 clients on SQLite
- Dockerfile (multi-stage CGO, non-root, healthcheck)
2026-04-11 13:47:05 -07:00

99 lines
3.7 KiB
Go

package engine
import (
"context"
"fmt"
"github.com/luxfi/graph/storage"
)
// V4 resolvers — PoolManager singleton, ModifyLiquidity, Positions, Subscriptions.
func (e *Engine) registerV4Resolvers() {
// PoolManager (V4 singleton — also aliased as "factory" for V3 compat)
e.resolvers["poolManager"] = e.resolvePoolManager
e.resolvers["poolManagers"] = e.resolvePoolManagers
// ModifyLiquidity (replaces separate mint/burn in V4)
e.resolvers["modifyLiquidity"] = e.resolveModifyLiquidity
e.resolvers["modifyLiquiditys"] = e.resolveModifyLiquiditys // Graph uses this plural
// Positions (V4 ERC721)
e.resolvers["position"] = e.resolvePosition
e.resolvers["positions"] = e.resolvePositions
// Subscriptions (V4 hooks)
e.resolvers["subscribe"] = e.resolveSubscribe
e.resolvers["subscribes"] = e.resolveSubscribes
e.resolvers["unsubscribe"] = e.resolveUnsubscribe
e.resolvers["unsubscribes"] = e.resolveUnsubscribes
// Hourly data
e.resolvers["poolHourDatas"] = e.resolvePoolHourDatas
e.resolvers["tokenHourDatas"] = e.resolveTokenHourDatas
e.resolvers["uniswapDayDatas"] = e.resolveUniswapDayDatas
}
func (e *Engine) resolvePoolManager(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
id := "1"
if v, ok := args["id"]; ok {
id = fmt.Sprint(v)
}
return s.GetFactory(ctx, id) // PoolManager shares factory storage
}
func (e *Engine) resolvePoolManagers(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
return s.GetFactories(ctx)
}
func (e *Engine) resolveModifyLiquidity(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
if id, ok := args["id"]; ok {
return s.GetModifyLiquidity(ctx, fmt.Sprint(id))
}
return nil, fmt.Errorf("modifyLiquidity requires id")
}
func (e *Engine) resolveModifyLiquiditys(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
limit, orderBy, orderDir, _ := parseListArgs(args, 100)
return s.GetModifyLiquiditys(ctx, limit, orderBy, orderDir)
}
func (e *Engine) resolveSubscribe(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
if id, ok := args["id"]; ok {
return s.GetSubscribe(ctx, fmt.Sprint(id))
}
return nil, fmt.Errorf("subscribe requires id")
}
func (e *Engine) resolveSubscribes(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
limit, orderBy, orderDir, _ := parseListArgs(args, 100)
return s.GetSubscribes(ctx, limit, orderBy, orderDir)
}
func (e *Engine) resolveUnsubscribe(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
if id, ok := args["id"]; ok {
return s.GetUnsubscribe(ctx, fmt.Sprint(id))
}
return nil, fmt.Errorf("unsubscribe requires id")
}
func (e *Engine) resolveUnsubscribes(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
limit, orderBy, orderDir, _ := parseListArgs(args, 100)
return s.GetUnsubscribes(ctx, limit, orderBy, orderDir)
}
func (e *Engine) resolvePoolHourDatas(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
limit, orderBy, orderDir, _ := parseListArgs(args, 24)
return s.GetPoolHourDatas(ctx, limit, orderBy, orderDir)
}
func (e *Engine) resolveTokenHourDatas(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
limit, orderBy, orderDir, _ := parseListArgs(args, 24)
return s.GetTokenHourDatas(ctx, limit, orderBy, orderDir)
}
func (e *Engine) resolveUniswapDayDatas(ctx context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
limit, orderBy, orderDir, where := parseListArgs(args, 30)
return s.GetFactoryDayDatas(ctx, limit, orderBy, orderDir, where)
}