Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makalu/contracts/subgraph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
generated/
build/
.turbo/
58 changes: 58 additions & 0 deletions Makalu/contracts/subgraph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Lithoswap V2 Subgraph (Makalu)

Indexes the Lithoswap V2 DEX on Lithosphere Makalu (700777) for pool, price and
volume analytics used by the explorer. It mirrors the pattern of the Kamet DEX
subgraph (self-hosted graph-node on vps2, `subgraph.litho.ai`) but targets our
**V2** contracts — the Kamet subgraph is **v3-shaped** (`sqrtPriceX96`, tick
math) and does not index v2, so this is a v2 fork of that approach, not a copy.

## What it tracks

Reserves, reserve-ratio prices (`token0Price` = token1 per token0), per-token
and per-pair **volume in token units**, swap/mint/burn events, and daily
aggregates (`PairDayData`, `TokenDayData`). **USD pricing is intentionally
omitted** — Makalu has no stablecoin pool to anchor it. When one lands, add a
`Bundle` + derived-ETH pricing (the canonical Uniswap-V2 approach) on top.

## Configure after deploying the DEX

The factory address and start block are placeholders until the DEX is deployed
(`Makalu/contracts/scripts/deploy-dex.ts` writes `deployments/dex-700777.json`).
Fill both in `networks.json` (and/or `subgraph.yaml`):

- `LithoswapV2Factory.address` → the deployed `LithoswapV2Factory`
- `startBlock` → the block the factory was deployed in (avoids scanning genesis)

## Build & deploy

```sh
cd Makalu/contracts/subgraph
pnpm install
pnpm codegen # generates ./generated from schema + ABIs
pnpm build:makalu # applies networks.json, compiles the wasm mappings
pnpm deploy # → subgraph.litho.ai (self-hosted graph-node on vps2)
```

`codegen` + `build` are the correctness gate for the AssemblyScript mappings —
run them wherever `@graphprotocol/graph-cli` and network access are available
(vps2 or CI); they are not run in this offline workspace.

## Consuming from the explorer

Query `https://subgraph.litho.ai/subgraphs/name/litho/lithoswap`. Example — top
pools by tx count with current price:

```graphql
{
pairs(first: 10, orderBy: txCount, orderDirection: desc) {
id
token0 { symbol }
token1 { symbol }
reserve0
reserve1
token0Price
volumeToken0
txCount
}
}
```
30 changes: 30 additions & 0 deletions Makalu/contracts/subgraph/abis/ERC20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
}
]
30 changes: 30 additions & 0 deletions Makalu/contracts/subgraph/abis/LithoswapV2Factory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "token0", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "token1", "type": "address" },
{ "indexed": false, "internalType": "address", "name": "pair", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "", "type": "uint256" }
],
"name": "PairCreated",
"type": "event"
},
{
"inputs": [],
"name": "allPairsLength",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "address", "name": "", "type": "address" }
],
"name": "getPair",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
}
]
87 changes: 87 additions & 0 deletions Makalu/contracts/subgraph/abis/LithoswapV2Pair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" }
],
"name": "Mint",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" }
],
"name": "Burn",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "amount0In", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "amount1In", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "amount0Out", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "amount1Out", "type": "uint256" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" }
],
"name": "Swap",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "uint112", "name": "reserve0", "type": "uint112" },
{ "indexed": false, "internalType": "uint112", "name": "reserve1", "type": "uint112" }
],
"name": "Sync",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "from", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [],
"name": "token0",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "token1",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getReserves",
"outputs": [
{ "internalType": "uint112", "name": "reserve0", "type": "uint112" },
{ "internalType": "uint112", "name": "reserve1", "type": "uint112" },
{ "internalType": "uint32", "name": "blockTimestampLast", "type": "uint32" }
],
"stateMutability": "view",
"type": "function"
}
]
8 changes: 8 additions & 0 deletions Makalu/contracts/subgraph/networks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"makalu": {
"LithoswapV2Factory": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 0
}
}
}
18 changes: 18 additions & 0 deletions Makalu/contracts/subgraph/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@lithosphere/lithoswap-subgraph",
"version": "0.1.0",
"private": true,
"description": "Lithoswap V2 subgraph — pools, prices and volume on Lithosphere Makalu",
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"build:makalu": "graph build --network makalu",
"create:local": "graph create --node http://localhost:8020/ litho/lithoswap",
"deploy:local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 litho/lithoswap",
"deploy": "graph deploy --node https://subgraph.litho.ai/deploy/ --ipfs https://subgraph.litho.ai/ipfs/ litho/lithoswap"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.71.0",
"@graphprotocol/graph-ts": "0.32.0"
}
}
116 changes: 116 additions & 0 deletions Makalu/contracts/subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Lithoswap V2 subgraph schema (Makalu).
#
# Focused on on-chain facts that don't need a USD reference: reserves,
# reserve-ratio prices, token-denominated volumes, liquidity/swap events, and
# daily aggregates for charts. USD pricing is intentionally omitted — Makalu has
# no stablecoin pool to anchor it; add a Bundle + derived pricing later if one
# lands.

type LithoswapFactory @entity {
" Factory address "
id: ID!
pairCount: Int!
txCount: BigInt!
totalVolumeToken: BigDecimal! # summed across pairs, token units (not USD)
}

type Token @entity {
" Token address "
id: ID!
symbol: String!
name: String!
decimals: BigInt!
totalSupply: BigInt!
tradeVolume: BigDecimal! # cumulative volume in this token's units
txCount: BigInt!
totalLiquidity: BigDecimal! # amount of this token pooled across all pairs
}

type Pair @entity {
" Pair (pool) address "
id: ID!
token0: Token!
token1: Token!
reserve0: BigDecimal!
reserve1: BigDecimal!
totalSupply: BigDecimal! # LP token supply
" token1 per token0 (reserve1/reserve0) "
token0Price: BigDecimal!
" token0 per token1 (reserve0/reserve1) "
token1Price: BigDecimal!
volumeToken0: BigDecimal!
volumeToken1: BigDecimal!
txCount: BigInt!
createdAtTimestamp: BigInt!
createdAtBlockNumber: BigInt!
}

type Transaction @entity {
" Transaction hash "
id: ID!
blockNumber: BigInt!
timestamp: BigInt!
mints: [Mint!]! @derivedFrom(field: "transaction")
burns: [Burn!]! @derivedFrom(field: "transaction")
swaps: [Swap!]! @derivedFrom(field: "transaction")
}

type Mint @entity {
" txhash-logindex "
id: ID!
transaction: Transaction!
timestamp: BigInt!
pair: Pair!
sender: Bytes!
amount0: BigDecimal!
amount1: BigDecimal!
}

type Burn @entity {
id: ID!
transaction: Transaction!
timestamp: BigInt!
pair: Pair!
sender: Bytes!
to: Bytes!
amount0: BigDecimal!
amount1: BigDecimal!
}

type Swap @entity {
id: ID!
transaction: Transaction!
timestamp: BigInt!
pair: Pair!
sender: Bytes!
from: Bytes!
to: Bytes!
amount0In: BigDecimal!
amount1In: BigDecimal!
amount0Out: BigDecimal!
amount1Out: BigDecimal!
}

type PairDayData @entity {
" pairAddress-dayId "
id: ID!
date: Int!
pair: Pair!
token0: Token!
token1: Token!
reserve0: BigDecimal!
reserve1: BigDecimal!
dailyVolumeToken0: BigDecimal!
dailyVolumeToken1: BigDecimal!
dailyTxns: BigInt!
}

type TokenDayData @entity {
" tokenAddress-dayId "
id: ID!
date: Int!
token: Token!
dailyVolumeToken: BigDecimal!
totalLiquidityToken: BigDecimal!
dailyTxns: BigInt!
}
Loading
Loading