mirror of
https://github.com/luxfi/graph.git
synced 2026-09-24 00:26:07 +00:00
Red re-verify found the V4 AMM-spoof gate left a parallel bypass.
MEDIUM — V2/V3 AMM handlers were UNGATED: handlePairCreated, handlePoolCreated,
handleSwapV2, handleSwapV3 accepted events from ANY emitter — a parallel path to
seed phantom pairs/pools/swaps and inflate the SAME public Factory/TVL/volume
aggregates the now-gated V4 handlers (0x9999) block. Mirror the V4 gate:
- PairCreated/PoolCreated now require the canonical FactoryV2/FactoryV3 emitter
(the AMM trust root), exactly as V4 requires 0x9999.
- V2/V3 Swaps are emitted by the pair/pool, not the factory, so the gate is
"is the emitter a pool the canonical factory created?" (isKnownPool). The
factory authorizes a pool; only that pool's Swaps are honored. A rogue
factory's PairCreated is rejected, so its pools are never registered, so its
Swaps are rejected — the whole parallel path is closed.
- Pair/pool keys lower-cased at seed so the Swap-side lookup is RPC-casing safe.
- Factory addresses configurable (Config.FactoryV2/V3 + FACTORY_V2/V3 env),
default to canonical Lux mainnet (LuxMainnet.Factory{V2,V3}); main wires env.
INFO — the per-namespace resolver limit lacked the `if limit < 1 { limit = 100 }`
floor that resolvers/dex has, so a negative/zero `first` flowed to ListByType
(`first:-1` = "no limit" in SQLite — an unbounded scan). Brought every pl()/
parseLimit() copy to the dex-canonical body (floor <1->100 + cap 1000); fhe and
platform also gained the previously-missing 1000 cap. All namespaces now identical.
Tests (go test ./...): indexer + resolvers/{dex,exchange,fhe,platform} green.
- TestHandleV2_RejectsNonFactory, TestHandleV3_RejectsNonFactory: rogue
PairCreated/PoolCreated/Swap seeds nothing and does not inflate the factory
aggregate; the canonical-source event IS honored end-to-end.
- TestPL_ClampsFirst / TestParseLimit_ClampsFirst (exchange/fhe/platform):
negative/zero floored to 100, capped at 1000.
79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
// Package liquid provides resolvers for liquid staking.
|
|
//
|
|
// Indexes: stakes, unstakes, rewards, validators.
|
|
//
|
|
// Entities: LiquidStake, LiquidUnstake, LiquidReward, LiquidValidator, LiquidStats
|
|
package liquid
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/luxfi/graph/storage"
|
|
)
|
|
|
|
type ResolverFunc = func(context.Context, *storage.Store, map[string]interface{}) (interface{}, error)
|
|
|
|
func Register(resolvers map[string]ResolverFunc) {
|
|
resolvers["liquidStake"] = resolveLiquidStake
|
|
resolvers["liquidStakes"] = resolveLiquidStakes
|
|
resolvers["liquidUnstake"] = resolveLiquidUnstake
|
|
resolvers["liquidUnstakes"] = resolveLiquidUnstakes
|
|
resolvers["liquidReward"] = resolveLiquidReward
|
|
resolvers["liquidRewards"] = resolveLiquidRewards
|
|
resolvers["liquidValidator"] = resolveLiquidValidator
|
|
resolvers["liquidValidators"] = resolveLiquidValidators
|
|
resolvers["liquidStats"] = resolveLiquidStats
|
|
}
|
|
|
|
func resolveLiquidStake(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
if id, ok := args["id"]; ok {
|
|
return s.GetByType("LiquidStake", fmt.Sprint(id))
|
|
}
|
|
return nil, fmt.Errorf("liquidStake requires id")
|
|
}
|
|
func resolveLiquidStakes(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
return s.ListByType("LiquidStake", pl(args))
|
|
}
|
|
func resolveLiquidUnstake(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
if id, ok := args["id"]; ok {
|
|
return s.GetByType("LiquidUnstake", fmt.Sprint(id))
|
|
}
|
|
return nil, fmt.Errorf("liquidUnstake requires id")
|
|
}
|
|
func resolveLiquidUnstakes(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
return s.ListByType("LiquidUnstake", pl(args))
|
|
}
|
|
func resolveLiquidReward(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
if id, ok := args["id"]; ok {
|
|
return s.GetByType("LiquidReward", fmt.Sprint(id))
|
|
}
|
|
return nil, fmt.Errorf("liquidReward requires id")
|
|
}
|
|
func resolveLiquidRewards(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
return s.ListByType("LiquidReward", pl(args))
|
|
}
|
|
func resolveLiquidValidator(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
if id, ok := args["id"]; ok {
|
|
return s.GetByType("LiquidValidator", fmt.Sprint(id))
|
|
}
|
|
return nil, fmt.Errorf("liquidValidator requires id")
|
|
}
|
|
func resolveLiquidValidators(_ context.Context, s *storage.Store, args map[string]interface{}) (interface{}, error) {
|
|
return s.ListByType("LiquidValidator", pl(args))
|
|
}
|
|
func resolveLiquidStats(_ context.Context, s *storage.Store, _ map[string]interface{}) (interface{}, error) {
|
|
return s.GetByType("LiquidStats", "1")
|
|
}
|
|
|
|
func pl(args map[string]interface{}) int {
|
|
limit := 100
|
|
if l, ok := args["first"]; ok {
|
|
fmt.Sscanf(fmt.Sprint(l), "%d", &limit)
|
|
}
|
|
if limit < 1 {
|
|
limit = 100
|
|
}
|
|
return min(limit, 1000)
|
|
}
|