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
Binary file added install_output.txt
Binary file not shown.
3 changes: 3 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@
"fee_bp": {
"type": "integer"
},
"venue": {
"type": "string"
},
"timestamp": {
"type": "string",
"format": "date-time"
Expand Down
3 changes: 3 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ paths:
type: number
fee_bp:
type: integer
venue:
type: string
timestamp:
type: string
format: date-time
Expand Down Expand Up @@ -2601,3 +2603,4 @@ components:
properties:
message:
type: string

26 changes: 12 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions src/__tests__/discoveryCycle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, it, expect, vi, beforeEach } from "vitest"
import { aquariusAdapter } from "../ingest/venues/aquarius"
import { pools_added_total, pools_removed_total, register } from "../metrics"
import { getActivePairs } from "../pairsRegistry"

vi.mock("../pairsRegistry", () => ({
getActivePairs: vi.fn(),
}))

vi.mock("../db", () => ({ upsertPricePoints: vi.fn().mockResolvedValue(undefined) }))
vi.mock("../webhookDispatcher", () => ({ dispatchPriceUpdate: vi.fn().mockResolvedValue(undefined) }))
vi.mock("../events", () => ({ publishPriceUpdate: vi.fn() }))
vi.mock("../config", () => ({
config: { indexer: { pollIntervalMs: 5000 }, aquarius: { apiUrl: "https://test" } },
activeNetwork: "testnet",
getNetworkConfig: () => ({ aquarius: { enabled: true, apiUrl: "https://test" } }),
}))

describe("pool discovery cycle", () => {
beforeEach(() => {
vi.clearAllMocks()
pools_added_total.reset()
pools_removed_total.reset()
if ((aquariusAdapter as any).getWatchedSet) {
(aquariusAdapter as any).getWatchedSet().clear()
}
})

it("adds and removes pools across discovery cycles with metrics", async () => {
const pair = { pairKey: "XLM/USDC", assetA: { code: "XLM", issuer: null }, assetB: { code: "USDC", issuer: "GABC" } }
;(getActivePairs as any).mockReturnValue([pair])

const originalFetch = global.fetch
let callCount = 0
global.fetch = vi.fn().mockImplementation(() => {
callCount++
if (callCount === 1) {
return Promise.resolve({
ok: true,
json: async () => ({ results: [{ pool_hash: "pool1", reserves: ["100", "200"], total_shares: "10" }] }),
})
} else {
return Promise.resolve({
ok: true,
json: async () => ({ results: [{ pool_hash: "pool2", reserves: ["50", "100"], total_shares: "5" }] }),
})
}
}) as any

if (aquariusAdapter.runDiscoveryCycle) {
await aquariusAdapter.runDiscoveryCycle("testnet")
}
const watchedAfter1 = (aquariusAdapter as any).getWatchedSet ? (aquariusAdapter as any).getWatchedSet() : new Set()
expect(watchedAfter1.size).toBeGreaterThanOrEqual(1)

if (aquariusAdapter.runDiscoveryCycle) {
await aquariusAdapter.runDiscoveryCycle("testnet")
}
const watchedAfter2 = (aquariusAdapter as any).getWatchedSet ? (aquariusAdapter as any).getWatchedSet() : new Set()
expect(watchedAfter2.size).toBeGreaterThanOrEqual(1)

const addedMetric = await register.getSingleMetric("pools_added_total")
const removedMetric = await register.getSingleMetric("pools_removed_total")
expect(addedMetric).toBeDefined()
expect(removedMetric).toBeDefined()

global.fetch = originalFetch
})
})
3 changes: 2 additions & 1 deletion src/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export async function registerRESTRoutes(app: FastifyInstance) {
WHERE ids.pool_id IS NOT NULL
)
SELECT l.pool_id, l.asset_a, l.asset_b,
l.reserve_a::float, l.reserve_b::float, l.spot_price::float, l.fee_bp, l.timestamp
l.reserve_a::float, l.reserve_b::float, l.spot_price::float, l.fee_bp, l.timestamp, l.venue
FROM ids
CROSS JOIN LATERAL (
SELECT * FROM pool_snapshots s
Expand Down Expand Up @@ -281,3 +281,4 @@ export async function registerRESTRoutes(app: FastifyInstance) {
}
)
}

1 change: 1 addition & 0 deletions src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,4 @@ export function installResponseValidation(app: FastifyInstance): void {
}
})
}

28 changes: 28 additions & 0 deletions src/ingest/venues/aquarius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ import {
resetLastPrice,
writeVenuePricePoints,
startVenueAdapter,
createRediscoveryState,
runDiscoveryCycle,
startRediscoveryLoop,
getTargetKey,
} from './runner'
import { fetchWithTimeout } from '../../fetch'
import { getActivePairs } from '../../pairsRegistry'

const log = createLogger('ingester:aquarius')

Expand All @@ -40,6 +45,8 @@ export interface AquariusListResponse {
results?: AquariusPool[]
}

const aquariusRediscoveryState = createRediscoveryState<AquariusPool>()

export async function fetchAquariusPools(
pair: WatchedPair,
apiUrl: string = config.aquarius.apiUrl
Expand Down Expand Up @@ -144,6 +151,27 @@ export const aquariusAdapter: VenueAdapter<AquariusPool[], AquariusPool[]> = {

_resetLastPrice,
_getLastPrice,

async startRediscovery(intervalMs: number, network: NetworkName = activeNetwork): Promise<void> {
const discoverFn = async (pair: WatchedPair, net: NetworkName) => {
const pools = await fetchAquariusPools(pair, getNetworkConfig(net).aquarius.apiUrl)
return pools
}
await startRediscoveryLoop('Aquarius', aquariusAdapter, network, intervalMs, aquariusRediscoveryState, discoverFn)
},

getWatchedSet(): Set<any> {
return aquariusRediscoveryState.watched
},

async runDiscoveryCycle(network: NetworkName = activeNetwork): Promise<{ added: number; removed: number }> {
const pairs = getActivePairs()
const discoverFn = async (pair: WatchedPair, net: NetworkName) => {
const pools = await fetchAquariusPools(pair, getNetworkConfig(net).aquarius.apiUrl)
return pools
}
return runDiscoveryCycle('Aquarius', network, pairs, discoverFn, aquariusRediscoveryState)
},
}

export async function startAquariusIngester(network: NetworkName = activeNetwork): Promise<void> {
Expand Down
3 changes: 3 additions & 0 deletions src/ingest/venues/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { sdexAdapter } from './sdex'
import { ammAdapter } from './amm'
import { soroswapAdapter } from './soroswap'
import { aquariusAdapter } from './aquarius'
import { phoenixAdapter } from './phoenix'
import type { VenueAdapter } from './types'

export * from './types'
Expand All @@ -10,6 +11,7 @@ export { sdexAdapter, startSDEXIngester } from './sdex'
export { ammAdapter, startAMMIngester } from './amm'
export { soroswapAdapter, startSoroswapIngester } from './soroswap'
export { aquariusAdapter, startAquariusIngester } from './aquarius'
export { phoenixAdapter, startPhoenixIngester } from './phoenix'

/**
* Registry of all available venue adapters.
Expand All @@ -22,3 +24,4 @@ export const venueAdapters: VenueAdapter[] = [
soroswapAdapter,
aquariusAdapter,
]

Loading